diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2010-09-28 13:27:19 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2010-09-28 13:27:19 +0000 |
commit | b2a30cd48a0621b360d23dd430c646d22e943d09 (patch) | |
tree | 99cea070a86b80281a4f4c0d45b3fb3c776528b0 /Bootloaders/CDC | |
parent | 713670043a1edb714461fc83c2b8817f3db99961 (diff) | |
download | lufa-b2a30cd48a0621b360d23dd430c646d22e943d09.tar.gz lufa-b2a30cd48a0621b360d23dd430c646d22e943d09.tar.bz2 lufa-b2a30cd48a0621b360d23dd430c646d22e943d09.zip |
Added CDC functional descriptor structs to the Low Level CDC demos and CDC class bootloader, to improve the readability of the descriptors.
Fixed BootloaderCDC project failing on some operating systems due to removed Line Encoding options (thanks to Alexey Belyaev).
Diffstat (limited to 'Bootloaders/CDC')
-rw-r--r-- | Bootloaders/CDC/BootloaderCDC.c | 42 | ||||
-rw-r--r-- | Bootloaders/CDC/BootloaderCDC.h | 42 | ||||
-rw-r--r-- | Bootloaders/CDC/Descriptors.c | 27 | ||||
-rw-r--r-- | Bootloaders/CDC/Descriptors.h | 54 |
4 files changed, 134 insertions, 31 deletions
diff --git a/Bootloaders/CDC/BootloaderCDC.c b/Bootloaders/CDC/BootloaderCDC.c index cfc040f8b..234b5ce88 100644 --- a/Bootloaders/CDC/BootloaderCDC.c +++ b/Bootloaders/CDC/BootloaderCDC.c @@ -36,6 +36,14 @@ #define INCLUDE_FROM_BOOTLOADERCDC_C #include "BootloaderCDC.h" +/** Contains the current baud rate and other settings of the first virtual serial port. This must be retained as some + * operating systems will not open the port unless the settings can be set successfully. + */ +CDC_Line_Coding_t LineEncoding = { .BaudRateBPS = 0, + .CharFormat = OneStopBit, + .ParityType = Parity_None, + .DataBits = 8 }; + /** Current address counter. This stores the current address of the FLASH or EEPROM as set by the host, * and is used when reading or writing to the AVRs memory (either FLASH or EEPROM depending on the issued * command.) @@ -113,6 +121,40 @@ void EVENT_USB_Device_ConfigurationChanged(void) ENDPOINT_BANK_SINGLE); } +/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific + * control requests that are not handled internally by the USB library (including the CDC control commands, + * which are all issued via the control endpoint), so that they can be handled appropriately for the application. + */ +void EVENT_USB_Device_UnhandledControlRequest(void) +{ + /* Process CDC specific control requests */ + switch (USB_ControlRequest.bRequest) + { + case REQ_GetLineEncoding: + if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) + { + Endpoint_ClearSETUP(); + + /* Write the line coding data to the control endpoint */ + Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t)); + Endpoint_ClearOUT(); + } + + break; + case REQ_SetLineEncoding: + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + { + Endpoint_ClearSETUP(); + + /* Read the line coding data in from the host into the global struct */ + Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t)); + Endpoint_ClearIN(); + } + + break; + } +} + /** Reads or writes a block of EEPROM or FLASH memory to or from the appropriate CDC data endpoint, depending * on the AVR910 protocol command issued. * diff --git a/Bootloaders/CDC/BootloaderCDC.h b/Bootloaders/CDC/BootloaderCDC.h index 7aa07a294..98154c2b9 100644 --- a/Bootloaders/CDC/BootloaderCDC.h +++ b/Bootloaders/CDC/BootloaderCDC.h @@ -49,7 +49,7 @@ #include <LUFA/Drivers/USB/USB.h> - /* Macros: */ + /* Macros: */ /** Version major of the CDC bootloader. */ #define BOOTLOADER_VERSION_MAJOR 0x01 @@ -65,10 +65,50 @@ /** Eight character bootloader firmware identifier reported to the host when requested */ #define SOFTWARE_IDENTIFIER "LUFACDC" + /** CDC Class specific request to get the current virtual serial port configuration settings. */ + #define REQ_GetLineEncoding 0x21 + + /** CDC Class specific request to set the current virtual serial port configuration settings. */ + #define REQ_SetLineEncoding 0x20 + /* Type Defines: */ + /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration + * as set by the host via a class specific request. + */ + typedef struct + { + uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second */ + uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the + * CDCDevice_CDC_LineCodingFormats_t enum + */ + uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the + * CDCDevice_LineCodingParity_t enum + */ + uint8_t DataBits; /**< Bits of data per character of the virtual serial port */ + } CDC_Line_Coding_t; + /** Type define for a non-returning pointer to the start of the loaded application in flash memory. */ typedef void (*AppPtr_t)(void) ATTR_NO_RETURN; + /* Enums: */ + /** Enum for the possible line encoding formats of a virtual serial port. */ + enum CDCDevice_CDC_LineCodingFormats_t + { + OneStopBit = 0, /**< Each frame contains one stop bit */ + OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits */ + TwoStopBits = 2, /**< Each frame contains two stop bits */ + }; + + /** Enum for the possible line encoding parity settings of a virtual serial port. */ + enum CDCDevice_LineCodingParity_t + { + Parity_None = 0, /**< No parity bit mode on each frame */ + Parity_Odd = 1, /**< Odd parity bit mode on each frame */ + Parity_Even = 2, /**< Even parity bit mode on each frame */ + Parity_Mark = 3, /**< Mark parity bit mode on each frame */ + Parity_Space = 4, /**< Space parity bit mode on each frame */ + }; + /* Function Prototypes: */ void CDC_Task(void); void SetupHardware(void); diff --git a/Bootloaders/CDC/Descriptors.c b/Bootloaders/CDC/Descriptors.c index 092ee2f8d..b86b2130e 100644 --- a/Bootloaders/CDC/Descriptors.c +++ b/Bootloaders/CDC/Descriptors.c @@ -55,7 +55,7 @@ USB_Descriptor_Device_t DeviceDescriptor = .VendorID = 0x03EB, .ProductID = 0x204A, - .ReleaseNumber = 0x0000, + .ReleaseNumber = 0x0002, .ManufacturerStrIndex = NO_DESCRIPTOR, .ProductStrIndex = 0x01, @@ -102,29 +102,30 @@ USB_Descriptor_Configuration_t ConfigurationDescriptor = .InterfaceStrIndex = NO_DESCRIPTOR }, - .CDC_Functional_IntHeader = + .CDC_Functional_Header = { - .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24}, - .SubType = 0x00, + .Header = {.Size = sizeof(USB_Descriptor_CDC_FunctionalHeader_t), .Type = DTYPE_CSInterface}, + .Subtype = 0x00, - .Data = {0x10, 0x01} + .CDCSpecification = VERSION_BCD(01.10), }, - .CDC_Functional_AbstractControlManagement = + .CDC_Functional_ACM = { - .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(1)), .Type = 0x24}, - .SubType = 0x02, + .Header = {.Size = sizeof(USB_Descriptor_CDC_FunctionalACM_t), .Type = DTYPE_CSInterface}, + .Subtype = 0x02, - .Data = {0x06} + .Capabilities = 0x04, }, .CDC_Functional_Union = { - .Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24}, - .SubType = 0x06, + .Header = {.Size = sizeof(USB_Descriptor_CDC_FunctionalUnion_t), .Type = DTYPE_CSInterface}, + .Subtype = 0x06, - .Data = {0x00, 0x01} - }, + .MasterInterfaceNumber = 0, + .SlaveInterfaceNumber = 1, + }, .CDC_NotificationEndpoint = { diff --git a/Bootloaders/CDC/Descriptors.h b/Bootloaders/CDC/Descriptors.h index 307b323a4..461088835 100644 --- a/Bootloaders/CDC/Descriptors.h +++ b/Bootloaders/CDC/Descriptors.h @@ -92,20 +92,6 @@ #error The selected AVR part is not currently supported by this bootloader. #endif - /** Structure for a CDC class Functional descriptor, with a given data size. This is used instead of a - * type define so that the same macro can be used for functional descriptors of varying data lengths, - * while allowing the sizeof() operator to return correct results. - * - * \param[in] DataSize Size of the functional descriptor's data payload, in bytes - */ - #define CDC_FUNCTIONAL_DESCRIPTOR(DataSize) \ - struct \ - { \ - USB_Descriptor_Header_t Header; \ - uint8_t SubType; \ - uint8_t Data[DataSize]; \ - } - /** Endpoint number for the CDC control interface event notification endpoint. */ #define CDC_NOTIFICATION_EPNUM 3 @@ -122,6 +108,40 @@ #define CDC_TXRX_EPSIZE 16 /* Type Defines: */ + /** Type define for a CDC class-specific functional header descriptor. This indicates to the host that the device + * contains one or more CDC functional data descriptors, which give the CDC interface's capabilities and configuration. + * See the CDC class specification for more details. + */ + typedef struct + { + USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */ + uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors. */ + uint16_t CDCSpecification; /**< Version number of the CDC specification implemented by the device, + * encoded in BCD format. + */ + } USB_Descriptor_CDC_FunctionalHeader_t; + + /** Type define for a CDC class-specific functional ACM descriptor. This indicates to the host that the CDC interface + * supports the CDC ACM subclass of the CDC specification. See the CDC class specification for more details. + */ + typedef struct + { + USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */ + uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors. */ + uint8_t Capabilities; /**< Capabilities of the ACM interface, given as a bit mask. */ + } USB_Descriptor_CDC_FunctionalACM_t; + + /** Type define for a CDC class-specific functional Union descriptor. This indicates to the host that specific + * CDC control and data interfaces are related. See the CDC class specification for more details. + */ + typedef struct + { + USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */ + uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors. */ + uint8_t MasterInterfaceNumber; /**< Interface number of the CDC Control interface. */ + uint8_t SlaveInterfaceNumber; /**< Interface number of the CDC Data interface. */ + } USB_Descriptor_CDC_FunctionalUnion_t; + /** Type define for the device configuration descriptor structure. This must be defined in the * application code, as the configuration descriptor contains several sub-descriptors which * vary between devices, and which describe the device's usage to the host. @@ -130,9 +150,9 @@ { USB_Descriptor_Configuration_Header_t Config; USB_Descriptor_Interface_t CDC_CCI_Interface; - CDC_FUNCTIONAL_DESCRIPTOR(2) CDC_Functional_IntHeader; - CDC_FUNCTIONAL_DESCRIPTOR(1) CDC_Functional_AbstractControlManagement; - CDC_FUNCTIONAL_DESCRIPTOR(2) CDC_Functional_Union; + USB_Descriptor_CDC_FunctionalHeader_t CDC_Functional_Header; + USB_Descriptor_CDC_FunctionalACM_t CDC_Functional_ACM; + USB_Descriptor_CDC_FunctionalUnion_t CDC_Functional_Union; USB_Descriptor_Endpoint_t CDC_NotificationEndpoint; USB_Descriptor_Interface_t CDC_DCI_Interface; USB_Descriptor_Endpoint_t CDC_DataOutEndpoint; |