@@ -261,70 +261,45 @@ char serial_read(void) {
261
261
}
262
262
263
263
uint32_t serial_bytes_available (void ) {
264
+ // There may be multiple serial input channels, so sum the count from all.
265
+ uint32_t count = 0 ;
266
+
264
267
#if CIRCUITPY_USB_VENDOR
265
268
if (tud_vendor_connected ()) {
266
- uint32_t count = tud_vendor_available ();
267
- if (count > 0 ) {
268
- return count ;
269
- }
269
+ count += tud_vendor_available ();
270
270
}
271
271
#endif
272
272
273
273
#if CIRCUITPY_CONSOLE_UART
274
- {
275
- uint32_t count = common_hal_busio_uart_rx_characters_available (& console_uart );
276
- if (count > 0 ) {
277
- return count ;
278
- }
279
- }
274
+ count += common_hal_busio_uart_rx_characters_available (& console_uart );
280
275
#endif
281
276
282
277
#if CIRCUITPY_SERIAL_BLE
283
- {
284
- uint32_t count = ble_serial_available ();
285
- if (count > 0 ) {
286
- return count ;
287
- }
288
- }
278
+ count += ble_serial_available ();
289
279
#endif
290
280
291
281
#if CIRCUITPY_WEB_WORKFLOW
292
- {
293
- uint32_t count = websocket_available ();
294
- if (count > 0 ) {
295
- return count ;
296
- }
297
- }
282
+ count += websocket_available ();
298
283
#endif
299
284
300
285
#if CIRCUITPY_USB_KEYBOARD_WORKFLOW
301
- {
302
- uint32_t count = usb_keyboard_chars_available ();
303
- if (count > 0 ) {
304
- return count ;
305
- }
306
- }
286
+ count += usb_keyboard_chars_available ();
307
287
#endif
308
288
309
289
#if CIRCUITPY_USB_CDC
310
290
if (usb_cdc_console_enabled ()) {
311
- uint32_t count = tud_cdc_available ();
312
- if (count > 0 ) {
313
- return count ;
314
- }
291
+ count += tud_cdc_available ();
315
292
}
316
293
#endif
317
294
318
295
#if CIRCUITPY_USB
319
- {
320
- uint32_t count = tud_cdc_available ();
321
- if (count > 0 ) {
322
- return count ;
323
- }
324
- }
296
+ count += tud_cdc_available ();
325
297
#endif
326
298
327
- return port_serial_bytes_available ();
299
+ // Port-specific serial input.
300
+ count += port_serial_bytes_available ();
301
+
302
+ return count ;
328
303
}
329
304
330
305
void serial_write_substring (const char * text , uint32_t length ) {
0 commit comments