25
25
*/
26
26
27
27
#include "usb.h"
28
+ #include <stdio.h>
28
29
29
30
#include <stdint.h>
30
31
49
50
#include "usb_mass_storage.h"
50
51
51
52
#include "supervisor/shared/autoreload.h"
53
+ #include "supervisor/serial.h"
52
54
53
55
// Store received characters on our own so that we can filter control characters
54
56
// and act immediately on CTRL-C for example.
@@ -126,7 +128,7 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
126
128
atomic_leave_critical (& flags );
127
129
return true;
128
130
}
129
-
131
+
130
132
for (uint16_t i = 0 ; i < count ; i ++ ) {
131
133
uint8_t c = cdc_packet_buffer [i ];
132
134
if (c == mp_interrupt_char ) {
@@ -150,15 +152,15 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
150
152
}
151
153
}
152
154
atomic_leave_critical (& flags );
153
-
155
+
154
156
// Trigger a follow up read if we have space.
155
- if (usb_rx_count < USB_RX_BUF_SIZE ) {
157
+ /* if (usb_rx_count < USB_RX_BUF_SIZE - 64 ) {
156
158
int32_t result = start_read();
157
159
if (result != ERR_NONE) {
158
160
return true;
159
161
}
160
- }
161
-
162
+ }*/
163
+
162
164
/* No error. */
163
165
return false;
164
166
}
@@ -170,7 +172,9 @@ static bool write_complete(const uint8_t ep,
170
172
return false; // No errors.
171
173
}
172
174
// This is called after writes are finished.
175
+
173
176
usb_transmitting = false;
177
+
174
178
/* No error. */
175
179
return false;
176
180
}
@@ -243,9 +247,16 @@ static bool cdc_enabled(void) {
243
247
}
244
248
245
249
bool usb_bytes_available (void ) {
250
+ // Check if the buffer has data, but not enough
251
+ // space to hold another read.
252
+ if (usb_rx_count > 64 ) {
253
+ return usb_rx_count > 0 ;
254
+ }
255
+ // Buffer has enough room
246
256
if (cdc_enabled () && !pending_read ) {
247
257
start_read ();
248
258
}
259
+ // Buffer is empty and/or no new data is available
249
260
if (usb_rx_count == 0 ) {
250
261
return false;
251
262
}
@@ -263,16 +274,16 @@ int usb_read(void) {
263
274
data = usb_rx_buf [usb_rx_buf_head ];
264
275
usb_rx_buf_head ++ ;
265
276
usb_rx_count -- ;
266
- if (( USB_RX_BUF_SIZE ) == usb_rx_buf_head ) {
277
+ if (usb_rx_buf_head == USB_RX_BUF_SIZE ) {
267
278
usb_rx_buf_head = 0 ;
268
279
}
269
280
CRITICAL_SECTION_LEAVE ();
270
281
271
282
// Trigger a new read because we just cleared some space.
272
- if (!pending_read && usb_rx_count == USB_RX_BUF_SIZE - 1 ) {
283
+ /* if (!pending_read && usb_rx_count == USB_RX_BUF_SIZE - 1) {
273
284
start_read();
274
- }
275
-
285
+ }*/
286
+
276
287
return data ;
277
288
}
278
289
0 commit comments