diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2012-08-04 16:54:07 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2012-08-04 18:43:45 -0400 |
commit | ebf132af79c2acca2d88d5bfca998102279f2c57 (patch) | |
tree | f8e0151fafed1a1363f108fac2def94ca7fec055 /libmaple/usb | |
parent | 88f81ac8622507de75b9c4a6b504d472c4844bac (diff) | |
download | librambutan-ebf132af79c2acca2d88d5bfca998102279f2c57.tar.gz librambutan-ebf132af79c2acca2d88d5bfca998102279f2c57.zip |
Prep usb_descriptors.h for removal.
Just change names and things to fit the libmaple style. Its contents
will move to the top-level <libmaple/usb.h> header next.
This API is still unstable, but we need to expose pieces of it in
order to get the Maple-specific pieces of usb_cdcacm.c into Wirish.
Adjust uses of the API appropriately.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'libmaple/usb')
-rw-r--r-- | libmaple/usb/stm32f1/usb_cdcacm.c | 44 | ||||
-rw-r--r-- | libmaple/usb/stm32f1/usb_descriptors.h | 84 |
2 files changed, 65 insertions, 63 deletions
diff --git a/libmaple/usb/stm32f1/usb_cdcacm.c b/libmaple/usb/stm32f1/usb_cdcacm.c index ca63b19..ba3c268 100644 --- a/libmaple/usb/stm32f1/usb_cdcacm.c +++ b/libmaple/usb/stm32f1/usb_cdcacm.c @@ -111,8 +111,8 @@ static void usbSetDeviceAddress(void); #define USB_DEVICE_SUBCLASS_CDC 0x00 #define LEAFLABS_ID_VENDOR 0x1EAF #define MAPLE_ID_PRODUCT 0x0004 -static const USB_Descriptor_Device usbVcomDescriptor_Device = { - .bLength = sizeof(USB_Descriptor_Device), +static const usb_descriptor_device usbVcomDescriptor_Device = { + .bLength = sizeof(usb_descriptor_device), .bDescriptorType = USB_DESCRIPTOR_TYPE_DEVICE, .bcdUSB = 0x0200, .bDeviceClass = USB_DEVICE_CLASS_CDC, @@ -129,24 +129,24 @@ static const USB_Descriptor_Device usbVcomDescriptor_Device = { }; typedef struct { - USB_Descriptor_Config_Header Config_Header; - USB_Descriptor_Interface CCI_Interface; + usb_descriptor_config_header Config_Header; + usb_descriptor_interface CCI_Interface; CDC_FUNCTIONAL_DESCRIPTOR(2) CDC_Functional_IntHeader; CDC_FUNCTIONAL_DESCRIPTOR(2) CDC_Functional_CallManagement; CDC_FUNCTIONAL_DESCRIPTOR(1) CDC_Functional_ACM; CDC_FUNCTIONAL_DESCRIPTOR(2) CDC_Functional_Union; - USB_Descriptor_Endpoint ManagementEndpoint; - USB_Descriptor_Interface DCI_Interface; - USB_Descriptor_Endpoint DataOutEndpoint; - USB_Descriptor_Endpoint DataInEndpoint; -} __packed USB_Descriptor_Config; + usb_descriptor_endpoint ManagementEndpoint; + usb_descriptor_interface DCI_Interface; + usb_descriptor_endpoint DataOutEndpoint; + usb_descriptor_endpoint DataInEndpoint; +} __packed usb_descriptor_config; #define MAX_POWER (100 >> 1) -static const USB_Descriptor_Config usbVcomDescriptor_Config = { +static const usb_descriptor_config usbVcomDescriptor_Config = { .Config_Header = { - .bLength = sizeof(USB_Descriptor_Config_Header), + .bLength = sizeof(usb_descriptor_config_header), .bDescriptorType = USB_DESCRIPTOR_TYPE_CONFIGURATION, - .wTotalLength = sizeof(USB_Descriptor_Config), + .wTotalLength = sizeof(usb_descriptor_config), .bNumInterfaces = 0x02, .bConfigurationValue = 0x01, .iConfiguration = 0x00, @@ -156,7 +156,7 @@ static const USB_Descriptor_Config usbVcomDescriptor_Config = { }, .CCI_Interface = { - .bLength = sizeof(USB_Descriptor_Interface), + .bLength = sizeof(usb_descriptor_interface), .bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE, .bInterfaceNumber = 0x00, .bAlternateSetting = 0x00, @@ -196,17 +196,17 @@ static const USB_Descriptor_Config usbVcomDescriptor_Config = { }, .ManagementEndpoint = { - .bLength = sizeof(USB_Descriptor_Endpoint), + .bLength = sizeof(usb_descriptor_endpoint), .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, .bEndpointAddress = (USB_DESCRIPTOR_ENDPOINT_IN | USB_CDCACM_MANAGEMENT_ENDP), - .bmAttributes = EP_TYPE_INTERRUPT, + .bmAttributes = USB_EP_TYPE_INTERRUPT, .wMaxPacketSize = USB_CDCACM_MANAGEMENT_EPSIZE, .bInterval = 0xFF, }, .DCI_Interface = { - .bLength = sizeof(USB_Descriptor_Interface), + .bLength = sizeof(usb_descriptor_interface), .bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE, .bInterfaceNumber = 0x01, .bAlternateSetting = 0x00, @@ -218,20 +218,20 @@ static const USB_Descriptor_Config usbVcomDescriptor_Config = { }, .DataOutEndpoint = { - .bLength = sizeof(USB_Descriptor_Endpoint), + .bLength = sizeof(usb_descriptor_endpoint), .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, .bEndpointAddress = (USB_DESCRIPTOR_ENDPOINT_OUT | USB_CDCACM_RX_ENDP), - .bmAttributes = EP_TYPE_BULK, + .bmAttributes = USB_EP_TYPE_BULK, .wMaxPacketSize = USB_CDCACM_RX_EPSIZE, .bInterval = 0x00, }, .DataInEndpoint = { - .bLength = sizeof(USB_Descriptor_Endpoint), + .bLength = sizeof(usb_descriptor_endpoint), .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, .bEndpointAddress = (USB_DESCRIPTOR_ENDPOINT_IN | USB_CDCACM_TX_ENDP), - .bmAttributes = EP_TYPE_BULK, + .bmAttributes = USB_EP_TYPE_BULK, .wMaxPacketSize = USB_CDCACM_TX_EPSIZE, .bInterval = 0x00, }, @@ -277,12 +277,12 @@ static const uint8 usbVcomDescriptor_iProduct[USB_DESCRIPTOR_STRING_LEN(8)] = { static ONE_DESCRIPTOR Device_Descriptor = { (uint8*)&usbVcomDescriptor_Device, - sizeof(USB_Descriptor_Device) + sizeof(usb_descriptor_device) }; static ONE_DESCRIPTOR Config_Descriptor = { (uint8*)&usbVcomDescriptor_Config, - sizeof(USB_Descriptor_Config) + sizeof(usb_descriptor_config) }; static ONE_DESCRIPTOR String_Descriptor[3] = { diff --git a/libmaple/usb/stm32f1/usb_descriptors.h b/libmaple/usb/stm32f1/usb_descriptors.h index 0732e73..9807f36 100644 --- a/libmaple/usb/stm32f1/usb_descriptors.h +++ b/libmaple/usb/stm32f1/usb_descriptors.h @@ -24,10 +24,24 @@ * SOFTWARE. *****************************************************************************/ -#ifndef _USB_DESCRIPTORS_H_ -#define _USB_DESCRIPTORS_H_ +#ifndef _LIBMAPLE_USB_DESCRIPTORS_H_ +#define _LIBMAPLE_USB_DESCRIPTORS_H_ -#include <libmaple/libmaple.h> +/* + * USB descriptors and associated paraphernalia. + * + * IMPORTANT: this API is unstable, and may change without notice. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <libmaple/libmaple_types.h> + +/* + * Descriptor types + */ #define USB_DESCRIPTOR_TYPE_DEVICE 0x01 #define USB_DESCRIPTOR_TYPE_CONFIGURATION 0x02 @@ -35,28 +49,12 @@ #define USB_DESCRIPTOR_TYPE_INTERFACE 0x04 #define USB_DESCRIPTOR_TYPE_ENDPOINT 0x05 -#define USB_DEVICE_CLASS_CDC 0x02 -#define USB_DEVICE_SUBCLASS_CDC 0x00 -#define USB_INTERFACE_CLASS_CDC 0x02 -/* CDC Abstract Control Model */ -#define USB_INTERFACE_SUBCLASS_CDC_ACM 0x02 -#define USB_INTERFACE_CLASS_DIC 0x0A - -#define USB_CONFIG_ATTR_BUSPOWERED 0b10000000 -#define USB_CONFIG_ATTR_SELF_POWERED 0b11000000 - -#define EP_TYPE_INTERRUPT 0x03 -#define EP_TYPE_BULK 0x02 - -#define USB_DESCRIPTOR_ENDPOINT_IN 0x80 -#define USB_DESCRIPTOR_ENDPOINT_OUT 0x00 +/* + * Descriptors and declaration helpers + */ #define USB_DESCRIPTOR_STRING_LEN(x) (2 + (x << 1)) -#if defined(__cplusplus) -extern "C" { -#endif - #define USB_DESCRIPTOR_STRING(len) \ struct { \ uint8 bLength; \ @@ -64,16 +62,7 @@ extern "C" { uint16 bString[len]; \ } __packed -#define CDC_FUNCTIONAL_DESCRIPTOR_SIZE(DataSize) (3 + DataSize) -#define CDC_FUNCTIONAL_DESCRIPTOR(DataSize) \ - struct { \ - uint8 bLength; \ - uint8 bDescriptorType; \ - uint8 SubType; \ - uint8 Data[DataSize]; \ - } __packed - -typedef struct { +typedef struct usb_descriptor_device { uint8 bLength; uint8 bDescriptorType; uint16 bcdUSB; @@ -88,9 +77,9 @@ typedef struct { uint8 iProduct; uint8 iSerialNumber; uint8 bNumConfigurations; -} __packed USB_Descriptor_Device; +} __packed usb_descriptor_device; -typedef struct { +typedef struct usb_descriptor_config_header { uint8 bLength; uint8 bDescriptorType; uint16 wTotalLength; @@ -99,9 +88,9 @@ typedef struct { uint8 iConfiguration; uint8 bmAttributes; uint8 bMaxPower; -} __packed USB_Descriptor_Config_Header; +} __packed usb_descriptor_config_header; -typedef struct { +typedef struct usb_descriptor_interface { uint8 bLength; uint8 bDescriptorType; uint8 bInterfaceNumber; @@ -111,22 +100,35 @@ typedef struct { uint8 bInterfaceSubClass; uint8 bInterfaceProtocol; uint8 iInterface; -} __packed USB_Descriptor_Interface; +} __packed usb_descriptor_interface; -typedef struct { +typedef struct usb_descriptor_endpoint { uint8 bLength; uint8 bDescriptorType; uint8 bEndpointAddress; uint8 bmAttributes; uint16 wMaxPacketSize; uint8 bInterval; -} __packed USB_Descriptor_Endpoint; +} __packed usb_descriptor_endpoint; -typedef struct { +typedef struct usb_descriptor_string { uint8 bLength; uint8 bDescriptorType; uint16 bString[]; -} USB_Descriptor_String; +} usb_descriptor_string; + +/* + * Common values that go inside descriptors + */ + +#define USB_CONFIG_ATTR_BUSPOWERED 0b10000000 +#define USB_CONFIG_ATTR_SELF_POWERED 0b11000000 + +#define USB_EP_TYPE_INTERRUPT 0x03 +#define USB_EP_TYPE_BULK 0x02 + +#define USB_DESCRIPTOR_ENDPOINT_IN 0x80 +#define USB_DESCRIPTOR_ENDPOINT_OUT 0x00 #if defined(__cplusplus) } |