@@ -88,10 +88,15 @@ int main(void)
88
88
89
89
for (;;)
90
90
{
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
+ }
95
100
96
101
/* Check if the UART receive buffer flush timer has expired or the buffer is nearly full */
97
102
RingBuff_Count_t BufferCount = RingBuffer_GetCount (& USARTtoUSB_Buffer );
@@ -153,10 +158,7 @@ void SetupHardware(void)
153
158
/** Event handler for the library USB Configuration Changed event. */
154
159
void EVENT_USB_Device_ConfigurationChanged (void )
155
160
{
156
-
157
-
158
- if (!(CDC_Device_ConfigureEndpoints (& VirtualSerial_CDC_Interface )))
159
- ;
161
+ CDC_Device_ConfigureEndpoints (& VirtualSerial_CDC_Interface );
160
162
}
161
163
162
164
/** 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
205
207
UCSR1C = 0 ;
206
208
207
209
/* 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 ;
211
210
UBRR1 = (CDCInterfaceInfo -> State .LineEncoding .BaudRateBPS == 57600 )
212
211
? SERIAL_UBBRVAL (CDCInterfaceInfo -> State .LineEncoding .BaudRateBPS )
213
212
: 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 ));
214
217
}
215
218
216
219
/** 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
233
236
bool CurrentDTRState = (CDCInterfaceInfo -> State .ControlLineStates .HostToDevice & CDC_CONTROL_LINE_OUT_DTR );
234
237
235
238
if (CurrentDTRState )
236
- {
237
- AVR_RESET_LINE_PORT &= ~AVR_RESET_LINE_MASK ;
238
- }
239
+ AVR_RESET_LINE_PORT &= ~AVR_RESET_LINE_MASK ;
239
240
else
240
- {
241
- AVR_RESET_LINE_PORT |= AVR_RESET_LINE_MASK ;
242
- }
241
+ AVR_RESET_LINE_PORT |= AVR_RESET_LINE_MASK ;
243
242
}
0 commit comments