@@ -66,33 +66,30 @@ void __USBSetDeviceAttributes(__USBDeviceAttributes &attrs) {
66
66
__usb_device_attrs = attrs;
67
67
}
68
68
69
- #define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
70
-
71
- #define USBD_ITF_CDC (0 ) // needs 2 interfaces
72
- #define USBD_ITF_MAX (2 )
73
-
74
- #define USBD_CDC_EP_CMD (0x81 )
75
- #define USBD_CDC_EP_OUT (0x02 )
76
- #define USBD_CDC_EP_IN (0x82 )
77
- #define USBD_CDC_CMD_MAX_SIZE (8 )
69
+ #define USBD_CDC_EP_CMD (0x81 )
70
+ #define USBD_CDC_EP_OUT (0x02 )
71
+ #define USBD_CDC_EP_IN (0x82 )
72
+ #define USBD_CDC_CMD_MAX_SIZE (8 )
78
73
#define USBD_CDC_IN_OUT_MAX_SIZE (64 )
79
74
80
- #define USBD_STR_0 (0x00 )
81
- #define USBD_STR_MANUF (0x01 )
82
- #define USBD_STR_PRODUCT (0x02 )
83
- #define USBD_STR_SERIAL (0x03 )
84
- #define USBD_STR_CDC (0x04 )
75
+ #define USBD_STR_0 (0x00 )
76
+ #define USBD_STR_MANUF (0x01 )
77
+ #define USBD_STR_PRODUCT (0x02 )
78
+ #define USBD_STR_SERIAL (0x03 )
79
+ #define USBD_STR_CDC (0x04 )
85
80
86
- #define EPNUM_HID 0x83
81
+ #define EPNUM_HID 0x83
87
82
88
- #define USBD_MSC_EPOUT 0x03
89
- #define USBD_MSC_EPIN 0x84
90
- #define USBD_MSC_EPSIZE 64
83
+ #define USBD_MSC_EPOUT 0x03
84
+ #define USBD_MSC_EPIN 0x84
85
+ #define USBD_MSC_EPSIZE 64
91
86
92
- #define EPNUM_HID2_EPOUT 0x05
93
- #define EPNUM_HID2_EPIN 0x85
87
+ #define EPNUM_HID2_EPOUT 0x05
88
+ #define EPNUM_HID2_EPIN 0x85
94
89
95
90
const uint8_t *tud_descriptor_device_cb (void ) {
91
+ bool isSerialOnly = (__USBInstallSerial && !__USBInstallKeyboard && !__USBInstallMouse && !__USBInstallJoystick && !__USBInstallConsumerControl && !__USBInstallMassStorage && !__USBInstallSecondHID_RawHID);
92
+
96
93
uint16_t vendorId = __usb_device_attrs.vendorId ;
97
94
uint16_t productId = __usb_device_attrs.productId ;
98
95
@@ -107,6 +104,9 @@ const uint8_t *tud_descriptor_device_cb(void) {
107
104
if (__USBInstallJoystick) {
108
105
productId |= 0x0100 ;
109
106
}
107
+ if (__USBInstallConsumerControl) {
108
+ productId |= 0x0200 ;
109
+ }
110
110
if (__USBInstallMassStorage) {
111
111
productId ^= 0x2000 ;
112
112
}
@@ -119,9 +119,9 @@ const uint8_t *tud_descriptor_device_cb(void) {
119
119
.bLength = sizeof (tusb_desc_device_t ),
120
120
.bDescriptorType = TUSB_DESC_DEVICE,
121
121
.bcdUSB = 0x0200 ,
122
- .bDeviceClass = TUSB_CLASS_MISC,
123
- .bDeviceSubClass = MISC_SUBCLASS_COMMON,
124
- .bDeviceProtocol = MISC_PROTOCOL_IAD,
122
+ .bDeviceClass = ( uint8_t ) (isSerialOnly ? TUSB_CLASS_MISC : 0 ) ,
123
+ .bDeviceSubClass = ( uint8_t ) (isSerialOnly ? MISC_SUBCLASS_COMMON : 0 ) ,
124
+ .bDeviceProtocol = ( uint8_t ) (isSerialOnly ? MISC_PROTOCOL_IAD : 0 ) ,
125
125
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
126
126
.idVendor = vendorId,
127
127
.idProduct = productId,
@@ -257,7 +257,7 @@ void __SetupDescHIDReport() {
257
257
uint8_t desc[] = { TUD_HID_REPORT_DESC_GAMEPAD (HID_REPORT_ID (report_id)) };
258
258
memcpy (__hid_report + offset, desc, sizeof (desc));
259
259
offset += sizeof (desc);
260
- } else if (Report_Type_ConsumerControl) {
260
+ } else if (report_type == Report_Type_ConsumerControl) {
261
261
uint8_t desc[] = { TUD_HID_REPORT_DESC_CONSUMER (HID_REPORT_ID (report_id)) };
262
262
memcpy (__hid_report + offset, desc, sizeof (desc));
263
263
offset += sizeof (desc);
@@ -299,7 +299,7 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
299
299
void __SetupUSBDescriptor () {
300
300
if (!usbd_desc_cfg) {
301
301
bool hasSerial = __USBInstallSerial;
302
- bool hasHID = __USBInstallKeyboard || __USBInstallMouse || __USBInstallJoystick;
302
+ bool hasHID = __USBInstallKeyboard || __USBInstallMouse || __USBInstallJoystick || __USBInstallConsumerControl ;
303
303
bool hasMSD = __USBInstallMassStorage;
304
304
bool hasHID2 = __USBInstallSecondHID_RawHID;
305
305
0 commit comments