Skip to content

Commit

Permalink
py/mpprint.h: Add do_printf() macro.
Browse files Browse the repository at this point in the history
Signed-off-by: IhorNehrutsa <[email protected]>
  • Loading branch information
IhorNehrutsa authored and IhorNehrutsa committed Jan 11, 2024
1 parent 2ed976f commit 21bbbd8
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 60 deletions.
6 changes: 3 additions & 3 deletions drivers/esp-hosted/esp_hosted_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
#include <stdint.h>
#include <string.h>

#include "esp_hosted_hal.h"
#include "esp_hosted_wifi.h"

#include "py/runtime.h"
#include "extmod/modmachine.h"
#ifdef MICROPY_HW_WIFI_LED
#include "led.h"
#endif

#include "esp_hosted_hal.h"
#include "esp_hosted_wifi.h"

extern void mod_network_poll_events(void);

STATIC mp_obj_t esp_hosted_pin_irq_callback(mp_obj_t self_in) {
Expand Down
27 changes: 2 additions & 25 deletions drivers/esp-hosted/esp_hosted_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,9 @@
#ifndef ESP_HOSTED_DEBUG
#define ESP_HOSTED_DEBUG (0)
#endif
#define DO_PRINTF (ESP_HOSTED_DEBUG)

#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"
#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 ESP_HOSTED_DEBUG
#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);
// #include "py/mpprint.h"

typedef enum {
ESP_HOSTED_MODE_BT,
Expand Down
5 changes: 2 additions & 3 deletions drivers/ninaw10/nina_bt_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <stdio.h>
#include <string.h>

// #define DO_PRINTF (1)

#include "py/runtime.h"
#include "extmod/mpbthci.h"

Expand All @@ -50,9 +52,6 @@
#define OCF_SET_EVENT_MASK (0x0001)
#define OCF_RESET (0x0003)

#define error_printf(...) // mp_printf(&mp_plat_print, "nina_bt_hci.c: " __VA_ARGS__)
#define debug_printf(...) // mp_printf(&mp_plat_print, "nina_bt_hci.c: " __VA_ARGS__)

// Provided by the port, and also possibly shared with the stack.
extern uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];

Expand Down
8 changes: 2 additions & 6 deletions drivers/ninaw10/nina_wifi_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* NINA-W10 driver BSP implementation.
*/

#define DO_PRINTF (NINA_DEBUG)

#include "py/mphal.h"

#if MICROPY_PY_NETWORK_NINAW10
Expand All @@ -40,12 +42,6 @@
#include "nina_bsp.h"
#include "nina_wifi_drv.h"

#if NINA_DEBUG
#define debug_printf(...) mp_printf(&mp_plat_print, __VA_ARGS__)
#else
#define debug_printf(...)
#endif

int nina_bsp_init(void) {
mp_hal_pin_output(MICROPY_HW_NINA_GPIO1);
mp_hal_pin_input(MICROPY_HW_NINA_ACK);
Expand Down
9 changes: 3 additions & 6 deletions drivers/ninaw10/nina_wifi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* NINA-W10 WiFi driver.
*/

#define DO_PRINTF (NINA_DEBUG)

#include "py/mphal.h"
#include "py/mperrno.h"

Expand All @@ -36,6 +38,7 @@
#include <string.h>
#include <stdio.h>

#include "py/mpprint.h"
#include "nina_bsp.h"
#include "nina_wifi_drv.h"

Expand Down Expand Up @@ -63,12 +66,6 @@
#define NINA_SSELECT_TIMEOUT (1000)
#define NINA_CONNECT_TIMEOUT (10000)

#if NINA_DEBUG
#define debug_printf(...) mp_printf(&mp_plat_print, __VA_ARGS__)
#else
#define debug_printf(...)
#endif

#ifndef __REVSH
#define __REVSH(x) ((((uint16_t)x) << 8) | (((uint16_t)x) >> 8))
#endif
Expand Down
6 changes: 3 additions & 3 deletions extmod/network_esp_hosted.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <stdarg.h>
#include <stdint.h>

#include "esp_hosted_hal.h"
#include "esp_hosted_wifi.h"

#include "py/objtuple.h"
#include "py/objlist.h"
#include "py/stream.h"
Expand All @@ -45,9 +48,6 @@
#include "extmod/modnetwork.h"
#include "modmachine.h"

#include "esp_hosted_wifi.h"
#include "esp_hosted_hal.h"

typedef struct _esp_hosted_obj_t {
mp_obj_base_t base;
uint32_t itf;
Expand Down
4 changes: 2 additions & 2 deletions extmod/network_ninaw10.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#if MICROPY_PY_NETWORK && MICROPY_PY_NETWORK_NINAW10

// #define DO_PRINTF (1)

#include <string.h>
#include <stdio.h>
#include <stdarg.h>
Expand Down Expand Up @@ -77,8 +79,6 @@ typedef struct _nina_obj_t {

#define is_nonblocking_error(errno) ((errno) == MP_EAGAIN || (errno) == MP_EWOULDBLOCK || (errno) == MP_EINPROGRESS)

#define debug_printf(...) // mp_printf(&mp_plat_print, __VA_ARGS__)

static uint16_t bind_port = BIND_PORT_RANGE_MIN;
const mp_obj_type_t mod_network_nic_type_nina;
static nina_obj_t network_nina_wl_sta = {{(mp_obj_type_t *)&mod_network_nic_type_nina}, false, false, MOD_NETWORK_STA_IF};
Expand Down
8 changes: 2 additions & 6 deletions ports/mimxrt/sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* THE SOFTWARE.
*/

#define DO_PRINTF (SDIO_DEBUG)

#include <stdio.h>
#include "py/mperrno.h"
#include "py/mphal.h"
Expand Down Expand Up @@ -79,12 +81,6 @@
#define SDMMC_CLOCK_25MHZ (25000000U)
#define SDMMC_CLOCK_50MHZ (50000000U)

#if SDIO_DEBUG
#define debug_printf(...) mp_printf(&mp_plat_print, __VA_ARGS__)
#else
#define debug_printf(...)
#endif

#define DMA_DESCRIPTOR_BUFFER_SIZE (32U)
AT_NONCACHEABLE_SECTION_ALIGN(
static uint32_t sdio_adma_descriptor_table[DMA_DESCRIPTOR_BUFFER_SIZE], USDHC_ADMA2_ADDRESS_ALIGN);
Expand Down
5 changes: 2 additions & 3 deletions ports/renesas-ra/mpbthciport.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* THE SOFTWARE.
*/

// #define DO_PRINTF (1)

#include "py/runtime.h"
#include "py/stream.h"
#include "py/mphal.h"
Expand All @@ -37,9 +39,6 @@

#if MICROPY_PY_BLUETOOTH

#define debug_printf(...) // mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)
#define error_printf(...) mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)

uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];

STATIC mp_sched_node_t mp_bluetooth_hci_sched_node;
Expand Down
5 changes: 2 additions & 3 deletions ports/rp2/mpbthciport.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* THE SOFTWARE.
*/

// #define DO_PRINTF (1)

#include "py/runtime.h"
#include "py/stream.h"
#include "py/mphal.h"
Expand All @@ -36,9 +38,6 @@

#if MICROPY_PY_BLUETOOTH

#define debug_printf(...) // mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)
#define error_printf(...) mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)

uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];

// Soft timer and scheduling node for scheduling a HCI poll.
Expand Down
26 changes: 26 additions & 0 deletions py/mpprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,30 @@ 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"

#ifndef DO_PRINTF
#define DO_PRINTF (0)
#endif

#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

0 comments on commit 21bbbd8

Please sign in to comment.