mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2025-02-05 18:40:21 +00:00
Fix stdio_set_chars_available_callback for usb (#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 #1603 Co-authored-by: Andrew Gordon <arg@gordondesign.ltd.uk>
This commit is contained in:
parent
fcd5333f6b
commit
ac8f277e5a
@ -57,7 +57,13 @@ 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)) {
|
||||
tud_task();
|
||||
#if PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK
|
||||
uint32_t chars_avail = tud_cdc_available();
|
||||
#endif
|
||||
mutex_exit(&stdio_usb_mutex);
|
||||
#if PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK
|
||||
if (chars_avail && chars_available_callback) chars_available_callback(chars_available_param);
|
||||
#endif
|
||||
} else {
|
||||
// if the mutex is already owned, then we are in non IRQ code in this file.
|
||||
//
|
||||
@ -147,12 +153,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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user