v2.0.0
stdio.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _PICO_STDIO_H
8#define _PICO_STDIO_H
9
17#include "pico.h"
18
19// PICO_CONFIG: PICO_STDOUT_MUTEX, Enable/disable mutex around stdout, type=bool, default=1, group=pico_stdio
20#ifndef PICO_STDOUT_MUTEX
21#define PICO_STDOUT_MUTEX 1
22#endif
23
24// PICO_CONFIG: PICO_STDIO_ENABLE_CRLF_SUPPORT, Enable/disable CR/LF output conversion support, type=bool, default=1, group=pico_stdio
25#ifndef PICO_STDIO_ENABLE_CRLF_SUPPORT
26#define PICO_STDIO_ENABLE_CRLF_SUPPORT 1
27#endif
28
29// PICO_CONFIG: PICO_STDIO_DEFAULT_CRLF, Default for CR/LF conversion enabled on all stdio outputs, type=bool, default=1, depends=PICO_STDIO_ENABLE_CRLF_SUPPORT, group=pico_stdio
30#ifndef PICO_STDIO_DEFAULT_CRLF
31#define PICO_STDIO_DEFAULT_CRLF 1
32#endif
33
34// PICO_CONFIG: PICO_STDIO_STACK_BUFFER_SIZE, Define printf buffer size (on stack)... this is just a working buffer not a max output size, min=0, max=512, default=128, group=pico_stdio
35#ifndef PICO_STDIO_STACK_BUFFER_SIZE
36#define PICO_STDIO_STACK_BUFFER_SIZE 128
37#endif
38
39// PICO_CONFIG: PICO_STDIO_DEADLOCK_TIMEOUT_MS, Time after which to assume stdio_usb is deadlocked by use in IRQ and give up, type=int, default=1000, group=pico_stdio
40#ifndef PICO_STDIO_DEADLOCK_TIMEOUT_MS
41#define PICO_STDIO_DEADLOCK_TIMEOUT_MS 1000
42#endif
43
44// PICO_CONFIG: PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS, Directly replace common stdio functions such as putchar from the C-library to avoid pulling in lots of c library code for simple output, type=bool, default=1, advanced=true, group=pico_stdio
45#ifndef PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS
46#define PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS 1
47#endif
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53#include <stdarg.h>
54
55typedef struct stdio_driver stdio_driver_t;
56
69bool stdio_init_all(void);
70
79bool stdio_deinit_all(void);
80
84void stdio_flush(void);
85
92int stdio_getchar_timeout_us(uint32_t timeout_us);
93
97 static inline int getchar_timeout_us(uint32_t timeout_us) {
98 return stdio_getchar_timeout_us(timeout_us);
99}
100
108void stdio_set_driver_enabled(stdio_driver_t *driver, bool enabled);
109
118void stdio_filter_driver(stdio_driver_t *driver);
119
128void stdio_set_translate_crlf(stdio_driver_t *driver, bool translate);
129
133int stdio_putchar_raw(int c);
134
138 static inline int putchar_raw(int c) {
139 return stdio_putchar_raw(c);
140}
141
145int stdio_puts_raw(const char *s);
146
150 static inline int puts_raw(const char *s) {
151 return stdio_puts_raw(s);
152}
153
160void stdio_set_chars_available_callback(void (*fn)(void*), void *param);
161
173int stdio_get_until(char *buf, int len, absolute_time_t until);
174
187int stdio_put_string(const char *s, int len, bool newline, bool cr_translation);
188
194int stdio_getchar(void);
195
201int stdio_putchar(int);
202
208int stdio_puts(const char *s);
209
215int stdio_vprintf(const char *format, va_list va);
216
222 int __printflike(1, 0) stdio_printf(const char* format, ...);
223
224#ifdef __cplusplus
225}
226#endif
227
228#endif
stdio_init_all
bool stdio_init_all(void)
Initialize all of the present standard stdio types that are linked into the binary.
Definition: stdio.c:200
stdio_put_string
int stdio_put_string(const char *s, int len, bool newline, bool cr_translation)
Prints a buffer to stdout with optional newline and carriage return insertion.
Definition: stdio.c:92
stdio_getchar_timeout_us
int stdio_getchar_timeout_us(uint32_t timeout_us)
Return a character from stdin if there is one available within a timeout.
Definition: stdio.c:255
stdio_puts
int stdio_puts(const char *s)
stdio_getchar Alias for puts that definitely does not go thru the implementation in the standard C li...
Definition: stdio.c:308
stdio_set_chars_available_callback
void stdio_set_chars_available_callback(void(*fn)(void *), void *param)
get notified when there are input characters available
Definition: stdio.c:282
stdio_putchar
int stdio_putchar(int)
stdio_getchar Alias for putchar that definitely does not go thru the implementation in the standard C...
Definition: stdio.c:302
getchar_timeout_us
static int getchar_timeout_us(uint32_t timeout_us)
Alias for stdio_getchar_timeout_us for backwards compatibility.
Definition: stdio.h:97
stdio_get_until
int stdio_get_until(char *buf, int len, absolute_time_t until)
Waits until a timeout to reard at least one character into a buffer.
Definition: stdio.c:116
stdio_set_driver_enabled
void stdio_set_driver_enabled(stdio_driver_t *driver, bool enabled)
Adds or removes a driver from the list of active drivers used for input/output.
Definition: stdio.c:151
stdio_putchar_raw
int stdio_putchar_raw(int c)
putchar variant that skips any CR/LF conversion if enabled
Definition: stdio.c:138
stdio_flush
void stdio_flush(void)
Flushes any buffered output.
Definition: stdio.c:168
puts_raw
static int puts_raw(const char *s)
Alias for stdio_puts_raw for backwards compatibility.
Definition: stdio.h:150
stdio_vprintf
int stdio_vprintf(const char *format, va_list va)
stdio_getchar Alias for vprintf that definitely does not go thru the implementation in the standard C...
Definition: stdio.c:317
stdio_set_translate_crlf
void stdio_set_translate_crlf(stdio_driver_t *driver, bool translate)
control conversion of line feeds to carriage return on transmissions
Definition: stdio.c:267
stdio_getchar
int stdio_getchar(void)
stdio_getchar Alias for getchar that definitely does not go thru the implementation in the standard C...
Definition: stdio.c:294
stdio_deinit_all
bool stdio_deinit_all(void)
Deinitialize all of the present standard stdio types that are linked into the binary.
Definition: stdio.c:226
stdio_puts_raw
int stdio_puts_raw(const char *s)
puts variant that skips any CR/LF conversion if enabled
Definition: stdio.c:144
stdio_filter_driver
void stdio_filter_driver(stdio_driver_t *driver)
Control limiting of output to a single driver.
Definition: stdio.c:263
putchar_raw
static int putchar_raw(int c)
Alias for stdio_putchar_raw for backwards compatibility.
Definition: stdio.h:138
__printflike
int __printflike(1, 0) stdio_printf(const char *format
stdio_getchar Alias for printf that definitely does not go thru the implementation in the standard C ...
absolute_time_t
uint64_t absolute_time_t
An opaque 64 bit timestamp in microseconds.
Definition: types.h:43
pico.h
stdio_driver
Definition: driver.h:12