From 7ba5513f9a2f8010601e8b11877788aa2148d0c9 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 24 Nov 2021 00:00:00 +0530 Subject: [PATCH] update espressif port - update esp-idf to v4.4 - add esp32s3 support - add analogio on esp32c3 - disable rgbmatrix on all espressif soc Co-authored-by: Scott Shawcroft Co-authored-by: Seon Rozenblum --- .gitmodules | 2 +- ports/espressif/Makefile | 49 +++++++----- ports/espressif/cam.c | 5 ++ .../espressif/common-hal/alarm/pin/PinAlarm.c | 2 +- .../espressif/common-hal/analogio/AnalogIn.c | 6 ++ .../espressif/common-hal/analogio/AnalogOut.c | 10 +++ .../common-hal/frequencyio/FrequencyIn.c | 10 ++- .../common-hal/microcontroller/Processor.c | 4 + .../common-hal/microcontroller/__init__.c | 7 +- ports/espressif/esp-idf | 2 +- ports/espressif/mpconfigport.mk | 9 ++- ports/espressif/mphalport.c | 13 +-- ports/espressif/peripherals/esp32s3/pins.c | 73 +++++++++++++++++ ports/espressif/peripherals/esp32s3/pins.h | 80 +++++++++++++++++++ ports/espressif/peripherals/pcnt.h | 1 + ports/espressif/peripherals/pins.h | 4 +- ports/espressif/supervisor/port.c | 16 ++-- ports/espressif/supervisor/usb.c | 7 +- 18 files changed, 243 insertions(+), 57 deletions(-) create mode 100644 ports/espressif/peripherals/esp32s3/pins.c create mode 100644 ports/espressif/peripherals/esp32s3/pins.h diff --git a/.gitmodules b/.gitmodules index e26d3dd76b..afc3add5fc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -149,7 +149,7 @@ [submodule "ports/espressif/esp-idf"] path = ports/espressif/esp-idf url = https://github.com/espressif/esp-idf.git - branch = release/v4.3 + branch = release/v4.4 [submodule "ports/espressif/certificates/nina-fw"] path = ports/espressif/certificates/nina-fw url = https://github.com/adafruit/nina-fw.git diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index 7a034c9d2a..b29c9f35cf 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -59,12 +59,12 @@ include $(TOP)/supervisor/supervisor.mk # Include make rules and variables common across CircuitPython builds. include $(TOP)/py/circuitpy_defns.mk -ifeq ($(IDF_TARGET),esp32s2) -IDF_TARGET_ARCH = xtensa -CROSS_COMPILE = xtensa-$(IDF_TARGET)-elf- -else ifeq ($(IDF_TARGET),esp32c3) +ifeq ($(IDF_TARGET),esp32c3) IDF_TARGET_ARCH = riscv CROSS_COMPILE = riscv32-esp-elf- +else +IDF_TARGET_ARCH = xtensa +CROSS_COMPILE = xtensa-$(IDF_TARGET)-elf- endif ####################################### @@ -92,6 +92,7 @@ INC += -I.\ -isystem esp-idf/components/esp_common/include \ -isystem esp-idf/components/esp_event/include \ -isystem esp-idf/components/esp_hw_support/include \ + -isystem esp-idf/components/esp_hw_support/include/soc \ -isystem esp-idf/components/esp_netif/include \ -isystem esp-idf/components/esp_pm/include \ -isystem esp-idf/components/esp_ringbuf/include \ @@ -101,6 +102,8 @@ INC += -I.\ -isystem esp-idf/components/esp_wifi/include \ -isystem esp-idf/components/freertos/include \ -isystem esp-idf/components/freertos/include/freertos \ + -isystem esp-idf/components/freertos/include/esp_additions \ + -isystem esp-idf/components/freertos/include/esp_additions/freertos \ -isystem esp-idf/components/freertos/port/$(IDF_TARGET_ARCH)/include \ -isystem esp-idf/components/hal/include \ -isystem esp-idf/components/hal/$(IDF_TARGET)/include \ @@ -158,12 +161,11 @@ endif LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref -Wl,--undefined=uxTopUsedPriority -LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/$(IDF_TARGET) \ - -L$(BUILD)/esp-idf/esp-idf/$(IDF_TARGET)/ld \ - -Lesp-idf/components/$(IDF_TARGET)/ld \ +LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/esp_system/ld \ -Lesp-idf/components/esp_rom/$(IDF_TARGET)/ld \ - -T$(IDF_TARGET)_out.ld \ - -T$(IDF_TARGET).project.ld \ + -Lesp-idf/components/soc/$(IDF_TARGET)/ld \ + -Tmemory.ld \ + -Tsections.ld \ -T$(IDF_TARGET).peripherals.ld \ -T$(IDF_TARGET).rom.ld \ -T$(IDF_TARGET).rom.api.ld \ @@ -174,10 +176,13 @@ ifeq ($(IDF_TARGET),esp32c3) LDFLAGS += -Tesp32c3.rom.newlib.ld \ -Tesp32c3.rom.version.ld \ -Tesp32c3.rom.eco3.ld -else +else ifeq ($(IDF_TARGET),esp32s2) LDFLAGS += -T$(IDF_TARGET).rom.newlib-data.ld \ -T$(IDF_TARGET).rom.newlib-funcs.ld \ -T$(IDF_TARGET).rom.spiflash.ld +else ifeq ($(IDF_TARGET),esp32s3) +LDFLAGS += -Tesp32s3.rom.newlib.ld \ + -Tesp32s3.rom.version.ld endif LDFLAGS += -Wl,-Bstatic \ @@ -224,10 +229,14 @@ SRC_C += \ peripherals/timer.c \ peripherals/$(IDF_TARGET)/pins.c -ifneq ($(IDF_TARGET),esp32c3) +ifeq ($(IDF_TARGET),esp32s2) SRC_C += \ cam.c \ - i2s_lcd_esp32s2_driver.c \ + i2s_lcd_esp32s2_driver.c +endif + +ifneq ($(IDF_TARGET),esp32c3) +SRC_C += \ peripherals/pcnt.c \ peripherals/touch.c endif @@ -315,20 +324,15 @@ menuconfig: $(BUILD)/esp-idf/config # qstr builds include headers so we need to make sure they are up to date $(HEADER_BUILD)/qstr.split: | $(BUILD)/esp-idf/config/sdkconfig.h -ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET) $(IDF_TARGET_ARCH) app_update bootloader_support driver efuse esp_adc_cal esp_common esp_event esp_hw_support esp_netif esp_pm esp_ringbuf esp_rom esp_system esp_timer esp-tls esp_wifi freertos hal heap log lwip mbedtls newlib nvs_flash pthread soc spi_flash vfs wpa_supplicant +BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a libsmartconfig.a libwapi.a +BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS)) +ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) app_update bootloader_support driver efuse esp_adc_cal esp_common esp_event esp_hw_support esp_ipc esp_netif esp_pm esp_phy esp_ringbuf esp_rom esp_system esp_timer esp-tls esp_wifi freertos hal heap log lwip mbedtls newlib nvs_flash pthread soc spi_flash vfs wpa_supplicant ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a) -ESP_IDF_WIFI_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_WIFI_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a) MBEDTLS_COMPONENTS_LINK = crypto tls x509 MBEDTLS_COMPONENTS_LINK_EXPANDED = $(foreach component, $(MBEDTLS_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/mbedtls/mbedtls/library/libmbed$(component).a) -BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a libsmartconfig.a libphy.a -ifneq ($(IDF_TARGET),esp32c3) -BINARY_WIFI_BLOBS += librtc.a -endif -BINARY_BLOBS = $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS)) - ifeq ($(IDF_TARGET_ARCH),xtensa) BINARY_BLOBS += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a ESP_IDF_COMPONENTS_EXPANDED += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a @@ -360,17 +364,18 @@ endif esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h $(Q)ninja -C $(BUILD)/esp-idf \ bootloader/bootloader.bin \ + esp-idf/esp_system/__ldgen_output_sections.ld \ esp-idf/app_update/libapp_update.a \ esp-idf/bootloader_support/libbootloader_support.a \ esp-idf/driver/libdriver.a \ esp-idf/efuse/libefuse.a \ - esp-idf/$(IDF_TARGET)/lib$(IDF_TARGET).a \ - esp-idf/$(IDF_TARGET)/ld/$(IDF_TARGET).project.ld \ esp-idf/esp_adc_cal/libesp_adc_cal.a \ esp-idf/esp_common/libesp_common.a \ esp-idf/esp_event/libesp_event.a \ esp-idf/esp_hw_support/libesp_hw_support.a \ + esp-idf/esp_ipc/libesp_ipc.a \ esp-idf/esp_netif/libesp_netif.a \ + esp-idf/esp_phy/libesp_phy.a \ esp-idf/esp_pm/libesp_pm.a \ esp-idf/esp_ringbuf/libesp_ringbuf.a \ esp-idf/esp_rom/libesp_rom.a \ diff --git a/ports/espressif/cam.c b/ports/espressif/cam.c index 146df43a41..ea50785cd9 100644 --- a/ports/espressif/cam.c +++ b/ports/espressif/cam.c @@ -21,8 +21,13 @@ #include "esp_log.h" #include "soc/i2s_struct.h" #include "soc/apb_ctrl_reg.h" +#ifdef CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/lldesc.h" #include "esp32s2/rom/cache.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "esp32s3/rom/lldesc.h" +#include "esp32s3/rom/cache.h" +#endif #include "soc/dport_access.h" #include "soc/dport_reg.h" #include "driver/ledc.h" diff --git a/ports/espressif/common-hal/alarm/pin/PinAlarm.c b/ports/espressif/common-hal/alarm/pin/PinAlarm.c index 754902f678..6318cc2cca 100644 --- a/ports/espressif/common-hal/alarm/pin/PinAlarm.c +++ b/ports/espressif/common-hal/alarm/pin/PinAlarm.c @@ -32,11 +32,11 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" +#include "esp_sleep.h" #include "hal/gpio_ll.h" #include "esp_debug_helpers.h" #include "components/driver/include/driver/rtc_io.h" -#include "components/esp_system/include/esp_sleep.h" #include "components/freertos/include/freertos/FreeRTOS.h" void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, const mcu_pin_obj_t *pin, bool value, bool edge, bool pull) { diff --git a/ports/espressif/common-hal/analogio/AnalogIn.c b/ports/espressif/common-hal/analogio/AnalogIn.c index df39b30c63..ba85d42735 100644 --- a/ports/espressif/common-hal/analogio/AnalogIn.c +++ b/ports/espressif/common-hal/analogio/AnalogIn.c @@ -40,7 +40,13 @@ #define DEFAULT_VREF 1100 #define NO_OF_SAMPLES 2 #define ATTENUATION ADC_ATTEN_DB_11 +#ifdef CONFIG_IDF_TARGET_ESP32C3 +#define DATA_WIDTH ADC_WIDTH_BIT_12 +#elif defined(CONFIG_IDF_TARGET_ESP32S2) #define DATA_WIDTH ADC_WIDTH_BIT_13 +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#define DATA_WIDTH ADC_WIDTH_BIT_12 +#endif void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mcu_pin_obj_t *pin) { diff --git a/ports/espressif/common-hal/analogio/AnalogOut.c b/ports/espressif/common-hal/analogio/AnalogOut.c index 589c477a78..2c79124759 100644 --- a/ports/espressif/common-hal/analogio/AnalogOut.c +++ b/ports/espressif/common-hal/analogio/AnalogOut.c @@ -41,6 +41,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) { + #ifdef CONFIG_IDF_TARGET_ESP32S2 if (pin == &pin_GPIO17) { self->channel = DAC_CHANNEL_1; } else if (pin == &pin_GPIO18) { @@ -49,6 +50,9 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, mp_raise_ValueError(translate("Invalid DAC pin supplied")); } dac_output_enable(self->channel); + #else + mp_raise_NotImplementedError(NULL); + #endif } bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) { @@ -56,18 +60,24 @@ bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) { } void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) { + #ifdef CONFIG_IDF_TARGET_ESP32S2 dac_output_disable(self->channel); self->channel = DAC_CHANNEL_MAX; + #endif } void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self, uint16_t value) { + #ifdef CONFIG_IDF_TARGET_ESP32S2 uint8_t dac_value = (value * 255) / 65535; dac_output_enable(self->channel); dac_output_voltage(self->channel, dac_value); + #endif } void analogout_reset(void) { + #ifdef CONFIG_IDF_TARGET_ESP32S2 dac_output_disable(DAC_CHANNEL_1); dac_output_disable(DAC_CHANNEL_2); + #endif } diff --git a/ports/espressif/common-hal/frequencyio/FrequencyIn.c b/ports/espressif/common-hal/frequencyio/FrequencyIn.c index cd13cddc66..e4d65c95bd 100644 --- a/ports/espressif/common-hal/frequencyio/FrequencyIn.c +++ b/ports/espressif/common-hal/frequencyio/FrequencyIn.c @@ -56,11 +56,15 @@ static void IRAM_ATTR timer_interrupt_handler(void *self_in) { // reset interrupt timg_dev_t *device = self->timer.group ? &(TIMERG1) : &(TIMERG0); if (self->timer.idx) { - device->int_clr.t1 = 1; + device->int_clr_timers.t1_int_clr = 1; } else { - device->int_clr.t0 = 1; + device->int_clr_timers.t0_int_clr = 1; } - device->hw_timer[self->timer.idx].config.alarm_en = 1; + #ifdef CONFIG_IDF_TARGET_ESP32S2 + device->hw_timer[self->timer.idx].config.tx_alarm_en = 1; + #elif defined(CONFIG_IDF_TARGET_ESP32S3) + device->hw_timer[self->timer.idx].config.tn_alarm_en = 1; + #endif } static void init_pcnt(frequencyio_frequencyin_obj_t *self) { diff --git a/ports/espressif/common-hal/microcontroller/Processor.c b/ports/espressif/common-hal/microcontroller/Processor.c index c50c6fbf7a..500d1f6d3e 100644 --- a/ports/espressif/common-hal/microcontroller/Processor.c +++ b/ports/espressif/common-hal/microcontroller/Processor.c @@ -43,11 +43,15 @@ float common_hal_mcu_processor_get_temperature(void) { float tsens_out; + #ifdef CONFIG_IDF_TARGET_ESP32S3 + mp_raise_NotImplementedError(NULL); + #else temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT(); // DEFAULT: range:-10℃ ~ 80℃, error < 1℃. temp_sensor_set_config(temp_sensor); temp_sensor_start(); temp_sensor_read_celsius(&tsens_out); temp_sensor_stop(); + #endif return tsens_out; } diff --git a/ports/espressif/common-hal/microcontroller/__init__.c b/ports/espressif/common-hal/microcontroller/__init__.c index 909ce19b00..3cf41ba7f0 100644 --- a/ports/espressif/common-hal/microcontroller/__init__.c +++ b/ports/espressif/common-hal/microcontroller/__init__.c @@ -47,13 +47,16 @@ #ifdef CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/rtc.h" -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif defined(CONFIG_IDF_TARGET_ESP32S2) #include "esp32s2/rom/rtc.h" #include "esp32s2/rom/usb/usb_persist.h" #include "esp32s2/rom/usb/chip_usb_dw_wrapper.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "esp32s3/rom/rtc.h" +#include "esp32s3/rom/usb/usb_persist.h" +#include "esp32s3/rom/usb/chip_usb_dw_wrapper.h" #endif - void common_hal_mcu_delay_us(uint32_t delay) { mp_hal_delay_us(delay); } diff --git a/ports/espressif/esp-idf b/ports/espressif/esp-idf index e493a4c30e..ddc44956bf 160000 --- a/ports/espressif/esp-idf +++ b/ports/espressif/esp-idf @@ -1 +1 @@ -Subproject commit e493a4c30e1b2f7c54a376327388b9e12262cbbf +Subproject commit ddc44956bf718540d5451e17e1becf6c7dffe5b8 diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index a7b69e0933..21459e01f5 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -26,7 +26,7 @@ CIRCUITPY_FRAMEBUFFERIO ?= 1 CIRCUITPY_FREQUENCYIO ?= 1 CIRCUITPY_IMAGECAPTURE ?= 1 CIRCUITPY_I2CPERIPHERAL ?= 1 -CIRCUITPY_RGBMATRIX ?= 1 +CIRCUITPY_RGBMATRIX ?= 0 CIRCUITPY_ROTARYIO ?= 1 CIRCUITPY_NVM ?= 1 CIRCUITPY_PS2IO ?= 1 @@ -43,17 +43,18 @@ CIRCUITPY_USB = 0 CIRCUITPY_ALARM = 0 CIRCUITPY_COUNTIO = 0 CIRCUITPY_ROTARYIO = 0 -CIRCUITPY_ANALOGIO = 0 -CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_IMAGECAPTURE = 0 CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE = 0 +else ifeq ($(IDF_TARGET),esp32s3) +CIRCUITPY_IMAGECAPTURE = 0 +CIRCUITPY_PARALLELDISPLAY = 0 endif -# From the ESP32-S2 datasheet: +# From ESP32-S2/S3 Technical Reference Manual: # # Endpoint number 0 always present (bi-directional, consisting of EP0 IN and EP0 OUT) # Six additional endpoints (endpoint numbers 1 to 6), configurable as IN or OUT diff --git a/ports/espressif/mphalport.c b/ports/espressif/mphalport.c index f22856f0a4..39b080fba3 100644 --- a/ports/espressif/mphalport.c +++ b/ports/espressif/mphalport.c @@ -25,22 +25,17 @@ * THE SOFTWARE. */ -#include - #include "py/mphal.h" -#include "py/mpstate.h" -#include "py/gc.h" - -#include "esp_debug_helpers.h" +#include "supervisor/cpu.h" #ifdef CONFIG_IDF_TARGET_ESP32C3 #include "components/esp_rom/include/esp32c3/rom/ets_sys.h" -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif defined(CONFIG_IDF_TARGET_ESP32S2) #include "components/esp_rom/include/esp32s2/rom/ets_sys.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "components/esp_rom/include/esp32s3/rom/ets_sys.h" #endif -#include "supervisor/cpu.h" - void mp_hal_delay_us(mp_uint_t delay) { ets_delay_us(delay); } diff --git a/ports/espressif/peripherals/esp32s3/pins.c b/ports/espressif/peripherals/esp32s3/pins.c new file mode 100644 index 0000000000..891cc398ae --- /dev/null +++ b/ports/espressif/peripherals/esp32s3/pins.c @@ -0,0 +1,73 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 microDev + * + * 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 "peripherals/pins.h" + +const mcu_pin_obj_t pin_GPIO0 = PIN(0, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO1 = PIN(1, ADC_UNIT_1, ADC_CHANNEL_0, TOUCH_PAD_NUM1); +const mcu_pin_obj_t pin_GPIO2 = PIN(2, ADC_UNIT_1, ADC_CHANNEL_1, TOUCH_PAD_NUM2); +const mcu_pin_obj_t pin_GPIO3 = PIN(3, ADC_UNIT_1, ADC_CHANNEL_2, TOUCH_PAD_NUM3); +const mcu_pin_obj_t pin_GPIO4 = PIN(4, ADC_UNIT_1, ADC_CHANNEL_3, TOUCH_PAD_NUM4); +const mcu_pin_obj_t pin_GPIO5 = PIN(5, ADC_UNIT_1, ADC_CHANNEL_4, TOUCH_PAD_NUM5); +const mcu_pin_obj_t pin_GPIO6 = PIN(6, ADC_UNIT_1, ADC_CHANNEL_5, TOUCH_PAD_NUM6); +const mcu_pin_obj_t pin_GPIO7 = PIN(7, ADC_UNIT_1, ADC_CHANNEL_6, TOUCH_PAD_NUM7); +const mcu_pin_obj_t pin_GPIO8 = PIN(8, ADC_UNIT_1, ADC_CHANNEL_7, TOUCH_PAD_NUM8); +const mcu_pin_obj_t pin_GPIO9 = PIN(9, ADC_UNIT_1, ADC_CHANNEL_8, TOUCH_PAD_NUM9); +const mcu_pin_obj_t pin_GPIO10 = PIN(10, ADC_UNIT_1, ADC_CHANNEL_9, TOUCH_PAD_NUM10); +const mcu_pin_obj_t pin_GPIO11 = PIN(11, ADC_UNIT_2, ADC_CHANNEL_0, TOUCH_PAD_NUM11); +const mcu_pin_obj_t pin_GPIO12 = PIN(12, ADC_UNIT_2, ADC_CHANNEL_1, TOUCH_PAD_NUM12); +const mcu_pin_obj_t pin_GPIO13 = PIN(13, ADC_UNIT_2, ADC_CHANNEL_2, TOUCH_PAD_NUM13); +const mcu_pin_obj_t pin_GPIO14 = PIN(14, ADC_UNIT_2, ADC_CHANNEL_3, TOUCH_PAD_NUM14); +const mcu_pin_obj_t pin_GPIO15 = PIN(15, ADC_UNIT_2, ADC_CHANNEL_4, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO16 = PIN(16, ADC_UNIT_2, ADC_CHANNEL_5, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO17 = PIN(17, ADC_UNIT_2, ADC_CHANNEL_6, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO18 = PIN(18, ADC_UNIT_2, ADC_CHANNEL_7, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO19 = PIN(19, ADC_UNIT_2, ADC_CHANNEL_8, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO20 = PIN(20, ADC_UNIT_2, ADC_CHANNEL_9, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO21 = PIN(21, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO26 = PIN(26, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO27 = PIN(27, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO28 = PIN(28, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO29 = PIN(29, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO30 = PIN(30, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO31 = PIN(31, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO32 = PIN(32, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO33 = PIN(33, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO34 = PIN(34, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO35 = PIN(35, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO36 = PIN(36, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO37 = PIN(37, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO38 = PIN(38, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO39 = PIN(39, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO40 = PIN(40, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO41 = PIN(41, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO42 = PIN(42, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO43 = PIN(43, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO44 = PIN(44, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO45 = PIN(45, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO46 = PIN(46, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO47 = PIN(47, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO48 = PIN(48, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); diff --git a/ports/espressif/peripherals/esp32s3/pins.h b/ports/espressif/peripherals/esp32s3/pins.h new file mode 100644 index 0000000000..c2a932f572 --- /dev/null +++ b/ports/espressif/peripherals/esp32s3/pins.h @@ -0,0 +1,80 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 microDev + * + * 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. + */ + +// DO NOT include this file directly. +// Use shared-bindings/microcontroller/Pin.h instead. +// This ensures that all necessary includes are already included. + +#ifndef MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_ESP32S3_PINS_H +#define MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_ESP32S3_PINS_H + +extern const mcu_pin_obj_t pin_GPIO0; +extern const mcu_pin_obj_t pin_GPIO1; +extern const mcu_pin_obj_t pin_GPIO2; +extern const mcu_pin_obj_t pin_GPIO3; +extern const mcu_pin_obj_t pin_GPIO4; +extern const mcu_pin_obj_t pin_GPIO5; +extern const mcu_pin_obj_t pin_GPIO6; +extern const mcu_pin_obj_t pin_GPIO7; +extern const mcu_pin_obj_t pin_GPIO8; +extern const mcu_pin_obj_t pin_GPIO9; +extern const mcu_pin_obj_t pin_GPIO10; +extern const mcu_pin_obj_t pin_GPIO11; +extern const mcu_pin_obj_t pin_GPIO12; +extern const mcu_pin_obj_t pin_GPIO13; +extern const mcu_pin_obj_t pin_GPIO14; +extern const mcu_pin_obj_t pin_GPIO15; +extern const mcu_pin_obj_t pin_GPIO16; +extern const mcu_pin_obj_t pin_GPIO17; +extern const mcu_pin_obj_t pin_GPIO18; +extern const mcu_pin_obj_t pin_GPIO19; +extern const mcu_pin_obj_t pin_GPIO20; +extern const mcu_pin_obj_t pin_GPIO21; +extern const mcu_pin_obj_t pin_GPIO26; +extern const mcu_pin_obj_t pin_GPIO27; +extern const mcu_pin_obj_t pin_GPIO28; +extern const mcu_pin_obj_t pin_GPIO29; +extern const mcu_pin_obj_t pin_GPIO30; +extern const mcu_pin_obj_t pin_GPIO31; +extern const mcu_pin_obj_t pin_GPIO32; +extern const mcu_pin_obj_t pin_GPIO33; +extern const mcu_pin_obj_t pin_GPIO34; +extern const mcu_pin_obj_t pin_GPIO35; +extern const mcu_pin_obj_t pin_GPIO36; +extern const mcu_pin_obj_t pin_GPIO37; +extern const mcu_pin_obj_t pin_GPIO38; +extern const mcu_pin_obj_t pin_GPIO39; +extern const mcu_pin_obj_t pin_GPIO40; +extern const mcu_pin_obj_t pin_GPIO41; +extern const mcu_pin_obj_t pin_GPIO42; +extern const mcu_pin_obj_t pin_GPIO43; +extern const mcu_pin_obj_t pin_GPIO44; +extern const mcu_pin_obj_t pin_GPIO45; +extern const mcu_pin_obj_t pin_GPIO46; +extern const mcu_pin_obj_t pin_GPIO47; +extern const mcu_pin_obj_t pin_GPIO48; + +#endif // MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_ESP32S3_PINS_H diff --git a/ports/espressif/peripherals/pcnt.h b/ports/espressif/peripherals/pcnt.h index 86a90b4444..b2bae7b371 100644 --- a/ports/espressif/peripherals/pcnt.h +++ b/ports/espressif/peripherals/pcnt.h @@ -28,6 +28,7 @@ #define MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_PCNT_HANDLER_H #include "driver/pcnt.h" +#include "soc/pcnt_struct.h" extern int peripherals_pcnt_init(pcnt_config_t pcnt_config); extern void peripherals_pcnt_deinit(pcnt_unit_t *unit); diff --git a/ports/espressif/peripherals/pins.h b/ports/espressif/peripherals/pins.h index 3bd66d49ac..4958c46410 100644 --- a/ports/espressif/peripherals/pins.h +++ b/ports/espressif/peripherals/pins.h @@ -67,8 +67,10 @@ extern const mp_obj_type_t mcu_pin_type; // Choose based on chip #ifdef CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/pins.h" -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif defined(CONFIG_IDF_TARGET_ESP32S2) #include "esp32s2/pins.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "esp32s3/pins.h" #endif #endif // MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_PINS_H diff --git a/ports/espressif/supervisor/port.c b/ports/espressif/supervisor/port.c index 30106075e7..277777a332 100644 --- a/ports/espressif/supervisor/port.c +++ b/ports/espressif/supervisor/port.c @@ -58,6 +58,9 @@ #if CIRCUITPY_COUNTIO || CIRCUITPY_ROTARYIO || CIRCUITPY_FREQUENCYIO #include "peripherals/pcnt.h" +#endif + +#if CIRCUITPY_TOUCHIO_USE_NATIVE #include "peripherals/touch.h" #endif @@ -69,17 +72,10 @@ #include "cam.h" #endif -#include "esp_heap_caps.h" -#include "esp_debug_helpers.h" - #include "soc/cache_memory.h" #include "soc/rtc_cntl_reg.h" -#ifdef CONFIG_IDF_TARGET_ESP32C3 -#include "components/esp_rom/include/esp32c3/rom/ets_sys.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "components/esp_rom/include/esp32s2/rom/ets_sys.h" -#endif +#include "esp_debug_helpers.h" #define HEAP_SIZE (48 * 1024) @@ -136,7 +132,7 @@ safe_mode_t port_init(void) { #ifdef CONFIG_IDF_TARGET_ESP32C3 common_hal_never_reset_pin(&pin_GPIO20); common_hal_never_reset_pin(&pin_GPIO21); - #elif CONFIG_IDF_TARGET_ESP32S2 + #elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) common_hal_never_reset_pin(&pin_GPIO43); common_hal_never_reset_pin(&pin_GPIO44); #endif @@ -153,7 +149,7 @@ safe_mode_t port_init(void) { common_hal_never_reset_pin(&pin_GPIO5); common_hal_never_reset_pin(&pin_GPIO6); common_hal_never_reset_pin(&pin_GPIO7); - #elif CONFIG_IDF_TARGET_ESP32S2 + #elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) common_hal_never_reset_pin(&pin_GPIO39); common_hal_never_reset_pin(&pin_GPIO40); common_hal_never_reset_pin(&pin_GPIO41); diff --git a/ports/espressif/supervisor/usb.c b/ports/espressif/supervisor/usb.c index 2137a7b0a4..7be3e84536 100644 --- a/ports/espressif/supervisor/usb.c +++ b/ports/espressif/supervisor/usb.c @@ -33,6 +33,7 @@ #include "shared/readline/readline.h" #include "hal/gpio_ll.h" +#include "hal/usb_hal.h" #include "soc/usb_periph.h" #include "components/driver/include/driver/gpio.h" @@ -40,15 +41,15 @@ #ifdef CONFIG_IDF_TARGET_ESP32C3 #include "components/esp_rom/include/esp32c3/rom/gpio.h" -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif defined(CONFIG_IDF_TARGET_ESP32S2) #include "components/esp_rom/include/esp32s2/rom/gpio.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "components/esp_rom/include/esp32s3/rom/gpio.h" #endif #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "hal/usb_hal.h" - #include "tusb.h" #ifdef CFG_TUSB_DEBUG