Skip to content

Commit 85f04a3

Browse files
Nicoobra
authored andcommitted
Added USB definitions, fixed USB device Descriptor
1 parent e3b6a34 commit 85f04a3

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

plugins/KeyboardioHID/USBCore.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020

2121
#if defined(USBCON)
2222

23-
#define EP_TYPE_CONTROL 0x00
24-
#define EP_TYPE_BULK_IN 0x81
25-
#define EP_TYPE_BULK_OUT 0x80
26-
#define EP_TYPE_INTERRUPT_IN 0xC1
27-
#define EP_TYPE_INTERRUPT_OUT 0xC0
28-
#define EP_TYPE_ISOCHRONOUS_IN 0x41
29-
#define EP_TYPE_ISOCHRONOUS_OUT 0x40
23+
#define EP_TYPE_CONTROL (0x00)
24+
#define EP_TYPE_BULK_IN ((1<<EPTYPE1) | (1<<EPDIR))
25+
#define EP_TYPE_BULK_OUT (1<<EPTYPE1)
26+
#define EP_TYPE_INTERRUPT_IN ((1<<EPTYPE1) | (1<<EPTYPE0) | (1<<EPDIR))
27+
#define EP_TYPE_INTERRUPT_OUT ((1<<EPTYPE1) | (1<<EPTYPE0))
28+
#define EP_TYPE_ISOCHRONOUS_IN ((1<<EPTYPE0) | (1<<EPDIR))
29+
#define EP_TYPE_ISOCHRONOUS_OUT (1<<EPTYPE0)
3030

3131
/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
3232
#define TX_RX_LED_PULSE_MS 100
@@ -71,19 +71,28 @@ const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT;
7171

7272
const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
7373

74-
75-
#ifdef CDC_ENABLED
76-
#define DEVICE_CLASS 0x02
77-
#else
78-
#define DEVICE_CLASS 0x00
79-
#endif
74+
// edit by NicoHood
75+
// refering to the official docs we have to use a different descriptor for CDC + HID:
76+
// http://www.usb.org/developers/defined_class
8077

8178
// DEVICE DESCRIPTOR
79+
#if defined(CDC_ENABLED) && defined(HID_ENABLED)
80+
const DeviceDescriptor USB_DeviceDescriptor =
81+
D_DEVICE(USB_DEVICE_CLASS_IAD, USB_DEVICE_SUB_CLASS_IAD, USB_DEVICE_PROTOCOL_IAD, 64, USB_VID, USB_PID, 0x100, IMANUFACTURER, IPRODUCT, 0, 1);
82+
83+
#elif defined(CDC_ENABLED)
8284
const DeviceDescriptor USB_DeviceDescriptor =
83-
D_DEVICE(0x00, 0x00, 0x00, 64, USB_VID, USB_PID, 0x100, IMANUFACTURER, IPRODUCT, 0, 1);
85+
D_DEVICE(USB_DEVICE_CDC_CLASS, USB_DEVICE_CDC_SUB_CLASS, USB_DEVICE_CDC_PROTOCOL, 64, USB_VID, USB_PID, 0x100, IMANUFACTURER, IPRODUCT, 0, 1);
86+
87+
//#elif defined(HID_ENABLED)
88+
#else
89+
const DeviceDescriptor USB_DeviceDescriptor =
90+
D_DEVICE(USB_DEVICE_NO_CLASS, USB_DEVICE_NO_SUB_CLASS, USB_DEVICE_NO_PROTOCOL, 64, USB_VID, USB_PID, 0x100, IMANUFACTURER, IPRODUCT, 0, 1);
91+
92+
#endif
8493

8594
const DeviceDescriptor USB_DeviceDescriptorA =
86-
D_DEVICE(DEVICE_CLASS, 0x00, 0x00, 64, USB_VID, USB_PID, 0x100, IMANUFACTURER, IPRODUCT, 0, 1);
95+
D_DEVICE(USB_DEVICE_NO_CLASS, USB_DEVICE_NO_SUB_CLASS, USB_DEVICE_NO_PROTOCOL, 64, USB_VID, USB_PID, 0x100, IMANUFACTURER, IPRODUCT, 0, 1);
8796

8897
//==================================================================
8998
//==================================================================
@@ -340,7 +349,7 @@ static
340349
void InitEP(u8 index, u8 type, u8 size)
341350
{
342351
UENUM = index;
343-
UECONX = 1;
352+
UECONX = (1 << EPEN);
344353
UECFG0X = type;
345354
UECFG1X = size;
346355
}
@@ -351,7 +360,7 @@ void InitEndpoints()
351360
for (u8 i = 1; i < sizeof(_initEndpoints); i++)
352361
{
353362
UENUM = i;
354-
UECONX = 1;
363+
UECONX = (1 << EPEN);
355364
UECFG0X = pgm_read_byte(_initEndpoints + i);
356365
UECFG1X = EP_DOUBLE_64;
357366
}

plugins/KeyboardioHID/USBCore.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@
8484
#define USB_DEVICE_CLASS_STORAGE 0x08
8585
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
8686

87+
// edit by NicoHood
88+
// added new definitions for correct USB descriptors
89+
// there are even more, these are the ones we need
90+
#define USB_DEVICE_CLASS_IAD 0xEF
91+
#define USB_DEVICE_SUB_CLASS_IAD 0x02
92+
#define USB_DEVICE_PROTOCOL_IAD 0x01
93+
94+
#define USB_DEVICE_CDC_CLASS 0x02
95+
#define USB_DEVICE_CDC_SUB_CLASS 0x00
96+
#define USB_DEVICE_CDC_PROTOCOL 0x00 // NoSpecific Protocol
97+
98+
#define USB_DEVICE_NO_CLASS 0x00
99+
#define USB_DEVICE_NO_SUB_CLASS 0x00
100+
#define USB_DEVICE_NO_PROTOCOL 0x00
101+
87102
#define USB_CONFIG_POWERED_MASK 0x40
88103
#define USB_CONFIG_BUS_POWERED 0x80
89104
#define USB_CONFIG_SELF_POWERED 0xC0

0 commit comments

Comments
 (0)