@@ -88,10 +88,15 @@ int main(void)
8888
8989 for (;;)
9090 {
91- /* Read bytes from the USB OUT endpoint into the USART transmit buffer */
92- int16_t ReceivedByte = CDC_Device_ReceiveByte (& VirtualSerial_CDC_Interface );
93- if (!(ReceivedByte < 0 ) && !(RingBuffer_IsFull (& USBtoUSART_Buffer )))
94- RingBuffer_Insert (& USBtoUSART_Buffer , ReceivedByte );
91+ /* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
92+ if (!(RingBuffer_IsFull (& USBtoUSART_Buffer )))
93+ {
94+ int16_t ReceivedByte = CDC_Device_ReceiveByte (& VirtualSerial_CDC_Interface );
95+
96+ /* Read bytes from the USB OUT endpoint into the USART transmit buffer */
97+ if (!(ReceivedByte < 0 ))
98+ RingBuffer_Insert (& USBtoUSART_Buffer , ReceivedByte );
99+ }
95100
96101 /* Check if the UART receive buffer flush timer has expired or the buffer is nearly full */
97102 RingBuff_Count_t BufferCount = RingBuffer_GetCount (& USARTtoUSB_Buffer );
@@ -153,10 +158,7 @@ void SetupHardware(void)
153158/** Event handler for the library USB Configuration Changed event. */
154159void EVENT_USB_Device_ConfigurationChanged (void )
155160{
156-
157-
158- if (!(CDC_Device_ConfigureEndpoints (& VirtualSerial_CDC_Interface )))
159- ;
161+ CDC_Device_ConfigureEndpoints (& VirtualSerial_CDC_Interface );
160162}
161163
162164/** Event handler for the library USB Unhandled Control Request event. */
@@ -205,12 +207,13 @@ void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCI
205207 UCSR1C = 0 ;
206208
207209 /* Special case 57600 baud for compatibility with the ATmega328 bootloader. */
208- UCSR1A = (CDCInterfaceInfo -> State .LineEncoding .BaudRateBPS == 57600 ) ? 0 : (1 << U2X1 );
209- UCSR1B = ((1 << RXCIE1 ) | (1 << TXEN1 ) | (1 << RXEN1 ));
210- UCSR1C = ConfigMask ;
211210 UBRR1 = (CDCInterfaceInfo -> State .LineEncoding .BaudRateBPS == 57600 )
212211 ? SERIAL_UBBRVAL (CDCInterfaceInfo -> State .LineEncoding .BaudRateBPS )
213212 : SERIAL_2X_UBBRVAL (CDCInterfaceInfo -> State .LineEncoding .BaudRateBPS );
213+
214+ UCSR1C = ConfigMask ;
215+ UCSR1A = (CDCInterfaceInfo -> State .LineEncoding .BaudRateBPS == 57600 ) ? 0 : (1 << U2X1 );
216+ UCSR1B = ((1 << RXCIE1 ) | (1 << TXEN1 ) | (1 << RXEN1 ));
214217}
215218
216219/** ISR to manage the reception of data from the serial port, placing received bytes into a circular buffer
@@ -233,11 +236,7 @@ void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* const C
233236 bool CurrentDTRState = (CDCInterfaceInfo -> State .ControlLineStates .HostToDevice & CDC_CONTROL_LINE_OUT_DTR );
234237
235238 if (CurrentDTRState )
236- {
237- AVR_RESET_LINE_PORT &= ~AVR_RESET_LINE_MASK ;
238- }
239+ AVR_RESET_LINE_PORT &= ~AVR_RESET_LINE_MASK ;
239240 else
240- {
241- AVR_RESET_LINE_PORT |= AVR_RESET_LINE_MASK ;
242- }
241+ AVR_RESET_LINE_PORT |= AVR_RESET_LINE_MASK ;
243242}
0 commit comments