Skip to content

Commit b6f8df9

Browse files
committed
feat(modules): add esp_memory
1 parent 2e541ad commit b6f8df9

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

modules/esp_memory/esp_memory.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "string.h"
2+
#include "esp_heap_caps.h"
3+
#include "py/runtime.h"
4+
5+
static mp_obj_t esp_memory_print_summary(void) {
6+
char buffer[128];
7+
sprintf(buffer,
8+
" Biggest / Free / Total\n"
9+
" SRAM : [%8d / %8d / %8d]\n"
10+
"PSRAM : [%8d / %8d / %8d]",
11+
(int)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL),
12+
(int)heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
13+
(int)heap_caps_get_total_size(MALLOC_CAP_INTERNAL),
14+
(int)heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM),
15+
(int)heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
16+
(int)heap_caps_get_total_size(MALLOC_CAP_SPIRAM));
17+
printf("%s\n", buffer);
18+
19+
return mp_const_none;
20+
}
21+
static MP_DEFINE_CONST_FUN_OBJ_0(esp_memory_print_summary_obj, esp_memory_print_summary);
22+
23+
static const mp_rom_map_elem_t esp_memory_module_globals_table[] = {
24+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp_memory) },
25+
{ MP_ROM_QSTR(MP_QSTR_print_summary), MP_ROM_PTR(&esp_memory_print_summary_obj) },
26+
};
27+
static MP_DEFINE_CONST_DICT(esp_memory_module_globals, esp_memory_module_globals_table);
28+
29+
// Define module object.
30+
const mp_obj_module_t esp_memory_module = {
31+
.base = { &mp_type_module },
32+
.globals = (mp_obj_dict_t *)&esp_memory_module_globals,
33+
};
34+
35+
// Register the module to make it available in Python.
36+
MP_REGISTER_MODULE(MP_QSTR_esp_memory, esp_memory_module);

modules/esp_memory/micropython.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Create an INTERFACE library for our C module.
2+
add_library(usermod_esp_memory INTERFACE)
3+
4+
# Add our source files to the lib
5+
target_sources(usermod_esp_memory INTERFACE
6+
${CMAKE_CURRENT_LIST_DIR}/esp_memory.c
7+
)
8+
9+
# Add the current directory as an include directory.
10+
target_include_directories(usermod_esp_memory INTERFACE
11+
${CMAKE_CURRENT_LIST_DIR}
12+
)
13+
14+
# Link our INTERFACE library to the usermod target.
15+
target_link_libraries(usermod INTERFACE usermod_esp_memory)

modules/micropython.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
# used to prefix subdirectories.
55

66
include(${CMAKE_CURRENT_LIST_DIR}/lv_binding_micropython/micropython.cmake)
7+
8+
if(ESP_PLATFORM)
9+
include(${CMAKE_CURRENT_LIST_DIR}/esp_memory/micropython.cmake)
10+
endif()

0 commit comments

Comments
 (0)