From f7f61c51be06fde04198456e6b57d3d393a8b3b8 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Tue, 13 Aug 2024 22:48:14 +0200 Subject: [PATCH] Tasmota and esp32-p4 changes --- CMakeLists.txt | 102 +--------- Kconfig.projbuild | 31 --- README.md | 75 +------ cores/esp32/Client.h | 2 + cores/esp32/Esp.cpp | 6 + cores/esp32/HWCDC.cpp | 18 +- cores/esp32/HardwareSerial.cpp | 24 +-- cores/esp32/HardwareSerial.h | 24 ++- cores/esp32/esp32-hal-cpu.c | 18 +- cores/esp32/esp32-hal-i2c-slave.c | 33 +++- cores/esp32/esp32-hal-ledc.c | 10 + cores/esp32/esp32-hal-matrix.c | 2 + cores/esp32/esp32-hal-misc.c | 6 +- cores/esp32/esp32-hal-psram.c | 2 + cores/esp32/esp32-hal-spi.c | 185 ++++++++++-------- cores/esp32/esp32-hal-spi.h | 2 +- cores/esp32/esp32-hal-uart.c | 57 +++--- cores/esp32/main.cpp | 6 + docs/en/migration_guides/2.x_to_3.0.rst | 1 - idf_component.yml | 47 +---- .../examples/RMT/RMTLoopback/RMTLoopback.ino | 2 +- .../ResetReason/ResetReason/ResetReason.ino | 2 + libraries/ESP_I2S/src/ESP_I2S.cpp | 4 +- libraries/ESP_I2S/src/ESP_I2S.h | 2 +- libraries/Ethernet/src/ETH.cpp | 5 + libraries/Ethernet/src/ETH.h | 3 + libraries/HTTPClient/src/HTTPClient.cpp | 2 + libraries/HTTPClient/src/HTTPClient.h | 4 + libraries/Network/src/NetworkClient.cpp | 10 +- libraries/Network/src/NetworkClient.h | 5 +- libraries/Network/src/NetworkEvents.h | 8 + libraries/Network/src/NetworkUdp.cpp | 4 +- libraries/Network/src/NetworkUdp.h | 3 +- libraries/PPP/src/PPP.cpp | 2 +- libraries/PPP/src/PPP.h | 2 +- libraries/SD_MMC/src/SD_MMC.cpp | 14 +- libraries/SPI/src/SPI.cpp | 2 +- libraries/Update/src/Update.h | 54 +---- libraries/Update/src/Updater.cpp | 185 +----------------- libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino | 2 +- libraries/WiFi/src/STA.cpp | 99 ---------- libraries/WiFi/src/WiFiGeneric.cpp | 9 +- libraries/WiFi/src/WiFiGeneric.h | 4 + libraries/WiFi/src/WiFiSTA.cpp | 4 +- libraries/WiFi/src/WiFiSTA.h | 10 +- tools/platformio-build.py | 23 ++- variants/esp32p4/pins_arduino.h | 35 ++++ 47 files changed, 400 insertions(+), 750 deletions(-) create mode 100644 variants/esp32p4/pins_arduino.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2086932a2d5..a10906d8463 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ # idf.py build set(min_supported_idf_version "5.1.0") -set(max_supported_idf_version "5.1.99") +set(max_supported_idf_version "5.3.99") set(idf_version "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH}") if ("${idf_version}" AND NOT "$ENV{ARDUINO_SKIP_IDF_VERSION_CHECK}") @@ -25,7 +25,6 @@ endif() set(CORE_SRCS cores/esp32/base64.cpp cores/esp32/cbuf.cpp - cores/esp32/chip-debug-report.cpp cores/esp32/esp32-hal-adc.c cores/esp32/esp32-hal-bt.c cores/esp32/esp32-hal-cpu.c @@ -78,39 +77,27 @@ set(CORE_SRCS set(ARDUINO_ALL_LIBRARIES ArduinoOTA AsyncUDP - BLE - BluetoothSerial DNSServer EEPROM - ESP_I2S - ESP_NOW - ESP_SR ESPmDNS Ethernet FFat FS HTTPClient HTTPUpdate - Insights LittleFS NetBIOS Network - OpenThread PPP Preferences - RainMaker SD_MMC SD - SimpleBLE - SPIFFS SPI Ticker Update USB WebServer - NetworkClientSecure WiFi - WiFiProv Wire ) @@ -119,26 +106,10 @@ set(ARDUINO_LIBRARY_ArduinoOTA_REQUIRES esp_https_ota) set(ARDUINO_LIBRARY_AsyncUDP_SRCS libraries/AsyncUDP/src/AsyncUDP.cpp) -set(ARDUINO_LIBRARY_BluetoothSerial_SRCS - libraries/BluetoothSerial/src/BluetoothSerial.cpp - libraries/BluetoothSerial/src/BTAddress.cpp - libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp - libraries/BluetoothSerial/src/BTScanResultsSet.cpp) - set(ARDUINO_LIBRARY_DNSServer_SRCS libraries/DNSServer/src/DNSServer.cpp) set(ARDUINO_LIBRARY_EEPROM_SRCS libraries/EEPROM/src/EEPROM.cpp) -set(ARDUINO_LIBRARY_ESP_I2S_SRCS libraries/ESP_I2S/src/ESP_I2S.cpp) - -set(ARDUINO_LIBRARY_ESP_NOW_SRCS - libraries/ESP_NOW/src/ESP32_NOW.cpp - libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp) - -set(ARDUINO_LIBRARY_ESP_SR_SRCS - libraries/ESP_SR/src/ESP_SR.cpp - libraries/ESP_SR/src/esp32-hal-sr.c) - set(ARDUINO_LIBRARY_ESPmDNS_SRCS libraries/ESPmDNS/src/ESPmDNS.cpp) set(ARDUINO_LIBRARY_Ethernet_SRCS libraries/Ethernet/src/ETH.cpp) @@ -153,32 +124,16 @@ set(ARDUINO_LIBRARY_HTTPClient_SRCS libraries/HTTPClient/src/HTTPClient.cpp) set(ARDUINO_LIBRARY_HTTPUpdate_SRCS libraries/HTTPUpdate/src/HTTPUpdate.cpp) -set(ARDUINO_LIBRARY_Insights_SRCS libraries/Insights/src/Insights.cpp) - set(ARDUINO_LIBRARY_LittleFS_SRCS libraries/LittleFS/src/LittleFS.cpp) set(ARDUINO_LIBRARY_NetBIOS_SRCS libraries/NetBIOS/src/NetBIOS.cpp) -set(ARDUINO_LIBRARY_OpenThread_SRCS - libraries/OpenThread/src/OThreadCLI.cpp - libraries/OpenThread/src/OThreadCLI_Util.cpp) - set(ARDUINO_LIBRARY_PPP_SRCS libraries/PPP/src/PPP.cpp libraries/PPP/src/ppp.c) set(ARDUINO_LIBRARY_Preferences_SRCS libraries/Preferences/src/Preferences.cpp) -set(ARDUINO_LIBRARY_RainMaker_SRCS - libraries/RainMaker/src/RMaker.cpp - libraries/RainMaker/src/RMakerNode.cpp - libraries/RainMaker/src/RMakerParam.cpp - libraries/RainMaker/src/RMakerDevice.cpp - libraries/RainMaker/src/RMakerType.cpp - libraries/RainMaker/src/RMakerQR.cpp - libraries/RainMaker/src/RMakerUtils.cpp - libraries/RainMaker/src/AppInsights.cpp) - set(ARDUINO_LIBRARY_SD_MMC_SRCS libraries/SD_MMC/src/SD_MMC.cpp) set(ARDUINO_LIBRARY_SD_SRCS @@ -186,10 +141,6 @@ set(ARDUINO_LIBRARY_SD_SRCS libraries/SD/src/sd_diskio.cpp libraries/SD/src/sd_diskio_crc.c) -set(ARDUINO_LIBRARY_SimpleBLE_SRCS libraries/SimpleBLE/src/SimpleBLE.cpp) - -set(ARDUINO_LIBRARY_SPIFFS_SRCS libraries/SPIFFS/src/SPIFFS.cpp) - set(ARDUINO_LIBRARY_SPI_SRCS libraries/SPI/src/SPI.cpp) set(ARDUINO_LIBRARY_Ticker_SRCS libraries/Ticker/src/Ticker.cpp) @@ -214,10 +165,6 @@ set(ARDUINO_LIBRARY_WebServer_SRCS libraries/WebServer/src/Parsing.cpp libraries/WebServer/src/detail/mimetable.cpp) -set(ARDUINO_LIBRARY_NetworkClientSecure_SRCS - libraries/NetworkClientSecure/src/ssl_client.cpp - libraries/NetworkClientSecure/src/NetworkClientSecure.cpp) - set(ARDUINO_LIBRARY_Network_SRCS libraries/Network/src/NetworkInterface.cpp libraries/Network/src/NetworkEvents.cpp @@ -236,43 +183,8 @@ set(ARDUINO_LIBRARY_WiFi_SRCS libraries/WiFi/src/STA.cpp libraries/WiFi/src/AP.cpp) -set(ARDUINO_LIBRARY_WiFiProv_SRCS libraries/WiFiProv/src/WiFiProv.cpp) - set(ARDUINO_LIBRARY_Wire_SRCS libraries/Wire/src/Wire.cpp) -set(ARDUINO_LIBRARY_BLE_SRCS - libraries/BLE/src/BLE2901.cpp - libraries/BLE/src/BLE2902.cpp - libraries/BLE/src/BLE2904.cpp - libraries/BLE/src/BLEAddress.cpp - libraries/BLE/src/BLEAdvertisedDevice.cpp - libraries/BLE/src/BLEAdvertising.cpp - libraries/BLE/src/BLEBeacon.cpp - libraries/BLE/src/BLECharacteristic.cpp - libraries/BLE/src/BLECharacteristicMap.cpp - libraries/BLE/src/BLEClient.cpp - libraries/BLE/src/BLEDescriptor.cpp - libraries/BLE/src/BLEDescriptorMap.cpp - libraries/BLE/src/BLEDevice.cpp - libraries/BLE/src/BLEEddystoneTLM.cpp - libraries/BLE/src/BLEEddystoneURL.cpp - libraries/BLE/src/BLEExceptions.cpp - libraries/BLE/src/BLEHIDDevice.cpp - libraries/BLE/src/BLERemoteCharacteristic.cpp - libraries/BLE/src/BLERemoteDescriptor.cpp - libraries/BLE/src/BLERemoteService.cpp - libraries/BLE/src/BLEScan.cpp - libraries/BLE/src/BLESecurity.cpp - libraries/BLE/src/BLEServer.cpp - libraries/BLE/src/BLEService.cpp - libraries/BLE/src/BLEServiceMap.cpp - libraries/BLE/src/BLEUtils.cpp - libraries/BLE/src/BLEUUID.cpp - libraries/BLE/src/BLEValue.cpp - libraries/BLE/src/FreeRTOS.cpp - libraries/BLE/src/GeneralUtils.cpp - ) - set(ARDUINO_LIBRARIES_SRCS) set(ARDUINO_LIBRARIES_REQUIRES) set(ARDUINO_LIBRARIES_INCLUDEDIRS) @@ -293,16 +205,8 @@ endforeach() set(includedirs variants/${CONFIG_ARDUINO_VARIANT}/ cores/esp32/ ${ARDUINO_LIBRARIES_INCLUDEDIRS}) set(srcs ${CORE_SRCS} ${ARDUINO_LIBRARIES_SRCS}) set(priv_includes cores/esp32/libb64) -set(requires spi_flash esp_partition mbedtls wifi_provisioning wpa_supplicant esp_adc esp_eth http_parser) -set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support bt esp_hid usb esp_psram ${ARDUINO_LIBRARIES_REQUIRES}) - -if(NOT CONFIG_ARDUINO_SELECTIVE_COMPILATION OR CONFIG_ARDUINO_SELECTIVE_OpenThread) - #if(CONFIG_SOC_IEEE802154_SUPPORTED) # Does not work! - #if(CONFIG_OPENTHREAD_ENABLED) # Does not work! - if(IDF_TARGET STREQUAL "esp32c6" OR IDF_TARGET STREQUAL "esp32h2") # Sadly only this works - list(APPEND requires openthread) - endif() -endif() +set(requires spi_flash esp_partition mbedtls wpa_supplicant esp_adc esp_eth http_parser) +set(priv_requires fatfs nvs_flash app_update bootloader_support bt esp_hid usb esp_psram ${ARDUINO_LIBRARIES_REQUIRES}) idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires}) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index 2085a11ea7d..9b53fb77e81 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -301,11 +301,6 @@ config ARDUINO_SELECTIVE_SD_MMC depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_FS default y -config ARDUINO_SELECTIVE_SPIFFS - bool "Enable SPIFFS" - depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_FS - default y - config ARDUINO_SELECTIVE_FFat bool "Enable FFat" depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_FS @@ -355,7 +350,6 @@ config ARDUINO_SELECTIVE_ESPmDNS config ARDUINO_SELECTIVE_HTTPClient bool "Enable HTTPClient" depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Network - select ARDUINO_SELECTIVE_NetworkClientSecure default y config ARDUINO_SELECTIVE_NetBIOS @@ -374,29 +368,4 @@ config ARDUINO_SELECTIVE_WiFi depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Network default y -config ARDUINO_SELECTIVE_NetworkClientSecure - bool "Enable NetworkClientSecure" - depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Network - default y - -config ARDUINO_SELECTIVE_WiFiProv - bool "Enable WiFiProv" - depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Network && ARDUINO_SELECTIVE_WiFi - default y - -config ARDUINO_SELECTIVE_BLE - bool "Enable BLE" - depends on ARDUINO_SELECTIVE_COMPILATION - default y - -config ARDUINO_SELECTIVE_BluetoothSerial - bool "Enable BluetoothSerial" - depends on ARDUINO_SELECTIVE_COMPILATION - default y - -config ARDUINO_SELECTIVE_SimpleBLE - bool "Enable SimpleBLE" - depends on ARDUINO_SELECTIVE_COMPILATION - default y - endmenu diff --git a/README.md b/README.md index ee1880b8d05..f29fcdba288 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,6 @@ -# Arduino core for the ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2 +# Tasmota Platformio Arduino for ESP32, ESP32-S2, ESP32-S3, ESP32-C2, ESP32-C3, ESP32-C6 and ESP32-H2 -[![Build Status](https://github.com/espressif/arduino-esp32/actions/workflows/push.yml/badge.svg?branch=master&event=push)](https://github.com/espressif/arduino-esp32/actions/workflows/push.yml) [![External Libraries Test](https://github.com/espressif/arduino-esp32/actions/workflows/lib.yml/badge.svg?branch=master&event=schedule)](https://github.com/espressif/arduino-esp32/blob/gh-pages/LIBRARIES_TEST.md) [![Hardware Tests](https://github.com/espressif/arduino-esp32/blob/gh-pages/runtime-tests-results/badge.svg)](https://github.com/espressif/arduino-esp32/actions/workflows/tests_results.yml) - -### Need help or have a question? Join the chat at [Gitter](https://gitter.im/espressif/arduino-esp32) or [open a new Discussion](https://github.com/espressif/arduino-esp32/discussions) - -## Contents - - - [Development Status](#development-status) - - [Development Planning](#development-planning) - - [Documentation](#documentation) - - [Supported Chips](#supported-chips) - - [Decoding exceptions](#decoding-exceptions) - - [Issue/Bug report template](#issuebug-report-template) - - [Contributing](#contributing) - -### Development Status - -Latest Stable Release [![Release Version](https://img.shields.io/github/release/espressif/arduino-esp32.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/latest/) [![Release Date](https://img.shields.io/github/release-date/espressif/arduino-esp32.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/latest/) [![Downloads](https://img.shields.io/github/downloads/espressif/arduino-esp32/latest/total.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/latest/) - -Latest Development Release [![Release Version](https://img.shields.io/github/release/espressif/arduino-esp32/all.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) [![Release Date](https://img.shields.io/github/release-date-pre/espressif/arduino-esp32.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) [![Downloads](https://img.shields.io/github/downloads-pre/espressif/arduino-esp32/latest/total.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) - -### Development Planning - -Our Development is fully tracked on this public **[Roadmap 🎉](https://github.com/orgs/espressif/projects/3)** - -For even more information you can join our **[Monthly Community Meetings 🔔](https://github.com/espressif/arduino-esp32/discussions/categories/monthly-community-meetings).** +### [![GitHub Releases](https://img.shields.io/github/downloads/tasmota/arduino-esp32/total?label=downloads)](https://github.com/tasmota/arduino-esp32/releases/latest) ### Documentation @@ -33,58 +9,25 @@ You can use the [Arduino-ESP32 Online Documentation](https://docs.espressif.com/ --- **Migration guide from version 2.x to 3.x is available [here](https://docs.espressif.com/projects/arduino-esp32/en/latest/migration_guides/2.x_to_3.0.html).** +The mentioned change from `flush` to `clear` is NOT done! --- -**APIs compatibility with ESP8266 and Arduino-CORE (Arduino.cc) is explained [here](https://docs.espressif.com/projects/arduino-esp32/en/latest/libraries.html#apis).** - ---- - -* [Getting Started](https://docs.espressif.com/projects/arduino-esp32/en/latest/getting_started.html) -* [Installing (Windows, Linux and macOS)](https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html) -* [Libraries](https://docs.espressif.com/projects/arduino-esp32/en/latest/libraries.html) -* [Arduino as an ESP-IDF component](https://docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html) -* [FAQ](https://docs.espressif.com/projects/arduino-esp32/en/latest/faq.html) -* [Troubleshooting](https://docs.espressif.com/projects/arduino-esp32/en/latest/troubleshooting.html) - ### Supported Chips -Here are the ESP32 series supported by the Arduino-ESP32 project: +Here are the ESP32 series supported by the Tasmota Arduino-ESP32 project: | **SoC** | **Stable** | **Development** | **Datasheet** | |----------|:----------:|:---------------:|:-------------------------------------------------------------------------------------------------:| -| ESP32 | Yes | Yes | [ESP32](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) | +| ESP32 | Yes | Yes | [ESP32](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) | +| ESP32solo1| Yes | Yes | [ESP32solo1](https://www.espressif.com/sites/default/files/documentation/esp32-solo-1_datasheet_en.pdf) | | ESP32-S2 | Yes | Yes | [ESP32-S2](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf) | -| ESP32-C3 | Yes | Yes | [ESP32-C3](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) | | ESP32-S3 | Yes | Yes | [ESP32-S3](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf) | +| ESP32-C2 | Yes | Yes | [ESP32-C2](https://www.espressif.com/sites/default/files/documentation/esp8684_datasheet_en.pdf) | +| ESP32-C3 | Yes | Yes | [ESP32-C3](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) | | ESP32-C6 | Yes | Yes | [ESP32-C6](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf) | | ESP32-H2 | Yes | Yes | [ESP32-H2](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf) | +| ESP32-P4 | No | Yes | ESP32-P4 | -> [!NOTE] -> ESP32-C2 is also supported by Arduino-ESP32 but requires rebuilding the static libraries. This is not trivial and requires a good understanding of the ESP-IDF -> build system. For more information, see the [Lib Builder documentation](https://docs.espressif.com/projects/arduino-esp32/en/latest/lib_builder.html). For more details visit the [supported chips](https://docs.espressif.com/projects/arduino-esp32/en/latest/getting_started.html#supported-soc-s) documentation page. - -### Decoding exceptions - -You can use [EspExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecoder) to get meaningful call trace. - -### Issue/Bug report template - -Before reporting an issue, make sure you've searched for similar one that was already created. Also make sure to go through all the issues labeled as [Type: For reference](https://github.com/espressif/arduino-esp32/issues?q=is%3Aissue+label%3A%22Type%3A+For+reference%22+). - -Finally, if you are sure no one else had the issue, follow the **Issue template** or **Feature request template** while reporting any [new Issue](https://github.com/espressif/arduino-esp32/issues/new/choose). - -### External libraries compilation test - -We have set-up CI testing for external libraries for ESP32 Arduino core. You can check test results in the file [LIBRARIES_TEST](https://github.com/espressif/arduino-esp32/blob/gh-pages/LIBRARIES_TEST.md). -For more information and how to add your library to the test see [external library testing](https://docs.espressif.com/projects/arduino-esp32/en/latest/external_libraries_test.html) in the documentation. - -### Contributing - -We welcome contributions to the Arduino ESP32 project! - -See [contributing](https://docs.espressif.com/projects/arduino-esp32/en/latest/contributing.html) in the documentation for more information on how to contribute to the project. - -> We would like to have this repository in a polite and friendly atmosphere, so please be kind and respectful to others. For more details, look at [Code of Conduct](https://github.com/espressif/arduino-esp32/blob/master/CODE_OF_CONDUCT.md). diff --git a/cores/esp32/Client.h b/cores/esp32/Client.h index ab013612401..582239de9eb 100644 --- a/cores/esp32/Client.h +++ b/cores/esp32/Client.h @@ -26,7 +26,9 @@ class Client : public Stream { public: virtual int connect(IPAddress ip, uint16_t port) = 0; + virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0; virtual int connect(const char *host, uint16_t port) = 0; + virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0; virtual size_t write(uint8_t) = 0; virtual size_t write(const uint8_t *buf, size_t size) = 0; virtual int available() = 0; diff --git a/cores/esp32/Esp.cpp b/cores/esp32/Esp.cpp index a463fc16ba0..35a8f9facf7 100644 --- a/cores/esp32/Esp.cpp +++ b/cores/esp32/Esp.cpp @@ -60,6 +60,9 @@ extern "C" { #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/spi_flash.h" #define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32h2 is located at 0x0000 +#elif CONFIG_IDF_TARGET_ESP32P4 +#include "esp32p4/rom/spi_flash.h" +#define ESP_FLASH_IMAGE_BASE 0x2000 // Esp32p4 is located at 0x2000 #else #error Target CONFIG_IDF_TARGET is not supported #endif @@ -335,6 +338,8 @@ uint32_t EspClass::getFlashChipSpeed(void) { return magicFlashChipSpeed(fhdr.spi_speed); } +// FIXME for P4 +#if !defined(CONFIG_IDF_TARGET_ESP32P4) FlashMode_t EspClass::getFlashChipMode(void) { #if CONFIG_IDF_TARGET_ESP32S2 uint32_t spi_ctrl = REG_READ(PERIPHS_SPI_FLASH_CTRL); @@ -361,6 +366,7 @@ FlashMode_t EspClass::getFlashChipMode(void) { } return (FM_DOUT); } +#endif // if !defined(CONFIG_IDF_TARGET_ESP32P4) uint32_t EspClass::magicFlashChipSize(uint8_t byte) { /* diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index b0f653e889e..8f243827579 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -285,15 +285,17 @@ bool HWCDC::deinit(void *busptr) { } running = true; // Setting USB D+ D- pins + // USB_DM_GPIO_NUM USB_DP_GPIO_NUM + // USB_INT_PHY0_DM_GPIO_NUM USB_INT_PHY0_DP_GPIO_NUM bool retCode = true; - retCode &= perimanClearPinBus(USB_DM_GPIO_NUM); - retCode &= perimanClearPinBus(USB_DP_GPIO_NUM); + retCode &= perimanClearPinBus(USB_INT_PHY0_DM_GPIO_NUM); + retCode &= perimanClearPinBus(USB_INT_PHY0_DP_GPIO_NUM); if (retCode) { // Force the host to re-enumerate (BUS_RESET) - pinMode(USB_DM_GPIO_NUM, OUTPUT_OPEN_DRAIN); - pinMode(USB_DP_GPIO_NUM, OUTPUT_OPEN_DRAIN); - digitalWrite(USB_DM_GPIO_NUM, LOW); - digitalWrite(USB_DP_GPIO_NUM, LOW); + pinMode(USB_INT_PHY0_DM_GPIO_NUM, OUTPUT_OPEN_DRAIN); + pinMode(USB_INT_PHY0_DP_GPIO_NUM, OUTPUT_OPEN_DRAIN); + digitalWrite(USB_INT_PHY0_DM_GPIO_NUM, LOW); + digitalWrite(USB_INT_PHY0_DP_GPIO_NUM, LOW); } // release the flag running = false; @@ -323,11 +325,11 @@ void HWCDC::begin(unsigned long baud) { // delay(10); // USB Host has to enumerate it again // Peripheral Manager setting for USB D+ D- pins - uint8_t pin = USB_DM_GPIO_NUM; + uint8_t pin = USB_INT_PHY0_DM_GPIO_NUM; if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DM, (void *)this, -1, -1)) { goto err; } - pin = USB_DP_GPIO_NUM; + pin = USB_INT_PHY0_DP_GPIO_NUM; if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DP, (void *)this, -1, -1)) { goto err; } diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 1f064faada6..c1cf8200a32 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -26,23 +26,23 @@ void serialEvent(void) __attribute__((weak)); void serialEvent(void) {} -#if SOC_UART_NUM > 1 +#if SOC_UART_HP_NUM > 1 void serialEvent1(void) __attribute__((weak)); void serialEvent1(void) {} -#endif /* SOC_UART_NUM > 1 */ +#endif /* SOC_UART_HP_NUM > 1 */ -#if SOC_UART_NUM > 2 +#if SOC_UART_HP_NUM > 2 void serialEvent2(void) __attribute__((weak)); void serialEvent2(void) {} -#endif /* SOC_UART_NUM > 2 */ +#endif /* SOC_UART_HP_NUM > 2 */ #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) // There is always Seria0 for UART0 HardwareSerial Serial0(0); -#if SOC_UART_NUM > 1 +#if SOC_UART_HP_NUM > 1 HardwareSerial Serial1(1); #endif -#if SOC_UART_NUM > 2 +#if SOC_UART_HP_NUM > 2 HardwareSerial Serial2(2); #endif @@ -72,12 +72,12 @@ void serialEventRun(void) { if (Serial0.available()) { serialEvent(); } -#if SOC_UART_NUM > 1 +#if SOC_UART_HP_NUM > 1 if (Serial1.available()) { serialEvent1(); } #endif -#if SOC_UART_NUM > 2 +#if SOC_UART_HP_NUM > 2 if (Serial2.available()) { serialEvent2(); } @@ -279,8 +279,8 @@ void HardwareSerial::_uartEventTask(void *args) { } void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms, uint8_t rxfifo_full_thrhd) { - if (_uart_nr >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use a number from 0 to %u", SOC_UART_NUM - 1); + if (_uart_nr >= SOC_UART_HP_NUM) { + log_e("Serial number is invalid, please use a number from 0 to %u", SOC_UART_HP_NUM - 1); return; } @@ -305,7 +305,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in txPin = _txPin < 0 ? (int8_t)SOC_TX0 : _txPin; } break; -#if SOC_UART_NUM > 1 // may save some flash bytes... +#if SOC_UART_HP_NUM > 1 // may save some flash bytes... case UART_NUM_1: if (rxPin < 0 && txPin < 0) { // do not change RX1/TX1 if it has already been set before @@ -314,7 +314,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in } break; #endif -#if SOC_UART_NUM > 2 // may save some flash bytes... +#if SOC_UART_HP_NUM > 2 // may save some flash bytes... case UART_NUM_2: if (rxPin < 0 && txPin < 0) { // do not change RX2/TX2 if it has already been set before diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 3fd5e7dc99b..8bd9c5c181a 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -125,6 +125,8 @@ typedef enum { #define SOC_RX0 (gpio_num_t)17 #elif CONFIG_IDF_TARGET_ESP32H2 #define SOC_RX0 (gpio_num_t)23 +#elif CONFIG_IDF_TARGET_ESP32P4 +#define SOC_RX0 (gpio_num_t)38 #endif #endif @@ -141,12 +143,14 @@ typedef enum { #define SOC_TX0 (gpio_num_t)16 #elif CONFIG_IDF_TARGET_ESP32H2 #define SOC_TX0 (gpio_num_t)24 +#elif CONFIG_IDF_TARGET_ESP32P4 +#define SOC_TX0 (gpio_num_t)37 #endif #endif // Default pins for UART1 are arbitrary, and defined here for convenience. -#if SOC_UART_NUM > 1 +#if SOC_UART_HP_NUM > 1 #ifndef RX1 #if CONFIG_IDF_TARGET_ESP32 #define RX1 (gpio_num_t)26 @@ -162,6 +166,8 @@ typedef enum { #define RX1 (gpio_num_t)4 #elif CONFIG_IDF_TARGET_ESP32H2 #define RX1 (gpio_num_t)0 +#elif CONFIG_IDF_TARGET_ESP32P4 +#define RX1 (gpio_num_t)11 #endif #endif @@ -180,18 +186,22 @@ typedef enum { #define TX1 (gpio_num_t)5 #elif CONFIG_IDF_TARGET_ESP32H2 #define TX1 (gpio_num_t)1 +#elif CONFIG_IDF_TARGET_ESP32P4 +#define TX1 (gpio_num_t)10 #endif #endif -#endif /* SOC_UART_NUM > 1 */ +#endif /* SOC_UART_HP_NUM > 1 */ // Default pins for UART2 are arbitrary, and defined here for convenience. -#if SOC_UART_NUM > 2 +#if SOC_UART_HP_NUM > 2 #ifndef RX2 #if CONFIG_IDF_TARGET_ESP32 #define RX2 (gpio_num_t)4 #elif CONFIG_IDF_TARGET_ESP32S3 #define RX2 (gpio_num_t)19 +#elif CONFIG_IDF_TARGET_ESP32P4 +#define RX2 (gpio_num_t)15 #endif #endif @@ -200,9 +210,11 @@ typedef enum { #define TX2 (gpio_num_t)25 #elif CONFIG_IDF_TARGET_ESP32S3 #define TX2 (gpio_num_t)20 +#elif CONFIG_IDF_TARGET_ESP32P4 +#define TX2 (gpio_num_t)14 #endif #endif -#endif /* SOC_UART_NUM > 2 */ +#endif /* SOC_UART_HP_NUM > 2 */ typedef std::function OnReceiveCb; typedef std::function OnReceiveErrorCb; @@ -357,10 +369,10 @@ extern void serialEventRun(void) __attribute__((weak)); #endif // ARDUINO_USB_CDC_ON_BOOT // There is always Seria0 for UART0 extern HardwareSerial Serial0; -#if SOC_UART_NUM > 1 +#if SOC_UART_HP_NUM > 1 extern HardwareSerial Serial1; #endif -#if SOC_UART_NUM > 2 +#if SOC_UART_HP_NUM > 2 extern HardwareSerial Serial2; #endif #endif //!defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) diff --git a/cores/esp32/esp32-hal-cpu.c b/cores/esp32/esp32-hal-cpu.c index 7027c7cad9d..070afba4810 100644 --- a/cores/esp32/esp32-hal-cpu.c +++ b/cores/esp32/esp32-hal-cpu.c @@ -19,9 +19,9 @@ #include "esp_attr.h" #include "esp_log.h" #include "soc/rtc.h" -#if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) +#if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4) #include "soc/rtc_cntl_reg.h" -#include "soc/apb_ctrl_reg.h" +#include "soc/syscon_reg.h" #endif #include "soc/efuse_reg.h" #include "esp32-hal.h" @@ -30,13 +30,13 @@ #include "esp_system.h" #ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 -#include "freertos/xtensa_timer.h" +#include "xtensa_timer.h" #include "esp32/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32S2 -#include "freertos/xtensa_timer.h" +#include "xtensa_timer.h" #include "esp32s2/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32S3 -#include "freertos/xtensa_timer.h" +#include "xtensa_timer.h" #include "esp32s3/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32C2 #include "esp32c2/rom/rtc.h" @@ -46,6 +46,8 @@ #include "esp32c6/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/rtc.h" +#elif CONFIG_IDF_TARGET_ESP32P4 +#include "esp32p4/rom/rtc.h" #else #error Target CONFIG_IDF_TARGET is not supported #endif @@ -161,7 +163,7 @@ bool removeApbChangeCallback(void *arg, apb_change_cb_t cb) { } static uint32_t calculateApb(rtc_cpu_freq_config_t *conf) { -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 return APB_CLK_FREQ; #else if (conf->freq_mhz >= 80) { @@ -235,7 +237,7 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz) { } //Make the frequency change rtc_clk_cpu_freq_set_config_fast(&conf); -#if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) +#if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4) if (capb != apb) { //Update REF_TICK (uncomment if REF_TICK is different than 1MHz) //if(conf.freq_mhz < 80){ @@ -248,7 +250,7 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz) { } #endif //Update FreeRTOS Tick Divisor -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 #elif CONFIG_IDF_TARGET_ESP32S3 diff --git a/cores/esp32/esp32-hal-i2c-slave.c b/cores/esp32/esp32-hal-i2c-slave.c index edae1e57c92..790203fcec2 100644 --- a/cores/esp32/esp32-hal-i2c-slave.c +++ b/cores/esp32/esp32-hal-i2c-slave.c @@ -49,6 +49,7 @@ #define I2C_SLAVE_USE_RX_QUEUE 0 // 1: Queue, 0: RingBuffer +#if !defined(CONFIG_IDF_TARGET_ESP32P4) #if SOC_I2C_NUM > 1 #define I2C_SCL_IDX(p) ((p == 0) ? I2CEXT0_SCL_OUT_IDX : ((p == 1) ? I2CEXT1_SCL_OUT_IDX : 0)) #define I2C_SDA_IDX(p) ((p == 0) ? I2CEXT0_SDA_OUT_IDX : ((p == 1) ? I2CEXT1_SDA_OUT_IDX : 0)) @@ -56,6 +57,12 @@ #define I2C_SCL_IDX(p) I2CEXT0_SCL_OUT_IDX #define I2C_SDA_IDX(p) I2CEXT0_SDA_OUT_IDX #endif +#endif // !defined(CONFIG_IDF_TARGET_ESP32P4) + +#ifdef CONFIG_IDF_TARGET_ESP32P4 +#define I2C_SCL_IDX(p) ((p == 0) ? I2C0_SCL_PAD_OUT_IDX : ((p == 1) ? I2C1_SCL_PAD_OUT_IDX : 0)) +#define I2C_SDA_IDX(p) ((p == 0) ? I2C0_SDA_PAD_OUT_IDX : ((p == 1) ? I2C1_SDA_PAD_OUT_IDX : 0)) +#endif // ifdef CONFIG_IDF_TARGET_ESP32P4 #if CONFIG_IDF_TARGET_ESP32 #define I2C_TXFIFO_WM_INT_ENA I2C_TXFIFO_EMPTY_INT_ENA @@ -173,7 +180,7 @@ static inline void i2c_ll_stretch_clr(i2c_dev_t *hw) { } static inline bool i2c_ll_slave_addressed(i2c_dev_t *hw) { -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 return hw->sr.slave_addressed; #else return hw->status_reg.slave_addressed; @@ -182,7 +189,7 @@ static inline bool i2c_ll_slave_addressed(i2c_dev_t *hw) { static inline bool i2c_ll_slave_rw(i2c_dev_t *hw) //not exposed by hal_ll { -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 return hw->sr.slave_rw; #else return hw->status_reg.slave_rw; @@ -316,7 +323,7 @@ esp_err_t i2cSlaveInit(uint8_t num, int sda, int scl, uint16_t slaveID, uint32_t } i2c_ll_slave_init(i2c->dev); - i2c_ll_set_fifo_mode(i2c->dev, true); + i2c_ll_set_data_mode(i2c->dev, I2C_DATA_MODE_MSB_FIRST, I2C_DATA_MODE_MSB_FIRST); i2c_ll_set_slave_addr(i2c->dev, slaveID, false); i2c_ll_set_tout(i2c->dev, I2C_LL_MAX_TIMEOUT); i2c_slave_set_frequency(i2c, frequency); @@ -337,16 +344,26 @@ esp_err_t i2cSlaveInit(uint8_t num, int sda, int scl, uint16_t slaveID, uint32_t i2c_ll_disable_intr_mask(i2c->dev, I2C_LL_INTR_MASK); i2c_ll_clear_intr_mask(i2c->dev, I2C_LL_INTR_MASK); - i2c_ll_set_fifo_mode(i2c->dev, true); + i2c_ll_set_data_mode(i2c->dev, I2C_DATA_MODE_MSB_FIRST, I2C_DATA_MODE_MSB_FIRST); if (!i2c->intr_handle) { uint32_t flags = ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED; +#if !defined(CONFIG_IDF_TARGET_ESP32P4) if (i2c->num == 0) { ret = esp_intr_alloc(ETS_I2C_EXT0_INTR_SOURCE, flags, &i2c_slave_isr_handler, i2c, &i2c->intr_handle); #if SOC_I2C_NUM > 1 } else { ret = esp_intr_alloc(ETS_I2C_EXT1_INTR_SOURCE, flags, &i2c_slave_isr_handler, i2c, &i2c->intr_handle); #endif +#endif // !defined(CONFIG_IDF_TARGET_ESP32P4) +#ifdef CONFIG_IDF_TARGET_ESP32P4 + if (i2c->num == 0) { + ret = esp_intr_alloc(ETS_I2C0_INTR_SOURCE, flags, &i2c_slave_isr_handler, i2c, &i2c->intr_handle); +#if SOC_I2C_NUM > 1 + } else { + ret = esp_intr_alloc(ETS_I2C1_INTR_SOURCE, flags, &i2c_slave_isr_handler, i2c, &i2c->intr_handle); +#endif +#endif // #ifdef CONFIG_IDF_TARGET_ESP32P4 } if (ret != ESP_OK) { @@ -515,16 +532,16 @@ static bool i2c_slave_set_frequency(i2c_slave_struct_t *i2c, uint32_t clk_speed) i2c_hal_clk_config_t clk_cal; #if SOC_I2C_SUPPORT_APB - i2c_ll_cal_bus_clk(APB_CLK_FREQ, clk_speed, &clk_cal); + i2c_ll_master_cal_bus_clk(APB_CLK_FREQ, clk_speed, &clk_cal); i2c_ll_set_source_clk(i2c->dev, SOC_MOD_CLK_APB); /*!< I2C source clock from APB, 80M*/ #elif SOC_I2C_SUPPORT_XTAL - i2c_ll_cal_bus_clk(XTAL_CLK_FREQ, clk_speed, &clk_cal); + i2c_ll_master_cal_bus_clk(XTAL_CLK_FREQ, clk_speed, &clk_cal); i2c_ll_set_source_clk(i2c->dev, SOC_MOD_CLK_XTAL); /*!< I2C source clock from XTAL, 40M */ #endif i2c_ll_set_txfifo_empty_thr(i2c->dev, a); i2c_ll_set_rxfifo_full_thr(i2c->dev, SOC_I2C_FIFO_LEN - a); - i2c_ll_set_bus_timing(i2c->dev, &clk_cal); - i2c_ll_set_filter(i2c->dev, 3); + i2c_ll_master_set_bus_timing(i2c->dev, &clk_cal); + i2c_ll_master_set_filter(i2c->dev, 3); return true; } diff --git a/cores/esp32/esp32-hal-ledc.c b/cores/esp32/esp32-hal-ledc.c index 15466390eb8..6945c8705dd 100644 --- a/cores/esp32/esp32-hal-ledc.c +++ b/cores/esp32/esp32-hal-ledc.c @@ -308,11 +308,21 @@ bool ledcOutputInvert(uint8_t pin, bool out_invert) { ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); if (bus != NULL) { gpio_set_level(pin, out_invert); +#if !defined(CONFIG_IDF_TARGET_ESP32P4) #ifdef SOC_LEDC_SUPPORT_HS_MODE esp_rom_gpio_connect_out_signal(pin, ((bus->channel / 8 == 0) ? LEDC_HS_SIG_OUT0_IDX : LEDC_LS_SIG_OUT0_IDX) + ((bus->channel) % 8), out_invert, 0); #else esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT0_IDX + ((bus->channel) % 8), out_invert, 0); #endif +#endif // !defined(CONFIG_IDF_TARGET_ESP32P4) + +#ifdef CONFIG_IDF_TARGET_ESP32P4 +#ifdef SOC_LEDC_SUPPORT_HS_MODE + esp_rom_gpio_connect_out_signal(pin, ((bus->channel / 8 == 0) ? LEDC_HS_SIG_OUT0_IDX : LEDC_LS_SIG_OUT_PAD_OUT0_IDX) + ((bus->channel) % 8), out_invert, 0); +#else + esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT_PAD_OUT0_IDX + ((bus->channel) % 8), out_invert, 0); +#endif +#endif // #ifdef CONFIG_IDF_TARGET_ESP32P4 return true; } return false; diff --git a/cores/esp32/esp32-hal-matrix.c b/cores/esp32/esp32-hal-matrix.c index fba044d0c85..7cddb4e04db 100644 --- a/cores/esp32/esp32-hal-matrix.c +++ b/cores/esp32/esp32-hal-matrix.c @@ -32,6 +32,8 @@ #include "esp32c6/rom/gpio.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/gpio.h" +#elif CONFIG_IDF_TARGET_ESP32P4 +#include "esp32p4/rom/gpio.h" #else #error Target CONFIG_IDF_TARGET is not supported #endif diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 82363b97bd0..157f8886ee7 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -29,9 +29,9 @@ #endif //CONFIG_BT_ENABLED #include #include "soc/rtc.h" -#if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) +#if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4) #include "soc/rtc_cntl_reg.h" -#include "soc/apb_ctrl_reg.h" +#include "soc/syscon_reg.h" #endif #include "esp_task_wdt.h" #include "esp32-hal.h" @@ -53,6 +53,8 @@ #include "esp32c6/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/rtc.h" +#elif CONFIG_IDF_TARGET_ESP32P4 +#include "esp32p4/rom/rtc.h" #else #error Target CONFIG_IDF_TARGET is not supported diff --git a/cores/esp32/esp32-hal-psram.c b/cores/esp32/esp32-hal-psram.c index 5a741908f07..f28095a6fd8 100644 --- a/cores/esp32/esp32-hal-psram.c +++ b/cores/esp32/esp32-hal-psram.c @@ -27,6 +27,8 @@ #include "esp32s2/rom/cache.h" #elif CONFIG_IDF_TARGET_ESP32S3 #include "esp32s3/rom/cache.h" +#elif CONFIG_IDF_TARGET_ESP32P4 +#include "esp32p4/rom/cache.h" #else #error Target CONFIG_IDF_TARGET is not supported #endif diff --git a/cores/esp32/esp32-hal-spi.c b/cores/esp32/esp32-hal-spi.c index 857c3d4bb2e..3dc7cee5200 100644 --- a/cores/esp32/esp32-hal-spi.c +++ b/cores/esp32/esp32-hal-spi.c @@ -55,6 +55,9 @@ #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/ets_sys.h" #include "esp32h2/rom/gpio.h" +#elif CONFIG_IDF_TARGET_ESP32P4 +#include "esp32p4/rom/ets_sys.h" +#include "esp32p4/rom/gpio.h" #else #error Target CONFIG_IDF_TARGET is not supported #endif @@ -96,6 +99,18 @@ struct spi_struct_t { #define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : 0)) #define SPI_SS_IDX(p, n) ((p == 0) ? SPI_FSPI_SS_IDX(n) : ((p == 1) ? SPI_HSPI_SS_IDX(n) : 0)) +#elif CONFIG_IDF_TARGET_ESP32P4 +// ESP32P4 +#define SPI_COUNT (2) + +#define SPI_CLK_IDX(p) ((p == 0) ? SPI2_CK_PAD_OUT_IDX : ((p == 1) ? SPI3_CK_PAD_OUT_IDX : 0)) +#define SPI_MISO_IDX(p) ((p == 0) ? SPI2_Q_PAD_OUT_IDX : ((p == 1) ? SPI3_QO_PAD_OUT_IDX : 0)) +#define SPI_MOSI_IDX(p) ((p == 0) ? SPI2_D_PAD_IN_IDX : ((p == 1) ? SPI3_D_PAD_IN_IDX : 0)) + +#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS1_PAD_OUT_IDX : ((n == 1) ? SPI3_CS1_PAD_OUT_IDX : 0)) +#define SPI_FSPI_SS_IDX(n) ((n == 0) ? SPI2_CS1_PAD_OUT_IDX : ((n == 1) ? SPI2_CS1_PAD_OUT_IDX : 0)) +#define SPI_SS_IDX(p, n) ((p == 0) ? SPI_FSPI_SS_IDX(n) : ((p == 1) ? SPI_HSPI_SS_IDX(n) : 0)) + #elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 // ESP32C3 #define SPI_COUNT (1) @@ -125,14 +140,15 @@ struct spi_struct_t { #if CONFIG_DISABLE_HAL_LOCKS #define SPI_MUTEX_LOCK() #define SPI_MUTEX_UNLOCK() - ++ static spi_t _spi_bus_array[] = { #if CONFIG_IDF_TARGET_ESP32S2 {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 0, -1, -1, -1, -1}, {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 1, -1, -1, -1, -1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 2, -1, -1, -1, -1} -#elif CONFIG_IDF_TARGET_ESP32S3 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1, -1, -1, -1, -1} +#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4 + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1}, + {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1, -1, -1, -1, -1} #elif CONFIG_IDF_TARGET_ESP32C2 {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1} #elif CONFIG_IDF_TARGET_ESP32C3 @@ -157,8 +173,9 @@ static spi_t _spi_bus_array[] = { {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 0, -1, -1, -1, -1}, {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 1, -1, -1, -1, -1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 2, -1, -1, -1, -1} -#elif CONFIG_IDF_TARGET_ESP32S3 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1, -1, -1, -1, -1} +#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4 + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1}, + {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1, -1, -1, -1, -1} #elif CONFIG_IDF_TARGET_ESP32C2 {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1} #elif CONFIG_IDF_TARGET_ESP32C3 @@ -370,7 +387,7 @@ void spiEnableSSPins(spi_t *spi, uint8_t ss_mask) { } SPI_MUTEX_LOCK(); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.val &= ~(ss_mask & SPI_SS_MASK_ALL); #else spi->dev->pin.val &= ~(ss_mask & SPI_SS_MASK_ALL); @@ -384,7 +401,7 @@ void spiDisableSSPins(spi_t *spi, uint8_t ss_mask) { } SPI_MUTEX_LOCK(); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.val |= (ss_mask & SPI_SS_MASK_ALL); #else spi->dev->pin.val |= (ss_mask & SPI_SS_MASK_ALL); @@ -418,7 +435,7 @@ void spiSSSet(spi_t *spi) { } SPI_MUTEX_LOCK(); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.cs_keep_active = 1; #else spi->dev->pin.cs_keep_active = 1; @@ -432,7 +449,7 @@ void spiSSClear(spi_t *spi) { } SPI_MUTEX_LOCK(); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.cs_keep_active = 0; #else spi->dev->pin.cs_keep_active = 0; @@ -461,7 +478,7 @@ uint8_t spiGetDataMode(spi_t *spi) { return 0; } #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 bool idleEdge = spi->dev->misc.ck_idle_edge; #else bool idleEdge = spi->dev->pin.ck_idle_edge; @@ -487,7 +504,7 @@ void spiSetDataMode(spi_t *spi, uint8_t dataMode) { switch (dataMode) { case SPI_MODE1: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.ck_idle_edge = 0; #else spi->dev->pin.ck_idle_edge = 0; @@ -496,7 +513,7 @@ void spiSetDataMode(spi_t *spi, uint8_t dataMode) { break; case SPI_MODE2: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.ck_idle_edge = 1; #else spi->dev->pin.ck_idle_edge = 1; @@ -505,7 +522,7 @@ void spiSetDataMode(spi_t *spi, uint8_t dataMode) { break; case SPI_MODE3: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.ck_idle_edge = 1; #else spi->dev->pin.ck_idle_edge = 1; @@ -515,7 +532,7 @@ void spiSetDataMode(spi_t *spi, uint8_t dataMode) { case SPI_MODE0: default: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.ck_idle_edge = 0; #else spi->dev->pin.ck_idle_edge = 0; @@ -565,7 +582,7 @@ static void spiInitBus(spi_t *spi) { #endif spi->dev->slave.val = 0; #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.val = 0; #else spi->dev->pin.val = 0; @@ -637,6 +654,14 @@ spi_t *spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t periph_ll_reset(PERIPH_SPI3_MODULE); periph_ll_enable_clk_clear_rst(PERIPH_SPI3_MODULE); } +#elif CONFIG_IDF_TARGET_ESP32P4 + if (spi_num == FSPI) { + periph_ll_reset(PERIPH_GPSPI2_MODULE); + periph_ll_enable_clk_clear_rst(PERIPH_GPSPI2_MODULE); + } else if (spi_num == HSPI) { + periph_ll_reset(PERIPH_GPSPI3_MODULE); + periph_ll_enable_clk_clear_rst(PERIPH_GPSPI3_MODULE); + } #elif CONFIG_IDF_TARGET_ESP32 if (spi_num == HSPI) { DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN); @@ -655,11 +680,11 @@ spi_t *spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t SPI_MUTEX_LOCK(); spiInitBus(spi); -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->clk_gate.clk_en = 1; spi->dev->clk_gate.mst_clk_sel = 1; spi->dev->clk_gate.mst_clk_active = 1; -#if !CONFIG_IDF_TARGET_ESP32C6 && !CONFIG_IDF_TARGET_ESP32H2 +#if !CONFIG_IDF_TARGET_ESP32C6 && !CONFIG_IDF_TARGET_ESP32H2 && !CONFIG_IDF_TARGET_ESP32P4 spi->dev->dma_conf.tx_seg_trans_clr_en = 1; spi->dev->dma_conf.rx_seg_trans_clr_en = 1; spi->dev->dma_conf.dma_seg_trans_en = 0; @@ -670,7 +695,7 @@ spi_t *spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t spi->dev->user.doutdin = 1; int i; for (i = 0; i < 16; i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[i].val = 0x00000000; #else spi->dev->data_buf[i] = 0x00000000; @@ -697,7 +722,7 @@ void spiWaitReady(spi_t *spi) { #if CONFIG_IDF_TARGET_ESP32S2 #define usr_mosi_dbitlen usr_mosi_bit_len #define usr_miso_dbitlen usr_miso_bit_len -#elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 #define usr_mosi_dbitlen ms_data_bitlen #define usr_miso_dbitlen ms_data_bitlen #define mosi_dlen ms_dlen @@ -718,13 +743,13 @@ void spiWrite(spi_t *spi, const uint32_t *data, uint8_t len) { spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif for (i = 0; i < len; i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[i].val = data[i]; #else spi->dev->data_buf[i] = data[i]; #endif } -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -745,20 +770,20 @@ void spiTransfer(spi_t *spi, uint32_t *data, uint8_t len) { spi->dev->mosi_dlen.usr_mosi_dbitlen = (len * 32) - 1; spi->dev->miso_dlen.usr_miso_dbitlen = (len * 32) - 1; for (i = 0; i < len; i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[i].val = data[i]; #else spi->dev->data_buf[i] = data[i]; #endif } -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif spi->dev->cmd.usr = 1; while (spi->dev->cmd.usr); for (i = 0; i < len; i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 data[i] = spi->dev->data_buf[i].val; #else data[i] = spi->dev->data_buf[i]; @@ -776,13 +801,13 @@ void spiWriteByte(spi_t *spi, uint8_t data) { #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -798,18 +823,18 @@ uint8_t spiTransferByte(spi_t *spi, uint8_t data) { SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; spi->dev->miso_dlen.usr_miso_dbitlen = 7; -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif spi->dev->cmd.usr = 1; while (spi->dev->cmd.usr); -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 data = spi->dev->data_buf[0].val & 0xFF; #else data = spi->dev->data_buf[0] & 0xFF; @@ -839,12 +864,12 @@ void spiWriteWord(spi_t *spi, uint16_t data) { #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -863,18 +888,18 @@ uint16_t spiTransferWord(spi_t *spi, uint16_t data) { SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; spi->dev->miso_dlen.usr_miso_dbitlen = 15; -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif spi->dev->cmd.usr = 1; while (spi->dev->cmd.usr); -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 data = spi->dev->data_buf[0].val; #else data = spi->dev->data_buf[0]; @@ -898,12 +923,12 @@ void spiWriteLong(spi_t *spi, uint32_t data) { #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -922,18 +947,18 @@ uint32_t spiTransferLong(spi_t *spi, uint32_t data) { SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; spi->dev->miso_dlen.usr_miso_dbitlen = 31; -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif spi->dev->cmd.usr = 1; while (spi->dev->cmd.usr); -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 data = spi->dev->data_buf[0].val; #else data = spi->dev->data_buf[0]; @@ -972,14 +997,14 @@ static void __spiTransferBytes(spi_t *spi, const uint8_t *data, uint8_t *out, ui spi->dev->miso_dlen.usr_miso_dbitlen = ((bytes * 8) - 1); for (i = 0; i < words; i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[i].val = wordsBuf[i]; //copy buffer to spi fifo #else spi->dev->data_buf[i] = wordsBuf[i]; //copy buffer to spi fifo #endif } -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -989,7 +1014,7 @@ static void __spiTransferBytes(spi_t *spi, const uint8_t *data, uint8_t *out, ui if (out) { for (i = 0; i < words; i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 wordsBuf[i] = spi->dev->data_buf[i].val; //copy spi fifo to buffer #else wordsBuf[i] = spi->dev->data_buf[i]; //copy spi fifo to buffer @@ -1062,7 +1087,7 @@ void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bit switch (dataMode) { case SPI_MODE1: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.ck_idle_edge = 0; #else spi->dev->pin.ck_idle_edge = 0; @@ -1071,7 +1096,7 @@ void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bit break; case SPI_MODE2: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.ck_idle_edge = 1; #else spi->dev->pin.ck_idle_edge = 1; @@ -1080,7 +1105,7 @@ void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bit break; case SPI_MODE3: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.ck_idle_edge = 1; #else spi->dev->pin.ck_idle_edge = 1; @@ -1090,7 +1115,7 @@ void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bit case SPI_MODE0: default: #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 \ - || CONFIG_IDF_TARGET_ESP32H2 + || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->misc.ck_idle_edge = 0; #else spi->dev->pin.ck_idle_edge = 0; @@ -1105,7 +1130,7 @@ void spiTransaction(spi_t *spi, uint32_t clockDiv, uint8_t dataMode, uint8_t bit spi->dev->ctrl.wr_bit_order = 1; spi->dev->ctrl.rd_bit_order = 1; } -#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 // Sync new config with hardware, fixes https://github.com/espressif/arduino-esp32/issues/9221 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); @@ -1134,12 +1159,12 @@ void ARDUINO_ISR_ATTR spiWriteByteNL(spi_t *spi, uint8_t data) { #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1153,18 +1178,18 @@ uint8_t spiTransferByteNL(spi_t *spi, uint8_t data) { } spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; spi->dev->miso_dlen.usr_miso_dbitlen = 7; -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif spi->dev->cmd.usr = 1; while (spi->dev->cmd.usr); -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 data = spi->dev->data_buf[0].val & 0xFF; #else data = spi->dev->data_buf[0] & 0xFF; @@ -1183,12 +1208,12 @@ void ARDUINO_ISR_ATTR spiWriteShortNL(spi_t *spi, uint16_t data) { #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1205,18 +1230,18 @@ uint16_t spiTransferShortNL(spi_t *spi, uint16_t data) { } spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; spi->dev->miso_dlen.usr_miso_dbitlen = 15; -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif spi->dev->cmd.usr = 1; while (spi->dev->cmd.usr); -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 data = spi->dev->data_buf[0].val & 0xFFFF; #else data = spi->dev->data_buf[0] & 0xFFFF; @@ -1238,12 +1263,12 @@ void ARDUINO_ISR_ATTR spiWriteLongNL(spi_t *spi, uint32_t data) { #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1260,18 +1285,18 @@ uint32_t spiTransferLongNL(spi_t *spi, uint32_t data) { } spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; spi->dev->miso_dlen.usr_miso_dbitlen = 31; -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif spi->dev->cmd.usr = 1; while (spi->dev->cmd.usr); -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 data = spi->dev->data_buf[0].val; #else data = spi->dev->data_buf[0]; @@ -1302,13 +1327,13 @@ void spiWriteNL(spi_t *spi, const void *data_in, uint32_t len) { spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif for (size_t i = 0; i < c_longs; i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[i].val = data[i]; #else spi->dev->data_buf[i] = data[i]; #endif } -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1341,7 +1366,7 @@ void spiTransferBytesNL(spi_t *spi, const void *data_in, uint8_t *data_out, uint spi->dev->miso_dlen.usr_miso_dbitlen = (c_len * 8) - 1; if (data) { for (size_t i = 0; i < c_longs; i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[i].val = data[i]; #else spi->dev->data_buf[i] = data[i]; @@ -1349,14 +1374,14 @@ void spiTransferBytesNL(spi_t *spi, const void *data_in, uint8_t *data_out, uint } } else { for (size_t i = 0; i < c_longs; i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[i].val = 0xFFFFFFFF; #else spi->dev->data_buf[i] = 0xFFFFFFFF; #endif } } -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1365,13 +1390,13 @@ void spiTransferBytesNL(spi_t *spi, const void *data_in, uint8_t *data_out, uint if (result) { if (c_len & 3) { for (size_t i = 0; i < (c_longs - 1); i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 result[i] = spi->dev->data_buf[i].val; #else result[i] = spi->dev->data_buf[i]; #endif } -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 uint32_t last_data = spi->dev->data_buf[c_longs - 1].val; #else uint32_t last_data = spi->dev->data_buf[c_longs - 1]; @@ -1383,7 +1408,7 @@ void spiTransferBytesNL(spi_t *spi, const void *data_in, uint8_t *data_out, uint } } else { for (size_t i = 0; i < c_longs; i++) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 result[i] = spi->dev->data_buf[i].val; #else result[i] = spi->dev->data_buf[i]; @@ -1425,18 +1450,18 @@ void spiTransferBitsNL(spi_t *spi, uint32_t data, uint32_t *out, uint8_t bits) { spi->dev->mosi_dlen.usr_mosi_dbitlen = (bits - 1); spi->dev->miso_dlen.usr_miso_dbitlen = (bits - 1); -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[0].val = data; #else spi->dev->data_buf[0] = data; #endif -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif spi->dev->cmd.usr = 1; while (spi->dev->cmd.usr); -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 data = spi->dev->data_buf[0].val; #else data = spi->dev->data_buf[0]; @@ -1477,34 +1502,34 @@ void ARDUINO_ISR_ATTR spiWritePixelsNL(spi_t *spi, const void *data_in, uint32_t if (msb) { if (l_bytes && i == (c_longs - 1)) { if (l_bytes == 2) { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 MSB_16_SET(spi->dev->data_buf[i].val, data[i]); #else MSB_16_SET(spi->dev->data_buf[i], data[i]); #endif } else { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[i].val = data[i] & 0xFF; #else spi->dev->data_buf[i] = data[i] & 0xFF; #endif } } else { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 MSB_PIX_SET(spi->dev->data_buf[i].val, data[i]); #else MSB_PIX_SET(spi->dev->data_buf[i], data[i]); #endif } } else { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->data_buf[i].val = data[i]; #else spi->dev->data_buf[i] = data[i]; #endif } } -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1528,7 +1553,7 @@ typedef union { uint32_t clkcnt_l : 6; /*it must be equal to spi_clkcnt_N.*/ uint32_t clkcnt_h : 6; /*it must be floor((spi_clkcnt_N+1)/2-1).*/ uint32_t clkcnt_n : 6; /*it is the divider of spi_clk. So spi_clk frequency is system/(spi_clkdiv_pre+1)/(spi_clkcnt_N+1)*/ -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 uint32_t clkdiv_pre : 4; /*it is pre-divider of spi_clk.*/ uint32_t reserved : 9; /*reserved*/ #else @@ -1573,7 +1598,7 @@ uint32_t spiFrequencyToClockDiv(uint32_t freq) { while (calPreVari++ <= 1) { calPre = (((apb_freq / (reg.clkcnt_n + 1)) / freq) - 1) + calPreVari; -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 if (calPre > 0xF) { reg.clkdiv_pre = 0xF; #else diff --git a/cores/esp32/esp32-hal-spi.h b/cores/esp32/esp32-hal-spi.h index a238cada87d..4900cc89c2f 100644 --- a/cores/esp32/esp32-hal-spi.h +++ b/cores/esp32/esp32-hal-spi.h @@ -28,7 +28,7 @@ extern "C" { #define SPI_HAS_TRANSACTION -#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4 #define FSPI 0 #define HSPI 1 #elif CONFIG_IDF_TARGET_ESP32S2 diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 0fbe4b3feb3..131e71321db 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -61,10 +61,10 @@ struct uart_struct_t { static uart_t _uart_bus_array[] = { {0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, -#if SOC_UART_NUM > 1 +#if SOC_UART_HP_NUM > 1 {1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, #endif -#if SOC_UART_NUM > 2 +#if SOC_UART_HP_NUM > 2 {2, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, #endif }; @@ -81,10 +81,10 @@ static uart_t _uart_bus_array[] = { static uart_t _uart_bus_array[] = { {NULL, 0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, -#if SOC_UART_NUM > 1 +#if SOC_UART_HP_NUM > 1 {NULL, 1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, #endif -#if SOC_UART_NUM > 2 +#if SOC_UART_HP_NUM > 2 {NULL, 2, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, #endif }; @@ -94,8 +94,8 @@ static uart_t _uart_bus_array[] = { // Negative Pin Number will keep it unmodified, thus this function can detach individual pins // This function will also unset the pins in the Peripheral Manager and set the pin to -1 after detaching static bool _uartDetachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) { - if (uart_num >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); + if (uart_num >= SOC_UART_HP_NUM) { + log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_HP_NUM - 1); return false; } // get UART information @@ -181,8 +181,8 @@ static bool _uartDetachBus_RTS(void *busptr) { // Attach function for UART // connects the IO Pad, set Paripheral Manager and internal UART structure data static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) { - if (uart_num >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); + if (uart_num >= SOC_UART_HP_NUM) { + log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_HP_NUM - 1); return false; } // get UART information @@ -308,8 +308,8 @@ bool uartIsDriverInstalled(uart_t *uart) { // Negative Pin Number will keep it unmodified, thus this function can set individual pins // When pins are changed, it will detach the previous one bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) { - if (uart_num >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); + if (uart_num >= SOC_UART_HP_NUM) { + log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_HP_NUM - 1); return false; } // get UART information @@ -378,7 +378,7 @@ bool _testUartBegin( uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint32_t rx_buffer_size, uint32_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd ) { - if (uart_nr >= SOC_UART_NUM) { + if (uart_nr >= SOC_UART_HP_NUM) { return false; // no new driver has to be installed } uart_t *uart = &_uart_bus_array[uart_nr]; @@ -400,8 +400,8 @@ uart_t *uartBegin( uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint32_t rx_buffer_size, uint32_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd ) { - if (uart_nr >= SOC_UART_NUM) { - log_e("UART number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); + if (uart_nr >= SOC_UART_HP_NUM) { + log_e("UART number is invalid, please use number from 0 to %u", SOC_UART_HP_NUM - 1); return NULL; // no new driver was installed } uart_t *uart = &_uart_bus_array[uart_nr]; @@ -604,8 +604,8 @@ bool uartSetRxFIFOFull(uart_t *uart, uint8_t numBytesFIFOFull) { } void uartEnd(uint8_t uart_num) { - if (uart_num >= SOC_UART_NUM) { - log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_NUM - 1); + if (uart_num >= SOC_UART_HP_NUM) { + log_e("Serial number is invalid, please use number from 0 to %u", SOC_UART_HP_NUM - 1); return; } // get UART information @@ -623,7 +623,7 @@ void uartSetRxInvert(uart_t *uart, bool invert) { if (uart == NULL) { return; } -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 // POTENTIAL ISSUE :: original code only set/reset rxd_inv bit // IDF or LL set/reset the whole inv_mask! // if (invert) @@ -819,14 +819,14 @@ static void ARDUINO_ISR_ATTR uart0_write_char(char c) { uart_ll_write_txfifo(&UART0, (const uint8_t *)&c, 1); } -#if SOC_UART_NUM > 1 +#if SOC_UART_HP_NUM > 1 static void ARDUINO_ISR_ATTR uart1_write_char(char c) { while (uart_ll_get_txfifo_len(&UART1) == 0); uart_ll_write_txfifo(&UART1, (const uint8_t *)&c, 1); } #endif -#if SOC_UART_NUM > 2 +#if SOC_UART_HP_NUM > 2 static void ARDUINO_ISR_ATTR uart2_write_char(char c) { while (uart_ll_get_txfifo_len(&UART2) == 0); uart_ll_write_txfifo(&UART2, (const uint8_t *)&c, 1); @@ -836,10 +836,10 @@ static void ARDUINO_ISR_ATTR uart2_write_char(char c) { void uart_install_putc() { switch (s_uart_debug_nr) { case 0: ets_install_putc1((void (*)(char)) & uart0_write_char); break; -#if SOC_UART_NUM > 1 +#if SOC_UART_HP_NUM > 1 case 1: ets_install_putc1((void (*)(char)) & uart1_write_char); break; #endif -#if SOC_UART_NUM > 2 +#if SOC_UART_HP_NUM > 2 case 2: ets_install_putc1((void (*)(char)) & uart2_write_char); break; #endif default: ets_install_putc1(NULL); break; @@ -850,7 +850,7 @@ void uart_install_putc() { // Routines that take care of UART mode in the HardwareSerial Class code // used to set UART_MODE_RS485_HALF_DUPLEX auto RTS for TXD for ESP32 chips bool uartSetMode(uart_t *uart, uart_mode_t mode) { - if (uart == NULL || uart->num >= SOC_UART_NUM) { + if (uart == NULL || uart->num >= SOC_UART_HP_NUM) { return false; } @@ -861,7 +861,7 @@ bool uartSetMode(uart_t *uart, uart_mode_t mode) { } void uartSetDebug(uart_t *uart) { - if (uart == NULL || uart->num >= SOC_UART_NUM) { + if (uart == NULL || uart->num >= SOC_UART_HP_NUM) { s_uart_debug_nr = -1; } else { s_uart_debug_nr = uart->num; @@ -896,7 +896,7 @@ int log_printfv(const char *format, va_list arg) { #endif */ #if (ARDUINO_USB_CDC_ON_BOOT == 1 && ARDUINO_USB_MODE == 0) || CONFIG_IDF_TARGET_ESP32C3 \ - || ((CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C6) && ARDUINO_USB_CDC_ON_BOOT == 1) + || ((CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32P4) && ARDUINO_USB_CDC_ON_BOOT == 1) vsnprintf(temp, len + 1, format, arg); ets_printf("%s", temp); #else @@ -1103,19 +1103,26 @@ unsigned long uartDetectBaudrate(uart_t *uart) { */ // gets the right TX or RX SIGNAL, based on the UART number from gpio_sig_map.h -#if SOC_UART_NUM > 2 +#if !defined(CONFIG_IDF_TARGET_ESP32P4) +#if SOC_UART_HP_NUM > 2 #define UART_TX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0TXD_OUT_IDX : (uartNumber == UART_NUM_1 ? U1TXD_OUT_IDX : U2TXD_OUT_IDX)) #define UART_RX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0RXD_IN_IDX : (uartNumber == UART_NUM_1 ? U1RXD_IN_IDX : U2RXD_IN_IDX)) #else #define UART_TX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0TXD_OUT_IDX : U1TXD_OUT_IDX) #define UART_RX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0RXD_IN_IDX : U1RXD_IN_IDX) #endif +#endif // if !defined(CONFIG_IDF_TARGET_ESP32P4) +// todo ESP32-P4 has 4 UART not 3 See IDF soc/esp32p4/uart_periph.c +#ifdef CONFIG_IDF_TARGET_ESP32P4 +#define UART_TX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? UART0_TXD_PAD_OUT_IDX : (uartNumber == UART_NUM_1 ? UART1_TXD_PAD_OUT_IDX : UART2_TXD_PAD_OUT_IDX)) +#define UART_RX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? UART0_RXD_PAD_IN_IDX : (uartNumber == UART_NUM_1 ? UART1_RXD_PAD_IN_IDX : UART2_RXD_PAD_IN_IDX)) +#endif // ifdef CONFIG_IDF_TARGET_ESP32P4 /* This function internally binds defined UARTs TX signal with defined RX pin of any UART (same or different). This creates a loop that lets us receive anything we send on the UART without external wires. */ void uart_internal_loopback(uint8_t uartNum, int8_t rxPin) { - if (uartNum > SOC_UART_NUM - 1 || !GPIO_IS_VALID_GPIO(rxPin)) { + if (uartNum > SOC_UART_HP_NUM - 1 || !GPIO_IS_VALID_GPIO(rxPin)) { return; } esp_rom_gpio_connect_out_signal(rxPin, UART_TX_SIGNAL(uartNum), false, false); diff --git a/cores/esp32/main.cpp b/cores/esp32/main.cpp index 6c4d50a9a84..746d18dc075 100644 --- a/cores/esp32/main.cpp +++ b/cores/esp32/main.cpp @@ -10,7 +10,9 @@ #endif #endif +#if defined __has_include && __has_include("chip-debug-report.h") #include "chip-debug-report.h" +#endif #ifndef ARDUINO_LOOP_STACK_SIZE #ifndef CONFIG_ARDUINO_LOOP_STACK_SIZE @@ -49,20 +51,24 @@ void loopTask(void *pvParameters) { // sets UART0 (default console) RX/TX pins as already configured in boot or as defined in variants/pins_arduino.h Serial0.setPins(gpioNumberToDigitalPin(SOC_RX0), gpioNumberToDigitalPin(SOC_TX0)); #endif +#if defined __has_include && __has_include("chip-debug-report.h") #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG printBeforeSetupInfo(); #else if (shouldPrintChipDebugReport()) { printBeforeSetupInfo(); } +#endif #endif setup(); +#if defined __has_include && __has_include("chip-debug-report.h") #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG printAfterSetupInfo(); #else if (shouldPrintChipDebugReport()) { printAfterSetupInfo(); } +#endif #endif for (;;) { #if CONFIG_FREERTOS_UNICORE diff --git a/docs/en/migration_guides/2.x_to_3.0.rst b/docs/en/migration_guides/2.x_to_3.0.rst index bb6cab294cc..9db94937e9a 100644 --- a/docs/en/migration_guides/2.x_to_3.0.rst +++ b/docs/en/migration_guides/2.x_to_3.0.rst @@ -223,6 +223,5 @@ WiFi Functional changes ^^^^^^^^^^^^^^^^^^ -* In Arduino (and other frameworks) the method named ``flush()`` is intended to send out the transmit buffer content. ``WiFiClient`` and ``WiFiUDP`` method ``flush()`` won't clear the receive buffer anymore. A new method called ``clear()`` is now used for that. Currently ``flush()`` does nothing in ``WiFiClient``, ``WiFiClientSecure`` and ``WiFiUDP``. * ``WiFiServer`` has functions ``accept()`` and ``available()`` with the same functionality. In Arduino, ``available()`` should work differently so it is now deprecated. * ``WiFiServer`` had unimplemented write functions inherited from ``Print`` class. These are now removed. Also unimplemented method ``stopAll()`` is removed. The methods were unimplemented because ``WiFiServer`` doesn't manage connected ``WiFiClient`` objects for print-to-all-clients functionality. diff --git a/idf_component.yml b/idf_component.yml index 81d79180dbb..e32ed1b585a 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -9,6 +9,7 @@ targets: - esp32c3 - esp32c6 - esp32h2 + - esp32p4 tags: - arduino files: @@ -20,6 +21,7 @@ files: - "variants/esp32c3/**/*" - "variants/esp32c6/**/*" - "variants/esp32h2/**/*" + - "variants/esp32p4/**/*" exclude: - "docs/" - "docs/**/*" @@ -42,55 +44,26 @@ files: - "platform.txt" - "programmers.txt" dependencies: - idf: ">=5.1,<5.2" + idf: ">=5.1,<5.4" # mdns 1.2.1 is necessary to build H2 with no WiFi espressif/mdns: version: "^1.2.3" require: public espressif/esp_modem: version: "^1.1.0" + rules: + - if: "target in [esp32, esp32s2, esp32s3, esp32h2, esp32p4]" espressif/esp-zboss-lib: version: "^1.0.1" rules: - - if: "target != esp32c2" + - if: "target in [esp32h2, esp32p4]" espressif/esp-zigbee-lib: version: "^1.0.1" rules: - - if: "target != esp32c2" + - if: "target in [esp32h2, esp32p4]" espressif/esp-dsp: - version: "^1.3.4" - rules: - - if: "target != esp32c2" - espressif/esp_rainmaker: - version: "^1.0.0" - rules: - - if: "target != esp32c2" - espressif/rmaker_common: - version: "^1.4.3" - rules: - - if: "target != esp32c2" - espressif/esp_insights: - version: "^1.0.1" + version: "^1.4.12" rules: - - if: "target != esp32c2" - espressif/qrcode: - version: "^0.1.0~1" - rules: - - if: "target != esp32c2" - espressif/esp-sr: - version: "^1.4.2" - rules: - - if: "target in [esp32s3]" - espressif/libsodium: - version: "^1.0.20~1" - require: public - espressif/esp-modbus: - version: "^1.0.15" - require: public + - if: "target in [esp32, esp32s2, esp32s3, esp32c2, esp32c3, eap32c6]" joltwallet/littlefs: - version: "^1.10.2" - chmorgan/esp-libhelix-mp3: - version: "1.0.3" - require: public -examples: - - path: ./idf_component_examples/hello_world + version: "^1.14.1" diff --git a/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino b/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino index eada1c7ea6b..17e7af290bf 100644 --- a/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino +++ b/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino @@ -21,7 +21,7 @@ * */ -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 // ESP32 C3 has only 2 channels for RX and 2 for TX, thus MAX RMT_MEM is 128 #define RMT_TX_PIN 4 #define RMT_RX_PIN 5 diff --git a/libraries/ESP32/examples/ResetReason/ResetReason/ResetReason.ino b/libraries/ESP32/examples/ResetReason/ResetReason/ResetReason.ino index 3c9dbb9b12f..0104c6422f2 100644 --- a/libraries/ESP32/examples/ResetReason/ResetReason/ResetReason.ino +++ b/libraries/ESP32/examples/ResetReason/ResetReason/ResetReason.ino @@ -26,6 +26,8 @@ #include "esp32c6/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/rtc.h" +#elif CONFIG_IDF_TARGET_ESP32P4 +#include "esp32p4/rom/rtc.h" #else #error Target CONFIG_IDF_TARGET is not supported #endif diff --git a/libraries/ESP_I2S/src/ESP_I2S.cpp b/libraries/ESP_I2S/src/ESP_I2S.cpp index 84050dfa6f8..b6e793e7f0f 100644 --- a/libraries/ESP_I2S/src/ESP_I2S.cpp +++ b/libraries/ESP_I2S/src/ESP_I2S.cpp @@ -12,7 +12,7 @@ #define I2S_READ_CHUNK_SIZE 1920 #define I2S_DEFAULT_CFG() \ - { .id = I2S_NUM_AUTO, .role = I2S_ROLE_MASTER, .dma_desc_num = 6, .dma_frame_num = 240, .auto_clear = true, } + { .id = I2S_NUM_AUTO, .role = I2S_ROLE_MASTER, .dma_desc_num = 6, .dma_frame_num = 240, .auto_clear = true, .intr_priority = 0, } #define I2S_STD_CHAN_CFG(_sample_rate, _data_bit_width, _slot_mode) \ { \ @@ -819,7 +819,7 @@ size_t I2SClass::readBytes(char *buffer, size_t size) { return total_size; } -size_t I2SClass::write(uint8_t *buffer, size_t size) { +size_t I2SClass::write(const uint8_t *buffer, size_t size) { size_t written = 0; size_t bytes_sent = 0; last_error = ESP_FAIL; diff --git a/libraries/ESP_I2S/src/ESP_I2S.h b/libraries/ESP_I2S/src/ESP_I2S.h index c83e3815ddb..60ccf0d4265 100644 --- a/libraries/ESP_I2S/src/ESP_I2S.h +++ b/libraries/ESP_I2S/src/ESP_I2S.h @@ -62,7 +62,7 @@ class I2SClass : public Stream { bool end(); size_t readBytes(char *buffer, size_t size); - size_t write(uint8_t *buffer, size_t size); + size_t write(const uint8_t *buffer, size_t size); i2s_chan_handle_t txChan(); uint32_t txSampleRate(); diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index 4d215d80034..aa32a5c7c4b 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -19,6 +19,8 @@ */ // Disable the automatic pin remapping of the API calls in this file +#if defined __has_include && __has_include("esp_eth_driver.h") + #define ARDUINO_CORE_BUILD #include "ETH.h" @@ -237,6 +239,7 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i case ETH_PHY_TLK110: phy = esp_eth_phy_new_ip101(&phy_config); break; case ETH_PHY_RTL8201: phy = esp_eth_phy_new_rtl8201(&phy_config); break; case ETH_PHY_DP83848: phy = esp_eth_phy_new_dp83848(&phy_config); break; + case ETH_PHY_JL1101: phy = esp_eth_phy_new_jl1101(&phy_config); break; case ETH_PHY_KSZ8041: phy = esp_eth_phy_new_ksz80xx(&phy_config); break; case ETH_PHY_KSZ8081: phy = esp_eth_phy_new_ksz80xx(&phy_config); break; default: log_e("Unsupported PHY %d", type); break; @@ -1007,3 +1010,5 @@ size_t ETHClass::printDriverInfo(Print &out) const { } ETHClass ETH; + +#endif /* defined __has_include && __has_include("esp_eth_driver.h") */ diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index 14d2d042614..5c8b331704e 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -17,6 +17,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#if defined __has_include && __has_include("esp_eth_driver.h") #ifndef _ETH_H_ #define _ETH_H_ @@ -101,6 +102,7 @@ typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, + ETH_PHY_JL1101, ETH_PHY_DP83848, ETH_PHY_KSZ8041, ETH_PHY_KSZ8081, @@ -223,3 +225,4 @@ class ETHClass : public NetworkInterface { extern ETHClass ETH; #endif /* _ETH_H_ */ +#endif /* defined __has_include && __has_include("esp_eth_driver.h") */ diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index 7881a877467..a3cad64f89e 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -35,6 +35,8 @@ /// Cookie jar support #include +#define HTTPCLIENT_NOSECURE + #ifdef HTTPCLIENT_1_1_COMPATIBLE class TransportTraits { public: diff --git a/libraries/HTTPClient/src/HTTPClient.h b/libraries/HTTPClient/src/HTTPClient.h index 80f6da28599..20d07c723ed 100644 --- a/libraries/HTTPClient/src/HTTPClient.h +++ b/libraries/HTTPClient/src/HTTPClient.h @@ -31,6 +31,10 @@ #define HTTPCLIENT_1_1_COMPATIBLE #endif +#ifndef HTTPCLIENT_NOSECURE +#define HTTPCLIENT_NOSECURE +#endif + #include #include #include diff --git a/libraries/Network/src/NetworkClient.cpp b/libraries/Network/src/NetworkClient.cpp index 9f4806df18a..820a97d2a43 100644 --- a/libraries/Network/src/NetworkClient.cpp +++ b/libraries/Network/src/NetworkClient.cpp @@ -146,7 +146,7 @@ class NetworkClientRxBuffer { return _fill - _pos + r_available(); } - void clear() { + void flush() { if (r_available()) { fillBuffer(); } @@ -369,8 +369,6 @@ int NetworkClient::read() { return data; } -void NetworkClient::flush() {} - size_t NetworkClient::write(const uint8_t *buf, size_t size) { int res = 0; int retry = WIFI_CLIENT_MAX_WRITE_RETRY; @@ -531,9 +529,11 @@ int NetworkClient::available() { return res; } -void NetworkClient::clear() { +// Though flushing means to send all pending data, +// seems that in Arduino it also means to clear RX +void NetworkClient::flush() { if (_rxBuffer != nullptr) { - _rxBuffer->clear(); + _rxBuffer->flush(); } } diff --git a/libraries/Network/src/NetworkClient.h b/libraries/Network/src/NetworkClient.h index 572292a7a99..ea45d81e051 100644 --- a/libraries/Network/src/NetworkClient.h +++ b/libraries/Network/src/NetworkClient.h @@ -28,7 +28,9 @@ class NetworkClientRxBuffer; class ESPLwIPClient : public Client { public: + virtual int connect(IPAddress ip, uint16_t port) = 0; virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0; + virtual int connect(const char *host, uint16_t port) = 0; virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0; virtual void setConnectionTimeout(uint32_t milliseconds) = 0; }; @@ -56,7 +58,6 @@ class NetworkClient : public ESPLwIPClient { size_t write(const uint8_t *buf, size_t size); size_t write_P(PGM_P buf, size_t size); size_t write(Stream &stream); - void flush(); // Print::flush tx int available(); int read(); int read(uint8_t *buf, size_t size); @@ -65,7 +66,7 @@ class NetworkClient : public ESPLwIPClient { return readBytes((char *)buffer, length); } int peek(); - void clear(); // clear rx + void flush(); void stop(); uint8_t connected(); void setSSE(bool sse); diff --git a/libraries/Network/src/NetworkEvents.h b/libraries/Network/src/NetworkEvents.h index 6c0e82f4d81..82912ace52c 100644 --- a/libraries/Network/src/NetworkEvents.h +++ b/libraries/Network/src/NetworkEvents.h @@ -9,7 +9,9 @@ #include "esp_err.h" #include "esp_event.h" #include "esp_netif_types.h" +#if defined __has_include && __has_include("esp_eth_driver.h") #include "esp_eth_driver.h" +#endif #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -20,8 +22,10 @@ #if SOC_WIFI_SUPPORTED #include "esp_wifi_types.h" #include "esp_smartconfig.h" +#if defined __has_include && __has_include("wifi_provisioning/wifi_config.h") #include "wifi_provisioning/wifi_config.h" #endif +#endif #if SOC_WIFI_SUPPORTED static const int WIFI_SCANNING_BIT = BIT0; @@ -92,7 +96,9 @@ typedef union { ip_event_ap_staipassigned_t wifi_ap_staipassigned; ip_event_got_ip_t got_ip; ip_event_got_ip6_t got_ip6; +#if defined __has_include && __has_include("esp_eth_driver.h") esp_eth_handle_t eth_connected; +#endif #if SOC_WIFI_SUPPORTED wifi_event_sta_scan_done_t wifi_scan_done; wifi_event_sta_authmode_change_t wifi_sta_authmode_change; @@ -105,7 +111,9 @@ typedef union { wifi_event_ap_stadisconnected_t wifi_ap_stadisconnected; wifi_event_ftm_report_t wifi_ftm_report; wifi_sta_config_t prov_cred_recv; +#if defined __has_include && __has_include("wifi_provisioning/wifi_config.h") wifi_prov_sta_fail_reason_t prov_fail_reason; +#endif smartconfig_event_got_ssid_pswd_t sc_got_ssid_pswd; #endif } arduino_event_info_t; diff --git a/libraries/Network/src/NetworkUdp.cpp b/libraries/Network/src/NetworkUdp.cpp index 21f568f65b0..3cdd754240b 100644 --- a/libraries/Network/src/NetworkUdp.cpp +++ b/libraries/Network/src/NetworkUdp.cpp @@ -288,8 +288,6 @@ size_t NetworkUDP::write(const uint8_t *buffer, size_t size) { return i; } -void NetworkUDP::flush() {} - int NetworkUDP::parsePacket() { if (rx_buffer) { return 0; @@ -392,7 +390,7 @@ int NetworkUDP::peek() { return rx_buffer->peek(); } -void NetworkUDP::clear() { +void NetworkUDP::flush() { if (!rx_buffer) { return; } diff --git a/libraries/Network/src/NetworkUdp.h b/libraries/Network/src/NetworkUdp.h index ec05991b7e3..62aa4f9cb20 100644 --- a/libraries/Network/src/NetworkUdp.h +++ b/libraries/Network/src/NetworkUdp.h @@ -64,14 +64,13 @@ class NetworkUDP : public UDP { int endPacket(); size_t write(uint8_t); size_t write(const uint8_t *buffer, size_t size); - void flush(); // Print::flush tx int parsePacket(); int available(); int read(); int read(unsigned char *buffer, size_t len); int read(char *buffer, size_t len); int peek(); - void clear(); // clear rx + void flush(); IPAddress remoteIP(); uint16_t remotePort(); }; diff --git a/libraries/PPP/src/PPP.cpp b/libraries/PPP/src/PPP.cpp index 8c25fe6aad5..d9c06d53b1f 100644 --- a/libraries/PPP/src/PPP.cpp +++ b/libraries/PPP/src/PPP.cpp @@ -248,7 +248,7 @@ bool PPPClass::begin(ppp_modem_model_t model, uint8_t uart_num, int baud_rate) { return false; } - _uart_num = uart_num; + _uart_num = uart_port_t(uart_num); _esp_modem = this; Network.begin(); diff --git a/libraries/PPP/src/PPP.h b/libraries/PPP/src/PPP.h index 52eed57edbc..493c5ef120e 100644 --- a/libraries/PPP/src/PPP.h +++ b/libraries/PPP/src/PPP.h @@ -103,7 +103,7 @@ class PPPClass : public NetworkInterface { int _rx_buffer_size; int _tx_buffer_size; esp_modem_dce_mode_t _mode; - uint8_t _uart_num; + uart_port_t _uart_num; static bool pppDetachBus(void *bus_pointer); }; diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index 13e5fcf27fc..36a015652a7 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -35,6 +35,7 @@ using namespace fs; SDMMCFS::SDMMCFS(FSImplPtr impl) : FS(impl), _card(nullptr) { +#if !defined(CONFIG_IDF_TARGET_ESP32P4) #if defined(SOC_SDMMC_USE_GPIO_MATRIX) && defined(BOARD_HAS_SDMMC) _pin_clk = SDMMC_CLK; _pin_cmd = SDMMC_CMD; @@ -44,8 +45,9 @@ SDMMCFS::SDMMCFS(FSImplPtr impl) : FS(impl), _card(nullptr) { _pin_d2 = SDMMC_D2; _pin_d3 = SDMMC_D3; #endif // BOARD_HAS_1BIT_SDMMC +#endif // !defined(CONFIG_IDF_TARGET_ESP32P4) -#elif SOC_SDMMC_USE_IOMUX +#elif SOC_SDMMC_USE_IOMUX && defined(BOARD_HAS_SDMMC) && defined(CONFIG_IDF_TARGET_ESP32) _pin_clk = SDMMC_SLOT1_IOMUX_PIN_NUM_CLK; _pin_cmd = SDMMC_SLOT1_IOMUX_PIN_NUM_CMD; _pin_d0 = SDMMC_SLOT1_IOMUX_PIN_NUM_D0; @@ -54,6 +56,16 @@ SDMMCFS::SDMMCFS(FSImplPtr impl) : FS(impl), _card(nullptr) { _pin_d2 = SDMMC_SLOT1_IOMUX_PIN_NUM_D2; _pin_d3 = SDMMC_SLOT1_IOMUX_PIN_NUM_D3; #endif // BOARD_HAS_1BIT_SDMMC + +#elif SOC_SDMMC_USE_IOMUX && defined(BOARD_HAS_SDMMC) && defined(CONFIG_IDF_TARGET_ESP32P4) + _pin_clk = SDMMC_SLOT0_IOMUX_PIN_NUM_CLK; + _pin_cmd = SDMMC_SLOT0_IOMUX_PIN_NUM_CMD; + _pin_d0 = SDMMC_SLOT0_IOMUX_PIN_NUM_D0; +#ifndef BOARD_HAS_1BIT_SDMMC + _pin_d1 = SDMMC_SLOT0_IOMUX_PIN_NUM_D1; + _pin_d2 = SDMMC_SLOT0_IOMUX_PIN_NUM_D2; + _pin_d3 = SDMMC_SLOT0_IOMUX_PIN_NUM_D3; +#endif // BOARD_HAS_1BIT_SDMMC #endif } diff --git a/libraries/SPI/src/SPI.cpp b/libraries/SPI/src/SPI.cpp index 93c686a0d13..35e52f43e4d 100644 --- a/libraries/SPI/src/SPI.cpp +++ b/libraries/SPI/src/SPI.cpp @@ -83,7 +83,7 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) { _miso = (_spi_num == FSPI) ? MISO : -1; _mosi = (_spi_num == FSPI) ? MOSI : -1; _ss = (_spi_num == FSPI) ? SS : -1; -#elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 +#elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 _sck = SCK; _miso = MISO; _mosi = MOSI; diff --git a/libraries/Update/src/Update.h b/libraries/Update/src/Update.h index 7ae5e980751..ece90a2af1a 100644 --- a/libraries/Update/src/Update.h +++ b/libraries/Update/src/Update.h @@ -25,7 +25,6 @@ #define UPDATE_ERROR_NO_PARTITION (10) #define UPDATE_ERROR_BAD_ARGUMENT (11) #define UPDATE_ERROR_ABORT (12) -#define UPDATE_ERROR_DECRYPT (13) #define UPDATE_SIZE_UNKNOWN 0xFFFFFFFF @@ -33,15 +32,7 @@ #define U_SPIFFS 100 #define U_AUTH 200 -#define ENCRYPTED_BLOCK_SIZE 16 -#define ENCRYPTED_TWEAK_BLOCK_SIZE 32 -#define ENCRYPTED_KEY_SIZE 32 - -#define U_AES_DECRYPT_NONE 0 -#define U_AES_DECRYPT_AUTO 1 -#define U_AES_DECRYPT_ON 2 -#define U_AES_DECRYPT_MODE_MASK 3 -#define U_AES_IMAGE_DECRYPTING_BIT 4 +#define ENCRYPTED_BLOCK_SIZE 16 #define SPI_SECTORS_PER_BLOCK 16 // usually large erase block is 32k/64k #define SPI_FLASH_BLOCK_SIZE (SPI_SECTORS_PER_BLOCK * SPI_FLASH_SEC_SIZE) @@ -63,15 +54,6 @@ class UpdateClass { */ bool begin(size_t size = UPDATE_SIZE_UNKNOWN, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW, const char *label = NULL); - /* - Setup decryption configuration - Crypt Key is 32bytes(256bits) block of data, use the same key as used to encrypt image file - Crypt Address, use the same value as used to encrypt image file - Crypt Config, use the same value as used to encrypt image file - Crypt Mode, used to select if image files should be decrypted or not - */ - bool setupCrypt(const uint8_t *cryptKey = 0, size_t cryptAddress = 0, uint8_t cryptConfig = 0xf, int cryptMode = U_AES_DECRYPT_AUTO); - /* Writes a buffer to the flash and increments the address Returns the amount written @@ -95,34 +77,10 @@ class UpdateClass { or there is an error this will clear everything and return false the last error is available through getError() - evenIfRemaining is helpful when you update without knowing the final size first + evenIfRemaining is helpfull when you update without knowing the final size first */ bool end(bool evenIfRemaining = false); - /* - sets AES256 key(32 bytes) used for decrypting image file - */ - bool setCryptKey(const uint8_t *cryptKey); - - /* - sets crypt mode used on image files - */ - bool setCryptMode(const int cryptMode); - - /* - sets address used for decrypting image file - */ - void setCryptAddress(const size_t cryptAddress) { - _cryptAddress = cryptAddress & 0x00fffff0; - } - - /* - sets crypt config used for decrypting image file - */ - void setCryptConfig(const uint8_t cryptConfig) { - _cryptCfg = cryptConfig & 0x0f; - } - /* Aborts the running update */ @@ -235,8 +193,6 @@ class UpdateClass { private: void _reset(); void _abort(uint8_t err); - void _cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key); - bool _decryptBuffer(); bool _writeBuffer(); bool _verifyHeader(uint8_t data); bool _verifyEnd(); @@ -244,8 +200,6 @@ class UpdateClass { bool _chkDataInBlock(const uint8_t *data, size_t len) const; // check if block contains any data or is empty uint8_t _error; - uint8_t *_cryptKey; - uint8_t *_cryptBuffer; uint8_t *_buffer; uint8_t *_skipBuffer; size_t _bufferLen; @@ -261,10 +215,6 @@ class UpdateClass { int _ledPin; uint8_t _ledOn; - - uint8_t _cryptMode; - size_t _cryptAddress; - uint8_t _cryptCfg; }; #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_UPDATE) diff --git a/libraries/Update/src/Updater.cpp b/libraries/Update/src/Updater.cpp index 4be13b9d1ed..e5717c5beea 100644 --- a/libraries/Update/src/Updater.cpp +++ b/libraries/Update/src/Updater.cpp @@ -9,7 +9,6 @@ #include "spi_flash_mmap.h" #include "esp_ota_ops.h" #include "esp_image_format.h" -#include "mbedtls/aes.h" static const char *_err2str(uint8_t _error) { if (_error == UPDATE_ERROR_OK) { @@ -38,8 +37,6 @@ static const char *_err2str(uint8_t _error) { return ("Bad Argument"); } else if (_error == UPDATE_ERROR_ABORT) { return ("Aborted"); - } else if (_error == UPDATE_ERROR_DECRYPT) { - return ("Decryption error"); } return ("UNKNOWN"); } @@ -67,8 +64,7 @@ bool UpdateClass::_enablePartition(const esp_partition_t *partition) { } UpdateClass::UpdateClass() - : _error(0), _cryptKey(0), _cryptBuffer(0), _buffer(0), _skipBuffer(0), _bufferLen(0), _size(0), _progress_callback(NULL), _progress(0), _paroffset(0), - _command(U_FLASH), _partition(NULL), _cryptMode(U_AES_DECRYPT_AUTO), _cryptAddress(0), _cryptCfg(0xf) {} + : _error(0), _buffer(0), _bufferLen(0), _size(0), _progress_callback(NULL), _progress(0), _paroffset(0), _command(U_FLASH), _partition(NULL) {} UpdateClass &UpdateClass::onProgress(THandlerFunction_Progress fn) { _progress_callback = fn; @@ -83,7 +79,6 @@ void UpdateClass::_reset() { delete[] _skipBuffer; } - _cryptBuffer = nullptr; _buffer = nullptr; _skipBuffer = nullptr; _bufferLen = 0; @@ -175,48 +170,6 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, con return true; } -bool UpdateClass::setupCrypt(const uint8_t *cryptKey, size_t cryptAddress, uint8_t cryptConfig, int cryptMode) { - if (setCryptKey(cryptKey)) { - if (setCryptMode(cryptMode)) { - setCryptAddress(cryptAddress); - setCryptConfig(cryptConfig); - return true; - } - } - return false; -} - -bool UpdateClass::setCryptKey(const uint8_t *cryptKey) { - if (!cryptKey) { - if (_cryptKey) { - delete[] _cryptKey; - _cryptKey = 0; - log_d("AES key unset"); - } - return false; //key cleared, no key to decrypt with - } - //initialize - if (!_cryptKey) { - _cryptKey = new (std::nothrow) uint8_t[ENCRYPTED_KEY_SIZE]; - } - if (!_cryptKey) { - log_e("new failed"); - return false; - } - memcpy(_cryptKey, cryptKey, ENCRYPTED_KEY_SIZE); - return true; -} - -bool UpdateClass::setCryptMode(const int cryptMode) { - if (cryptMode >= U_AES_DECRYPT_NONE && cryptMode <= U_AES_DECRYPT_ON) { - _cryptMode = cryptMode; - } else { - log_e("bad crypt mode argument %i", cryptMode); - return false; - } - return true; -} - void UpdateClass::_abort(uint8_t err) { _reset(); _error = err; @@ -226,135 +179,7 @@ void UpdateClass::abort() { _abort(UPDATE_ERROR_ABORT); } -void UpdateClass::_cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key) { - memcpy(tweaked_key, _cryptKey, ENCRYPTED_KEY_SIZE); - if (_cryptCfg == 0) { - return; //no tweaking needed, use crypt key as-is - } - - const uint8_t pattern[] = {23, 23, 23, 14, 23, 23, 23, 12, 23, 23, 23, 10, 23, 23, 23, 8}; - int pattern_idx = 0; - int key_idx = 0; - int bit_len = 0; - uint32_t tweak = 0; - cryptAddress &= 0x00ffffe0; //bit 23-5 - cryptAddress <<= 8; //bit23 shifted to bit31(MSB) - while (pattern_idx < sizeof(pattern)) { - tweak = cryptAddress << (23 - pattern[pattern_idx]); //bit shift for small patterns - // alternative to: tweak = rotl32(tweak,8 - bit_len); - tweak = (tweak << (8 - bit_len)) | (tweak >> (24 + bit_len)); //rotate to line up with end of previous tweak bits - bit_len += pattern[pattern_idx++] - 4; //add number of bits in next pattern(23-4 = 19bits = 23bit to 5bit) - while (bit_len > 7) { - tweaked_key[key_idx++] ^= tweak; //XOR byte - // alternative to: tweak = rotl32(tweak, 8); - tweak = (tweak << 8) | (tweak >> 24); //compiler should optimize to use rotate(fast) - bit_len -= 8; - } - tweaked_key[key_idx] ^= tweak; //XOR remaining bits, will XOR zeros if no remaining bits - } - if (_cryptCfg == 0xf) { - return; //return with fully tweaked key - } - - //some of tweaked key bits need to be restore back to crypt key bits - const uint8_t cfg_bits[] = {67, 65, 63, 61}; - key_idx = 0; - pattern_idx = 0; - while (key_idx < ENCRYPTED_KEY_SIZE) { - bit_len += cfg_bits[pattern_idx]; - if ((_cryptCfg & (1 << pattern_idx)) == 0) { //restore crypt key bits - while (bit_len > 0) { - if (bit_len > 7 || ((_cryptCfg & (2 << pattern_idx)) == 0)) { //restore a crypt key byte - tweaked_key[key_idx] = _cryptKey[key_idx]; - } else { //MSBits restore crypt key bits, LSBits keep as tweaked bits - tweaked_key[key_idx] &= (0xff >> bit_len); - tweaked_key[key_idx] |= (_cryptKey[key_idx] & (~(0xff >> bit_len))); - } - key_idx++; - bit_len -= 8; - } - } else { //keep tweaked key bits - while (bit_len > 0) { - if (bit_len < 8 && ((_cryptCfg & (2 << pattern_idx)) == 0)) { //MSBits keep as tweaked bits, LSBits restore crypt key bits - tweaked_key[key_idx] &= (~(0xff >> bit_len)); - tweaked_key[key_idx] |= (_cryptKey[key_idx] & (0xff >> bit_len)); - } - key_idx++; - bit_len -= 8; - } - } - pattern_idx++; - } -} - -bool UpdateClass::_decryptBuffer() { - if (!_cryptKey) { - log_w("AES key not set"); - return false; - } - if (_bufferLen % ENCRYPTED_BLOCK_SIZE != 0) { - log_e("buffer size error"); - return false; - } - if (!_cryptBuffer) { - _cryptBuffer = new (std::nothrow) uint8_t[ENCRYPTED_BLOCK_SIZE]; - } - if (!_cryptBuffer) { - log_e("new failed"); - return false; - } - uint8_t tweaked_key[ENCRYPTED_KEY_SIZE]; //tweaked crypt key - int done = 0; - - /* - Mbedtls functions will be replaced with esp_aes functions when hardware acceleration is available - - To Do: - Replace mbedtls for the cases where there's no hardware acceleration - */ - - mbedtls_aes_context ctx; //initialize AES - mbedtls_aes_init(&ctx); - while ((_bufferLen - done) >= ENCRYPTED_BLOCK_SIZE) { - for (int i = 0; i < ENCRYPTED_BLOCK_SIZE; i++) { - _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i] = _buffer[i + done]; //reverse order 16 bytes to decrypt - } - if (((_cryptAddress + _progress + done) % ENCRYPTED_TWEAK_BLOCK_SIZE) == 0 || done == 0) { - _cryptKeyTweak(_cryptAddress + _progress + done, tweaked_key); //update tweaked crypt key - if (mbedtls_aes_setkey_enc(&ctx, tweaked_key, 256)) { - return false; - } - if (mbedtls_aes_setkey_dec(&ctx, tweaked_key, 256)) { - return false; - } - } - if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, _cryptBuffer, _cryptBuffer)) { //use MBEDTLS_AES_ENCRYPT to decrypt flash code - return false; - } - for (int i = 0; i < ENCRYPTED_BLOCK_SIZE; i++) { - _buffer[i + done] = _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i]; //reverse order 16 bytes from decrypt - } - done += ENCRYPTED_BLOCK_SIZE; - } - return true; -} - bool UpdateClass::_writeBuffer() { - //first bytes of loading image, check to see if loading image needs decrypting - if (!_progress) { - _cryptMode &= U_AES_DECRYPT_MODE_MASK; - if ((_cryptMode == U_AES_DECRYPT_ON) || ((_command == U_FLASH) && (_cryptMode & U_AES_DECRYPT_AUTO) && (_buffer[0] != ESP_IMAGE_HEADER_MAGIC))) { - _cryptMode |= U_AES_IMAGE_DECRYPTING_BIT; //set to decrypt the loading image - log_d("Decrypting OTA Image"); - } - } - //check if data in buffer needs decrypting - if (_cryptMode & U_AES_IMAGE_DECRYPTING_BIT) { - if (!_decryptBuffer()) { - _abort(UPDATE_ERROR_DECRYPT); - return false; - } - } //first bytes of new firmware uint8_t skip = 0; if (!_progress && _command == U_FLASH) { @@ -524,11 +349,9 @@ size_t UpdateClass::writeStream(Stream &data) { return 0; } - if (_command == U_FLASH && !_cryptMode) { - if (!_verifyHeader(data.peek())) { - _reset(); - return 0; - } + if (!_verifyHeader(data.peek())) { + _reset(); + return 0; } if (_ledPin != -1) { diff --git a/libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino b/libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino index d7241a2f1a4..05cbc4a1841 100644 --- a/libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino +++ b/libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino @@ -50,7 +50,7 @@ void wifiConnectedLoop() { if (packetLength >= NTP_PACKET_SIZE) { ntpClient.read(ntpPacketBuffer, NTP_PACKET_SIZE); } - ntpClient.clear(); + ntpClient.flush(); uint32_t secsSince1900 = (uint32_t)ntpPacketBuffer[40] << 24 | (uint32_t)ntpPacketBuffer[41] << 16 | (uint32_t)ntpPacketBuffer[42] << 8 | ntpPacketBuffer[43]; //Serial.printf("Seconds since Jan 1 1900: %u\n", secsSince1900); diff --git a/libraries/WiFi/src/STA.cpp b/libraries/WiFi/src/STA.cpp index 443d2621957..bede1680ec4 100644 --- a/libraries/WiFi/src/STA.cpp +++ b/libraries/WiFi/src/STA.cpp @@ -419,105 +419,6 @@ bool STAClass::connect(const char *ssid, const char *passphrase, int32_t channel return true; } -/** - * Start Wifi connection with a WPA2 Enterprise AP - * if passphrase is set the most secure supported mode will be automatically selected - * @param ssid const char* Pointer to the SSID string. - * @param method wpa2_method_t The authentication method of WPA2 (WPA2_AUTH_TLS, WPA2_AUTH_PEAP, WPA2_AUTH_TTLS) - * @param wpa2_identity const char* Pointer to the entity - * @param wpa2_username const char* Pointer to the username - * @param password const char * Pointer to the password. - * @param ca_pem const char* Pointer to a string with the contents of a .pem file with CA cert - * @param client_crt const char* Pointer to a string with the contents of a .crt file with client cert - * @param client_key const char* Pointer to a string with the contents of a .key file with client key - * @param bssid uint8_t[6] Optional. BSSID / MAC of AP - * @param channel Optional. Channel of AP - * @param connect Optional. call connect - * @return - */ -bool STAClass::connect( - const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity, const char *wpa2_username, const char *wpa2_password, const char *ca_pem, - const char *client_crt, const char *client_key, int ttls_phase2_type, int32_t channel, const uint8_t *bssid, bool tryConnect -) { - if (_esp_netif == NULL) { - log_e("STA not started! You must call begin() first."); - return false; - } - - if (connected()) { - log_w("STA currently connected. Disconnecting..."); - if (!disconnect(true, 1000)) { - return false; - } - } - - if (!wpa2_ssid || *wpa2_ssid == 0x00 || strlen(wpa2_ssid) > 32) { - log_e("SSID too long or missing!"); - return false; - } - - if (wpa2_identity && strlen(wpa2_identity) > 64) { - log_e("identity too long!"); - return false; - } - - if (wpa2_username && strlen(wpa2_username) > 64) { - log_e("username too long!"); - return false; - } - - if (wpa2_password && strlen(wpa2_password) > 64) { - log_e("password too long!"); - return false; - } - - if (ttls_phase2_type >= 0) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_ttls_phase2_method((esp_eap_ttls_phase2_types)ttls_phase2_type); -#else - esp_wifi_sta_wpa2_ent_set_ttls_phase2_method((esp_eap_ttls_phase2_types)ttls_phase2_type); -#endif - } - - if (ca_pem) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem)); -#else - esp_wifi_sta_wpa2_ent_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem)); -#endif - } - - if (client_crt) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_certificate_and_key((uint8_t *)client_crt, strlen(client_crt), (uint8_t *)client_key, strlen(client_key), NULL, 0); -#else - esp_wifi_sta_wpa2_ent_set_cert_key((uint8_t *)client_crt, strlen(client_crt), (uint8_t *)client_key, strlen(client_key), NULL, 0); -#endif - } - -#if __has_include("esp_eap_client.h") - esp_eap_client_set_identity((uint8_t *)wpa2_identity, strlen(wpa2_identity)); -#else - esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)wpa2_identity, strlen(wpa2_identity)); -#endif - if (method == WPA2_AUTH_PEAP || method == WPA2_AUTH_TTLS) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_username((uint8_t *)wpa2_username, strlen(wpa2_username)); - esp_eap_client_set_password((uint8_t *)wpa2_password, strlen(wpa2_password)); -#else - esp_wifi_sta_wpa2_ent_set_username((uint8_t *)wpa2_username, strlen(wpa2_username)); - esp_wifi_sta_wpa2_ent_set_password((uint8_t *)wpa2_password, strlen(wpa2_password)); -#endif - } -#if __has_include("esp_eap_client.h") - esp_wifi_sta_enterprise_enable(); //set config settings to enable function -#else - esp_wifi_sta_wpa2_ent_enable(); //set config settings to enable function -#endif - - return connect(wpa2_ssid, NULL, channel, bssid, tryConnect); //connect to wifi -} - bool STAClass::disconnect(bool eraseap, unsigned long timeout) { if (eraseap) { if (!started()) { diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index 75a01d1362f..0f5ec0ee279 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -126,7 +126,9 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev /* * Provisioning * */ - } else if (event_base == WIFI_PROV_EVENT && event_id == WIFI_PROV_INIT) { + } +#if defined __has_include && __has_include("wifi_provisioning/wifi_config.h") + else if (event_base == WIFI_PROV_EVENT && event_id == WIFI_PROV_INIT) { log_v("Provisioning Initialized!"); arduino_event.event_id = ARDUINO_EVENT_PROV_INIT; } else if (event_base == WIFI_PROV_EVENT && event_id == WIFI_PROV_DEINIT) { @@ -157,6 +159,7 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev log_v("Provisioning Success!"); arduino_event.event_id = ARDUINO_EVENT_PROV_CRED_SUCCESS; } +#endif // __has_include ("wifi_provisioning/wifi_config.h") if (arduino_event.event_id < ARDUINO_EVENT_MAX) { Network.postEvent(&arduino_event); @@ -174,10 +177,12 @@ static bool initWiFiEvents() { return false; } +#if defined __has_include && __has_include("wifi_provisioning/wifi_config.h") if (esp_event_handler_instance_register(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb, NULL, NULL)) { log_e("event_handler_instance_register for WIFI_PROV_EVENT Failed!"); return false; } +#endif // __has_include ("wifi_provisioning/wifi_config.h") return true; } @@ -193,10 +198,12 @@ static bool deinitWiFiEvents() { return false; } +#if defined __has_include && __has_include("wifi_provisioning/wifi_config.h") if (esp_event_handler_unregister(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb)) { log_e("esp_event_handler_unregister for WIFI_PROV_EVENT Failed!"); return false; } +#endif // __has_include ("wifi_provisioning/wifi_config.h") return true; } diff --git a/libraries/WiFi/src/WiFiGeneric.h b/libraries/WiFi/src/WiFiGeneric.h index 3cb1515b324..df46639fb03 100644 --- a/libraries/WiFi/src/WiFiGeneric.h +++ b/libraries/WiFi/src/WiFiGeneric.h @@ -32,8 +32,12 @@ #include "IPAddress.h" #include "esp_smartconfig.h" #include "esp_netif_types.h" +#if defined __has_include && __has_include("esp_eth_driver.h") #include "esp_eth_driver.h" +#endif +#if defined __has_include && __has_include("wifi_provisioning/manager.h") #include "wifi_provisioning/manager.h" +#endif #include "lwip/ip_addr.h" #include "Network.h" diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index 1c1ce42c12f..470db1a5675 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -65,13 +65,13 @@ wl_status_t WiFiSTAClass::status() { wl_status_t WiFiSTAClass::begin( const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity, const char *wpa2_username, const char *wpa2_password, const char *ca_pem, - const char *client_crt, const char *client_key, int ttls_phase2_type, int32_t channel, const uint8_t *bssid, bool connect + const char *client_crt, const char *client_key, int32_t channel, const uint8_t *bssid, bool connect ) { if (!STA.begin()) { return WL_CONNECT_FAILED; } - if (!STA.connect(wpa2_ssid, method, wpa2_identity, wpa2_username, wpa2_password, ca_pem, client_crt, client_key, ttls_phase2_type, channel, bssid, connect)) { + if (!STA.connect(wpa2_ssid, method, wpa2_identity, wpa2_username, wpa2_password, ca_pem, client_crt, client_key, channel, bssid, connect)) { return WL_CONNECT_FAILED; } diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index 2c046c4c4b9..d5c5d377d3b 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -55,8 +55,7 @@ class STAClass : public NetworkInterface { bool connect(const char *ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t *bssid = NULL, bool connect = true); bool connect( const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity = NULL, const char *wpa2_username = NULL, const char *wpa2_password = NULL, - const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int ttls_phase2_type = -1, int32_t channel = 0, - const uint8_t *bssid = 0, bool connect = true + const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true ); bool disconnect(bool eraseap = false, unsigned long timeout = 0); bool reconnect(); @@ -110,17 +109,16 @@ class WiFiSTAClass { wl_status_t begin( const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity = NULL, const char *wpa2_username = NULL, const char *wpa2_password = NULL, - const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int ttls_phase2_type = -1, int32_t channel = 0, - const uint8_t *bssid = 0, bool connect = true + const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true ); wl_status_t begin( const String &wpa2_ssid, wpa2_auth_method_t method, const String &wpa2_identity = (const char *)NULL, const String &wpa2_username = (const char *)NULL, const String &wpa2_password = (const char *)NULL, const String &ca_pem = (const char *)NULL, const String &client_crt = (const char *)NULL, - const String &client_key = (const char *)NULL, int ttls_phase2_type = -1, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true + const String &client_key = (const char *)NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true ) { return begin( wpa2_ssid.c_str(), method, wpa2_identity.c_str(), wpa2_username.c_str(), wpa2_password.c_str(), ca_pem.c_str(), client_crt.c_str(), client_key.c_str(), - ttls_phase2_type, channel, bssid, connect + channel, bssid, connect ); } wl_status_t begin(const char *ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t *bssid = NULL, bool connect = true); diff --git a/tools/platformio-build.py b/tools/platformio-build.py index 06b5dac2e1b..3421286a708 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -35,7 +35,7 @@ partitions_name = board_config.get("build.partitions", board_config.get("build.arduino.partitions", "")) FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") -FRAMEWORK_LIBS_DIR = platform.get_package_dir("framework-arduinoespressif32-libs") +FRAMEWORK_LIBS_DIR = join(FRAMEWORK_DIR, "tools", "esp32-arduino-libs") assert isdir(FRAMEWORK_DIR) @@ -175,9 +175,15 @@ def add_tinyuf2_extra_image(): libs = [] variants_dir = join(FRAMEWORK_DIR, "variants") +try: + build_variants_dir = join(board_config.get("build.variants_dir")) +except Exception: + build_variants_dir = "" if "build.variants_dir" in board_config: - variants_dir = join("$PROJECT_DIR", board_config.get("build.variants_dir")) + if len(build_variants_dir) > 1: + variants_dir = join("$PROJECT_DIR", board_config.get("build.variants_dir")) + if "build.variant" in board_config: env.Append(CPPPATH=[join(variants_dir, board_config.get("build.variant"))]) @@ -200,17 +206,26 @@ def add_tinyuf2_extra_image(): # Process framework extra images # +# Tasmota places extra images "safeboot" in custom variants folder in project directory +build_name = join(board_config.get("name")) +if len(build_variants_dir) > 1: + EXTRA_IMG_DIR = join(variants_dir) +else: + EXTRA_IMG_DIR = FRAMEWORK_DIR + if "tasmota" in build_name.lower(): + EXTRA_IMG_DIR = join(EXTRA_IMG_DIR, "variants", "tasmota") + env.Append( LIBSOURCE_DIRS=[join(FRAMEWORK_DIR, "libraries")], FLASH_EXTRA_IMAGES=[ ( - "0x1000" if build_mcu in ("esp32", "esp32s2") else "0x0000", + "0x1000" if build_mcu in ("esp32", "esp32s2") else ("0x2000" if build_mcu in ("esp32p4") else "0x0000"), get_bootloader_image(variants_dir), ), ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")), ] - + [(offset, join(FRAMEWORK_DIR, img)) for offset, img in board_config.get("upload.arduino.flash_extra_images", [])], + + [(offset, join(EXTRA_IMG_DIR, img)) for offset, img in board_config.get("upload.arduino.flash_extra_images", [])], ) # Add an extra UF2 image if the 'TinyUF2' partition is selected diff --git a/variants/esp32p4/pins_arduino.h b/variants/esp32p4/pins_arduino.h new file mode 100644 index 00000000000..d048050079d --- /dev/null +++ b/variants/esp32p4/pins_arduino.h @@ -0,0 +1,35 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define PIN_NEOPIXEL 8 +// BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +// RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() +#define RGB_BUILTIN LED_BUILTIN +#define RGB_BRIGHTNESS 64 + +static const uint8_t TX = 37; +static const uint8_t RX = 38; + +static const uint8_t SDA = 13; +static const uint8_t SCL = 12; + +static const uint8_t SS = 7; +static const uint8_t MOSI = 8; +static const uint8_t MISO = 10; +static const uint8_t SCK = 9; + +static const uint8_t A0 = 0; +static const uint8_t A1 = 1; +static const uint8_t A2 = 2; +static const uint8_t A3 = 3; +static const uint8_t A4 = 4; +static const uint8_t A5 = 5; +static const uint8_t A6 = 6; + +#endif /* Pins_Arduino_h */