From f1713a25598e82e9d00a8e4c40044f590cc2c958 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Wed, 22 Aug 2012 20:15:11 +0200 Subject: Add descriptor classes. --- usb/descriptor.h | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 usb/descriptor.h diff --git a/usb/descriptor.h b/usb/descriptor.h new file mode 100644 index 0000000..f806984 --- /dev/null +++ b/usb/descriptor.h @@ -0,0 +1,138 @@ +#ifndef DESCRIPTOR_H +#define DESCRIPTOR_H + +#include + +struct Device_desc { + enum { + SIZE = 18, + }; + + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; +}; + + +struct Configuration_desc { + enum { + SIZE = 9, + }; + + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t wTotalLength; + uint8_t bNumInterfaces; + uint8_t bConfigurationvalue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t bMaxPower; +} __attribute__((packed)); + +struct Interface_desc { + enum { + SIZE = 9, + }; + + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; +} __attribute__((packed)); + +struct Endpoint_desc { + enum { + SIZE = 7, + }; + + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint16_t wMaxPacketSize; + uint8_t bInterval; +} __attribute__((packed)); + +struct CDC_Header_desc { + enum { + SIZE = 5, + }; + + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bDescriptorSubType; + uint16_t bcdCDC; +} __attribute__((packed)); + +struct CDC_Call_Management_desc { + enum { + SIZE = 5, + }; + + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bDescriptorSubType; + uint8_t bmCapabilities; + uint8_t bDataInterface; +} __attribute__((packed)); + +struct CDC_ACM_desc { + enum { + SIZE = 4, + }; + + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bDescriptorSubType; + uint8_t bmCapabilities; +} __attribute__((packed)); + +struct CDC_Union_desc { + enum { + SIZE = 5, + }; + + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bDescriptorSubType; + uint8_t bControlInterface; + uint8_t bSubordinateInterface0; +} __attribute__((packed)); + +template +struct X { + enum { + SIZE = A::SIZE + B::SIZE, + }; + + A a; + B b; +} __attribute__((packed)); + +template +constexpr A pack(A a) { + return a; +} + +template +constexpr auto pack(A a, R... r) -> X { + return {a, pack(r...)}; +} + +#endif -- cgit v1.2.3