1 /*
2  * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _PICO_STDIO_USB_H
8 #define _PICO_STDIO_USB_H
9 
10 #include "pico/stdio.h"
11 
12 /** \brief Support for stdin/stdout over USB serial (CDC)
13  *  \defgroup pico_stdio_usb pico_stdio_usb
14  *  \ingroup pico_stdio
15  *
16  *  Linking this library or calling `pico_enable_stdio_usb(TARGET)` in the CMake (which
17  *  achieves the same thing) will add USB CDC to the drivers used for standard output
18  *
19  *  Note this library is a developer convenience. It is not applicable in all cases; for one it takes full control of the USB device precluding your
20  *  use of the USB in device or host mode. For this reason, this library will automatically disengage if you try to using it alongside \ref tinyusb_device or
21  *  \ref tinyusb_host. It also takes control of a lower level IRQ and sets up a periodic background task.
22  */
23 
24 // PICO_CONFIG: PICO_STDIO_USB_DEFAULT_CRLF, Default state of CR/LF translation for USB output, type=bool, default=PICO_STDIO_DEFAULT_CRLF, group=pico_stdio_usb
25 #ifndef PICO_STDIO_USB_DEFAULT_CRLF
26 #define PICO_STDIO_USB_DEFAULT_CRLF PICO_STDIO_DEFAULT_CRLF
27 #endif
28 
29 // PICO_CONFIG: PICO_STDIO_USB_STDOUT_TIMEOUT_US, Number of microseconds to be blocked trying to write USB output before assuming the host has disappeared and discarding data, default=500000, group=pico_stdio_usb
30 #ifndef PICO_STDIO_USB_STDOUT_TIMEOUT_US
31 #define PICO_STDIO_USB_STDOUT_TIMEOUT_US 500000
32 #endif
33 
34 // todo perhaps unnecessarily high?
35 // PICO_CONFIG: PICO_STDIO_USB_TASK_INTERVAL_US, Period of microseconds between calling tud_task in the background, default=1000, advanced=true, group=pico_stdio_usb
36 #ifndef PICO_STDIO_USB_TASK_INTERVAL_US
37 #define PICO_STDIO_USB_TASK_INTERVAL_US 1000
38 #endif
39 
40 // PICO_CONFIG: PICO_STDIO_USB_LOW_PRIORITY_IRQ, low priority (non hardware) IRQ number to claim for tud_task() background execution, default=31, advanced=true, group=pico_stdio_usb
41 #ifndef PICO_STDIO_USB_LOW_PRIORITY_IRQ
42 #define PICO_STDIO_USB_LOW_PRIORITY_IRQ 31
43 #endif
44 
45 extern stdio_driver_t stdio_usb;
46 
47 /*! \brief Explicitly initialize USB stdio and add it to the current set of stdin drivers
48  *  \ingroup pico_stdio_uart
49  */
50 bool stdio_usb_init(void);
51 
52 #endif
53