Skip to content

Commit 064ac2d

Browse files
dhalbertjoshua-beck-0908
authored andcommitted
address review; fix STM; add limitation for STM
1 parent e847999 commit 064ac2d

File tree

5 files changed

+29
-49
lines changed

5 files changed

+29
-49
lines changed

ports/espressif/supervisor/usb_serial_jtag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ char usb_serial_jtag_read_char(void) {
122122
}
123123

124124
uint32_t usb_serial_jtag_bytes_available(void) {
125-
return ringbuf_num_filled(&ringbuf) || usb_serial_jtag_ll_rxfifo_data_available();
125+
return ringbuf_num_filled(&ringbuf) + usb_serial_jtag_ll_rxfifo_data_available();
126126
}
127127

128128
void usb_serial_jtag_write(const char *text, uint32_t length) {

ports/silabs/supervisor/serial.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ char port_serial_read(void) {
141141
return (char)data;
142142
}
143143

144-
// Checking ring buffer haves bytes available or not
145-
bool port_serial_bytes_available(void) {
146-
return ringbuf_num_filled(&con_uart_rx_ringbuf) > 0 ? true : false;
144+
uint32_t port_serial_bytes_available(void) {
145+
return ringbuf_num_filled(&con_uart_rx_ringbuf);
147146
}
148147

149148
// Send n bytes data to serial by EUSART0

ports/stm/supervisor/serial.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ char port_serial_read(void) {
6666
#endif
6767
}
6868

69-
bool port_serial_bytes_available(void) {
69+
// There is no easy way to find the number of pending characters, so just say there's 1.
70+
uint32_t port_serial_bytes_available(void) {
7071
#if CPY_STM32F4
71-
return __HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE);
72+
return __HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE) ? 1 : 0;
7273
#else
73-
return false;
74+
return 0;
7475
#endif
7576
}
7677

shared-bindings/supervisor/Runtime.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,14 @@ MP_PROPERTY_GETTER(supervisor_runtime_serial_connected_obj,
8888
(mp_obj_t)&supervisor_runtime_get_serial_connected_obj);
8989

9090
//| serial_bytes_available: int
91-
//| """Returns the number of bytes are available to read
92-
//| on the USB serial input. Allows for polling to see whether
93-
//| to call the built-in input() or wait. (read-only)
91+
//| """Returns the number of bytes are available to read on the console serial input.
92+
//| Multiple console serial inputs may be in use at once, including
93+
//| USB, web workflow, BLE workflow, and/or UART.
94+
//|
95+
//| Allows for polling to see whether to call the built-in input() or wait. (read-only)
96+
//|
97+
//| **Limitations**: On STM, UART (not USB) console input can only determine that at least one character
98+
//| is available, and so if only the UART console is in use, only ``1`` or ``0`` will be returned.
9499
//|
95100
//| Changed in version 9.1.0: Previously returned only ``True`` or ``False``.
96101
//| Since ``0`` acts as ``False``, ``if supervisor.runtime.serial_byes_available:``

supervisor/shared/serial.c

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -295,70 +295,45 @@ char serial_read(void) {
295295
}
296296

297297
uint32_t serial_bytes_available(void) {
298+
// There may be multiple serial input channels, so sum the count from all.
299+
uint32_t count = 0;
300+
298301
#if CIRCUITPY_USB_VENDOR
299302
if (tud_vendor_connected()) {
300-
uint32_t count = tud_vendor_available();
301-
if (count > 0) {
302-
return count;
303-
}
303+
count += tud_vendor_available();
304304
}
305305
#endif
306306

307307
#if CIRCUITPY_CONSOLE_UART
308-
{
309-
uint32_t count = common_hal_busio_uart_rx_characters_available(&console_uart);
310-
if (count > 0) {
311-
return count;
312-
}
313-
}
308+
count += common_hal_busio_uart_rx_characters_available(&console_uart);
314309
#endif
315310

316311
#if CIRCUITPY_SERIAL_BLE
317-
{
318-
uint32_t count = ble_serial_available();
319-
if (count > 0) {
320-
return count;
321-
}
322-
}
312+
count += ble_serial_available();
323313
#endif
324314

325315
#if CIRCUITPY_WEB_WORKFLOW
326-
{
327-
uint32_t count = websocket_available();
328-
if (count > 0) {
329-
return count;
330-
}
331-
}
316+
count += websocket_available();
332317
#endif
333318

334319
#if CIRCUITPY_USB_KEYBOARD_WORKFLOW
335-
{
336-
uint32_t count = usb_keyboard_chars_available();
337-
if (count > 0) {
338-
return count;
339-
}
340-
}
320+
count += usb_keyboard_chars_available();
341321
#endif
342322

343323
#if CIRCUITPY_USB_CDC
344324
if (usb_cdc_console_enabled()) {
345-
uint32_t count = tud_cdc_available();
346-
if (count > 0) {
347-
return count;
348-
}
325+
count += tud_cdc_available();
349326
}
350327
#endif
351328

352329
#if CIRCUITPY_USB
353-
{
354-
uint32_t count = tud_cdc_available();
355-
if (count > 0) {
356-
return count;
357-
}
358-
}
330+
count += tud_cdc_available();
359331
#endif
360332

361-
return port_serial_bytes_available();
333+
// Port-specific serial input.
334+
count += port_serial_bytes_available();
335+
336+
return count;
362337
}
363338

364339
void serial_write_substring(const char *text, uint32_t length) {

0 commit comments

Comments
 (0)