diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index be5a05a1c..ade7e7fa5 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -1,40 +1,46 @@ -name: Cron Build +name: Cron Deploy -on: +on: schedule: # ┌───────────── minute (0 - 59) # │ ┌───────────── hour (0 - 23) # │ │ ┌───────────── day of the month (1 - 31) # │ │ │ ┌───────────── month (1 - 12 or JAN-DEC) # │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT) -# │ │ │ │ │ +# │ │ │ │ │ # │ │ │ │ │ # │ │ │ │ │ # * * * * * - cron: '0 */6 * * *' + workflow_dispatch: # For manually rebuilding the libraries -jobs: +defaults: run: + shell: bash + +jobs: + build-libs: name: Build with IDF ${{ matrix.idf_branch }} - runs-on: ubuntu-latest - + if: github.repository_owner == 'espressif' + uses: ./.github/workflows/cron_build.yml + with: + idf_branch: ${{ matrix.idf_branch }} + lib_builder_branch: ${{ matrix.lib_builder_branch }} + targets: ${{ matrix.targets }} + secrets: inherit strategy: + fail-fast: false matrix: - idf_branch: [release/v3.3] - #idf_branch: [release/v3.3, release/v4.0] - steps: - - uses: actions/checkout@v1 - - name: Install dependencies - run: sudo apt-get install git wget curl libssl-dev libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-click python-cryptography python-future python-pyparsing python-pyelftools cmake ninja-build ccache - - name: Install Python Wheel - run: pip install wheel - - name: Build - env: - GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }} - IDF_BRANCH: ${{ matrix.idf_branch }} - run: bash ./tools/cron.sh - - name: Upload archive - uses: actions/upload-artifact@v1 - with: - name: artifacts - path: dist + include: + # - idf_branch: "release/v5.1" + # lib_builder_branch: "release/v5.1" + # targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2" + # - idf_branch: "release/v5.3" + # lib_builder_branch: "release/v5.3" + # targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4" + - idf_branch: "release/v5.4" + lib_builder_branch: "master" + targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4" + - idf_branch: "release/v5.5" + lib_builder_branch: "release/v5.5" + targets: "esp32,esp32s2,esp32s3,esp32c3,esp32c6,esp32h2,esp32p4,esp32c5" diff --git a/.github/workflows/cron_build.yml b/.github/workflows/cron_build.yml new file mode 100644 index 000000000..fd9634928 --- /dev/null +++ b/.github/workflows/cron_build.yml @@ -0,0 +1,163 @@ +name: Cron Build Matrix + +on: + workflow_call: + inputs: + idf_branch: + type: string + required: true + description: 'IDF branch to build' + lib_builder_branch: + type: string + required: true + description: 'Branch of the lib-builder to use' + targets: + type: string + required: true + description: 'Targets to build' + +env: + IDF_BRANCH: ${{ inputs.idf_branch }} + +jobs: + check-if-needed: + name: Check if deploy is needed for ${{ inputs.idf_branch }} + runs-on: ubuntu-latest + outputs: + idf_commit: ${{ steps.check.outputs.idf_commit }} + ar_branch: ${{ steps.check.outputs.ar_branch }} + ar_new_commit_message: ${{ steps.check.outputs.ar_new_commit_message }} + ar_new_branch_name: ${{ steps.check.outputs.ar_new_branch_name }} + ar_new_pr_title: ${{ steps.check.outputs.ar_new_pr_title }} + ar_has_commit: ${{ steps.check.outputs.ar_has_commit }} + ar_has_branch: ${{ steps.check.outputs.ar_has_branch }} + ar_has_pr: ${{ steps.check.outputs.ar_has_pr }} + libs_release_tag: ${{ steps.check.outputs.libs_release_tag }} + libs_version: ${{ steps.check.outputs.libs_version }} + libs_release_id: ${{ steps.check.outputs.libs_release_id }} + libs_has_release: ${{ steps.check.outputs.libs_has_release }} + libs_asset_id: ${{ steps.check.outputs.libs_asset_id }} + libs_has_asset: ${{ steps.check.outputs.libs_has_asset }} + deploy_needed: ${{ steps.check.outputs.deploy_needed }} + targets_list: ${{ steps.check.outputs.targets_list }} + steps: + - name: Checkout ${{ inputs.lib_builder_branch }} + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ inputs.lib_builder_branch }} + + - name: Check deploy and generate variables + id: check + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + source ./tools/check-deploy-needed.sh + targets_list=$(echo "${{ inputs.targets }}" | sed 's/ *, */,/g' | sed 's/^/["/' | sed 's/$/"]/' | sed 's/,/","/g') + echo "Targets list: $targets_list" + echo "targets_list=$targets_list" >> $GITHUB_OUTPUT + + build-libs: + name: Build for ${{ matrix.target }} (${{ inputs.idf_branch }}) + runs-on: ubuntu-latest + if: needs.check-if-needed.outputs.deploy_needed == '1' + needs: check-if-needed + strategy: + fail-fast: false + matrix: + target: ${{ fromJson(needs.check-if-needed.outputs.targets_list) }} + steps: + - name: Checkout ${{ inputs.lib_builder_branch }} + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ inputs.lib_builder_branch }} + + - name: Install dependencies + run: bash ./tools/prepare-ci.sh + + - name: Build + env: + GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN || secrets.GITHUB_TOKEN }} + GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }} + GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }} + TARGET: ${{ matrix.target }} + run: | + bash ./tools/cron.sh + + - name: Replace invalid characters in the artifact name + run: | + branch=${{ inputs.idf_branch }} + echo "libs_branch=${branch//\//_}" >> $GITHUB_ENV + + - name: Upload build + if: failure() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: build-${{ env.libs_branch }}-${{ matrix.target }} + path: build + + - name: Upload library files + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: libs-${{ env.libs_branch }}-${{ matrix.target }} + path: dist + + combine-artifacts: + name: Combine artifacts and push changes for IDF ${{ inputs.idf_branch }} + runs-on: ubuntu-latest + needs: [check-if-needed, build-libs] + if: needs.check-if-needed.outputs.deploy_needed == '1' + steps: + - name: Checkout ${{ inputs.lib_builder_branch }} + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ inputs.lib_builder_branch }} + + - name: Replace invalid characters in the artifact name + run: | + branch=${{ inputs.idf_branch }} + echo "libs_branch=${branch//\//_}" >> $GITHUB_ENV + + - name: Download artifacts + uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1 + with: + path: dist + pattern: libs-${{ env.libs_branch }}-* + merge-multiple: true + + - name: Combine artifacts + run: bash ./tools/combine-artifacts.sh + + - name: Upload full esp32-arduino-libs archive + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: esp32-arduino-libs-${{ env.libs_branch }} + path: dist/esp32-arduino-libs.zip + compression-level: 0 + + - name: Push changes + env: + GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }} + GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }} + GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }} + IDF_COMMIT: ${{ needs.check-if-needed.outputs.idf_commit }} + AR_BRANCH: ${{ needs.check-if-needed.outputs.ar_branch }} + AR_NEW_COMMIT_MESSAGE: ${{ needs.check-if-needed.outputs.ar_new_commit_message }} + AR_NEW_BRANCH_NAME: ${{ needs.check-if-needed.outputs.ar_new_branch_name }} + AR_NEW_PR_TITLE: ${{ needs.check-if-needed.outputs.ar_new_pr_title }} + AR_HAS_COMMIT: ${{ needs.check-if-needed.outputs.ar_has_commit }} + AR_HAS_BRANCH: ${{ needs.check-if-needed.outputs.ar_has_branch }} + AR_HAS_PR: ${{ needs.check-if-needed.outputs.ar_has_pr }} + LIBS_RELEASE_TAG: ${{ needs.check-if-needed.outputs.libs_release_tag }} + LIBS_VERSION: ${{ needs.check-if-needed.outputs.libs_version }} + LIBS_RELEASE_ID: ${{ needs.check-if-needed.outputs.libs_release_id }} + LIBS_HAS_RELEASE: ${{ needs.check-if-needed.outputs.libs_has_release }} + LIBS_ASSET_ID: ${{ needs.check-if-needed.outputs.libs_asset_id }} + LIBS_HAS_ASSET: ${{ needs.check-if-needed.outputs.libs_has_asset }} + run: | + bash ./tools/push-to-arduino.sh + + - name: Upload package_esp32_index.template.json + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: package-esp32-index-json-${{ env.libs_branch }} + path: out/package_esp32_index.template.json diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..c89352150 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,102 @@ +name: Build and push Docker image + +on: + push: + branches: + - 'master' + - 'release/*' + tags: + - 'v*.*' + pull_request: + paths: + - ".github/workflows/docker.yml" + - "tools/config_editor/requirements.txt" + - "tools/docker/Dockerfile" + - "tools/docker/entrypoint.sh" + +env: + # Build the image for amd64 and arm64 + BUILD_PLATFORMS: linux/amd64,linux/arm64 + DOCKERHUB_REPO: ${{ github.repository_owner }}/esp32-arduino-lib-builder + +jobs: + docker: + # Disable the job in forks + if: ${{ github.event_name == 'pull_request' || github.repository_owner == 'espressif' }} + name: Build docker image and push if needed + runs-on: ubuntu-latest + steps: + # Depending on the branch/tag, set CLONE_BRANCH_OR_TAG variable (used in the Dockerfile + # as a build arg) and TAG_NAME (used when tagging the image). + # + # The following 3 steps cover the alternatives (tag, release branch, master branch): + - name: Set variables (tags) + if: ${{ github.ref_type == 'tag' }} + run: | + echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV + echo "TAG_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV + echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV + + - name: Set variables (release branches) + if: ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'release/') }} + run: | + echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV + echo "TAG_NAME=release-${GITHUB_REF_NAME##release/}" >> $GITHUB_ENV + echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV + + - name: Set variables (main branch) + if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }} + run: | + echo "CLONE_BRANCH_OR_TAG=master" >> $GITHUB_ENV + echo "TAG_NAME=latest" >> $GITHUB_ENV + echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV + + - name: Set variables (pull requests) + if: ${{ github.event_name == 'pull_request' }} + run: | + echo "CLONE_BRANCH_OR_TAG=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV + echo "TAG_NAME=PR_${{ github.event.number }}" >> $GITHUB_ENV + echo "URL=${{ github.server_url }}/${{ github.event.pull_request.head.repo.full_name }}.git" >> $GITHUB_ENV + + # Display the variables set above, just in case. + - name: Check variables + run: | + echo "CLONE_BRANCH_OR_TAG: $CLONE_BRANCH_OR_TAG" + echo "TAG_NAME: $TAG_NAME" + echo "URL: $URL" + + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Login to Docker Hub + if: ${{ github.event_name == 'push' }} + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up QEMU for multiarch builds + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 + + - name: Build and push + uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0 + with: + context: tools/docker + push: ${{ github.event_name == 'push' }} + tags: ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }} + platforms: ${{ env.BUILD_PLATFORMS }} + build-args: | + LIBBUILDER_CLONE_URL=${{ env.URL }} + LIBBUILDER_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }} + + - name: Update Docker Hub repository description (master branch) + if: ${{ github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master' }} + uses: peter-evans/dockerhub-description@e98e4d1628a5f3be2be7c231e50981aee98723ae # v4.0.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: ${{ env.DOCKERHUB_REPO }} + readme-filepath: ./tools/docker/README.md diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 371dc30db..756ab0991 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -5,22 +5,79 @@ on: branches: - master pull_request: + paths: + - "**" + - "!**.md" + - "!.github/workflows/cron_build.yml" + - "!.github/workflows/cron.yml" + - "!.github/workflows/docker.yml" + - "!.github/workflows/repository_dispatch.yml" + - "!tools/config_editor/**" + - "!tools/docker/**" -jobs: +concurrency: + group: esp-idf-libs-${{github.event.pull_request.number || github.ref}} + cancel-in-progress: true +jobs: build-libs: - name: Build Arduino Libs + name: Build Libs for ${{ matrix.target }} runs-on: ubuntu-latest + strategy: + matrix: + target: [esp32, esp32s2, esp32s3, esp32c2, esp32c3, esp32c6, esp32h2, esp32p4] + fail-fast: false steps: - - uses: actions/checkout@v1 + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Install dependencies - run: sudo apt-get install git wget curl libssl-dev libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-click python-cryptography python-future python-pyparsing python-pyelftools cmake ninja-build ccache - - name: Install Python Wheel - run: pip install wheel - - name: Build Arduino Libs - run: bash ./build.sh + run: bash ./tools/prepare-ci.sh + + - name: Build Libs for ${{ matrix.target }} + run: bash ./build.sh -e -t ${{ matrix.target }} + + - name: Upload build + if: failure() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: build-${{ matrix.target }} + path: build + - name: Upload archive - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: - name: artifacts + name: artifacts-${{ matrix.target }} path: dist + + combine-artifacts: + name: Combine artifacts + needs: build-libs + runs-on: ubuntu-latest + steps: + - name: Download artifacts + uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1 + with: + path: dist + pattern: artifacts-* + merge-multiple: true + + - shell: bash + run: | + mkdir -p out + find dist -name 'arduino-esp32-libs-esp*.tar.gz' -exec tar zxvf {} -C out \; + cd out/tools/esp32-arduino-libs && tar zcf ../../../dist/esp32-arduino-libs.tar.gz * && cd ../../.. + cp out/package_esp32_index.template.json dist/package_esp32_index.template.json + + - name: Upload full esp32-arduino-libs archive + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: esp32-arduino-libs + path: dist/esp32-arduino-libs.tar.gz + + - name: Upload package_esp32_index.template.json + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: package-esp32-index-json + path: dist/package_esp32_index.template.json + diff --git a/.github/workflows/repository_dispatch.yml b/.github/workflows/repository_dispatch.yml index 5a8b072cb..62837976b 100644 --- a/.github/workflows/repository_dispatch.yml +++ b/.github/workflows/repository_dispatch.yml @@ -7,17 +7,30 @@ jobs: name: Dispatch Event runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + - name: Install dependencies - run: sudo apt-get install git wget curl libssl-dev libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-click python-cryptography python-future python-pyparsing python-pyelftools cmake ninja-build ccache - - name: Install Python Wheel - run: pip install wheel + run: bash ./tools/prepare-ci.sh + - name: Handle Event env: GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }} + GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }} + GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }} run: bash ./tools/repository_dispatch.sh + + - name: Upload build + if: failure() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: build + path: build + - name: Upload archive - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: artifacts path: dist diff --git a/.gitignore b/.gitignore index 1b7d85e82..b0749543f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,24 @@ -sdkconfig.old .DS_Store +.vscode +managed_components/ components/arduino/ -components/esp-face/ +components/esp-dl/ +components/esp-sr/ components/esp32-camera/ +components/esp_littlefs/ +components/esp-rainmaker/ +components/espressif__esp-dsp/ +components/esp-insights/ +components/arduino_tinyusb/tinyusb/ +components/tflite-micro/ esp-idf/ out/ build/ -xtensa-esp32-elf/ dist/ +env.sh +sdkconfig +sdkconfig.old +version.txt +dependencies.lock +managed_components/ +target/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1afdd10ad..000000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -sudo: false -language: python -os: - - linux - -git: - depth: false - -addons: - apt: - packages: - - git - - wget - - curl - - libssl-dev - - libncurses-dev - - flex - - bison - - gperf - - python - - python-pip - - python-setuptools - - python-serial - - python-click - - python-cryptography - - python-future - - python-pyparsing - - python-pyelftools - - cmake - - ninja-build - - ccache - -stages: - - build - -jobs: - include: - - - name: "Build Arduino Libs" - if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) - stage: build - script: bash $TRAVIS_BUILD_DIR/build.sh diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..b79d85c0a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,42 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(arduino-lib-builder) + +idf_build_get_property(elf EXECUTABLE GENERATOR_EXPRESSION) + +add_custom_command( + OUTPUT "idf_libs" + COMMAND ${CMAKE_SOURCE_DIR}/tools/copy-libs.sh ${IDF_TARGET} "${CONFIG_LIB_BUILDER_FLASHMODE}" "${CONFIG_SPIRAM_MODE_OCT}" "${CONFIG_IDF_TARGET_ARCH_XTENSA}" + DEPENDS ${elf} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + VERBATIM +) +add_custom_target(idf-libs DEPENDS "idf_libs") + +add_custom_command( + OUTPUT "copy_bootloader" + COMMAND ${CMAKE_SOURCE_DIR}/tools/copy-bootloader.sh ${IDF_TARGET} "${CONFIG_LIB_BUILDER_FLASHMODE}" "${CONFIG_LIB_BUILDER_FLASHFREQ}" + DEPENDS bootloader + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + VERBATIM +) +add_custom_target(copy-bootloader DEPENDS "copy_bootloader") + +add_custom_command( + OUTPUT "mem_variant" + COMMAND ${CMAKE_SOURCE_DIR}/tools/copy-mem-variant.sh ${IDF_TARGET} "${CONFIG_LIB_BUILDER_FLASHMODE}" "${CONFIG_SPIRAM_MODE_OCT}" + DEPENDS ${elf} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + VERBATIM +) +add_custom_target(mem-variant DEPENDS "mem_variant") + +idf_build_set_property(COMPILE_DEFINITIONS "-DESP32_ARDUINO_LIB_BUILDER" APPEND) + +################## +### ESP Matter ### +################## +idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++2a;-DCHIP_HAVE_CONFIG_H" APPEND) diff --git a/Makefile b/Makefile deleted file mode 100644 index 56441d16c..000000000 --- a/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -PROJECT_NAME := esp32-arduino-lib-builder - -EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/components/esp-face/lib -EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/components/esp-face/image_util -EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/components/esp-face/face_detection -EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/components/esp-face/face_recognition - -include $(IDF_PATH)/make/project.mk - -IDF_INCLUDES = $(filter $(IDF_PATH)/components/%, $(COMPONENT_INCLUDES)) -IDF_OUT = $(patsubst $(IDF_PATH)/components/%,%,$(IDF_INCLUDES)) - -PROJ_INCLUDES = $(filter-out $(PROJECT_PATH)/components/arduino/%,$(filter $(PROJECT_PATH)/components/%, $(COMPONENT_INCLUDES))) -PROJ_OUT = $(patsubst $(PROJECT_PATH)/components/%,%,$(PROJ_INCLUDES)) - -idf-libs: all - @$(PROJECT_PATH)/tools/prepare-libs.sh $(IDF_OUT) $(PROJ_OUT) diff --git a/README.md b/README.md index b14b38f3c..16452f7e1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ESP32 Arduino Lib Builder [![Build Status](https://travis-ci.org/espressif/esp32-arduino-lib-builder.svg?branch=master)](https://travis-ci.org/espressif/esp32-arduino-lib-builder) +# ESP32 Arduino Lib Builder [![ESP32 Arduino Libs CI](https://github.com/espressif/esp32-arduino-lib-builder/actions/workflows/push.yml/badge.svg)](https://github.com/espressif/esp32-arduino-lib-builder/actions/workflows/push.yml) This repository contains the scripts that produce the libraries included with esp32-arduino. @@ -6,9 +6,39 @@ Tested on Ubuntu (32 and 64 bit), Raspberry Pi and MacOS. ### Build on Ubuntu and Raspberry Pi ```bash -sudo apt-get install git wget curl libssl-dev libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-click python-cryptography python-future python-pyparsing python-pyelftools cmake ninja-build ccache +sudo apt-get install git wget curl libssl-dev libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-click python-cryptography python-future python-pyparsing python-pyelftools cmake ninja-build ccache jq sudo pip install --upgrade pip git clone https://github.com/espressif/esp32-arduino-lib-builder cd esp32-arduino-lib-builder ./build.sh ``` + +### Using the User Interface + +You can more easily build the libraries using the user interface found in the `tools/config_editor/` folder. +It is a Python script that allows you to select and edit the options for the libraries you want to build. +The script has mouse support and can also be pre-configured using the same command line arguments as the `build.sh` script. +For more information and troubleshooting, please refer to the [UI README](tools/config_editor/README.md). + +To use it, follow these steps: + +1. Make sure you have the following prerequisites: + - Python 3.9 or later + - All the dependencies listed in the previous section + +2. Install the required UI packages using `pip install -r tools/config_editor/requirements.txt`. + +3. Execute the script `tools/config_editor/app.py` from any folder. It will automatically detect the path to the root of the repository. + +4. Configure the compilation and ESP-IDF options as desired. + +5. Click on the "Compile Static Libraries" button to start the compilation process. + +6. The script will show the compilation output in a new screen. Note that the compilation process can take many hours, depending on the number of libraries selected and the options chosen. + +7. If the compilation is successful and the option to copy the libraries to the Arduino Core folder is enabled, it will already be available for use in the Arduino IDE. Otherwise, you can find the compiled libraries in the `esp32-arduino-libs` folder alongside this repository. + - Note that the copy operation doesn't currently support the core downloaded from the Arduino IDE Boards Manager, only the manual installation from the [`arduino-esp32`](https://github.com/espressif/arduino-esp32) repository. + +### Documentation + +For more information about how to use the Library builder, please refer to this [Documentation page](https://docs.espressif.com/projects/arduino-esp32/en/latest/lib_builder.html?highlight=lib%20builder) diff --git a/build.sh b/build.sh index aea6f7b23..50e376c2a 100755 --- a/build.sh +++ b/build.sh @@ -1,61 +1,338 @@ #!/bin/bash -if ! [ -x "$(command -v python)" ]; then - echo "ERROR: python is not installed! Please install python first." - exit 1 +if ! [ -x "$(command -v python3)" ]; then + echo "ERROR: python is not installed or not in PATH! Please install python first." + exit 1 fi if ! [ -x "$(command -v git)" ]; then - echo "ERROR: git is not installed! Please install git first." - exit 1 + echo "ERROR: git is not installed or not in PATH! Please install git first." + exit 1 fi -if ! [ -x "$(command -v make)" ]; then - echo "ERROR: Make is not installed! Please install Make first." - exit 1 +if ! [ -x "$(command -v ninja)" ]; then + echo "ERROR: ninja is not installed or not in PATH! Please install ninja first." + exit 1 fi -if ! [ -x "$(command -v flex)" ]; then - echo "ERROR: flex is not installed! Please install flex first." - exit 1 -fi +# Fixes building some components. See https://github.com/espressif/arduino-esp32/issues/10167 +export IDF_COMPONENT_OVERWRITE_MANAGED_COMPONENTS=1 + +CCACHE_ENABLE=1 -if ! [ -x "$(command -v bison)" ]; then - echo "ERROR: bison is not installed! Please install bison first." - exit 1 +TARGET="all" +BUILD_TYPE="all" +BUILD_DEBUG="default" +SKIP_ENV=0 +COPY_OUT=0 +ARCHIVE_OUT=0 +if [ -z $DEPLOY_OUT ]; then + DEPLOY_OUT=0 fi -if ! [ -x "$(command -v gperf)" ]; then - echo "ERROR: gperf is not installed! Please install gperf first." - exit 1 +function print_help() { + echo "Usage: build.sh [-s] [-n] [-A ] [-I ] [-D ] [-i ] [-c ] [-t ] [-b ] [config ...]" + echo " -s Skip installing/updating of ESP-IDF and all components" + echo " -n Disable ccache" + echo " -A Set which branch of arduino-esp32 to be used for compilation" + echo " -I Set which branch of ESP-IDF to be used for compilation" + echo " -i Set which commit of ESP-IDF to be used for compilation" + echo " -e Archive the build to dist" + echo " -d Deploy the build to github arduino-esp32" + echo " -D Debug level to be set to ESP-IDF. One of default,none,error,warning,info,debug or verbose" + echo " -c Set the arduino-esp32 folder to copy the result to. ex. '$HOME/Arduino/hardware/espressif/esp32'" + echo " -t Set the build target(chip) ex. 'esp32s3' or select multiple targets(chips) by separating them with comma ex. 'esp32,esp32s3,esp32c3'" + echo " -b Set the build type. ex. 'build' to build the project and prepare for uploading to a board" + echo " ... Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash@80MHz. Requires -b" + exit 1 +} + +while getopts ":A:I:i:c:t:b:D:sde" opt; do + case ${opt} in + s ) + SKIP_ENV=1 + ;; + n ) + CCACHE_ENABLE=0 + ;; + d ) + DEPLOY_OUT=1 + ;; + e ) + ARCHIVE_OUT=1 + ;; + c ) + export ESP32_ARDUINO="$OPTARG" + COPY_OUT=1 + ;; + A ) + export AR_BRANCH="$OPTARG" + ;; + I ) + export IDF_BRANCH="$OPTARG" + ;; + i ) + export IDF_COMMIT="$OPTARG" + ;; + D ) + BUILD_DEBUG="$OPTARG" + ;; + t ) + IFS=',' read -ra TARGET <<< "$OPTARG" + ;; + b ) + b=$OPTARG + if [ "$b" != "build" ] && + [ "$b" != "menuconfig" ] && + [ "$b" != "reconfigure" ] && + [ "$b" != "idf-libs" ] && + [ "$b" != "copy-bootloader" ] && + [ "$b" != "mem-variant" ]; then + print_help + fi + BUILD_TYPE="$b" + ;; + \? ) + echo "Invalid option: -$OPTARG" 1>&2 + print_help + ;; + : ) + echo "Invalid option: -$OPTARG requires an argument" 1>&2 + print_help + ;; + esac +done +shift $((OPTIND -1)) +CONFIGS=$@ + +export IDF_CCACHE_ENABLE=$CCACHE_ENABLE + +# Output the TARGET array +echo "TARGET(s): ${TARGET[@]}" + +mkdir -p dist + +if [ $SKIP_ENV -eq 0 ]; then + echo "* Installing/Updating ESP-IDF and all components..." + # update components from git + ./tools/update-components.sh + if [ $? -ne 0 ]; then exit 1; fi + + # install arduino component + ./tools/install-arduino.sh + if [ $? -ne 0 ]; then exit 1; fi + + # install esp-idf + source ./tools/install-esp-idf.sh + if [ $? -ne 0 ]; then exit 1; fi +else + # $IDF_PATH/install.sh + # source $IDF_PATH/export.sh + source ./tools/config.sh fi -if ! [ -x "$(command -v stat)" ]; then - echo "ERROR: stat is not installed! Please install stat first." - exit 1 +if [ "$BUILD_TYPE" != "all" ]; then + if [ "$TARGET" = "all" ]; then + echo "ERROR: You need to specify target for non-default builds" + print_help + fi + + # Target Features Configs + for target_json in `jq -c '.targets[]' configs/builds.json`; do + target=$(echo "$target_json" | jq -c '.target' | tr -d '"') + + # Check if $target is in the $TARGET array + target_in_array=false + for item in "${TARGET[@]}"; do + if [ "$item" = "$target" ]; then + target_in_array=true + break + fi + done + + if [ "$target_in_array" = false ]; then + # Skip building for targets that are not in the $TARGET array + continue + fi + + configs="configs/defconfig.common;configs/defconfig.$target;configs/defconfig.debug_$BUILD_DEBUG" + for defconf in `echo "$target_json" | jq -c '.features[]' | tr -d '"'`; do + configs="$configs;configs/defconfig.$defconf" + done + + echo "* Building for $target" + + # Configs From Arguments + for conf in $CONFIGS; do + configs="$configs;configs/defconfig.$conf" + done + + echo "idf.py -DIDF_TARGET=\"$target\" -DSDKCONFIG_DEFAULTS=\"$configs\" $BUILD_TYPE" + rm -rf build sdkconfig + idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$configs" $BUILD_TYPE + if [ $? -ne 0 ]; then exit 1; fi + done + exit 0 fi -mkdir -p dist +rm -rf build sdkconfig out +mkdir -p "$AR_TOOLS/esp32-arduino-libs" -# update components from git -./tools/update-components.sh -if [ $? -ne 0 ]; then exit 1; fi +#targets_count=`jq -c '.targets[] | length' configs/builds.json` +for target_json in `jq -c '.targets[]' configs/builds.json`; do + target=$(echo "$target_json" | jq -c '.target' | tr -d '"') + target_skip=$(echo "$target_json" | jq -c '.skip // 0') -# install esp-idf and gcc toolchain -source ./tools/install-esp-idf.sh -if [ $? -ne 0 ]; then exit 1; fi + # Check if $target is in the $TARGET array if not "all" + if [ "$TARGET" != "all" ]; then + target_in_array=false + for item in "${TARGET[@]}"; do + if [ "$item" = "$target" ]; then + target_in_array=true + break + fi + done -# build and prepare libs -./tools/build-libs.sh -if [ $? -ne 0 ]; then exit 1; fi + # If $target is not in the $TARGET array, skip processing + if [ "$target_in_array" = false ]; then + echo "* Skipping Target: $target" + continue + fi + fi -# bootloader -./tools/build-bootloaders.sh -if [ $? -ne 0 ]; then exit 1; fi + # Skip chips that should not be a part of the final libs + # WARNING!!! this logic needs to be updated when cron builds are split into jobs + if [ "$TARGET" = "all" ] && [ $target_skip -eq 1 ]; then + echo "* Skipping Target: $target" + continue + fi -# archive the build -./tools/archive-build.sh -if [ $? -ne 0 ]; then exit 1; fi + echo "* Target: $target" -# POST Build -#./tools/copy-to-arduino.sh + # Build Main Configs List + main_configs="configs/defconfig.common;configs/defconfig.$target;configs/defconfig.debug_$BUILD_DEBUG" + for defconf in `echo "$target_json" | jq -c '.features[]' | tr -d '"'`; do + main_configs="$main_configs;configs/defconfig.$defconf" + done + + # Build IDF Libs + idf_libs_configs="$main_configs" + for defconf in `echo "$target_json" | jq -c '.idf_libs[]' | tr -d '"'`; do + idf_libs_configs="$idf_libs_configs;configs/defconfig.$defconf" + done + + echo "* Build IDF-Libs: $idf_libs_configs" + rm -rf build sdkconfig + idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" idf-libs + if [ $? -ne 0 ]; then exit 1; fi + + if [ "$target" == "esp32s3" ]; then + idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" srmodels_bin + if [ $? -ne 0 ]; then exit 1; fi + AR_SDK="$AR_TOOLS/esp32-arduino-libs/$target" + # sr model.bin + if [ -f "build/srmodels/srmodels.bin" ]; then + echo "$AR_SDK/esp_sr" + mkdir -p "$AR_SDK/esp_sr" + cp -f "build/srmodels/srmodels.bin" "$AR_SDK/esp_sr/" + cp -f "partitions.csv" "$AR_SDK/esp_sr/" + fi + fi + + # Build Bootloaders + for boot_conf in `echo "$target_json" | jq -c '.bootloaders[]'`; do + bootloader_configs="$main_configs" + for defconf in `echo "$boot_conf" | jq -c '.[]' | tr -d '"'`; do + bootloader_configs="$bootloader_configs;configs/defconfig.$defconf"; + done + + echo "* Build BootLoader: $bootloader_configs" + rm -rf build sdkconfig + idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$bootloader_configs" copy-bootloader + if [ $? -ne 0 ]; then exit 1; fi + done + + # Build Memory Variants + for mem_conf in `echo "$target_json" | jq -c '.mem_variants[]'`; do + mem_configs="$main_configs" + for defconf in `echo "$mem_conf" | jq -c '.[]' | tr -d '"'`; do + mem_configs="$mem_configs;configs/defconfig.$defconf"; + done + + echo "* Build Memory Variant: $mem_configs" + rm -rf build sdkconfig + idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$mem_configs" mem-variant + if [ $? -ne 0 ]; then exit 1; fi + done +done + +# +# Add components version info +# +rm -rf "$AR_TOOLS/esp32-arduino-libs/versions.txt" +# The lib-builder version +component_version="lib-builder: "$(git -C "$AR_ROOT" symbolic-ref --short HEAD || git -C "$AR_ROOT" tag --points-at HEAD)" "$(git -C "$AR_ROOT" rev-parse --short HEAD) +echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt" +# ESP-IDF version +component_version="esp-idf: "$(git -C "$IDF_PATH" symbolic-ref --short HEAD || git -C "$IDF_PATH" tag --points-at HEAD)" "$(git -C "$IDF_PATH" rev-parse --short HEAD) +echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt" +# components version +for component in `ls "$AR_COMPS"`; do + if [ -d "$AR_COMPS/$component/.git" ]; then + component_version="$component: "$(git -C "$AR_COMPS/$component" symbolic-ref --short HEAD || git -C "$AR_COMPS/$component" tag --points-at HEAD)" "$(git -C "$AR_COMPS/$component" rev-parse --short HEAD) + echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt" + fi +done +# TinyUSB version +component_version="tinyusb: "$(git -C "$AR_COMPS/arduino_tinyusb/tinyusb" symbolic-ref --short HEAD || git -C "$AR_COMPS/arduino_tinyusb/tinyusb" tag --points-at HEAD)" "$(git -C "$AR_COMPS/arduino_tinyusb/tinyusb" rev-parse --short HEAD) +echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt" +# managed components version +for component in `ls "$AR_MANAGED_COMPS"`; do + if [ -d "$AR_MANAGED_COMPS/$component/.git" ]; then + component_version="$component: "$(git -C "$AR_MANAGED_COMPS/$component" symbolic-ref --short HEAD || git -C "$AR_MANAGED_COMPS/$component" tag --points-at HEAD)" "$(git -C "$AR_MANAGED_COMPS/$component" rev-parse --short HEAD) + echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt" + elif [ -f "$AR_MANAGED_COMPS/$component/idf_component.yml" ]; then + component_version="$component: "$(cat "$AR_MANAGED_COMPS/$component/idf_component.yml" | grep "^version: " | cut -d ' ' -f 2) + echo $component_version >> "$AR_TOOLS/esp32-arduino-libs/versions.txt" + fi +done + +# update package_esp32_index.template.json +if [ "$BUILD_TYPE" = "all" ]; then + echo "* Generating package_esp32_index.template.json..." + python3 ./tools/gen_tools_json.py -i "$IDF_PATH" -j "$AR_COMPS/arduino/package/package_esp32_index.template.json" -o "$AR_OUT/" + python3 ./tools/gen_tools_json.py -i "$IDF_PATH" -o "$TOOLS_JSON_OUT/" + if [ $? -ne 0 ]; then exit 1; fi +fi + +# Generate pioarduino manifest file +if [ "$BUILD_TYPE" = "all" ]; then + echo "* Generating pioarduino manifest file..." + pushd $IDF_PATH + ibr=$(git describe --all 2>/dev/null) + ic=$(git -C "$IDF_PATH" rev-parse --short HEAD) + popd + python3 ./tools/gen_pioarduino_manifest.py -o "$TOOLS_JSON_OUT/" -s "$ibr" -c "$ic" + if [ $? -ne 0 ]; then exit 1; fi +fi + +# copy everything to arduino-esp32 installation +if [ $COPY_OUT -eq 1 ] && [ -d "$ESP32_ARDUINO" ]; then + echo "* Copying to Arduino..." + ./tools/copy-to-arduino.sh + if [ $? -ne 0 ]; then exit 1; fi +fi + +# push changes to esp32-arduino-libs and create pull request into arduino-esp32 +if [ $DEPLOY_OUT -eq 1 ]; then + echo "* Pushing to Arduino..." + ./tools/push-to-arduino.sh + if [ $? -ne 0 ]; then exit 1; fi +fi + +# archive the build +if [ $ARCHIVE_OUT -eq 1 ]; then + echo "* Archiving build..." + ./tools/archive-build.sh "$TARGET" + if [ $? -ne 0 ]; then exit 1; fi +fi diff --git a/components/arduino_tinyusb/CMakeLists.txt b/components/arduino_tinyusb/CMakeLists.txt new file mode 100755 index 000000000..fd6f5983d --- /dev/null +++ b/components/arduino_tinyusb/CMakeLists.txt @@ -0,0 +1,79 @@ +if(CONFIG_TINYUSB_ENABLED) + + ### variables ### + ################# + + if(IDF_TARGET STREQUAL "esp32s2") + set(compile_options + "-DCFG_TUSB_MCU=OPT_MCU_ESP32S2" + "-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}" + "-Wno-type-limits" # needed for the vanila tinyusb with turned off classes + ) + elseif(IDF_TARGET STREQUAL "esp32s3") + set(compile_options + "-DCFG_TUSB_MCU=OPT_MCU_ESP32S3" + "-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}" + "-Wno-type-limits" # needed for the vanila tinyusb with turned off classes + ) + elseif(IDF_TARGET STREQUAL "esp32p4") + set(compile_options + "-DCFG_TUSB_MCU=OPT_MCU_ESP32P4" + "-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}" + "-Wno-type-limits" # needed for the vanila tinyusb with turned off classes + ) + endif() + + set(srcs + # espressif: + "${COMPONENT_DIR}/src/dcd_dwc2.c" + # tusb: + #"${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c" + "${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c" + "${COMPONENT_DIR}/tinyusb/src/class/cdc/cdc_device.c" + "${COMPONENT_DIR}/tinyusb/src/class/hid/hid_device.c" + "${COMPONENT_DIR}/tinyusb/src/class/midi/midi_device.c" + "${COMPONENT_DIR}/tinyusb/src/class/msc/msc_device.c" + "${COMPONENT_DIR}/tinyusb/src/class/video/video_device.c" + "${COMPONENT_DIR}/tinyusb/src/class/dfu/dfu_rt_device.c" + "${COMPONENT_DIR}/tinyusb/src/class/dfu/dfu_device.c" + "${COMPONENT_DIR}/tinyusb/src/class/vendor/vendor_device.c" + "${COMPONENT_DIR}/tinyusb/src/class/net/ncm_device.c" + "${COMPONENT_DIR}/tinyusb/src/common/tusb_fifo.c" + "${COMPONENT_DIR}/tinyusb/src/device/usbd_control.c" + "${COMPONENT_DIR}/tinyusb/src/device/usbd.c" + "${COMPONENT_DIR}/tinyusb/src/tusb.c") + + set(includes_private + # tusb: + "${COMPONENT_DIR}/tinyusb/hw/bsp/" + "${COMPONENT_DIR}/tinyusb/src/" + "${COMPONENT_DIR}/tinyusb/src/device" + "${COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2" + ) + + idf_component_get_property(FREERTOS_ORIG_INCLUDE_PATH freertos + ORIG_INCLUDE_PATH) + set(includes_public + # tusb: + "${FREERTOS_ORIG_INCLUDE_PATH}" + "${COMPONENT_DIR}/tinyusb/src/" + # espressif: + "${COMPONENT_DIR}/include") + + set(requires esp_rom freertos soc) + set(priv_requires arduino main) + + idf_component_register( + INCLUDE_DIRS ${includes_public} + PRIV_INCLUDE_DIRS ${includes_private} + SRCS ${srcs} + REQUIRES ${requires} + PRIV_REQUIRES ${priv_requires} + ) + target_compile_options(${COMPONENT_TARGET} PRIVATE ${compile_options}) + +else() + + idf_component_register() + +endif() diff --git a/components/arduino_tinyusb/Kconfig.projbuild b/components/arduino_tinyusb/Kconfig.projbuild new file mode 100755 index 000000000..f0a1b4dc6 --- /dev/null +++ b/components/arduino_tinyusb/Kconfig.projbuild @@ -0,0 +1,271 @@ +menu "Arduino TinyUSB" + depends on ENABLE_ARDUINO_DEPENDS && SOC_USB_OTG_SUPPORTED + + config TINYUSB_ENABLED + bool "Enable TinyUSB driver" + default y + depends on IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32P4 + select FREERTOS_SUPPORT_STATIC_ALLOCATION + select FREERTOS_USE_AUTHENTIC_INCLUDE_PATHS + help + Adds support for TinyUSB + + menu "Serial (CDC) driver" + depends on TINYUSB_ENABLED + + config TINYUSB_CDC_ENABLED + bool "Enable USB Serial (CDC) TinyUSB driver" + default y + help + Enable USB Serial (CDC) TinyUSB driver. + + config TINYUSB_DESC_CDC_STRING + string "CDC Device String" + default "Espressif CDC Device" + depends on TINYUSB_CDC_ENABLED + help + Specify name of the CDC device + + config TINYUSB_CDC_RX_BUFSIZE + int "CDC FIFO size of RX" + default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 512 if IDF_TARGET_ESP32P4 + depends on TINYUSB_CDC_ENABLED + help + CDC FIFO size of RX + + config TINYUSB_CDC_TX_BUFSIZE + int "CDC FIFO size of TX" + default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 512 if IDF_TARGET_ESP32P4 + depends on TINYUSB_CDC_ENABLED + help + CDC FIFO size of TX + + config TINYUSB_CDC_MAX_PORTS + int "Maximum enabled CDC ports" + range 1 2 + default 1 + depends on TINYUSB_CDC_ENABLED + help + Maximum enabled CDC ports + + endmenu + + menu "Mass Storage (MSC) driver" + depends on TINYUSB_ENABLED + + config TINYUSB_MSC_ENABLED + bool "Enable USB Mass Storage (MSC) TinyUSB driver" + default y + help + Enable USB Mass Storage (MSC) TinyUSB driver. + + config TINYUSB_DESC_MSC_STRING + string "MSC Device String" + default "Espressif MSC Device" + depends on TINYUSB_MSC_ENABLED + help + Specify name of the MSC device + + config TINYUSB_MSC_BUFSIZE + int "MSC Buffer size" + range 512 4096 + default 4096 + depends on TINYUSB_MSC_ENABLED + help + MSC Buffer size + + endmenu + + menu "Human Interface (HID) driver" + depends on TINYUSB_ENABLED + + config TINYUSB_HID_ENABLED + bool "Enable USB Human Interface (HID) TinyUSB driver" + default y + help + Enable USB Human Interface (HID) TinyUSB driver. + + config TINYUSB_DESC_HID_STRING + string "HID Device String" + default "Espressif HID Device" + depends on TINYUSB_HID_ENABLED + help + Specify name of the HID device + + config TINYUSB_HID_BUFSIZE + int "HID Buffer size" + default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 512 if IDF_TARGET_ESP32P4 + depends on TINYUSB_HID_ENABLED + help + HID Buffer size. Should be sufficient to hold ID (if any) + Data + + endmenu + + menu "MIDI driver" + depends on TINYUSB_ENABLED + + config TINYUSB_MIDI_ENABLED + bool "Enable USB MIDI TinyUSB driver" + default y + help + Enable USB MIDI TinyUSB driver. + + config TINYUSB_DESC_MIDI_STRING + string "MIDI Device String" + default "Espressif MIDI Device" + depends on TINYUSB_MIDI_ENABLED + help + Specify name of the MIDI device + + config TINYUSB_MIDI_RX_BUFSIZE + int "MIDI FIFO size of RX" + default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 512 if IDF_TARGET_ESP32P4 + depends on TINYUSB_MIDI_ENABLED + help + MIDI FIFO size of RX + + config TINYUSB_MIDI_TX_BUFSIZE + int "MIDI FIFO size of TX" + default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 512 if IDF_TARGET_ESP32P4 + depends on TINYUSB_MIDI_ENABLED + help + MIDI FIFO size of TX + + endmenu + + menu "VIDEO driver" + depends on TINYUSB_ENABLED + + config TINYUSB_VIDEO_ENABLED + bool "Enable USB VIDEO TinyUSB driver" + default y + help + Enable USB VIDEO TinyUSB driver. + + config TINYUSB_DESC_VIDEO_STRING + string "VIDEO Device String" + default "Espressif VIDEO Device" + depends on TINYUSB_VIDEO_ENABLED + help + Specify name of the VIDEO device + + config TINYUSB_VIDEO_STREAMING_BUFSIZE + int "VIDEO streaming endpoint size" + range 0 512 + default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 512 if IDF_TARGET_ESP32P4 + depends on TINYUSB_VIDEO_ENABLED + help + VIDEO streaming endpoint size + + config TINYUSB_VIDEO_STREAMING_IFS + int "Number of VIDEO streaming interfaces" + range 1 3 + default 1 + depends on TINYUSB_VIDEO_ENABLED + help + The number of VIDEO streaming interfaces + endmenu + + menu "DFU Runtime driver" + depends on TINYUSB_ENABLED + + config TINYUSB_DFU_RT_ENABLED + bool "Enable USB DFU Runtime TinyUSB driver" + default y + help + Enable USB DFU Runtime TinyUSB driver. + + config TINYUSB_DESC_DFU_RT_STRING + string "DFU_RT Device String" + default "Espressif DFU_RT Device" + depends on TINYUSB_DFU_RT_ENABLED + help + Specify name of the DFU_RT device + + endmenu + + menu "DFU driver" + depends on TINYUSB_ENABLED + + config TINYUSB_DFU_ENABLED + bool "Enable USB DFU TinyUSB driver" + default y + help + Enable USB DFU TinyUSB driver. + + config TINYUSB_DESC_DFU_STRING + string "DFU Device String" + default "Espressif DFU Device" + depends on TINYUSB_DFU_ENABLED + help + Specify name of the DFU device + + config TINYUSB_DFU_BUFSIZE + int "DFU buffer size" + default 4096 + depends on TINYUSB_DFU_ENABLED + help + DFU buffer size + + endmenu + + menu "VENDOR driver" + depends on TINYUSB_ENABLED + + config TINYUSB_VENDOR_ENABLED + bool "Enable USB VENDOR TinyUSB driver" + default y + help + Enable USB VENDOR TinyUSB driver. + + config TINYUSB_DESC_VENDOR_STRING + string "VENDOR Device String" + default "Espressif VENDOR Device" + depends on TINYUSB_VENDOR_ENABLED + help + Specify name of the VENDOR device + + config TINYUSB_VENDOR_RX_BUFSIZE + int "VENDOR FIFO size of RX" + default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 512 if IDF_TARGET_ESP32P4 + depends on TINYUSB_VENDOR_ENABLED + help + VENDOR FIFO size of RX + + config TINYUSB_VENDOR_TX_BUFSIZE + int "VENDOR FIFO size of TX" + default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 512 if IDF_TARGET_ESP32P4 + depends on TINYUSB_VENDOR_ENABLED + help + VENDOR FIFO size of TX + + endmenu + + menu "NCM driver" + depends on TINYUSB_ENABLED + + config TINYUSB_NCM_ENABLED + bool "Enable USB NCM TinyUSB driver" + default y + help + Enable USB NCM TinyUSB driver. + + endmenu + + config TINYUSB_DEBUG_LEVEL + int "TinyUSB log level (0-3)" + default 0 + range 0 3 + depends on TINYUSB_ENABLED + help + Define amount of log output from TinyUSB + +endmenu diff --git a/components/arduino_tinyusb/include/tusb_config.h b/components/arduino_tinyusb/include/tusb_config.h new file mode 100755 index 000000000..7802bea8f --- /dev/null +++ b/components/arduino_tinyusb/include/tusb_config.h @@ -0,0 +1,160 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org), + * Additions Copyright (c) 2020, Espressif Systems (Shanghai) PTE LTD + * + * 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. + * + */ + +#pragma once +#include "tusb_option.h" +#include "sdkconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* */ +/* KCONFIG */ +/* */ + +#ifndef CONFIG_TINYUSB_CDC_ENABLED +# define CONFIG_TINYUSB_CDC_ENABLED 0 +#endif + +#ifndef CONFIG_TINYUSB_MSC_ENABLED +# define CONFIG_TINYUSB_MSC_ENABLED 0 +#endif + +#ifndef CONFIG_TINYUSB_HID_ENABLED +# define CONFIG_TINYUSB_HID_ENABLED 0 +#endif + +#ifndef CONFIG_TINYUSB_MIDI_ENABLED +# define CONFIG_TINYUSB_MIDI_ENABLED 0 +#endif + +#ifndef CONFIG_TINYUSB_VIDEO_ENABLED +# define CONFIG_TINYUSB_VIDEO_ENABLED 0 +#endif + +#ifndef CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED +# define CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED 0 +#endif + +#ifndef CONFIG_TINYUSB_DFU_RT_ENABLED +# define CONFIG_TINYUSB_DFU_RT_ENABLED 0 +#endif + +#ifndef CONFIG_TINYUSB_DFU_ENABLED +# define CONFIG_TINYUSB_DFU_ENABLED 0 +#endif + +#ifndef CONFIG_TINYUSB_VENDOR_ENABLED +# define CONFIG_TINYUSB_VENDOR_ENABLED 0 +#endif + +#ifndef CONFIG_TINYUSB_NCM_ENABLED +# define CONFIG_TINYUSB_NCM_ENABLED 0 +#endif + +/* */ +/* COMMON CONFIGURATION */ +/* */ +#ifndef CFG_TUSB_MCU +#define CFG_TUSB_MCU OPT_MCU_ESP32S2 +#endif +#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE +#define CFG_TUSB_OS OPT_OS_FREERTOS + +/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. + * Tinyusb use follows macros to declare transferring memory so that they can be put + * into those specific section. + * e.g + * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) + * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) + */ +#ifndef CFG_TUSB_MEM_SECTION +# define CFG_TUSB_MEM_SECTION +#endif + +#ifndef CFG_TUSB_MEM_ALIGN +# define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4) +#endif + +#if CONFIG_IDF_TARGET_ESP32P4 +#define CFG_TUD_MAX_SPEED OPT_MODE_HIGH_SPEED +#else +#define CFG_TUD_MAX_SPEED OPT_MODE_FULL_SPEED +#endif + +/* */ +/* DRIVER CONFIGURATION */ +/* */ + +#define CFG_TUD_MAINTASK_SIZE 4096 +#define CFG_TUD_ENDOINT_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) +#define CFG_TUD_ENDOINT0_SIZE 64 + +// Enabled Drivers +#ifdef CONFIG_TINYUSB_CDC_MAX_PORTS +#define CFG_TUD_CDC CONFIG_TINYUSB_CDC_MAX_PORTS +#else +#define CFG_TUD_CDC 0 +#endif +#define CFG_TUD_MSC CONFIG_TINYUSB_MSC_ENABLED +#define CFG_TUD_HID CONFIG_TINYUSB_HID_ENABLED +#define CFG_TUD_MIDI CONFIG_TINYUSB_MIDI_ENABLED +#define CFG_TUD_VIDEO CONFIG_TINYUSB_VIDEO_ENABLED +#define CFG_TUD_CUSTOM_CLASS CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED +#define CFG_TUD_DFU_RUNTIME CONFIG_TINYUSB_DFU_RT_ENABLED +#define CFG_TUD_DFU CONFIG_TINYUSB_DFU_ENABLED +#define CFG_TUD_VENDOR CONFIG_TINYUSB_VENDOR_ENABLED +#define CFG_TUD_NCM CONFIG_TINYUSB_NCM_ENABLED + +// CDC FIFO size of TX and RX +#define CFG_TUD_CDC_RX_BUFSIZE CONFIG_TINYUSB_CDC_RX_BUFSIZE +#define CFG_TUD_CDC_TX_BUFSIZE CONFIG_TINYUSB_CDC_TX_BUFSIZE + +// MSC Buffer size of Device Mass storage: +#define CFG_TUD_MSC_BUFSIZE CONFIG_TINYUSB_MSC_BUFSIZE + +// HID buffer size Should be sufficient to hold ID (if any) + Data +#define CFG_TUD_HID_BUFSIZE CONFIG_TINYUSB_HID_BUFSIZE + +// MIDI FIFO size of TX and RX +#define CFG_TUD_MIDI_RX_BUFSIZE CONFIG_TINYUSB_MIDI_RX_BUFSIZE +#define CFG_TUD_MIDI_TX_BUFSIZE CONFIG_TINYUSB_MIDI_TX_BUFSIZE + +// The number of video streaming interfaces and endpoint size +#define CFG_TUD_VIDEO_STREAMING CONFIG_TINYUSB_VIDEO_STREAMING_IFS +#define CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE CONFIG_TINYUSB_VIDEO_STREAMING_BUFSIZE + +// DFU buffer size +#define CFG_TUD_DFU_XFER_BUFSIZE CONFIG_TINYUSB_DFU_BUFSIZE + +// VENDOR FIFO size of TX and RX +#define CFG_TUD_VENDOR_RX_BUFSIZE CONFIG_TINYUSB_VENDOR_RX_BUFSIZE +#define CFG_TUD_VENDOR_TX_BUFSIZE CONFIG_TINYUSB_VENDOR_TX_BUFSIZE + +#ifdef __cplusplus +} +#endif diff --git a/components/arduino_tinyusb/patches/dcd_dwc2.patch b/components/arduino_tinyusb/patches/dcd_dwc2.patch new file mode 100644 index 000000000..14e6975f0 --- /dev/null +++ b/components/arduino_tinyusb/patches/dcd_dwc2.patch @@ -0,0 +1,84 @@ +--- a/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:17:40.000000000 +0300 ++++ b/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:19:48.000000000 +0300 +@@ -243,6 +243,17 @@ + //-------------------------------------------------------------------- + // Endpoint + //-------------------------------------------------------------------- ++#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) ++// Keep count of how many FIFOs are in use ++static uint8_t _allocated_fifos = 1; //FIFO0 is always in use ++ ++// Will either return an unused FIFO number, or 0 if all are used. ++static uint8_t get_free_fifo(void) { ++ if (_allocated_fifos < 5) return _allocated_fifos++; ++ return 0; ++} ++#endif ++ + static void edpt_activate(uint8_t rhport, const tusb_desc_endpoint_t* p_endpoint_desc) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const uint8_t epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress); +@@ -266,7 +277,18 @@ + depctl.set_data0_iso_even = 1; + } + if (dir == TUSB_DIR_IN) { +- depctl.tx_fifo_num = epnum; ++ //depctl.tx_fifo_num = epnum; ++ uint8_t fifo_num = epnum; ++#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) ++ // Special Case for EP5, which is used by CDC but not actually called by the driver ++ // we can give it a fake FIFO ++ if (epnum == 5) { ++ fifo_num = epnum; ++ } else { ++ fifo_num = get_free_fifo(); ++ } ++#endif ++ depctl.tx_fifo_num = fifo_num; + } + + dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; +@@ -557,6 +579,10 @@ + } + } + ++#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) ++ _allocated_fifos = 1; ++#endif ++ + dfifo_flush_tx(dwc2, 0x10); // all tx fifo + dfifo_flush_rx(dwc2); + +@@ -997,6 +1023,9 @@ + if (gintsts & GINTSTS_USBRST) { + // USBRST is start of reset. + dwc2->gintsts = GINTSTS_USBRST; ++#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) ++ _allocated_fifos = 1; ++#endif + handle_bus_reset(rhport); + } + +@@ -1008,7 +1037,11 @@ + + if (gintsts & GINTSTS_USBSUSP) { + dwc2->gintsts = GINTSTS_USBSUSP; +- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true); ++ //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true); ++ dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true); ++#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) ++ _allocated_fifos = 1; ++#endif + } + + if (gintsts & GINTSTS_WKUINT) { +@@ -1025,6 +1058,9 @@ + + if (otg_int & GOTGINT_SEDET) { + dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true); ++#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) ++ _allocated_fifos = 1; ++#endif + } + + dwc2->gotgint = otg_int; diff --git a/components/arduino_tinyusb/src/dcd_dwc2.c b/components/arduino_tinyusb/src/dcd_dwc2.c new file mode 100644 index 000000000..ea931ab90 --- /dev/null +++ b/components/arduino_tinyusb/src/dcd_dwc2.c @@ -0,0 +1,1110 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 William D. Jones + * Copyright (c) 2019 Ha Thach (tinyusb.org) + * Copyright (c) 2020 Jan Duempelmann + * Copyright (c) 2020 Reinhard Panhuber + * + * 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. + * + * This file is part of the TinyUSB stack. + */ + +#include "tusb_option.h" + +#if CFG_TUD_ENABLED && defined(TUP_USBIP_DWC2) + +#if !(CFG_TUD_DWC2_SLAVE_ENABLE || CFG_TUD_DWC2_DMA_ENABLE) +#error DWC2 require either CFG_TUD_DWC2_SLAVE_ENABLE or CFG_TUD_DWC2_DMA_ENABLE to be enabled +#endif + +// Debug level for DWC2 +#define DWC2_DEBUG 2 + +#include "device/dcd.h" +#include "dwc2_common.h" + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM +//--------------------------------------------------------------------+ +typedef struct { + uint8_t* buffer; + tu_fifo_t* ff; + uint16_t total_len; + uint16_t max_size; + uint8_t interval; +} xfer_ctl_t; + +static xfer_ctl_t xfer_status[DWC2_EP_MAX][2]; +#define XFER_CTL_BASE(_ep, _dir) (&xfer_status[_ep][_dir]) + +typedef struct { + // EP0 transfers are limited to 1 packet - larger sizes has to be split + uint16_t ep0_pending[2]; // Index determines direction as tusb_dir_t type + uint16_t dfifo_top; // top free location in DFIFO in words + + // Number of IN endpoints active + uint8_t allocated_epin_count; + + // SOF enabling flag - required for SOF to not get disabled in ISR when SOF was enabled by + bool sof_en; +} dcd_data_t; + +static dcd_data_t _dcd_data; + +CFG_TUD_MEM_SECTION static struct { + TUD_EPBUF_DEF(setup_packet, 8); +} _dcd_usbbuf; + +TU_ATTR_ALWAYS_INLINE static inline uint8_t dwc2_ep_count(const dwc2_regs_t* dwc2) { + #if TU_CHECK_MCU(OPT_MCU_GD32VF103) + return DWC2_EP_MAX; + #else + const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; + return ghwcfg2.num_dev_ep + 1; + #endif +} + + +//-------------------------------------------------------------------- +// DMA +//-------------------------------------------------------------------- +#if CFG_TUD_MEM_DCACHE_ENABLE +bool dcd_dcache_clean(const void* addr, uint32_t data_size) { + TU_VERIFY(addr && data_size); + return dwc2_dcache_clean(addr, data_size); +} + +bool dcd_dcache_invalidate(const void* addr, uint32_t data_size) { + TU_VERIFY(addr && data_size); + return dwc2_dcache_invalidate(addr, data_size); +} + +bool dcd_dcache_clean_invalidate(const void* addr, uint32_t data_size) { + TU_VERIFY(addr && data_size); + return dwc2_dcache_clean_invalidate(addr, data_size); +} +#endif + +TU_ATTR_ALWAYS_INLINE static inline bool dma_device_enabled(const dwc2_regs_t* dwc2) { + (void) dwc2; + // Internal DMA only + const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; + return CFG_TUD_DWC2_DMA_ENABLE && ghwcfg2.arch == GHWCFG2_ARCH_INTERNAL_DMA; +} + +static void dma_setup_prepare(uint8_t rhport) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + + if (dwc2->gsnpsid >= DWC2_CORE_REV_3_00a) { + if(dwc2->epout[0].doepctl & DOEPCTL_EPENA) { + return; + } + } + + // Receive only 1 packet + dwc2->epout[0].doeptsiz = (1 << DOEPTSIZ_STUPCNT_Pos) | (1 << DOEPTSIZ_PKTCNT_Pos) | (8 << DOEPTSIZ_XFRSIZ_Pos); + dwc2->epout[0].doepdma = (uintptr_t) _dcd_usbbuf.setup_packet; + dwc2->epout[0].doepctl |= DOEPCTL_EPENA | DOEPCTL_USBAEP; +} + +//--------------------------------------------------------------------+ +// Data FIFO +//--------------------------------------------------------------------+ + + +/* Device Data FIFO scheme + + The FIFO is split up into + - EPInfo: for storing DMA metadata, only required when use DMA. Maximum size is called + EP_LOC_CNT = ep_fifo_size - ghwcfg3.dfifo_depth. For value less than EP_LOC_CNT, gdfifocfg must be configured before + gahbcfg.dmaen is set + - Buffer mode: 1 word per endpoint direction + - Scatter/Gather DMA: 4 words per endpoint direction + - TX FIFO: one fifo for each IN endpoint. Size is dynamic depending on packet size, starting from top with EP0 IN. + - Shared RX FIFO: a shared fifo for all OUT endpoints. Typically, can hold up to 2 packets of the largest EP size. + + We allocated TX FIFO from top to bottom (using top pointer), this to allow the RX FIFO to grow dynamically which is + possible since the free space is located between the RX and TX FIFOs. + + ---------------- ep_fifo_size + | DxEPIDMAn | + |-------------|-- gdfifocfg.EPINFOBASE (max is ghwcfg3.dfifo_depth) + | IN FIFO 0 | control EP + |-------------| + | IN FIFO 1 | + |-------------| + | . . . . | + |-------------| + | IN FIFO n | + |-------------| + | FREE | + |-------------|-- GRXFSIZ (expandable) + | OUT FIFO | + | ( Shared ) | + --------------- 0 + + According to "FIFO RAM allocation" section in RM, FIFO RAM are allocated as follows (each word 32-bits): + - Each EP IN needs at least max packet size + - All EP OUT shared a unique OUT FIFO which uses (for Slave or Buffer DMA, Scatt/Gather DMA use different formula): + - 13 for setup packets + control words (up to 3 setup packets). + - 1 for global NAK (not required/used here). + - Largest-EPsize/4 + 1. ( FS: 64 bytes, HS: 512 bytes). Recommended is "2 x (Largest-EPsize/4 + 1)" + - 2 for each used OUT endpoint + + Therefore GRXFSIZ = 13 + 1 + 2 x (Largest-EPsize/4 + 1) + 2 x EPOUTnum +*/ + +TU_ATTR_ALWAYS_INLINE static inline uint16_t calc_device_grxfsiz(uint16_t largest_ep_size, uint8_t ep_count) { + return 13 + 1 + 2 * ((largest_ep_size / 4) + 1) + 2 * ep_count; +} + +static bool dfifo_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t packet_size) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const dwc2_controller_t* dwc2_controller = &_dwc2_controller[rhport]; + const uint8_t ep_count = dwc2_controller->ep_count; + const uint8_t epnum = tu_edpt_number(ep_addr); + const uint8_t dir = tu_edpt_dir(ep_addr); + + TU_ASSERT(epnum < ep_count); + + uint16_t fifo_size = tu_div_ceil(packet_size, 4); + if (dir == TUSB_DIR_OUT) { + // Calculate required size of RX FIFO + const uint16_t new_sz = calc_device_grxfsiz(4 * fifo_size, ep_count); + + // If size_rx needs to be extended check if there is enough free space + if (dwc2->grxfsiz < new_sz) { + TU_ASSERT(new_sz <= _dcd_data.dfifo_top); + dwc2->grxfsiz = new_sz; // Enlarge RX FIFO + } + } else { + // Check IN endpoints concurrently active limit + if(dwc2_controller->ep_in_count) { + TU_ASSERT(_dcd_data.allocated_epin_count < dwc2_controller->ep_in_count); + _dcd_data.allocated_epin_count++; + } + + // If The TXFELVL is configured as half empty, the fifo must be twice the max_size. + if ((dwc2->gahbcfg & GAHBCFG_TX_FIFO_EPMTY_LVL) == 0) { + fifo_size *= 2; + } + + // Check if free space is available + TU_ASSERT(_dcd_data.dfifo_top >= fifo_size + dwc2->grxfsiz); + _dcd_data.dfifo_top -= fifo_size; + // TU_LOG(DWC2_DEBUG, " TX FIFO %u: allocated %u words at offset %u\r\n", epnum, fifo_size, dfifo_top); + + // Both TXFD and TXSA are in unit of 32-bit words. + if (epnum == 0) { + dwc2->dieptxf0 = (fifo_size << DIEPTXF0_TX0FD_Pos) | _dcd_data.dfifo_top; + } else { + // DIEPTXF starts at FIFO #1. + dwc2->dieptxf[epnum - 1] = (fifo_size << DIEPTXF_INEPTXFD_Pos) | _dcd_data.dfifo_top; + } + } + + return true; +} + +static void dfifo_device_init(uint8_t rhport) { + const dwc2_controller_t* dwc2_controller = &_dwc2_controller[rhport]; + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + dwc2->grxfsiz = calc_device_grxfsiz(CFG_TUD_ENDPOINT0_SIZE, dwc2_controller->ep_count); + + // Scatter/Gather DMA mode is not yet supported. Buffer DMA only need 1 words per endpoint direction + const bool is_dma = dma_device_enabled(dwc2); + _dcd_data.dfifo_top = dwc2_controller->ep_fifo_size/4; + if (is_dma) { + _dcd_data.dfifo_top -= 2 * dwc2_controller->ep_count; + } + dwc2->gdfifocfg = (_dcd_data.dfifo_top << GDFIFOCFG_EPINFOBASE_SHIFT) | _dcd_data.dfifo_top; + + // Allocate FIFO for EP0 IN + dfifo_alloc(rhport, 0x80, CFG_TUD_ENDPOINT0_SIZE); +} + + +//-------------------------------------------------------------------- +// Endpoint +//-------------------------------------------------------------------- +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) +// Keep count of how many FIFOs are in use +static uint8_t _allocated_fifos = 1; //FIFO0 is always in use + +// Will either return an unused FIFO number, or 0 if all are used. +static uint8_t get_free_fifo(void) { + if (_allocated_fifos < 5) return _allocated_fifos++; + return 0; +} +#endif + +static void edpt_activate(uint8_t rhport, const tusb_desc_endpoint_t* p_endpoint_desc) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const uint8_t epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress); + const uint8_t dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress); + + xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, dir); + xfer->max_size = tu_edpt_packet_size(p_endpoint_desc); + xfer->interval = p_endpoint_desc->bInterval; + + // Endpoint control + dwc2_depctl_t depctl = {.value = 0}; + depctl.mps = xfer->max_size; + depctl.active = 1; + depctl.type = p_endpoint_desc->bmAttributes.xfer; + if (p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS) { + depctl.set_data0_iso_even = 1; + } + if (dir == TUSB_DIR_IN) { + //depctl.tx_fifo_num = epnum; + uint8_t fifo_num = epnum; +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) + // Special Case for EP5, which is used by CDC but not actually called by the driver + // we can give it a fake FIFO + if (epnum == 5) { + fifo_num = epnum; + } else { + fifo_num = get_free_fifo(); + } +#endif + depctl.tx_fifo_num = fifo_num; + } + + dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; + dep->ctl = depctl.value; + dwc2->daintmsk |= TU_BIT(epnum + DAINT_SHIFT(dir)); +} + +static void edpt_disable(uint8_t rhport, uint8_t ep_addr, bool stall) { + (void) rhport; + + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const uint8_t epnum = tu_edpt_number(ep_addr); + const uint8_t dir = tu_edpt_dir(ep_addr); + dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; + + if (dir == TUSB_DIR_IN) { + // Only disable currently enabled non-control endpoint + if ((epnum == 0) || !(dep->diepctl & DIEPCTL_EPENA)) { + dep->diepctl |= DIEPCTL_SNAK | (stall ? DIEPCTL_STALL : 0); + } else { + // Stop transmitting packets and NAK IN xfers. + dep->diepctl |= DIEPCTL_SNAK; + while ((dep->diepint & DIEPINT_INEPNE) == 0) {} + + // Disable the endpoint. + dep->diepctl |= DIEPCTL_EPDIS | (stall ? DIEPCTL_STALL : 0); + while ((dep->diepint & DIEPINT_EPDISD_Msk) == 0) {} + + dep->diepint = DIEPINT_EPDISD; + } + + // Flush the FIFO, and wait until we have confirmed it cleared. + dfifo_flush_tx(dwc2, epnum); + } else { + // Only disable currently enabled non-control endpoint + if ((epnum == 0) || !(dep->doepctl & DOEPCTL_EPENA)) { + dep->doepctl |= stall ? DOEPCTL_STALL : 0; + } else { + // Asserting GONAK is required to STALL an OUT endpoint. + // Simpler to use polling here, we don't use the "B"OUTNAKEFF interrupt + // anyway, and it can't be cleared by user code. If this while loop never + // finishes, we have bigger problems than just the stack. + dwc2->dctl |= DCTL_SGONAK; + while ((dwc2->gintsts & GINTSTS_BOUTNAKEFF_Msk) == 0) {} + + // Ditto here disable the endpoint. + dep->doepctl |= DOEPCTL_EPDIS | (stall ? DOEPCTL_STALL : 0); + while ((dep->doepint & DOEPINT_EPDISD_Msk) == 0) {} + + dep->doepint = DOEPINT_EPDISD; + + // Allow other OUT endpoints to keep receiving. + dwc2->dctl |= DCTL_CGONAK; + } + } +} + +static void edpt_schedule_packets(uint8_t rhport, const uint8_t epnum, const uint8_t dir) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + xfer_ctl_t* const xfer = XFER_CTL_BASE(epnum, dir); + dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; + + uint16_t num_packets; + uint16_t total_bytes; + + // EP0 is limited to one packet per xfer + if (epnum == 0) { + total_bytes = tu_min16(_dcd_data.ep0_pending[dir], xfer->max_size); + _dcd_data.ep0_pending[dir] -= total_bytes; + num_packets = 1; + } else { + total_bytes = xfer->total_len; + num_packets = tu_div_ceil(total_bytes, xfer->max_size); + if (num_packets == 0) { + num_packets = 1; // zero length packet still count as 1 + } + } + + // transfer size: A full OUT transfer (multiple packets, possibly) triggers XFRC. + dwc2_ep_tsize_t deptsiz = {.value = 0}; + deptsiz.xfer_size = total_bytes; + deptsiz.packet_count = num_packets; + dep->tsiz = deptsiz.value; + + // control + dwc2_depctl_t depctl = {.value = dep->ctl}; + depctl.clear_nak = 1; + depctl.enable = 1; + if (depctl.type == DEPCTL_EPTYPE_ISOCHRONOUS && xfer->interval == 1) { + const dwc2_dsts_t dsts = {.value = dwc2->dsts}; + const uint32_t odd_now = dsts.frame_number & 1u; + if (odd_now) { + depctl.set_data0_iso_even = 1; + } else { + depctl.set_data1_iso_odd = 1; + } + } + + const bool is_dma = dma_device_enabled(dwc2); + if(is_dma) { + if (dir == TUSB_DIR_IN && total_bytes != 0) { + dcd_dcache_clean(xfer->buffer, total_bytes); + } + dep->diepdma = (uintptr_t) xfer->buffer; + dep->diepctl = depctl.value; // enable endpoint + } else { + dep->diepctl = depctl.value; // enable endpoint + + // Enable tx fifo empty interrupt only if there is data. Note must after depctl enable + if (dir == TUSB_DIR_IN && total_bytes != 0) { + dwc2->diepempmsk |= (1 << epnum); + } + } +} + +//-------------------------------------------------------------------- +// Controller API +//-------------------------------------------------------------------- +bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + + tu_memclr(&_dcd_data, sizeof(_dcd_data)); + + // Core Initialization + const bool is_highspeed = dwc2_core_is_highspeed(dwc2, TUSB_ROLE_DEVICE); + const bool is_dma = dma_device_enabled(dwc2); + TU_ASSERT(dwc2_core_init(rhport, is_highspeed, is_dma)); + + //------------- 7.1 Device Initialization -------------// + // Set device max speed + uint32_t dcfg = dwc2->dcfg & ~DCFG_DSPD_Msk; + if (is_highspeed) { + dcfg |= DCFG_DSPD_HS << DCFG_DSPD_Pos; + + // XCVRDLY: transceiver delay between xcvr_sel and txvalid during device chirp is required + // when using with some PHYs such as USB334x (USB3341, USB3343, USB3346, USB3347) + const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; + if (ghwcfg2.hs_phy_type == GHWCFG2_HSPHY_ULPI) { + dcfg |= DCFG_XCVRDLY; + } + } else { + dcfg |= DCFG_DSPD_FS << DCFG_DSPD_Pos; + } + + dcfg |= DCFG_NZLSOHSK; // send STALL back and discard if host send non-zlp during control status + dwc2->dcfg = dcfg; + + dcd_disconnect(rhport); + + // Force device mode + dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_FHMOD) | GUSBCFG_FDMOD; + + // Clear A override, force B Valid + dwc2->gotgctl = (dwc2->gotgctl & ~GOTGCTL_AVALOEN) | GOTGCTL_BVALOEN | GOTGCTL_BVALOVAL; + + // Enable required interrupts + dwc2->gintmsk |= GINTMSK_OTGINT | GINTMSK_USBSUSPM | GINTMSK_USBRST | GINTMSK_ENUMDNEM | GINTMSK_WUIM; + + // TX FIFO empty level for interrupt is complete empty + uint32_t gahbcfg = dwc2->gahbcfg; + gahbcfg |= GAHBCFG_TX_FIFO_EPMTY_LVL; + gahbcfg |= GAHBCFG_GINT; // Enable global interrupt + dwc2->gahbcfg = gahbcfg; + + dcd_connect(rhport); + return true; +} + +void dcd_int_enable(uint8_t rhport) { + dwc2_dcd_int_enable(rhport); +} + +void dcd_int_disable(uint8_t rhport) { + dwc2_dcd_int_disable(rhport); +} + +void dcd_set_address(uint8_t rhport, uint8_t dev_addr) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + dwc2->dcfg = (dwc2->dcfg & ~DCFG_DAD_Msk) | (dev_addr << DCFG_DAD_Pos); + + // Response with status after changing device address + dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0); +} + +void dcd_remote_wakeup(uint8_t rhport) { + (void) rhport; + + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + + // set remote wakeup + dwc2->dctl |= DCTL_RWUSIG; + + // enable SOF to detect bus resume + dwc2->gintsts = GINTSTS_SOF; + dwc2->gintmsk |= GINTMSK_SOFM; + + // Per specs: remote wakeup signal bit must be clear within 1-15ms + dwc2_remote_wakeup_delay(); + + dwc2->dctl &= ~DCTL_RWUSIG; +} + +void dcd_connect(uint8_t rhport) { + (void) rhport; + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + +#ifdef TUP_USBIP_DWC2_ESP32 + usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf; + conf.pad_pull_override = 0; + conf.dp_pullup = 0; + conf.dp_pulldown = 0; + conf.dm_pullup = 0; + conf.dm_pulldown = 0; + USB_WRAP.otg_conf = conf; +#endif + + dwc2->dctl &= ~DCTL_SDIS; +} + +void dcd_disconnect(uint8_t rhport) { + (void) rhport; + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + +#ifdef TUP_USBIP_DWC2_ESP32 + usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf; + conf.pad_pull_override = 1; + conf.dp_pullup = 0; + conf.dp_pulldown = 1; + conf.dm_pullup = 0; + conf.dm_pulldown = 1; + USB_WRAP.otg_conf = conf; +#endif + + dwc2->dctl |= DCTL_SDIS; +} + +// Be advised: audio, video and possibly other iso-ep classes use dcd_sof_enable() to enable/disable its corresponding ISR on purpose! +void dcd_sof_enable(uint8_t rhport, bool en) { + (void) rhport; + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + + _dcd_data.sof_en = en; + + if (en) { + dwc2->gintsts = GINTSTS_SOF; + dwc2->gintmsk |= GINTMSK_SOFM; + } else { + dwc2->gintmsk &= ~GINTMSK_SOFM; + } +} + +/*------------------------------------------------------------------*/ +/* DCD Endpoint port + *------------------------------------------------------------------*/ + +bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const* desc_edpt) { + TU_ASSERT(dfifo_alloc(rhport, desc_edpt->bEndpointAddress, tu_edpt_packet_size(desc_edpt))); + edpt_activate(rhport, desc_edpt); + return true; +} + +// Close all non-control endpoints, cancel all pending transfers if any. +void dcd_edpt_close_all(uint8_t rhport) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + uint8_t const ep_count = _dwc2_controller[rhport].ep_count; + + _dcd_data.allocated_epin_count = 0; + + // Disable non-control interrupt + dwc2->daintmsk = (1 << DAINTMSK_OEPM_Pos) | (1 << DAINTMSK_IEPM_Pos); + + for (uint8_t n = 1; n < ep_count; n++) { + for (uint8_t d = 0; d < 2; d++) { + dwc2_dep_t* dep = &dwc2->ep[d][n]; + if (dep->ctl & EPCTL_EPENA) { + dep->ctl |= EPCTL_SNAK | EPCTL_EPDIS; + } + xfer_status[n][1-d].max_size = 0; + } + } + +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) + _allocated_fifos = 1; +#endif + + dfifo_flush_tx(dwc2, 0x10); // all tx fifo + dfifo_flush_rx(dwc2); + + dfifo_device_init(rhport); // re-init dfifo +} + +bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) { + TU_ASSERT(dfifo_alloc(rhport, ep_addr, largest_packet_size)); + return true; +} + +bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) { + // Disable EP to clear potential incomplete transfers + edpt_disable(rhport, p_endpoint_desc->bEndpointAddress, false); + edpt_activate(rhport, p_endpoint_desc); + return true; +} + +bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes) { + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); + + xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, dir); + xfer->buffer = buffer; + xfer->ff = NULL; + xfer->total_len = total_bytes; + + // EP0 can only handle one packet + if (epnum == 0) { + _dcd_data.ep0_pending[dir] = total_bytes; + } + + // Schedule packets to be sent within interrupt + edpt_schedule_packets(rhport, epnum, dir); + + return true; +} + +// The number of bytes has to be given explicitly to allow more flexible control of how many +// bytes should be written and second to keep the return value free to give back a boolean +// success message. If total_bytes is too big, the FIFO will copy only what is available +// into the USB buffer! +bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t* ff, uint16_t total_bytes) { + // USB buffers always work in bytes so to avoid unnecessary divisions we demand item_size = 1 + TU_ASSERT(ff->item_size == 1); + + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); + + xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, dir); + xfer->buffer = NULL; + xfer->ff = ff; + xfer->total_len = total_bytes; + + // Schedule packets to be sent within interrupt + // TODO xfer fifo may only available for slave mode + edpt_schedule_packets(rhport, epnum, dir); + + return true; +} + +void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + edpt_disable(rhport, ep_addr, true); + if((tu_edpt_number(ep_addr) == 0) && dma_device_enabled(dwc2)) { + dma_setup_prepare(rhport); + } +} + +void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); + dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum]; + + // Clear stall and reset data toggle + dep->ctl &= ~EPCTL_STALL;; + dep->ctl |= EPCTL_SD0PID_SEVNFRM; +} + +//-------------------------------------------------------------------- +// Interrupt Handler +//-------------------------------------------------------------------- + +// 7.4.1 Initialization on USB Reset +static void handle_bus_reset(uint8_t rhport) { + dwc2_regs_t *dwc2 = DWC2_REG(rhport); + const uint8_t ep_count = dwc2_ep_count(dwc2); + + tu_memclr(xfer_status, sizeof(xfer_status)); + + _dcd_data.sof_en = false; + _dcd_data.allocated_epin_count = 0; + + // 1. NAK for all OUT endpoints + for (uint8_t n = 0; n < ep_count; n++) { + dwc2->epout[n].doepctl |= DOEPCTL_SNAK; + } + + // Disable all IN endpoints + for (uint8_t n = 0; n < ep_count; n++) { + if (dwc2->epin[n].diepctl & DIEPCTL_EPENA) { + dwc2->epin[n].diepctl |= DIEPCTL_SNAK | DIEPCTL_EPDIS; + } + } + + // 2. Set up interrupt mask for EP0 + dwc2->daintmsk = TU_BIT(DAINTMSK_OEPM_Pos) | TU_BIT(DAINTMSK_IEPM_Pos); + dwc2->doepmsk = DOEPMSK_STUPM | DOEPMSK_XFRCM; + dwc2->diepmsk = DIEPMSK_TOM | DIEPMSK_XFRCM; + + // 4. Set up DFIFO + dfifo_flush_tx(dwc2, 0x10); // all tx fifo + dfifo_flush_rx(dwc2); + dfifo_device_init(rhport); + + // 5. Reset device address + dwc2_dcfg_t dcfg = {.value = dwc2->dcfg}; + dcfg.address = 0; + dwc2->dcfg = dcfg.value; + + // Fixed both control EP0 size to 64 bytes + dwc2->epin[0].ctl &= ~(0x03 << DIEPCTL_MPSIZ_Pos); + dwc2->epout[0].ctl &= ~(0x03 << DOEPCTL_MPSIZ_Pos); + + xfer_status[0][TUSB_DIR_OUT].max_size = 64; + xfer_status[0][TUSB_DIR_IN].max_size = 64; + + if(dma_device_enabled(dwc2)) { + dma_setup_prepare(rhport); + } else { + dwc2->epout[0].doeptsiz |= (3 << DOEPTSIZ_STUPCNT_Pos); + } + + dwc2->gintmsk |= GINTMSK_OEPINT | GINTMSK_IEPINT; +} + +static void handle_enum_done(uint8_t rhport) { + dwc2_regs_t *dwc2 = DWC2_REG(rhport); + const dwc2_dsts_t dsts = {.value = dwc2->dsts}; + tusb_speed_t speed; + switch (dsts.enum_speed) { + case DCFG_SPEED_HIGH: + speed = TUSB_SPEED_HIGH; + break; + + case DCFG_SPEED_LOW: + speed = TUSB_SPEED_LOW; + break; + + case DCFG_SPEED_FULL_30_60MHZ: + case DCFG_SPEED_FULL_48MHZ: + default: + speed = TUSB_SPEED_FULL; + break; + } + + // TODO must update GUSBCFG_TRDT according to link speed + dcd_event_bus_reset(rhport, speed, true); +} + +#if 0 +TU_ATTR_ALWAYS_INLINE static inline void print_doepint(uint32_t doepint) { + const char* str[] = { + "XFRC", "DIS", "AHBERR", "SETUP_DONE", + "ORXED", "STATUS_RX", "SETUP_B2B", "RSV7", + "OPERR", "BNA", "RSV10", "ISODROP", + "BBLERR", "NAK", "NYET", "SETUP_RX" + }; + + for(uint32_t i=0; ififo[0]; + + // Pop control word off FIFO + const dwc2_grxstsp_t grxstsp = {.value = dwc2->grxstsp}; + const uint8_t epnum = grxstsp.ep_ch_num; + + dwc2_dep_t* epout = &dwc2->epout[epnum]; + + switch (grxstsp.packet_status) { + case GRXSTS_PKTSTS_GLOBAL_OUT_NAK: + // Global OUT NAK: do nothing + break; + + case GRXSTS_PKTSTS_SETUP_RX: { + // Setup packet received + uint32_t* setup = (uint32_t*)(uintptr_t) _dcd_usbbuf.setup_packet; + // We can receive up to three setup packets in succession, but only the last one is valid. + setup[0] = (*rx_fifo); + setup[1] = (*rx_fifo); + break; + } + + case GRXSTS_PKTSTS_SETUP_DONE: + // Setup packet done: + // After popping this out, dwc2 asserts a DOEPINT_SETUP interrupt which is handled by handle_epout_irq() + epout->doeptsiz |= (3 << DOEPTSIZ_STUPCNT_Pos); + break; + + case GRXSTS_PKTSTS_RX_DATA: { + // Out packet received + const uint16_t byte_count = grxstsp.byte_count; + xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT); + + if (byte_count) { + // Read packet off RxFIFO + if (xfer->ff) { + tu_fifo_write_n_const_addr_full_words(xfer->ff, (const void*) (uintptr_t) rx_fifo, byte_count); + } else { + dfifo_read_packet(dwc2, xfer->buffer, byte_count); + xfer->buffer += byte_count; + } + + // short packet, minus remaining bytes (xfer_size) + if (byte_count < xfer->max_size) { + const dwc2_ep_tsize_t tsiz = {.value = epout->tsiz}; + xfer->total_len -= tsiz.xfer_size; + if (epnum == 0) { + xfer->total_len -= _dcd_data.ep0_pending[TUSB_DIR_OUT]; + _dcd_data.ep0_pending[TUSB_DIR_OUT] = 0; + } + } + } + break; + } + + case GRXSTS_PKTSTS_RX_COMPLETE: + // Out packet done + // After this entry is popped from the receive FIFO, dwc2 asserts a Transfer Completed interrupt on + // the specified OUT endpoint which will be handled by handle_epout_irq() + break; + + default: break; + } +} + +static void handle_epout_slave(uint8_t rhport, uint8_t epnum, dwc2_doepint_t doepint_bm) { + if (doepint_bm.setup_phase_done) { + dcd_event_setup_received(rhport, _dcd_usbbuf.setup_packet, true); + return; + } + + // Normal OUT transfer complete + if (doepint_bm.xfer_complete) { + // only handle data skip if it is setup or status related + // Note: even though (xfer_complete + status_phase_rx) is for buffered DMA only, for STM32L47x (dwc2 v3.00a) they + // can is set when GRXSTS_PKTSTS_SETUP_RX is popped therefore they can bet set before/together with setup_phase_done + if (!doepint_bm.status_phase_rx && !doepint_bm.setup_packet_rx) { + xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT); + + if ((epnum == 0) && _dcd_data.ep0_pending[TUSB_DIR_OUT]) { + // EP0 can only handle one packet, Schedule another packet to be received. + edpt_schedule_packets(rhport, epnum, TUSB_DIR_OUT); + } else { + dcd_event_xfer_complete(rhport, epnum, xfer->total_len, XFER_RESULT_SUCCESS, true); + } + } + } +} + +static void handle_epin_slave(uint8_t rhport, uint8_t epnum, dwc2_diepint_t diepint_bm) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + dwc2_dep_t* epin = &dwc2->epin[epnum]; + xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_IN); + + if (diepint_bm.xfer_complete) { + if ((epnum == 0) && _dcd_data.ep0_pending[TUSB_DIR_IN]) { + // EP0 can only handle one packet. Schedule another packet to be transmitted. + edpt_schedule_packets(rhport, epnum, TUSB_DIR_IN); + } else { + dcd_event_xfer_complete(rhport, epnum | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true); + } + } + + // TX FIFO empty bit is read-only. It will only be cleared by hardware when written bytes is more than + // - 64 bytes or + // - Half/Empty of TX FIFO size (configured by GAHBCFG.TXFELVL) + if (diepint_bm.txfifo_empty && (dwc2->diepempmsk & (1 << epnum))) { + dwc2_ep_tsize_t tsiz = {.value = epin->tsiz}; + const uint16_t remain_packets = tsiz.packet_count; + + // Process every single packet (only whole packets can be written to fifo) + for (uint16_t i = 0; i < remain_packets; i++) { + tsiz.value = epin->tsiz; + const uint16_t remain_bytes = (uint16_t) tsiz.xfer_size; + const uint16_t xact_bytes = tu_min16(remain_bytes, xfer->max_size); + + // Check if dtxfsts has enough space available + if (xact_bytes > ((epin->dtxfsts & DTXFSTS_INEPTFSAV_Msk) << 2)) { + break; + } + + // Push packet to Tx-FIFO + if (xfer->ff) { + volatile uint32_t* tx_fifo = dwc2->fifo[epnum]; + tu_fifo_read_n_const_addr_full_words(xfer->ff, (void*)(uintptr_t)tx_fifo, xact_bytes); + } else { + dfifo_write_packet(dwc2, epnum, xfer->buffer, xact_bytes); + xfer->buffer += xact_bytes; + } + } + + // Turn off TXFE if all bytes are written. + tsiz.value = epin->tsiz; + if (tsiz.xfer_size == 0) { + dwc2->diepempmsk &= ~(1 << epnum); + } + } +} +#endif + +#if CFG_TUD_DWC2_DMA_ENABLE +static void handle_epout_dma(uint8_t rhport, uint8_t epnum, dwc2_doepint_t doepint_bm) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + + if (doepint_bm.setup_phase_done) { + dma_setup_prepare(rhport); + dcd_dcache_invalidate(_dcd_usbbuf.setup_packet, 8); + dcd_event_setup_received(rhport, _dcd_usbbuf.setup_packet, true); + return; + } + + // OUT XFER complete + if (doepint_bm.xfer_complete) { + // only handle data skip if it is setup or status related + // Normal OUT transfer complete + if (!doepint_bm.status_phase_rx && !doepint_bm.setup_packet_rx) { + if ((epnum == 0) && _dcd_data.ep0_pending[TUSB_DIR_OUT]) { + // EP0 can only handle one packet Schedule another packet to be received. + edpt_schedule_packets(rhport, epnum, TUSB_DIR_OUT); + } else { + dwc2_dep_t* epout = &dwc2->epout[epnum]; + xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_OUT); + + // determine actual received bytes + const dwc2_ep_tsize_t tsiz = {.value = epout->tsiz}; + const uint16_t remain = tsiz.xfer_size; + xfer->total_len -= remain; + + // this is ZLP, so prepare EP0 for next setup + // TODO use status phase rx + if(epnum == 0 && xfer->total_len == 0) { + dma_setup_prepare(rhport); + } + + dcd_dcache_invalidate(xfer->buffer, xfer->total_len); + dcd_event_xfer_complete(rhport, epnum, xfer->total_len, XFER_RESULT_SUCCESS, true); + } + } + } +} + +static void handle_epin_dma(uint8_t rhport, uint8_t epnum, dwc2_diepint_t diepint_bm) { + xfer_ctl_t* xfer = XFER_CTL_BASE(epnum, TUSB_DIR_IN); + + if (diepint_bm.xfer_complete) { + if ((epnum == 0) && _dcd_data.ep0_pending[TUSB_DIR_IN]) { + // EP0 can only handle one packet. Schedule another packet to be transmitted. + edpt_schedule_packets(rhport, epnum, TUSB_DIR_IN); + } else { + if(epnum == 0) { + dma_setup_prepare(rhport); + } + dcd_event_xfer_complete(rhport, epnum | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true); + } + } +} +#endif + +static void handle_ep_irq(uint8_t rhport, uint8_t dir) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const bool is_dma = dma_device_enabled(dwc2); + const uint8_t ep_count = dwc2_ep_count(dwc2); + const uint8_t daint_offset = (dir == TUSB_DIR_IN) ? DAINT_IEPINT_Pos : DAINT_OEPINT_Pos; + dwc2_dep_t* ep_base = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][0]; + + // DAINT for a given EP clears when DEPINTx is cleared. + // EPINT will be cleared when DAINT bits are cleared. + for (uint8_t epnum = 0; epnum < ep_count; epnum++) { + if (dwc2->daint & TU_BIT(daint_offset + epnum)) { + dwc2_dep_t* epout = &ep_base[epnum]; + union { + uint32_t value; + dwc2_diepint_t diepint_bm; + dwc2_doepint_t doepint_bm; + } intr; + intr.value = epout->intr; + + epout->intr = intr.value; // Clear interrupt + + if (is_dma) { + #if CFG_TUD_DWC2_DMA_ENABLE + if (dir == TUSB_DIR_IN) { + handle_epin_dma(rhport, epnum, intr.diepint_bm); + } else { + handle_epout_dma(rhport, epnum, intr.doepint_bm); + } + #endif + } else { + #if CFG_TUD_DWC2_SLAVE_ENABLE + if (dir == TUSB_DIR_IN) { + handle_epin_slave(rhport, epnum, intr.diepint_bm); + } else { + handle_epout_slave(rhport, epnum, intr.doepint_bm); + } + #endif + } + } + } +} + +/* Interrupt Hierarchy + DIEPINT DIEPINT + \ / + \ / + DAINT + / \ + / \ + GINTSTS: OEPInt IEPInt | USBReset | EnumDone | USBSusp | WkUpInt | OTGInt | SOF | RXFLVL + + Note: when OTG_MULTI_PROC_INTRPT = 1, Device Each endpoint interrupt deachint/deachmsk/diepeachmsk/doepeachmsk + are combined to generate dedicated interrupt line for each endpoint. + */ +void dcd_int_handler(uint8_t rhport) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + + const uint32_t gintmask = dwc2->gintmsk; + const uint32_t gintsts = dwc2->gintsts & gintmask; + + if (gintsts & GINTSTS_USBRST) { + // USBRST is start of reset. + dwc2->gintsts = GINTSTS_USBRST; +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) + _allocated_fifos = 1; +#endif + handle_bus_reset(rhport); + } + + if (gintsts & GINTSTS_ENUMDNE) { + // ENUMDNE is the end of reset where speed of the link is detected + dwc2->gintsts = GINTSTS_ENUMDNE; + handle_enum_done(rhport); + } + + if (gintsts & GINTSTS_USBSUSP) { + dwc2->gintsts = GINTSTS_USBSUSP; + //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true); + dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true); +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) + _allocated_fifos = 1; +#endif + } + + if (gintsts & GINTSTS_WKUINT) { + dwc2->gintsts = GINTSTS_WKUINT; + dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true); + } + + // TODO check GINTSTS_DISCINT for disconnect detection + // if(int_status & GINTSTS_DISCINT) + + if (gintsts & GINTSTS_OTGINT) { + // OTG INT bit is read-only + const uint32_t otg_int = dwc2->gotgint; + + if (otg_int & GOTGINT_SEDET) { + dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true); +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) + _allocated_fifos = 1; +#endif + } + + dwc2->gotgint = otg_int; + } + + if(gintsts & GINTSTS_SOF) { + dwc2->gintsts = GINTSTS_SOF; + const uint32_t frame = (dwc2->dsts & DSTS_FNSOF) >> DSTS_FNSOF_Pos; + + // Disable SOF interrupt if SOF was not explicitly enabled since SOF was used for remote wakeup detection + if (!_dcd_data.sof_en) { + dwc2->gintmsk &= ~GINTMSK_SOFM; + } + + dcd_event_sof(rhport, frame, true); + } + +#if CFG_TUD_DWC2_SLAVE_ENABLE + // RxFIFO non-empty interrupt handling. + if (gintsts & GINTSTS_RXFLVL) { + // RXFLVL bit is read-only + dwc2->gintmsk &= ~GINTMSK_RXFLVLM; // disable RXFLVL interrupt while reading + + do { + handle_rxflvl_irq(rhport); // read all packets + } while(dwc2->gintsts & GINTSTS_RXFLVL); + + dwc2->gintmsk |= GINTMSK_RXFLVLM; + } +#endif + + // OUT endpoint interrupt handling. + if (gintsts & GINTSTS_OEPINT) { + // OEPINT is read-only, clear using DOEPINTn + handle_ep_irq(rhport, TUSB_DIR_OUT); + } + + // IN endpoint interrupt handling. + if (gintsts & GINTSTS_IEPINT) { + // IEPINT bit read-only, clear using DIEPINTn + handle_ep_irq(rhport, TUSB_DIR_IN); + } +} + +#if CFG_TUD_TEST_MODE +void dcd_enter_test_mode(uint8_t rhport, tusb_feature_test_mode_t test_selector) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + + // Enable the test mode + dwc2->dctl = (dwc2->dctl & ~DCTL_TCTL_Msk) | (((uint8_t) test_selector) << DCTL_TCTL_Pos); +} +#endif + +#endif diff --git a/components/fb_gfx/fb_gfx.c b/components/fb_gfx/fb_gfx.c index 42c1721f2..ab373c16f 100644 --- a/components/fb_gfx/fb_gfx.c +++ b/components/fb_gfx/fb_gfx.c @@ -38,17 +38,24 @@ typedef struct { // Data stored for FONT AS A WHOLE: void fb_gfx_fillRect(fb_data_t *fb, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color) { - int32_t line_step = (fb->width - w) * 3; - uint8_t *data = fb->data + ((x + (y * fb->width)) * 3); + int32_t line_step = (fb->width - w) * fb->bytes_per_pixel; + uint8_t *data = fb->data + ((x + (y * fb->width)) * fb->bytes_per_pixel); uint8_t c0 = color >> 16; uint8_t c1 = color >> 8; uint8_t c2 = color; for (int i=0; ibytes_per_pixel == 2){ + data[0] = c1; + data[1] = c2; + } else if(fb->bytes_per_pixel == 1){ + data[0] = c2; + } else { + data[0] = c0; + data[1] = c1; + data[2] = c2; + } + data+=fb->bytes_per_pixel; } data += line_step; } @@ -108,7 +115,7 @@ uint8_t fb_gfx_putc(fb_data_t *fb, int32_t x, int32_t y, uint32_t color, unsigne return xa; } -uint32_t fb_gfx_print(fb_data_t *fb, int x, int y, uint32_t color, const char * str) +uint32_t fb_gfx_print(fb_data_t *fb, int32_t x, int32_t y, uint32_t color, const char * str) { uint32_t l = 0; int xc = x, yc = y, lc = fb->width - gfxFont->glyph[0].xAdvance; diff --git a/components/fb_gfx/include/fb_gfx.h b/components/fb_gfx/include/fb_gfx.h index 079ff7bfe..158c80f6b 100644 --- a/components/fb_gfx/include/fb_gfx.h +++ b/components/fb_gfx/include/fb_gfx.h @@ -19,7 +19,7 @@ extern "C" { #endif typedef enum { - FB_RGB888, FB_BGR888, FB_RGB565, FB_BGR565 + FB_RGB888, FB_BGR888, FB_RGB565, FB_BGR565, FB_GRAY } fb_format_t; typedef struct { diff --git a/configs/builds.json b/configs/builds.json new file mode 100644 index 000000000..ddfb8e4f8 --- /dev/null +++ b/configs/builds.json @@ -0,0 +1,164 @@ +{ + "mem_variants_files":[ + { + "file":"libspi_flash.a", + "src":"build/esp-idf/spi_flash/libspi_flash.a", + "out":"lib/libspi_flash.a", + "targets":["esp32","esp32c2","esp32c3","esp32s2","esp32s3","esp32c6","esp32h2","esp32p4"] + }, + { + "file":"libesp_psram.a", + "src":"build/esp-idf/esp_psram/libesp_psram.a", + "out":"lib/libesp_psram.a", + "targets":["esp32s3"] + }, + { + "file":"libesp_system.a", + "src":"build/esp-idf/esp_system/libesp_system.a", + "out":"lib/libesp_system.a", + "targets":["esp32s3"] + }, + { + "file":"libfreertos.a", + "src":"build/esp-idf/freertos/libfreertos.a", + "out":"lib/libfreertos.a", + "targets":["esp32s3"] + }, + { + "file":"libbootloader_support.a", + "src":"build/esp-idf/bootloader_support/libbootloader_support.a", + "out":"lib/libbootloader_support.a", + "targets":["esp32s3"] + }, + { + "file":"libesp_hw_support.a", + "src":"build/esp-idf/esp_hw_support/libesp_hw_support.a", + "out":"lib/libesp_hw_support.a", + "targets":["esp32s3"] + }, + { + "file":"sections.ld", + "src":"build/esp-idf/esp_system/ld/sections.ld", + "out":"ld/sections.ld", + "targets":["esp32s3"] + } + ], + "targets":[ + { + "target": "esp32p4", + "features":["qio_ram"], + "idf_libs":["qio","80m"], + "bootloaders":[ + ["qio","80m"], + ["dio","80m"], + ["qio","40m"], + ["dio","40m"] + ], + "mem_variants":[ + ["dio","80m"] + ] + }, + { + "target": "esp32c2", + "skip": 1, + "features":[], + "idf_libs":["qio","60m"], + "bootloaders":[ + ["qio","60m"], + ["dio","60m"], + ["qio","30m"], + ["dio","30m"] + ], + "mem_variants":[ + ["dio","60m"] + ] + }, + { + "target": "esp32h2", + "features":[], + "idf_libs":["qio","64m"], + "bootloaders":[ + ["qio","64m"], + ["dio","64m"], + ["qio","16m"], + ["dio","16m"] + ], + "mem_variants":[ + ["dio","64m"] + ] + }, + { + "target": "esp32c6", + "features":[], + "idf_libs":["qio","80m"], + "bootloaders":[ + ["qio","80m"], + ["dio","80m"], + ["qio","40m"], + ["dio","40m"] + ], + "mem_variants":[ + ["dio","80m"] + ] + }, + { + "target": "esp32c3", + "features":[], + "idf_libs":["qio","80m"], + "bootloaders":[ + ["qio","80m"], + ["dio","80m"], + ["qio","40m"], + ["dio","40m"] + ], + "mem_variants":[ + ["dio","80m"] + ] + }, + { + "target": "esp32", + "features":["qio_ram"], + "idf_libs":["qio","80m"], + "bootloaders":[ + ["qio","80m"], + ["dio","80m"], + ["qio","40m"], + ["dio","40m"] + ], + "mem_variants":[ + ["dio","80m"] + ] + }, + { + "target": "esp32s2", + "features":["qio_ram"], + "idf_libs":["qio","80m"], + "bootloaders":[ + ["qio","80m"], + ["dio","80m"], + ["qio","40m"], + ["dio","40m"] + ], + "mem_variants":[ + ["dio","80m"] + ] + }, + { + "target": "esp32s3", + "features":["esp_sr"], + "idf_libs":["qio","80m","qio_ram"], + "bootloaders":[ + ["qio","120m","qio_ram"], + ["qio","80m","qio_ram"], + ["dio","80m","qio_ram"], + ["opi","80m","opi_ram"] + ], + "mem_variants":[ + ["qio","80m","opi_ram"], + ["dio","80m","qio_ram"], + ["dio","80m","opi_ram"], + ["opi","80m","opi_ram"] + ] + } + ] +} diff --git a/configs/defconfig.120m b/configs/defconfig.120m new file mode 100644 index 000000000..a21a8285e --- /dev/null +++ b/configs/defconfig.120m @@ -0,0 +1,2 @@ +CONFIG_ESPTOOLPY_FLASHFREQ_120M=y +CONFIG_SPIRAM_SPEED_120M=y \ No newline at end of file diff --git a/configs/defconfig.16m b/configs/defconfig.16m new file mode 100644 index 000000000..b7916fbce --- /dev/null +++ b/configs/defconfig.16m @@ -0,0 +1 @@ +CONFIG_ESPTOOLPY_FLASHFREQ_16M=y \ No newline at end of file diff --git a/configs/defconfig.30m b/configs/defconfig.30m new file mode 100644 index 000000000..f915b230f --- /dev/null +++ b/configs/defconfig.30m @@ -0,0 +1 @@ +CONFIG_ESPTOOLPY_FLASHFREQ_30M=y diff --git a/configs/defconfig.40m b/configs/defconfig.40m new file mode 100644 index 000000000..079a0336a --- /dev/null +++ b/configs/defconfig.40m @@ -0,0 +1,2 @@ +CONFIG_ESPTOOLPY_FLASHFREQ_40M=y +CONFIG_SPIRAM_SPEED_40M=y \ No newline at end of file diff --git a/configs/defconfig.60m b/configs/defconfig.60m new file mode 100644 index 000000000..797665f52 --- /dev/null +++ b/configs/defconfig.60m @@ -0,0 +1 @@ +CONFIG_ESPTOOLPY_FLASHFREQ_60M=y diff --git a/configs/defconfig.64m b/configs/defconfig.64m new file mode 100644 index 000000000..c33173f13 --- /dev/null +++ b/configs/defconfig.64m @@ -0,0 +1 @@ +CONFIG_ESPTOOLPY_FLASHFREQ_64M=y \ No newline at end of file diff --git a/configs/defconfig.80m b/configs/defconfig.80m new file mode 100644 index 000000000..38980b0d9 --- /dev/null +++ b/configs/defconfig.80m @@ -0,0 +1,2 @@ +CONFIG_ESPTOOLPY_FLASHFREQ_80M=y +CONFIG_SPIRAM_SPEED_80M=y \ No newline at end of file diff --git a/configs/defconfig.common b/configs/defconfig.common new file mode 100644 index 000000000..48baf5081 --- /dev/null +++ b/configs/defconfig.common @@ -0,0 +1,142 @@ +CONFIG_AUTOSTART_ARDUINO=y +# CONFIG_WS2812_LED_ENABLE is not set +CONFIG_ARDUHAL_ESP_LOG=y +CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y +CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y +CONFIG_BT_BLE_BLUFI_ENABLE=y +CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y +CONFIG_BT_BTC_TASK_STACK_SIZE=8192 +CONFIG_BT_BTU_TASK_STACK_SIZE=8192 +CONFIG_BLE_MESH=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_CXX_EXCEPTIONS=y +CONFIG_COMPILER_STACK_CHECK_MODE_NORM=y +CONFIG_COMPILER_WARN_WRITE_STRINGS=y +CONFIG_ESP_HTTPS_SERVER_ENABLE=y +CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH=y +CONFIG_ESP_INT_WDT_TIMEOUT_MS=300 +CONFIG_ESP_IPC_TASK_STACK_SIZE=1024 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096 +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2048 +CONFIG_ESP_TASK_WDT_PANIC=y +CONFIG_ESP_TIMER_TASK_STACK_SIZE=8192 +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESP_WIFI_FTM_ENABLE=y +CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=8 +CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM=8 +CONFIG_ESP_WIFI_CACHE_TX_BUFFER_NUM=16 +CONFIG_ESP_WIFI_CSI_ENABLED=y +CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y +# CONFIG_ESP_WIFI_IRAM_OPT is not set +# CONFIG_ESP_WIFI_RX_IRAM_OPT is not set +CONFIG_ESP_PHY_REDUCE_TX_POWER=y +CONFIG_ETH_SPI_ETHERNET_DM9051=y +CONFIG_ETH_SPI_ETHERNET_W5500=y +CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL=y +CONFIG_FATFS_CODEPAGE_850=y +CONFIG_FATFS_LFN_STACK=y +# CONFIG_FATFS_API_ENCODING_ANSI_OEM is not set +CONFIG_FATFS_API_ENCODING_UTF_8=y +CONFIG_FATFS_USE_LABEL=y +# CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT is not set +CONFIG_FMB_TIMER_PORT_ENABLED=y +CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y +# CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION is not set +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024 +CONFIG_FREERTOS_USE_TRACE_FACILITY=y +CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y +CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y +CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y +CONFIG_HEAP_POISONING_LIGHT=y +CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024 +CONFIG_HTTPD_WS_SUPPORT=y +# CONFIG_LOG_COLORS is not set +CONFIG_LWIP_ETHARP_TRUST_IP_MAC=y +# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set +CONFIG_LWIP_TCP_SYNMAXRTX=6 +CONFIG_LWIP_TCP_MSS=1436 +CONFIG_LWIP_TCP_RTO_TIME=3000 +CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096 +CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0=y +CONFIG_LWIP_MAX_SOCKETS=16 +CONFIG_LWIP_IP_FORWARD=y +CONFIG_LWIP_IPV4_NAPT=y +CONFIG_LWIP_DHCP_RESTORE_LAST_IP=n +CONFIG_LWIP_DHCP_OPTIONS_LEN=128 +CONFIG_LWIP_SNTP_MAX_SERVERS=3 +CONFIG_LWIP_SNTP_UPDATE_DELAY=10800000 +CONFIG_LWIP_DHCP_GET_NTP_SRV=y +CONFIG_LWIP_IPV6_AUTOCONFIG=y +CONFIG_LWIP_IPV6_DHCP6=y +CONFIG_LWIP_IPV6_RDNSS_MAX_DNS_SERVERS=2 +CONFIG_LWIP_PPP_SUPPORT=y +CONFIG_LWIP_PPP_NOTIFY_PHASE_SUPPORT=y +CONFIG_LWIP_PPP_PAP_SUPPORT=y +CONFIG_LWIP_PPP_ENABLE_IPV6=n +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y +CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_DEFAULT=y +CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_DEFAULT=y +CONFIG_LWIP_MULTICAST_PING=y +CONFIG_LWIP_BROADCAST_PING=y +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 +CONFIG_MBEDTLS_PSK_MODES=y +CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y +CONFIG_MBEDTLS_ECJPAKE_C=y +CONFIG_MBEDTLS_HKDF_C=y +CONFIG_MBEDTLS_CAMELLIA_C=y +CONFIG_MBEDTLS_GCM_SUPPORT_NON_AES_CIPHER=y +# CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN is not set +CONFIG_MBEDTLS_SSL_PROTO_DTLS=y +CONFIG_OPENSSL_ASSERT_DO_NOTHING=y +CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=2048 +CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y +CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=10 +CONFIG_SPI_FLASH_ERASE_YIELD_TICKS=2 +CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE=4096 +# CONFIG_SPI_MASTER_ISR_IN_IRAM is not set +# CONFIG_SPI_SLAVE_ISR_IN_IRAM is not set +CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=4096 +CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=0 +CONFIG_ESP_RMAKER_SKIP_VERSION_CHECK=y +CONFIG_ESP_RMAKER_USER_ID_CHECK=y +CONFIG_ESP_INSIGHTS_ENABLED=y +CONFIG_ESP_INSIGHTS_COREDUMP_ENABLE=n +CONFIG_ESP_INSIGHTS_TRANSPORT_HTTPS=y +CONFIG_DIAG_LOG_DROP_WIFI_LOGS=y +CONFIG_DIAG_ENABLE_METRICS=y +CONFIG_DIAG_ENABLE_HEAP_METRICS=y +CONFIG_DIAG_ENABLE_WIFI_METRICS=y +CONFIG_DIAG_ENABLE_VARIABLES=y +CONFIG_DIAG_ENABLE_NETWORK_VARIABLES=y +CONFIG_ESP_COREDUMP_ENABLE=y +CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y +CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF=y +CONFIG_ESP_COREDUMP_CHECKSUM_CRC32=y +CONFIG_ESP_COREDUMP_MAX_TASKS_NUM=64 +CONFIG_ESP_COREDUMP_STACK_SIZE=0 +CONFIG_MBEDTLS_DYNAMIC_BUFFER=y +CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y +CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y +CONFIG_I2S_ISR_IRAM_SAFE=y +# +# Matter Settings +# +# Disable Matter BLE +CONFIG_ENABLE_CHIPOBLE=n +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=n +# ESP Insights +CONFIG_ENABLE_ESP_INSIGHTS_TRACE=n +# Use compact attribute storage mode +CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y + +#TinyUSB Config +CONFIG_TINYUSB_CDC_MAX_PORTS=2 +CONFIG_USB_HOST_HUBS_SUPPORTED=y +CONFIG_USB_HOST_HUB_MULTI_LEVEL=y +CONFIG_USB_HOST_HW_BUFFER_BIAS_PERIODIC_OUT=y + +# Zigbee Config +CONFIG_ZB_ENABLED=y diff --git a/configs/defconfig.debug_debug b/configs/defconfig.debug_debug new file mode 100644 index 000000000..3cec23da4 --- /dev/null +++ b/configs/defconfig.debug_debug @@ -0,0 +1,2 @@ +CONFIG_BOOTLOADER_LOG_LEVEL_INFO=y +CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y diff --git a/configs/defconfig.debug_default b/configs/defconfig.debug_default new file mode 100644 index 000000000..c1858126e --- /dev/null +++ b/configs/defconfig.debug_default @@ -0,0 +1,2 @@ +CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y +CONFIG_LOG_DEFAULT_LEVEL_ERROR=y diff --git a/configs/defconfig.debug_error b/configs/defconfig.debug_error new file mode 100644 index 000000000..c1858126e --- /dev/null +++ b/configs/defconfig.debug_error @@ -0,0 +1,2 @@ +CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y +CONFIG_LOG_DEFAULT_LEVEL_ERROR=y diff --git a/configs/defconfig.debug_info b/configs/defconfig.debug_info new file mode 100644 index 000000000..312255bd2 --- /dev/null +++ b/configs/defconfig.debug_info @@ -0,0 +1,2 @@ +CONFIG_BOOTLOADER_LOG_LEVEL_INFO=y +CONFIG_LOG_DEFAULT_LEVEL_INFO=y diff --git a/configs/defconfig.debug_none b/configs/defconfig.debug_none new file mode 100644 index 000000000..941e46f21 --- /dev/null +++ b/configs/defconfig.debug_none @@ -0,0 +1,2 @@ +CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y +CONFIG_LOG_DEFAULT_LEVEL_NONE=y diff --git a/configs/defconfig.debug_verbose b/configs/defconfig.debug_verbose new file mode 100644 index 000000000..27413d5d8 --- /dev/null +++ b/configs/defconfig.debug_verbose @@ -0,0 +1,2 @@ +CONFIG_BOOTLOADER_LOG_LEVEL_INFO=y +CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=y diff --git a/configs/defconfig.debug_warning b/configs/defconfig.debug_warning new file mode 100644 index 000000000..5d306f463 --- /dev/null +++ b/configs/defconfig.debug_warning @@ -0,0 +1,2 @@ +CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y +CONFIG_LOG_DEFAULT_LEVEL_WARN=y diff --git a/configs/defconfig.dio b/configs/defconfig.dio new file mode 100644 index 000000000..17c6c1faa --- /dev/null +++ b/configs/defconfig.dio @@ -0,0 +1 @@ +CONFIG_ESPTOOLPY_FLASHMODE_DIO=y \ No newline at end of file diff --git a/configs/defconfig.dout b/configs/defconfig.dout new file mode 100644 index 000000000..48d652cc2 --- /dev/null +++ b/configs/defconfig.dout @@ -0,0 +1 @@ +CONFIG_ESPTOOLPY_FLASHMODE_DOUT=y \ No newline at end of file diff --git a/configs/defconfig.esp32 b/configs/defconfig.esp32 new file mode 100644 index 000000000..db01aeab3 --- /dev/null +++ b/configs/defconfig.esp32 @@ -0,0 +1,22 @@ +CONFIG_BTDM_CTRL_MODE_BTDM=y +CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE=20 +CONFIG_BT_ENABLED=y +CONFIG_BT_CLASSIC_ENABLED=y +CONFIG_BT_A2DP_ENABLE=y +CONFIG_BT_SPP_ENABLED=y +CONFIG_BT_HFP_ENABLE=y +CONFIG_BT_STACK_NO_LOG=y +CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y +CONFIG_SPIRAM=y +CONFIG_SPIRAM_OCCUPY_HSPI_HOST=y +CONFIG_ULP_COPROC_ENABLED=y +# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set +CONFIG_FREERTOS_FPU_IN_ISR=y +# CONFIG_USE_WAKENET is not set +# CONFIG_USE_MULTINET is not set +CONFIG_TWAI_ERRATA_FIX_BUS_OFF_REC=y +CONFIG_TWAI_ERRATA_FIX_TX_INTR_LOST=y +CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID=y +CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT=y +CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 diff --git a/configs/defconfig.esp32c2 b/configs/defconfig.esp32c2 new file mode 100644 index 000000000..11c0100a0 --- /dev/null +++ b/configs/defconfig.esp32c2 @@ -0,0 +1,8 @@ +CONFIG_XTAL_FREQ_26=y +CONFIG_XTAL_FREQ=26 +CONFIG_BT_ENABLED=y +CONFIG_BT_BLE_BLUFI_ENABLE=y +CONFIG_RTC_CLK_CAL_CYCLES=576 +# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 +CONFIG_ESP32C2_REV2_DEVELOPMENT=y diff --git a/configs/defconfig.esp32c3 b/configs/defconfig.esp32c3 new file mode 100644 index 000000000..1baf62540 --- /dev/null +++ b/configs/defconfig.esp32c3 @@ -0,0 +1,9 @@ +CONFIG_RTC_CLK_CAL_CYCLES=576 +# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 +CONFIG_BT_ENABLED=y +CONFIG_ESP_WIFI_11KV_SUPPORT=y +CONFIG_ESP_WIFI_SCAN_CACHE=y +CONFIG_ESP_WIFI_MBO_SUPPORT=y +CONFIG_ESP_WIFI_11R_SUPPORT=y +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 diff --git a/configs/defconfig.esp32c6 b/configs/defconfig.esp32c6 new file mode 100644 index 000000000..d0e2b7bbd --- /dev/null +++ b/configs/defconfig.esp32c6 @@ -0,0 +1,50 @@ +CONFIG_BT_ENABLED=y +CONFIG_BT_BLE_BLUFI_ENABLE=y +CONFIG_RTC_CLK_CAL_CYCLES=576 +# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 +# This Enables RISCV LP for C6 - but it can't be used within Arduino at this time. +#CONFIG_ULP_COPROC_ENABLED=y +#CONFIG_ULP_COPROC_LP_CORE=y +#CONFIG_ULP_COPROC_RESERVE_MEM=4096 + +# +# OpenThread +# +CONFIG_OPENTHREAD_ENABLED=y +# Border Router disabled +# CONFIG_OPENTHREAD_BORDER_ROUTER=y +# CONFIG_OPENTHREAD_RADIO_SPINEL_UART=y + +# DNS64 and NAT64 will be disabled for a while +# OT IDF issue https://github.com/espressif/esp-idf/issues/15069 +# CONFIG_OPENTHREAD_DNS64_CLIENT=y + +# Radio for RPC +# CONFIG_OPENTHREAD_RADIO=y +# CONFIG_OPENTHREAD_RADIO_NATIVE=y +# CONFIG_OPENTHREAD_DIAG=n +CONFIG_OPENTHREAD_COMMISSIONER=y +CONFIG_OPENTHREAD_JOINER=y +CONFIG_OPENTHREAD_CLI=y +CONFIG_OPENTHREAD_SRP_CLIENT=y +CONFIG_OPENTHREAD_DNS_CLIENT=y +# Default dataset for quick start +CONFIG_OPENTHREAD_NETWORK_NAME="OpenThread-ESP" +CONFIG_OPENTHREAD_MESH_LOCAL_PREFIX="fd00:db8:a0:0::/64" +CONFIG_OPENTHREAD_NETWORK_CHANNEL=15 +CONFIG_OPENTHREAD_NETWORK_PANID=0x1234 +CONFIG_OPENTHREAD_NETWORK_EXTPANID="dead00beef00cafe" +CONFIG_OPENTHREAD_NETWORK_MASTERKEY="00112233445566778899aabbccddeeff" +CONFIG_OPENTHREAD_NETWORK_PSKC="104810e2315100afd6bc9215a6bfac53" +# end of OpenThread + +# Matter shall use only WiFi +CONFIG_ENABLE_MATTER_OVER_THREAD=n + +# +# Zigbee +# +CONFIG_ZB_ZED=y +CONFIG_ZB_RADIO_NATIVE=y +# end of Zigbee diff --git a/configs/defconfig.esp32h2 b/configs/defconfig.esp32h2 new file mode 100644 index 000000000..024120d34 --- /dev/null +++ b/configs/defconfig.esp32h2 @@ -0,0 +1,43 @@ +CONFIG_BT_ENABLED=y +CONFIG_BT_BLE_BLUFI_ENABLE=y +CONFIG_RTC_CLK_CAL_CYCLES=576 +# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=2304 + +# +# OpenThread +# +CONFIG_OPENTHREAD_ENABLED=y +# Border Router disabled +# CONFIG_OPENTHREAD_BORDER_ROUTER=y +# CONFIG_OPENTHREAD_RADIO_SPINEL_UART=y + +# DNS64 and NAT64 will be disabled for a while +# OT IDF issue https://github.com/espressif/esp-idf/issues/15069 +# CONFIG_OPENTHREAD_DNS64_CLIENT=y + +# Radio for RPC +# CONFIG_OPENTHREAD_RADIO=y +# CONFIG_OPENTHREAD_RADIO_NATIVE=y +# CONFIG_OPENTHREAD_DIAG=n +CONFIG_OPENTHREAD_COMMISSIONER=y +CONFIG_OPENTHREAD_JOINER=y +CONFIG_OPENTHREAD_CLI=y +CONFIG_OPENTHREAD_SRP_CLIENT=y +CONFIG_OPENTHREAD_DNS_CLIENT=y +# Default dataset for quick start +CONFIG_OPENTHREAD_NETWORK_NAME="OpenThread-ESP" +CONFIG_OPENTHREAD_MESH_LOCAL_PREFIX="fd00:db8:a0:0::/64" +CONFIG_OPENTHREAD_NETWORK_CHANNEL=15 +CONFIG_OPENTHREAD_NETWORK_PANID=0x1234 +CONFIG_OPENTHREAD_NETWORK_EXTPANID="dead00beef00cafe" +CONFIG_OPENTHREAD_NETWORK_MASTERKEY="00112233445566778899aabbccddeeff" +CONFIG_OPENTHREAD_NETWORK_PSKC="104810e2315100afd6bc9215a6bfac53" +# end of OpenThread + +# +# Zigbee +# +CONFIG_ZB_ZED=y +CONFIG_ZB_RADIO_NATIVE=y +# end of Zigbee diff --git a/configs/defconfig.esp32p4 b/configs/defconfig.esp32p4 new file mode 100644 index 000000000..9cc5e8392 --- /dev/null +++ b/configs/defconfig.esp32p4 @@ -0,0 +1,19 @@ +CONFIG_IDF_EXPERIMENTAL_FEATURES=y +CONFIG_SPIRAM=y +CONFIG_SPIRAM_SPEED_200M=y +# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set +CONFIG_LWIP_TCP_SACK_OUT=y + +CONFIG_SLAVE_IDF_TARGET_ESP32C6=y +CONFIG_ESP_SDIO_BUS_WIDTH=4 +CONFIG_ESP_SDIO_CLOCK_FREQ_KHZ=40000 +CONFIG_ESP_SDIO_PIN_CMD=19 +CONFIG_ESP_SDIO_PIN_CLK=18 +CONFIG_ESP_SDIO_PIN_D0=14 +CONFIG_ESP_SDIO_PIN_D1=15 +CONFIG_ESP_SDIO_PIN_D2=16 +CONFIG_ESP_SDIO_PIN_D3=17 + +# RGB Display Optimizations +CONFIG_LCD_RGB_ISR_IRAM_SAFE=y +CONFIG_LCD_RGB_RESTART_IN_VSYNC=y diff --git a/configs/defconfig.esp32s2 b/configs/defconfig.esp32s2 new file mode 100644 index 000000000..3b0af548a --- /dev/null +++ b/configs/defconfig.esp32s2 @@ -0,0 +1,17 @@ +CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_SPIRAM=y +CONFIG_ESP32S2_KEEP_USB_ALIVE=y +# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set +# CONFIG_USE_WAKENET is not set +# CONFIG_USE_MULTINET is not set +CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y +CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=n + +# ULP Setting for IDF 5.x +CONFIG_ULP_COPROC_ENABLED=y +# end of ULP COPROC_ENABLE +# Choose FSM or RISCV exclusively! Never both. +CONFIG_ULP_COPROC_TYPE_FSM=y +# CONFIG_ULP_COPROC_TYPE_RISCV=y +CONFIG_ULP_COPROC_RESERVE_MEM=512 diff --git a/configs/defconfig.esp32s3 b/configs/defconfig.esp32s3 new file mode 100644 index 000000000..36fa6b6a5 --- /dev/null +++ b/configs/defconfig.esp32s3 @@ -0,0 +1,23 @@ +CONFIG_BT_ENABLED=y +CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_SPIRAM=y +CONFIG_RTC_CLK_CAL_CYCLES=576 +CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_TWO=y +# CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND is not set +# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set +CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=3120 +CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=n + +# ULP Setting for IDF 5.x +CONFIG_ULP_COPROC_ENABLED=y +# end of ULP COPROC_ENABLE +# Choose FSM or RISCV exclusively! Never both. +CONFIG_ULP_COPROC_TYPE_FSM=y +# CONFIG_ULP_COPROC_TYPE_RISCV=y +CONFIG_ULP_COPROC_RESERVE_MEM=512 + +# RGB Display Optimizations +# CONFIG_LCD_RGB_ISR_IRAM_SAFE is not set +CONFIG_LCD_RGB_RESTART_IN_VSYNC=y diff --git a/configs/defconfig.esp_sr b/configs/defconfig.esp_sr new file mode 100644 index 000000000..03b7c462e --- /dev/null +++ b/configs/defconfig.esp_sr @@ -0,0 +1,37 @@ +CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_SR_WN_WN9_HIESP=y +CONFIG_SR_MN_CN_NONE=y +CONFIG_SR_MN_EN_MULTINET5_SINGLE_RECOGNITION_QUANT8=y +CONFIG_EN_SPEECH_COMMAND_ID0="" +CONFIG_EN_SPEECH_COMMAND_ID1="" +CONFIG_EN_SPEECH_COMMAND_ID2="" +CONFIG_EN_SPEECH_COMMAND_ID3="" +CONFIG_EN_SPEECH_COMMAND_ID4="" +CONFIG_EN_SPEECH_COMMAND_ID5="" +CONFIG_EN_SPEECH_COMMAND_ID6="" +CONFIG_EN_SPEECH_COMMAND_ID7="" +CONFIG_EN_SPEECH_COMMAND_ID8="" +CONFIG_EN_SPEECH_COMMAND_ID9="" +CONFIG_EN_SPEECH_COMMAND_ID10="" +CONFIG_EN_SPEECH_COMMAND_ID11="" +CONFIG_EN_SPEECH_COMMAND_ID12="" +CONFIG_EN_SPEECH_COMMAND_ID13="" +CONFIG_EN_SPEECH_COMMAND_ID14="" +CONFIG_EN_SPEECH_COMMAND_ID15="" +CONFIG_EN_SPEECH_COMMAND_ID16="" +CONFIG_EN_SPEECH_COMMAND_ID17="" +CONFIG_EN_SPEECH_COMMAND_ID18="" +CONFIG_EN_SPEECH_COMMAND_ID19="" +CONFIG_EN_SPEECH_COMMAND_ID20="" +CONFIG_EN_SPEECH_COMMAND_ID21="" +CONFIG_EN_SPEECH_COMMAND_ID22="" +CONFIG_EN_SPEECH_COMMAND_ID23="" +CONFIG_EN_SPEECH_COMMAND_ID24="" +CONFIG_EN_SPEECH_COMMAND_ID25="" +CONFIG_EN_SPEECH_COMMAND_ID26="" +CONFIG_EN_SPEECH_COMMAND_ID27="" +CONFIG_EN_SPEECH_COMMAND_ID28="" +CONFIG_EN_SPEECH_COMMAND_ID29="" +CONFIG_EN_SPEECH_COMMAND_ID30="" +CONFIG_EN_SPEECH_COMMAND_ID31="" diff --git a/configs/defconfig.opi b/configs/defconfig.opi new file mode 100644 index 000000000..7cfbc5c13 --- /dev/null +++ b/configs/defconfig.opi @@ -0,0 +1,2 @@ +CONFIG_ESPTOOLPY_OCT_FLASH=y +CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_DTR=y \ No newline at end of file diff --git a/configs/defconfig.opi_ram b/configs/defconfig.opi_ram new file mode 100644 index 000000000..16e6a278c --- /dev/null +++ b/configs/defconfig.opi_ram @@ -0,0 +1,3 @@ +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_IGNORE_NOTFOUND=y +# CONFIG_SPIRAM_MEMTEST is not set \ No newline at end of file diff --git a/configs/defconfig.qio b/configs/defconfig.qio new file mode 100644 index 000000000..b467882f8 --- /dev/null +++ b/configs/defconfig.qio @@ -0,0 +1 @@ +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y \ No newline at end of file diff --git a/configs/defconfig.qio_ram b/configs/defconfig.qio_ram new file mode 100644 index 000000000..902680b3a --- /dev/null +++ b/configs/defconfig.qio_ram @@ -0,0 +1 @@ +# CONFIG_SPIRAM_BOOT_INIT is not set \ No newline at end of file diff --git a/configs/defconfig.qout b/configs/defconfig.qout new file mode 100644 index 000000000..154cabf41 --- /dev/null +++ b/configs/defconfig.qout @@ -0,0 +1 @@ +CONFIG_ESPTOOLPY_FLASHMODE_QOUT=y \ No newline at end of file diff --git a/configs/pioarduino_end.txt b/configs/pioarduino_end.txt new file mode 100644 index 000000000..d9b5d5467 --- /dev/null +++ b/configs/pioarduino_end.txt @@ -0,0 +1,11 @@ + "ARDUINO_ARCH_ESP32", + "CHIP_HAVE_CONFIG_H", + ("ESP32", "ESP32"), + ("F_CPU", "$BOARD_F_CPU"), + ("ARDUINO", 10812), + ("ARDUINO_VARIANT", '\\"%s\\"' % board_config.get("build.variant").replace('"', "")), + ("ARDUINO_BOARD", '\\"%s\\"' % board_config.get("name").replace('"', "")), + "ARDUINO_PARTITION_%s" % basename(board_config.get( + "build.partitions", "default.csv")).replace(".csv", "").replace("-", "_") + ] +) diff --git a/configs/pioarduino_start.txt b/configs/pioarduino_start.txt new file mode 100644 index 000000000..ec10a10dc --- /dev/null +++ b/configs/pioarduino_start.txt @@ -0,0 +1,62 @@ +# Copyright 2014-present PlatformIO +# +# 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. + +""" +Arduino + +Arduino Wiring-based Framework allows writing cross-platform software to +control devices attached to a wide range of Arduino boards to create all +kinds of creative coding, interactive objects, spaces or physical experiences. + +http://arduino.cc/en/Reference/HomePage +""" + +# Extends: https://github.com/pioarduino/platform-espressif32/blob/develop/builder/main.py + +from os.path import basename, join + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() + +FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoespressif32") +FRAMEWORK_SDK_DIR = env.PioPlatform().get_package_dir( + "framework-arduinoespressif32-libs" +) + +board_config = env.BoardConfig() + +flatten_cppdefines = env.Flatten(env['CPPDEFINES']) + +# +# zigbee libs +# +if "ZIGBEE_MODE_ZCZR" in flatten_cppdefines: + env.Append( + LIBS=[ + "-lesp_zb_api.zczr", + "-lzboss_stack.zczr", + "-lzboss_port.native" + ] + ) +if "ZIGBEE_MODE_ED" in flatten_cppdefines: + env.Append( + LIBS=[ + "-lesp_zb_api.ed", + "-lzboss_stack.ed", + "-lzboss_port.native" + ] + ) + +env.Append( diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt new file mode 100644 index 000000000..1ab83d39a --- /dev/null +++ b/main/CMakeLists.txt @@ -0,0 +1 @@ +idf_component_register(SRCS "sketch.cpp" "arduino-lib-builder-gcc.c" "arduino-lib-builder-cpp.cpp" "arduino-lib-builder-as.S" INCLUDE_DIRS ".") diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild new file mode 100644 index 000000000..10edb39c4 --- /dev/null +++ b/main/Kconfig.projbuild @@ -0,0 +1,24 @@ +config LIB_BUILDER_FLASHMODE + string + default "qio" if ESPTOOLPY_FLASHMODE_QIO + default "qout" if ESPTOOLPY_FLASHMODE_QOUT + default "dio" if ESPTOOLPY_FLASHMODE_DIO + default "dout" if ESPTOOLPY_FLASHMODE_DOUT + default "opi" if ESPTOOLPY_FLASHMODE_OPI + +config LIB_BUILDER_FLASHFREQ + string + default "120m" if ESPTOOLPY_FLASHFREQ_120M + default "80m" if ESPTOOLPY_FLASHFREQ_80M + default "64m" if ESPTOOLPY_FLASHFREQ_64M + default "60m" if ESPTOOLPY_FLASHFREQ_60M + default "40m" if ESPTOOLPY_FLASHFREQ_40M + default "32m" if ESPTOOLPY_FLASHFREQ_32M + default "30m" if ESPTOOLPY_FLASHFREQ_30M + default "26m" if ESPTOOLPY_FLASHFREQ_26M + default "20m" if ESPTOOLPY_FLASHFREQ_20M + default "16m" if ESPTOOLPY_FLASHFREQ_16M + +config LIB_BUILDER_COMPILE + bool + default y \ No newline at end of file diff --git a/main/arduino-lib-builder-as.S b/main/arduino-lib-builder-as.S new file mode 100644 index 000000000..e69de29bb diff --git a/main/arduino-lib-builder-cpp.cpp b/main/arduino-lib-builder-cpp.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/main/arduino-lib-builder-gcc.c b/main/arduino-lib-builder-gcc.c new file mode 100644 index 000000000..e69de29bb diff --git a/main/idf_component.yml b/main/idf_component.yml new file mode 100644 index 000000000..a85eca541 --- /dev/null +++ b/main/idf_component.yml @@ -0,0 +1,23 @@ +dependencies: + # Required IDF version + idf: ">=5.3" + espressif/esp32-camera: + version: "master" + git: https://github.com/espressif/esp32-camera.git + require: public + rules: + - if: "target in [esp32, esp32s2, esp32s3]" + espressif/esp-tflite-micro: + version: ">=1.2.0" + require: public + rules: + - if: "target not in [esp32c2]" + espressif/esp-sr: + version: ">=1.4.2" + rules: + - if: "target in [esp32s3]" + espressif/esp_matter: + version: "1.4.1" + require: public + rules: + - if: "target not in [esp32c2, esp32h2, esp32p4]" diff --git a/main/sketch.cpp b/main/sketch.cpp index 19b54ea3a..10a17a8f2 100644 --- a/main/sketch.cpp +++ b/main/sketch.cpp @@ -1,9 +1,10 @@ #include "Arduino.h" -void setup(){ - +void setup() { + Serial.begin(115200); } -void loop(){ - +void loop() { + Serial.println("Hello World!"); + delay(1000); } diff --git a/partitions.csv b/partitions.csv new file mode 100644 index 000000000..97e41c452 --- /dev/null +++ b/partitions.csv @@ -0,0 +1,8 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x300000, +app1, app, ota_1, 0x310000, 0x300000, +spiffs, data, spiffs, 0x610000, 0x700000, +model, data, spiffs, 0xD10000, 0x2E0000, +coredump, data, coredump,0xFF0000, 0x10000, diff --git a/patches/esp32s2_i2c_ll_master_init.diff b/patches/esp32s2_i2c_ll_master_init.diff new file mode 100644 index 000000000..2a129c695 --- /dev/null +++ b/patches/esp32s2_i2c_ll_master_init.diff @@ -0,0 +1,17 @@ +diff --git a/components/hal/esp32s2/include/hal/i2c_ll.h b/components/hal/esp32s2/include/hal/i2c_ll.h +index f9a66b61d6..2f669b68c0 100644 +--- a/components/hal/esp32s2/include/hal/i2c_ll.h ++++ b/components/hal/esp32s2/include/hal/i2c_ll.h +@@ -653,10 +653,12 @@ static inline void i2c_ll_enable_controller_clock(i2c_dev_t *hw, bool en) + static inline void i2c_ll_master_init(i2c_dev_t *hw) + { + typeof(hw->ctr) ctrl_reg; ++ uint32_t ref_always_on = hw->ctr.ref_always_on; + ctrl_reg.val = 0; + ctrl_reg.ms_mode = 1; + ctrl_reg.sda_force_out = 1; + ctrl_reg.scl_force_out = 1; ++ ctrl_reg.ref_always_on = ref_always_on; + hw->ctr.val = ctrl_reg.val; + } + diff --git a/patches/lwip_max_tcp_pcb.diff b/patches/lwip_max_tcp_pcb.diff new file mode 100644 index 000000000..6b9e73cb6 --- /dev/null +++ b/patches/lwip_max_tcp_pcb.diff @@ -0,0 +1,118 @@ +diff --git a/components/lwip/lwip/src/core/memp.c b/components/lwip/lwip/src/core/memp.c +index 352ce5a55127a658b6b3c9d8541298c42df332ff..39433cf476b3456b046e337e9b1f016299964a84 100644 +--- a/components/lwip/lwip/src/core/memp.c ++++ b/components/lwip/lwip/src/core/memp.c +@@ -240,6 +240,10 @@ memp_init(void) + #endif /* MEMP_OVERFLOW_CHECK >= 2 */ + } + ++#if MEMP_MEM_MALLOC && ESP_LWIP && LWIP_TCP ++static u32_t num_tcp_pcb = 0; ++#endif ++ + static void * + #if !MEMP_OVERFLOW_CHECK + do_memp_malloc_pool(const struct memp_desc *desc) +@@ -251,6 +255,16 @@ do_memp_malloc_pool_fn(const struct memp_desc *desc, const char *file, const int + SYS_ARCH_DECL_PROTECT(old_level); + + #if MEMP_MEM_MALLOC ++#if ESP_LWIP ++#if LWIP_TCP ++ if(desc == memp_pools[MEMP_TCP_PCB]){ ++ if(num_tcp_pcb >= MEMP_NUM_TCP_PCB){ ++ return NULL; ++ } ++ } ++#endif ++#endif ++ + memp = (struct memp *)mem_malloc(MEMP_SIZE + MEMP_ALIGN_SIZE(desc->size)); + SYS_ARCH_PROTECT(old_level); + #else /* MEMP_MEM_MALLOC */ +@@ -260,6 +274,12 @@ do_memp_malloc_pool_fn(const struct memp_desc *desc, const char *file, const int + #endif /* MEMP_MEM_MALLOC */ + + if (memp != NULL) { ++#if MEMP_MEM_MALLOC && ESP_LWIP && LWIP_TCP ++ if (desc == memp_pools[MEMP_TCP_PCB]) { ++ num_tcp_pcb++; ++ } ++#endif ++ + #if !MEMP_MEM_MALLOC + #if MEMP_OVERFLOW_CHECK == 1 + memp_overflow_check_element(memp, desc); +@@ -369,6 +389,12 @@ do_memp_free_pool(const struct memp_desc *desc, void *mem) + + SYS_ARCH_PROTECT(old_level); + ++#if MEMP_MEM_MALLOC && ESP_LWIP && LWIP_TCP ++ if (desc == memp_pools[MEMP_TCP_PCB]) { ++ num_tcp_pcb--; ++ } ++#endif ++ + #if MEMP_OVERFLOW_CHECK == 1 + memp_overflow_check_element(memp, desc); + #endif /* MEMP_OVERFLOW_CHECK */ +diff --git a/components/lwip/lwip/src/core/tcp.c b/components/lwip/lwip/src/core/tcp.c +index 3fbdd89ae07807208ff7466abb50f90b5e7727e4..fe6baaf250927cb4b89f8d1dbd41c73def88692b 100644 +--- a/components/lwip/lwip/src/core/tcp.c ++++ b/components/lwip/lwip/src/core/tcp.c +@@ -1765,7 +1765,9 @@ tcp_kill_state(enum tcp_state state) + struct tcp_pcb *pcb, *inactive; + u32_t inactivity; + ++#if !ESP_LWIP + LWIP_ASSERT("invalid state", (state == CLOSING) || (state == LAST_ACK)); ++#endif + + inactivity = 0; + inactive = NULL; +@@ -1870,17 +1872,41 @@ tcp_alloc(u8_t prio) + tcp_kill_state(CLOSING); + /* Try to allocate a tcp_pcb again. */ + pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB); ++#if ESP_LWIP + if (pcb == NULL) { +- /* Try killing oldest active connection with lower priority than the new one. */ +- LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing oldest connection with prio lower than %d\n", prio)); +- tcp_kill_prio(prio); +- /* Try to allocate a tcp_pcb again. */ ++ /* Try killing oldest connection in FIN_WAIT_2. */ ++ LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest FIN_WAIT_2 connection\n")); ++ tcp_kill_state(FIN_WAIT_2); + pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB); ++ if (pcb == NULL) { ++ /* Try killing oldest connection in FIN_WAIT_1. */ ++ LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest FIN_WAIT_1 connection\n")); ++ tcp_kill_state(FIN_WAIT_1); ++ pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB); ++#endif ++ if (pcb == NULL) { ++ /* Try killing oldest active connection with lower priority than the new one. */ ++ LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing oldest connection with prio lower than %d\n", prio)); ++ tcp_kill_prio(prio); ++ /* Try to allocate a tcp_pcb again. */ ++ pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB); ++ if (pcb != NULL) { ++ /* adjust err stats: memp_malloc failed multiple times before */ ++ MEMP_STATS_DEC(err, MEMP_TCP_PCB); ++ } ++ } ++#if ESP_LWIP ++ if (pcb != NULL) { ++ /* adjust err stats: memp_malloc failed multiple times before */ ++ MEMP_STATS_DEC(err, MEMP_TCP_PCB); ++ } ++ } + if (pcb != NULL) { + /* adjust err stats: memp_malloc failed multiple times before */ + MEMP_STATS_DEC(err, MEMP_TCP_PCB); + } + } ++#endif + if (pcb != NULL) { + /* adjust err stats: memp_malloc failed multiple times before */ + MEMP_STATS_DEC(err, MEMP_TCP_PCB); diff --git a/sdkconfig b/sdkconfig deleted file mode 100644 index 60e763437..000000000 --- a/sdkconfig +++ /dev/null @@ -1,953 +0,0 @@ -# -# Automatically generated file; DO NOT EDIT. -# Espressif IoT Development Framework Configuration -# -CONFIG_IDF_TARGET="esp32" -CONFIG_IDF_FIRMWARE_CHIP_ID=0x0000 - -# -# SDK tool configuration -# -CONFIG_TOOLPREFIX="xtensa-esp32-elf-" -CONFIG_PYTHON="python" -CONFIG_MAKE_WARN_UNDEFINED_VARIABLES=y - -# -# Application manager -# -CONFIG_APP_COMPILE_TIME_DATE=y -CONFIG_APP_EXCLUDE_PROJECT_VER_VAR= -CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR= -CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 - -# -# Arduino Configuration -# -CONFIG_ENABLE_ARDUINO_DEPENDS=y -CONFIG_AUTOSTART_ARDUINO=y -CONFIG_ARDUINO_RUN_CORE0= -CONFIG_ARDUINO_RUN_CORE1=y -CONFIG_ARDUINO_RUN_NO_AFFINITY= -CONFIG_ARDUINO_RUNNING_CORE=1 -CONFIG_ARDUINO_EVENT_RUN_CORE0= -CONFIG_ARDUINO_EVENT_RUN_CORE1=y -CONFIG_ARDUINO_EVENT_RUN_NO_AFFINITY= -CONFIG_ARDUINO_EVENT_RUNNING_CORE=1 -CONFIG_ARDUINO_UDP_RUN_CORE0= -CONFIG_ARDUINO_UDP_RUN_CORE1=y -CONFIG_ARDUINO_UDP_RUN_NO_AFFINITY= -CONFIG_ARDUINO_UDP_TASK_PRIORITY=3 -CONFIG_ARDUINO_UDP_RUNNING_CORE=1 -CONFIG_DISABLE_HAL_LOCKS= - -# -# Debug Log Configuration -# -CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_NONE= -CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_ERROR=y -CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_WARN= -CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO= -CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_DEBUG= -CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_VERBOSE= -CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL=1 -CONFIG_ARDUHAL_LOG_COLORS= -CONFIG_ARDUHAL_ESP_LOG=y -CONFIG_ARDUHAL_PARTITION_SCHEME_DEFAULT=y -CONFIG_ARDUHAL_PARTITION_SCHEME_MINIMAL= -CONFIG_ARDUHAL_PARTITION_SCHEME_NO_OTA= -CONFIG_ARDUHAL_PARTITION_SCHEME_HUGE_APP= -CONFIG_ARDUHAL_PARTITION_SCHEME_MIN_SPIFFS= -CONFIG_ARDUHAL_PARTITION_SCHEME="default" -CONFIG_AUTOCONNECT_WIFI= -CONFIG_ARDUINO_SELECTIVE_COMPILATION= - -# -# Bootloader config -# -CONFIG_LOG_BOOTLOADER_LEVEL_NONE=y -CONFIG_LOG_BOOTLOADER_LEVEL_ERROR= -CONFIG_LOG_BOOTLOADER_LEVEL_WARN= -CONFIG_LOG_BOOTLOADER_LEVEL_INFO= -CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG= -CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE= -CONFIG_LOG_BOOTLOADER_LEVEL=0 -CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V= -CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y -CONFIG_BOOTLOADER_FACTORY_RESET= -CONFIG_BOOTLOADER_APP_TEST= -CONFIG_BOOTLOADER_WDT_ENABLE=y -CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE= -CONFIG_BOOTLOADER_WDT_TIME_MS=9000 -CONFIG_APP_ROLLBACK_ENABLE= - -# -# Security features -# -CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT= -CONFIG_SECURE_BOOT_ENABLED= -CONFIG_FLASH_ENCRYPTION_ENABLED= - -# -# Serial flasher config -# -CONFIG_ESPTOOLPY_PORT="/dev/cu.usbserial-DO00EAB0" -CONFIG_ESPTOOLPY_BAUD_115200B= -CONFIG_ESPTOOLPY_BAUD_230400B= -CONFIG_ESPTOOLPY_BAUD_921600B=y -CONFIG_ESPTOOLPY_BAUD_2MB= -CONFIG_ESPTOOLPY_BAUD_OTHER= -CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200 -CONFIG_ESPTOOLPY_BAUD=921600 -CONFIG_ESPTOOLPY_COMPRESSED=y -CONFIG_FLASHMODE_QIO= -CONFIG_FLASHMODE_QOUT= -CONFIG_FLASHMODE_DIO= -CONFIG_FLASHMODE_DOUT=y -CONFIG_ESPTOOLPY_FLASHMODE="dout" -CONFIG_ESPTOOLPY_FLASHFREQ_80M= -CONFIG_ESPTOOLPY_FLASHFREQ_40M=y -CONFIG_ESPTOOLPY_FLASHFREQ_26M= -CONFIG_ESPTOOLPY_FLASHFREQ_20M= -CONFIG_ESPTOOLPY_FLASHFREQ="40m" -CONFIG_ESPTOOLPY_FLASHSIZE_1MB= -CONFIG_ESPTOOLPY_FLASHSIZE_2MB= -CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y -CONFIG_ESPTOOLPY_FLASHSIZE_8MB= -CONFIG_ESPTOOLPY_FLASHSIZE_16MB= -CONFIG_ESPTOOLPY_FLASHSIZE="4MB" -CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y -CONFIG_ESPTOOLPY_BEFORE_RESET=y -CONFIG_ESPTOOLPY_BEFORE_NORESET= -CONFIG_ESPTOOLPY_BEFORE="default_reset" -CONFIG_ESPTOOLPY_AFTER_RESET=y -CONFIG_ESPTOOLPY_AFTER_NORESET= -CONFIG_ESPTOOLPY_AFTER="hard_reset" -CONFIG_MONITOR_BAUD_9600B= -CONFIG_MONITOR_BAUD_57600B= -CONFIG_MONITOR_BAUD_115200B=y -CONFIG_MONITOR_BAUD_230400B= -CONFIG_MONITOR_BAUD_921600B= -CONFIG_MONITOR_BAUD_2MB= -CONFIG_MONITOR_BAUD_OTHER= -CONFIG_MONITOR_BAUD_OTHER_VAL=115200 -CONFIG_MONITOR_BAUD=115200 - -# -# Partition Table -# -CONFIG_PARTITION_TABLE_SINGLE_APP=y -CONFIG_PARTITION_TABLE_TWO_OTA= -CONFIG_PARTITION_TABLE_CUSTOM= -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" -CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv" -CONFIG_PARTITION_TABLE_OFFSET=0x8000 -CONFIG_PARTITION_TABLE_MD5=y - -# -# Compiler options -# -CONFIG_OPTIMIZATION_LEVEL_DEBUG=y -CONFIG_OPTIMIZATION_LEVEL_RELEASE= -CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y -CONFIG_OPTIMIZATION_ASSERTIONS_SILENT= -CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED= -CONFIG_CXX_EXCEPTIONS=y -CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE=0 -CONFIG_STACK_CHECK_NONE= -CONFIG_STACK_CHECK_NORM=y -CONFIG_STACK_CHECK_STRONG= -CONFIG_STACK_CHECK_ALL= -CONFIG_STACK_CHECK=y -CONFIG_WARN_WRITE_STRINGS=y -CONFIG_DISABLE_GCC8_WARNINGS= - -# -# Component config -# - -# -# Application Level Tracing -# -CONFIG_ESP32_APPTRACE_DEST_TRAX= -CONFIG_ESP32_APPTRACE_DEST_NONE=y -CONFIG_ESP32_APPTRACE_ENABLE= -CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y -CONFIG_AWS_IOT_SDK= - -# -# Bluetooth -# -CONFIG_BT_ENABLED=y - -# -# Bluetooth controller -# -CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY= -CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY= -CONFIG_BTDM_CONTROLLER_MODE_BTDM=y -CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN=3 -CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN=2 -CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN=0 -CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF=0 -CONFIG_BTDM_CTRL_AUTO_LATENCY= -CONFIG_BTDM_CTRL_AUTO_LATENCY_EFF= -CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT=y -CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF=y -CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF=3 -CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF=2 -CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF=0 -CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE_0=y -CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE_1= -CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0 -CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI=y -CONFIG_BTDM_CONTROLLER_HCI_MODE_UART_H4= - -# -# MODEM SLEEP Options -# -CONFIG_BTDM_CONTROLLER_MODEM_SLEEP=y -CONFIG_BTDM_MODEM_SLEEP_MODE_ORIG=y -CONFIG_BTDM_MODEM_SLEEP_MODE_EVED= -CONFIG_BTDM_LPCLK_SEL_MAIN_XTAL=y -CONFIG_BLE_SCAN_DUPLICATE=y -CONFIG_SCAN_DUPLICATE_BY_DEVICE_ADDR=y -CONFIG_SCAN_DUPLICATE_BY_ADV_DATA= -CONFIG_SCAN_DUPLICATE_BY_ADV_DATA_AND_DEVICE_ADDR= -CONFIG_SCAN_DUPLICATE_TYPE=0 -CONFIG_DUPLICATE_SCAN_CACHE_SIZE=20 -CONFIG_BLE_MESH_SCAN_DUPLICATE_EN= -CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y -CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y -CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_NUM=100 -CONFIG_BLE_ADV_REPORT_DISCARD_THRSHOLD=20 -CONFIG_BTDM_COEX_BT_OPTIONS= -CONFIG_BLUEDROID_ENABLED=y -CONFIG_BLUEDROID_PINNED_TO_CORE_0=y -CONFIG_BLUEDROID_PINNED_TO_CORE_1= -CONFIG_BLUEDROID_PINNED_TO_CORE=0 -CONFIG_BTC_TASK_STACK_SIZE=8192 -CONFIG_BTU_TASK_STACK_SIZE=4096 -CONFIG_BLUEDROID_MEM_DEBUG= -CONFIG_CLASSIC_BT_ENABLED=y -CONFIG_A2DP_ENABLE=y -CONFIG_A2DP_SINK_TASK_STACK_SIZE=2048 -CONFIG_A2DP_SOURCE_TASK_STACK_SIZE=2048 -CONFIG_BT_SPP_ENABLED=y -CONFIG_HFP_ENABLE=y -CONFIG_HFP_CLIENT_ENABLE=y -CONFIG_HFP_AUDIO_DATA_PATH_PCM=y -CONFIG_HFP_AUDIO_DATA_PATH_HCI= -CONFIG_BT_SSP_ENABLED=y -CONFIG_GATTS_ENABLE=y -CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL= -CONFIG_GATTS_SEND_SERVICE_CHANGE_AUTO=y -CONFIG_GATTS_SEND_SERVICE_CHANGE_MODE=0 -CONFIG_GATTC_ENABLE=y -CONFIG_GATTC_CACHE_NVS_FLASH= -CONFIG_BLE_SMP_ENABLE=y -CONFIG_SMP_SLAVE_CON_PARAMS_UPD_ENABLE= -CONFIG_BT_STACK_NO_LOG=y -CONFIG_BT_ACL_CONNECTIONS=4 -CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y -CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y -CONFIG_BLE_HOST_QUEUE_CONGESTION_CHECK= -CONFIG_SMP_ENABLE=y -CONFIG_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY= -CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT=30 -CONFIG_BT_RESERVE_DRAM=0xdb5c -CONFIG_BLE_MESH= - -# -# Driver configurations -# - -# -# ADC configuration -# -CONFIG_ADC_FORCE_XPD_FSM= -CONFIG_ADC2_DISABLE_DAC=y - -# -# SPI configuration -# -CONFIG_SPI_MASTER_IN_IRAM= -CONFIG_SPI_MASTER_ISR_IN_IRAM=y -CONFIG_SPI_SLAVE_IN_IRAM= -CONFIG_SPI_SLAVE_ISR_IN_IRAM=y - -# -# eFuse Bit Manager -# -CONFIG_EFUSE_CUSTOM_TABLE= -CONFIG_EFUSE_VIRTUAL= -CONFIG_EFUSE_CODE_SCHEME_COMPAT_NONE= -CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4=y -CONFIG_EFUSE_CODE_SCHEME_COMPAT_REPEAT= -CONFIG_EFUSE_MAX_BLK_LEN=192 -CONFIG_C_IMPL= -CONFIG_XTENSA_IMPL=y - -# -# ESP-FACE Configuration -# -CONFIG_MTMN_LITE_QUANT=y -CONFIG_MTMN_LITE_FLOAT= -CONFIG_MTMN_HEAVY_QUANT= -CONFIG_FRMN= -CONFIG_MFN56_1X=y -CONFIG_MFN56_2X= -CONFIG_MFN56_3X= -CONFIG_MFN56_4X= - -# -# Object Detection -# -CONFIG_DETECT_WITH_LANDMARK= - -# -# Pose Estimation -# -CONFIG_HD_NANO1=y -CONFIG_HD_LITE1= -CONFIG_HP_NANO1=y -CONFIG_HP_LITE1= - -# -# ESP32-specific -# -CONFIG_IDF_TARGET_ESP32=y -CONFIG_ESP32_ECO3_CACHE_LOCK_FIX=y -CONFIG_ESP32_REV_MIN_0=y -CONFIG_ESP32_REV_MIN_1= -CONFIG_ESP32_REV_MIN_2= -CONFIG_ESP32_REV_MIN_3= -CONFIG_ESP32_REV_MIN=0 -CONFIG_ESP32_DPORT_WORKAROUND=y -CONFIG_ESP32_DEFAULT_CPU_FREQ_80= -CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y -CONFIG_ESP32_DEFAULT_CPU_FREQ_240= -CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=160 -CONFIG_SPIRAM_SUPPORT=y - -# -# SPI RAM config -# -CONFIG_SPIRAM_BOOT_INIT= -CONFIG_SPIRAM_USE_MEMMAP= -CONFIG_SPIRAM_USE_CAPS_ALLOC=y -CONFIG_SPIRAM_USE_MALLOC= -CONFIG_SPIRAM_TYPE_AUTO=y -CONFIG_SPIRAM_TYPE_ESPPSRAM32= -CONFIG_SPIRAM_TYPE_ESPPSRAM64= -CONFIG_SPIRAM_SIZE=-1 -CONFIG_SPIRAM_SPEED_40M=y -CONFIG_SPIRAM_CACHE_WORKAROUND=y -CONFIG_SPIRAM_BANKSWITCH_ENABLE=y -CONFIG_SPIRAM_BANKSWITCH_RESERVE=8 -CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST= -CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY= - -# -# PSRAM clock and cs IO for ESP32-DOWD -# -CONFIG_D0WD_PSRAM_CLK_IO=17 -CONFIG_D0WD_PSRAM_CS_IO=16 - -# -# PSRAM clock and cs IO for ESP32-D2WD -# -CONFIG_D2WD_PSRAM_CLK_IO=9 -CONFIG_D2WD_PSRAM_CS_IO=10 - -# -# PSRAM clock and cs IO for ESP32-PICO -# -CONFIG_PICO_PSRAM_CS_IO=10 -CONFIG_SPIRAM_SPIWP_SD3_PIN=7 -CONFIG_SPIRAM_2T_MODE= -CONFIG_MEMMAP_TRACEMEM= -CONFIG_MEMMAP_TRACEMEM_TWOBANKS= -CONFIG_ESP32_TRAX= -CONFIG_TRACEMEM_RESERVE_DRAM=0x0 -CONFIG_TWO_UNIVERSAL_MAC_ADDRESS= -CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y -CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4 -CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 -CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2048 -CONFIG_MAIN_TASK_STACK_SIZE=4096 -CONFIG_IPC_TASK_STACK_SIZE=1024 -CONFIG_TIMER_TASK_STACK_SIZE=4096 -CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF=y -CONFIG_NEWLIB_STDOUT_LINE_ENDING_LF= -CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR= -CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF= -CONFIG_NEWLIB_STDIN_LINE_ENDING_LF= -CONFIG_NEWLIB_STDIN_LINE_ENDING_CR=y -CONFIG_NEWLIB_NANO_FORMAT= -CONFIG_CONSOLE_UART_DEFAULT=y -CONFIG_CONSOLE_UART_CUSTOM= -CONFIG_CONSOLE_UART_NONE= -CONFIG_CONSOLE_UART_NUM=0 -CONFIG_CONSOLE_UART_BAUDRATE=115200 -CONFIG_ULP_COPROC_ENABLED=y -CONFIG_ULP_COPROC_RESERVE_MEM=512 -CONFIG_ESP32_PANIC_PRINT_HALT= -CONFIG_ESP32_PANIC_PRINT_REBOOT=y -CONFIG_ESP32_PANIC_SILENT_REBOOT= -CONFIG_ESP32_PANIC_GDBSTUB= -CONFIG_ESP32_DEBUG_OCDAWARE=y -CONFIG_ESP32_DEBUG_STUBS_ENABLE=y -CONFIG_INT_WDT=y -CONFIG_INT_WDT_TIMEOUT_MS=300 -CONFIG_INT_WDT_CHECK_CPU1=y -CONFIG_TASK_WDT=y -CONFIG_TASK_WDT_PANIC=y -CONFIG_TASK_WDT_TIMEOUT_S=5 -CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=y -CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1= -CONFIG_BROWNOUT_DET=y -CONFIG_BROWNOUT_DET_LVL_SEL_0=y -CONFIG_BROWNOUT_DET_LVL_SEL_1= -CONFIG_BROWNOUT_DET_LVL_SEL_2= -CONFIG_BROWNOUT_DET_LVL_SEL_3= -CONFIG_BROWNOUT_DET_LVL_SEL_4= -CONFIG_BROWNOUT_DET_LVL_SEL_5= -CONFIG_BROWNOUT_DET_LVL_SEL_6= -CONFIG_BROWNOUT_DET_LVL_SEL_7= -CONFIG_BROWNOUT_DET_LVL=0 -CONFIG_REDUCE_PHY_TX_POWER=y -CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y -CONFIG_ESP32_TIME_SYSCALL_USE_RTC= -CONFIG_ESP32_TIME_SYSCALL_USE_FRC1= -CONFIG_ESP32_TIME_SYSCALL_USE_NONE= -CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y -CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL= -CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_OSC= -CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_8MD256= -CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024 -CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=2000 -CONFIG_ESP32_XTAL_FREQ_40= -CONFIG_ESP32_XTAL_FREQ_26= -CONFIG_ESP32_XTAL_FREQ_AUTO=y -CONFIG_ESP32_XTAL_FREQ=0 -CONFIG_DISABLE_BASIC_ROM_CONSOLE= -CONFIG_ESP_TIMER_PROFILING= -CONFIG_COMPATIBLE_PRE_V2_1_BOOTLOADERS= -CONFIG_ESP_ERR_TO_NAME_LOOKUP=y -CONFIG_ESP32_DPORT_DIS_INTERRUPT_LVL=5 - -# -# Wi-Fi -# -CONFIG_SW_COEXIST_ENABLE=y -CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=16 -CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32 -CONFIG_ESP32_WIFI_STATIC_TX_BUFFER= -CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y -CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1 -CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32 -CONFIG_ESP32_WIFI_CSI_ENABLED= -CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y -CONFIG_ESP32_WIFI_TX_BA_WIN=6 -CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y -CONFIG_ESP32_WIFI_RX_BA_WIN=16 -CONFIG_ESP32_WIFI_NVS_ENABLED=y -CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y -CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1= -CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752 -CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32 -CONFIG_ESP32_WIFI_DEBUG_LOG_ENABLE= -CONFIG_ESP32_WIFI_IRAM_OPT= -CONFIG_ESP32_WIFI_RX_IRAM_OPT= - -# -# PHY -# -CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y -CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION= -CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20 -CONFIG_ESP32_PHY_MAX_TX_POWER=20 - -# -# Power Management -# -CONFIG_PM_ENABLE= - -# -# Camera configuration -# -CONFIG_OV7670_SUPPORT=y -CONFIG_OV7725_SUPPORT=y -CONFIG_NT99141_SUPPORT=y -CONFIG_OV2640_SUPPORT=y -CONFIG_OV3660_SUPPORT=y -CONFIG_OV5640_SUPPORT=y -CONFIG_SCCB_HARDWARE_I2C_PORT0= -CONFIG_SCCB_HARDWARE_I2C_PORT1=y -CONFIG_CAMERA_CORE0= -CONFIG_CAMERA_CORE1=y -CONFIG_CAMERA_NO_AFFINITY= - -# -# ADC-Calibration -# -CONFIG_ADC_CAL_EFUSE_TP_ENABLE=y -CONFIG_ADC_CAL_EFUSE_VREF_ENABLE=y -CONFIG_ADC_CAL_LUT_ENABLE=y - -# -# Event Loop Library -# -CONFIG_EVENT_LOOP_PROFILING= - -# -# ESP HTTP client -# -CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y -CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH= - -# -# HTTP Server -# -CONFIG_HTTPD_MAX_REQ_HDR_LEN=512 -CONFIG_HTTPD_MAX_URI_LEN=512 -CONFIG_HTTPD_ERR_RESP_NO_DELAY=y -CONFIG_HTTPD_PURGE_BUF_LEN=32 -CONFIG_HTTPD_LOG_PURGE_DATA= - -# -# ESP HTTPS OTA -# -CONFIG_OTA_ALLOW_HTTP= - -# -# Core dump -# -CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH= -CONFIG_ESP32_ENABLE_COREDUMP_TO_UART= -CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y -CONFIG_ESP32_ENABLE_COREDUMP= - -# -# Ethernet -# -CONFIG_DMA_RX_BUF_NUM=10 -CONFIG_DMA_TX_BUF_NUM=10 -CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE=y -CONFIG_EMAC_CHECK_LINK_PERIOD_MS=2000 -CONFIG_EMAC_TASK_PRIORITY=20 -CONFIG_EMAC_TASK_STACK_SIZE=3072 - -# -# FAT Filesystem support -# -CONFIG_FATFS_CODEPAGE_DYNAMIC= -CONFIG_FATFS_CODEPAGE_437= -CONFIG_FATFS_CODEPAGE_720= -CONFIG_FATFS_CODEPAGE_737= -CONFIG_FATFS_CODEPAGE_771= -CONFIG_FATFS_CODEPAGE_775= -CONFIG_FATFS_CODEPAGE_850=y -CONFIG_FATFS_CODEPAGE_852= -CONFIG_FATFS_CODEPAGE_855= -CONFIG_FATFS_CODEPAGE_857= -CONFIG_FATFS_CODEPAGE_860= -CONFIG_FATFS_CODEPAGE_861= -CONFIG_FATFS_CODEPAGE_862= -CONFIG_FATFS_CODEPAGE_863= -CONFIG_FATFS_CODEPAGE_864= -CONFIG_FATFS_CODEPAGE_865= -CONFIG_FATFS_CODEPAGE_866= -CONFIG_FATFS_CODEPAGE_869= -CONFIG_FATFS_CODEPAGE_932= -CONFIG_FATFS_CODEPAGE_936= -CONFIG_FATFS_CODEPAGE_949= -CONFIG_FATFS_CODEPAGE_950= -CONFIG_FATFS_CODEPAGE=850 -CONFIG_FATFS_LFN_NONE= -CONFIG_FATFS_LFN_HEAP= -CONFIG_FATFS_LFN_STACK=y -CONFIG_FATFS_MAX_LFN=255 -CONFIG_FATFS_API_ENCODING_ANSI_OEM=y -CONFIG_FATFS_API_ENCODING_UTF_16= -CONFIG_FATFS_API_ENCODING_UTF_8= -CONFIG_FATFS_FS_LOCK=0 -CONFIG_FATFS_TIMEOUT_MS=10000 -CONFIG_FATFS_PER_FILE_CACHE=y -CONFIG_FATFS_ALLOC_PREFER_EXTRAM=y - -# -# Modbus configuration -# -CONFIG_MB_QUEUE_LENGTH=20 -CONFIG_MB_SERIAL_TASK_STACK_SIZE=2048 -CONFIG_MB_SERIAL_BUF_SIZE=256 -CONFIG_MB_SERIAL_TASK_PRIO=10 -CONFIG_MB_CONTROLLER_SLAVE_ID_SUPPORT= -CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT=20 -CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE=20 -CONFIG_MB_CONTROLLER_STACK_SIZE=4096 -CONFIG_MB_EVENT_QUEUE_TIMEOUT=20 -CONFIG_MB_TIMER_PORT_ENABLED=y -CONFIG_MB_TIMER_GROUP=0 -CONFIG_MB_TIMER_INDEX=0 - -# -# FreeRTOS -# -CONFIG_FREERTOS_UNICORE= -CONFIG_FREERTOS_NO_AFFINITY=0x7FFFFFFF -CONFIG_FREERTOS_CORETIMER_0=y -CONFIG_FREERTOS_CORETIMER_1= -CONFIG_FREERTOS_HZ=1000 -CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION= -CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE= -CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL= -CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y -CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y -CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y -CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 -CONFIG_FREERTOS_ASSERT_FAIL_ABORT=y -CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE= -CONFIG_FREERTOS_ASSERT_DISABLE= -CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024 -CONFIG_FREERTOS_ISR_STACKSIZE=1536 -CONFIG_FREERTOS_LEGACY_HOOKS= -CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16 -CONFIG_SUPPORT_STATIC_ALLOCATION= -CONFIG_TIMER_TASK_PRIORITY=1 -CONFIG_TIMER_TASK_STACK_DEPTH=2048 -CONFIG_TIMER_QUEUE_LENGTH=10 -CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 -CONFIG_FREERTOS_USE_TRACE_FACILITY= -CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS= -CONFIG_FREERTOS_DEBUG_INTERNALS= -CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y -CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y -CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE= - -# -# Heap memory debugging -# -CONFIG_HEAP_POISONING_DISABLED= -CONFIG_HEAP_POISONING_LIGHT=y -CONFIG_HEAP_POISONING_COMPREHENSIVE= -CONFIG_HEAP_TRACING= -CONFIG_HEAP_TASK_TRACKING= - -# -# libsodium -# -CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y - -# -# Log output -# -CONFIG_LOG_DEFAULT_LEVEL_NONE= -CONFIG_LOG_DEFAULT_LEVEL_ERROR=y -CONFIG_LOG_DEFAULT_LEVEL_WARN= -CONFIG_LOG_DEFAULT_LEVEL_INFO= -CONFIG_LOG_DEFAULT_LEVEL_DEBUG= -CONFIG_LOG_DEFAULT_LEVEL_VERBOSE= -CONFIG_LOG_DEFAULT_LEVEL=1 -CONFIG_LOG_COLORS= - -# -# LWIP -# -CONFIG_L2_TO_L3_COPY= -CONFIG_ETHARP_SUPPORT_VLAN= -CONFIG_LWIP_IRAM_OPTIMIZATION= -CONFIG_LWIP_MAX_SOCKETS=10 -CONFIG_LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS=y -CONFIG_USE_ONLY_LWIP_SELECT= -CONFIG_LWIP_SO_LINGER= -CONFIG_LWIP_SO_REUSE=y -CONFIG_LWIP_SO_REUSE_RXTOALL=y -CONFIG_LWIP_SO_RCVBUF=y -CONFIG_LWIP_IP4_FRAG=y -CONFIG_LWIP_IP6_FRAG=y -CONFIG_LWIP_IP4_REASSEMBLY= -CONFIG_LWIP_IP6_REASSEMBLY= -CONFIG_LWIP_STATS= -CONFIG_LWIP_ETHARP_TRUST_IP_MAC=y -CONFIG_ESP_GRATUITOUS_ARP=y -CONFIG_GARP_TMR_INTERVAL=60 -CONFIG_TCPIP_RECVMBOX_SIZE=32 -CONFIG_LWIP_DHCP_DOES_ARP_CHECK= -CONFIG_LWIP_DHCP_RESTORE_LAST_IP=y - -# -# DHCP server -# -CONFIG_LWIP_DHCPS_LEASE_UNIT=60 -CONFIG_LWIP_DHCPS_MAX_STATION_NUM=8 -CONFIG_LWIP_AUTOIP= -CONFIG_LWIP_IPV6_AUTOCONFIG= -CONFIG_LWIP_NETIF_LOOPBACK=y -CONFIG_LWIP_LOOPBACK_MAX_PBUFS=8 - -# -# TCP -# -CONFIG_LWIP_TCP_ISN_HOOK=y -CONFIG_LWIP_MAX_ACTIVE_TCP=16 -CONFIG_LWIP_MAX_LISTENING_TCP=16 -CONFIG_TCP_MAXRTX=12 -CONFIG_TCP_SYNMAXRTX=6 -CONFIG_TCP_MSS=1436 -CONFIG_TCP_MSL=60000 -CONFIG_TCP_SND_BUF_DEFAULT=5744 -CONFIG_TCP_WND_DEFAULT=5744 -CONFIG_TCP_RECVMBOX_SIZE=6 -CONFIG_TCP_QUEUE_OOSEQ=y -CONFIG_ESP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES= -CONFIG_TCP_OVERSIZE_MSS=y -CONFIG_TCP_OVERSIZE_QUARTER_MSS= -CONFIG_TCP_OVERSIZE_DISABLE= -CONFIG_LWIP_TCP_RTO_TIME=3000 - -# -# UDP -# -CONFIG_LWIP_MAX_UDP_PCBS=16 -CONFIG_UDP_RECVMBOX_SIZE=6 -CONFIG_TCPIP_TASK_STACK_SIZE=2560 -CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY= -CONFIG_TCPIP_TASK_AFFINITY_CPU0=y -CONFIG_TCPIP_TASK_AFFINITY_CPU1= -CONFIG_TCPIP_TASK_AFFINITY=0x0 -CONFIG_LWIP_IPV6_MEMP_NUM_ND6_QUEUE=3 -CONFIG_LWIP_IPV6_ND6_NUM_NEIGHBORS=5 -CONFIG_PPP_SUPPORT=y -CONFIG_PPP_NOTIFY_PHASE_SUPPORT= -CONFIG_PPP_PAP_SUPPORT=y -CONFIG_PPP_CHAP_SUPPORT=y -CONFIG_PPP_MSCHAP_SUPPORT=y -CONFIG_PPP_MPPE_SUPPORT=y -CONFIG_PPP_DEBUG_ON= - -# -# ICMP -# -CONFIG_LWIP_MULTICAST_PING= -CONFIG_LWIP_BROADCAST_PING= - -# -# LWIP RAW API -# -CONFIG_LWIP_MAX_RAW_PCBS=16 - -# -# SNTP -# -CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1 -CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000 -CONFIG_LWIP_ESP_LWIP_ASSERT=y - -# -# mbedTLS -# -CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y -CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC= -CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC= -CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC= -CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384 -CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN= -CONFIG_MBEDTLS_DEBUG= -CONFIG_MBEDTLS_ECP_RESTARTABLE= -CONFIG_MBEDTLS_CMAC_C= -CONFIG_MBEDTLS_HARDWARE_AES=y -CONFIG_MBEDTLS_HARDWARE_MPI= -CONFIG_MBEDTLS_HARDWARE_SHA= -CONFIG_MBEDTLS_HAVE_TIME=y -CONFIG_MBEDTLS_HAVE_TIME_DATE= -CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=y -CONFIG_MBEDTLS_TLS_SERVER_ONLY= -CONFIG_MBEDTLS_TLS_CLIENT_ONLY= -CONFIG_MBEDTLS_TLS_DISABLED= -CONFIG_MBEDTLS_TLS_SERVER=y -CONFIG_MBEDTLS_TLS_CLIENT=y -CONFIG_MBEDTLS_TLS_ENABLED=y - -# -# TLS Key Exchange Methods -# -CONFIG_MBEDTLS_PSK_MODES=y -CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y -CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_PSK=y -CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK=y -CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=y -CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=y -CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=y -CONFIG_MBEDTLS_SSL_RENEGOTIATION=y -CONFIG_MBEDTLS_SSL_PROTO_SSL3= -CONFIG_MBEDTLS_SSL_PROTO_TLS1=y -CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=y -CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y -CONFIG_MBEDTLS_SSL_PROTO_DTLS= -CONFIG_MBEDTLS_SSL_ALPN=y -CONFIG_MBEDTLS_SSL_SESSION_TICKETS=y - -# -# Symmetric Ciphers -# -CONFIG_MBEDTLS_AES_C=y -CONFIG_MBEDTLS_CAMELLIA_C= -CONFIG_MBEDTLS_DES_C= -CONFIG_MBEDTLS_RC4_DISABLED=y -CONFIG_MBEDTLS_RC4_ENABLED_NO_DEFAULT= -CONFIG_MBEDTLS_RC4_ENABLED= -CONFIG_MBEDTLS_BLOWFISH_C= -CONFIG_MBEDTLS_XTEA_C= -CONFIG_MBEDTLS_CCM_C=y -CONFIG_MBEDTLS_GCM_C=y -CONFIG_MBEDTLS_RIPEMD160_C= - -# -# Certificates -# -CONFIG_MBEDTLS_PEM_PARSE_C=y -CONFIG_MBEDTLS_PEM_WRITE_C=y -CONFIG_MBEDTLS_X509_CRL_PARSE_C=y -CONFIG_MBEDTLS_X509_CSR_PARSE_C=y -CONFIG_MBEDTLS_ECP_C=y -CONFIG_MBEDTLS_ECDH_C=y -CONFIG_MBEDTLS_ECDSA_C=y -CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y -CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y -CONFIG_MBEDTLS_ECP_NIST_OPTIM=y - -# -# mDNS -# -CONFIG_MDNS_MAX_SERVICES=10 - -# -# ESP-MQTT Configurations -# -CONFIG_MQTT_PROTOCOL_311=y -CONFIG_MQTT_TRANSPORT_SSL=y -CONFIG_MQTT_TRANSPORT_WEBSOCKET=y -CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE=y -CONFIG_MQTT_USE_CUSTOM_CONFIG= -CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED= -CONFIG_MQTT_CUSTOM_OUTBOX= - -# -# NVS -# - -# -# OpenSSL -# -CONFIG_OPENSSL_DEBUG= -CONFIG_OPENSSL_ASSERT_DO_NOTHING=y -CONFIG_OPENSSL_ASSERT_EXIT= - -# -# PThreads -# -CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT=5 -CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=2048 -CONFIG_PTHREAD_STACK_MIN=768 -CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY=y -CONFIG_ESP32_DEFAULT_PTHREAD_CORE_0= -CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1= -CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT=-1 -CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread" - -# -# SPI Flash driver -# -CONFIG_SPI_FLASH_VERIFY_WRITE= -CONFIG_SPI_FLASH_ENABLE_COUNTERS= -CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y -CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS=y -CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_FAILS= -CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED= -CONFIG_SPI_FLASH_YIELD_DURING_ERASE= - -# -# SPIFFS Configuration -# -CONFIG_SPIFFS_MAX_PARTITIONS=3 - -# -# SPIFFS Cache Configuration -# -CONFIG_SPIFFS_CACHE=y -CONFIG_SPIFFS_CACHE_WR=y -CONFIG_SPIFFS_CACHE_STATS= -CONFIG_SPIFFS_PAGE_CHECK=y -CONFIG_SPIFFS_GC_MAX_RUNS=10 -CONFIG_SPIFFS_GC_STATS= -CONFIG_SPIFFS_PAGE_SIZE=256 -CONFIG_SPIFFS_OBJ_NAME_LEN=32 -CONFIG_SPIFFS_USE_MAGIC=y -CONFIG_SPIFFS_USE_MAGIC_LENGTH=y -CONFIG_SPIFFS_META_LENGTH=4 -CONFIG_SPIFFS_USE_MTIME=y - -# -# Debug Configuration -# -CONFIG_SPIFFS_DBG= -CONFIG_SPIFFS_API_DBG= -CONFIG_SPIFFS_GC_DBG= -CONFIG_SPIFFS_CACHE_DBG= -CONFIG_SPIFFS_CHECK_DBG= -CONFIG_SPIFFS_TEST_VISUALISATION= - -# -# TCP/IP Adapter -# -CONFIG_IP_LOST_TIMER_INTERVAL=120 -CONFIG_TCPIP_LWIP=y - -# -# Unity unit testing library -# -CONFIG_UNITY_ENABLE_FLOAT=y -CONFIG_UNITY_ENABLE_DOUBLE=y -CONFIG_UNITY_ENABLE_COLOR= -CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y -CONFIG_UNITY_ENABLE_FIXTURE= - -# -# Virtual file system -# -CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT=y -CONFIG_SUPPORT_TERMIOS=y - -# -# Wear Levelling -# -CONFIG_WL_SECTOR_SIZE_512= -CONFIG_WL_SECTOR_SIZE_4096=y -CONFIG_WL_SECTOR_SIZE=4096 - -# -# Wi-Fi Provisioning Manager -# -CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16 - -# -# Supplicant -# -CONFIG_WPA_WPS_WARS= diff --git a/tools/add_sdk_json.py b/tools/add_sdk_json.py new file mode 100644 index 000000000..7b12289bb --- /dev/null +++ b/tools/add_sdk_json.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python + +from __future__ import print_function + +__author__ = "Hristo Gochkov" +__version__ = "2023" + +import os +import shutil +import errno +import os.path +import json +import platform +import sys +import stat +import argparse + +if sys.version_info[0] == 3: + unicode = lambda s: str(s) + +def add_system(systems, host, url, filename, sha, size): + system = { + "host": host, + "url": url, + "archiveFileName": filename, + "checksum": "SHA-256:"+sha, + "size": str(size) + } + systems.append(system) + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + prog = 'add_sdk_json', + description = 'Update SDK in Arduino package index') + parser.add_argument('-j', '--pkg-json', dest='arduino_json', required=True, help='path to package json') + parser.add_argument('-n', '--name', dest='tool_name', required=True, help='name of the SDK package') + parser.add_argument('-v', '--version', dest='tool_version', required=True, help='version of the new SDK') + parser.add_argument('-u', '--url', dest='tool_url', required=True, help='url to the zip of the new SDK') + parser.add_argument('-f', '--filename', dest='tool_filename', required=True, help='filename of the zip of the new SDK') + parser.add_argument('-s', '--size', dest='tool_size', required=True, help='size of the zip of the new SDK') + parser.add_argument('-c', '--sha', dest='tool_sha', required=True, help='sha256 of the zip of the new SDK') + args = parser.parse_args() + + print('Destination : {0}.'.format(args.arduino_json)) + print('Tool Name : {0}.'.format(args.tool_name)) + print('Tool Version : {0}.'.format(args.tool_version)) + print('Tool URL : {0}.'.format(args.tool_url)) + print('Tool File Name: {0}.'.format(args.tool_filename)) + print('Tool Size : {0}.'.format(args.tool_size)) + print('Tool SHA256 : {0}.'.format(args.tool_sha)) + + arduino_json = args.arduino_json; + tool_name = args.tool_name; + tool_version = args.tool_version; + tool_url = args.tool_url; + tool_filename = args.tool_filename; + tool_size = args.tool_size; + tool_sha = args.tool_sha; + + # code start + farray = {"packages":[{"platforms":[{"toolsDependencies":[]}],"tools":[]}]} + if os.path.isfile(arduino_json) == True: + farray = json.load(open(arduino_json)) + + dep_found = False + dep_skip = False + for dep in farray['packages'][0]['platforms'][0]['toolsDependencies']: + if dep['name'] == tool_name: + if dep['version'] == tool_version and not tool_name.startswith('esp32-arduino-libs'): + print('Skipping {0}. Same version {1}'.format(tool_name, tool_version)) + dep_skip = True + break + print('Updating dependency version of {0} from {1} to {2}'.format(tool_name, dep['version'], tool_version)) + dep['version'] = tool_version + dep_found = True + break + + if dep_skip == False: + if dep_found == False: + print('Adding new dependency: {0} version {1}'.format(tool_name, tool_version)) + deps = { + "packager": "esp32", + "name": tool_name, + "version": tool_version + } + farray['packages'][0]['platforms'][0]['toolsDependencies'].append(deps) + + systems = [] + add_system(systems, "i686-mingw32", tool_url, tool_filename, tool_sha, tool_size) + add_system(systems, "x86_64-mingw32", tool_url, tool_filename, tool_sha, tool_size) + add_system(systems, "arm64-apple-darwin", tool_url, tool_filename, tool_sha, tool_size) + add_system(systems, "x86_64-apple-darwin", tool_url, tool_filename, tool_sha, tool_size) + add_system(systems, "x86_64-pc-linux-gnu", tool_url, tool_filename, tool_sha, tool_size) + add_system(systems, "i686-pc-linux-gnu", tool_url, tool_filename, tool_sha, tool_size) + add_system(systems, "aarch64-linux-gnu", tool_url, tool_filename, tool_sha, tool_size) + add_system(systems, "arm-linux-gnueabihf", tool_url, tool_filename, tool_sha, tool_size) + + tool_found = False + for t in farray['packages'][0]['tools']: + if t['name'] == tool_name: + t['version'] = tool_version + t['systems'] = systems + tool_found = True + print('Updating systems of {0} to version {1}'.format(tool_name, tool_version)) + break + + if tool_found == False: + print('Adding new tool: {0} version {1}'.format(tool_name, tool_version)) + tools = { + "name": tool_name, + "version": tool_version, + "systems": systems + } + farray['packages'][0]['tools'].append(tools) + + json_str = json.dumps(farray, indent=2) + with open(arduino_json, "w") as f: + f.write(json_str+"\n") + f.close() + # print(json_str) + print('{0} generated'.format(arduino_json)) diff --git a/tools/archive-build.sh b/tools/archive-build.sh index d6682ff97..f973a42ef 100755 --- a/tools/archive-build.sh +++ b/tools/archive-build.sh @@ -1,16 +1,12 @@ #!/bin/bash -IDF_COMMIT=$(git -C "$IDF_PATH" rev-parse --short HEAD) -IDF_BRANCH=$(git -C "$IDF_PATH" symbolic-ref --short HEAD) - +IDF_COMMIT=$(git -C "$IDF_PATH" rev-parse --short HEAD || echo "") +IDF_BRANCH=$(git -C "$IDF_PATH" symbolic-ref --short HEAD || git -C "$IDF_PATH" tag --points-at HEAD || echo "") idf_version_string=${IDF_BRANCH//\//_}"-$IDF_COMMIT" -archive_path="dist/arduino-esp32-libs-$idf_version_string.tar.gz" -build_archive_path="dist/arduino-esp32-build-$idf_version_string.tar.gz" -mkdir -p dist && rm -rf "$archive_path" "$build_archive_path" +archive_path="dist/arduino-esp32-libs-$1-$idf_version_string.tar.gz" + +mkdir -p dist && rm -rf "$archive_path" if [ -d "out" ]; then cd out && tar zcf "../$archive_path" * && cd .. fi -if [ -d "build" ]; then - cd build && tar zcf "../$build_archive_path" * && cd .. -fi diff --git a/tools/build-bootloaders.sh b/tools/build-bootloaders.sh deleted file mode 100755 index 83df37fd2..000000000 --- a/tools/build-bootloaders.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash -source ./tools/config.sh -TARGET_PATH=$AR_SDK/bin -mkdir -p $TARGET_PATH || exit 1 - -$SED -i '/CONFIG_ESP32_DEFAULT_CPU_FREQ_80/c\CONFIG_ESP32_DEFAULT_CPU_FREQ_80=' ./sdkconfig -$SED -i '/CONFIG_ESP32_DEFAULT_CPU_FREQ_160/c\CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y' ./sdkconfig -$SED -i '/CONFIG_ESP32_DEFAULT_CPU_FREQ_240/c\CONFIG_ESP32_DEFAULT_CPU_FREQ_240=' ./sdkconfig -$SED -i '/CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ/c\CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=160' ./sdkconfig - -$SED -i '/CONFIG_ESPTOOLPY_FLASHFREQ_80M/c\CONFIG_ESPTOOLPY_FLASHFREQ_80M=y' ./sdkconfig -$SED -i '/CONFIG_ESPTOOLPY_FLASHFREQ_40M/c\CONFIG_ESPTOOLPY_FLASHFREQ_40M=' ./sdkconfig - -$SED -i '/CONFIG_SPIRAM_SPEED_40M/c\CONFIG_SPIRAM_SPEED_40M=' ./sdkconfig -echo "CONFIG_SPIRAM_SPEED_80M=y" >> ./sdkconfig -echo "CONFIG_BOOTLOADER_SPI_WP_PIN=7" >> ./sdkconfig -echo "CONFIG_SPIRAM_OCCUPY_HSPI_HOST=y" >> ./sdkconfig -echo "CONFIG_SPIRAM_OCCUPY_VSPI_HOST=" >> ./sdkconfig -echo "CONFIG_SPIRAM_OCCUPY_NO_HOST=" >> ./sdkconfig - -$SED -i '/CONFIG_FLASHMODE_QIO/c\CONFIG_FLASHMODE_QIO=y' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_QOUT/c\CONFIG_FLASHMODE_QOUT=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DIO/c\CONFIG_FLASHMODE_DIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DOUT/c\CONFIG_FLASHMODE_DOUT=' ./sdkconfig -echo "******** BUILDING BOOTLOADER QIO 80MHz *******" -make -j8 bootloader || exit 1 -cp build/bootloader/bootloader.bin $TARGET_PATH/bootloader_qio_80m.bin - -$SED -i '/CONFIG_FLASHMODE_QIO/c\CONFIG_FLASHMODE_QIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_QOUT/c\CONFIG_FLASHMODE_QOUT=y' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DIO/c\CONFIG_FLASHMODE_DIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DOUT/c\CONFIG_FLASHMODE_DOUT=' ./sdkconfig -echo "******** BUILDING BOOTLOADER QOUT 80MHz *******" -make -j8 bootloader || exit 1 -cp build/bootloader/bootloader.bin $TARGET_PATH/bootloader_qout_80m.bin - -echo "CONFIG_SPIRAM_SPIWP_SD3_PIN=7" >> ./sdkconfig - -$SED -i '/CONFIG_FLASHMODE_QIO/c\CONFIG_FLASHMODE_QIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_QOUT/c\CONFIG_FLASHMODE_QOUT=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DIO/c\CONFIG_FLASHMODE_DIO=y' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DOUT/c\CONFIG_FLASHMODE_DOUT=' ./sdkconfig -echo "******** BUILDING BOOTLOADER DIO 80MHz *******" -make -j8 bootloader || exit 1 -cp build/bootloader/bootloader.bin $TARGET_PATH/bootloader_dio_80m.bin - -$SED -i '/CONFIG_FLASHMODE_QIO/c\CONFIG_FLASHMODE_QIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_QOUT/c\CONFIG_FLASHMODE_QOUT=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DIO/c\CONFIG_FLASHMODE_DIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DOUT/c\CONFIG_FLASHMODE_DOUT=y' ./sdkconfig -echo "******** BUILDING BOOTLOADER DOUT 80MHz *******" -make -j8 bootloader || exit 1 -cp build/bootloader/bootloader.bin $TARGET_PATH/bootloader_dout_80m.bin - -$SED -i '/CONFIG_ESPTOOLPY_FLASHFREQ_80M/c\CONFIG_ESPTOOLPY_FLASHFREQ_80M=' ./sdkconfig -$SED -i '/CONFIG_ESPTOOLPY_FLASHFREQ_40M/c\CONFIG_ESPTOOLPY_FLASHFREQ_40M=y' ./sdkconfig - -echo "CONFIG_BOOTLOADER_SPI_WP_PIN=7" >> ./sdkconfig -echo "CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V=" >> ./sdkconfig - -$SED -i '/CONFIG_FLASHMODE_QIO/c\CONFIG_FLASHMODE_QIO=y' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_QOUT/c\CONFIG_FLASHMODE_QOUT=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DIO/c\CONFIG_FLASHMODE_DIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DOUT/c\CONFIG_FLASHMODE_DOUT=' ./sdkconfig -echo "******** BUILDING BOOTLOADER QIO 40MHz *******" -make -j8 bootloader || exit 1 -cp build/bootloader/bootloader.bin $TARGET_PATH/bootloader_qio_40m.bin - -$SED -i '/CONFIG_FLASHMODE_QIO/c\CONFIG_FLASHMODE_QIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_QOUT/c\CONFIG_FLASHMODE_QOUT=y' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DIO/c\CONFIG_FLASHMODE_DIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DOUT/c\CONFIG_FLASHMODE_DOUT=' ./sdkconfig -echo "******** BUILDING BOOTLOADER QOUT 40MHz *******" -make -j8 bootloader || exit 1 -cp build/bootloader/bootloader.bin $TARGET_PATH/bootloader_qout_40m.bin - -echo "CONFIG_SPIRAM_SPIWP_SD3_PIN=7" >> ./sdkconfig - -$SED -i '/CONFIG_FLASHMODE_QIO/c\CONFIG_FLASHMODE_QIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_QOUT/c\CONFIG_FLASHMODE_QOUT=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DIO/c\CONFIG_FLASHMODE_DIO=y' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DOUT/c\CONFIG_FLASHMODE_DOUT=' ./sdkconfig -echo "******** BUILDING BOOTLOADER DIO 40MHz *******" -make -j8 bootloader || exit 1 -cp build/bootloader/bootloader.bin $TARGET_PATH/bootloader_dio_40m.bin - -$SED -i '/CONFIG_FLASHMODE_QIO/c\CONFIG_FLASHMODE_QIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_QOUT/c\CONFIG_FLASHMODE_QOUT=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DIO/c\CONFIG_FLASHMODE_DIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DOUT/c\CONFIG_FLASHMODE_DOUT=y' ./sdkconfig -echo "******** BUILDING BOOTLOADER DOUT 40MHz *******" -make -j8 bootloader || exit 1 -cp build/bootloader/bootloader.bin $TARGET_PATH/bootloader_dout_40m.bin - diff --git a/tools/build-libs.sh b/tools/build-libs.sh deleted file mode 100755 index 49a668826..000000000 --- a/tools/build-libs.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -#remove previous build -rm -rf ./out ./build - -# ensure proper settings -$SED -i '/CONFIG_FLASHMODE_QIO/c\CONFIG_FLASHMODE_QIO=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_QOUT/c\CONFIG_FLASHMODE_QOUT=' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DIO/c\CONFIG_FLASHMODE_DIO=y' ./sdkconfig -$SED -i '/CONFIG_FLASHMODE_DOUT/c\CONFIG_FLASHMODE_DOUT=' ./sdkconfig - -$SED -i '/CONFIG_ESP32_DEFAULT_CPU_FREQ_80/c\CONFIG_ESP32_DEFAULT_CPU_FREQ_80=' ./sdkconfig -$SED -i '/CONFIG_ESP32_DEFAULT_CPU_FREQ_160/c\CONFIG_ESP32_DEFAULT_CPU_FREQ_160=' ./sdkconfig -$SED -i '/CONFIG_ESP32_DEFAULT_CPU_FREQ_240/c\CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y' ./sdkconfig -$SED -i '/CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ/c\CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240' ./sdkconfig - -# make the example -make defconfig -make -j8 #fixes make issue where build fails in arduino core subfolder -make -j8 idf-libs || exit 1 diff --git a/tools/check-deploy-needed.sh b/tools/check-deploy-needed.sh new file mode 100755 index 000000000..e33cc169c --- /dev/null +++ b/tools/check-deploy-needed.sh @@ -0,0 +1,139 @@ +#/bin/bash + +source ./tools/config.sh + +IDF_COMMIT=`github_last_commit "$IDF_REPO" "$IDF_BRANCH"` + +if [ -z $IDF_COMMIT ]; then + echo "Failed to get IDF commit for branch $IDF_BRANCH" + exit 1 +fi + +if [ -z $GITHUB_HEAD_REF ]; then + current_branch=`git branch --show-current` +else + current_branch="$GITHUB_HEAD_REF" +fi + +AR_BRANCH="master" +if [[ "$current_branch" != "master" && `github_branch_exists "$AR_REPO" "$current_branch"` == "1" ]]; then + AR_BRANCH="$current_branch" +else + AR_BRANCH_NAME="idf-$IDF_BRANCH" + has_ar_branch=`github_branch_exists "$AR_REPO" "$AR_BRANCH_NAME"` + if [ "$has_ar_branch" == "1" ]; then + AR_BRANCH="$AR_BRANCH_NAME" + else + has_ar_branch=`github_branch_exists "$AR_REPO" "$AR_PR_TARGET_BRANCH"` + if [ "$has_ar_branch" == "1" ]; then + AR_BRANCH="$AR_PR_TARGET_BRANCH" + fi + fi +fi + +# format new branch name and pr title +AR_NEW_BRANCH_NAME="idf-$IDF_BRANCH" +AR_NEW_COMMIT_MESSAGE="IDF $IDF_BRANCH $IDF_COMMIT" +AR_NEW_PR_TITLE="IDF $IDF_BRANCH" + +LIBS_RELEASE_TAG="idf-"${IDF_BRANCH//\//_}"" +LIBS_VERSION_PREFIX="$LIBS_RELEASE_TAG-$IDF_COMMIT-v" +VERSION_COUNTER=1 + +AR_HAS_BRANCH=`github_branch_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME"` +if [ "$AR_HAS_BRANCH" == "1" ]; then + LATEST_LIBS_IDF=`github_get_libs_idf "$AR_REPO" "$AR_NEW_BRANCH_NAME" "$AR_NEW_PR_TITLE"` +else + LATEST_LIBS_IDF=`github_get_libs_idf "$AR_REPO" "$AR_BRANCH" "$AR_NEW_PR_TITLE"` +fi + +echo "Current IDF commit: $IDF_COMMIT" +echo "Latest IDF commit in $AR_BRANCH of $AR_REPO: $LATEST_LIBS_IDF" + +AR_HAS_COMMIT=`if [ "$LATEST_LIBS_IDF" == "$IDF_COMMIT" ]; then echo "1"; else echo "0"; fi` +AR_HAS_PR=`github_pr_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME"` + +LIBS_RELEASE_ID=`github_release_id "$AR_LIBS_REPO" "$LIBS_RELEASE_TAG"` +LIBS_HAS_RELEASE=`if [ -n "$LIBS_RELEASE_ID" ]; then echo "1"; else echo "0"; fi` + +if [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]; then + echo "Workflow dispatch event. Generating new libs." + while true; do + LIBS_ASSET_ID=`github_release_asset_id "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "esp32-arduino-libs-$LIBS_VERSION_PREFIX$VERSION_COUNTER.zip"` + if [ -n "$LIBS_ASSET_ID" ]; then + VERSION_COUNTER=$((VERSION_COUNTER+1)) + else + break + fi + done +else + LIBS_ASSET_ID=`github_release_asset_id "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "esp32-arduino-libs-$LIBS_VERSION_PREFIX$VERSION_COUNTER.zip"` +fi + +LIBS_VERSION="$LIBS_VERSION_PREFIX$VERSION_COUNTER" +LIBS_HAS_ASSET=`if [ -n "$LIBS_ASSET_ID" ]; then echo "1"; else echo "0"; fi` + +export IDF_COMMIT + +export AR_NEW_BRANCH_NAME +export AR_NEW_COMMIT_MESSAGE +export AR_NEW_PR_TITLE + +export AR_HAS_COMMIT +export AR_HAS_BRANCH +export AR_HAS_PR + +export LIBS_RELEASE_TAG +export LIBS_VERSION +export LIBS_RELEASE_ID +export LIBS_HAS_RELEASE +export LIBS_ASSET_ID +export LIBS_HAS_ASSET + +if [ "$LIBS_HAS_RELEASE" == "1" ]; then + if [ "$LIBS_HAS_ASSET" == "0" ] || [ "$AR_HAS_COMMIT" == "0" ]; then + echo "Deploy needed" + export DEPLOY_NEEDED="1" + else + echo "Deploy not needed. Skipping..." + export DEPLOY_NEEDED="0" + fi +else + echo "Release for tag \"$LIBS_RELEASE_TAG\" not found. Please create the release first." + exit 1 +fi + +echo "IDF_COMMIT: $IDF_COMMIT" +echo "AR_BRANCH: $AR_BRANCH" +echo "AR_NEW_COMMIT_MESSAGE: $AR_NEW_COMMIT_MESSAGE" +echo "AR_NEW_BRANCH_NAME: $AR_NEW_BRANCH_NAME" +echo "AR_NEW_PR_TITLE: $AR_NEW_PR_TITLE" +echo "AR_HAS_COMMIT: $AR_HAS_COMMIT" +echo "AR_HAS_BRANCH: $AR_HAS_BRANCH" +echo "AR_HAS_PR: $AR_HAS_PR" +echo "LIBS_RELEASE_TAG: $LIBS_RELEASE_TAG" +echo "LIBS_VERSION: $LIBS_VERSION" +echo "LIBS_RELEASE_ID: $LIBS_RELEASE_ID" +echo "LIBS_HAS_RELEASE: $LIBS_HAS_RELEASE" +echo "LIBS_ASSET_ID: $LIBS_ASSET_ID" +echo "LIBS_HAS_ASSET: $LIBS_HAS_ASSET" +echo "DEPLOY_NEEDED: $DEPLOY_NEEDED" + +if [ ! -x $GITHUB_OUTPUT ]; then + echo "idf_commit=$IDF_COMMIT" >> "$GITHUB_OUTPUT" + echo "ar_branch=$AR_BRANCH" >> "$GITHUB_OUTPUT" + echo "ar_new_commit_message=$AR_NEW_COMMIT_MESSAGE" >> "$GITHUB_OUTPUT" + echo "ar_new_branch_name=$AR_NEW_BRANCH_NAME" >> "$GITHUB_OUTPUT" + echo "ar_new_pr_title=$AR_NEW_PR_TITLE" >> "$GITHUB_OUTPUT" + echo "ar_has_commit=$AR_HAS_COMMIT" >> "$GITHUB_OUTPUT" + echo "ar_has_branch=$AR_HAS_BRANCH" >> "$GITHUB_OUTPUT" + echo "ar_has_pr=$AR_HAS_PR" >> "$GITHUB_OUTPUT" + echo "libs_release_tag=$LIBS_RELEASE_TAG" >> "$GITHUB_OUTPUT" + echo "libs_version=$LIBS_VERSION" >> "$GITHUB_OUTPUT" + echo "libs_release_id=$LIBS_RELEASE_ID" >> "$GITHUB_OUTPUT" + echo "libs_has_release=$LIBS_HAS_RELEASE" >> "$GITHUB_OUTPUT" + echo "libs_asset_id=$LIBS_ASSET_ID" >> "$GITHUB_OUTPUT" + echo "libs_has_asset=$LIBS_HAS_ASSET" >> "$GITHUB_OUTPUT" + echo "deploy_needed=$DEPLOY_NEEDED" >> "$GITHUB_OUTPUT" +fi + diff --git a/tools/combine-artifacts.sh b/tools/combine-artifacts.sh new file mode 100755 index 000000000..8cb1c25e2 --- /dev/null +++ b/tools/combine-artifacts.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e +mkdir -p out + +libs_folder="out/tools/esp32-arduino-libs" + +files=$(find dist -name 'arduino-esp32-libs-esp*.tar.gz') +for file in $files; do + echo "Extracting $file" + tar zxf $file -C out + cat $libs_folder/versions.txt >> $libs_folder/versions_full.txt +done + +# Merge versions.txt files +awk -i inplace '!seen[$0]++' $libs_folder/versions_full.txt +mv -f $libs_folder/versions_full.txt $libs_folder/versions.txt + +echo "Creating zip file" +cd out/tools && zip -q -r ../../dist/esp32-arduino-libs.zip * && cd ../.. diff --git a/tools/config.sh b/tools/config.sh index 06080f23d..79d4feef5 100755 --- a/tools/config.sh +++ b/tools/config.sh @@ -1,64 +1,84 @@ #!/bin/bash -IDF_COMPS="$IDF_PATH/components" -IDF_TOOLCHAIN="xtensa-esp32-elf" -IDF_TOOLCHAIN_LINUX_ARMEL="https://dl.espressif.com/dl/xtensa-esp32-elf-linux-armel-1.22.0-96-g2852398-5.2.0.tar.gz" -IDF_TOOLCHAIN_LINUX32="https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-96-g2852398-5.2.0.tar.gz" -IDF_TOOLCHAIN_LINUX64="https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-96-g2852398-5.2.0.tar.gz" -IDF_TOOLCHAIN_WIN32="https://dl.espressif.com/dl/xtensa-esp32-elf-win32-1.22.0-96-g2852398-5.2.0.zip" -IDF_TOOLCHAIN_MACOS="https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-96-g2852398-5.2.0.tar.gz" + +if [ -z $IDF_PATH ]; then + export IDF_PATH="$PWD/esp-idf" +fi if [ -z $IDF_BRANCH ]; then - IDF_BRANCH="release/v3.3" + IDF_BRANCH="release/v5.4" +fi + +if [ -z $AR_PR_TARGET_BRANCH ]; then + AR_PR_TARGET_BRANCH="master" +fi + +if [ -z $IDF_TARGET ]; then + if [ -f sdkconfig ]; then + IDF_TARGET=`cat sdkconfig | grep CONFIG_IDF_TARGET= | cut -d'"' -f2` + if [ "$IDF_TARGET" = "" ]; then + IDF_TARGET="esp32" + fi + else + IDF_TARGET="esp32" + fi fi # Owner of the target ESP32 Arduino repository -AR_USER="espressif" +AR_USER="${GITHUB_REPOSITORY_OWNER:-espressif}" # The full name of the repository AR_REPO="$AR_USER/arduino-esp32" +IDF_REPO="$AR_USER/esp-idf" +AR_LIBS_REPO="$AR_USER/esp32-arduino-lib-builder" -IDF_REPO_URL="https://github.com/espressif/esp-idf.git" -CAMERA_REPO_URL="https://github.com/espressif/esp32-camera.git" -FACE_REPO_URL="https://github.com/espressif/esp-face.git" AR_REPO_URL="https://github.com/$AR_REPO.git" - +IDF_REPO_URL="https://github.com/$IDF_REPO.git" +AR_LIBS_REPO_URL="https://github.com/$AR_LIBS_REPO.git" if [ -n $GITHUB_TOKEN ]; then - AR_REPO_URL="https://$GITHUB_TOKEN@github.com/$AR_REPO.git" + AR_REPO_URL="https://$GITHUB_TOKEN@github.com/$AR_REPO.git" + AR_LIBS_REPO_URL="https://$GITHUB_TOKEN@github.com/$AR_LIBS_REPO.git" fi AR_ROOT="$PWD" AR_COMPS="$AR_ROOT/components" +AR_MANAGED_COMPS="$AR_ROOT/managed_components" AR_OUT="$AR_ROOT/out" AR_TOOLS="$AR_OUT/tools" +AR_PATCHES="$AR_ROOT/patches" AR_PLATFORM_TXT="$AR_OUT/platform.txt" -AR_PLATFORMIO_PY="$AR_TOOLS/platformio-build.py" -AR_ESPTOOL_PY="$AR_TOOLS/esptool.py" AR_GEN_PART_PY="$AR_TOOLS/gen_esp32part.py" -AR_SDK="$AR_TOOLS/sdk" +AR_SDK="$AR_TOOLS/esp32-arduino-libs/$IDF_TARGET" +PIOARDUINO_SDK="FRAMEWORK_SDK_DIR, \"$IDF_TARGET\"" +TOOLS_JSON_OUT="$AR_TOOLS/esp32-arduino-libs" + +if [ -d "$IDF_PATH" ]; then + export IDF_COMMIT=$(git -C "$IDF_PATH" rev-parse --short HEAD) + export IDF_BRANCH=$(git -C "$IDF_PATH" symbolic-ref --short HEAD || git -C "$IDF_PATH" tag --points-at HEAD) +fi function get_os(){ - OSBITS=`arch` - if [[ "$OSTYPE" == "linux"* ]]; then + OSBITS=`uname -m` + if [[ "$OSTYPE" == "linux"* ]]; then if [[ "$OSBITS" == "i686" ]]; then - echo "linux32" + echo "linux32" elif [[ "$OSBITS" == "x86_64" ]]; then - echo "linux64" + echo "linux64" elif [[ "$OSBITS" == "armv7l" ]]; then - echo "linux-armel" + echo "linux-armel" else - echo "unknown" - return 1 + echo "unknown" + return 1 fi - elif [[ "$OSTYPE" == "darwin"* ]]; then - echo "macos" - elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then - echo "win32" - else - echo "$OSTYPE" - return 1 - fi - return 0 + elif [[ "$OSTYPE" == "darwin"* ]]; then + echo "macos" + elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then + echo "win32" + else + echo "$OSTYPE" + return 1 + fi + return 0 } AR_OS=`get_os` @@ -67,41 +87,154 @@ export SED="sed" export SSTAT="stat -c %s" if [[ "$AR_OS" == "macos" ]]; then - export SED="gsed" - export SSTAT="stat -f %z" + if ! [ -x "$(command -v gsed)" ]; then + echo "ERROR: gsed is not installed! Please install gsed first. ex. brew install gsed" + exit 1 + fi + if ! [ -x "$(command -v gawk)" ]; then + echo "ERROR: gawk is not installed! Please install gawk first. ex. brew install gawk" + exit 1 + fi + export SED="gsed" + export SSTAT="stat -f %z" fi -function git_commit_exists(){ #git_commit_exists - local repo_path="$1" - local commit_message="$2" - local commits_found=`git -C "$repo_path" log --all --grep="$commit_message" | grep commit` - if [ -n "$commits_found" ]; then echo 1; else echo 0; fi +function github_get_libs_idf(){ # github_get_libs_idf + local repo_path="$1" + local branch_name="$2" + local message_prefix="$3" + message_prefix=$(echo $message_prefix | sed 's/[]\/$*.^|[]/\\&/g') # Escape special characters + local page=1 + local version_found="" + local libs_version="" + + while [[ "$libs_version" == "" && "$page" -le 3 ]]; do + # Get the latest commit message that matches the prefix and extract the hash from the last commit message + version_found=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits?sha=$branch_name&per_page=100&page=$page" | \ + jq -r --arg prefix "$message_prefix" '[ .[] | select(.commit.message | test($prefix + " [a-f0-9]{8}")) ][0] | .commit.message' | \ + grep -Eo "$message_prefix [a-f0-9]{8}" | \ + awk 'END {print $NF}'` + if [[ "$version_found" != "" && "$version_found" != "null" ]]; then + libs_version=$version_found + else + page=$((page+1)) + fi + done + + if [ ! "$libs_version" == "" ] && [ ! "$libs_version" == "null" ]; then echo $libs_version; else echo ""; fi } +function github_commit_exists(){ #github_commit_exists + local repo_path="$1" + local branch_name="$2" + local commit_message="$3" + local page=1 + local commits_found=0 + + while [ "$page" -le 3 ]; do + local response=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits?sha=$branch_name&per_page=100&page=$page"` + + if [[ -z "$response" || "$response" == "[]" ]]; then + break + fi + + local commits=`echo "$response" | jq -r '.[].commit.message' | grep "$commit_message" | wc -l` + if [ "$commits" -gt 0 ]; then + commits_found=1 + break + fi + + page=$((page+1)) + done + + echo $commits_found +} + +function github_last_commit(){ # github_last_commit + local repo_path="$1" + local branch_name="$2" + local commit=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits/heads/$branch_name" | jq -r '.sha'` + if [ ! "$commit" == "" ] && [ ! "$commit" == "null" ]; then + echo ${commit:0:8} + else + echo "" + fi +} + +function github_branch_exists(){ # github_branch_exists + local repo_path="$1" + local branch_name="$2" + local branch=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/branches/$branch_name" | jq -r '.name'` + if [ "$branch" == "$branch_name" ]; then echo 1; else echo 0; fi +} + +function github_pr_exists(){ # github_pr_exists + local repo_path="$1" + local branch_name="$2" + local pr_num=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/pulls?head=$AR_USER:$branch_name&state=open" | jq -r '.[].number'` + if [ ! "$pr_num" == "" ] && [ ! "$pr_num" == "null" ]; then echo 1; else echo 0; fi +} + +function github_release_id(){ # github_release_id + local repo_path="$1" + local release_tag="$2" + local release=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases" | jq --arg release_tag "$release_tag" -r '.[] | select(.tag_name == $release_tag) | .id'` + if [ ! "$release" == "" ] && [ ! "$release" == "null" ]; then echo "$release"; else echo ""; fi +} + +function github_release_asset_id(){ # github_release_asset_id + local repo_path="$1" + local release_id="$2" + local release_file="$3" + local release_asset=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases/$release_id/assets" | jq --arg release_file "$release_file" -r '.[] | select(.name == $release_file) | .id'` + if [ ! "$release_asset" == "" ] && [ ! "$release_asset" == "null" ]; then echo "$release_asset"; else echo ""; fi +} + +function github_release_asset_upload(){ # github_release_asset_upload + local repo_path="$1" + local release_id="$2" + local release_file_name="$3" + local release_file_path="$4" + local file_extension="${release_file_name##*.}" + local release_asset=`curl -s -k -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" -H "Content-Type: application/$file_extension" --data-binary "@$release_file_path" "https://uploads.github.com/repos/$repo_path/releases/$release_id/assets?name=$release_file_name" | jq -r '.id'` + if [ ! "$release_asset" == "" ] && [ ! "$release_asset" == "null" ]; then echo "$release_asset"; else echo ""; fi +} + +function github_release_asset_delete(){ # github_release_asset_delete + local repo_path="$1" + local release_asset_id="$2" + local res + local return_code + res=$(curl -s -k -o /dev/null -w "%{http_code}" -X DELETE -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases/assets/$release_asset_id") + return_code=$? + if [ "$res" -eq 204 ] && [ "$return_code" -eq 0 ] ; then echo 1; else echo 0; fi +} + + function git_branch_exists(){ # git_branch_exists - local repo_path="$1" - local branch_name="$2" - local branch_found=`git -C "$repo_path" ls-remote --heads origin "$branch_name"` - if [ -n "$branch_found" ]; then echo 1; else echo 0; fi + local repo_path="$1" + local branch_name="$2" + local branch_found=`git -C "$repo_path" ls-remote --heads origin "$branch_name"` + if [ -n "$branch_found" ]; then echo 1; else echo 0; fi } -function git_pr_exists(){ # git_pr_exists - local pr_num=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$AR_REPO/pulls?head=$AR_USER:$1&state=open" | jq -r '.[].number'` - if [ ! "$pr_num" == "" ] && [ ! "$pr_num" == "null" ]; then echo 1; else echo 0; fi +function git_commit_exists(){ #git_commit_exists + local repo_path="$1" + local commit_message="$2" + local commits_found=`git -C "$repo_path" log --all --grep="$commit_message" | grep commit` + if [ -n "$commits_found" ]; then echo 1; else echo 0; fi } function git_create_pr(){ # git_create_pr - local pr_branch="$1" - local pr_title="$2" - local pr_body="" - for component in `ls "$AR_COMPS"`; do - if [ ! $component == "arduino" ] && [ -d "$AR_COMPS/$component/.git" ]; then - pr_body+="$component: "$(git -C "$AR_COMPS/$component" symbolic-ref --short HEAD)" "$(git -C "$AR_COMPS/$component" rev-parse --short HEAD)"\r\n" - fi - done - local pr_data="{\"title\": \"$pr_title\", \"body\": \"$pr_body\", \"head\": \"$AR_USER:$pr_branch\", \"base\": \"master\"}" - git_create_pr_res=`echo "$pr_data" | curl -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" --data @- "https://api.github.com/repos/$AR_REPO/pulls"` - local done_pr=`echo "$git_create_pr_res" | jq -r '.title'` - if [ ! "$done_pr" == "" ] && [ ! "$done_pr" == "null" ]; then echo 1; else echo 0; fi + local pr_branch="$1" + local pr_title="$2" + local pr_target="$3" + local pr_body="\`\`\`\r\n" + while read -r line; do pr_body+=$line"\r\n"; done < "$AR_TOOLS/esp32-arduino-libs/versions.txt" + pr_body+="\`\`\`\r\n" + local pr_data="{\"title\": \"$pr_title\", \"body\": \"$pr_body\", \"head\": \"$AR_USER:$pr_branch\", \"base\": \"$pr_target\"}" + git_create_pr_res=`echo "$pr_data" | curl -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" --data @- "https://api.github.com/repos/$AR_REPO/pulls"` + local done_pr=`echo "$git_create_pr_res" | jq -r '.title'` + if [ ! "$done_pr" == "" ] && [ ! "$done_pr" == "null" ]; then echo 1; else echo 0; fi } diff --git a/tools/config_editor/.gitignore b/tools/config_editor/.gitignore new file mode 100644 index 000000000..a230a78ae --- /dev/null +++ b/tools/config_editor/.gitignore @@ -0,0 +1,2 @@ +.venv/ +__pycache__/ diff --git a/tools/config_editor/README.md b/tools/config_editor/README.md new file mode 100644 index 000000000..9abd93fc7 --- /dev/null +++ b/tools/config_editor/README.md @@ -0,0 +1,40 @@ +# Arduino Static Libraries Configuration Editor + +This is a simple application to configure the static libraries for the ESP32 Arduino core. +It allows the user to select the targets to compile, change the configuration options and compile the libraries. +It has mouse support and can be pre-configured using command line arguments. + +## Requirements + - Python 3.9 or later + - Install the required packages using `pip install -r requirements.txt` + - The requirements from esp32-arduino-lib-builder + +## Troubleshooting + +In some cases, the UI might not look as expected. This can happen due to the terminal emulator not supporting the required features. + +### WSL + +If you are using WSL, it is recommended to use the Windows Terminal to visualize the application. Otherwise, the application layout and colors might not be displayed correctly. +The Windows Terminal can be installed from the Microsoft Store. + +### MacOS + +If you are using MacOS and the application looks weird, check [this guide from Textual](https://textual.textualize.io/FAQ/#why-doesnt-textual-look-good-on-macos) to fix it. + +## Usage + +These command line arguments can be used to pre-configure the application: + +``` +Command line arguments: + -t, --target <target> Comma-separated list of targets to be compiled. + Choose from: all, esp32, esp32s2, esp32s3, esp32c2, esp32c3, esp32c6, esp32h2. Default: all except esp32c2 + --copy, --no-copy Enable/disable copying the compiled libraries to arduino-esp32. Enabled by default + -c, --arduino-path <path> Path to arduino-esp32 directory. Default: OS dependent + -A, --arduino-branch <branch> Branch of the arduino-esp32 repository to be used. Default: set by the build script + -I, --idf-branch <branch> Branch of the ESP-IDF repository to be used. Default: set by the build script + -i, --idf-commit <commit> Commit of the ESP-IDF repository to be used. Default: set by the build script + -D, --debug-level <level> Debug level to be set to ESP-IDF. + Choose from: default, none, error, warning, info, debug, verbose. Default: default +``` diff --git a/tools/config_editor/app.py b/tools/config_editor/app.py new file mode 100755 index 000000000..dbe24ca05 --- /dev/null +++ b/tools/config_editor/app.py @@ -0,0 +1,295 @@ +#!/usr/bin/env python + +""" +Arduino Static Libraries Configuration Editor + +This is a simple application to configure the static libraries for the ESP32 Arduino core. +It allows the user to select the targets to compile, change the configuration options and compile the libraries. + +Requires Python 3.9 or later. + +The application is built using the "textual" library, which is a Python library for building text-based user interfaces. + +Note that this application still needs the requirements from esp32-arduino-lib-builder to be installed. + +Command line arguments: + -t, --target <target> Comma-separated list of targets to be compiled. + Choose from: all, esp32, esp32s2, esp32s3, esp32c2, esp32c3, esp32c6, esp32h2. Default: all except esp32c2 + --copy, --no-copy Enable/disable copying the compiled libraries to arduino-esp32. Enabled by default + -c, --arduino-path <path> Path to arduino-esp32 directory. Default: OS dependent + -A, --arduino-branch <branch> Branch of the arduino-esp32 repository to be used. Default: set by the build script + -I, --idf-branch <branch> Branch of the ESP-IDF repository to be used. Default: set by the build script + -i, --idf-commit <commit> Commit of the ESP-IDF repository to be used. Default: set by the build script + -D, --debug-level <level> Debug level to be set to ESP-IDF. + Choose from: default, none, error, warning, info, debug, verbose. Default: default + +""" + +import argparse +import json +import os +import platform +import sys + +from pathlib import Path + +try: + from textual.app import App, ComposeResult + from textual.binding import Binding + from textual.containers import VerticalScroll + from textual.screen import Screen + from textual.widgets import Button, Header, Label, Footer +except ImportError: + print("Please install the \"textual\" package before running this script.") + exit(1) + +from settings import SettingsScreen +from editor import EditorScreen +from compile import CompileScreen + +class MainScreen(Screen): + # Main screen class + + # Set the key bindings + BINDINGS = [ + Binding("c", "app.push_screen('compile')", "Compile"), + Binding("e", "app.push_screen('editor')", "Editor"), + Binding("s", "app.push_screen('settings')", "Settings"), + Binding("q", "app.quit", "Quit"), + ] + + def on_button_pressed(self, event: Button.Pressed) -> None: + # Event handler called when a button is pressed + if event.button.id == "compile-button": + print("Compile button pressed") + self.app.push_screen("compile") + elif event.button.id == "settings-button": + print("Settings button pressed") + self.app.push_screen("settings") + elif event.button.id == "editor-button": + print("Editor button pressed") + self.app.push_screen("editor") + elif event.button.id == "quit-button": + print("Quit button pressed") + self.app.exit() + + def compose(self) -> ComposeResult: + # Compose main menu + yield Header() + with VerticalScroll(id="main-menu-container"): + yield Label("ESP32 Arduino Static Libraries Configuration Editor", id="main-menu-title") + yield Button("Compile Static Libraries", id="compile-button", classes="main-menu-button") + yield Button("Sdkconfig Editor", id="editor-button", classes="main-menu-button") + yield Button("Settings", id="settings-button", classes="main-menu-button") + yield Button("Quit", id="quit-button", classes="main-menu-button") + yield Footer() + + def on_mount(self) -> None: + # Event handler called when the app is mounted for the first time + self.sub_title = "Main Menu" + print("Main screen mounted.") + +class ConfigEditorApp(App): + # Main application class + + # Set the root and script paths + SCRIPT_PATH = os.path.abspath(os.path.dirname(__file__)) + ROOT_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", "..")) + + # Set the application options + supported_targets = [] + setting_enable_copy = True + + # Options to be set by the command line arguments + setting_target = "" + setting_arduino_path = "" + setting_output_permissions = "" + setting_arduino_branch = "" + setting_idf_branch = "" + setting_idf_commit = "" + setting_debug_level = "" + + ENABLE_COMMAND_PALETTE = False + CSS_PATH = "style.tcss" + SCREENS = { + "main": MainScreen, + "settings": SettingsScreen, + "compile": CompileScreen, + "editor": EditorScreen, + } + + def on_mount(self) -> None: + print("Application mounted. Initial options:") + print("Python version: " + sys.version) + print("Root path: " + self.ROOT_PATH) + print("Script path: " + self.SCRIPT_PATH) + print("Supported Targets: " + ", ".join(self.supported_targets)) + print("Default targets: " + self.setting_target) + print("Enable Copy: " + str(self.setting_enable_copy)) + print("Arduino Path: " + str(self.setting_arduino_path)) + print("Arduino Branch: " + str(self.setting_arduino_branch)) + print("IDF Branch: " + str(self.setting_idf_branch)) + print("IDF Commit: " + str(self.setting_idf_commit)) + print("IDF Debug Level: " + str(self.setting_debug_level)) + self.title = "Configurator" + self.push_screen("main") + +def arduino_default_path(): + sys_name = platform.system() + home = str(Path.home()) + if sys_name == "Linux": + return os.path.join(home, "Arduino", "hardware", "espressif", "esp32") + else: # Windows and MacOS + return os.path.join(home, "Documents", "Arduino", "hardware", "espressif", "esp32") + +def check_arduino_path(path): + return os.path.isdir(path) + +def main() -> None: + # Set the PYTHONUNBUFFERED environment variable to "1" to disable the output buffering + os.environ['PYTHONUNBUFFERED'] = "1" + + # Check Python version + if sys.version_info < (3, 9): + print("This script requires Python 3.9 or later") + exit(1) + + app = ConfigEditorApp() + + # List of tuples for the target choices containing the target name and if it is enabled by default + target_choices = [] + + # Parse build JSON file + build_json_path = os.path.join(app.ROOT_PATH, "configs", "builds.json") + if os.path.isfile(build_json_path): + with open(build_json_path, "r") as build_json_file: + build_json = json.load(build_json_file) + for target in build_json["targets"]: + try: + default = False if target["skip"] else True + except: + default = True + target_choices.append((target["target"], default)) + else: + print("Error: configs/builds.json file not found.") + exit(1) + + target_choices.sort(key=lambda x: x[0]) + + parser = argparse.ArgumentParser(description="Configure and compile the ESP32 Arduino static libraries") + + parser.add_argument("-t", "--target", + metavar="<target>", + type=str, + default="default", + required=False, + help="Comma-separated list of targets to be compiled. Choose from: " + ", ".join([x[0] for x in target_choices]) + + ". Default: All except " + ", ".join([x[0] for x in target_choices if not x[1]])) + + parser.add_argument("--copy", + type=bool, + action=argparse.BooleanOptionalAction, + default=True, + required=False, + help="Enable/disable copying the compiled libraries to arduino-esp32. Enabled by default") + + parser.add_argument("-c", "--arduino-path", + metavar="<arduino path>", + type=str, + default=arduino_default_path(), + required=False, + help="Path to arduino-esp32 directory. Default: " + arduino_default_path()) + + parser.add_argument("--output-permissions", + metavar="<uid:gid>", + type=str, + default="", + required=False, + help=argparse.SUPPRESS) # Hidden option. It is only supposed to be used by the docker container + + parser.add_argument("-A", "--arduino-branch", + metavar="<arduino branch>", + type=str, + default="", + required=False, + help="Branch of the arduino-esp32 repository to be used") + + parser.add_argument("-I", "--idf-branch", + metavar="<IDF branch>", + type=str, + default="", + required=False, + help="Branch of the ESP-IDF repository to be used") + + parser.add_argument("-i", "--idf-commit", + metavar="<IDF commit>", + type=str, + default="", + required=False, + help="Commit of the ESP-IDF repository to be used") + + debug_level_choices = ("default", "none", "error", "warning", "info", "debug", "verbose") + parser.add_argument("-D", "--debug-level", + metavar="<level>", + type=str, + default="default", + choices=debug_level_choices, + required=False, + help="Debug level to be set to ESP-IDF. Choose from: " + ", ".join(debug_level_choices)) + + args = parser.parse_args() + + # Force targets to be lower case + args.target = args.target.lower() + + # Check if the target is valid + if args.target == "default": + args.target = ",".join([x[0] for x in target_choices if x[1]]) + elif args.target == "all": + args.target = ",".join([x[0] for x in target_choices]) + + app.supported_targets = [x[0] for x in target_choices] + + for target in args.target.split(","): + if target not in app.supported_targets: + print("Invalid target: " + target) + exit(1) + + app.setting_target = args.target + + # Check if the Arduino path is valid + if args.copy: + if check_arduino_path(args.arduino_path): + app.setting_enable_copy = True + elif args.arduino_path == arduino_default_path(): + print("Warning: Default Arduino path not found. Disabling copy to Arduino.") + app.setting_enable_copy = False + elif args.arduino_path == "/arduino-esp32": # Docker mount point + print("Warning: Docker mount point not found. Disabling copy to Arduino.") + app.setting_enable_copy = False + else: + print("Error: Invalid path to Arduino core: " + os.path.abspath(args.arduino_path)) + exit(1) + else: + app.setting_enable_copy = False + + # Set the other options + app.setting_arduino_path = os.path.abspath(args.arduino_path) + app.setting_output_permissions = args.output_permissions + app.setting_arduino_branch = args.arduino_branch + app.setting_idf_branch = args.idf_branch + app.setting_idf_commit = args.idf_commit + app.setting_debug_level = args.debug_level + + # Change to the root directory of the app to the root of the project + os.chdir(app.ROOT_PATH) + + # Main function to run the app + app.run() + + # Propagate the exit code from the app + exit(app.return_code or 0) + +if __name__ == "__main__": + # If this script is run directly, start the app + main() diff --git a/tools/config_editor/compile.py b/tools/config_editor/compile.py new file mode 100644 index 000000000..efb812174 --- /dev/null +++ b/tools/config_editor/compile.py @@ -0,0 +1,203 @@ +import sys +import subprocess +import os +import re + +from rich.console import RenderableType + +from textual import on, work +from textual.app import ComposeResult +from textual.binding import Binding +from textual.events import ScreenResume +from textual.containers import Container +from textual.screen import Screen +from textual.widgets import Header, Static, RichLog, Button, Footer + +class CompileScreen(Screen): + # Compile screen + + # Set the key bindings + BINDINGS = [ + Binding("escape", "back", "Back") + ] + + # Child process running the libraries compilation + child_process = None + + log_widget: RichLog + button_widget: Button + + def action_back(self) -> None: + self.workers.cancel_all() + if self.child_process: + # Terminate the child process if it is running + print("Terminating child process") + self.child_process.terminate() + try: + self.child_process.stdout.close() + self.child_process.stderr.close() + except: + pass + self.child_process.wait() + self.dismiss() + + def print_output(self, renderable: RenderableType, style=None) -> None: + # Print output to the RichLog widget + if style is None: + self.log_widget.write(renderable) + else: + # Check the available styles at https://rich.readthedocs.io/en/stable/style.html + self.log_widget.write("[" + str(style) + "]" + renderable) + + def print_error(self, error: str) -> None: + # Print error to the RichLog widget + self.log_widget.write("[b bright_red]" + error) + self.button_widget.add_class("-error") + #print("Error: " + error) # For debugging + + def print_success(self, message: str) -> None: + # Print success message to the RichLog widget + self.log_widget.write("[b bright_green]" + message) + self.button_widget.add_class("-success") + #print("Success: " + message) # For debugging + + def print_warning(self, message: str) -> None: + # Print warning message to the RichLog widget + self.log_widget.write("[b bright_yellow]" + message) + #print("Warning: " + message) # For debugging + + def print_info(self, message: str) -> None: + # Print info message to the RichLog widget + self.log_widget.write("[b bright_cyan]" + message) + #print("Info: " + message) # For debugging + + @work(name="compliation_worker", group="compilation", exclusive=True, thread=True) + def compile_libs(self) -> None: + # Compile the libraries + print("Starting compilation process") + + label = self.query_one("#compile-title", Static) + self.child_process = None + + if not self.app.setting_target: + self.print_error("No target selected") + label.update("No target selected") + return + elif self.app.setting_target == ",".join(self.app.supported_targets): + target = "all targets" + else: + target = self.app.setting_target.replace(",", ", ").upper() + + label.update("Compiling for " + target) + self.print_info("======== Compiling for " + target + " ========") + + command = ["./build.sh", "-t", self.app.setting_target, "-D", self.app.setting_debug_level] + + #command.append("--help") # For testing output without compiling + + if self.app.setting_enable_copy: + if os.path.isdir(self.app.setting_arduino_path): + command.extend(["-c", self.app.setting_arduino_path]) + else: + self.print_error("Invalid path to Arduino core: " + self.app.setting_arduino_path) + label.update("Invalid path to Arduino core") + return + + if self.app.setting_arduino_branch: + command.extend(["-A", self.app.setting_arduino_branch]) + + if self.app.setting_idf_branch: + command.extend(["-I", self.app.setting_idf_branch]) + + if self.app.setting_idf_commit: + command.extend(["-i", self.app.setting_idf_commit]) + + self.print_info("Running: " + " ".join(command) + "\n") + self.child_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + try: + for output in self.child_process.stdout: + if output == '' and self.child_process.poll() is not None: + break + if output: + self.print_output(output.strip()) # Update RichLog widget with subprocess output + self.child_process.stdout.close() + except Exception as e: + print("Error reading child process output: " + str(e)) + print("Process might have terminated") + + if not self.child_process: + self.print_error("Compilation failed for " + target + "Child process failed to start") + label.update("Compilation failed for " + target + "Child process failed to start") + return + else: + self.child_process.wait() + + if self.child_process.returncode != 0: + self.print_error("Compilation failed for " + target + ". Return code: " + str(self.child_process.returncode)) + self.print_error("Errors:") + try: + for error in self.child_process.stderr: + if error: + self.print_error(error.strip()) + self.child_process.stderr.close() + except Exception as e: + print("Error reading child process errors: " + str(e)) + label.update("Compilation failed for " + target) + else: + if self.app.setting_output_permissions: + regex = r"^[1-9][0-9]*:[1-9][0-9]*$" # Regex to match the uid:gid format. Note that 0:0 (root) is not allowed + if re.match(regex, self.app.setting_output_permissions): + print_info("Setting permissions to: " + self.app.setting_output_permissions) + chown_process = None + try: + chown_process = subprocess.run(["chown", "-R", self.app.setting_output_permissions, self.app.setting_arduino_path]) + chown_process.wait() + except Exception as e: + print("Error changing permissions: " + str(e)) + + if chown_process and chown_process.returncode != 0: + self.print_error("Error changing permissions") + self.print_error("Please change the ownership of generated files manually") + else: + self.print_success("Permissions changed successfully") + elif self.app.setting_output_permissions == "0:0": + self.print_warning("Permissions settings are set to root (0:0)") + self.print_warning("Please change the ownership of generated files manually") + self.print_warning("If you are compiling for Windows, you may ignore this warning") + else: + self.print_error("Invalid permissions format: " + self.app.setting_output_permissions) + self.print_error("Please change the ownership of generated files manually") + + self.print_success("Compilation successful for " + target) + label.update("Compilation successful for " + target) + + def on_button_pressed(self, event: Button.Pressed) -> None: + # Event handler called when a button is pressed + self.action_back() + + @on(ScreenResume) + def on_resume(self) -> None: + # Event handler called every time the screen is activated + print("Compile screen resumed. Clearing logs and starting compilation process") + self.button_widget.remove_class("-error") + self.button_widget.remove_class("-success") + self.log_widget.clear() + self.log_widget.focus() + self.compile_libs() + + def compose(self) -> ComposeResult: + # Compose the compilation screen + yield Header() + with Container(id="compile-log-container"): + self.log_widget = RichLog(markup=True, id="compile-log") + yield self.log_widget + with Container(id="compile-status-container"): + yield Static("Compiling for ...", id="compile-title") + self.button_widget = Button("Back", id="compile-back-button") + yield self.button_widget + yield Footer() + + def on_mount(self) -> None: + # Event handler called when the screen is mounted + print("Compile screen mounted") + self.sub_title = "Compilation" diff --git a/tools/config_editor/editor.py b/tools/config_editor/editor.py new file mode 100644 index 000000000..87217f49d --- /dev/null +++ b/tools/config_editor/editor.py @@ -0,0 +1,86 @@ +import os + +from textual import on +from textual.app import ComposeResult +from textual.binding import Binding +from textual.containers import Container, VerticalScroll, Horizontal +from textual.screen import Screen +from textual.events import ScreenResume +from textual.widgets import DirectoryTree, Header, TextArea, Button, Footer + +class EditorScreen(Screen): + # Configuration file editor screen + + # Set the key bindings + BINDINGS = [ + Binding("ctrl+s", "save", "Save", priority=True), + Binding("escape", "app.pop_screen", "Discard") + ] + + # Current file being edited + current_file = "" + + def action_save(self) -> None: + code_view = self.query_one("#code", TextArea) + current_text = code_view.text + try: + file = open(self.curent_file, "w") + file.write(current_text) + file.close() + except Exception: + print("Error saving file: " + self.curent_file) + self.sub_title = "ERROR" + else: + print("File saved: " + self.curent_file) + self.sub_title = self.curent_file + self.dismiss() + + def on_button_pressed(self, event: Button.Pressed) -> None: + # Event handler called when a button is pressed + if event.button.id == "save-editor-button" and self.curent_file != "": + print("Save button pressed. Trying to save file: " + self.curent_file) + self.action_save() + elif event.button.id == "cancel-editor-button": + print("Cancel button pressed") + self.dismiss() + + def on_directory_tree_file_selected(self, event: DirectoryTree.FileSelected) -> None: + # Called when the user click a file in the directory tree + event.stop() + code_view = self.query_one("#code", TextArea) + code_view.clear() + self.curent_file = str(event.path) + try: + print("Opening file: " + self.curent_file) + file = open(self.curent_file, "r") + file_content = file.read() + file.close() + except Exception: + print("Error opening file: " + self.curent_file) + self.sub_title = "ERROR" + else: + print("File opened: " + self.curent_file) + code_view.insert(file_content) + self.sub_title = self.curent_file + + @on(ScreenResume) + def on_resume(self) -> None: + # Event handler called every time the screen is activated + print("Editor screen resumed. Clearing code view") + self.sub_title = "Select a file" + self.query_one(DirectoryTree).focus() + self.query_one(TextArea).clear() + self.curent_file = "" + + def compose(self) -> ComposeResult: + # Compose editor screen + path = os.path.join(self.app.ROOT_PATH, 'configs') + yield Header() + with Container(): + yield DirectoryTree(path, id="tree-view") + with VerticalScroll(id="code-view"): + yield TextArea.code_editor("", id="code") + with Horizontal(id="editor-buttons-container"): + yield Button("Save", id="save-editor-button", classes="editor-button") + yield Button("Cancel", id="cancel-editor-button", classes="editor-button") + yield Footer() diff --git a/tools/config_editor/requirements.txt b/tools/config_editor/requirements.txt new file mode 100644 index 000000000..f3cac7be0 --- /dev/null +++ b/tools/config_editor/requirements.txt @@ -0,0 +1 @@ +textual==0.79.0 diff --git a/tools/config_editor/settings.py b/tools/config_editor/settings.py new file mode 100644 index 000000000..c92358374 --- /dev/null +++ b/tools/config_editor/settings.py @@ -0,0 +1,149 @@ +import math + +from textual import on +from textual.app import ComposeResult +from textual.binding import Binding +from textual.containers import VerticalScroll, Container, Horizontal +from textual.screen import Screen +from textual.events import ScreenResume +from textual.widgets import Header, Button, Switch, Label, Footer, Checkbox + +from widgets import LabelledInput, LabelledSelect + +class SettingsScreen(Screen): + # Settings screen + + # Set the key bindings + BINDINGS = [ + Binding("s", "save", "Save"), + Binding("escape", "app.pop_screen", "Discard") + ] + + enable_copy_switch: Switch + arduino_path_input: LabelledInput + arduino_branch_input: LabelledInput + idf_branch_input: LabelledInput + idf_commit_input: LabelledInput + idf_debug_select: LabelledSelect + + def action_save(self) -> None: + checkboxes = self.query(Checkbox) + self.app.setting_target = "" + for checkbox in checkboxes: + if checkbox.value: + if self.app.setting_target: + self.app.setting_target += "," + self.app.setting_target += checkbox.id.replace("-checkbox", "") + print("Target setting updated: " + self.app.setting_target) + + self.app.setting_enable_copy = self.enable_copy_switch.value + print("Enable copy setting updated: " + str(self.app.setting_enable_copy)) + + if self.enable_copy_switch.value: + self.app.setting_arduino_path = self.arduino_path_input.get_input_value() + print("Arduino path setting updated: " + self.app.setting_arduino_path) + + self.app.setting_arduino_branch = self.arduino_branch_input.get_input_value() + print("Arduino branch setting updated: " + self.app.setting_arduino_branch) + + self.app.setting_idf_branch = self.idf_branch_input.get_input_value() + print("IDF branch setting updated: " + self.app.setting_idf_branch) + + self.app.setting_idf_commit = self.idf_commit_input.get_input_value() + print("IDF commit setting updated: " + self.app.setting_idf_commit) + + self.app.setting_debug_level = self.idf_debug_select.get_select_value() + print("Debug level setting updated: " + self.app.setting_debug_level) + + def on_button_pressed(self, event: Button.Pressed) -> None: + # Event handler called when a button is pressed + if event.button.id == "save-settings-button": + print("Save button pressed") + self.action_save() + elif event.button.id == "cancel-settings-button": + print("Cancel button pressed") + self.dismiss() + + @on(ScreenResume) + def on_resume(self) -> None: + # Event handler called every time the screen is activated + print("Settings screen resumed. Updating settings.") + targets = self.app.setting_target.split(",") + checkboxes = self.query(Checkbox) + for checkbox in checkboxes: + checkbox.value = False + if checkbox.id.replace("-checkbox", "") in targets: + checkbox.value = True + self.enable_copy_switch.value = self.app.setting_enable_copy + if self.app.setting_enable_copy: + self.arduino_path_input.visible = True + else: + self.arduino_path_input.visible = False + self.arduino_path_input.set_input_value(self.app.setting_arduino_path) + self.arduino_branch_input.set_input_value(self.app.setting_arduino_branch) + self.idf_branch_input.set_input_value(self.app.setting_idf_branch) + self.idf_commit_input.set_input_value(self.app.setting_idf_commit) + self.idf_debug_select.set_select_value(self.app.setting_debug_level) + + def on_switch_changed(self, event: Switch.Changed) -> None: + # Event handler called when a switch is changed + if event.switch.id == "enable-copy-switch": + if event.switch.value: + self.arduino_path_input.visible = True + else: + self.arduino_path_input.visible = False + + def compose(self) -> ComposeResult: + # Compose the target selection screen + yield Header() + with VerticalScroll(id="settings-scroll-container"): + + yield Label("Compilation Targets", id="settings-target-label") + with Container(id="settings-target-container"): + for target in self.app.supported_targets: + yield Checkbox(target.upper(), id=target + "-checkbox") + + with Horizontal(classes="settings-switch-container"): + self.enable_copy_switch = Switch(value=self.app.setting_enable_copy, id="enable-copy-switch") + yield self.enable_copy_switch + + yield Label("Copy to arduino-esp32 after compilation") + + self.arduino_path_input = LabelledInput("Arduino-esp32 Path", placeholder="Path to your arduino-esp32 installation", value=self.app.setting_arduino_path, id="arduino-path-input") + yield self.arduino_path_input + + self.arduino_branch_input = LabelledInput("Arduino-esp32 Branch", placeholder="Leave empty to use default", value=self.app.setting_arduino_branch, id="arduino-branch-input") + yield self.arduino_branch_input + + self.idf_branch_input = LabelledInput("ESP-IDF Branch", placeholder="Leave empty to use default", value=self.app.setting_idf_branch, id="idf-branch-input") + yield self.idf_branch_input + + self.idf_commit_input = LabelledInput("ESP-IDF Commit", placeholder="Leave empty to use default", value=self.app.setting_idf_commit, id="idf-commit-input") + yield self.idf_commit_input + + debug_options = [ + ("Default", "default"), + ("None", "none"), + ("Error", "error"), + ("Warning", "warning"), + ("Info", "info"), + ("Debug", "debug"), + ("Verbose", "verbose") + ] + self.idf_debug_select = LabelledSelect("ESP-IDF Debug Level", debug_options, allow_blank=False, id="idf-debug-select") + yield self.idf_debug_select + + with Horizontal(id="settings-button-container"): + yield Button("Save", id="save-settings-button", classes="settings-button") + yield Button("Cancel", id="cancel-settings-button", classes="settings-button") + yield Footer() + + def on_mount(self) -> None: + # Event handler called when the screen is mounted for the first time + self.sub_title = "Settings" + target_container = self.query_one("#settings-target-container") + # Height needs to be 3 for each row of targets + 1 + height_value = str(int(math.ceil(len(self.app.supported_targets) / int(target_container.styles.grid_size_columns)) * 3 + 1)) + print("Target container height: " + height_value) + target_container.styles.height = height_value + print("Settings screen mounted") diff --git a/tools/config_editor/style.tcss b/tools/config_editor/style.tcss new file mode 100644 index 000000000..4359e58e0 --- /dev/null +++ b/tools/config_editor/style.tcss @@ -0,0 +1,202 @@ +# General + +Screen { + background: $surface-darken-1; +} + +Button { + width: auto; + min-width: 16; + height: auto; + color: $text; + border: none; + background: #038c8c; + border-top: tall #026868; + border-bottom: tall #6ab8b8; + text-align: center; + content-align: center middle; + text-style: bold; + + &:focus { + text-style: bold reverse; + } + &:hover { + border-top: tall #014444; + border-bottom: tall #3d8080; + background: #025b5b; + color: $text; + } + &.-active { + background: #025b5b; + border-bottom: tall #3d8080; + border-top: tall #014444; + tint: $background 30%; + } + + &.-success { + background: $success; + color: $text; + border-top: tall $success-lighten-2; + border-bottom: tall $success-darken-3; + + &:hover { + background: $success-darken-2; + color: $text; + border-top: tall $success; + } + + &.-active { + background: $success; + border-bottom: tall $success-lighten-2; + border-top: tall $success-darken-2; + } + } + + &.-error { + background: $error; + color: $text; + border-top: tall $error-lighten-2; + border-bottom: tall $error-darken-3; + + &:hover { + background: $error-darken-1; + color: $text; + border-top: tall $error; + } + + &.-active { + background: $error; + border-bottom: tall $error-lighten-2; + border-top: tall $error-darken-2; + } + } +} + +# Main Screen + +.main-menu-button { + margin-bottom: 1; + min-width: 100%; + max-width: 0.4fr; +} + +#main-menu-container { + align: center middle; + width: 1fr; +} + +#main-menu-title { + text-align: center; + margin-bottom: 4; + text-style: bold; + color: auto; + width: 0.4fr; +} + +# Compile Screen + +#compile-status-container { + layout: horizontal; + padding: 0 2; + height: 4; +} + +#compile-title { + dock: left; +} + +#compile-back-button { + dock: right; +} + +#compile-log { + background: $surface; + padding: 0 1 1 1; + margin: 1 2; +} + +# Settings Screen + +#settings-scroll-container { + padding: 1; +} + +#settings-button-container { + width: 100%; + max-height: 20%; + min-height: 5; + align: center middle; +} + +#settings-target-label { + margin-left: 1; +} + +#settings-target-container { + layout: grid; + grid-size: 4; +} + +#settings-target-container Checkbox { + width: 100%; + margin-right: -1; +} + +.settings-button { + margin: 1; + min-width: 100%; + max-width: 0.2fr; + align: center middle; +} + +.settings-switch-container { + height: 4; +} + +.settings-switch-container Switch { + margin-right: 2; +} + +.settings-switch-container Label { + margin-top: 1; +} + +# Editor Screen + +#tree-view { + display: none; + scrollbar-gutter: stable; + overflow: auto; + width: auto; + height: 100%; + dock: left; + display: block; + max-width: 50%; +} + +#code-view { + overflow: auto scroll; + min-width: 100%; +} + +#code { + width: 100%; +} + +.editor-button { + width: 20%; +} + +#save-editor-button { + dock: left; + margin: 1; +} + +#cancel-editor-button { + dock: right; + margin: 1 3; +} + +#editor-buttons-container { + height: 5; +} diff --git a/tools/config_editor/widgets.py b/tools/config_editor/widgets.py new file mode 100644 index 000000000..afec3297f --- /dev/null +++ b/tools/config_editor/widgets.py @@ -0,0 +1,95 @@ +from textual.widget import Widget + +from textual.widgets import Input, Label, Select + +class LabelledInput(Widget): + DEFAULT_CSS = """ + LabelledInput { + height: 4; + margin-bottom: 1; + } + LabelledInput Label { + padding-left: 1; + } + """ + + label_widget: Label + input_widget: Input + + def set_input_value(self, value): + self.input_widget.value = value + + def get_input_value(self): + return self.input_widget.value + + def __init__(self, + label, + *, + placeholder="", + value="", + name=None, + id=None, + classes=None, + disabled=False): + super().__init__(name=name, id=id, classes=classes, disabled=disabled) + self.__label = label + self.__placeholder = placeholder + self.__init_value = value + + def compose(self): + self.label_widget = Label(f"{self.__label}:") + self.input_widget = Input(placeholder=self.__placeholder, value=self.__init_value) + yield self.label_widget + yield self.input_widget + + +class LabelledSelect(Widget): + DEFAULT_CSS = """ + LabelledSelect { + height: 4; + margin-bottom: 1; + } + LabelledSelect Label { + padding-left: 1; + } + """ + + label_widget: Label + select_widget: Select + + def set_select_options(self, options): + self.__options = options + self.select_widget.options = options + + def get_select_options(self): + return self.__options + + def set_select_value(self, value): + self.select_widget.value = value + + def get_select_value(self): + return self.select_widget.value + + def __init__(self, + label, + options, + *, + prompt="Select", + allow_blank=True, + value=Select.BLANK, + name=None, + id=None, + classes=None, + disabled=False): + super().__init__(name=name, id=id, classes=classes, disabled=disabled) + self.__label = label + self.__options = options + self.__init_value = value + self.__prompt = prompt + self.__allow_blank = allow_blank + + def compose(self): + self.label_widget = Label(f"{self.__label}:") + self.select_widget = Select(options=self.__options, value=self.__init_value, prompt=self.__prompt, allow_blank=self.__allow_blank) + yield self.label_widget + yield self.select_widget diff --git a/tools/copy-bootloader.sh b/tools/copy-bootloader.sh new file mode 100755 index 000000000..1442c70fa --- /dev/null +++ b/tools/copy-bootloader.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +IDF_TARGET=$1 +FLASH_MODE="$2" +FLASH_FREQ="$3" +BOOTCONF=$FLASH_MODE"_$FLASH_FREQ" + +source ./tools/config.sh + +echo "Copying bootloader: $AR_SDK/bin/bootloader_$BOOTCONF.elf" + +mkdir -p "$AR_SDK/bin" + +cp "build/bootloader/bootloader.elf" "$AR_SDK/bin/bootloader_$BOOTCONF.elf" diff --git a/tools/copy-libs.sh b/tools/copy-libs.sh new file mode 100755 index 000000000..7c302ab66 --- /dev/null +++ b/tools/copy-libs.sh @@ -0,0 +1,591 @@ +#!/bin/bash +# config + +IDF_TARGET=$1 +IS_XTENSA=$4 +OCT_FLASH="$2" +OCT_PSRAM= + +if [ "$3" = "y" ]; then + OCT_PSRAM="opi" +else + OCT_PSRAM="qspi" +fi +MEMCONF=$OCT_FLASH"_$OCT_PSRAM" + +source ./tools/config.sh + +echo "IDF_TARGET: $IDF_TARGET, MEMCONF: $MEMCONF, PWD: $PWD, OUT: $AR_SDK" + +# clean previous +if [ -e "$AR_SDK/sdkconfig" ]; then + rm -rf "$AR_SDK/sdkconfig" +fi +if [ -e "$AR_SDK/lib" ]; then + rm -rf "$AR_SDK/lib" +fi +if [ -e "$AR_SDK/ld" ]; then + rm -rf "$AR_SDK/ld" +fi +if [ -e "$AR_SDK/include" ]; then + rm -rf "$AR_SDK/include" +fi +if [ -e "$AR_SDK/flags" ]; then + rm -rf "$AR_SDK/flags" +fi +if [ -e "$AR_SDK/$MEMCONF" ]; then + rm -rf "$AR_SDK/$MEMCONF" +fi +if [ -e "$AR_SDK/pioarduino-build.py" ]; then + rm -rf "$AR_SDK/pioarduino-build.py" +fi + +mkdir -p "$AR_SDK" +mkdir -p "$AR_SDK/lib" + +function get_actual_path(){ + d="$1"; + if [ -d "$d" ]; then + p="$PWD"; cd "$d"; r="$PWD"; cd "$p"; echo "$r"; + else + echo ""; + fi +} + +# +# START OF DATA EXTRACTION FROM CMAKE +# + +C_FLAGS="" +CPP_FLAGS="" +AS_FLAGS="" + +INCLUDES="" +DEFINES="" + +EXCLUDE_LIBS=";" + +LD_FLAGS="" +LD_LIBS="" +LD_LIB_FILES="" +LD_LIBS_SEARCH="" +LD_SCRIPTS="" +LD_SCRIPT_DIRS="" + +PIOARDUINO_CC_FLAGS="" +PIOARDUINO_C_FLAGS="" +PIOARDUINO_CXX_FLAGS="" +PIOARDUINO_AS_FLAGS="" +PIOARDUINO_LD_FLAGS="" +PIOARDUINO_LD_FUNCS="" +PIOARDUINO_LD_SCRIPTS="" + +TOOLCHAIN_PREFIX="" +if [ "$IS_XTENSA" = "y" ]; then + TOOLCHAIN="xtensa-$IDF_TARGET-elf" +else + TOOLCHAIN="riscv32-esp-elf" +fi + +# copy zigbee + zboss lib +if [ -d "managed_components/espressif__esp-zigbee-lib/lib/$IDF_TARGET/" ]; then + cp -r "managed_components/espressif__esp-zigbee-lib/lib/$IDF_TARGET"/* "$AR_SDK/lib/" + EXCLUDE_LIBS+="esp_zb_api.ed;esp_zb_api.zczr;" +fi + +if [ -d "managed_components/espressif__esp-zboss-lib/lib/$IDF_TARGET/" ]; then + cp -r "managed_components/espressif__esp-zboss-lib/lib/$IDF_TARGET"/* "$AR_SDK/lib/" + EXCLUDE_LIBS+="zboss_stack.ed;zboss_stack.zczr;zboss_port.native;zboss_port.native.debug;zboss_port.remote;zboss_port.remote.debug;" +fi + +#collect includes, defines and c-flags +str=`cat build/compile_commands.json | grep arduino-lib-builder-gcc.c | grep command | cut -d':' -f2 | cut -d',' -f1` +str="${str:2:${#str}-1}" #remove leading space and quotes +str=`printf '%b' "$str"` #unescape the string +set -- $str +for item in "${@:2:${#@}-5}"; do + prefix="${item:0:2}" + if [ "$prefix" = "-I" ]; then + item="${item:2}" + if [ "${item:0:1}" = "/" ]; then + item=`get_actual_path $item` + INCLUDES+="$item " + elif [ "${item:0:2}" = ".." ]; then + if [[ "${item:0:14}" = "../components/" && "${item:0:22}" != "../components/arduino/" ]] || [[ "${item:0:11}" = "../esp-idf/" ]] || [[ "${item:0:22}" = "../managed_components/" ]]; then + item="$PWD${item:2}" + item=`get_actual_path $item` + INCLUDES+="$item " + fi + else + item="$PWD/build/$item" + item=`get_actual_path $item` + INCLUDES+="$item " + fi + elif [ "$prefix" = "-D" ]; then + if [[ "${item:2:7}" != "ARDUINO" ]] && [[ "$item" != "-DESP32=ESP32" ]]; then #skip ARDUINO defines + DEFINES+="$item " + fi + elif [ "$prefix" = "-O" ]; then + PIOARDUINO_CC_FLAGS+="$item " + elif [[ "$item" != "-Wall" && "$item" != "-Werror=all" && "$item" != "-Wextra" ]]; then + if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" && "${item:0:20}" != "-fdiagnostics-color=" && "${item:0:19}" != "-fdebug-prefix-map=" ]]; then + C_FLAGS+="$item " + fi + fi +done + +#collect asm-flags +str=`cat build/compile_commands.json | grep arduino-lib-builder-as.S | grep command | cut -d':' -f2 | cut -d',' -f1` +str="${str:2:${#str}-1}" #remove leading space and quotes +str=`printf '%b' "$str"` #unescape the string +set -- $str +for item in "${@:2:${#@}-5}"; do + prefix="${item:0:2}" + if [[ "$prefix" != "-I" && "$prefix" != "-D" && "$item" != "-Wall" && "$item" != "-Werror=all" && "$item" != "-Wextra" && "$prefix" != "-O" ]]; then + if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" && "${item:0:20}" != "-fdiagnostics-color=" && "${item:0:19}" != "-fdebug-prefix-map=" ]]; then + AS_FLAGS+="$item " + if [[ $C_FLAGS == *"$item"* ]]; then + PIOARDUINO_CC_FLAGS+="$item " + else + PIOARDUINO_AS_FLAGS+="$item " + fi + fi + fi +done + +#collect cpp-flags +str=`cat build/compile_commands.json | grep arduino-lib-builder-cpp.cpp | grep command | cut -d':' -f2 | cut -d',' -f1` +str="${str:2:${#str}-1}" #remove leading space and quotes +str=`printf '%b' "$str"` #unescape the string +set -- $str +for item in "${@:2:${#@}-5}"; do + prefix="${item:0:2}" + if [[ "$prefix" != "-I" && "$prefix" != "-D" && "$item" != "-Wall" && "$item" != "-Werror=all" && "$item" != "-Wextra" && "$prefix" != "-O" ]]; then + if [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" && "${item:0:20}" != "-fdiagnostics-color=" && "${item:0:19}" != "-fdebug-prefix-map=" ]]; then + CPP_FLAGS+="$item " + if [[ $PIOARDUINO_CC_FLAGS != *"$item"* ]]; then + PIOARDUINO_CXX_FLAGS+="$item " + fi + fi + fi +done + +set -- $C_FLAGS +for item; do + if [[ $PIOARDUINO_CC_FLAGS != *"$item"* ]]; then + PIOARDUINO_C_FLAGS+="$item " + fi +done + +#parse link command to extract libs and flags +add_next=0 +is_dir=0 +is_script=0 +if [ -f "build/CMakeFiles/arduino-lib-builder.elf.dir/link.txt" ]; then + str=`cat build/CMakeFiles/arduino-lib-builder.elf.dir/link.txt` +else + libs=`cat build/build.ninja | grep LINK_LIBRARIES` + libs="${libs:19:${#libs}-1}" + flags=`cat build/build.ninja | grep LINK_FLAGS` + flags="${flags:15:${#flags}-1}" + paths=`cat build/build.ninja | grep LINK_PATH` + paths="${paths:14:${#paths}-1}" + if [ "$IDF_TARGET" = "esp32" ]; then + flags="-Wno-frame-address $flags" + fi + if [ "$IS_XTENSA" = "y" ]; then + flags="-mlongcalls $flags" + fi + str="$flags $libs $paths" +fi +if [ "$IDF_TARGET" = "esp32" ]; then + LD_SCRIPTS+="-T esp32.rom.redefined.ld " + PIOARDUINO_LD_SCRIPTS+="esp32.rom.redefined.ld " +fi +set -- $str +for item; do + prefix="${item:0:1}" + if [ "$prefix" = "-" ]; then + if [ "${item:0:10}" != "-Wl,--Map=" ]; then + if [ "$item" = "-L" ]; then # -L /path + add_next=1 + is_dir=1 + elif [ "${item:0:2}" = "-L" ]; then # -L/path + LD_SCRIPT_DIRS+="${item:2} " + elif [ "$item" = "-T" ]; then # -T script.ld + add_next=1 + is_script=1 + LD_SCRIPTS+="$item " + elif [ "$item" = "-u" ]; then # -u function_name + add_next=1 + LD_FLAGS+="$item " + elif [ "${item:0:2}" = "-l" ]; then # -l[lib_name] + short_name="${item:2}" + if [[ $EXCLUDE_LIBS != *";$short_name;"* ]]; then + LD_LIBS+="$item " + exclude_libs=";m;c;gcc;stdc++;" + if [[ $exclude_libs != *";$short_name;"* && $LD_LIBS_SEARCH != *"lib$short_name.a"* ]]; then + LD_LIBS_SEARCH+="lib$short_name.a " + #echo "1. lib add: $item" + fi + fi + elif [ "$item" = "-o" ]; then + add_next=0 + is_script=0 + is_dir=0 + elif [[ "${item:0:23}" != "-mfix-esp32-psram-cache" && "${item:0:18}" != "-fmacro-prefix-map" && "${item:0:19}" != "-fdebug-prefix-map=" && "${item:0:17}" != "-Wl,--start-group" && "${item:0:15}" != "-Wl,--end-group" ]]; then + LD_FLAGS+="$item " + PIOARDUINO_LD_FLAGS+="$item " + fi + fi + else + if [ "$add_next" = "1" ]; then + add_next=0 + if [ "$is_dir" = "1" ]; then + is_dir=0 + LD_SCRIPT_DIRS+="$item " + elif [ "$is_script" = "1" ]; then + is_script=0 + LD_SCRIPTS+="$item " + PIOARDUINO_LD_SCRIPTS+="$item " + else + LD_FLAGS+="$item " + PIOARDUINO_LD_FUNCS+="$item " + fi + else + if [ "${item:${#item}-2:2}" = ".a" ]; then + if [ "${item:0:1}" != "/" ]; then + item="$PWD/build/$item" + fi + lname=$(basename $item) + lname="${lname:3:${#lname}-5}" + if [[ "$lname" != "main" && "$lname" != "arduino" ]]; then + lsize=$($SSTAT "$item") + if (( lsize > 8 )); then + # do we already have this file? + if [[ $LD_LIB_FILES != *"$item"* ]]; then + # do we already have lib with the same name? + if [[ $LD_LIBS != *"-l$lname"* ]]; then + if [[ $EXCLUDE_LIBS != *";$lname;"* ]]; then + #echo "2. collecting lib '$lname' and file: $item" + LD_LIB_FILES+="$item " + LD_LIBS+="-l$lname " + fi + else + # echo "!!! need to rename: '$lname'" + for i in {2..9}; do + n_item="${item:0:${#item}-2}_$i.a" + n_name=$lname"_$i" + if [ -f "$n_item" ]; then + if [[ $EXCLUDE_LIBS != *";$lname;"* ]]; then + #echo "3. renamed add: -l$n_name" + LD_LIBS+="-l$n_name " + fi + break + elif [[ $LD_LIB_FILES != *"$n_item"* && $LD_LIBS != *"-l$n_name"* ]]; then + if [[ $EXCLUDE_LIBS != *";$lname;"* ]]; then + #echo "4. Renaming '$lname' to '$n_name': $item" + cp -f "$item" "$n_item" + LD_LIB_FILES+="$n_item " + LD_LIBS+="-l$n_name " + fi + break + fi + done + fi + else + if [[ $EXCLUDE_LIBS != *";$lname;"* ]]; then + #echo "5. just add: -l$lname" + LD_LIBS+="-l$lname " + fi + fi + else + echo "*** Skipping $(basename $item): size too small $lsize" + fi + fi + elif [[ "${item:${#item}-4:4}" = ".obj" || "${item:${#item}-4:4}" = ".elf" || "${item:${#item}-4:4}" = "-g++" ]]; then + item="$item" + else + echo "*** BAD LD ITEM: $item ${item:${#item}-2:2}" + fi + fi + fi +done + +# +# END OF DATA EXTRACTION FROM CMAKE +# + +mkdir -p "$AR_SDK" + +# start generation of pioarduino-build.py +AR_PIOARDUINO_PY="$AR_SDK/pioarduino-build.py" +cat configs/pioarduino_start.txt > "$AR_PIOARDUINO_PY" + +echo " ASFLAGS=[" >> "$AR_PIOARDUINO_PY" +if [ "$IS_XTENSA" = "y" ]; then + echo " \"-mlongcalls\"" >> "$AR_PIOARDUINO_PY" +else + echo " \"-march=rv32imc\"" >> "$AR_PIOARDUINO_PY" +fi +echo " ]," >> "$AR_PIOARDUINO_PY" +echo "" >> "$AR_PIOARDUINO_PY" + +echo " ASPPFLAGS=[" >> "$AR_PIOARDUINO_PY" +set -- $PIOARDUINO_AS_FLAGS +for item; do + echo " \"$item\"," >> "$AR_PIOARDUINO_PY" +done +echo " \"-x\", \"assembler-with-cpp\"" >> "$AR_PIOARDUINO_PY" +echo " ]," >> "$AR_PIOARDUINO_PY" +echo "" >> "$AR_PIOARDUINO_PY" + +echo " CFLAGS=[" >> "$AR_PIOARDUINO_PY" +set -- $PIOARDUINO_C_FLAGS +last_item="${@: -1}" +for item in "${@:0:${#@}}"; do + if [ "${item:0:1}" != "/" ]; then + echo " \"$item\"," >> "$AR_PIOARDUINO_PY" + fi +done +echo " \"$last_item\"" >> "$AR_PIOARDUINO_PY" +echo " ]," >> "$AR_PIOARDUINO_PY" +echo "" >> "$AR_PIOARDUINO_PY" + +echo " CXXFLAGS=[" >> "$AR_PIOARDUINO_PY" +set -- $PIOARDUINO_CXX_FLAGS +last_item="${@: -1}" +for item in "${@:0:${#@}}"; do + if [ "${item:0:1}" != "/" ]; then + echo " \"$item\"," >> "$AR_PIOARDUINO_PY" + fi +done +echo " \"$last_item\"" >> "$AR_PIOARDUINO_PY" +echo " ]," >> "$AR_PIOARDUINO_PY" +echo "" >> "$AR_PIOARDUINO_PY" + +echo " CCFLAGS=[" >> "$AR_PIOARDUINO_PY" +set -- $PIOARDUINO_CC_FLAGS +for item; do + echo " \"$item\"," >> "$AR_PIOARDUINO_PY" +done +echo " \"-MMD\"" >> "$AR_PIOARDUINO_PY" +echo " ]," >> "$AR_PIOARDUINO_PY" +echo "" >> "$AR_PIOARDUINO_PY" + +echo " LINKFLAGS=[" >> "$AR_PIOARDUINO_PY" +set -- $PIOARDUINO_LD_FLAGS +for item; do + echo " \"$item\"," >> "$AR_PIOARDUINO_PY" +done +set -- $PIOARDUINO_LD_SCRIPTS +for item; do + echo " \"-T\", \"$item\"," >> "$AR_PIOARDUINO_PY" +done +set -- $PIOARDUINO_LD_FUNCS +for item; do + echo " \"-u\", \"$item\"," >> "$AR_PIOARDUINO_PY" +done +echo " '-Wl,-Map=\"%s\"' % join(\"\${BUILD_DIR}\", \"\${PROGNAME}.map\")" >> "$AR_PIOARDUINO_PY" + +echo " ]," >> "$AR_PIOARDUINO_PY" +echo "" >> "$AR_PIOARDUINO_PY" + +# include dirs +REL_INC="" +echo " CPPPATH=[" >> "$AR_PIOARDUINO_PY" + +set -- $INCLUDES + +for item; do + if [[ "$item" != $PWD ]]; then + ipath="$item" + fname=`basename "$ipath"` + dname=`basename $(dirname "$ipath")` + if [[ "$fname" == "main" && "$dname" == $(basename "$PWD") ]]; then + continue + fi + while [[ "$dname" != "components" && "$dname" != "managed_components" && "$dname" != "build" ]]; do + ipath=`dirname "$ipath"` + fname=`basename "$ipath"` + dname=`basename $(dirname "$ipath")` + done + if [[ "$fname" == "arduino" ]]; then + continue + fi + if [[ "$fname" == "config" ]]; then + continue + fi + + out_sub="${item#*$ipath}" + out_cpath="$AR_SDK/include/$fname$out_sub" + REL_INC+="-iwithprefixbefore $fname$out_sub " + if [ "$out_sub" = "" ]; then + echo " join($PIOARDUINO_SDK, \"include\", \"$fname\")," >> "$AR_PIOARDUINO_PY" + else + pioarduino_sub="${out_sub:1}" + pioarduino_sub=`echo $pioarduino_sub | sed 's/\//\\", \\"/g'` + echo " join($PIOARDUINO_SDK, \"include\", \"$fname\", \"$pioarduino_sub\")," >> "$AR_PIOARDUINO_PY" + fi + for f in `find "$item" -name '*.h'`; do + rel_f=${f#*$item} + rel_p=${rel_f%/*} + mkdir -p "$out_cpath$rel_p" + cp -n $f "$out_cpath$rel_p/" + done + for f in `find "$item" -name '*.hpp'`; do + rel_f=${f#*$item} + rel_p=${rel_f%/*} + mkdir -p "$out_cpath$rel_p" + cp -n $f "$out_cpath$rel_p/" + done + for f in `find "$item" -name '*.inc'`; do + rel_f=${f#*$item} + rel_p=${rel_f%/*} + mkdir -p "$out_cpath$rel_p" + cp -n $f "$out_cpath$rel_p/" + done + # Temporary measure to fix issues caused by https://github.com/espressif/esp-idf/commit/dc4731101dd567cc74bbe4d0f03afe52b7db9afb#diff-1d2ce0d3989a80830fdf230bcaafb3117f32046d16cf46616ac3d55b4df2a988R17 + if [[ "$fname" == "bt" && "$out_sub" == "/include/$IDF_TARGET/include" && -f "$ipath/controller/$IDF_TARGET/esp_bt_cfg.h" ]]; then + mkdir -p "$AR_SDK/include/$fname/controller/$IDF_TARGET" + cp -n "$ipath/controller/$IDF_TARGET/esp_bt_cfg.h" "$AR_SDK/include/$fname/controller/$IDF_TARGET/esp_bt_cfg.h" + fi + fi +done +echo " join($PIOARDUINO_SDK, board_config.get(\"build.arduino.memory_type\", (board_config.get(\"build.flash_mode\", \"dio\") + \"_$OCT_PSRAM\")), \"include\")," >> "$AR_PIOARDUINO_PY" +echo " join(FRAMEWORK_DIR, \"cores\", board_config.get(\"build.core\"))" >> "$AR_PIOARDUINO_PY" +echo " ]," >> "$AR_PIOARDUINO_PY" +echo "" >> "$AR_PIOARDUINO_PY" + +AR_LIBS="$LD_LIBS" +PIOARDUINO_LIBS="" +set -- $LD_LIBS +for item; do + if [ "$PIOARDUINO_LIBS" != "" ]; then + PIOARDUINO_LIBS+=", " + fi + PIOARDUINO_LIBS+="\"$item\"" +done + +set -- $LD_LIB_FILES +for item; do + cp "$item" "$AR_SDK/lib/" +done + +echo " LIBPATH=[" >> "$AR_PIOARDUINO_PY" +echo " join($PIOARDUINO_SDK, \"lib\")," >> "$AR_PIOARDUINO_PY" +echo " join($PIOARDUINO_SDK, \"ld\")," >> "$AR_PIOARDUINO_PY" +echo " join($PIOARDUINO_SDK, board_config.get(\"build.arduino.memory_type\", (board_config.get(\"build.flash_mode\", \"dio\") + \"_$OCT_PSRAM\")))" >> "$AR_PIOARDUINO_PY" +echo " ]," >> "$AR_PIOARDUINO_PY" +echo "" >> "$AR_PIOARDUINO_PY" + +echo " LIBS=[" >> "$AR_PIOARDUINO_PY" +echo " $PIOARDUINO_LIBS" >> "$AR_PIOARDUINO_PY" +echo " ]," >> "$AR_PIOARDUINO_PY" +echo "" >> "$AR_PIOARDUINO_PY" + +echo " CPPDEFINES=[" >> "$AR_PIOARDUINO_PY" +set -- $DEFINES +for item; do + item="${item:2}" #remove -D + if [[ $item == *"="* ]]; then + item=(${item//=/ }) + re='^[+-]?[0-9]+([.][0-9]+)?$' + if [[ ${item[1]} =~ $re ]]; then + echo " (\"${item[0]}\", ${item[1]})," >> "$AR_PIOARDUINO_PY" + else + echo " (\"${item[0]}\", '${item[1]}')," >> "$AR_PIOARDUINO_PY" + fi + else + echo " \"$item\"," >> "$AR_PIOARDUINO_PY" + fi +done + +# end generation of pioarduino-build.py +cat configs/pioarduino_end.txt >> "$AR_PIOARDUINO_PY" + +# replace double backslashes with single one +DEFINES=`echo "$DEFINES" | tr -s '\'` + +# target flags files +FLAGS_DIR="$AR_SDK/flags" +mkdir -p "$FLAGS_DIR" +echo -n "$DEFINES" > "$FLAGS_DIR/defines" +echo -n "$REL_INC" > "$FLAGS_DIR/includes" +echo -n "$C_FLAGS" > "$FLAGS_DIR/c_flags" +echo -n "$CPP_FLAGS" > "$FLAGS_DIR/cpp_flags" +echo -n "$AS_FLAGS" > "$FLAGS_DIR/S_flags" +echo -n "$LD_FLAGS" > "$FLAGS_DIR/ld_flags" +echo -n "$LD_SCRIPTS" > "$FLAGS_DIR/ld_scripts" +echo -n "$AR_LIBS" > "$FLAGS_DIR/ld_libs" + +# Matter Library adjustments +for flag_file in "c_flags" "cpp_flags" "S_flags"; do + echo "Fixing $FLAGS_DIR/$flag_file" + sed 's/\\\"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib\/address_resolve\/AddressResolve_DefaultImpl.h>\\\"/-DCHIP_HAVE_CONFIG_H/' $FLAGS_DIR/$flag_file > $FLAGS_DIR/$flag_file.temp + mv $FLAGS_DIR/$flag_file.temp $FLAGS_DIR/$flag_file +done +# this is not necessary for Matter 1.4, but it is for Matter 1.3 +#CHIP_RESOLVE_DIR="$AR_SDK/include/espressif__esp_matter/connectedhomeip/connectedhomeip/src/lib/address_resolve" +#sed 's/CHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER/<lib\/address_resolve\/AddressResolve_DefaultImpl.h>/' $CHIP_RESOLVE_DIR/AddressResolve.h > $CHIP_RESOLVE_DIR/AddressResolve_temp.h +#mv $CHIP_RESOLVE_DIR/AddressResolve_temp.h $CHIP_RESOLVE_DIR/AddressResolve.h +# End of Matter Library adjustments + +# sdkconfig +cp -f "sdkconfig" "$AR_SDK/sdkconfig" + +# dependencies.lock +cp -f "dependencies.lock" "$AR_SDK/dependencies.lock" + +# gen_esp32part.py +# cp "$IDF_PATH/components/partition_table/gen_esp32part.py" "$AR_GEN_PART_PY" + +# copy precompiled libs (if we need them) +function copy_precompiled_lib(){ + lib_file="$1" + lib_name="$(basename $lib_file)" + if [[ $LD_LIBS_SEARCH == *"$lib_name"* ]]; then + cp "$lib_file" "$AR_SDK/ld/" + fi +} + +# idf ld scripts +mkdir -p "$AR_SDK/ld" +set -- $LD_SCRIPT_DIRS +for item; do + item="${item%\"}" + item="${item#\"}" + find "$item" -name '*.ld' -exec cp -f {} "$AR_SDK/ld/" \; + for lib in `find "$item" -name '*.a'`; do + copy_precompiled_lib "$lib" + done +done + +for lib in "openthread" "espressif__esp-tflite-micro" "bt" "espressif__esp_matter"; do + if [ -f "$AR_SDK/lib/lib$lib.a" ]; then + echo "Stripping $AR_SDK/lib/lib$lib.a" + "$TOOLCHAIN-strip" -g "$AR_SDK/lib/lib$lib.a" + fi +done + +# Handle Mem Variants +mkdir -p "$AR_SDK/$MEMCONF/include" +mv "$PWD/build/config/sdkconfig.h" "$AR_SDK/$MEMCONF/include/sdkconfig.h" +for mem_variant in `jq -c '.mem_variants_files[]' configs/builds.json`; do + skip_file=1 + for file_target in $(echo "$mem_variant" | jq -c '.targets[]' | tr -d '"'); do + if [ "$file_target" == "$IDF_TARGET" ]; then + skip_file=0 + break + fi + done + if [ $skip_file -eq 0 ]; then + file=$(echo "$mem_variant" | jq -c '.file' | tr -d '"') + out=$(echo "$mem_variant" | jq -c '.out' | tr -d '"') + mv "$AR_SDK/$out" "$AR_SDK/$MEMCONF/$file" + fi +done; + +# Add IDF versions to sdkconfig +echo "#define CONFIG_ARDUINO_IDF_COMMIT \"$IDF_COMMIT\"" >> "$AR_SDK/$MEMCONF/include/sdkconfig.h" +echo "#define CONFIG_ARDUINO_IDF_BRANCH \"$IDF_BRANCH\"" >> "$AR_SDK/$MEMCONF/include/sdkconfig.h" diff --git a/tools/copy-mem-variant.sh b/tools/copy-mem-variant.sh new file mode 100755 index 000000000..9b8f3b58e --- /dev/null +++ b/tools/copy-mem-variant.sh @@ -0,0 +1,39 @@ +#!/bin/bash +IDF_TARGET=$1 +OCT_FLASH="$2" +OCT_PSRAM= + +if [ "$3" = "y" ]; then + OCT_PSRAM="opi" +else + OCT_PSRAM="qspi" +fi + +MEMCONF=$OCT_FLASH"_$OCT_PSRAM" + +source ./tools/config.sh + +echo "IDF_TARGET: $IDF_TARGET, MEMCONF: $MEMCONF" + +# Add IDF versions to sdkconfig +echo "#define CONFIG_ARDUINO_IDF_COMMIT \"$IDF_COMMIT\"" >> "build/config/sdkconfig.h" +echo "#define CONFIG_ARDUINO_IDF_BRANCH \"$IDF_BRANCH\"" >> "build/config/sdkconfig.h" + +# Handle Mem Variants +rm -rf "$AR_SDK/$MEMCONF" +mkdir -p "$AR_SDK/$MEMCONF/include" +mv "build/config/sdkconfig.h" "$AR_SDK/$MEMCONF/include/sdkconfig.h" +for mem_variant in `jq -c '.mem_variants_files[]' configs/builds.json`; do + skip_file=1 + for file_target in $(echo "$mem_variant" | jq -c '.targets[]' | tr -d '"'); do + if [ "$file_target" == "$IDF_TARGET" ]; then + skip_file=0 + break + fi + done + if [ $skip_file -eq 0 ]; then + file=$(echo "$mem_variant" | jq -c '.file' | tr -d '"') + src=$(echo "$mem_variant" | jq -c '.src' | tr -d '"') + cp "$src" "$AR_SDK/$MEMCONF/$file" + fi +done; diff --git a/tools/copy-to-arduino.sh b/tools/copy-to-arduino.sh index 7c2f81563..96092e068 100755 --- a/tools/copy-to-arduino.sh +++ b/tools/copy-to-arduino.sh @@ -14,9 +14,10 @@ if ! [ -d "$ESP32_ARDUINO" ]; then exit 1 fi -rm -rf $ESP32_ARDUINO/tools/sdk -cp -Rf $AR_SDK $ESP32_ARDUINO/tools/sdk -cp -f $AR_ESPTOOL_PY $ESP32_ARDUINO/tools/esptool.py -cp -f $AR_GEN_PART_PY $ESP32_ARDUINO/tools/gen_esp32part.py -cp -f $AR_PLATFORMIO_PY $ESP32_ARDUINO/tools/platformio-build.py -cp -f $AR_PLATFORM_TXT $ESP32_ARDUINO/platform.txt +echo "Installing new libraries to $ESP32_ARDUINO" + +rm -rf $ESP32_ARDUINO/package/package_esp32_index.template.json && \ +cp -f $AR_OUT/package_esp32_index.template.json $ESP32_ARDUINO/package/package_esp32_index.template.json + +rm -rf $ESP32_ARDUINO/tools/esp32-arduino-libs && \ +cp -Rf $AR_TOOLS/esp32-arduino-libs $ESP32_ARDUINO/tools/ diff --git a/tools/cron.sh b/tools/cron.sh old mode 100644 new mode 100755 index 6122b1eed..1ca166717 --- a/tools/cron.sh +++ b/tools/cron.sh @@ -1,10 +1,7 @@ #!/bin/bash -if [ ! "$GITHUB_EVENT_NAME" == "schedule" ]; then - echo "Wrong event '$GITHUB_EVENT_NAME'!" - exit 1 +if [ -z "$TARGET" ]; then + TARGET="all" fi -git checkout "$IDF_BRANCH" #local branches should match what the matrix wants to build -source ./build.sh -bash ./tools/push-to-arduino.sh +bash ./build.sh -e -t $TARGET diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile new file mode 100644 index 000000000..699f0bd8e --- /dev/null +++ b/tools/docker/Dockerfile @@ -0,0 +1,79 @@ +# To Do: Check if it is worth to use espressif/idf as base image (image size will be much bigger) +FROM ubuntu:latest + +# switch to root, let the entrypoint drop back to host user +USER root +SHELL ["/bin/bash", "-c"] + +ARG DEBIAN_FRONTEND=noninteractive + +RUN : \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + bison \ + ccache \ + cmake \ + curl \ + flex \ + git \ + gperf \ + jq \ + libncurses-dev \ + libssl-dev \ + libusb-1.0 \ + ninja-build \ + patch \ + python3 \ + python3-click \ + python3-cryptography \ + python3-future \ + python3-pip \ + python3-pyelftools \ + python3-pyparsing \ + python3-serial \ + python3-setuptools \ + python3-venv \ + wget \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* \ + && : + +# To build the image for a branch or a tag of the lib-builder, pass --build-arg LIBBUILDER_CLONE_BRANCH_OR_TAG=name. +# To build the image with a specific commit ID of lib-builder, pass --build-arg LIBBUILDER_CHECKOUT_REF=commit-id. +# It is possibe to combine both, e.g.: +# LIBBUILDER_CLONE_BRANCH_OR_TAG=release/vX.Y +# LIBBUILDER_CHECKOUT_REF=<some commit on release/vX.Y branch>. +# Use LIBBUILDER_CLONE_SHALLOW=1 to peform shallow clone (i.e. --depth=1 --shallow-submodules) +# Use LIBBUILDER_CLONE_SHALLOW_DEPTH=X to define the depth if LIBBUILDER_CLONE_SHALLOW is used (i.e. --depth=X) + +ARG LIBBUILDER_CLONE_URL=https://github.com/espressif/esp32-arduino-lib-builder +ARG LIBBUILDER_CLONE_BRANCH_OR_TAG=master +ARG LIBBUILDER_CHECKOUT_REF= +ARG LIBBUILDER_CLONE_SHALLOW= +ARG LIBBUILDER_CLONE_SHALLOW_DEPTH=1 + +ENV LIBBUILDER_PATH=/opt/esp/lib-builder +# Ccache is installed, enable it by default +ENV IDF_CCACHE_ENABLE=1 + +RUN echo LIBBUILDER_CHECKOUT_REF=$LIBBUILDER_CHECKOUT_REF LIBBUILDER_CLONE_BRANCH_OR_TAG=$LIBBUILDER_CLONE_BRANCH_OR_TAG && \ + git clone --recursive \ + ${LIBBUILDER_CLONE_SHALLOW:+--depth=${LIBBUILDER_CLONE_SHALLOW_DEPTH} --shallow-submodules} \ + ${LIBBUILDER_CLONE_BRANCH_OR_TAG:+-b $LIBBUILDER_CLONE_BRANCH_OR_TAG} \ + $LIBBUILDER_CLONE_URL $LIBBUILDER_PATH && \ + git config --system --add safe.directory $LIBBUILDER_PATH && \ + if [ -n "$LIBBUILDER_CHECKOUT_REF" ]; then \ + cd $LIBBUILDER_PATH && \ + if [ -n "$LIBBUILDER_CLONE_SHALLOW" ]; then \ + git fetch origin --depth=${LIBBUILDER_CLONE_SHALLOW_DEPTH} --recurse-submodules ${LIBBUILDER_CHECKOUT_REF}; \ + fi && \ + git checkout $LIBBUILDER_CHECKOUT_REF && \ + git submodule update --init --recursive; \ + fi && \ + pip3 install --break-system-packages --upgrade -r $LIBBUILDER_PATH/tools/config_editor/requirements.txt + +COPY entrypoint.sh $LIBBUILDER_PATH/entrypoint.sh + +WORKDIR /opt/esp/lib-builder +ENTRYPOINT [ "/opt/esp/lib-builder/entrypoint.sh" ] +CMD [ "python3", "tools/config_editor/app.py" ] diff --git a/tools/docker/README.md b/tools/docker/README.md new file mode 100644 index 000000000..d6a213129 --- /dev/null +++ b/tools/docker/README.md @@ -0,0 +1,50 @@ +<!-- This is a brief version of the Arduino Core for ESP32 documentation (add specific link) + intended to be displayed on the Docker Hub page: https://hub.docker.com/r/espressif/esp32-arduino-lib-builder. + When changing this page, please keep the documentation in sync. + (Keep the differences between Markdown and restructuredText in mind.) + --> + +# ESP-IDF Docker Image + +This is a Docker image for the [ESP32 Arduino Lib Builder](https://github.com/espressif/esp32-arduino-lib-builder). It is intended for building the static libraries of ESP-IDF components for use in Arduino projects. + +This image contains a copy of the esp32-arduino-lib-builder repository and already include or will obtain all the required tools and dependencies to build the Arduino static libraries. + +Currently supported architectures are: + - `amd64` + - `arm64` + +## Tags + +Multiple tags of this image are maintained: + + - `latest`: tracks `master` branch of esp32-arduino-lib-builder + - `release-vX.Y`: tracks `release/vX.Y` branch of esp32-arduino-lib-builder + +## Basic Usage + +```bash +docker run --rm -it -e "TERM=xterm-256color" -v <path to arduino-esp32>:/arduino-esp32 espressif/esp32-arduino-lib-builder:release-v5.3 +``` + +The above command explained: + + - `docker run`: Runs a command in a new container. + - `--rm`: Optional. Automatically removes the container when it exits. Remove this flag if you plan to use the container multiple times. + - `-i`: Runs the container in interactive mode. + - `-t`: Allocates a pseudo-TTY. + - `-e "TERM=xterm-256color"`: Optional. Sets the terminal type to `xterm-256color` to display colors correctly. + - `-v <path to arduino-esp32>:/arduino-esp32`: Optional. Mounts the Arduino Core for ESP32 repository at `/arduino-esp32` inside the container. Replace `<path to arduino-esp32>` with the path to the repository on the host machine. If not provided, the container will not copy the compiled libraries to the host machine. + - `espressif/esp32-arduino-lib-builder:release-v5.3`: The Docker image to use. + +After running the above command, you will be inside the container and can build the libraries using the user interface. + +By default the docker container will run the user interface script. If you want to run a specific command, you can pass it as an argument to the docker run command. For example, to run a terminal inside the container, you can run: + +```bash +docker run -it espressif/esp32-arduino-lib-builder:release-v5.3 /bin/bash +``` + +## Documentation + +For more information about this image and the detailed usage instructions, please refer to the [Arduino Core for ESP32 documentation](https://docs.espressif.com/projects/arduino-esp32/en/latest/lib_builder.html#docker-image). diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh new file mode 100755 index 000000000..4b3826713 --- /dev/null +++ b/tools/docker/entrypoint.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -e + +# LIBBUILDER_GIT_SAFE_DIR has the same format as system PATH environment variable. +# All path specified in LIBBUILDER_GIT_SAFE_DIR will be added to user's +# global git config as safe.directory paths. For more information +# see git-config manual page. +if [ -n "${LIBBUILDER_GIT_SAFE_DIR+x}" ] +then + echo "Adding following directories into git's safe.directory" + echo "$LIBBUILDER_GIT_SAFE_DIR" | tr ':' '\n' | while read -r dir + do + git config --global --add safe.directory "$dir" + echo " $dir" + done +fi + +# Check if the mount point /arduino-esp32 exists +if [ -d "/arduino-esp32" ] && [[ "$@" == "python3 tools/config_editor/app.py"* ]]; then + # Running UI with mount point detected, adding -c and --output-permissions arguments + echo "Output folder permissions: `stat -c "%u:%g" /arduino-esp32`" + exec "$@" -c /arduino-esp32 --output-permissions `stat -c "%u:%g" /arduino-esp32` +else + # Running UI without mount point detected or running another command + exec "$@" +fi diff --git a/tools/docker/run.ps1 b/tools/docker/run.ps1 new file mode 100644 index 000000000..5ecb01a64 --- /dev/null +++ b/tools/docker/run.ps1 @@ -0,0 +1,64 @@ +# This is an example of how to run the docker container. +# This script is not part of the container, it is meant to be run on the host machine. +# Note that this file will build the release/v5.3 branch. For other branches, change the tag accordingly. +# You can check the available tags at https://hub.docker.com/r/espressif/esp32-arduino-lib-builder/tags +# As this script is unsigned, you may need to run `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass` before running it. +# Usage: .\run.ps1 <path_to_arduino_esp32> + +# Exit on error +$ErrorActionPreference = "stop" + +# https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/ +# Check if command exists +Function Test-CommandExists +{ + Param ($command) + try { + if (Get-Command $command) { + RETURN $true + } + } + catch { + RETURN $false + } +} + +# Check if path exists +Function Test-PathExists +{ + Param ($path) + try { + if (Test-Path -Path $path) { + RETURN $true + } + } + catch { + RETURN $false + } +} + +if (-not (Test-CommandExists docker)) { + Write-Host "ERROR: Docker is not installed! Please install docker first." -ForegroundColor red + exit 1 +} + +if ($args.Count -gt 0) { + $ARDUINO_DIR = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($args[0]) +} + +$DOCKER_ARGS = @() +$DOCKER_ARGS += '-it' +$DOCKER_ARGS += '-e', 'TERM=xterm-256color' + +if ((Test-PathExists $ARDUINO_DIR)) { + $DOCKER_ARGS += '-v', "${ARDUINO_DIR}:/arduino-esp32" +} else { + Write-Output "Warning: Invalid arduino directory: '$ARDUINO_DIR'. Ignoring it." +} + +if ($env:LIBBUILDER_GIT_SAFE_DIR) { + $DOCKER_ARGS += '-e', "LIBBUILDER_GIT_SAFE_DIR=$env:LIBBUILDER_GIT_SAFE_DIR" +} + +Write-Output "Running: docker run $($DOCKER_ARGS -join ' ') espressif/esp32-arduino-lib-builder" +docker run @($DOCKER_ARGS) espressif/esp32-arduino-lib-builder:release-v5.3 diff --git a/tools/docker/run.sh b/tools/docker/run.sh new file mode 100755 index 000000000..c7f97a6f5 --- /dev/null +++ b/tools/docker/run.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# This is an example of how to run the docker container. +# This script is not part of the container, it is meant to be run on the host machine. +# Note that this file will build the release/v5.3 branch. For other branches, change the tag accordingly. +# You can check the available tags at https://hub.docker.com/r/espressif/esp32-arduino-lib-builder/tags +# Usage: ./run.sh <path_to_arduino_esp32> + +if ! [ -x "$(command -v docker)" ]; then + echo "ERROR: Docker is not installed! Please install docker first." + exit 1 +fi + +if [ -n "$1" ]; then + ARDUINO_DIR=$(realpath "$1") +else + ARDUINO_DIR="" +fi + +DOCKER_ARGS=() + +DOCKER_ARGS+=(-it) +DOCKER_ARGS+=(-e TERM=xterm-256color) + +if [ -d "$ARDUINO_DIR" ]; then + DOCKER_ARGS+=(-v $ARDUINO_DIR:/arduino-esp32) +else + echo "Warning: Invalid arduino directory: '$ARDUINO_DIR'. Ignoring it." +fi + +if [ -n "$LIBBUILDER_GIT_SAFE_DIR" ]; then + DOCKER_ARGS+=(-e LIBBUILDER_GIT_SAFE_DIR=$LIBBUILDER_GIT_SAFE_DIR) +fi + +echo "Running: docker run ${DOCKER_ARGS[@]} espressif/esp32-arduino-lib-builder" +docker run ${DOCKER_ARGS[@]} espressif/esp32-arduino-lib-builder:release-v5.3 diff --git a/tools/gen_pioarduino_manifest.py b/tools/gen_pioarduino_manifest.py new file mode 100644 index 000000000..9d2b99c19 --- /dev/null +++ b/tools/gen_pioarduino_manifest.py @@ -0,0 +1,86 @@ +import argparse +import json +import os +import re +import sys + +MANIFEST_DATA = { + "name": "framework-arduinoespressif32-libs", + "description": "Precompiled libraries for Arduino Wiring-based Framework for the Espressif ESP32 series of SoCs", + "keywords": ["framework", "arduino", "espressif", "esp32"], + "license": "LGPL-2.1-or-later", + "repository": { + "type": "git", + "url": "https://github.com/espressif/esp32-arduino-lib-builder", + }, +} + + +def convert_version(version_string): + """A helper function that converts a custom IDF version string + extracted from a Git repository to a suitable SemVer alternative. For example: + 'release/v5.1' becomes '5.1.0', + 'v7.7.7' becomes '7.7.7' + """ + + regex_pattern = ( + r"v(?P<MAJOR>0|[1-9]\d*)\.(?P<MINOR>0|[1-9]\d*)\.*(?P<PATCH>0|[1-9]\d*)*" + ) + match = re.search(regex_pattern, version_string) + if not match: + sys.stderr.write( + f"Failed to find a regex match for '{regex_pattern}' in '{version_string}'\n" + ) + return "" + + major, minor, patch = match.groups() + if not patch: + patch = "0" + + return ".".join((major, minor, patch)) + + +def main(dst_dir, version_string, commit_hash): + + converted_version = convert_version(version_string) + if not converted_version: + sys.stderr.write(f"Failed to convert version '{version_string}'\n") + return -1 + + manifest_file_path = os.path.join(dst_dir, "package.json") + with open(manifest_file_path, "w", encoding="utf8") as fp: + MANIFEST_DATA["version"] = f"{converted_version}+sha.{commit_hash}" + json.dump(MANIFEST_DATA, fp, indent=2) + + print( + f"Generated pioarduino manifest file '{manifest_file_path}' with '{converted_version}' version" + ) + return 0 + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "-o", + "--dst-dir", + dest="dst_dir", + required=True, + help="Destination folder where the 'package.json' manifest will be located", + ) + parser.add_argument( + "-s", + "--version-string", + dest="version_string", + required=True, + help="ESP-IDF version string used for compiling libraries", + ) + parser.add_argument( + "-c", + "--commit-hash", + dest="commit_hash", + required=True, + help="ESP-IDF revision in form of a commit hash", + ) + args = parser.parse_args() + + sys.exit(main(args.dst_dir, args.version_string, args.commit_hash)) diff --git a/tools/gen_tools_json.py b/tools/gen_tools_json.py new file mode 100644 index 000000000..f03b73d78 --- /dev/null +++ b/tools/gen_tools_json.py @@ -0,0 +1,242 @@ +#!/usr/bin/env python +# python tools/gen_tools_json.py -i $IDF_PATH -j components/arduino/package/package_esp32_index.template.json -o out/ + +from __future__ import print_function + +__author__ = "Hristo Gochkov" +__version__ = "2023" + +import os +import shutil +import errno +import os.path +import json +import platform +import sys +import stat +import argparse +import re +import requests + +if sys.version_info[0] == 3: + unicode = lambda s: str(s) + +release_manifests = [] + +def replace_if_xz(system): + if not system['url'].endswith(".tar.xz"): + return system + + new_url = system['url'].replace(".tar.xz", ".tar.gz") + new_name = system['archiveFileName'].replace(".tar.xz", ".tar.gz") + new_signed_url = system['url'].replace(".tar.xz", "_signed.tar.gz") + new_signed_name = system['archiveFileName'].replace(".tar.xz", "_signed.tar.gz") + new_checksum = "" + new_size = 0 + + # let's get the checksum file from the release + release_manifest_url = "" + # parse the download url to extract all info needed for the checksum file url + urlx = re.findall("^https://github.com/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/releases/download/([a-zA-Z0-9_\-.]+)/([a-zA-Z0-9_\-.]+)$", new_url) + if urlx and len(urlx) > 0: + (owner, proj, version, filename) = urlx[0] + release_manifest_url = "https://github.com/%s/%s/releases/download/%s/%s-%s-checksum.sha256" % (owner, proj, version, proj, version) + else: + print("No manifest match") + return system + + # check if we have already downloaded and parsed that manifest + manifest_index = 0 + manifest_found = False + for manifest in release_manifests: + if manifest['url'] == release_manifest_url: + manifest_found = True + break + manifest_index = manifest_index + 1 + + # download and parse manifest + if not manifest_found: + manifest = { + "url": release_manifest_url, + "files": [] + } + release_manifest_contents = requests.get(release_manifest_url).text + x = re.findall("\s([a-zA-Z0-9_\-.]+):\s([0-9]+)\s[a-z]+\\n([a-f0-9]+)\s\*.*", release_manifest_contents) + if x and len(x) > 0: + for line in x: + (filename, size, checksum) = line + file = { + "name":filename, + "checksum":checksum, + "size":size + } + manifest["files"].append(file) + else: + print("No line match") + return system + + release_manifests.append(manifest) + + # find the new file in the list and get it's size and checksum + for file in release_manifests[manifest_index]['files']: + if file['name'] == new_signed_name: + print("Found a signed version of the file") + new_url = new_signed_url + new_name = new_signed_name + break + for file in release_manifests[manifest_index]['files']: + if file['name'] == new_name: + system['url'] = new_url + system['archiveFileName'] = new_name + system["checksum"] = "SHA-256:"+file['checksum'] + system["size"] = file['size'] + break + return system + +if __name__ == '__main__': + + parser = argparse.ArgumentParser( + prog = 'gen_tools_json', + description = 'Update Arduino package index with the tolls found in ESP-IDF') + parser.add_argument('-i', '--esp-idf', dest='idf_path', required=True, help='Path to ESP-IDF') + parser.add_argument('-j', '--pkg-json', dest='arduino_json', required=False, help='path to Arduino package json') + parser.add_argument('-o', '--out-path', dest='out_path', required=True, help='Output path to store the update package json') + args = parser.parse_args() + + simple_output = False + if args.arduino_json == None: + print('Source was not selected') + simple_output = True + else: + print('Source {0}.'.format(args.arduino_json)) + + idf_path = args.idf_path; + arduino_json = args.arduino_json; + out_path = args.out_path; + + # settings + arduino_tools = ["xtensa-esp-elf","xtensa-esp-elf-gdb","riscv32-esp-elf","riscv32-esp-elf-gdb","openocd-esp32"] + + # code start + farray = {"packages":[{"platforms":[{"toolsDependencies":[]}],"tools":[]}]} + if simple_output == False: + farray = json.load(open(arduino_json)) + + idf_tools = json.load(open(idf_path + '/tools/tools.json')) + for tool in idf_tools['tools']: + try: + tool_index = arduino_tools.index(tool['name']) + except: + continue + tool_name = tool['name'] + tool_version = tool['versions'][0]['name'] + if tool_name.endswith('-elf'): + tool_name += '-gcc' + print('Found {0}, version: {1}'.format(tool_name, tool_version)) + + if simple_output == False: + dep_found = False + dep_skip = False + for dep in farray['packages'][0]['platforms'][0]['toolsDependencies']: + if dep['name'] == tool_name: + if dep['version'] == tool_version: + print('Skipping {0}. Same version {1}'.format(tool_name, tool_version)) + dep_skip = True + break + print('Updating dependency version of {0} from {1} to {2}'.format(tool_name, dep['version'], tool_version)) + dep['version'] = tool_version + dep_found = True + if dep_skip == True: + continue + if dep_found == False: + print('Adding new dependency: {0} version {1}'.format(tool_name, tool_version)) + deps = { + "packager": "esp32", + "name": tool_name, + "version": tool_version + } + farray['packages'][0]['platforms'][0]['toolsDependencies'].append(deps) + else: + print('Adding dependency: {0} version {1}'.format(tool_name, tool_version)) + deps = { + "packager": "esp32", + "name": tool_name, + "version": tool_version + } + farray['packages'][0]['platforms'][0]['toolsDependencies'].append(deps) + + systems = [] + for arch in tool['versions'][0]: + if arch == 'name' or arch == 'status': + continue + tool_data = tool['versions'][0][arch] + + system = { + "host": '', + "url": tool_data['url'], + "archiveFileName": os.path.basename(tool_data['url']), + "checksum": "SHA-256:"+tool_data['sha256'], + "size": str(tool_data['size']) + } + + if arch == "win32": + system["host"] = "i686-mingw32"; + elif arch == "win64": + system["host"] = "x86_64-mingw32"; + elif arch == "macos-arm64": + system["host"] = "arm64-apple-darwin"; + elif arch == "macos": + system["host"] = "x86_64-apple-darwin"; + elif arch == "linux-amd64": + system["host"] = "x86_64-pc-linux-gnu"; + elif arch == "linux-i686": + system["host"] = "i686-pc-linux-gnu"; + elif arch == "linux-arm64": + system["host"] = "aarch64-linux-gnu"; + elif arch == "linux-armel": + system["host"] = "arm-linux-gnueabihf"; + elif arch == "linux-armhf": + # system["host"] = "arm-linux-gnueabihf"; + continue + else : + continue + + system = replace_if_xz(system) + + systems.append(system) + + if simple_output == False: + tool_found = False + for t in farray['packages'][0]['tools']: + if t['name'] == tool_name: + t['version'] = tool_version + t['systems'] = systems + tool_found = True + print('Updating binaries of {0} to version {1}'.format(tool_name, tool_version)) + if tool_found == False: + print('Adding new tool: {0} version {1}'.format(tool_name, tool_version)) + tools = { + "name": tool_name, + "version": tool_version, + "systems": systems + } + farray['packages'][0]['tools'].append(tools) + else: + print('Adding tool: {0} version {1}'.format(tool_name, tool_version)) + tools = { + "name": tool_name, + "version": tool_version, + "systems": systems + } + farray['packages'][0]['tools'].append(tools) + + json_str = json.dumps(farray, indent=2) + out_file = out_path + "tools.json" + if simple_output == False: + out_file = out_path + os.path.basename(arduino_json) + + with open(out_file, "w") as f: + f.write(json_str+"\n") + f.close() + # print(json_str) + print('{0} generated'.format(out_file)) diff --git a/tools/get_projbuild_gitconfig.py b/tools/get_projbuild_gitconfig.py new file mode 100644 index 000000000..305bb117c --- /dev/null +++ b/tools/get_projbuild_gitconfig.py @@ -0,0 +1,124 @@ +# This file is expected to be present in ${COMPONENT_DIR} +# accessed from components/esp_insights/CMakeLists.txt +# Used in: +# 1. Project ESP Insights build package tar file + +#from __future__ import unicode_literals +import os +import sys +import json +import subprocess +from builtins import range, str +from io import open + +# Input project directory from CMakeLists.txt +PROJ_DIR=sys.argv[1] +# Input project name +PROJ_NAME=sys.argv[2] +# Input project version +PROJ_VER=sys.argv[3] +# Input custom config filename from CMakeLists.txt +FILENAME=sys.argv[4] +# Input IDF_PATH from CMakeLists.txt +IDF_PATH=sys.argv[5] +# Input target +TARGET=sys.argv[6] + +NEWLINE = "\n" + +CONFIG = {} + +# Set Config + +# Set current directory i.e Set ${COMPONENT_DIR} as current directory +CURR_DIR = os.getcwd() + +def _change_dir(dirname): + # Change directory + os.chdir(dirname) + + +def _set_submodule_cfg(submodules, repo_name): + # Set config for submodules + CFG_TITLE = "submodules" + NAME_STR = "name" + VERSION_STR = "version" + CONFIG[repo_name][CFG_TITLE] = [] + + if submodules: + # Get the submodule name and version + submodules_list = submodules.strip().split(NEWLINE) + for i in range(0, len(submodules_list), 2): + name = submodules_list[i].split('\'')[1] + version = submodules_list[i+1] + submodule_json = { NAME_STR: name, VERSION_STR: version } + CONFIG[repo_name][CFG_TITLE].append(submodule_json) + + +def run_cmd(command, get_basename=False): + try: + resp = subprocess.check_output(command, shell=True).strip().decode('utf-8') + if get_basename: + resp = os.path.basename(resp) + return resp + except subprocess.CalledProcessError: + raise Exception("ERROR: Please check command : {}".format(command)) + +def set_cfg(config_name): + # Set config for ESP-IDF Repo + if config_name == "esp-idf": + # Get repo name (for IDF repo) + REPO_CMD='git rev-parse --show-toplevel' + repo_name = run_cmd(REPO_CMD, get_basename=True) + CONFIG[repo_name] = {} + + # Get commit HEAD + GITHEAD_STR = "HEAD" + HEAD='git describe --always --tags --dirty' + head_ver = run_cmd(HEAD) + CONFIG[repo_name][GITHEAD_STR] = head_ver + + # Get submodule latest refs + SUBMODULE = 'git submodule foreach git describe --always --tags --dirty' + submodules = run_cmd(SUBMODULE) + _set_submodule_cfg(submodules, repo_name) + elif config_name == "toolchain": + # Set config for Toolchain Version + arch_target = "xtensa-" + TARGET + if TARGET == "esp32c3" or TARGET == "esp32c2" or TARGET == "esp32h2" or TARGET == "esp32c6": + arch_target = "riscv32-esp" + # Get toolchain version + TOOLCHAIN_STR = "toolchain" + TOOLCHAIN = arch_target + '-elf-gcc --version' + toolchain = run_cmd(TOOLCHAIN) + CONFIG[TOOLCHAIN_STR] = toolchain.strip().split(NEWLINE)[0] + +# Set project details - name and version +def set_project_details(): + # Set project name and version + CONFIG['project'] = {} + CONFIG['project']['name'] = PROJ_NAME + CONFIG['project']['version'] = PROJ_VER + +try: + with open(FILENAME, "w+", encoding="utf-8") as output_file: + # ESP-IDF REPO CONFIG + # Change to ESP-IDF Directory + _change_dir(IDF_PATH) + set_cfg("esp-idf") + + # Change back to ${COMPONENT_DIR} + _change_dir(CURR_DIR) + + # Set project name and version + set_project_details() + + # GET TOOLCHAIN VERSION + set_cfg("toolchain") + + output_file.write(str(json.dumps(CONFIG, indent=4, sort_keys=True))) + +except Exception as e: + # Remove config file created if error occurs + os.system("rm " + FILENAME) + sys.exit(e) \ No newline at end of file diff --git a/tools/install-arduino.sh b/tools/install-arduino.sh new file mode 100755 index 000000000..1a0ba4d39 --- /dev/null +++ b/tools/install-arduino.sh @@ -0,0 +1,48 @@ +#/bin/bash + +source ./tools/config.sh + +# +# CLONE/UPDATE ARDUINO +# +echo "Updating ESP32 Arduino..." +if [ ! -d "$AR_COMPS/arduino" ]; then + git clone $AR_REPO_URL "$AR_COMPS/arduino" +fi + +if [ -z $AR_BRANCH ]; then + if [ -z $GITHUB_HEAD_REF ]; then + current_branch=`git branch --show-current` + else + current_branch="$GITHUB_HEAD_REF" + fi + echo "Current Branch: $current_branch" + if [[ "$current_branch" != "master" && `git_branch_exists "$AR_COMPS/arduino" "$current_branch"` == "1" ]]; then + export AR_BRANCH="$current_branch" + else + if [ "$IDF_TAG" ]; then #tag was specified at build time + AR_BRANCH_NAME="idf-$IDF_TAG" + elif [ "$IDF_COMMIT" ]; then #commit was specified at build time + AR_BRANCH_NAME="idf-$IDF_COMMIT" + else + AR_BRANCH_NAME="idf-$IDF_BRANCH" + fi + has_ar_branch=`git_branch_exists "$AR_COMPS/arduino" "$AR_BRANCH_NAME"` + if [ "$has_ar_branch" == "1" ]; then + export AR_BRANCH="$AR_BRANCH_NAME" + else + has_ar_branch=`git_branch_exists "$AR_COMPS/arduino" "$AR_PR_TARGET_BRANCH"` + if [ "$has_ar_branch" == "1" ]; then + export AR_BRANCH="$AR_PR_TARGET_BRANCH" + fi + fi + fi +fi + +if [ "$AR_BRANCH" ]; then + echo "AR_BRANCH='$AR_BRANCH'" + git -C "$AR_COMPS/arduino" fetch --all && \ + git -C "$AR_COMPS/arduino" checkout "$AR_BRANCH" && \ + git -C "$AR_COMPS/arduino" pull --ff-only +fi +if [ $? -ne 0 ]; then exit 1; fi diff --git a/tools/install-esp-idf.sh b/tools/install-esp-idf.sh index 9b625d0ab..0519ae67a 100755 --- a/tools/install-esp-idf.sh +++ b/tools/install-esp-idf.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#/bin/bash source ./tools/config.sh @@ -11,131 +11,41 @@ fi # CLONE ESP-IDF # -if [ -z "$IDF_PATH" ]; then +if [ ! -d "$IDF_PATH" ]; then echo "ESP-IDF is not installed! Installing local copy" + git clone $IDF_REPO_URL -b $IDF_BRANCH idf_was_installed="1" - if ! [ -d esp-idf ]; then - git clone $IDF_REPO_URL -b $IDF_BRANCH - fi - export IDF_PATH="$AR_ROOT/esp-idf" fi -if [ "$IDF_COMMIT" ]; then +git -C "$IDF_PATH" fetch --all --tags + +if [ "$IDF_TAG" ]; then + git -C "$IDF_PATH" checkout "tags/$IDF_TAG" + idf_was_installed="1" +elif [ "$IDF_COMMIT" ]; then git -C "$IDF_PATH" checkout "$IDF_COMMIT" commit_predefined="1" fi -export IDF_COMMIT=$(git -C "$IDF_PATH" rev-parse --short HEAD) -export IDF_BRANCH=$(git -C "$IDF_PATH" symbolic-ref --short HEAD) - -# -# SETUP ARDUINO DEPLOY -# - -if [ "$GITHUB_EVENT_NAME" == "schedule" ] || [ "$GITHUB_EVENT_NAME" == "repository_dispatch" -a "$GITHUB_EVENT_ACTION" == "deploy" ]; then - # format new branch name and pr title - if [ -x $commit_predefined ]; then #commit was not specified at build time - AR_NEW_BRANCH_NAME="idf-$IDF_BRANCH" - AR_NEW_COMMIT_MESSAGE="IDF $IDF_BRANCH $IDF_COMMIT" - AR_NEW_PR_TITLE="IDF $IDF_BRANCH" - else - AR_NEW_BRANCH_NAME="idf-$IDF_COMMIT" - AR_NEW_COMMIT_MESSAGE="IDF $IDF_COMMIT" - AR_NEW_PR_TITLE="$AR_NEW_COMMIT_MESSAGE" - fi - - AR_HAS_COMMIT=`git_commit_exists "$AR_COMPS/arduino" "$AR_NEW_COMMIT_MESSAGE"` - AR_HAS_BRANCH=`git_branch_exists "$AR_COMPS/arduino" "$AR_NEW_BRANCH_NAME"` - AR_HAS_PR=`git_pr_exists "$AR_NEW_BRANCH_NAME"` - - if [ "$AR_HAS_COMMIT" == "1" ]; then - echo "Commit '$AR_NEW_COMMIT_MESSAGE' Already Exists" - exit 0 - fi - - if [ "$AR_HAS_BRANCH" == "1" ]; then - echo "Branch '$AR_NEW_BRANCH_NAME' Already Exists" - fi - - if [ "$AR_HAS_PR" == "1" ]; then - echo "PR '$AR_NEW_PR_TITLE' Already Exists" - fi - - # setup git for pushing - git config --global github.user "$GITHUB_ACTOR" - git config --global user.name "$GITHUB_ACTOR" - git config --global user.email "$GITHUB_ACTOR@github.com" - - # create or checkout the branch - if [ ! $AR_HAS_BRANCH == "0" ]; then - echo "Switching to arduino branch '$AR_NEW_BRANCH_NAME'..." - git -C "$AR_COMPS/arduino" checkout $AR_NEW_BRANCH_NAME - else - echo "Creating arduino branch '$AR_NEW_BRANCH_NAME'..." - git -C "$AR_COMPS/arduino" checkout -b $AR_NEW_BRANCH_NAME - fi - if [ $? -ne 0 ]; then - echo "ERROR: Checkout of branch '$AR_NEW_BRANCH_NAME' failed" - exit 1 - fi - - export AR_NEW_BRANCH_NAME - export AR_NEW_COMMIT_MESSAGE - export AR_NEW_PR_TITLE - - export AR_HAS_COMMIT - export AR_HAS_BRANCH - export AR_HAS_PR -fi - # -# UPDATE IDF MODULES +# UPDATE ESP-IDF TOOLS AND MODULES # -if [ -x $idf_was_installed ]; then - git -C $IDF_PATH fetch origin && git -C $IDF_PATH pull origin $IDF_BRANCH - git -C $IDF_PATH submodule update --init --recursive -else +if [ ! -x $idf_was_installed ] || [ ! -x $commit_predefined ]; then git -C $IDF_PATH submodule update --init --recursive - cd $IDF_PATH && python -m pip install -r requirements.txt && cd "$AR_ROOT" + $IDF_PATH/install.sh + export IDF_COMMIT=$(git -C "$IDF_PATH" rev-parse --short HEAD) + export IDF_BRANCH=$(git -C "$IDF_PATH" symbolic-ref --short HEAD || git -C "$IDF_PATH" tag --points-at HEAD) + + # Temporarily patch the ESP32-S2 I2C LL driver to keep the clock source + cd $IDF_PATH + patch -p1 -N -i $AR_PATCHES/esp32s2_i2c_ll_master_init.diff + patch -p1 -N -i $AR_PATCHES/lwip_max_tcp_pcb.diff + cd - fi # -# INSTALL TOOLCHAIN +# SETUP ESP-IDF ENV # -if ! [ -x "$(command -v $IDF_TOOLCHAIN-gcc)" ]; then - echo "GCC toolchain is not installed! Installing local copy" - - if ! [ -d "$IDF_TOOLCHAIN" ]; then - TC_EXT="tar.gz" - if [[ "$AR_OS" == "win32" ]]; then - TC_EXT="zip" - fi - if ! [ -f $IDF_TOOLCHAIN.$TC_EXT ]; then - if [[ "$AR_OS" == "linux32" ]]; then - TC_LINK="$IDF_TOOLCHAIN_LINUX32" - elif [[ "$AR_OS" == "linux64" ]]; then - TC_LINK="$IDF_TOOLCHAIN_LINUX64" - elif [[ "$AR_OS" == "linux-armel" ]]; then - TC_LINK="$IDF_TOOLCHAIN_LINUX_ARMEL" - elif [[ "$AR_OS" == "macos" ]]; then - TC_LINK="$IDF_TOOLCHAIN_MACOS" - elif [[ "$AR_OS" == "win32" ]]; then - TC_LINK="$IDF_TOOLCHAIN_WIN32" - else - echo "Unsupported OS $OSTYPE" - exit 1 - fi - echo "Downloading $TC_LINK" - curl -k -o $IDF_TOOLCHAIN.$TC_EXT $TC_LINK || exit 1 - fi - if [[ "$AR_OS" == "win32" ]]; then - unzip $IDF_TOOLCHAIN.$TC_EXT || exit 1 - else - tar zxf $IDF_TOOLCHAIN.$TC_EXT || exit 1 - fi - rm -rf $IDF_TOOLCHAIN.$TC_EXT - fi - export PATH="$AR_ROOT/$IDF_TOOLCHAIN/bin:$PATH" -fi +source $IDF_PATH/export.sh diff --git a/tools/patch-tinyusb.sh b/tools/patch-tinyusb.sh new file mode 100755 index 000000000..eeaa4d43b --- /dev/null +++ b/tools/patch-tinyusb.sh @@ -0,0 +1,4 @@ +#!/bin/bash +mv components/arduino_tinyusb/src/dcd_dwc2.c components/arduino_tinyusb/src/dcd_dwc2.c.prev +cp components/arduino_tinyusb/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c components/arduino_tinyusb/src/dcd_dwc2.c +patch -p1 -N -i components/arduino_tinyusb/patches/dcd_dwc2.patch diff --git a/tools/prepare-ci.sh b/tools/prepare-ci.sh new file mode 100755 index 000000000..6867ae045 --- /dev/null +++ b/tools/prepare-ci.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +sudo apt update && sudo apt install -y git wget curl libssl-dev libncurses-dev flex bison gperf python3 cmake ninja-build ccache +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3 get-pip.py && \ +pip3 install setuptools pyserial click future wheel cryptography pyparsing pyelftools diff --git a/tools/prepare-libs.sh b/tools/prepare-libs.sh deleted file mode 100755 index 63ff7b2e3..000000000 --- a/tools/prepare-libs.sh +++ /dev/null @@ -1,150 +0,0 @@ -#!/bin/bash -# config -source ./tools/config.sh - -# clean previous -if [ -e "$AR_TOOLS" ]; then - rm -rf "$AR_TOOLS" -fi -mkdir -p "$AR_SDK" - -# start generation of platformio-build.py -awk "/CPPPATH\=\[/{n++}{print>n\"pio_start.txt\"}" $AR_COMPS/arduino/tools/platformio-build.py -awk "/LIBSOURCE_DIRS\=\[/{n++}{print>n\"pio_end.txt\"}" 1pio_start.txt -cat 2pio_start.txt >> 1pio_end.txt -cat pio_start.txt > "$AR_PLATFORMIO_PY" -rm pio_end.txt 1pio_start.txt 2pio_start.txt pio_start.txt - -# include dirs -AR_INC="-DESP_PLATFORM -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" -DHAVE_CONFIG_H -DGCC_NOT_5_2_0=0 -DWITH_POSIX \"-I{compiler.sdk.path}/include/config\"" -echo " CPPPATH=[" >> "$AR_PLATFORMIO_PY" && echo " join(FRAMEWORK_DIR, \"tools\", \"sdk\", \"include\", \"config\")," >> "$AR_PLATFORMIO_PY" -while [ "$1" != "" ]; do - cpath=$1 - cname=$(echo $cpath| cut -d'/' -f 1) - if [ -d "$AR_COMPS/$cpath" ]; then - full_cpath="$AR_COMPS/$cpath" - else - full_cpath="$IDF_COMPS/$cpath" - fi - out_cpath="$AR_SDK/include/$cname" - if [ ! -d $out_cpath ]; then - #first encounter of this component - AR_INC+=" \"-I{compiler.sdk.path}/include/$cname\"" - echo " join(FRAMEWORK_DIR, \"tools\", \"sdk\", \"include\", \"$cname\")," >> "$AR_PLATFORMIO_PY" - fi - for f in `find $full_cpath -name '*.h'`; do - rel_f=${f#*$cpath/} - full_f=/$rel_f - rel_p=${full_f%/*} - mkdir -p "$out_cpath$rel_p" - cp -f $f "$out_cpath$rel_p/" - done - for f in `find $full_cpath -name '*.hpp'`; do - rel_f=${f#*$cpath/} - full_f=/$rel_f - rel_p=${full_f%/*} - mkdir -p "$out_cpath$rel_p" - cp -f $f "$out_cpath$rel_p/" - done - shift -done -echo " join(FRAMEWORK_DIR, \"cores\", env.BoardConfig().get(\"build.core\"))" >> "$AR_PLATFORMIO_PY" -echo " ]," >> "$AR_PLATFORMIO_PY" -echo "" >> "$AR_PLATFORMIO_PY" - -minlsize=8 - -# idf libs -mkdir -p $AR_SDK/lib && \ -for lib in `find $IDF_COMPS -name '*.a' | grep -v libg | grep -v libc_rom | grep -v workaround | grep -v libc-minusrom`; do - lsize=$($SSTAT "$lib") - if (( lsize > minlsize )); then - cp -f $lib $AR_SDK/lib/ - else - echo "skipping $lib: size too small $lsize" - fi -done - -# component libs -for lib in `find components -name '*.a' | grep -v arduino`; do - lsize=$($SSTAT "$lib") - if (( lsize > minlsize )); then - cp -f $lib $AR_SDK/lib/ - else - echo "skipping $lib: size too small $lsize" - fi -done - -# compiled libs -for lib in `find build -name '*.a' | grep -v bootloader | grep -v libmain | grep -v idf_test | grep -v aws_iot | grep -v libmicro | grep -v libarduino`; do - lsize=$($SSTAT "$lib") - if (( lsize > minlsize )); then - cp -f $lib $AR_SDK/lib/ - else - echo "skipping $lib: size too small $lsize" - fi -done -cp build/bootloader_support/libbootloader_support.a $AR_SDK/lib/ -cp build/micro-ecc/libmicro-ecc.a $AR_SDK/lib/ - -# remove liblib.a from esp-face (empty and causing issues on Windows) -rm -rf $AR_SDK/lib/liblib.a - -# generate Arduino and PIO configs -AR_LIBS="" -PIO_LIBS="\"-lgcc\"" -cd "$AR_SDK/lib/" -for lib in `find . -name '*.a'`; do - AR_LIBS+="-l"$(basename ${lib:5} .a)" " - PIO_LIBS+=", \"-l"$(basename ${lib:5} .a)"\"" -done -PIO_LIBS+=", \"-lstdc++\"" -cd "$AR_ROOT" - -echo " LIBPATH=[" >> "$AR_PLATFORMIO_PY" -echo " join(FRAMEWORK_DIR, \"tools\", \"sdk\", \"lib\")," >> "$AR_PLATFORMIO_PY" -echo " join(FRAMEWORK_DIR, \"tools\", \"sdk\", \"ld\")" >> "$AR_PLATFORMIO_PY" -echo " ]," >> "$AR_PLATFORMIO_PY" -echo "" >> "$AR_PLATFORMIO_PY" - -echo " LIBS=[" >> "$AR_PLATFORMIO_PY" -echo " $PIO_LIBS" >> "$AR_PLATFORMIO_PY" -echo " ]," >> "$AR_PLATFORMIO_PY" -echo "" >> "$AR_PLATFORMIO_PY" - -# end generation of platformio-build.py -cat 1pio_end.txt >> "$AR_PLATFORMIO_PY" -rm 1pio_end.txt - -# arduino platform.txt -awk "/compiler.cpreprocessor.flags\=/{n++}{print>n\"platform_start.txt\"}" $AR_COMPS/arduino/platform.txt -$SED -i '/compiler.cpreprocessor.flags\=/d' 1platform_start.txt -awk "/compiler.c.elf.libs\=/{n++}{print>n\"platform_mid.txt\"}" 1platform_start.txt -$SED -i '/compiler.c.elf.libs\=/d' 1platform_mid.txt -rm 1platform_start.txt -cat platform_start.txt > "$AR_PLATFORM_TXT" -echo "compiler.cpreprocessor.flags=$AR_INC" >> "$AR_PLATFORM_TXT" -cat platform_mid.txt >> "$AR_PLATFORM_TXT" -echo "compiler.c.elf.libs=-lgcc $AR_LIBS -lstdc++" >> "$AR_PLATFORM_TXT" -cat 1platform_mid.txt >> "$AR_PLATFORM_TXT" -rm platform_start.txt platform_mid.txt 1platform_mid.txt - -# sdkconfig -mkdir -p $AR_SDK/include/config && cp -f build/include/sdkconfig.h $AR_SDK/include/config/sdkconfig.h -cp -f sdkconfig $AR_SDK/sdkconfig - -# esptool.py -cp $IDF_COMPS/esptool_py/esptool/esptool.py $AR_ESPTOOL_PY - -# gen_esp32part.py -cp $IDF_COMPS/partition_table/gen_esp32part.py $AR_GEN_PART_PY - -# idf ld scripts -mkdir -p $AR_SDK/ld && find $IDF_COMPS/esp32/ld -name '*.ld' -exec cp -f {} $AR_SDK/ld/ \; - -# ld script -cp -f build/esp32/*.ld $AR_SDK/ld/ - -# Add IDF versions to sdkconfig -echo "#define CONFIG_ARDUINO_IDF_COMMIT \"$IDF_COMMIT\"" >> $AR_SDK/include/config/sdkconfig.h -echo "#define CONFIG_ARDUINO_IDF_BRANCH \"$IDF_BRANCH\"" >> $AR_SDK/include/config/sdkconfig.h diff --git a/tools/push-to-arduino.sh b/tools/push-to-arduino.sh index 7ebb077f0..8b9b552a7 100755 --- a/tools/push-to-arduino.sh +++ b/tools/push-to-arduino.sh @@ -1,59 +1,181 @@ #!/bin/bash -source ./tools/config.sh + +source ./tools/install-arduino.sh if [ -x $GITHUB_TOKEN ]; then echo "ERROR: GITHUB_TOKEN was not defined" exit 1 fi -if ! [ -d "$AR_COMPS/arduino" ]; then - echo "ERROR: Target arduino folder does not exist!" - exit 1 -fi +# setup git for pushing +git config --global github.user "$GITHUB_ACTOR" +git config --global user.name "$GITHUB_ACTOR" +git config --global user.email "$GITHUB_ACTOR@github.com" # # UPDATE FILES # -if [ $AR_HAS_COMMIT == "0" ]; then - cd $AR_COMPS/arduino +# +# esp32-arduino-libs +# + +LIBS_ZIP_FILENAME="esp32-arduino-libs-$LIBS_VERSION.zip" +LIBS_JSON_FILENAME="package-$LIBS_VERSION.json" +IDF_LIBS_ZIP_URL="https://github.com/$AR_LIBS_REPO/releases/download/$LIBS_RELEASE_TAG/$LIBS_ZIP_FILENAME" +IDF_LIBS_JSON_URL="https://github.com/$AR_LIBS_REPO/releases/download/$LIBS_RELEASE_TAG/$LIBS_JSON_FILENAME" + +if [ $AR_HAS_COMMIT == "0" ] || [ $LIBS_HAS_ASSET == "0" ]; then + cd "$AR_ROOT" + mkdir -p dist + + # check if the release exists + if [ $LIBS_HAS_RELEASE == "0" ]; then + echo "Release for tag \"$LIBS_RELEASE_TAG\" not found. Please create the release first." + exit 1 + fi + + # Delete old assets for the version + if [ $LIBS_HAS_ASSET == "1" ]; then + echo "Deleting existing assets for version '$LIBS_VERSION'..." + if [ `github_release_asset_delete "$AR_LIBS_REPO" "$LIBS_ASSET_ID"` == "0" ]; then + echo "ERROR: Failed to delete asset '$LIBS_ZIP_FILENAME'" + fi + JSON_ASSET_ID=`github_release_asset_id "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "$LIBS_JSON_FILENAME"` + if [ "$JSON_ASSET_ID" != "" ] && [ `github_release_asset_delete "$AR_LIBS_REPO" "$JSON_ASSET_ID"` == "0" ]; then + echo "ERROR: Failed to delete asset '$LIBS_JSON_FILENAME'" + fi + fi + + sleep 5 + echo "Creating asset '$LIBS_ZIP_FILENAME'..." + mv -f "dist/esp32-arduino-libs.zip" "dist/$LIBS_ZIP_FILENAME" + + LIBS_ASSET_ID=`github_release_asset_upload "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "$LIBS_ZIP_FILENAME" "dist/$LIBS_ZIP_FILENAME"` + if [ -z "$LIBS_ASSET_ID" ]; then + echo "ERROR: Failed to upload asset '$LIBS_ZIP_FILENAME. Retrying..." + LIBS_ASSET_ID=`github_release_asset_upload "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "$LIBS_ZIP_FILENAME" "dist/$LIBS_ZIP_FILENAME"` + if [ -z "$LIBS_ASSET_ID" ]; then + echo "ERROR: Failed to upload asset '$LIBS_ZIP_FILENAME'" + exit 1 + fi + fi + + echo "Finished uploading asset '$LIBS_ZIP_FILENAME'. Asset ID: $LIBS_ASSET_ID" + sleep 5 + + # Calculate the local file checksum and size + local_checksum=$(sha256sum "dist/$LIBS_ZIP_FILENAME" | awk '{print $1}') + local_size=$(stat -c%s "dist/$LIBS_ZIP_FILENAME") + + echo "Downloading asset '$LIBS_ZIP_FILENAME' and checking integrity..." + + # Download the file + remote_file="remote-$LIBS_ZIP_FILENAME" + curl -s -L -o "$remote_file" "$IDF_LIBS_ZIP_URL" + + # Check if the download was successful + if [ $? -ne 0 ]; then + echo "Error downloading file from $IDF_LIBS_ZIP_URL" + exit 1 + fi + + # Calculate the remote file checksum and size + remote_checksum=$(sha256sum "$remote_file" | awk '{print $1}') + remote_size=$(stat -c%s "$remote_file") + + echo "Local: $local_size bytes, $local_checksum" + echo "Remote: $remote_size bytes, $remote_checksum" + + # Check if the checksums match + if [ "$local_checksum" != "$remote_checksum" ]; then + echo "Checksum mismatch for downloaded file" + echo "Deleting asset and exiting..." + if [ `github_release_asset_delete "$AR_LIBS_REPO" "$LIBS_ASSET_ID"` == "0" ]; then + echo "ERROR: Failed to delete asset '$LIBS_ZIP_FILENAME'" + fi + exit 1 + fi + + # Clean up the downloaded file + rm "$remote_file" + + # Print the results + echo "Tool: esp32-arduino-libs" + echo "Version: $LIBS_VERSION" + echo "URL: $IDF_LIBS_ZIP_URL" + echo "File: $LIBS_ZIP_FILENAME" + echo "Size: $local_size bytes" + echo "SHA-256: $local_checksum" + echo "JSON: $AR_OUT/package_esp32_index.template.json" + cd "$AR_ROOT" + python3 tools/add_sdk_json.py -j "$AR_OUT/package_esp32_index.template.json" -n "esp32-arduino-libs" -v "$LIBS_VERSION" -u "$IDF_LIBS_ZIP_URL" -f "$LIBS_ZIP_FILENAME" -s "$local_size" -c "$local_checksum" + if [ $? -ne 0 ]; then exit 1; fi + + JSON_ASSET_ID=`github_release_asset_upload "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "$LIBS_JSON_FILENAME" "$AR_OUT/package_esp32_index.template.json"` + if [ -z "$JSON_ASSET_ID" ]; then + echo "ERROR: Failed to upload asset '$LIBS_JSON_FILENAME'. Retrying..." + JSON_ASSET_ID=`github_release_asset_upload "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "$LIBS_JSON_FILENAME" "$AR_OUT/package_esp32_index.template.json"` + if [ -z "$JSON_ASSET_ID" ]; then + echo "ERROR: Failed to upload asset '$LIBS_JSON_FILENAME'" + exit 1 + fi + fi +fi + +# +# esp32-arduino +# + +if [ $AR_HAS_COMMIT == "0" ] || [ $LIBS_HAS_ASSET == "0" ]; then + cd "$AR_ROOT" + # create or checkout the branch + if [ ! $AR_HAS_BRANCH == "0" ]; then + echo "Switching to arduino branch '$AR_NEW_BRANCH_NAME'..." + git -C "$AR_COMPS/arduino" checkout $AR_NEW_BRANCH_NAME + else + echo "Creating arduino branch '$AR_NEW_BRANCH_NAME'..." + git -C "$AR_COMPS/arduino" checkout -b $AR_NEW_BRANCH_NAME + fi + if [ $? -ne 0 ]; then + echo "ERROR: Checkout of branch '$AR_NEW_BRANCH_NAME' failed" + exit 1 + fi # make changes to the files echo "Patching files in branch '$AR_NEW_BRANCH_NAME'..." - rm -rf $AR_COMPS/arduino/tools/sdk - cp -Rf $AR_SDK $AR_COMPS/arduino/tools/sdk - cp -f $AR_ESPTOOL_PY $AR_COMPS/arduino/tools/esptool.py - cp -f $AR_GEN_PART_PY $AR_COMPS/arduino/tools/gen_esp32part.py - cp -f $AR_PLATFORMIO_PY $AR_COMPS/arduino/tools/platformio-build.py - cp -f $AR_PLATFORM_TXT $AR_COMPS/arduino/platform.txt + rm -rf "$AR_COMPS/arduino/package/package_esp32_index.template.json" && cp -f "$AR_OUT/package_esp32_index.template.json" "$AR_COMPS/arduino/package/package_esp32_index.template.json" + + cd $AR_COMPS/arduino # did any of the files change? if [ -n "$(git status --porcelain)" ]; then echo "Pushing changes to branch '$AR_NEW_BRANCH_NAME'..." - git add . && git commit --message "$AR_NEW_COMMIT_MESSAGE" && git push -u origin $AR_NEW_BRANCH_NAME + git add . && git commit --message "$AR_NEW_COMMIT_MESSAGE" && git push -u origin $AR_NEW_BRANCH_NAME if [ $? -ne 0 ]; then - echo "ERROR: Pushing to branch '$AR_NEW_BRANCH_NAME' failed" + echo "ERROR: Pushing to branch '$AR_NEW_BRANCH_NAME' failed" exit 1 fi else - echo "No changes in branch '$AR_NEW_BRANCH_NAME'" - if [ $AR_HAS_BRANCH == "0" ]; then - echo "Delete created branch '$AR_NEW_BRANCH_NAME'" - git branch -d $AR_NEW_BRANCH_NAME - fi - exit 0 + echo "No changes in branch '$AR_NEW_BRANCH_NAME'" + if [ $AR_HAS_BRANCH == "0" ]; then + echo "Delete created branch '$AR_NEW_BRANCH_NAME'" + git branch -d $AR_NEW_BRANCH_NAME + fi + exit 0 fi -fi -# -# CREATE PULL REQUEST -# - -if [ "$AR_HAS_PR" == "0" ]; then - pr_created=`git_create_pr "$AR_NEW_BRANCH_NAME" "$AR_NEW_PR_TITLE"` - if [ $pr_created == "0" ]; then - echo "ERROR: Failed to create PR '$AR_NEW_PR_TITLE': "`echo "$git_create_pr_res" | jq -r '.message'`": "`echo "$git_create_pr_res" | jq -r '.errors[].message'` - exit 1 + # CREATE PULL REQUEST + if [ "$AR_HAS_PR" == "0" ]; then + echo "Creating PR '$AR_NEW_PR_TITLE'..." + pr_created=`git_create_pr "$AR_NEW_BRANCH_NAME" "$AR_NEW_PR_TITLE" "$AR_PR_TARGET_BRANCH"` + if [ $pr_created == "0" ]; then + echo "ERROR: Failed to create PR '$AR_NEW_PR_TITLE': "`echo "$git_create_pr_res" | jq -r '.message'`": "`echo "$git_create_pr_res" | jq -r '.errors[].message'` + exit 1 + fi + else + echo "PR '$AR_NEW_PR_TITLE' Already Exists" fi fi + exit 0 diff --git a/tools/repository_dispatch.sh b/tools/repository_dispatch.sh old mode 100644 new mode 100755 index 2fdce4ae2..ad23620a8 --- a/tools/repository_dispatch.sh +++ b/tools/repository_dispatch.sh @@ -9,10 +9,12 @@ EVENT_JSON=`cat "$GITHUB_EVENT_PATH"` action=`echo "$EVENT_JSON" | jq -r '.action'` payload=`echo "$EVENT_JSON" | jq -r '.client_payload'` branch=`echo "$payload" | jq -r '.branch'` +tag=`echo "$payload" | jq -r '.tag'` commit=`echo "$payload" | jq -r '.commit'` builder=`echo "$payload" | jq -r '.builder'` +arduino=`echo "$payload" | jq -r '.arduino'` -echo "Action: $action, Branch: $branch, Commit: $commit, Builder: $builder" +echo "Action: $action, IDF Branch: $branch, IDF Tag: $tag, IDF Commit: $commit, Builder Branch: $builder, Arduino Branch: $arduino, Actor: $GITHUB_ACTOR" if [ ! "$action" == "deploy" ] && [ ! "$action" == "build" ]; then echo "Bad Action $action" @@ -25,7 +27,9 @@ if [ ! "$commit" == "" ] && [ ! "$commit" == "null" ]; then export IDF_COMMIT="$commit" else commit="" - if [ ! "$branch" == "" ] && [ ! "$branch" == "null" ]; then + if [ ! "$tag" == "" ] && [ ! "$tag" == "null" ]; then + export IDF_TAG="$tag" + elif [ ! "$branch" == "" ] && [ ! "$branch" == "null" ]; then export IDF_BRANCH="$branch" fi fi @@ -34,8 +38,16 @@ if [ ! "$builder" == "" ] && [ ! "$builder" == "null" ]; then git checkout "$builder" fi -source ./build.sh +if [ ! "$arduino" == "" ] && [ ! "$arduino" == "null" ]; then + export AR_BRANCH="$arduino" +fi if [ "$action" == "deploy" ]; then - bash ./tools/push-to-arduino.sh + DEPLOY_OUT=1 fi + +source ./build.sh + +# if [ "$action" == "deploy" ]; then +# bash ./tools/push-to-arduino.sh +# fi diff --git a/tools/update-components.sh b/tools/update-components.sh index 52c5b6f65..298783c74 100755 --- a/tools/update-components.sh +++ b/tools/update-components.sh @@ -1,40 +1,17 @@ -#!/bin/bash +#/bin/bash source ./tools/config.sh # -# CLONE/UPDATE ARDUINO +# CLONE/UPDATE TINYUSB # - -if [ ! -d "$AR_COMPS/arduino" ]; then - git clone $AR_REPO_URL "$AR_COMPS/arduino" -else - git -C "$AR_COMPS/arduino" fetch origin && \ - git -C "$AR_COMPS/arduino" pull origin master -fi -if [ $? -ne 0 ]; then exit 1; fi -git -C "$AR_COMPS/arduino" submodule update --init --recursive - -# -# CLONE/UPDATE ESP32-CAMERA -# - -if [ ! -d "$AR_COMPS/esp32-camera" ]; then - git clone $CAMERA_REPO_URL "$AR_COMPS/esp32-camera" -else - git -C "$AR_COMPS/esp32-camera" fetch origin && \ - git -C "$AR_COMPS/esp32-camera" pull origin master -fi -if [ $? -ne 0 ]; then exit 1; fi - -# -# CLONE/UPDATE ESP-FACE -# - -if [ ! -d "$AR_COMPS/esp-face" ]; then - git clone $FACE_REPO_URL "$AR_COMPS/esp-face" +echo "Updating TinyUSB..." +TINYUSB_REPO_URL="https://github.com/hathach/tinyusb.git" +TINYUSB_REPO_DIR="$AR_COMPS/arduino_tinyusb/tinyusb" +if [ ! -d "$TINYUSB_REPO_DIR" ]; then + git clone "$TINYUSB_REPO_URL" "$TINYUSB_REPO_DIR" else - git -C "$AR_COMPS/esp-face" fetch origin && \ - git -C "$AR_COMPS/esp-face" pull origin master + git -C "$TINYUSB_REPO_DIR" fetch && \ + git -C "$TINYUSB_REPO_DIR" pull --ff-only fi if [ $? -ne 0 ]; then exit 1; fi