Skip to content

Commit

Permalink
Fix stdio_set_chars_available_callback for usb
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
peterharperuk and arg08 committed Feb 26, 2024
1 parent 0c65e1d commit cbb669b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/rp2_common/pico_stdio_usb/stdio_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ static int64_t timer_task(__unused alarm_id_t id, __unused void *user_data) {

static void low_priority_worker_irq(void) {
if (mutex_try_enter(&stdio_usb_mutex, NULL)) {
uint32_t chars_avail;
tud_task();
chars_avail = tud_cdc_available();
mutex_exit(&stdio_usb_mutex);
if (chars_avail) chars_available_callback(chars_available_param);
} else {
// if the mutex is already owned, then we are in non IRQ code in this file.
//
Expand Down Expand Up @@ -147,12 +150,6 @@ int stdio_usb_in_chars(char *buf, int length) {
}

#if PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK
void tud_cdc_rx_cb(__unused uint8_t itf) {
if (chars_available_callback) {
usbd_defer_func(chars_available_callback, chars_available_param, false);
}
}

void stdio_usb_set_chars_available_callback(void (*fn)(void*), void *param) {
chars_available_callback = fn;
chars_available_param = param;
Expand Down

0 comments on commit cbb669b

Please sign in to comment.