summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-08-14 15:56:01 -0700
committerScott Shawcroft <scott@tannewt.org>2020-08-19 14:23:28 -0700
commit1034cc12177d998df1c7f3381668040bb13ced58 (patch)
tree2390d7bf2d8b0520e93d4d21128b29afd9214688
parentb3a449c2764f25a3c4becdbbed47e02ca36f755b (diff)
Add espidf module.
-rw-r--r--ports/esp32s2/Makefile1
-rw-r--r--ports/esp32s2/bindings/espidf/__init__.c79
-rw-r--r--ports/esp32s2/mpconfigport.mk1
-rw-r--r--py/circuitpy_mpconfig.h8
-rw-r--r--py/circuitpy_mpconfig.mk6
5 files changed, 95 insertions, 0 deletions
diff --git a/ports/esp32s2/Makefile b/ports/esp32s2/Makefile
index 142387f63..ea9c68592 100644
--- a/ports/esp32s2/Makefile
+++ b/ports/esp32s2/Makefile
@@ -166,6 +166,7 @@ SRC_C += \
background.c \
fatfs_port.c \
mphalport.c \
+ bindings/espidf/__init__.c \
boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.c \
modules/$(CIRCUITPY_MODULE).c \
diff --git a/ports/esp32s2/bindings/espidf/__init__.c b/ports/esp32s2/bindings/espidf/__init__.c
new file mode 100644
index 000000000..11df76ec0
--- /dev/null
+++ b/ports/esp32s2/bindings/espidf/__init__.c
@@ -0,0 +1,79 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "py/obj.h"
+#include "py/runtime.h"
+
+#include "esp-idf/components/heap/include/esp_heap_caps.h"
+
+//| """Direct access to a few ESP-IDF details. This module *should not* include any functionality
+//| that could be implemented by other frameworks. It should only include ESP-IDF specific
+//| things."""
+
+//| def heap_caps_get_total_size() -> int:
+//| """Return the total size of the ESP-IDF, which includes the CircuitPython heap."""
+//| ...
+//|
+
+STATIC mp_obj_t espidf_heap_caps_get_total_size(void) {
+ return MP_OBJ_NEW_SMALL_INT(heap_caps_get_total_size(MALLOC_CAP_8BIT));
+}
+MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_total_size_obj, espidf_heap_caps_get_total_size);
+
+//| def heap_caps_get_free_size() -> int:
+//| """Return total free memory in the ESP-IDF heap."""
+//| ...
+//|
+
+STATIC mp_obj_t espidf_heap_caps_get_free_size(void) {
+ return MP_OBJ_NEW_SMALL_INT(heap_caps_get_free_size(MALLOC_CAP_8BIT));
+}
+MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_free_size_obj, espidf_heap_caps_get_free_size);
+
+//| def heap_caps_get_largest_free_block() -> int:
+//| """Return the size of largest free memory block in the ESP-IDF heap."""
+//| ...
+//|
+
+STATIC mp_obj_t espidf_heap_caps_get_largest_free_block(void) {
+ return MP_OBJ_NEW_SMALL_INT(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT));
+}
+MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_heap_caps_get_largest_free_block);
+
+STATIC const mp_rom_map_elem_t espidf_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_espidf) },
+
+ { MP_ROM_QSTR(MP_QSTR_heap_caps_get_total_size), MP_ROM_PTR(&espidf_heap_caps_get_total_size_obj)},
+ { MP_ROM_QSTR(MP_QSTR_heap_caps_get_free_size), MP_ROM_PTR(&espidf_heap_caps_get_free_size_obj)},
+ { MP_ROM_QSTR(MP_QSTR_heap_caps_get_largest_free_block), MP_ROM_PTR(&espidf_heap_caps_get_largest_free_block_obj)},
+};
+
+STATIC MP_DEFINE_CONST_DICT(espidf_module_globals, espidf_module_globals_table);
+
+const mp_obj_module_t espidf_module = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&espidf_module_globals,
+};
diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk
index 62d2da607..525271438 100644
--- a/ports/esp32s2/mpconfigport.mk
+++ b/ports/esp32s2/mpconfigport.mk
@@ -25,5 +25,6 @@ CIRCUITPY_RTC = 0
CIRCUITPY_NVM = 0
CIRCUITPY_USB_MIDI = 0 # We don't have enough endpoints to include MIDI.
CIRCUITPY_WIFI = 1
+CIRCUITPY_ESPIDF = 1
CIRCUITPY_MODULE ?= none
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h
index b2543dcad..b3fd8a05d 100644
--- a/py/circuitpy_mpconfig.h
+++ b/py/circuitpy_mpconfig.h
@@ -363,6 +363,13 @@ extern const struct _mp_obj_module_t terminalio_module;
#define TERMINALIO_MODULE
#endif
+#if CIRCUITPY_ESPIDF
+extern const struct _mp_obj_module_t espidf_module;
+#define ESPIDF_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_espidf),(mp_obj_t)&espidf_module },
+#else
+#define ESPIDF_MODULE
+#endif
+
#if CIRCUITPY_FRAMEBUFFERIO
extern const struct _mp_obj_module_t framebufferio_module;
#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;
TERMINALIO_MODULE \
VECTORIO_MODULE \
ERRNO_MODULE \
+ ESPIDF_MODULE \
FRAMEBUFFERIO_MODULE \
FREQUENCYIO_MODULE \
GAMEPAD_MODULE \
diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk
index 8b34dced2..b6fd805d3 100644
--- a/py/circuitpy_mpconfig.mk
+++ b/py/circuitpy_mpconfig.mk
@@ -95,6 +95,12 @@ CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
CIRCUITPY_DISPLAYIO ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO)
+# CIRCUITPY_ESPIDF is handled in the atmel-samd tree.
+# Only for ESP32S chips.
+# Assume not a ESP build.
+CIRCUITPY_ESPIDF ?= 0
+CFLAGS += -DCIRCUITPY_ESPIDF=$(CIRCUITPY_ESPIDF)
+
ifeq ($(CIRCUITPY_DISPLAYIO),1)
CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD)
else