X-Git-Url: http://git.linex4red.de/pub/lufa.git/blobdiff_plain/eff07bb87758a12064d9de9c859b1e6e6502f2ea..042d3288ad52301c5b0ef69eada03eee83497dda:/Demos/Device/LowLevel/CDC/CDC.c diff --git a/Demos/Device/LowLevel/CDC/CDC.c b/Demos/Device/LowLevel/CDC/CDC.c index 73b486ccd..9ee744ea0 100644 --- a/Demos/Device/LowLevel/CDC/CDC.c +++ b/Demos/Device/LowLevel/CDC/CDC.c @@ -45,16 +45,10 @@ * It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical * serial link characteristics and instead sends and receives data in endpoint streams. */ -CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600, - .CharFormat = OneStopBit, - .ParityType = Parity_None, - .DataBits = 8 }; - -/** Indicates if the host has set the device line encoding. Until the line encoding is set by the host, the device should - * not attempt to send any bytes. - */ -bool LineEncodingSet = false; - +CDC_Line_Coding_t LineEncoding = { .BaudRateBPS = 0, + .CharFormat = OneStopBit, + .ParityType = Parity_None, + .DataBits = 8 }; #if 0 /* NOTE: Here you can set up a standard stream using the created virtual serial port, so that the standard stream functions in @@ -65,7 +59,7 @@ static int CDC_putchar(char c, FILE *stream) { Endpoint_SelectEndpoint(CDC_TX_EPNUM); - if (!(LineEncodingSet)) + if (!(LineEncoding.BaudRateBPS)) return -1; while (!(Endpoint_IsReadWriteAllowed())) @@ -84,7 +78,7 @@ static int CDC_getchar(FILE *stream) { int c; - if (!(LineEncodingSet)) + if (!(LineEncoding.BaudRateBPS)) return -1; Endpoint_SelectEndpoint(CDC_RX_EPNUM); @@ -149,7 +143,7 @@ void SetupHardware(void) /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and * starts the library USB task to begin the enumeration and USB management process. */ -void EVENT_USB_Connect(void) +void EVENT_USB_Device_Connect(void) { /* Indicate USB enumerating */ LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); @@ -158,7 +152,7 @@ void EVENT_USB_Connect(void) /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via * the status LEDs and stops the USB management and CDC management tasks. */ -void EVENT_USB_Disconnect(void) +void EVENT_USB_Device_Disconnect(void) { /* Indicate USB not ready */ LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); @@ -167,7 +161,7 @@ void EVENT_USB_Disconnect(void) /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration * of the USB device after enumeration - the device endpoints are configured and the CDC management task started. */ -void EVENT_USB_ConfigurationChanged(void) +void EVENT_USB_Device_ConfigurationChanged(void) { /* Indicate USB connected and ready */ LEDs_SetAllLEDs(LEDMASK_USB_READY); @@ -193,16 +187,17 @@ void EVENT_USB_ConfigurationChanged(void) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); } + + /* Reset line encoding baud rate so that the host knows to send new values */ + LineEncoding.BaudRateBPS = 0; } -/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific +/** 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_UnhandledControlPacket(void) +void EVENT_USB_Device_UnhandledControlRequest(void) { - uint8_t* LineCodingData = (uint8_t*)&LineCoding; - /* Process CDC specific control requests */ switch (USB_ControlRequest.bRequest) { @@ -213,7 +208,7 @@ void EVENT_USB_UnhandledControlPacket(void) Endpoint_ClearSETUP(); /* Write the line coding data to the control endpoint */ - Endpoint_Write_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t)); + Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t)); /* Finalize the stream transfer to send the last packet or clear the host abort */ Endpoint_ClearOUT(); @@ -227,10 +222,7 @@ void EVENT_USB_UnhandledControlPacket(void) Endpoint_ClearSETUP(); /* Read the line coding data in from the host into the global struct */ - Endpoint_Read_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t)); - - /* Indicate that the line encoding has been set, and the device may now send data */ - LineEncodingSet = true; + Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t)); /* Finalize the stream transfer to clear the last packet from the host */ Endpoint_ClearIN(); @@ -314,7 +306,7 @@ void CDC_Task(void) { ActionSent = false; } - else if ((ActionSent == false) && LineEncodingSet) + else if ((ActionSent == false) && LineEncoding.BaudRateBPS) { ActionSent = true;