diff --git a/.github/scripts/install-arduino-core-esp32.sh b/.github/scripts/install-arduino-core-esp32.sh index 8584da5b6e2..cc685711e15 100755 --- a/.github/scripts/install-arduino-core-esp32.sh +++ b/.github/scripts/install-arduino-core-esp32.sh @@ -20,7 +20,7 @@ if [ ! -d "$ARDUINO_ESP32_PATH" ]; then ln -s $GITHUB_WORKSPACE esp32 else echo "Cloning Core Repository..." - git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1 + git clone https://github.com/tasmota/arduino-esp32.git esp32 > /dev/null 2>&1 fi #echo "Updating Submodules ..." diff --git a/.github/scripts/install-arduino-ide.sh b/.github/scripts/install-arduino-ide.sh index 5647229cb40..0f36120b3a9 100755 --- a/.github/scripts/install-arduino-ide.sh +++ b/.github/scripts/install-arduino-ide.sh @@ -34,9 +34,6 @@ else fi export OS_NAME -ARDUINO_BUILD_DIR="$HOME/.arduino/build.tmp" -ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp" - if [ "$OS_IS_MACOS" == "1" ]; then export ARDUINO_IDE_PATH="/Applications/Arduino.app/Contents/Java" export ARDUINO_USR_PATH="$HOME/Documents/Arduino" @@ -81,156 +78,3 @@ if [ ! -d "$ARDUINO_IDE_PATH" ]; then echo "" fi -function build_sketch(){ # build_sketch [extra-options] - if [ "$#" -lt 2 ]; then - echo "ERROR: Illegal number of parameters" - echo "USAGE: build_sketch [extra-options]" - return 1 - fi - - local fqbn="$1" - local sketch="$2" - local xtra_opts="$3" - local win_opts="" - if [ "$OS_IS_WINDOWS" == "1" ]; then - local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"` - local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"` - win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version -prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version" - fi - - #echo "" - #echo "Compiling '"$(basename "$sketch")"' ..." - mkdir -p "$ARDUINO_BUILD_DIR" - mkdir -p "$ARDUINO_CACHE_DIR" - $ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=10810 \ - -fqbn=$fqbn \ - -warnings="all" \ - -tools "$ARDUINO_IDE_PATH/tools-builder" \ - -tools "$ARDUINO_IDE_PATH/tools" \ - -built-in-libraries "$ARDUINO_IDE_PATH/libraries" \ - -hardware "$ARDUINO_IDE_PATH/hardware" \ - -hardware "$ARDUINO_USR_PATH/hardware" \ - -libraries "$ARDUINO_USR_PATH/libraries" \ - -build-cache "$ARDUINO_CACHE_DIR" \ - -build-path "$ARDUINO_BUILD_DIR" \ - $win_opts $xtra_opts "$sketch" -} - -function count_sketches(){ # count_sketches - local examples="$1" - local target="$2" - rm -rf sketches.txt - if [ ! -d "$examples" ]; then - touch sketches.txt - return 0 - fi - local sketches=$(find $examples -name *.ino) - local sketchnum=0 - for sketch in $sketches; do - local sketchdir=$(dirname $sketch) - local sketchdirname=$(basename $sketchdir) - local sketchname=$(basename $sketch) - if [[ "$sketchdirname.ino" != "$sketchname" ]]; then - continue - elif [[ -f "$sketchdir/.skip.$target" ]]; then - continue - else - echo $sketch >> sketches.txt - sketchnum=$(($sketchnum + 1)) - fi - done - return $sketchnum -} - -function build_sketches(){ # build_sketches [extra-options] - local fqbn=$1 - local target="$2" - local examples=$3 - local chunk_idex=$4 - local chunks_num=$5 - local xtra_opts=$6 - - if [ "$#" -lt 3 ]; then - echo "ERROR: Illegal number of parameters" - echo "USAGE: build_sketches [ ] [extra-options]" - return 1 - fi - - if [ "$#" -lt 5 ]; then - chunk_idex="0" - chunks_num="1" - xtra_opts=$4 - fi - - if [ "$chunks_num" -le 0 ]; then - echo "ERROR: Chunks count must be positive number" - return 1 - fi - if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then - echo "ERROR: Chunk index must be less than chunks count" - return 1 - fi - - set +e - count_sketches "$examples" "$target" - local sketchcount=$? - set -e - local sketches=$(cat sketches.txt) - rm -rf sketches.txt - - local chunk_size=$(( $sketchcount / $chunks_num )) - local all_chunks=$(( $chunks_num * $chunk_size )) - if [ "$all_chunks" -lt "$sketchcount" ]; then - chunk_size=$(( $chunk_size + 1 )) - fi - - local start_index=0 - local end_index=0 - if [ "$chunk_idex" -ge "$chunks_num" ]; then - start_index=$chunk_idex - end_index=$sketchcount - else - start_index=$(( $chunk_idex * $chunk_size )) - if [ "$sketchcount" -le "$start_index" ]; then - echo "Skipping job" - return 0 - fi - - end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size )) - if [ "$end_index" -gt "$sketchcount" ]; then - end_index=$sketchcount - fi - fi - - local start_num=$(( $start_index + 1 )) - echo "Found $sketchcount Sketches for target '$target'"; - echo "Chunk Index : $chunk_idex" - echo "Chunk Count : $chunks_num" - echo "Chunk Size : $chunk_size" - echo "Start Sketch: $start_num" - echo "End Sketch : $end_index" - - local sketchnum=0 - for sketch in $sketches; do - local sketchdir=$(dirname $sketch) - local sketchdirname=$(basename $sketchdir) - local sketchname=$(basename $sketch) - if [ "${sketchdirname}.ino" != "$sketchname" ] \ - || [ -f "$sketchdir/.skip.$target" ]; then - continue - fi - sketchnum=$(($sketchnum + 1)) - if [ "$sketchnum" -le "$start_index" ] \ - || [ "$sketchnum" -gt "$end_index" ]; then - continue - fi - echo "" - echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname" - build_sketch "$fqbn" "$sketch" "$xtra_opts" - local result=$? - if [ $result -ne 0 ]; then - return $result - fi - done - return 0 -} diff --git a/.github/scripts/install-platformio-esp32.sh b/.github/scripts/install-platformio-esp32.sh index 0d27967bfa8..a19e11b9ae6 100755 --- a/.github/scripts/install-platformio-esp32.sh +++ b/.github/scripts/install-platformio-esp32.sh @@ -3,9 +3,9 @@ export PLATFORMIO_ESP32_PATH="$HOME/.platformio/packages/framework-arduinoespressif32" PLATFORMIO_ESP32_URL="https://github.com/platformio/platform-espressif32.git#feature/arduino-idf-master" -XTENSA32_TOOLCHAIN_VERSION="8.4.0+2021r1" -XTENSA32S2_TOOLCHAIN_VERSION="8.4.0+2021r1" -RISCV_TOOLCHAIN_VERSION="8.4.0+2021r1" +XTENSA32_TOOLCHAIN_VERSION="8.4.0+2021r2-patch2" +XTENSA32S2_TOOLCHAIN_VERSION="8.4.0+2021r2-patch2" +RISCV_TOOLCHAIN_VERSION="8.4.0+2021r2-patch2" ESPTOOLPY_VERSION="~1.30100.0" ESPRESSIF_ORGANIZATION_NAME="espressif" diff --git a/.github/scripts/on-push.sh b/.github/scripts/on-push.sh index dbca978fdfb..5d8ffe9cd3e 100755 --- a/.github/scripts/on-push.sh +++ b/.github/scripts/on-push.sh @@ -2,6 +2,40 @@ set -e +function build(){ + local target=$1 + local fqbn=$2 + local chunk_index=$3 + local chunks_cnt=$4 + local sketches=$5 + + local BUILD_SKETCH="${SCRIPTS_DIR}/sketch_utils.sh build" + local BUILD_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh chunk_build" + + local args="$ARDUINO_IDE_PATH $ARDUINO_USR_PATH" + + args+=" \"$fqbn\"" + + if [ "$OS_IS_LINUX" == "1" ]; then + args+=" $target" + args+=" $ARDUINO_ESP32_PATH/libraries" + args+=" $chunk_index $chunks_cnt" + ${BUILD_SKETCHES} ${args} + else + if [ "$OS_IS_WINDOWS" == "1" ]; then + local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"` + local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"` + win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version + -prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version" + args+=" ${win_opts}" + fi + + for sketch in ${sketches}; do + ${BUILD_SKETCH} ${args} ${sketch} + done + fi +} + if [ -z "$GITHUB_WORKSPACE" ]; then export GITHUB_WORKSPACE="$PWD" export GITHUB_REPOSITORY="espressif/arduino-esp32" @@ -22,57 +56,31 @@ fi #echo "Updating submodules ..." #git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1 +SCRIPTS_DIR="./.github/scripts" if [ "$BUILD_PIO" -eq 0 ]; then - # ArduinoIDE ESP32 Test - TARGET="esp32" - FQBN="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app" source ./.github/scripts/install-arduino-ide.sh - source ./.github/scripts/install-arduino-core-esp32.sh - if [ "$OS_IS_WINDOWS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" - elif [ "$OS_IS_MACOS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" - else - # CMake Test - if [ "$CHUNK_INDEX" -eq 0 ]; then - bash "$ARDUINO_ESP32_PATH/.github/scripts/check-cmakelists.sh" - fi - build_sketches "$FQBN" "$TARGET" "$ARDUINO_ESP32_PATH/libraries" "$CHUNK_INDEX" "$CHUNKS_CNT" - fi + source ${SCRIPTS_DIR}/install-arduino-core-esp32.sh - # ArduinoIDE ESP32S2 Test - TARGET="esp32s2" - FQBN="espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app" - if [ "$OS_IS_WINDOWS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" - elif [ "$OS_IS_MACOS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" - else - build_sketches "$FQBN" "$TARGET" "$ARDUINO_ESP32_PATH/libraries" "$CHUNK_INDEX" "$CHUNKS_CNT" - fi + FQBN_ESP32="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app" + FQBN_ESP32S2="espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app" + FQBN_ESP32C3="espressif:esp32:esp32c3:PartitionScheme=huge_app" - # ArduinoIDE ESP32C3 Test - TARGET="esp32c3" - FQBN="espressif:esp32:esp32c3:PartitionScheme=huge_app" - if [ "$OS_IS_WINDOWS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" - elif [ "$OS_IS_MACOS" == "1" ]; then - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" - else - build_sketches "$FQBN" "$TARGET" "$ARDUINO_ESP32_PATH/libraries" "$CHUNK_INDEX" "$CHUNKS_CNT" - fi + SKETCHES_ESP32="\ + $ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino\ + $ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino\ + $ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino\ + " + + SKETCHES_ESP32XX="\ + $ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino\ + $ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino\ + " + + build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32 + build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX + build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX else - source ./.github/scripts/install-platformio-esp32.sh + source ./${SCRIPTS_DIR}/install-platformio-esp32.sh # PlatformIO ESP32 Test BOARD="esp32dev" OPTIONS="board_build.partitions = huge_app.csv" diff --git a/.github/scripts/sketch_utils.sh b/.github/scripts/sketch_utils.sh new file mode 100755 index 00000000000..abc6a0476e5 --- /dev/null +++ b/.github/scripts/sketch_utils.sh @@ -0,0 +1,184 @@ +#!/bin/bash + +function build_sketch(){ # build_sketch [extra-options] + if [ "$#" -lt 4 ]; then + echo "ERROR: Illegal number of parameters" + echo "USAGE: ${0} build [extra-options]" + return 1 + fi + + ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp" + local ide_path=$1 + local usr_path=$2 + local fqbn=$3 + local sketch=$4 + local xtra_opts=$5 + local win_opts=$6 + + build_dir="$(dirname $sketch)/build" + mkdir -p "$build_dir" + mkdir -p "$ARDUINO_CACHE_DIR" + $ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \ + -fqbn=$fqbn \ + -warnings="all" \ + -tools "$ide_path/tools-builder" \ + -tools "$ide_path/tools" \ + -built-in-libraries "$ide_path/libraries" \ + -hardware "$ide_path/hardware" \ + -hardware "$usr_path/hardware" \ + -libraries "$usr_path/libraries" \ + -build-cache "$ARDUINO_CACHE_DIR" \ + -build-path "$build_dir" \ + $win_opts $xtra_opts "$sketch" +} + +function count_sketches(){ # count_sketches + local path=$1 + local target=$2 + + if [ $# -lt 2 ]; then + echo "ERROR: Illegal number of parameters" + echo "USAGE: ${0} count " + fi + + rm -rf sketches.txt + if [ ! -d "$path" ]; then + touch sketches.txt + return 0 + fi + + local sketches=$(find $path -name *.ino) + local sketchnum=0 + for sketch in $sketches; do + local sketchdir=$(dirname $sketch) + local sketchdirname=$(basename $sketchdir) + local sketchname=$(basename $sketch) + if [[ "$sketchdirname.ino" != "$sketchname" ]]; then + continue + elif [[ -f "$sketchdir/.skip.$target" ]]; then + continue + else + echo $sketch >> sketches.txt + sketchnum=$(($sketchnum + 1)) + fi + done + return $sketchnum +} + +function build_sketches(){ # build_sketches [extra-options] + local ide_path=$1 + local usr_path=$2 + local fqbn=$3 + local target=$4 + local path=$5 + local chunk_idex=$6 + local chunks_num=$7 + local xtra_opts=$8 + + if [ "$#" -lt 7 ]; then + echo "ERROR: Illegal number of parameters" + echo "USAGE: ${0} chunk_build [ ] [extra-options]" + return 1 + fi + + if [ "$chunks_num" -le 0 ]; then + echo "ERROR: Chunks count must be positive number" + return 1 + fi + if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then + echo "ERROR: Chunk index must be less than chunks count" + return 1 + fi + + set +e + count_sketches "$path" "$target" + local sketchcount=$? + set -e + local sketches=$(cat sketches.txt) + rm -rf sketches.txt + + local chunk_size=$(( $sketchcount / $chunks_num )) + local all_chunks=$(( $chunks_num * $chunk_size )) + if [ "$all_chunks" -lt "$sketchcount" ]; then + chunk_size=$(( $chunk_size + 1 )) + fi + + local start_index=0 + local end_index=0 + if [ "$chunk_idex" -ge "$chunks_num" ]; then + start_index=$chunk_idex + end_index=$sketchcount + else + start_index=$(( $chunk_idex * $chunk_size )) + if [ "$sketchcount" -le "$start_index" ]; then + echo "Skipping job" + return 0 + fi + + end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size )) + if [ "$end_index" -gt "$sketchcount" ]; then + end_index=$sketchcount + fi + fi + + local start_num=$(( $start_index + 1 )) + echo "Found $sketchcount Sketches for target '$target'"; + echo "Chunk Index : $chunk_idex" + echo "Chunk Count : $chunks_num" + echo "Chunk Size : $chunk_size" + echo "Start Sketch: $start_num" + echo "End Sketch : $end_index" + + local sketchnum=0 + for sketch in $sketches; do + local sketchdir=$(dirname $sketch) + local sketchdirname=$(basename $sketchdir) + local sketchname=$(basename $sketch) + sketchnum=$(($sketchnum + 1)) + if [ "$sketchnum" -le "$start_index" ] \ + || [ "$sketchnum" -gt "$end_index" ]; then + continue + fi + echo "" + echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname" + build_sketch "$ide_path" "$usr_path" "$fqbn" "$sketch" "$xtra_opts" + local result=$? + if [ $result -ne 0 ]; then + return $result + fi + done + return 0 +} + +USAGE=" +USAGE: ${0} [command] [options] +Available commands: + count: Count sketches. + build: Build a sketch. + chunk_build: Build a chunk of sketches. +" + +cmd=$1 +shift +if [ -z $cmd ]; then + echo "ERROR: No command supplied" + echo "$USAGE" + exit 2 +fi + +case "$cmd" in + "count") + count_sketches $* + ;; + "build") + build_sketch $* + ;; + "chunk_build") + build_sketches $* + ;; + *) + echo "ERROR: Unrecognized command" + echo "$USAGE" + exit 2 +esac + diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b5afd130dbd..773f2961f24 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -14,6 +14,13 @@ concurrency: jobs: + cmake-check: + name: Check cmake file + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: bash ./.github/scripts/check-cmakelists.sh + # Ubuntu build-arduino-linux: name: Arduino ${{ matrix.chunk }} on ubuntu-latest diff --git a/.github/workflows/upload-idf-component.yml b/.github/workflows/upload-idf-component.yml new file mode 100644 index 00000000000..d9e4032df08 --- /dev/null +++ b/.github/workflows/upload-idf-component.yml @@ -0,0 +1,19 @@ +name: Push components to https://components.espressif.com +on: + push: + tags: + - v* +jobs: + upload_components: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: "recursive" + + - name: Upload components to the component registry + uses: espressif/github-actions/upload_components@master + with: + name: arduino-esp32 + namespace: espressif + api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} diff --git a/CMakeLists.txt b/CMakeLists.txt index ae3f956bee7..7923bd4605c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,13 +86,9 @@ set(LIBRARY_SRCS libraries/HTTPClient/src/HTTPClient.cpp libraries/HTTPUpdate/src/HTTPUpdate.cpp libraries/LittleFS/src/LittleFS.cpp + libraries/I2S/src/I2S.cpp libraries/NetBIOS/src/NetBIOS.cpp libraries/Preferences/src/Preferences.cpp - 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/SD_MMC/src/SD_MMC.cpp libraries/SD/src/SD.cpp libraries/SD/src/sd_diskio.cpp @@ -162,7 +158,6 @@ set(BLE_SRCS libraries/BLE/src/GeneralUtils.cpp ) - set(includedirs variants/${IDF_TARGET}/ cores/esp32/ @@ -179,9 +174,9 @@ set(includedirs libraries/HTTPClient/src libraries/HTTPUpdate/src libraries/LittleFS/src + libraries/I2S/src libraries/NetBIOS/src libraries/Preferences/src - libraries/RainMaker/src libraries/SD_MMC/src libraries/SD/src libraries/SimpleBLE/src @@ -234,10 +229,8 @@ function(maybe_add_component component_name) endif() endfunction() -if(IDF_TARGET MATCHES "esp32" AND CONFIG_ESP_RMAKER_TASK_STACK) - maybe_add_component(esp_rainmaker) - maybe_add_component(qrcode) -endif() +maybe_add_component(esp-dsp) + if(IDF_TARGET MATCHES "esp32s2|esp32s3" AND CONFIG_TINYUSB_ENABLED) maybe_add_component(arduino_tinyusb) endif() diff --git a/boards.txt b/boards.txt index b39c070e8a8..db5eb8378b7 100755 --- a/boards.txt +++ b/boards.txt @@ -55,6 +55,7 @@ esp32s3.build.flash_mode=dio esp32s3.build.boot=qio esp32s3.build.partitions=default esp32s3.build.defines= +esp32s3.build.extra_libs="-L{compiler.sdk.path}/lib/spiram" esp32s3.build.loop_core= esp32s3.build.event_core= @@ -97,8 +98,13 @@ esp32s3.menu.UploadMode.cdc.upload.wait_for_upload_port=true esp32s3.menu.PSRAM.disabled=Disabled esp32s3.menu.PSRAM.disabled.build.defines= -esp32s3.menu.PSRAM.enabled=Enabled -esp32s3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +esp32s3.menu.PSRAM.disabled.build.extra_libs="-L{compiler.sdk.path}/lib/spiram" +esp32s3.menu.PSRAM.qspi=QSPI +esp32s3.menu.PSRAM.qspi.build.defines=-DBOARD_HAS_PSRAM +esp32s3.menu.PSRAM.qspi.build.extra_libs="-L{compiler.sdk.path}/lib/spiram" +esp32s3.menu.PSRAM.opi=OPI +esp32s3.menu.PSRAM.opi.build.defines=-DBOARD_HAS_PSRAM -DCONFIG_SPIRAM_BOOT_INIT -DCONFIG_SPIRAM_MODE_OCT=1 +esp32s3.menu.PSRAM.opi.build.extra_libs="-L{compiler.sdk.path}/lib/opiram" esp32s3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) esp32s3.menu.PartitionScheme.default.build.partitions=default @@ -844,6 +850,111 @@ pico32.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## +esp32s3box.name=ESP32-S3-Box +esp32s3box.vid.0=0x303a +esp32s3box.pid.0=0x1001 + +esp32s3box.upload.tool=esptool_py +esp32s3box.upload.maximum_size=1310720 +esp32s3box.upload.maximum_data_size=327680 +esp32s3box.upload.speed=921600 +esp32s3box.upload.flags= +esp32s3box.upload.extra_flags= +esp32s3box.upload.use_1200bps_touch=false +esp32s3box.upload.wait_for_upload_port=false + +esp32s3box.serial.disableDTR=false +esp32s3box.serial.disableRTS=false + +esp32s3box.build.tarch=xtensa +esp32s3box.build.bootloader_addr=0x0 +esp32s3box.build.target=esp32s3 +esp32s3box.build.mcu=esp32s3 +esp32s3box.build.core=esp32 +esp32s3box.build.variant=esp32s3box +esp32s3box.build.board=ESP32_S3_BOX + +esp32s3box.build.usb_mode=1 +esp32s3box.build.cdc_on_boot=1 +esp32s3box.build.msc_on_boot=0 +esp32s3box.build.dfu_on_boot=0 +esp32s3box.build.f_cpu=240000000L +esp32s3box.build.flash_size=16MB +esp32s3box.build.flash_freq=80m +esp32s3box.build.flash_mode=dio +esp32s3box.build.boot=qio +esp32s3box.build.partitions=default +esp32s3box.build.extra_libs="-L{compiler.sdk.path}/lib/opiram" +esp32s3box.build.defines=-DBOARD_HAS_PSRAM -DCONFIG_SPIRAM_BOOT_INIT -DCONFIG_SPIRAM_MODE_OCT=1 +esp32s3box.build.loop_core=-DARDUINO_RUNNING_CORE=1 +esp32s3box.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 + +esp32s3box.menu.USBMode.hwcdc=Hardware CDC and JTAG +esp32s3box.menu.USBMode.hwcdc.build.usb_mode=1 +esp32s3box.menu.USBMode.hwcdc.upload.use_1200bps_touch=false +esp32s3box.menu.USBMode.hwcdc.upload.wait_for_upload_port=false +esp32s3box.menu.USBMode.default=USB-OTG +esp32s3box.menu.USBMode.default.build.usb_mode=0 +esp32s3box.menu.USBMode.default.upload.use_1200bps_touch=true +esp32s3box.menu.USBMode.default.upload.wait_for_upload_port=true + +esp32s3box.menu.MSCOnBoot.default=Disabled +esp32s3box.menu.MSCOnBoot.default.build.msc_on_boot=0 +esp32s3box.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +esp32s3box.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +esp32s3box.menu.DFUOnBoot.default=Disabled +esp32s3box.menu.DFUOnBoot.default.build.dfu_on_boot=0 +esp32s3box.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +esp32s3box.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +esp32s3box.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +esp32s3box.menu.PartitionScheme.default.build.partitions=default +esp32s3box.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +esp32s3box.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +esp32s3box.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +esp32s3box.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +esp32s3box.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +esp32s3box.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +esp32s3box.menu.PartitionScheme.no_ota.build.partitions=no_ota +esp32s3box.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +esp32s3box.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +esp32s3box.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +esp32s3box.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +esp32s3box.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +esp32s3box.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +esp32s3box.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +esp32s3box.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +esp32s3box.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +esp32s3box.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +esp32s3box.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +esp32s3box.menu.PartitionScheme.huge_app.build.partitions=huge_app +esp32s3box.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +esp32s3box.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +esp32s3box.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +esp32s3box.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +esp32s3box.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +esp32s3box.menu.PartitionScheme.fatflash.build.partitions=ffat +esp32s3box.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +esp32s3box.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +esp32s3box.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +esp32s3box.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 + +esp32s3box.menu.DebugLevel.none=None +esp32s3box.menu.DebugLevel.none.build.code_debug=0 +esp32s3box.menu.DebugLevel.error=Error +esp32s3box.menu.DebugLevel.error.build.code_debug=1 +esp32s3box.menu.DebugLevel.warn=Warn +esp32s3box.menu.DebugLevel.warn.build.code_debug=2 +esp32s3box.menu.DebugLevel.info=Info +esp32s3box.menu.DebugLevel.info.build.code_debug=3 +esp32s3box.menu.DebugLevel.debug=Debug +esp32s3box.menu.DebugLevel.debug.build.code_debug=4 +esp32s3box.menu.DebugLevel.verbose=Verbose +esp32s3box.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + esp32s2usb.name=ESP32S2 Native USB esp32s2usb.vid.0=0x303a esp32s2usb.pid.0=0x0003 @@ -1542,6 +1653,564 @@ tinys2.menu.DebugLevel.verbose.build.code_debug=5 ############################################################## +tinys3.name=UM TinyS3 +tinys3.vid.0=0x303a +tinys3.pid.0=0x80D0 + +tinys3.upload.tool=esptool_py +tinys3.upload.maximum_size=1310720 +tinys3.upload.maximum_data_size=327680 +tinys3.upload.flags= +tinys3.upload.extra_flags= +tinys3.upload.use_1200bps_touch=false +tinys3.upload.wait_for_upload_port=false + +tinys3.serial.disableDTR=false +tinys3.serial.disableRTS=false + +tinys3.build.tarch=xtensa +tinys3.build.bootloader_addr=0x0 +tinys3.build.target=esp32s3 +tinys3.build.mcu=esp32s3 +tinys3.build.core=esp32 +tinys3.build.variant=um_tinys3 +tinys3.build.board=TINYS3 + +tinys3.build.usb_mode=1 +tinys3.build.cdc_on_boot=0 +tinys3.build.msc_on_boot=0 +tinys3.build.dfu_on_boot=0 +tinys3.build.f_cpu=240000000L +tinys3.build.flash_size=4MB +tinys3.build.flash_freq=80m +tinys3.build.flash_mode=dio +tinys3.build.boot=qio +tinys3.build.partitions=default +tinys3.build.defines= +tinys3.build.loop_core= +tinys3.build.event_core= + +tinys3.menu.LoopCore.1=Core 1 +tinys3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +tinys3.menu.LoopCore.0=Core 0 +tinys3.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +tinys3.menu.EventsCore.1=Core 1 +tinys3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +tinys3.menu.EventsCore.0=Core 0 +tinys3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +tinys3.menu.USBMode.hwcdc=Hardware CDC and JTAG +tinys3.menu.USBMode.hwcdc.build.usb_mode=1 +tinys3.menu.USBMode.default=USB-OTG +tinys3.menu.USBMode.default.build.usb_mode=0 + + +tinys3.menu.CDCOnBoot.cdc=Enabled +tinys3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +tinys3.menu.CDCOnBoot.default=Disabled +tinys3.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +tinys3.menu.MSCOnBoot.default=Disabled +tinys3.menu.MSCOnBoot.default.build.msc_on_boot=0 +tinys3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +tinys3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +tinys3.menu.DFUOnBoot.default=Disabled +tinys3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +tinys3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +tinys3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +tinys3.menu.UploadMode.cdc=Internal USB +tinys3.menu.UploadMode.cdc.upload.use_1200bps_touch=true +tinys3.menu.UploadMode.cdc.upload.wait_for_upload_port=true +tinys3.menu.UploadMode.default=UART0 +tinys3.menu.UploadMode.default.upload.use_1200bps_touch=false +tinys3.menu.UploadMode.default.upload.wait_for_upload_port=false + +tinys3.menu.PSRAM.enabled=Enabled +tinys3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +tinys3.menu.PSRAM.disabled=Disabled +tinys3.menu.PSRAM.disabled.build.defines= + +tinys3.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +tinys3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +tinys3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +tinys3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +tinys3.menu.PartitionScheme.default.build.partitions=default +tinys3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +tinys3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +tinys3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +tinys3.menu.PartitionScheme.minimal.build.partitions=minimal +tinys3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +tinys3.menu.PartitionScheme.no_ota.build.partitions=no_ota +tinys3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +tinys3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +tinys3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +tinys3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +tinys3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +tinys3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +tinys3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +tinys3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +tinys3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +tinys3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +tinys3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +tinys3.menu.PartitionScheme.huge_app.build.partitions=huge_app +tinys3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +tinys3.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +tinys3.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +tinys3.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +tinys3.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +tinys3.menu.PartitionScheme.fatflash.build.partitions=ffat +tinys3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +tinys3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +tinys3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +tinys3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 + +tinys3.menu.CPUFreq.240=240MHz (WiFi) +tinys3.menu.CPUFreq.240.build.f_cpu=240000000L +tinys3.menu.CPUFreq.160=160MHz (WiFi) +tinys3.menu.CPUFreq.160.build.f_cpu=160000000L +tinys3.menu.CPUFreq.80=80MHz (WiFi) +tinys3.menu.CPUFreq.80.build.f_cpu=80000000L +tinys3.menu.CPUFreq.40=40MHz +tinys3.menu.CPUFreq.40.build.f_cpu=40000000L +tinys3.menu.CPUFreq.20=20MHz +tinys3.menu.CPUFreq.20.build.f_cpu=20000000L +tinys3.menu.CPUFreq.10=10MHz +tinys3.menu.CPUFreq.10.build.f_cpu=10000000L + +tinys3.menu.FlashMode.qio=QIO +tinys3.menu.FlashMode.qio.build.flash_mode=dio +tinys3.menu.FlashMode.qio.build.boot=qio +tinys3.menu.FlashMode.dio=DIO +tinys3.menu.FlashMode.dio.build.flash_mode=dio +tinys3.menu.FlashMode.dio.build.boot=dio +tinys3.menu.FlashMode.qout=QOUT +tinys3.menu.FlashMode.qout.build.flash_mode=dout +tinys3.menu.FlashMode.qout.build.boot=qout +tinys3.menu.FlashMode.dout=DOUT +tinys3.menu.FlashMode.dout.build.flash_mode=dout +tinys3.menu.FlashMode.dout.build.boot=dout + +tinys3.menu.FlashFreq.80=80MHz +tinys3.menu.FlashFreq.80.build.flash_freq=80m +tinys3.menu.FlashFreq.40=40MHz +tinys3.menu.FlashFreq.40.build.flash_freq=40m + +tinys3.menu.FlashSize.8M=8MB (64Mb) +tinys3.menu.FlashSize.8M.build.flash_size=8MB +tinys3.menu.FlashSize.8M.build.partitions=default_8MB +tinys3.menu.FlashSize.4M=4MB (32Mb) +tinys3.menu.FlashSize.4M.build.flash_size=4MB +tinys3.menu.FlashSize.2M=2MB (16Mb) +tinys3.menu.FlashSize.2M.build.flash_size=2MB +tinys3.menu.FlashSize.2M.build.partitions=minimal +tinys3.menu.FlashSize.16M=16MB (128Mb) +tinys3.menu.FlashSize.16M.build.flash_size=16MB + +tinys3.menu.UploadSpeed.921600=921600 +tinys3.menu.UploadSpeed.921600.upload.speed=921600 +tinys3.menu.UploadSpeed.115200=115200 +tinys3.menu.UploadSpeed.115200.upload.speed=115200 +tinys3.menu.UploadSpeed.256000.windows=256000 +tinys3.menu.UploadSpeed.256000.upload.speed=256000 +tinys3.menu.UploadSpeed.230400.windows.upload.speed=256000 +tinys3.menu.UploadSpeed.230400=230400 +tinys3.menu.UploadSpeed.230400.upload.speed=230400 +tinys3.menu.UploadSpeed.460800.linux=460800 +tinys3.menu.UploadSpeed.460800.macosx=460800 +tinys3.menu.UploadSpeed.460800.upload.speed=460800 +tinys3.menu.UploadSpeed.512000.windows=512000 +tinys3.menu.UploadSpeed.512000.upload.speed=512000 + +tinys3.menu.DebugLevel.none=None +tinys3.menu.DebugLevel.none.build.code_debug=0 +tinys3.menu.DebugLevel.error=Error +tinys3.menu.DebugLevel.error.build.code_debug=1 +tinys3.menu.DebugLevel.warn=Warn +tinys3.menu.DebugLevel.warn.build.code_debug=2 +tinys3.menu.DebugLevel.info=Info +tinys3.menu.DebugLevel.info.build.code_debug=3 +tinys3.menu.DebugLevel.debug=Debug +tinys3.menu.DebugLevel.debug.build.code_debug=4 +tinys3.menu.DebugLevel.verbose=Verbose +tinys3.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +pros3.name=UM PROS3 +pros3.vid.0=0x303a +pros3.pid.0=0x80D3 + +pros3.upload.tool=esptool_py +pros3.upload.maximum_size=1310720 +pros3.upload.maximum_data_size=327680 +pros3.upload.flags= +pros3.upload.extra_flags= +pros3.upload.use_1200bps_touch=false +pros3.upload.wait_for_upload_port=false + +pros3.serial.disableDTR=false +pros3.serial.disableRTS=false + +pros3.build.tarch=xtensa +pros3.build.bootloader_addr=0x0 +pros3.build.target=esp32s3 +pros3.build.mcu=esp32s3 +pros3.build.core=esp32 +pros3.build.variant=um_pros3 +pros3.build.board=PROS3 + +pros3.build.usb_mode=1 +pros3.build.cdc_on_boot=0 +pros3.build.msc_on_boot=0 +pros3.build.dfu_on_boot=0 +pros3.build.f_cpu=240000000L +pros3.build.flash_size=4MB +pros3.build.flash_freq=80m +pros3.build.flash_mode=dio +pros3.build.boot=qio +pros3.build.partitions=default +pros3.build.defines= +pros3.build.loop_core= +pros3.build.event_core= + +pros3.menu.LoopCore.1=Core 1 +pros3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +pros3.menu.LoopCore.0=Core 0 +pros3.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +pros3.menu.EventsCore.1=Core 1 +pros3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +pros3.menu.EventsCore.0=Core 0 +pros3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +pros3.menu.USBMode.hwcdc=Hardware CDC and JTAG +pros3.menu.USBMode.hwcdc.build.usb_mode=1 +pros3.menu.USBMode.default=USB-OTG +pros3.menu.USBMode.default.build.usb_mode=0 + + +pros3.menu.CDCOnBoot.cdc=Enabled +pros3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +pros3.menu.CDCOnBoot.default=Disabled +pros3.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +pros3.menu.MSCOnBoot.default=Disabled +pros3.menu.MSCOnBoot.default.build.msc_on_boot=0 +pros3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +pros3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +pros3.menu.DFUOnBoot.default=Disabled +pros3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +pros3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +pros3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +pros3.menu.UploadMode.cdc=Internal USB +pros3.menu.UploadMode.cdc.upload.use_1200bps_touch=true +pros3.menu.UploadMode.cdc.upload.wait_for_upload_port=true +pros3.menu.UploadMode.default=UART0 +pros3.menu.UploadMode.default.upload.use_1200bps_touch=false +pros3.menu.UploadMode.default.upload.wait_for_upload_port=false + +pros3.menu.PSRAM.enabled=Enabled +pros3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +pros3.menu.PSRAM.disabled=Disabled +pros3.menu.PSRAM.disabled.build.defines= + +pros3.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +pros3.menu.PartitionScheme.fatflash.build.partitions=ffat +pros3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +pros3.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +pros3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +pros3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +pros3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +pros3.menu.PartitionScheme.default.build.partitions=default +pros3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +pros3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +pros3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +pros3.menu.PartitionScheme.minimal.build.partitions=minimal +pros3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +pros3.menu.PartitionScheme.no_ota.build.partitions=no_ota +pros3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +pros3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +pros3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +pros3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +pros3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +pros3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +pros3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +pros3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +pros3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +pros3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +pros3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +pros3.menu.PartitionScheme.huge_app.build.partitions=huge_app +pros3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +pros3.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +pros3.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +pros3.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +pros3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +pros3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +pros3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 + +pros3.menu.CPUFreq.240=240MHz (WiFi) +pros3.menu.CPUFreq.240.build.f_cpu=240000000L +pros3.menu.CPUFreq.160=160MHz (WiFi) +pros3.menu.CPUFreq.160.build.f_cpu=160000000L +pros3.menu.CPUFreq.80=80MHz (WiFi) +pros3.menu.CPUFreq.80.build.f_cpu=80000000L +pros3.menu.CPUFreq.40=40MHz +pros3.menu.CPUFreq.40.build.f_cpu=40000000L +pros3.menu.CPUFreq.20=20MHz +pros3.menu.CPUFreq.20.build.f_cpu=20000000L +pros3.menu.CPUFreq.10=10MHz +pros3.menu.CPUFreq.10.build.f_cpu=10000000L + +pros3.menu.FlashMode.qio=QIO +pros3.menu.FlashMode.qio.build.flash_mode=dio +pros3.menu.FlashMode.qio.build.boot=qio +pros3.menu.FlashMode.dio=DIO +pros3.menu.FlashMode.dio.build.flash_mode=dio +pros3.menu.FlashMode.dio.build.boot=dio +pros3.menu.FlashMode.qout=QOUT +pros3.menu.FlashMode.qout.build.flash_mode=dout +pros3.menu.FlashMode.qout.build.boot=qout +pros3.menu.FlashMode.dout=DOUT +pros3.menu.FlashMode.dout.build.flash_mode=dout +pros3.menu.FlashMode.dout.build.boot=dout + +pros3.menu.FlashFreq.80=80MHz +pros3.menu.FlashFreq.80.build.flash_freq=80m +pros3.menu.FlashFreq.40=40MHz +pros3.menu.FlashFreq.40.build.flash_freq=40m + +pros3.menu.FlashSize.16M=16MB (128Mb) +pros3.menu.FlashSize.16M.build.flash_size=16MB +pros3.menu.FlashSize.8M=8MB (64Mb) +pros3.menu.FlashSize.8M.build.flash_size=8MB +pros3.menu.FlashSize.8M.build.partitions=default_8MB +pros3.menu.FlashSize.4M=4MB (32Mb) +pros3.menu.FlashSize.4M.build.flash_size=4MB +pros3.menu.FlashSize.2M=2MB (16Mb) +pros3.menu.FlashSize.2M.build.flash_size=2MB +pros3.menu.FlashSize.2M.build.partitions=minimal + +pros3.menu.UploadSpeed.921600=921600 +pros3.menu.UploadSpeed.921600.upload.speed=921600 +pros3.menu.UploadSpeed.115200=115200 +pros3.menu.UploadSpeed.115200.upload.speed=115200 +pros3.menu.UploadSpeed.256000.windows=256000 +pros3.menu.UploadSpeed.256000.upload.speed=256000 +pros3.menu.UploadSpeed.230400.windows.upload.speed=256000 +pros3.menu.UploadSpeed.230400=230400 +pros3.menu.UploadSpeed.230400.upload.speed=230400 +pros3.menu.UploadSpeed.460800.linux=460800 +pros3.menu.UploadSpeed.460800.macosx=460800 +pros3.menu.UploadSpeed.460800.upload.speed=460800 +pros3.menu.UploadSpeed.512000.windows=512000 +pros3.menu.UploadSpeed.512000.upload.speed=512000 + +pros3.menu.DebugLevel.none=None +pros3.menu.DebugLevel.none.build.code_debug=0 +pros3.menu.DebugLevel.error=Error +pros3.menu.DebugLevel.error.build.code_debug=1 +pros3.menu.DebugLevel.warn=Warn +pros3.menu.DebugLevel.warn.build.code_debug=2 +pros3.menu.DebugLevel.info=Info +pros3.menu.DebugLevel.info.build.code_debug=3 +pros3.menu.DebugLevel.debug=Debug +pros3.menu.DebugLevel.debug.build.code_debug=4 +pros3.menu.DebugLevel.verbose=Verbose +pros3.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + +feathers3.name=UM FeatherS3 +feathers3.vid.0=0x303a +feathers3.pid.0=0x80D6 + +feathers3.upload.tool=esptool_py +feathers3.upload.maximum_size=1310720 +feathers3.upload.maximum_data_size=327680 +feathers3.upload.flags= +feathers3.upload.extra_flags= +feathers3.upload.use_1200bps_touch=false +feathers3.upload.wait_for_upload_port=false + +feathers3.serial.disableDTR=false +feathers3.serial.disableRTS=false + +feathers3.build.tarch=xtensa +feathers3.build.bootloader_addr=0x0 +feathers3.build.target=esp32s3 +feathers3.build.mcu=esp32s3 +feathers3.build.core=esp32 +feathers3.build.variant=um_feathers3 +feathers3.build.board=FEATHERS3 + +feathers3.build.usb_mode=1 +feathers3.build.cdc_on_boot=0 +feathers3.build.msc_on_boot=0 +feathers3.build.dfu_on_boot=0 +feathers3.build.f_cpu=240000000L +feathers3.build.flash_size=4MB +feathers3.build.flash_freq=80m +feathers3.build.flash_mode=dio +feathers3.build.boot=qio +feathers3.build.partitions=default +feathers3.build.defines= +feathers3.build.loop_core= +feathers3.build.event_core= + +feathers3.menu.LoopCore.1=Core 1 +feathers3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +feathers3.menu.LoopCore.0=Core 0 +feathers3.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +feathers3.menu.EventsCore.1=Core 1 +feathers3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +feathers3.menu.EventsCore.0=Core 0 +feathers3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +feathers3.menu.USBMode.hwcdc=Hardware CDC and JTAG +feathers3.menu.USBMode.hwcdc.build.usb_mode=1 +feathers3.menu.USBMode.default=USB-OTG +feathers3.menu.USBMode.default.build.usb_mode=0 + + +feathers3.menu.CDCOnBoot.cdc=Enabled +feathers3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +feathers3.menu.CDCOnBoot.default=Disabled +feathers3.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +feathers3.menu.MSCOnBoot.default=Disabled +feathers3.menu.MSCOnBoot.default.build.msc_on_boot=0 +feathers3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +feathers3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +feathers3.menu.DFUOnBoot.default=Disabled +feathers3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +feathers3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +feathers3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +feathers3.menu.UploadMode.cdc=Internal USB +feathers3.menu.UploadMode.cdc.upload.use_1200bps_touch=true +feathers3.menu.UploadMode.cdc.upload.wait_for_upload_port=true +feathers3.menu.UploadMode.default=UART0 +feathers3.menu.UploadMode.default.upload.use_1200bps_touch=false +feathers3.menu.UploadMode.default.upload.wait_for_upload_port=false + +feathers3.menu.PSRAM.enabled=Enabled +feathers3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +feathers3.menu.PSRAM.disabled=Disabled +feathers3.menu.PSRAM.disabled.build.defines= + +feathers3.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FAT) +feathers3.menu.PartitionScheme.fatflash.build.partitions=ffat +feathers3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +feathers3.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT) +feathers3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +feathers3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +feathers3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +feathers3.menu.PartitionScheme.default.build.partitions=default +feathers3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +feathers3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +feathers3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +feathers3.menu.PartitionScheme.minimal.build.partitions=minimal +feathers3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +feathers3.menu.PartitionScheme.no_ota.build.partitions=no_ota +feathers3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +feathers3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +feathers3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +feathers3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +feathers3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +feathers3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +feathers3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +feathers3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +feathers3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +feathers3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +feathers3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +feathers3.menu.PartitionScheme.huge_app.build.partitions=huge_app +feathers3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +feathers3.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +feathers3.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +feathers3.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +feathers3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS) +feathers3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +feathers3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 + +feathers3.menu.CPUFreq.240=240MHz (WiFi) +feathers3.menu.CPUFreq.240.build.f_cpu=240000000L +feathers3.menu.CPUFreq.160=160MHz (WiFi) +feathers3.menu.CPUFreq.160.build.f_cpu=160000000L +feathers3.menu.CPUFreq.80=80MHz (WiFi) +feathers3.menu.CPUFreq.80.build.f_cpu=80000000L +feathers3.menu.CPUFreq.40=40MHz +feathers3.menu.CPUFreq.40.build.f_cpu=40000000L +feathers3.menu.CPUFreq.20=20MHz +feathers3.menu.CPUFreq.20.build.f_cpu=20000000L +feathers3.menu.CPUFreq.10=10MHz +feathers3.menu.CPUFreq.10.build.f_cpu=10000000L + +feathers3.menu.FlashMode.qio=QIO +feathers3.menu.FlashMode.qio.build.flash_mode=dio +feathers3.menu.FlashMode.qio.build.boot=qio +feathers3.menu.FlashMode.dio=DIO +feathers3.menu.FlashMode.dio.build.flash_mode=dio +feathers3.menu.FlashMode.dio.build.boot=dio +feathers3.menu.FlashMode.qout=QOUT +feathers3.menu.FlashMode.qout.build.flash_mode=dout +feathers3.menu.FlashMode.qout.build.boot=qout +feathers3.menu.FlashMode.dout=DOUT +feathers3.menu.FlashMode.dout.build.flash_mode=dout +feathers3.menu.FlashMode.dout.build.boot=dout + +feathers3.menu.FlashFreq.80=80MHz +feathers3.menu.FlashFreq.80.build.flash_freq=80m +feathers3.menu.FlashFreq.40=40MHz +feathers3.menu.FlashFreq.40.build.flash_freq=40m + +feathers3.menu.FlashSize.16M=16MB (128Mb) +feathers3.menu.FlashSize.16M.build.flash_size=16MB +feathers3.menu.FlashSize.8M=8MB (64Mb) +feathers3.menu.FlashSize.8M.build.flash_size=8MB +feathers3.menu.FlashSize.8M.build.partitions=default_8MB +feathers3.menu.FlashSize.4M=4MB (32Mb) +feathers3.menu.FlashSize.4M.build.flash_size=4MB +feathers3.menu.FlashSize.2M=2MB (16Mb) +feathers3.menu.FlashSize.2M.build.flash_size=2MB +feathers3.menu.FlashSize.2M.build.partitions=minimal + +feathers3.menu.UploadSpeed.921600=921600 +feathers3.menu.UploadSpeed.921600.upload.speed=921600 +feathers3.menu.UploadSpeed.115200=115200 +feathers3.menu.UploadSpeed.115200.upload.speed=115200 +feathers3.menu.UploadSpeed.256000.windows=256000 +feathers3.menu.UploadSpeed.256000.upload.speed=256000 +feathers3.menu.UploadSpeed.230400.windows.upload.speed=256000 +feathers3.menu.UploadSpeed.230400=230400 +feathers3.menu.UploadSpeed.230400.upload.speed=230400 +feathers3.menu.UploadSpeed.460800.linux=460800 +feathers3.menu.UploadSpeed.460800.macosx=460800 +feathers3.menu.UploadSpeed.460800.upload.speed=460800 +feathers3.menu.UploadSpeed.512000.windows=512000 +feathers3.menu.UploadSpeed.512000.upload.speed=512000 + +feathers3.menu.DebugLevel.none=None +feathers3.menu.DebugLevel.none.build.code_debug=0 +feathers3.menu.DebugLevel.error=Error +feathers3.menu.DebugLevel.error.build.code_debug=1 +feathers3.menu.DebugLevel.warn=Warn +feathers3.menu.DebugLevel.warn.build.code_debug=2 +feathers3.menu.DebugLevel.info=Info +feathers3.menu.DebugLevel.info.build.code_debug=3 +feathers3.menu.DebugLevel.debug=Debug +feathers3.menu.DebugLevel.debug.build.code_debug=4 +feathers3.menu.DebugLevel.verbose=Verbose +feathers3.menu.DebugLevel.verbose.build.code_debug=5 + +############################################################## + S_ODI_Ultra.name=S.ODI Ultra v1 S_ODI_Ultra.upload.tool=esptool_py @@ -5274,6 +5943,284 @@ adafruit_qtpy_esp32s2.menu.DebugLevel.debug.build.code_debug=4 adafruit_qtpy_esp32s2.menu.DebugLevel.verbose=Verbose adafruit_qtpy_esp32s2.menu.DebugLevel.verbose.build.code_debug=5 +############################################################## + +adafruit_qtpy_esp32c3.name=Adafruit QT Py ESP32-C3 +adafruit_qtpy_esp32c3.vid.0=0x303a +adafruit_qtpy_esp32c3.pid.0=0x1001 + +adafruit_qtpy_esp32c3.upload.tool=esptool_py +adafruit_qtpy_esp32c3.upload.maximum_size=1310720 +adafruit_qtpy_esp32c3.upload.maximum_data_size=327680 +adafruit_qtpy_esp32c3.upload.flags= +adafruit_qtpy_esp32c3.upload.extra_flags= +adafruit_qtpy_esp32c3.upload.use_1200bps_touch=false +adafruit_qtpy_esp32c3.upload.wait_for_upload_port=false + +adafruit_qtpy_esp32c3.serial.disableDTR=false +adafruit_qtpy_esp32c3.serial.disableRTS=false + +adafruit_qtpy_esp32c3.build.tarch=riscv32 +adafruit_qtpy_esp32c3.build.target=esp +adafruit_qtpy_esp32c3.build.mcu=esp32c3 +adafruit_qtpy_esp32c3.build.core=esp32 +adafruit_qtpy_esp32c3.build.variant=adafruit_qtpy_esp32c3 +adafruit_qtpy_esp32c3.build.board=ADAFRUIT_QTPY_ESP32C3 +adafruit_qtpy_esp32c3.build.bootloader_addr=0x0 + +adafruit_qtpy_esp32c3.build.cdc_on_boot=0 +adafruit_qtpy_esp32c3.build.f_cpu=160000000L +adafruit_qtpy_esp32c3.build.flash_size=4MB +adafruit_qtpy_esp32c3.build.flash_freq=80m +adafruit_qtpy_esp32c3.build.flash_mode=dout +adafruit_qtpy_esp32c3.build.boot=dout +adafruit_qtpy_esp32c3.build.partitions=default +adafruit_qtpy_esp32c3.build.defines= + +adafruit_qtpy_esp32c3.menu.CDCOnBoot.cdc=Enabled +adafruit_qtpy_esp32c3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +adafruit_qtpy_esp32c3.menu.CDCOnBoot.default=Disabled +adafruit_qtpy_esp32c3.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +adafruit_qtpy_esp32c3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.default.build.partitions=default +adafruit_qtpy_esp32c3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +adafruit_qtpy_esp32c3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.minimal.build.partitions=minimal +adafruit_qtpy_esp32c3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.no_ota.build.partitions=no_ota +adafruit_qtpy_esp32c3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +adafruit_qtpy_esp32c3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +adafruit_qtpy_esp32c3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.huge_app.build.partitions=huge_app +adafruit_qtpy_esp32c3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +adafruit_qtpy_esp32c3.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +adafruit_qtpy_esp32c3.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +adafruit_qtpy_esp32c3.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 + +adafruit_qtpy_esp32c3.menu.CPUFreq.160=160MHz (WiFi) +adafruit_qtpy_esp32c3.menu.CPUFreq.160.build.f_cpu=160000000L +adafruit_qtpy_esp32c3.menu.CPUFreq.80=80MHz (WiFi) +adafruit_qtpy_esp32c3.menu.CPUFreq.80.build.f_cpu=80000000L +adafruit_qtpy_esp32c3.menu.CPUFreq.40=40MHz +adafruit_qtpy_esp32c3.menu.CPUFreq.40.build.f_cpu=40000000L +adafruit_qtpy_esp32c3.menu.CPUFreq.20=20MHz +adafruit_qtpy_esp32c3.menu.CPUFreq.20.build.f_cpu=20000000L +adafruit_qtpy_esp32c3.menu.CPUFreq.10=10MHz +adafruit_qtpy_esp32c3.menu.CPUFreq.10.build.f_cpu=10000000L + +adafruit_qtpy_esp32c3.menu.FlashMode.dout=DOUT +adafruit_qtpy_esp32c3.menu.FlashMode.dout.build.flash_mode=dout +adafruit_qtpy_esp32c3.menu.FlashMode.dout.build.boot=dout +adafruit_qtpy_esp32c3.menu.FlashMode.qio=QIO +adafruit_qtpy_esp32c3.menu.FlashMode.qio.build.flash_mode=dio +adafruit_qtpy_esp32c3.menu.FlashMode.qio.build.boot=qio +adafruit_qtpy_esp32c3.menu.FlashMode.dio=DIO +adafruit_qtpy_esp32c3.menu.FlashMode.dio.build.flash_mode=dio +adafruit_qtpy_esp32c3.menu.FlashMode.dio.build.boot=dio +adafruit_qtpy_esp32c3.menu.FlashMode.qout=QOUT +adafruit_qtpy_esp32c3.menu.FlashMode.qout.build.flash_mode=dout +adafruit_qtpy_esp32c3.menu.FlashMode.qout.build.boot=qout + +adafruit_qtpy_esp32c3.menu.FlashFreq.80=80MHz +adafruit_qtpy_esp32c3.menu.FlashFreq.80.build.flash_freq=80m +adafruit_qtpy_esp32c3.menu.FlashFreq.40=40MHz +adafruit_qtpy_esp32c3.menu.FlashFreq.40.build.flash_freq=40m + +adafruit_qtpy_esp32c3.menu.FlashSize.4M=4MB (32Mb) +adafruit_qtpy_esp32c3.menu.FlashSize.4M.build.flash_size=4MB +adafruit_qtpy_esp32c3.menu.FlashSize.2M=2MB (16Mb) +adafruit_qtpy_esp32c3.menu.FlashSize.2M.build.flash_size=2MB +adafruit_qtpy_esp32c3.menu.FlashSize.2M.build.partitions=minimal + +adafruit_qtpy_esp32c3.menu.UploadSpeed.115200=115200 +adafruit_qtpy_esp32c3.menu.UploadSpeed.115200.upload.speed=115200 +adafruit_qtpy_esp32c3.menu.UploadSpeed.921600=921600 +adafruit_qtpy_esp32c3.menu.UploadSpeed.921600.upload.speed=921600 +adafruit_qtpy_esp32c3.menu.UploadSpeed.921600=921600 +adafruit_qtpy_esp32c3.menu.UploadSpeed.921600.upload.speed=921600 +adafruit_qtpy_esp32c3.menu.UploadSpeed.115200=115200 +adafruit_qtpy_esp32c3.menu.UploadSpeed.115200.upload.speed=115200 +adafruit_qtpy_esp32c3.menu.UploadSpeed.256000.windows=256000 +adafruit_qtpy_esp32c3.menu.UploadSpeed.256000.upload.speed=256000 +adafruit_qtpy_esp32c3.menu.UploadSpeed.230400.windows.upload.speed=256000 +adafruit_qtpy_esp32c3.menu.UploadSpeed.230400=230400 +adafruit_qtpy_esp32c3.menu.UploadSpeed.230400.upload.speed=230400 +adafruit_qtpy_esp32c3.menu.UploadSpeed.460800.linux=460800 +adafruit_qtpy_esp32c3.menu.UploadSpeed.460800.macosx=460800 +adafruit_qtpy_esp32c3.menu.UploadSpeed.460800.upload.speed=460800 +adafruit_qtpy_esp32c3.menu.UploadSpeed.512000.windows=512000 +adafruit_qtpy_esp32c3.menu.UploadSpeed.512000.upload.speed=512000 + +adafruit_qtpy_esp32c3.menu.DebugLevel.none=None +adafruit_qtpy_esp32c3.menu.DebugLevel.none.build.code_debug=0 +adafruit_qtpy_esp32c3.menu.DebugLevel.error=Error +adafruit_qtpy_esp32c3.menu.DebugLevel.error.build.code_debug=1 +adafruit_qtpy_esp32c3.menu.DebugLevel.warn=Warn +adafruit_qtpy_esp32c3.menu.DebugLevel.warn.build.code_debug=2 +adafruit_qtpy_esp32c3.menu.DebugLevel.info=Info +adafruit_qtpy_esp32c3.menu.DebugLevel.info.build.code_debug=3 +adafruit_qtpy_esp32c3.menu.DebugLevel.debug=Debug +adafruit_qtpy_esp32c3.menu.DebugLevel.debug.build.code_debug=4 +adafruit_qtpy_esp32c3.menu.DebugLevel.verbose=Verbose +adafruit_qtpy_esp32c3.menu.DebugLevel.verbose.build.code_debug=5 + + +adafruit_qtpy_esp32_pico.name=Adafruit QT Py ESP32 Pico + +adafruit_qtpy_esp32_pico.upload.tool=esptool_py +adafruit_qtpy_esp32_pico.upload.maximum_size=1310720 +adafruit_qtpy_esp32_pico.upload.maximum_data_size=327680 +adafruit_qtpy_esp32_pico.upload.flags= +adafruit_qtpy_esp32_pico.upload.extra_flags= + +adafruit_qtpy_esp32_pico.serial.disableDTR=true +adafruit_qtpy_esp32_pico.serial.disableRTS=true + +adafruit_qtpy_esp32_pico.build.tarch=xtensa +adafruit_qtpy_esp32_pico.build.bootloader_addr=0x1000 +adafruit_qtpy_esp32_pico.build.target=esp32 +adafruit_qtpy_esp32_pico.build.mcu=esp32 +adafruit_qtpy_esp32_pico.build.core=esp32 +adafruit_qtpy_esp32_pico.build.variant=adafruit_qtpy_esp32 +adafruit_qtpy_esp32_pico.build.board=ADAFRUIT_QTPY_ESP32_PICO + +adafruit_qtpy_esp32_pico.build.f_cpu=240000000L +adafruit_qtpy_esp32_pico.build.flash_size=8MB +adafruit_qtpy_esp32_pico.build.flash_freq=80m +adafruit_qtpy_esp32_pico.build.flash_mode=dio +adafruit_qtpy_esp32_pico.build.boot=dio +adafruit_qtpy_esp32_pico.build.partitions=default +adafruit_qtpy_esp32_pico.build.defines= + +adafruit_qtpy_esp32_pico.menu.PartitionScheme.default=Default +adafruit_qtpy_esp32_pico.menu.PartitionScheme.default.build.partitions=default +adafruit_qtpy_esp32_pico.menu.PartitionScheme.no_ota=No OTA (Large APP) +adafruit_qtpy_esp32_pico.menu.PartitionScheme.no_ota.build.partitions=no_ota +adafruit_qtpy_esp32_pico.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +adafruit_qtpy_esp32_pico.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA) +adafruit_qtpy_esp32_pico.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +adafruit_qtpy_esp32_pico.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 + +adafruit_qtpy_esp32_pico.menu.UploadSpeed.921600=921600 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.921600.upload.speed=921600 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.115200=115200 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.115200.upload.speed=115200 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.256000.windows=256000 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.256000.upload.speed=256000 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.230400.windows.upload.speed=256000 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.230400=230400 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.230400.upload.speed=230400 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.460800.linux=460800 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.460800.macosx=460800 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.460800.upload.speed=460800 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.512000.windows=512000 +adafruit_qtpy_esp32_pico.menu.UploadSpeed.512000.upload.speed=512000 + +adafruit_qtpy_esp32_pico.menu.PSRAM.enabled=Enabled +adafruit_qtpy_esp32_pico.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-strategy=memw +adafruit_qtpy_esp32_pico.menu.PSRAM.enabled.build.extra_libs= +adafruit_qtpy_esp32_pico.menu.PSRAM.disabled=Disabled +adafruit_qtpy_esp32_pico.menu.PSRAM.disabled.build.defines= +adafruit_qtpy_esp32_pico.menu.PSRAM.disabled.build.extra_libs= + +adafruit_qtpy_esp32_pico.menu.DebugLevel.none=None +adafruit_qtpy_esp32_pico.menu.DebugLevel.none.build.code_debug=0 +adafruit_qtpy_esp32_pico.menu.DebugLevel.error=Error +adafruit_qtpy_esp32_pico.menu.DebugLevel.error.build.code_debug=1 +adafruit_qtpy_esp32_pico.menu.DebugLevel.warn=Warn +adafruit_qtpy_esp32_pico.menu.DebugLevel.warn.build.code_debug=2 +adafruit_qtpy_esp32_pico.menu.DebugLevel.info=Info +adafruit_qtpy_esp32_pico.menu.DebugLevel.info.build.code_debug=3 +adafruit_qtpy_esp32_pico.menu.DebugLevel.debug=Debug +adafruit_qtpy_esp32_pico.menu.DebugLevel.debug.build.code_debug=4 +adafruit_qtpy_esp32_pico.menu.DebugLevel.verbose=Verbose +adafruit_qtpy_esp32_pico.menu.DebugLevel.verbose.build.code_debug=5 + + + +adafruit_feather_esp32_v2.name=Adafruit Feather ESP32 V2 + +adafruit_feather_esp32_v2.upload.tool=esptool_py +adafruit_feather_esp32_v2.upload.maximum_size=1310720 +adafruit_feather_esp32_v2.upload.maximum_data_size=327680 +adafruit_feather_esp32_v2.upload.flags= +adafruit_feather_esp32_v2.upload.extra_flags= + +adafruit_feather_esp32_v2.serial.disableDTR=true +adafruit_feather_esp32_v2.serial.disableRTS=true + +adafruit_feather_esp32_v2.build.tarch=xtensa +adafruit_feather_esp32_v2.build.bootloader_addr=0x1000 +adafruit_feather_esp32_v2.build.target=esp32 +adafruit_feather_esp32_v2.build.mcu=esp32 +adafruit_feather_esp32_v2.build.core=esp32 +adafruit_feather_esp32_v2.build.variant=adafruit_feather_esp32_v2 +adafruit_feather_esp32_v2.build.board=ADAFRUIT_FEATHER_ESP32_V2 + +adafruit_feather_esp32_v2.build.f_cpu=240000000L +adafruit_feather_esp32_v2.build.flash_size=8MB +adafruit_feather_esp32_v2.build.flash_freq=80m +adafruit_feather_esp32_v2.build.flash_mode=dio +adafruit_feather_esp32_v2.build.boot=dio +adafruit_feather_esp32_v2.build.partitions=default +adafruit_feather_esp32_v2.build.defines= + +adafruit_feather_esp32_v2.menu.PartitionScheme.default=Default +adafruit_feather_esp32_v2.menu.PartitionScheme.default.build.partitions=default +adafruit_feather_esp32_v2.menu.PartitionScheme.no_ota=No OTA (Large APP) +adafruit_feather_esp32_v2.menu.PartitionScheme.no_ota.build.partitions=no_ota +adafruit_feather_esp32_v2.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +adafruit_feather_esp32_v2.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA) +adafruit_feather_esp32_v2.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +adafruit_feather_esp32_v2.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 + +adafruit_feather_esp32_v2.menu.UploadSpeed.921600=921600 +adafruit_feather_esp32_v2.menu.UploadSpeed.921600.upload.speed=921600 +adafruit_feather_esp32_v2.menu.UploadSpeed.115200=115200 +adafruit_feather_esp32_v2.menu.UploadSpeed.115200.upload.speed=115200 +adafruit_feather_esp32_v2.menu.UploadSpeed.256000.windows=256000 +adafruit_feather_esp32_v2.menu.UploadSpeed.256000.upload.speed=256000 +adafruit_feather_esp32_v2.menu.UploadSpeed.230400.windows.upload.speed=256000 +adafruit_feather_esp32_v2.menu.UploadSpeed.230400=230400 +adafruit_feather_esp32_v2.menu.UploadSpeed.230400.upload.speed=230400 +adafruit_feather_esp32_v2.menu.UploadSpeed.460800.linux=460800 +adafruit_feather_esp32_v2.menu.UploadSpeed.460800.macosx=460800 +adafruit_feather_esp32_v2.menu.UploadSpeed.460800.upload.speed=460800 +adafruit_feather_esp32_v2.menu.UploadSpeed.512000.windows=512000 +adafruit_feather_esp32_v2.menu.UploadSpeed.512000.upload.speed=512000 + +adafruit_feather_esp32_v2.menu.PSRAM.enabled=Enabled +adafruit_feather_esp32_v2.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-strategy=memw +adafruit_feather_esp32_v2.menu.PSRAM.enabled.build.extra_libs= +adafruit_feather_esp32_v2.menu.PSRAM.disabled=Disabled +adafruit_feather_esp32_v2.menu.PSRAM.disabled.build.defines= +adafruit_feather_esp32_v2.menu.PSRAM.disabled.build.extra_libs= + +adafruit_feather_esp32_v2.menu.DebugLevel.none=None +adafruit_feather_esp32_v2.menu.DebugLevel.none.build.code_debug=0 +adafruit_feather_esp32_v2.menu.DebugLevel.error=Error +adafruit_feather_esp32_v2.menu.DebugLevel.error.build.code_debug=1 +adafruit_feather_esp32_v2.menu.DebugLevel.warn=Warn +adafruit_feather_esp32_v2.menu.DebugLevel.warn.build.code_debug=2 +adafruit_feather_esp32_v2.menu.DebugLevel.info=Info +adafruit_feather_esp32_v2.menu.DebugLevel.info.build.code_debug=3 +adafruit_feather_esp32_v2.menu.DebugLevel.debug=Debug +adafruit_feather_esp32_v2.menu.DebugLevel.debug.build.code_debug=4 +adafruit_feather_esp32_v2.menu.DebugLevel.verbose=Verbose +adafruit_feather_esp32_v2.menu.DebugLevel.verbose.build.code_debug=5 + + + ############################################################## nodemcu-32s.name=NodeMCU-32S diff --git a/cores/esp32/Esp.cpp b/cores/esp32/Esp.cpp index 6978e7e4414..7dd9a929f4e 100644 --- a/cores/esp32/Esp.cpp +++ b/cores/esp32/Esp.cpp @@ -43,11 +43,11 @@ extern "C" { #elif CONFIG_IDF_TARGET_ESP32S3 #include "esp32s3/rom/spi_flash.h" #include "soc/efuse_reg.h" -#define ESP_FLASH_IMAGE_BASE 0x1000 +#define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32s3 is located at 0x0000 #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/spi_flash.h" #define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32c3 is located at 0x0000 -#else +#else #error Target CONFIG_IDF_TARGET is not supported #endif #else // ESP32 Before IDF 4.0 @@ -192,7 +192,7 @@ static uint32_t sketchSize(sketchSize_t response) { return data.image_len; } } - + uint32_t EspClass::getSketchSize () { return sketchSize(SKETCH_SIZE_TOTAL); } @@ -231,6 +231,10 @@ String EspClass::getSketchMD5() md5.add(buf.get(), readBytes); lengthLeft -= readBytes; offset += readBytes; + + #if CONFIG_FREERTOS_UNICORE + delay(1); // Fix solo WDT + #endif } md5.calculate(); result = md5.toString(); @@ -391,17 +395,17 @@ bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) return spi_flash_read(offset, (uint32_t*) data, size) == ESP_OK; } -bool EspClass::partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size) +bool EspClass::partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size) { return esp_partition_erase_range(partition, offset, size) == ESP_OK; } -bool EspClass::partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) +bool EspClass::partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) { return esp_partition_write(partition, offset, data, size) == ESP_OK; } -bool EspClass::partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) +bool EspClass::partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) { return esp_partition_read(partition, offset, data, size) == ESP_OK; } diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 96cc603fd44..08394059f93 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -35,20 +35,24 @@ void serialEvent(void) {} #ifndef RX1 #if CONFIG_IDF_TARGET_ESP32 #define RX1 9 -#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#elif CONFIG_IDF_TARGET_ESP32S2 #define RX1 18 #elif CONFIG_IDF_TARGET_ESP32C3 #define RX1 18 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define RX1 15 #endif #endif #ifndef TX1 #if CONFIG_IDF_TARGET_ESP32 #define TX1 10 -#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#elif CONFIG_IDF_TARGET_ESP32S2 #define TX1 17 #elif CONFIG_IDF_TARGET_ESP32C3 #define TX1 19 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define TX1 16 #endif #endif @@ -60,16 +64,16 @@ void serialEvent1(void) {} #ifndef RX2 #if CONFIG_IDF_TARGET_ESP32 #define RX2 16 -#else -#define RX2 -1 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define RX2 19 #endif #endif #ifndef TX2 #if CONFIG_IDF_TARGET_ESP32 #define TX2 17 -#else -#define TX2 -1 +#elif CONFIG_IDF_TARGET_ESP32S3 +#define TX2 20 #endif #endif diff --git a/cores/esp32/WMath.cpp b/cores/esp32/WMath.cpp index bb75fc8a2f6..931ac96637b 100644 --- a/cores/esp32/WMath.cpp +++ b/cores/esp32/WMath.cpp @@ -67,14 +67,14 @@ long random(long howsmall, long howbig) } long map(long x, long in_min, long in_max, long out_min, long out_max) { - const long dividend = out_max - out_min; - const long divisor = in_max - in_min; - const long delta = x - in_min; - if(divisor == 0){ - log_e("Invalid map input range, min == max"); - return -1; //AVR returns -1, SAM returns 0 + const long run = in_max - in_min; + if(run == 0){ + log_e("map(): Invalid input range, min == max"); + return -1; // AVR returns -1, SAM returns 0 } - return (delta * dividend + (divisor / 2)) / divisor + out_min; + const long rise = out_max - out_min; + const long delta = x - in_min; + return (delta * rise) / run + out_min; } uint16_t makeWord(uint16_t w) diff --git a/cores/esp32/WString.cpp b/cores/esp32/WString.cpp index ded2a3c1e78..f69302a253f 100644 --- a/cores/esp32/WString.cpp +++ b/cores/esp32/WString.cpp @@ -24,6 +24,7 @@ #include #include "WString.h" #include "stdlib_noniso.h" +#include "esp32-hal-log.h" /*********************************************/ /* Constructors */ @@ -773,8 +774,10 @@ void String::replace(const String& find, const String& replace) { } if(size == len()) return; - if(size > capacity() && !changeBuffer(size)) - return; // XXX: tell user! + if(size > capacity() && !changeBuffer(size)) { + log_w("String.Replace() Insufficient space to replace string"); + return; + } int index = len() - 1; while(index >= 0 && (index = lastIndexOf(find, index)) >= 0) { readFrom = wbuffer() + index + find.len(); diff --git a/cores/esp32/esp32-hal-cpu.c b/cores/esp32/esp32-hal-cpu.c index 8295efd7b19..d79803f6124 100644 --- a/cores/esp32/esp32-hal-cpu.c +++ b/cores/esp32/esp32-hal-cpu.c @@ -147,7 +147,7 @@ bool removeApbChangeCallback(void * arg, apb_change_cb_t cb){ } static uint32_t calculateApb(rtc_cpu_freq_config_t * conf){ -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 return APB_CLK_FREQ; #else if(conf->freq_mhz >= 80){ diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index 552126b848d..664fc168800 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -56,6 +56,8 @@ const int8_t esp32_adc2gpio[20] = {36, 37, 38, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26}; #elif CONFIG_IDF_TARGET_ESP32S2 const int8_t esp32_adc2gpio[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; +#elif CONFIG_IDF_TARGET_ESP32C3 +const int8_t esp32_adc2gpio[20] = {1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; #endif const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[SOC_GPIO_PIN_COUNT]={ diff --git a/cores/esp32/esp32-hal-ledc.c b/cores/esp32/esp32-hal-ledc.c index 997bb806b80..6274ed0708c 100644 --- a/cores/esp32/esp32-hal-ledc.c +++ b/cores/esp32/esp32-hal-ledc.c @@ -168,8 +168,6 @@ void ledcAttachPin(uint8_t pin, uint8_t chan) .hpoint = 0 }; ledc_channel_config(&ledc_channel); - - pinMode(pin,OUTPUT); } void ledcDetachPin(uint8_t pin) diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 5d5421eb7a2..d50885b32dd 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -235,7 +235,7 @@ void initArduino() #endif esp_log_level_set("*", CONFIG_LOG_DEFAULT_LEVEL); esp_err_t err = nvs_flash_init(); - if(err == ESP_ERR_NVS_NO_FREE_PAGES){ + if(err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND){ const esp_partition_t* partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL); if (partition != NULL) { err = esp_partition_erase_range(partition, 0, partition->size); @@ -244,6 +244,8 @@ void initArduino() } else { log_e("Failed to format the broken NVS partition!"); } + } else { + log_e("Could not find NVS partition"); } } if(err) { diff --git a/cores/esp32/esp32-hal-psram.c b/cores/esp32/esp32-hal-psram.c index 9d8ae13967c..88e7bc18681 100644 --- a/cores/esp32/esp32-hal-psram.c +++ b/cores/esp32/esp32-hal-psram.c @@ -87,12 +87,12 @@ bool psramInit(){ log_e("PSRAM could not be added to the heap!"); return false; } -#if CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL && !CONFIG_ARDUINO_ISR_IRAM - heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL); -#endif +#if CONFIG_SPIRAM_USE_MALLOC && !CONFIG_ARDUINO_ISR_IRAM + heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL); #endif +#endif /* CONFIG_SPIRAM_BOOT_INIT */ + log_i("PSRAM enabled"); spiramDetected = true; - log_d("PSRAM enabled"); return true; } diff --git a/cores/esp32/esp32-hal-spi.c b/cores/esp32/esp32-hal-spi.c index ca514200252..39ad027be55 100644 --- a/cores/esp32/esp32-hal-spi.c +++ b/cores/esp32/esp32-hal-spi.c @@ -55,8 +55,6 @@ #include "esp_intr.h" #endif -#ifndef CONFIG_IDF_TARGET_ESP32S3 - struct spi_struct_t { spi_dev_t * dev; #if !CONFIG_DISABLE_HAL_LOCKS @@ -78,25 +76,20 @@ struct spi_struct_t { #define SPI_FSPI_SS_IDX(n) ((n==0)?FSPICS0_OUT_IDX:((n==1)?FSPICS1_OUT_IDX:((n==2)?FSPICS2_OUT_IDX:FSPICS0_OUT_IDX))) #define SPI_SS_IDX(p, n) ((p==0)?SPI_SPI_SS_IDX(n):((p==1)?SPI_SPI_SS_IDX(n):((p==2)?SPI_HSPI_SS_IDX(n):0))) -#define SPI_INTR_SOURCE(u) ((u==0)?ETS_SPI1_INTR_SOURCE:((u==1)?ETS_SPI2_INTR_SOURCE:((u==2)?ETS_SPI3_INTR_SOURCE:0))) - #elif CONFIG_IDF_TARGET_ESP32S3 // ESP32S3 #define SPI_COUNT (2) -#define SPI_CLK_IDX(p) ((p==0)?SPICLK_OUT_IDX:((p==1)?FSPICLK_OUT_IDX:0)) -#define SPI_MISO_IDX(p) ((p==0)?SPIQ_OUT_IDX:((p==1)?FSPIQ_OUT_IDX:0)) -#define SPI_MOSI_IDX(p) ((p==0)?SPID_IN_IDX:((p==1)?FSPID_IN_IDX:0)) +#define SPI_CLK_IDX(p) ((p==0)?FSPICLK_OUT_IDX:((p==1)?SPI3_CLK_OUT_IDX:0)) +#define SPI_MISO_IDX(p) ((p==0)?FSPIQ_OUT_IDX:((p==1)?SPI3_Q_OUT_IDX:0)) +#define SPI_MOSI_IDX(p) ((p==0)?FSPID_IN_IDX:((p==1)?SPI3_D_IN_IDX:0)) -#define SPI_SPI_SS_IDX(n) ((n==0)?SPICS0_OUT_IDX:((n==1)?SPICS1_OUT_IDX:0)) #define SPI_HSPI_SS_IDX(n) ((n==0)?SPI3_CS0_OUT_IDX:((n==1)?SPI3_CS1_OUT_IDX:0)) #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_SPI_SS_IDX(n):((p==1)?SPI_SPI_SS_IDX(n):0)) - -#define SPI_INTR_SOURCE(u) ((u==0)?ETS_SPI1_INTR_SOURCE:((u==1)?ETS_SPI2_INTR_SOURCE: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_ESP32C3 -// ESP32S2 +// ESP32C3 #define SPI_COUNT (1) #define SPI_CLK_IDX(p) FSPICLK_OUT_IDX @@ -106,8 +99,6 @@ struct spi_struct_t { #define SPI_SPI_SS_IDX(n) ((n==0)?FSPICS0_OUT_IDX:((n==1)?FSPICS1_OUT_IDX:((n==2)?FSPICS2_OUT_IDX:FSPICS0_OUT_IDX))) #define SPI_SS_IDX(p, n) SPI_SPI_SS_IDX(n) -#define SPI_INTR_SOURCE(u) ETS_SPI2_INTR_SOURCE - #else // ESP32 #define SPI_COUNT (4) @@ -121,8 +112,6 @@ struct spi_struct_t { #define SPI_VSPI_SS_IDX(n) ((n==0)?VSPICS0_OUT_IDX:((n==1)?VSPICS1_OUT_IDX:((n==2)?VSPICS2_OUT_IDX:VSPICS0_OUT_IDX))) #define SPI_SS_IDX(p, n) ((p==0)?SPI_SPI_SS_IDX(n):((p==1)?SPI_SPI_SS_IDX(n):((p==2)?SPI_HSPI_SS_IDX(n):((p==3)?SPI_VSPI_SS_IDX(n):0)))) -#define SPI_INTR_SOURCE(u) ((u==0)?ETS_SPI0_INTR_SOURCE:((u==1)?ETS_SPI1_INTR_SOURCE:((u==2)?ETS_SPI2_INTR_SOURCE:((p==3)?ETS_SPI3_INTR_SOURCE:0)))) - #endif #if CONFIG_DISABLE_HAL_LOCKS @@ -135,8 +124,10 @@ static spi_t _spi_bus_array[] = { {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 2} #elif CONFIG_IDF_TARGET_ESP32S3 - {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 0}, - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 1} + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0}, + {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1} +#elif CONFIG_IDF_TARGET_ESP32C3 + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0} #else {(volatile spi_dev_t *)(DR_REG_SPI0_BASE), 0}, {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 1}, @@ -154,10 +145,10 @@ static spi_t _spi_bus_array[] = { {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 2} #elif CONFIG_IDF_TARGET_ESP32S3 - {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 0}, - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 1} + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0}, + {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1} #elif CONFIG_IDF_TARGET_ESP32C3 - {(volatile spi_dev_t *)(&GPSPI2), NULL, FSPI} + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0} #else {(volatile spi_dev_t *)(DR_REG_SPI0_BASE), NULL, 0}, {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 1}, @@ -173,13 +164,20 @@ void spiAttachSCK(spi_t * spi, int8_t sck) return; } if(sck < 0) { -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S2 if(spi->num == FSPI) { sck = 36; } else { log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + sck = 12; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { sck = 14; @@ -203,13 +201,20 @@ void spiAttachMISO(spi_t * spi, int8_t miso) return; } if(miso < 0) { -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S2 if(spi->num == FSPI) { miso = 37; } else { log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + miso = 13; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { miso = 12; @@ -242,6 +247,13 @@ void spiAttachMOSI(spi_t * spi, int8_t mosi) log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + mosi = 11; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { mosi = 13; @@ -272,6 +284,13 @@ void spiDetachSCK(spi_t * spi, int8_t sck) log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + sck = 12; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { sck = 14; @@ -302,6 +321,13 @@ void spiDetachMISO(spi_t * spi, int8_t miso) log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + miso = 13; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { miso = 12; @@ -332,6 +358,13 @@ void spiDetachMOSI(spi_t * spi, int8_t mosi) log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + mosi = 11; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { mosi = 13; @@ -359,13 +392,20 @@ void spiAttachSS(spi_t * spi, uint8_t cs_num, int8_t ss) } if(ss < 0) { cs_num = 0; -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S2 if(spi->num == FSPI) { ss = 34; } else { log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + ss = 10; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { ss = 15; @@ -390,13 +430,20 @@ void spiDetachSS(spi_t * spi, int8_t ss) return; } if(ss < 0) { -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S2 if(spi->num == FSPI) { ss = 34; } else { log_e("HSPI Does not have default pins on ESP32S2!"); return; } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi->num == FSPI) { + ss = 10; + } else { + log_e("HSPI Does not have default pins on ESP32S3!"); + return; + } #elif CONFIG_IDF_TARGET_ESP32 if(spi->num == HSPI) { ss = 15; @@ -615,7 +662,7 @@ static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb static void spiInitBus(spi_t * spi) { -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->slave.trans_done = 0; #endif spi->dev->slave.val = 0; @@ -627,7 +674,7 @@ static void spiInitBus(spi_t * spi) spi->dev->user.val = 0; spi->dev->user1.val = 0; spi->dev->ctrl.val = 0; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->ctrl1.val = 0; spi->dev->ctrl2.val = 0; #else @@ -669,7 +716,7 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_ } #endif -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S2 if(spi_num == FSPI) { DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN); DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI2_RST); @@ -680,6 +727,14 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_ DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN); DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST); } +#elif CONFIG_IDF_TARGET_ESP32S3 + if(spi_num == FSPI) { + periph_module_reset( PERIPH_SPI2_MODULE ); + periph_module_enable( PERIPH_SPI2_MODULE ); + } else if(spi_num == HSPI) { + periph_module_reset( PERIPH_SPI3_MODULE ); + periph_module_enable( PERIPH_SPI3_MODULE ); + } #elif CONFIG_IDF_TARGET_ESP32 if(spi_num == HSPI) { DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN); @@ -698,7 +753,7 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_ SPI_MUTEX_LOCK(); spiInitBus(spi); -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->clk_gate.clk_en = 1; spi->dev->clk_gate.mst_clk_sel = 1; spi->dev->clk_gate.mst_clk_active = 1; @@ -732,10 +787,10 @@ void spiWaitReady(spi_t * spi) while(spi->dev->cmd.usr); } -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#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_ESP32C3 +#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 #define usr_mosi_dbitlen ms_data_bitlen #define usr_miso_dbitlen ms_data_bitlen #define mosi_dlen ms_dlen @@ -753,13 +808,13 @@ void spiWrite(spi_t * spi, const uint32_t *data, uint8_t len) } SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = (len * 32) - 1; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif for(i=0; idev->data_buf[i] = data[i]; } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -783,7 +838,7 @@ void spiTransfer(spi_t * spi, uint32_t *data, uint8_t len) for(i=0; idev->data_buf[i] = data[i]; } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -802,11 +857,11 @@ void spiWriteByte(spi_t * spi, uint8_t data) } SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -824,7 +879,7 @@ uint8_t spiTransferByte(spi_t * spi, uint8_t data) spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; spi->dev->miso_dlen.usr_miso_dbitlen = 7; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -855,11 +910,11 @@ void spiWriteWord(spi_t * spi, uint16_t data) } SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -880,7 +935,7 @@ uint16_t spiTransferWord(spi_t * spi, uint16_t data) spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; spi->dev->miso_dlen.usr_miso_dbitlen = 15; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -904,11 +959,11 @@ void spiWriteLong(spi_t * spi, uint32_t data) } SPI_MUTEX_LOCK(); spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -929,7 +984,7 @@ uint32_t spiTransferLong(spi_t * spi, uint32_t data) spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; spi->dev->miso_dlen.usr_miso_dbitlen = 31; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -972,7 +1027,7 @@ static void __spiTransferBytes(spi_t * spi, const uint8_t * data, uint8_t * out, spi->dev->data_buf[i] = wordsBuf[i]; //copy buffer to spi fifo } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1104,11 +1159,11 @@ void ARDUINO_ISR_ATTR spiWriteByteNL(spi_t * spi, uint8_t data) return; } spi->dev->mosi_dlen.usr_mosi_dbitlen = 7; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1124,7 +1179,7 @@ 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; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1143,11 +1198,11 @@ void ARDUINO_ISR_ATTR spiWriteShortNL(spi_t * spi, uint16_t data) MSB_16_SET(data, data); } spi->dev->mosi_dlen.usr_mosi_dbitlen = 15; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1166,7 +1221,7 @@ 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; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1188,11 +1243,11 @@ void ARDUINO_ISR_ATTR spiWriteLongNL(spi_t * spi, uint32_t data) MSB_32_SET(data, data); } spi->dev->mosi_dlen.usr_mosi_dbitlen = 31; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1211,7 +1266,7 @@ 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; spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1240,13 +1295,13 @@ void spiWriteNL(spi_t * spi, const void * data_in, uint32_t len){ c_longs = (longs > 16)?16:longs; spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len*8)-1; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif for (int i=0; idev->data_buf[i] = data[i]; } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1286,7 +1341,7 @@ void spiTransferBytesNL(spi_t * spi, const void * data_in, uint8_t * data_out, u spi->dev->data_buf[i] = 0xFFFFFFFF; } } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1345,7 +1400,7 @@ 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); spi->dev->data_buf[0] = data; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1381,7 +1436,7 @@ void ARDUINO_ISR_ATTR spiWritePixelsNL(spi_t * spi, const void * data_in, uint32 l_bytes = (c_len & 3); spi->dev->mosi_dlen.usr_mosi_dbitlen = (c_len*8)-1; -#ifndef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 spi->dev->miso_dlen.usr_miso_dbitlen = 0; #endif for (int i=0; idev->data_buf[i] = data[i]; } } -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 spi->dev->cmd.update = 1; while (spi->dev->cmd.update); #endif @@ -1425,7 +1480,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_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 uint32_t clkdiv_pre: 4; /*it is pre-divider of spi_clk.*/ uint32_t reserved: 9; /*reserved*/ #else @@ -1472,7 +1527,7 @@ uint32_t spiFrequencyToClockDiv(uint32_t freq) while(calPreVari++ <= 1) { calPre = (((apb_freq / (reg.clkcnt_n + 1)) / freq) - 1) + calPreVari; -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 if(calPre > 0xF) { reg.clkdiv_pre = 0xF; #else @@ -1503,4 +1558,3 @@ uint32_t spiFrequencyToClockDiv(uint32_t freq) } return bestReg.value; } -#endif /* ifndef CONFIG_IDF_TARGET_ESP32S3 */ diff --git a/cores/esp32/esp32-hal-spi.h b/cores/esp32/esp32-hal-spi.h index 6fbb7b3dca7..89ceefccd60 100644 --- a/cores/esp32/esp32-hal-spi.h +++ b/cores/esp32/esp32-hal-spi.h @@ -25,7 +25,7 @@ extern "C" { #define SPI_HAS_TRANSACTION -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 #define FSPI 0 #define HSPI 1 #else diff --git a/cores/esp32/esp32-hal-touch.c b/cores/esp32/esp32-hal-touch.c index 6e2b069bed0..e5eaf497b5e 100644 --- a/cores/esp32/esp32-hal-touch.c +++ b/cores/esp32/esp32-hal-touch.c @@ -12,223 +12,251 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "esp32-hal-touch.h" -#ifndef CONFIG_IDF_TARGET_ESP32C3 -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_attr.h" -#include "soc/rtc_io_reg.h" -#include "soc/sens_reg.h" -#include "soc/sens_struct.h" -#include "soc/rtc_cntl_reg.h" +#include "soc/soc_caps.h" +#if SOC_TOUCH_SENSOR_NUM > 0 + #include "driver/touch_sensor.h" +#include "esp32-hal-touch.h" -#include "esp_system.h" -#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ -#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 -#include "esp32/rom/ets_sys.h" -#include "esp_intr_alloc.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/ets_sys.h" -#include "esp_intr_alloc.h" -#include "soc/periph_defs.h" -#elif CONFIG_IDF_TARGET_ESP32S3 -#include "esp32s3/rom/ets_sys.h" -#include "esp_intr_alloc.h" -#include "soc/periph_defs.h" -#else -#error Target CONFIG_IDF_TARGET is not supported -#endif -#else // ESP32 Before IDF 4.0 -#include "rom/ets_sys.h" -#include "esp_intr.h" -#endif +/* + Internal Private Touch Data Structure and Functions +*/ +#if SOC_TOUCH_VERSION_1 // ESP32 static uint16_t __touchSleepCycles = 0x1000; static uint16_t __touchMeasureCycles = 0x1000; +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 +static uint16_t __touchSleepCycles = TOUCH_PAD_SLEEP_CYCLE_DEFAULT; +static uint16_t __touchMeasureCycles = TOUCH_PAD_MEASURE_CYCLE_DEFAULT; +#endif typedef void (*voidFuncPtr)(void); -static voidFuncPtr __touchInterruptHandlers[10] = {0,}; -static intr_handle_t touch_intr_handle = NULL; +typedef void (*voidArgFuncPtr)(void *); + +typedef struct { + voidFuncPtr fn; + bool callWithArgs; + void* arg; +#if SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 + bool lastStatusIsPressed; +#endif +} TouchInterruptHandle_t; + +static TouchInterruptHandle_t __touchInterruptHandlers[SOC_TOUCH_SENSOR_NUM] = {0,}; -void ARDUINO_ISR_ATTR __touchISR(void * arg) +static void ARDUINO_ISR_ATTR __touchISR(void * arg) { -#if CONFIG_IDF_TARGET_ESP32 - uint32_t pad_intr = READ_PERI_REG(SENS_SAR_TOUCH_CTRL2_REG) & 0x3ff; - uint32_t rtc_intr = READ_PERI_REG(RTC_CNTL_INT_ST_REG); - uint8_t i = 0; +#if SOC_TOUCH_VERSION_1 // ESP32 + uint32_t pad_intr = touch_pad_get_status(); //clear interrupt - WRITE_PERI_REG(RTC_CNTL_INT_CLR_REG, rtc_intr); - SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_EN_CLR); - - if (rtc_intr & RTC_CNTL_TOUCH_INT_ST) { - for (i = 0; i < 10; ++i) { - if ((pad_intr >> i) & 0x01) { - if(__touchInterruptHandlers[i]){ - __touchInterruptHandlers[i](); + touch_pad_clear_status(); + // call Pad ISR User callback + for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) { + if ((pad_intr >> i) & 0x01) { + if(__touchInterruptHandlers[i].fn){ + // keeping backward compatibility with "void cb(void)" and with new "void cb(vooid *)" + if (__touchInterruptHandlers[i].callWithArgs) { + ((voidArgFuncPtr)__touchInterruptHandlers[i].fn)(__touchInterruptHandlers[i].arg); + } else { + __touchInterruptHandlers[i].fn(); } } } } +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + touch_pad_intr_mask_t evt = touch_pad_read_intr_status_mask(); + uint8_t pad_num = touch_pad_get_current_meas_channel(); + if (evt & TOUCH_PAD_INTR_MASK_ACTIVE) { + // touch has been pressed / touched + __touchInterruptHandlers[pad_num].lastStatusIsPressed = true; + } + if (evt & TOUCH_PAD_INTR_MASK_INACTIVE) { + // touch has been released / untouched + __touchInterruptHandlers[pad_num].lastStatusIsPressed = false; + } + if(__touchInterruptHandlers[pad_num].fn){ + // keeping backward compatibility with "void cb(void)" and with new "void cb(vooid *)" + if (__touchInterruptHandlers[pad_num].callWithArgs) { + ((voidArgFuncPtr)__touchInterruptHandlers[pad_num].fn)(__touchInterruptHandlers[pad_num].arg); + } else { + __touchInterruptHandlers[pad_num].fn(); + } + } #endif } -void __touchSetCycles(uint16_t measure, uint16_t sleep) + + +static void __touchSetCycles(uint16_t measure, uint16_t sleep) { __touchSleepCycles = sleep; __touchMeasureCycles = measure; -#if CONFIG_IDF_TARGET_ESP32 - //Touch pad SleepCycle Time - SET_PERI_REG_BITS(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_SLEEP_CYCLES, __touchSleepCycles, SENS_TOUCH_SLEEP_CYCLES_S); - //Touch Pad Measure Time - SET_PERI_REG_BITS(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_MEAS_DELAY, __touchMeasureCycles, SENS_TOUCH_MEAS_DELAY_S); -#else touch_pad_set_meas_time(sleep, measure); -#endif } -void __touchInit() + + +static void __touchInit() { static bool initialized = false; if(initialized){ return; } - initialized = true; -#if CONFIG_IDF_TARGET_ESP32 - SET_PERI_REG_BITS(RTC_IO_TOUCH_CFG_REG, RTC_IO_TOUCH_XPD_BIAS, 1, RTC_IO_TOUCH_XPD_BIAS_S); - SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_EN_CLR); - //clear touch enable - WRITE_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG, 0x0); - SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_TOUCH_SLP_TIMER_EN); - __touchSetCycles(__touchMeasureCycles, __touchSleepCycles); - esp_intr_alloc(ETS_RTC_CORE_INTR_SOURCE, (int)ARDUINO_ISR_FLAG, __touchISR, NULL, &touch_intr_handle); -#else - touch_pad_init(); - touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V5); - touch_pad_set_idle_channel_connect(TOUCH_PAD_CONN_GND); - __touchSetCycles(__touchMeasureCycles, __touchSleepCycles); + + esp_err_t err = ESP_OK; + +#if SOC_TOUCH_VERSION_1 // ESP32 + err = touch_pad_init(); + if (err != ESP_OK) { + goto err; + } + // the next two lines will drive the touch reading values -- both will return ESP_OK + touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V); + touch_pad_set_meas_time(__touchMeasureCycles, __touchSleepCycles); + // Touch Sensor Timer initiated + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); // returns ESP_OK + err = touch_pad_filter_start(10); + if (err != ESP_OK) { + goto err; + } + // Initial no Threshold and setup + for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) { + __touchInterruptHandlers[i].fn = NULL; + touch_pad_config(i, SOC_TOUCH_PAD_THRESHOLD_MAX); // returns ESP_OK + } + // keep ISR activated - it can run all together (ISR + touchRead()) + err = touch_pad_isr_register(__touchISR, NULL); + if (err != ESP_OK) { + goto err; + } + touch_pad_intr_enable(); // returns ESP_OK +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + err = touch_pad_init(); + if (err != ESP_OK) { + goto err; + } + // the next lines will drive the touch reading values -- all os them return ESP_OK + touch_pad_set_meas_time(__touchSleepCycles, __touchMeasureCycles); + touch_pad_set_voltage(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD, TOUCH_PAD_LOW_VOLTAGE_THRESHOLD, TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD); + touch_pad_set_idle_channel_connect(TOUCH_PAD_IDLE_CH_CONNECT_DEFAULT); touch_pad_denoise_t denoise = { .grade = TOUCH_PAD_DENOISE_BIT4, .cap_level = TOUCH_PAD_DENOISE_CAP_L4, }; touch_pad_denoise_set_config(&denoise); touch_pad_denoise_enable(); - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); - touch_pad_fsm_start(); + // Touch Sensor Timer initiated + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); // returns ESP_OK + touch_pad_fsm_start(); // returns ESP_OK + + // Initial no Threshold and setup - TOUCH0 is internal denoise channel + for (int i = 1; i < SOC_TOUCH_SENSOR_NUM; i++) { + __touchInterruptHandlers[i].fn = NULL; + touch_pad_config(i); // returns ESP_OK + } + // keep ISR activated - it can run all together (ISR + touchRead()) + err = touch_pad_isr_register(__touchISR, NULL, TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); + if (err != ESP_OK) { + goto err; + } + touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); // returns ESP_OK #endif + + initialized = true; + return; +err: + log_e(" Touch sensor initialization error."); + initialized = false; + return; } -uint16_t __touchRead(uint8_t pin) +static touch_value_t __touchRead(uint8_t pin) { int8_t pad = digitalPinToTouchChannel(pin); if(pad < 0){ return 0; } + __touchInit(); - pinMode(pin, ANALOG); + touch_value_t touch_value; + touch_pad_read_raw_data(pad, &touch_value); - __touchInit(); + return touch_value; +} -#if CONFIG_IDF_TARGET_ESP32 - uint32_t v0 = READ_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG); - //Disable Intr & enable touch pad - WRITE_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG, - (v0 & ~((1 << (pad + SENS_TOUCH_PAD_OUTEN2_S)) | (1 << (pad + SENS_TOUCH_PAD_OUTEN1_S)))) - | (1 << (pad + SENS_TOUCH_PAD_WORKEN_S))); +static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Args, touch_value_t threshold, bool callWithArgs) +{ + int8_t pad = digitalPinToTouchChannel(pin); + if(pad < 0){ + return; + } - SET_PERI_REG_MASK(SENS_SAR_TOUCH_ENABLE_REG, (1 << (pad + SENS_TOUCH_PAD_WORKEN_S))); + if (userFunc == NULL) { + // dettach ISR User Call + __touchInterruptHandlers[pad].fn = NULL; + threshold = SOC_TOUCH_PAD_THRESHOLD_MAX; // deactivate the ISR with SOC_TOUCH_PAD_THRESHOLD_MAX + } else { + // attach ISR User Call + __touchInit(); + __touchInterruptHandlers[pad].fn = userFunc; + __touchInterruptHandlers[pad].callWithArgs = callWithArgs; + __touchInterruptHandlers[pad].arg = Args; + } - uint32_t rtc_tio_reg = RTC_IO_TOUCH_PAD0_REG + pad * 4; - WRITE_PERI_REG(rtc_tio_reg, (READ_PERI_REG(rtc_tio_reg) - & ~(RTC_IO_TOUCH_PAD0_DAC_M)) - | (7 << RTC_IO_TOUCH_PAD0_DAC_S)//Touch Set Slope - | RTC_IO_TOUCH_PAD0_TIE_OPT_M //Enable Tie,Init Level - | RTC_IO_TOUCH_PAD0_START_M //Enable Touch Pad IO - | RTC_IO_TOUCH_PAD0_XPD_M); //Enable Touch Pad Power on +#if SOC_TOUCH_VERSION_1 // ESP32 + touch_pad_config(pad, threshold); +#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3 + touch_pad_set_thresh(pad, threshold); +#endif +} - //force oneTime test start - SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_EN_M|SENS_TOUCH_START_FORCE_M); +// it keeps backwards compatibility +static void __touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), touch_value_t threshold) +{ + __touchConfigInterrupt(pin, userFunc, NULL, threshold, false); +} - SET_PERI_REG_BITS(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_XPD_WAIT, 10, SENS_TOUCH_XPD_WAIT_S); +// new additional version of the API with User Args +static void __touchAttachArgsInterrupt(uint8_t pin, void (*userFunc)(void), void *args, touch_value_t threshold) +{ + __touchConfigInterrupt(pin, userFunc, args, threshold, true); +} - while (GET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_DONE) == 0) {}; +// new additional API to dettach touch ISR +static void __touchDettachInterrupt(uint8_t pin) +{ + __touchConfigInterrupt(pin, NULL, NULL, 0, false); // userFunc as NULL acts as dettaching +} - uint16_t touch_value = READ_PERI_REG(SENS_SAR_TOUCH_OUT1_REG + (pad / 2) * 4) >> ((pad & 1) ? SENS_TOUCH_MEAS_OUT1_S : SENS_TOUCH_MEAS_OUT0_S); - //clear touch force ,select the Touch mode is Timer - CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_EN_M|SENS_TOUCH_START_FORCE_M); +/* + External Public Touch API Functions +*/ - //restore previous value - WRITE_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG, v0); - return touch_value; -#else - static uint32_t chan_mask = 0; - uint32_t value = 0; - if((chan_mask & (1 << pad)) == 0){ - if(touch_pad_set_thresh((touch_pad_t)pad, TOUCH_PAD_THRESHOLD_MAX) != ESP_OK){ - log_e("touch_pad_set_thresh failed"); - } else if(touch_pad_config((touch_pad_t)pad) != ESP_OK){ - log_e("touch_pad_config failed"); - } else { - chan_mask |= (1 << pad); - } - } - if((chan_mask & (1 << pad)) != 0) { - if(touch_pad_read_raw_data((touch_pad_t)pad, &value) != ESP_OK){ - log_e("touch_pad_read_raw_data failed"); - } +#if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC +void touchInterruptSetThresholdDirection(bool mustbeLower) { + if (mustbeLower) { + touch_pad_set_trigger_mode(TOUCH_TRIGGER_BELOW); + } else { + touch_pad_set_trigger_mode(TOUCH_TRIGGER_ABOVE); } - return value; -#endif } - -void __touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), uint16_t threshold) -{ +#elif SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 +// returns true if touch pad has been and continues pressed and false otherwise +bool touchInterruptGetLastStatus(uint8_t pin) { int8_t pad = digitalPinToTouchChannel(pin); if(pad < 0){ - return; + return false; } - pinMode(pin, ANALOG); - - __touchInit(); - - __touchInterruptHandlers[pad] = userFunc; - -#if CONFIG_IDF_TARGET_ESP32 - //clear touch force ,select the Touch mode is Timer - CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_START_EN_M|SENS_TOUCH_START_FORCE_M); - - //interrupt when touch value < threshold - CLEAR_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_OUT_SEL); - //Intr will give ,when SET0 < threshold - SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL1_REG, SENS_TOUCH_OUT_1EN); - //Enable Rtc Touch Module Intr,the Interrupt need Rtc out Enable - SET_PERI_REG_MASK(RTC_CNTL_INT_ENA_REG, RTC_CNTL_TOUCH_INT_ENA); - - //set threshold - uint8_t shift = (pad & 1) ? SENS_TOUCH_OUT_TH1_S : SENS_TOUCH_OUT_TH0_S; - SET_PERI_REG_BITS((SENS_SAR_TOUCH_THRES1_REG + (pad / 2) * 4), SENS_TOUCH_OUT_TH0, threshold, shift); - - uint32_t rtc_tio_reg = RTC_IO_TOUCH_PAD0_REG + pad * 4; - WRITE_PERI_REG(rtc_tio_reg, (READ_PERI_REG(rtc_tio_reg) - & ~(RTC_IO_TOUCH_PAD0_DAC_M)) - | (7 << RTC_IO_TOUCH_PAD0_DAC_S)//Touch Set Slope - | RTC_IO_TOUCH_PAD0_TIE_OPT_M //Enable Tie,Init Level - | RTC_IO_TOUCH_PAD0_START_M //Enable Touch Pad IO - | RTC_IO_TOUCH_PAD0_XPD_M); //Enable Touch Pad Power on - - //Enable Digital rtc control :work mode and out mode - SET_PERI_REG_MASK(SENS_SAR_TOUCH_ENABLE_REG, - (1 << (pad + SENS_TOUCH_PAD_WORKEN_S)) | \ - (1 << (pad + SENS_TOUCH_PAD_OUTEN2_S)) | \ - (1 << (pad + SENS_TOUCH_PAD_OUTEN1_S))); -#else - -#endif + return __touchInterruptHandlers[pad].lastStatusIsPressed; } - -extern uint16_t touchRead(uint8_t pin) __attribute__ ((weak, alias("__touchRead"))); -extern void touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), uint16_t threshold) __attribute__ ((weak, alias("__touchAttachInterrupt"))); -extern void touchSetCycles(uint16_t measure, uint16_t sleep) __attribute__ ((weak, alias("__touchSetCycles"))); #endif + +extern touch_value_t touchRead(uint8_t) __attribute__ ((weak, alias("__touchRead"))); +extern void touchAttachInterrupt(uint8_t, voidFuncPtr, touch_value_t) __attribute__ ((weak, alias("__touchAttachInterrupt"))); +extern void touchAttachInterruptArg(uint8_t, voidArgFuncPtr, void *, touch_value_t) __attribute__ ((weak, alias("__touchAttachArgsInterrupt"))); +extern void touchDetachInterrupt(uint8_t) __attribute__ ((weak, alias("__touchDettachInterrupt"))); +extern void touchSetCycles(uint16_t, uint16_t) __attribute__ ((weak, alias("__touchSetCycles"))); + +#endif // #if SOC_TOUCH_SENSOR_NUM > 0 diff --git a/cores/esp32/esp32-hal-touch.h b/cores/esp32/esp32-hal-touch.h index 6f3b0fd0f7d..a8cda191c31 100644 --- a/cores/esp32/esp32-hal-touch.h +++ b/cores/esp32/esp32-hal-touch.h @@ -24,8 +24,21 @@ extern "C" { #endif +#include "soc/soc_caps.h" #include "esp32-hal.h" +#if SOC_TOUCH_SENSOR_NUM > 0 + +#if !defined(SOC_TOUCH_VERSION_1) && !defined(SOC_TOUCH_VERSION_2) +#error Touch IDF driver Not supported! +#endif + +#if SOC_TOUCH_VERSION_1 // ESP32 +typedef uint16_t touch_value_t; +#elif SOC_TOUCH_VERSION_2 // ESP32S2 ESP32S3 +typedef uint32_t touch_value_t; +#endif + /* * Set cycles that measurement operation takes * The result from touchRead, threshold and detection @@ -40,17 +53,44 @@ void touchSetCycles(uint16_t measure, uint16_t sleep); * You can use this method to chose a good threshold value * to use as value for touchAttachInterrupt * */ -uint16_t touchRead(uint8_t pin); +touch_value_t touchRead(uint8_t pin); /* - * Set function to be called if touch pad value falls - * below the given threshold. Use touchRead to determine - * a proper threshold between touched and untouched state + * Set function to be called if touch pad value falls (ESP32) + * below the given threshold / rises (ESP32-S2/S3) by given increment (threshold). + * Use touchRead to determine a proper threshold between touched and untouched state * */ -void touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), uint16_t threshold); +void touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), touch_value_t threshold); +void touchAttachInterruptArg(uint8_t pin, void (*userFunc)(void*), void *arg, touch_value_t threshold); +void touchDetachInterrupt(uint8_t pin); + +/* + * Specific functions to ESP32 + * Tells the driver if it shall activate the ISR if the sensor is Lower or Higher than the Threshold + * Default if Lower. + **/ + +#if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC +void touchInterruptSetThresholdDirection(bool mustbeLower); +#endif + + +/* + * Specific functions to ESP32-S2 and ESP32-S3 + * Returns true when the latest ISR status for the Touchpad is that it is touched (Active) + * and false when the Touchpad is untoouched (Inactive) + * This function can be used in conjunction with ISR User callback in order to take action + * as soon as the touchpad is touched and/or released + **/ + +#if SOC_TOUCH_VERSION_2 // Only for ESP32S2 and ESP32S3 +// returns true if touch pad has been and continues pressed and false otherwise +bool touchInterruptGetLastStatus(uint8_t pin); +#endif + +#endif // SOC_TOUCH_SENSOR_NUM > 0 #ifdef __cplusplus } #endif - #endif /* MAIN_ESP32_HAL_TOUCH_H_ */ diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 298b731d41e..445f157c1ea 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -73,7 +73,7 @@ static uart_t _uart_bus_array[] = { // solves issue https://github.com/espressif/arduino-esp32/issues/6032 // baudrate must be multiplied when CPU Frequency is lower than APB 80MHz -uint32_t _get_effective_baudrate(uint32_t baudrate) +uint32_t _get_effective_baudrate(uint32_t baudrate) { uint32_t Freq = getApbFrequency()/1000000; if (Freq < 80) { @@ -106,9 +106,7 @@ static void uart_event_task(void *args) switch(event.type) { //Event of UART receving data case UART_DATA: - UART_MUTEX_LOCK(); if(uart->onReceive) uart->onReceive(); - UART_MUTEX_UNLOCK(); break; //Event of HW FIFO overflow detected case UART_FIFO_OVF: @@ -145,7 +143,7 @@ static void uart_event_task(void *args) } -bool uartIsDriverInstalled(uart_t* uart) +bool uartIsDriverInstalled(uart_t* uart) { if(uart == NULL) { return 0; @@ -163,9 +161,9 @@ void uartSetPins(uart_t* uart, uint8_t rxPin, uint8_t txPin) return; } UART_MUTEX_LOCK(); - ESP_ERROR_CHECK(uart_set_pin(uart->num, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); + ESP_ERROR_CHECK(uart_set_pin(uart->num, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); UART_MUTEX_UNLOCK(); - + } @@ -210,10 +208,10 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx ESP_ERROR_CHECK(uart_param_config(uart_nr, &uart_config)); ESP_ERROR_CHECK(uart_set_pin(uart_nr, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); - // Is it right or the idea is to swap rx and tx pins? + // Is it right or the idea is to swap rx and tx pins? if (inverted) { // invert signal for both Rx and Tx - ESP_ERROR_CHECK(uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV)); + ESP_ERROR_CHECK(uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV)); } // Creating UART event Task @@ -233,7 +231,7 @@ void uartEnd(uart_t* uart) if(uart == NULL) { return; } - + UART_MUTEX_LOCK(); uart_driver_delete(uart->num); if (uart->envent_task) { @@ -250,13 +248,13 @@ void uartSetRxInvert(uart_t* uart, bool invert) if (uart == NULL) return; #if 0 - // POTENTIAL ISSUE :: original code only set/reset rxd_inv bit + // POTENTIAL ISSUE :: original code only set/reset rxd_inv bit // IDF or LL set/reset the whole inv_mask! if (invert) ESP_ERROR_CHECK(uart_set_line_inverse(uart->num, UART_SIGNAL_RXD_INV)); else ESP_ERROR_CHECK(uart_set_line_inverse(uart->num, UART_SIGNAL_INV_DISABLE)); - + #else // this implementation is better over IDF API because it only affects RXD // this is supported in ESP32, ESP32-S2 and ESP32-C3 @@ -265,7 +263,7 @@ void uartSetRxInvert(uart_t* uart, bool invert) hw->conf0.rxd_inv = 1; else hw->conf0.rxd_inv = 0; -#endif +#endif } @@ -291,7 +289,7 @@ uint32_t uartAvailableForWrite(uart_t* uart) return 0; } UART_MUTEX_LOCK(); - uint32_t available = uart_ll_get_txfifo_len(UART_LL_GET_HW(uart->num)); + uint32_t available = uart_ll_get_txfifo_len(UART_LL_GET_HW(uart->num)); UART_MUTEX_UNLOCK(); return available; } @@ -375,7 +373,7 @@ void uartFlushTxOnly(uart_t* uart, bool txOnly) if(uart == NULL) { return; } - + UART_MUTEX_LOCK(); while(!uart_ll_is_tx_idle(UART_LL_GET_HW(uart->num))); @@ -488,7 +486,7 @@ int log_printf(const char *format, ...) xSemaphoreTake(_uart_bus_array[s_uart_debug_nr].lock, portMAX_DELAY); } #endif - + vsnprintf(temp, len+1, format, arg); ets_printf("%s", temp); @@ -569,22 +567,22 @@ unsigned long uartBaudrateDetect(uart_t *uart, bool flg) * To start detection of baud rate with the uart the auto_baud.en bit needs to be cleared and set. The bit period is * detected calling uartBadrateDetect(). The raw baudrate is computed using the UART_CLK_FREQ. The raw baudrate is * rounded to the closed real baudrate. - * + * * ESP32-C3 reports wrong baud rate detection as shown below: - * + * * This will help in a future recall for the C3. * Baud Sent: Baud Read: * 300 --> 19536 * 2400 --> 19536 - * 4800 --> 19536 - * 9600 --> 28818 + * 4800 --> 19536 + * 9600 --> 28818 * 19200 --> 57678 * 38400 --> 115440 * 57600 --> 173535 * 115200 --> 347826 * 230400 --> 701754 - * - * + * + * */ void uartStartDetectBaudrate(uart_t *uart) { if(uart == NULL) { @@ -594,10 +592,10 @@ void uartStartDetectBaudrate(uart_t *uart) { uart_dev_t *hw = UART_LL_GET_HW(uart->num); #ifdef CONFIG_IDF_TARGET_ESP32C3 - + // ESP32-C3 requires further testing - // Baud rate detection returns wrong values - + // Baud rate detection returns wrong values + log_e("ESP32-C3 baud rate detection is not supported."); return; @@ -613,7 +611,7 @@ void uartStartDetectBaudrate(uart_t *uart) { hw->auto_baud.en = 1; #endif } - + unsigned long uartDetectBaudrate(uart_t *uart) { @@ -671,4 +669,4 @@ uartDetectBaudrate(uart_t *uart) log_e("ESP32-C3 baud rate detection is not supported."); return 0; #endif -} +} \ No newline at end of file diff --git a/docs/ISSUE_TEMPLATE.md b/docs/ISSUE_TEMPLATE.md deleted file mode 100644 index 5cf96ef213b..00000000000 --- a/docs/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,47 +0,0 @@ -Make your question, not a Statement, inclusive. Include all pertinent information: - -What you are trying to do -Describe your system (Hardware, computer, O/S, core version, environment) -Describe what is failing -Show the shortest possible code that will duplicate the error -Show the EXACT error message (it doesn't work is not enough) -Then if someone is interested and knowledgeable you might get a answer. All of this work on your part shows us that you have worked to solve YOUR problem. The more complete your issue posting is, the more likely someone will volunteer their time to help you. - -If you have a Guru Meditation Error or Backtrace, ***please decode it***: -[ExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecoder) - ------------------------------ Remove above ----------------------------- - - -### Hardware: -||||||| -|:---|---|---|---|---|---| -|Board|ESP32 Dev Module|node32|ttgo_lora|ESP32-S2-Saola|Custom w/ ESP32-S2-WROVER 16MB| -|Version/Date|1.0.4|2.0.0|0badbeef|11/jul/2017|today's master| -|IDE name|Arduino IDE|Atom + Platform.io|IDF component|VSCode| -|Flash Frequency|40Mhz|80Mhz| -|PSRAM enabled|yes|no| -|Upload Speed|115200| -|Computer OS|Windows 10|Mac OSX|Ubuntu| - -### Description: -Describe your problem here - - -### Sketch: (leave the backquotes for [code formatting](https://help.github.com/articles/creating-and-highlighting-code-blocks/)) -```cpp - -//Change the code below by your sketch -#include - -void setup() { -} - -void loop() { -} -``` - -### Debug Messages: -``` -Enable Core debug level: Debug on tools menu of Arduino IDE, then put the serial output here -``` diff --git a/docs/source/api/i2c.rst b/docs/source/api/i2c.rst index 4c690488e28..f53d8f27a3c 100644 --- a/docs/source/api/i2c.rst +++ b/docs/source/api/i2c.rst @@ -381,4 +381,4 @@ Here is an example of how to use the I2C in Slave Mode. .. literalinclude:: ../../../libraries/Wire/examples/WireSlave/WireSlave.ino :language: arduino -.. _Arduino Wire Library: https://www.arduino.cc/en/reference/wire \ No newline at end of file +.. _Arduino Wire Library: https://www.arduino.cc/en/reference/wire diff --git a/docs/source/api/i2s.rst b/docs/source/api/i2s.rst new file mode 100644 index 00000000000..02539fb3f2b --- /dev/null +++ b/docs/source/api/i2s.rst @@ -0,0 +1,566 @@ +### +I2S +### + +About +----- + +I2S - Inter-IC Sound, correctly written I²S pronounced "eye-squared-ess", alternative notation is IIS. I²S is an electrical serial bus interface standard used for connecting digital audio devices together. + +It is used to communicate PCM (Pulse-Code Modulation) audio data between integrated circuits in an electronic device. The I²S bus separates clock and serial data signals, resulting in simpler receivers than those required for asynchronous communications systems that need to recover the clock from the data stream. + +Despite the similar name, I²S is unrelated and incompatible with the bidirectional I²C (IIC) bus. + +The I²S bus consists of at least three lines: + +.. note:: All lines can be attached to almost any pin and this change can occur even during operation. + +* **Bit clock line** + + * Officially "continuous serial clock (SCK)". Typically written "bit clock (BCLK)". + * In this library function parameter ``sckPin`` or constant ``PIN_I2S_SCK``. + +* **Word clock line** + + * Officially "word select (WS)". Typically called "left-right clock (LRCLK)" or "frame sync (FS)". + * 0 = Left channel, 1 = Right channel + * In this library function parameter ``fsPin`` or constant ``PIN_I2S_FS``. + +* **Data line** + + * Officially "serial data (SD)", but can be called SDATA, SDIN, SDOUT, DACDAT, ADCDAT, etc. + * Unlike Arduino I2S with single data pin switching between input and output, in ESP core driver use separate data line for input and output. + * For backward compatibility, the shared data pin is ``sdPin`` or constant ``PIN_I2S_SD`` when using simplex mode. + + * When using in duplex mode, there are two data lines: + + * Output data line is called ``outSdPin`` for function parameter, or constant ``PIN_I2S_SD_OUT`` + * Input data line is called ``inSdPin`` for function parameter, or constant ``PIN_I2S_SD_IN`` + +I2S Modes +--------- + +The I2S can be set up in three groups of modes: + +* Master (default) or Slave. +* Simplex (default) or Duplex. +* Operation modes (Philips standard, ADC/DAC, PDM) + + * Most of them are dual-channel, some can be single channel + +.. note:: Officially supported operation mode is only ``I2S_PHILIPS_MODE``. Other modes are implemented, but we cannot guarantee flawless execution and behavior. + +Master / Slave Mode +******************* + +In **Master mode** (default) the device is generating clock signal ``sckPin`` and word select signal on ``fsPin``. + +In **Slave mode** the device listens on attached pins for the clock signal and word select - i.e. unless externally driven the pins will remain LOW. + +How to enter either mode is described in the function section. + +Operation Modes +*************** + +Setting the operation mode is done with function ``begin`` (see API section) + +* ``I2S_PHILIPS_MODE`` + * Currently the only official* ``PIN_I2S_SCK`` +* ``PIN_I2S_FS`` +* ``PIN_I2S_SD`` +* ``PIN_I2S_SD_OUT`` only need to send one channel data but the data will be copied for another channel automatically, then both channels will transmit same data. + +* ``ADC_DAC_MODE`` + The output will be an analog signal on pins ``25`` (L or R?) and ``26`` (L or R?). + Input will be received on pin ``_inSdPin``. + The data are sampled in 12 bits and stored in a 16 bits, with the 4 most significant bits set to zero. + +* ``PDM_STEREO_MODE`` + Pulse-density-modulation is similar to PWM, but instead, the pulses have constant width. The signal is modulated with the number of ones or zeroes in sequence. + +* ``PDM_MONO_MODE`` + Single-channel version of PDM mode described above. + +Simplex / Duplex Mode +********************* + +The **Simplex** mode is the default after driver initialization. Simplex mode uses the shared data pin ``sdPin`` or constant ``PIN_I2S_SD`` for both output and input, but can only read or write. This is the same behavior as in original Arduino library. + +The **Duplex** mode uses two separate data pins: + +* Output pin ``outSdPin`` for function parameter, or constant ``PIN_I2S_SD_OUT`` +* Input pin ``inSdPin`` for function parameter, or constant ``PIN_I2S_SD_IN`` + +In this mode, the driver is able to read and write simultaneously on each line and is suitable for applications like walkie-talkie or phone. + +Switching between these modes is performed simply by calling setDuplex() or setSimplex() (see APi section for details and more functions). + +Arduino-ESP32 I2S API +--------------------- + +The ESP32 I2S library is based on the Arduino I2S Library and implements a few more APIs, described in this `documentation `_. + +Initialization and deinitialization +*********************************** + +Before initialization, choose which pins you want to use. In DAC mode you can use only pins `25` and `26` for the output. + +begin (Master Mode) +^^^^^^^^^^^^^^^^^^^ + +Before usage choose which pins you want to use. In DAC mode you can use only pins 25 and 26 as output. + +.. code-block:: arduino + + int begin(int mode, int sampleRate, int bitsPerSample) + +Parameters: + +* [in] ``mode`` one of above mentioned operation mode, for example ``I2S_PHILIPS_MODE``. + +* [in] ``sampleRate`` is the sampling rate in Hz. Currently officially supported value is only 16000 - other than this value will print warning, but continue to operate, however the resulting audio quality may suffer and the app may crash. + +* [in] ``bitsPerSample`` is the number of bits in a channel sample. + +Currently, the supported value is only 16 - other than this value will print a warning, but continues to operate, however, the resulting audio quality may suffer and the application may crash. + +For ``ADC_DAC_MODE`` the only possible value will remain 16. + +This function will return ``true`` on success or ``fail`` in case of failure. + +When failed, an error message will be printed if subscribed. + +begin (Slave Mode) +^^^^^^^^^^^^^^^^^^ + +Performs initialization before use - creates buffers, task handling underlying driver messages, configuring and starting the driver operation. + +This version initializes I2S in SLAVE mode (see previous entry for MASTER mode). + +.. code-block:: arduino + + int begin(int mode, int bitsPerSample) + +Parameters: + +* [in] ``mode`` one of above mentioned modes for example ``I2S_PHILIPS_MODE``. + +* [in] ``bitsPerSample`` is the umber of bits in a channel sample. Currently, the only supported value is only 16 - other than this value will print warning, but continue to operate, however the resulting audio quality may suffer and the app may crash. + +For ``ADC_DAC_MODE`` the only possible value will remain 16. + +This function will return ``true`` on success or ``fail`` in case of failure. + +When failed, an error message will be printed if subscribed. + +end +^^^ + +Performs safe deinitialization - free buffers, destroy task, end driver operation, etc. + +.. code-block:: arduino + + void end() + +Pin setup +********* + +Pins can be changed in two ways- 1st constants, 2nd functions. + +.. note:: Shared data pin can be equal to any other data pin, but must not be equal to clock pin nor frame sync pin! Input and Output pins must not be equal, but one of them can be equal to shared data pin! + +.. code-block:: arduino + + sckPin != fsPin != outSdPin != inSdPin + +.. code-block:: arduino + + sckPin != fsPin != sdPin + +By default, the pin numbers are defined in constants in the header file. You can redefine any of those constants before including ``I2S.h``. This way the driver will use these new default values and you will not need to specify pins in your code. The constants and their default values are: + +* ``PIN_I2S_SCK`` 14 +* ``PIN_I2S_FS`` 25 +* ``PIN_I2S_SD`` 26 +* ``PIN_I2S_SD_OUT`` 26 +* ``PIN_I2S_SD_IN`` 35 + +The second option to change pins is using the following functions. These functions can be called on either on initialized or uninitialized object. + +If called on the initialized object (after calling ``begin``) the pins will change during operation. +If called on the uninitialized object (before calling ``begin``, or after calling ``end``) the new pin setup will be used on next initialization. + +setSckPin +^^^^^^^^^ + +Set and apply clock pin. + +.. code-block:: arduino + + int setSckPin(int sckPin) + +This function will return ``true`` on success or ``fail`` in case of failure. + +setFsPin +^^^^^^^^ + +Set and apply frame sync pin. + +.. code-block:: arduino + + int setFsPin(int fsPin) + +This function will return ``true`` on success or ``fail`` in case of failure. + +setDataPin +^^^^^^^^^^ + +Set and apply shared data pin used in simplex mode. + +.. code-block:: arduino + + int setDataPin(int sdPin) + +This function will return ``true`` on success or ``fail`` in case of failure. + +setDataInPin +^^^^^^^^^^^^ + +Set and apply data input pin. + +.. code-block:: arduino + + int setDataInPin(int inSdPin) + +This function will return ``true`` on success or ``fail`` in case of failure. + +setDataOutPin +^^^^^^^^^^^^^ + +Set and apply data output pin. + +.. code-block:: arduino + + int setDataOutPin(int outSdPin) + +This function will return ``true`` on success or ``fail`` in case of failure. + +setAllPins +^^^^^^^^^^ + +Set all pins using given values in parameters. This is simply a wrapper of four functions mentioned above. + +.. code-block:: arduino + + int setAllPins(int sckPin, int fsPin, int sdPin, int outSdPin, int inSdPin) + +Set all pins to default i.e. take values from constants mentioned above. This simply calls the the function with the following constants. + +* ``PIN_I2S_SCK`` 14 +* ``PIN_I2S_FS`` 25 +* ``PIN_I2S_SD`` 26 +* ``PIN_I2S_SD_OUT`` 26 +* ``PIN_I2S_SD_IN`` 35 + +.. code-block:: arduino + + int setAllPins() + +getSckPin +^^^^^^^^^ + +Get the current value of the clock pin. + +.. code-block:: arduino + + int getSckPin() + +getFsPin +^^^^^^^^ + +Get the current value of frame sync pin. + +.. code-block:: arduino + + int getFsPin() + +getDataPin +^^^^^^^^^^ + +Get the current value of shared data pin. + +.. code-block:: arduino + + int getDataPin() + +getDataInPin +^^^^^^^^^^^^ + +Get the current value of data input pin. + +.. code-block:: arduino + + int getDataInPin() + +getDataOutPin +^^^^^^^^^^^^^ + +Get the current value of data output pin. + +.. code-block:: arduino + + int getDataOutPin() + +onTransmit +^^^^^^^^^^ + +Register the function to be called on each successful transmit event. + +.. code-block:: arduino + + void onTransmit(void(*)(void)) + +onReceive +^^^^^^^^^ + +Register the function to be called on each successful receives event. + +.. code-block:: arduino + + void onReceive(void(*)(void)) + +setBufferSize +^^^^^^^^^^^^^ + +Set the size of buffer. + +.. code-block:: arduino + + int setBufferSize(int bufferSize) + +This function can be called on both the initialized or uninitialized driver. + +If called on initialized, it will change internal values for buffer size and re-initialize driver with new value. +If called on uninitialized, it will only change the internal values which will be used for next initialization. + +Parameter ``bufferSize`` must be in range from 8 to 1024 and the unit is sample words. The default value is 128. + +Example: 16 bit sample, dual channel, buffer size for input: + + ``128 = 2B sample * 2 channels * 128 buffer size * buffer count (default 2) = 1024B`` + +And more ```1024B`` for output buffer in total of ``2kB`` used. + +This function always assumes dual-channel, keeping the same size even for MONO modes. + +This function will return ``true`` on success or ``fail`` in case of failure. + +When failed, an error message will be printed. + +getBufferSize +^^^^^^^^^^^^^ + +Get current buffer sizes in sample words (see description for ``setBufferSize``). + +.. code-block:: arduino + + int getBufferSize() + +Duplex vs Simplex +***************** + +Original Arduino I2S library supports only *simplex* mode (only transmit or only receive at a time). For compatibility, we kept this behavior, but ESP natively supports *duplex* mode (receive and transmit simultaneously on separate pins). +By default this library is initialized in simplex mode as it would in Arduino, switching input and output on ``sdPin`` (constant ``PIN_I2S_SD`` default pin 26). + +setDuplex +^^^^^^^^^ + +Switch to duplex mode and use separate pins: + +.. code-block:: arduino + + int setDuplex() + +input: inSdPin (constant PIN_I2S_SD_IN, default 35) +output: outSdPin (constant PIN_I2S_SD, default 26) + +setSimplex +^^^^^^^^^^ + +(Default mode) + +Switch to simplex mode using shared data pin sdPin (constant PIN_I2S_SD, default 26). + +.. code-block:: arduino + + int setSimplex() + +isDuplex +^^^^^^^^ + +Returns 1 if current mode is duplex, 0 if current mode is simplex (default). + +.. code-block:: arduino + + int isDuplex() + +Data stream +*********** + +available +^^^^^^^^^ + +Returns number of **bytes** ready to read. + +.. code-block:: arduino + + int available() + +read +^^^^ + +Read ``size`` bytes from internal buffer if possible. + +.. code-block:: arduino + + int read(void* buffer, size_t size) + +This function is non-blocking, i.e. if the requested number of bytes is not available, it will return as much as possible without waiting. + +Hint: use ``available()`` before calling this function. + +Parameters: + +[out] ``void* buffer`` buffer into which will be copied data read from internal buffer. WARNING: this buffer must be allocated before use! + +[in] ``size_t size`` number of bytes required to be read. + +Returns number of successfully bytes read. Returns ``false``` in case of reading error. + +Read one sample. + +.. code-block:: arduino + + int read() + +peek +^^^^ + +Read one sample from the internal buffer and returns it. + +.. code-block:: arduino + + int peek() + +Repeated peeks will be returned in the same sample until ``read`` is called. + +flush +^^^^^ + +Force write internal buffer to driver. + +.. code-block:: arduino + + void flush() + +write +^^^^^ + +Write a single byte. + +.. code-block:: arduino + + size_t write(uint8_t) + +Single-sample writes are blocking - waiting until there is free space in the internal buffer to be written into. + +Returns number of successfully written bytes, in this case, 1. Returns 0 on error. + +Write single sample. + +.. code-block:: arduino + + size_t write(int32_t) + +Single-sample writes are blocking - waiting until there is free space in the internal buffer to be written into. + +Returns number of successfully written bytes. Returns 0 on error. + +Expected return number is ``bitsPerSample/8``. + +Write buffer of supplied size; + +.. code-block:: arduino + + size_t write(const void *buffer, size_t size) + +Parameters: + +[in] ``const void *buffer`` buffer to be written +[in] ``size_t size`` size of buffer in bytes + +Returns number of successfully written bytes. Returns 0 in case of error. +The expected return number is equal to ``size``. + +write +^^^^^ + +This is a wrapper of the previous function performing typecast from `uint8_t*`` to ``void*``. + +.. code-block:: arduino + + size_t write(const uint8_t *buffer, size_t size) + +availableForWrite +^^^^^^^^^^^^^^^^^ + +Returns number of bytes available for write. + +.. code-block:: arduino + + int availableForWrite() + +write_blocking +^^^^^^^^^^^^^^ + +Core function implementing blocking write, i.e. waits until all requested data are written. + +.. code-block:: arduino + + size_t write_blocking(const void *buffer, size_t size) + +WARNING: If too many bytes are requested, this can cause WatchDog Trigger Reset! + +Returns number of successfully written bytes. Returns 0 on error. + +write_nonblocking +^^^^^^^^^^^^^^^^^ + +Core function implementing non-blocking write, i.e. writes as much as possible and exits. + +.. code-block:: arduino + + size_t write_nonblocking(const void *buffer, size_t size) + +Returns number of successfully written bytes. Returns 0 on error. + +Sample code +----------- + +.. code-block:: c + + #include + const int buff_size = 128; + int available, read; + uint8_t buffer[buff_size]; + + I2S.begin(I2S_PHILIPS_MODE, 16000, 16); + I2S.read(); // Switch the driver in simplex mode to receive + available = I2S.available(); + if(available < buff_size){ + read = I2S.read(buffer, available); + }else{ + read = I2S.read(buffer, buff_size); + } + I2S.write(buffer, read); + I2S.end(); diff --git a/docs/source/boards/boards.rst b/docs/source/boards/boards.rst index 12dbe4b175d..b0376f9c398 100644 --- a/docs/source/boards/boards.rst +++ b/docs/source/boards/boards.rst @@ -98,18 +98,13 @@ Generic Vendor .. note:: Create one file per board or one file with multiple boards. Do not add board information/description on this file. +.. include:: ../common/datasheet.inc + Resources --------- -* `ESP32 Datasheet`_ (Datasheet) -* `ESP32-S2 Datasheet`_ (Datasheet) -* `ESP32-C3 Datasheet`_ (Datasheet) - .. _Espressif Systems: https://www.espressif.com .. _Espressif Product Selector: https://products.espressif.com/ -.. _ESP32 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf -.. _ESP32-S2 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf -.. _ESP32-C3 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf .. |board_lolin_d32| raw:: html diff --git a/docs/source/boards/generic.rst b/docs/source/boards/generic.rst index 95bbcbeda4f..8ca4a79eace 100644 --- a/docs/source/boards/generic.rst +++ b/docs/source/boards/generic.rst @@ -26,9 +26,4 @@ Pin Layout Add here the pin layout image (not required). -Resources ---------- - -* `ESP32`_ (Datasheet) - -.. _ESP32: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf +.. include:: ../common/datasheet.inc diff --git a/docs/source/common/datasheet.inc b/docs/source/common/datasheet.inc new file mode 100644 index 00000000000..5f68b0115ff --- /dev/null +++ b/docs/source/common/datasheet.inc @@ -0,0 +1,13 @@ +Datasheet +--------- + +* `ESP32`_ (Datasheet) +* `ESP32-S2`_ (Datasheet) +* `ESP32-C3`_ (Datasheet) +* `ESP32-S3`_ (Datasheet) + +.. _Espressif Product Selector: https://products.espressif.com/ +.. _ESP32: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf +.. _ESP32-S2: https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf +.. _ESP32-C3: https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf +.. _ESP32-S3: https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf diff --git a/docs/source/conf.py b/docs/source/conf.py index 33b42328007..36d9fbf4286 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -18,11 +18,11 @@ # -- Project information ----------------------------------------------------- project = 'Arduino-ESP32' -copyright = '2021, Espressif' +copyright = '2022, Espressif' author = 'Espressif' # The full version, including alpha/beta/rc tags -release = '2.0.0' +release = '2.0.2' # -- General configuration --------------------------------------------------- diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 91b66b343a3..66c917283ad 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -34,10 +34,10 @@ Here are the ESP32 series supported by the Arduino-ESP32 project: ======== ====== =========== =================================== SoC Stable Development Datasheet ======== ====== =========== =================================== -ESP32 Yes Yes `ESP32 Datasheet`_ -ESP32-S2 Yes Yes `ESP32-S2 Datasheet`_ -ESP32-C3 Yes Yes `ESP32-C3 Datasheet`_ -ESP32-S3 No No `ESP32-S3 Datasheet`_ +ESP32 Yes Yes `ESP32`_ +ESP32-S2 Yes Yes `ESP32-S2`_ +ESP32-C3 Yes Yes `ESP32-C3`_ +ESP32-S3 No Yes `ESP32-S3`_ ======== ====== =========== =================================== See `Boards `_ for more details about ESP32 development boards. @@ -91,7 +91,9 @@ Before opening a new issue, please read this: Be sure to search for a similar reported issue. This avoids duplicating or creating noise in the GitHub Issues reporting. We also have the troubleshooting guide to save your time on the most common issues reported by users. -For more details, see the `Issue Template `_. +For more details about creating new Issue, see the `Issue Template `_. + +If you have any new idea, see the `Feature request Template `_. First Steps ----------- @@ -114,15 +116,14 @@ in the examples menu or inside each library folder. https://github.com/espressif/arduino-esp32/tree/master/libraries + +.. include:: common/datasheet.inc + Resources --------- .. _Espressif Systems: https://www.espressif.com .. _Espressif Product Selector: https://products.espressif.com/ -.. _ESP32 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf -.. _ESP32-S2 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf -.. _ESP32-C3 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf -.. _ESP32-S3 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf .. _Arduino.cc: https://www.arduino.cc/en/Main/Software .. _Arduino Reference: https://www.arduino.cc/reference/en/ .. _ESP32 Forum: https://esp32.com diff --git a/docs/source/index.rst b/docs/source/index.rst index 60d39d8442a..02f62c30290 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -8,7 +8,7 @@ Here you will find all the relevant information about the project. This is a work in progress documentation and we will appreciate your help! We are looking for contributors! .. toctree:: - :maxdepth: 2 + :maxdepth: 1 :caption: Contents: Getting Started diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index 12dd8cfd37f..d9febb08a1a 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -28,7 +28,7 @@ Currently, the Arduino ESP32 supports the following peripherals with Arduino API +---------------+---------------+---------------+---------------+-------------------------------+ | I2C | Yes | Yes | Yes | | +---------------+---------------+---------------+---------------+-------------------------------+ -| I2S | No | No | No | WIP | +| I2S | Yes | No | No | WIP | +---------------+---------------+---------------+---------------+-------------------------------+ | LEDC | Yes | Yes | Yes | | +---------------+---------------+---------------+---------------+-------------------------------+ @@ -64,12 +64,7 @@ Notes .. note:: Some peripherals are not available for all ESP32 families. To see more details about it, see the corresponding SoC at `Product Selector `_ page. -Datasheet -^^^^^^^^^ - -* `ESP32 `_ -* `ESP32-S2 `_ -* `ESP32-C3 `_ +.. include:: common/datasheet.inc APIs ---- @@ -78,13 +73,6 @@ The Arduino ESP32 offers some unique APIs, described in this section: .. toctree:: :maxdepth: 1 - - Bluetooth - Deep Sleep - ESPNOW - GPIO - I2C - RainMaker - Reset Reason - USB - Wi-Fi + :glob: + + api/* diff --git a/docs/source/tutorials/io_mux.rst b/docs/source/tutorials/io_mux.rst index 547be0e184b..8bdbb0799c3 100644 --- a/docs/source/tutorials/io_mux.rst +++ b/docs/source/tutorials/io_mux.rst @@ -62,7 +62,7 @@ JTAG Dedicated GPIOs SD/SDIO/MMC HostController Dedicated GPIOs Motor PWM Any GPIO SDIO/SPI SlaveController Dedicated GPIOs -UART Any GPIO +UART Any GPIO[1] I2C Any GPIO I2S Any GPIO LED PWM Any GPIO @@ -72,8 +72,11 @@ Parallel QSPI Dedicated GPIOs EMAC Dedicated GPIOs Pulse Counter Any GPIO TWAI Any GPIO +USB Dedicated GPIOs ============================== =================================== +[1] except for the download/programming mode decided by the bootloader. + This table is present on each datasheet provided by Espressif. Usage Examples @@ -106,16 +109,11 @@ To change the pins, we must call the ``Wire.setPins(int sda, int scl);`` functio A similar approach also applies for the other peripherals. +.. include:: ../common/datasheet.inc + Resources --------- -* `ESP32`_ (Datasheet) -* `ESP32-S2`_ (Datasheet) -* `ESP32-C3`_ (Datasheet) - .. _Espressif Systems: https://www.espressif.com .. _Espressif Product Selector: https://products.espressif.com/ -.. _ESP32: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf -.. _ESP32-S2: https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf -.. _ESP32-C3: https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf .. _IO MUX GPIO: https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf#iomuxgpio diff --git a/idf_component.yml b/idf_component.yml new file mode 100644 index 00000000000..9894a2ce923 --- /dev/null +++ b/idf_component.yml @@ -0,0 +1,21 @@ +description: "Arduino core for ESP32, ESP32-S and ESP32-C series of SoCs" +url: "https://github.com/espressif/arduino-esp32" +targets: + - esp32 + - esp32s2 + - esp32s3 + - esp32c3 +tags: + - arduino +files: + include: + - "cores/**/*" + - "variants/esp32/**/*" + - "variants/esp32s2/**/*" + - "variants/esp32s3/**/*" + - "variants/esp32c3/**/*" + - "libraries/**/*" + - "CMakeLists.txt" + - "Kconfig.projbuild" + exclude: + - "**/*" diff --git a/libraries/DNSServer/src/DNSServer.h b/libraries/DNSServer/src/DNSServer.h index a10ef9eaaf1..a8de0eff73b 100644 --- a/libraries/DNSServer/src/DNSServer.h +++ b/libraries/DNSServer/src/DNSServer.h @@ -66,8 +66,8 @@ struct DNSHeader struct DNSQuestion { - uint8_t QName[255] ; - int8_t QNameLength ; + uint8_t QName[256] ; //need 1 Byte for zero termination! + uint8_t QNameLength ; uint16_t QType ; uint16_t QClass ; } ; @@ -106,4 +106,4 @@ class DNSServer void replyWithIP(); void replyWithCustomCode(); }; -#endif \ No newline at end of file +#endif diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino b/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino index 44ff625bf05..515391c9785 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino +++ b/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino @@ -62,6 +62,7 @@ void setup() { config.frame_size = FRAMESIZE_SVGA; config.jpeg_quality = 12; config.fb_count = 1; + config.fb_location = CAMERA_FB_IN_DRAM; } #if defined(CAMERA_MODEL_ESP_EYE) diff --git a/libraries/RainMaker/examples/RMakerCustom/.skip.esp32c3 b/libraries/ESP32/examples/Touch/TouchButton/.skip.esp32c3 similarity index 100% rename from libraries/RainMaker/examples/RMakerCustom/.skip.esp32c3 rename to libraries/ESP32/examples/Touch/TouchButton/.skip.esp32c3 diff --git a/libraries/RainMaker/examples/RMakerCustom/.skip.esp32s2 b/libraries/ESP32/examples/Touch/TouchButton/.skip.esp32s2 similarity index 100% rename from libraries/RainMaker/examples/RMakerCustom/.skip.esp32s2 rename to libraries/ESP32/examples/Touch/TouchButton/.skip.esp32s2 diff --git a/libraries/RainMaker/examples/RMakerSonoffDualR3/.skip.esp32c3 b/libraries/ESP32/examples/Touch/TouchButton/.skip.esp32s3 similarity index 100% rename from libraries/RainMaker/examples/RMakerSonoffDualR3/.skip.esp32c3 rename to libraries/ESP32/examples/Touch/TouchButton/.skip.esp32s3 diff --git a/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino b/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino new file mode 100644 index 00000000000..b1dbc63fdcb --- /dev/null +++ b/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino @@ -0,0 +1,46 @@ +/* + +This is an example how to use Touch Intrrerupts +The sketh will tell when it is touched and then relesased as like a push-button + +This method based on touchInterruptSetThresholdDirection() is only available for ESP32 +*/ + +#include "Arduino.h" + +int threshold = 40; +bool touchActive = false; +bool lastTouchActive = false; +bool testingLower = true; + +void gotTouchEvent(){ + if (lastTouchActive != testingLower) { + touchActive = !touchActive; + testingLower = !testingLower; + // Touch ISR will be inverted: Lower <--> Higher than the Threshold after ISR event is noticed + touchInterruptSetThresholdDirection(testingLower); + } +} + +void setup() { + Serial.begin(115200); + delay(1000); // give me time to bring up serial monitor + Serial.println("ESP32 Touch Interrupt Test"); + touchAttachInterrupt(T2, gotTouchEvent, threshold); + + // Touch ISR will be activated when touchRead is lower than the Threshold + touchInterruptSetThresholdDirection(testingLower); +} + +void loop(){ + if(lastTouchActive != touchActive){ + lastTouchActive = touchActive; + if (touchActive) { + Serial.println(" ---- Touch was Pressed"); + } else { + Serial.println(" ---- Touch was Released"); + } + } + Serial.printf("T2 pin2 = %d \n", touchRead(T2)); + delay(125); +} diff --git a/libraries/RainMaker/examples/RMakerSonoffDualR3/.skip.esp32s2 b/libraries/ESP32/examples/Touch/TouchButtonV2/.skip.esp32 similarity index 100% rename from libraries/RainMaker/examples/RMakerSonoffDualR3/.skip.esp32s2 rename to libraries/ESP32/examples/Touch/TouchButtonV2/.skip.esp32 diff --git a/libraries/RainMaker/examples/RMakerSwitch/.skip.esp32c3 b/libraries/ESP32/examples/Touch/TouchButtonV2/.skip.esp32c3 similarity index 100% rename from libraries/RainMaker/examples/RMakerSwitch/.skip.esp32c3 rename to libraries/ESP32/examples/Touch/TouchButtonV2/.skip.esp32c3 diff --git a/libraries/ESP32/examples/Touch/TouchButtonV2/TouchButtonV2.ino b/libraries/ESP32/examples/Touch/TouchButtonV2/TouchButtonV2.ino new file mode 100644 index 00000000000..640fd2d3b59 --- /dev/null +++ b/libraries/ESP32/examples/Touch/TouchButtonV2/TouchButtonV2.ino @@ -0,0 +1,53 @@ +/* + +This is an example how to use Touch Intrrerupts +The sketh will tell when it is touched and then relesased as like a push-button + +This method based on touchInterruptGetLastStatus() is only available for ESP32 S2 and S3 +*/ + +#include "Arduino.h" + +int threshold = 1500; // ESP32S2 +bool touch1detected = false; +bool touch2detected = false; + +void gotTouch1() { + touch1detected = true; +} + +void gotTouch2() { + touch2detected = true; +} + +void setup() { + Serial.begin(115200); + delay(1000); // give me time to bring up serial monitor + + Serial.println("\n ESP32 Touch Interrupt Test\n"); + touchAttachInterrupt(T1, gotTouch1, threshold); + touchAttachInterrupt(T2, gotTouch2, threshold); +} + +void loop() { + static uint32_t count = 0; + + if (touch1detected) { + touch1detected = false; + if (touchInterruptGetLastStatus(T1)) { + Serial.println(" --- T1 Touched"); + } else { + Serial.println(" --- T1 Released"); + } + } + if (touch2detected) { + touch2detected = false; + if (touchInterruptGetLastStatus(T2)) { + Serial.println(" --- T2 Touched"); + } else { + Serial.println(" --- T2 Released"); + } + } + + delay(80); +} diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index a7bf13e89f5..ca8969a33a2 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -255,7 +255,7 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol) _protocol = url.substring(0, index); if (_protocol != expectedProtocol) { - log_w("unexpected protocol: %s, expected %s", _protocol.c_str(), expectedProtocol); + log_d("unexpected protocol: %s, expected %s", _protocol.c_str(), expectedProtocol); return false; } diff --git a/libraries/HTTPClient/src/HTTPClient.h b/libraries/HTTPClient/src/HTTPClient.h index 1bb84d6d6b5..fb6a7d4db87 100644 --- a/libraries/HTTPClient/src/HTTPClient.h +++ b/libraries/HTTPClient/src/HTTPClient.h @@ -27,7 +27,9 @@ #ifndef HTTPClient_H_ #define HTTPClient_H_ +#ifndef HTTPCLIENT_1_1_COMPATIBLE #define HTTPCLIENT_1_1_COMPATIBLE +#endif #include #include diff --git a/libraries/RainMaker/examples/RMakerSwitch/.skip.esp32s2 b/libraries/I2S/examples/ADCPlotter/.skip.esp32c3 similarity index 100% rename from libraries/RainMaker/examples/RMakerSwitch/.skip.esp32s2 rename to libraries/I2S/examples/ADCPlotter/.skip.esp32c3 diff --git a/libraries/I2S/examples/ADCPlotter/ADCPlotter.ino b/libraries/I2S/examples/ADCPlotter/ADCPlotter.ino new file mode 100644 index 00000000000..5f3bd93ca9d --- /dev/null +++ b/libraries/I2S/examples/ADCPlotter/ADCPlotter.ino @@ -0,0 +1,86 @@ +/* + This example is only for ESP devices. + + This example demonstrates usage of integrated Digital to Analog Converter (DAC) + You can display sound wave from audio device, or just measure voltage. + + To display audio prepare circuit found in following link or drafted as ASCII art + https://forum.arduino.cc/index.php?topic=567581.0 + (!) Note that unlike in the link we are connecting the supply line to 3.3V (not 5V) + because ADC can measure only up to around 3V. Anything above 3V will be very inaccurate. + + ^ +3.3V + | + _ + | |10k + |_| + | | |10uF + GPIO34-------------*------------| |----------- line in +(Default ADC pin) | +| | + | + _ + | |10k + |_| + | + | + V GND + +Connect hot wire of your audio to Line in and GNd wire of audio cable to common ground (GND) + +Second option to measure voltage on trimmer / potentiometer has following connection + ^ +3.3V + | + _ + | | + GPIO34----------->| | +(Default ADC pin) |_| + | + | + _ + | | optional resistor + |_| + | + | + V GND + Optional resistor will decrease read value. + + Steps to run: + 1. Select target board: + Tools -> Board -> ESP32 Arduino -> your board + 2. Upload sketch + Press upload button (arrow in top left corner) + When you see in console line like this: "Connecting........_____.....__" + On your board press and hold Boot button and press EN button shortly. Now you can release both buttons. + You should see lines like this: "Writing at 0x00010000... (12 %)" with rising percentage on each line. + If this fails, try the board buttons right after pressing upload button, or reconnect the USB cable. + 3. Open plotter + Tools -> Serial Plotter + Enjoy + +Created by Tomas Pilny +on 17th June 2021 +*/ + +#include + +void setup() { + // Open serial communications and wait for port to open: + // A baud rate of 115200 is used instead of 9600 for a faster data rate + // on non-native USB ports + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start I2S at 8 kHz with 32-bits per sample + if (!I2S.begin(ADC_DAC_MODE, 8000, 16)) { + Serial.println("Failed to initialize I2S!"); + while (1); // do nothing + } +} + +void loop() { + // read a sample + int sample = I2S.read(); + Serial.println(sample); +} diff --git a/libraries/I2S/examples/FullDuplex/.skip.esp32c3 b/libraries/I2S/examples/FullDuplex/.skip.esp32c3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/I2S/examples/FullDuplex/FullDuplex.ino b/libraries/I2S/examples/FullDuplex/FullDuplex.ino new file mode 100644 index 00000000000..9b3625fbd60 --- /dev/null +++ b/libraries/I2S/examples/FullDuplex/FullDuplex.ino @@ -0,0 +1,59 @@ +/* + This example is only for ESP + This example demonstrates simultaneous usage of microphone and speaker using single I2S module. + The application transfers data from input to output + + Circuit: + * ESP32 + * GND connected GND + * VIN connected 5V + * SCK 5 + * FS 25 + * DIN 35 + * DOUT 26 + * I2S microphone + * I2S decoder + headphones / speaker + + created 8 October 2021 + by Tomas Pilny + */ + +#include +const long sampleRate = 16000; +const int bitsPerSample = 32; +uint8_t *buffer; + +void setup() { + Serial.begin(115200); + //I2S.setAllPins(5, 25, 35, 26); // you can change default pins; order of pins = (CLK, WS, IN, OUT) + if(!I2S.setDuplex()){ + Serial.println("ERROR - could not set duplex"); + while(true){ + vTaskDelay(10); // Cannot continue + } + } + if (!I2S.begin(I2S_PHILIPS_MODE, sampleRate, bitsPerSample)) { + Serial.println("Failed to initialize I2S!"); + while(true){ + vTaskDelay(10); // Cannot continue + } + } + buffer = (uint8_t*) malloc(I2S.getBufferSize() * (bitsPerSample / 8)); + if(buffer == NULL){ + Serial.println("Failed to allocate buffer!"); + while(true){ + vTaskDelay(10); // Cannot continue + } + } + Serial.println("Setup done"); +} + +void loop() { + //I2S.write(I2S.read()); // primitive implementation sample-by-sample + + // Buffer based implementation + I2S.read(buffer, I2S.getBufferSize() * (bitsPerSample / 8)); + I2S.write(buffer, I2S.getBufferSize() * (bitsPerSample / 8)); + + //optimistic_yield(1000); // yield if last yield occurred before CPU clock cycles ago +} diff --git a/libraries/I2S/examples/InputSerialPlotter/.skip.esp32c3 b/libraries/I2S/examples/InputSerialPlotter/.skip.esp32c3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino b/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino new file mode 100644 index 00000000000..db9f7d0d4f8 --- /dev/null +++ b/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino @@ -0,0 +1,44 @@ +/* + This example reads audio data from an Invensense's ICS43432 I2S microphone + breakout board, and prints out the samples to the Serial console. The + Serial Plotter built into the Arduino IDE can be used to plot the audio + data (Tools -> Serial Plotter) + + Circuit: + * Arduino/Genuino Zero, MKR family and Nano 33 IoT + * ICS43432: + * GND connected GND + * 3.3V connected to 3.3V (Zero, Nano, ESP32), VCC (MKR) + * WS connected to pin 0 (Zero) or 3 (MKR), A2 (Nano) or 25 (ESP32) + * CLK connected to pin 1 (Zero) or 2 (MKR), A3 (Nano) or 5 (ESP32) + * SD connected to pin 9 (Zero) or A6 (MKR), 4 (Nano) or 26 (ESP32) + created 17 November 2016 + by Sandeep Mistry + */ + +#include + +void setup() { + // Open serial communications and wait for port to open: + // A baud rate of 115200 is used instead of 9600 for a faster data rate + // on non-native USB ports + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start I2S at 8 kHz with 32-bits per sample + if (!I2S.begin(I2S_PHILIPS_MODE, 8000, 32)) { + Serial.println("Failed to initialize I2S!"); + while (1); // do nothing + } +} + +void loop() { + // read a sample + int sample = I2S.read(); + + if (sample && sample != -1 && sample != 1) { + Serial.println(sample); + } +} diff --git a/libraries/I2S/examples/SimpleTone/.skip.esp32c3 b/libraries/I2S/examples/SimpleTone/.skip.esp32c3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/I2S/examples/SimpleTone/SimpleTone.ino b/libraries/I2S/examples/SimpleTone/SimpleTone.ino new file mode 100644 index 00000000000..dd312cf8a82 --- /dev/null +++ b/libraries/I2S/examples/SimpleTone/SimpleTone.ino @@ -0,0 +1,79 @@ +/* + This example generates a square wave based tone at a specified frequency + and sample rate. Then outputs the data using the I2S interface to a + MAX08357 I2S Amp Breakout board. + + I2S Circuit: + * Arduino/Genuino Zero, MKR family and Nano 33 IoT + * MAX08357: + * GND connected GND + * VIN connected 5V + * LRC connected to pin 0 (Zero) or 3 (MKR), A2 (Nano) or 25 (ESP32) + * BCLK connected to pin 1 (Zero) or 2 (MKR), A3 (Nano) or 5 (ESP32) + * DIN connected to pin 9 (Zero) or A6 (MKR), 4 (Nano) or 26 (ESP32) + + DAC Circuit: + * ESP32 or ESP32-S2 + * Audio amplifier + - Note: + - ESP32 has DAC on GPIO pins 25 and 26. + - ESP32-S2 has DAC on GPIO pins 17 and 18. + - Connect speaker(s) or headphones. + + created 17 November 2016 + by Sandeep Mistry + For ESP extended + Tomas Pilny + 2nd September 2021 + */ + +#include +const int frequency = 440; // frequency of square wave in Hz +const int amplitude = 500; // amplitude of square wave +const int sampleRate = 8000; // sample rate in Hz +const int bps = 16; + +const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave + +short sample = amplitude; // current sample value +int count = 0; + +i2s_mode_t mode = I2S_PHILIPS_MODE; // I2S decoder is needed +// i2s_mode_t mode = ADC_DAC_MODE; // Audio amplifier is needed + +// Mono channel input +// This is ESP specific implementation - +// samples will be automatically copied to both channels inside I2S driver +// If you want to have true mono output use I2S_PHILIPS_MODE and interlay +// second channel with 0-value samples. +// The order of channels is RIGH followed by LEFT +//i2s_mode_t mode = I2S_RIGHT_JUSTIFIED_MODE; // I2S decoder is needed + +void setup() { + Serial.begin(115200); + Serial.println("I2S simple tone"); + + // start I2S at the sample rate with 16-bits per sample + if (!I2S.begin(mode, sampleRate, bps)) { + Serial.println("Failed to initialize I2S!"); + while (1); // do nothing + } +} + +void loop() { + if (count % halfWavelength == 0 ) { + // invert the sample every half wavelength count multiple to generate square wave + sample = -1 * sample; + } + + if(mode == I2S_PHILIPS_MODE || mode == ADC_DAC_MODE){ // write the same sample twice, once for Right and once for Left channel + I2S.write(sample); // Right channel + I2S.write(sample); // Left channel + }else if(mode == I2S_RIGHT_JUSTIFIED_MODE || mode == I2S_LEFT_JUSTIFIED_MODE){ + // write the same only once - it will be automatically copied to the other channel + I2S.write(sample); + } + + // increment the counter for the next sample + count++; +} diff --git a/libraries/I2S/keywords.txt b/libraries/I2S/keywords.txt new file mode 100644 index 00000000000..ad1b8028d42 --- /dev/null +++ b/libraries/I2S/keywords.txt @@ -0,0 +1,61 @@ +####################################### +# Syntax Coloring Map I2S +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +I2S KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +I2SClass KEYWORD2 +begin KEYWORD2 +end KEYWORD2 + +onReceive KEYWORD2 +onTransmit KEYWORD2 + +setSckPin KEYWORD2 +setFsPin KEYWORD2 +setDataInPin KEYWORD2 +setDataOutPin KEYWORD2 +setAllPins KEYWORD2 + +getSckPin KEYWORD2 +getFsPin KEYWORD2 +getDataPin KEYWORD2 +getDataInPin KEYWORD2 +getDataOutPin KEYWORD2 + +setDuplex KEYWORD2 +setSimplex KEYWORD2 +isDuplex KEYWORD2 + +setBufferSize KEYWORD2 +getBufferSize KEYWORD2 + +write KEYWORD2 +availableForWrite KEYWORD2 + +read KEYWORD2 +available KEYWORD2 + +gpioToAdcUnit KEYWORD2 +gpioToAdcChannel KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### +I2S_PHILIPS_MODE LITERAL1 +I2S_RIGHT_JUSTIFIED_MODE LITERAL1 +I2S_LEFT_JUSTIFIED_MODE LITERAL1 +I2S_ADC_DAC LITERAL1 +I2S_PDM LITERAL1 + +PIN_I2S_SCK LITERAL1 +PIN_I2S_FS LITERAL1 +PIN_I2S_SD LITERAL1 +PIN_I2S_SD_OUT LITERAL1 diff --git a/libraries/I2S/library.properties b/libraries/I2S/library.properties new file mode 100644 index 00000000000..bb77e306158 --- /dev/null +++ b/libraries/I2S/library.properties @@ -0,0 +1,9 @@ +name=I2S +version=1.0 +author=Tomas Pilny +maintainer=Tomas Pilny +sentence=Enables the communication with devices that use the Inter-IC Sound (I2S) Bus. Specific implementation for ESP. +paragraph= +category=Communication +url=http://www.arduino.cc/en/Reference/I2S +architectures=esp32 diff --git a/libraries/I2S/src/I2S.cpp b/libraries/I2S/src/I2S.cpp new file mode 100644 index 00000000000..393052c136f --- /dev/null +++ b/libraries/I2S/src/I2S.cpp @@ -0,0 +1,1209 @@ +/* + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include +#include "I2S.h" +#include "freertos/semphr.h" + +#define _I2S_EVENT_QUEUE_LENGTH 16 +#define _I2S_DMA_BUFFER_COUNT 2 // BUFFER COUNT must be between 2 and 128 +#define I2S_INTERFACES_COUNT SOC_I2S_NUM + +#ifndef I2S_DEVICE + #define I2S_DEVICE 0 +#endif + +#ifndef I2S_CLOCK_GENERATOR + #define I2S_CLOCK_GENERATOR 0 // does nothing for ESP +#endif + +I2SClass::I2SClass(uint8_t deviceIndex, uint8_t clockGenerator, uint8_t sdPin, uint8_t sckPin, uint8_t fsPin) : + _deviceIndex(deviceIndex), + _sdPin(sdPin), // shared data pin + _inSdPin(PIN_I2S_SD_IN), // input data pin + _outSdPin(PIN_I2S_SD), // output data pin + _sckPin(sckPin), // clock pin + _fsPin(fsPin), // frame (word) select pin + + _state(I2S_STATE_IDLE), + _bitsPerSample(0), + _sampleRate(0), + _mode(I2S_PHILIPS_MODE), + + _buffer_byte_size(0), + + _driverInstalled(false), + _initialized(false), + _callbackTaskHandle(NULL), + _i2sEventQueue(NULL), + _i2s_general_mutex(NULL), + _input_ring_buffer(NULL), + _output_ring_buffer(NULL), + _i2s_dma_buffer_size(128), // Number of frames in each DMA buffer. Frame size = number of channels * Bytes per sample; Must be between 8 and 1024 + _driveClock(true), + _peek_buff(0), + _peek_buff_valid(false), + _nesting_counter(0), + + _onTransmit(NULL), + _onReceive(NULL) +{ + _i2s_general_mutex = xSemaphoreCreateMutex(); + if(_i2s_general_mutex == NULL){ + log_e("I2S could not create internal mutex!"); + } +} + +int I2SClass::_createCallbackTask(){ + int stack_size = 20000; + if(_callbackTaskHandle != NULL){ + log_e("Callback task already exists!"); + return 0; // ERR + } + + xTaskCreate( + onDmaTransferComplete, // Function to implement the task + "onDmaTransferComplete", // Name of the task + stack_size, // Stack size in words + NULL, // Task input parameter + 2, // Priority of the task + &_callbackTaskHandle // Task handle. + ); + if(_callbackTaskHandle == NULL){ + log_e("Could not create callback task"); + return 0; // ERR + } + return 1; // OK +} + +int I2SClass::_installDriver(){ + if(_driverInstalled){ + log_e("I2S driver is already installed"); + return 0; // ERR + } + + esp_i2s::i2s_mode_t i2s_mode = (esp_i2s::i2s_mode_t)(esp_i2s::I2S_MODE_RX | esp_i2s::I2S_MODE_TX); + + if(_driveClock){ + i2s_mode = (esp_i2s::i2s_mode_t)(i2s_mode | esp_i2s::I2S_MODE_MASTER); + }else{ + i2s_mode = (esp_i2s::i2s_mode_t)(i2s_mode | esp_i2s::I2S_MODE_SLAVE); + } + + if(_mode == ADC_DAC_MODE){ + #if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + if(_bitsPerSample != 16){ // ADC/DAC can only work in 16-bit sample mode + log_e("ERROR invalid bps for ADC/DAC. Allowed only 16, requested %d", _bitsPerSample); + return 0; // ERR + } + i2s_mode = (esp_i2s::i2s_mode_t)(i2s_mode | esp_i2s::I2S_MODE_DAC_BUILT_IN | esp_i2s::I2S_MODE_ADC_BUILT_IN); + #else + log_e("This chip does not support ADC / DAC mode"); + return 0; // ERR + #endif + }else if(_mode == I2S_PHILIPS_MODE || + _mode == I2S_RIGHT_JUSTIFIED_MODE || + _mode == I2S_LEFT_JUSTIFIED_MODE){ // End of ADC/DAC mode; start of Normal Philips mode + if(_bitsPerSample != 8 && _bitsPerSample != 16 && _bitsPerSample != 24 && _bitsPerSample != 32){ + log_e("Invalid bits per sample for normal mode (requested %d)\nAllowed bps = 8 | 16 | 24 | 32", _bitsPerSample); + return 0; // ERR + } + if(_bitsPerSample == 24){ + log_w("Original Arduino library does not support 24 bits per sample.\nKeep that in mind if you should switch back to Arduino"); + } + }else if(_mode == PDM_STEREO_MODE || _mode == PDM_MONO_MODE){ // end of Normal Philips mode; start of PDM mode + #if (SOC_I2S_SUPPORTS_PDM_TX && SOC_I2S_SUPPORTS_PDM_RX) + i2s_mode = (esp_i2s::i2s_mode_t)(i2s_mode | esp_i2s::I2S_MODE_PDM); + #else + log_e("This chip does not support PDM"); + return 0; // ERR + #endif + } // Mode + esp_i2s::i2s_config_t i2s_config = { + .mode = i2s_mode, + .sample_rate = _sampleRate, + .bits_per_sample = (esp_i2s::i2s_bits_per_sample_t)_bitsPerSample, + .channel_format = esp_i2s::I2S_CHANNEL_FMT_RIGHT_LEFT, + .communication_format = (esp_i2s::i2s_comm_format_t)(esp_i2s::I2S_COMM_FORMAT_STAND_I2S), + .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, + .dma_buf_count = _I2S_DMA_BUFFER_COUNT, + .dma_buf_len = _i2s_dma_buffer_size, + .use_apll = false + }; + + if(_driveClock == false){ + i2s_config.use_apll = true; + i2s_config.fixed_mclk = 512*_sampleRate; + } + + // Install and start i2s driver + while(ESP_OK != esp_i2s::i2s_driver_install((esp_i2s::i2s_port_t) _deviceIndex, &i2s_config, _I2S_EVENT_QUEUE_LENGTH, &_i2sEventQueue)){ + // increase buffer size + if(2*_i2s_dma_buffer_size <= 1024){ + log_w("WARNING i2s driver install failed.\nTrying to increase I2S DMA buffer size from %d to %d\n", _i2s_dma_buffer_size, 2*_i2s_dma_buffer_size); + setBufferSize(2*_i2s_dma_buffer_size); + }else if(_i2s_dma_buffer_size < 1024){ + log_w("WARNING i2s driver install failed.\nTrying to decrease I2S DMA buffer size from %d to 1024\n", _i2s_dma_buffer_size); + setBufferSize(1024); + }else{ // install failed with max buffer size + log_e("ERROR i2s driver install failed"); + return 0; // ERR + } + } //try installing with increasing size + + if(_mode == I2S_RIGHT_JUSTIFIED_MODE || _mode == I2S_LEFT_JUSTIFIED_MODE || _mode == PDM_MONO_MODE){ // mono/single channel + // Set the clock for MONO. Stereo is not supported yet. + if(ESP_OK != esp_i2s::i2s_set_clk((esp_i2s::i2s_port_t) _deviceIndex, _sampleRate, (esp_i2s::i2s_bits_per_sample_t)_bitsPerSample, esp_i2s::I2S_CHANNEL_MONO)){ + log_e("Setting the I2S Clock has failed!\n"); + return 0; // ERR + } + } // mono channel mode + +#if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + if(_mode == ADC_DAC_MODE){ + esp_i2s::i2s_set_dac_mode(esp_i2s::I2S_DAC_CHANNEL_BOTH_EN); + esp_i2s::adc_unit_t adc_unit; + if(!_gpioToAdcUnit((gpio_num_t)_inSdPin, &adc_unit)){ + log_e("pin to adc unit conversion failed"); + return 0; // ERR + } + esp_i2s::adc_channel_t adc_channel; + if(!_gpioToAdcChannel((gpio_num_t)_inSdPin, &adc_channel)){ + log_e("pin to adc channel conversion failed"); + return 0; // ERR + } + if(ESP_OK != esp_i2s::i2s_set_adc_mode(adc_unit, (esp_i2s::adc1_channel_t)adc_channel)){ + log_e("i2s_set_adc_mode failed"); + return 0; // ERR + } + if(ESP_OK != esp_i2s::i2s_set_pin((esp_i2s::i2s_port_t) _deviceIndex, NULL)){ + log_e("i2s_set_pin failed"); + return 0; // ERR + } + + if(adc_unit == esp_i2s::ADC_UNIT_1){ + esp_i2s::adc1_config_width(esp_i2s::ADC_WIDTH_BIT_12); + esp_i2s::adc1_config_channel_atten((esp_i2s::adc1_channel_t)adc_channel, esp_i2s::ADC_ATTEN_DB_11); + }else if(adc_unit == esp_i2s::ADC_UNIT_2){ + esp_i2s::adc2_config_channel_atten((esp_i2s::adc2_channel_t)adc_channel, esp_i2s::ADC_ATTEN_DB_11); + } + + esp_i2s::i2s_adc_enable((esp_i2s::i2s_port_t) _deviceIndex); + _driverInstalled = true; + }else // End of ADC/DAC mode +#endif // SOC_I2S_SUPPORTS_ADC_DAC + if(_mode == I2S_PHILIPS_MODE || _mode == I2S_RIGHT_JUSTIFIED_MODE || _mode == I2S_LEFT_JUSTIFIED_MODE || _mode == PDM_STEREO_MODE || _mode == PDM_MONO_MODE){ // if I2S mode + _driverInstalled = true; // IDF I2S driver must be installed before calling _applyPinSetting + if(!_applyPinSetting()){ + log_e("could not apply pin setting during driver install"); + _uninstallDriver(); + return 0; // ERR + } + } // if I2S _mode + return 1; // OK +} + +// Init in MASTER mode: the SCK and FS pins are driven as outputs using the sample rate +int I2SClass::begin(int mode, int sampleRate, int bitsPerSample){ + _take_if_not_holding(); + // master mode (driving clock and frame select pins - output) + int ret = begin(mode, sampleRate, bitsPerSample, true); + _give_if_top_call(); + return ret; +} + +// Init in SLAVE mode: the SCK and FS pins are inputs, other side controls sample rate +int I2SClass::begin(int mode, int bitsPerSample){ + _take_if_not_holding(); + // slave mode (not driving clock and frame select pin - input) + int ret = begin(mode, 96000, bitsPerSample, false); + _give_if_top_call(); + return ret; +} + + +// Core function +int I2SClass::begin(int mode, int sampleRate, int bitsPerSample, bool driveClock){ + _take_if_not_holding(); + if(_initialized){ + log_e("ERROR: Object already initialized! Call I2S.end() to disable"); + _give_if_top_call(); + return 0; // ERR + } + _driveClock = driveClock; + _mode = mode; + _sampleRate = (uint32_t)sampleRate; + _bitsPerSample = bitsPerSample; + + // There is work in progress on this library. + if(_bitsPerSample == 16 && _sampleRate > 16000 && driveClock){ + log_w("This sample rate is not officially supported - audio might be noisy.\nTry using sample rate below or equal to 16000"); + } + if(_bitsPerSample != 16){ + log_w("This bit-per-sample is not officially supported - audio quality might suffer.\nTry using 16bps, with sample rate below or equal 16000"); + } + if(_mode != I2S_PHILIPS_MODE){ + log_w("This mode is not officially supported - audio quality might suffer.\nAt the moment the only supported mode is I2S_PHILIPS_MODE"); + } + + if (_state != I2S_STATE_IDLE && _state != I2S_STATE_DUPLEX) { + log_e("Error: unexpected _state (%d)", _state); + _give_if_top_call(); + return 0; // ERR + } + + switch (mode) { + case I2S_PHILIPS_MODE: + case I2S_RIGHT_JUSTIFIED_MODE: + case I2S_LEFT_JUSTIFIED_MODE: + + #if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + case ADC_DAC_MODE: + #endif + + case PDM_STEREO_MODE: + case PDM_MONO_MODE: + break; + + default: // invalid mode + log_e("ERROR: unknown mode"); + _give_if_top_call(); + return 0; // ERR + } + + if(!_installDriver()){ + log_e("ERROR: failed to install driver"); + end(); + _give_if_top_call(); + return 0; // ERR + } + + _buffer_byte_size = _i2s_dma_buffer_size * (_bitsPerSample / 8) * _I2S_DMA_BUFFER_COUNT * 2; + _input_ring_buffer = xRingbufferCreate(_buffer_byte_size, RINGBUF_TYPE_BYTEBUF); + _output_ring_buffer = xRingbufferCreate(_buffer_byte_size, RINGBUF_TYPE_BYTEBUF); + if(_input_ring_buffer == NULL || _output_ring_buffer == NULL){ + log_e("ERROR: could not create one or both internal buffers. Requested size = %d\n", _buffer_byte_size); + _give_if_top_call(); + return 0; // ERR + } + + if(!_createCallbackTask()){ + log_e("ERROR: failed to create callback task"); + end(); + _give_if_top_call(); + return 0; // ERR + } + _initialized = true; + _give_if_top_call(); + return 1; // OK +} + +int I2SClass::_applyPinSetting(){ + if(_driverInstalled){ + esp_i2s::i2s_pin_config_t pin_config = { + .bck_io_num = _sckPin, + .ws_io_num = _fsPin, + .data_out_num = I2S_PIN_NO_CHANGE, + .data_in_num = I2S_PIN_NO_CHANGE + }; + if (_state == I2S_STATE_DUPLEX){ // duplex + pin_config.data_out_num = _outSdPin; + pin_config.data_in_num = _inSdPin; + }else{ // simplex + if(_state == I2S_STATE_RECEIVER){ + pin_config.data_out_num = I2S_PIN_NO_CHANGE; + pin_config.data_in_num = _sdPin; + }else if(_state == I2S_STATE_TRANSMITTER){ + pin_config.data_out_num = _sdPin; + pin_config.data_in_num = I2S_PIN_NO_CHANGE; + }else{ + pin_config.data_out_num = I2S_PIN_NO_CHANGE; + pin_config.data_in_num = _sdPin; + } + } + if(ESP_OK != esp_i2s::i2s_set_pin((esp_i2s::i2s_port_t) _deviceIndex, &pin_config)){ + log_e("i2s_set_pin failed; attempted settings: SCK=%d; FS=%d; DIN=%d; DOUT=%d", pin_config.bck_io_num, pin_config.ws_io_num, pin_config.data_in_num, pin_config.data_out_num); + return 0; // ERR + }else{ + return 1; // OK + } + } // if(_driverInstalled) + return 1; // OK +} + +void I2SClass::_setSckPin(int sckPin){ + _take_if_not_holding(); + if(sckPin >= 0){ + _sckPin = sckPin; + }else{ + _sckPin = PIN_I2S_SCK; + } + _give_if_top_call(); +} + +int I2SClass::setSckPin(int sckPin){ + _take_if_not_holding(); + _setSckPin(sckPin); + int ret = _applyPinSetting(); + _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +void I2SClass::_setFsPin(int fsPin){ + if(fsPin >= 0){ + _fsPin = fsPin; + }else{ + _fsPin = PIN_I2S_FS; + } +} + +int I2SClass::setFsPin(int fsPin){ + _take_if_not_holding(); + _setFsPin(fsPin); + int ret = _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +// shared data pin for simplex +void I2SClass::_setDataPin(int sdPin){ + if(sdPin >= 0){ + _sdPin = sdPin; + }else{ + _sdPin = PIN_I2S_SD; + } +} + +// shared data pin for simplex +int I2SClass::setDataPin(int sdPin){ + _take_if_not_holding(); + _setDataPin(sdPin); + int ret = _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +void I2SClass::_setDataInPin(int inSdPin){ + if(inSdPin >= 0){ + _inSdPin = inSdPin; + }else{ + _inSdPin = PIN_I2S_SD_IN; + } +} + +int I2SClass::setDataInPin(int inSdPin){ + _take_if_not_holding(); + _setDataInPin(inSdPin); + int ret = _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +void I2SClass::_setDataOutPin(int outSdPin){ + if(outSdPin >= 0){ + _outSdPin = outSdPin; + }else{ + _outSdPin = PIN_I2S_SD; + } +} + +int I2SClass::setDataOutPin(int outSdPin){ + _take_if_not_holding(); + _setDataOutPin(outSdPin); + int ret = _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +int I2SClass::setAllPins(){ + _take_if_not_holding(); + int ret = setAllPins(PIN_I2S_SCK, PIN_I2S_FS, PIN_I2S_SD, PIN_I2S_SD_OUT, PIN_I2S_SD_IN); + _give_if_top_call(); + return ret; +} + +int I2SClass::setAllPins(int sckPin, int fsPin, int sdPin, int outSdPin, int inSdPin){ + _take_if_not_holding(); + _setSckPin(sckPin); + _setFsPin(fsPin); + _setDataPin(sdPin); + _setDataOutPin(outSdPin); + _setDataInPin(inSdPin); + int ret = _applyPinSetting(); + _give_if_top_call(); + return ret; +} + +int I2SClass::setDuplex(){ + _take_if_not_holding(); + _state = I2S_STATE_DUPLEX; + _give_if_top_call(); + return 1; +} + +int I2SClass::setSimplex(){ + _take_if_not_holding(); + _state = I2S_STATE_IDLE; + _give_if_top_call(); + return 1; +} + +int I2SClass::isDuplex(){ + _take_if_not_holding(); + int ret = (int)(_state == I2S_STATE_DUPLEX); + _give_if_top_call(); + return ret; +} + +int I2SClass::getSckPin(){ + _take_if_not_holding(); + int ret = _sckPin; + _give_if_top_call(); + return ret; +} + +int I2SClass::getFsPin(){ + _take_if_not_holding(); + int ret = _fsPin; + _give_if_top_call(); + return ret; +} + +int I2SClass::getDataPin(){ + _take_if_not_holding(); + int ret = _sdPin; + _give_if_top_call(); + return ret; +} + +int I2SClass::getDataInPin(){ + _take_if_not_holding(); + int ret = _inSdPin; + _give_if_top_call(); + return ret; +} + +int I2SClass::getDataOutPin(){ + _take_if_not_holding(); + int ret = _outSdPin; + _give_if_top_call(); + return ret; +} + +void I2SClass::_uninstallDriver(){ + if(_driverInstalled){ + #if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + if(_mode == ADC_DAC_MODE){ + esp_i2s::i2s_adc_disable((esp_i2s::i2s_port_t) _deviceIndex); + } + #endif + esp_i2s::i2s_driver_uninstall((esp_i2s::i2s_port_t) _deviceIndex); + + if(_state != I2S_STATE_DUPLEX){ + _state = I2S_STATE_IDLE; + } + _driverInstalled = false; + } // if(_driverInstalled) +} + +void I2SClass::end(){ + _take_if_not_holding(); + if(xTaskGetCurrentTaskHandle() != _callbackTaskHandle){ + if(_callbackTaskHandle){ + vTaskDelete(_callbackTaskHandle); + _callbackTaskHandle = NULL; // prevent secondary termination to non-existing task + } + _uninstallDriver(); + _onTransmit = NULL; + _onReceive = NULL; + if(_input_ring_buffer != NULL){ + vRingbufferDelete(_input_ring_buffer); + _input_ring_buffer = NULL; + } + if(_output_ring_buffer != NULL){ + vRingbufferDelete(_output_ring_buffer); + _output_ring_buffer = NULL; + } + _initialized = false; + }else{ + log_w("WARNING: ending I2SClass from callback task not permitted, but attempted!"); + } + _give_if_top_call(); +} + +// Bytes available to read +int I2SClass::available(){ + _take_if_not_holding(); + int ret = 0; + if(_input_ring_buffer != NULL){ + ret = _buffer_byte_size - (int)xRingbufferGetCurFreeSize(_input_ring_buffer); + } + _give_if_top_call(); + return ret; +} + +union i2s_sample_t { + uint8_t b8; + int16_t b16; + int32_t b32; +}; + +int I2SClass::read(){ + _take_if_not_holding(); + i2s_sample_t sample; + sample.b32 = 0; + if(_initialized){ + read(&sample, _bitsPerSample / 8); + + if (_bitsPerSample == 32) { + _give_if_top_call(); + return sample.b32; + } else if (_bitsPerSample == 16) { + _give_if_top_call(); + return sample.b16; + } else if (_bitsPerSample == 8) { + _give_if_top_call(); + return sample.b8; + } else { + _give_if_top_call(); + return 0; // sample value + } + } // if(_initialized) + _give_if_top_call(); + return 0; // sample value +} + +int I2SClass::read(void* buffer, size_t size){ + _take_if_not_holding(); + size_t requested_size = size; + if(_initialized){ + if(!_enableReceiver()){ + _give_if_top_call(); + return 0; // There was an error switching to receiver + } // _enableReceiver succeeded ? + + size_t item_size = 0; + void *tmp_buffer; + if(_input_ring_buffer != NULL){ + if(_peek_buff_valid){ + memcpy(buffer, &_peek_buff, _bitsPerSample/8); + _peek_buff_valid = false; + requested_size -= _bitsPerSample/8; + } + tmp_buffer = xRingbufferReceiveUpTo(_input_ring_buffer, &item_size, pdMS_TO_TICKS(1000), requested_size); + if(tmp_buffer != NULL){ + memcpy(buffer, tmp_buffer, item_size); + #if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + if(_mode == ADC_DAC_MODE){ + for(size_t i = 0; i < item_size / 2; ++i){ + ((uint16_t*)buffer)[i] = ((uint16_t*)buffer)[i] & 0x0FFF; + } + } // ADC/DAC mode + #endif + vRingbufferReturnItem(_input_ring_buffer, tmp_buffer); + _give_if_top_call(); + return item_size; + }else{ + log_w("input buffer is empty - timed out"); + _give_if_top_call(); + return 0; // 0 Bytes read / ERR + } // tmp buffer not NULL ? + } // ring buffer not NULL ? + } // if(_initialized) + _give_if_top_call(); + return 0; // 0 Bytes read / ERR +} + +size_t I2SClass::write(uint8_t data){ + _take_if_not_holding(); + size_t ret = 0; + if(_initialized){ + ret = write_blocking((int32_t*)&data, 1); + } + _give_if_top_call(); + return ret; +} + +size_t I2SClass::write(int32_t sample){ + _take_if_not_holding(); + size_t ret = 0; + if(_initialized){ + ret = write_blocking(&sample, _bitsPerSample/8); + } + _give_if_top_call(); + return ret; +} + +size_t I2SClass::write(const uint8_t *buffer, size_t size){ + _take_if_not_holding(); + size_t ret = 0; + if(_initialized){ + ret = write((const void*)buffer, size); + } + _give_if_top_call(); + return ret; +} + +size_t I2SClass::write(const void *buffer, size_t size){ + _take_if_not_holding(); + size_t ret = 0; + if(_initialized){ + //size_t ret = write_blocking(buffer, size); + ret = write_nonblocking(buffer, size); + } // if(_initialized) + _give_if_top_call(); + return ret; +} + +// blocking version of write +// This version of write will wait indefinitely to write requested samples +// into output buffer +size_t I2SClass::write_blocking(const void *buffer, size_t size){ + _take_if_not_holding(); + if(_initialized){ + if(!_enableTransmitter()){ + _give_if_top_call(); + return 0; // There was an error switching to transmitter + } // _enableTransmitter succeeded ? + + if(_output_ring_buffer != NULL){ + int ret = xRingbufferSend(_output_ring_buffer, buffer, size, portMAX_DELAY); + if(pdTRUE == ret){ + _give_if_top_call(); + return size; + }else{ + log_e("xRingbufferSend() with infinite wait returned with error"); + _give_if_top_call(); + return 0; + } // ring buffer send ok ? + } // ring buffer not NULL ? + } // if(_initialized) + return 0; + log_w("I2S not initialized"); + _give_if_top_call(); + return 0; +} + +// non-blocking version of write +// In case there is not enough space in buffer to write requested size +// this function will try to flush the buffer and write requested data with 0 time-out +size_t I2SClass::write_nonblocking(const void *buffer, size_t size){ + _take_if_not_holding(); + if(_initialized){ + if(_state != I2S_STATE_TRANSMITTER && _state != I2S_STATE_DUPLEX){ + if(!_enableTransmitter()){ + _give_if_top_call(); + return 0; // There was an error switching to transmitter + } + } + if(availableForWrite() < size){ + flush(); + } + if(_output_ring_buffer != NULL){ + if(pdTRUE == xRingbufferSend(_output_ring_buffer, buffer, size, 0)){ + _give_if_top_call(); + return size; + }else{ + log_w("I2S could not write all data into ring buffer!"); + _give_if_top_call(); + return 0; + } + } + } // if(_initialized) + return 0; + _give_if_top_call(); // this should not be needed +} + +/* + Read 1 sample from internal buffer and return it. + Repeated peeks will return the same sample until read is called. +*/ +int I2SClass::peek(){ + _take_if_not_holding(); + int ret = 0; + if(_initialized && _input_ring_buffer != NULL && !_peek_buff_valid){ + size_t item_size = 0; + void *item = NULL; + + item = xRingbufferReceiveUpTo(_input_ring_buffer, &item_size, 0, _bitsPerSample/8); // fetch 1 sample + if (item != NULL && item_size == _bitsPerSample/8){ + _peek_buff = *((int*)item); + vRingbufferReturnItem(_input_ring_buffer, item); + _peek_buff_valid = true; + } + + } // if(_initialized) + if(_peek_buff_valid){ + ret = _peek_buff; + } + _give_if_top_call(); + return ret; +} + +void I2SClass::flush(){ + _take_if_not_holding(); + if(_initialized){ + const size_t single_dma_buf = _i2s_dma_buffer_size*(_bitsPerSample/8)*2; + size_t item_size = 0; + void *item = NULL; + if(_output_ring_buffer != NULL){ + item = xRingbufferReceiveUpTo(_output_ring_buffer, &item_size, 0, single_dma_buf); + if (item != NULL){ + _fix_and_write(item, item_size); + vRingbufferReturnItem(_output_ring_buffer, item); + } + } + } // if(_initialized) + _give_if_top_call(); +} + +// Bytes available to write +int I2SClass::availableForWrite(){ + _take_if_not_holding(); + int ret = 0; + if(_initialized){ + if(_output_ring_buffer != NULL){ + ret = (int)xRingbufferGetCurFreeSize(_output_ring_buffer); + } + } // if(_initialized) + _give_if_top_call(); + return ret; +} + +void I2SClass::onTransmit(void(*function)(void)){ + _take_if_not_holding(); + _onTransmit = function; + _give_if_top_call(); +} + +void I2SClass::onReceive(void(*function)(void)){ + _take_if_not_holding(); + _onReceive = function; + _give_if_top_call(); +} + +int I2SClass::setBufferSize(int bufferSize){ + _take_if_not_holding(); + int ret = 0; + if(bufferSize >= 8 && bufferSize <= 1024){ + _i2s_dma_buffer_size = bufferSize; + }else{ + log_e("setBufferSize: wrong input! Buffer size must be between 8 and 1024. Requested %d", bufferSize); + _give_if_top_call(); + return 0; // ERR + } // check requested buffer size + + if(_initialized){ + _uninstallDriver(); + ret = _installDriver(); + _give_if_top_call(); + return ret; + }else{ // check requested buffer size + _give_if_top_call(); + return 1; // It's ok to change buffer size for uninitialized driver - new size will be used on begin() + } // if(_initialized) + _give_if_top_call(); + return 0; // ERR +} + +int I2SClass::getBufferSize(){ + _take_if_not_holding(); + int ret = _i2s_dma_buffer_size; + _give_if_top_call(); + return ret; +} + +int I2SClass::_enableTransmitter(){ + if(_state != I2S_STATE_DUPLEX && _state != I2S_STATE_TRANSMITTER){ + _state = I2S_STATE_TRANSMITTER; + return _applyPinSetting(); + } + return 1; // Ok +} + +int I2SClass::_enableReceiver(){ + if(_state != I2S_STATE_DUPLEX && _state != I2S_STATE_RECEIVER){ + _state = I2S_STATE_RECEIVER; + return _applyPinSetting(); + } + return 1; // Ok +} + +void I2SClass::_tx_done_routine(uint8_t* prev_item){ + static bool prev_item_valid = false; + const size_t single_dma_buf = _i2s_dma_buffer_size*(_bitsPerSample/8)*2; // *2 for stereo - it has double number of samples for 2 channels + static size_t item_size = 0; + static size_t prev_item_size = 0; + static void *item = NULL; + static int prev_item_offset = 0; + static size_t bytes_written = 0; + + if(prev_item_valid){ // use item from previous round + _fix_and_write(prev_item+prev_item_offset, prev_item_size, &bytes_written); + if(prev_item_size == bytes_written){ + prev_item_valid = false; + } // write size check + prev_item_offset = bytes_written; + prev_item_size -= bytes_written; + } // prev_item_valid + + if(_output_ring_buffer != NULL && (_buffer_byte_size - xRingbufferGetCurFreeSize(_output_ring_buffer) >= single_dma_buf)){ // fill up the I2S DMA buffer + bytes_written = 0; + item_size = 0; + if(_buffer_byte_size - xRingbufferGetCurFreeSize(_output_ring_buffer) >= _i2s_dma_buffer_size*(_bitsPerSample/8)){ // don't read from almost empty buffer + item = xRingbufferReceiveUpTo(_output_ring_buffer, &item_size, pdMS_TO_TICKS(0), single_dma_buf); + if (item != NULL){ + _fix_and_write(item, item_size, &bytes_written); + if(item_size != bytes_written){ // save item that was not written correctly for later + memcpy(prev_item, (void*)&((uint8_t*)item)[bytes_written], item_size-bytes_written); + prev_item_size = item_size - bytes_written; + prev_item_offset = 0; + prev_item_valid = true; + } // save item that was not written correctly for later + vRingbufferReturnItem(_output_ring_buffer, item); + } // Check received item + } // don't read from almost empty buffer + } // fill up the I2S DMA buffer + if(_onTransmit){ + _onTransmit(); + } // user callback +} + +void I2SClass::_rx_done_routine(){ + size_t bytes_read = 0; + const size_t single_dma_buf = _i2s_dma_buffer_size*(_bitsPerSample/8); + + if(_input_ring_buffer != NULL){ + uint8_t *_inputBuffer = (uint8_t*)malloc(_i2s_dma_buffer_size*4); + size_t avail = xRingbufferGetCurFreeSize(_input_ring_buffer); + if(avail > 0){ + esp_err_t ret = esp_i2s::i2s_read((esp_i2s::i2s_port_t) _deviceIndex, _inputBuffer, avail <= single_dma_buf ? avail : single_dma_buf, (size_t*) &bytes_read, 0); + if(ret != ESP_OK){ + log_w("i2s_read returned with error %d", ret); + } + _post_read_data_fix(_inputBuffer, &bytes_read); + } + + if(bytes_read > 0){ // when read more than 0, then send to ring buffer + if(pdTRUE != xRingbufferSend(_input_ring_buffer, _inputBuffer, bytes_read, 0)){ + log_w("I2S failed to send item from DMA to internal buffer\n"); + } // xRingbufferSendComplete + } // if(bytes_read > 0) + free(_inputBuffer); + if (_onReceive && avail < _buffer_byte_size){ // when user callback is registered && and there is some data in ring buffer to read + _onReceive(); + } // user callback + } +} + +void I2SClass::_onTransferComplete(){ + uint8_t prev_item[_i2s_dma_buffer_size*4]; + esp_i2s::i2s_event_t i2s_event; + + while(true){ + xQueueReceive(_i2sEventQueue, &i2s_event, portMAX_DELAY); + if(i2s_event.type == esp_i2s::I2S_EVENT_TX_DONE){ + _tx_done_routine(prev_item); + }else if(i2s_event.type == esp_i2s::I2S_EVENT_RX_DONE){ + _rx_done_routine(); + } // RX Done + } // infinite loop +} + +void I2SClass::onDmaTransferComplete(void*){ + I2S._onTransferComplete(); +} + +void I2SClass::_take_if_not_holding(){ + TaskHandle_t mutex_holder = xSemaphoreGetMutexHolder(_i2s_general_mutex); + if(mutex_holder != NULL && mutex_holder == xTaskGetCurrentTaskHandle()){ + ++_nesting_counter; + return; // we are already holding this mutex - no need to take it + } + + // we are not holding the mutex - wait for it and take it + if(xSemaphoreTake(_i2s_general_mutex, portMAX_DELAY) != pdTRUE ){ + log_e("I2S internal mutex take returned with error"); + } + //_give_if_top_call(); // call after this function +} + +void I2SClass::_give_if_top_call(){ + if(_nesting_counter){ + --_nesting_counter; + }else{ + if(xSemaphoreGive(_i2s_general_mutex) != pdTRUE){ + log_e("I2S internal mutex give error"); + } + } +} + + +// Fixes data in-situ received from esp i2s driver. After fixing they reflect what was on the bus. +// input - bytes as received from i2s_read - this serves as input and output buffer +// size - number of bytes (this may be changed during operation) +void I2SClass::_post_read_data_fix(void *input, size_t *size){ + ulong dst_ptr = 0; + switch(_bitsPerSample){ + case 8: + for(int i = 0; i < *size; i+=4){ + ((uint8_t*)input)[dst_ptr++] = ((uint8_t*)input)[i+3]; + ((uint8_t*)input)[dst_ptr++] = ((uint8_t*)input)[i+1]; + } + *size /= 2; + break; + case 16: + uint16_t tmp; + for(int i = 0; i < *size/2; i+=2){ + tmp = ((uint16_t*)input)[i]; + ((uint16_t*)input)[dst_ptr++] = ((uint16_t*)input)[i+1]; + ((uint16_t*)input)[dst_ptr++] = tmp; + } + break; + default: ; // Do nothing + } // switch +} + +// Prepares data and writes them to IDF i2s driver. +// This counters possible bug in ESP IDF I2S driver +// output - bytes to be sent +// size - number of bytes in original buffer +// bytes_written - number of bytes used from original buffer +// actual_bytes_written - number of bytes written by i2s_write after fix +void I2SClass::_fix_and_write(void *output, size_t size, size_t *bytes_written, size_t *actual_bytes_written){ + long start = millis(); + ulong src_ptr = 0; + uint8_t* buff = NULL; + size_t buff_size = size; + switch(_bitsPerSample){ + case 8: + buff_size = size *2; + buff = (uint8_t*)calloc(buff_size, sizeof(uint8_t)); + if(buff == NULL){ + log_e("callock error"); + if(bytes_written != NULL){ *bytes_written = 0; } + return; + } + for(int i = 0; i < buff_size ; i+=4){ + ((uint8_t*)buff)[i+3] = (uint16_t)((uint8_t*)output)[src_ptr++]; + ((uint8_t*)buff)[i+1] = (uint16_t)((uint8_t*)output)[src_ptr++]; + } + break; + case 16: + buff = (uint8_t*)malloc(buff_size); + if(buff == NULL){ + log_e("malloc error"); + if(bytes_written != NULL){ *bytes_written = 0; } + return; + } + for(int i = 0; i < size/2; i += 2 ){ + ((uint16_t*)buff)[i] = ((uint16_t*)output)[i+1]; // [1] <- [0] + ((uint16_t*)buff)[i+1] = ((uint16_t*)output)[i]; // [0] <- [1] + } + break; + case 24: + buff = (uint8_t*)output; + break; + case 32: + buff = (uint8_t*)output; + break; + default: ; // Do nothing + } // switch + + size_t _bytes_written; + esp_err_t ret = esp_i2s::i2s_write((esp_i2s::i2s_port_t) _deviceIndex, buff, buff_size, &_bytes_written, 0); // fixed + if(ret != ESP_OK){ + log_e("Error: writing data to i2s - function returned with err code %d", ret); + } + if(ret == ESP_OK && buff_size != _bytes_written){ + log_w("Warning: writing data to i2s - written %d B instead of requested %d B", _bytes_written, buff_size); + } + // free if the buffer was actually allocated + if(_bitsPerSample == 8 || _bitsPerSample == 16){ + free(buff); + } + if(bytes_written != NULL){ + *bytes_written = _bitsPerSample == 8 ? _bytes_written/2 : _bytes_written; + } + if(actual_bytes_written != NULL){ + *actual_bytes_written = _bytes_written; + } +} + + +#if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) +int I2SClass::_gpioToAdcUnit(gpio_num_t gpio_num, esp_i2s::adc_unit_t* adc_unit){ + switch(gpio_num){ +#if CONFIG_IDF_TARGET_ESP32 + // ADC 1 + case GPIO_NUM_36: + case GPIO_NUM_37: + case GPIO_NUM_38: + case GPIO_NUM_39: + case GPIO_NUM_32: + case GPIO_NUM_33: + case GPIO_NUM_34: + case GPIO_NUM_35: + *adc_unit = esp_i2s::ADC_UNIT_1; + return 1; // OK + + // ADC 2 + case GPIO_NUM_0: + log_w("GPIO 0 for ADC should not be used for dev boards due to external auto program circuits."); + case GPIO_NUM_4: + case GPIO_NUM_2: + case GPIO_NUM_15: + case GPIO_NUM_13: + case GPIO_NUM_12: + case GPIO_NUM_14: + case GPIO_NUM_27: + case GPIO_NUM_25: + case GPIO_NUM_26: + *adc_unit = esp_i2s::ADC_UNIT_2; + return 1; // OK +#endif + +#if (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3) + case GPIO_NUM_1: + case GPIO_NUM_2: + case GPIO_NUM_3: + case GPIO_NUM_4: + case GPIO_NUM_5: + case GPIO_NUM_6: + case GPIO_NUM_7: + case GPIO_NUM_8: + case GPIO_NUM_9: + case GPIO_NUM_10: + *adc_unit = esp_i2s::ADC_UNIT_1; + return 1; // OK +#endif + +#if CONFIG_IDF_TARGET_ESP32S2 + case GPIO_NUM_11: + case GPIO_NUM_12: + case GPIO_NUM_13: + case GPIO_NUM_14: + case GPIO_NUM_15: + case GPIO_NUM_16: + case GPIO_NUM_17: + case GPIO_NUM_18: + case GPIO_NUM_19: + case GPIO_NUM_20: + *adc_unit = esp_i2s::ADC_UNIT_2; + return 1; // OK +#endif + +#if (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2) + case GPIO_NUM_0: + case GPIO_NUM_1: + case GPIO_NUM_2: + case GPIO_NUM_3: + case GPIO_NUM_4: + *adc_unit = esp_i2s::ADC_UNIT_1; + return 1; // OK + case GPIO_NUM_5: + *adc_unit = esp_i2s::ADC_UNIT_2; + return 1; // OK +#endif + default: + log_e("GPIO %d not usable for ADC!", gpio_num); + log_i("Please refer to documentation https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html"); + return 0; // ERR + } +} + +int I2SClass::_gpioToAdcChannel(gpio_num_t gpio_num, esp_i2s::adc_channel_t* adc_channel){ + switch(gpio_num){ +#if CONFIG_IDF_TARGET_ESP32 + // ADC 1 + case GPIO_NUM_36: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK + case GPIO_NUM_37: *adc_channel = esp_i2s::ADC_CHANNEL_1; return 1; // OK + case GPIO_NUM_38: *adc_channel = esp_i2s::ADC_CHANNEL_2; return 1; // OK + case GPIO_NUM_39: *adc_channel = esp_i2s::ADC_CHANNEL_3; return 1; // OK + case GPIO_NUM_32: *adc_channel = esp_i2s::ADC_CHANNEL_4; return 1; // OK + case GPIO_NUM_33: *adc_channel = esp_i2s::ADC_CHANNEL_5; return 1; // OK + case GPIO_NUM_34: *adc_channel = esp_i2s::ADC_CHANNEL_6; return 1; // OK + case GPIO_NUM_35: *adc_channel = esp_i2s::ADC_CHANNEL_7; return 1; // OK + + // ADC 2 + case GPIO_NUM_0: + log_w("GPIO 0 for ADC should not be used for dev boards due to external auto program circuits."); + *adc_channel = esp_i2s::ADC_CHANNEL_1; return 1; // OK + case GPIO_NUM_4: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK + case GPIO_NUM_2: *adc_channel = esp_i2s::ADC_CHANNEL_2; return 1; // OK + case GPIO_NUM_15: *adc_channel = esp_i2s::ADC_CHANNEL_3; return 1; // OK + case GPIO_NUM_13: *adc_channel = esp_i2s::ADC_CHANNEL_4; return 1; // OK + case GPIO_NUM_12: *adc_channel = esp_i2s::ADC_CHANNEL_5; return 1; // OK + case GPIO_NUM_14: *adc_channel = esp_i2s::ADC_CHANNEL_6; return 1; // OK + case GPIO_NUM_27: *adc_channel = esp_i2s::ADC_CHANNEL_7; return 1; // OK + case GPIO_NUM_25: *adc_channel = esp_i2s::ADC_CHANNEL_8; return 1; // OK + case GPIO_NUM_26: *adc_channel = esp_i2s::ADC_CHANNEL_9; return 1; // OK +#endif + +#if (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3) + case GPIO_NUM_1: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK + case GPIO_NUM_2: *adc_channel = esp_i2s::ADC_CHANNEL_1; return 1; // OK + case GPIO_NUM_3: *adc_channel = esp_i2s::ADC_CHANNEL_2; return 1; // OK + case GPIO_NUM_4: *adc_channel = esp_i2s::ADC_CHANNEL_3; return 1; // OK + case GPIO_NUM_5: *adc_channel = esp_i2s::ADC_CHANNEL_4; return 1; // OK + case GPIO_NUM_6: *adc_channel = esp_i2s::ADC_CHANNEL_5; return 1; // OK + case GPIO_NUM_7: *adc_channel = esp_i2s::ADC_CHANNEL_6; return 1; // OK + case GPIO_NUM_8: *adc_channel = esp_i2s::ADC_CHANNEL_7; return 1; // OK + case GPIO_NUM_9: *adc_channel = esp_i2s::ADC_CHANNEL_8; return 1; // OK + case GPIO_NUM_10: *adc_channel = esp_i2s::ADC_CHANNEL_9; return 1; // OK +#endif + +#if CONFIG_IDF_TARGET_ESP32S2 + case GPIO_NUM_11: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK + case GPIO_NUM_12: *adc_channel = esp_i2s::ADC_CHANNEL_1; return 1; // OK + case GPIO_NUM_13: *adc_channel = esp_i2s::ADC_CHANNEL_2; return 1; // OK + case GPIO_NUM_14: *adc_channel = esp_i2s::ADC_CHANNEL_3; return 1; // OK + case GPIO_NUM_15: *adc_channel = esp_i2s::ADC_CHANNEL_4; return 1; // OK + case GPIO_NUM_16: *adc_channel = esp_i2s::ADC_CHANNEL_5; return 1; // OK + case GPIO_NUM_17: *adc_channel = esp_i2s::ADC_CHANNEL_6; return 1; // OK + case GPIO_NUM_18: *adc_channel = esp_i2s::ADC_CHANNEL_7; return 1; // OK + case GPIO_NUM_19: *adc_channel = esp_i2s::ADC_CHANNEL_8; return 1; // OK + case GPIO_NUM_20: *adc_channel = esp_i2s::ADC_CHANNEL_9; return 1; // OK +#endif + +#if (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2) + case GPIO_NUM_0: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK + case GPIO_NUM_1: *adc_channel = esp_i2s::ADC_CHANNEL_1; return 1; // OK + case GPIO_NUM_2: *adc_channel = esp_i2s::ADC_CHANNEL_2; return 1; // OK + case GPIO_NUM_3: *adc_channel = esp_i2s::ADC_CHANNEL_3; return 1; // OK + case GPIO_NUM_4: *adc_channel = esp_i2s::ADC_CHANNEL_4; return 1; // OK + case GPIO_NUM_5: *adc_channel = esp_i2s::ADC_CHANNEL_0; return 1; // OK +#endif + default: + log_e("GPIO %d not usable for ADC!", gpio_num); + log_i("Please refer to documentation https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html"); + return 0; // ERR + } +} +#endif // SOC_I2S_SUPPORTS_ADC_DAC + +#if I2S_INTERFACES_COUNT > 0 + I2SClass I2S(I2S_DEVICE, I2S_CLOCK_GENERATOR, PIN_I2S_SD, PIN_I2S_SCK, PIN_I2S_FS); // default - half duplex +#endif + +#if I2S_INTERFACES_COUNT > 1 + // TODO set default pins for second module + //I2SClass I2S1(I2S_DEVICE+1, I2S_CLOCK_GENERATOR, PIN_I2S_SD, PIN_I2S_SCK, PIN_I2S_FS); // default - half duplex +#endif diff --git a/libraries/I2S/src/I2S.h b/libraries/I2S/src/I2S.h new file mode 100644 index 00000000000..623fa8917b4 --- /dev/null +++ b/libraries/I2S/src/I2S.h @@ -0,0 +1,195 @@ +/* + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _I2S_H_INCLUDED +#define _I2S_H_INCLUDED + +#include +#include "freertos/ringbuf.h" + +namespace esp_i2s { + #include "driver/i2s.h" // ESP specific i2s driver +} + +// Default pins +#ifndef PIN_I2S_SCK + #define PIN_I2S_SCK 14 +#endif + +#ifndef PIN_I2S_FS + #if CONFIG_IDF_TARGET_ESP32S2 + #define PIN_I2S_FS 27 + #else + #define PIN_I2S_FS 25 + #endif +#endif + +#ifndef PIN_I2S_SD + #define PIN_I2S_SD 26 +#endif + +#ifndef PIN_I2S_SD_OUT + #define PIN_I2S_SD_OUT 26 +#endif + +#ifndef PIN_I2S_SD_IN + #define PIN_I2S_SD_IN 35 // Pin 35 is only input! +#endif + +typedef enum { + I2S_PHILIPS_MODE, + I2S_RIGHT_JUSTIFIED_MODE, + I2S_LEFT_JUSTIFIED_MODE, + ADC_DAC_MODE, + PDM_STEREO_MODE, + PDM_MONO_MODE +} i2s_mode_t; + +class I2SClass : public Stream +{ +public: + // The device index and pins must map to the "COM" pads in Table 6-1 of the datasheet + I2SClass(uint8_t deviceIndex, uint8_t clockGenerator, uint8_t sdPin, uint8_t sckPin, uint8_t fsPin); + + // Init in MASTER mode: the SCK and FS pins are driven as outputs using the sample rate + int begin(int mode, int sampleRate, int bitsPerSample); + + // Init in SLAVE mode: the SCK and FS pins are inputs, other side controls sample rate + int begin(int mode, int bitsPerSample); + + // change pin setup and mode (default is Half Duplex) + // Can be called only on initialized object (after begin) + int setSckPin(int sckPin); + int setFsPin(int fsPin); + int setDataPin(int sdPin); // shared data pin for simplex + int setDataOutPin(int outSdPin); + int setDataInPin(int inSdPin); + + int setAllPins(); + int setAllPins(int sckPin, int fsPin, int sdPin, int outSdPin, int inSdPin); + + int getSckPin(); + int getFsPin(); + int getDataPin(); + int getDataOutPin(); + int getDataInPin(); + + int setDuplex(); + int setSimplex(); + int isDuplex(); + + void end(); + + // from Stream + virtual int available(); + virtual int read(); + virtual int peek(); + virtual void flush(); + + // from Print + virtual size_t write(uint8_t); + virtual size_t write(const uint8_t *buffer, size_t size); + + virtual int availableForWrite(); + + int read(void* buffer, size_t size); + + //size_t write(int); + size_t write(int32_t); + size_t write(const void *buffer, size_t size); + size_t write_blocking(const void *buffer, size_t size); + size_t write_nonblocking(const void *buffer, size_t size); + + void onTransmit(void(*)(void)); + void onReceive(void(*)(void)); + + int setBufferSize(int bufferSize); + int getBufferSize(); +private: + #if (SOC_I2S_SUPPORTS_ADC && SOC_I2S_SUPPORTS_DAC) + int _gpioToAdcUnit(gpio_num_t gpio_num, esp_i2s::adc_unit_t* adc_unit); + int _gpioToAdcChannel(gpio_num_t gpio_num, esp_i2s::adc_channel_t* adc_channel); + #endif + int begin(int mode, int sampleRate, int bitsPerSample, bool driveClock); + + int _enableTransmitter(); + int _enableReceiver(); + void _onTransferComplete(); + + int _createCallbackTask(); + + static void onDmaTransferComplete(void*); + int _installDriver(); + void _uninstallDriver(); + void _setSckPin(int sckPin); + void _setFsPin(int fsPin); + void _setDataPin(int sdPin); + void _setDataOutPin(int outSdPin); + void _setDataInPin(int inSdPin); + int _applyPinSetting(); + +private: + typedef enum { + I2S_STATE_IDLE, + I2S_STATE_TRANSMITTER, + I2S_STATE_RECEIVER, + I2S_STATE_DUPLEX + } i2s_state_t; + + int _deviceIndex; + int _sdPin; + int _inSdPin; + int _outSdPin; + int _sckPin; + int _fsPin; + + i2s_state_t _state; + int _bitsPerSample; + uint32_t _sampleRate; + int _mode; + + uint16_t _buffer_byte_size; + + bool _driverInstalled; // Is IDF I2S driver installed? + bool _initialized; // Is everything initialized (callback task, I2S driver, ring buffers)? + TaskHandle_t _callbackTaskHandle; + QueueHandle_t _i2sEventQueue; + SemaphoreHandle_t _i2s_general_mutex; + RingbufHandle_t _input_ring_buffer; + RingbufHandle_t _output_ring_buffer; + int _i2s_dma_buffer_size; + bool _driveClock; + uint32_t _peek_buff; + bool _peek_buff_valid; + + void _tx_done_routine(uint8_t* prev_item); + void _rx_done_routine(); + + uint16_t _nesting_counter; + void _take_if_not_holding(); + void _give_if_top_call(); + void _post_read_data_fix(void *input, size_t *size); + void _fix_and_write(void *output, size_t size, size_t *bytes_written = NULL, size_t *actual_bytes_written = NULL); + + void (*_onTransmit)(void); + void (*_onReceive)(void); +}; + +extern I2SClass I2S; + +#endif diff --git a/libraries/README.md b/libraries/README.md index e7c77efbad5..d7e0e8fbd29 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -67,9 +67,6 @@ arduino-esp32 includes libraries for Arduino compatibility along with some objec ### Preferences Flash keystore using ESP32 NVS -### ESP RainMaker - End-to-end platform by Espressif that enables Makers to realize their IoT ideas faster - ### SD Secure Digital card filesystem using SPI access diff --git a/libraries/RainMaker/README.md b/libraries/RainMaker/README.md deleted file mode 100644 index 03f5e4c520a..00000000000 --- a/libraries/RainMaker/README.md +++ /dev/null @@ -1,483 +0,0 @@ -# ESP RainMaker library for Arduino -This library allows to work with ESP RainMaker. - -ESP RainMaker is an end-to-end solution offered by Espressif to enable remote control and monitoring for ESP32-S2 and ESP32 based products without any configuration required in the Cloud. The primary components of this solution are: - -- Claiming Service (to get the Cloud connectivity credentials) -- RainMaker library (i.e. this library, to develop the firmware) -- RainMaker Cloud (backend, offering remote connectivity) -- RainMaker Phone App/CLI (Client utilities for remote access) - -The key features of ESP RainMaker are: - -1. Ability to define own devices and parameters, of any type, in the firmware. -2. Zero configuration required on the Cloud. -3. Phone apps that dynamically render the UI as per the device information. - -This ESP RainMaker library is built using esp-rainmaker component. - -#### Repository Source - -- [ESP RainMaker](https://github.com/espressif/esp-rainmaker) - -## Phone Apps - -#### Android - -- [Google PlayStore](https://play.google.com/store/apps/details?id=com.espressif.rainmaker) -- [Direct APK](https://github.com/espressif/esp-rainmaker/wiki) -- [Source Code](https://github.com/espressif/esp-rainmaker-android) - -#### iOS -- [Apple App Store](https://apps.apple.com/app/esp-rainmaker/id1497491540) -- [Source Code](https://github.com/espressif/esp-rainmaker-ios) - -## Documentation - -Additional information about ESP RainMaker can be found [here](https://rainmaker.espressif.com/) - -NOTE : ESP RainMaker library is currently supported for ESP32 board only. - -## ESP RainMaker Agent API - -### RMaker.initNode() -This initializes the ESP RainMaker agent, wifi and creates the node. -``` -Node initNode(const char *name, const char *type); -``` -* **Parameters** -1. `name`: Name of the node -2. `type`: Type of the node - -* **Return** -1. Object of Node. - -* You can also set the configuration of the node using the following API - 1. RMaker.setTimeSync(bool val) -> NOTE: If you want to set the configuration for the node then these configuration API must be called before `RMaker.initNode()`. - -### RMaker.start() -It starts the ESP RainMaker agent. -``` -esp_err_t start() -``` -* **Return** -1. ESP_OK : On success -2. Error in case of failure - -> NOTE : -> 1. ESP RainMaker agent should be initialized before this call. -> 2. Once ESP RainMaker agent starts, compulsorily call WiFi.beginProvision() API. - -### RMaker.stop() -It stops the ESP RainMaker agent which was started using `RMaker.start()`. -``` -esp_err_t stop() -``` -* **Return** -1. ESP_OK : On success -2. Error in case of failure - -### RMaker.deinitNode() -It deinitializes the ESP RainMaker agent and the node created using `RMaker.initNode()`. -``` -esp_err_t deinitNode(Node node) -``` -* **Parameter** -1. `node` : Node object created using `RMaker.initNode()` -* **Return** -1. ESP_OK : On success -2. Error in case of failure - -### RMaker.enableOTA() -It enables OTA as per the ESP RainMaker Specification. For more details refer ESP RainMaker documentation. check [here](https://rainmaker.espressif.com/docs/ota.html) -``` -esp_err_t enableOTA(ota_type_t type); -``` -* **Parameter** -1. `type` : The OTA workflow type. - - OTA_USING_PARAMS - - OTA_USING_TOPICS -* **Return** -1. ESP_OK : On success -2. Error in case of failure - -### RMaker.enableSchedule() -This API enables the scheduling service for the node. For more information, check [here](https://rainmaker.espressif.com/docs/scheduling.html). -``` -esp_err_t enableSchedule(); -``` -* **Return** -1. ESP_OK : On success -2. Error in case of failure - -### RMaker.setTimeZone() -This API set's the timezone as a user friendly location string. Check [here](https://rainmaker.espressif.com/docs/time-service.html) for a list of valid values. -``` -esp_err_t setTimeZone(const char *tz); -``` -* **Parameter** -1. `tz' : Valid values as specified in documentation. - -* **Return** -1. ESP_OK : On success -2. Error in case of failure -> NOTE : default value is "Asia/Shanghai". -> This API comes into picture only when working with scheduling. - -## ESP RainMaker NODE APIs -`Node` class expose API's for node. -> NOTE : my_node is the object of Node class. - -### my_node.getNodeID() -It returns the unique node_id assigned to the node. This node_id is usually the MAC address of the board. -``` -char * getNodeID() -``` -* **Return** -1. `char * ` : Pointer to a NULL terminated node_id string. - -### my_node.getNodeInfo() -It returns pointer to the node_info_t as configured during node initialisation. -``` -node_info_t * getNodeInfo(); -``` -* **Return** -1. `node_info_t` : Pointer to the structure node_info_t on success. -2. `NULL` : On failure. - -* **ESP RainMaker node info** -It has following data member -1. char * name -2. char * type -3. char * fw_version -4. char * model - -### my_node.addNodeAttr() -It adds a new attribute as the metadata to the node. -``` -esp_err_t addNodeAttr(const char *attr_name, const char *val); -``` -* **Parameters** -1. `attr_name` : Name of the attribute -2. `val` : Value of the attribute - -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -> NOTE : Only string values are allowed. - -### my_node.addDevice() -It adds a device to the node. -``` -esp_err_t addDevice(Device device); -``` -* **Parameter** -1. `device` : Device object - -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -> NOTE : -> - This is the mandatory API to register device to node. -> - Single Node can have multiple devices. -> - Device name should be unique for each device. - -### my_node.removeDevice() -It removes a device from the node. -``` -esp_err_t removeDevice(Device device); -``` -* **Parameter** -1. `device` : Device object - -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -## ESP RainMaker DEVICE API's -`Device` class expose API's for virtual devices on the node. -Parameterized constructor is defined which creates the virtual device on the node. Using Device class object you can create your own device. -> NOTE : my_device is the object of Device class -``` -Device my_device(const char *dev_name, const char *dev_type, void *priv_data); -``` -* **Parameters** -1. `dev_name` : Unique device name -2. `dev_type` : Optional device type. It can be kept NULL. - * Standard Device Types - * ESP_RMAKER_DEVICE_SWITCH - * ESP_RMAKER_DEVICE_LIGHTBULB - * ESP_RMAKER_DEVICE_FAN - * ESP_RMAKER_DEVICE_TEMP_SENSOR -3. `priv_data` : Private data associated with the device. This will be passed to the callbacks. - -> NOTE : This created device should be added to the node using `my_node.addDevice(my_device)`. - -- Sample example -``` -Device my_device("Switch"); -Device my_device("Switch1", NULL, NULL); -``` -> Here, dev_name is compulsory, rest are optional. -> Node can have multiple device, each device should have unique device name. - -### Standard Device -- Classes are defined for the standard devices. -- Creating object of these class creates the standard device with default parameters to it. -- Class for standard devices - * Switch - * LightBulb - * TemperatureSensor - * Fan -``` -Switch my_switch(const char *dev_name, void *priv_data, bool power); -``` -* **Parameters** -1. `dev_name` : Unique device name by default it is "switch" for switch device. -2. `priv_data` : Private data associated with the device. This will be passed to the callbacks. -3. `power` : It is the value that can be set for primary parameter. - -- Sample example for standard device. -``` -Switch switch1; -Switch switch2("switch2", NULL, true); -``` -`"switch2"` : Name for standard device. - -`NULL` : Private data for the device, which will be used in callback. - -`true` : Default value for the primary param, in case of switch it is power. - -> NOTE : No parameter are compulsory for standard devices. However if you are creating two objects of same standard class then in that case you will have to set the device name, if not then both device will have same name which is set by default, hence device will not get create. Device name should be unique for each device. - -### my_device.getDeviceName() -It returns the name of the Device. -``` -const char * getDeviceName(); -``` -* **Return** -1. `char *`: Returns Device name. - -> NOTE : Each device on the node should have unique device name. - -### my_device.addDeviceAttr() -It adds attribute to the device. Device attributes are reported only once after a boot-up as part of the node configuration. Eg. Serial Number -``` -esp_err_t addDeviceAttr(const char *attr_name, const char *val); -``` -* **Parameters** -1. `attr_name` : Name of the attribute -2. `val` : Value of the attribute - -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -### my_device.deleteDevice() -It deletes the device created using parameterized constructor. This device should be first removed from the node using `my_node.removeDevice(my_device)`. -``` -esp_err_t deleteDevice(); -``` -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -### my_device.addXParam() -It adds standard parameter to the device. -> NOTE : X is the default name by which parameter is referred, you can specify your own name to each parameter. - -> Default - -> Eg. `my_device.addPowerParam(true)` here power parameter is referred with name Power. -> Eg. `my_device.addHueParam(12)` here hue parameter is referred with name Hue. - -> You can specify your own name to each parameter - -> Eg. `my_device.addNameParam("NickName")` here name parameter is referred with name NickName. -> Eg. `my_device.addPowerParam(true, "FanPower")` here power parameter is referred with name FanPower. - -``` -esp_err_t addNameParam(const char *param_name = ESP_RMAKER_DEF_NAME_PARAM); -esp_err_t addPowerParam(bool val, const char *param_name = ESP_RMAKER_DEF_POWER_NAME); -esp_err_t addBrightnessParam(int val, const char *param_name = ESP_RMAKER_DEF_BRIGHTNESS_NAME); -esp_err_t addHueParam(int val, const char *param_name = ESP_RMAKER_DEF_HUE_NAME); -esp_err_t addSaturationParam(int val, const char *param_name = ESP_RMAKER_DEF_SATURATION_NAME); -esp_err_t addIntensityParam(int val, const char *param_name = ESP_RMAKER_DEF_INTENSITY_NAME); -esp_err_t addCCTParam(int val, const char *param_name = ESP_RMAKER_DEF_CCT_NAME); -esp_err_t addDirectionParam(int val, const char *param_name = ESP_RMAKER_DEF_DIRECTION_NAME); -esp_err_t addSpeedParam(int val, const char *param_name = ESP_RMAKER_DEF_SPEED_NAME); -esp_err_t addTempratureParam(float val, const char *param_name = ESP_RMAKER_DEF_TEMPERATURE_NAME); -``` -* **Standard Parameters** - -* These are the standard parameters. - * Name : ESP_RMAKER_DEF_NAME_PARAM - * Power : ESP_RMAKER_DEF_POWER_NAME - * Brightness : ESP_RMAKER_DEF_BRIGHTNESS_NAME - * Hue : ESP_RMAKER_DEF_HUE_NAME - * Saturation : ESP_RMAKER_DEF_SATURATION_NAME - * Intensity : ESP_RMAKER_DEF_INTENSITY_NAME - * CCT : ESP_RMAKER_DEF_CCT_NAME - * Direction : ESP_RMAKER_DEF_DIRECTION_NAME - * Speed : ESP_RMAKER_DEF_SPEED_NAME - * Temperature : ESP_RMAKER_DEF_TEMPERATURE_NAME -> NOTE : Care should be taken while accessing name of parameter. Above mentioned are the two ways using which default name of parameters can be accessed. Either LHS or RHS. - -### my_device.assignPrimaryParam() -It assigns a parameter (already added using addXParam() or addParam()) as a primary parameter, which can be used by clients (phone apps specifically) to give prominence to it. -``` -esp_err_t assignPrimaryParam(param_handle_t *param); -``` -* **Parameter** -1. `param` : Handle of the parameter. It is obtained using `my_device.getParamByName()`. -``` -param_handle_t * getParamByName(const char *param_name); -``` -> NOTE : -> `param_name` : It is the name of the parameter which was added using addXparam() or addParam(). - -### my_device.addParam() -It allows user to add custom parameter to the device created using `Param` class. -``` -esp_err_t addParam(Param parameter); -``` -* **Parameter** -1. `parameter` : Object of Param - -* **Return** -1. ESP_OK : On success -2. Error in case of failure -> NOTE : Param class exposes API's to create the custom parameter. - -### my_device.updateAndReportParam() -It updates the parameter assosicated with particular device on ESP RainMaker cloud. -``` -esp_err_t updateAndReportParam(const char *param_name, value); -``` -* **Parameters** -1. `param_name` : Name of the parameter -2. `value` : Value to be updated. It can be int, bool, char * , float. - -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -### my_device.addCb() -It registers read and write callback for the device which will be invoked as per requests received from the cloud (or other paths as may be added in future). -``` -void addCb(deviceWriteCb write_cb, deviceReadCb read_cb); -``` -* **Parameters** -1. `write_cb` : Function with signature [ func_name(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx); ] -2. `read_cb` : Function with signature [ func_name(Device *device, Param *param, void *priv_data, read_ctx_t *ctx); ] - -* **param_val_t val** -Value can be accessed as below -1. `bool` : val.val.b -2. `integer` : val.val.i -3. `float` : val.val.f -4. `char *` : val.val.s - -## ESP RainMaker PARAM API's -`Param` class expose API's for creating custom parameters for the devices and report and update values associated with parameter to the ESP RainMaker cloud. Parameterized constructor is defined which creates custom parameter. -> NOTE : my_param is the object of Param class. - -``` -Param my_param(const char *param_name, const char *param_type, param_val_t val, uint8_t properties); -``` -* **Parameters** -1. `param_name` : Name of the parameter -2. `param_type` : Type of the parameter. It is optional can be kept NULL. -3. `val` : Define the default value for the parameter. It should be defined using `value(int ival)` , `value(bool bval)` , `value(float fval)` , `value(char *sval)`. -4. `properties` : Properties of the parameter, which will be a logical OR of flags. - * Flags - * PROP_FLAG_WRITE - * PROP_FLAG_READ - * PROP_FLAG_TIME_SERIES - * PROP_FLAG_PERSIST - -`Sample example : Param my_param("bright", NULL, value(30), PROP_FLAG_READ | PROP_FLAG_WRITE | PROP_FLAG_PERSIST);` -> NOTE : Parameter created using Param class should be added to the device using `my_device.addParam(my_param);` - -### my_param.addUIType() -Add a UI type to the parameter. This will be used by the Phone apps (or other clients) to render appropriate UI for the given parameter. Please refer the RainMaker documentation [here](https://rainmaker.espressif.com/docs/standard-types.html#ui-elements) for supported UI Types. -``` -esp_err_t addUIType(const char *ui_type); -``` -* **Paramter** -1. `ui_type` : String describing the UI Type. - * Standard UI Types - * ESP_RMAKER_UI_TOGGLE - * ESP_RMAKER_UI_SLIDER - * ESP_RMAKER_UI_DROPDOWN - * ESP_RMAKER_UI_TEXT - -* **Returns** -1. ESP_OK : On success. -2. Error in case of failure. - -### my_param.addBounds() -Add bounds for an integer/float parameter. This can be used to add bounds (min/max values) for a given integer/float parameter. Eg. brightness will have bounds as 0 and 100 if it is a percentage. -``` -esp_err_t addBounds(param_val_t min, param_val_t max, param_val_t step); -``` -* **Parameters** -1. `min` : Minimum value -2. `max` : Maximum value -3. `step` : step Minimum stepping - -* **Returns** -1. ESP_OK : On success. -2. Error in case of failure. - -`Sample example : my_param.addBounds(value(0), value(100), value(5));` - -### my_param.updateAndReport() -It updates the parameter and report it to ESP RainMaker cloud. This is called in callback. -``` -esp_err_t updateAndReport(param_val_t val); -``` -* **Parameters** -1. `val` : New value of the parameter - -* **Return** -1. ESP_OK : On success. -2. Error in case of failure. - -> NOTE : -> - This API should always be called inside device write callback, if you aimed at updating n reporting parameter values, changed via RainMaker Client (Phone App), to the ESP RainMaker cloud. -> - If not called then paramter values will not be updated to the ESP RainMaker cloud. - -### printQR() -This API displays QR code, which is used in provisioning. -``` -printQR(const char *serv_name, const char *pop, const char *transport); -``` -* **Parameters** -1. `name` : Service name used in provisioning API. -2. `pop` : Proof of posession used in provisioning API. -3. `transport` : - 1. `softap` : In case of provisioning using SOFTAP. - 2. `ble` : In case of provisioning using BLE. - -### RMakerFactoryReset() -Reset the device to factory defaults. - -``` -RMakerFactoryReset(2); -``` -* **Parameters** -1. `seconds` : Time in seconds after which the chip should reboot after doing a factory reset. - - -### RMakerWiFiReset() -Reset Wi-Fi credentials. -``` -RMakerWiFiReset(2); -``` - -* **Parameters** -1. `seconds` : Time in seconds after which the chip should reboot after doing a Wi-Fi reset. diff --git a/libraries/RainMaker/examples/README.md b/libraries/RainMaker/examples/README.md deleted file mode 100644 index 6c5bded09ac..00000000000 --- a/libraries/RainMaker/examples/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# ESP RainMaker Examples - -While building any examples for ESP RainMaker, take care of the following: -1. Change partition scheme in Arduino IDE to RainMaker (Tools -> Partition Scheme -> RainMaker). -2. Once ESP RainMaker gets started, compulsorily call `WiFi.beginProvision()` which is responsible for user-node mapping. -3. Use appropriate provisioning scheme as per the board. - - ESP32 Board: BLE Provisioning - - ESP32S2 Board: SoftAP Provisioning -4. Set debug level to Info (Tools -> Core Debug Level -> Info). This is recommended, but not mandatory. - diff --git a/libraries/RainMaker/examples/RMakerCustom/README.md b/libraries/RainMaker/examples/RMakerCustom/README.md deleted file mode 100644 index 42c998d49c4..00000000000 --- a/libraries/RainMaker/examples/RMakerCustom/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# ESP RainMaker Custom Device - -This example demonstrates how to build a custom device to be used with ESP RainMaker. - -## What to expect in this example? - -- This example sketch uses the on board Boot button and GPIO16 to demonstrate an ESP RainMaker AC dimmer device. -- After compiling and flashing the example, add your device using the [ESP RainMaker phone apps](https://rainmaker.espressif.com/docs/quick-links.html#phone-apps) by scanning the QR code. -- Toggling the state from the phone app will toggle the dimmer state (GPIO16). -- Pressing the Boot button will toggle the dimmer state (GPIO16) and the same will reflect on the phone app. -- You can also change the Level from the phone app and see it reflect on the device as a print message. - -### Output - -``` -[ 87][I][RMaker.cpp:13] event_handler(): RainMaker Initialised. -[ 94][I][WiFiProv.cpp:158] beginProvision(): Already Provisioned -[ 95][I][WiFiProv.cpp:162] beginProvision(): Attempting connect to AP: Viking007_2GEXT - -Received value = false for Dimmer - Power -Toggle State to true. -[ 22532][I][RMakerDevice.cpp:162] updateAndReportParam(): Device : Dimmer, Param Name : Power, Val : true - -Received value = 73 for Dimmer - Level -``` - -### Resetting the device -- Press and Hold the Boot button for more than 3 seconds and then release to reset Wi-Fi configuration. -- Press and Hold the Boot button for more than 10 seconds and then release to reset to factory defaults. diff --git a/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino b/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino deleted file mode 100644 index 55012e413c6..00000000000 --- a/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino +++ /dev/null @@ -1,126 +0,0 @@ -//This example demonstrates the ESP RainMaker with a custom device -#include "RMaker.h" -#include "WiFi.h" -#include "WiFiProv.h" - -#define DEFAULT_POWER_MODE true -#define DEFAULT_DIMMER_LEVEL 50 -const char *service_name = "PROV_1234"; -const char *pop = "abcd1234"; - -//GPIO for push button -static int gpio_0 = 0; -//GPIO for virtual device -static int gpio_dimmer = 16; -/* Variable for reading pin status*/ -bool dimmer_state = true; - -// The framework provides some standard device types like switch, lightbulb, fan, temperature sensor. -// But, you can also define custom devices using the 'Device' base class object, as shown here -static Device my_device("Dimmer", "custom.device.dimmer", &gpio_dimmer); - -void sysProvEvent(arduino_event_t *sys_event) -{ - switch (sys_event->event_id) { - case ARDUINO_EVENT_PROV_START: -#if CONFIG_IDF_TARGET_ESP32 - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - printQR(service_name, pop, "ble"); -#else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); - printQR(service_name, pop, "softap"); -#endif - break; - } -} - -void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) -{ - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if(strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name); - dimmer_state = val.val.b; - (dimmer_state == false) ? digitalWrite(gpio_dimmer, LOW) : digitalWrite(gpio_dimmer, HIGH); - param->updateAndReport(val); - } else if (strcmp(param_name, "Level") == 0) { - Serial.printf("\nReceived value = %d for %s - %s\n", val.val.i, device_name, param_name); - param->updateAndReport(val); - } -} - -void setup() -{ - Serial.begin(115200); - pinMode(gpio_0, INPUT); - pinMode(gpio_dimmer, OUTPUT); - digitalWrite(gpio_dimmer, DEFAULT_POWER_MODE); - - Node my_node; - my_node = RMaker.initNode("ESP RainMaker Node"); - - //Create custom dimmer device - my_device.addNameParam(); - my_device.addPowerParam(DEFAULT_POWER_MODE); - my_device.assignPrimaryParam(my_device.getParamByName(ESP_RMAKER_DEF_POWER_NAME)); - - //Create and add a custom level parameter - Param level_param("Level", "custom.param.level", value(DEFAULT_DIMMER_LEVEL), PROP_FLAG_READ | PROP_FLAG_WRITE); - level_param.addBounds(value(0), value(100), value(1)); - level_param.addUIType(ESP_RMAKER_UI_SLIDER); - my_device.addParam(level_param); - - my_device.addCb(write_callback); - - //Add custom dimmer device to the node - my_node.addDevice(my_device); - - //This is optional - RMaker.enableOTA(OTA_USING_PARAMS); - //If you want to enable scheduling, set time zone for your region using setTimeZone(). - //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html - // RMaker.setTimeZone("Asia/Shanghai"); - // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone - RMaker.enableTZService(); - - RMaker.enableSchedule(); - - RMaker.start(); - - WiFi.onEvent(sysProvEvent); -#if CONFIG_IDF_TARGET_ESP32 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); -#else - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); -#endif -} - -void loop() -{ - if(digitalRead(gpio_0) == LOW) { //Push button pressed - - // Key debounce handling - delay(100); - int startTime = millis(); - while(digitalRead(gpio_0) == LOW) delay(50); - int endTime = millis(); - - if ((endTime - startTime) > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if ((endTime - startTime) > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } else { - // Toggle device state - dimmer_state = !dimmer_state; - Serial.printf("Toggle State to %s.\n", dimmer_state ? "true" : "false"); - my_device.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, dimmer_state); - (dimmer_state == false) ? digitalWrite(gpio_dimmer, LOW) : digitalWrite(gpio_dimmer, HIGH); - } - } - delay(100); -} diff --git a/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino b/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino deleted file mode 100644 index 37eda40134b..00000000000 --- a/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino +++ /dev/null @@ -1,193 +0,0 @@ -//This example demonstrates the ESP RainMaker with a standard Switch device. -#include "RMaker.h" -#include "WiFi.h" -#include "WiFiProv.h" - -#define DEFAULT_POWER_MODE false -const char *service_name = "PROV_SONOFF_DUALR3"; -const char *pop = "123456"; - -// GPIO for push button -static uint8_t gpio_reset = 0; -// GPIO for switch -static uint8_t gpio_switch1 = 32; -static uint8_t gpio_switch2 = 33; -// GPIO for virtual device -static uint8_t gpio_relay1 = 27; -static uint8_t gpio_relay2 = 14; -/* Variable for reading pin status*/ -bool switch_state_ch1 = true; -bool switch_state_ch2 = true; -// GPIO for link status LED -static uint8_t gpio_led = 13; - -struct LightSwitch { - const uint8_t pin; - bool pressed; -}; - -// Define the light switches for channel 1 and 2 -LightSwitch switch_ch1 = {gpio_switch1, false}; -LightSwitch switch_ch2 = {gpio_switch2, false}; - -//The framework provides some standard device types like switch, lightbulb, fan, temperature sensor. -static Switch my_switch1("Switch_ch1", &gpio_relay1); -static Switch my_switch2("Switch_ch2", &gpio_relay2); - -void sysProvEvent(arduino_event_t *sys_event) -{ - switch (sys_event->event_id) { - case ARDUINO_EVENT_PROV_START: -#if CONFIG_IDF_TARGET_ESP32 - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - printQR(service_name, pop, "ble"); -#else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); - printQR(service_name, pop, "softap"); -#endif - break; - case ARDUINO_EVENT_WIFI_STA_CONNECTED: - Serial.printf("\nConnected to Wi-Fi!\n"); - digitalWrite(gpio_led, true); - break; - } -} - -void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) -{ - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if(strcmp(device_name, "Switch_ch1") == 0) { - - Serial.printf("Lightbulb = %s\n", val.val.b? "true" : "false"); - - if(strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name); - switch_state_ch1 = val.val.b; - (switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH); - param->updateAndReport(val); - } - - } else if(strcmp(device_name, "Switch_ch2") == 0) { - - Serial.printf("Switch value = %s\n", val.val.b? "true" : "false"); - - if(strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name); - switch_state_ch2 = val.val.b; - (switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH); - param->updateAndReport(val); - } - - } - -} - -void ARDUINO_ISR_ATTR isr(void* arg) { - LightSwitch* s = static_cast(arg); - s->pressed = true; -} - -void setup() -{ - uint32_t chipId = 0; - - Serial.begin(115200); - - // Configure the input GPIOs - pinMode(gpio_reset, INPUT); - pinMode(switch_ch1.pin, INPUT_PULLUP); - attachInterruptArg(switch_ch1.pin, isr, &switch_ch1, CHANGE); - pinMode(switch_ch2.pin, INPUT_PULLUP); - attachInterruptArg(switch_ch2.pin, isr, &switch_ch2, CHANGE); - - // Set the Relays GPIOs as output mode - pinMode(gpio_relay1, OUTPUT); - pinMode(gpio_relay2, OUTPUT); - pinMode(gpio_led, OUTPUT); - // Write to the GPIOs the default state on booting - digitalWrite(gpio_relay1, DEFAULT_POWER_MODE); - digitalWrite(gpio_relay2, DEFAULT_POWER_MODE); - digitalWrite(gpio_led, false); - - Node my_node; - my_node = RMaker.initNode("Sonoff Dual R3"); - - //Standard switch device - my_switch1.addCb(write_callback); - my_switch2.addCb(write_callback); - - //Add switch device to the node - my_node.addDevice(my_switch1); - my_node.addDevice(my_switch2); - - //This is optional - RMaker.enableOTA(OTA_USING_PARAMS); - //If you want to enable scheduling, set time zone for your region using setTimeZone(). - //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html - // RMaker.setTimeZone("Asia/Shanghai"); - // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone - RMaker.enableTZService(); - RMaker.enableSchedule(); - - //Service Name - for(int i=0; i<17; i=i+8) { - chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; - } - - Serial.printf("\nChip ID: %d Service Name: %s\n", chipId, service_name); - - Serial.printf("\nStarting ESP-RainMaker\n"); - RMaker.start(); - - WiFi.onEvent(sysProvEvent); -#if CONFIG_IDF_TARGET_ESP32 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); -#else - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); -#endif -} - -void loop() -{ - - if (switch_ch1.pressed) { - Serial.printf("Switch 1 has been changed\n"); - switch_ch1.pressed = false; - // Toggle switch 1 device state - switch_state_ch1 = !switch_state_ch1; - Serial.printf("Toggle State to %s.\n", switch_state_ch1 ? "true" : "false"); - my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch1); - (switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH); - } else if (switch_ch2.pressed) { - Serial.printf("Switch 2 has been changed\n"); - switch_ch2.pressed = false; - // Toggle switch 2 device state - switch_state_ch2 = !switch_state_ch2; - Serial.printf("Toggle State to %s.\n", switch_state_ch2 ? "true" : "false"); - my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch2); - (switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH); - } - - // Read GPIO0 (external button to reset device - if(digitalRead(gpio_reset) == LOW) { //Push button pressed - Serial.printf("Reset Button Pressed!\n"); - // Key debounce handling - delay(100); - int startTime = millis(); - while(digitalRead(gpio_reset) == LOW) delay(50); - int endTime = millis(); - - if ((endTime - startTime) > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if ((endTime - startTime) > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } - } - delay(100); -} diff --git a/libraries/RainMaker/examples/RMakerSwitch/README.md b/libraries/RainMaker/examples/RMakerSwitch/README.md deleted file mode 100644 index 55b5ab1ed41..00000000000 --- a/libraries/RainMaker/examples/RMakerSwitch/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# ESP RainMaker Switch - -This example demonstrates how to build a switch device to be used with ESP RainMaker. - -## What to expect in this example? - -- This example sketch uses the on board Boot button and GPIO16 to demonstrate an ESP RainMaker switch device. -- After compiling and flashing the example, add your device using the [ESP RainMaker phone apps](https://rainmaker.espressif.com/docs/quick-links.html#phone-apps) by scanning the QR code. -- Toggling the state from the phone app will toggle the switch state (GPIO16). -- Pressing the Boot button will toggle the switch state (GPIO16) and the same will reflect on the phone app. - -### Output - -``` -[ 63][I][RMaker.cpp:13] event_handler(): RainMaker Initialised. -[ 69][I][WiFiProv.cpp:158] beginProvision(): Already Provisioned -[ 69][I][WiFiProv.cpp:162] beginProvision(): Attempting connect to AP: Viking007_2GEXT - -Toggle State to false. -[ 8182][I][RMakerDevice.cpp:162] updateAndReportParam(): Device : Switch, Param Name : Power, Val : false -Toggle State to true. -[ 9835][I][RMakerDevice.cpp:162] updateAndReportParam(): Device : Switch, Param Name : Power, Val : true -Received value = false for Switch - Power -Received value = true for Switch - Power -Toggle State to false. -[ 29937][I][RMakerDevice.cpp:162] updateAndReportParam(): Device : Switch, Param Name : Power, Val : false -``` - -### Resetting the device -- Press and Hold the Boot button for more than 3 seconds and then release to reset Wi-Fi configuration. -- Press and Hold the Boot button for more than 10 seconds and then release to reset to factory defaults. diff --git a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino b/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino deleted file mode 100644 index e486bd200fb..00000000000 --- a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino +++ /dev/null @@ -1,111 +0,0 @@ -//This example demonstrates the ESP RainMaker with a standard Switch device. -#include "RMaker.h" -#include "WiFi.h" -#include "WiFiProv.h" - -#define DEFAULT_POWER_MODE true -const char *service_name = "PROV_1234"; -const char *pop = "abcd1234"; - -//GPIO for push button -static int gpio_0 = 0; -//GPIO for virtual device -static int gpio_switch = 16; -/* Variable for reading pin status*/ -bool switch_state = true; - -//The framework provides some standard device types like switch, lightbulb, fan, temperaturesensor. -static Switch my_switch("Switch", &gpio_switch); - -void sysProvEvent(arduino_event_t *sys_event) -{ - switch (sys_event->event_id) { - case ARDUINO_EVENT_PROV_START: -#if CONFIG_IDF_TARGET_ESP32 - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - printQR(service_name, pop, "ble"); -#else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); - printQR(service_name, pop, "softap"); -#endif - break; - } -} - -void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) -{ - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if(strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name); - switch_state = val.val.b; - (switch_state == false) ? digitalWrite(gpio_switch, LOW) : digitalWrite(gpio_switch, HIGH); - param->updateAndReport(val); - } -} - -void setup() -{ - Serial.begin(115200); - pinMode(gpio_0, INPUT); - pinMode(gpio_switch, OUTPUT); - digitalWrite(gpio_switch, DEFAULT_POWER_MODE); - - Node my_node; - my_node = RMaker.initNode("ESP RainMaker Node"); - - //Standard switch device - my_switch.addCb(write_callback); - - //Add switch device to the node - my_node.addDevice(my_switch); - - //This is optional - RMaker.enableOTA(OTA_USING_PARAMS); - //If you want to enable scheduling, set time zone for your region using setTimeZone(). - //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html - // RMaker.setTimeZone("Asia/Shanghai"); - // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone - RMaker.enableTZService(); - - RMaker.enableSchedule(); - - RMaker.start(); - - WiFi.onEvent(sysProvEvent); -#if CONFIG_IDF_TARGET_ESP32 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); -#else - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name); -#endif -} - -void loop() -{ - if(digitalRead(gpio_0) == LOW) { //Push button pressed - - // Key debounce handling - delay(100); - int startTime = millis(); - while(digitalRead(gpio_0) == LOW) delay(50); - int endTime = millis(); - - if ((endTime - startTime) > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if ((endTime - startTime) > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } else { - // Toggle device state - switch_state = !switch_state; - Serial.printf("Toggle State to %s.\n", switch_state ? "true" : "false"); - my_switch.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state); - (switch_state == false) ? digitalWrite(gpio_switch, LOW) : digitalWrite(gpio_switch, HIGH); - } - } - delay(100); -} diff --git a/libraries/RainMaker/library.properties b/libraries/RainMaker/library.properties deleted file mode 100644 index b144328fef2..00000000000 --- a/libraries/RainMaker/library.properties +++ /dev/null @@ -1,8 +0,0 @@ -name=ESP RainMaker -version=2.0.0 -author=Sweety Mhaiske -maintainer=Hristo Gochkov -sentence=ESP RainMaker Support -paragraph=With this library you can build connected devices and access them via phone apps without having to manage the infrastructure. -url=https://rainmaker.espressif.com -architectures=esp32,esp32s2 diff --git a/libraries/RainMaker/src/RMaker.cpp b/libraries/RainMaker/src/RMaker.cpp deleted file mode 100644 index de6903c0538..00000000000 --- a/libraries/RainMaker/src/RMaker.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "RMaker.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 -#include -#include -bool wifiLowLevelInit(bool persistent); -static esp_err_t err; - -static void event_handler(void *arg, esp_event_base_t event_base, int event_id, void *event_data) -{ - if (event_base == RMAKER_EVENT) { - switch (event_id) { - case RMAKER_EVENT_INIT_DONE: - log_i("RainMaker Initialised."); - break; - case RMAKER_EVENT_CLAIM_STARTED: - log_i("RainMaker Claim Started."); - break; - case RMAKER_EVENT_CLAIM_SUCCESSFUL: - log_i("RainMaker Claim Successful."); - break; - case RMAKER_EVENT_CLAIM_FAILED: - log_i("RainMaker Claim Failed."); - break; - default: - log_i("Unhandled RainMaker Event:"); - } - } -} - -void RMakerClass::setTimeSync(bool val) -{ - rainmaker_cfg.enable_time_sync = val; -} - -Node RMakerClass::initNode(const char *name, const char *type) -{ - wifiLowLevelInit(true); - Node node; - esp_rmaker_node_t *rnode = NULL; - esp_event_handler_register(RMAKER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); - rnode = esp_rmaker_node_init(&rainmaker_cfg, name, type); - if (!rnode){ - log_e("Node init failed"); - return node; - } - node.setNodeHandle(rnode); - return node; -} - -esp_err_t RMakerClass::start() -{ - err = esp_rmaker_start(); - if(err != ESP_OK){ - log_e("ESP RainMaker core task failed"); - } - return err; -} - -esp_err_t RMakerClass::stop() -{ - err = esp_rmaker_stop(); - if(err != ESP_OK) { - log_e("ESP RainMaker stop error"); - } - return err; -} - -esp_err_t RMakerClass::deinitNode(Node rnode) -{ - err = esp_rmaker_node_deinit(rnode.getNodeHandle()); - if(err != ESP_OK) { - log_e("Node deinit failed"); - } - return err; -} - -esp_err_t RMakerClass::setTimeZone(const char *tz) -{ - err = esp_rmaker_time_set_timezone(tz); - if(err != ESP_OK) { - log_e("Setting time zone error"); - } - return err; -} - -esp_err_t RMakerClass::enableSchedule() -{ - err = esp_rmaker_schedule_enable(); - if(err != ESP_OK) { - log_e("Schedule enable failed"); - } - return err; -} - -esp_err_t RMakerClass::enableTZService() -{ - err = esp_rmaker_timezone_service_enable(); - if(err != ESP_OK) { - log_e("Timezone service enable failed"); - } - return err; -} - -esp_err_t RMakerClass::enableOTA(ota_type_t type, const char *cert) -{ - esp_rmaker_ota_config_t ota_config; - ota_config.server_cert = cert; - err = esp_rmaker_ota_enable(&ota_config, type); - if(err != ESP_OK) { - log_e("OTA enable failed"); - } - return err; -} - -RMakerClass RMaker; -#endif diff --git a/libraries/RainMaker/src/RMaker.h b/libraries/RainMaker/src/RMaker.h deleted file mode 100644 index 53c60bce189..00000000000 --- a/libraries/RainMaker/src/RMaker.h +++ /dev/null @@ -1,30 +0,0 @@ -#include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - -#include "Arduino.h" -#include "RMakerNode.h" -#include "RMakerQR.h" -#include "RMakerUtils.h" -#include - -class RMakerClass -{ - private: - esp_rmaker_config_t rainmaker_cfg = {false}; - - public: - - void setTimeSync(bool val); - Node initNode(const char *name, const char *type = "ESP RainMaker with Arduino"); - esp_err_t deinitNode(Node node); - esp_err_t setTimeZone(const char *tz = "Asia/Shanghai"); - esp_err_t enableSchedule(); - esp_err_t enableTZService(); - esp_err_t enableOTA(ota_type_t type, const char *cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT); - esp_err_t start(); - esp_err_t stop(); -}; - -extern RMakerClass RMaker; - -#endif diff --git a/libraries/RainMaker/src/RMakerDevice.cpp b/libraries/RainMaker/src/RMakerDevice.cpp deleted file mode 100644 index e0108c32963..00000000000 --- a/libraries/RainMaker/src/RMakerDevice.cpp +++ /dev/null @@ -1,209 +0,0 @@ -#include "RMakerDevice.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - -static esp_err_t err; -typedef void (*deviceWriteCb)(Device*, Param*, const param_val_t val, void *priv_data, write_ctx_t *ctx); -typedef void (*deviceReadCb)(Device*, Param*, void *priv_data, read_ctx_t *ctx); - -void (*write_cb)(Device*, Param*, param_val_t, void*, write_ctx_t*); -void (*read_cb)(Device*, Param*, void*, read_ctx_t*); -Device device; -Param param; - -static esp_err_t write_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, const param_val_t val, void *priv_data, write_ctx_t *ctx) -{ - device.setDeviceHandle(dev_handle); - param.setParamHandle(par_handle); - - write_cb(&device, ¶m, val, priv_data, ctx); - return ESP_OK; -} - -static esp_err_t read_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, void *priv_data, read_ctx_t *ctx) -{ - device.setDeviceHandle(dev_handle); - param.setParamHandle(par_handle); - - read_cb(&device, ¶m, priv_data, ctx); - return ESP_OK; -} - -esp_err_t Device::deleteDevice() -{ - err = esp_rmaker_device_delete(getDeviceHandle()); - if(err != ESP_OK) { - log_e("Device deletion error"); - return err; - } - return ESP_OK; -} - -void Device::addCb(deviceWriteCb writeCb, deviceReadCb readCb) -{ - write_cb = writeCb; - read_cb = readCb; - err = esp_rmaker_device_add_cb(getDeviceHandle(), write_callback, read_callback); - if(err != ESP_OK) { - log_e("Callback register error"); - } -} - -esp_err_t Device::addDeviceAttr(const char *attr_name, const char *val) -{ - err = esp_rmaker_device_add_attribute(getDeviceHandle(), attr_name, val); - if(err != ESP_OK) { - log_e("Failed to add attriute to the device"); - return err; - } - return ESP_OK; -} - -//Generic Parameter -esp_err_t Device::addParam(Param parameter) -{ - err = esp_rmaker_device_add_param(getDeviceHandle(), parameter.getParamHandle()); - if(err != ESP_OK) { - log_e("Adding custom parameter error"); - return err; - } - return ESP_OK; -} - -//Standard Device Parameter -esp_err_t Device::addNameParam(const char *param_name) -{ - param_handle_t *param = esp_rmaker_name_param_create(param_name, getDeviceName()); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addPowerParam(bool val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_power_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addBrightnessParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_brightness_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addHueParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_hue_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addSaturationParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_saturation_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addIntensityParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_intensity_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addCCTParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_cct_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addDirectionParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_direction_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addSpeedParam(int val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_speed_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addTempratureParam(float val, const char *param_name) -{ - param_handle_t *param = esp_rmaker_temperature_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -param_handle_t *Device::getParamByName(const char *param_name) -{ - return esp_rmaker_device_get_param_by_name(getDeviceHandle(), param_name); -} - -esp_err_t Device::assignPrimaryParam(param_handle_t *param) -{ - err = esp_rmaker_device_assign_primary_param(getDeviceHandle(), param); - if(err != ESP_OK){ - log_e("Assigning primary param error"); - } - return err; -} - -const param_handle_t* getParamHandlebyName(const esp_rmaker_device_t *device_handle, const char *param_name) -{ - const param_handle_t *param = esp_rmaker_device_get_param_by_name(device_handle, param_name); - return param; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, bool my_val) -{ - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_bool(my_val); - err = esp_rmaker_param_update_and_report(param, val); - if(err != ESP_OK) { - log_e("Update paramter failed"); - return err; - }else { - log_i("Device : %s, Param Name : %s, Val : %s", getDeviceName(), param_name, my_val ? "true" : "false"); - } - return ESP_OK; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, int my_val) -{ - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_int(my_val); - esp_err_t err = esp_rmaker_param_update_and_report(param, val); - if(err != ESP_OK) { - log_e("Update paramter failed"); - return err; - }else { - log_i("Device : %s, Param Name : %s, Val : %d", getDeviceName(), param_name, my_val); - } - return ESP_OK; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, float my_val) -{ - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_float(my_val); - esp_err_t err = esp_rmaker_param_update_and_report(param, val); - if(err != ESP_OK) { - log_e("Update paramter failed"); - return err; - }else { - log_i("Device : %s, Param Name : %s, Val : %f", getDeviceName(), param_name, my_val); - } - return ESP_OK; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, const char *my_val) -{ - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_str(my_val); - esp_err_t err = esp_rmaker_param_update_and_report(param, val); - if(err != ESP_OK) { - log_e("Update paramter failed"); - return err; - }else { - log_i("Device : %s, Param Name : %s, Val : %s", getDeviceName(), param_name, my_val); - } - return ESP_OK; -} - -#endif diff --git a/libraries/RainMaker/src/RMakerDevice.h b/libraries/RainMaker/src/RMakerDevice.h deleted file mode 100644 index 13cb67ac302..00000000000 --- a/libraries/RainMaker/src/RMakerDevice.h +++ /dev/null @@ -1,154 +0,0 @@ -#include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - -#include "RMakerParam.h" -#include -#include - -class Device -{ - private: - const device_handle_t *device_handle; - - public: - Device() - { - device_handle = NULL; - } - Device(const char *dev_name, const char *dev_type = NULL, void *priv_data = NULL) - { - device_handle = esp_rmaker_device_create(dev_name, dev_type, priv_data); - if(device_handle == NULL){ - log_e("Device create error"); - } - } - void setDeviceHandle(const esp_rmaker_device_t *device_handle) - { - this->device_handle = device_handle; - } - const char *getDeviceName() - { - return esp_rmaker_device_get_name(device_handle); - } - const esp_rmaker_device_t *getDeviceHandle() - { - return device_handle; - } - - typedef void (*deviceWriteCb)(Device*, Param*, const param_val_t val, void *priv_data, write_ctx_t *ctx); - typedef void (*deviceReadCb)(Device*, Param*, void *priv_data, read_ctx_t *ctx); - - esp_err_t deleteDevice(); - void addCb(deviceWriteCb write_cb, deviceReadCb read_cb = NULL); - esp_err_t addDeviceAttr(const char *attr_name, const char *val); - param_handle_t *getParamByName(const char *param_name); - esp_err_t assignPrimaryParam(param_handle_t *param); - - //Generic Device Parameter - esp_err_t addParam(Param parameter); - - //Standard Device Parameter - esp_err_t addNameParam(const char *param_name = ESP_RMAKER_DEF_NAME_PARAM); - esp_err_t addPowerParam(bool val, const char *param_name = ESP_RMAKER_DEF_POWER_NAME); - esp_err_t addBrightnessParam(int val, const char *param_name = ESP_RMAKER_DEF_BRIGHTNESS_NAME); - esp_err_t addHueParam(int val, const char *param_name = ESP_RMAKER_DEF_HUE_NAME); - esp_err_t addSaturationParam(int val, const char *param_name = ESP_RMAKER_DEF_SATURATION_NAME); - esp_err_t addIntensityParam(int val, const char *param_name = ESP_RMAKER_DEF_INTENSITY_NAME); - esp_err_t addCCTParam(int val, const char *param_name = ESP_RMAKER_DEF_CCT_NAME); - esp_err_t addDirectionParam(int val, const char *param_name = ESP_RMAKER_DEF_DIRECTION_NAME); - esp_err_t addSpeedParam(int val, const char *param_name = ESP_RMAKER_DEF_SPEED_NAME); - esp_err_t addTempratureParam(float val, const char *param_name = ESP_RMAKER_DEF_TEMPERATURE_NAME); - - //Update Parameter - esp_err_t updateAndReportParam(const char *param_name, bool val); - esp_err_t updateAndReportParam(const char *param_name, int val); - esp_err_t updateAndReportParam(const char *param_name, float val); - esp_err_t updateAndReportParam(const char *param_name, const char *val); - -}; - -class Switch : public Device -{ - public: - Switch() - { - standardSwitchDevice("Switch", NULL, true); - } - Switch(const char *dev_name, void *priv_data = NULL, bool power = true) - { - standardSwitchDevice(dev_name, priv_data, power); - } - void standardSwitchDevice(const char *dev_name, void *priv_data, bool power) - { - esp_rmaker_device_t *dev_handle = esp_rmaker_switch_device_create(dev_name, priv_data, power); - setDeviceHandle(dev_handle); - if(dev_handle == NULL){ - log_e("Switch device not created"); - } - } -}; - -class LightBulb : public Device -{ - public: - LightBulb() - { - standardLightBulbDevice("Light", NULL, true); - } - LightBulb(const char *dev_name, void *priv_data = NULL, bool power = true) - { - standardLightBulbDevice(dev_name, priv_data, power); - } - void standardLightBulbDevice(const char *dev_name, void *priv_data, bool power) - { - esp_rmaker_device_t *dev_handle = esp_rmaker_lightbulb_device_create(dev_name, priv_data, power); - setDeviceHandle(dev_handle); - if(dev_handle == NULL){ - log_e("Light device not created"); - } - } -}; - -class Fan : public Device -{ - public: - Fan() - { - standardFanDevice("Fan", NULL, true); - } - Fan(const char *dev_name, void *priv_data = NULL, bool power = true) - { - standardFanDevice(dev_name, priv_data, power); - } - void standardFanDevice(const char *dev_name, void *priv_data, bool power) - { - esp_rmaker_device_t *dev_handle = esp_rmaker_fan_device_create(dev_name, priv_data, power); - setDeviceHandle(dev_handle); - if(dev_handle == NULL){ - log_e("Fan device not created"); - } - } -}; - -class TemperatureSensor : public Device -{ - public: - TemperatureSensor() - { - standardTemperatureSensorDevice("Temperature-Sensor", NULL, 25.0); - } - TemperatureSensor(const char *dev_name, void *priv_data = NULL, float temp = 25.0) - { - standardTemperatureSensorDevice(dev_name, priv_data, temp); - } - void standardTemperatureSensorDevice(const char *dev_name, void *priv_data, float temp) - { - esp_rmaker_device_t *dev_handle = esp_rmaker_temp_sensor_device_create(dev_name, priv_data, temp); - setDeviceHandle(dev_handle); - if(dev_handle == NULL){ - log_e("Temperature Sensor device not created"); - } - } -}; - -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerNode.cpp b/libraries/RainMaker/src/RMakerNode.cpp deleted file mode 100644 index 3f2555f8b05..00000000000 --- a/libraries/RainMaker/src/RMakerNode.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "RMakerNode.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 -static esp_err_t err; - -esp_err_t Node::addDevice(Device device) -{ - err = esp_rmaker_node_add_device(node, device.getDeviceHandle()); - if(err != ESP_OK){ - log_e("Device was not added to the Node"); - } - return err; -} - -esp_err_t Node::removeDevice(Device device) -{ - err = esp_rmaker_node_remove_device(node, device.getDeviceHandle()); - if(err != ESP_OK){ - log_e("Device was not removed from the Node"); - } - return err; -} - -char *Node::getNodeID() -{ - return esp_rmaker_get_node_id(); -} - -node_info_t *Node::getNodeInfo() -{ - return esp_rmaker_node_get_info(node); -} - -esp_err_t Node::addNodeAttr(const char *attr_name, const char *val) -{ - err = esp_rmaker_node_add_attribute(node, attr_name, val); - if(err != ESP_OK) { - log_e("Failed to add attribute to the Node"); - } - return err; -} -#endif diff --git a/libraries/RainMaker/src/RMakerNode.h b/libraries/RainMaker/src/RMakerNode.h deleted file mode 100644 index 733ca407f96..00000000000 --- a/libraries/RainMaker/src/RMakerNode.h +++ /dev/null @@ -1,33 +0,0 @@ -#include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - -#include "RMakerDevice.h" - -class Node -{ - private: - esp_rmaker_node_t *node; - - public: - Node() - { - node = NULL; - } - void setNodeHandle(esp_rmaker_node_t *rnode) - { - node = rnode; - } - esp_rmaker_node_t *getNodeHandle() - { - return node; - } - - esp_err_t addDevice(Device device); - esp_err_t removeDevice(Device device); - - char *getNodeID(); - node_info_t *getNodeInfo(); - esp_err_t addNodeAttr(const char *attr_name, const char *val); -}; - -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerParam.cpp b/libraries/RainMaker/src/RMakerParam.cpp deleted file mode 100644 index e1de774017f..00000000000 --- a/libraries/RainMaker/src/RMakerParam.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "RMakerParam.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - -static esp_err_t err; - -esp_err_t Param::addUIType(const char *ui_type) -{ - err = esp_rmaker_param_add_ui_type(param_handle, ui_type); - if(err != ESP_OK) { - log_e("Add UI type error"); - } - return err; -} - -esp_err_t Param::addBounds(param_val_t min, param_val_t max, param_val_t step) -{ - err = esp_rmaker_param_add_bounds(param_handle, min, max, step); - if(err != ESP_OK) { - log_e("Add Bounds error"); - } - return err; -} - -esp_err_t Param::updateAndReport(param_val_t val) -{ - err = esp_rmaker_param_update_and_report(getParamHandle(), val); - if(err != ESP_OK){ - log_e("Update and Report param failed"); - } - return err; -} - -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerParam.h b/libraries/RainMaker/src/RMakerParam.h deleted file mode 100644 index 0bd9aedb116..00000000000 --- a/libraries/RainMaker/src/RMakerParam.h +++ /dev/null @@ -1,38 +0,0 @@ -#include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - -#include "RMakerType.h" - -class Param -{ - private: - const param_handle_t *param_handle; - - public: - Param() - { - param_handle = NULL; - } - Param(const char *param_name, const char *param_type, param_val_t val, uint8_t properties) - { - param_handle = esp_rmaker_param_create(param_name, param_type, val, properties); - } - void setParamHandle(const param_handle_t *param_handle) - { - this->param_handle = param_handle; - } - const char *getParamName() - { - return esp_rmaker_param_get_name(param_handle); - } - const param_handle_t *getParamHandle() - { - return param_handle; - } - - esp_err_t addUIType(const char *ui_type); - esp_err_t addBounds(param_val_t min, param_val_t max, param_val_t step); - esp_err_t updateAndReport(param_val_t val); -}; - -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerQR.h b/libraries/RainMaker/src/RMakerQR.h deleted file mode 100644 index fd5053d0dde..00000000000 --- a/libraries/RainMaker/src/RMakerQR.h +++ /dev/null @@ -1,24 +0,0 @@ -#include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - -#include - -#define PROV_QR_VERSION "v1" -#define QRCODE_BASE_URL "https://rainmaker.espressif.com/qrcode.html" - -static void printQR(const char *name, const char *pop, const char *transport) -{ - if (!name || !pop || !transport) { - log_w("Cannot generate QR code payload. Data missing."); - return; - } - char payload[150]; - snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" \ - ",\"pop\":\"%s\",\"transport\":\"%s\"}", - PROV_QR_VERSION, name, pop, transport); - Serial.printf("Scan this QR code from the ESP RainMaker phone app.\n"); - qrcode_display(payload); - Serial.printf("If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s\n", QRCODE_BASE_URL, payload); -} - -#endif diff --git a/libraries/RainMaker/src/RMakerType.cpp b/libraries/RainMaker/src/RMakerType.cpp deleted file mode 100644 index a4f6f2f381f..00000000000 --- a/libraries/RainMaker/src/RMakerType.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "RMakerType.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - -param_val_t value(int ival) -{ - return esp_rmaker_int(ival); -} - -param_val_t value(bool bval) -{ - return esp_rmaker_bool(bval); -} - -param_val_t value(char *sval) -{ - return esp_rmaker_str(sval); -} - -param_val_t value(float fval) -{ - return esp_rmaker_float(fval); -} - -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerType.h b/libraries/RainMaker/src/RMakerType.h deleted file mode 100644 index 09029f9e8a0..00000000000 --- a/libraries/RainMaker/src/RMakerType.h +++ /dev/null @@ -1,23 +0,0 @@ -#include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - -#include -#include -#include -#include - -typedef esp_rmaker_node_t* node_t; -typedef esp_rmaker_node_info_t node_info_t; -typedef esp_rmaker_param_val_t param_val_t; -typedef esp_rmaker_write_ctx_t write_ctx_t; -typedef esp_rmaker_read_ctx_t read_ctx_t; -typedef esp_rmaker_device_t device_handle_t; -typedef esp_rmaker_param_t param_handle_t; -typedef esp_rmaker_ota_type_t ota_type_t; - -param_val_t value(int); -param_val_t value(bool); -param_val_t value(char *); -param_val_t value(float); - -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerUtils.h b/libraries/RainMaker/src/RMakerUtils.h deleted file mode 100644 index 41745d2e027..00000000000 --- a/libraries/RainMaker/src/RMakerUtils.h +++ /dev/null @@ -1,16 +0,0 @@ -#include "esp_system.h" -#if ESP_IDF_VERSION_MAJOR >= 4 && CONFIG_ESP_RMAKER_TASK_STACK && CONFIG_IDF_TARGET_ESP32 - -#include - -static void RMakerFactoryReset(int seconds) -{ - esp_rmaker_factory_reset(seconds); -} - -static void RMakerWiFiReset(int seconds) -{ - esp_rmaker_wifi_reset(seconds); -} - -#endif diff --git a/libraries/SD/src/sd_diskio.cpp b/libraries/SD/src/sd_diskio.cpp index cf85f67d5b1..038c26ade36 100644 --- a/libraries/SD/src/sd_diskio.cpp +++ b/libraries/SD/src/sd_diskio.cpp @@ -121,7 +121,7 @@ bool sdSelectCard(uint8_t pdrv) { ardu_sdcard_t * card = s_cards[pdrv]; digitalWrite(card->ssPin, LOW); - bool s = sdWait(pdrv, 300); + bool s = sdWait(pdrv, 500); if (!s) { log_e("Select Failed"); digitalWrite(card->ssPin, HIGH); @@ -506,10 +506,17 @@ DSTATUS ff_sd_initialize(uint8_t pdrv) card->spi->transfer(0XFF); } - if (sdTransaction(pdrv, GO_IDLE_STATE, 0, NULL) != 1) { + // Fix mount issue - sdWait fail ignored before command GO_IDLE_STATE + digitalWrite(card->ssPin, LOW); + if(!sdWait(pdrv, 500)){ + log_w("sdWait fail ignored, card initialize continues"); + } + if (sdCommand(pdrv, GO_IDLE_STATE, 0, NULL) != 1){ + sdDeselectCard(pdrv); log_w("GO_IDLE_STATE failed"); goto unknown_card; } + sdDeselectCard(pdrv); token = sdTransaction(pdrv, CRC_ON_OFF, 1, NULL); if (token == 0x5) { diff --git a/libraries/Update/src/Updater.cpp b/libraries/Update/src/Updater.cpp index f9ecbfb057f..2b40185e7ae 100644 --- a/libraries/Update/src/Updater.cpp +++ b/libraries/Update/src/Updater.cpp @@ -352,7 +352,7 @@ size_t UpdateClass::writeStream(Stream &data) { bytesToRead = remaining(); } - /* + /* Init read&timeout counters and try to read, if read failed, increase counter, wait 100ms and try to read again. If counter > 300 (30 sec), give up/abort */ @@ -377,6 +377,8 @@ size_t UpdateClass::writeStream(Stream &data) { if((_bufferLen == remaining() || _bufferLen == SPI_FLASH_SEC_SIZE) && !_writeBuffer()) return written; written += toRead; + + delay(1); // Fix solo WDT } return written; } diff --git a/libraries/WebServer/src/WebServer.h b/libraries/WebServer/src/WebServer.h index c169da82229..0293a09f209 100644 --- a/libraries/WebServer/src/WebServer.h +++ b/libraries/WebServer/src/WebServer.h @@ -85,13 +85,13 @@ class WebServer void requestAuthentication(HTTPAuthMethod mode = BASIC_AUTH, const char* realm = NULL, const String& authFailMsg = String("") ); typedef std::function THandlerFunction; - void on(const Uri &uri, THandlerFunction handler); - void on(const Uri &uri, HTTPMethod method, THandlerFunction fn); - void on(const Uri &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn); + void on(const Uri &uri, THandlerFunction fn); + void on(const Uri &uri, HTTPMethod method, THandlerFunction fn); + void on(const Uri &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn); //ufn handles file uploads void addHandler(RequestHandler* handler); void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL ); void onNotFound(THandlerFunction fn); //called when handler is not assigned - void onFileUpload(THandlerFunction fn); //handle file uploads + void onFileUpload(THandlerFunction ufn); //handle file uploads String uri() { return _currentUri; } HTTPMethod method() { return _currentMethod; } diff --git a/libraries/WebServer/src/detail/RequestHandlersImpl.h b/libraries/WebServer/src/detail/RequestHandlersImpl.h index 699015746b3..4a7c28e58ae 100644 --- a/libraries/WebServer/src/detail/RequestHandlersImpl.h +++ b/libraries/WebServer/src/detail/RequestHandlersImpl.h @@ -68,7 +68,8 @@ class StaticRequestHandler : public RequestHandler { , _path(path) , _cache_header(cache_header) { - _isFile = fs.exists(path); + File f = fs.open(path); + _isFile = (f && (! f.isDirectory())); log_v("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header ? cache_header : ""); // issue 5506 - cache_header can be nullptr _baseUriLength = _uri.length(); } diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index 3bcaececc7a..5dfdacdc05d 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -1192,6 +1192,94 @@ bool WiFiGenericClass::initiateFTM(uint8_t frm_count, uint16_t burst_period, uin return true; } +/** + * Configure Dual antenna. + * @param gpio_ant1 Configure the GPIO number for the antenna 1 connected to the RF switch (default GPIO2 on ESP32-WROOM-DA) + * @param gpio_ant2 Configure the GPIO number for the antenna 2 connected to the RF switch (default GPIO25 on ESP32-WROOM-DA) + * @param rx_mode Set the RX antenna mode. See wifi_rx_ant_t for the options. + * @param tx_mode Set the TX antenna mode. See wifi_tx_ant_t for the options. + * @return true on success + */ +bool WiFiGenericClass::setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2, wifi_rx_ant_t rx_mode, wifi_tx_ant_t tx_mode) { + + wifi_ant_gpio_config_t wifi_ant_io; + + if (ESP_OK != esp_wifi_get_ant_gpio(&wifi_ant_io)) { + log_e("Failed to get antenna configuration"); + return false; + } + + wifi_ant_io.gpio_cfg[0].gpio_num = gpio_ant1; + wifi_ant_io.gpio_cfg[0].gpio_select = 1; + wifi_ant_io.gpio_cfg[1].gpio_num = gpio_ant2; + wifi_ant_io.gpio_cfg[1].gpio_select = 1; + + if (ESP_OK != esp_wifi_set_ant_gpio(&wifi_ant_io)) { + log_e("Failed to set antenna GPIO configuration"); + return false; + } + + // Set antenna default configuration + wifi_ant_config_t ant_config = { + .rx_ant_mode = WIFI_ANT_MODE_AUTO, + .tx_ant_mode = WIFI_ANT_MODE_AUTO, + .enabled_ant0 = 0, + .enabled_ant1 = 1, + }; + + switch (rx_mode) + { + case WIFI_RX_ANT0: + ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT0; + break; + case WIFI_RX_ANT1: + ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT1; + break; + case WIFI_RX_ANT_AUTO: + log_i("TX Antenna will be automatically selected"); + ant_config.rx_ant_default = WIFI_ANT_ANT0; + ant_config.rx_ant_mode = WIFI_ANT_MODE_AUTO; + // Force TX for AUTO if RX is AUTO + ant_config.tx_ant_mode = WIFI_ANT_MODE_AUTO; + goto set_ant; + break; + default: + log_e("Invalid default antenna! Falling back to AUTO"); + ant_config.rx_ant_mode = WIFI_ANT_MODE_AUTO; + break; + } + + switch (tx_mode) + { + case WIFI_TX_ANT0: + ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT0; + break; + case WIFI_TX_ANT1: + ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT1; + break; + case WIFI_TX_ANT_AUTO: + log_i("RX Antenna will be automatically selected"); + ant_config.rx_ant_default = WIFI_ANT_ANT0; + ant_config.tx_ant_mode = WIFI_ANT_MODE_AUTO; + // Force RX for AUTO if RX is AUTO + ant_config.rx_ant_mode = WIFI_ANT_MODE_AUTO; + break; + default: + log_e("Invalid default antenna! Falling back to AUTO"); + ant_config.rx_ant_default = WIFI_ANT_ANT0; + ant_config.tx_ant_mode = WIFI_ANT_MODE_AUTO; + break; + } + +set_ant: + if (ESP_OK != esp_wifi_set_ant(&ant_config)) { + log_e("Failed to set antenna configuration"); + return false; + } + + return true; +} + // ----------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------ Generic Network function --------------------------------------------- // ----------------------------------------------------------------------------------------------------------------------- diff --git a/libraries/WiFi/src/WiFiGeneric.h b/libraries/WiFi/src/WiFiGeneric.h index 7079c032993..f8a1bb77d37 100644 --- a/libraries/WiFi/src/WiFiGeneric.h +++ b/libraries/WiFi/src/WiFiGeneric.h @@ -139,6 +139,18 @@ static const int WIFI_SCAN_DONE_BIT= BIT12; static const int WIFI_DNS_IDLE_BIT = BIT13; static const int WIFI_DNS_DONE_BIT = BIT14; +typedef enum { + WIFI_RX_ANT0 = 0, + WIFI_RX_ANT1, + WIFI_RX_ANT_AUTO +} wifi_rx_ant_t; + +typedef enum { + WIFI_TX_ANT0 = 0, + WIFI_TX_ANT1, + WIFI_TX_ANT_AUTO +} wifi_tx_ant_t; + class WiFiGenericClass { public: @@ -174,6 +186,8 @@ class WiFiGenericClass bool initiateFTM(uint8_t frm_count=16, uint16_t burst_period=2, uint8_t channel=1, const uint8_t * mac=NULL); + bool setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2, wifi_rx_ant_t rx_mode, wifi_tx_ant_t tx_mode); + static const char * getHostname(); static bool setHostname(const char * hostname); static bool hostname(const String& aHostname) { return setHostname(aHostname.c_str()); } diff --git a/libraries/WiFiClientSecure/src/ssl_client.cpp b/libraries/WiFiClientSecure/src/ssl_client.cpp index 0d28e85acae..1524bcc91f8 100644 --- a/libraries/WiFiClientSecure/src/ssl_client.cpp +++ b/libraries/WiFiClientSecure/src/ssl_client.cpp @@ -171,7 +171,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p if (insecure) { mbedtls_ssl_conf_authmode(&ssl_client->ssl_conf, MBEDTLS_SSL_VERIFY_NONE); - log_i("WARNING: Skipping SSL Verification. INSECURE!"); + log_d("WARNING: Skipping SSL Verification. INSECURE!"); } else if (rootCABuff != NULL) { log_v("Loading CA cert"); mbedtls_x509_crt_init(&ssl_client->ca_cert); @@ -335,8 +335,13 @@ void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, cons mbedtls_ssl_config_free(&ssl_client->ssl_conf); mbedtls_ctr_drbg_free(&ssl_client->drbg_ctx); mbedtls_entropy_free(&ssl_client->entropy_ctx); + + // save only interesting field + int timeout = ssl_client->handshake_timeout; // reset embedded pointers to zero memset(ssl_client, 0, sizeof(sslclient_context)); + + ssl_client->handshake_timeout = timeout; } diff --git a/libraries/WiFiProv/src/WiFiProv.h b/libraries/WiFiProv/src/WiFiProv.h index 11dfd2e47e1..bbcab41a6f8 100644 --- a/libraries/WiFiProv/src/WiFiProv.h +++ b/libraries/WiFiProv/src/WiFiProv.h @@ -17,6 +17,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef WiFiProv_h +#define WiFiProv_h + #include "WiFi.h" #include "wifi_provisioning/manager.h" //Select the scheme using which you want to provision @@ -48,3 +51,5 @@ class WiFiProvClass }; extern WiFiProvClass WiFiProv; + +#endif diff --git a/platform.txt b/platform.txt index 7be1e3a7c1b..f2f0519aef1 100644 --- a/platform.txt +++ b/platform.txt @@ -39,7 +39,7 @@ build.extra_flags.esp32=-DARDUINO_USB_CDC_ON_BOOT=0 # # ESP32S3 Support Start # -compiler.cpreprocessor.flags.esp32s3=-DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -D_GNU_SOURCE -DIDF_VER="v4.4-rc1" -DESP_PLATFORM -D_POSIX_READER_WRITER_LOCKS "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/newlib/platform_include" "-I{compiler.sdk.path}/include/freertos/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions/freertos" "-I{compiler.sdk.path}/include/freertos/port/xtensa/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions" "-I{compiler.sdk.path}/include/esp_hw_support/include" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc/esp32s3" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32s3" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32s3/private_include" "-I{compiler.sdk.path}/include/heap/include" "-I{compiler.sdk.path}/include/log/include" "-I{compiler.sdk.path}/include/lwip/include/apps" "-I{compiler.sdk.path}/include/lwip/include/apps/sntp" "-I{compiler.sdk.path}/include/lwip/lwip/src/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include/arch" "-I{compiler.sdk.path}/include/soc/include" "-I{compiler.sdk.path}/include/soc/esp32s3" "-I{compiler.sdk.path}/include/soc/esp32s3/include" "-I{compiler.sdk.path}/include/hal/esp32s3/include" "-I{compiler.sdk.path}/include/hal/include" "-I{compiler.sdk.path}/include/hal/platform_port/include" "-I{compiler.sdk.path}/include/esp_rom/include" "-I{compiler.sdk.path}/include/esp_rom/include/esp32s3" "-I{compiler.sdk.path}/include/esp_rom/esp32s3" "-I{compiler.sdk.path}/include/esp_common/include" "-I{compiler.sdk.path}/include/esp_system/include" "-I{compiler.sdk.path}/include/esp_system/port/soc" "-I{compiler.sdk.path}/include/esp_system/port/public_compat" "-I{compiler.sdk.path}/include/xtensa/include" "-I{compiler.sdk.path}/include/xtensa/esp32s3/include" "-I{compiler.sdk.path}/include/driver/include" "-I{compiler.sdk.path}/include/driver/esp32s3/include" "-I{compiler.sdk.path}/include/esp_pm/include" "-I{compiler.sdk.path}/include/esp_ringbuf/include" "-I{compiler.sdk.path}/include/efuse/include" "-I{compiler.sdk.path}/include/efuse/esp32s3/include" "-I{compiler.sdk.path}/include/vfs/include" "-I{compiler.sdk.path}/include/esp_wifi/include" "-I{compiler.sdk.path}/include/esp_event/include" "-I{compiler.sdk.path}/include/esp_netif/include" "-I{compiler.sdk.path}/include/esp_eth/include" "-I{compiler.sdk.path}/include/tcpip_adapter/include" "-I{compiler.sdk.path}/include/esp_phy/include" "-I{compiler.sdk.path}/include/esp_phy/esp32s3/include" "-I{compiler.sdk.path}/include/esp_ipc/include" "-I{compiler.sdk.path}/include/app_trace/include" "-I{compiler.sdk.path}/include/esp_timer/include" "-I{compiler.sdk.path}/include/mbedtls/port/include" "-I{compiler.sdk.path}/include/mbedtls/mbedtls/include" "-I{compiler.sdk.path}/include/mbedtls/esp_crt_bundle/include" "-I{compiler.sdk.path}/include/app_update/include" "-I{compiler.sdk.path}/include/spi_flash/include" "-I{compiler.sdk.path}/include/bootloader_support/include" "-I{compiler.sdk.path}/include/nvs_flash/include" "-I{compiler.sdk.path}/include/pthread/include" "-I{compiler.sdk.path}/include/esp_gdbstub/include" "-I{compiler.sdk.path}/include/esp_gdbstub/xtensa" "-I{compiler.sdk.path}/include/esp_gdbstub/esp32s3" "-I{compiler.sdk.path}/include/espcoredump/include" "-I{compiler.sdk.path}/include/espcoredump/include/port/xtensa" "-I{compiler.sdk.path}/include/wpa_supplicant/include" "-I{compiler.sdk.path}/include/wpa_supplicant/port/include" "-I{compiler.sdk.path}/include/wpa_supplicant/esp_supplicant/include" "-I{compiler.sdk.path}/include/ieee802154/include" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/asio/asio/asio/include" "-I{compiler.sdk.path}/include/asio/port/include" "-I{compiler.sdk.path}/include/bt/common/osi/include" "-I{compiler.sdk.path}/include/bt/include/esp32s3/include" "-I{compiler.sdk.path}/include/bt/common/api/include/api" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/blufi/include" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/include" "-I{compiler.sdk.path}/include/bt/host/bluedroid/api/include/api" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_common/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_common/tinycrypt/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_core" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_core/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_core/storage" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/btc/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_models/common/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_models/client/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_models/server/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/api/core/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/api/models/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/api" "-I{compiler.sdk.path}/include/cbor/port/include" "-I{compiler.sdk.path}/include/unity/include" "-I{compiler.sdk.path}/include/unity/unity/src" "-I{compiler.sdk.path}/include/cmock/CMock/src" "-I{compiler.sdk.path}/include/coap/port/include" "-I{compiler.sdk.path}/include/coap/libcoap/include" "-I{compiler.sdk.path}/include/nghttp/port/include" "-I{compiler.sdk.path}/include/nghttp/nghttp2/lib/includes" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp-tls/esp-tls-crypto" "-I{compiler.sdk.path}/include/esp_adc_cal/include" "-I{compiler.sdk.path}/include/esp_hid/include" "-I{compiler.sdk.path}/include/tcp_transport/include" "-I{compiler.sdk.path}/include/esp_http_client/include" "-I{compiler.sdk.path}/include/esp_http_server/include" "-I{compiler.sdk.path}/include/esp_https_ota/include" "-I{compiler.sdk.path}/include/esp_https_server/include" "-I{compiler.sdk.path}/include/esp_lcd/include" "-I{compiler.sdk.path}/include/esp_lcd/interface" "-I{compiler.sdk.path}/include/protobuf-c/protobuf-c" "-I{compiler.sdk.path}/include/protocomm/include/common" "-I{compiler.sdk.path}/include/protocomm/include/security" "-I{compiler.sdk.path}/include/protocomm/include/transports" "-I{compiler.sdk.path}/include/mdns/include" "-I{compiler.sdk.path}/include/esp_local_ctrl/include" "-I{compiler.sdk.path}/include/sdmmc/include" "-I{compiler.sdk.path}/include/esp_serial_slave_link/include" "-I{compiler.sdk.path}/include/esp_websocket_client/include" "-I{compiler.sdk.path}/include/expat/expat/expat/lib" "-I{compiler.sdk.path}/include/expat/port/include" "-I{compiler.sdk.path}/include/wear_levelling/include" "-I{compiler.sdk.path}/include/fatfs/diskio" "-I{compiler.sdk.path}/include/fatfs/vfs" "-I{compiler.sdk.path}/include/fatfs/src" "-I{compiler.sdk.path}/include/freemodbus/common/include" "-I{compiler.sdk.path}/include/idf_test/include" "-I{compiler.sdk.path}/include/idf_test/include/esp32s3" "-I{compiler.sdk.path}/include/jsmn/include" "-I{compiler.sdk.path}/include/json/cJSON" "-I{compiler.sdk.path}/include/libsodium/libsodium/src/libsodium/include" "-I{compiler.sdk.path}/include/libsodium/port_include" "-I{compiler.sdk.path}/include/mqtt/esp-mqtt/include" "-I{compiler.sdk.path}/include/openssl/include" "-I{compiler.sdk.path}/include/perfmon/include" "-I{compiler.sdk.path}/include/spiffs/include" "-I{compiler.sdk.path}/include/usb/include" "-I{compiler.sdk.path}/include/ulp/include" "-I{compiler.sdk.path}/include/wifi_provisioning/include" "-I{compiler.sdk.path}/include/freertos/include/freertos" "-I{compiler.sdk.path}/include/arduino_tinyusb/tinyusb/src" "-I{compiler.sdk.path}/include/arduino_tinyusb/include" "-I{compiler.sdk.path}/include/esp_littlefs/src" "-I{compiler.sdk.path}/include/esp_littlefs/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dotprod/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/support/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/hann/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_harris/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/flat_top/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/iir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/add/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sub/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mul/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/addc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mulc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sqrt/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/matrix/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fft/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dct/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/conv/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/common/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf_imu13states/include" "-I{compiler.sdk.path}/include/esp-face/include" "-I{compiler.sdk.path}/include/esp-face/include/tool" "-I{compiler.sdk.path}/include/esp-face/include/typedef" "-I{compiler.sdk.path}/include/esp-face/include/image" "-I{compiler.sdk.path}/include/esp-face/include/math" "-I{compiler.sdk.path}/include/esp-face/include/nn" "-I{compiler.sdk.path}/include/esp-face/include/layer" "-I{compiler.sdk.path}/include/esp-face/include/detect" "-I{compiler.sdk.path}/include/esp-face/include/model_zoo" "-I{compiler.sdk.path}/include/esp32-camera/driver/include" "-I{compiler.sdk.path}/include/esp32-camera/conversions/include" "-I{compiler.sdk.path}/include/fb_gfx/include" +compiler.cpreprocessor.flags.esp32s3=-DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -D_GNU_SOURCE -DIDF_VER="v4.4-98-geb3797dc3f" -DESP_PLATFORM -D_POSIX_READER_WRITER_LOCKS "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/newlib/platform_include" "-I{compiler.sdk.path}/include/freertos/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions/freertos" "-I{compiler.sdk.path}/include/freertos/port/xtensa/include" "-I{compiler.sdk.path}/include/freertos/include/esp_additions" "-I{compiler.sdk.path}/include/esp_hw_support/include" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc" "-I{compiler.sdk.path}/include/esp_hw_support/include/soc/esp32s3" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32s3" "-I{compiler.sdk.path}/include/esp_hw_support/port/esp32s3/private_include" "-I{compiler.sdk.path}/include/heap/include" "-I{compiler.sdk.path}/include/log/include" "-I{compiler.sdk.path}/include/lwip/include/apps" "-I{compiler.sdk.path}/include/lwip/include/apps/sntp" "-I{compiler.sdk.path}/include/lwip/lwip/src/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include" "-I{compiler.sdk.path}/include/lwip/port/esp32/include/arch" "-I{compiler.sdk.path}/include/soc/include" "-I{compiler.sdk.path}/include/soc/esp32s3" "-I{compiler.sdk.path}/include/soc/esp32s3/include" "-I{compiler.sdk.path}/include/hal/esp32s3/include" "-I{compiler.sdk.path}/include/hal/include" "-I{compiler.sdk.path}/include/hal/platform_port/include" "-I{compiler.sdk.path}/include/esp_rom/include" "-I{compiler.sdk.path}/include/esp_rom/include/esp32s3" "-I{compiler.sdk.path}/include/esp_rom/esp32s3" "-I{compiler.sdk.path}/include/esp_common/include" "-I{compiler.sdk.path}/include/esp_system/include" "-I{compiler.sdk.path}/include/esp_system/port/soc" "-I{compiler.sdk.path}/include/esp_system/port/public_compat" "-I{compiler.sdk.path}/include/xtensa/include" "-I{compiler.sdk.path}/include/xtensa/esp32s3/include" "-I{compiler.sdk.path}/include/driver/include" "-I{compiler.sdk.path}/include/driver/esp32s3/include" "-I{compiler.sdk.path}/include/esp_pm/include" "-I{compiler.sdk.path}/include/esp_ringbuf/include" "-I{compiler.sdk.path}/include/efuse/include" "-I{compiler.sdk.path}/include/efuse/esp32s3/include" "-I{compiler.sdk.path}/include/vfs/include" "-I{compiler.sdk.path}/include/esp_wifi/include" "-I{compiler.sdk.path}/include/esp_event/include" "-I{compiler.sdk.path}/include/esp_netif/include" "-I{compiler.sdk.path}/include/esp_eth/include" "-I{compiler.sdk.path}/include/tcpip_adapter/include" "-I{compiler.sdk.path}/include/esp_phy/include" "-I{compiler.sdk.path}/include/esp_phy/esp32s3/include" "-I{compiler.sdk.path}/include/esp_ipc/include" "-I{compiler.sdk.path}/include/app_trace/include" "-I{compiler.sdk.path}/include/esp_timer/include" "-I{compiler.sdk.path}/include/mbedtls/port/include" "-I{compiler.sdk.path}/include/mbedtls/mbedtls/include" "-I{compiler.sdk.path}/include/mbedtls/esp_crt_bundle/include" "-I{compiler.sdk.path}/include/app_update/include" "-I{compiler.sdk.path}/include/spi_flash/include" "-I{compiler.sdk.path}/include/bootloader_support/include" "-I{compiler.sdk.path}/include/nvs_flash/include" "-I{compiler.sdk.path}/include/pthread/include" "-I{compiler.sdk.path}/include/esp_gdbstub/include" "-I{compiler.sdk.path}/include/esp_gdbstub/xtensa" "-I{compiler.sdk.path}/include/esp_gdbstub/esp32s3" "-I{compiler.sdk.path}/include/espcoredump/include" "-I{compiler.sdk.path}/include/espcoredump/include/port/xtensa" "-I{compiler.sdk.path}/include/wpa_supplicant/include" "-I{compiler.sdk.path}/include/wpa_supplicant/port/include" "-I{compiler.sdk.path}/include/wpa_supplicant/esp_supplicant/include" "-I{compiler.sdk.path}/include/ieee802154/include" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/asio/asio/asio/include" "-I{compiler.sdk.path}/include/asio/port/include" "-I{compiler.sdk.path}/include/bt/common/osi/include" "-I{compiler.sdk.path}/include/bt/include/esp32s3/include" "-I{compiler.sdk.path}/include/bt/common/api/include/api" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/blufi/include" "-I{compiler.sdk.path}/include/bt/common/btc/profile/esp/include" "-I{compiler.sdk.path}/include/bt/host/bluedroid/api/include/api" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_common/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_common/tinycrypt/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_core" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_core/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_core/storage" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/btc/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_models/common/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_models/client/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/mesh_models/server/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/api/core/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/api/models/include" "-I{compiler.sdk.path}/include/bt/esp_ble_mesh/api" "-I{compiler.sdk.path}/include/cbor/port/include" "-I{compiler.sdk.path}/include/unity/include" "-I{compiler.sdk.path}/include/unity/unity/src" "-I{compiler.sdk.path}/include/cmock/CMock/src" "-I{compiler.sdk.path}/include/coap/port/include" "-I{compiler.sdk.path}/include/coap/libcoap/include" "-I{compiler.sdk.path}/include/nghttp/port/include" "-I{compiler.sdk.path}/include/nghttp/nghttp2/lib/includes" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp-tls/esp-tls-crypto" "-I{compiler.sdk.path}/include/esp_adc_cal/include" "-I{compiler.sdk.path}/include/esp_hid/include" "-I{compiler.sdk.path}/include/tcp_transport/include" "-I{compiler.sdk.path}/include/esp_http_client/include" "-I{compiler.sdk.path}/include/esp_http_server/include" "-I{compiler.sdk.path}/include/esp_https_ota/include" "-I{compiler.sdk.path}/include/esp_https_server/include" "-I{compiler.sdk.path}/include/esp_lcd/include" "-I{compiler.sdk.path}/include/esp_lcd/interface" "-I{compiler.sdk.path}/include/protobuf-c/protobuf-c" "-I{compiler.sdk.path}/include/protocomm/include/common" "-I{compiler.sdk.path}/include/protocomm/include/security" "-I{compiler.sdk.path}/include/protocomm/include/transports" "-I{compiler.sdk.path}/include/mdns/include" "-I{compiler.sdk.path}/include/esp_local_ctrl/include" "-I{compiler.sdk.path}/include/sdmmc/include" "-I{compiler.sdk.path}/include/esp_serial_slave_link/include" "-I{compiler.sdk.path}/include/esp_websocket_client/include" "-I{compiler.sdk.path}/include/expat/expat/expat/lib" "-I{compiler.sdk.path}/include/expat/port/include" "-I{compiler.sdk.path}/include/wear_levelling/include" "-I{compiler.sdk.path}/include/fatfs/diskio" "-I{compiler.sdk.path}/include/fatfs/vfs" "-I{compiler.sdk.path}/include/fatfs/src" "-I{compiler.sdk.path}/include/freemodbus/common/include" "-I{compiler.sdk.path}/include/idf_test/include" "-I{compiler.sdk.path}/include/idf_test/include/esp32s3" "-I{compiler.sdk.path}/include/jsmn/include" "-I{compiler.sdk.path}/include/json/cJSON" "-I{compiler.sdk.path}/include/libsodium/libsodium/src/libsodium/include" "-I{compiler.sdk.path}/include/libsodium/port_include" "-I{compiler.sdk.path}/include/mqtt/esp-mqtt/include" "-I{compiler.sdk.path}/include/openssl/include" "-I{compiler.sdk.path}/include/perfmon/include" "-I{compiler.sdk.path}/include/spiffs/include" "-I{compiler.sdk.path}/include/usb/include" "-I{compiler.sdk.path}/include/ulp/include" "-I{compiler.sdk.path}/include/wifi_provisioning/include" "-I{compiler.sdk.path}/include/freertos/include/freertos" "-I{compiler.sdk.path}/include/arduino_tinyusb/tinyusb/src" "-I{compiler.sdk.path}/include/arduino_tinyusb/include" "-I{compiler.sdk.path}/include/esp_littlefs/src" "-I{compiler.sdk.path}/include/esp_littlefs/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dotprod/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/support/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/hann/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_harris/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/blackman_nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/nuttall/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/windows/flat_top/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/iir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fir/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/add/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sub/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mul/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/addc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/mulc/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/math/sqrt/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/matrix/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/fft/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/dct/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/conv/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/common/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf/include" "-I{compiler.sdk.path}/include/esp-dsp/modules/kalman/ekf_imu13states/include" "-I{compiler.sdk.path}/include/esp-face/include" "-I{compiler.sdk.path}/include/esp-face/include/tool" "-I{compiler.sdk.path}/include/esp-face/include/typedef" "-I{compiler.sdk.path}/include/esp-face/include/image" "-I{compiler.sdk.path}/include/esp-face/include/math" "-I{compiler.sdk.path}/include/esp-face/include/nn" "-I{compiler.sdk.path}/include/esp-face/include/layer" "-I{compiler.sdk.path}/include/esp-face/include/detect" "-I{compiler.sdk.path}/include/esp-face/include/model_zoo" "-I{compiler.sdk.path}/include/esp32-camera/driver/include" "-I{compiler.sdk.path}/include/esp32-camera/conversions/include" "-I{compiler.sdk.path}/include/fb_gfx/include" compiler.c.elf.libs.esp32s3=-lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lbt -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_https_server -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lperfmon -lspiffs -lusb -lulp -lwifi_provisioning -lesp-dsp -lesp32-camera -lesp_littlefs -lfb_gfx -lasio -lcbor -lcmock -lunity -lcoap -lesp_lcd -lesp_local_ctrl -lesp_https_server -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lmqtt -lperfmon -lusb -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lspiffs -lwifi_provisioning -lprotocomm -lbt -lbtdm_app -lprotobuf-c -lmdns -ljson -larduino_tinyusb -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lbtbb -lesp_phy -lphy -lbtbb -lesp_phy -lphy -lbtbb -lxt_hal -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx -lapp_trace -lgcov -lapp_trace -lgcov -lc compiler.c.flags.esp32s3=-mlongcalls -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu99 -Wno-old-style-declaration -MMD -c compiler.cpp.flags.esp32s3=-mlongcalls -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -std=gnu++11 -fexceptions -fno-rtti -MMD -c @@ -119,13 +119,14 @@ compiler.libraries.ldflags= # This can be overriden in boards.txt build.flash_size=4MB build.flash_mode=dio -build.boot=bootloader +build.boot=qio build.bootloader_addr=0x1000 build.code_debug=0 build.defines= build.loop_core= build.event_core= build.extra_flags=-DESP32 -DCORE_DEBUG_LEVEL={build.code_debug} {build.loop_core} {build.event_core} {build.defines} {build.extra_flags.{build.mcu}} +build.extra_libs= # Custom build options build.opt.name=build_opt.h @@ -164,7 +165,7 @@ recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.fla recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" ## Combine gc-sections, archives, and objects -recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-Wl,--Map={build.path}/{build.project_name}.map" "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} {compiler.libraries.ldflags} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf" +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-Wl,--Map={build.path}/{build.project_name}.map" "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} -Wl,--start-group {object_files} "{archive_file_path}" {build.extra_libs} {compiler.c.elf.libs} {compiler.libraries.ldflags} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf" ## Create partitions.bin recipe.objcopy.partitions.bin.pattern={tools.gen_esp32part.cmd} -q "{build.path}/partitions.csv" "{build.path}/{build.project_name}.partitions.bin" diff --git a/tools/platformio-build-esp32s3.py b/tools/platformio-build-esp32s3.py index 9d3283a1006..8f85b55be48 100644 --- a/tools/platformio-build-esp32s3.py +++ b/tools/platformio-build-esp32s3.py @@ -307,7 +307,7 @@ "UNITY_INCLUDE_CONFIG_H", "WITH_POSIX", "_GNU_SOURCE", - ("IDF_VER", '\\"v4.4-rc1\\"'), + ("IDF_VER", '\\"v4.4-98-geb3797dc3f\\"'), "ESP_PLATFORM", "_POSIX_READER_WRITER_LOCKS", "ARDUINO_ARCH_ESP32", @@ -324,7 +324,7 @@ ], FLASH_EXTRA_IMAGES=[ - ("0x1000", join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "bin", "bootloader_${BOARD_FLASH_MODE}_${__get_board_f_flash(__env__)}.bin")), + ("0x0000", join(FRAMEWORK_DIR, "tools", "sdk", "esp32s3", "bin", "bootloader_${BOARD_FLASH_MODE}_${__get_board_f_flash(__env__)}.bin")), ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")) ] diff --git a/tools/sdk/esp32s3/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h b/tools/sdk/esp32s3/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h index 73c8605e078..285cbb028cf 100644 --- a/tools/sdk/esp32s3/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h +++ b/tools/sdk/esp32s3/include/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h @@ -236,7 +236,7 @@ typedef enum { #define ESP_BT_GAP_MIN_INQ_LEN (0x01) /*!< Minimum inquiry duration, unit is 1.28s */ #define ESP_BT_GAP_MAX_INQ_LEN (0x30) /*!< Maximum inquiry duration, unit is 1.28s */ -/// A2DP state callback parameters +/// GAP state callback parameters typedef union { /** * @brief ESP_BT_GAP_DISC_RES_EVT diff --git a/tools/sdk/esp32s3/include/driver/include/driver/ledc.h b/tools/sdk/esp32s3/include/driver/include/driver/ledc.h index bc8328cdd20..0e7f7169296 100644 --- a/tools/sdk/esp32s3/include/driver/include/driver/ledc.h +++ b/tools/sdk/esp32s3/include/driver/include/driver/ledc.h @@ -443,9 +443,6 @@ esp_err_t ledc_set_fade_time_and_start(ledc_mode_t speed_mode, ledc_channel_t ch * - ESP_FAIL Fade function init error */ esp_err_t ledc_set_fade_step_and_start(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t target_duty, uint32_t scale, uint32_t cycle_num, ledc_fade_mode_t fade_mode); -#ifdef __cplusplus -} -#endif /** * @brief LEDC callback registration function @@ -461,3 +458,6 @@ esp_err_t ledc_set_fade_step_and_start(ledc_mode_t speed_mode, ledc_channel_t ch * - ESP_FAIL Fade function init error */ esp_err_t ledc_cb_register(ledc_mode_t speed_mode, ledc_channel_t channel, ledc_cbs_t *cbs, void *user_arg); +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32s3/include/esp_common/include/esp_check.h b/tools/sdk/esp32s3/include/esp_common/include/esp_check.h index 524cb376a38..d0e09cf28f0 100644 --- a/tools/sdk/esp32s3/include/esp_common/include/esp_check.h +++ b/tools/sdk/esp32s3/include/esp_common/include/esp_check.h @@ -25,6 +25,7 @@ extern "C" { */ #if defined(CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT) #define ESP_RETURN_ON_ERROR(x, log_tag, format, ...) do { \ + (void)log_tag; \ esp_err_t err_rc_ = (x); \ if (unlikely(err_rc_ != ESP_OK)) { \ return err_rc_; \ @@ -35,6 +36,7 @@ extern "C" { * A version of ESP_RETURN_ON_ERROR() macro that can be called from ISR. */ #define ESP_RETURN_ON_ERROR_ISR(x, log_tag, format, ...) do { \ + (void)log_tag; \ esp_err_t err_rc_ = (x); \ if (unlikely(err_rc_ != ESP_OK)) { \ return err_rc_; \ @@ -46,6 +48,7 @@ extern "C" { * sets the local variable 'ret' to the code, and then exits by jumping to 'goto_tag'. */ #define ESP_GOTO_ON_ERROR(x, goto_tag, log_tag, format, ...) do { \ + (void)log_tag; \ esp_err_t err_rc_ = (x); \ if (unlikely(err_rc_ != ESP_OK)) { \ ret = err_rc_; \ @@ -57,6 +60,7 @@ extern "C" { * A version of ESP_GOTO_ON_ERROR() macro that can be called from ISR. */ #define ESP_GOTO_ON_ERROR_ISR(x, goto_tag, log_tag, format, ...) do { \ + (void)log_tag; \ esp_err_t err_rc_ = (x); \ if (unlikely(err_rc_ != ESP_OK)) { \ ret = err_rc_; \ @@ -69,6 +73,7 @@ extern "C" { * and returns with the supplied 'err_code'. */ #define ESP_RETURN_ON_FALSE(a, err_code, log_tag, format, ...) do { \ + (void)log_tag; \ if (unlikely(!(a))) { \ return err_code; \ } \ @@ -78,6 +83,7 @@ extern "C" { * A version of ESP_RETURN_ON_FALSE() macro that can be called from ISR. */ #define ESP_RETURN_ON_FALSE_ISR(a, err_code, log_tag, format, ...) do { \ + (void)log_tag; \ if (unlikely(!(a))) { \ return err_code; \ } \ @@ -88,6 +94,7 @@ extern "C" { * sets the local variable 'ret' to the supplied 'err_code', and then exits by jumping to 'goto_tag'. */ #define ESP_GOTO_ON_FALSE(a, err_code, goto_tag, log_tag, format, ...) do { \ + (void)log_tag; \ if (unlikely(!(a))) { \ ret = err_code; \ goto goto_tag; \ @@ -98,6 +105,7 @@ extern "C" { * A version of ESP_GOTO_ON_FALSE() macro that can be called from ISR. */ #define ESP_GOTO_ON_FALSE_ISR(a, err_code, goto_tag, log_tag, format, ...) do { \ + (void)log_tag; \ if (unlikely(!(a))) { \ ret = err_code; \ goto goto_tag; \ diff --git a/tools/sdk/esp32s3/include/esp_common/include/esp_err.h b/tools/sdk/esp32s3/include/esp_common/include/esp_err.h index d31bb9a0753..f317f8a09f5 100644 --- a/tools/sdk/esp32s3/include/esp_common/include/esp_err.h +++ b/tools/sdk/esp32s3/include/esp_common/include/esp_err.h @@ -1,16 +1,9 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + #pragma once #include @@ -46,6 +39,7 @@ typedef int esp_err_t; #define ESP_ERR_MESH_BASE 0x4000 /*!< Starting number of MESH error codes */ #define ESP_ERR_FLASH_BASE 0x6000 /*!< Starting number of flash error codes */ #define ESP_ERR_HW_CRYPTO_BASE 0xc000 /*!< Starting number of HW cryptography module error codes */ +#define ESP_ERR_MEMPROT_BASE 0xd000 /*!< Starting number of Memory Protection API error codes */ /** * @brief Returns string for esp_err_t error codes diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/esp_memprot.h b/tools/sdk/esp32s3/include/esp_hw_support/include/esp_memprot.h new file mode 100644 index 00000000000..c9557eae935 --- /dev/null +++ b/tools/sdk/esp32s3/include/esp_hw_support/include/esp_memprot.h @@ -0,0 +1,199 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +///////////////////////////////////////////////////////////////////////////////////////// +// ESP Memory Protection API (PMS) +// - allows configuration and violation-interrupt handling of the PMS module operations +// - not intended for public use. + +#pragma once + +#include "sdkconfig.h" +#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_MEMPROT_TEST + +#include +#include +#include "esp_err.h" +#include "esp_memprot_err.h" +#include "soc_memprot_types.h" +#include "esp_memprot_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ESP_MEMPROT_ERR_CHECK(retval, fnc) if ((retval=fnc) != ESP_OK) { return retval; } + +/** +* @brief Basic PMS interrupt source info +*/ +typedef struct { + esp_mprot_mem_t mem_type; /*!< Memory type containing the faulting address */ + int core; /*!< CPU/Core ID running the faulting instruction */ +} esp_memp_intr_source_t; + +/** + * @brief Clears current interrupt ON flag for given Memory type and CPU/Core ID + * + * This operation is non-atomic for some chips by PMS module design + * In such a case the interrupt clearing happens in two steps: + * 1. Interrupt CLR flag is set (clears interrupt-ON status and inhibits linked interrupt processing) + * 2. Interrupt CLR flag is reset (resumes the interrupt monitoring) + * + * @param mem_type Memory type (see esp_mprot_mem_t enum) + * @param core Target CPU/Core ID (see *_CPU_NUM defs in soc.h). Can be NULL on 1-CPU systems + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on passing invalid pointer + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_monitor_clear_intr(const esp_mprot_mem_t mem_type, int const *const core); + +/** + * @brief Checks whether any of the PMS settings is locked + * + * @param[out] locked Any lock on? (true/false) + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on invalid locked ptr + * Other failures: error code of any failing esp_mprot_get_*_lock() routine (called internally) + */ +esp_err_t esp_mprot_is_conf_locked_any(bool *locked); + +/** + * @brief Checks whether any PMS violation-interrupt monitoring is enabled + * + * @param[out] locked Any PMS violation interrupt monitor is enabled (true/false) + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on invalid enabled ptr + * Other failures: error code of esp_mprot_get_monitor_en() routine (called internally for all Memory types) + */ +esp_err_t esp_mprot_is_intr_ena_any(bool *enabled); + +/** + * @brief Returns active PMS violation-interrupt Memory type if any (MEMPROT_TYPE_NONE when none detected) + * and the CPU/CoreID which was running the faulty code (-1 when no interrupt available) + * + * If there are more interrupts indicated on (shouldn't happen), the order of precedence is given by 'esp_mprot_mem_t' enum definition (low->high) + * + * @param[out] mem_type Out-pointer for Memory type given by the faulting address (see esp_mprot_mem_t enum) + * @param[out] core Out-pointer for CPU/Core ID (see *_CPU_NUM defs in soc.h) + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on passing invalid pointer(s) + */ +esp_err_t esp_mprot_get_active_intr(esp_memp_intr_source_t *active_memp_intr); + +/** + * @brief Returns the address which caused the violation interrupt for given Memory type and CPU/Core ID. + * This function is to be called after a basic resolving of (current) interrupt's parameters (ie corresponding + * Memory type and CPU ID see esp_mprot_get_active_intr()). This is to minimize processing time of actual exception + * as this API is typicaly used in a panic-handling code. + * If there is no active interrupt available for the Memory type/CPU ID required, fault_addr is set to NULL. + * + * @param mem_type memory type + * @param[out] fault_addr Address of the operation which caused the PMS violation interrupt + * @param core Faulting instruction CPU/Core ID (see *_CPU_NUM defs in soc.h). Can be NULL on 1-CPU systems + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARG on invalid fault_addr pointer + */ +esp_err_t esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, void **fault_addr, int const *const core); + +/** + * @brief Returns PMS World identifier of the code causing the violation interrupt + * + * The value is read from appropriate PMS violation status register and thus might be 0 if the interrupt is not currently active. + * + * @param mem_type Memory type + * @param[out] world PMS World type (see esp_mprot_pms_world_t) + * @param core Faulting instruction CPU/Core ID (see *_CPU_NUM defs in soc.h). Can be NULL on 1-CPU systems + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARG on passing invalid pointer(s) + * ESP_ERR_MEMPROT_WORLD_INVALID on invalid World identifier fetched from the register + */ +esp_err_t esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type, esp_mprot_pms_world_t *world, int const *const core); + +/** + * @brief Returns an operation type which caused the violation interrupt + * + * The operation resolving is processed over various PMS status register flags, according to given Memory type argument. + * If the interrupt is not active the result returned is irrelevant (likely evaluated to MEMPROT_OP_READ). + * + * @param mem_type Memory type + * @param[out] oper Operation type (see MEMPROT_OP_* defines) + * @param core Faulting instruction CPU/Core ID (see *_CPU_NUM defs in soc.h). Can be NULL on 1-CPU systems + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARG on invalid oper pointer + */ +esp_err_t esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_type, uint32_t *oper, int const *const core); + +/** + * @brief Checks whether given memory type supports byte-enables info + * + * Byte-enables status is available only for DMA/DRAM operations + * + * @param mem_type memory type + * + * @return byte-enables info available true/false + */ +bool esp_mprot_has_byte_enables(const esp_mprot_mem_t mem_type); + +/** + * @brief Returns byte-enables for the address which caused the violation interrupt + * + * The value is taken from appropriate PMS violation status register, based on given Memory type + * + * @param mem_type Memory type (MEMPROT_TYPE_DRAM0_SRAM) + * @param[out] byte_en Byte-enables bits + * @param core Faulting instruction CPU/Core ID (see *_CPU_NUM defs in soc.h). Can be NULL on 1-CPU systems + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARGUMENT on invalid byte_en pointer + */ +esp_err_t esp_mprot_get_violate_byte_enables(const esp_mprot_mem_t mem_type, uint32_t *byte_en, int const *const core); + +/** + * @brief Convenient routine for setting the PMS defaults + * + * Called on system startup, depending on ESP_SYSTEM_MEMPROT_FEATURE Kconfig value + * + * @param memp_config pointer to Memprot configuration structure (esp_memp_config_t). The structure si chip-specific, + * for details and defaults see appropriate [target-chip]/soc_memprot_types.h + * + * @return ESP_OK on success + * Other failures: error code of the failing routine called internally. No specific error processing provided in such a case + * due to large number of embedded calls (ie no global unique error table is provided and thus one error code can have different meanings, + * depending on the routine issuing the error) + */ +esp_err_t esp_mprot_set_prot(const esp_memp_config_t *memp_config); + +/** + * @brief Generates PMS configuration string of actual device (diagnostics) + * + * The functions generates a string from current configuration, control and status registers of the PMS (or similar) module of actual device. + * The values are fetched using HAL LL calls to help finding possible errors in the Memprot API implementation + * + * @param[out] dump_info_string configuration string buffer pointer. The string is allocated by the callee and must be freed by the caller. + * + * @return ESP_OK on success + * ESP_ERR_NO_MEM on buffer allocation failure + * ESP_ERR_INVALID_ARGUMENT on invalid dump_info_string pointer + */ +esp_err_t esp_mprot_dump_configuration(char **dump_info_string); + +#ifdef __cplusplus +} +#endif + +#endif //CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_MEMPROT_TEST diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/esp_memprot_err.h b/tools/sdk/esp32s3/include/esp_hw_support/include/esp_memprot_err.h new file mode 100644 index 00000000000..5556d2c8894 --- /dev/null +++ b/tools/sdk/esp32s3/include/esp_hw_support/include/esp_memprot_err.h @@ -0,0 +1,28 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD +* +* SPDX-License-Identifier: Apache-2.0 +*/ + +#pragma once + +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @brief ESP Memprot API error code definition +*/ +#define ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID (ESP_ERR_MEMPROT_BASE + 1) /**< Memory type invalid in given context */ +#define ESP_ERR_MEMPROT_SPLIT_ADDR_INVALID (ESP_ERR_MEMPROT_BASE + 2) /**< Splitting address invalid in given context */ +#define ESP_ERR_MEMPROT_SPLIT_ADDR_OUT_OF_RANGE (ESP_ERR_MEMPROT_BASE + 3) /**< Splitting address out of range */ +#define ESP_ERR_MEMPROT_SPLIT_ADDR_UNALIGNED (ESP_ERR_MEMPROT_BASE + 4) /**< Splitting address not aligned to required boundaries */ +#define ESP_ERR_MEMPROT_UNIMGMT_BLOCK_INVALID (ESP_ERR_MEMPROT_BASE + 5) /**< Required unified-management block is not valid */ +#define ESP_ERR_MEMPROT_WORLD_INVALID (ESP_ERR_MEMPROT_BASE + 6) /**< Required World identifier is not valid */ +#define ESP_ERR_MEMPROT_AREA_INVALID (ESP_ERR_MEMPROT_BASE + 7) /**< Required Area identifier is not valid */ + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/esp_memprot_types.h b/tools/sdk/esp32s3/include/esp_hw_support/include/esp_memprot_types.h new file mode 100644 index 00000000000..e37fee54578 --- /dev/null +++ b/tools/sdk/esp32s3/include/esp_hw_support/include/esp_memprot_types.h @@ -0,0 +1,36 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief PMS World type (attribute per PMS area, similar to x86 Ring scheme) + */ +typedef enum { + MEMPROT_PMS_WORLD_NONE = 0x00000000, + MEMPROT_PMS_WORLD_0 = 0x00000001, + MEMPROT_PMS_WORLD_1 = 0x00000002, + MEMPROT_PMS_WORLD_2 = 0x00000004, + MEMPROT_PMS_WORLD_ALL = 0x7FFFFFFF, + MEMPROT_PMS_WORLD_INVALID = 0x80000000 +} esp_mprot_pms_world_t; + +/** + * @brief Memory operation/permission type recognized by PMS + */ +#define MEMPROT_OP_NONE 0x00000000 +#define MEMPROT_OP_READ 0x00000001 +#define MEMPROT_OP_WRITE 0x00000002 +#define MEMPROT_OP_EXEC 0x00000004 +#define MEMPROT_OP_INVALID 0x80000000 + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/esp_private/esp_memprot_internal.h b/tools/sdk/esp32s3/include/esp_hw_support/include/esp_private/esp_memprot_internal.h new file mode 100644 index 00000000000..caeb7584862 --- /dev/null +++ b/tools/sdk/esp32s3/include/esp_hw_support/include/esp_private/esp_memprot_internal.h @@ -0,0 +1,199 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include "sdkconfig.h" +#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_MEMPROT_TEST + +#include +#include +#include "esp_err.h" +#include "esp_memprot_err.h" +#include "hal/memprot_types.h" +#include "soc_memprot_types.h" +#include "esp_memprot_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @brief Convert Memprot low level errors to esp_err_t +*/ +esp_err_t esp_mprot_ll_err_to_esp_err(const memprot_ll_err_t err); + +/** + * @brief Convert Memprot low level PMS World IDs to esp_mprot_pms_world_t + */ +esp_mprot_pms_world_t esp_mprot_ll_world_to_hl_world(const memprot_ll_world_t world); + +/** + * @brief Converts operation type to string, no combination of operations allowed + * + * @param oper_type PMS operation type + */ +const char *esp_mprot_oper_type_to_str(const uint32_t oper_type); + +/** + * @brief Converts PMS World type to string + * + * @param area_type PMS World type + */ +const char *esp_mprot_pms_world_to_str(const esp_mprot_pms_world_t world_type); + +/** + * @brief Sets splitting address for given line type in the target Memory type + * + * @param mem_type memory type + * @param line_type split address type + * @param line_addr target address from a memory range relevant to given line_addr + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_MEMPROT_SPLIT_ADDR_INVALID on invalid line_type + * ESP_ERR_MEMPROT_SPLIT_ADDR_OUT_OF_RANGE on splitting line out of given memory-type range + * ESP_ERR_MEMPROT_SPLIT_ADDR_UNALIGNED on splitting line not aligned to PMS-required boundaries + */ +esp_err_t esp_mprot_set_split_addr(const esp_mprot_mem_t mem_type, const esp_mprot_split_addr_t line_type, const void *line_addr); + +/** + * @brief Gets PMS splitting address for given split_addr type + * + * The value is read from the PMS configuration registers + * + * @param mem_type memory type + * @param line_type Split line type (see esp_mprot_split_addr_t enum) + * @param[out] line_addr Split line address from the configuration register + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on line_addr is pointer + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_MEMPROT_SPLIT_ADDR_INVALID on invalid line_type + */ +esp_err_t esp_mprot_get_split_addr(const esp_mprot_mem_t mem_type, const esp_mprot_split_addr_t line_type, void **line_addr); + +/** + * @brief Returns default main I/D splitting address for given Memory type + * + * @param mem_type memory type + * @param[out] def_split_addr Main I/D splitting address of required mem_type + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARG on invalid def_split_addr pointer + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_get_default_main_split_addr(const esp_mprot_mem_t mem_type, void **def_split_addr); + +/** + * @brief Sets a lock for the main IRAM/DRAM splitting addresses + * Locks can be unlocked only by digital system reset + * + * @param mem_type memory type + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_set_split_addr_lock(const esp_mprot_mem_t mem_type); + +/** + * @brief Gets a lock status for the splitting address configuration of given Memory type + * + * @param mem_type memory type + * @param[out] locked mem_type related lock status + * + * @return ESP_OK on success + * ESP_ERR_INVALID_ARGUMENT on invalid locked pointer + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_get_split_addr_lock(const esp_mprot_mem_t mem_type, bool *locked); + +/** + * @brief Sets a lock for PMS Area settings of required Memory type + * Locks can be unlocked only by digital system reset + * + * @param mem_type memory type + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_set_pms_lock(const esp_mprot_mem_t mem_type); + +/** + * @brief Gets a lock status for PMS Area settings of required Memory type + * + * @param mem_type memory type + * @param[out] locked mem_type related lock status + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARGUMENT on invalid locked pointer + */ +esp_err_t esp_mprot_get_pms_lock(const esp_mprot_mem_t mem_type, bool *locked); + +/** + * @brief Sets permissions for given PMS Area + * + * @param area_type PMS area type + * @param flags combination of MEMPROT_OP_* defines + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_set_pms_area(const esp_mprot_pms_area_t area_type, const uint32_t flags); + +/** + * @brief Gets current permissions for given PMS Area + * + * @param area_type PMS area type + * @param[out] flags combination of MEMPROT_OP_* defines + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARG on invalid flags pointer + */ +esp_err_t esp_mprot_get_pms_area(const esp_mprot_pms_area_t area_type, uint32_t *flags); + +/** + * @brief Sets a lock for PMS interrupt monitor settings of required Memory type + * + * Locks can be unlocked only by digital system reset + * + * @param mem_type memory type (see esp_mprot_mem_t enum) + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_set_monitor_lock(const esp_mprot_mem_t mem_type); + +/** + * @brief Gets a lock status for PMS interrupt monitor settings of required Memory type + * + * @param mem_type memory type + * @param[out] locked mem_type related lock status + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + * ESP_ERR_INVALID_ARG on invalid locked pointer + */ +esp_err_t esp_mprot_get_monitor_lock(const esp_mprot_mem_t mem_type, bool *locked); + +/** + * @brief Enable PMS violation interrupt monitoring of required Memory type + * + * @param mem_type memory type + * @param enable enable/disable violation interrupt monitoring + * + * @return ESP_OK on success + * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type + */ +esp_err_t esp_mprot_set_monitor_en(const esp_mprot_mem_t mem_type, const bool enable); + +#ifdef __cplusplus +} +#endif + +#endif //CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_MEMPROT_TEST diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32c3/memprot.h b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32c3/memprot.h deleted file mode 100644 index 818cd677dc8..00000000000 --- a/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32c3/memprot.h +++ /dev/null @@ -1,449 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - - -/* INTERNAL API - * generic interface to PMS memory protection features - */ - -#pragma once - -#include -#include - -#include "esp_attr.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef IRAM_SRAM_START -#define IRAM_SRAM_START 0x4037C000 -#endif - -#ifndef DRAM_SRAM_START -#define DRAM_SRAM_START 0x3FC7C000 -#endif - -#ifndef MAP_DRAM_TO_IRAM -#define MAP_DRAM_TO_IRAM(addr) (addr - DRAM_SRAM_START + IRAM_SRAM_START) -#endif - -#ifndef MAP_IRAM_TO_DRAM -#define MAP_IRAM_TO_DRAM(addr) (addr - IRAM_SRAM_START + DRAM_SRAM_START) -#endif - -typedef enum { - MEMPROT_NONE = 0x00000000, - MEMPROT_IRAM0_SRAM = 0x00000001, - MEMPROT_DRAM0_SRAM = 0x00000002, - MEMPROT_ALL = 0xFFFFFFFF -} mem_type_prot_t; - -typedef enum { - MEMPROT_SPLITLINE_NONE = 0, - MEMPROT_IRAM0_DRAM0_SPLITLINE, - MEMPROT_IRAM0_LINE_0_SPLITLINE, - MEMPROT_IRAM0_LINE_1_SPLITLINE, - MEMPROT_DRAM0_DMA_LINE_0_SPLITLINE, - MEMPROT_DRAM0_DMA_LINE_1_SPLITLINE -} split_line_t; - -typedef enum { - MEMPROT_PMS_AREA_NONE = 0, - MEMPROT_IRAM0_PMS_AREA_0, - MEMPROT_IRAM0_PMS_AREA_1, - MEMPROT_IRAM0_PMS_AREA_2, - MEMPROT_IRAM0_PMS_AREA_3, - MEMPROT_DRAM0_PMS_AREA_0, - MEMPROT_DRAM0_PMS_AREA_1, - MEMPROT_DRAM0_PMS_AREA_2, - MEMPROT_DRAM0_PMS_AREA_3 -} pms_area_t; - -typedef enum -{ - MEMPROT_PMS_WORLD_0 = 0, - MEMPROT_PMS_WORLD_1, - MEMPROT_PMS_WORLD_2, - MEMPROT_PMS_WORLD_INVALID = 0xFFFFFFFF -} pms_world_t; - -typedef enum -{ - MEMPROT_PMS_OP_READ = 0, - MEMPROT_PMS_OP_WRITE, - MEMPROT_PMS_OP_FETCH, - MEMPROT_PMS_OP_INVALID = 0xFFFFFFFF -} pms_operation_type_t; - -/** - * @brief Converts Memory protection type to string - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -const char *esp_memprot_mem_type_to_str(mem_type_prot_t mem_type); - -/** - * @brief Converts Split line type to string - * - * @param line_type Split line type (see split_line_t enum) - */ -const char *esp_memprot_split_line_to_str(split_line_t line_type); - -/** - * @brief Converts PMS Area type to string - * - * @param area_type PMS Area type (see pms_area_t enum) - */ -const char *esp_memprot_pms_to_str(pms_area_t area_type); - -/** - * @brief Returns PMS splitting address for given Split line type - * - * The value is taken from PMS configuration registers (IRam0 range) - * For details on split lines see 'esp_memprot_set_prot_int' function description - * - * @param line_type Split line type (see split_line_t enum) - * - * @return appropriate split line address - */ -uint32_t *esp_memprot_get_split_addr(split_line_t line_type); - -/** - * @brief Returns default main IRAM/DRAM splitting address - * - * The address value is given by _iram_text_end global (IRam0 range) - - * @return Main I/D split line (IRam0_DRam0_Split_Addr) - */ -void *esp_memprot_get_default_main_split_addr(void); - -/** - * @brief Sets a lock for the main IRAM/DRAM splitting address - * - * Locks can be unlocked only by digital system reset - */ -void esp_memprot_set_split_line_lock(void); - -/** - * @brief Gets a lock status for the main IRAM/DRAM splitting address - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_split_line_lock(void); - -/** - * @brief Sets required split line address - * - * @param line_type Split line type (see split_line_t enum) - * @param line_addr target address from a memory range relevant to given line_type (IRAM/DRAM) - */ -void esp_memprot_set_split_line(split_line_t line_type, const void *line_addr); - -/** - * @brief Sets a lock for PMS Area settings of required Memory type - * - * Locks can be unlocked only by digital system reset - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_pms_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets a lock status for PMS Area settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_pms_lock(mem_type_prot_t mem_type); - -/** - * @brief Sets permissions for given PMS Area in IRam0 memory range (MEMPROT_IRAM0_SRAM) - * - * @param area_type IRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag - * @param w Write permission flag - * @param x Execute permission flag - */ -void esp_memprot_iram_set_pms_area(pms_area_t area_type, bool r, bool w, bool x); - -/** - * @brief Gets current permissions for given PMS Area in IRam0 memory range (MEMPROT_IRAM0_SRAM) - * - * @param area_type IRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag holder - * @param w Write permission flag holder - * @param x Execute permission flag holder - */ -void esp_memprot_iram_get_pms_area(pms_area_t area_type, bool *r, bool *w, bool *x); - -/** - * @brief Sets permissions for given PMS Area in DRam0 memory range (MEMPROT_DRAM0_SRAM) - * - * @param area_type DRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag - * @param w Write permission flag - */ -void esp_memprot_dram_set_pms_area(pms_area_t area_type, bool r, bool w); - -/** - * @brief Gets current permissions for given PMS Area in DRam0 memory range (MEMPROT_DRAM0_SRAM) - * - * @param area_type DRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag holder - * @param w Write permission flag holder - */ -void esp_memprot_dram_get_pms_area(pms_area_t area_type, bool *r, bool *w); - -/** - * @brief Sets a lock for PMS interrupt monitor settings of required Memory type - * - * Locks can be unlocked only by digital system reset - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_monitor_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets a lock status for PMS interrupt monitor settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_monitor_lock(mem_type_prot_t mem_type); - -/** - * @brief Enable PMS violation interrupt monitoring of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * @param enable/disable - */ -void esp_memprot_set_monitor_en(mem_type_prot_t mem_type, bool enable); - -/** - * @brief Gets enable/disable status for PMS interrupt monitor settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (enabled/disabled) - */ -bool esp_memprot_get_monitor_en(mem_type_prot_t mem_type); - -/** - * @brief Gets CPU ID for currently active PMS violation interrupt - * - * @return CPU ID (CPU_PRO for ESP32C3) - */ -int IRAM_ATTR esp_memprot_intr_get_cpuid(void); - -/** - * @brief Clears current interrupt ON flag for given Memory type - * - * Interrupt clearing happens in two steps: - * 1. Interrupt CLR flag is set (to clear the interrupt ON status) - * 2. Interrupt CLR flag is reset (to allow further monitoring) - * This operation is non-atomic by PMS module design - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void IRAM_ATTR esp_memprot_monitor_clear_intr(mem_type_prot_t mem_type); - -/** - * @brief Returns active PMS violation interrupt (if any) - * - * This function iterates through supported Memory type status registers - * and returns the first interrupt-on flag. If none is found active, - * MEMPROT_NONE is returned. - * Order of checking (in current version): - * 1. MEMPROT_IRAM0_SRAM - * 2. MEMPROT_DRAM0_SRAM - * - * @return mem_type Memory protection type related to active interrupt found (see mem_type_prot_t enum) - */ -mem_type_prot_t IRAM_ATTR esp_memprot_get_active_intr_memtype(void); - -/** - * @brief Checks whether any violation interrupt is active - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_is_locked_any(void); - -/** - * @brief Checks whether any violation interrupt is enabled - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_is_intr_ena_any(void); - -/** - * @brief Checks whether any violation interrupt is enabled - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_get_violate_intr_on(mem_type_prot_t mem_type); - -/** - * @brief Returns the address which caused the violation interrupt (if any) - * - * The address is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return faulting address - */ -uint32_t IRAM_ATTR esp_memprot_get_violate_addr(mem_type_prot_t mem_type); - -/** - * @brief Returns the World identifier of the code causing the violation interrupt (if any) - * - * The value is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return World identifier (see pms_world_t enum) - */ -pms_world_t IRAM_ATTR esp_memprot_get_violate_world(mem_type_prot_t mem_type); - -/** - * @brief Returns Read or Write operation type which caused the violation interrupt (if any) - * - * The value (bit) is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return PMS operation type relevant to mem_type parameter (se pms_operation_type_t) - */ -pms_operation_type_t IRAM_ATTR esp_memprot_get_violate_wr(mem_type_prot_t mem_type); - -/** - * @brief Returns LoadStore flag of the operation type which caused the violation interrupt (if any) - * - * The value (bit) is taken from appropriate PMS violation status register, based given Memory type - * Effective only on IRam0 access - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (LoadStore bit on/off) - */ -bool IRAM_ATTR esp_memprot_get_violate_loadstore(mem_type_prot_t mem_type); - -/** - * @brief Returns byte-enables for the address which caused the violation interrupt (if any) - * - * The value is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return byte-enables - */ -uint32_t IRAM_ATTR esp_memprot_get_violate_byte_en(mem_type_prot_t mem_type); - -/** - * @brief Returns raw contents of DRam0 status register 1 - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_dram_status_reg_1(void); - -/** - * @brief Returns raw contents of DRam0 status register 2 - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_dram_status_reg_2(void); - -/** - * @brief Returns raw contents of IRam0 status register - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_iram_status_reg(void); - -/** - * @brief Register PMS violation interrupt in global interrupt matrix for given Memory type - * - * Memory protection components uses specific interrupt number, see ETS_MEMPROT_ERR_INUM - * The registration makes the panic-handler routine being called when the interrupt appears - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_intr_matrix(mem_type_prot_t mem_type); - -/** - * @brief Convenient routine for setting the PMS defaults - * - * Called on application startup, depending on CONFIG_ESP_SYSTEM_MEMPROT_FEATURE Kconfig settings - * For implementation details see 'esp_memprot_set_prot_int' description - * - * @param invoke_panic_handler register all interrupts for panic handling (true/false) - * @param lock_feature lock the defaults to prevent further PMS settings changes (true/false) - * @param mem_type_mask 32-bit field of specific PMS parts to configure (see 'esp_memprot_set_prot_int') - */ -void esp_memprot_set_prot(bool invoke_panic_handler, bool lock_feature, uint32_t *mem_type_mask); - -/** - * @brief Internal routine for setting the PMS defaults - * - * Called on application startup from within 'esp_memprot_set_prot'. Allows setting a specific splitting address - * (main I/D split line) - see the parameter 'split_addr'. If the 'split_addr' equals to NULL, default I/D split line - * is used (&_iram_text_end) and all the remaining lines share the same address. - * The function sets all the split lines and PMS areas to the same space, - * ie there is a single instruction space and single data space at the end. - * The PMS split lines and permission areas scheme described below: - * - * DRam0/DMA IRam0 - * ----------------------------------------------- - * ... | IRam0_PMS_0 | - * DRam0_PMS_0 ----------------------------------------------- IRam0_line1_Split_addr - * ... | IRam0_PMS_1 | - * ... ----------------------------------------------- IRam0_line0_Split_addr - * | IRam0_PMS_2 | - * =============================================== IRam0_DRam0_Split_addr (main I/D) - * | DRam0_PMS_1 | - * DRam0_DMA_line0_Split_addr ----------------------------------------------- ... - * | DRam0_PMS_2 | ... - * DRam0_DMA_line1_Split_addr ----------------------------------------------- IRam0_PMS_3 - * | DRam0_PMS_3 | ... - * ----------------------------------------------- - * - * Default settings provided by 'esp_memprot_set_prot_int' are as follows: - * - * DRam0/DMA IRam0 - * ----------------------------------------------- - * | IRam0_PMS_0 = IRam0_PMS_1 = IRam0_PMS_2 | - * | DRam0_PMS_0 | IRam0_line1_Split_addr - * DRam0_DMA_line0_Split_addr | | = - * = =============================================== IRam0_line0_Split_addr - * DRam0_DMA_line1_Split_addr | | = - * | DRam0_PMS_1 = DRam0_PMS_2 = DRam0_PMS_3 | IRam0_DRam0_Split_addr (main I/D) - * | IRam0_PMS_3 | - * ----------------------------------------------- - * - * Once the memprot feature is locked, it can be unlocked only by digital system reset - * - * @param invoke_panic_handler register all the violation interrupts for panic handling (true/false) - * @param lock_feature lock the defaults to prevent further PMS settings changes (true/false) - * @param split_addr specific main I/D adrees or NULL to use default ($_iram_text_end) - * @param mem_type_mask 32-bit field of specific PMS parts to configure (members of mem_type_prot_t) - */ -void esp_memprot_set_prot_int(bool invoke_panic_handler, bool lock_feature, void *split_addr, uint32_t *mem_type_mask); - -/** - * @brief Returns raw contents of PMS interrupt monitor register for given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return 32-bit register value - */ -uint32_t esp_memprot_get_monitor_enable_reg(mem_type_prot_t mem_type); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32c3/soc_memprot_types.h b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32c3/soc_memprot_types.h new file mode 100644 index 00000000000..318c6109617 --- /dev/null +++ b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32c3/soc_memprot_types.h @@ -0,0 +1,175 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +////////////////////////////////////////////////////////// +// ESP32-C3 PMS memory protection types +// + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Memory types recognized by PMS + */ +typedef enum { + MEMPROT_TYPE_NONE = 0x00000000, + MEMPROT_TYPE_IRAM0_SRAM = 0x00000001, + MEMPROT_TYPE_DRAM0_SRAM = 0x00000002, + MEMPROT_TYPE_IRAM0_RTCFAST = 0x00000004, + MEMPROT_TYPE_ALL = 0x7FFFFFFF, + MEMPROT_TYPE_INVALID = 0x80000000, + MEMPROT_TYPE_IRAM0_ANY = MEMPROT_TYPE_IRAM0_SRAM | MEMPROT_TYPE_IRAM0_RTCFAST +} esp_mprot_mem_t; + +/** + * @brief Splitting address (line) type + */ +typedef enum { + MEMPROT_SPLIT_ADDR_NONE = 0x00000000, + MEMPROT_SPLIT_ADDR_IRAM0_DRAM0 = 0x00000001, + MEMPROT_SPLIT_ADDR_IRAM0_LINE_0 = 0x00000002, + MEMPROT_SPLIT_ADDR_IRAM0_LINE_1 = 0x00000004, + MEMPROT_SPLIT_ADDR_DRAM0_DMA_LINE_0 = 0x00000008, + MEMPROT_SPLIT_ADDR_DRAM0_DMA_LINE_1 = 0x00000010, + MEMPROT_SPLIT_ADDR_ALL = 0x7FFFFFFF, + MEMPROT_SPLIT_ADDR_INVALID = 0x80000000, + MEMPROT_SPLIT_ADDR_MAIN = MEMPROT_SPLIT_ADDR_IRAM0_DRAM0 +} esp_mprot_split_addr_t; + +/** + * @brief PMS area type (memory space between adjacent splitting addresses or above/below the main splt.address) + */ +typedef enum { + MEMPROT_PMS_AREA_NONE = 0x00000000, + MEMPROT_PMS_AREA_IRAM0_0 = 0x00000001, + MEMPROT_PMS_AREA_IRAM0_1 = 0x00000002, + MEMPROT_PMS_AREA_IRAM0_2 = 0x00000004, + MEMPROT_PMS_AREA_IRAM0_3 = 0x00000008, + MEMPROT_PMS_AREA_DRAM0_0 = 0x00000010, + MEMPROT_PMS_AREA_DRAM0_1 = 0x00000020, + MEMPROT_PMS_AREA_DRAM0_2 = 0x00000040, + MEMPROT_PMS_AREA_DRAM0_3 = 0x00000080, + MEMPROT_PMS_AREA_IRAM0_RTCFAST_LO = 0x00000100, + MEMPROT_PMS_AREA_IRAM0_RTCFAST_HI = 0x00000200, + MEMPROT_PMS_AREA_ALL = 0x7FFFFFFF, + MEMPROT_PMS_AREA_INVALID = 0x80000000 +} esp_mprot_pms_area_t; + +/** +* @brief Memory protection configuration +*/ +typedef struct { + bool invoke_panic_handler; /*!< Register PMS violation interrupt for panic-handling */ + bool lock_feature; /*!< Lock all PMS settings */ + void *split_addr; /*!< Main I/D splitting address */ + uint32_t mem_type_mask; /*!< Memory types required to protect. See esp_mprot_mem_t enum */ +} esp_memp_config_t; + +#define ESP_MEMPROT_DEFAULT_CONFIG() { \ + .invoke_panic_handler = true, \ + .lock_feature = true, \ + .split_addr = NULL, \ + .mem_type_mask = MEMPROT_TYPE_ALL \ +} + +/** + * @brief Converts Memory protection type to string + * + * @param mem_type Memory protection type + */ +static inline const char *esp_mprot_mem_type_to_str(const esp_mprot_mem_t mem_type) +{ + switch (mem_type) { + case MEMPROT_TYPE_NONE: + return "NONE"; + case MEMPROT_TYPE_IRAM0_SRAM: + return "IRAM0_SRAM"; + case MEMPROT_TYPE_DRAM0_SRAM: + return "DRAM0_SRAM"; + case MEMPROT_TYPE_IRAM0_RTCFAST: + return "IRAM0_RTCFAST"; + case MEMPROT_TYPE_IRAM0_ANY: + return "IRAM0_ANY"; + case MEMPROT_TYPE_ALL: + return "ALL"; + default: + return "INVALID"; + } +} + +/** + * @brief Converts Splitting address type to string + * + * @param line_type Split line type + */ +static inline const char *esp_mprot_split_addr_to_str(const esp_mprot_split_addr_t line_type) +{ + switch (line_type) { + case MEMPROT_SPLIT_ADDR_NONE: + return "SPLIT_ADDR_NONE"; + case MEMPROT_SPLIT_ADDR_IRAM0_DRAM0: + return "SPLIT_ADDR_IRAM0_DRAM0"; + case MEMPROT_SPLIT_ADDR_IRAM0_LINE_0: + return "SPLIT_ADDR_IRAM0_LINE_0"; + case MEMPROT_SPLIT_ADDR_IRAM0_LINE_1: + return "SPLIT_ADDR_IRAM0_LINE_1"; + case MEMPROT_SPLIT_ADDR_DRAM0_DMA_LINE_0: + return "SPLIT_ADDR_DRAM0_DMA_LINE_0"; + case MEMPROT_SPLIT_ADDR_DRAM0_DMA_LINE_1: + return "SPLIT_ADDR_DRAM0_DMA_LINE_1"; + case MEMPROT_SPLIT_ADDR_ALL: + return "SPLIT_ADDR_ALL"; + default: + return "SPLIT_ADDR_INVALID"; + } +} + +/** + * @brief Converts PMS Area type to string + * + * @param area_type PMS Area type + */ +static inline const char *esp_mprot_pms_area_to_str(const esp_mprot_pms_area_t area_type) +{ + switch (area_type) { + case MEMPROT_PMS_AREA_NONE: + return "PMS_AREA_NONE"; + case MEMPROT_PMS_AREA_IRAM0_0: + return "PMS_AREA_IRAM0_0"; + case MEMPROT_PMS_AREA_IRAM0_1: + return "PMS_AREA_IRAM0_1"; + case MEMPROT_PMS_AREA_IRAM0_2: + return "PMS_AREA_IRAM0_2"; + case MEMPROT_PMS_AREA_IRAM0_3: + return "PMS_AREA_IRAM0_3"; + case MEMPROT_PMS_AREA_DRAM0_0: + return "PMS_AREA_DRAM0_0"; + case MEMPROT_PMS_AREA_DRAM0_1: + return "PMS_AREA_DRAM0_1"; + case MEMPROT_PMS_AREA_DRAM0_2: + return "PMS_AREA_DRAM0_2"; + case MEMPROT_PMS_AREA_DRAM0_3: + return "PMS_AREA_DRAM0_3"; + case MEMPROT_PMS_AREA_IRAM0_RTCFAST_LO: + return "PMS_AREA_IRAM0_RTCFAST_LO"; + case MEMPROT_PMS_AREA_IRAM0_RTCFAST_HI: + return "PMS_AREA_IRAM0_RTCFAST_HI"; + case MEMPROT_PMS_AREA_ALL: + return "PMS_AREA_ALL"; + default: + return "PMS_AREA_INVALID"; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32h2/memprot.h b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32h2/memprot.h deleted file mode 100644 index 75228580ffd..00000000000 --- a/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32h2/memprot.h +++ /dev/null @@ -1,448 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - - -/* INTERNAL API - * generic interface to PMS memory protection features - */ - -#pragma once - -#include -#include -#include "esp_attr.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef IRAM_SRAM_START -#define IRAM_SRAM_START 0x4037C000 -#endif - -#ifndef DRAM_SRAM_START -#define DRAM_SRAM_START 0x3FC7C000 -#endif - -#ifndef MAP_DRAM_TO_IRAM -#define MAP_DRAM_TO_IRAM(addr) (addr - DRAM_SRAM_START + IRAM_SRAM_START) -#endif - -#ifndef MAP_IRAM_TO_DRAM -#define MAP_IRAM_TO_DRAM(addr) (addr - IRAM_SRAM_START + DRAM_SRAM_START) -#endif - -typedef enum { - MEMPROT_NONE = 0x00000000, - MEMPROT_IRAM0_SRAM = 0x00000001, - MEMPROT_DRAM0_SRAM = 0x00000002, - MEMPROT_ALL = 0xFFFFFFFF -} mem_type_prot_t; - -typedef enum { - MEMPROT_SPLITLINE_NONE = 0, - MEMPROT_IRAM0_DRAM0_SPLITLINE, - MEMPROT_IRAM0_LINE_0_SPLITLINE, - MEMPROT_IRAM0_LINE_1_SPLITLINE, - MEMPROT_DRAM0_DMA_LINE_0_SPLITLINE, - MEMPROT_DRAM0_DMA_LINE_1_SPLITLINE -} split_line_t; - -typedef enum { - MEMPROT_PMS_AREA_NONE = 0, - MEMPROT_IRAM0_PMS_AREA_0, - MEMPROT_IRAM0_PMS_AREA_1, - MEMPROT_IRAM0_PMS_AREA_2, - MEMPROT_IRAM0_PMS_AREA_3, - MEMPROT_DRAM0_PMS_AREA_0, - MEMPROT_DRAM0_PMS_AREA_1, - MEMPROT_DRAM0_PMS_AREA_2, - MEMPROT_DRAM0_PMS_AREA_3 -} pms_area_t; - -typedef enum -{ - MEMPROT_PMS_WORLD_0 = 0, - MEMPROT_PMS_WORLD_1, - MEMPROT_PMS_WORLD_2, - MEMPROT_PMS_WORLD_INVALID = 0xFFFFFFFF -} pms_world_t; - -typedef enum -{ - MEMPROT_PMS_OP_READ = 0, - MEMPROT_PMS_OP_WRITE, - MEMPROT_PMS_OP_FETCH, - MEMPROT_PMS_OP_INVALID = 0xFFFFFFFF -} pms_operation_type_t; - -/** - * @brief Converts Memory protection type to string - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -const char *esp_memprot_mem_type_to_str(mem_type_prot_t mem_type); - -/** - * @brief Converts Split line type to string - * - * @param line_type Split line type (see split_line_t enum) - */ -const char *esp_memprot_split_line_to_str(split_line_t line_type); - -/** - * @brief Converts PMS Area type to string - * - * @param area_type PMS Area type (see pms_area_t enum) - */ -const char *esp_memprot_pms_to_str(pms_area_t area_type); - -/** - * @brief Returns PMS splitting address for given Split line type - * - * The value is taken from PMS configuration registers (IRam0 range) - * For details on split lines see 'esp_memprot_set_prot_int' function description - * - * @param line_type Split line type (see split_line_t enum) - * - * @return appropriate split line address - */ -uint32_t *esp_memprot_get_split_addr(split_line_t line_type); - -/** - * @brief Returns default main IRAM/DRAM splitting address - * - * The address value is given by _iram_text_end global (IRam0 range) - - * @return Main I/D split line (IRam0_DRam0_Split_Addr) - */ -void *esp_memprot_get_default_main_split_addr(void); - -/** - * @brief Sets a lock for the main IRAM/DRAM splitting address - * - * Locks can be unlocked only by digital system reset - */ -void esp_memprot_set_split_line_lock(void); - -/** - * @brief Gets a lock status for the main IRAM/DRAM splitting address - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_split_line_lock(void); - -/** - * @brief Sets required split line address - * - * @param line_type Split line type (see split_line_t enum) - * @param line_addr target address from a memory range relevant to given line_type (IRAM/DRAM) - */ -void esp_memprot_set_split_line(split_line_t line_type, const void *line_addr); - -/** - * @brief Sets a lock for PMS Area settings of required Memory type - * - * Locks can be unlocked only by digital system reset - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_pms_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets a lock status for PMS Area settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_pms_lock(mem_type_prot_t mem_type); - -/** - * @brief Sets permissions for given PMS Area in IRam0 memory range (MEMPROT_IRAM0_SRAM) - * - * @param area_type IRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag - * @param w Write permission flag - * @param x Execute permission flag - */ -void esp_memprot_iram_set_pms_area(pms_area_t area_type, bool r, bool w, bool x); - -/** - * @brief Gets current permissions for given PMS Area in IRam0 memory range (MEMPROT_IRAM0_SRAM) - * - * @param area_type IRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag holder - * @param w Write permission flag holder - * @param x Execute permission flag holder - */ -void esp_memprot_iram_get_pms_area(pms_area_t area_type, bool *r, bool *w, bool *x); - -/** - * @brief Sets permissions for given PMS Area in DRam0 memory range (MEMPROT_DRAM0_SRAM) - * - * @param area_type DRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag - * @param w Write permission flag - */ -void esp_memprot_dram_set_pms_area(pms_area_t area_type, bool r, bool w); - -/** - * @brief Gets current permissions for given PMS Area in DRam0 memory range (MEMPROT_DRAM0_SRAM) - * - * @param area_type DRam0 PMS Area type (see pms_area_t enum) - * @param r Read permission flag holder - * @param w Write permission flag holder - */ -void esp_memprot_dram_get_pms_area(pms_area_t area_type, bool *r, bool *w); - -/** - * @brief Sets a lock for PMS interrupt monitor settings of required Memory type - * - * Locks can be unlocked only by digital system reset - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_monitor_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets a lock status for PMS interrupt monitor settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_monitor_lock(mem_type_prot_t mem_type); - -/** - * @brief Enable PMS violation interrupt monitoring of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * @param enable/disable - */ -void esp_memprot_set_monitor_en(mem_type_prot_t mem_type, bool enable); - -/** - * @brief Gets enable/disable status for PMS interrupt monitor settings of required Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (enabled/disabled) - */ -bool esp_memprot_get_monitor_en(mem_type_prot_t mem_type); - -/** - * @brief Gets CPU ID for currently active PMS violation interrupt - * - * @return CPU ID (CPU_PRO for ESP32H2) - */ -int IRAM_ATTR esp_memprot_intr_get_cpuid(void); - -/** - * @brief Clears current interrupt ON flag for given Memory type - * - * Interrupt clearing happens in two steps: - * 1. Interrupt CLR flag is set (to clear the interrupt ON status) - * 2. Interrupt CLR flag is reset (to allow further monitoring) - * This operation is non-atomic by PMS module design - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void IRAM_ATTR esp_memprot_monitor_clear_intr(mem_type_prot_t mem_type); - -/** - * @brief Returns active PMS violation interrupt (if any) - * - * This function iterates through supported Memory type status registers - * and returns the first interrupt-on flag. If none is found active, - * MEMPROT_NONE is returned. - * Order of checking (in current version): - * 1. MEMPROT_IRAM0_SRAM - * 2. MEMPROT_DRAM0_SRAM - * - * @return mem_type Memory protection type related to active interrupt found (see mem_type_prot_t enum) - */ -mem_type_prot_t IRAM_ATTR esp_memprot_get_active_intr_memtype(void); - -/** - * @brief Checks whether any violation interrupt is active - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_is_locked_any(void); - -/** - * @brief Checks whether any violation interrupt is enabled - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_is_intr_ena_any(void); - -/** - * @brief Checks whether any violation interrupt is enabled - * - * @return true/false (yes/no) - */ -bool IRAM_ATTR esp_memprot_get_violate_intr_on(mem_type_prot_t mem_type); - -/** - * @brief Returns the address which caused the violation interrupt (if any) - * - * The address is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return faulting address - */ -uint32_t IRAM_ATTR esp_memprot_get_violate_addr(mem_type_prot_t mem_type); - -/** - * @brief Returns the World identifier of the code causing the violation interrupt (if any) - * - * The value is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return World identifier (see pms_world_t enum) - */ -pms_world_t IRAM_ATTR esp_memprot_get_violate_world(mem_type_prot_t mem_type); - -/** - * @brief Returns Read or Write operation type which caused the violation interrupt (if any) - * - * The value (bit) is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return PMS operation type relevant to mem_type parameter (se pms_operation_type_t) - */ -pms_operation_type_t IRAM_ATTR esp_memprot_get_violate_wr(mem_type_prot_t mem_type); - -/** - * @brief Returns LoadStore flag of the operation type which caused the violation interrupt (if any) - * - * The value (bit) is taken from appropriate PMS violation status register, based given Memory type - * Effective only on IRam0 access - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return true/false (LoadStore bit on/off) - */ -bool IRAM_ATTR esp_memprot_get_violate_loadstore(mem_type_prot_t mem_type); - -/** - * @brief Returns byte-enables for the address which caused the violation interrupt (if any) - * - * The value is taken from appropriate PMS violation status register, based given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return byte-enables - */ -uint32_t IRAM_ATTR esp_memprot_get_violate_byte_en(mem_type_prot_t mem_type); - -/** - * @brief Returns raw contents of DRam0 status register 1 - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_dram_status_reg_1(void); - -/** - * @brief Returns raw contents of DRam0 status register 2 - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_dram_status_reg_2(void); - -/** - * @brief Returns raw contents of IRam0 status register - * - * @return 32-bit register value - */ -uint32_t IRAM_ATTR esp_memprot_get_iram_status_reg(void); - -/** - * @brief Register PMS violation interrupt in global interrupt matrix for given Memory type - * - * Memory protection components uses specific interrupt number, see ETS_MEMPROT_ERR_INUM - * The registration makes the panic-handler routine being called when the interrupt appears - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - */ -void esp_memprot_set_intr_matrix(mem_type_prot_t mem_type); - -/** - * @brief Convenient routine for setting the PMS defaults - * - * Called on application startup, depending on CONFIG_ESP_SYSTEM_MEMPROT_FEATURE Kconfig settings - * For implementation details see 'esp_memprot_set_prot_int' description - * - * @param invoke_panic_handler register all interrupts for panic handling (true/false) - * @param lock_feature lock the defaults to prevent further PMS settings changes (true/false) - * @param mem_type_mask 32-bit field of specific PMS parts to configure (see 'esp_memprot_set_prot_int') - */ -void esp_memprot_set_prot(bool invoke_panic_handler, bool lock_feature, uint32_t *mem_type_mask); - -/** - * @brief Internal routine for setting the PMS defaults - * - * Called on application startup from within 'esp_memprot_set_prot'. Allows setting a specific splitting address - * (main I/D split line) - see the parameter 'split_addr'. If the 'split_addr' equals to NULL, default I/D split line - * is used (&_iram_text_end) and all the remaining lines share the same address. - * The function sets all the split lines and PMS areas to the same space, - * ie there is a single instruction space and single data space at the end. - * The PMS split lines and permission areas scheme described below: - * - * DRam0/DMA IRam0 - * ----------------------------------------------- - * ... | IRam0_PMS_0 | - * DRam0_PMS_0 ----------------------------------------------- IRam0_line1_Split_addr - * ... | IRam0_PMS_1 | - * ... ----------------------------------------------- IRam0_line0_Split_addr - * | IRam0_PMS_2 | - * =============================================== IRam0_DRam0_Split_addr (main I/D) - * | DRam0_PMS_1 | - * DRam0_DMA_line0_Split_addr ----------------------------------------------- ... - * | DRam0_PMS_2 | ... - * DRam0_DMA_line1_Split_addr ----------------------------------------------- IRam0_PMS_3 - * | DRam0_PMS_3 | ... - * ----------------------------------------------- - * - * Default settings provided by 'esp_memprot_set_prot_int' are as follows: - * - * DRam0/DMA IRam0 - * ----------------------------------------------- - * | IRam0_PMS_0 = IRam0_PMS_1 = IRam0_PMS_2 | - * | DRam0_PMS_0 | IRam0_line1_Split_addr - * DRam0_DMA_line0_Split_addr | | = - * = =============================================== IRam0_line0_Split_addr - * DRam0_DMA_line1_Split_addr | | = - * | DRam0_PMS_1 = DRam0_PMS_2 = DRam0_PMS_3 | IRam0_DRam0_Split_addr (main I/D) - * | IRam0_PMS_3 | - * ----------------------------------------------- - * - * Once the memprot feature is locked, it can be unlocked only by digital system reset - * - * @param invoke_panic_handler register all the violation interrupts for panic handling (true/false) - * @param lock_feature lock the defaults to prevent further PMS settings changes (true/false) - * @param split_addr specific main I/D adrees or NULL to use default ($_iram_text_end) - * @param mem_type_mask 32-bit field of specific PMS parts to configure (members of mem_type_prot_t) - */ -void esp_memprot_set_prot_int(bool invoke_panic_handler, bool lock_feature, void *split_addr, uint32_t *mem_type_mask); - -/** - * @brief Returns raw contents of PMS interrupt monitor register for given Memory type - * - * @param mem_type Memory protection type (see mem_type_prot_t enum) - * - * @return 32-bit register value - */ -uint32_t esp_memprot_get_monitor_enable_reg(mem_type_prot_t mem_type); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32h2/soc_memprot_types.h b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32h2/soc_memprot_types.h new file mode 100644 index 00000000000..3048088eba4 --- /dev/null +++ b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32h2/soc_memprot_types.h @@ -0,0 +1,117 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +////////////////////////////////////////////////////////// +// ESP32-H2 PMS memory protection types +// + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Memory types recognized by PMS + */ +typedef enum { + MEMPROT_TYPE_NONE = 0x00000000, + MEMPROT_TYPE_ALL = 0x7FFFFFFF, + MEMPROT_TYPE_INVALID = 0x80000000 +} esp_mprot_mem_t; + +/** + * @brief Splitting address (line) type + */ +typedef enum { + MEMPROT_SPLIT_ADDR_NONE = 0x00000000, + MEMPROT_SPLIT_ADDR_ALL = 0x7FFFFFFF, + MEMPROT_SPLIT_ADDR_INVALID = 0x80000000 +} esp_mprot_split_addr_t; + +/** + * @brief PMS area type (memory space between adjacent splitting addresses or above/below the main splt.address) + */ +typedef enum { + MEMPROT_PMS_AREA_NONE = 0x00000000, + MEMPROT_PMS_AREA_ALL = 0x7FFFFFFF, + MEMPROT_PMS_AREA_INVALID = 0x80000000 +} esp_mprot_pms_area_t; + +/** +* @brief Memory protection configuration +*/ +typedef struct { + bool invoke_panic_handler; /*!< Register PMS violation interrupt for panic-handling */ + bool lock_feature; /*!< Lock all PMS settings */ + void *split_addr; /*!< Main I/D splitting address */ + uint32_t mem_type_mask; /*!< Memory types required to protect. See esp_mprot_mem_t enum */ +} esp_memp_config_t; + +#define ESP_MEMPROT_DEFAULT_CONFIG() {\ + .invoke_panic_handler = true, \ + .lock_feature = true, \ + .split_addr = NULL, \ + .mem_type_mask = MEMPROT_TYPE_ALL \ +} + +/** + * @brief Converts Memory protection type to string + * + * @param mem_type Memory protection type + */ +static inline const char *esp_mprot_mem_type_to_str(const esp_mprot_mem_t mem_type) +{ + switch (mem_type) { + case MEMPROT_TYPE_NONE: + return "MEMPROT_TYPE_NONE"; + case MEMPROT_TYPE_ALL: + return "MEMPROT_TYPE_ALL"; + default: + return "MEMPROT_TYPE_INVALID"; + } +} + +/** + * @brief Converts Splitting address type to string + * + * @param line_type Split line type + */ +static inline const char *esp_mprot_split_addr_to_str(const esp_mprot_split_addr_t line_type) +{ + switch (line_type) { + case MEMPROT_SPLIT_ADDR_NONE: + return "MEMPROT_SPLIT_ADDR_NONE"; + case MEMPROT_SPLIT_ADDR_ALL: + return "MEMPROT_SPLIT_ADDR_ALL"; + default: + return "MEMPROT_SPLIT_ADDR_INVALID"; + } +} + +/** + * @brief Converts PMS Area type to string + * + * @param area_type PMS Area type + */ +static inline const char *esp_mprot_pms_area_to_str(const esp_mprot_pms_area_t area_type) +{ + switch (area_type) { + case MEMPROT_PMS_AREA_NONE: + return "MEMPROT_PMS_AREA_NONE"; + case MEMPROT_PMS_AREA_ALL: + return "MEMPROT_PMS_AREA_ALL"; + default: + return "MEMPROT_PMS_AREA_INVALID"; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32s2/soc_memprot_types.h b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32s2/soc_memprot_types.h new file mode 100644 index 00000000000..f17e2143133 --- /dev/null +++ b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32s2/soc_memprot_types.h @@ -0,0 +1,117 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +////////////////////////////////////////////////////////// +// ESP32-S2 PMS memory protection types +// + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Memory types recognized by PMS + */ +typedef enum { + MEMPROT_TYPE_NONE = 0x00000000, + MEMPROT_TYPE_ALL = 0x7FFFFFFF, + MEMPROT_TYPE_INVALID = 0x80000000 +} esp_mprot_mem_t; + +/** + * @brief Splitting address (line) type + */ +typedef enum { + MEMPROT_SPLIT_ADDR_NONE = 0x00000000, + MEMPROT_SPLIT_ADDR_ALL = 0x7FFFFFFF, + MEMPROT_SPLIT_ADDR_INVALID = 0x80000000 +} esp_mprot_split_addr_t; + +/** + * @brief PMS area type (memory space between adjacent splitting addresses or above/below the main splt.address) + */ +typedef enum { + MEMPROT_PMS_AREA_NONE = 0x00000000, + MEMPROT_PMS_AREA_ALL = 0x7FFFFFFF, + MEMPROT_PMS_AREA_INVALID = 0x80000000 +} esp_mprot_pms_area_t; + +/** +* @brief Memory protection configuration +*/ +typedef struct { + bool invoke_panic_handler; /*!< Register PMS violation interrupt for panic-handling */ + bool lock_feature; /*!< Lock all PMS settings */ + void *split_addr; /*!< Main I/D splitting address */ + uint32_t mem_type_mask; /*!< Memory types required to protect. See esp_mprot_mem_t enum */ +} esp_memp_config_t; + +#define ESP_MEMPROT_DEFAULT_CONFIG() { \ + .invoke_panic_handler = true, \ + .lock_feature = true, \ + .split_addr = NULL, \ + .mem_type_mask = MEMPROT_TYPE_ALL \ +} + +/** + * @brief Converts Memory protection type to string + * + * @param mem_type Memory protection type + */ +static inline const char *esp_mprot_mem_type_to_str(const esp_mprot_mem_t mem_type) +{ + switch (mem_type) { + case MEMPROT_TYPE_NONE: + return "MEMPROT_TYPE_NONE"; + case MEMPROT_TYPE_ALL: + return "MEMPROT_TYPE_ALL"; + default: + return "MEMPROT_TYPE_INVALID"; + } +} + +/** + * @brief Converts Splitting address type to string + * + * @param line_type Split line type + */ +static inline const char *esp_mprot_split_addr_to_str(const esp_mprot_split_addr_t line_type) +{ + switch (line_type) { + case MEMPROT_SPLIT_ADDR_NONE: + return "MEMPROT_SPLIT_ADDR_NONE"; + case MEMPROT_SPLIT_ADDR_ALL: + return "MEMPROT_SPLIT_ADDR_ALL"; + default: + return "MEMPROT_SPLIT_ADDR_INVALID"; + } +} + +/** + * @brief Converts PMS Area type to string + * + * @param area_type PMS Area type + */ +static inline const char *esp_mprot_pms_area_to_str(const esp_mprot_pms_area_t area_type) +{ + switch (area_type) { + case MEMPROT_PMS_AREA_NONE: + return "MEMPROT_PMS_AREA_NONE"; + case MEMPROT_PMS_AREA_ALL: + return "MEMPROT_PMS_AREA_ALL"; + default: + return "MEMPROT_PMS_AREA_INVALID"; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32s3/memprot.h b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32s3/memprot.h deleted file mode 100644 index 948e0676680..00000000000 --- a/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32s3/memprot.h +++ /dev/null @@ -1,484 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - - -/* INTERNAL API - * generic interface to MMU memory protection features - */ - -#pragma once -#include -#include -#include "esp_attr.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - MEMPROT_NONE = 0x00000000, - MEMPROT_IRAM0_SRAM = 0x00000001, - MEMPROT_DRAM0_SRAM = 0x00000002, - MEMPROT_IRAM0_RTCFAST = 0x00000004, - MEMPROT_DRAM0_RTCFAST = 0x00000008, - MEMPROT_PERI1_RTCSLOW = 0x00000010, - MEMPROT_PERI2_RTCSLOW_0 = 0x00000020, - MEMPROT_PERI2_RTCSLOW_1 = 0x00000040, - MEMPROT_ALL = 0xFFFFFFFF -} mem_type_prot_t; - - -/** - * @brief Returns splitting address for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Splitting address for the memory region required. - * The address is given by region-specific global symbol exported from linker script, - * it is not read out from related configuration register. - */ -uint32_t *IRAM_ATTR esp_memprot_get_split_addr(mem_type_prot_t mem_type); - -/** - * @brief Initializes illegal memory access control (MMU) for required memory section. - * - * All memory access interrupts share ETS_MEMACCESS_ERR_INUM input channel, it is caller's - * responsibility to properly detect actual intr. source as well as possible prioritization in case - * of multiple source reported during one intr.handling routine run - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - */ -void esp_memprot_intr_init(mem_type_prot_t mem_type); - -/** - * @brief Enable/disable the memory protection interrupt - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param enable enable/disable - */ -void esp_memprot_intr_ena(mem_type_prot_t mem_type, bool enable); - -/** - * @brief Sets a request for clearing interrupt-on flag for specified memory region (register write) - * - * @note When called without actual interrupt-on flag set, subsequent occurrence of related interrupt is ignored. - * Should be used only after the real interrupt appears, typically as the last step in interrupt handler's routine. - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - */ -void esp_memprot_clear_intr(mem_type_prot_t mem_type); - -/** - * @brief Detects which memory protection interrupt is active - * - * @note Check order - * MEMPROT_IRAM0_SRAM - * MEMPROT_IRAM0_RTCFAST - * MEMPROT_DRAM0_SRAM - * MEMPROT_DRAM0_RTCFAST - * - * @return Memory protection area type (see mem_type_prot_t enum) - */ -mem_type_prot_t IRAM_ATTR esp_memprot_get_active_intr_memtype(void); - -/** - * @brief Gets interrupt status register contents for specified memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Contents of status register - */ -uint32_t esp_memprot_get_fault_reg(mem_type_prot_t mem_type); - -/** - * @brief Get details of given interrupt status - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param faulting_address Faulting address causing the interrupt [out] - * @param op_type Operation being processed at the faulting address [out] - * IRAM0: 0 - read, 1 - write - * DRAM0: 0 - read, 1 - write - * @param op_subtype Additional info for op_type [out] - * IRAM0: 0 - instruction segment access, 1 - data segment access - * DRAM0: 0 - non-atomic operation, 1 - atomic operation - */ -void IRAM_ATTR esp_memprot_get_fault_status(mem_type_prot_t mem_type, uint32_t **faulting_address, uint32_t *op_type, uint32_t *op_subtype); - -/** - * @brief Gets string representation of required memory region identifier - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return mem_type as string - */ -const char *IRAM_ATTR esp_memprot_type_to_str(mem_type_prot_t mem_type); - -/** - * @brief Detects whether any of the interrupt locks is active (requires digital system reset to unlock) - * - * @return true/false - */ -bool esp_memprot_is_locked_any(void); - -/** - * @brief Sets lock for specified memory region. - * - * Locks can be unlocked only by digital system reset - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - */ -void esp_memprot_set_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets lock status for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return true/false (locked/unlocked) - */ -bool esp_memprot_get_lock(mem_type_prot_t mem_type); - -/** - * @brief Gets permission control configuration register contents for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Permission control register contents - */ -uint32_t esp_memprot_get_conf_reg(mem_type_prot_t mem_type); - -/** - * @brief Gets interrupt permission settings for unified management block - * - * Gets interrupt permission settings register contents for required memory region, returns settings for unified management blocks - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Permission settings register contents - */ -uint32_t esp_memprot_get_perm_uni_reg(mem_type_prot_t mem_type); - -/** - * @brief Gets interrupt permission settings for split management block - * - * Gets interrupt permission settings register contents for required memory region, returns settings for split management blocks - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Permission settings register contents - */ -uint32_t esp_memprot_get_perm_split_reg(mem_type_prot_t mem_type); - -/** - * @brief Detects whether any of the memory protection interrupts is enabled - * - * @return true/false - */ -bool esp_memprot_is_intr_ena_any(void); - -/** - * @brief Gets interrupt-enabled flag for given memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Interrupt-enabled value - */ -uint32_t esp_memprot_get_intr_ena_bit(mem_type_prot_t mem_type); - -/** - * @brief Gets interrupt-active flag for given memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Interrupt-active value - */ -uint32_t esp_memprot_get_intr_on_bit(mem_type_prot_t mem_type); - -/** - * @brief Gets interrupt-clear request flag for given memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * - * @return Interrupt-clear request value - */ -uint32_t esp_memprot_get_intr_clr_bit(mem_type_prot_t mem_type); - -/** - * @brief Gets read permission value for specified block and memory region - * - * Returns read permission bit value for required unified-management block (0-3) in given memory region. - * Applicable to all memory types. - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param block Memory block identifier (0-3) - * - * @return Read permission value for required block - */ -uint32_t esp_memprot_get_uni_block_read_bit(mem_type_prot_t mem_type, uint32_t block); - -/** - * @brief Gets write permission value for specified block and memory region - * - * Returns write permission bit value for required unified-management block (0-3) in given memory region. - * Applicable to all memory types. - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param block Memory block identifier (0-3) - * - * @return Write permission value for required block - */ -uint32_t esp_memprot_get_uni_block_write_bit(mem_type_prot_t mem_type, uint32_t block); - -/** - * @brief Gets execute permission value for specified block and memory region - * - * Returns execute permission bit value for required unified-management block (0-3) in given memory region. - * Applicable only to IRAM memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param block Memory block identifier (0-3) - * - * @return Execute permission value for required block - */ -uint32_t esp_memprot_get_uni_block_exec_bit(mem_type_prot_t mem_type, uint32_t block); - -/** - * @brief Sets permissions for specified block in DRAM region - * - * Sets Read and Write permission for specified unified-management block (0-3) in given memory region. - * Applicable only to DRAM memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param block Memory block identifier (0-3) - * @param write_perm Write permission flag - * @param read_perm Read permission flag - */ -void esp_memprot_set_uni_block_perm_dram(mem_type_prot_t mem_type, uint32_t block, bool write_perm, bool read_perm); - -/** - * @brief Sets permissions for high and low memory segment in DRAM region - * - * Sets Read and Write permission for both low and high memory segments given by splitting address. - * The splitting address must be equal to or higher then beginning of block 5 - * Applicable only to DRAM memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param split_addr Address to split the memory region to lower and higher segment - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_set_prot_dram(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool hw, bool hr); - -/** - * @brief Sets permissions for specified block in IRAM region - * - * Sets Read, Write and Execute permission for specified unified-management block (0-3) in given memory region. - * Applicable only to IRAM memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param block Memory block identifier (0-3) - * @param write_perm Write permission flag - * @param exec_perm Execute permission flag - */ -void esp_memprot_set_uni_block_perm_iram(mem_type_prot_t mem_type, uint32_t block, bool write_perm, bool read_perm, bool exec_perm); - -/** - * @brief Sets permissions for high and low memory segment in IRAM region - * - * Sets Read, Write and Execute permission for both low and high memory segments given by splitting address. - * The splitting address must be equal to or higher then beginning of block 5 - * Applicable only to IRAM memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param split_addr Address to split the memory region to lower and higher segment - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param lx Low segment Execute permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - * @param hx High segment Execute permission flag - */ -void esp_memprot_set_prot_iram(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool lx, bool hw, bool hr, bool hx); - -/** - * @brief Activates memory protection for all supported memory region types - * - * @note The feature is disabled when JTAG interface is connected - * - * @param invoke_panic_handler map mem.prot interrupt to ETS_MEMACCESS_ERR_INUM and thus invokes panic handler when fired ('true' not suitable for testing) - * @param lock_feature sets LOCK bit, see esp_memprot_set_lock() ('true' not suitable for testing) - * @param mem_type_mask holds a set of required memory protection types (bitmask built of mem_type_prot_t). NULL means default (MEMPROT_ALL in this version) - */ -void esp_memprot_set_prot(bool invoke_panic_handler, bool lock_feature, uint32_t *mem_type_mask); - -/** - * @brief Get permission settings bits for IRAM0 split mgmt. Only IRAM0 memory types allowed - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param lx Low segment Execute permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - * @param hx High segment Execute permission flag - */ -void esp_memprot_get_perm_split_bits_iram(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *lx, bool *hw, bool *hr, bool *hx); - -/** - * @brief Get permission settings bits for DRAM0 split mgmt. Only DRAM0 memory types allowed - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_get_perm_split_bits_dram(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *hw, bool *hr); - -/** - * @brief Sets permissions for high and low memory segment in PERIBUS1 region - * - * Sets Read and Write permission for both low and high memory segments given by splitting address. - * Applicable only to PERIBUS1 memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param split_addr Address to split the memory region to lower and higher segment - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_set_prot_peri1(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool hw, bool hr); - -/** - * @brief Get permission settings bits for PERIBUS1 split mgmt. Only PERIBUS1 memory types allowed - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_get_perm_split_bits_peri1(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *hw, bool *hr); - -/** - * @brief Get permission settings bits for PERIBUS2 split mgmt. Only PERIBUS2 memory types allowed - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param lx Low segment Execute permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - * @param hx High segment Execute permission flag - */ -void esp_memprot_get_perm_split_bits_peri2(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *lx, bool *hw, bool *hr, bool *hx); - -/** - * @brief Sets permissions for high and low memory segment in PERIBUS2 region - * - * Sets Read Write permission for both low and high memory segments given by splitting address. - * Applicable only to PERIBUS2 memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param split_addr Address to split the memory region to lower and higher segment - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param lx Low segment Execute permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - * @param hx High segment Execute permission flag - */ -void esp_memprot_set_prot_peri2(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool lx, bool hw, bool hr, bool hx); - -/** - * @brief Get permissions for specified memory type. Irrelevant bits are ignored - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lw Low segment Write permission flag - * @param lr Low segment Read permission flag - * @param lx Low segment Execute permission flag - * @param hw High segment Write permission flag - * @param hr High segment Read permission flag - * @param hx High segment Execute permission flag - */ -void esp_memprot_get_permissions(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *lx, bool *hw, bool *hr, bool *hx); - -/** - * @brief Get Read permission settings for low and high regions of given memory type - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Read permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_get_perm_read(mem_type_prot_t mem_type, bool *lr, bool *hr); - -/** - * @brief Get Write permission settings for low and high regions of given memory type - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Write permission flag - * @param hr High segment Write permission flag - */ -void esp_memprot_get_perm_write(mem_type_prot_t mem_type, bool *lw, bool *hw); - -/** - * @brief Get Execute permission settings for low and high regions of given memory type - * Applicable only to IBUS-compatible memory types - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Exec permission flag - * @param hr High segment Exec permission flag - */ -void esp_memprot_get_perm_exec(mem_type_prot_t mem_type, bool *lx, bool *hx); - -/** - * @brief Returns the lowest address in required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - */ -uint32_t esp_memprot_get_low_limit(mem_type_prot_t mem_type); - -/** - * @brief Returns the highest address in required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - */ -uint32_t esp_memprot_get_high_limit(mem_type_prot_t mem_type); - -/** - * @brief Sets READ permission bit for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Read permission flag - * @param hr High segment Read permission flag - */ -void esp_memprot_set_read_perm(mem_type_prot_t mem_type, bool lr, bool hr); - -/** - * @brief Sets WRITE permission bit for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Write permission flag - * @param hr High segment Write permission flag - */ -void esp_memprot_set_write_perm(mem_type_prot_t mem_type, bool lw, bool hw); - -/** - * @brief Sets EXECUTE permission bit for required memory region - * - * @param mem_type Memory protection area type (see mem_type_prot_t enum) - * @param lr Low segment Exec permission flag - * @param hr High segment Exec permission flag - */ -void esp_memprot_set_exec_perm(mem_type_prot_t mem_type, bool lx, bool hx); - - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32s3/soc_memprot_types.h b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32s3/soc_memprot_types.h new file mode 100644 index 00000000000..06dde33ffad --- /dev/null +++ b/tools/sdk/esp32s3/include/esp_hw_support/include/soc/esp32s3/soc_memprot_types.h @@ -0,0 +1,119 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +////////////////////////////////////////////////////////// +// ESP32-S3 PMS memory protection types +// + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Memory types recognized by PMS + */ +typedef enum { + MEMPROT_TYPE_NONE = 0x00000000, + MEMPROT_TYPE_ALL = 0x7FFFFFFF, + MEMPROT_TYPE_INVALID = 0x80000000 +} esp_mprot_mem_t; + +/** + * @brief Splitting address (line) type + */ +typedef enum { + MEMPROT_SPLIT_ADDR_NONE = 0x00000000, + MEMPROT_SPLIT_ADDR_ALL = 0x7FFFFFFF, + MEMPROT_SPLIT_ADDR_INVALID = 0x80000000 +} esp_mprot_split_addr_t; + +/** + * @brief PMS area type (memory space between adjacent splitting addresses or above/below the main splt.address) + */ +typedef enum { + MEMPROT_PMS_AREA_NONE = 0x00000000, + MEMPROT_PMS_AREA_ALL = 0x7FFFFFFF, + MEMPROT_PMS_AREA_INVALID = 0x80000000 +} esp_mprot_pms_area_t; + +/** +* @brief Memory protection configuration +*/ +typedef struct { + bool invoke_panic_handler; /*!< Register PMS violation interrupt for panic-handling */ + bool lock_feature; /*!< Lock all PMS settings */ + void *split_addr; /*!< Main I/D splitting address */ + uint32_t mem_type_mask; /*!< Memory types required to protect. See esp_mprot_mem_t enum */ + int target_cpu[]; /*!< Array of CPU/core IDs required to receive given PMS protection */ +} esp_memp_config_t; + +#define ESP_MEMPROT_DEFAULT_CONFIG() { \ + .invoke_panic_handler = true, \ + .lock_feature = true, \ + .split_addr = NULL, \ + .mem_type_mask = MEMPROT_TYPE_ALL,\ + .target_cpu[] = {PRO_CPU_NUM, APP_CPU_NUM} \ +} + +/** + * @brief Converts Memory protection type to string + * + * @param mem_type Memory protection type + */ +static inline const char *esp_mprot_mem_type_to_str(const esp_mprot_mem_t mem_type) +{ + switch (mem_type) { + case MEMPROT_TYPE_NONE: + return "MEMPROT_TYPE_NONE"; + case MEMPROT_TYPE_ALL: + return "MEMPROT_TYPE_ALL"; + default: + return "MEMPROT_TYPE_INVALID"; + } +} + +/** + * @brief Converts Splitting address type to string + * + * @param line_type Split line type + */ +static inline const char *esp_mprot_split_addr_to_str(const esp_mprot_split_addr_t line_type) +{ + switch (line_type) { + case MEMPROT_SPLIT_ADDR_NONE: + return "MEMPROT_SPLIT_ADDR_NONE"; + case MEMPROT_SPLIT_ADDR_ALL: + return "MEMPROT_SPLIT_ADDR_ALL"; + default: + return "MEMPROT_SPLIT_ADDR_INVALID"; + } +} + +/** + * @brief Converts PMS Area type to string + * + * @param area_type PMS Area type + */ +static inline const char *esp_mprot_pms_area_to_str(const esp_mprot_pms_area_t area_type) +{ + switch (area_type) { + case MEMPROT_PMS_AREA_NONE: + return "MEMPROT_PMS_AREA_NONE"; + case MEMPROT_PMS_AREA_ALL: + return "MEMPROT_PMS_AREA_ALL"; + default: + return "MEMPROT_PMS_AREA_INVALID"; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32s3/include/freertos/include/freertos/projdefs.h b/tools/sdk/esp32s3/include/freertos/include/freertos/projdefs.h index ec8022ca0b0..1949e6e30b3 100644 --- a/tools/sdk/esp32s3/include/freertos/include/freertos/projdefs.h +++ b/tools/sdk/esp32s3/include/freertos/include/freertos/projdefs.h @@ -41,7 +41,7 @@ typedef void (* TaskFunction_t)( void * ); #endif #ifdef ESP_PLATFORM #ifndef pdTICKS_TO_MS - #define pdTICKS_TO_MS( xTicks ) ( ( uint32_t ) ( xTicks ) * 1000 / configTICK_RATE_HZ ) + #define pdTICKS_TO_MS( xTicks ) ( ( TickType_t ) ( ( uint64_t ) ( xTicks ) * 1000 / configTICK_RATE_HZ ) ) #endif #endif // ESP_PLATFORM diff --git a/tools/sdk/esp32s3/include/hal/esp32s3/include/hal/trace_ll.h b/tools/sdk/esp32s3/include/hal/esp32s3/include/hal/trace_ll.h index b271409b0a0..ccf4e885535 100644 --- a/tools/sdk/esp32s3/include/hal/esp32s3/include/hal/trace_ll.h +++ b/tools/sdk/esp32s3/include/hal/esp32s3/include/hal/trace_ll.h @@ -1,24 +1,23 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once #include #include "soc/dport_reg.h" +#include "soc/tracemem_config.h" -static inline void trace_ll_set_mem_block(int block) +static inline void trace_ll_set_mem_block(int cpu, int block) { - // IDF-1785 - abort(); + uint32_t block_bits = 0; + + if (cpu == 0) { + block_bits = TRACEMEM_CORE0_MUX_BLK_BITS(block); + } else { + block_bits = TRACEMEM_CORE1_MUX_BLK_BITS(block); + } + DPORT_SET_PERI_REG_MASK(SENSITIVE_INTERNAL_SRAM_USAGE_2_REG, block_bits); } diff --git a/tools/sdk/esp32s3/include/hal/include/hal/i2s_types.h b/tools/sdk/esp32s3/include/hal/include/hal/i2s_types.h index 48d745eb2fa..c59220c89cd 100644 --- a/tools/sdk/esp32s3/include/hal/include/hal/i2s_types.h +++ b/tools/sdk/esp32s3/include/hal/include/hal/i2s_types.h @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once diff --git a/tools/sdk/esp32s3/include/hal/include/hal/memprot_types.h b/tools/sdk/esp32s3/include/hal/include/hal/memprot_types.h index 42231f43eaf..15e3c3959ab 100644 --- a/tools/sdk/esp32s3/include/hal/include/hal/memprot_types.h +++ b/tools/sdk/esp32s3/include/hal/include/hal/memprot_types.h @@ -1,16 +1,8 @@ -// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -25,11 +17,34 @@ extern "C" { typedef enum { MEMP_LL_OK = 0, MEMP_LL_FAIL = 1, - MEMP_LL_ERR_SPLIT_ADDR_INVALID = 2, + MEMP_LL_ERR_SPLIT_ADDR_OUT_OF_RANGE = 2, + MEMP_LL_ERR_SPLIT_ADDR_INVALID = 2, /* temporary duplicate for S2 builds */ MEMP_LL_ERR_SPLIT_ADDR_UNALIGNED = 3, - MEMP_LL_ERR_UNI_BLOCK_INVALID = 4 + MEMP_LL_ERR_UNI_BLOCK_INVALID = 4, + MEMP_LL_ERR_AREA_INVALID = 5, + MEMP_LL_ERR_WORLD_INVALID = 6 } memprot_ll_err_t; +/** + * @brief Memprot LL PMS World IDs + * + */ +typedef enum { + MEMP_LL_WORLD_NONE = 0x00, + MEMP_LL_WORLD_0 = 0x01, + MEMP_LL_WORLD_1 = 0x10 +} memprot_ll_world_t; + +/** + * @brief Memprot LL PMS Area IDs + * + */ +typedef enum { + MEMP_LL_AREA_NONE = 0, + MEMP_LL_AREA_LOW = 1, + MEMP_LL_AREA_HIGH = 2 +} memprot_ll_area_t; + #ifdef __cplusplus } #endif diff --git a/tools/sdk/esp32s3/include/idf_test/include/esp32/idf_performance_target.h b/tools/sdk/esp32s3/include/idf_test/include/esp32/idf_performance_target.h index 5700d9f39ed..d6b64df99a7 100644 --- a/tools/sdk/esp32s3/include/idf_test/include/esp32/idf_performance_target.h +++ b/tools/sdk/esp32s3/include/idf_test/include/esp32/idf_performance_target.h @@ -33,88 +33,6 @@ #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 30 #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 27 -/* - * Flash Performance value - * 4 subsections: legacy, normal (new driver after v4.0), SPI1 (external but on SPI1), external (SPI2) - * These thresholds are set to about 70% of the average test data, under certain condition. - * Contact Espressif for details. - */ -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B -//The single_core config is much faster than other configs. Use the value of other configs -//Collect data and correct it later -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B -//The single_core config is much faster than other configs. Use the value of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B 35300 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB (697*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB (6780*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE 11200 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B -//The single_core config is much faster than other configs. Use the value of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B 20100 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B -//The single_core config is much faster than other configs. Use the value of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B 35200 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB (754*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB (6650*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE 45300 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B -//The single_core config is much faster than other configs. Use the value of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B 16200 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B -//The single_core config is much faster than other configs. Use the value of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B 33600 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB (484*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB (1512*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE 49600 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B -//Collect data and correct it later -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B (261*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB (470*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB (261*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE 30900 -#endif - // floating point instructions per divide and per sqrt (configured for worst-case with PSRAM workaround) #define IDF_PERFORMANCE_MAX_CYCLES_PER_DIV 70 #define IDF_PERFORMANCE_MAX_CYCLES_PER_SQRT 140 diff --git a/tools/sdk/esp32s3/include/idf_test/include/esp32c3/idf_performance_target.h b/tools/sdk/esp32s3/include/idf_test/include/esp32c3/idf_performance_target.h index c77e3efb1ec..7fbf8b9eaf5 100644 --- a/tools/sdk/esp32s3/include/idf_test/include/esp32c3/idf_performance_target.h +++ b/tools/sdk/esp32s3/include/idf_test/include/esp32c3/idf_performance_target.h @@ -29,85 +29,6 @@ #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 32 #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 30 -/* - * Flash Performance value - * 4 subsections: legacy, normal (new driver after v4.0), SPI1 (external but on SPI1), external (SPI2) - * These thresholds are set to about 70% of the average test data, under certain condition. - * Contact Espressif for details. - */ -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B -// rom options is much slower. use its 70% -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B 42200 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B -// legacy & suspend config are much faster. use the 70% of slower configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B (179*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB (622*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB (6536*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE 23700 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B 46400 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B -// legacy & suspend config are much faster. use the 70% of slower configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B (183*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB (605*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB (6676*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE 22900 -#endif - -// No SPI1 tests for C3 -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE 0 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B 43300 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B -// rom options is much slower. use its 70% -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B 99500 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB (300*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB (754*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE 33900 -#endif - // floating point instructions per divide and per sqrt (configured for worst-case with PSRAM workaround) #define IDF_PERFORMANCE_MAX_CYCLES_PER_DIV 70 #define IDF_PERFORMANCE_MAX_CYCLES_PER_SQRT 140 diff --git a/tools/sdk/esp32s3/include/idf_test/include/esp32h2/idf_performance_target.h b/tools/sdk/esp32s3/include/idf_test/include/esp32h2/idf_performance_target.h index af5738d1fcd..7fbf8b9eaf5 100644 --- a/tools/sdk/esp32s3/include/idf_test/include/esp32h2/idf_performance_target.h +++ b/tools/sdk/esp32s3/include/idf_test/include/esp32h2/idf_performance_target.h @@ -29,42 +29,6 @@ #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 32 #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 30 -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B 53400 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB (701*1000) -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B 53600 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE 44300 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B 24400 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B 64900 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B (309*1000) -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB (1697*1000) -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE 76600 -#endif - // floating point instructions per divide and per sqrt (configured for worst-case with PSRAM workaround) #define IDF_PERFORMANCE_MAX_CYCLES_PER_DIV 70 #define IDF_PERFORMANCE_MAX_CYCLES_PER_SQRT 140 diff --git a/tools/sdk/esp32s3/include/idf_test/include/esp32s2/idf_performance_target.h b/tools/sdk/esp32s3/include/idf_test/include/esp32s2/idf_performance_target.h index dc8a060f54b..cd037bb47d7 100644 --- a/tools/sdk/esp32s3/include/idf_test/include/esp32s2/idf_performance_target.h +++ b/tools/sdk/esp32s3/include/idf_test/include/esp32s2/idf_performance_target.h @@ -25,82 +25,3 @@ #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 32 #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 30 - -/* - * Flash Performance value - * 4 subsections: legacy, normal (new driver after v4.0), SPI1 (external but on SPI1), external (SPI2) - * These thresholds are set to about 70% of the average test data, under certain condition. - * Contact Espressif for details. - */ -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B -//Great variation, use the 70% of min value -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B 33300 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B -// legacy config is much faster. use the 70% of slower configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B (239*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB -// Weird data. Use 70% average of slower configs. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB (546*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB (1191*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE 19500 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B -//release config is much faster than other configs. Use 70% average of other configs -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B 46300 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B (249*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB (851*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB (11480*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE 40100 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B 30500 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B (183*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB (474*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB (1283*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE 44100 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B 47800 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B (252*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB -// write with large RAM buffer tests has lower performance value than normal performance tests -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB (398*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB (1204*1000) -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE 22100 -#endif diff --git a/tools/sdk/esp32s3/include/idf_test/include/esp32s3/idf_performance_target.h b/tools/sdk/esp32s3/include/idf_test/include/esp32s3/idf_performance_target.h index b744cda8fa0..d735bb27023 100644 --- a/tools/sdk/esp32s3/include/idf_test/include/esp32s3/idf_performance_target.h +++ b/tools/sdk/esp32s3/include/idf_test/include/esp32s3/idf_performance_target.h @@ -24,82 +24,6 @@ #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 32 #define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 30 -/* - * Flash Performance value - * 4 subsections: legacy, normal (new driver after v4.0), SPI1 (external but on SPI1), external (SPI2) - * These thresholds are set to about 70% of the average test data, under certain condition. - * Contact Espressif for details. - * - * Currently all performance data on S3 are set to 0 for now. Update to a proper value later. - */ -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_WR_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_RD_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_LEGACY_ERASE 0 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_WR_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_RD_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_ERASE 0 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_WR_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_RD_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_SPI1_ERASE 0 -#endif - -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_4B 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_WR_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_RD_2KB 0 -#endif -#ifndef IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE -//erase performance is highly depending on the chip vendor. Use 70% of the minimal value. -#define IDF_PERFORMANCE_MIN_FLASH_SPEED_BYTE_PER_SEC_EXT_ERASE 0 -#endif - // floating point instructions per divide and per sqrt (configured for worst-case with PSRAM workaround) #define IDF_PERFORMANCE_MAX_CYCLES_PER_DIV 70 #define IDF_PERFORMANCE_MAX_CYCLES_PER_SQRT 140 diff --git a/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_reg.h b/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_reg.h index e0f773962dc..e17afb79b5c 100644 --- a/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_reg.h +++ b/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_reg.h @@ -1,16 +1,8 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once #include "soc.h" @@ -25,10 +17,6 @@ extern "C" { #define DPORT_DATE_REG SYSTEM_DATE_REG -#define TRACEMEM_MUX_BLK0_NUM 19 -#define TRACEMEM_MUX_BLK1_NUM 20 -#define TRACEMEM_BLK_NUM2ADDR(_n_) (0x3FFB8000UL + 0x4000UL*((_n_)-4)) - #ifndef __ASSEMBLER__ #include "dport_access.h" #endif diff --git a/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/tracemem_config.h b/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/tracemem_config.h new file mode 100644 index 00000000000..55c9b907dd9 --- /dev/null +++ b/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/tracemem_config.h @@ -0,0 +1,39 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#define TRACEMEM_MUX_BLK0_NUM 22 +#define TRACEMEM_MUX_BLK1_NUM 23 + +#if (TRACEMEM_MUX_BLK0_NUM < 6) || (TRACEMEM_MUX_BLK0_NUM > 29) +#error Invalid TRAX block 0 num! +#endif +#if (TRACEMEM_MUX_BLK1_NUM < 6) || (TRACEMEM_MUX_BLK1_NUM > 29) +#error Invalid TRAX block 1 num! +#endif + +#if TRACEMEM_MUX_BLK0_NUM < 6 +#define TRACEMEM_BLK0_ADDR (0x3FC88000UL + 0x2000UL*(TRACEMEM_MUX_BLK0_NUM-2UL)) +#elif TRACEMEM_MUX_BLK0_NUM < 30 +#define TRACEMEM_BLK0_ADDR (0x3FC90000UL + 0x4000UL*(TRACEMEM_MUX_BLK0_NUM-6UL)) +#endif +#if TRACEMEM_MUX_BLK1_NUM < 6 +#define TRACEMEM_BLK1_ADDR (0x3FC88000UL + 0x2000UL*(TRACEMEM_MUX_BLK1_NUM-2UL)) +#elif TRACEMEM_MUX_BLK1_NUM < 30 +#define TRACEMEM_BLK1_ADDR (0x3FC90000UL + 0x4000UL*(TRACEMEM_MUX_BLK1_NUM-6UL)) +#endif + +#define TRACEMEM_MUX_BLK_ALLOC(_n_) (((_n_)-2UL)%4UL) +#define TRACEMEM_CORE0_MUX_BLK_BITS(_n_) (BIT(((_n_)-2UL)/4UL) | (TRACEMEM_MUX_BLK_ALLOC(_n_) << 14)) +#define TRACEMEM_CORE1_MUX_BLK_BITS(_n_) (BIT(7UL+(((_n_)-2UL)/4UL)) | (TRACEMEM_MUX_BLK_ALLOC(_n_) << 16)) + +#ifdef __cplusplus +} +#endif diff --git a/tools/sdk/esp32s3/ld/libbtbb.a b/tools/sdk/esp32s3/ld/libbtbb.a index b3bb0e2ba16..da9a4549320 100644 Binary files a/tools/sdk/esp32s3/ld/libbtbb.a and b/tools/sdk/esp32s3/ld/libbtbb.a differ diff --git a/tools/sdk/esp32s3/ld/libphy.a b/tools/sdk/esp32s3/ld/libphy.a index d6dcc9ec9c5..e5fc84515bb 100644 Binary files a/tools/sdk/esp32s3/ld/libphy.a and b/tools/sdk/esp32s3/ld/libphy.a differ diff --git a/tools/sdk/esp32s3/lib/libapp_trace.a b/tools/sdk/esp32s3/lib/libapp_trace.a index 668bed76d0d..12ad1d0ea6f 100644 Binary files a/tools/sdk/esp32s3/lib/libapp_trace.a and b/tools/sdk/esp32s3/lib/libapp_trace.a differ diff --git a/tools/sdk/esp32s3/lib/libapp_update.a b/tools/sdk/esp32s3/lib/libapp_update.a index 6038a8f1ff6..0a1e0ee5c68 100644 Binary files a/tools/sdk/esp32s3/lib/libapp_update.a and b/tools/sdk/esp32s3/lib/libapp_update.a differ diff --git a/tools/sdk/esp32s3/lib/libbootloader_support.a b/tools/sdk/esp32s3/lib/libbootloader_support.a index 6939b745d92..5c337e54aaa 100644 Binary files a/tools/sdk/esp32s3/lib/libbootloader_support.a and b/tools/sdk/esp32s3/lib/libbootloader_support.a differ diff --git a/tools/sdk/esp32s3/lib/libbt.a b/tools/sdk/esp32s3/lib/libbt.a index 0b66f16ca08..df892f1db19 100644 Binary files a/tools/sdk/esp32s3/lib/libbt.a and b/tools/sdk/esp32s3/lib/libbt.a differ diff --git a/tools/sdk/esp32s3/lib/libconsole.a b/tools/sdk/esp32s3/lib/libconsole.a index 3584dde29de..d83f66dee53 100644 Binary files a/tools/sdk/esp32s3/lib/libconsole.a and b/tools/sdk/esp32s3/lib/libconsole.a differ diff --git a/tools/sdk/esp32s3/lib/libdriver.a b/tools/sdk/esp32s3/lib/libdriver.a index 816c55f415f..a3b927fd414 100644 Binary files a/tools/sdk/esp32s3/lib/libdriver.a and b/tools/sdk/esp32s3/lib/libdriver.a differ diff --git a/tools/sdk/esp32s3/lib/libefuse.a b/tools/sdk/esp32s3/lib/libefuse.a index 9c949887dcd..5b70876eb4c 100644 Binary files a/tools/sdk/esp32s3/lib/libefuse.a and b/tools/sdk/esp32s3/lib/libefuse.a differ diff --git a/tools/sdk/esp32s3/lib/libesp-dsp.a b/tools/sdk/esp32s3/lib/libesp-dsp.a index 83e24b7dbc9..a36ac8ba910 100644 Binary files a/tools/sdk/esp32s3/lib/libesp-dsp.a and b/tools/sdk/esp32s3/lib/libesp-dsp.a differ diff --git a/tools/sdk/esp32s3/lib/libesp-tls.a b/tools/sdk/esp32s3/lib/libesp-tls.a index 6a786294143..735757eb171 100644 Binary files a/tools/sdk/esp32s3/lib/libesp-tls.a and b/tools/sdk/esp32s3/lib/libesp-tls.a differ diff --git a/tools/sdk/esp32s3/lib/libesp32-camera.a b/tools/sdk/esp32s3/lib/libesp32-camera.a index 1b9130d0f41..c368723e992 100644 Binary files a/tools/sdk/esp32s3/lib/libesp32-camera.a and b/tools/sdk/esp32s3/lib/libesp32-camera.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_adc_cal.a b/tools/sdk/esp32s3/lib/libesp_adc_cal.a index 8e87c204306..f0b832a1837 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_adc_cal.a and b/tools/sdk/esp32s3/lib/libesp_adc_cal.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_common.a b/tools/sdk/esp32s3/lib/libesp_common.a index 10362e282d5..d8c5b4acfc3 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_common.a and b/tools/sdk/esp32s3/lib/libesp_common.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_eth.a b/tools/sdk/esp32s3/lib/libesp_eth.a index c45e630f84e..ebeb3b8e2c9 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_eth.a and b/tools/sdk/esp32s3/lib/libesp_eth.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_event.a b/tools/sdk/esp32s3/lib/libesp_event.a index 8ad5c2be706..d979bbc839f 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_event.a and b/tools/sdk/esp32s3/lib/libesp_event.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_hid.a b/tools/sdk/esp32s3/lib/libesp_hid.a index b90f3e486df..3d2bad6bf0f 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_hid.a and b/tools/sdk/esp32s3/lib/libesp_hid.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_http_client.a b/tools/sdk/esp32s3/lib/libesp_http_client.a index 6ffb943d0c0..2418082c108 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_http_client.a and b/tools/sdk/esp32s3/lib/libesp_http_client.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_http_server.a b/tools/sdk/esp32s3/lib/libesp_http_server.a index d62c90658b1..401dd4fd051 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_http_server.a and b/tools/sdk/esp32s3/lib/libesp_http_server.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_https_ota.a b/tools/sdk/esp32s3/lib/libesp_https_ota.a index cdf63a26593..6da283cf766 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_https_ota.a and b/tools/sdk/esp32s3/lib/libesp_https_ota.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_https_server.a b/tools/sdk/esp32s3/lib/libesp_https_server.a index ec943be5caa..d9866114854 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_https_server.a and b/tools/sdk/esp32s3/lib/libesp_https_server.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_ipc.a b/tools/sdk/esp32s3/lib/libesp_ipc.a index 7c849f71b38..9626f5c4dbe 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_ipc.a and b/tools/sdk/esp32s3/lib/libesp_ipc.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_lcd.a b/tools/sdk/esp32s3/lib/libesp_lcd.a index eb7d27678b4..4a48a3b71e8 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_lcd.a and b/tools/sdk/esp32s3/lib/libesp_lcd.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_littlefs.a b/tools/sdk/esp32s3/lib/libesp_littlefs.a index c4538d35e0f..720f12734a1 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_littlefs.a and b/tools/sdk/esp32s3/lib/libesp_littlefs.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_local_ctrl.a b/tools/sdk/esp32s3/lib/libesp_local_ctrl.a index 80c48de50a1..85b2bf968f5 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_local_ctrl.a and b/tools/sdk/esp32s3/lib/libesp_local_ctrl.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_netif.a b/tools/sdk/esp32s3/lib/libesp_netif.a index 48add430dd4..999656d82ae 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_netif.a and b/tools/sdk/esp32s3/lib/libesp_netif.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_phy.a b/tools/sdk/esp32s3/lib/libesp_phy.a index ad4ea7c8f8d..5f1953406ff 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_phy.a and b/tools/sdk/esp32s3/lib/libesp_phy.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_pm.a b/tools/sdk/esp32s3/lib/libesp_pm.a index 391a4c72b4f..c2dabb91eed 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_pm.a and b/tools/sdk/esp32s3/lib/libesp_pm.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_serial_slave_link.a b/tools/sdk/esp32s3/lib/libesp_serial_slave_link.a index a2aa8ea0e71..e6aa1ecca7c 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_serial_slave_link.a and b/tools/sdk/esp32s3/lib/libesp_serial_slave_link.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_timer.a b/tools/sdk/esp32s3/lib/libesp_timer.a index f6d464e1d85..c9daa357c0b 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_timer.a and b/tools/sdk/esp32s3/lib/libesp_timer.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_websocket_client.a b/tools/sdk/esp32s3/lib/libesp_websocket_client.a index 1faba7ce0fe..2ae644e3554 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_websocket_client.a and b/tools/sdk/esp32s3/lib/libesp_websocket_client.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_wifi.a b/tools/sdk/esp32s3/lib/libesp_wifi.a index 4814f7a99b1..80d262a3bfe 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_wifi.a and b/tools/sdk/esp32s3/lib/libesp_wifi.a differ diff --git a/tools/sdk/esp32s3/lib/libespcoredump.a b/tools/sdk/esp32s3/lib/libespcoredump.a index 582f12f7aab..e998c101522 100644 Binary files a/tools/sdk/esp32s3/lib/libespcoredump.a and b/tools/sdk/esp32s3/lib/libespcoredump.a differ diff --git a/tools/sdk/esp32s3/lib/libfatfs.a b/tools/sdk/esp32s3/lib/libfatfs.a index e492146c6f6..b83caf421c7 100644 Binary files a/tools/sdk/esp32s3/lib/libfatfs.a and b/tools/sdk/esp32s3/lib/libfatfs.a differ diff --git a/tools/sdk/esp32s3/lib/libfreemodbus.a b/tools/sdk/esp32s3/lib/libfreemodbus.a index a6fd77f208c..32fc3d31dfd 100644 Binary files a/tools/sdk/esp32s3/lib/libfreemodbus.a and b/tools/sdk/esp32s3/lib/libfreemodbus.a differ diff --git a/tools/sdk/esp32s3/lib/libfreertos.a b/tools/sdk/esp32s3/lib/libfreertos.a index 740ad2f26c3..4e7a1aca01f 100644 Binary files a/tools/sdk/esp32s3/lib/libfreertos.a and b/tools/sdk/esp32s3/lib/libfreertos.a differ diff --git a/tools/sdk/esp32s3/lib/libhal.a b/tools/sdk/esp32s3/lib/libhal.a index c27decb860b..52d29a938a6 100644 Binary files a/tools/sdk/esp32s3/lib/libhal.a and b/tools/sdk/esp32s3/lib/libhal.a differ diff --git a/tools/sdk/esp32s3/lib/libheap.a b/tools/sdk/esp32s3/lib/libheap.a index 07aa45a0df0..8b53088d189 100644 Binary files a/tools/sdk/esp32s3/lib/libheap.a and b/tools/sdk/esp32s3/lib/libheap.a differ diff --git a/tools/sdk/esp32s3/lib/liblwip.a b/tools/sdk/esp32s3/lib/liblwip.a index 46dc0715c35..35f05cda0fb 100644 Binary files a/tools/sdk/esp32s3/lib/liblwip.a and b/tools/sdk/esp32s3/lib/liblwip.a differ diff --git a/tools/sdk/esp32s3/lib/libmbedcrypto.a b/tools/sdk/esp32s3/lib/libmbedcrypto.a index 176e8890170..c6b3c23fe60 100644 Binary files a/tools/sdk/esp32s3/lib/libmbedcrypto.a and b/tools/sdk/esp32s3/lib/libmbedcrypto.a differ diff --git a/tools/sdk/esp32s3/lib/libmdns.a b/tools/sdk/esp32s3/lib/libmdns.a index cbfa041f790..7fff4dfcbe3 100644 Binary files a/tools/sdk/esp32s3/lib/libmdns.a and b/tools/sdk/esp32s3/lib/libmdns.a differ diff --git a/tools/sdk/esp32s3/lib/libmqtt.a b/tools/sdk/esp32s3/lib/libmqtt.a index 9e4d16a3583..6e9dd1e59c0 100644 Binary files a/tools/sdk/esp32s3/lib/libmqtt.a and b/tools/sdk/esp32s3/lib/libmqtt.a differ diff --git a/tools/sdk/esp32s3/lib/libnvs_flash.a b/tools/sdk/esp32s3/lib/libnvs_flash.a index 8209b619e1d..b87ac68dfc6 100644 Binary files a/tools/sdk/esp32s3/lib/libnvs_flash.a and b/tools/sdk/esp32s3/lib/libnvs_flash.a differ diff --git a/tools/sdk/esp32s3/lib/libperfmon.a b/tools/sdk/esp32s3/lib/libperfmon.a index 732bc7e23b4..d03473727ff 100644 Binary files a/tools/sdk/esp32s3/lib/libperfmon.a and b/tools/sdk/esp32s3/lib/libperfmon.a differ diff --git a/tools/sdk/esp32s3/lib/libprotocomm.a b/tools/sdk/esp32s3/lib/libprotocomm.a index 505e179de84..4e884e3fa46 100644 Binary files a/tools/sdk/esp32s3/lib/libprotocomm.a and b/tools/sdk/esp32s3/lib/libprotocomm.a differ diff --git a/tools/sdk/esp32s3/lib/libpthread.a b/tools/sdk/esp32s3/lib/libpthread.a index bce15e28d06..e66a7e2013e 100644 Binary files a/tools/sdk/esp32s3/lib/libpthread.a and b/tools/sdk/esp32s3/lib/libpthread.a differ diff --git a/tools/sdk/esp32s3/lib/libsdmmc.a b/tools/sdk/esp32s3/lib/libsdmmc.a index 592017f60b7..e0dd99637dd 100644 Binary files a/tools/sdk/esp32s3/lib/libsdmmc.a and b/tools/sdk/esp32s3/lib/libsdmmc.a differ diff --git a/tools/sdk/esp32s3/lib/libspiffs.a b/tools/sdk/esp32s3/lib/libspiffs.a index 9aad1b40cfe..e35001ee4ea 100644 Binary files a/tools/sdk/esp32s3/lib/libspiffs.a and b/tools/sdk/esp32s3/lib/libspiffs.a differ diff --git a/tools/sdk/esp32s3/lib/libtcp_transport.a b/tools/sdk/esp32s3/lib/libtcp_transport.a index df8b7d231a6..0cde60dd404 100644 Binary files a/tools/sdk/esp32s3/lib/libtcp_transport.a and b/tools/sdk/esp32s3/lib/libtcp_transport.a differ diff --git a/tools/sdk/esp32s3/lib/libtcpip_adapter.a b/tools/sdk/esp32s3/lib/libtcpip_adapter.a index dbf6806ee65..64134cd0357 100644 Binary files a/tools/sdk/esp32s3/lib/libtcpip_adapter.a and b/tools/sdk/esp32s3/lib/libtcpip_adapter.a differ diff --git a/tools/sdk/esp32s3/lib/libulp.a b/tools/sdk/esp32s3/lib/libulp.a index 14c0dd18bac..1e71ce7d2ac 100644 Binary files a/tools/sdk/esp32s3/lib/libulp.a and b/tools/sdk/esp32s3/lib/libulp.a differ diff --git a/tools/sdk/esp32s3/lib/libusb.a b/tools/sdk/esp32s3/lib/libusb.a index 044f3f5607c..d21ec4d0332 100644 Binary files a/tools/sdk/esp32s3/lib/libusb.a and b/tools/sdk/esp32s3/lib/libusb.a differ diff --git a/tools/sdk/esp32s3/lib/libvfs.a b/tools/sdk/esp32s3/lib/libvfs.a index d24ad41141d..a8eb0e7c6e6 100644 Binary files a/tools/sdk/esp32s3/lib/libvfs.a and b/tools/sdk/esp32s3/lib/libvfs.a differ diff --git a/tools/sdk/esp32s3/lib/libwear_levelling.a b/tools/sdk/esp32s3/lib/libwear_levelling.a index cdb393482d5..d28cacdea5d 100644 Binary files a/tools/sdk/esp32s3/lib/libwear_levelling.a and b/tools/sdk/esp32s3/lib/libwear_levelling.a differ diff --git a/tools/sdk/esp32s3/lib/libwifi_provisioning.a b/tools/sdk/esp32s3/lib/libwifi_provisioning.a index 10f5ae27fe0..3dcab4ecacc 100644 Binary files a/tools/sdk/esp32s3/lib/libwifi_provisioning.a and b/tools/sdk/esp32s3/lib/libwifi_provisioning.a differ diff --git a/tools/sdk/esp32s3/lib/libwpa_supplicant.a b/tools/sdk/esp32s3/lib/libwpa_supplicant.a index a1896c42b07..1565217b523 100644 Binary files a/tools/sdk/esp32s3/lib/libwpa_supplicant.a and b/tools/sdk/esp32s3/lib/libwpa_supplicant.a differ diff --git a/tools/sdk/esp32s3/lib/opiram/libesp_hw_support.a b/tools/sdk/esp32s3/lib/opiram/libesp_hw_support.a new file mode 100644 index 00000000000..98669d458f2 Binary files /dev/null and b/tools/sdk/esp32s3/lib/opiram/libesp_hw_support.a differ diff --git a/tools/sdk/esp32s3/lib/opiram/libesp_system.a b/tools/sdk/esp32s3/lib/opiram/libesp_system.a new file mode 100644 index 00000000000..06c8bf93926 Binary files /dev/null and b/tools/sdk/esp32s3/lib/opiram/libesp_system.a differ diff --git a/tools/sdk/esp32s3/lib/opiram/libspi_flash.a b/tools/sdk/esp32s3/lib/opiram/libspi_flash.a new file mode 100644 index 00000000000..5cafedfc6f2 Binary files /dev/null and b/tools/sdk/esp32s3/lib/opiram/libspi_flash.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_hw_support.a b/tools/sdk/esp32s3/lib/spiram/libesp_hw_support.a similarity index 98% rename from tools/sdk/esp32s3/lib/libesp_hw_support.a rename to tools/sdk/esp32s3/lib/spiram/libesp_hw_support.a index 13d1fcbdae5..0852a79bef1 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_hw_support.a and b/tools/sdk/esp32s3/lib/spiram/libesp_hw_support.a differ diff --git a/tools/sdk/esp32s3/lib/libesp_system.a b/tools/sdk/esp32s3/lib/spiram/libesp_system.a similarity index 98% rename from tools/sdk/esp32s3/lib/libesp_system.a rename to tools/sdk/esp32s3/lib/spiram/libesp_system.a index 1a4b69ae087..eb11f20df7b 100644 Binary files a/tools/sdk/esp32s3/lib/libesp_system.a and b/tools/sdk/esp32s3/lib/spiram/libesp_system.a differ diff --git a/tools/sdk/esp32s3/lib/libspi_flash.a b/tools/sdk/esp32s3/lib/spiram/libspi_flash.a similarity index 99% rename from tools/sdk/esp32s3/lib/libspi_flash.a rename to tools/sdk/esp32s3/lib/spiram/libspi_flash.a index ee4b43caeab..31903772b6c 100644 Binary files a/tools/sdk/esp32s3/lib/libspi_flash.a and b/tools/sdk/esp32s3/lib/spiram/libspi_flash.a differ diff --git a/variants/adafruit_feather_esp32_v2/pins_arduino.h b/variants/adafruit_feather_esp32_v2/pins_arduino.h new file mode 100644 index 00000000000..2bfaf63b7aa --- /dev/null +++ b/variants/adafruit_feather_esp32_v2/pins_arduino.h @@ -0,0 +1,73 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define EXTERNAL_NUM_INTERRUPTS 16 +#define NUM_DIGITAL_PINS 40 +#define NUM_ANALOG_INPUTS 16 + +#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1) +#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) +#define digitalPinHasPWM(p) (p < 34) + +static const uint8_t LED_BUILTIN = 13; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN + +static const uint8_t TX = 7; +static const uint8_t RX = 8; +static const uint8_t TX1 = 7; +static const uint8_t RX1 = 8; + +static const uint8_t SDA = 22; +static const uint8_t SCL = 20; + +static const uint8_t SS = 33; +static const uint8_t MOSI = 19; +static const uint8_t MISO = 21; +static const uint8_t SCK = 5; + +// mapping to match other feathers and also in order +static const uint8_t A0 = 26; +static const uint8_t A1 = 25; +static const uint8_t A2 = 34; +static const uint8_t A3 = 39; +static const uint8_t A4 = 36; +static const uint8_t A5 = 4; +static const uint8_t A6 = 14; +static const uint8_t A7 = 32; +static const uint8_t A8 = 15; +static const uint8_t A9 = 33; +static const uint8_t A10 = 27; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; + +// vbat measure +static const uint8_t BATT_MONITOR = 35; +static const uint8_t A13 = 35; + +// internal switch +static const uint8_t BUTTON = 38; + +// Neopixel +static const uint8_t NEOPIXEL_PIN = 0; + +// Neopixel & I2C power +static const uint8_t NEOPIXEL_I2C_POWER = 2; + +static const uint8_t T0 = 4; +static const uint8_t T1 = 0; +static const uint8_t T2 = 2; +static const uint8_t T3 = 15; +static const uint8_t T4 = 13; +static const uint8_t T5 = 12; +static const uint8_t T6 = 14; +static const uint8_t T7 = 27; +static const uint8_t T8 = 33; +static const uint8_t T9 = 32; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +#endif /* Pins_Arduino_h */ diff --git a/variants/adafruit_feather_esp32_v2/variant.cpp b/variants/adafruit_feather_esp32_v2/variant.cpp new file mode 100644 index 00000000000..9345f6058a6 --- /dev/null +++ b/variants/adafruit_feather_esp32_v2/variant.cpp @@ -0,0 +1,40 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#include "esp32-hal-gpio.h" +#include "pins_arduino.h" + +extern "C" { + +// Initialize variant/board, called before setup() +void initVariant(void) +{ + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels & I2C + pinMode(NEOPIXEL_I2C_POWER, OUTPUT); + digitalWrite(NEOPIXEL_I2C_POWER, HIGH); +} + +} diff --git a/variants/adafruit_feather_esp32s2/pins_arduino.h b/variants/adafruit_feather_esp32s2/pins_arduino.h index 4e5e13de6e2..bde8d973d8f 100644 --- a/variants/adafruit_feather_esp32s2/pins_arduino.h +++ b/variants/adafruit_feather_esp32s2/pins_arduino.h @@ -26,6 +26,7 @@ #define NEOPIXEL_POWER 21 // power pin #define NEOPIXEL_POWER_ON HIGH // power pin state when on #define I2C_POWER 7 // I2C power pin +#define PIN_I2C_POWER 7 // I2C power pin static const uint8_t SDA = 3; static const uint8_t SCL = 4; diff --git a/variants/adafruit_qtpy_esp32/pins_arduino.h b/variants/adafruit_qtpy_esp32/pins_arduino.h index 72a5606c5d6..091554a08dd 100644 --- a/variants/adafruit_qtpy_esp32/pins_arduino.h +++ b/variants/adafruit_qtpy_esp32/pins_arduino.h @@ -11,14 +11,14 @@ #define digitalPinToInterrupt(p) (((p)<40)?(p):-1) #define digitalPinHasPWM(p) (p < 34) -static const uint8_t NEOPIXEL = 5; +static const uint8_t PIN_NEOPIXEL = 5; static const uint8_t NEOPIXEL_POWER = 8; static const uint8_t TX = 32; static const uint8_t RX = 7; -static const uint8_t TX1 = 32; -static const uint8_t RX1 = 7; +#define TX1 32 +#define RX1 7 static const uint8_t SDA = 25; static const uint8_t SCL = 33; @@ -43,7 +43,7 @@ static const uint8_t A8 = 14; static const uint8_t A9 = 12; static const uint8_t A10 = 13; -static const uint8_t SWITCH = 0; +static const uint8_t BUTTON = 0; static const uint8_t T0 = 4; static const uint8_t T3 = 15; diff --git a/variants/adafruit_qtpy_esp32/variant.cpp b/variants/adafruit_qtpy_esp32/variant.cpp new file mode 100644 index 00000000000..726ec8fa483 --- /dev/null +++ b/variants/adafruit_qtpy_esp32/variant.cpp @@ -0,0 +1,40 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#include "esp32-hal-gpio.h" +#include "pins_arduino.h" + +extern "C" { + +// Initialize variant/board, called before setup() +void initVariant(void) +{ + // This board has a power control pin, and we must set it to output and high + // in order to enable the NeoPixels. + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); +} + +} diff --git a/variants/adafruit_qtpy_esp32c3/pins_arduino.h b/variants/adafruit_qtpy_esp32c3/pins_arduino.h new file mode 100644 index 00000000000..61d1f49492b --- /dev/null +++ b/variants/adafruit_qtpy_esp32c3/pins_arduino.h @@ -0,0 +1,34 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define EXTERNAL_NUM_INTERRUPTS 22 +#define NUM_DIGITAL_PINS 22 +#define NUM_ANALOG_INPUTS 6 + +#define analogInputToDigitalPin(p) (((p) + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +#define EXTERNAL_NUM_INTERRUPTS 46 +#define NUM_DIGITAL_PINS 48 +#define NUM_ANALOG_INPUTS 20 + +#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1) +#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) +#define digitalPinHasPWM(p) (p < 46) + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 41; +static const uint8_t SCL = 40; + +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; + +static const uint8_t A8 = 9; +static const uint8_t A9 = 10; +static const uint8_t A10 = 11; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; +static const uint8_t A13 = 14; + +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +// Wire1 for ES7210 MIC ADC, ES8311 I2S DAC, ICM-42607-P IMU and TT21100 Touch Panel +#define I2C_SDA 8 +#define I2C_SCL 18 + +#define ES7210_ADDR 0x40 //MIC ADC +#define ES8311_ADDR 0x18 //I2S DAC +#define ICM42607P_ADDR 0x68 //IMU +#define TT21100_ADDR 0x24 //Touch Panel + +#define TFT_DC 4 +#define TFT_CS 5 +#define TFT_MOSI 6 +#define TFT_CLK 7 +#define TFT_MISO 0 +#define TFT_BL 45 +#define TFT_RST 48 + +#define I2S_LRCK 47 +#define I2S_MCLK 2 +#define I2S_SCLK 17 +#define I2S_SDIN 16 +#define I2S_DOUT 15 + +#define SDMMC_CLK 13 +#define SDMMC_CMD 11 +#define SDMMC_D0 14 +#define SDMMC_D1 12 +#define SDMMC_D2 10 +#define SDMMC_D3 9 + +#define PA_PIN 46 //Audio Amp Power +#define MUTE_PIN 1 //MUTE Button +#define TS_IRQ 3 //Touch Screen IRQ + +#endif /* Pins_Arduino_h */ diff --git a/variants/feather_esp32/pins_arduino.h b/variants/feather_esp32/pins_arduino.h index 743d53c3cb2..7cb6d8ff471 100644 --- a/variants/feather_esp32/pins_arduino.h +++ b/variants/feather_esp32/pins_arduino.h @@ -45,14 +45,13 @@ static const uint8_t A11 = 12; static const uint8_t A12 = 13; // vbat measure +static const uint8_t BATT_MONITOR = 35; static const uint8_t A13 = 35; //static const uint8_t Ax = 0; // not used/available //static const uint8_t Ax = 2; // not used/available static const uint8_t T0 = 4; -static const uint8_t T1 = 0; -static const uint8_t T2 = 2; static const uint8_t T3 = 15; static const uint8_t T4 = 13; static const uint8_t T5 = 12; diff --git a/variants/um_feathers3/pins_arduino.h b/variants/um_feathers3/pins_arduino.h new file mode 100644 index 00000000000..b0c8d473c5b --- /dev/null +++ b/variants/um_feathers3/pins_arduino.h @@ -0,0 +1,68 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303A +#define USB_PID 0x80D6 +#define USB_MANUFACTURER "Unexpected Maker" +#define USB_PRODUCT "FeatherS3" +#define USB_SERIAL "" + +#define EXTERNAL_NUM_INTERRUPTS 46 +#define NUM_DIGITAL_PINS 21 +#define NUM_ANALOG_INPUTS 13 + +#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1) +#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) +#define digitalPinHasPWM(p) (p < 46) + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 8; +static const uint8_t SCL = 9; + +static const uint8_t SS = 5; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; +static const uint8_t A9 = 10; +static const uint8_t A10 = 11; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; + +static const uint8_t T1 = 1; +static const uint8_t T3 = 3; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T14 = 14; + +static const uint8_t VBAT_SENSE = 2; +static const uint8_t VBUS_SENSE = 34; + +static const uint8_t RGB_DATA = 40; +static const uint8_t RGB_PWR = 39; +static const uint8_t LDO2 = 39; +static const uint8_t LED_BUILTIN = 13; +static const uint8_t LED = 13; + +#endif /* Pins_Arduino_h */ diff --git a/variants/um_pros3/pins_arduino.h b/variants/um_pros3/pins_arduino.h new file mode 100644 index 00000000000..dc8b76768b5 --- /dev/null +++ b/variants/um_pros3/pins_arduino.h @@ -0,0 +1,68 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303A +#define USB_PID 0x80D3 +#define USB_MANUFACTURER "Unexpected Maker" +#define USB_PRODUCT "ProS3" +#define USB_SERIAL "" + +#define EXTERNAL_NUM_INTERRUPTS 46 +#define NUM_DIGITAL_PINS 27 +#define NUM_ANALOG_INPUTS 14 + +#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1) +#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) +#define digitalPinHasPWM(p) (p < 46) + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 8; +static const uint8_t SCL = 9; + +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; +static const uint8_t A13 = 14; +static const uint8_t A14 = 15; +static const uint8_t A15 = 16; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +static const uint8_t VBAT_SENSE = 10; +static const uint8_t VBUS_SENSE = 33; + +static const uint8_t RGB_DATA = 18; +static const uint8_t RGB_PWR = 17; +static const uint8_t LDO2 = 17; + +#endif /* Pins_Arduino_h */ diff --git a/variants/um_tinys3/pins_arduino.h b/variants/um_tinys3/pins_arduino.h new file mode 100644 index 00000000000..780482cf5a0 --- /dev/null +++ b/variants/um_tinys3/pins_arduino.h @@ -0,0 +1,59 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303A +#define USB_PID 0x80D0 +#define USB_MANUFACTURER "Unexpected Maker" +#define USB_PRODUCT "TinyS3" +#define USB_SERIAL "" + +#define EXTERNAL_NUM_INTERRUPTS 46 +#define NUM_DIGITAL_PINS 17 +#define NUM_ANALOG_INPUTS 9 + +#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1) +#define digitalPinToInterrupt(p) (((p)<48)?(p):-1) +#define digitalPinHasPWM(p) (p < 46) + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 8; +static const uint8_t SCL = 9; + +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; + +static const uint8_t VBAT_SENSE = 10; +static const uint8_t VBUS_SENSE = 33; + +static const uint8_t RGB_DATA = 18; +static const uint8_t RGB_PWR = 17; + +#endif /* Pins_Arduino_h */