From b4541209cb447bb89feb62018e2043285a5633d0 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 12 Oct 2015 14:41:05 +0200 Subject: [PATCH 1/3] adapt SAM core to PluggableUSB stable API --- .../sam/cores/arduino/USB/PluggableUSB.cpp | 95 ++++++++++--------- .../sam/cores/arduino/USB/PluggableUSB.h | 55 +++++++---- .../arduino/sam/cores/arduino/USB/USBCore.cpp | 8 +- .../arduino/sam/cores/arduino/USB/USBCore.h | 7 +- 4 files changed, 97 insertions(+), 68 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp index 84d781d812a..0f2d08c0d8d 100644 --- a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp @@ -19,80 +19,89 @@ #include "USBAPI.h" #include "USBDesc.h" +#include "USBCore.h" #include "PluggableUSB.h" +#if defined(USBCON) #ifdef PLUGGABLE_USB_ENABLED -#define MAX_MODULES 6 - -static uint8_t lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; -static uint8_t lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; - extern uint32_t EndPoints[]; -//PUSBCallbacks cbs[MAX_MODULES]; -static uint8_t modules_count = 0; - -static PUSBListNode* rootNode = NULL; - -int PUSB_GetInterface(uint8_t* interfaceNum) +int PluggableUSB_::getInterface(uint8_t* interfaceCount) { - int ret = 0; - PUSBListNode* node = rootNode; - for (uint8_t i=0; icb->getInterface(interfaceNum); - node = node->next; + int sent = 0; + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + int res = node->getInterface(interfaceCount); + if (res < 0) + return -1; + sent += res; } - return ret; + return sent; } -int PUSB_GetDescriptor(int8_t t) +int PluggableUSB_::getDescriptor(USBSetup& setup) { - int ret = 0; - PUSBListNode* node = rootNode; - for (uint8_t i=0; icb->getDescriptor(t); - node = node->next; + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + int ret = node->getDescriptor(setup); + // ret!=0 -> request has been processed + if (ret) + return ret; } - return ret; + return 0; } -bool PUSB_Setup(USBSetup& setup, uint8_t j) +bool PluggableUSB_::setup(USBSetup& setup) { - bool ret = false; - PUSBListNode* node = rootNode; - for (uint8_t i=0; icb->setup(setup, j); - node = node->next; + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + if (node->setup(setup)) { + return true; + } } - return ret; + return false; } -int8_t PUSB_AddFunction(PUSBListNode *node, uint8_t* interface) +bool PluggableUSB_::plug(PluggableUSBModule *node) { - if (modules_count >= MAX_MODULES) { - return 0; + if ((lastEp + node->numEndpoints) > USB_ENDPOINTS) { + return false; } - if (modules_count == 0) { + if (!rootNode) { rootNode = node; } else { - PUSBListNode *current = rootNode; - while(current->next != NULL) { + PluggableUSBModule *current = rootNode; + while (current->next) { current = current->next; } current->next = node; } - *interface = lastIf; - lastIf += node->cb->numInterfaces; - for ( uint8_t i = 0; i< node->cb->numEndpoints; i++) { - EndPoints[lastEp] = node->cb->endpointType[i]; + node->pluggedInterface = lastIf; + node->pluggedEndpoint = lastEp; + lastIf += node->numInterfaces; + for (uint8_t i = 0; i < node->numEndpoints; i++) { + EndPoints[lastEp] = node->endpointType[i]; lastEp++; } - modules_count++; - return lastEp - node->cb->numEndpoints; + return true; // restart USB layer??? } +PluggableUSB_& PluggableUSB() +{ + static PluggableUSB_ obj; + return obj; +} + +PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT), + lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT), + rootNode(NULL) +{ + // Empty +} + +#endif #endif \ No newline at end of file diff --git a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h index c53aae66f6e..eb18ca2537a 100644 --- a/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h +++ b/hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h @@ -25,30 +25,47 @@ #if defined(USBCON) -typedef struct __attribute__((packed)) -{ - bool (*setup)(USBSetup& setup, uint8_t i); - int (*getInterface)(uint8_t* interfaceNum); - int (*getDescriptor)(int8_t t); - int8_t numEndpoints; - int8_t numInterfaces; - uint32_t *endpointType; -} PUSBCallbacks; - -class PUSBListNode { +class PluggableUSBModule { public: - PUSBListNode *next = NULL; - PUSBCallbacks *cb; - PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;} -}; + PluggableUSBModule(uint8_t numEps, uint8_t numIfs, uint32_t *epType) : + numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) + { } + +protected: + virtual bool setup(USBSetup& setup) = 0; + virtual int getInterface(uint8_t* interfaceCount) = 0; + virtual int getDescriptor(USBSetup& setup) = 0; + + uint8_t pluggedInterface; + uint8_t pluggedEndpoint; + + const uint8_t numEndpoints; + const uint8_t numInterfaces; + const uint32_t *endpointType; -int8_t PUSB_AddFunction(PUSBListNode *node, uint8_t *interface); + PluggableUSBModule *next = NULL; -int PUSB_GetInterface(uint8_t* interfaceNum); + friend class PluggableUSB_; +}; + +class PluggableUSB_ { +public: + PluggableUSB_(); + bool plug(PluggableUSBModule *node); + int getInterface(uint8_t* interfaceCount); + int getDescriptor(USBSetup& setup); + bool setup(USBSetup& setup); -int PUSB_GetDescriptor(int8_t t); +private: + uint8_t lastIf; + uint8_t lastEp; + PluggableUSBModule* rootNode; +}; -bool PUSB_Setup(USBSetup& setup, uint8_t i); +// Replacement for global singleton. +// This function prevents static-initialization-order-fiasco +// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use +PluggableUSB_& PluggableUSB(); #endif diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index 3fc6e43d618..421b48f7e7b 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -296,7 +296,7 @@ bool USBD_ClassInterfaceRequest(USBSetup& setup) #endif #ifdef PLUGGABLE_USB_ENABLED - return PUSB_Setup(setup, i); + return PluggableUSB().setup(setup); #endif return false; @@ -311,7 +311,7 @@ int USBD_SendInterfaces(void) #endif #ifdef PLUGGABLE_USB_ENABLED - PUSB_GetInterface(&interfaces); + PluggableUSB().getInterface(&interfaces); #endif TRACE_CORE(printf("=> USBD_SendInterfaces, interfaces=%d\r\n", interfaces);) @@ -327,7 +327,7 @@ int USBD_SendOtherInterfaces(void) #endif #ifdef PLUGGABLE_USB_ENABLED - PUSB_GetInterface(&interfaces); + PluggableUSB().getInterface(&interfaces); #endif TRACE_CORE(printf("=> USBD_SendInterfaces, interfaces=%d\r\n", interfaces);) @@ -399,7 +399,7 @@ static bool USBD_SendDescriptor(USBSetup& setup) USBD_InitControl(setup.wLength); #ifdef PLUGGABLE_USB_ENABLED - ret = PUSB_GetDescriptor(t); + ret = PluggableUSB().getDescriptor(setup); if (ret != 0) { return (ret > 0 ? true : false); } diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.h b/hardware/arduino/sam/cores/arduino/USB/USBCore.h index c522d448207..10df90ba7aa 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.h @@ -46,8 +46,9 @@ #define REQUEST_OTHER 0x03 #define REQUEST_RECIPIENT 0x1F -#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE) -#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE) +#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_CLASS | REQUEST_INTERFACE) +#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE | REQUEST_CLASS | REQUEST_INTERFACE) +#define REQUEST_DEVICETOHOST_STANDARD_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_STANDARD | REQUEST_INTERFACE) // Class requests @@ -91,6 +92,8 @@ #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) #define USB_ENDPOINT_IN(addr) ((addr) | 0x80) +#define USB_ENDPOINTS 7 + #define USB_ENDPOINT_TYPE_MASK 0x03 #define USB_ENDPOINT_TYPE_CONTROL 0x00 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 From ddae105dc316ca5e463404c28cf0c96949e6861d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 12 Oct 2015 14:41:23 +0200 Subject: [PATCH 2/3] [HID] port to stable PluggableUSB API --- hardware/arduino/sam/libraries/HID/HID.cpp | 196 +++++++++------------ hardware/arduino/sam/libraries/HID/HID.h | 125 ++++++++----- 2 files changed, 164 insertions(+), 157 deletions(-) diff --git a/hardware/arduino/sam/libraries/HID/HID.cpp b/hardware/arduino/sam/libraries/HID/HID.cpp index b2a79423e35..8d3a5a52e8c 100644 --- a/hardware/arduino/sam/libraries/HID/HID.cpp +++ b/hardware/arduino/sam/libraries/HID/HID.cpp @@ -13,156 +13,134 @@ ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -** SOFTWARE. +** SOFTWARE. */ -#include "USB/PluggableUSB.h" #include "HID.h" -HID_ HID; +#if defined(USBCON) -static uint8_t HID_ENDPOINT_INT; - -//================================================================================ -//================================================================================ - -// HID report descriptor - -#define LSB(_x) ((_x) & 0xFF) -#define MSB(_x) ((_x) >> 8) - -#define RAWHID_USAGE_PAGE 0xFFC0 -#define RAWHID_USAGE 0x0C00 -#define RAWHID_TX_SIZE 64 -#define RAWHID_RX_SIZE 64 - -static uint8_t HID_INTERFACE; - -HIDDescriptor _hidInterface; - -static HIDDescriptorListNode* rootNode = NULL; -static uint8_t sizeof_hidReportDescriptor = 0; -static uint8_t modules_count = 0; -//================================================================================ -//================================================================================ -// Driver - -uint8_t _hid_protocol = 1; -uint8_t _hid_idle = 1; +HID_& HID() +{ + static HID_ obj; + return obj; +} -int HID_GetInterface(uint8_t* interfaceNum) +int HID_::getInterface(uint8_t* interfaceCount) { - interfaceNum[0] += 1; // uses 1 - _hidInterface = - { - D_INTERFACE(HID_INTERFACE,1,3,0,0), - D_HIDREPORT(sizeof_hidReportDescriptor), - D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) + *interfaceCount += 1; // uses 1 + HIDDescriptor hidInterface = { + D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), + D_HIDREPORT(descriptorSize), + D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, 0x40, 0x01) }; - return USBD_SendControl(0,&_hidInterface,sizeof(_hidInterface)); + return USBD_SendControl(0, &hidInterface, sizeof(hidInterface)); } -int HID_GetDescriptor(int8_t t) +int HID_::getDescriptor(USBSetup& setup) { - if (HID_REPORT_DESCRIPTOR_TYPE == t) { - HIDDescriptorListNode* current = rootNode; - int total = 0; - while(current != NULL) { - total += USBD_SendControl(0,current->data,current->length); - current = current->next; - } - return total; - } else { - return 0; + // Check if this is a HID Class Descriptor request + if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; } + if (setup.wValueH != HID_REPORT_DESCRIPTOR_TYPE) { return 0; } + + // In a HID Class Descriptor wIndex cointains the interface number + if (setup.wIndex != pluggedInterface) { return 0; } + + int total = 0; + HIDSubDescriptor* node; + for (node = rootNode; node; node = node->next) { + int res = USBD_SendControl(0, node->data, node->length); + if (res == -1) + return -1; + total += res; } + return total; } -void HID_::AppendDescriptor(HIDDescriptorListNode *node) +void HID_::AppendDescriptor(HIDSubDescriptor *node) { - if (modules_count == 0) { + if (!rootNode) { rootNode = node; } else { - HIDDescriptorListNode *current = rootNode; - while(current->next != NULL) { + HIDSubDescriptor *current = rootNode; + while (current->next) { current = current->next; } current->next = node; } - modules_count++; - sizeof_hidReportDescriptor += node->length; + descriptorSize += node->length; } void HID_::SendReport(uint8_t id, const void* data, int len) { uint8_t p[64]; - const uint8_t *d = reinterpret_cast(data); - p[0] = id; - for (uint32_t i=0; i #include +#include "USB/PluggableUSB.h" -#define _USING_HID +#if defined(USBCON) -//================================================================================ -//================================================================================ -// HID 'Driver' +#define _USING_HID +// HID 'Driver' +// ------------ #define HID_GET_REPORT 0x01 #define HID_GET_IDLE 0x02 #define HID_GET_PROTOCOL 0x03 @@ -42,49 +40,80 @@ #define HID_REPORT_DESCRIPTOR_TYPE 0x22 #define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 -class HIDDescriptorListNode { +// HID subclass HID1.11 Page 8 4.2 Subclass +#define HID_SUBCLASS_NONE 0 +#define HID_SUBCLASS_BOOT_INTERFACE 1 + +// HID Keyboard/Mouse bios compatible protocols HID1.11 Page 9 4.3 Protocols +#define HID_PROTOCOL_NONE 0 +#define HID_PROTOCOL_KEYBOARD 1 +#define HID_PROTOCOL_MOUSE 2 + +// Normal or bios protocol (Keyboard/Mouse) HID1.11 Page 54 7.2.5 Get_Protocol Request +// "protocol" variable is used for this purpose. +#define HID_BOOT_PROTOCOL 0 +#define HID_REPORT_PROTOCOL 1 + +typedef struct +{ + uint8_t len; // 9 + uint8_t dtype; // 0x21 + uint8_t addr; + uint8_t versionL; // 0x101 + uint8_t versionH; // 0x101 + uint8_t country; + uint8_t desctype; // 0x22 report + uint8_t descLenL; + uint8_t descLenH; +} HIDDescDescriptor; + +typedef struct +{ + InterfaceDescriptor hid; + HIDDescDescriptor desc; + EndpointDescriptor in; +} HIDDescriptor; + +class HIDSubDescriptor { public: - HIDDescriptorListNode *next = NULL; - HIDDescriptorListNode(const void *d, const uint16_t l) : data(d), length(l) { } + HIDSubDescriptor *next = NULL; + HIDSubDescriptor(const void *d, const uint16_t l) : data(d), length(l) { } const void* data; const uint16_t length; }; -class HID_ +class HID_ : public PluggableUSBModule { public: HID_(void); int begin(void); void SendReport(uint8_t id, const void* data, int len); - void AppendDescriptor(HIDDescriptorListNode* node); -}; + void AppendDescriptor(HIDSubDescriptor* node); -typedef struct -{ - uint8_t len; // 9 - uint8_t dtype; // 0x21 - uint8_t addr; - uint8_t versionL; // 0x101 - uint8_t versionH; // 0x101 - uint8_t country; - uint8_t desctype; // 0x22 report - uint8_t descLenL; - uint8_t descLenH; -} HIDDescDescriptor; +protected: + // Implementation of the PluggableUSBModule + int getInterface(uint8_t* interfaceCount); + int getDescriptor(USBSetup& setup); + bool setup(USBSetup& setup); -typedef struct -{ - InterfaceDescriptor hid; - HIDDescDescriptor desc; - EndpointDescriptor in; -} HIDDescriptor; +private: + uint32_t epType[1]; + + HIDSubDescriptor* rootNode; + uint16_t descriptorSize; + + uint8_t protocol; + uint8_t idle; +}; -#define HID_TX HID_ENDPOINT_INT +// Replacement for global singleton. +// This function prevents static-initialization-order-fiasco +// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use +HID_& HID(); -#define D_HIDREPORT(_descriptorLength) \ - { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 } +#define D_HIDREPORT(length) { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) } -#define WEAK __attribute__ ((weak)) +#endif // USBCON -#endif +#endif // HID_h From bf609ecc4cf1478b5b81cd2a2a6b2185673babcd Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 12 Oct 2015 14:42:13 +0200 Subject: [PATCH 3/3] [USB] remove all warnings from SAM USB core --- .../arduino/sam/cores/arduino/USB/USBAPI.h | 2 +- .../arduino/sam/cores/arduino/USB/USBCore.cpp | 18 +++++++++--------- .../arduino/sam/cores/arduino/USB/USBCore.h | 18 +++++++++++++++--- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/USB/USBAPI.h b/hardware/arduino/sam/cores/arduino/USB/USBAPI.h index 97e8ad6fec5..ee9739cb58d 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBAPI.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBAPI.h @@ -131,7 +131,7 @@ bool CDC_Setup(USBSetup& setup); void USBD_InitControl(int end); int USBD_SendControl(uint8_t flags, const void* d, uint32_t len); int USBD_RecvControl(void* d, uint32_t len); -int USBD_SendInterfaces(void); +uint8_t USBD_SendInterfaces(void); bool USBD_ClassInterfaceRequest(USBSetup& setup); diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index 421b48f7e7b..6631ec006e5 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -101,7 +101,7 @@ const DeviceDescriptor USB_DeviceDescriptor = const DeviceDescriptor USB_DeviceDescriptorA = D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); -const DeviceDescriptor USB_DeviceQualifier = +const QualifierDescriptor USB_DeviceQualifier = D_QUALIFIER(0x00,0x00,0x00,64,1); //! 7.1.20 Test Mode Support @@ -130,7 +130,7 @@ class LockEP { irqflags_t flags; public: - LockEP(uint32_t ep) : flags(cpu_irq_save()) + LockEP(uint32_t ep __attribute__ ((unused))) : flags(cpu_irq_save()) { } ~LockEP() @@ -219,8 +219,8 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len) return r; } -int _cmark; -int _cend; +uint16_t _cmark; +uint16_t _cend; void USBD_InitControl(int end) { @@ -229,7 +229,7 @@ void USBD_InitControl(int end) } // Clipped by _cmark/_cend -int USBD_SendControl(uint8_t flags, const void* d, uint32_t len) +int USBD_SendControl(uint8_t flags __attribute__ ((unused)), const void* d, uint32_t len) { const uint8_t* data = (const uint8_t*)d; uint32_t length = len; @@ -302,7 +302,7 @@ bool USBD_ClassInterfaceRequest(USBSetup& setup) return false; } -int USBD_SendInterfaces(void) +uint8_t USBD_SendInterfaces(void) { uint8_t interfaces = 0; @@ -318,7 +318,7 @@ int USBD_SendInterfaces(void) return interfaces; } -int USBD_SendOtherInterfaces(void) +uint8_t USBD_SendOtherInterfaces(void) { uint8_t interfaces = 0; @@ -342,7 +342,7 @@ static bool USBD_SendConfiguration(int maxlen) // Count and measure interfaces USBD_InitControl(0); //TRACE_CORE(printf("=> USBD_SendConfiguration _cmark1=%d\r\n", _cmark);) - int interfaces = USBD_SendInterfaces(); + uint8_t interfaces = USBD_SendInterfaces(); //TRACE_CORE(printf("=> USBD_SendConfiguration _cmark2=%d\r\n", _cmark);) //TRACE_CORE(printf("=> USBD_SendConfiguration sizeof=%d\r\n", sizeof(ConfigDescriptor));) @@ -365,7 +365,7 @@ static bool USBD_SendOtherConfiguration(int maxlen) // Count and measure interfaces USBD_InitControl(0); //TRACE_CORE(printf("=> USBD_SendConfiguration _cmark1=%d\r\n", _cmark);) - int interfaces = USBD_SendOtherInterfaces(); + uint8_t interfaces = USBD_SendOtherInterfaces(); //TRACE_CORE(printf("=> USBD_SendConfiguration _cmark2=%d\r\n", _cmark);) //TRACE_CORE(printf("=> USBD_SendConfiguration sizeof=%d\r\n", sizeof(ConfigDescriptor));) diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.h b/hardware/arduino/sam/cores/arduino/USB/USBCore.h index 10df90ba7aa..893d84fcbbe 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.h @@ -149,6 +149,18 @@ typedef struct { uint8_t maxPower; } ConfigDescriptor; +// Device Qualifier (only needed for USB2.0 devices) +typedef struct { + uint8_t bLength; + uint8_t dtype; + uint16_t bDescriptorType; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint8_t bNumConfigurations; +} QualifierDescriptor; + // String // Interface @@ -257,16 +269,16 @@ _Pragma("pack()") { 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs } #define D_CONFIG(_totalLength,_interfaces) \ - { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_SELF_POWERED, USB_CONFIG_POWER_MA(500) } + { 9, 2, (uint16_t)(_totalLength),_interfaces, 1, 0, USB_CONFIG_SELF_POWERED, USB_CONFIG_POWER_MA(500) } #define D_OTHERCONFIG(_totalLength,_interfaces) \ - { 9, 7, _totalLength,_interfaces, 1, 0, USB_CONFIG_SELF_POWERED, USB_CONFIG_POWER_MA(500) } + { 9, 7, (uint16_t)(_totalLength),_interfaces, 1, 0, USB_CONFIG_SELF_POWERED, USB_CONFIG_POWER_MA(500) } #define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \ { 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 } #define D_ENDPOINT(_addr,_attr,_packetSize, _interval) \ - { 7, 5, _addr,_attr,_packetSize, _interval } + { 7, 5, (uint8_t)(_addr),_attr,_packetSize, _interval } #define D_QUALIFIER(_class,_subClass,_proto,_packetSize0,_configs) \ { 10, 6, 0x200, _class,_subClass,_proto,_packetSize0,_configs }