Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new stdio_usb_run_chars_available_callback() function #2300

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,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 runs 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_run_chars_available_callback(void);
#endif

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 7 additions & 1 deletion src/rp2_common/pico_stdio_usb/stdio_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static void low_priority_worker_irq(void) {
#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);
if (chars_avail && chars_available_callback) stdio_usb_run_chars_available_callback();
#endif
} else {
// if the mutex is already owned, then we are in non IRQ code in this file.
Expand Down Expand Up @@ -171,6 +171,12 @@ void stdio_usb_set_chars_available_callback(void (*fn)(void*), void *param) {
chars_available_callback = fn;
chars_available_param = param;
}

void stdio_usb_run_chars_available_callback(void) {
if (chars_available_callback) {
chars_available_callback(chars_available_param);
}
}
#endif

stdio_driver_t stdio_usb = {
Expand Down