Skip to content

Commit 8c2d04e

Browse files
ak15199dpgeorge
authored andcommitted
esp32/modesp: Add osdebug() function to disable or change IDF logging.
Code lineage: osdebug() is based loosely on the version in esp8266, but there didn't seem to be an obvious way of choosing a particular UART. The basic behavior is the same, though: provide None, and logging is disabled; provide an integer and logging is restored to the default level. To build on that, and because the IDF provides more functionality, a second parameter has now been implemented which allows the active log level to be set: esp.osdebug(uart[, level]) The module has a corresponding set of LOG_ values to set this accordingly.
1 parent 5a5f945 commit 8c2d04e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

ports/esp32/modesp.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <stdio.h>
3131

3232
#include "rom/gpio.h"
33+
#include "esp_log.h"
3334
#include "esp_spi_flash.h"
3435

3536
#include "py/runtime.h"
@@ -38,6 +39,23 @@
3839
#include "drivers/dht/dht.h"
3940
#include "modesp.h"
4041

42+
STATIC mp_obj_t esp_osdebug(size_t n_args, const mp_obj_t *args) {
43+
esp_log_level_t level = LOG_LOCAL_LEVEL;
44+
if (n_args == 2) {
45+
level = mp_obj_get_int(args[1]);
46+
}
47+
if (args[0] == mp_const_none) {
48+
// Disable logging
49+
esp_log_level_set("*", ESP_LOG_ERROR);
50+
} else {
51+
// Enable logging at the given level
52+
// TODO args[0] should set the UART to which debug is sent
53+
esp_log_level_set("*", level);
54+
}
55+
return mp_const_none;
56+
}
57+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_osdebug_obj, 1, 2, esp_osdebug);
58+
4159
STATIC mp_obj_t esp_flash_read(mp_obj_t offset_in, mp_obj_t buf_in) {
4260
mp_int_t offset = mp_obj_get_int(offset_in);
4361
mp_buffer_info_t bufinfo;
@@ -107,6 +125,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_neopixel_write_obj, esp_neopixel_write_);
107125
STATIC const mp_rom_map_elem_t esp_module_globals_table[] = {
108126
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp) },
109127

128+
{ MP_ROM_QSTR(MP_QSTR_osdebug), MP_ROM_PTR(&esp_osdebug_obj) },
129+
110130
{ MP_ROM_QSTR(MP_QSTR_flash_read), MP_ROM_PTR(&esp_flash_read_obj) },
111131
{ MP_ROM_QSTR(MP_QSTR_flash_write), MP_ROM_PTR(&esp_flash_write_obj) },
112132
{ MP_ROM_QSTR(MP_QSTR_flash_erase), MP_ROM_PTR(&esp_flash_erase_obj) },
@@ -118,6 +138,14 @@ STATIC const mp_rom_map_elem_t esp_module_globals_table[] = {
118138

119139
{ MP_ROM_QSTR(MP_QSTR_neopixel_write), MP_ROM_PTR(&esp_neopixel_write_obj) },
120140
{ MP_ROM_QSTR(MP_QSTR_dht_readinto), MP_ROM_PTR(&dht_readinto_obj) },
141+
142+
// Constants for second arg of osdebug()
143+
{ MP_ROM_QSTR(MP_QSTR_LOG_NONE), MP_ROM_INT((mp_uint_t)ESP_LOG_NONE)},
144+
{ MP_ROM_QSTR(MP_QSTR_LOG_ERROR), MP_ROM_INT((mp_uint_t)ESP_LOG_ERROR)},
145+
{ MP_ROM_QSTR(MP_QSTR_LOG_WARNING), MP_ROM_INT((mp_uint_t)ESP_LOG_WARN)},
146+
{ MP_ROM_QSTR(MP_QSTR_LOG_INFO), MP_ROM_INT((mp_uint_t)ESP_LOG_INFO)},
147+
{ MP_ROM_QSTR(MP_QSTR_LOG_DEBUG), MP_ROM_INT((mp_uint_t)ESP_LOG_DEBUG)},
148+
{ MP_ROM_QSTR(MP_QSTR_LOG_VERBOSE), MP_ROM_INT((mp_uint_t)ESP_LOG_VERBOSE)},
121149
};
122150

123151
STATIC MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy