0xC0, /* bmAttributes (self powered). */ 50), /* bMaxPower (100mA). */ /* Interface Descriptor.*/ USB_DESC_INTERFACE (0x00, /* bInterfaceNumber. */ 0x00, /* bAlternateSetting. */ 0x01, /* bNumEndpoints. */ 0x02, /* bInterfaceClass (Communications Interface Class, CDC section 4.2). */ 0x02, /* bInterfaceSubClass (Abstract Control Model, CDC section 4.3). */ 0x01, /* bInterfaceProtocol (AT commands, CDC section 4.4). */ 0), /* iInterface. */ /* Header Functional Descriptor (CDC section 5.2.3).*/ USB_DESC_BYTE (5), /* bLength. */ USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */ USB_DESC_BYTE (0x00), /* bDescriptorSubtype (Header Functional Descriptor. */ USB_DESC_BCD (0x0110), /* bcdCDC. */ /* Call Management Functional Descriptor. */ USB_DESC_BYTE (5), /* bFunctionLength. */ USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */ USB_DESC_BYTE (0x01), /* bDescriptorSubtype (Call Management Functional Descriptor). */ USB_DESC_BYTE (0x00), /* bmCapabilities (D0+D1). */ USB_DESC_BYTE (0x01), /* bDataInterface. */ /* ACM Functional Descriptor.*/ USB_DESC_BYTE (4), /* bFunctionLength. */ USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */ USB_DESC_BYTE (0x02), /* bDescriptorSubtype (Abstract
1, /* bConfigurationValue */ 0, /* iConfiguration */ 0xC0, /* bmAttributes (self powered, set to 0x80 if not) */ 50), /* bMaxPower (100mA) */ /* Interface Descriptor (9 bytes) */ USB_DESC_INTERFACE(0, /* bInterfaceNumber */ 0, /* bAlternateSetting */ 1, /* bNumEndpoints */ 0x03, /* bInterfaceClass: HID */ 0x00, /* bInterfaceSubClass: None */ 0x00, /* bInterfaceProtocol: None */ 0), /* iInterface */ /* HID descriptor (9 bytes) */ USB_DESC_BYTE(9), /* bLength */ USB_DESC_BYTE(0x21), /* bDescriptorType (HID class) */ USB_DESC_BCD(0x0111), /* bcdHID: HID version 1.11 */ USB_DESC_BYTE(0), /* bCountryCode */ USB_DESC_BYTE(1), /* bNumDescriptors */ USB_DESC_BYTE(0x22), /* bDescriptorType (report desc) */ USB_DESC_WORD(sizeof(hid_report_descriptor_data)), /* wDescriptorLength */ /* HID debug Endpoint (IN) Descriptor (7 bytes) */ USB_DESC_ENDPOINT(DEBUG_TX_ENDPOINT | 0x80, /* bEndpointAddress */ 0x03, /* bmAttributes (Interrupt) */ DEBUG_TX_SIZE, /* wMaxPacketSize */ 1) /* bInterval */ }; /* Configuration Descriptor wrapper */
// Macro to encode a given four digit floating point version number (e.g. 01.23) into Binary Coded Decimal format for descriptor fields requiring BCD encoding, such as the USB version number in the standard device descriptor. #define VERSION_BCD(x) (((((VERSION_TENS(x) << 4) | VERSION_ONES(x)) << 8) | ((VERSION_TENTHS(x) << 4) | VERSION_HUNDREDTHS(x)))) //Macro to calculate the Unicode length of a string with a given number of Unicode characters #define USB_STRING_LEN(UnicodeChars) (2 + ((UnicodeChars) << 1)) // Helper macro for byte values into descriptor strings. #define USB_DESC_BYTE(b) ((uint8_t)(b)) // Helper macro for word values into descriptor strings. #define USB_DESC_WORD(w) \ (uint8_t)((w) & 255), \ (uint8_t)(((w) >> 8) & 255) // ============================== Descriptors ================================== // Device static const uint8_t DeviceDescriptor[] = { USB_DESC_BYTE(18), USB_DESC_BYTE(dtDevice), USB_DESC_WORD(0x0200), // USB 2.0 USB_DESC_BYTE(0x02), // bDeviceClass (CDC) USB_DESC_BYTE(0x00), // bDeviceSubClass USB_DESC_BYTE(0x00), // bDeviceProtocol USB_DESC_BYTE(0x40), // bMaxPacketSize. USB_DESC_WORD(0x0483), // idVendor (ST). USB_DESC_WORD(0x5740), // idProduct. USB_DESC_WORD(0x0200), // bcdDevice. USB_DESC_BYTE(1), // iManufacturer. USB_DESC_BYTE(2), // iProduct. USB_DESC_BYTE(0), // iSerialNumber. USB_DESC_BYTE(1) // bNumConfigurations. };
USB_MS_DATA_EP | 0x00, /* address (end point index | IN direction) */ USB_EP_MODE_TYPE_BULK, /* attributes (bulk) */ 64, /* max packet size */ 0x05 /* polling interval (ignored for bulk end-points) */ ) }; static const USBDescriptor configurationDescriptor = { sizeof(configurationDescriptorData), configurationDescriptorData }; /* Language descriptor */ static const uint8_t languageDescriptorData[] = { USB_DESC_BYTE(4), USB_DESC_BYTE(USB_DESCRIPTOR_STRING), USB_DESC_WORD(0x0409) /* U.S. english */ }; static const USBDescriptor languageDescriptor = { sizeof(languageDescriptorData), languageDescriptorData }; /* Vendor descriptor */ static const uint8_t vendorDescriptorData[] = { USB_DESC_BYTE(20), USB_DESC_BYTE(USB_DESCRIPTOR_STRING), 'P', 0, 'a', 0, 'p', 0, 'a', 0, 'r', 0, 'a', 0, 'z', 0, 'z', 0, 'i', 0
USB_MS_DATA_EP | 0x80, /* address (end point index | OUT direction) */ USB_EP_MODE_TYPE_BULK, /* attributes (bulk) */ 64, /* max packet size */ 0x05 /* polling interval (ignored for bulk end-points) */ ) }; static const USBDescriptor configurationDescriptor = { sizeof(configurationDescriptorData), configurationDescriptorData }; /* Language descriptor */ static const uint8_t languageDescriptorData[] = { USB_DESC_BYTE(4), USB_DESC_BYTE(USB_DESCRIPTOR_STRING), USB_DESC_WORD(0x0409) /* U.S. english */ }; static const USBDescriptor languageDescriptor = { sizeof(languageDescriptorData), languageDescriptorData }; /* Vendor descriptor */ static const uint8_t vendorDescriptorData[] = { USB_DESC_BYTE(16), USB_DESC_BYTE(USB_DESCRIPTOR_STRING), 'A', 0, 'x', 0, 'o', 0, 'l', 0, 'o', 0, 't', 0, 'i', 0
&hid_configuration_descriptor_data[HID_DESCRIPTOR_OFFSET] }; /* * HID Report Descriptor * * This is the description of the format and the content of the * different IN or/and OUT reports that your application can * receive/send * * See "Device Class Definition for Human Interface Devices (HID)" * (http://www.usb.org/developers/hidpage/HID1_11.pdf) for the * detailed description of all the fields */ static const uint8_t hid_report_descriptor_data[] = { USB_DESC_BYTE (0x06), /* Usage Page - */ USB_DESC_WORD (0xFF00), /* Vendor Defined. */ USB_DESC_BYTE (0x09), /* Usage - */ USB_DESC_BYTE (0x01), /* Vendor Defined. */ USB_DESC_BYTE (0xA1), /* Collection - */ USB_DESC_BYTE (0x01), /* Application. */ USB_DESC_BYTE (0x09), /* Usage - */ USB_DESC_BYTE (0x01), /* Vendor Defined. */ USB_DESC_BYTE (0x15), /* Logical Minimum - */ USB_DESC_BYTE (0x00), /* 0. */ USB_DESC_BYTE (0x26), /* Logical Maximum - */ USB_DESC_WORD (0x00FF), /* 255. */ USB_DESC_BYTE (0x75), /* Report size - */ USB_DESC_BYTE (0x08), /* 8 bits. */ USB_DESC_BYTE (0x95), /* Report count - */