Skip to content

Commit dbc5b5e

Browse files
committed
fix consumer control support
1 parent df1e6f5 commit dbc5b5e

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

cores/rp2040/RP2040USB.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,30 @@ void __USBSetDeviceAttributes(__USBDeviceAttributes &attrs) {
6666
__usb_device_attrs = attrs;
6767
}
6868

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)
7873
#define USBD_CDC_IN_OUT_MAX_SIZE (64)
7974

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)
8580

86-
#define EPNUM_HID 0x83
81+
#define EPNUM_HID 0x83
8782

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
9186

92-
#define EPNUM_HID2_EPOUT 0x05
93-
#define EPNUM_HID2_EPIN 0x85
87+
#define EPNUM_HID2_EPOUT 0x05
88+
#define EPNUM_HID2_EPIN 0x85
9489

9590
const uint8_t *tud_descriptor_device_cb(void) {
91+
bool isSerialOnly = (__USBInstallSerial && !__USBInstallKeyboard && !__USBInstallMouse && !__USBInstallJoystick && !__USBInstallConsumerControl && !__USBInstallMassStorage && !__USBInstallSecondHID_RawHID);
92+
9693
uint16_t vendorId = __usb_device_attrs.vendorId;
9794
uint16_t productId = __usb_device_attrs.productId;
9895

@@ -107,6 +104,9 @@ const uint8_t *tud_descriptor_device_cb(void) {
107104
if (__USBInstallJoystick) {
108105
productId |= 0x0100;
109106
}
107+
if (__USBInstallConsumerControl) {
108+
productId |= 0x0200;
109+
}
110110
if (__USBInstallMassStorage) {
111111
productId ^= 0x2000;
112112
}
@@ -119,9 +119,9 @@ const uint8_t *tud_descriptor_device_cb(void) {
119119
.bLength = sizeof(tusb_desc_device_t),
120120
.bDescriptorType = TUSB_DESC_DEVICE,
121121
.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),
125125
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
126126
.idVendor = vendorId,
127127
.idProduct = productId,
@@ -257,7 +257,7 @@ void __SetupDescHIDReport() {
257257
uint8_t desc[] = { TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(report_id)) };
258258
memcpy(__hid_report + offset, desc, sizeof(desc));
259259
offset += sizeof(desc);
260-
} else if (Report_Type_ConsumerControl) {
260+
} else if (report_type == Report_Type_ConsumerControl) {
261261
uint8_t desc[] = { TUD_HID_REPORT_DESC_CONSUMER(HID_REPORT_ID(report_id)) };
262262
memcpy(__hid_report + offset, desc, sizeof(desc));
263263
offset += sizeof(desc);
@@ -299,7 +299,7 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
299299
void __SetupUSBDescriptor() {
300300
if (!usbd_desc_cfg) {
301301
bool hasSerial = __USBInstallSerial;
302-
bool hasHID = __USBInstallKeyboard || __USBInstallMouse || __USBInstallJoystick;
302+
bool hasHID = __USBInstallKeyboard || __USBInstallMouse || __USBInstallJoystick || __USBInstallConsumerControl;
303303
bool hasMSD = __USBInstallMassStorage;
304304
bool hasHID2 = __USBInstallSecondHID_RawHID;
305305

0 commit comments

Comments
 (0)