56
56
static uint8_t usb_rx_buf [USB_RX_BUF_SIZE ];
57
57
58
58
// Receive buffer head
59
- static volatile uint8_t usb_rx_buf_head ;
59
+ static volatile uint8_t usb_rx_buf_head = 0 ;
60
60
61
61
// Receive buffer tail
62
- static volatile uint8_t usb_rx_buf_tail ;
62
+ static volatile uint8_t usb_rx_buf_tail = 0 ;
63
63
64
64
// Number of bytes in receive buffer
65
- volatile uint8_t usb_rx_count ;
65
+ volatile uint8_t usb_rx_count = 0 ;
66
66
67
67
volatile bool mp_cdc_enabled = false;
68
68
volatile bool usb_transmitting = false;
@@ -133,8 +133,11 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
133
133
uint8_t c = cdc_packet_buffer [i ];
134
134
if (c == mp_interrupt_char ) {
135
135
mp_keyboard_interrupt ();
136
- // Don't put the interrupt into the buffer, just continue.
137
- continue ;
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 ;
138
141
} else {
139
142
// The count of characters present in receive buffer is
140
143
// incremented.
@@ -144,7 +147,7 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
144
147
if (usb_rx_buf_tail == USB_RX_BUF_SIZE ) {
145
148
// Reached the end of buffer, revert back to beginning of
146
149
// buffer.
147
- usb_rx_buf_tail = 0x00 ;
150
+ usb_rx_buf_tail = 0 ;
148
151
}
149
152
}
150
153
}
@@ -219,8 +222,7 @@ void init_usb(void) {
219
222
mscdf_register_callback (MSCDF_CB_TEST_DISK_READY , (FUNC_PTR )usb_msc_disk_is_ready );
220
223
mscdf_register_callback (MSCDF_CB_XFER_BLOCKS_DONE , (FUNC_PTR )usb_msc_xfer_done );
221
224
222
- int32_t result = usbdc_start (& multi_desc );
223
- while (result != ERR_NONE ) {}
225
+ usbdc_start (& multi_desc );
224
226
usbdc_attach ();
225
227
}
226
228
@@ -315,3 +317,12 @@ void usb_write(const char* buffer, uint32_t len) {
315
317
bool usb_connected (void ) {
316
318
return cdc_enabled ();
317
319
}
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