|
@@ -349,134 +349,174 @@ const PROGMEM uchar mouse_extra_hid_report[] = {
|
|
|
#endif
|
|
|
|
|
|
|
|
|
-const PROGMEM usbStringDescriptor_t usbDescriptorStringZero = {
|
|
|
+const PROGMEM usbStringDescriptor_t usbStringDescriptorZero = {
|
|
|
.header = {
|
|
|
- .bLength = USB_STRING_LEN(1),
|
|
|
+ .bLength = USB_STRING_LEN(1),
|
|
|
.bDescriptorType = USBDESCR_STRING
|
|
|
},
|
|
|
- .bString = {0x0409}
|
|
|
+ .bString = {0x0409}
|
|
|
};
|
|
|
|
|
|
-const PROGMEM usbStringDescriptor_t usbDescriptorStringManufacturer = {
|
|
|
+const PROGMEM usbStringDescriptor_t usbStringDescriptorManufacturer = {
|
|
|
.header = {
|
|
|
- .bLength = USB_STRING_LEN(sizeof(STR(MANUFACTURER)) - 1),
|
|
|
+ .bLength = USB_STRING_LEN(sizeof(STR(MANUFACTURER)) - 1),
|
|
|
.bDescriptorType = USBDESCR_STRING
|
|
|
},
|
|
|
- .bString = LSTR(MANUFACTURER)
|
|
|
+ .bString = LSTR(MANUFACTURER)
|
|
|
};
|
|
|
|
|
|
-const PROGMEM usbStringDescriptor_t usbDescriptorStringProduct = {
|
|
|
+const PROGMEM usbStringDescriptor_t usbStringDescriptorProduct = {
|
|
|
.header = {
|
|
|
- .bLength = USB_STRING_LEN(sizeof(STR(PRODUCT)) - 1),
|
|
|
+ .bLength = USB_STRING_LEN(sizeof(STR(PRODUCT)) - 1),
|
|
|
.bDescriptorType = USBDESCR_STRING
|
|
|
},
|
|
|
- .bString = LSTR(PRODUCT)
|
|
|
+ .bString = LSTR(PRODUCT)
|
|
|
};
|
|
|
|
|
|
-const PROGMEM usbStringDescriptor_t usbDescriptorStringSerial = {
|
|
|
+const PROGMEM usbStringDescriptor_t usbStringDescriptorSerial = {
|
|
|
.header = {
|
|
|
- .bLength = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1),
|
|
|
+ .bLength = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1),
|
|
|
.bDescriptorType = USBDESCR_STRING
|
|
|
},
|
|
|
- .bString = LSTR(SERIAL_NUMBER)
|
|
|
+ .bString = LSTR(SERIAL_NUMBER)
|
|
|
};
|
|
|
-
|
|
|
|
|
|
+#if USB_CFG_DESCR_PROPS_DEVICE
|
|
|
|
|
|
- * Descriptor for compite device: Keyboard + Mouse
|
|
|
- *
|
|
|
- * contains: device, interface, HID and endpoint descriptors
|
|
|
+ * Device descriptor
|
|
|
*/
|
|
|
+const PROGMEM usbDeviceDescriptor_t usbDeviceDescriptor = {
|
|
|
+ .header = {
|
|
|
+ .bLength = sizeof(usbDeviceDescriptor_t),
|
|
|
+ .bDescriptorType = USBDESCR_DEVICE
|
|
|
+ },
|
|
|
+ .bcdUSB = 0x0110,
|
|
|
+ .bDeviceClass = USB_CFG_DEVICE_CLASS,
|
|
|
+ .bDeviceSubClass = USB_CFG_DEVICE_SUBCLASS,
|
|
|
+ .bDeviceProtocol = 0x00,
|
|
|
+ .bMaxPacketSize0 = 8,
|
|
|
+ .idVendor = VENDOR_ID,
|
|
|
+ .idProduct = PRODUCT_ID,
|
|
|
+ .bcdDevice = DEVICE_VER,
|
|
|
+ .iManufacturer = 0x01,
|
|
|
+ .iProduct = 0x02,
|
|
|
+ .iSerialNumber = 0x03,
|
|
|
+ .bNumConfigurations = 1
|
|
|
+};
|
|
|
+#endif
|
|
|
+
|
|
|
#if USB_CFG_DESCR_PROPS_CONFIGURATION
|
|
|
-const PROGMEM char usbDescriptorConfiguration[] = {
|
|
|
-
|
|
|
- 9,
|
|
|
- USBDESCR_CONFIG,
|
|
|
-# if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
|
|
|
- 59,
|
|
|
-# else
|
|
|
- 34,
|
|
|
-# endif
|
|
|
- 0,
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ * Configuration descriptors
|
|
|
+ */
|
|
|
+const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
|
|
|
+ .header = {
|
|
|
+ .header = {
|
|
|
+ .bLength = sizeof(usbConfigurationDescriptorHeader_t),
|
|
|
+ .bDescriptorType = USBDESCR_CONFIG
|
|
|
+ },
|
|
|
+ .wTotalLength = sizeof(usbConfigurationDescriptor_t),
|
|
|
# if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
|
|
|
- 2,
|
|
|
+ .bNumInterfaces = 2,
|
|
|
# else
|
|
|
- 1,
|
|
|
+ .bNumInterfaces = 1,
|
|
|
# endif
|
|
|
- 1,
|
|
|
- 0,
|
|
|
+ .bConfigurationValue = 0x01,
|
|
|
+ .iConfiguration = 0x00,
|
|
|
# if USB_CFG_IS_SELF_POWERED
|
|
|
- (1 << 7) | USBATTR_SELFPOWER,
|
|
|
+ .bmAttributes = (1 << 7) | USBATTR_SELFPOWER,
|
|
|
# else
|
|
|
- (1 << 7),
|
|
|
+ .bmAttributes = (1 << 7),
|
|
|
# endif
|
|
|
- USB_MAX_POWER_CONSUMPTION / 2,
|
|
|
+ .bMaxPower = USB_MAX_POWER_CONSUMPTION / 2
|
|
|
+ },
|
|
|
|
|
|
|
|
|
- * Keyboard interface
|
|
|
+ * Keyboard
|
|
|
*/
|
|
|
-
|
|
|
- 9,
|
|
|
- USBDESCR_INTERFACE,
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- USB_CFG_HAVE_INTRIN_ENDPOINT,
|
|
|
- USB_CFG_INTERFACE_CLASS, USB_CFG_INTERFACE_SUBCLASS, USB_CFG_INTERFACE_PROTOCOL, 0,
|
|
|
-
|
|
|
- 9,
|
|
|
- USBDESCR_HID,
|
|
|
- 0x01, 0x01,
|
|
|
- 0x00,
|
|
|
- 0x01,
|
|
|
- 0x22,
|
|
|
- sizeof(keyboard_hid_report), 0,
|
|
|
-
|
|
|
-# if USB_CFG_HAVE_INTRIN_ENDPOINT
|
|
|
- 7,
|
|
|
- USBDESCR_ENDPOINT,
|
|
|
- (char)0x81,
|
|
|
- 0x03,
|
|
|
- 8, 0,
|
|
|
- USB_POLLING_INTERVAL_MS,
|
|
|
+ .keyboardInterface = {
|
|
|
+ .header = {
|
|
|
+ .bLength = sizeof(usbInterfaceDescriptor_t),
|
|
|
+ .bDescriptorType = USBDESCR_INTERFACE
|
|
|
+ },
|
|
|
+ .bInterfaceNumber = 0,
|
|
|
+ .bAlternateSetting = 0x00,
|
|
|
+ .bNumEndpoints = USB_CFG_HAVE_INTRIN_ENDPOINT,
|
|
|
+ .bInterfaceClass = USB_CFG_INTERFACE_CLASS,
|
|
|
+ .bInterfaceSubClass = USB_CFG_INTERFACE_SUBCLASS,
|
|
|
+ .bInterfaceProtocol = USB_CFG_INTERFACE_PROTOCOL,
|
|
|
+ .iInterface = 0x00
|
|
|
+ },
|
|
|
+ .keyboardHID = {
|
|
|
+ .header = {
|
|
|
+ .bLength = sizeof(usbHIDDescriptor_t),
|
|
|
+ .bDescriptorType = USBDESCR_HID
|
|
|
+ },
|
|
|
+ .bcdHID = 0x0101,
|
|
|
+ .bCountryCode = 0x00,
|
|
|
+ .bNumDescriptors = 1,
|
|
|
+ .bDescriptorType = USBDESCR_HID_REPORT,
|
|
|
+ .wDescriptorLength = sizeof(keyboard_hid_report)
|
|
|
+ },
|
|
|
+# ifdef USB_CFG_HAVE_INTRIN_ENDPOINT
|
|
|
+ .keyboardINEndpoint = {
|
|
|
+ .header = {
|
|
|
+ .bLength = sizeof(usbEndpointDescriptor_t),
|
|
|
+ .bDescriptorType = USBDESCR_ENDPOINT
|
|
|
+ },
|
|
|
+ .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | 1),
|
|
|
+ .bmAttributes = 0x03,
|
|
|
+ .wMaxPacketSize = 8,
|
|
|
+ .bInterval = USB_POLLING_INTERVAL_MS
|
|
|
+ },
|
|
|
# endif
|
|
|
|
|
|
# if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
|
|
|
|
|
|
- * Mouse/extrakeys interface
|
|
|
+ * Mouse/Extrakeys
|
|
|
*/
|
|
|
-
|
|
|
- 9,
|
|
|
- USBDESCR_INTERFACE,
|
|
|
- 1,
|
|
|
- 0,
|
|
|
- USB_CFG_HAVE_INTRIN_ENDPOINT3,
|
|
|
- 0x03,
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- 0,
|
|
|
-
|
|
|
- 9,
|
|
|
- USBDESCR_HID,
|
|
|
- 0x01, 0x01,
|
|
|
- 0x00,
|
|
|
- 0x01,
|
|
|
- 0x22,
|
|
|
- sizeof(mouse_extra_hid_report), 0,
|
|
|
-# if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
|
|
-
|
|
|
- 7,
|
|
|
- USBDESCR_ENDPOINT,
|
|
|
- (char)(0x80 | USB_CFG_EP3_NUMBER),
|
|
|
- 0x03,
|
|
|
- 8, 0,
|
|
|
- USB_POLLING_INTERVAL_MS,
|
|
|
+ .mouseExtraInterface = {
|
|
|
+ .header = {
|
|
|
+ .bLength = sizeof(usbInterfaceDescriptor_t),
|
|
|
+ .bDescriptorType = USBDESCR_INTERFACE
|
|
|
+ },
|
|
|
+ .bInterfaceNumber = 1,
|
|
|
+ .bAlternateSetting = 0x00,
|
|
|
+ .bNumEndpoints = USB_CFG_HAVE_INTRIN_ENDPOINT3,
|
|
|
+ .bInterfaceClass = 0x03,
|
|
|
+ .bInterfaceSubClass = 0x00,
|
|
|
+ .bInterfaceProtocol = 0x00,
|
|
|
+ .iInterface = 0x00
|
|
|
+ },
|
|
|
+ .mouseExtraHID = {
|
|
|
+ .header = {
|
|
|
+ .bLength = sizeof(usbHIDDescriptor_t),
|
|
|
+ .bDescriptorType = USBDESCR_HID
|
|
|
+ },
|
|
|
+ .bcdHID = 0x0101,
|
|
|
+ .bCountryCode = 0x00,
|
|
|
+ .bNumDescriptors = 1,
|
|
|
+ .bDescriptorType = USBDESCR_HID_REPORT,
|
|
|
+ .wDescriptorLength = sizeof(mouse_extra_hid_report)
|
|
|
+ },
|
|
|
+# if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
|
|
+ .mouseExtraINEndpoint = {
|
|
|
+ .header = {
|
|
|
+ .bLength = sizeof(usbEndpointDescriptor_t),
|
|
|
+ .bDescriptorType = USBDESCR_ENDPOINT
|
|
|
+ },
|
|
|
+ .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP3_NUMBER),
|
|
|
+ .bmAttributes = 0x03,
|
|
|
+ .wMaxPacketSize = 8,
|
|
|
+ .bInterval = USB_POLLING_INTERVAL_MS
|
|
|
+ }
|
|
|
# endif
|
|
|
# endif
|
|
|
};
|
|
|
#endif
|
|
|
|
|
|
+
|
|
|
+
|
|
|
USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
|
|
|
usbMsgLen_t len = 0;
|
|
|
|
|
@@ -489,42 +529,48 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
|
|
|
debug_hex16(rq->wLength.word); debug("\n");
|
|
|
*/
|
|
|
switch (rq->wValue.bytes[1]) {
|
|
|
+#if USB_CFG_DESCR_PROPS_DEVICE
|
|
|
+ case USBDESCR_DEVICE:
|
|
|
+ usbMsgPtr = (unsigned char *)&usbDeviceDescriptor;
|
|
|
+ len = sizeof(usbDeviceDescriptor_t);
|
|
|
+ break;
|
|
|
+#endif
|
|
|
#if USB_CFG_DESCR_PROPS_CONFIGURATION
|
|
|
case USBDESCR_CONFIG:
|
|
|
- usbMsgPtr = (unsigned char *)usbDescriptorConfiguration;
|
|
|
- len = sizeof(usbDescriptorConfiguration);
|
|
|
+ usbMsgPtr = (unsigned char *)&usbConfigurationDescriptor;
|
|
|
+ len = sizeof(usbConfigurationDescriptor_t);
|
|
|
break;
|
|
|
#endif
|
|
|
case USBDESCR_STRING:
|
|
|
switch (rq->wValue.bytes[0]) {
|
|
|
case 0:
|
|
|
- usbMsgPtr = (unsigned char *)&usbDescriptorStringZero;
|
|
|
- len = usbDescriptorStringZero.header.bLength;
|
|
|
+ usbMsgPtr = (unsigned char *)&usbStringDescriptorZero;
|
|
|
+ len = usbStringDescriptorZero.header.bLength;
|
|
|
break;
|
|
|
case 1:
|
|
|
- usbMsgPtr = (unsigned char *)&usbDescriptorStringManufacturer;
|
|
|
- len = usbDescriptorStringManufacturer.header.bLength;
|
|
|
+ usbMsgPtr = (unsigned char *)&usbStringDescriptorManufacturer;
|
|
|
+ len = usbStringDescriptorManufacturer.header.bLength;
|
|
|
break;
|
|
|
case 2:
|
|
|
- usbMsgPtr = (unsigned char *)&usbDescriptorStringProduct;
|
|
|
- len = usbDescriptorStringProduct.header.bLength;
|
|
|
+ usbMsgPtr = (unsigned char *)&usbStringDescriptorProduct;
|
|
|
+ len = usbStringDescriptorProduct.header.bLength;
|
|
|
break;
|
|
|
case 3:
|
|
|
- usbMsgPtr = (unsigned char *)&usbDescriptorStringSerial;
|
|
|
- len = usbDescriptorStringSerial.header.bLength;
|
|
|
+ usbMsgPtr = (unsigned char *)&usbStringDescriptorSerial;
|
|
|
+ len = usbStringDescriptorSerial.header.bLength;
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
case USBDESCR_HID:
|
|
|
switch (rq->wValue.bytes[0]) {
|
|
|
case 0:
|
|
|
- usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 9 + 9);
|
|
|
- len = 9;
|
|
|
+ usbMsgPtr = (unsigned char *)&usbConfigurationDescriptor.keyboardHID;
|
|
|
+ len = sizeof(usbHIDDescriptor_t);
|
|
|
break;
|
|
|
#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
|
|
|
case 1:
|
|
|
- usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 9 + (9 + 9 + 7) + 9);
|
|
|
- len = 9;
|
|
|
+ usbMsgPtr = (unsigned char *)&usbConfigurationDescriptor.mouseExtraHID;
|
|
|
+ len = sizeof(usbHIDDescriptor_t);
|
|
|
break;
|
|
|
#endif
|
|
|
}
|