Skip to content

Commit ac8f277

Browse files
peterharperukarg08
andauthored
Fix stdio_set_chars_available_callback for usb (raspberrypi#1649)
When you get a callback to tell you a character is available, you should be able to call getchar_timeout_us, but it's not working for USB Fixes raspberrypi#1603 Co-authored-by: Andrew Gordon <[email protected]>
1 parent fcd5333 commit ac8f277

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/rp2_common/pico_stdio_usb/stdio_usb.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ static int64_t timer_task(__unused alarm_id_t id, __unused void *user_data) {
5757
static void low_priority_worker_irq(void) {
5858
if (mutex_try_enter(&stdio_usb_mutex, NULL)) {
5959
tud_task();
60+
#if PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK
61+
uint32_t chars_avail = tud_cdc_available();
62+
#endif
6063
mutex_exit(&stdio_usb_mutex);
64+
#if PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK
65+
if (chars_avail && chars_available_callback) chars_available_callback(chars_available_param);
66+
#endif
6167
} else {
6268
// if the mutex is already owned, then we are in non IRQ code in this file.
6369
//
@@ -147,12 +153,6 @@ int stdio_usb_in_chars(char *buf, int length) {
147153
}
148154

149155
#if PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK
150-
void tud_cdc_rx_cb(__unused uint8_t itf) {
151-
if (chars_available_callback) {
152-
usbd_defer_func(chars_available_callback, chars_available_param, false);
153-
}
154-
}
155-
156156
void stdio_usb_set_chars_available_callback(void (*fn)(void*), void *param) {
157157
chars_available_callback = fn;
158158
chars_available_param = param;

0 commit comments

Comments
 (0)