X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/713670043a1edb714461fc83c2b8817f3db99961..b2a30cd48a0621b360d23dd430c646d22e943d09:/Bootloaders/CDC/BootloaderCDC.c?ds=inline 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. *