From d286a97c4238a2f879f496a256a4246d68a66230 Mon Sep 17 00:00:00 2001 From: Alexander Mueller Date: Mon, 25 Sep 2023 15:20:21 +0200 Subject: [PATCH] CustomHID: support different report descriptor sizes Right now if you have more than 1 CustomHID interface, all interfaces have report descriptors of the same size. Support different sizes by adding an entry to USBD_CUSTOM_HID_ItfTypeDef. The default is USBD_CUSTOM_HID_REPORT_DESC_SIZE, so this is backwards compatible. --- Class/CompositeBuilder/Src/usbd_composite_builder.c | 2 +- Class/CustomHID/Inc/usbd_customhid.h | 1 + Class/CustomHID/Src/usbd_customhid_if_template.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Class/CompositeBuilder/Src/usbd_composite_builder.c b/Class/CompositeBuilder/Src/usbd_composite_builder.c index e14c5cd..775b43d 100644 --- a/Class/CompositeBuilder/Src/usbd_composite_builder.c +++ b/Class/CompositeBuilder/Src/usbd_composite_builder.c @@ -1393,7 +1393,7 @@ static void USBD_CMPSIT_CUSTOMHIDDesc(USBD_HandleTypeDef *pdev, uint32_t pConf, pDesc->bCountryCode = 0x00U; pDesc->bNumDescriptors = 0x01U; pDesc->bDescriptorType = 0x22U; - pDesc->wItemLength = USBD_CUSTOM_HID_REPORT_DESC_SIZE; + pDesc->wItemLength = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->wReportDescrLen; *Sze += (uint32_t)sizeof(USBD_DescTypeDef); /* Descriptor of Custom HID endpoints */ diff --git a/Class/CustomHID/Inc/usbd_customhid.h b/Class/CustomHID/Inc/usbd_customhid.h index 2f4c634..322b6f0 100644 --- a/Class/CustomHID/Inc/usbd_customhid.h +++ b/Class/CustomHID/Inc/usbd_customhid.h @@ -103,6 +103,7 @@ typedef enum typedef struct _USBD_CUSTOM_HID_Itf { uint8_t *pReport; + uint16_t wReportDescrLen; int8_t (* Init)(void); int8_t (* DeInit)(void); int8_t (* OutEvent)(uint8_t event_idx, uint8_t state); diff --git a/Class/CustomHID/Src/usbd_customhid_if_template.c b/Class/CustomHID/Src/usbd_customhid_if_template.c index 85881bd..f7b4fe9 100644 --- a/Class/CustomHID/Src/usbd_customhid_if_template.c +++ b/Class/CustomHID/Src/usbd_customhid_if_template.c @@ -49,6 +49,7 @@ __ALIGN_BEGIN static uint8_t TEMPLATE_CUSTOM_HID_ReportDesc[USBD_CUSTOM_HID_REPO USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops = { TEMPLATE_CUSTOM_HID_ReportDesc, + USBD_CUSTOM_HID_REPORT_DESC_SIZE, TEMPLATE_CUSTOM_HID_Init, TEMPLATE_CUSTOM_HID_DeInit, TEMPLATE_CUSTOM_HID_OutEvent,