Skip to content

Commit 2abdbf4

Browse files
committed
Add new stdio_usb_run_chars_available_callback() function
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.
1 parent c757f36 commit 2abdbf4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h

+13
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ bool stdio_usb_deinit(void);
161161
* \return true if stdio is connected over CDC
162162
*/
163163
bool stdio_usb_connected(void);
164+
165+
#if PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK
166+
/*! \brief Explicitly runs the registered USB stdio chars_available_callback
167+
* \ingroup pico_stdio_usb
168+
*
169+
* \ref This method is normally called by the internal USB stdio background thread when there is new USB CDC
170+
* data available to read. However, if the internal background thread is disabled (e.g. when the user
171+
* directly links tinyUSB), the user will need to implement their own background thread and call this
172+
* method directly.
173+
*/
174+
void stdio_usb_run_chars_available_callback(void);
175+
#endif
176+
164177
#ifdef __cplusplus
165178
}
166179
#endif

src/rp2_common/pico_stdio_usb/stdio_usb.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void low_priority_worker_irq(void) {
6666
#endif
6767
mutex_exit(&stdio_usb_mutex);
6868
#if PICO_STDIO_USB_SUPPORT_CHARS_AVAILABLE_CALLBACK
69-
if (chars_avail && chars_available_callback) chars_available_callback(chars_available_param);
69+
if (chars_avail && chars_available_callback) stdio_usb_run_chars_available_callback();
7070
#endif
7171
} else {
7272
// if the mutex is already owned, then we are in non IRQ code in this file.
@@ -171,6 +171,11 @@ void stdio_usb_set_chars_available_callback(void (*fn)(void*), void *param) {
171171
chars_available_callback = fn;
172172
chars_available_param = param;
173173
}
174+
void stdio_usb_run_chars_available_callback(void) {
175+
if (chars_available_callback) {
176+
chars_available_callback(chars_available_param);
177+
}
178+
}
174179
#endif
175180

176181
stdio_driver_t stdio_usb = {

0 commit comments

Comments
 (0)