From aa08ab00f096a288d413854fb6b2de80f252d146 Mon Sep 17 00:00:00 2001 From: IhorNehrutsa Date: Wed, 10 Jan 2024 17:35:55 +0200 Subject: [PATCH] py/mpprint.h: Add do_printf() macro. Signed-off-by: IhorNehrutsa --- drivers/esp-hosted/esp_hosted_hal.h | 4 ++-- py/mpprint.h | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/esp-hosted/esp_hosted_hal.h b/drivers/esp-hosted/esp_hosted_hal.h index 0bc7db928235a..314bee6e4ebc3 100644 --- a/drivers/esp-hosted/esp_hosted_hal.h +++ b/drivers/esp-hosted/esp_hosted_hal.h @@ -36,7 +36,7 @@ #if ESP_HOSTED_DEBUG #define PROTOBUF_C_UNPACK_ERROR(...) error_printf(__VA_ARGS__); #endif - +/* #define ANSI_C_RED "\x1B[31m" #define ANSI_C_GREEN "\x1B[32m" #define ANSI_C_YELLOW "\x1B[33m" @@ -58,7 +58,7 @@ #define warn_printf(...) do_printf(ANSI_C_YELLOW); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT); #define error_printf(...) do_printf(ANSI_C_RED); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT); #define crit_printf(...) do_printf(ANSI_C_MAGENTA); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT); - +*/ typedef enum { ESP_HOSTED_MODE_BT, ESP_HOSTED_MODE_WIFI, diff --git a/py/mpprint.h b/py/mpprint.h index 8383ea85794c2..5d5408885f65e 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -79,4 +79,26 @@ int mp_printf(const mp_print_t *print, const char *fmt, ...); int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #endif +#define ANSI_C_RED "\x1B[31m" +#define ANSI_C_GREEN "\x1B[32m" +#define ANSI_C_YELLOW "\x1B[33m" +#define ANSI_C_BLUE "\x1B[34m" +#define ANSI_C_MAGENTA "\x1B[35m" +#define ANSI_C_CYAN "\x1B[36m" +#define ANSI_C_WHITE "\x1B[37m" +#define ANSI_C_DEFAULT "\x1B[0m" + +#if DO_PRINTF +#define do_printf(...) mp_printf(&mp_plat_print, __VA_ARGS__) +#else +#define do_printf(...) +#endif + +// Logging macros. +#define debug_printf(...) do_printf(ANSI_C_BLUE); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT); +#define info_printf(...) do_printf(ANSI_C_GREEN); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT); +#define warn_printf(...) do_printf(ANSI_C_YELLOW); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT); +#define error_printf(...) do_printf(ANSI_C_RED); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT); +#define crit_printf(...) do_printf(ANSI_C_MAGENTA); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT); + #endif // MICROPY_INCLUDED_PY_MPPRINT_H