Skip to content

Commit 1034cc1

Browse files
committed
Add espidf module.
1 parent b3a449c commit 1034cc1

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

ports/esp32s2/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ SRC_C += \
166166
background.c \
167167
fatfs_port.c \
168168
mphalport.c \
169+
bindings/espidf/__init__.c \
169170
boards/$(BOARD)/board.c \
170171
boards/$(BOARD)/pins.c \
171172
modules/$(CIRCUITPY_MODULE).c \
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/obj.h"
28+
#include "py/runtime.h"
29+
30+
#include "esp-idf/components/heap/include/esp_heap_caps.h"
31+
32+
//| """Direct access to a few ESP-IDF details. This module *should not* include any functionality
33+
//| that could be implemented by other frameworks. It should only include ESP-IDF specific
34+
//| things."""
35+
36+
//| def heap_caps_get_total_size() -> int:
37+
//| """Return the total size of the ESP-IDF, which includes the CircuitPython heap."""
38+
//| ...
39+
//|
40+
41+
STATIC mp_obj_t espidf_heap_caps_get_total_size(void) {
42+
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_total_size(MALLOC_CAP_8BIT));
43+
}
44+
MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_total_size_obj, espidf_heap_caps_get_total_size);
45+
46+
//| def heap_caps_get_free_size() -> int:
47+
//| """Return total free memory in the ESP-IDF heap."""
48+
//| ...
49+
//|
50+
51+
STATIC mp_obj_t espidf_heap_caps_get_free_size(void) {
52+
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_free_size(MALLOC_CAP_8BIT));
53+
}
54+
MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_free_size_obj, espidf_heap_caps_get_free_size);
55+
56+
//| def heap_caps_get_largest_free_block() -> int:
57+
//| """Return the size of largest free memory block in the ESP-IDF heap."""
58+
//| ...
59+
//|
60+
61+
STATIC mp_obj_t espidf_heap_caps_get_largest_free_block(void) {
62+
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT));
63+
}
64+
MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_heap_caps_get_largest_free_block);
65+
66+
STATIC const mp_rom_map_elem_t espidf_module_globals_table[] = {
67+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_espidf) },
68+
69+
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_total_size), MP_ROM_PTR(&espidf_heap_caps_get_total_size_obj)},
70+
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_free_size), MP_ROM_PTR(&espidf_heap_caps_get_free_size_obj)},
71+
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_largest_free_block), MP_ROM_PTR(&espidf_heap_caps_get_largest_free_block_obj)},
72+
};
73+
74+
STATIC MP_DEFINE_CONST_DICT(espidf_module_globals, espidf_module_globals_table);
75+
76+
const mp_obj_module_t espidf_module = {
77+
.base = { &mp_type_module },
78+
.globals = (mp_obj_dict_t*)&espidf_module_globals,
79+
};

ports/esp32s2/mpconfigport.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ CIRCUITPY_RTC = 0
2525
CIRCUITPY_NVM = 0
2626
CIRCUITPY_USB_MIDI = 0 # We don't have enough endpoints to include MIDI.
2727
CIRCUITPY_WIFI = 1
28+
CIRCUITPY_ESPIDF = 1
2829

2930
CIRCUITPY_MODULE ?= none

py/circuitpy_mpconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ extern const struct _mp_obj_module_t terminalio_module;
363363
#define TERMINALIO_MODULE
364364
#endif
365365

366+
#if CIRCUITPY_ESPIDF
367+
extern const struct _mp_obj_module_t espidf_module;
368+
#define ESPIDF_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_espidf),(mp_obj_t)&espidf_module },
369+
#else
370+
#define ESPIDF_MODULE
371+
#endif
372+
366373
#if CIRCUITPY_FRAMEBUFFERIO
367374
extern const struct _mp_obj_module_t framebufferio_module;
368375
#define FRAMEBUFFERIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_framebufferio), (mp_obj_t)&framebufferio_module },
@@ -750,6 +757,7 @@ extern const struct _mp_obj_module_t wifi_module;
750757
TERMINALIO_MODULE \
751758
VECTORIO_MODULE \
752759
ERRNO_MODULE \
760+
ESPIDF_MODULE \
753761
FRAMEBUFFERIO_MODULE \
754762
FREQUENCYIO_MODULE \
755763
GAMEPAD_MODULE \

py/circuitpy_mpconfig.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
9595
CIRCUITPY_DISPLAYIO ?= $(CIRCUITPY_FULL_BUILD)
9696
CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO)
9797

98+
# CIRCUITPY_ESPIDF is handled in the atmel-samd tree.
99+
# Only for ESP32S chips.
100+
# Assume not a ESP build.
101+
CIRCUITPY_ESPIDF ?= 0
102+
CFLAGS += -DCIRCUITPY_ESPIDF=$(CIRCUITPY_ESPIDF)
103+
98104
ifeq ($(CIRCUITPY_DISPLAYIO),1)
99105
CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD)
100106
else

0 commit comments

Comments
 (0)