From d7edec67ce2b405e7bf91f5b1d5e9d3b5ff5ab58 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 5 Sep 2023 14:31:08 -0700 Subject: [PATCH 01/42] 8.2.x backport Added Arduino Nano ESP32-S3 --- .../boards/arduino_nano_esp32s3/board.c | 51 +++++++++++++++ .../arduino_nano_esp32s3/mpconfigboard.h | 57 +++++++++++++++++ .../arduino_nano_esp32s3/mpconfigboard.mk | 17 +++++ .../boards/arduino_nano_esp32s3/pins.c | 64 +++++++++++++++++++ .../boards/arduino_nano_esp32s3/sdkconfig | 43 +++++++++++++ .../board.c | 51 +++++++++++++++ .../mpconfigboard.h | 54 ++++++++++++++++ .../mpconfigboard.mk | 17 +++++ .../pins.c | 64 +++++++++++++++++++ .../sdkconfig | 43 +++++++++++++ tools/ci_check_duplicate_usb_vid_pid.py | 2 + 11 files changed, 463 insertions(+) create mode 100644 ports/espressif/boards/arduino_nano_esp32s3/board.c create mode 100644 ports/espressif/boards/arduino_nano_esp32s3/mpconfigboard.h create mode 100644 ports/espressif/boards/arduino_nano_esp32s3/mpconfigboard.mk create mode 100644 ports/espressif/boards/arduino_nano_esp32s3/pins.c create mode 100644 ports/espressif/boards/arduino_nano_esp32s3/sdkconfig create mode 100644 ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/board.c create mode 100644 ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/mpconfigboard.h create mode 100644 ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/mpconfigboard.mk create mode 100644 ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/pins.c create mode 100644 ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig diff --git a/ports/espressif/boards/arduino_nano_esp32s3/board.c b/ports/espressif/boards/arduino_nano_esp32s3/board.c new file mode 100644 index 0000000000..8952a19c5d --- /dev/null +++ b/ports/espressif/boards/arduino_nano_esp32s3/board.c @@ -0,0 +1,51 @@ +/* + * 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 "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "components/driver/include/driver/gpio.h" + +void board_init(void) { + // Debug UART + #ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + #endif +} + +bool espressif_board_reset_pin_number(gpio_num_t pin_number) { + if (pin_number == 13) { + // Set D13 LED to input when not in use + gpio_set_direction(pin_number, GPIO_MODE_DEF_INPUT); + gpio_set_pull_mode(pin_number, GPIO_PULLDOWN_ONLY); + return true; + } + + return false; +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/arduino_nano_esp32s3/mpconfigboard.h b/ports/espressif/boards/arduino_nano_esp32s3/mpconfigboard.h new file mode 100644 index 0000000000..7c046d9b72 --- /dev/null +++ b/ports/espressif/boards/arduino_nano_esp32s3/mpconfigboard.h @@ -0,0 +1,57 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + */ + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "Arduino Nano ESP32" +#define MICROPY_HW_MCU_NAME "ESP32S3" + +// Status LED +#define CIRCUITPY_RGB_STATUS_INVERTED_PWM +#define CIRCUITPY_RGB_STATUS_R (&pin_GPIO46) +#define CIRCUITPY_RGB_STATUS_G (&pin_GPIO0) +#define CIRCUITPY_RGB_STATUS_B (&pin_GPIO45) + +#define MICROPY_HW_LED_STATUS (&pin_GPIO13) + +#if QSPI_FLASH_FILESYSTEM +#define MICROPY_QSPI_DATA0 (&pin_GPIO32) +#define MICROPY_QSPI_DATA1 (&pin_GPIO31) +#define MICROPY_QSPI_DATA2 (&pin_GPIO28) +#define MICROPY_QSPI_DATA3 (&pin_GPIO27) +#define MICROPY_QSPI_SCK (&pin_GPIO30) +#define MICROPY_QSPI_CS (&pin_GPIO29) +#endif + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO12) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO11) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO48) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO38) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO47) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO44) +#define DEFAULT_UART_BUS_TX (&pin_GPIO43) diff --git a/ports/espressif/boards/arduino_nano_esp32s3/mpconfigboard.mk b/ports/espressif/boards/arduino_nano_esp32s3/mpconfigboard.mk new file mode 100644 index 0000000000..c9af3af25e --- /dev/null +++ b/ports/espressif/boards/arduino_nano_esp32s3/mpconfigboard.mk @@ -0,0 +1,17 @@ +USB_VID = 0x2341 +USB_PID = 0x0070 + +USB_PRODUCT = "Arduino Nano ESP32" +USB_MANUFACTURER = "Arduino" + +IDF_TARGET = esp32s3 + +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 8MB + +INTERNAL_FLASH_FILESYSTEM = 0 +QSPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICES = GD25WQ128E + +CIRCUITPY_ESPCAMERA = 0 diff --git a/ports/espressif/boards/arduino_nano_esp32s3/pins.c b/ports/espressif/boards/arduino_nano_esp32s3/pins.c new file mode 100644 index 0000000000..ca56c8900c --- /dev/null +++ b/ports/espressif/boards/arduino_nano_esp32s3/pins.c @@ -0,0 +1,64 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_B0), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_B1), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO21) }, + + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO38) }, + + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO47) }, + + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO48) }, + + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO2) }, + + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_GPIO4) }, + + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO11) }, + + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO12) }, + + { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO13) }, + + { MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_GPIO14) }, + + { MP_ROM_QSTR(MP_QSTR_LED_R), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_LED_G), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_LED_B), MP_ROM_PTR(&pin_GPIO45) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig b/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig new file mode 100644 index 0000000000..2acf08a4a7 --- /dev/null +++ b/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig @@ -0,0 +1,43 @@ +# +# Component config +# +# +# ESP32S3-Specific +# +CONFIG_ESP32S3_SPIRAM_SUPPORT=y + +# +# SPI RAM config +# +# CONFIG_SPIRAM_MODE_QUAD is not set +CONFIG_SPIRAM_MODE_OCT=y +# CONFIG_SPIRAM_TYPE_AUTO is not set +CONFIG_SPIRAM_TYPE_ESPPSRAM64=y +CONFIG_SPIRAM_SIZE=8388608 +# +# PSRAM Clock and CS IO for ESP32S3 +# +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM Clock and CS IO for ESP32S3 + +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +CONFIG_SPIRAM_SPEED_80M=y +# CONFIG_SPIRAM_SPEED_40M is not set +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# end of SPI RAM config + +# end of ESP32S3-Specific + +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# end of LWIP diff --git a/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/board.c b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/board.c new file mode 100644 index 0000000000..8952a19c5d --- /dev/null +++ b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/board.c @@ -0,0 +1,51 @@ +/* + * 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 "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "components/driver/include/driver/gpio.h" + +void board_init(void) { + // Debug UART + #ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + #endif +} + +bool espressif_board_reset_pin_number(gpio_num_t pin_number) { + if (pin_number == 13) { + // Set D13 LED to input when not in use + gpio_set_direction(pin_number, GPIO_MODE_DEF_INPUT); + gpio_set_pull_mode(pin_number, GPIO_PULLDOWN_ONLY); + return true; + } + + return false; +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/mpconfigboard.h b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/mpconfigboard.h new file mode 100644 index 0000000000..4d4adcf1cb --- /dev/null +++ b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/mpconfigboard.h @@ -0,0 +1,54 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + */ + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "Arduino Nano ESP32" +#define MICROPY_HW_MCU_NAME "ESP32S3" + +// Status LED +#define CIRCUITPY_RGB_STATUS_INVERTED_PWM +#define CIRCUITPY_RGB_STATUS_R (&pin_GPIO46) +#define CIRCUITPY_RGB_STATUS_G (&pin_GPIO45) +#define CIRCUITPY_RGB_STATUS_B (&pin_GPIO0) + +#define MICROPY_HW_LED_STATUS (&pin_GPIO13) + +#if QSPI_FLASH_FILESYSTEM +#define MICROPY_QSPI_DATA0 (&pin_GPIO32) +#define MICROPY_QSPI_DATA1 (&pin_GPIO31) +#define MICROPY_QSPI_DATA2 (&pin_GPIO28) +#define MICROPY_QSPI_DATA3 (&pin_GPIO27) +#define MICROPY_QSPI_SCK (&pin_GPIO30) +#define MICROPY_QSPI_CS (&pin_GPIO29) +#endif + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO12) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO11) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO48) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO38) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO47) diff --git a/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/mpconfigboard.mk b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/mpconfigboard.mk new file mode 100644 index 0000000000..925c4ab6e2 --- /dev/null +++ b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/mpconfigboard.mk @@ -0,0 +1,17 @@ +USB_VID = 0x2341 +USB_PID = 0x056B + +USB_PRODUCT = "Arduino Nano ESP32" +USB_MANUFACTURER = "Arduino" + +IDF_TARGET = esp32s3 + +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 8MB + +INTERNAL_FLASH_FILESYSTEM = 0 +QSPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICES = GD25WQ128E + +CIRCUITPY_ESPCAMERA = 0 diff --git a/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/pins.c b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/pins.c new file mode 100644 index 0000000000..aa89a58ee4 --- /dev/null +++ b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/pins.c @@ -0,0 +1,64 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_B0), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_B1), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO21) }, + + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO38) }, + + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO47) }, + + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO48) }, + + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO2) }, + + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_GPIO4) }, + + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO11) }, + + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO12) }, + + { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO13) }, + + { MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_GPIO14) }, + + { MP_ROM_QSTR(MP_QSTR_LED_R), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_LED_G), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_LED_B), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig new file mode 100644 index 0000000000..26a26b5fe8 --- /dev/null +++ b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig @@ -0,0 +1,43 @@ +# +# Component config +# +# +# ESP32S3-Specific +# +CONFIG_ESP32S3_SPIRAM_SUPPORT=y + +# +# SPI RAM config +# +# CONFIG_SPIRAM_MODE_QUAD is not set +CONFIG_SPIRAM_MODE_OCT=y +# CONFIG_SPIRAM_TYPE_AUTO is not set +CONFIG_SPIRAM_TYPE_ESPPSRAM64=y +CONFIG_SPIRAM_SIZE=8388608 +# +# PSRAM Clock and CS IO for ESP32S3 +# +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM Clock and CS IO for ESP32S3 + +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +CONFIG_SPIRAM_SPEED_80M=y +# CONFIG_SPIRAM_SPEED_40M is not set +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# end of SPI RAM config + +# end of ESP32S3-Specific + +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="nano-esp32" +# end of LWIP diff --git a/tools/ci_check_duplicate_usb_vid_pid.py b/tools/ci_check_duplicate_usb_vid_pid.py index f20630e886..f22225007b 100644 --- a/tools/ci_check_duplicate_usb_vid_pid.py +++ b/tools/ci_check_duplicate_usb_vid_pid.py @@ -63,6 +63,8 @@ DEFAULT_CLUSTERLIST = { ], "0x239A:0x102E": ["weact_studio_pico", "weact_studio_pico_16mb"], "0x303A:0x8166": ["yd_esp32_s3_n8r8", "yd_esp32_s3_n16r8"], + "0x2341:0x056B": ["arduino_nano_esp32s3", "arduino_nano_esp32s3_inverted_statusled"], + "0x2E8A:0x1020": ["waveshare_rp2040_plus_4mb", "waveshare_rp2040_plus_16mb"], } cli_parser = argparse.ArgumentParser( From d871bc37c560db18971c3eea4e3d0ce043f95721 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 6 Sep 2023 15:49:51 -0400 Subject: [PATCH 02/42] remove lib/certificates/nina-fw submodule --- .gitmodules | 3 --- lib/certificates/README.md | 3 --- lib/certificates/nina-fw | 1 - 3 files changed, 7 deletions(-) delete mode 100644 lib/certificates/README.md delete mode 160000 lib/certificates/nina-fw diff --git a/.gitmodules b/.gitmodules index 7cb54a92dc..4ddbc618b7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -144,9 +144,6 @@ path = ports/espressif/esp-idf url = https://github.com/adafruit/esp-idf.git branch = release/v4.4-circuitpython -[submodule "ports/espressif/certificates/nina-fw"] - path = lib/certificates/nina-fw - url = https://github.com/adafruit/nina-fw.git [submodule "frozen/Adafruit_CircuitPython_ST7789"] path = frozen/Adafruit_CircuitPython_ST7789 url = https://github.com/adafruit/Adafruit_CircuitPython_ST7789 diff --git a/lib/certificates/README.md b/lib/certificates/README.md deleted file mode 100644 index dd5cf25b00..0000000000 --- a/lib/certificates/README.md +++ /dev/null @@ -1,3 +0,0 @@ -We share root certificates with the nina-fw to ensure they both use the same roots. - -https://github.com/adafruit/nina-fw diff --git a/lib/certificates/nina-fw b/lib/certificates/nina-fw deleted file mode 160000 index 21205e4005..0000000000 --- a/lib/certificates/nina-fw +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 21205e400515a698266abaaea902bd1ea897bb5d From 58a21326b2da50ad47d14c353f884f8d5213541b Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 6 Sep 2023 16:22:42 -0400 Subject: [PATCH 03/42] Update to new certificates submodule. --- .gitmodules | 3 +++ lib/certificates | 1 + ports/espressif/esp-idf-config/sdkconfig-esp32.defaults | 2 +- ports/espressif/esp-idf-config/sdkconfig.defaults | 2 +- ports/raspberrypi/Makefile | 2 +- tools/ci_fetch_deps.py | 4 ++-- 6 files changed, 9 insertions(+), 5 deletions(-) create mode 160000 lib/certificates diff --git a/.gitmodules b/.gitmodules index 4ddbc618b7..e4b59e8e42 100644 --- a/.gitmodules +++ b/.gitmodules @@ -338,3 +338,6 @@ [submodule "frozen/Adafruit_CircuitPython_Wave"] path = frozen/Adafruit_CircuitPython_Wave url = https://github.com/adafruit/Adafruit_CircuitPython_Wave.git +[submodule "lib/certificates"] + path = lib/certificates + url = https://github.com/adafruit/certificates diff --git a/lib/certificates b/lib/certificates new file mode 160000 index 0000000000..5c85c604a0 --- /dev/null +++ b/lib/certificates @@ -0,0 +1 @@ +Subproject commit 5c85c604a0d77a08df93435e4afad5f541c38923 diff --git a/ports/espressif/esp-idf-config/sdkconfig-esp32.defaults b/ports/espressif/esp-idf-config/sdkconfig-esp32.defaults index b6c5a938b1..54e800cd62 100644 --- a/ports/espressif/esp-idf-config/sdkconfig-esp32.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig-esp32.defaults @@ -776,7 +776,7 @@ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y # CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN is not set CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_NONE=y CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE=y -CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH="../../lib/certificates/nina-fw/data/roots.pem" +CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH="../../lib/certificates/data/roots.pem" # end of Certificate Bundle CONFIG_MBEDTLS_ECP_RESTARTABLE=y diff --git a/ports/espressif/esp-idf-config/sdkconfig.defaults b/ports/espressif/esp-idf-config/sdkconfig.defaults index b183cd630d..b27d846f2c 100644 --- a/ports/espressif/esp-idf-config/sdkconfig.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig.defaults @@ -572,7 +572,7 @@ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y # CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN is not set CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_NONE=y CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE=y -CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH="../../lib/certificates/nina-fw/data/roots.pem" +CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH="../../lib/certificates/data/roots.pem" # end of Certificate Bundle CONFIG_MBEDTLS_ECP_RESTARTABLE=y diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index 7eb67b77ba..e6cbcfbbce 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -345,7 +345,7 @@ CFLAGS += \ -isystem $(TOP)/lib/mbedtls/include \ -DMBEDTLS_CONFIG_FILE='"mbedtls/mbedtls_config.h"' \ -$(BUILD)/x509_crt_bundle.S: $(TOP)/lib/certificates/nina-fw/data/roots.pem $(TOP)/tools/gen_crt_bundle.py +$(BUILD)/x509_crt_bundle.S: $(TOP)/lib/certificates/data/roots.pem $(TOP)/tools/gen_crt_bundle.py $(Q)$(PYTHON) $(TOP)/tools/gen_crt_bundle.py -i $< -o $@ --asm OBJ_MBEDTLS := $(BUILD)/x509_crt_bundle.o $(patsubst %.c,$(BUILD)/%.o,$(SRC_MBEDTLS))): CFLAGS += -Wno-suggest-attribute=format diff --git a/tools/ci_fetch_deps.py b/tools/ci_fetch_deps.py index 15ef6a51cd..30ab7ca5a4 100644 --- a/tools/ci_fetch_deps.py +++ b/tools/ci_fetch_deps.py @@ -24,7 +24,7 @@ PORT_DEPS = { "cxd56": ["extmod/ulab/", "lib/tinyusb/"], "espressif": [ "extmod/ulab/", - "lib/certificates/nina-fw/", + "lib/certificates/", "lib/protomatter/", "lib/quirc/", "lib/tinyusb/", @@ -37,7 +37,7 @@ PORT_DEPS = { "lib/adafruit_floppy/", "lib/mbedtls/", "lib/mp3/", - "lib/certificates/nina-fw/", + "lib/certificates/", "lib/protomatter/", "lib/quirc/", "lib/tinyusb/", From e71c39736e05d599918749a1e81d731218180bde Mon Sep 17 00:00:00 2001 From: Seon Rozenblum Date: Thu, 7 Sep 2023 12:13:37 +1000 Subject: [PATCH 04/42] Added UM FeatherS3 second I2C STEMMAQT --- .../unexpectedmaker_feathers3/mpconfigboard.h | 5 +-- .../boards/unexpectedmaker_feathers3/pins.c | 32 +++++++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ports/espressif/boards/unexpectedmaker_feathers3/mpconfigboard.h b/ports/espressif/boards/unexpectedmaker_feathers3/mpconfigboard.h index 67054b8664..1d51cb77d9 100644 --- a/ports/espressif/boards/unexpectedmaker_feathers3/mpconfigboard.h +++ b/ports/espressif/boards/unexpectedmaker_feathers3/mpconfigboard.h @@ -34,8 +34,9 @@ #define MICROPY_HW_LED_STATUS (&pin_GPIO13) -#define DEFAULT_I2C_BUS_SCL (&pin_GPIO9) -#define DEFAULT_I2C_BUS_SDA (&pin_GPIO8) +#define CIRCUITPY_BOARD_I2C (2) +#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO9, .sda = &pin_GPIO8}, \ + {.scl = &pin_GPIO15, .sda = &pin_GPIO16}} #define DEFAULT_SPI_BUS_SCK (&pin_GPIO36) #define DEFAULT_SPI_BUS_MOSI (&pin_GPIO35) diff --git a/ports/espressif/boards/unexpectedmaker_feathers3/pins.c b/ports/espressif/boards/unexpectedmaker_feathers3/pins.c index 9a2fde5a0c..5cdfc69ed2 100644 --- a/ports/espressif/boards/unexpectedmaker_feathers3/pins.c +++ b/ports/espressif/boards/unexpectedmaker_feathers3/pins.c @@ -1,5 +1,7 @@ #include "shared-bindings/board/__init__.h" +CIRCUITPY_BOARD_BUS_SINGLETON(stemma_i2c, i2c, 1) + STATIC const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS @@ -89,11 +91,16 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO11) }, { MP_ROM_QSTR(MP_QSTR_A10), MP_ROM_PTR(&pin_GPIO11) }, - { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) }, // Blue LED + // Blue LED + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) }, + + // STEMMA QT Vertical Connector I2C IO + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_SCL2), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_SDA2), MP_ROM_PTR(&pin_GPIO16) }, // Battery voltage sense pin - // I really don't know what name to use here. Adafruit use BATTERY & VOLTAGE_MONITOR - // I prefer VBAT or VBAT_SENSE { MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO2) }, { MP_ROM_QSTR(MP_QSTR_VBAT), MP_ROM_PTR(&pin_GPIO2) }, { MP_ROM_QSTR(MP_QSTR_VBAT_SENSE), MP_ROM_PTR(&pin_GPIO2) }, @@ -103,18 +110,29 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_VBUS), MP_ROM_PTR(&pin_GPIO34) }, { MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_GPIO34) }, + // Neopixel pins { MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO39) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO40) }, - { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, // Ambient Light Sensor - { MP_ROM_QSTR(MP_QSTR_AMB), MP_ROM_PTR(&pin_GPIO4) }, // Ambient Light Sensor + // Ambient Light Sensor + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_AMB), MP_ROM_PTR(&pin_GPIO4) }, - { MP_ROM_QSTR(MP_QSTR_LDO2), MP_ROM_PTR(&pin_GPIO39) }, // Second LDO Enable control - { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, // Second LDO Enable control + // Second LDO Enable control + { MP_ROM_QSTR(MP_QSTR_LDO2), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, + // I2C { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_STEMMA_VERTICAL_I2C), MP_ROM_PTR(&board_stemma_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C2), MP_ROM_PTR(&board_stemma_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_I2C2), MP_ROM_PTR(&board_stemma_i2c_obj) }, + + // SPI { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + + // UART { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From c5bc59e692ddc91fd442bc29979c4ea0c9c20728 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 7 Sep 2023 08:32:21 -0400 Subject: [PATCH 05/42] update protomatter to 1.6.1 (used for RGBMatrix) --- lib/protomatter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protomatter b/lib/protomatter index ed2e701871..c9c1189e9d 160000 --- a/lib/protomatter +++ b/lib/protomatter @@ -1 +1 @@ -Subproject commit ed2e7018718caebba2b7550517b556e7734357ef +Subproject commit c9c1189e9d6200bb09bf4a87d84be9459cae481b From 722d64b0e7a53b240eaa395a5716e6cbbb482ae4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 11 Sep 2023 12:07:45 -0400 Subject: [PATCH 06/42] Add root cert DST Root CA X3 for Let's Encrypt --- lib/certificates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/certificates b/lib/certificates index 5c85c604a0..cbb33c111f 160000 --- a/lib/certificates +++ b/lib/certificates @@ -1 +1 @@ -Subproject commit 5c85c604a0d77a08df93435e4afad5f541c38923 +Subproject commit cbb33c111f245411370c1e571012472323df3f07 From 05267948b4639316b87899428a0bdf112bdb53f4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 12 Sep 2023 11:24:02 -0400 Subject: [PATCH 07/42] Revert "formatting" (from #8089) This reverts commit 4bb475b930d4237f09f26ac3a6f841fbd690d026. --- ports/nrf/common-hal/busio/UART.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 626956946f..94201774de 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -266,7 +266,7 @@ bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { } void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { - volatile uint32_t *power_cycle = (void *)(self->uarte->p_reg) + 0xFFC; + volatile uint32_t *power_cycle = (void*)(self->uarte->p_reg) + 0xFFC; if (!common_hal_busio_uart_deinited(self)) { nrfx_uarte_rx_abort(self->uarte); nrfx_uarte_tx_abort(self->uarte); From 46bcd103a7a52cc1c80aedbc20928422115b2345 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 12 Sep 2023 11:24:49 -0400 Subject: [PATCH 08/42] Revert "Reset UART on deinit, reduces power consumption" (from #8089) This reverts commit ec1e7a03b38c625664a4615e60d26956205d7a67. --- ports/nrf/common-hal/busio/UART.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 94201774de..10a34e09df 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -266,15 +266,8 @@ bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { } void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { - volatile uint32_t *power_cycle = (void*)(self->uarte->p_reg) + 0xFFC; if (!common_hal_busio_uart_deinited(self)) { - nrfx_uarte_rx_abort(self->uarte); - nrfx_uarte_tx_abort(self->uarte); nrfx_uarte_uninit(self->uarte); - // power cycle the peripheral as per https://devzone.nordicsemi.com/f/nordic-q-a/26030/how-to-reach-nrf52840-uarte-current-supply-specification/102605#102605 - *power_cycle = 0; - *power_cycle; - *power_cycle = 1; reset_pin_number(self->tx_pin_number); reset_pin_number(self->rx_pin_number); reset_pin_number(self->rts_pin_number); From d8aeceb70686d5e23a121be8bf92715d6105c21f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 12 Sep 2023 12:45:46 -0400 Subject: [PATCH 09/42] SSLContext.load_verify_locations - no kw-only args --- shared-bindings/ssl/SSLContext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/ssl/SSLContext.c b/shared-bindings/ssl/SSLContext.c index ac5f7ad42d..5695cf1b9b 100644 --- a/shared-bindings/ssl/SSLContext.c +++ b/shared-bindings/ssl/SSLContext.c @@ -101,7 +101,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ssl_sslcontext_load_cert_chain_obj, 1, ssl_ssl STATIC mp_obj_t ssl_sslcontext_load_verify_locations(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_cadata }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_cadata, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_cadata, MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; ssl_sslcontext_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); From 9acc542957c13bdadfc0bfda7b447edca38e26e8 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Mon, 11 Sep 2023 23:35:54 +0300 Subject: [PATCH 10/42] Deinit all the pins. --- ports/espressif/common-hal/espcamera/Camera.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/espressif/common-hal/espcamera/Camera.c b/ports/espressif/common-hal/espcamera/Camera.c index 574b4e846b..7db8a4b4c1 100644 --- a/ports/espressif/common-hal/espcamera/Camera.c +++ b/ports/espressif/common-hal/espcamera/Camera.c @@ -161,6 +161,10 @@ extern void common_hal_espcamera_camera_deinit(espcamera_camera_obj_t *self) { esp_camera_deinit(); + reset_pin_number(self->camera_config.pin_pclk); + reset_pin_number(self->camera_config.pin_vsync); + reset_pin_number(self->camera_config.pin_href); + self->camera_config.xclk_freq_hz = 0; } From 18041ea5960291c1b8e59d3b6835bda76c35de76 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 14 Sep 2023 09:37:59 -0500 Subject: [PATCH 11/42] rgbmatrix: more small doc improvements * Not all ports support 30 RGB pins etc * Link to the guide page on laying out multiple panels --- shared-bindings/rgbmatrix/RGBMatrix.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c index c68798e352..ea980712df 100644 --- a/shared-bindings/rgbmatrix/RGBMatrix.c +++ b/shared-bindings/rgbmatrix/RGBMatrix.c @@ -159,7 +159,11 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_ //| parameter is specified and is not 0, it is checked against the calculated //| height. //| -//| Up to 30 RGB pins and 8 address pins are supported. +//| Tiled matrices, those with more than one panel, must be laid out `in a specific order, as detailed in the guide +//| `_. +//| +//| At least 6 RGB pins and 5 address pins are supported, for common panels with up to 64 rows of pixels. +//| Some microcontrollers may support more, up to a soft limit of 30 RGB pins and 8 address pins. //| //| The RGB pins must be within a single "port" and performance and memory //| usage are best when they are all within "close by" bits of the port. From 9b20e31cf41ef22a5c10daa2cb66a0bc5d62eff7 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 14 Sep 2023 10:23:13 -0500 Subject: [PATCH 12/42] rgbmatrix: also explain the order of rgb and addr pins --- shared-bindings/rgbmatrix/RGBMatrix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c index ea980712df..7f9ee34c90 100644 --- a/shared-bindings/rgbmatrix/RGBMatrix.c +++ b/shared-bindings/rgbmatrix/RGBMatrix.c @@ -196,8 +196,8 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_ //| :param int tile: In a multi-row matrix, the number of rows of panels //| :param int bit_depth: The color depth of the matrix. A value of 1 gives 8 colors, a value of 2 gives 64 colors, and so on. Increasing bit depth increases the CPU and RAM usage of the RGBMatrix, and may lower the panel refresh rate. The framebuffer is always in RGB565 format regardless of the bit depth setting //| :param bool serpentine: In a multi-row matrix, True when alternate rows of panels are rotated 180°, which can reduce wiring length -//| :param Sequence[digitalio.DigitalInOut] rgb_pins: The matrix's RGB pins -//| :param Sequence[digitalio.DigitalInOut] addr_pins: The matrix's address pins +//| :param Sequence[digitalio.DigitalInOut] rgb_pins: The matrix's RGB pins in the order ``(R1,G1,B1,R2,G2,B2...)`` +//| :param Sequence[digitalio.DigitalInOut] addr_pins: The matrix's address pins in the order ``(A,B,C,D...)`` //| :param digitalio.DigitalInOut clock_pin: The matrix's clock pin //| :param digitalio.DigitalInOut latch_pin: The matrix's latch pin //| :param digitalio.DigitalInOut output_enable_pin: The matrix's output enable pin From 9710ef0200b7dacc3e497b71e4cb0d7ae082cbb5 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 14 Sep 2023 10:27:03 -0500 Subject: [PATCH 13/42] matrixportal_m4: Add board.MTX_ADDRESS and board.MTX_COMMON This eases using the RGBMatrix constructor and matches the Matrixportal S3. --- .../atmel-samd/boards/matrixportal_m4/pins.c | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/ports/atmel-samd/boards/matrixportal_m4/pins.c b/ports/atmel-samd/boards/matrixportal_m4/pins.c index 205cd6f3c6..5bcaa5cca6 100644 --- a/ports/atmel-samd/boards/matrixportal_m4/pins.c +++ b/ports/atmel-samd/boards/matrixportal_m4/pins.c @@ -1,5 +1,40 @@ #include "shared-bindings/board/__init__.h" +STATIC const mp_rom_obj_tuple_t matrix_addr_tuple = { + {&mp_type_tuple}, + 5, + { + MP_ROM_PTR(&pin_PB07), + MP_ROM_PTR(&pin_PB08), + MP_ROM_PTR(&pin_PB09), + MP_ROM_PTR(&pin_PB15), + MP_ROM_PTR(&pin_PB13), + } +}; + +STATIC const mp_rom_obj_tuple_t matrix_data_tuple = { + {&mp_type_tuple}, + 6, + { + MP_ROM_PTR(&pin_PB00), + MP_ROM_PTR(&pin_PB01), + MP_ROM_PTR(&pin_PB02), + + MP_ROM_PTR(&pin_PB03), + MP_ROM_PTR(&pin_PB04), + MP_ROM_PTR(&pin_PB05), + } +}; + +STATIC const mp_rom_map_elem_t matrix_common_table[] = { + { MP_OBJ_NEW_QSTR(MP_QSTR_rgb_pins),MP_ROM_PTR(&matrix_data_tuple) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_clock_pin),MP_ROM_PTR(&pin_PB06) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_latch_pin),MP_ROM_PTR(&pin_PB14) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_output_enable_pin),MP_ROM_PTR(&pin_PB12) }, +}; +MP_DEFINE_CONST_DICT(matrix_common_dict, matrix_common_table); + + STATIC const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS @@ -30,6 +65,9 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_MOSI),MP_ROM_PTR(&pin_PA19) }, { MP_OBJ_NEW_QSTR(MP_QSTR_MISO),MP_ROM_PTR(&pin_PA17) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MTX_ADDRESS),MP_ROM_PTR(&matrix_addr_tuple) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MTX_COMMON),MP_ROM_PTR(&matrix_common_dict) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MTX_R1),MP_ROM_PTR(&pin_PB00) }, { MP_OBJ_NEW_QSTR(MP_QSTR_MTX_G1),MP_ROM_PTR(&pin_PB01) }, { MP_OBJ_NEW_QSTR(MP_QSTR_MTX_B1),MP_ROM_PTR(&pin_PB02) }, From b61900f881e629999eeeee866c3c40553006c7fe Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 14 Sep 2023 10:37:44 -0500 Subject: [PATCH 14/42] fixup! matrixportal_m4: Add board.MTX_ADDRESS and board.MTX_COMMON --- ports/atmel-samd/boards/matrixportal_m4/pins.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/atmel-samd/boards/matrixportal_m4/pins.c b/ports/atmel-samd/boards/matrixportal_m4/pins.c index 5bcaa5cca6..591796f22b 100644 --- a/ports/atmel-samd/boards/matrixportal_m4/pins.c +++ b/ports/atmel-samd/boards/matrixportal_m4/pins.c @@ -1,3 +1,4 @@ +#include "py/objtuple.h" #include "shared-bindings/board/__init__.h" STATIC const mp_rom_obj_tuple_t matrix_addr_tuple = { From 0e78ab6ed5b398b99cbe73665a6f9fc398143d48 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 14 Sep 2023 10:31:48 -0500 Subject: [PATCH 15/42] rgbmatrix: document MTX_ADDRESS and MTX_COMMON --- shared-bindings/rgbmatrix/RGBMatrix.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c index 7f9ee34c90..266d22447b 100644 --- a/shared-bindings/rgbmatrix/RGBMatrix.c +++ b/shared-bindings/rgbmatrix/RGBMatrix.c @@ -192,6 +192,14 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_ //| A RGBMatrix is often used in conjunction with a //| `framebufferio.FramebufferDisplay`. //| +//| On boards designed for use with RGBMatrix panels, `board.MTX_ADDRESS` is a tuple of all the address pins, and `board.MTX_COMMON` is a dictionary with ``rgb_pins``, ``clock_pin``, ``latch_pin``, and ``output_enable_pin``. +//| For panels that use fewer than the maximum number of address pins, "slice" the ``MTX_ADDRESS`` to get the correct number of address pins. +//| Using these board properties makes calling the constructor simpler and more portable: +//| +//| .. code-block:: python +//| +//| matrix = rgbmatrix.RGBMatrix(..., addr_pins=board.MTX_ADDRESS[:4], **board.MTX_COMMON) +//| //| :param int width: The overall width of the whole matrix in pixels. For a matrix with multiple panels in row, this is the width of a single panel times the number of panels across. //| :param int tile: In a multi-row matrix, the number of rows of panels //| :param int bit_depth: The color depth of the matrix. A value of 1 gives 8 colors, a value of 2 gives 64 colors, and so on. Increasing bit depth increases the CPU and RAM usage of the RGBMatrix, and may lower the panel refresh rate. The framebuffer is always in RGB565 format regardless of the bit depth setting From ee86c7649f605573649a6f514bc5160906c038ae Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 18 Sep 2023 10:23:01 -0500 Subject: [PATCH 16/42] fix markup, that's not a link --- shared-bindings/rgbmatrix/RGBMatrix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c index 266d22447b..71a865aa61 100644 --- a/shared-bindings/rgbmatrix/RGBMatrix.c +++ b/shared-bindings/rgbmatrix/RGBMatrix.c @@ -192,8 +192,8 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_ //| A RGBMatrix is often used in conjunction with a //| `framebufferio.FramebufferDisplay`. //| -//| On boards designed for use with RGBMatrix panels, `board.MTX_ADDRESS` is a tuple of all the address pins, and `board.MTX_COMMON` is a dictionary with ``rgb_pins``, ``clock_pin``, ``latch_pin``, and ``output_enable_pin``. -//| For panels that use fewer than the maximum number of address pins, "slice" the ``MTX_ADDRESS`` to get the correct number of address pins. +//| On boards designed for use with RGBMatrix panels, ``board.MTX_ADDRESS`` is a tuple of all the address pins, and ``board.MTX_COMMON`` is a dictionary with ``rgb_pins``, ``clock_pin``, ``latch_pin``, and ``output_enable_pin``. +//| For panels that use fewer than the maximum number of address pins, "slice" ``MTX_ADDRESS`` to get the correct number of address pins. //| Using these board properties makes calling the constructor simpler and more portable: //| //| .. code-block:: python From 931a6adb81bcfb96a1ac15060cc685a592e6d744 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 18 Sep 2023 19:43:02 -0400 Subject: [PATCH 17/42] fix CPU on Monster M4SK; turn off audiobusio by default on SAMD51G --- ports/atmel-samd/boards/capablerobot_usbhub/mpconfigboard.mk | 3 --- ports/atmel-samd/boards/cp32-m4/mpconfigboard.h | 2 +- ports/atmel-samd/boards/cp32-m4/mpconfigboard.mk | 3 --- .../atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.mk | 3 --- .../atmel-samd/boards/loc_ber_m4_base_board/mpconfigboard.mk | 3 --- ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk | 3 --- ports/atmel-samd/boards/monster_m4sk/mpconfigboard.h | 3 ++- ports/atmel-samd/boards/monster_m4sk/mpconfigboard.mk | 3 ++- ports/atmel-samd/boards/robohatmm1_m4/mpconfigboard.mk | 2 -- ports/atmel-samd/boards/trellis_m4_express/mpconfigboard.mk | 3 --- ports/atmel-samd/mpconfigport.mk | 5 +++++ 11 files changed, 10 insertions(+), 23 deletions(-) diff --git a/ports/atmel-samd/boards/capablerobot_usbhub/mpconfigboard.mk b/ports/atmel-samd/boards/capablerobot_usbhub/mpconfigboard.mk index 388aa6e914..a3e80dc28a 100644 --- a/ports/atmel-samd/boards/capablerobot_usbhub/mpconfigboard.mk +++ b/ports/atmel-samd/boards/capablerobot_usbhub/mpconfigboard.mk @@ -10,9 +10,6 @@ QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "GD25Q16C, W25Q16JVxQ" LONGINT_IMPL = MPZ -# No I2S on SAMD51G -CIRCUITPY_AUDIOBUSIO = 0 - CIRCUITPY_FULL_BUILD = 0 CIRCUITPY_AUDIOIO = 0 CIRCUITPY_AUDIOCORE = 0 diff --git a/ports/atmel-samd/boards/cp32-m4/mpconfigboard.h b/ports/atmel-samd/boards/cp32-m4/mpconfigboard.h index 13433707af..e8e4c195e1 100644 --- a/ports/atmel-samd/boards/cp32-m4/mpconfigboard.h +++ b/ports/atmel-samd/boards/cp32-m4/mpconfigboard.h @@ -1,5 +1,5 @@ #define MICROPY_HW_BOARD_NAME "CP32-M4" -#define MICROPY_HW_MCU_NAME "samd51j20" +#define MICROPY_HW_MCU_NAME "samd51j20A" #define MICROPY_HW_APA102_MOSI (&pin_PA12) #define MICROPY_HW_APA102_SCK (&pin_PA13) diff --git a/ports/atmel-samd/boards/cp32-m4/mpconfigboard.mk b/ports/atmel-samd/boards/cp32-m4/mpconfigboard.mk index af0129f10f..fdf3f4ee67 100644 --- a/ports/atmel-samd/boards/cp32-m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/cp32-m4/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q128JVxM" LONGINT_IMPL = MPZ - -# No I2S on SAMD51G. -CIRCUITPY_AUDIOBUSIO = 0 diff --git a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.mk index 7a45ef21e9..e0fb86f098 100644 --- a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.mk @@ -10,7 +10,4 @@ QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = GD25Q16C LONGINT_IMPL = MPZ -# No I2S on SAMD51G -CIRCUITPY_AUDIOBUSIO = 0 - CIRCUITPY_BITBANG_APA102 = 1 diff --git a/ports/atmel-samd/boards/loc_ber_m4_base_board/mpconfigboard.mk b/ports/atmel-samd/boards/loc_ber_m4_base_board/mpconfigboard.mk index 3c407f5306..baedebe811 100644 --- a/ports/atmel-samd/boards/loc_ber_m4_base_board/mpconfigboard.mk +++ b/ports/atmel-samd/boards/loc_ber_m4_base_board/mpconfigboard.mk @@ -11,9 +11,6 @@ CIRCUITPY_FULL_BUILD = 0 LONGINT_IMPL = MPZ -# No I2S on SAMD51G -CIRCUITPY_AUDIOBUSIO = 0 - CIRCUITPY_BITBANG_APA102 = 1 # Override optimization to keep binary small OPTIMIZATION_FLAGS = -Os diff --git a/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk b/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk index c3e21a4c36..adbe8c3897 100644 --- a/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk @@ -10,9 +10,6 @@ QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q16JVxM, W25Q16JVxQ" LONGINT_IMPL = MPZ -# No I2S on SAMD51G -CIRCUITPY_AUDIOBUSIO = 0 - CIRCUITPY_BITBANG_APA102 = 1 #Include these Python libraries in firmware. diff --git a/ports/atmel-samd/boards/monster_m4sk/mpconfigboard.h b/ports/atmel-samd/boards/monster_m4sk/mpconfigboard.h index 26100960d8..6007edc58a 100644 --- a/ports/atmel-samd/boards/monster_m4sk/mpconfigboard.h +++ b/ports/atmel-samd/boards/monster_m4sk/mpconfigboard.h @@ -1,5 +1,6 @@ #define MICROPY_HW_BOARD_NAME "Adafruit Monster M4SK" -#define MICROPY_HW_MCU_NAME "samd51j19" +// Board is mislabeled as SAMD51J19. +#define MICROPY_HW_MCU_NAME "samd51g19" #define CIRCUITPY_MCU_FAMILY samd51 diff --git a/ports/atmel-samd/boards/monster_m4sk/mpconfigboard.mk b/ports/atmel-samd/boards/monster_m4sk/mpconfigboard.mk index 87efe005f3..77513fcf27 100644 --- a/ports/atmel-samd/boards/monster_m4sk/mpconfigboard.mk +++ b/ports/atmel-samd/boards/monster_m4sk/mpconfigboard.mk @@ -3,7 +3,8 @@ USB_PID = 0x8048 USB_PRODUCT = "Monster M4SK" USB_MANUFACTURER = "Adafruit Industries LLC" -CHIP_VARIANT = SAMD51J19A +# Board is mislabeled as SAMD51J19. +CHIP_VARIANT = SAMD51G19A CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 diff --git a/ports/atmel-samd/boards/robohatmm1_m4/mpconfigboard.mk b/ports/atmel-samd/boards/robohatmm1_m4/mpconfigboard.mk index 0ae092c693..d464d783a6 100644 --- a/ports/atmel-samd/boards/robohatmm1_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/robohatmm1_m4/mpconfigboard.mk @@ -12,8 +12,6 @@ SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q64JVxQ" LONGINT_IMPL = MPZ -# No I2S on SAMD51G -CIRCUITPY_AUDIOBUSIO = 0 # Make room for more stuff CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_DISPLAYIO = 0 diff --git a/ports/atmel-samd/boards/trellis_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/trellis_m4_express/mpconfigboard.mk index 81df26b0c6..47fbdcceb9 100644 --- a/ports/atmel-samd/boards/trellis_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/trellis_m4_express/mpconfigboard.mk @@ -10,7 +10,4 @@ QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q64JVxQ, GD25Q64C" LONGINT_IMPL = MPZ -# No I2S on SAMD51G -CIRCUITPY_AUDIOBUSIO = 0 - CIRCUITPY_BITBANG_APA102 = 1 diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index 032e49ce36..884e191fa7 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -108,6 +108,11 @@ CIRCUITPY_SAMD ?= 1 CIRCUITPY_SYNTHIO_MAX_CHANNELS = 12 CIRCUITPY_WATCHDOG ?= 1 +ifeq ($(CHIP_VARIANT),SAMD51G19A) +# No I2S on SAMD51G +CIRCUITPY_AUDIOBUSIO = 0 +endif + endif # samd51 ###################################################################### From 8f3c6422ee4f56b7df8dcce860167ed48242ba5d Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 20 Sep 2023 14:04:08 -0700 Subject: [PATCH 18/42] Fix MDNS after the user turns off wifi We need to reset our MDNS state instead of just the IDF's. --- ports/espressif/common-hal/mdns/Server.c | 22 +++++++++++++++++----- ports/espressif/common-hal/mdns/Server.h | 2 ++ ports/espressif/common-hal/wifi/Radio.c | 4 ++-- ports/espressif/esp-idf | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ports/espressif/common-hal/mdns/Server.c b/ports/espressif/common-hal/mdns/Server.c index 18c0f0f5e4..f26597a5bf 100644 --- a/ports/espressif/common-hal/mdns/Server.c +++ b/ports/espressif/common-hal/mdns/Server.c @@ -36,16 +36,22 @@ // Track whether the underlying IDF mdns has been started so that we only // create a single inited MDNS object to CircuitPython. (After deinit, another // could be created.) -STATIC bool mdns_started = false; +STATIC mdns_server_obj_t *_active_object = NULL; void mdns_server_construct(mdns_server_obj_t *self, bool workflow) { - if (mdns_started) { + if (_active_object != NULL) { + if (self == _active_object) { + return; + } // Mark this object as deinited because another is already using MDNS. self->inited = false; return; } - mdns_init(); - mdns_started = true; + esp_err_t ret = mdns_init(); + if (ret != ESP_OK) { + return; + } + _active_object = self; uint8_t mac[6]; esp_netif_get_mac(common_hal_wifi_radio_obj.netif, mac); @@ -86,10 +92,16 @@ void common_hal_mdns_server_deinit(mdns_server_obj_t *self) { return; } self->inited = false; - mdns_started = false; + _active_object = NULL; mdns_free(); } +void mdns_server_deinit_singleton(void) { + if (_active_object != NULL) { + common_hal_mdns_server_deinit(_active_object); + } +} + bool common_hal_mdns_server_deinited(mdns_server_obj_t *self) { return !self->inited; } diff --git a/ports/espressif/common-hal/mdns/Server.h b/ports/espressif/common-hal/mdns/Server.h index ee463657f1..cbdde02929 100644 --- a/ports/espressif/common-hal/mdns/Server.h +++ b/ports/espressif/common-hal/mdns/Server.h @@ -36,3 +36,5 @@ typedef struct { // Track if this object owns access to the underlying MDNS service. bool inited; } mdns_server_obj_t; + +void mdns_server_deinit_singleton(void); diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index 0dcb02a327..b64abd8fb8 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -44,7 +44,7 @@ #include "components/lwip/include/apps/ping/ping_sock.h" #if CIRCUITPY_MDNS -#include "components/mdns/include/mdns.h" +#include "common-hal/mdns/Server.h" #endif #define MAC_ADDRESS_LENGTH 6 @@ -97,7 +97,7 @@ void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) { common_hal_wifi_radio_stop_scanning_networks(self); } #if CIRCUITPY_MDNS - mdns_free(); + mdns_server_deinit_singleton(); #endif ESP_ERROR_CHECK(esp_wifi_stop()); self->started = false; diff --git a/ports/espressif/esp-idf b/ports/espressif/esp-idf index 630c2724fc..b6b7a7aad5 160000 --- a/ports/espressif/esp-idf +++ b/ports/espressif/esp-idf @@ -1 +1 @@ -Subproject commit 630c2724fc8c69eeaaa1bb025de52b99c5cb11aa +Subproject commit b6b7a7aad56ede8f2d4e213c3dd3621dacc34122 From 9012e34ce146da69a93fe3426399cd14cfc2480f Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 20:24:31 +0800 Subject: [PATCH 19/42] Add files via upload --- .../boards/magiclick_s3_n4r2/board.c | 40 ++++++++++ .../boards/magiclick_s3_n4r2/mpconfigboard.h | 45 +++++++++++ .../boards/magiclick_s3_n4r2/mpconfigboard.mk | 31 ++++++++ .../espressif/boards/magiclick_s3_n4r2/pins.c | 76 +++++++++++++++++++ .../boards/magiclick_s3_n4r2/sdkconfig | 50 ++++++++++++ 5 files changed, 242 insertions(+) create mode 100644 ports/espressif/boards/magiclick_s3_n4r2/board.c create mode 100644 ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h create mode 100644 ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk create mode 100644 ports/espressif/boards/magiclick_s3_n4r2/pins.c create mode 100644 ports/espressif/boards/magiclick_s3_n4r2/sdkconfig diff --git a/ports/espressif/boards/magiclick_s3_n4r2/board.c b/ports/espressif/boards/magiclick_s3_n4r2/board.c new file mode 100644 index 0000000000..b39d31bbc2 --- /dev/null +++ b/ports/espressif/boards/magiclick_s3_n4r2/board.c @@ -0,0 +1,40 @@ +/* + * 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 "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + +void board_init(void) { + // Debug UART + #ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + #endif +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. + diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h new file mode 100644 index 0000000000..1c57b242f1 --- /dev/null +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + */ + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "MagiClick S3 N4R2" +#define MICROPY_HW_MCU_NAME "ESP32S3" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO17) +// #define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO38) + +#define CIRCUITPY_BOARD_I2C (1) +#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO36, .sda = &pin_GPIO35}} + + +#define CIRCUITPY_BOARD_SPI (1) +#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO5, .mosi = &pin_GPIO4, .miso = &pin_GPIO6}} + +// #define CIRCUITPY_BOARD_UART (1) +// #define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO5, .rx = &pin_GPIO16}} + +#define DOUBLE_TAP_PIN (&pin_GPIO6) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk new file mode 100644 index 0000000000..64c87e9256 --- /dev/null +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk @@ -0,0 +1,31 @@ +USB_VID = 0x303A +USB_PID = 0x81AA + +USB_PRODUCT = "MagiClick S3 n4r2" +USB_MANUFACTURER = "MakerM0" + +IDF_TARGET = esp32s3 + +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 8MB + +CIRCUITPY_ESPCAMERA = 0 +CIRCUITPY_DISPLAYIO = 1 +CIRCUITPY_GIFIO = 1 + + + +# # Include these Python libraries in firmware. +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Text +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Shapes +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LSM6DS +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_ST7789 +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Ticks +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_asyncio +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_MIDI +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FakeRequests +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests \ No newline at end of file diff --git a/ports/espressif/boards/magiclick_s3_n4r2/pins.c b/ports/espressif/boards/magiclick_s3_n4r2/pins.c new file mode 100644 index 0000000000..309e81f3cb --- /dev/null +++ b/ports/espressif/boards/magiclick_s3_n4r2/pins.c @@ -0,0 +1,76 @@ +#include "shared-bindings/board/__init__.h" + +CIRCUITPY_BOARD_BUS_SINGLETON(stemma_i2c, i2c, 1) + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_IO47), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, + + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_K1), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_K2), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_K3), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_SCLK), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_IOX), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_BAT), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_WS), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_BCK), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_DATA), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_SD), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_BACKLIGHT), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_LCD_RESET), MP_ROM_PTR(&pin_GPIO10) }, + + + + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_stemma_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig new file mode 100644 index 0000000000..bc89e46013 --- /dev/null +++ b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig @@ -0,0 +1,50 @@ +# +# Component config +# +# +# ESP32S3-Specific +# +CONFIG_ESP32S3_SPIRAM_SUPPORT=y +# +# SPI RAM config +# +CONFIG_SPIRAM_MODE_QUAD=y +# CONFIG_SPIRAM_MODE_OCT is not set +CONFIG_SPIRAM_TYPE_AUTO=y +# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set +CONFIG_SPIRAM_SIZE=2097152 +# +# PSRAM Clock and CS IO for ESP32S3 +# +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM Clock and CS IO for ESP32S3 + +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_SPEED_120M is not set +CONFIG_SPIRAM_SPEED_80M=y +# CONFIG_SPIRAM_SPEED_40M is not set +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# end of SPI RAM config + +# end of ESP32S3-Specific + +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# end of LWIP + + +# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_160 = y +# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ=160 +# end of Component config From 9d906805217d7515466e28e93775daaef5cfaac7 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 20:48:30 +0800 Subject: [PATCH 20/42] Add board def for MagiClick S3 The board is related here: https://github.com/MakerM0/MagiClick-esp32s3 VID&PID can be found here: https://github.com/espressif/usb-pids --- .../boards/magiclick_s3_n4r2/board.c | 33 ++++++++ .../boards/magiclick_s3_n4r2/mpconfigboard.h | 45 +++++++++++ .../boards/magiclick_s3_n4r2/mpconfigboard.mk | 31 ++++++++ .../espressif/boards/magiclick_s3_n4r2/pins.c | 76 +++++++++++++++++++ .../boards/magiclick_s3_n4r2/sdkconfig | 50 ++++++++++++ 5 files changed, 235 insertions(+) create mode 100644 ports/espressif/boards/magiclick_s3_n4r2/board.c create mode 100644 ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h create mode 100644 ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk create mode 100644 ports/espressif/boards/magiclick_s3_n4r2/pins.c create mode 100644 ports/espressif/boards/magiclick_s3_n4r2/sdkconfig diff --git a/ports/espressif/boards/magiclick_s3_n4r2/board.c b/ports/espressif/boards/magiclick_s3_n4r2/board.c new file mode 100644 index 0000000000..3fc5c03323 --- /dev/null +++ b/ports/espressif/boards/magiclick_s3_n4r2/board.c @@ -0,0 +1,33 @@ +/* + * 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 "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. + diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h new file mode 100644 index 0000000000..1c57b242f1 --- /dev/null +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + */ + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "MagiClick S3 N4R2" +#define MICROPY_HW_MCU_NAME "ESP32S3" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO17) +// #define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO38) + +#define CIRCUITPY_BOARD_I2C (1) +#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO36, .sda = &pin_GPIO35}} + + +#define CIRCUITPY_BOARD_SPI (1) +#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO5, .mosi = &pin_GPIO4, .miso = &pin_GPIO6}} + +// #define CIRCUITPY_BOARD_UART (1) +// #define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO5, .rx = &pin_GPIO16}} + +#define DOUBLE_TAP_PIN (&pin_GPIO6) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk new file mode 100644 index 0000000000..64c87e9256 --- /dev/null +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk @@ -0,0 +1,31 @@ +USB_VID = 0x303A +USB_PID = 0x81AA + +USB_PRODUCT = "MagiClick S3 n4r2" +USB_MANUFACTURER = "MakerM0" + +IDF_TARGET = esp32s3 + +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 8MB + +CIRCUITPY_ESPCAMERA = 0 +CIRCUITPY_DISPLAYIO = 1 +CIRCUITPY_GIFIO = 1 + + + +# # Include these Python libraries in firmware. +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Text +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Shapes +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LSM6DS +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_ST7789 +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Ticks +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_asyncio +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_MIDI +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FakeRequests +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests \ No newline at end of file diff --git a/ports/espressif/boards/magiclick_s3_n4r2/pins.c b/ports/espressif/boards/magiclick_s3_n4r2/pins.c new file mode 100644 index 0000000000..309e81f3cb --- /dev/null +++ b/ports/espressif/boards/magiclick_s3_n4r2/pins.c @@ -0,0 +1,76 @@ +#include "shared-bindings/board/__init__.h" + +CIRCUITPY_BOARD_BUS_SINGLETON(stemma_i2c, i2c, 1) + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_IO47), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, + + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_K1), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_K2), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_K3), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_SCLK), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_IOX), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_BAT), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_WS), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_BCK), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_DATA), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_SD), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_BACKLIGHT), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_LCD_RESET), MP_ROM_PTR(&pin_GPIO10) }, + + + + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_stemma_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig new file mode 100644 index 0000000000..bc89e46013 --- /dev/null +++ b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig @@ -0,0 +1,50 @@ +# +# Component config +# +# +# ESP32S3-Specific +# +CONFIG_ESP32S3_SPIRAM_SUPPORT=y +# +# SPI RAM config +# +CONFIG_SPIRAM_MODE_QUAD=y +# CONFIG_SPIRAM_MODE_OCT is not set +CONFIG_SPIRAM_TYPE_AUTO=y +# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set +CONFIG_SPIRAM_SIZE=2097152 +# +# PSRAM Clock and CS IO for ESP32S3 +# +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM Clock and CS IO for ESP32S3 + +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_SPEED_120M is not set +CONFIG_SPIRAM_SPEED_80M=y +# CONFIG_SPIRAM_SPEED_40M is not set +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# end of SPI RAM config + +# end of ESP32S3-Specific + +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# end of LWIP + + +# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_160 = y +# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ=160 +# end of Component config From a5ae99a5b62f997672b9474348bd070372c18367 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:12:49 +0800 Subject: [PATCH 21/42] Update mpconfigboard.mk --- ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk index 64c87e9256..b5c6b3c270 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk @@ -12,7 +12,7 @@ CIRCUITPY_ESP_FLASH_SIZE = 8MB CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_DISPLAYIO = 1 -CIRCUITPY_GIFIO = 1 +# CIRCUITPY_GIFIO = 1 @@ -28,4 +28,4 @@ CIRCUITPY_GIFIO = 1 # FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_MIDI # FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register # FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FakeRequests -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests \ No newline at end of file +# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests From 12f35d1a0fe2a86c8985da799dbd81387d16bc73 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:16:41 +0800 Subject: [PATCH 22/42] Update mpconfigboard.mk --- ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk index b5c6b3c270..513605aaca 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk @@ -29,3 +29,4 @@ CIRCUITPY_DISPLAYIO = 1 # FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register # FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FakeRequests # FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests + From 6d7a08bcdcca7f275aaad04dd36bb9dbb50f5723 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:16:58 +0800 Subject: [PATCH 23/42] Update board.c --- ports/espressif/boards/magiclick_s3_n4r2/board.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/board.c b/ports/espressif/boards/magiclick_s3_n4r2/board.c index 3fc5c03323..1fb6e07acf 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/board.c +++ b/ports/espressif/boards/magiclick_s3_n4r2/board.c @@ -31,3 +31,4 @@ // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. + From 6f77f0f1630cef42dfcf230d8d861f89fcff8c50 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:17:11 +0800 Subject: [PATCH 24/42] Update mpconfigboard.h --- ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h index 1c57b242f1..6bfb3dfb0b 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h @@ -43,3 +43,4 @@ // #define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO5, .rx = &pin_GPIO16}} #define DOUBLE_TAP_PIN (&pin_GPIO6) + From 9ab8822c59ba957bb2e71cad695f8e786c063d07 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:17:25 +0800 Subject: [PATCH 25/42] Update pins.c --- ports/espressif/boards/magiclick_s3_n4r2/pins.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/pins.c b/ports/espressif/boards/magiclick_s3_n4r2/pins.c index 309e81f3cb..ad1e50b52d 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/pins.c +++ b/ports/espressif/boards/magiclick_s3_n4r2/pins.c @@ -74,3 +74,4 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); + From ab8e119510e7a9f317464a695d22b91129d8c8e4 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:17:39 +0800 Subject: [PATCH 26/42] Update sdkconfig --- ports/espressif/boards/magiclick_s3_n4r2/sdkconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig index bc89e46013..e82159f279 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig +++ b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig @@ -48,3 +48,4 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_160 = y # CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ=160 # end of Component config + From 5ffb7e7c8343152580e01b46c8f78bda52b6bfb6 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:38:30 +0800 Subject: [PATCH 27/42] Update mpconfigboard.mk --- ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk index 513605aaca..401c293769 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk @@ -10,7 +10,7 @@ CIRCUITPY_ESP_FLASH_MODE = dio CIRCUITPY_ESP_FLASH_FREQ = 80m CIRCUITPY_ESP_FLASH_SIZE = 8MB -CIRCUITPY_ESPCAMERA = 0 + CIRCUITPY_DISPLAYIO = 1 # CIRCUITPY_GIFIO = 1 From 0507e7a00d3d82cb123babd12a5b8827c4b7052c Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:50:30 +0800 Subject: [PATCH 28/42] Update mpconfigboard.mk --- ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk index 401c293769..8217fac256 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk @@ -8,11 +8,11 @@ IDF_TARGET = esp32s3 CIRCUITPY_ESP_FLASH_MODE = dio CIRCUITPY_ESP_FLASH_FREQ = 80m -CIRCUITPY_ESP_FLASH_SIZE = 8MB - +CIRCUITPY_ESP_FLASH_SIZE = 4MB +CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_DISPLAYIO = 1 -# CIRCUITPY_GIFIO = 1 + From c35839afc547820a3d6cb4f16c85b21aa475353d Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:05:34 +0800 Subject: [PATCH 29/42] Update board.c --- ports/espressif/boards/magiclick_s3_n4r2/board.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/board.c b/ports/espressif/boards/magiclick_s3_n4r2/board.c index 1fb6e07acf..dd11618242 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/board.c +++ b/ports/espressif/boards/magiclick_s3_n4r2/board.c @@ -25,10 +25,6 @@ */ #include "supervisor/board.h" -#include "mpconfigboard.h" -#include "shared-bindings/microcontroller/Pin.h" - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. - From 3913adf7fbc446dbab853af077b097541d9ffcf6 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:06:38 +0800 Subject: [PATCH 30/42] Update sdkconfig --- .../boards/magiclick_s3_n4r2/sdkconfig | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig index e82159f279..2d72ed5391 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig +++ b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig @@ -8,14 +8,15 @@ CONFIG_ESP32S3_SPIRAM_SUPPORT=y # # SPI RAM config # -CONFIG_SPIRAM_MODE_QUAD=y -# CONFIG_SPIRAM_MODE_OCT is not set +# CONFIG_SPIRAM_MODE_QUAD is not set +CONFIG_SPIRAM_MODE_OCT=y CONFIG_SPIRAM_TYPE_AUTO=y # CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set # CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set # CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set -CONFIG_SPIRAM_SIZE=2097152 -# +CONFIG_SPIRAM_SIZE=8388608 +# end of SPI RAM config + # PSRAM Clock and CS IO for ESP32S3 # CONFIG_DEFAULT_PSRAM_CLK_IO=30 @@ -41,11 +42,5 @@ CONFIG_SPIRAM_MEMTEST=y # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +CONFIG_LWIP_LOCAL_HOSTNAME="Metro-ESP32S3" # end of LWIP - - -# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_160 = y -# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ=160 -# end of Component config - From 918f93fc2ce02c2707421eb81ac8d30f9a540808 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:08:00 +0800 Subject: [PATCH 31/42] Update mpconfigboard.mk --- .../boards/magiclick_s3_n4r2/mpconfigboard.mk | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk index 8217fac256..bff979b998 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk @@ -13,20 +13,3 @@ CIRCUITPY_ESP_FLASH_SIZE = 4MB CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_DISPLAYIO = 1 - - - -# # Include these Python libraries in firmware. -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Text -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Shapes -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LSM6DS -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_ST7789 -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Ticks -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_asyncio -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_MIDI -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FakeRequests -# FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests - From 71e165b1fcfc23e4fa80626db2052d2e9416b9f9 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:22:48 +0800 Subject: [PATCH 32/42] Update pins.c --- ports/espressif/boards/magiclick_s3_n4r2/pins.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/pins.c b/ports/espressif/boards/magiclick_s3_n4r2/pins.c index ad1e50b52d..33473cd178 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/pins.c +++ b/ports/espressif/boards/magiclick_s3_n4r2/pins.c @@ -40,12 +40,9 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, { MP_ROM_QSTR(MP_QSTR_IO47), MP_ROM_PTR(&pin_GPIO47) }, - { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, - - + { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, - { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO17) }, { MP_ROM_QSTR(MP_QSTR_K1), MP_ROM_PTR(&pin_GPIO11) }, { MP_ROM_QSTR(MP_QSTR_K2), MP_ROM_PTR(&pin_GPIO0) }, @@ -64,14 +61,9 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO38) }, { MP_ROM_QSTR(MP_QSTR_BACKLIGHT), MP_ROM_PTR(&pin_GPIO37) }, { MP_ROM_QSTR(MP_QSTR_LCD_RESET), MP_ROM_PTR(&pin_GPIO10) }, - - - - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_stemma_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); - From ca4ecf043ebd306a4781233cd8ca0b581616a20c Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:23:12 +0800 Subject: [PATCH 33/42] Update board.c --- ports/espressif/boards/magiclick_s3_n4r2/board.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/board.c b/ports/espressif/boards/magiclick_s3_n4r2/board.c index dd11618242..164430c88c 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/board.c +++ b/ports/espressif/boards/magiclick_s3_n4r2/board.c @@ -27,4 +27,3 @@ #include "supervisor/board.h" // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. - From 1143d3e33aa17d3f816f7bf6c07904639b6dbfd9 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:23:56 +0800 Subject: [PATCH 34/42] Update mpconfigboard.h --- ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h index 6bfb3dfb0b..17e0465793 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.h @@ -34,7 +34,6 @@ #define CIRCUITPY_BOARD_I2C (1) #define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO36, .sda = &pin_GPIO35}} - #define CIRCUITPY_BOARD_SPI (1) #define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO5, .mosi = &pin_GPIO4, .miso = &pin_GPIO6}} @@ -43,4 +42,3 @@ // #define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO5, .rx = &pin_GPIO16}} #define DOUBLE_TAP_PIN (&pin_GPIO6) - From e197493537bb719d3521e597a0b9fed224fa6974 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:24:24 +0800 Subject: [PATCH 35/42] Update mpconfigboard.mk --- ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk index bff979b998..dbc712fb6c 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk @@ -12,4 +12,3 @@ CIRCUITPY_ESP_FLASH_SIZE = 4MB CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_DISPLAYIO = 1 - From 9284d25ad49029051b7c72c7253ab5afb01a6364 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:28:48 +0800 Subject: [PATCH 36/42] Update pins.c --- ports/espressif/boards/magiclick_s3_n4r2/pins.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/pins.c b/ports/espressif/boards/magiclick_s3_n4r2/pins.c index 33473cd178..077378ac88 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/pins.c +++ b/ports/espressif/boards/magiclick_s3_n4r2/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -CIRCUITPY_BOARD_BUS_SINGLETON(stemma_i2c, i2c, 1) - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS @@ -62,7 +60,6 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_BACKLIGHT), MP_ROM_PTR(&pin_GPIO37) }, { MP_ROM_QSTR(MP_QSTR_LCD_RESET), MP_ROM_PTR(&pin_GPIO10) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_stemma_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, }; From 6acce761816c448edf9c8910963353003a87e520 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:35:31 +0800 Subject: [PATCH 37/42] Update pins.c --- ports/espressif/boards/magiclick_s3_n4r2/pins.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/pins.c b/ports/espressif/boards/magiclick_s3_n4r2/pins.c index 077378ac88..acaa95c643 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/pins.c +++ b/ports/espressif/boards/magiclick_s3_n4r2/pins.c @@ -1,8 +1,6 @@ #include "shared-bindings/board/__init__.h" - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS - { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, From 761ac3b363c90b92de7a45e97daef909f9ab8be3 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:40:08 +0800 Subject: [PATCH 38/42] Update pins.c --- ports/espressif/boards/magiclick_s3_n4r2/pins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/pins.c b/ports/espressif/boards/magiclick_s3_n4r2/pins.c index acaa95c643..f88843e365 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/pins.c +++ b/ports/espressif/boards/magiclick_s3_n4r2/pins.c @@ -36,7 +36,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, { MP_ROM_QSTR(MP_QSTR_IO47), MP_ROM_PTR(&pin_GPIO47) }, - { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO17) }, From f5d4f1edb7fd5fa3ad465327b5b2531ebd4aac09 Mon Sep 17 00:00:00 2001 From: Randy Hudson Date: Mon, 25 Sep 2023 22:11:25 -0400 Subject: [PATCH 39/42] Fixed displayio/Bitmap value_count range --- shared-bindings/displayio/Bitmap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 5b939c5892..a5ab44a402 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -1,3 +1,5 @@ + + /* * This file is part of the Micro Python project, http://micropython.org/ * @@ -64,7 +66,7 @@ STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_ar mp_arg_check_num(n_args, n_kw, 3, 3, false); uint32_t width = mp_arg_validate_int_range(mp_obj_get_int(all_args[0]), 0, 32767, MP_QSTR_width); uint32_t height = mp_arg_validate_int_range(mp_obj_get_int(all_args[1]), 0, 32767, MP_QSTR_height); - uint32_t value_count = mp_arg_validate_int_range(mp_obj_get_int(all_args[2]), 1, 65535, MP_QSTR_value_count); + uint32_t value_count = mp_arg_validate_int_range(mp_obj_get_int(all_args[2]), 1, 65536, MP_QSTR_value_count); uint32_t bits = 1; while ((value_count - 1) >> bits) { From 79161dbeb22aa526a97f776874e331fe9179fa99 Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:47:47 +0800 Subject: [PATCH 40/42] Update sdkconfig --- ports/espressif/boards/magiclick_s3_n4r2/sdkconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig index 2d72ed5391..3cad2c2454 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig +++ b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig @@ -9,12 +9,12 @@ CONFIG_ESP32S3_SPIRAM_SUPPORT=y # SPI RAM config # # CONFIG_SPIRAM_MODE_QUAD is not set -CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_MODE_QUAD=y CONFIG_SPIRAM_TYPE_AUTO=y # CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set # CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set # CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set -CONFIG_SPIRAM_SIZE=8388608 +CONFIG_SPIRAM_SIZE=2097152 # end of SPI RAM config # PSRAM Clock and CS IO for ESP32S3 @@ -42,5 +42,5 @@ CONFIG_SPIRAM_MEMTEST=y # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="Metro-ESP32S3" +CONFIG_LWIP_LOCAL_HOSTNAME="MagiClick-ESP32S3" # end of LWIP From 7aa85353e7fbb55b97c3227ebfd0485453c7565f Mon Sep 17 00:00:00 2001 From: MakerM0 <117961102+MakerM0@users.noreply.github.com> Date: Fri, 29 Sep 2023 16:32:33 +0800 Subject: [PATCH 41/42] Update mpconfigboard.mk --- ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk index dbc712fb6c..d5db305f95 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk +++ b/ports/espressif/boards/magiclick_s3_n4r2/mpconfigboard.mk @@ -12,3 +12,4 @@ CIRCUITPY_ESP_FLASH_SIZE = 4MB CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_DISPLAYIO = 1 +CIRCUITPY_GIFIO = 1 From 4c21f221148a66b368954023b9f6215cfe0d2c14 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 29 Sep 2023 14:49:59 -0700 Subject: [PATCH 42/42] Improve RGBMatrix allocation tracking This prevents leaks but not all use-after-free issues. --- .../boards/adafruit_matrixportal_s3/pins.c | 4 +- .../common-hal/rgbmatrix/RGBMatrix.c | 3 + shared-bindings/rgbmatrix/RGBMatrix.c | 6 +- shared-bindings/rgbmatrix/RGBMatrix.h | 1 + shared-module/rgbmatrix/RGBMatrix.c | 72 +++++++++++++++---- shared-module/rgbmatrix/RGBMatrix.h | 2 + 6 files changed, 69 insertions(+), 19 deletions(-) diff --git a/ports/espressif/boards/adafruit_matrixportal_s3/pins.c b/ports/espressif/boards/adafruit_matrixportal_s3/pins.c index 5cdd9ab92c..9f3c9cfd36 100644 --- a/ports/espressif/boards/adafruit_matrixportal_s3/pins.c +++ b/ports/espressif/boards/adafruit_matrixportal_s3/pins.c @@ -5,10 +5,10 @@ STATIC const mp_rom_obj_tuple_t matrix_addr_tuple = { {&mp_type_tuple}, 5, { - MP_ROM_PTR(&pin_GPIO35), + MP_ROM_PTR(&pin_GPIO45), MP_ROM_PTR(&pin_GPIO36), MP_ROM_PTR(&pin_GPIO48), - MP_ROM_PTR(&pin_GPIO45), + MP_ROM_PTR(&pin_GPIO35), MP_ROM_PTR(&pin_GPIO21), } }; diff --git a/ports/espressif/common-hal/rgbmatrix/RGBMatrix.c b/ports/espressif/common-hal/rgbmatrix/RGBMatrix.c index 1ac1fe2005..4e3b8d844d 100644 --- a/ports/espressif/common-hal/rgbmatrix/RGBMatrix.c +++ b/ports/espressif/common-hal/rgbmatrix/RGBMatrix.c @@ -61,6 +61,9 @@ void common_hal_rgbmatrix_timer_enable(void *ptr) { } void common_hal_rgbmatrix_timer_disable(void *ptr) { + if (ptr == NULL) { + return; + } timer_index_t *timer = (timer_index_t *)ptr; if (timer->idx == TIMER_MAX) { return; diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c index 71a865aa61..31dd8a28a0 100644 --- a/shared-bindings/rgbmatrix/RGBMatrix.c +++ b/shared-bindings/rgbmatrix/RGBMatrix.c @@ -376,9 +376,7 @@ STATIC const mp_rom_map_elem_t rgbmatrix_rgbmatrix_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(rgbmatrix_rgbmatrix_locals_dict, rgbmatrix_rgbmatrix_locals_dict_table); STATIC void rgbmatrix_rgbmatrix_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t *bufinfo) { - rgbmatrix_rgbmatrix_obj_t *self = (rgbmatrix_rgbmatrix_obj_t *)self_in; - - *bufinfo = self->bufinfo; + common_hal_rgbmatrix_rgbmatrix_get_bufinfo(self_in, bufinfo); } // These version exists so that the prototype matches the protocol, @@ -442,7 +440,7 @@ STATIC mp_int_t rgbmatrix_rgbmatrix_get_buffer(mp_obj_t self_in, mp_buffer_info_ if ((flags & MP_BUFFER_WRITE) && !(self->bufinfo.typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW)) { return 1; } - *bufinfo = self->bufinfo; + common_hal_rgbmatrix_rgbmatrix_get_bufinfo(self_in, bufinfo); bufinfo->typecode = 'H'; return 0; } diff --git a/shared-bindings/rgbmatrix/RGBMatrix.h b/shared-bindings/rgbmatrix/RGBMatrix.h index 9d85bf2b95..0081570f42 100644 --- a/shared-bindings/rgbmatrix/RGBMatrix.h +++ b/shared-bindings/rgbmatrix/RGBMatrix.h @@ -34,6 +34,7 @@ extern const mp_obj_type_t rgbmatrix_RGBMatrix_type; void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, int width, int bit_depth, uint8_t rgb_count, uint8_t *rgb_pins, uint8_t addr_count, uint8_t *addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, int8_t tile, bool serpentine, void *timer); void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t *); void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t *); +void common_hal_rgbmatrix_rgbmatrix_get_bufinfo(rgbmatrix_rgbmatrix_obj_t *self, mp_buffer_info_t *bufinfo); void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self); void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t *self, bool paused); bool common_hal_rgbmatrix_rgbmatrix_get_paused(rgbmatrix_rgbmatrix_obj_t *self); diff --git a/shared-module/rgbmatrix/RGBMatrix.c b/shared-module/rgbmatrix/RGBMatrix.c index 556ef431ed..4d2458a6b6 100644 --- a/shared-module/rgbmatrix/RGBMatrix.c +++ b/shared-module/rgbmatrix/RGBMatrix.c @@ -79,8 +79,12 @@ STATIC void common_hal_rgbmatrix_rgbmatrix_construct1(rgbmatrix_rgbmatrix_obj_t } // verify that the matrix is big enough mp_get_index(mp_obj_get_type(self->framebuffer), self->bufinfo.len, MP_OBJ_NEW_SMALL_INT(self->bufsize - 1), false); + self->allocation = NULL; } else { - self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize); + // The supervisor allocation can move memory by changing self->allocation->ptr. + // So we hold onto it and update bufinfo every time we use it. + self->allocation = allocate_memory(align32_size(self->bufsize), false, true); + self->bufinfo.buf = self->allocation->ptr; self->bufinfo.len = self->bufsize; self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW; } @@ -146,7 +150,9 @@ STATIC void free_pin_seq(uint8_t *seq, int count) { extern int pm_row_count; STATIC void common_hal_rgbmatrix_rgbmatrix_deinit1(rgbmatrix_rgbmatrix_obj_t *self) { - common_hal_rgbmatrix_timer_disable(self->timer); + if (self->timer != NULL) { + common_hal_rgbmatrix_timer_disable(self->timer); + } if (_PM_protoPtr == &self->protomatter) { _PM_protoPtr = NULL; @@ -160,15 +166,15 @@ STATIC void common_hal_rgbmatrix_rgbmatrix_deinit1(rgbmatrix_rgbmatrix_obj_t *se // If it was supervisor-allocated, it is supervisor-freed and the pointer // is zeroed, otherwise the pointer is just zeroed - if (self->bufinfo.buf) { - common_hal_rgbmatrix_free_impl(self->bufinfo.buf); - self->bufinfo.buf = NULL; + if (self->allocation != NULL) { + free_memory(self->allocation); } - // If a framebuffer was passed in to the constructor, clear the reference // here so that it will become GC'able self->framebuffer = mp_const_none; + + self->bufinfo.buf = NULL; } void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t *self) { @@ -187,6 +193,13 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t *self) { self->base.type = &mp_type_NoneType; } +void common_hal_rgbmatrix_rgbmatrix_get_bufinfo(rgbmatrix_rgbmatrix_obj_t *self, mp_buffer_info_t *bufinfo) { + if (self->allocation != NULL) { + self->bufinfo.buf = self->allocation->ptr; + } + *bufinfo = self->bufinfo; +} + void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self) { if (self->framebuffer != mp_const_none) { memset(&self->bufinfo, 0, sizeof(self->bufinfo)); @@ -196,11 +209,6 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self) common_hal_rgbmatrix_rgbmatrix_deinit1(self); common_hal_rgbmatrix_rgbmatrix_construct1(self, mp_const_none); #endif - if (self->bufinfo.buf == NULL) { - self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize); - self->bufinfo.len = self->bufsize; - self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW; - } memset(self->bufinfo.buf, 0, self->bufinfo.len); common_hal_rgbmatrix_rgbmatrix_set_paused(self, false); } @@ -214,6 +222,9 @@ void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t *self, _PM_stop(&self->protomatter); } else if (!paused && self->paused) { _PM_resume(&self->protomatter); + if (self->allocation) { + self->bufinfo.buf = self->allocation->ptr; + } _PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width); _PM_swapbuffer_maybe(&self->protomatter); } @@ -226,6 +237,9 @@ bool common_hal_rgbmatrix_rgbmatrix_get_paused(rgbmatrix_rgbmatrix_obj_t *self) void common_hal_rgbmatrix_rgbmatrix_refresh(rgbmatrix_rgbmatrix_obj_t *self) { if (!self->paused) { + if (self->allocation != NULL) { + self->bufinfo.buf = self->allocation->ptr; + } _PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width); _PM_swapbuffer_maybe(&self->protomatter); } @@ -240,11 +254,43 @@ int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t *self) { return computed_height; } +// Track the returned pointers and their matching allocation so that we can free +// them even when the memory was moved by the supervisor. This prevents leaks +// but doesn't protect against the memory being used after its been freed! The +// long term fix is to utilize a permanent heap that can be shared with MP's +// split heap. +typedef struct matrix_allocation { + void *original_pointer; + supervisor_allocation *allocation; +} matrix_allocation_t; + +// Four should be more than we ever need. ProtoMatter does 3 allocations currently. +static matrix_allocation_t allocations[4]; + void *common_hal_rgbmatrix_allocator_impl(size_t sz) { supervisor_allocation *allocation = allocate_memory(align32_size(sz), false, true); - return allocation ? allocation->ptr : NULL; + if (allocation == NULL) { + return NULL; + } + for (size_t i = 0; i < sizeof(allocations); i++) { + matrix_allocation_t *matrix_allocation = &allocations[i]; + if (matrix_allocation->original_pointer == NULL) { + matrix_allocation->original_pointer = allocation->ptr; + matrix_allocation->allocation = allocation; + return allocation->ptr; + } + } + return NULL; } void common_hal_rgbmatrix_free_impl(void *ptr_in) { - free_memory(allocation_from_ptr(ptr_in)); + for (size_t i = 0; i < sizeof(allocations); i++) { + matrix_allocation_t *matrix_allocation = &allocations[i]; + if (matrix_allocation->original_pointer == ptr_in) { + matrix_allocation->original_pointer = NULL; + free_memory(matrix_allocation->allocation); + matrix_allocation->allocation = NULL; + return; + } + } } diff --git a/shared-module/rgbmatrix/RGBMatrix.h b/shared-module/rgbmatrix/RGBMatrix.h index 65bfc9799e..51aca3fb50 100644 --- a/shared-module/rgbmatrix/RGBMatrix.h +++ b/shared-module/rgbmatrix/RGBMatrix.h @@ -28,12 +28,14 @@ #include "py/obj.h" #include "lib/protomatter/src/core.h" +#include "supervisor/memory.h" extern const mp_obj_type_t rgbmatrix_RGBMatrix_type; typedef struct { mp_obj_base_t base; mp_obj_t framebuffer; mp_buffer_info_t bufinfo; + supervisor_allocation *allocation; Protomatter_core protomatter; void *timer; uint16_t bufsize, width;