Skip to content

Commit 2a33114

Browse files
authored
Merge pull request #3772 from Ingramz/master
Improve readability of USBHID related descriptors
2 parents 9ea5702 + 29d5ebb commit 2a33114

File tree

4 files changed

+157
-152
lines changed

4 files changed

+157
-152
lines changed

features/unsupported/USBDevice/USBHID/USBHID.cpp

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,23 @@ uint8_t * USBHID::stringIproductDesc() {
199199

200200
uint8_t * USBHID::reportDesc() {
201201
static uint8_t reportDescriptor[] = {
202-
0x06, LSB(0xFFAB), MSB(0xFFAB),
203-
0x0A, LSB(0x0200), MSB(0x0200),
204-
0xA1, 0x01, // Collection 0x01
205-
0x75, 0x08, // report size = 8 bits
206-
0x15, 0x00, // logical minimum = 0
207-
0x26, 0xFF, 0x00, // logical maximum = 255
208-
0x95, input_length, // report count
209-
0x09, 0x01, // usage
210-
0x81, 0x02, // Input (array)
211-
0x95, output_length,// report count
212-
0x09, 0x02, // usage
213-
0x91, 0x02, // Output (array)
214-
0xC0 // end collection
202+
USAGE_PAGE(2), LSB(0xFFAB), MSB(0xFFAB),
203+
USAGE(2), LSB(0x0200), MSB(0x0200),
204+
COLLECTION(1), 0x01, // Collection (Application)
215205

206+
REPORT_SIZE(1), 0x08, // 8 bits
207+
LOGICAL_MINIMUM(1), 0x00,
208+
LOGICAL_MAXIMUM(1), 0xFF,
209+
210+
REPORT_COUNT(1), input_length,
211+
USAGE(1), 0x01,
212+
INPUT(1), 0x02, // Data, Var, Abs
213+
214+
REPORT_COUNT(1), output_length,
215+
USAGE(1), 0x02,
216+
OUTPUT(1), 0x02, // Data, Var, Abs
217+
218+
END_COLLECTION(0),
216219
};
217220
reportLength = sizeof(reportDescriptor);
218221
return reportDescriptor;
@@ -226,51 +229,51 @@ uint8_t * USBHID::reportDesc() {
226229

227230
uint8_t * USBHID::configurationDesc() {
228231
static uint8_t configurationDescriptor[] = {
229-
CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
230-
CONFIGURATION_DESCRIPTOR, // bDescriptorType
231-
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
232-
MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
233-
0x01, // bNumInterfaces
234-
DEFAULT_CONFIGURATION, // bConfigurationValue
235-
0x00, // iConfiguration
236-
C_RESERVED | C_SELF_POWERED, // bmAttributes
237-
C_POWER(0), // bMaxPower
238-
239-
INTERFACE_DESCRIPTOR_LENGTH, // bLength
240-
INTERFACE_DESCRIPTOR, // bDescriptorType
241-
0x00, // bInterfaceNumber
242-
0x00, // bAlternateSetting
243-
0x02, // bNumEndpoints
244-
HID_CLASS, // bInterfaceClass
245-
HID_SUBCLASS_NONE, // bInterfaceSubClass
246-
HID_PROTOCOL_NONE, // bInterfaceProtocol
247-
0x00, // iInterface
248-
249-
HID_DESCRIPTOR_LENGTH, // bLength
250-
HID_DESCRIPTOR, // bDescriptorType
251-
LSB(HID_VERSION_1_11), // bcdHID (LSB)
252-
MSB(HID_VERSION_1_11), // bcdHID (MSB)
253-
0x00, // bCountryCode
254-
0x01, // bNumDescriptors
255-
REPORT_DESCRIPTOR, // bDescriptorType
256-
(uint8_t)(LSB(this->reportDescLength())), // wDescriptorLength (LSB)
257-
(uint8_t)(MSB(this->reportDescLength())), // wDescriptorLength (MSB)
258-
259-
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
260-
ENDPOINT_DESCRIPTOR, // bDescriptorType
261-
PHY_TO_DESC(EPINT_IN), // bEndpointAddress
262-
E_INTERRUPT, // bmAttributes
263-
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
264-
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
265-
1, // bInterval (milliseconds)
266-
267-
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
268-
ENDPOINT_DESCRIPTOR, // bDescriptorType
269-
PHY_TO_DESC(EPINT_OUT), // bEndpointAddress
270-
E_INTERRUPT, // bmAttributes
271-
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
272-
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
273-
1, // bInterval (milliseconds)
232+
CONFIGURATION_DESCRIPTOR_LENGTH, // bLength
233+
CONFIGURATION_DESCRIPTOR, // bDescriptorType
234+
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
235+
MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
236+
0x01, // bNumInterfaces
237+
DEFAULT_CONFIGURATION, // bConfigurationValue
238+
0x00, // iConfiguration
239+
C_RESERVED | C_SELF_POWERED, // bmAttributes
240+
C_POWER(0), // bMaxPower
241+
242+
INTERFACE_DESCRIPTOR_LENGTH, // bLength
243+
INTERFACE_DESCRIPTOR, // bDescriptorType
244+
0x00, // bInterfaceNumber
245+
0x00, // bAlternateSetting
246+
0x02, // bNumEndpoints
247+
HID_CLASS, // bInterfaceClass
248+
HID_SUBCLASS_NONE, // bInterfaceSubClass
249+
HID_PROTOCOL_NONE, // bInterfaceProtocol
250+
0x00, // iInterface
251+
252+
HID_DESCRIPTOR_LENGTH, // bLength
253+
HID_DESCRIPTOR, // bDescriptorType
254+
LSB(HID_VERSION_1_11), // bcdHID (LSB)
255+
MSB(HID_VERSION_1_11), // bcdHID (MSB)
256+
0x00, // bCountryCode
257+
0x01, // bNumDescriptors
258+
REPORT_DESCRIPTOR, // bDescriptorType
259+
(uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
260+
(uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
261+
262+
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
263+
ENDPOINT_DESCRIPTOR, // bDescriptorType
264+
PHY_TO_DESC(EPINT_IN), // bEndpointAddress
265+
E_INTERRUPT, // bmAttributes
266+
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
267+
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
268+
1, // bInterval (milliseconds)
269+
270+
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
271+
ENDPOINT_DESCRIPTOR, // bDescriptorType
272+
PHY_TO_DESC(EPINT_OUT), // bEndpointAddress
273+
E_INTERRUPT, // bmAttributes
274+
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
275+
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
276+
1, // bInterval (milliseconds)
274277
};
275278
return configurationDescriptor;
276279
}

features/unsupported/USBDevice/USBHID/USBHID_Types.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
#define HID_VERSION_1_11 (0x0111)
2626

2727
/* HID Class */
28-
#define HID_CLASS (3)
29-
#define HID_SUBCLASS_NONE (0)
30-
#define HID_PROTOCOL_NONE (0)
28+
#define HID_CLASS (3)
29+
#define HID_SUBCLASS_NONE (0)
30+
#define HID_SUBCLASS_BOOT (1)
31+
#define HID_PROTOCOL_NONE (0)
32+
#define HID_PROTOCOL_KEYBOARD (1)
33+
#define HID_PROTOCOL_MOUSE (2)
3134

3235
/* Descriptors */
3336
#define HID_DESCRIPTOR (33)

features/unsupported/USBDevice/USBHID/USBKeyboard.cpp

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -503,51 +503,51 @@ bool USBKeyboard::mediaControl(MEDIA_KEY key) {
503503

504504
uint8_t * USBKeyboard::configurationDesc() {
505505
static uint8_t configurationDescriptor[] = {
506-
CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
507-
CONFIGURATION_DESCRIPTOR, // bDescriptorType
508-
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
509-
MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
510-
0x01, // bNumInterfaces
511-
DEFAULT_CONFIGURATION, // bConfigurationValue
512-
0x00, // iConfiguration
513-
C_RESERVED | C_SELF_POWERED, // bmAttributes
514-
C_POWER(0), // bMaxPowerHello World from Mbed
515-
516-
INTERFACE_DESCRIPTOR_LENGTH, // bLength
517-
INTERFACE_DESCRIPTOR, // bDescriptorType
518-
0x00, // bInterfaceNumber
519-
0x00, // bAlternateSetting
520-
0x02, // bNumEndpoints
521-
HID_CLASS, // bInterfaceClass
522-
1, // bInterfaceSubClass
523-
1, // bInterfaceProtocol (keyboard)
524-
0x00, // iInterface
525-
526-
HID_DESCRIPTOR_LENGTH, // bLength
527-
HID_DESCRIPTOR, // bDescriptorType
528-
LSB(HID_VERSION_1_11), // bcdHID (LSB)
529-
MSB(HID_VERSION_1_11), // bcdHID (MSB)
530-
0x00, // bCountryCode
531-
0x01, // bNumDescriptors
532-
REPORT_DESCRIPTOR, // bDescriptorType
533-
(uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
534-
(uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
535-
536-
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
537-
ENDPOINT_DESCRIPTOR, // bDescriptorType
538-
PHY_TO_DESC(EPINT_IN), // bEndpointAddress
539-
E_INTERRUPT, // bmAttributes
540-
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
541-
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
542-
1, // bInterval (milliseconds)
543-
544-
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
545-
ENDPOINT_DESCRIPTOR, // bDescriptorType
546-
PHY_TO_DESC(EPINT_OUT), // bEndpointAddress
547-
E_INTERRUPT, // bmAttributes
548-
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
549-
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
550-
1, // bInterval (milliseconds)
506+
CONFIGURATION_DESCRIPTOR_LENGTH, // bLength
507+
CONFIGURATION_DESCRIPTOR, // bDescriptorType
508+
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
509+
MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
510+
0x01, // bNumInterfaces
511+
DEFAULT_CONFIGURATION, // bConfigurationValue
512+
0x00, // iConfiguration
513+
C_RESERVED | C_SELF_POWERED, // bmAttributes
514+
C_POWER(0), // bMaxPower
515+
516+
INTERFACE_DESCRIPTOR_LENGTH, // bLength
517+
INTERFACE_DESCRIPTOR, // bDescriptorType
518+
0x00, // bInterfaceNumber
519+
0x00, // bAlternateSetting
520+
0x02, // bNumEndpoints
521+
HID_CLASS, // bInterfaceClass
522+
HID_SUBCLASS_BOOT, // bInterfaceSubClass
523+
HID_PROTOCOL_KEYBOARD, // bInterfaceProtocol
524+
0x00, // iInterface
525+
526+
HID_DESCRIPTOR_LENGTH, // bLength
527+
HID_DESCRIPTOR, // bDescriptorType
528+
LSB(HID_VERSION_1_11), // bcdHID (LSB)
529+
MSB(HID_VERSION_1_11), // bcdHID (MSB)
530+
0x00, // bCountryCode
531+
0x01, // bNumDescriptors
532+
REPORT_DESCRIPTOR, // bDescriptorType
533+
(uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
534+
(uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
535+
536+
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
537+
ENDPOINT_DESCRIPTOR, // bDescriptorType
538+
PHY_TO_DESC(EPINT_IN), // bEndpointAddress
539+
E_INTERRUPT, // bmAttributes
540+
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
541+
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
542+
1, // bInterval (milliseconds)
543+
544+
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
545+
ENDPOINT_DESCRIPTOR, // bDescriptorType
546+
PHY_TO_DESC(EPINT_OUT), // bEndpointAddress
547+
E_INTERRUPT, // bmAttributes
548+
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
549+
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
550+
1, // bInterval (milliseconds)
551551
};
552552
return configurationDescriptor;
553553
}

features/unsupported/USBDevice/USBHID/USBMouse.cpp

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ uint8_t * USBMouse::reportDesc() {
142142
return reportDescriptor;
143143
} else if (mouse_type == ABS_MOUSE) {
144144
static uint8_t reportDescriptor[] = {
145-
146145
USAGE_PAGE(1), 0x01, // Generic Desktop
147146
USAGE(1), 0x02, // Mouse
148147
COLLECTION(1), 0x01, // Application
@@ -195,51 +194,51 @@ uint8_t * USBMouse::reportDesc() {
195194

196195
uint8_t * USBMouse::configurationDesc() {
197196
static uint8_t configurationDescriptor[] = {
198-
CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
199-
CONFIGURATION_DESCRIPTOR, // bDescriptorType
200-
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
201-
MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
202-
0x01, // bNumInterfaces
203-
DEFAULT_CONFIGURATION, // bConfigurationValue
204-
0x00, // iConfiguration
205-
C_RESERVED | C_SELF_POWERED, // bmAttributes
206-
C_POWER(0), // bMaxPowerHello World from Mbed
207-
208-
INTERFACE_DESCRIPTOR_LENGTH, // bLength
209-
INTERFACE_DESCRIPTOR, // bDescriptorType
210-
0x00, // bInterfaceNumber
211-
0x00, // bAlternateSetting
212-
0x02, // bNumEndpoints
213-
HID_CLASS, // bInterfaceClass
214-
1, // bInterfaceSubClass
215-
2, // bInterfaceProtocol (mouse)
216-
0x00, // iInterface
217-
218-
HID_DESCRIPTOR_LENGTH, // bLength
219-
HID_DESCRIPTOR, // bDescriptorType
220-
LSB(HID_VERSION_1_11), // bcdHID (LSB)
221-
MSB(HID_VERSION_1_11), // bcdHID (MSB)
222-
0x00, // bCountryCode
223-
0x01, // bNumDescriptors
224-
REPORT_DESCRIPTOR, // bDescriptorType
225-
(uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
226-
(uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
227-
228-
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
229-
ENDPOINT_DESCRIPTOR, // bDescriptorType
230-
PHY_TO_DESC(EPINT_IN), // bEndpointAddress
231-
E_INTERRUPT, // bmAttributes
232-
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
233-
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
234-
1, // bInterval (milliseconds)
235-
236-
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
237-
ENDPOINT_DESCRIPTOR, // bDescriptorType
238-
PHY_TO_DESC(EPINT_OUT), // bEndpointAddress
239-
E_INTERRUPT, // bmAttributes
240-
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
241-
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
242-
1, // bInterval (milliseconds)
197+
CONFIGURATION_DESCRIPTOR_LENGTH, // bLength
198+
CONFIGURATION_DESCRIPTOR, // bDescriptorType
199+
LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
200+
MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
201+
0x01, // bNumInterfaces
202+
DEFAULT_CONFIGURATION, // bConfigurationValue
203+
0x00, // iConfiguration
204+
C_RESERVED | C_SELF_POWERED, // bmAttributes
205+
C_POWER(0), // bMaxPower
206+
207+
INTERFACE_DESCRIPTOR_LENGTH, // bLength
208+
INTERFACE_DESCRIPTOR, // bDescriptorType
209+
0x00, // bInterfaceNumber
210+
0x00, // bAlternateSetting
211+
0x02, // bNumEndpoints
212+
HID_CLASS, // bInterfaceClass
213+
HID_SUBCLASS_BOOT, // bInterfaceSubClass
214+
HID_PROTOCOL_MOUSE, // bInterfaceProtocol
215+
0x00, // iInterface
216+
217+
HID_DESCRIPTOR_LENGTH, // bLength
218+
HID_DESCRIPTOR, // bDescriptorType
219+
LSB(HID_VERSION_1_11), // bcdHID (LSB)
220+
MSB(HID_VERSION_1_11), // bcdHID (MSB)
221+
0x00, // bCountryCode
222+
0x01, // bNumDescriptors
223+
REPORT_DESCRIPTOR, // bDescriptorType
224+
(uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
225+
(uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
226+
227+
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
228+
ENDPOINT_DESCRIPTOR, // bDescriptorType
229+
PHY_TO_DESC(EPINT_IN), // bEndpointAddress
230+
E_INTERRUPT, // bmAttributes
231+
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
232+
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
233+
1, // bInterval (milliseconds)
234+
235+
ENDPOINT_DESCRIPTOR_LENGTH, // bLength
236+
ENDPOINT_DESCRIPTOR, // bDescriptorType
237+
PHY_TO_DESC(EPINT_OUT), // bEndpointAddress
238+
E_INTERRUPT, // bmAttributes
239+
LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
240+
MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
241+
1, // bInterval (milliseconds)
243242
};
244243
return configurationDescriptor;
245244
}

0 commit comments

Comments
 (0)