Add new stdio_usb_call_chars_available_callback() function (#2300)

When the user links in tinyUSB directly, the pico_stdio_usb library
disables some of its functionality, including its built-in background
processing thread. The user can implement their own background thread
in order to continue using the stdio functionality, except that there
is no wey to trigger the registered chars_available_callback. This
commit adds a new `stdio_usb_run_chars_available_callback()` method to
allow user's background threads to run the callback.
This commit is contained in:
Michael Brase 2025-03-22 18:47:40 -05:00 committed by GitHub
parent f81851a2cb
commit e43b7534ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View file

@ -192,6 +192,19 @@ bool stdio_usb_deinit(void);
* \return true if stdio is connected over CDC
*/
bool stdio_usb_connected(void);
#if PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK
/*! \brief Explicitly calls the registered USB stdio chars_available_callback
* \ingroup pico_stdio_usb
*
* \ref This method is normally called by the internal USB stdio background thread when there is new USB CDC
* data available to read. However, if the internal background thread is disabled (e.g. when the user
* directly links tinyUSB), the user will need to implement their own background thread and call this
* method directly.
*/
void stdio_usb_call_chars_available_callback(void);
#endif
#ifdef __cplusplus
}
#endif

View file

@ -170,6 +170,12 @@ void stdio_usb_set_chars_available_callback(void (*fn)(void*), void *param) {
chars_available_callback = fn;
chars_available_param = param;
}
void stdio_usb_call_chars_available_callback(void) {
if (chars_available_callback) {
chars_available_callback(chars_available_param);
}
}
#endif
stdio_driver_t stdio_usb = {