https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
image.png image.png image.png勾选 “Generate peripheral initialization ...” 一项,以便能够更改库函数
image.png打开 usbd_hid.c
和 usb_device.c
文件
main.c
/* USER CODE BEGIN Includes */
#include "usbd_hid.h"
/* USER CODE END Includes */
// ...
/* USER CODE BEGIN 2 */
extern USBD_HandleTypeDef hUsbDeviceFS;
uint8_t HID_buffer[8] = {0};
/* USER CODE END 2 */
// ...
/* USER CODE BEGIN 3 */
HID_buffer[0] = 0b00000010; // shift
HID_buffer[2] = 7; // D
USBD_HID_SendReport(&hUsbDeviceFS, HID_buffer, 8);
HAL_Delay(20);
HID_buffer[0] = 0; // shift
HID_buffer[2] = 0; // D
USBD_HID_SendReport(&hUsbDeviceFS, HID_buffer, 8);
HAL_Delay(2000);
}
/* USER CODE END 3 */
网友评论