From 4cb1332b24c1f543c8e6fe5508f9f03bb605c183 Mon Sep 17 00:00:00 2001 From: Serge Bazanski <q3k@q3k.org> Date: Tue, 4 Jul 2023 01:47:33 +0200 Subject: [PATCH] micropython: limit access to safe GPIOs Hacking on things is fun, but accidentally doing machine.Pin(1337).on() and frying your flow3r isn't. Especially if you're just copypasting code from the Internet. We might add some escape hatch for this later for board experimentation/testing/debugging..? --- components/flow3r_bsp/Kconfig | 7 ++ .../micropython/include/mpconfigboard.h | 2 + .../vendor/ports/esp32/machine_pin.c | 100 ++++++++++++++++++ 3 files changed, 109 insertions(+) diff --git a/components/flow3r_bsp/Kconfig b/components/flow3r_bsp/Kconfig index 06f539f6a8..25cebf3afe 100644 --- a/components/flow3r_bsp/Kconfig +++ b/components/flow3r_bsp/Kconfig @@ -9,23 +9,27 @@ menu "Flow3r Config" - No line in/out jacks - White bottom board - USB-C jack points side of leaf + select FLOW3R_ESP32S3 bool "Prototype 1" config FLOW3R_HW_GEN_P3 help Prototype version 3, a.k.a. proto3 Visual identifiers: - Sticker with B3xx (xx being arbitrary digits) on the back + select FLOW3R_ESP32S3 bool "Prototype 3" config FLOW3R_HW_GEN_P4 help Prototype version 4, a.k.a. proto4 Visual identifiers: - Sticker with B4xx (xx being arbitrary digits) on the back + select FLOW3R_ESP32S3 bool "Prototype 4" config FLOW3R_HW_GEN_P6 help Prototype version 6, a.k.a. proto6 - Sticker with B6xx (xx being arbitrary digits) on the back + select FLOW3R_ESP32S3 bool "Prototype 6" endchoice @@ -42,4 +46,7 @@ menu "Flow3r Config" bool "Spirals" endchoice + config FLOW3R_ESP32S3 + bool + endmenu diff --git a/components/micropython/include/mpconfigboard.h b/components/micropython/include/mpconfigboard.h index 6850b8f38e..fab8e7180c 100644 --- a/components/micropython/include/mpconfigboard.h +++ b/components/micropython/include/mpconfigboard.h @@ -6,6 +6,8 @@ #define MICROPY_PY_MACHINE_PWM (1) #define MICROPY_HW_I2C0_SCL (9) #define MICROPY_HW_I2C0_SDA (8) +#define MICROPY_HW_ESP32S3_EXTENDED_IO (0) + #define MICROPY_ESP_IDF_4 1 #define MICROPY_VFS_POSIX 1 diff --git a/components/micropython/vendor/ports/esp32/machine_pin.c b/components/micropython/vendor/ports/esp32/machine_pin.c index 5ea41701af..b764a37361 100644 --- a/components/micropython/vendor/ports/esp32/machine_pin.c +++ b/components/micropython/vendor/ports/esp32/machine_pin.c @@ -144,6 +144,56 @@ STATIC const machine_pin_obj_t machine_pin_obj[GPIO_NUM_MAX] = { {{&machine_pin_type}, GPIO_NUM_20}, {{&machine_pin_type}, GPIO_NUM_21}, + #elif CONFIG_FLOW3R_ESP32S3 + + {{NULL}, -1}, // 0 + {{NULL}, -1}, // 1 + {{NULL}, -1}, // 2 + {{NULL}, -1}, // 3 + {{&machine_pin_type}, GPIO_NUM_4}, // Badgelink + {{&machine_pin_type}, GPIO_NUM_5}, // Badgelink + {{&machine_pin_type}, GPIO_NUM_6}, // Badgelink + {{&machine_pin_type}, GPIO_NUM_7}, // Badgelink + {{NULL}, -1}, // 8 + {{NULL}, -1}, // 9 + {{NULL}, -1}, // 10 + {{NULL}, -1}, // 11 + {{NULL}, -1}, // 12 + {{NULL}, -1}, // 13 + {{NULL}, -1}, // 14 + {{NULL}, -1}, // 15 + {{NULL}, -1}, // 16 + {{&machine_pin_type}, GPIO_NUM_17}, // QWIIC + {{NULL}, -1}, // 18 + {{NULL}, -1}, // 19 + {{NULL}, -1}, // 20 + {{NULL}, -1}, // 21 + {{NULL}, -1}, // 22 + {{NULL}, -1}, // 23 + {{NULL}, -1}, // 24 + {{NULL}, -1}, // 25 + {{NULL}, -1}, // 26 + {{NULL}, -1}, // 27 + {{NULL}, -1}, // 28 + {{NULL}, -1}, // 29 + {{NULL}, -1}, // 30 + {{NULL}, -1}, // 31 + {{NULL}, -1}, // 32 + {{NULL}, -1}, // 33 + {{NULL}, -1}, // 34 + {{NULL}, -1}, // 35 + {{NULL}, -1}, // 36 + {{NULL}, -1}, // 37 + {{NULL}, -1}, // 38 + {{NULL}, -1}, // 39 + {{NULL}, -1}, // 40 + {{NULL}, -1}, // 41 + {{NULL}, -1}, // 42 + {{NULL}, -1}, // 43 + {{NULL}, -1}, // 44 + {{&machine_pin_type}, GPIO_NUM_45}, // QWIIC + {{NULL}, -1}, // 46 + #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 {{&machine_pin_type}, GPIO_NUM_0}, @@ -616,6 +666,56 @@ STATIC const machine_pin_irq_obj_t machine_pin_irq_object[GPIO_NUM_MAX] = { {{&machine_pin_irq_type}, GPIO_NUM_20}, {{&machine_pin_irq_type}, GPIO_NUM_21}, + #elif CONFIG_FLOW3R_ESP32S3 + + {{NULL}, -1}, // 0 + {{NULL}, -1}, // 1 + {{NULL}, -1}, // 2 + {{NULL}, -1}, // 3 + {{&machine_pin_irq_type}, GPIO_NUM_4}, // Badgelink + {{&machine_pin_irq_type}, GPIO_NUM_5}, // Badgelink + {{&machine_pin_irq_type}, GPIO_NUM_6}, // Badgelink + {{&machine_pin_irq_type}, GPIO_NUM_7}, // Badgelink + {{NULL}, -1}, // 8 + {{NULL}, -1}, // 9 + {{NULL}, -1}, // 10 + {{NULL}, -1}, // 11 + {{NULL}, -1}, // 12 + {{NULL}, -1}, // 13 + {{NULL}, -1}, // 14 + {{NULL}, -1}, // 15 + {{NULL}, -1}, // 16 + {{&machine_pin_irq_type}, GPIO_NUM_17}, // QWIIC + {{NULL}, -1}, // 18 + {{NULL}, -1}, // 19 + {{NULL}, -1}, // 20 + {{NULL}, -1}, // 21 + {{NULL}, -1}, // 22 + {{NULL}, -1}, // 23 + {{NULL}, -1}, // 24 + {{NULL}, -1}, // 25 + {{NULL}, -1}, // 26 + {{NULL}, -1}, // 27 + {{NULL}, -1}, // 28 + {{NULL}, -1}, // 29 + {{NULL}, -1}, // 30 + {{NULL}, -1}, // 31 + {{NULL}, -1}, // 32 + {{NULL}, -1}, // 33 + {{NULL}, -1}, // 34 + {{NULL}, -1}, // 35 + {{NULL}, -1}, // 36 + {{NULL}, -1}, // 37 + {{NULL}, -1}, // 38 + {{NULL}, -1}, // 39 + {{NULL}, -1}, // 40 + {{NULL}, -1}, // 41 + {{NULL}, -1}, // 42 + {{NULL}, -1}, // 43 + {{NULL}, -1}, // 44 + {{&machine_pin_irq_type}, GPIO_NUM_45}, // QWIIC + {{NULL}, -1}, // 46 + #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 {{&machine_pin_irq_type}, GPIO_NUM_0}, -- GitLab