5656static uint8_t usb_rx_buf [USB_RX_BUF_SIZE ];
5757
5858// Receive buffer head
59- static volatile uint8_t usb_rx_buf_head = 0 ;
59+ static volatile uint8_t usb_rx_buf_head ;
6060
6161// Receive buffer tail
62- static volatile uint8_t usb_rx_buf_tail = 0 ;
62+ static volatile uint8_t usb_rx_buf_tail ;
6363
6464// Number of bytes in receive buffer
65- volatile uint8_t usb_rx_count = 0 ;
65+ volatile uint8_t usb_rx_count ;
6666
6767volatile bool mp_cdc_enabled = false;
6868volatile bool usb_transmitting = false;
@@ -133,11 +133,8 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
133133 uint8_t c = cdc_packet_buffer [i ];
134134 if (c == mp_interrupt_char ) {
135135 mp_keyboard_interrupt ();
136- // If interrupted, flush all the input.
137- usb_rx_count = 0 ;
138- usb_rx_buf_head = 0 ;
139- usb_rx_buf_tail = 0 ;
140- break ;
136+ // Don't put the interrupt into the buffer, just continue.
137+ continue ;
141138 } else {
142139 // The count of characters present in receive buffer is
143140 // incremented.
@@ -147,7 +144,7 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
147144 if (usb_rx_buf_tail == USB_RX_BUF_SIZE ) {
148145 // Reached the end of buffer, revert back to beginning of
149146 // buffer.
150- usb_rx_buf_tail = 0 ;
147+ usb_rx_buf_tail = 0x00 ;
151148 }
152149 }
153150 }
@@ -222,7 +219,8 @@ void init_usb(void) {
222219 mscdf_register_callback (MSCDF_CB_TEST_DISK_READY , (FUNC_PTR )usb_msc_disk_is_ready );
223220 mscdf_register_callback (MSCDF_CB_XFER_BLOCKS_DONE , (FUNC_PTR )usb_msc_xfer_done );
224221
225- usbdc_start (& multi_desc );
222+ int32_t result = usbdc_start (& multi_desc );
223+ while (result != ERR_NONE ) {}
226224 usbdc_attach ();
227225}
228226
@@ -317,12 +315,3 @@ void usb_write(const char* buffer, uint32_t len) {
317315bool usb_connected (void ) {
318316 return cdc_enabled ();
319317}
320-
321- // Poll for input if keyboard interrupts are enabled,
322- // so that we can check for the interrupt char. read_complete() does the checking.
323- void usb_cdc_background () {
324- //
325- if (mp_interrupt_char != -1 && cdc_enabled () && !pending_read ) {
326- start_read ();
327- }
328- }
0 commit comments