Skip to content

Commit

Permalink
py/mpconfig: Provide config option for internal printf printer.
Browse files Browse the repository at this point in the history
The C-level printf is usually used for internal debugging prints, and a
port/board may want to redirect this somewhere other than stdout.

Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Mar 10, 2023
1 parent b3c8ab3 commit 78dc2db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,11 @@ typedef double mp_float_t;
#define MICROPY_USE_INTERNAL_PRINTF (1)
#endif

// The mp_print_t printer used for printf output when MICROPY_USE_INTERNAL_PRINTF is enabled
#ifndef MICROPY_INTERNAL_PRINTF_PRINTER
#define MICROPY_INTERNAL_PRINTF_PRINTER (&mp_plat_print)
#endif

// Support for internal scheduler
#ifndef MICROPY_ENABLE_SCHEDULER
#define MICROPY_ENABLE_SCHEDULER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
Expand Down
4 changes: 2 additions & 2 deletions shared/libc/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ int snprintf(char *str, size_t size, const char *fmt, ...);
int printf(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int ret = mp_vprintf(&mp_plat_print, fmt, ap);
int ret = mp_vprintf(MICROPY_INTERNAL_PRINTF_PRINTER, fmt, ap);
va_end(ap);
return ret;
}

int vprintf(const char *fmt, va_list ap) {
return mp_vprintf(&mp_plat_print, fmt, ap);
return mp_vprintf(MICROPY_INTERNAL_PRINTF_PRINTER, fmt, ap);
}

// need this because gcc optimises printf("%c", c) -> putchar(c), and printf("a") -> putchar('a')
Expand Down

0 comments on commit 78dc2db

Please sign in to comment.