打开 usbd_custom_hid_if.c 文件,找到 CUSTOM_HID_ReportDesc_FS, 修改报告描述符为:#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 23
/** Usb HID report descriptor. */
__ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE]
__ALIGN_END =
{
/* USER CODE BEGIN 0 */
0x06, 0x00, 0xFF, /* USAGE_PAGE (Vendor Page: 0xFF00) */
0x09, 0x01, /* USAGE (Demo Kit) */
0xa1, 0x00, /* COLLECTION (Physical) */
0x85, 0x80, /* REPORT_ID (128) */
0x09, 0x55, /*USAGE (LED 1) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x26, 0xFF, 0x00, /* LOGICAL_MAXIMUM (255) */
0x75, 0x08, /* REPORT_SIZE (8 bits) */
0x95, 0x01, /* REPORT_COUNT (1) */
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol */
/* USER CODE END 0 */
0xC0 /* END_COLLECTION */
};
然后找到 CUSTOM_HID_OutEvent_FS 函数,修改为:
static int8_t CUSTOM_HID_OutEvent_FS(uint8_t event_idx, uint8_t state)
{
/* USER CODE BEGIN 6 */
extern RTC_HandleTypeDef hrtc;
if(event_idx ==0x80 && state ==0x55)
{
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR0,0x32F2);
HAL_PWR_DisableBkUpAccess();
HAL_NVIC_SystemReset();
while (1);
}
return (USBD_OK);
/* USER CODE END 6 */
}
|