diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 6f70f7e98..000000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -custom: https://platformio.org/donate diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md new file mode 100644 index 000000000..189906050 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -0,0 +1,41 @@ +--- +name: Problem Report +about: Create a Report to help us improve +--- + + + +### PROBLEM DESCRIPTION +_A clear and concise description of what the problem is._ + + +### TO REPRODUCE +_Steps to reproduce the behavior:_ + + +### EXPECTED BEHAVIOUR +_A clear and concise description of what you expected to happen._ + + +### SCREENSHOTS +_If applicable, add screenshots to help explain your problem._ + + +### ADDITIONAL CONTEXT +_Add any other context about the problem here._ + + +**(Please, remember to close the issue when the problem has been addressed)** diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000..828634eb6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: pioarduino Users Chat + url: https://discord.gg/Nutz9crnZr + about: Chat for feedback, questions and troubleshooting. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..8438f074e --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,9 @@ +## Description: + +**Related issue (if applicable):** fixes # + +## Checklist: + - [ ] The pull request is done against the latest develop branch + - [ ] Only relevant files were touched + - [ ] Only one feature/fix was added per PR, more changes are allowed when changing boards.json + - [ ] I accept the [CLA](https://github.com/pioarduino/platform-espressif32/blob/main/CONTRIBUTING.md#contributor-license-agreement-cla) diff --git a/.github/config.yml b/.github/config.yml new file mode 100644 index 000000000..3397d6b43 --- /dev/null +++ b/.github/config.yml @@ -0,0 +1,11 @@ +# Configuration for sentiment-bot - https://github.com/behaviorbot/sentiment-bot + +# *Required* toxicity threshold between 0 and .99 with the higher numbers being the most toxic +# Anything higher than this threshold will be marked as toxic and commented on +sentimentBotToxicityThreshold: .7 + +# *Required* Comment to reply with +sentimentBotReplyComment: > + Please be sure to review the code of conduct and be respectful of other users. + +# Note: the bot will only work if your repository has a Code of Conduct diff --git a/.github/stale.yml b/.github/stale.yml deleted file mode 100644 index 4da62e844..000000000 --- a/.github/stale.yml +++ /dev/null @@ -1,21 +0,0 @@ -# Number of days of inactivity before an issue becomes stale -daysUntilStale: 30 -# Number of days of inactivity before a stale issue is closed -daysUntilClose: 7 -# Issues with these labels will never be considered stale -exemptLabels: - - bug - - known issue - - feature - - enhancement - - board request - - package update -# Label to use when marking an issue as stale -staleLabel: stale -# Comment to post when marking an issue as stale. Set to `false` to disable -markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. Please provide more details or it will be closed if no - further activity occurs. Thank you for your contributions. -# Comment to post when closing a stale issue. Set to `false` to disable -closeComment: false diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 1e5c12efb..c77c2082d 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -1,21 +1,32 @@ -name: Examples +name: CI Examples -on: [push, pull_request] +on: + workflow_dispatch: # Manually start a workflow + push: + paths-ignore: + - '.github/**' # Ignore changes towards the .github directory + - '**.md' # Do no build if *.md files changes jobs: build: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-24.04, windows-2022, macos-15] example: - - "examples/arduino-ble5-advertising" - "examples/arduino-blink" + - "examples/arduino-rmt-blink" - "examples/arduino-usb-keyboard" - "examples/arduino-wifiscan" + - "examples/arduino-zigbee-light" + - "examples/arduino-zigbee-switch" + - "examples/tasmota" + - "examples/espidf-arduino-h2zero-BLE_scan" + #- "examples/espidf-arduino-matter-light" + - "examples/arduino-matter-light" - "examples/espidf-arduino-blink" - - "examples/espidf-arduino-wifiscan" - - "examples/espidf-ble-eddystone" + - "examples/espidf-arduino-littlefs" + - "examples/espidf-blink" - "examples/espidf-coap-server" - "examples/espidf-exceptions" - "examples/espidf-hello-world" @@ -23,22 +34,27 @@ jobs: - "examples/espidf-peripherals-uart" - "examples/espidf-peripherals-usb" - "examples/espidf-storage-sdcard" - - "examples/espidf-storage-spiffs" - - "examples/espidf-ulp-adc" - - "examples/espidf-ulp-pulse" + - "examples/espidf-ulp" + - "examples/espidf-ulp-riscv" + - "examples/espidf-ulp-lp" runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: "recursive" - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: "3.13" - name: Install dependencies run: | - pip install -U https://github.com/platformio/platformio/archive/develop.zip - pio pkg install --global --platform symlink://. - - name: Build examples + python -m pip install --upgrade pip + pip install wheel + pip install -U https://github.com/pioarduino/platformio-core/archive/refs/tags/v6.1.18.zip + pio pkg install --global --platform file://. + - name: git clone Tasmota and add to examples run: | - pio run -d ${{ matrix.example }} + git clone -b development --depth 1 https://github.com/arendst/Tasmota.git examples/tasmota + cp examples/tasmota_platformio_override.ini examples/tasmota/platformio_override.ini + - name: Build examples + run: pio run -d ${{ matrix.example }} diff --git a/.github/workflows/release_zips.yml b/.github/workflows/release_zips.yml new file mode 100644 index 000000000..a3d12f233 --- /dev/null +++ b/.github/workflows/release_zips.yml @@ -0,0 +1,17 @@ +name: Create zip file with recursive source clone for release + +on: + push: + tags: + - 54* + +jobs: + release_zips: + name: Create release zip file + runs-on: ubuntu-22.04 + steps: + - name: Create a recursive clone source zip + uses: pioarduino/github-actions/release_zips@release_idf + env: + RELEASE_PROJECT_NAME: platform-espressif32 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/stale-actions.yml b/.github/workflows/stale-actions.yml new file mode 100644 index 000000000..5d5f62748 --- /dev/null +++ b/.github/workflows/stale-actions.yml @@ -0,0 +1,23 @@ +name: "Mark or close stale issues and PRs" + +on: + schedule: + - cron: "30 * * * *" + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v9 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + days-before-stale: 25 + days-before-close: 5 + stale-issue-message: "This issue has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions." + stale-pr-message: "This PR has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions." + close-issue-message: "This issue was automatically closed because of being stale. Feel free to open a new one if you still experience this problem." + close-pr-message: "This PR was automatically closed because of being stale." + stale-pr-label: "stale" + stale-issue-label: "stale" + exempt-issue-labels: "bug,enhancement,pinned,security" + exempt-pr-labels: "bug,enhancement,pinned,security" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 446f8849c..000000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: "Unit Testing" - -on: [push, pull_request] - -jobs: - build: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - python-version: [3.9] - example: - - "examples/espidf-hello-world" - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - with: - submodules: "recursive" - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -U https://github.com/platformio/platformio/archive/develop.zip - pio pkg install --global --platform symlink://. - - name: Build test - run: | - pio test -d ${{ matrix.example }} --without-uploading --without-testing diff --git a/.gitignore b/.gitignore index 0d20b6487..0205d62f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +.DS_Store diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..03a725f57 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,111 @@ +# Contributing + +**Any contribution helps our team and makes pioarduino better for the entire community!** + +Everybody is welcome and invited to contribute to pioarduino Project by: + +* Testing newly released features and reporting issues. +* Providing Pull Requests (Features, Proof of Concepts or Fixes) +* Contributing missing documentation for features in our (not yet existing ;-)) documentation + +This document describes rules that are in effect for this repository, meant for handling issues by contributors in the issue tracker and PRs. + +## Opening New Issues + +**Issue tracker is NOT a general discussion forum!** +1. Opening an issue means that a problem exists in the code and should be addressed by the project contributors. +2. When opening an issue, provide as much as possible infos. The information is important! With insufficient info about the provided issue, the issue may be closed. +3. Questions of type "How do I..." or "Can you please help me with..." WILL NOT be handled here. Such questions should be directed to pioarduino Support Chat. All issues of this type will be closed with a simple reference to this contributing policy. +4. Issues about topics already handled in the documentation will be closed in a similar manner. +5. Issues for unmerged PRs will be closed. If there is an issue with a PR, the explanation should be added to the PR itself. +6. Issues with accompanied investigation that shows the root of the problem should be given priority. +7. Duplicate issues will be closed. + +## Triaging of Issues/PR's + +1. Any contributor to the project can participate in the triaging process, if he/she/them chooses to do so. +2. An issue that needs to be closed, either due to not complying with this policy, or for other reasons, should be closed by a contributor. +3. Issues that are accepted should be marked with appropriate labels. +4. Issues that could impact functionality for many users should be considered severe. +5. Issues with feature requests should be discussed for viability/desirability. +6. Feature requests or changes that are meant to address a very specific/limited use case, may be denied, or may be required to be redesigned, generalized, or simplified. +7. Feature requests that are not accompanied by a PR: + * could be closed immediately (denied). + * could be closed after some predetermined period of time (left as candidate for somebody to pick up). +8. In some cases, feedback may be requested from the issue reporter, either as additional info for clarification, additional testing, or other. If no feedback is provided, the issue may be closed by a contributor or after 30 days by the STALE bot. + +## Pull requests + +A Pull Request (PR) is the process where code modifications are managed in GitHub. + +The process is straight-forward. + + - Read [How to get faster PR reviews](https://github.com/kubernetes/community/blob/master/contributors/guide/pull-requests.md#best-practices-for-faster-reviews) by Kubernetes (but skip step 0) + - Fork the pioarduino platform-espressif32 Repository [git repository](https://github.com/pioarduino/platform-espressif32). + - Write/Change the code in your Fork for a new feature, bug fix, optimization, etc. + - Ensure tests work. + - Create a Pull Request against the [**develop**](https://github.com/pioarduino/platform-espressif32/tree/develop) branch of pioarduino. + +1. All pull requests must be done against the develop branch. +2. Only relevant files should be touched (Also beware if your editor has auto-formatting feature enabled). +3. Only one feature/fix should be added per PR. A PR for mass changes in boards manifest is allowed. +4. PRs that don't compile (fail in CI Tests) or cause coding errors will not be merged. Please fix the issue. Same goes for PRs that are raised against older commit in develop - you might need to rebase and resolve conflicts. +5. All pull requests should undergo peer review by at least one contributor other than the creator, excepts for the owner. +6. All pull requests should consider updates to the documentation. +7. Pull requests that address an outstanding issue, particularly an issue deemed to be severe, should be given priority. +8. If a PR is accepted, then it should undergo review and updated based on the feedback provided, then merged. +9. By submitting a PR, it is needed to use the provided PR template and check all boxes, performing the required tasks and accepting the CLA. +10. Pull requests that don't meet the above will be denied and closed. + +-------------------------------------- + +## Contributor License Agreement (CLA) + +``` +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I + have the right to submit it under the GPL-3.0 license; or + +(b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the GPL-3.0 license; or + +(c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +(d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it) is maintained indefinitely + and may be redistributed consistent with this project or the open + source license(s) involved. +``` + +This Contributor License Agreement (CLA) was adopted on April 1st, 2019. + +The text of this license is available under the [Creative Commons Attribution-ShareAlike 3.0 Unported License](http://creativecommons.org/licenses/by-sa/3.0/). It is based on the Linux [Developer Certificate Of Origin](http://elinux.org/Developer_Certificate_Of_Origin), but is modified to explicitly use the GPL-3.0 license and not mention sign-off (due to GitHub.com keeps an historial, with your user name, of PRs' commits and all editions on PR's comments). + +To accept the CLA it is required to put a x between [ ] on `[ ] I accept the CLA` in the PR template when submitting it. The [ ] is an opt-in box, so you have to manually accept it. + +**Why a CLA ?** + +_"A Contributor License Agreement (CLA) is strongly recommended when accepting third party contributions to an open development project, such as an open source software project. In order to redistribute contributions, it is necessary to ensure that the project has the necessary rights to do so. A Contributor License Agreement is a lightweight agreement, signed by the copyright holder, that grants the necessary rights for the contribution to be redistributed as part of the project."_ [OSS Watch](http://oss-watch.ac.uk/resources/cla) + +A CLA is a legal document in which you state _you are entitled to contribute the code/documentation/translation to the project_ you’re contributing to and that _you are willing to have it used in distributions and derivative works_. This means that should there be any kind of legal issue in the future as to the origins and ownership of any particular piece of code, then that project has the necessary forms on file from the contributor(s) saying they were permitted to make this contribution. + +CLA is a safety because it also ensures that once you have provided a contribution, you cannot try to withdraw permission for its use at a later date. People can therefore use that software, confident that they will not be asked to stop using pieces of the code at a later date. + +A __license__ grants "outbound" rights to the user of project. + +A __CLA__ enables a contributor to grant "inbound" rights to a project. + + + + + + + + diff --git a/README.md b/README.md index 4cc9c51a9..4de6a2a77 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,59 @@ -# Espressif 32: development platform for [PlatformIO](https://platformio.org) +# pioarduino (p)eople (i)nitiated (o)ptimized (arduino) -[![Build Status](https://github.com/platformio/platform-espressif32/workflows/Examples/badge.svg)](https://github.com/platformio/platform-espressif32/actions) +[![Build Status](https://github.com/pioarduino/platform-espressif32/actions/workflows/examples.yml/badge.svg)](https://github.com/pioarduino/platform-espressif32/actions) +[![Discord](https://img.shields.io/discord/1263397951829708871.svg?logo=discord&logoColor=white&color=5865F2&label=Discord)](https://discord.gg/Nutz9crnZr) +[![GitHub Releases](https://img.shields.io/github/downloads/pioarduino/platform-espressif32/total?label=downloads)](https://github.com/pioarduino/platform-espressif32/releases/latest) ESP32 is a series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and Bluetooth. ESP32 integrates an antenna switch, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules. -* [Home](https://registry.platformio.org/platforms/platformio/espressif32) (home page in the PlatformIO Registry) -* [Documentation](https://docs.platformio.org/page/platforms/espressif32.html) (advanced usage, packages, boards, frameworks, etc.) +* Issues with boards (wrong / missing). All issues caused from boards will not be fixed from the maintainer(s). A PR needs to be provided against branch `develop` to solve. +* No support for the Arduino Nora Nano board, issues needs to be solved by the community +## IDE Preparation -# Usage - -1. [Install PlatformIO](https://platformio.org) -2. Create PlatformIO project and configure a platform option in [platformio.ini](https://docs.platformio.org/page/projectconf.html) file: +- [Download and install Microsoft Visual Studio Code](https://code.visualstudio.com/). pioarduino IDE is on top of it. +- Open the extension manager. +- Search for the `pioarduino ide` extension. +- Install pioarduino IDE extension. -## Stable version +# Usage +1. Setup new VSCode pioarduino project. +1. Configure a platform option in platformio.ini file: -See `platform` [documentation](https://docs.platformio.org/en/latest/projectconf/sections/env/options/platform/platform.html#projectconf-env-platform) for details. +### Stable Arduino +currently espressif Arduino 3.2.0 and IDF 5.4.1 ```ini [env:stable] -; recommended to pin to a version, see https://github.com/platformio/platform-espressif32/releases -; platform = espressif32 @ ^6.0.1 -platform = espressif32 +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip board = ... ... ``` -## Development version +### Development Arduino +espressif Arduino repo branch master and latest compiled Arduino libs ```ini [env:development] -platform = https://github.com/platformio/platform-espressif32.git +platform = https://github.com/pioarduino/platform-espressif32.git#develop board = ... ... ``` -# Configuration +### ESP32-solo1 and ESP32-C2 Arduino support (with pioarduino only feature: *Hybrid compile*) +Example configuration: + +```ini +[env:esp32solo1] +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +framework = arduino +board = esp32-solo1 +monitor_speed = 115200 + +[env:esp32-c2-devkitm-1] +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +framework = arduino +board = esp32-c2-devkitm-1 +monitor_speed = 115200 +``` -Please navigate to [documentation](https://docs.platformio.org/page/platforms/espressif32.html). +Looking for sponsor button? There is none. If you want to donate, please spend a litte to a charity organization. diff --git a/boards/4d_systems_esp32s3_gen4_r8n16.json b/boards/4d_systems_esp32s3_gen4_r8n16.json index 4418be557..753980a74 100644 --- a/boards/4d_systems_esp32s3_gen4_r8n16.json +++ b/boards/4d_systems_esp32s3_gen4_r8n16.json @@ -1,9 +1,8 @@ { "build": { "arduino": { - "ldscript": "esp32s3_out.ld", "memory_type": "qio_opi", - "partitions": "default_16MB.csv" + "partitions": "esp_sr_16.csv" }, "core": "esp32", "extra_flags": [ diff --git a/boards/adafruit_feather_esp32c6.json b/boards/adafruit_feather_esp32c6.json new file mode 100644 index 000000000..2eaf8f768 --- /dev/null +++ b/boards/adafruit_feather_esp32c6.json @@ -0,0 +1,38 @@ +{ + "build": { + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ADAFRUIT_FEATHER_ESP32C6", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32c6", + "variant": "adafruit_feather_esp32c6" + }, + "connectivity": [ + "wifi", + "bluetooth", + "zigbee", + "thread" + ], + "debug": { + "openocd_target": "esp32c6.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Adafruit Feather ESP32-C6", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.adafruit.com/product/5933", + "vendor": "Adafruit" +} diff --git a/boards/adafruit_feather_esp32s3_tft.json b/boards/adafruit_feather_esp32s3_tft.json index 0b1d9433f..a37b7e42d 100644 --- a/boards/adafruit_feather_esp32s3_tft.json +++ b/boards/adafruit_feather_esp32s3_tft.json @@ -1,15 +1,16 @@ { "build": { "arduino": { - "ldscript": "esp32s3_out.ld", - "partitions": "partitions-4MB-tinyuf2.csv" + "partitions": "partitions-4MB-tinyuf2.csv", + "memory_type": "qio_qspi" }, "core": "esp32", "extra_flags": [ "-DARDUINO_ADAFRUIT_FEATHER_ESP32S3_TFT", "-DARDUINO_USB_CDC_ON_BOOT=1", "-DARDUINO_RUNNING_CORE=1", - "-DARDUINO_EVENT_RUNNING_CORE=1" + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" ], "f_cpu": "240000000L", "f_flash": "80000000L", diff --git a/boards/adafruit_matrixportal_esp32s3.json b/boards/adafruit_matrixportal_esp32s3.json index df10505ad..dfdb07c3f 100644 --- a/boards/adafruit_matrixportal_esp32s3.json +++ b/boards/adafruit_matrixportal_esp32s3.json @@ -1,8 +1,8 @@ { "build": { "arduino":{ - "ldscript": "esp32s3_out.ld", - "partitions": "partitions-8MB-tinyuf2.csv" + "partitions": "partitions-8MB-tinyuf2.csv", + "memory_type": "qio_qspi" }, "core": "esp32", "extra_flags": [ diff --git a/boards/adafruit_qualia_s3_rgb666.json b/boards/adafruit_qualia_s3_rgb666.json index e1607a913..c122ae785 100644 --- a/boards/adafruit_qualia_s3_rgb666.json +++ b/boards/adafruit_qualia_s3_rgb666.json @@ -1,9 +1,8 @@ { "build": { "arduino":{ - "ldscript": "esp32s3_out.ld", "memory_type": "qio_opi", - "partitions": "partitions-16MB-tinyuf2.csv" + "partitions": "tinyuf2-partitions-16MB.csv" }, "core": "esp32", "extra_flags": [ diff --git a/boards/arduino_nano_esp32.json b/boards/arduino_nano_esp32.json index e1bf757d5..4d7267937 100644 --- a/boards/arduino_nano_esp32.json +++ b/boards/arduino_nano_esp32.json @@ -1,14 +1,13 @@ { "build": { "arduino":{ - "ldscript": "esp32s3_out.ld", "partitions": "app3M_fat9M_fact512k_16MB.csv", "memory_type": "qio_opi" }, "core": "esp32", "extra_flags": [ "-DARDUINO_NANO_ESP32", - "-DBOARD_HAS_PIN_REMAP", + "-DBOARD_USES_HW_GPIO_NUMBERS", "-DBOARD_HAS_PSRAM", "-DUSB_MANUFACTURER=\\\"Arduino\\\"", "-DUSB_PRODUCT=\\\"NanoESP32\\\"", @@ -42,6 +41,14 @@ ], "name": "Arduino Nano ESP32", "upload": { + "arduino": { + "flash_extra_images": [ + [ + "0xf70000", + "variants/arduino_nano_nora/extra/nora_recovery/nora_recovery.ino.bin" + ] + ] + }, "flash_size": "16MB", "maximum_ram_size": 327680, "maximum_size": 16777216, diff --git a/boards/bpi-centi-s3.json b/boards/bpi-centi-s3.json new file mode 100644 index 000000000..01c9509e2 --- /dev/null +++ b/boards/bpi-centi-s3.json @@ -0,0 +1,52 @@ +{ + "build": { + "arduino": { + "partitions": "default_8MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM", + "-DARDUINO_BPI_CENTI_S3", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x80DF" + ] + ], + "mcu": "esp32s3", + "variant": "bpi_leaf_s3" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "platforms" : [ + "espressif32" + ], + "name": "BPI-Centi-S3", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://wiki.banana-pi.org/BPI-Leaf-S3", + "vendor": "BPI Tech" +} diff --git a/boards/dfrobot_romeo_esp32s3.json b/boards/dfrobot_romeo_esp32s3.json index 55e69db5c..f0810d86c 100644 --- a/boards/dfrobot_romeo_esp32s3.json +++ b/boards/dfrobot_romeo_esp32s3.json @@ -1,7 +1,6 @@ { "build": { "arduino": { - "ldscript": "esp32s3_out.ld", "partitions": "app3M_fat9M_16MB.csv", "memory_type": "qio_opi" }, @@ -10,7 +9,8 @@ "-DARDUINO_DFROBOT_ROMEO_ESP32S3", "-DARDUINO_USB_MODE=1", "-DARDUINO_RUNNING_CORE=1", - "-DARDUINO_EVENT_RUNNING_CORE=1" + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" ], "f_cpu": "240000000L", "f_flash": "80000000L", diff --git a/boards/esp32-c2-devkitm-1.json b/boards/esp32-c2-devkitm-1.json new file mode 100644 index 000000000..dcf2ca442 --- /dev/null +++ b/boards/esp32-c2-devkitm-1.json @@ -0,0 +1,35 @@ +{ + "build": { + "core": "esp32", + "f_cpu": "120000000L", + "f_flash": "60000000L", + "flash_mode": "qio", + "mcu": "esp32c2", + "variant": "esp32c2" + }, + "connectivity": [ + "wifi" + ], + "debug": { + "openocd_target": "esp32c2.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif ESP32-C2-DevKitM-1", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 278528, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "espidf": { + "custom_sdkconfig": [ + "CONFIG_IDF_TARGET=\"esp32c2\"" + ] + }, + "url": "https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp8684/esp8684-devkitm-1/user_guide.html", + "vendor": "Espressif" +} diff --git a/boards/esp32-c6-devkitc-1.json b/boards/esp32-c6-devkitc-1.json index 18a76dcc7..a5732a1c0 100644 --- a/boards/esp32-c6-devkitc-1.json +++ b/boards/esp32-c6-devkitc-1.json @@ -4,12 +4,18 @@ "f_cpu": "160000000L", "f_flash": "80000000L", "flash_mode": "qio", - "mcu": "esp32c6" + "mcu": "esp32c6", + "variant": "esp32c6" }, "connectivity": [ + "bluetooth", "wifi" ], + "debug": { + "openocd_target": "esp32c6.cfg" + }, "frameworks": [ + "arduino", "espidf" ], "name": "Espressif ESP32-C6-DevKitC-1", diff --git a/boards/esp32-c6-devkitm-1.json b/boards/esp32-c6-devkitm-1.json index c30687fa9..069d0d791 100644 --- a/boards/esp32-c6-devkitm-1.json +++ b/boards/esp32-c6-devkitm-1.json @@ -14,6 +14,7 @@ "openocd_target": "esp32c6.cfg" }, "frameworks": [ + "arduino", "espidf" ], "name": "Espressif ESP32-C6-DevKitM-1", diff --git a/boards/esp32-h2-devkitm-1.json b/boards/esp32-h2-devkitm-1.json new file mode 100644 index 000000000..519f61b22 --- /dev/null +++ b/boards/esp32-h2-devkitm-1.json @@ -0,0 +1,38 @@ +{ + "build": { + "core": "esp32", + "f_cpu": "96000000L", + "f_flash": "64000000L", + "f_image": "48000000L", + "flash_mode": "qio", + "mcu": "esp32h2", + "variant": "esp32h2", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ] + }, + "connectivity": [ + "bluetooth", + "zigbee" + ], + "debug": { + "openocd_target": "esp32h2.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif ESP32-H2-DevKit", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://docs.espressif.com/projects/espressif-esp-dev-kits/en/latest/esp32h2/esp32-h2-devkitm-1/index.html", + "vendor": "Espressif" +} diff --git a/boards/esp32-p4-evboard.json b/boards/esp32-p4-evboard.json new file mode 100644 index 000000000..1ea928367 --- /dev/null +++ b/boards/esp32-p4-evboard.json @@ -0,0 +1,37 @@ +{ + "build": { + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "360000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32p4", + "variant": "esp32p4" + }, + "arduino": { + "partitions": "default_16MB.csv" + }, + "connectivity": [ + "bluetooth", + "openthread" + ], + "debug": { + "openocd_target": "esp32p4.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif ESP32-P4 Function EV Board", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 512000, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 1500000 + }, + "url": "https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32p4/esp32-p4-function-ev-board/index.html", + "vendor": "Espressif" +} diff --git a/boards/esp32-p4.json b/boards/esp32-p4.json new file mode 100644 index 000000000..0a05148b0 --- /dev/null +++ b/boards/esp32-p4.json @@ -0,0 +1,34 @@ +{ + "build": { + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "360000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32p4", + "variant": "esp32p4" + }, + "connectivity": [ + "bluetooth", + "openthread" + ], + "debug": { + "openocd_target": "esp32p4.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif ESP32-P4 generic", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://docs.espressif.com", + "vendor": "Espressif" +} diff --git a/boards/esp32-s3-devkitc-1-n32r8v.json b/boards/esp32-s3-devkitc-1-n32r8v.json new file mode 100644 index 000000000..39d725adf --- /dev/null +++ b/boards/esp32-s3-devkitc-1-n32r8v.json @@ -0,0 +1,52 @@ +{ + "build": { + "arduino":{ + "partitions": "default_32MB.csv", + "memory_type": "opi_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "opi", + "psram_type": "opi", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif ESP32-S3-DevKitC-1-N32R8V (32 MB Flash Octal, 8 MB PSRAM Octal)", + "upload": { + "flash_size": "32MB", + "maximum_ram_size": 327680, + "maximum_size": 33554432, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" +} diff --git a/boards/esp32-s3-devkitc1-n16r16.json b/boards/esp32-s3-devkitc1-n16r16.json new file mode 100644 index 000000000..99c71136d --- /dev/null +++ b/boards/esp32-s3-devkitc1-n16r16.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "partitions": "default_16MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "opi", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "platforms": [ + "espressif32" + ], + "name": "Espressif ESP32-S3-DevKitC-1-N16R8V (16 MB Flash Quad, 16 MB PSRAM Octal)", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" +} \ No newline at end of file diff --git a/boards/esp32-s3-devkitc1-n16r2.json b/boards/esp32-s3-devkitc1-n16r2.json new file mode 100644 index 000000000..08968e5c8 --- /dev/null +++ b/boards/esp32-s3-devkitc1-n16r2.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "partitions": "default_16MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "platforms": [ + "espressif32" + ], + "name": "Espressif ESP32-S3-DevKitC-1-N8R8 (16 MB Flash Quad, 2 MB PSRAM Quad)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" +} \ No newline at end of file diff --git a/boards/esp32-s3-devkitc1-n16r8.json b/boards/esp32-s3-devkitc1-n16r8.json new file mode 100644 index 000000000..1c7e5d635 --- /dev/null +++ b/boards/esp32-s3-devkitc1-n16r8.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "partitions": "default_16MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "opi", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "platforms": [ + "espressif32" + ], + "name": "Espressif ESP32-S3-DevKitC-1-N16R8V (16 MB Flash Quad, 8 MB PSRAM Octal)", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" +} \ No newline at end of file diff --git a/boards/esp32-s3-devkitc1-n4r2.json b/boards/esp32-s3-devkitc1-n4r2.json new file mode 100644 index 000000000..1ed4a3321 --- /dev/null +++ b/boards/esp32-s3-devkitc1-n4r2.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "partitions": "default_4MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "platforms": [ + "espressif32" + ], + "name": "Espressif ESP32-S3-DevKitC-1-N8R8 (4 MB Flash Quad, 2 MB PSRAM Quad)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" +} \ No newline at end of file diff --git a/boards/esp32-s3-devkitc1-n4r8.json b/boards/esp32-s3-devkitc1-n4r8.json new file mode 100644 index 000000000..338fee270 --- /dev/null +++ b/boards/esp32-s3-devkitc1-n4r8.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "partitions": "default_4MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "opi", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "platforms": [ + "espressif32" + ], + "name": "Espressif ESP32-S3-DevKitC-1-N8R8 (4 MB Flash Quad, 8 MB PSRAM Octal)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" +} \ No newline at end of file diff --git a/boards/esp32-s3-devkitc1-n8r2.json b/boards/esp32-s3-devkitc1-n8r2.json new file mode 100644 index 000000000..46e2a89b5 --- /dev/null +++ b/boards/esp32-s3-devkitc1-n8r2.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "partitions": "default_8MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "platforms": [ + "espressif32" + ], + "name": "Espressif ESP32-S3-DevKitC-1-N8R8 (8 MB Flash Quad, 2 MB PSRAM quad)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" +} \ No newline at end of file diff --git a/boards/esp32-s3-devkitc1-n8r8.json b/boards/esp32-s3-devkitc1-n8r8.json new file mode 100644 index 000000000..6284c7c63 --- /dev/null +++ b/boards/esp32-s3-devkitc1-n8r8.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "partitions": "default_8MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "opi", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "platforms": [ + "espressif32" + ], + "name": "Espressif ESP32-S3-DevKitC-1-N8R8 (8 MB Flash Quad, 8 MB PSRAM Octal)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" +} \ No newline at end of file diff --git a/boards/esp32-s3-fh4r2.json b/boards/esp32-s3-fh4r2.json new file mode 100644 index 000000000..1333a31d6 --- /dev/null +++ b/boards/esp32-s3-fh4r2.json @@ -0,0 +1,56 @@ +{ + "build": { + "arduino":{ + "partitions": "default.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "platforms" : [ + "espressif32" + ], + "name": "Espressif ESP32-S3-FH4R2 (4 MB QD, 2MB PSRAM)", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" + } \ No newline at end of file diff --git a/boards/esp32-solo1.json b/boards/esp32-solo1.json new file mode 100644 index 000000000..906772ba4 --- /dev/null +++ b/boards/esp32-solo1.json @@ -0,0 +1,39 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DARDUINO_ESP32_DEV -DARDUINO_USB_CDC_ON_BOOT=0 -DCORE32SOLO1", + "f_cpu": "160000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_target": "esp32-solo-1.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif Generic ESP32-solo1 4M Flash", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "espidf": { + "custom_sdkconfig": [ + "CONFIG_FREERTOS_UNICORE=y" + ] + }, + "url": "https://en.wikipedia.org/wiki/ESP32", + "vendor": "Espressif" +} diff --git a/boards/esp32s3_120_16_8-qio_opi.json b/boards/esp32s3_120_16_8-qio_opi.json new file mode 100644 index 000000000..e4d20f47b --- /dev/null +++ b/boards/esp32s3_120_16_8-qio_opi.json @@ -0,0 +1,50 @@ +{ + "build": { + "arduino": { + "memory_type": "qio_opi", + "partitions": "default_16MB.csv" + }, + "core": "esp32", + "f_cpu": "240000000L", + "f_flash": "80000000L", + "f_boot": "120000000L", + "boot": "qio", + "flash_mode": "qio", + "extra_flags": [ + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "ESP32-S3 16MB QIO, 8MB OPI PSRAM", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.espressif.com/sites/default/files/documentation/esp32-s3-wroom-1_wroom-1u_datasheet_en.pdf", + "vendor": "espressif" +} diff --git a/boards/feenove-esp32-s3-n8r8.json b/boards/feenove-esp32-s3-n8r8.json new file mode 100644 index 000000000..0c508d5a7 --- /dev/null +++ b/boards/feenove-esp32-s3-n8r8.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "partitions": "default_8MB.csv", + "memory_type": "dio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "dio", + "psram_type": "opi", + "hwids": [ + [ + "0X303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "platforms" : [ + "espressif32" + ], + "name": "Freenove ESP32-S3 WROOM N8R8 (8MB Flash / 8MB PSRAM)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://github.com/Freenove/Freenove_ESP32_S3_WROOM_Board", + "vendor": "Freenove" +} diff --git a/boards/freenove_esp32_s3_wroom.json b/boards/freenove_esp32_s3_wroom.json new file mode 100644 index 000000000..ea439ab58 --- /dev/null +++ b/boards/freenove_esp32_s3_wroom.json @@ -0,0 +1,54 @@ +{ + "build": { + "arduino": { + "partitions": "default_8MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_MODE=0", + "-DARDUINO_USB_CDC_ON_BOOT=0" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "opi", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Freenove ESP32-S3 WROOM N8R8 (8MB Flash / 8MB PSRAM)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://github.com/Freenove/Freenove_ESP32_S3_WROOM_Board", + "vendor": "Freenove" +} diff --git a/boards/freenove_esp32_wrover.json b/boards/freenove_esp32_wrover.json new file mode 100644 index 000000000..7f1aeba02 --- /dev/null +++ b/boards/freenove_esp32_wrover.json @@ -0,0 +1,39 @@ +{ + "build": { + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32_DEV", + "-DBOARD_HAS_PSRAM", + "-mfix-esp32-psram-cache-issue", + "-mfix-esp32-psram-cache-strategy=memw" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wrover-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Freenove ESP32-Wrover", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://store.freenove.com/products/fnk0060", + "vendor": "Freenove" +} diff --git a/boards/heltec_wifi_kit_32_V3.json b/boards/heltec_wifi_kit_32_V3.json index d10631917..ba8370001 100644 --- a/boards/heltec_wifi_kit_32_V3.json +++ b/boards/heltec_wifi_kit_32_V3.json @@ -1,7 +1,6 @@ { "build": { "arduino": { - "ldscript": "esp32s3_out.ld", "partitions": "default_8MB.csv" }, "core": "esp32", @@ -21,7 +20,7 @@ ] ], "mcu": "esp32s3", - "variant": "heltec_wifi_kit_32_v3" + "variant": "heltec_wifi_kit_32_V3" }, "connectivity": [ "wifi", diff --git a/boards/heltec_wireless_stick_lite.json b/boards/heltec_wireless_stick_lite.json index 6ffac9acf..c7ec8bccc 100644 --- a/boards/heltec_wireless_stick_lite.json +++ b/boards/heltec_wireless_stick_lite.json @@ -1,12 +1,9 @@ { "build": { - "arduino":{ - "ldscript": "esp32_out.ld" - }, "core": "esp32", "extra_flags": "-DARDUINO_HELTEC_WIRELESS_STICK_LITE", "f_cpu": "240000000L", - "f_flash": "40000000L", + "f_flash": "80000000L", "flash_mode": "dio", "mcu": "esp32", "variant": "heltec_wireless_stick_lite" diff --git a/boards/huidu_hd_wf2.json b/boards/huidu_hd_wf2.json new file mode 100644 index 000000000..eecb9d64d --- /dev/null +++ b/boards/huidu_hd_wf2.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "partitions": "default_8MB.csv" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_HUIDU_HD_WF2", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "dio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "huidu_hd_wf2" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Huidu HD-WF2", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.hdwell.com/Product/index46.html", + "vendor": "Huidu Tech", + "information_urls": [ + "https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA/discussions/667", + "https://github.com/vortigont/FireLamp_JeeUI/wiki/Huidu-HD%E2%80%90WF2" + ] +} diff --git a/boards/huidu_hd_wf4.json b/boards/huidu_hd_wf4.json new file mode 100644 index 000000000..b0acdffc2 --- /dev/null +++ b/boards/huidu_hd_wf4.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "partitions": "default_8MB.csv" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_HUIDU_HD_WF4", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "dio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "huidu_hd_wf4" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Huidu HD-WF4", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.hdwell.com/Product/index46.html", + "vendor": "Huidu Tech", + "information_urls": [ + "https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA/discussions/667", + "https://github.com/vortigont/FireLamp_JeeUI/wiki/Huidu-HD%E2%80%90WF4" + ] +} diff --git a/boards/jczn_2432s028r.json b/boards/jczn_2432s028r.json new file mode 100644 index 000000000..b5c10fad3 --- /dev/null +++ b/boards/jczn_2432s028r.json @@ -0,0 +1,32 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DARDUINO_JCZN_2432S028R", + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "qio", + "mcu": "esp32", + "variant": "jczn_2432s028r" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "ESP32-2432S028R CYD", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "http://pan.jczn1688.com/directlink/1/ESP32%20module/2.8inch_ESP32-2432S028R.rar", + "vendor": "JCZN" +} diff --git a/boards/lilygo-t3-s3.json b/boards/lilygo-t3-s3.json new file mode 100644 index 000000000..6a00b6fba --- /dev/null +++ b/boards/lilygo-t3-s3.json @@ -0,0 +1,42 @@ +{ + "build": { + "arduino": { + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_LILYGO_T3_S3_V1_X", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DARDUINO_USB_MODE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "LilyGo T3-S3", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://lilygo.cc/products/t3s3-v1-0", + "vendor": "LilyGo" +} diff --git a/boards/lolin_s3_mini.json b/boards/lolin_s3_mini.json index 7f55f0bde..c68309a7f 100644 --- a/boards/lolin_s3_mini.json +++ b/boards/lolin_s3_mini.json @@ -1,18 +1,18 @@ { "build": { "arduino": { - "ldscript": "esp32s3_out.ld", "memory_type": "qio_qspi" }, "core": "esp32", "extra_flags": [ "-DBOARD_HAS_PSRAM", "-DARDUINO_LOLIN_S3_MINI", - "-DARDUINO_USB_MODE=1" + "-DARDUINO_USB_CDC_ON_BOOT=1" ], "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "qio", + "psram_type" : "qio", "hwids": [ [ "0x303A", diff --git a/boards/lolin_s3_mini_pro.json b/boards/lolin_s3_mini_pro.json new file mode 100644 index 000000000..3afcb49fb --- /dev/null +++ b/boards/lolin_s3_mini_pro.json @@ -0,0 +1,47 @@ +{ + "build": { + "arduino": { + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM", + "-DARDUINO_LOLIN_S3_MINI_PRO", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type" : "qio", + "hwids": [ + [ + "0x303A", + "0x8167" + ] + ], + "mcu": "esp32s3", + "variant": "lolin_s3_mini_pro" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "WEMOS LOLIN S3 Mini Pro", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.wemos.cc/en/latest/s3/index.html", + "vendor": "WEMOS" +} + \ No newline at end of file diff --git a/boards/m5stack_paper.json b/boards/m5stack_paper.json new file mode 100644 index 000000000..ce33c0995 --- /dev/null +++ b/boards/m5stack_paper.json @@ -0,0 +1,34 @@ +{ + "build": { + "arduino":{ + "partitions": "default_16MB.csv" + }, + "core": "esp32", + "extra_flags": "-DARDUINO_M5STACK_Paper -DBOARD_HAS_PSRAM", + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32", + "variant": "m5stack_paper" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "frameworks": [ + "arduino", + "espidf" + ], + "name": "M5Stack Paper", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 4521984, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 460800 + }, + "url": "http://www.m5stack.com", + "vendor": "M5Stack" +} diff --git a/boards/nologo_esp32c3_super_mini.json b/boards/nologo_esp32c3_super_mini.json new file mode 100644 index 000000000..e8e302c43 --- /dev/null +++ b/boards/nologo_esp32c3_super_mini.json @@ -0,0 +1,32 @@ +{ + "build": { + "core": "esp32", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "extra_flags": "-DARDUINO_ESP32C3_DEV -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1", + "mcu": "esp32c3", + "variant": "nologo_esp32c3_super_mini" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "openocd_target": "esp32c3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Nologo ESP32C3 SuperMini", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.nologo.tech/product/esp32/esp32c3/esp32c3supermini/esp32C3SuperMini.html", + "vendor": "Nologo" +} \ No newline at end of file diff --git a/boards/rymcu-esp32-s3-devkitc-1.json b/boards/rymcu-esp32-s3-devkitc-1.json new file mode 100644 index 000000000..848537a67 --- /dev/null +++ b/boards/rymcu-esp32-s3-devkitc-1.json @@ -0,0 +1,51 @@ +{ + "build": { + "arduino":{ + "partitions": "default_8MB.csv" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "RYMCU ESP32-S3-DevKitC-1-N8R2 (8 MB QD, 2 MB PSRAM)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://rymcu.com/products", + "vendor": "RYMCU" +} diff --git a/boards/seeed_xiao_esp32c6.json b/boards/seeed_xiao_esp32c6.json new file mode 100644 index 000000000..224f0e215 --- /dev/null +++ b/boards/seeed_xiao_esp32c6.json @@ -0,0 +1,48 @@ +{ + "build": { + "core": "esp32", + "extra_flags": [ + "-DARDUINO_XIAO_ESP32C6", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x2886", + "0x0046" + ], + [ + "0x303a", + "0x1001" + ] + ], + "mcu": "esp32c6", + "variant": "XIAO_ESP32C6" + }, + "connectivity": [ + "wifi", + "bluetooth", + "zigbee", + "thread" + ], + "debug": { + "openocd_target": "esp32c6.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Seeed Studio XIAO ESP32C6", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://wiki.seeedstudio.com/XIAO_ESP32C6_Getting_Started/", + "vendor": "Seeed Studio" +} diff --git a/boards/sparkfun_esp32c6_thing_plus.json b/boards/sparkfun_esp32c6_thing_plus.json new file mode 100644 index 000000000..f752f6638 --- /dev/null +++ b/boards/sparkfun_esp32c6_thing_plus.json @@ -0,0 +1,38 @@ +{ + "build": { + "core": "esp32", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32c6", + "variant": "sparkfun_esp32c6_thing_plus", + "extra_flags": [ + "-DARDUINO_ESP32C6_THING_PLUS", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1" + ] + }, + "connectivity": [ + "wifi", + "bluetooth", + "zigbee", + "thread" + ], + "debug": { + "openocd_target": "esp32c6.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Sparkfun ESP32-C6 Thing Plus", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.sparkfun.com/products/22924", + "vendor": "Sparkfun" +} diff --git a/boards/sparkfun_esp32s3_thing_plus.json b/boards/sparkfun_esp32s3_thing_plus.json new file mode 100644 index 000000000..5dcaefb95 --- /dev/null +++ b/boards/sparkfun_esp32s3_thing_plus.json @@ -0,0 +1,52 @@ +{ + "build": { + "arduino": { + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM", + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "sparkfun_esp32s3_thing_plus" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "SPARKFUN_ESP32S3_THING_PLUS", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.sparkfun.com/products/24408", + "vendor": "SparkFun" +} diff --git a/boards/sparkfun_pro_micro_esp32c3.json b/boards/sparkfun_pro_micro_esp32c3.json new file mode 100644 index 000000000..e31d53fc7 --- /dev/null +++ b/boards/sparkfun_pro_micro_esp32c3.json @@ -0,0 +1,36 @@ +{ + "build": { + "core": "esp32", + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "extra_flags": [ + "-DSPARKFUN_PRO_MICRO_ESP32C3", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "mcu": "esp32c3", + "variant": "sparkfun_pro_micro_esp32c3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "openocd_target": "esp32c3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "SparkFun Pro Micro ESP32-C3", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.sparkfun.com/sparkfun-pro-micro-esp32-c3.html", + "vendor": "Sparkfun" +} \ No newline at end of file diff --git a/boards/sparkfun_qwiic_pocket_esp32c6.json b/boards/sparkfun_qwiic_pocket_esp32c6.json new file mode 100644 index 000000000..c627d2449 --- /dev/null +++ b/boards/sparkfun_qwiic_pocket_esp32c6.json @@ -0,0 +1,38 @@ +{ + "build": { + "core": "esp32", + "extra_flags": [ + "-DARDUINO_SFE_QWIIC_POCKET_ESP32C6", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32c6", + "variant": "sparkfun_esp32c6_qwiic_pocket" + }, + "connectivity": [ + "wifi", + "bluetooth", + "zigbee", + "thread" + ], + "debug": { + "openocd_target": "esp32c6.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "SparkFun ESP32-C6 Qwiic Pocket", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.sparkfun.com/products/22925", + "vendor": "SparkFun" +} diff --git a/boards/um_bling.json b/boards/um_bling.json new file mode 100644 index 000000000..aeeabadfe --- /dev/null +++ b/boards/um_bling.json @@ -0,0 +1,51 @@ +{ + "build": { + "arduino":{ + "partitions": "default_8MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_BLING", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0X303A", + "0x817F" + ] + ], + "mcu": "esp32s3", + "variant": "um_bling" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Unexpected Maker BLING!", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://unexpectedmaker.com/shop/bling", + "vendor": "Unexpected Maker" +} diff --git a/boards/um_feathers3.json b/boards/um_feathers3.json index 1a851fab5..9c39ea916 100644 --- a/boards/um_feathers3.json +++ b/boards/um_feathers3.json @@ -1,7 +1,6 @@ { "build": { "arduino":{ - "ldscript": "esp32s3_out.ld", "partitions": "default_16MB.csv", "memory_type": "qio_qspi" }, @@ -10,6 +9,7 @@ "-DARDUINO_FEATHERS3", "-DBOARD_HAS_PSRAM", "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1", "-DARDUINO_RUNNING_CORE=1", "-DARDUINO_EVENT_RUNNING_CORE=1" ], diff --git a/boards/um_feathers3_neo.json b/boards/um_feathers3_neo.json new file mode 100644 index 000000000..0849ee390 --- /dev/null +++ b/boards/um_feathers3_neo.json @@ -0,0 +1,51 @@ +{ + "build": { + "arduino":{ + "partitions": "default_8MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_FEATHERS3NEO", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0X303A", + "0x81FB" + ] + ], + "mcu": "esp32s3", + "variant": "um_feathers3neo" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Unexpected Maker FeatherS3 Neo", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://unexpectedmaker.com/shop/feathers3neo", + "vendor": "Unexpected Maker" +} diff --git a/boards/um_nanos3.json b/boards/um_nanos3.json index 921a36e3f..742c0ac7d 100644 --- a/boards/um_nanos3.json +++ b/boards/um_nanos3.json @@ -1,7 +1,6 @@ { "build": { "arduino": { - "ldscript": "esp32s3_out.ld", "partitions": "default_8MB.csv", "memory_type": "qio_qspi" }, @@ -10,6 +9,7 @@ "-DBOARD_HAS_PSRAM", "-DARDUINO_NANOS3", "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1", "-DARDUINO_RUNNING_CORE=1", "-DARDUINO_EVENT_RUNNING_CORE=1" ], diff --git a/boards/um_omgs3.json b/boards/um_omgs3.json new file mode 100644 index 000000000..55994d4a1 --- /dev/null +++ b/boards/um_omgs3.json @@ -0,0 +1,51 @@ +{ + "build": { + "arduino":{ + "partitions": "default_8MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_OMGS3", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0X303A", + "0x8224" + ] + ], + "mcu": "esp32s3", + "variant": "um_omgs3" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Unexpected Maker OMGS3", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://unexpectedmaker.com/shop/omgs3", + "vendor": "Unexpected Maker" +} diff --git a/boards/um_pros3.json b/boards/um_pros3.json index 8edcefac3..484c0247b 100644 --- a/boards/um_pros3.json +++ b/boards/um_pros3.json @@ -1,7 +1,6 @@ { "build": { "arduino": { - "ldscript": "esp32s3_out.ld", "partitions": "default_16MB.csv", "memory_type": "qio_qspi" }, @@ -10,6 +9,7 @@ "-DARDUINO_PROS3", "-DBOARD_HAS_PSRAM", "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1", "-DARDUINO_RUNNING_CORE=1", "-DARDUINO_EVENT_RUNNING_CORE=1" ], diff --git a/boards/um_tinyc6.json b/boards/um_tinyc6.json new file mode 100644 index 000000000..f34eee9cd --- /dev/null +++ b/boards/um_tinyc6.json @@ -0,0 +1,38 @@ +{ + "build": { + "arduino":{ + "partitions": "default_8MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_TINYC6" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32c6", + "variant": "um_tinyc6" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32c6.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Unexpected Maker TinyC6", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://unexpectedmaker.com/shop/tinyc6", + "vendor": "Unexpected Maker" +} diff --git a/boards/um_tinys2.json b/boards/um_tinys2.json index 8a57216ac..7ca5ca4b4 100644 --- a/boards/um_tinys2.json +++ b/boards/um_tinys2.json @@ -1,7 +1,8 @@ { "build": { "arduino": { - "ldscript": "esp32s2_out.ld" + "partitions": "default_4MB.csv", + "memory_type": "qio_qspi" }, "core": "esp32", "extra_flags": [ diff --git a/boards/um_tinys3.json b/boards/um_tinys3.json index ed7b2a028..cac1514fe 100644 --- a/boards/um_tinys3.json +++ b/boards/um_tinys3.json @@ -1,7 +1,6 @@ { "build": { "arduino":{ - "ldscript": "esp32s3_out.ld", "partitions": "default_8MB.csv", "memory_type": "qio_qspi" }, @@ -10,6 +9,7 @@ "-DARDUINO_TINYS3", "-DBOARD_HAS_PSRAM", "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1", "-DARDUINO_RUNNING_CORE=1", "-DARDUINO_EVENT_RUNNING_CORE=1" ], @@ -46,6 +46,6 @@ "require_upload_port": true, "speed": 460800 }, - "url": "https://unexpectedmaker.com/shop/ttinys3-esp32s3", + "url": "https://unexpectedmaker.com/shop/tinys3", "vendor": "Unexpected Maker" } diff --git a/boards/waveshare_esp32_s3_zero.json b/boards/waveshare_esp32_s3_zero.json new file mode 100644 index 000000000..5965e4500 --- /dev/null +++ b/boards/waveshare_esp32_s3_zero.json @@ -0,0 +1,41 @@ +{ + "build": { + "arduino":{ + "memory_type": "qio_qspi" + }, + "core": "esp32", + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32s3", + "variant": "waveshare_esp32_s3_zero", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ] + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Waveshare ESP32-S3-Zero", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.waveshare.com/wiki/ESP32-S3-Zero", + "vendor": "Waveshare" +} diff --git a/boards/waveshare_esp32s3_touch_lcd_128.json b/boards/waveshare_esp32s3_touch_lcd_128.json new file mode 100644 index 000000000..d619940df --- /dev/null +++ b/boards/waveshare_esp32s3_touch_lcd_128.json @@ -0,0 +1,52 @@ +{ + "build": { + "arduino":{ + "memory_type": "qio_qspi", + "partitions": "default.csv" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_WAVESHARE_ESP32S3_TOUCH_LCD_128", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x1a86", + "0x55d3" + ] + ], + "mcu": "esp32s3", + "variant": "waveshare_esp32s3_touch_lcd_128" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Waveshare ESP32-S3-Touch-LCD-1.28 (16 MB QD, 2MB PSRAM)", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-1.28", + "vendor": "Waveshare" + } diff --git a/boards/weactstudio_esp32c3coreboard.json b/boards/weactstudio_esp32c3coreboard.json new file mode 100644 index 000000000..50f98736f --- /dev/null +++ b/boards/weactstudio_esp32c3coreboard.json @@ -0,0 +1,42 @@ +{ + "build": { + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32C3_DEV", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "160000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32c3", + "variant": "esp32c3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "openocd_target": "esp32c3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "WeAct Studio ESP32C3CoreBoard", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 409600, + "maximum_size": 393216, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://github.com/WeActStudio/WeActStudio.ESP32C3CoreBoard", + "vendor": "WeAct Studio" +} diff --git a/boards/ws_esp32_s3_matrix.json b/boards/ws_esp32_s3_matrix.json new file mode 100644 index 000000000..d116bc55c --- /dev/null +++ b/boards/ws_esp32_s3_matrix.json @@ -0,0 +1,32 @@ +{ + "build": { + "core": "esp32", + "f_cpu": "240000000L", + "f_flash": "80000000L", + "memory_type": "qio_qspi", + "mcu": "esp32s3", + "variant": "ws_esp32_s3_matrix" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Waveshare ESP32-S3-Matrix", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.waveshare.com/wiki/ESP32-S3-Matrix", + "vendor": "Waveshare" +} diff --git a/boards/wt32-sc01-plus.json b/boards/wt32-sc01-plus.json new file mode 100644 index 000000000..bc9eb99e8 --- /dev/null +++ b/boards/wt32-sc01-plus.json @@ -0,0 +1,50 @@ +{ + "build": { + "arduino":{ + "partitions": "tinyuf2-partitions-16MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_WT32_SC01_PLUS", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0X303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "wt32-sc01-plus" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "wt32-sc01-plus", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 460800 + }, + "url": "http://www.wireless-tag.com/portfolio/wt32-eth01", + "vendor": "Wireless-Tag" +} diff --git a/boards/yb_esp32s3_amp_v2.json b/boards/yb_esp32s3_amp_v2.json new file mode 100644 index 000000000..645a8d597 --- /dev/null +++ b/boards/yb_esp32s3_amp_v2.json @@ -0,0 +1,47 @@ +{ + "build": { + "arduino":{ + "partitions": "default_8MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_YB_ESP32S3_AMP_V2", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x1A86", + "0x7523" + ] + ], + "mcu": "esp32s3", + "variant": "yb_esp32s3_amp_v2" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "YelloByte YB-ESP32-S3-AMP (Rev.2)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://github.com/yellobyte/ESP32-DevBoards-Getting-Started/tree/main/boards/YB-ESP32-S3-AMP", + "vendor": "YelloByte" +} diff --git a/boards/yb_esp32s3_amp_v3.json b/boards/yb_esp32s3_amp_v3.json new file mode 100644 index 000000000..8297e8bd5 --- /dev/null +++ b/boards/yb_esp32s3_amp_v3.json @@ -0,0 +1,48 @@ +{ + "build": { + "arduino":{ + "partitions": "default_8MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_YB_ESP32S3_AMP_V3", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "yb_esp32s3_amp_v3" + }, + "connectivity": [ + "wifi", + "bluetooth" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "YelloByte YB-ESP32-S3-AMP (Rev.3)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://github.com/yellobyte/ESP32-DevBoards-Getting-Started/tree/main/boards/YB-ESP32-S3-AMP", + "vendor": "YelloByte" +} diff --git a/boards/yb_esp32s3_eth.json b/boards/yb_esp32s3_eth.json new file mode 100644 index 000000000..1d99b67f9 --- /dev/null +++ b/boards/yb_esp32s3_eth.json @@ -0,0 +1,51 @@ +{ + "build": { + "arduino":{ + "partitions": "default.csv" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_YB_ESP32S3_ETH", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "yb_esp32s3_eth" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "YelloByte YB-ESP32-S3-ETH", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://github.com/yellobyte/ESP32-DevBoards-Getting-Started/tree/main/boards/YB-ESP32-S3-ETH", + "vendor": "YelloByte" +} diff --git a/builder/build_lib/CMakeLists.txt b/builder/build_lib/CMakeLists.txt new file mode 100644 index 000000000..1ab83d39a --- /dev/null +++ b/builder/build_lib/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/builder/build_lib/arduino-lib-builder-as.S b/builder/build_lib/arduino-lib-builder-as.S new file mode 100644 index 000000000..e69de29bb diff --git a/builder/build_lib/arduino-lib-builder-cpp.cpp b/builder/build_lib/arduino-lib-builder-cpp.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/builder/build_lib/arduino-lib-builder-gcc.c b/builder/build_lib/arduino-lib-builder-gcc.c new file mode 100644 index 000000000..e69de29bb diff --git a/builder/build_lib/idf_component.yml b/builder/build_lib/idf_component.yml new file mode 100644 index 000000000..94024598e --- /dev/null +++ b/builder/build_lib/idf_component.yml @@ -0,0 +1,12 @@ +dependencies: + # Required IDF version + idf: ">=5.1" + espressif/cmake_utilities: + version: "0.*" + espressif/fb_gfx: + version: "master" + path: components/fb_gfx + git: https://github.com/espressif/esp32-arduino-lib-builder.git + require: public + rules: + - if: "target in [esp32, esp32s2, esp32s3, esp32p4]" diff --git a/builder/build_lib/sketch.cpp b/builder/build_lib/sketch.cpp new file mode 100644 index 000000000..10a17a8f2 --- /dev/null +++ b/builder/build_lib/sketch.cpp @@ -0,0 +1,10 @@ +#include "Arduino.h" + +void setup() { + Serial.begin(115200); +} + +void loop() { + Serial.println("Hello World!"); + delay(1000); +} diff --git a/builder/frameworks/_embed_files.py b/builder/frameworks/_embed_files.py index c89dc4338..d8d9a352c 100644 --- a/builder/frameworks/_embed_files.py +++ b/builder/frameworks/_embed_files.py @@ -110,14 +110,14 @@ def transform_to_asm(target, source, env): " ".join( [ "riscv32-esp-elf-objcopy" - if mcu in ("esp32c3", "esp32c6") + if mcu in ("esp32c2","esp32c3","esp32c6","esp32h2","esp32p4") else "xtensa-%s-elf-objcopy" % mcu, "--input-target", "binary", "--output-target", - "elf32-littleriscv" if mcu in ("esp32c3","esp32c6") else "elf32-xtensa-le", + "elf32-littleriscv" if mcu in ("esp32c2","esp32c3","esp32c6","esp32h2","esp32p4") else "elf32-xtensa-le", "--binary-architecture", - "riscv" if mcu in ("esp32c3","esp32c6") else "xtensa", + "riscv" if mcu in ("esp32c2","esp32c3","esp32c6","esp32h2","esp32p4") else "xtensa", "--rename-section", ".data=.rodata.embedded", "$SOURCE", diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index 537f4b292..4c2bd9306 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -22,18 +22,244 @@ http://arduino.cc/en/Reference/HomePage """ +import subprocess +import json +import semantic_version +import os +import sys +import shutil from os.path import join -from SCons.Script import DefaultEnvironment, SConscript +from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, SConscript +from platformio import fs +from platformio.package.version import pepver_to_semver +from platformio.project.config import ProjectConfig +from platformio.package.manager.tool import ToolPackageManager env = DefaultEnvironment() +pm = ToolPackageManager() +platform = env.PioPlatform() +config = env.GetProjectConfig() board = env.BoardConfig() -build_core = board.get("build.core", "").lower() +mcu = board.get("build.mcu", "esp32") +board_sdkconfig = board.get("espidf.custom_sdkconfig", "") +entry_custom_sdkconfig = "\n" +flag_custom_sdkconfig = False +IS_WINDOWS = sys.platform.startswith("win") + +if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"): + entry_custom_sdkconfig = env.GetProjectOption("custom_sdkconfig") + flag_custom_sdkconfig = True + +if len(str(board_sdkconfig)) > 2: + flag_custom_sdkconfig = True + +extra_flags = (''.join([element for element in board.get("build.extra_flags", "")])).replace("-D", " ") +framework_reinstall = False +flag_any_custom_sdkconfig = False + +FRAMEWORK_LIB_DIR = platform.get_package_dir("framework-arduinoespressif32-libs") SConscript("_embed_files.py", exports="env") -if "espidf" not in env.subst("$PIOFRAMEWORK"): - SConscript( - join(DefaultEnvironment().PioPlatform().get_package_dir( - "framework-arduinoespressif32"), "tools", "platformio-build.py")) - env["INTEGRATION_EXTRA_DATA"].update({"application_offset": env.subst("$ESP32_APP_OFFSET")}) +flag_any_custom_sdkconfig = os.path.exists(join(platform.get_package_dir("framework-arduinoespressif32-libs"),"sdkconfig")) + +# Esp32-solo1 libs needs adopted settings +if flag_custom_sdkconfig == True and ("CORE32SOLO1" in extra_flags or "CONFIG_FREERTOS_UNICORE=y" in entry_custom_sdkconfig or "CONFIG_FREERTOS_UNICORE=y" in board_sdkconfig): + if len(str(env.GetProjectOption("build_unflags"))) == 2: # No valid env, needs init + env['BUILD_UNFLAGS'] = {} + build_unflags = " ".join(env['BUILD_UNFLAGS']) + build_unflags = build_unflags + " -mdisable-hardware-atomics -ustart_app_other_cores" + new_build_unflags = build_unflags.split() + env.Replace( + BUILD_UNFLAGS=new_build_unflags + ) + +def install_python_deps(): + def _get_installed_pip_packages(): + result = {} + packages = {} + pip_output = subprocess.check_output( + [ + env.subst("$PYTHONEXE"), + "-m", + "pip", + "list", + "--format=json", + "--disable-pip-version-check", + ] + ) + try: + packages = json.loads(pip_output) + except: + print("Warning! Couldn't extract the list of installed Python packages.") + return {} + for p in packages: + result[p["name"]] = pepver_to_semver(p["version"]) + + return result + + deps = { + "wheel": ">=0.35.1", + "rich-click": ">=1.8.6", + "PyYAML": ">=6.0.2", + "intelhex": ">=2.3.0" + } + + installed_packages = _get_installed_pip_packages() + packages_to_install = [] + for package, spec in deps.items(): + if package not in installed_packages: + packages_to_install.append(package) + else: + version_spec = semantic_version.Spec(spec) + if not version_spec.match(installed_packages[package]): + packages_to_install.append(package) + + if packages_to_install: + env.Execute( + env.VerboseAction( + ( + '"$PYTHONEXE" -m pip install -U ' + + " ".join( + [ + '"%s%s"' % (p, deps[p]) + for p in packages_to_install + ] + ) + ), + "Installing Arduino Python dependencies", + ) + ) + return + +install_python_deps() + +def get_MD5_hash(phrase): + import hashlib + return hashlib.md5((phrase).encode('utf-8')).hexdigest()[:16] + + +def matching_custom_sdkconfig(): + # check if current env is matching to existing sdkconfig + cust_sdk_is_present = False + matching_sdkconfig = False + last_sdkconfig_path = join(env.subst("$PROJECT_DIR"),"sdkconfig.defaults") + if flag_any_custom_sdkconfig == False: + matching_sdkconfig = True + return matching_sdkconfig, cust_sdk_is_present + if os.path.exists(last_sdkconfig_path) == False: + return matching_sdkconfig, cust_sdk_is_present + if flag_custom_sdkconfig == False: + matching_sdkconfig = False + return matching_sdkconfig, cust_sdk_is_present + with open(last_sdkconfig_path) as src: + line = src.readline() + if line.startswith("# TASMOTA__"): + cust_sdk_is_present = True; + costum_options = entry_custom_sdkconfig + if (line.split("__")[1]).strip() == get_MD5_hash((costum_options).strip() + mcu): + matching_sdkconfig = True + + return matching_sdkconfig, cust_sdk_is_present + +def check_reinstall_frwrk(): + framework_reinstall = False + cust_sdk_is_present = False + matching_sdkconfig = False + if flag_custom_sdkconfig == True: + matching_sdkconfig, cust_sdk_is_present = matching_custom_sdkconfig() + if flag_custom_sdkconfig == False and flag_any_custom_sdkconfig == True: + # case custom sdkconfig exists and a env without "custom_sdkconfig" + framework_reinstall = True + if flag_custom_sdkconfig == True and matching_sdkconfig == False: + # check if current custom sdkconfig is different from existing + framework_reinstall = True + return framework_reinstall + + +FRAMEWORK_SDK_DIR = fs.to_unix_path( + os.path.join( + FRAMEWORK_LIB_DIR, + mcu, + "include", + ) +) + +IS_INTEGRATION_DUMP = env.IsIntegrationDump() + + +def is_framework_subfolder(potential_subfolder): + if not os.path.isabs(potential_subfolder): + return False + if ( + os.path.splitdrive(FRAMEWORK_SDK_DIR)[0] + != os.path.splitdrive(potential_subfolder)[0] + ): + return False + return os.path.commonpath([FRAMEWORK_SDK_DIR]) == os.path.commonpath( + [FRAMEWORK_SDK_DIR, potential_subfolder] + ) + + +def shorthen_includes(env, node): + if IS_INTEGRATION_DUMP: + # Don't shorten include paths for IDE integrations + return node + + includes = [fs.to_unix_path(inc) for inc in env.get("CPPPATH", [])] + shortened_includes = [] + generic_includes = [] + for inc in includes: + if is_framework_subfolder(inc): + shortened_includes.append( + "-iwithprefix/" + + fs.to_unix_path(os.path.relpath(inc, FRAMEWORK_SDK_DIR)) + ) + else: + generic_includes.append(inc) + + return env.Object( + node, + CPPPATH=generic_includes, + CCFLAGS=env["CCFLAGS"] + + ["-iprefix", FRAMEWORK_SDK_DIR] + + shortened_includes, + ASFLAGS=env["ASFLAGS"] + + ["-iprefix", FRAMEWORK_SDK_DIR] + + shortened_includes, + ) + +def call_compile_libs(): + if mcu == "esp32c2": + ARDUINO_FRMWRK_C2_LIB_DIR = join(platform.get_package_dir("framework-arduinoespressif32-libs"),mcu) + if not os.path.exists(ARDUINO_FRMWRK_C2_LIB_DIR): + ARDUINO_C2_DIR = join(platform.get_package_dir("framework-arduino-c2-skeleton-lib"),mcu) + shutil.copytree(ARDUINO_C2_DIR, ARDUINO_FRMWRK_C2_LIB_DIR, dirs_exist_ok=True) + print("*** Compile Arduino IDF libs for %s ***" % env["PIOENV"]) + SConscript("espidf.py") + +if check_reinstall_frwrk() == True: + print("*** Reinstall Arduino framework ***") + shutil.rmtree(platform.get_package_dir("framework-arduinoespressif32")) + shutil.rmtree(platform.get_package_dir("framework-arduinoespressif32-libs")) + ARDUINO_FRMWRK_URL = str(platform.get_package_spec("framework-arduinoespressif32")).split("uri=",1)[1][:-1] + ARDUINO_FRMWRK_LIB_URL = str(platform.get_package_spec("framework-arduinoespressif32-libs")).split("uri=",1)[1][:-1] + pm.install(ARDUINO_FRMWRK_URL) + pm.install(ARDUINO_FRMWRK_LIB_URL) + if flag_custom_sdkconfig == True: + call_compile_libs() + flag_custom_sdkconfig = False + +if flag_custom_sdkconfig == True and flag_any_custom_sdkconfig == False: + call_compile_libs() + +if "arduino" in env.subst("$PIOFRAMEWORK") and "espidf" not in env.subst("$PIOFRAMEWORK") and env.subst("$ARDUINO_LIB_COMPILE_FLAG") in ("Inactive", "True"): + if IS_WINDOWS: + env.AddBuildMiddleware(shorthen_includes) + if os.path.exists(join(platform.get_package_dir( + "framework-arduinoespressif32"), "tools", "platformio-build.py")): + PIO_BUILD = "platformio-build.py" + else: + PIO_BUILD = "pioarduino-build.py" + SConscript(join(platform.get_package_dir("framework-arduinoespressif32"), "tools", PIO_BUILD)) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 3b9850039..b77b73305 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -26,7 +26,9 @@ import sys import shutil import os +from os.path import join import re +import requests import platform as sys_platform import click @@ -42,6 +44,7 @@ from platformio.compat import IS_WINDOWS from platformio.proc import exec_command from platformio.builder.tools.piolib import ProjectAsLibBuilder +from platformio.project.config import ProjectConfig from platformio.package.version import get_original_version, pepver_to_semver # Added to avoid conflicts between installed Python packages from @@ -53,12 +56,80 @@ env = DefaultEnvironment() env.SConscript("_embed_files.py", exports="env") +def install_standard_python_deps(): + def _get_installed_standard_pip_packages(): + result = {} + packages = {} + pip_output = subprocess.check_output( + [ + env.subst("$PYTHONEXE"), + "-m", + "pip", + "list", + "--format=json", + "--disable-pip-version-check", + ] + ) + try: + packages = json.loads(pip_output) + except: + print("Warning! Couldn't extract the list of installed Python packages.") + return {} + for p in packages: + result[p["name"]] = pepver_to_semver(p["version"]) + + return result + + deps = { + "wheel": ">=0.35.1", + "rich-click": ">=1.8.6", + "PyYAML": ">=6.0.2" + } + + installed_packages = _get_installed_standard_pip_packages() + packages_to_install = [] + for package, spec in deps.items(): + if package not in installed_packages: + packages_to_install.append(package) + else: + version_spec = semantic_version.Spec(spec) + if not version_spec.match(installed_packages[package]): + packages_to_install.append(package) + + if packages_to_install: + env.Execute( + env.VerboseAction( + ( + '"$PYTHONEXE" -m pip install -U ' + + " ".join( + [ + '"%s%s"' % (p, deps[p]) + for p in packages_to_install + ] + ) + ), + "Installing standard Python dependencies", + ) + ) + return + +install_standard_python_deps() + +# Allow changes in folders of managed components +os.environ["IDF_COMPONENT_OVERWRITE_MANAGED_COMPONENTS"] = "1" + platform = env.PioPlatform() +config = env.GetProjectConfig() board = env.BoardConfig() mcu = board.get("build.mcu", "esp32") +flash_speed = board.get("build.f_flash", "40000000L") +flash_frequency = str(flash_speed.replace("000000L", "m")) +flash_mode = board.get("build.flash_mode", "dio") idf_variant = mcu.lower() +flag_custom_sdkonfig = False +flag_custom_component_add = False +flag_custom_component_remove = False -# Required until Arduino switches to v5 IDF5 = ( platform.get_package_version("framework-espidf") .split(".")[1] @@ -67,22 +138,15 @@ IDF_ENV_VERSION = "1.0.0" FRAMEWORK_DIR = platform.get_package_dir("framework-espidf") TOOLCHAIN_DIR = platform.get_package_dir( - "toolchain-riscv32-esp" - if mcu in ("esp32c3", "esp32c6") - else ( - ( - "toolchain-xtensa-esp-elf" - if "arduino" not in env.subst("$PIOFRAMEWORK") - else "toolchain-xtensa-%s" % mcu - ) - ) + "toolchain-xtensa-esp-elf" + if mcu in ("esp32", "esp32s2", "esp32s3") + else "toolchain-riscv32-esp" ) assert os.path.isdir(FRAMEWORK_DIR) assert os.path.isdir(TOOLCHAIN_DIR) -# The latest IDF uses a standalone GDB package which requires at least PlatformIO 6.1.11 if ( ["espidf"] == env.get("PIOFRAMEWORK") and semantic_version.Version.coerce(__version__) @@ -91,9 +155,10 @@ ): print("Warning! Debugging an IDF project requires PlatformIO Core >= 6.1.11!") -# Arduino framework as a component is not compatible with ESP-IDF >=4.1 +# Arduino framework as a component is not compatible with ESP-IDF >5.3 if "arduino" in env.subst("$PIOFRAMEWORK"): ARDUINO_FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") + ARDUINO_FRMWRK_LIB_DIR = platform.get_package_dir("framework-arduinoespressif32-libs") # Possible package names in 'package@version' format is not compatible with CMake if "@" in os.path.basename(ARDUINO_FRAMEWORK_DIR): new_path = os.path.join( @@ -113,6 +178,208 @@ os.path.join(PROJECT_DIR, "sdkconfig.%s" % env.subst("$PIOENV")), )) +# +# generate modified Arduino IDF sdkconfig, applying settings from "custom_sdkconfig" +# +if config.has_option("env:"+env["PIOENV"], "custom_component_add"): + flag_custom_component_add = True +if config.has_option("env:"+env["PIOENV"], "custom_component_remove"): + flag_custom_component_remove = True + +if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"): + flag_custom_sdkonfig = True +if "espidf.custom_sdkconfig" in board: + flag_custom_sdkonfig = True + +def HandleArduinoIDFsettings(env): + def get_MD5_hash(phrase): + import hashlib + return hashlib.md5((phrase).encode('utf-8')).hexdigest()[:16] + + def custom_sdkconfig_file(string): + if not config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"): + return "" + sdkconfig_entrys = env.GetProjectOption("custom_sdkconfig").splitlines() + for file in sdkconfig_entrys: + if "http" in file and "://" in file: + response = requests.get(file.split(" ")[0]) + if response.ok: + target = str(response.content.decode('utf-8')) + else: + print("Failed to download:", file) + return "" + return target + if "file://" in file: + file_path = join(PROJECT_DIR,file.lstrip("file://").split(os.path.sep)[-1]) + if os.path.exists(file_path): + with open(file_path, 'r') as file: + target = file.read() + else: + print("File not found:", file_path) + return "" + return target + return "" + + + custom_sdk_config_flags = "" + board_idf_config_flags = "" + sdkconfig_file_flags = "" + custom_sdkconfig_file_str = "" + + if config.has_option("env:"+env["PIOENV"], "custom_sdkconfig"): + flag_custom_sdkonfig = True + custom_sdk_config_flags = (env.GetProjectOption("custom_sdkconfig").rstrip("\n")) + "\n" + custom_sdkconfig_file_str = custom_sdkconfig_file(sdkconfig_file_flags) + + if "espidf.custom_sdkconfig" in board: + board_idf_config_flags = ('\n'.join([element for element in board.get("espidf.custom_sdkconfig", "")])).rstrip("\n") + "\n" + flag_custom_sdkonfig = True + + if flag_custom_sdkonfig == True: # TDOO duplicated + print("*** Add \"custom_sdkconfig\" settings to IDF sdkconfig.defaults ***") + idf_config_flags = custom_sdk_config_flags + if custom_sdkconfig_file_str != "": + sdkconfig_file_flags = custom_sdkconfig_file_str + "\n" + idf_config_flags = sdkconfig_file_flags + idf_config_flags + idf_config_flags = board_idf_config_flags + idf_config_flags + if flash_frequency != "80m": + idf_config_flags = idf_config_flags + "# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set\n" + esptool_flashfreq_y = "CONFIG_ESPTOOLPY_FLASHFREQ_%s=y\n" % flash_frequency.upper() + esptool_flashfreq_M = "CONFIG_ESPTOOLPY_FLASHFREQ=\"%s\"\n" % flash_frequency + idf_config_flags = idf_config_flags + esptool_flashfreq_y + esptool_flashfreq_M + if flash_mode != "qio": + idf_config_flags = idf_config_flags + "# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set\n" + esptool_flashmode = "CONFIG_ESPTOOLPY_FLASHMODE_%s=y\n" % flash_mode.upper() + if esptool_flashmode not in idf_config_flags: + idf_config_flags = idf_config_flags + esptool_flashmode + if mcu in ("esp32") and "CONFIG_FREERTOS_UNICORE=y" in idf_config_flags: + idf_config_flags = idf_config_flags + "# CONFIG_SPIRAM is not set\n" + + idf_config_flags = idf_config_flags.splitlines() + sdkconfig_src = join(ARDUINO_FRMWRK_LIB_DIR,mcu,"sdkconfig") + + def get_flag(line): + if line.startswith("#") and "is not set" in line: + return line.split(" ")[1] + elif not line.startswith("#") and len(line.split("=")) > 1: + return line.split("=")[0] + else: + return None + + with open(sdkconfig_src) as src: + sdkconfig_dst = os.path.join(PROJECT_DIR, "sdkconfig.defaults") + dst = open(sdkconfig_dst,"w") + dst.write("# TASMOTA__"+ get_MD5_hash(''.join(custom_sdk_config_flags).strip() + mcu) +"\n") + while line := src.readline(): + flag = get_flag(line) + if flag is None: + dst.write(line) + else: + no_match = True + for item in idf_config_flags: + if flag == get_flag(item.replace("\'", "")): + dst.write(item.replace("\'", "")+"\n") + no_match = False + print("Replace:",line,"with:",item.replace("\'", "")) + idf_config_flags.remove(item) + if no_match: + dst.write(line) + for item in idf_config_flags: # are there new flags? + print("Add:",item.replace("\'", "")) + dst.write(item.replace("\'", "")+"\n") + dst.close() + return + else: + return + +def HandleCOMPONENTsettings(env): + if flag_custom_component_add == True or flag_custom_component_remove == True: # todo remove duplicated + import yaml + from yaml import SafeLoader + print("*** \"custom_component\" is used to select managed idf components ***") + if flag_custom_component_remove == True: + idf_custom_component_remove = env.GetProjectOption("custom_component_remove").splitlines() + else: + idf_custom_component_remove = "" + if flag_custom_component_add == True: + idf_custom_component_add = env.GetProjectOption("custom_component_add").splitlines() + else: + idf_custom_component_add = "" + + # search "idf_component.yml" file + try: # 1.st in Arduino framework + idf_component_yml_src = os.path.join(ARDUINO_FRAMEWORK_DIR, "idf_component.yml") + shutil.copy(join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml"),join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml.orig")) + yml_file_dir = idf_component_yml_src + except: # 2.nd Project source + try: + idf_component_yml_src = os.path.join(PROJECT_SRC_DIR, "idf_component.yml") + shutil.copy(join(PROJECT_SRC_DIR,"idf_component.yml"),join(PROJECT_SRC_DIR,"idf_component.yml.orig")) + yml_file_dir = idf_component_yml_src + except: # no idf_component.yml in Project source -> create + idf_component_yml_src = os.path.join(PROJECT_SRC_DIR, "idf_component.yml") + yml_file_dir = idf_component_yml_src + idf_component_yml_str = """ + dependencies: + idf: \">=5.1\" + """ + idf_component_yml = yaml.safe_load(idf_component_yml_str) + with open(idf_component_yml_src, 'w',) as f : + yaml.dump(idf_component_yml,f) + + yaml_file=open(idf_component_yml_src,"r") + idf_component=yaml.load(yaml_file, Loader=SafeLoader) + idf_component_str=json.dumps(idf_component) # convert to json string + idf_component_json=json.loads(idf_component_str) # convert string to json dict + + if idf_custom_component_remove != "": + for entry in idf_custom_component_remove: + # checking if the entry exists before removing + if entry in idf_component_json["dependencies"]: + print("*** Removing component:",entry) + del idf_component_json["dependencies"][entry] + + if idf_custom_component_add != "": + for entry in idf_custom_component_add: + if len(str(entry)) > 4: # too short or empty entry + # add new entrys to json + if "@" in entry: + idf_comp_entry = str(entry.split("@")[0]).replace(" ", "") + idf_comp_vers = str(entry.split("@")[1]).replace(" ", "") + else: + idf_comp_entry = str(entry).replace(" ", "") + idf_comp_vers = "*" + if idf_comp_entry not in idf_component_json["dependencies"]: + print("*** Adding component:", idf_comp_entry, idf_comp_vers) + new_entry = {idf_comp_entry: {"version": idf_comp_vers}} + idf_component_json["dependencies"].update(new_entry) + + idf_component_yml_file = open(yml_file_dir,"w") + yaml.dump(idf_component_json, idf_component_yml_file) + idf_component_yml_file.close() + # print("JSON from modified idf_component.yml:") + # print(json.dumps(idf_component_json)) + return + return + +if flag_custom_component_add == True or flag_custom_component_remove == True: + HandleCOMPONENTsettings(env) + +if flag_custom_sdkonfig == True and "arduino" in env.subst("$PIOFRAMEWORK"): + HandleArduinoIDFsettings(env) + LIB_SOURCE = os.path.join(ProjectConfig.get_instance().get("platformio", "platforms_dir"), "espressif32", "builder", "build_lib") + if not bool(os.path.exists(os.path.join(PROJECT_DIR, ".dummy"))): + shutil.copytree(LIB_SOURCE, os.path.join(PROJECT_DIR, ".dummy")) + PROJECT_SRC_DIR = os.path.join(PROJECT_DIR, ".dummy") + env.Replace( + PROJECT_SRC_DIR=PROJECT_SRC_DIR, + BUILD_FLAGS="", + BUILD_UNFLAGS="", + LINKFLAGS="", + PIOFRAMEWORK="arduino", + ARDUINO_LIB_COMPILE_FLAG="Build", + ) + env["INTEGRATION_EXTRA_DATA"].update({"arduino_lib_compile_flag": env.subst("$ARDUINO_LIB_COMPILE_FLAG")}) def get_project_lib_includes(env): project = ProjectAsLibBuilder(env, "$PROJECT_DIR") @@ -139,13 +406,15 @@ def is_cmake_reconfigure_required(cmake_api_reply_dir): ] cmake_preconf_dir = os.path.join(BUILD_DIR, "config") deafult_sdk_config = os.path.join(PROJECT_DIR, "sdkconfig.defaults") + idf_deps_lock = os.path.join(PROJECT_DIR, "dependencies.lock") + ninja_buildfile = os.path.join(BUILD_DIR, "build.ninja") for d in (cmake_api_reply_dir, cmake_preconf_dir): if not os.path.isdir(d) or not os.listdir(d): return True if not os.path.isfile(cmake_cache_file): return True - if not os.path.isfile(os.path.join(BUILD_DIR, "build.ninja")): + if not os.path.isfile(ninja_buildfile): return True if not os.path.isfile(SDKCONFIG_PATH) or os.path.getmtime( SDKCONFIG_PATH @@ -155,6 +424,10 @@ def is_cmake_reconfigure_required(cmake_api_reply_dir): deafult_sdk_config ) > os.path.getmtime(cmake_cache_file): return True + if os.path.isfile(idf_deps_lock) and os.path.getmtime( + idf_deps_lock + ) > os.path.getmtime(ninja_buildfile): + return True if any( os.path.getmtime(f) > os.path.getmtime(cmake_cache_file) for f in cmake_txt_files + [cmake_preconf_dir, FRAMEWORK_DIR] @@ -256,14 +529,6 @@ def populate_idf_env_vars(idf_env): os.path.dirname(get_python_exe()), ] - if mcu not in ("esp32c3", "esp32c6"): - additional_packages.append( - os.path.join(platform.get_package_dir("toolchain-esp32ulp"), "bin"), - ) - - if IS_WINDOWS: - additional_packages.append(platform.get_package_dir("tool-mconf")) - idf_env["PATH"] = os.pathsep.join(additional_packages + [idf_env["PATH"]]) # Some users reported that the `IDF_TOOLS_PATH` var can seep into the @@ -330,8 +595,9 @@ def _normalize_define(define_string): define_string = define_string.strip() if "=" in define_string: define, value = define_string.split("=", maxsplit=1) - if '"' in value and not value.startswith("\\"): - # Escape only raw values + if any(char in value for char in (' ', '<', '>')): + value = f'"{value}"' + elif '"' in value and not value.startswith("\\"): value = value.replace('"', '\\"') return (define, value) return define_string @@ -342,8 +608,11 @@ def _normalize_define(define_string): ] for f in compile_group.get("compileCommandFragments", []): - if f.get("fragment", "").startswith("-D"): - result.append(_normalize_define(f["fragment"][2:])) + fragment = f.get("fragment", "").strip() + if fragment.startswith('"'): + fragment = fragment.strip('"') + if fragment.startswith("-D"): + result.append(_normalize_define(fragment[2:])) return result @@ -429,8 +698,8 @@ def _extract_flags(config): for cg in config["compileGroups"]: flags[cg["language"]] = [] for ccfragment in cg["compileCommandFragments"]: - fragment = ccfragment.get("fragment", "") - if not fragment.strip() or fragment.startswith("-D"): + fragment = ccfragment.get("fragment", "").strip("\" ") + if not fragment or fragment.startswith("-D"): continue flags[cg["language"]].extend( click.parser.split_arg_string(fragment.strip()) @@ -511,7 +780,7 @@ def extract_linker_script_fragments_backup(framework_components_dir, sdk_config) sys.stderr.write("Error: Failed to extract paths to linker script fragments\n") env.Exit(1) - if mcu in ("esp32c3", "esp32c6"): + if mcu not in ("esp32", "esp32s2", "esp32s3"): result.append(os.path.join(framework_components_dir, "riscv", "linker.lf")) # Add extra linker fragments @@ -652,16 +921,31 @@ def generate_project_ld_script(sdk_config, ignore_targets=None): '--objdump "{objdump}"' ).format(**args) + initial_ld_script = os.path.join( + FRAMEWORK_DIR, + "components", + "esp_system", + "ld", + idf_variant, + "sections.ld.in", + ) + + framework_version = [int(v) for v in get_framework_version().split(".")] + if framework_version[:2] > [5, 2]: + initial_ld_script = preprocess_linker_file( + initial_ld_script, + os.path.join( + BUILD_DIR, + "esp-idf", + "esp_system", + "ld", + "sections.ld.in", + ) + ) + return env.Command( os.path.join("$BUILD_DIR", "sections.ld"), - os.path.join( - FRAMEWORK_DIR, - "components", - "esp_system", - "ld", - idf_variant, - "sections.ld.in", - ), + initial_ld_script, env.VerboseAction(cmd, "Generating project linker script $TARGET"), ) @@ -700,7 +984,7 @@ def prepare_build_envs(config, default_env, debug_allowed=True): build_env = default_env.Clone() build_env.SetOption("implicit_cache", 1) for cc in compile_commands: - build_flags = cc.get("fragment") + build_flags = cc.get("fragment", "").strip("\" ") if not build_flags.startswith("-D"): if build_flags.startswith("-include") and ".." in build_flags: source_index = cg.get("sourceIndexes")[0] @@ -860,6 +1144,7 @@ def build_bootloader(sdk_config): "-DPYTHON=" + get_python_exe(), "-DIDF_PATH=" + FRAMEWORK_DIR, "-DSDKCONFIG=" + SDKCONFIG_PATH, + "-DPROJECT_SOURCE_DIR=" + PROJECT_DIR, "-DLEGACY_INCLUDE_COMMON_HEADERS=", "-DEXTRA_COMPONENT_DIRS=" + os.path.join(FRAMEWORK_DIR, "components", "bootloader"), @@ -1052,7 +1337,8 @@ def generate_empty_partition_image(binary_path, image_size): ), ) - env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", empty_partition) + if flag_custom_sdkonfig == False: + env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", empty_partition) def get_partition_info(pt_path, pt_offset, pt_params): @@ -1111,6 +1397,46 @@ def get_app_partition_offset(pt_table, pt_offset): return app_params.get("offset", "0x10000") +def preprocess_linker_file(src_ld_script, target_ld_script): + return env.Command( + target_ld_script, + src_ld_script, + env.VerboseAction( + " ".join( + [ + os.path.join( + platform.get_package_dir("tool-cmake"), + "bin", + "cmake", + ), + "-DCC=%s" + % os.path.join( + TOOLCHAIN_DIR, + "bin", + "$CC", + ), + "-DSOURCE=$SOURCE", + "-DTARGET=$TARGET", + "-DCONFIG_DIR=%s" % os.path.join(BUILD_DIR, "config"), + "-DLD_DIR=%s" + % os.path.join( + FRAMEWORK_DIR, "components", "esp_system", "ld" + ), + "-P", + os.path.join( + "$BUILD_DIR", + "esp-idf", + "esp_system", + "ld", + "linker_script_generator.cmake", + ), + ] + ), + "Generating LD script $TARGET", + ), + ) + + def generate_mbedtls_bundle(sdk_config): bundle_path = os.path.join("$BUILD_DIR", "x509_crt_bundle") if os.path.isfile(env.subst(bundle_path)): @@ -1201,15 +1527,15 @@ def _get_installed_pip_packages(python_exe_path): return deps = { + "wheel": ">=0.35.1", # https://github.com/platformio/platformio-core/issues/4614 "urllib3": "<2", # https://github.com/platformio/platform-espressif32/issues/635 - "cryptography": "~=41.0.1" if IDF5 else ">=2.1.4,<35.0.0", + "cryptography": "~=41.0.1", "future": ">=0.18.3", - "pyparsing": ">=3.1.0,<4" if IDF5 else ">=2.0.3,<2.4.0", - "kconfiglib": "~=14.1.0" if IDF5 else "~=13.7.1", - "idf-component-manager": "~=1.5.2" if IDF5 else "~=1.0", - "esp-idf-kconfig": ">=1.4.2,<2.0.0" + "pyparsing": ">=3.1.0,<4", + "idf-component-manager": "~=2.0.1", + "esp-idf-kconfig": ">=2.5.0" } if sys_platform.system() == "Darwin" and "arm" in sys_platform.machine().lower(): @@ -1245,17 +1571,6 @@ def _get_installed_pip_packages(python_exe_path): ) ) - # A special "esp-windows-curses" python package is required on Windows - # for Menuconfig on IDF <5 - if not IDF5 and "esp-windows-curses" not in installed_packages: - env.Execute( - env.VerboseAction( - '"%s" -m pip install "file://%s/tools/kconfig_new/esp-windows-curses"' - % (python_exe_path, FRAMEWORK_DIR), - "Installing windows-curses package", - ) - ) - def get_idf_venv_dir(): # The name of the IDF venv contains the IDF version to avoid possible conflicts and @@ -1270,11 +1585,37 @@ def get_idf_venv_dir(): def ensure_python_venv_available(): + def _get_idf_venv_python_version(): + try: + version = subprocess.check_output( + [ + get_python_exe(), + "-c", + "import sys;print('{0}.{1}.{2}-{3}.{4}'.format(*list(sys.version_info)))" + ], text=True + ) + return version.strip() + except subprocess.CalledProcessError as e: + print("Failed to extract Python version from IDF virtual env!") + return None + def _is_venv_outdated(venv_data_file): try: with open(venv_data_file, "r", encoding="utf8") as fp: venv_data = json.load(fp) if venv_data.get("version", "") != IDF_ENV_VERSION: + print( + "Warning! IDF virtual environment version changed!" + ) + return True + if ( + venv_data.get("python_version", "") + != _get_idf_venv_python_version() + ): + print( + "Warning! Python version in the IDF virtual environment" + " differs from the current Python!" + ) return True return False except: @@ -1289,7 +1630,7 @@ def _create_venv(venv_dir): if os.path.isdir(venv_dir): try: - print("Removing an oudated IDF virtual environment") + print("Removing an outdated IDF virtual environment") shutil.rmtree(venv_dir) except OSError: print( @@ -1314,8 +1655,12 @@ def _create_venv(venv_dir): venv_data_file = os.path.join(venv_dir, "pio-idf-venv.json") if not os.path.isfile(venv_data_file) or _is_venv_outdated(venv_data_file): _create_venv(venv_dir) + install_python_deps() with open(venv_data_file, "w", encoding="utf8") as fp: - venv_info = {"version": IDF_ENV_VERSION} + venv_info = { + "version": IDF_ENV_VERSION, + "python_version": _get_idf_venv_python_version() + } json.dump(venv_info, fp, indent=2) @@ -1334,11 +1679,10 @@ def get_python_exe(): # -# ESP-IDF requires Python packages with specific versions in a virtual environment +# Ensure Python environment contains everything required for IDF # ensure_python_venv_available() -install_python_deps() # ESP-IDF package doesn't contain .git folder, instead package version is specified # in a special file "version.h" in the root folder of the package @@ -1356,19 +1700,31 @@ def get_python_exe(): # if not board.get("build.ldscript", ""): - linker_script = env.Command( - os.path.join("$BUILD_DIR", "memory.ld"), - board.get( - "build.esp-idf.ldscript", + initial_ld_script = board.get("build.esp-idf.ldscript", os.path.join( + FRAMEWORK_DIR, + "components", + "esp_system", + "ld", + idf_variant, + "memory.ld.in", + )) + + framework_version = [int(v) for v in get_framework_version().split(".")] + if framework_version[:2] > [5, 2]: + initial_ld_script = preprocess_linker_file( + initial_ld_script, os.path.join( - FRAMEWORK_DIR, - "components", + BUILD_DIR, + "esp-idf", "esp_system", "ld", - idf_variant, "memory.ld.in", - ), - ), + ) + ) + + linker_script = env.Command( + os.path.join("$BUILD_DIR", "memory.ld"), + initial_ld_script, env.VerboseAction( '$CC -I"$BUILD_DIR/config" -I"%s" -C -P -x c -E $SOURCE -o $TARGET' % os.path.join(FRAMEWORK_DIR, "components", "esp_system", "ld"), @@ -1507,7 +1863,8 @@ def get_python_exe(): # Compile bootloader # -env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", build_bootloader(sdk_config)) +if flag_custom_sdkonfig == False: + env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", build_bootloader(sdk_config)) # # Target: ESP-IDF menuconfig @@ -1530,7 +1887,17 @@ def get_python_exe(): # Extra flags which need to be explicitly specified in LINKFLAGS section because SCons # cannot merge them correctly -extra_flags = filter_args(link_args["LINKFLAGS"], ["-T", "-u"]) +extra_flags = filter_args( + link_args["LINKFLAGS"], + [ + "-T", + "-u", + "-Wl,--start-group", + "-Wl,--end-group", + "-Wl,--whole-archive", + "-Wl,--no-whole-archive", + ], +) link_args["LINKFLAGS"] = sorted(list(set(link_args["LINKFLAGS"]) - set(extra_flags))) # remove the main linker script flags '-T memory.ld' @@ -1606,7 +1973,7 @@ def _skip_prj_source_files(node): ( board.get( "upload.bootloader_offset", - "0x0" if mcu in ("esp32c3", "esp32c6", "esp32s3") else "0x1000", + "0x1000" if mcu in ["esp32", "esp32s2"] else ("0x2000" if mcu in ["esp32p4"] else "0x0"), ), os.path.join("$BUILD_DIR", "bootloader.bin"), ), @@ -1717,10 +2084,88 @@ def _skip_prj_source_files(node): # ulp_dir = os.path.join(PROJECT_DIR, "ulp") -if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c3", "esp32c6"): - env.SConscript("ulp.py", exports="env sdk_config project_config idf_variant") +if os.path.isdir(ulp_dir) and os.listdir(ulp_dir) and mcu not in ("esp32c2", "esp32c3", "esp32h2"): + env.SConscript("ulp.py", exports="env sdk_config project_config app_includes idf_variant") # +# Compile Arduino IDF sources +# + +if "arduino" in env.get("PIOFRAMEWORK") and "espidf" not in env.get("PIOFRAMEWORK"): + def idf_lib_copy(source, target, env): + env_build = join(env["PROJECT_BUILD_DIR"],env["PIOENV"]) + sdkconfig_h_path = join(env_build,"config","sdkconfig.h") + arduino_libs = ARDUINO_FRMWRK_LIB_DIR + lib_src = join(env_build,"esp-idf") + lib_dst = join(arduino_libs,mcu,"lib") + ld_dst = join(arduino_libs,mcu,"ld") + mem_var = join(arduino_libs,mcu,board.get("build.arduino.memory_type", (board.get("build.flash_mode", "dio") + "_qspi"))) + src = [join(lib_src,x) for x in os.listdir(lib_src)] + src = [folder for folder in src if not os.path.isfile(folder)] # folders only + for folder in src: + files = [join(folder,x) for x in os.listdir(folder)] + for file in files: + if file.strip().endswith(".a"): + shutil.copyfile(file,join(lib_dst,file.split(os.path.sep)[-1])) + + shutil.move(join(lib_dst,"libspi_flash.a"),join(mem_var,"libspi_flash.a")) + shutil.move(join(env_build,"memory.ld"),join(ld_dst,"memory.ld")) + if mcu == "esp32s3": + shutil.move(join(lib_dst,"libesp_psram.a"),join(mem_var,"libesp_psram.a")) + shutil.move(join(lib_dst,"libesp_system.a"),join(mem_var,"libesp_system.a")) + shutil.move(join(lib_dst,"libfreertos.a"),join(mem_var,"libfreertos.a")) + shutil.move(join(lib_dst,"libbootloader_support.a"),join(mem_var,"libbootloader_support.a")) + shutil.move(join(lib_dst,"libesp_hw_support.a"),join(mem_var,"libesp_hw_support.a")) + shutil.move(join(lib_dst,"libesp_lcd.a"),join(mem_var,"libesp_lcd.a")) + + shutil.copyfile(sdkconfig_h_path,join(mem_var,"include","sdkconfig.h")) + if not bool(os.path.isfile(join(arduino_libs,mcu,"sdkconfig.orig"))): + shutil.move(join(arduino_libs,mcu,"sdkconfig"),join(arduino_libs,mcu,"sdkconfig.orig")) + shutil.copyfile(join(env.subst("$PROJECT_DIR"),"sdkconfig."+env["PIOENV"]),join(arduino_libs,mcu,"sdkconfig")) + shutil.copyfile(join(env.subst("$PROJECT_DIR"),"sdkconfig."+env["PIOENV"]),join(arduino_libs,"sdkconfig")) + try: + os.remove(join(env.subst("$PROJECT_DIR"),"dependencies.lock")) + os.remove(join(env.subst("$PROJECT_DIR"),"CMakeLists.txt")) + except: + pass + print("*** Copied compiled %s IDF libraries to Arduino framework ***" % idf_variant) + + pio_exe_path = shutil.which("platformio"+(".exe" if IS_WINDOWS else "")) + pio_cmd = env["PIOENV"] + env.Execute( + env.VerboseAction( + ( + '"%s" run -e ' % pio_exe_path + + " ".join(['"%s"' % pio_cmd]) + ), + "*** Starting Arduino compile %s with custom libraries ***" % pio_cmd, + ) + ) + if flag_custom_component_add == True or flag_custom_component_remove == True: + try: + shutil.copy(join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml.orig"),join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml")) + print("*** Original Arduino \"idf_component.yml\" restored ***") + except: + print("*** Original Arduino \"idf_component.yml\" couldnt be restored ***") + env.AddPostAction("checkprogsize", idf_lib_copy) + +if "espidf" in env.get("PIOFRAMEWORK") and (flag_custom_component_add == True or flag_custom_component_remove == True): + def idf_custom_component(source, target, env): + try: + shutil.copy(join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml.orig"),join(ARDUINO_FRAMEWORK_DIR,"idf_component.yml")) + print("*** Original Arduino \"idf_component.yml\" restored ***") + except: + try: + shutil.copy(join(PROJECT_SRC_DIR,"idf_component.yml.orig"),join(PROJECT_SRC_DIR,"idf_component.yml")) + print("*** Original \"idf_component.yml\" restored ***") + except: # no "idf_component.yml" in source folder + try: + os.remove(join(PROJECT_SRC_DIR,"idf_component.yml")) + print("*** pioarduino generated \"idf_component.yml\" removed ***") + except: + print("*** \"idf_component.yml\" couldnt be removed ***") + env.AddPostAction("checkprogsize", idf_custom_component) +# # Process OTA partition and image # @@ -1733,7 +2178,10 @@ def _skip_prj_source_files(node): if ota_partition_params["size"] and ota_partition_params["offset"]: # Generate an empty image if OTA is enabled in partition table ota_partition_image = os.path.join("$BUILD_DIR", "ota_data_initial.bin") - generate_empty_partition_image(ota_partition_image, ota_partition_params["size"]) + if "arduino" in env.subst("$PIOFRAMEWORK"): + ota_partition_image = os.path.join(ARDUINO_FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin") + else: + generate_empty_partition_image(ota_partition_image, ota_partition_params["size"]) env.Append( FLASH_EXTRA_IMAGES=[ @@ -1745,18 +2193,61 @@ def _skip_prj_source_files(node): ) ] ) + EXTRA_IMG_DIR = join(env.subst("$PROJECT_DIR"), "variants", "tasmota") + env.Append( + FLASH_EXTRA_IMAGES=[ + (offset, join(EXTRA_IMG_DIR, img)) for offset, img in board.get("upload.arduino.flash_extra_images", []) + ] + ) + +def _parse_size(value): + if isinstance(value, int): + return value + elif value.isdigit(): + return int(value) + elif value.startswith("0x"): + return int(value, 16) + elif value[-1].upper() in ("K", "M"): + base = 1024 if value[-1].upper() == "K" else 1024 * 1024 + return int(value[:-1]) * base + return value # # Configure application partition offset # -env.Replace( - ESP32_APP_OFFSET=get_app_partition_offset( - env.subst("$PARTITIONS_TABLE_CSV"), partition_table_offset - ) -) +partitions_csv = env.subst("$PARTITIONS_TABLE_CSV") +result = [] +next_offset = 0 +bound = int(board.get("upload.offset_address", "0x10000"), 16) # default 0x10000 +with open(partitions_csv) as fp: + for line in fp.readlines(): + line = line.strip() + if not line or line.startswith("#"): + continue + tokens = [t.strip() for t in line.split(",")] + if len(tokens) < 5: + continue + partition = { + "name": tokens[0], + "type": tokens[1], + "subtype": tokens[2], + "offset": tokens[3] or next_offset, + "size": tokens[4], + "flags": tokens[5] if len(tokens) > 5 else None + } + result.append(partition) + next_offset = _parse_size(partition["offset"]) + if (partition["subtype"] == "ota_0"): + bound = next_offset + next_offset = (next_offset + bound - 1) & ~(bound - 1) + +env.Replace(ESP32_APP_OFFSET=str(hex(bound))) +# # Propagate application offset to debug configurations +# + env["INTEGRATION_EXTRA_DATA"].update( {"application_offset": env.subst("$ESP32_APP_OFFSET")} ) diff --git a/builder/frameworks/ulp.py b/builder/frameworks/ulp.py index 1a66c2bc9..7afa2efe5 100644 --- a/builder/frameworks/ulp.py +++ b/builder/frameworks/ulp.py @@ -13,6 +13,7 @@ # limitations under the License. import os +import sys from platformio import fs from platformio.util import get_systype @@ -20,7 +21,7 @@ from SCons.Script import Import -Import("env sdk_config project_config idf_variant") +Import("env sdk_config project_config app_includes idf_variant") ulp_env = env.Clone() platform = ulp_env.PioPlatform() @@ -36,31 +37,31 @@ def prepare_ulp_env_vars(env): toolchain_path = platform.get_package_dir( "toolchain-xtensa-esp-elf" - if "arduino" not in env.subst("$PIOFRAMEWORK") - else "toolchain-xtensa-%s" % idf_variant + if idf_variant not in ("esp32c6", "esp32p4") + else "toolchain-riscv32-esp" + ) + + toolchain_path_ulp = platform.get_package_dir( + "toolchain-esp32ulp" + if sdk_config.get("ULP_COPROC_TYPE_FSM", False) + else "" ) additional_packages = [ toolchain_path, - os.path.join( - platform.get_package_dir("toolchain-esp32ulp"), - "bin", - ), + toolchain_path_ulp, platform.get_package_dir("tool-ninja"), os.path.join(platform.get_package_dir("tool-cmake"), "bin"), os.path.dirname(where_is_program("python")), ] - if "windows" in get_systype(): - additional_packages.append(platform.get_package_dir("tool-mconf")) - for package in additional_packages: ulp_env.PrependENVPath("PATH", package) def collect_ulp_sources(): return [ - fs.to_unix_path(os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp", f)) + os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp", f) for f in os.listdir(os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp")) if f.endswith((".c", ".S", ".s")) ] @@ -82,9 +83,23 @@ def get_component_includes(target_config): def generate_ulp_config(target_config): def _generate_ulp_configuration_action(env, target, source): riscv_ulp_enabled = sdk_config.get("ULP_COPROC_TYPE_RISCV", False) + lp_core_ulp_enabled = sdk_config.get("ULP_COPROC_TYPE_LP_CORE", False) + + if lp_core_ulp_enabled == False: + ulp_toolchain = "toolchain-%sulp%s.cmake"% ( + "" if riscv_ulp_enabled else idf_variant + "-", + "-riscv" if riscv_ulp_enabled else "", + ) + else: + ulp_toolchain = "toolchain-lp-core-riscv.cmake" + + comp_includes = ";".join(get_component_includes(target_config)) + plain_includes = ";".join(app_includes["plain_includes"]) + comp_includes = comp_includes + plain_includes cmd = ( os.path.join(platform.get_package_dir("tool-cmake"), "bin", "cmake"), + "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", "-DCMAKE_GENERATOR=Ninja", "-DCMAKE_TOOLCHAIN_FILE=" + os.path.join( @@ -92,28 +107,28 @@ def _generate_ulp_configuration_action(env, target, source): "components", "ulp", "cmake", - "toolchain-%sulp%s.cmake" - % ( - "" if riscv_ulp_enabled else idf_variant + "-", - "-riscv" if riscv_ulp_enabled else "", - ), + ulp_toolchain, ), - "-DULP_S_SOURCES=%s" % ";".join([s.get_abspath() for s in source]), + "-DULP_S_SOURCES=%s" % ";".join([fs.to_unix_path(s.get_abspath()) for s in source]), "-DULP_APP_NAME=ulp_main", "-DCOMPONENT_DIR=" + os.path.join(ulp_env.subst("$PROJECT_DIR"), "ulp"), - "-DCOMPONENT_INCLUDES=%s" % ";".join(get_component_includes(target_config)), + "-DCOMPONENT_INCLUDES=" + comp_includes, "-DIDF_TARGET=%s" % idf_variant, "-DIDF_PATH=" + fs.to_unix_path(FRAMEWORK_DIR), "-DSDKCONFIG_HEADER=" + os.path.join(BUILD_DIR, "config", "sdkconfig.h"), "-DPYTHON=" + env.subst("$PYTHONEXE"), - "-DULP_COCPU_IS_RISCV=%s" % ("ON" if riscv_ulp_enabled else "OFF"), + "-DSDKCONFIG_CMAKE=" + os.path.join(BUILD_DIR, "config", "sdkconfig.cmake"), + "-DCMAKE_MODULE_PATH=" + fs.to_unix_path(os.path.join(FRAMEWORK_DIR, "components", "ulp", "cmake")), "-GNinja", "-B", ULP_BUILD_DIR, os.path.join(FRAMEWORK_DIR, "components", "ulp", "cmake"), ) - exec_command(cmd) + result = exec_command(cmd) + if result["returncode"] != 0: + sys.stderr.write(result["err"] + "\n") + env.Exit(1) ulp_sources = collect_ulp_sources() ulp_sources.sort() diff --git a/builder/main.py b/builder/main.py index 98ae15526..4c770f0c9 100644 --- a/builder/main.py +++ b/builder/main.py @@ -22,10 +22,14 @@ from platformio.util import get_serial_ports +env = DefaultEnvironment() +platform = env.PioPlatform() + # # Helpers # +FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") def BeforeUpload(target, source, env): upload_options = {} @@ -58,7 +62,6 @@ def _get_board_memory_type(env): ), ) - def _normalize_frequency(frequency): frequency = str(frequency).replace("L", "") return str(int(int(frequency) / 1000000)) + "m" @@ -76,7 +79,6 @@ def _get_board_f_image(env): return _get_board_f_flash(env) - def _get_board_f_boot(env): board_config = env.BoardConfig() if "build.f_boot" in board_config: @@ -86,7 +88,7 @@ def _get_board_f_boot(env): def _get_board_flash_mode(env): - if ["arduino"] == env.get("PIOFRAMEWORK") and _get_board_memory_type(env) in ( + if _get_board_memory_type(env) in ( "opi_opi", "opi_qspi", ): @@ -101,7 +103,7 @@ def _get_board_flash_mode(env): def _get_board_boot_mode(env): memory_type = env.BoardConfig().get("build.arduino.memory_type", "") build_boot = env.BoardConfig().get("build.boot", "$BOARD_FLASH_MODE") - if ["arduino"] == env.get("PIOFRAMEWORK") and memory_type in ("opi_opi", "opi_qspi"): + if memory_type in ("opi_opi", "opi_qspi"): build_boot = "opi" return build_boot @@ -128,9 +130,8 @@ def _parse_partitions(env): return result = [] - # The first offset is 0x9000 because partition table is flashed to 0x8000 and - # occupies an entire flash sector, which size is 0x1000 - next_offset = 0x9000 + next_offset = 0 + app_offset = int(board.get("upload.offset_address", "0x10000"), 16) # default 0x10000 with open(partitions_csv) as fp: for line in fp.readlines(): line = line.strip() @@ -139,7 +140,6 @@ def _parse_partitions(env): tokens = [t.strip() for t in line.split(",")] if len(tokens) < 5: continue - bound = 0x10000 if tokens[1] in ("0", "app") else 4 calculated_offset = (next_offset + bound - 1) & ~(bound - 1) partition = { @@ -151,10 +151,14 @@ def _parse_partitions(env): "flags": tokens[5] if len(tokens) > 5 else None } result.append(partition) - next_offset = _parse_size(partition["offset"]) + _parse_size( - partition["size"] - ) - + next_offset = _parse_size(partition["offset"]) + if (partition["subtype"] == "ota_0"): + app_offset = next_offset + next_offset = next_offset + _parse_size(partition["size"]) + # Configure application partition offset + env.Replace(ESP32_APP_OFFSET=str(hex(app_offset))) + # Propagate application offset to debug configurations + env["INTEGRATION_EXTRA_DATA"].update({"application_offset": str(hex(app_offset))}) return result @@ -181,17 +185,13 @@ def _update_max_upload_size(env): "table! Default partition will be used!" % custom_app_partition_name ) - # Otherwise, one of the `factory` or `ota_0` partitions is used to determine - # available memory size. If both partitions are set, we should prefer the `factory`, - # but there are cases (e.g. Adafruit's `partitions-4MB-tinyuf2.csv`) that uses the - # `factory` partition for their UF2 bootloader. So let's use the first match - # https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#subtype for p in partitions.values(): - if p["type"] in ("0", "app") and p["subtype"] in ("factory", "ota_0"): + if p["type"] in ("0", "app") and p["subtype"] in ("ota_0"): board.update("upload.maximum_size", _parse_size(p["size"])) break + def _to_unix_slashes(path): return path.replace("\\", "/") @@ -204,7 +204,7 @@ def _to_unix_slashes(path): def fetch_fs_size(env): fs = None for p in _parse_partitions(env): - if p["type"] == "data" and p["subtype"] in ("spiffs", "fat"): + if p["type"] == "data" and p["subtype"] in ("spiffs", "fat", "littlefs"): fs = p if not fs: sys.stderr.write( @@ -230,13 +230,11 @@ def __fetch_fs_size(target, source, env): return (target, source) -env = DefaultEnvironment() -platform = env.PioPlatform() board = env.BoardConfig() mcu = board.get("build.mcu", "esp32") toolchain_arch = "xtensa-%s" % mcu filesystem = board.get("build.filesystem", "spiffs") -if mcu in ("esp32c3", "esp32c6"): +if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"): toolchain_arch = "riscv32-esp" if "INTEGRATION_EXTRA_DATA" not in env: @@ -257,15 +255,14 @@ def __fetch_fs_size(target, source, env): GDB=join( platform.get_package_dir( "tool-riscv32-esp-elf-gdb" - if mcu in ("esp32c3", "esp32c6") + if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4") else "tool-xtensa-esp-elf-gdb" ) or "", "bin", "%s-elf-gdb" % toolchain_arch, - ) if env.get("PIOFRAMEWORK") == ["espidf"] else "%s-elf-gdb" % toolchain_arch, - OBJCOPY=join( - platform.get_package_dir("tool-esptoolpy") or "", "esptool.py"), + ), + OBJCOPY=join(platform.get_package_dir("tool-esptoolpy") or "", "esptool.py"), RANLIB="%s-elf-gcc-ranlib" % toolchain_arch, SIZETOOL="%s-elf-size" % toolchain_arch, @@ -302,7 +299,8 @@ def __fetch_fs_size(target, source, env): "ESP32_FS_IMAGE_NAME", env.get("ESP32_SPIFFS_IMAGE_NAME", filesystem) ), - ESP32_APP_OFFSET=board.get("upload.offset_address", "0x10000"), + ESP32_APP_OFFSET=env.get("INTEGRATION_EXTRA_DATA").get("application_offset"), + ARDUINO_LIB_COMPILE_FLAG="Inactive", PROGSUFFIX=".elf" ) @@ -315,7 +313,7 @@ def __fetch_fs_size(target, source, env): BUILDERS=dict( ElfToBin=Builder( action=env.VerboseAction(" ".join([ - '"$PYTHONEXE" "$OBJCOPY"', + '"$PYTHONEXE" "$OBJCOPY"', "--chip", mcu, "elf2image", "--flash_mode", "${__get_board_flash_mode(__env__)}", "--flash_freq", "${__get_board_f_image(__env__)}", @@ -335,7 +333,7 @@ def __fetch_fs_size(target, source, env): "-b", "$FS_BLOCK", ] - if filesystem in ("spiffs", "littlefs") + if filesystem in ("littlefs", "spiffs") else [] ) + ["$TARGET"] @@ -388,9 +386,6 @@ def __fetch_fs_size(target, source, env): env.VerboseAction( lambda source, target, env: _update_max_upload_size(env), "Retrieving maximum program size $SOURCES")) -# remove after PIO Core 3.6 release -elif set(["checkprogsize", "upload"]) & set(COMMAND_LINE_TARGETS): - _update_max_upload_size(env) # # Target: Print binary size @@ -432,9 +427,7 @@ def __fetch_fs_size(target, source, env): "See https://docs.platformio.org/page/platforms/" "espressif32.html#over-the-air-ota-update\n") env.Replace( - UPLOADER=join( - platform.get_package_dir("framework-arduinoespressif32") or "", - "tools", "espota.py"), + UPLOADER=join(FRAMEWORK_DIR,"tools", "espota.py"), UPLOADERFLAGS=["--debug", "--progress", "-i", "$UPLOAD_PORT"], UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS -f $SOURCE' ) @@ -455,7 +448,7 @@ def __fetch_fs_size(target, source, env): "write_flash", "-z", "--flash_mode", "${__get_board_flash_mode(__env__)}", "--flash_freq", "${__get_board_f_image(__env__)}", - "--flash_size", board.get("upload.flash_size", "detect") + "--flash_size", "detect" ], UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $ESP32_APP_OFFSET $SOURCE' ) @@ -473,7 +466,7 @@ def __fetch_fs_size(target, source, env): "write_flash", "-z", "--flash_mode", "${__get_board_flash_mode(__env__)}", "--flash_freq", "${__get_board_f_image(__env__)}", - "--flash_size", board.get("upload.flash_size", "detect"), + "--flash_size", "detect", "$FS_START" ], UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $SOURCE', @@ -484,7 +477,6 @@ def __fetch_fs_size(target, source, env): env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") ] - elif upload_protocol == "dfu": hwids = board.get("build.hwids", [["0x2341", "0x0070"]]) @@ -508,6 +500,7 @@ def __fetch_fs_size(target, source, env): elif upload_protocol in debug_tools: + _parse_partitions(env) openocd_args = ["-d%d" % (2 if int(ARGUMENTS.get("PIOVERBOSE", 0)) else 1)] openocd_args.extend( debug_tools.get(upload_protocol).get("server").get("arguments", [])) @@ -520,9 +513,7 @@ def __fetch_fs_size(target, source, env): % ( "$FS_START" if "uploadfs" in COMMAND_LINE_TARGETS - else board.get( - "upload.offset_address", "$ESP32_APP_OFFSET" - ) + else env.get("INTEGRATION_EXTRA_DATA").get("application_offset") ), ] ) @@ -562,6 +553,21 @@ def __fetch_fs_size(target, source, env): env.AddPlatformTarget( "uploadfsota", target_firm, upload_actions, "Upload Filesystem Image OTA") +# +# Target: Erase Flash and Upload +# + +env.AddPlatformTarget( + "erase_upload", + target_firm, + [ + env.VerboseAction(BeforeUpload, "Looking for upload port..."), + env.VerboseAction("$ERASECMD", "Erasing..."), + env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") + ], + "Erase Flash and Upload", +) + # # Target: Erase Flash # @@ -570,20 +576,12 @@ def __fetch_fs_size(target, source, env): "erase", None, [ - env.VerboseAction(env.AutodetectUploadPort, "Looking for serial port..."), + env.VerboseAction(BeforeUpload, "Looking for upload port..."), env.VerboseAction("$ERASECMD", "Erasing...") ], "Erase Flash", ) -# -# Information about obsolete method of specifying linker scripts -# - -if any("-Wl,-T" in f for f in env.get("LINKFLAGS", [])): - print("Warning! '-Wl,-T' option for specifying linker scripts is deprecated. " - "Please use 'board_build.ldscript' option in your 'platformio.ini' file.") - # # Override memory inspection behavior # diff --git a/code_of_conduct.md b/code_of_conduct.md new file mode 100644 index 000000000..d12204350 --- /dev/null +++ b/code_of_conduct.md @@ -0,0 +1,134 @@ + +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official email address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[pioarduino](https://github.com/pioarduino/platform-espressif32/issues/new/choose). +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations + diff --git a/examples/arduino-ble5-advertising/README.md b/examples/arduino-ble5-advertising/README.md deleted file mode 100644 index f34cc0db8..000000000 --- a/examples/arduino-ble5-advertising/README.md +++ /dev/null @@ -1,27 +0,0 @@ -How to build PlatformIO based project -===================================== - -1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) -2. Download [development platform with examples](https://github.com/platformio/platform-espressif32/archive/develop.zip) -3. Extract ZIP archive -4. Run these commands: - -```shell -# Change directory to example -$ cd platform-espressif32/examples/arduino-ble5-advertising - -# Build project -$ pio run - -# Upload firmware -$ pio run --target upload - -# Build specific environment -$ pio run -e esp32-c3-devkitm-1 - -# Upload firmware for the specific environment -$ pio run -e esp32-c3-devkitm-1 --target upload - -# Clean build files -$ pio run --target clean -``` \ No newline at end of file diff --git a/examples/arduino-ble5-advertising/src/BLE5_periodic_advertising.ino b/examples/arduino-ble5-advertising/src/BLE5_periodic_advertising.ino deleted file mode 100644 index 1b36bbb8b..000000000 --- a/examples/arduino-ble5-advertising/src/BLE5_periodic_advertising.ino +++ /dev/null @@ -1,72 +0,0 @@ -/* - Simple BLE5 multi advertising example on esp32 C3/S3 - only ESP_BLE_GAP_SET_EXT_ADV_PROP_NONCONN_NONSCANNABLE_UNDIRECTED can be used for periodic advertising - - author: chegewara -*/ - -#include -#include - - -esp_ble_gap_ext_adv_params_t ext_adv_params_2M = { - .type = ESP_BLE_GAP_SET_EXT_ADV_PROP_NONCONN_NONSCANNABLE_UNDIRECTED, - .interval_min = 0x40, - .interval_max = 0x40, - .channel_map = ADV_CHNL_ALL, - .own_addr_type = BLE_ADDR_TYPE_RANDOM, - .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, - .primary_phy = ESP_BLE_GAP_PHY_1M, - .max_skip = 0, - .secondary_phy = ESP_BLE_GAP_PHY_2M, - .sid = 1, - .scan_req_notif = false, -}; - -static uint8_t raw_scan_rsp_data_2m[] = { - 0x02, 0x01, 0x06, - 0x02, 0x0a, 0xeb, - 0x12, 0x09, 'E', 'S', 'P', '_', 'M', 'U', 'L', 'T', 'I', '_', 'A', - 'D', 'V', '_', '2', 'M', 0X0 -}; - -static esp_ble_gap_periodic_adv_params_t periodic_adv_params = { - .interval_min = 0x320, // 1000 ms interval - .interval_max = 0x640, - .properties = 0, // Do not include TX power -}; - -static uint8_t periodic_adv_raw_data[] = { - 0x02, 0x01, 0x06, - 0x02, 0x0a, 0xeb, - 0x03, 0x03, 0xab, 0xcd, - 0x11, 0x09, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I', - 'C', '_', 'A', 'D', 'V' -}; - - -uint8_t addr_2m[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x02}; - -BLEMultiAdvertising advert(1); // max number of advertisement data - -void setup() { - Serial.begin(115200); - Serial.println("Multi-Advertising..."); - - BLEDevice::init(""); - - advert.setAdvertisingParams(0, &ext_adv_params_2M); - advert.setAdvertisingData(0, sizeof(raw_scan_rsp_data_2m), &raw_scan_rsp_data_2m[0]); - advert.setInstanceAddress(0, addr_2m); - advert.setDuration(0, 0, 0); - - delay(100); - advert.start(); - advert.setPeriodicAdvertisingParams(0, &periodic_adv_params); - advert.setPeriodicAdvertisingData(0, sizeof(periodic_adv_raw_data), &periodic_adv_raw_data[0]); - advert.startPeriodicAdvertising(0); -} - -void loop() { - delay(2000); -} diff --git a/examples/arduino-blink/.travis.yml b/examples/arduino-blink/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/arduino-blink/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/arduino-blink/README.md b/examples/arduino-blink/README.md index 8f42ed5c7..1573f15cd 100644 --- a/examples/arduino-blink/README.md +++ b/examples/arduino-blink/README.md @@ -1,7 +1,7 @@ How to build PlatformIO based project ===================================== -1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) +1. [Install PlatformIO Core](http://docs.platformio.org/page/core.html) 2. Download [development platform with examples](https://github.com/platformio/platform-espressif32/archive/develop.zip) 3. Extract ZIP archive 4. Run these commands: diff --git a/examples/arduino-blink/platformio.ini b/examples/arduino-blink/platformio.ini index fa67ab603..8fe2201b7 100644 --- a/examples/arduino-blink/platformio.ini +++ b/examples/arduino-blink/platformio.ini @@ -5,47 +5,123 @@ ; Library options: dependencies, extra library storages ; ; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html +; http://docs.platformio.org/page/projectconf.html -[env:esp-wrover-kit] +[env:esp32solo1] platform = espressif32 framework = arduino -board = esp-wrover-kit -monitor_speed = 115200 -build_flags = - ; https://docs.espressif.com/projects/esp-idf/en/latest/get-started/get-started-wrover-kit.html#rgb-led - -D LED_BUILTIN=2 +board = esp32-solo1 +build_flags = -DLED_BUILTIN=2 +custom_component_remove = + espressif/esp_hosted + espressif/esp_wifi_remote + espressif/esp-dsp + espressif/esp32-camera + espressif/libsodium + espressif/esp-modbus + espressif/qrcode + espressif/esp_insights + espressif/esp_diag_data_store + espressif/esp_diagnostics + espressif/esp_rainmaker + espressif/rmaker_common -[env:esp32doit-devkit-v1] +[env:esp32-c2-devkitm-1] platform = espressif32 framework = arduino -board = esp32doit-devkit-v1 +board = esp32-c2-devkitm-1 monitor_speed = 115200 +custom_component_remove = espressif/esp_hosted + espressif/esp_wifi_remote + espressif/esp-dsp + espressif/esp32-camera + espressif/libsodium + espressif/esp-modbus + espressif/qrcode + espressif/esp_insights + espressif/esp_diag_data_store + espressif/esp_diagnostics + espressif/esp_rainmaker + espressif/rmaker_common -[env:lolin32] +[env:esp32-s3-arduino_nano_esp32] platform = espressif32 framework = arduino -board = lolin32 +board = arduino_nano_esp32 monitor_speed = 115200 +custom_component_remove = espressif/esp_hosted + espressif/esp_wifi_remote + espressif/esp-dsp + espressif/esp32-camera + espressif/libsodium + espressif/esp-modbus + espressif/qrcode + espressif/esp_insights + espressif/esp_diag_data_store + espressif/esp_diagnostics + espressif/esp_rainmaker + espressif/rmaker_common -[env:lolin_c3_mini] +[env:esp32s3-qio_opi_per] +; OPI Performance settings -> Display use platform = espressif32 framework = arduino -board = lolin_c3_mini -monitor_speed = 115200 +board = esp32s3_120_16_8-qio_opi +custom_sdkconfig = CONFIG_SPIRAM_MODE_OCT=y + CONFIG_SPIRAM_SPEED_120M=y + CONFIG_LCD_RGB_ISR_IRAM_SAFE=y + CONFIG_GDMA_CTRL_FUNC_IN_IRAM=y + CONFIG_I2S_ISR_IRAM_SAFE=y + CONFIG_GDMA_ISR_IRAM_SAFE=y + CONFIG_SPIRAM_XIP_FROM_PSRAM=y + CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y + CONFIG_SPIRAM_RODATA=y + CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y + CONFIG_ESP32S3_DATA_CACHE_64KB=y + CONFIG_ESP32S3_DATA_CACHE_LINE_64B=y +custom_component_remove = espressif/esp_hosted + espressif/esp_wifi_remote + espressif/qrcode + espressif/esp_insights + espressif/esp_diag_data_store + espressif/esp_diagnostics + espressif/esp_rainmaker + espressif/rmaker_common +custom_component_add = lvgl/lvgl @ ^9.2.2 -[env:esp32-s3-devkitc-1] +[env:esp32-c6-devkitc-1] platform = espressif32 framework = arduino -board = esp32-s3-devkitc-1 +board = esp32-c6-devkitc-1 monitor_speed = 115200 +custom_component_remove = espressif/esp_hosted + espressif/esp_wifi_remote + espressif/mdns + espressif/esp-dsp + espressif/esp_modem + espressif/esp32-camera -[env:arduino_nano_esp32] +[env:esp32-h2-devkitm-1] platform = espressif32 framework = arduino -board = arduino_nano_esp32 +board = esp32-h2-devkitm-1 +monitor_speed = 115200 +custom_component_remove = espressif/esp_hosted + espressif/esp_wifi_remote + espressif/mdns + espressif/esp-dsp + espressif/esp_modem + espressif/esp32-camera -[env:adafruit_qtpy_esp32s3_n4r2] +[env:esp32-p4] platform = espressif32 -board = adafruit_qtpy_esp32s3_n4r2 framework = arduino +board = esp32-p4 +build_flags = -DLED_BUILTIN=2 +monitor_speed = 115200 +custom_component_remove = espressif/esp_hosted + espressif/esp_wifi_remote + espressif/mdns + espressif/esp-dsp + espressif/esp_modem + espressif/esp32-camera diff --git a/examples/arduino-blink/src/Blink.cpp b/examples/arduino-blink/src/Blink.cpp index 5981d69d3..1b1c30f8d 100644 --- a/examples/arduino-blink/src/Blink.cpp +++ b/examples/arduino-blink/src/Blink.cpp @@ -7,9 +7,7 @@ #include // Set LED_BUILTIN if it is not defined by Arduino framework -#ifndef LED_BUILTIN - #define LED_BUILTIN 2 -#endif +// #define LED_BUILTIN 2 void setup() { diff --git a/examples/arduino-ble5-advertising/include/README b/examples/arduino-matter-light/include/README similarity index 100% rename from examples/arduino-ble5-advertising/include/README rename to examples/arduino-matter-light/include/README diff --git a/examples/arduino-ble5-advertising/lib/README b/examples/arduino-matter-light/lib/README similarity index 100% rename from examples/arduino-ble5-advertising/lib/README rename to examples/arduino-matter-light/lib/README diff --git a/examples/arduino-ble5-advertising/platformio.ini b/examples/arduino-matter-light/platformio.ini similarity index 71% rename from examples/arduino-ble5-advertising/platformio.ini rename to examples/arduino-matter-light/platformio.ini index 638c205b6..fca1f7a22 100644 --- a/examples/arduino-ble5-advertising/platformio.ini +++ b/examples/arduino-matter-light/platformio.ini @@ -5,10 +5,12 @@ ; Library options: dependencies, extra library storages ; ; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html +; http://docs.platformio.org/page/projectconf.html -[env:esp32-c3-devkitm-1] + +[env:esp32-c6-devkitc-1] platform = espressif32 -board = esp32-c3-devkitm-1 framework = arduino +board_build.partitions = huge_app.csv +board = esp32-c6-devkitc-1 monitor_speed = 115200 diff --git a/examples/arduino-matter-light/src/.gitignore b/examples/arduino-matter-light/src/.gitignore new file mode 100644 index 000000000..89cc49cbd --- /dev/null +++ b/examples/arduino-matter-light/src/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/examples/arduino-matter-light/src/MatterColorLight.ino b/examples/arduino-matter-light/src/MatterColorLight.ino new file mode 100644 index 000000000..dd1724f60 --- /dev/null +++ b/examples/arduino-matter-light/src/MatterColorLight.ino @@ -0,0 +1,180 @@ +// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Matter Manager +#include +#include +#include + +// List of Matter Endpoints for this Node +// Color Light Endpoint +MatterColorLight ColorLight; + +// WiFi is manually set and started +const char *ssid = "your-ssid"; // Change this to your WiFi SSID +const char *password = "your-password"; // Change this to your WiFi password + +// it will keep last OnOff & HSV Color state stored, using Preferences +Preferences matterPref; +const char *onOffPrefKey = "OnOff"; +const char *hsvColorPrefKey = "HSV"; + +// set your board RGB LED pin here +#ifdef RGB_BUILTIN +const uint8_t ledPin = RGB_BUILTIN; +#else +const uint8_t ledPin = 2; // Set your pin here if your board has not defined LED_BUILTIN +#warning "Do not forget to set the RGB LED pin" +#endif + +// set your board USER BUTTON pin here +const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button. + +// Button control +uint32_t button_time_stamp = 0; // debouncing control +bool button_state = false; // false = released | true = pressed +const uint32_t debouceTime = 250; // button debouncing time (ms) +const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission + +// Set the RGB LED Light based on the current state of the Color Light +bool setLightState(bool state, espHsvColor_t colorHSV) { + + if (state) { +#ifdef RGB_BUILTIN + espRgbColor_t rgbColor = espHsvColorToRgbColor(colorHSV); + // set the RGB LED + rgbLedWrite(ledPin, rgbColor.r, rgbColor.g, rgbColor.b); +#else + // No Color RGB LED, just use the HSV value (brightness) to control the LED + analogWrite(ledPin, colorHSV.v); +#endif + } else { + digitalWrite(ledPin, LOW); + } + // store last HSV Color and OnOff state for when the Light is restarted / power goes off + matterPref.putBool(onOffPrefKey, state); + matterPref.putUInt(hsvColorPrefKey, colorHSV.h << 16 | colorHSV.s << 8 | colorHSV.v); + // This callback must return the success state to Matter core + return true; +} + +void setup() { + // Initialize the USER BUTTON (Boot button) GPIO that will act as a toggle switch + pinMode(buttonPin, INPUT_PULLUP); + // Initialize the LED (light) GPIO and Matter End Point + pinMode(ledPin, OUTPUT); + + Serial.begin(115200); + + // We start by connecting to a WiFi network + Serial.print("Connecting to "); + Serial.println(ssid); + // Manually connect to WiFi + WiFi.begin(ssid, password); + // Wait for connection + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println("\r\nWiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + delay(500); + + // Initialize Matter EndPoint + matterPref.begin("MatterPrefs", false); + // default OnOff state is ON if not stored before + bool lastOnOffState = matterPref.getBool(onOffPrefKey, true); + // default HSV color is blue HSV(169, 254, 254) + uint32_t prefHsvColor = matterPref.getUInt(hsvColorPrefKey, 169 << 16 | 254 << 8 | 254); + espHsvColor_t lastHsvColor = {uint8_t(prefHsvColor >> 16), uint8_t(prefHsvColor >> 8), uint8_t(prefHsvColor)}; + ColorLight.begin(lastOnOffState, lastHsvColor); + // set the callback function to handle the Light state change + ColorLight.onChange(setLightState); + + // lambda functions are used to set the attribute change callbacks + ColorLight.onChangeOnOff([](bool state) { + Serial.printf("Light OnOff changed to %s\r\n", state ? "ON" : "OFF"); + return true; + }); + ColorLight.onChangeColorHSV([](HsvColor_t hsvColor) { + Serial.printf("Light HSV Color changed to (%d,%d,%d)\r\n", hsvColor.h, hsvColor.s, hsvColor.v); + return true; + }); + + // Matter beginning - Last step, after all EndPoints are initialized + Matter.begin(); + // This may be a restart of a already commissioned Matter accessory + if (Matter.isDeviceCommissioned()) { + Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use."); + Serial.printf( + "Initial state: %s | RGB Color: (%d,%d,%d) \r\n", ColorLight ? "ON" : "OFF", ColorLight.getColorRGB().r, ColorLight.getColorRGB().g, + ColorLight.getColorRGB().b + ); + // configure the Light based on initial on-off state and its color + ColorLight.updateAccessory(); + } +} + +void loop() { + // Check Matter Light Commissioning state, which may change during execution of loop() + if (!Matter.isDeviceCommissioned()) { + Serial.println(""); + Serial.println("Matter Node is not commissioned yet."); + Serial.println("Initiate the device discovery in your Matter environment."); + Serial.println("Commission it to your Matter hub with the manual pairing code or QR code"); + Serial.printf("Manual pairing code: %s\r\n", Matter.getManualPairingCode().c_str()); + Serial.printf("QR code URL: %s\r\n", Matter.getOnboardingQRCodeUrl().c_str()); + // waits for Matter Light Commissioning. + uint32_t timeCount = 0; + while (!Matter.isDeviceCommissioned()) { + delay(100); + if ((timeCount++ % 50) == 0) { // 50*100ms = 5 sec + Serial.println("Matter Node not commissioned yet. Waiting for commissioning."); + } + } + Serial.printf( + "Initial state: %s | RGB Color: (%d,%d,%d) \r\n", ColorLight ? "ON" : "OFF", ColorLight.getColorRGB().r, ColorLight.getColorRGB().g, + ColorLight.getColorRGB().b + ); + // configure the Light based on initial on-off state and its color + ColorLight.updateAccessory(); + Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use."); + } + + // A button is also used to control the light + // Check if the button has been pressed + if (digitalRead(buttonPin) == LOW && !button_state) { + // deals with button debouncing + button_time_stamp = millis(); // record the time while the button is pressed. + button_state = true; // pressed. + } + + // Onboard User Button is used as a Light toggle switch or to decommission it + uint32_t time_diff = millis() - button_time_stamp; + if (digitalRead(buttonPin) == HIGH && button_state && time_diff > debouceTime) { + // Toggle button is released - toggle the light + Serial.println("User button released. Toggling Light!"); + ColorLight.toggle(); // Matter Controller also can see the change + button_state = false; // released + } + + // Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node + if (button_state && time_diff > decommissioningTimeout) { + Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again."); + ColorLight = false; // turn the light off + Matter.decommission(); + button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so + } +} diff --git a/examples/arduino-ble5-advertising/test/README b/examples/arduino-matter-light/test/README similarity index 100% rename from examples/arduino-ble5-advertising/test/README rename to examples/arduino-matter-light/test/README diff --git a/examples/arduino-rmt-blink/platformio.ini b/examples/arduino-rmt-blink/platformio.ini new file mode 100644 index 000000000..e3c6beacd --- /dev/null +++ b/examples/arduino-rmt-blink/platformio.ini @@ -0,0 +1,27 @@ +[env:esp32-s2] +platform = espressif32 +framework = arduino +board = esp32-s2-saola-1 +build_flags = -DBUILTIN_RGBLED_PIN=18 + -DNR_OF_LEDS=1 + +[env:esp32-s3] +platform = espressif32 +framework = arduino +board = esp32-s3-devkitc-1 +build_flags = -DBUILTIN_RGBLED_PIN=48 + -DNR_OF_LEDS=1 + +[env:esp32-c3] +platform = espressif32 +framework = arduino +board = esp32-c3-devkitm-1 +build_flags = -DBUILTIN_RGBLED_PIN=8 + -DNR_OF_LEDS=1 + +[env:esp32-c6] +platform = espressif32 +framework = arduino +board = esp32-c6-devkitm-1 +build_flags = -DBUILTIN_RGBLED_PIN=8 + -DNR_OF_LEDS=1 diff --git a/examples/arduino-rmt-blink/src/RMTWriteNeoPixel.ino b/examples/arduino-rmt-blink/src/RMTWriteNeoPixel.ino new file mode 100644 index 000000000..dbc183884 --- /dev/null +++ b/examples/arduino-rmt-blink/src/RMTWriteNeoPixel.ino @@ -0,0 +1,103 @@ +// Copyright 2023 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @brief This example demonstrates usage of RGB LED driven by RMT + * + * The output is a visual WS2812 RGB LED color moving in a 8 x 4 LED matrix + * Parameters can be changed by the user. In a single LED circuit, it will just blink. + */ + +// The effect seen in ESP32C3, ESP32S2 and ESP32S3 is like a Blink of RGB LED +//#if CONFIG_IDF_TARGET_ESP32S2 +//#define BUILTIN_RGBLED_PIN 18 +//#elif CONFIG_IDF_TARGET_ESP32S3 +//#define BUILTIN_RGBLED_PIN 48 // 48 or 38 +//#elif CONFIG_IDF_TARGET_ESP32C3 +//#define BUILTIN_RGBLED_PIN 8 +//#else +//#define BUILTIN_RGBLED_PIN 21 // ESP32 has no builtin RGB LED +//#endif + +//#define NR_OF_LEDS 8*4 +#define NR_OF_ALL_BITS 24*NR_OF_LEDS + +// +// Note: This example uses Neopixel LED board, 32 LEDs chained one +// after another, each RGB LED has its 24 bit value +// for color configuration (8b for each color) +// +// Bits encoded as pulses as follows: +// +// "0": +// +-------+ +-- +// | | | +// | | | +// | | | +// ---| |--------------| +// + + + +// | 0.4us | 0.85 0us | +// +// "1": +// +-------------+ +-- +// | | | +// | | | +// | | | +// | | | +// ---+ +-------+ +// | 0.8us | 0.4us | + +rmt_data_t led_data[NR_OF_ALL_BITS]; + +void setup() { + Serial.begin(115200); + if (!rmtInit(BUILTIN_RGBLED_PIN, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) { + Serial.println("init sender failed\n"); + } + Serial.println("real tick set to: 100ns"); +} + +int color[] = { 0x55, 0x11, 0x77 }; // Green Red Blue values +int led_index = 0; + +void loop() { + // Init data with only one led ON + int led, col, bit; + int i=0; + for (led=0; led=NR_OF_LEDS) { + led_index = 0; + } + // Send the data and wait until it is done + rmtWrite(BUILTIN_RGBLED_PIN, led_data, NR_OF_ALL_BITS, RMT_WAIT_FOR_EVER); + delay(100); +} diff --git a/examples/arduino-usb-keyboard/platformio.ini b/examples/arduino-usb-keyboard/platformio.ini index 3f51b8378..434e1a6f3 100644 --- a/examples/arduino-usb-keyboard/platformio.ini +++ b/examples/arduino-usb-keyboard/platformio.ini @@ -14,6 +14,3 @@ monitor_speed = 115200 [env:esp32-s2-saola-1] board = esp32-s2-saola-1 - -[env:esp32-s2-kaluga-1] -board = esp32-s2-kaluga-1 \ No newline at end of file diff --git a/examples/arduino-wifiscan/.travis.yml b/examples/arduino-wifiscan/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/arduino-wifiscan/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/arduino-wifiscan/README.md b/examples/arduino-wifiscan/README.md index 35564a6b9..785231de3 100644 --- a/examples/arduino-wifiscan/README.md +++ b/examples/arduino-wifiscan/README.md @@ -1,7 +1,7 @@ How to build PlatformIO based project ===================================== -1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) +1. [Install PlatformIO Core](http://docs.platformio.org/page/core.html) 2. Download [development platform with examples](https://github.com/platformio/platform-espressif32/archive/develop.zip) 3. Extract ZIP archive 4. Run these commands: diff --git a/examples/arduino-wifiscan/platformio.ini b/examples/arduino-wifiscan/platformio.ini index 2b88d2a7d..38cd6b894 100644 --- a/examples/arduino-wifiscan/platformio.ini +++ b/examples/arduino-wifiscan/platformio.ini @@ -5,28 +5,10 @@ ; Library options: dependencies, extra library storages ; ; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:esp32dev] -platform = espressif32 -framework = arduino -board = esp32dev -monitor_speed = 115200 +; http://docs.platformio.org/page/projectconf.html [env:esp-wrover-kit] platform = espressif32 framework = arduino board = esp-wrover-kit monitor_speed = 115200 - -[env:espea32] -platform = espressif32 -framework = arduino -board = espea32 -monitor_speed = 115200 - -[env:esp320] -platform = espressif32 -framework = arduino -board = esp320 -monitor_speed = 115200 diff --git a/examples/arduino-zigbee-light/README.md b/examples/arduino-zigbee-light/README.md new file mode 100644 index 000000000..1b9d9725a --- /dev/null +++ b/examples/arduino-zigbee-light/README.md @@ -0,0 +1,65 @@ +# Arduino-ESP32 Zigbee On/Off Light Example + +This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) on/off light. + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## Hardware Required + +* One development board (ESP32-H2 or ESP32-C6) acting as Zigbee coordinator (loaded with Zigbee_On_Off_switch example) +* A USB cable for power supply and programming +* Choose another board (ESP32-H2 or ESP32-C6) as Zigbee end device and upload the Zigbee_On_Off_Light example + +### Configure the Project + +Set the LED GPIO by changing the `LED_PIN` definition. By default, the LED_PIN is `RGB_BUILTIN`. +By default, the `neoPixelWrite` function is used to control the LED. You can change it to digitalWrite to control a simple LED. + +#### Using Arduino IDE + +To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits). + +* Before Compile/Verify, select the correct board: `Tools -> Board`. +* Select the End device Zigbee mode: `Tools -> Zigbee mode: Zigbee ED (end device)` +* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs` +* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port. + +## Troubleshooting + +If the End device flashed with this example is not connecting to the coordinator, erase the flash before flashing it to the board. It is recommended to do this if you did changes to the coordinator. +You can do the following: + +* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled` +* In the sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function. + +By default, the coordinator network is open for 180s after rebooting or flashing new firmware. After that, the network is closed for adding new devices. +You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function. + +***Important: Make sure you are using a good quality USB cable and that you have a reliable power source*** + +* **LED not blinking:** Check the wiring connection and the IO selection. +* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed. +* **COM port not detected:** Check the USB cable and the USB to Serial driver installation. + +If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute). + +## Contribute + +To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst) + +If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome! + +Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else. + +## Resources + +* Official ESP32 Forum: [Link](https://esp32.com) +* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) +* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf) +* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf) +* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com) diff --git a/examples/espidf-ble-eddystone/include/README b/examples/arduino-zigbee-light/include/README similarity index 100% rename from examples/espidf-ble-eddystone/include/README rename to examples/arduino-zigbee-light/include/README diff --git a/examples/espidf-ble-eddystone/lib/README b/examples/arduino-zigbee-light/lib/README similarity index 100% rename from examples/espidf-ble-eddystone/lib/README rename to examples/arduino-zigbee-light/lib/README diff --git a/examples/espidf-ble-eddystone/platformio.ini b/examples/arduino-zigbee-light/platformio.ini similarity index 55% rename from examples/espidf-ble-eddystone/platformio.ini rename to examples/arduino-zigbee-light/platformio.ini index 6d6af7407..2160dc35f 100644 --- a/examples/espidf-ble-eddystone/platformio.ini +++ b/examples/arduino-zigbee-light/platformio.ini @@ -5,10 +5,16 @@ ; Library options: dependencies, extra library storages ; ; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html +; http://docs.platformio.org/page/projectconf.html -[env:esp32dev] + +[env:esp32-h2-devkitm-1] platform = espressif32 -framework = espidf -board = esp32dev +framework = arduino +board = esp32-h2-devkitm-1 monitor_speed = 115200 +board_build.partitions = zigbee.csv +board_build.filesystem = spiffs +build_flags = + -DZIGBEE_MODE_ED + -DCORE_DEBUG_LEVEL=5 diff --git a/examples/arduino-zigbee-light/src/Zigbee_On_Off_Light.ino b/examples/arduino-zigbee-light/src/Zigbee_On_Off_Light.ino new file mode 100644 index 000000000..6db8bd7b0 --- /dev/null +++ b/examples/arduino-zigbee-light/src/Zigbee_On_Off_Light.ino @@ -0,0 +1,101 @@ +// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @brief This example demonstrates simple Zigbee light bulb. + * + * The example demonstrates how to use Zigbee library to create a end device light bulb. + * The light bulb is a Zigbee end device, which is controlled by a Zigbee coordinator. + * + * Proper Zigbee mode must be selected in Tools->Zigbee mode + * and also the correct partition scheme must be selected in Tools->Partition Scheme. + * + * Please check the README.md for instructions and more detailed description. + * + * Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/) + */ + +#ifndef ZIGBEE_MODE_ED +#error "Zigbee end device mode is not selected in Tools->Zigbee mode" +#endif + +#include "Zigbee.h" + +/* Zigbee light bulb configuration */ +#define ZIGBEE_LIGHT_ENDPOINT 10 +uint8_t led = RGB_BUILTIN; +uint8_t button = BOOT_PIN; + +ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT); + +/********************* RGB LED functions **************************/ +void setLED(bool value) { + digitalWrite(led, value); +} + +/********************* Arduino functions **************************/ +void setup() { + Serial.begin(115200); + + // Init LED and turn it OFF (if LED_PIN == RGB_BUILTIN, the rgbLedWrite() will be used under the hood) + pinMode(led, OUTPUT); + digitalWrite(led, LOW); + + // Init button for factory reset + pinMode(button, INPUT_PULLUP); + + //Optional: set Zigbee device name and model + zbLight.setManufacturerAndModel("Espressif", "ZBLightBulb"); + + // Set callback function for light change + zbLight.onLightChange(setLED); + + //Add endpoint to Zigbee Core + Serial.println("Adding ZigbeeLight endpoint to Zigbee Core"); + Zigbee.addEndpoint(&zbLight); + + // When all EPs are registered, start Zigbee. By default acts as ZIGBEE_END_DEVICE + if (!Zigbee.begin()) { + Serial.println("Zigbee failed to start!"); + Serial.println("Rebooting..."); + ESP.restart(); + } + Serial.println("Connecting to network"); + while (!Zigbee.connected()) { + Serial.print("."); + delay(100); + } + Serial.println(); +} + +void loop() { + // Checking button for factory reset + if (digitalRead(button) == LOW) { // Push button pressed + // Key debounce handling + delay(100); + int startTime = millis(); + while (digitalRead(button) == LOW) { + delay(50); + if ((millis() - startTime) > 3000) { + // If key pressed for more than 3secs, factory reset Zigbee and reboot + Serial.println("Resetting Zigbee to factory and rebooting in 1s."); + delay(1000); + Zigbee.factoryReset(); + } + } + // Toggle light by pressing the button + zbLight.setLight(!zbLight.getLightState()); + } + delay(100); +} diff --git a/examples/espidf-ble-eddystone/test/README b/examples/arduino-zigbee-light/test/README similarity index 100% rename from examples/espidf-ble-eddystone/test/README rename to examples/arduino-zigbee-light/test/README diff --git a/examples/arduino-zigbee-switch/README.md b/examples/arduino-zigbee-switch/README.md new file mode 100644 index 000000000..90a95c3fc --- /dev/null +++ b/examples/arduino-zigbee-switch/README.md @@ -0,0 +1,65 @@ +# Arduino-ESP32 Zigbee On/Off Light Switch Example + +This example shows how to configure Zigbee Coordinator and use it as a Home Automation (HA) on/off light switch. + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## Hardware Required + +* One development board (ESP32-H2 or ESP32-C6) acting as Zigbee end device (loaded with Zigbee_On_Off_Light example). +* A USB cable for power supply and programming. +* Choose another board (ESP32-H2 or ESP32-C6) as Zigbee coordinator and upload the Zigbee_On_Off_Switch example. + +### Configure the Project + +Set the Button Switch GPIO by changing the `GPIO_INPUT_IO_TOGGLE_SWITCH` definition. By default, it's the pin `9` (BOOT button on ESP32-C6 and ESP32-H2). + +#### Using Arduino IDE + +To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits). + +* Before Compile/Verify, select the correct board: `Tools -> Board`. +* Select the Coordinator Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator/router)`. +* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`. +* Select the COM port: `Tools -> Port: xxx where the `xxx` is the detected COM port. +* Optional: Set debug level to info to see logs from Zigbee stack: `Tools -> Core Debug Level: Info`. + +## Troubleshooting + +If the End device flashed with the example `Zigbee_Light_Bulb` is not connecting to the coordinator, erase the flash of the End device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator. +You can do the following: + +* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`. +* In the `Zigbee_Light_Bulb` example sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function. + +By default, the coordinator network is open for 180s after rebooting or flashing new firmware. After that, the network is closed for adding new devices. +You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function. + +***Important: Make sure you are using a good quality USB cable and that you have a reliable power source*** + +* **LED not blinking:** Check the wiring connection and the IO selection. +* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed. +* **COM port not detected:** Check the USB cable and the USB to Serial driver installation. + +If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute). + +## Contribute + +To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst) + +If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome! + +Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else. + +## Resources + +* Official ESP32 Forum: [Link](https://esp32.com) +* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) +* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf) +* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf) +* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com) diff --git a/examples/espidf-storage-spiffs/include/README b/examples/arduino-zigbee-switch/include/README similarity index 100% rename from examples/espidf-storage-spiffs/include/README rename to examples/arduino-zigbee-switch/include/README diff --git a/examples/espidf-storage-spiffs/lib/README b/examples/arduino-zigbee-switch/lib/README similarity index 100% rename from examples/espidf-storage-spiffs/lib/README rename to examples/arduino-zigbee-switch/lib/README diff --git a/examples/arduino-zigbee-switch/platformio.ini b/examples/arduino-zigbee-switch/platformio.ini new file mode 100644 index 000000000..0c3ce6a38 --- /dev/null +++ b/examples/arduino-zigbee-switch/platformio.ini @@ -0,0 +1,20 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + + +[env:esp32-c6-devkitc-1] +platform = espressif32 +framework = arduino +board = esp32-c6-devkitc-1 +monitor_speed = 115200 +board_build.partitions = zigbee_zczr.csv +board_build.filesystem = spiffs +build_flags = + -DZIGBEE_MODE_ZCZR + -DCORE_DEBUG_LEVEL=5 diff --git a/examples/arduino-zigbee-switch/src/Zigbee_On_Off_Switch.ino b/examples/arduino-zigbee-switch/src/Zigbee_On_Off_Switch.ino new file mode 100644 index 000000000..56d23cdc9 --- /dev/null +++ b/examples/arduino-zigbee-switch/src/Zigbee_On_Off_Switch.ino @@ -0,0 +1,192 @@ +// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @brief This example demonstrates simple Zigbee light switch. + * + * The example demonstrates how to use Zigbee library to control a light bulb. + * The light bulb is a Zigbee end device, which is controlled by a Zigbee coordinator (Switch). + * Button switch and Zigbee runs in separate tasks. + * + * Proper Zigbee mode must be selected in Tools->Zigbee mode + * and also the correct partition scheme must be selected in Tools->Partition Scheme. + * + * Please check the README.md for instructions and more detailed description. + * + * Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/) + */ + +#ifndef ZIGBEE_MODE_ZCZR +#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode" +#endif + +#include "Zigbee.h" + +/* Zigbee switch configuration */ +#define SWITCH_ENDPOINT_NUMBER 5 + +#define GPIO_INPUT_IO_TOGGLE_SWITCH BOOT_PIN +#define PAIR_SIZE(TYPE_STR_PAIR) (sizeof(TYPE_STR_PAIR) / sizeof(TYPE_STR_PAIR[0])) + +typedef enum { + SWITCH_ON_CONTROL, + SWITCH_OFF_CONTROL, + SWITCH_ONOFF_TOGGLE_CONTROL, + SWITCH_LEVEL_UP_CONTROL, + SWITCH_LEVEL_DOWN_CONTROL, + SWITCH_LEVEL_CYCLE_CONTROL, + SWITCH_COLOR_CONTROL, +} SwitchFunction; + +typedef struct { + uint8_t pin; + SwitchFunction func; +} SwitchData; + +typedef enum { + SWITCH_IDLE, + SWITCH_PRESS_ARMED, + SWITCH_PRESS_DETECTED, + SWITCH_PRESSED, + SWITCH_RELEASE_DETECTED, +} SwitchState; + +static SwitchData buttonFunctionPair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ONOFF_TOGGLE_CONTROL}}; + +ZigbeeSwitch zbSwitch = ZigbeeSwitch(SWITCH_ENDPOINT_NUMBER); + +/********************* Zigbee functions **************************/ +static void onZbButton(SwitchData *button_func_pair) { + if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) { + // Send toggle command to the light + Serial.println("Toggling light"); + zbSwitch.lightToggle(); + } +} + +/********************* GPIO functions **************************/ +static QueueHandle_t gpio_evt_queue = NULL; + +static void IRAM_ATTR onGpioInterrupt(void *arg) { + xQueueSendFromISR(gpio_evt_queue, (SwitchData *)arg, NULL); +} + +static void enableGpioInterrupt(bool enabled) { + for (int i = 0; i < PAIR_SIZE(buttonFunctionPair); ++i) { + if (enabled) { + enableInterrupt((buttonFunctionPair[i]).pin); + } else { + disableInterrupt((buttonFunctionPair[i]).pin); + } + } +} + +/********************* Arduino functions **************************/ +void setup() { + Serial.begin(115200); + + //Optional: set Zigbee device name and model + zbSwitch.setManufacturerAndModel("Espressif", "ZigbeeSwitch"); + + //Optional to allow multiple light to bind to the switch + zbSwitch.allowMultipleBinding(true); + + //Add endpoint to Zigbee Core + Serial.println("Adding ZigbeeSwitch endpoint to Zigbee Core"); + Zigbee.addEndpoint(&zbSwitch); + + //Open network for 180 seconds after boot + Zigbee.setRebootOpenNetwork(180); + + // Init button switch + for (int i = 0; i < PAIR_SIZE(buttonFunctionPair); i++) { + pinMode(buttonFunctionPair[i].pin, INPUT_PULLUP); + /* create a queue to handle gpio event from isr */ + gpio_evt_queue = xQueueCreate(10, sizeof(SwitchData)); + if (gpio_evt_queue == 0) { + Serial.println("Queue creating failed, rebooting..."); + ESP.restart(); + } + attachInterruptArg(buttonFunctionPair[i].pin, onGpioInterrupt, (void *)(buttonFunctionPair + i), FALLING); + } + + // When all EPs are registered, start Zigbee with ZIGBEE_COORDINATOR mode + if (!Zigbee.begin(ZIGBEE_COORDINATOR)) { + Serial.println("Zigbee failed to start!"); + Serial.println("Rebooting..."); + ESP.restart(); + } + + Serial.println("Waiting for Light to bound to the switch"); + //Wait for switch to bound to a light: + while (!zbSwitch.bound()) { + Serial.printf("."); + delay(500); + } + + // Optional: List all bound devices and read manufacturer and model name + std::list boundLights = zbSwitch.getBoundDevices(); + for (const auto &device : boundLights) { + Serial.printf("Device on endpoint %d, short address: 0x%x\r\n", device->endpoint, device->short_addr); + Serial.printf( + "IEEE Address: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\r\n", device->ieee_addr[7], device->ieee_addr[6], device->ieee_addr[5], device->ieee_addr[4], + device->ieee_addr[3], device->ieee_addr[2], device->ieee_addr[1], device->ieee_addr[0] + ); + Serial.printf("Light manufacturer: %s\r\n", zbSwitch.readManufacturer(device->endpoint, device->short_addr, device->ieee_addr)); + Serial.printf("Light model: %s\r\n", zbSwitch.readModel(device->endpoint, device->short_addr, device->ieee_addr)); + } + + Serial.println(); +} + +void loop() { + // Handle button switch in loop() + uint8_t pin = 0; + SwitchData buttonSwitch; + static SwitchState buttonState = SWITCH_IDLE; + bool eventFlag = false; + + /* check if there is any queue received, if yes read out the buttonSwitch */ + if (xQueueReceive(gpio_evt_queue, &buttonSwitch, portMAX_DELAY)) { + pin = buttonSwitch.pin; + enableGpioInterrupt(false); + eventFlag = true; + } + while (eventFlag) { + bool value = digitalRead(pin); + switch (buttonState) { + case SWITCH_IDLE: buttonState = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_IDLE; break; + case SWITCH_PRESS_DETECTED: buttonState = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_RELEASE_DETECTED; break; + case SWITCH_RELEASE_DETECTED: + buttonState = SWITCH_IDLE; + /* callback to button_handler */ + (*onZbButton)(&buttonSwitch); + break; + default: break; + } + if (buttonState == SWITCH_IDLE) { + enableGpioInterrupt(true); + eventFlag = false; + break; + } + vTaskDelay(10 / portTICK_PERIOD_MS); + } + + // print the bound lights every 10 seconds + static uint32_t lastPrint = 0; + if (millis() - lastPrint > 10000) { + lastPrint = millis(); + zbSwitch.printBoundDevices(Serial); + } +} diff --git a/examples/espidf-storage-spiffs/test/README b/examples/arduino-zigbee-switch/test/README similarity index 100% rename from examples/espidf-storage-spiffs/test/README rename to examples/arduino-zigbee-switch/test/README diff --git a/examples/espidf-arduino-blink/.travis.yml b/examples/espidf-arduino-blink/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-arduino-blink/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-arduino-blink/CMakeLists.txt b/examples/espidf-arduino-blink/CMakeLists.txt index 650d1b97d..6d4f2430b 100644 --- a/examples/espidf-arduino-blink/CMakeLists.txt +++ b/examples/espidf-arduino-blink/CMakeLists.txt @@ -1,3 +1,3 @@ cmake_minimum_required(VERSION 3.16.0) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(espidf-arduino-wifiscan) +project(espidf-arduino-blink) diff --git a/examples/espidf-arduino-blink/platformio.ini b/examples/espidf-arduino-blink/platformio.ini index b92c49577..0399901d7 100644 --- a/examples/espidf-arduino-blink/platformio.ini +++ b/examples/espidf-arduino-blink/platformio.ini @@ -11,14 +11,19 @@ platform = espressif32 framework = arduino, espidf build_flags = - -D CONFIG_BLINK_GPIO=2 + -DCONFIG_BLINK_GPIO=2 monitor_speed = 115200 +board_build.embed_txtfiles = + managed_components/espressif__esp_insights/server_certs/https_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt -[env:esp32dev] -board = esp32dev - -[env:espea32] -board = espea32 +[env:esp32-s3] +board = 4d_systems_esp32s3_gen4_r8n16 +build_flags = + -DCONFIG_BLINK_GPIO=2 + -DARDUINO_PARTITION_esp_sr_16 -[env:esp320] -board = esp320 +[env:esp32-c6-devkitm-1] +board = esp32-c6-devkitm-1 diff --git a/examples/espidf-arduino-blink/sdkconfig.defaults b/examples/espidf-arduino-blink/sdkconfig.defaults index 1af06b975..54ef4be5d 100644 --- a/examples/espidf-arduino-blink/sdkconfig.defaults +++ b/examples/espidf-arduino-blink/sdkconfig.defaults @@ -1,5 +1,157 @@ +CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y + +# +# SPI RAM config +# +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_TYPE_AUTO=y +CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y +CONFIG_SPIRAM_SPEED_80M=y +CONFIG_SPIRAM_SPEED=80 +CONFIG_SPIRAM_USE_MALLOC=y +CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=4096 +CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y +CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=0 + 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=4096 +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_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_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_MBEDTLS_PSK_MODES=y CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y +CONFIG_MBEDTLS_CAMELLIA_C=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=n +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=1024 +CONFIG_MBEDTLS_DYNAMIC_BUFFER=y +CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y +CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=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/examples/espidf-arduino-blink/src/Blink.cpp b/examples/espidf-arduino-blink/src/Blink.cpp index c69fd30f5..b584a2c73 100644 --- a/examples/espidf-arduino-blink/src/Blink.cpp +++ b/examples/espidf-arduino-blink/src/Blink.cpp @@ -29,7 +29,7 @@ void blink_task(void *pvParameter) Technical Reference for a list of pads and their default functions.) */ - gpio_pad_select_gpio(BLINK_GPIO); + esp_rom_gpio_pad_select_gpio(BLINK_GPIO); /* Set the GPIO as a push/pull output */ gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); while(1) { diff --git a/examples/espidf-arduino-h2zero-BLE_scan/.gitignore b/examples/espidf-arduino-h2zero-BLE_scan/.gitignore new file mode 100644 index 000000000..b9f3806a2 --- /dev/null +++ b/examples/espidf-arduino-h2zero-BLE_scan/.gitignore @@ -0,0 +1,2 @@ +.pio +.vscode diff --git a/examples/espidf-arduino-h2zero-BLE_scan/CMakeLists.txt b/examples/espidf-arduino-h2zero-BLE_scan/CMakeLists.txt new file mode 100644 index 000000000..b6275f681 --- /dev/null +++ b/examples/espidf-arduino-h2zero-BLE_scan/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.16.0) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +add_compile_definitions(ARDUINO_ARCH_ESP32=1) +project(Arduino_IDF_BLE_scan) diff --git a/examples/espidf-arduino-h2zero-BLE_scan/README.md b/examples/espidf-arduino-h2zero-BLE_scan/README.md new file mode 100644 index 000000000..5601e540c --- /dev/null +++ b/examples/espidf-arduino-h2zero-BLE_scan/README.md @@ -0,0 +1,7 @@ +# Arduino_IDF_BLE_scan example using 3rd party NimBLE stack + +BLE scan example, using the great h2zero NimBLE implementation. The needed NimBLE lib is loaded via the IDF component manager -> `idf_component.yml`. +Mandantory not to forget to switch Arduino included BLE libs. +Done in `sdkconfig.defaults` + +Thx @h2zero for the great BLE library. diff --git a/examples/espidf-ulp-adc/include/README b/examples/espidf-arduino-h2zero-BLE_scan/include/README similarity index 100% rename from examples/espidf-ulp-adc/include/README rename to examples/espidf-arduino-h2zero-BLE_scan/include/README diff --git a/examples/espidf-ulp-adc/lib/README b/examples/espidf-arduino-h2zero-BLE_scan/lib/README similarity index 100% rename from examples/espidf-ulp-adc/lib/README rename to examples/espidf-arduino-h2zero-BLE_scan/lib/README diff --git a/examples/espidf-arduino-h2zero-BLE_scan/platformio.ini b/examples/espidf-arduino-h2zero-BLE_scan/platformio.ini new file mode 100644 index 000000000..7b9a51745 --- /dev/null +++ b/examples/espidf-arduino-h2zero-BLE_scan/platformio.ini @@ -0,0 +1,27 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env] +platform = espressif32 +framework = arduino, espidf +monitor_speed = 115200 +board_build.embed_txtfiles = + managed_components/espressif__esp_insights/server_certs/https_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt +lib_ignore = + BLE + BluetoothSerial + SimpleBLE + WiFiProv + +[env:esp32] +board = esp32dev diff --git a/examples/espidf-arduino-h2zero-BLE_scan/sdkconfig.defaults b/examples/espidf-arduino-h2zero-BLE_scan/sdkconfig.defaults new file mode 100644 index 000000000..267ca7f35 --- /dev/null +++ b/examples/espidf-arduino-h2zero-BLE_scan/sdkconfig.defaults @@ -0,0 +1,34 @@ +# CONFIG_AUTOSTART_ARDUINO is not set +# CONFIG_WS2812_LED_ENABLE is not set +CONFIG_FREERTOS_HZ=1000 +CONFIG_MBEDTLS_PSK_MODES=y +CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y + +# Override some defaults so BT stack is enabled +# in this example +# +# BT config +# +CONFIG_BT_ENABLED=y +CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n +CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_ENABLED=y + +# +# Arduino Configuration +# +# +# Disable all Arduino included BLE libraries +# +CONFIG_ARDUINO_SELECTIVE_COMPILATION=y +# CONFIG_ARDUINO_SELECTIVE_WiFiProv is not set +# CONFIG_ARDUINO_SELECTIVE_BLE is not set +# CONFIG_ARDUINO_SELECTIVE_BluetoothSerial is not set +# CONFIG_ARDUINO_SELECTIVE_SimpleBLE is not set +# end of Arduino Configuration \ No newline at end of file diff --git a/examples/espidf-arduino-h2zero-BLE_scan/src/CMakeLists.txt b/examples/espidf-arduino-h2zero-BLE_scan/src/CMakeLists.txt new file mode 100644 index 000000000..483bc0cfc --- /dev/null +++ b/examples/espidf-arduino-h2zero-BLE_scan/src/CMakeLists.txt @@ -0,0 +1,6 @@ +# This file was automatically generated for projects +# without default 'CMakeLists.txt' file. + +FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*) + +idf_component_register(SRCS ${app_sources}) diff --git a/examples/espidf-arduino-h2zero-BLE_scan/src/idf_component.yml b/examples/espidf-arduino-h2zero-BLE_scan/src/idf_component.yml new file mode 100644 index 000000000..0d925b9bd --- /dev/null +++ b/examples/espidf-arduino-h2zero-BLE_scan/src/idf_component.yml @@ -0,0 +1,41 @@ +dependencies: + # Required IDF version + idf: ">=4.4" + + esp-nimble-cpp: + git: https://github.com/h2zero/esp-nimble-cpp.git + version: 877a29a8b1d0022c5e8f67ba8b879316e67b6c3d + + + # # Defining a dependency from the registry: + # # https://components.espressif.com/component/example/cmp + # example/cmp: "^3.3.3" # Automatically update minor releases + # + # # Other ways to define dependencies + # + # # For components maintained by Espressif only name can be used. + # # Same as `espressif/cmp` + # component: "~1.0.0" # Automatically update bugfix releases + # + # # Or in a longer form with extra parameters + # component2: + # version: ">=2.0.0" + # + # # For transient dependencies `public` flag can be set. + # # `public` flag doesn't have an effect for the `main` component. + # # All dependencies of `main` are public by default. + # public: true + # + # # For components hosted on non-default registry: + # service_url: "https://componentregistry.company.com" + # + # # For components in git repository: + # test_component: + # path: test_component + # git: ssh://git@gitlab.com/user/components.git + # + # # For test projects during component development + # # components can be used from a local directory + # # with relative or absolute path + # some_local_component: + # path: ../../projects/component diff --git a/examples/espidf-arduino-h2zero-BLE_scan/src/main.cpp b/examples/espidf-arduino-h2zero-BLE_scan/src/main.cpp new file mode 100644 index 000000000..04b6e5f0d --- /dev/null +++ b/examples/espidf-arduino-h2zero-BLE_scan/src/main.cpp @@ -0,0 +1,54 @@ +/* + Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp + Ported to Arduino ESP32 by Evandro Copercini + Refactored back to IDF by H2zero +*/ + +/** NimBLE differences highlighted in comment blocks **/ + +/*******original******** +#include +#include +#include +#include +***********************/ + +#include + +#include + +extern "C"{void app_main(void);} + +int scanTime = 5 * 1000; // In milliseconds, 0 = scan forever +BLEScan* pBLEScan; + +class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { + void onResult(BLEAdvertisedDevice* advertisedDevice) { + printf("Advertised Device: %s \n", advertisedDevice->toString().c_str()); + } +}; + +void scanTask (void * parameter){ + for(;;) { + // put your main code here, to run repeatedly: + BLEScanResults foundDevices = pBLEScan->getResults(scanTime, false); + printf("Devices found: %d\n", foundDevices.getCount()); + printf("Scan done!\n"); + pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory + vTaskDelay(2000/portTICK_PERIOD_MS); // Delay a second between loops. + } + + vTaskDelete(NULL); +} + +void app_main(void) { + printf("Scanning...\n"); + + BLEDevice::init(""); + pBLEScan = BLEDevice::getScan(); //create new scan + pBLEScan->setScanCallbacks(new MyAdvertisedDeviceCallbacks()); + pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster + pBLEScan->setInterval(100); + pBLEScan->setWindow(99); // less or equal setInterval value + xTaskCreate(scanTask, "scanTask", 5000, NULL, 1, NULL); +} diff --git a/examples/espidf-arduino-littlefs/.gitignore b/examples/espidf-arduino-littlefs/.gitignore new file mode 100644 index 000000000..b9f3806a2 --- /dev/null +++ b/examples/espidf-arduino-littlefs/.gitignore @@ -0,0 +1,2 @@ +.pio +.vscode diff --git a/examples/espidf-arduino-littlefs/CMakeLists.txt b/examples/espidf-arduino-littlefs/CMakeLists.txt new file mode 100644 index 000000000..1c734fcfb --- /dev/null +++ b/examples/espidf-arduino-littlefs/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.16.0) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(espidf-arduino-littlefs) diff --git a/examples/espidf-arduino-littlefs/README.md b/examples/espidf-arduino-littlefs/README.md new file mode 100644 index 000000000..8e58b4a04 --- /dev/null +++ b/examples/espidf-arduino-littlefs/README.md @@ -0,0 +1 @@ +# Arduino_IDF_LittleFS diff --git a/examples/espidf-arduino-littlefs/data/file1.txt b/examples/espidf-arduino-littlefs/data/file1.txt new file mode 100644 index 000000000..7c4a013e5 --- /dev/null +++ b/examples/espidf-arduino-littlefs/data/file1.txt @@ -0,0 +1 @@ +aaa \ No newline at end of file diff --git a/examples/espidf-arduino-littlefs/data/testfolder/test2.txt b/examples/espidf-arduino-littlefs/data/testfolder/test2.txt new file mode 100644 index 000000000..01f02e32c --- /dev/null +++ b/examples/espidf-arduino-littlefs/data/testfolder/test2.txt @@ -0,0 +1 @@ +bbb \ No newline at end of file diff --git a/examples/espidf-ulp-pulse/include/README b/examples/espidf-arduino-littlefs/include/README similarity index 100% rename from examples/espidf-ulp-pulse/include/README rename to examples/espidf-arduino-littlefs/include/README diff --git a/examples/espidf-ulp-pulse/lib/README b/examples/espidf-arduino-littlefs/lib/README similarity index 100% rename from examples/espidf-ulp-pulse/lib/README rename to examples/espidf-arduino-littlefs/lib/README diff --git a/examples/espidf-arduino-littlefs/partitions_custom.csv b/examples/espidf-arduino-littlefs/partitions_custom.csv new file mode 100644 index 000000000..960469b82 --- /dev/null +++ b/examples/espidf-arduino-littlefs/partitions_custom.csv @@ -0,0 +1,7 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x140000, +app1, app, ota_1, 0x150000,0x140000, +spiffs, data, spiffs, 0x290000,0x160000, +coredump, data, coredump,0x3F0000,0x10000, diff --git a/examples/espidf-arduino-littlefs/platformio.ini b/examples/espidf-arduino-littlefs/platformio.ini new file mode 100644 index 000000000..0ae6edc07 --- /dev/null +++ b/examples/espidf-arduino-littlefs/platformio.ini @@ -0,0 +1,24 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env] +platform = espressif32 +framework = arduino, espidf +board_build.filesystem = littlefs +board_build.partitions = partitions_custom.csv +monitor_speed = 115200 + +[env:esp32dev] +board = esp32dev +board_build.embed_txtfiles = + managed_components/espressif__esp_insights/server_certs/https_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt diff --git a/examples/espidf-arduino-littlefs/sdkconfig.defaults b/examples/espidf-arduino-littlefs/sdkconfig.defaults new file mode 100644 index 000000000..a8f9a5467 --- /dev/null +++ b/examples/espidf-arduino-littlefs/sdkconfig.defaults @@ -0,0 +1,9 @@ +CONFIG_AUTOSTART_ARDUINO=y +# CONFIG_WS2812_LED_ENABLE is not set +CONFIG_FREERTOS_HZ=1000 +CONFIG_MBEDTLS_PSK_MODES=y +CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y diff --git a/examples/espidf-arduino-littlefs/src/CMakeLists.txt b/examples/espidf-arduino-littlefs/src/CMakeLists.txt new file mode 100644 index 000000000..483bc0cfc --- /dev/null +++ b/examples/espidf-arduino-littlefs/src/CMakeLists.txt @@ -0,0 +1,6 @@ +# This file was automatically generated for projects +# without default 'CMakeLists.txt' file. + +FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*) + +idf_component_register(SRCS ${app_sources}) diff --git a/examples/espidf-arduino-littlefs/src/main.cpp b/examples/espidf-arduino-littlefs/src/main.cpp new file mode 100644 index 000000000..67bbc3234 --- /dev/null +++ b/examples/espidf-arduino-littlefs/src/main.cpp @@ -0,0 +1,282 @@ +#include +#include "FS.h" +#include +#include + +/* You only need to format LittleFS the first time you run a + test or else use the LITTLEFS plugin to create a partition + https://github.com/lorol/arduino-esp32littlefs-plugin */ + +#define FORMAT_LITTLEFS_IF_FAILED true + +void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ + Serial.printf("Listing directory: %s\r\n", dirname); + + File root = fs.open(dirname); + if(!root){ + Serial.println("- failed to open directory"); + return; + } + if(!root.isDirectory()){ + Serial.println(" - not a directory"); + return; + } + + File file = root.openNextFile(); + while(file){ + if(file.isDirectory()){ + Serial.print(" DIR : "); + + Serial.print(file.name()); + time_t t= file.getLastWrite(); + struct tm * tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); + + if(levels){ + listDir(fs, file.name(), levels -1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + + Serial.print(file.size()); + time_t t= file.getLastWrite(); + struct tm * tmstruct = localtime(&t); + Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec); + } + file = root.openNextFile(); + } +} + +void createDir(fs::FS &fs, const char * path){ + Serial.printf("Creating Dir: %s\n", path); + if(fs.mkdir(path)){ + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } +} + +void removeDir(fs::FS &fs, const char * path){ + Serial.printf("Removing Dir: %s\n", path); + if(fs.rmdir(path)){ + Serial.println("Dir removed"); + } else { + Serial.println("rmdir failed"); + } +} + +void readFile(fs::FS &fs, const char * path){ + Serial.printf("Reading file: %s\r\n", path); + + File file = fs.open(path); + if(!file || file.isDirectory()){ + Serial.println("- failed to open file for reading"); + return; + } + + Serial.println("- read from file:"); + while(file.available()){ + Serial.write(file.read()); + } + file.close(); +} + +void writeFile(fs::FS &fs, const char * path, const char * message){ + Serial.printf("Writing file: %s\r\n", path); + + File file = fs.open(path, FILE_WRITE); + if(!file){ + Serial.println("- failed to open file for writing"); + return; + } + if(file.print(message)){ + Serial.println("- file written"); + } else { + Serial.println("- write failed"); + } + file.close(); +} + +void appendFile(fs::FS &fs, const char * path, const char * message){ + Serial.printf("Appending to file: %s\r\n", path); + + File file = fs.open(path, FILE_APPEND); + if(!file){ + Serial.println("- failed to open file for appending"); + return; + } + if(file.print(message)){ + Serial.println("- message appended"); + } else { + Serial.println("- append failed"); + } + file.close(); +} + +void renameFile(fs::FS &fs, const char * path1, const char * path2){ + Serial.printf("Renaming file %s to %s\r\n", path1, path2); + if (fs.rename(path1, path2)) { + Serial.println("- file renamed"); + } else { + Serial.println("- rename failed"); + } +} + +void deleteFile(fs::FS &fs, const char * path){ + Serial.printf("Deleting file: %s\r\n", path); + if(fs.remove(path)){ + Serial.println("- file deleted"); + } else { + Serial.println("- delete failed"); + } +} + +// SPIFFS-like write and delete file + +// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L60 +void writeFile2(fs::FS &fs, const char * path, const char * message){ + if(!fs.exists(path)){ + if (strchr(path, '/')) { + Serial.printf("Create missing folders of: %s\r\n", path); + char *pathStr = strdup(path); + if (pathStr) { + char *ptr = strchr(pathStr, '/'); + while (ptr) { + *ptr = 0; + fs.mkdir(pathStr); + *ptr = '/'; + ptr = strchr(ptr+1, '/'); + } + } + free(pathStr); + } + } + + Serial.printf("Writing file to: %s\r\n", path); + File file = fs.open(path, FILE_WRITE); + if(!file){ + Serial.println("- failed to open file for writing"); + return; + } + if(file.print(message)){ + Serial.println("- file written"); + } else { + Serial.println("- write failed"); + } + file.close(); +} + +// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.h#L149 +void deleteFile2(fs::FS &fs, const char * path){ + Serial.printf("Deleting file and empty folders on path: %s\r\n", path); + + if(fs.remove(path)){ + Serial.println("- file deleted"); + } else { + Serial.println("- delete failed"); + } + + char *pathStr = strdup(path); + if (pathStr) { + char *ptr = strrchr(pathStr, '/'); + if (ptr) { + Serial.printf("Removing all empty folders on path: %s\r\n", path); + } + while (ptr) { + *ptr = 0; + fs.rmdir(pathStr); + ptr = strrchr(pathStr, '/'); + } + free(pathStr); + } +} + +void testFileIO(fs::FS &fs, const char * path){ + Serial.printf("Testing file I/O with %s\r\n", path); + + static uint8_t buf[512]; + size_t len = 0; + File file = fs.open(path, FILE_WRITE); + if(!file){ + Serial.println("- failed to open file for writing"); + return; + } + + size_t i; + Serial.print("- writing" ); + uint32_t start = millis(); + for(i=0; i<2048; i++){ + if ((i & 0x001F) == 0x001F){ + Serial.print("."); + } + file.write(buf, 512); + } + Serial.println(""); + uint32_t end = millis() - start; + Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, (unsigned int)end); + file.close(); + + file = fs.open(path); + start = millis(); + end = start; + i = 0; + if(file && !file.isDirectory()){ + len = file.size(); + size_t flen = len; + start = millis(); + Serial.print("- reading" ); + while(len){ + size_t toRead = len; + if(toRead > 512){ + toRead = 512; + } + file.read(buf, toRead); + if ((i++ & 0x001F) == 0x001F){ + Serial.print("."); + } + len -= toRead; + } + Serial.println(""); + end = millis() - start; + Serial.printf("- %u bytes read in %u ms\r\n", flen, (unsigned int)end); + file.close(); + } else { + Serial.println("- failed to open file for reading"); + } +} + +void setup(){ + Serial.begin(115200); + if(!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED)){ + Serial.println("LittleFS Mount Failed"); + return; + } + + listDir(LittleFS, "/", 0); + createDir(LittleFS, "/mydir"); + writeFile(LittleFS, "/mydir/hello2.txt", "Hello2"); + //writeFile(LittleFS, "/mydir/newdir2/newdir3/hello3.txt", "Hello3"); + writeFile2(LittleFS, "/mydir/newdir2/newdir3/hello3.txt", "Hello3"); + listDir(LittleFS, "/", 3); + deleteFile(LittleFS, "/mydir/hello2.txt"); + //deleteFile(LittleFS, "/mydir/newdir2/newdir3/hello3.txt"); + deleteFile2(LittleFS, "/mydir/newdir2/newdir3/hello3.txt"); + removeDir(LittleFS, "/mydir"); + listDir(LittleFS, "/", 3); + writeFile(LittleFS, "/hello.txt", "Hello "); + appendFile(LittleFS, "/hello.txt", "World!\r\n"); + readFile(LittleFS, "/hello.txt"); + renameFile(LittleFS, "/hello.txt", "/foo.txt"); + readFile(LittleFS, "/foo.txt"); + deleteFile(LittleFS, "/foo.txt"); + testFileIO(LittleFS, "/test.txt"); + deleteFile(LittleFS, "/test.txt"); + + Serial.println( "Test complete" ); +} + +void loop(){ + +} diff --git a/examples/espidf-arduino-matter-light/CMakeLists.txt b/examples/espidf-arduino-matter-light/CMakeLists.txt new file mode 100644 index 000000000..4a9c0c2e8 --- /dev/null +++ b/examples/espidf-arduino-matter-light/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.16.0) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +set(PROJECT_VER "1.0") +set(PROJECT_VER_NUMBER 1) + +project(matter-light) + + +# WARNING: This is just an example for using key for decrypting the encrypted OTA image +# Please do not use it as is. +if(CONFIG_ENABLE_ENCRYPTED_OTA) + target_add_binary_data(light.elf "esp_image_encryption_key.pem" TEXT) +endif() + +if(CONFIG_IDF_TARGET_ESP32C2) + include(relinker) +endif() + +idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DCHIP_HAVE_CONFIG_H" APPEND) +idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND) +# For RISCV chips, project_include.cmake sets -Wno-format, but does not clear various +# flags that depend on -Wformat +idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND) \ No newline at end of file diff --git a/examples/espidf-arduino-matter-light/README.md b/examples/espidf-arduino-matter-light/README.md new file mode 100644 index 000000000..7d8768865 --- /dev/null +++ b/examples/espidf-arduino-matter-light/README.md @@ -0,0 +1,68 @@ +| Supported Targets | ESP32-S3 | ESP32-C3 | ESP32-C6 | +| ----------------- | -------- | -------- | -------- | + + +# Managed Component Light + +This example is configured by default to work with the ESP32-S3, which has the RGB LED GPIO set as pin 48 and the BOOT button on GPIO 0. + +This example creates a Color Temperature Light device using the esp_matter component downloaded from the [Espressif Component Registry](https://components.espressif.com/) instead of an extra component locally, so the example can work without setting up the esp-matter environment. + +See the [docs](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html) for more information about building and flashing the firmware. + +The code is based on the Arduino API and uses Arduino as an IDF Component. + +## How to use it + +Once the device runs for the first time, it must be commissioned to the Matter Fabric of the available Matter Environment. +Possible Matter Environments are: +- Amazon Alexa +- Google Home Assistant (*) +- Apple Home +- Open Source Home Assistant + +(*) Google Home Assistant requires the user to set up a Matter Light using the [Google Home Developer Console](https://developers.home.google.com/codelabs/matter-device#2). It is necessary to create a Matter Light device with VID = 0xFFF1 and PID = 0x8000. Otherwise, the Light won't show up in the GHA APP. This action is necessary because the Firmware uses Testing credentials and Google requires the user to create the testing device before using it. + +There is no QR Code to be used when the Smartphone APP wants to add the Matter Device. +Please enter the code manually: `34970112332` + +The devboard has a built-in LED that will be used as the Matter Light. +The default setting of the code uses pin 48 for the ESP32-S3. +Please change it in `main/matter_accessory_driver.h` or in the `sdkconfig.defaults.` file. + +## LED Status and Factory Mode + +The WS2812b built-in LED will turn purple as soon as the device is flashed and runs for the first time. +The purple color indicates that the Matter Accessory has not been commissioned yet. +After using a Matter provider Smartphone APP to add a Matter device to your Home Application, it may turn orange to indicate that it has no WiFi connection. + +Once it connects to the WiFi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment. +Please note that Matter over WiFi using an ESP32 device will connect to a 2.4GHz WiFi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID. + +The Matter and WiFi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and WiFi Network again once it is reset. + +The Matter Smartphone APP will control the light state (ON/OFF), temperature (Warm/Cold White), and brightness. + +## On Board Light toggle button + +The built-in BOOT button will toggle On/Off and replicate the new state to the Matter Environment, making it visible in the Matter Smartphone APP as well. + +## Returning to the Factory State + +Holding the BOOT button pressed for more than 10 seconds and then releasing it will erase all Matter and WiFi configuration, forcing it to reset to factory state. After that, the device needs to be commissioned again. Previous setups done in the Smartphone APP won't work again; therefore, the virtual device shall be removed from the APP. + +## Building the Application using WiFi and Matter + +Use ESP-IDF 5.1.4 from https://github.com/espressif/esp-idf/tree/release/v5.1 +This example has been tested with Arduino Core 3.0.4 + +There is a configuration file for these SoC: esp32s3, esp32c3, esp32c6. +Those are the tested devices that have a WS2812 RGB LED and can run BLE, WiFi and Matter. + +In case it is necessary to change the Button Pin or the REG LED Pin, please use the `menuconfig` and change the Menu Option `Light Matter Accessory` + +## Using OpenThread with Matter + +This is possible with the ESP32-C6. +It is neessasy to have a Thread Border Routed in the Matter Environment. Check you matter hardware provider. + diff --git a/examples/espidf-arduino-matter-light/include/README b/examples/espidf-arduino-matter-light/include/README new file mode 100644 index 000000000..194dcd432 --- /dev/null +++ b/examples/espidf-arduino-matter-light/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/espidf-arduino-matter-light/lib/README b/examples/espidf-arduino-matter-light/lib/README new file mode 100644 index 000000000..2593a33f9 --- /dev/null +++ b/examples/espidf-arduino-matter-light/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/espidf-arduino-matter-light/main/CMakeLists.txt b/examples/espidf-arduino-matter-light/main/CMakeLists.txt new file mode 100644 index 000000000..dfe4b7586 --- /dev/null +++ b/examples/espidf-arduino-matter-light/main/CMakeLists.txt @@ -0,0 +1,9 @@ +# This file was automatically generated for projects +# without default 'CMakeLists.txt' file. + +FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/main/*.*) + +idf_component_register(SRCS ${app_sources}) + +#set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) +#target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") \ No newline at end of file diff --git a/examples/espidf-arduino-matter-light/main/Kconfig.projbuild b/examples/espidf-arduino-matter-light/main/Kconfig.projbuild new file mode 100644 index 000000000..50e8914f0 --- /dev/null +++ b/examples/espidf-arduino-matter-light/main/Kconfig.projbuild @@ -0,0 +1,102 @@ +menu "Light Matter Accessory" + menu "On Board Light ON/OFF Button" + config BUTTON_PIN + int + prompt "Button 1 GPIO" + default ENV_GPIO_BOOT_BUTTON + range -1 ENV_GPIO_IN_RANGE_MAX + help + The GPIO pin for button that will be used to turn on/off the Matter Light. It shall be connected to a push button. It can use the BOOT button of the development board. + endmenu + + + menu "LEDs" + config WS2812_PIN + int + prompt "WS2812 RGB LED GPIO" + default ENV_GPIO_RGB_LED + range -1 ENV_GPIO_OUT_RANGE_MAX + help + The GPIO pin for the Matter Light that will be driven by RMT. It shall be connected to one single WS2812 RGB LED. + endmenu + + # TARGET CONFIGURATION + if IDF_TARGET_ESP32C3 + config ENV_GPIO_RANGE_MIN + int + default 0 + + config ENV_GPIO_RANGE_MAX + int + default 19 + # GPIOs 20/21 are always used by UART in examples + + config ENV_GPIO_IN_RANGE_MAX + int + default ENV_GPIO_RANGE_MAX + + config ENV_GPIO_OUT_RANGE_MAX + int + default ENV_GPIO_RANGE_MAX + + config ENV_GPIO_BOOT_BUTTON + int + default 9 + + config ENV_GPIO_RGB_LED + int + default 8 + endif + if IDF_TARGET_ESP32C6 + config ENV_GPIO_RANGE_MIN + int + default 0 + + config ENV_GPIO_RANGE_MAX + int + default 30 + # GPIOs 16/17 are always used by UART in examples + + config ENV_GPIO_IN_RANGE_MAX + int + default ENV_GPIO_RANGE_MAX + + config ENV_GPIO_OUT_RANGE_MAX + int + default ENV_GPIO_RANGE_MAX + + config ENV_GPIO_BOOT_BUTTON + int + default 9 + + config ENV_GPIO_RGB_LED + int + default 8 + endif + if IDF_TARGET_ESP32S3 + config ENV_GPIO_RANGE_MIN + int + default 0 + + config ENV_GPIO_RANGE_MAX + int + default 48 + + config ENV_GPIO_IN_RANGE_MAX + int + default ENV_GPIO_RANGE_MAX + + config ENV_GPIO_OUT_RANGE_MAX + int + default ENV_GPIO_RANGE_MAX + + config ENV_GPIO_BOOT_BUTTON + int + default 0 + + config ENV_GPIO_RGB_LED + int + default 48 + endif + +endmenu diff --git a/examples/espidf-arduino-matter-light/main/builtinLED.cpp b/examples/espidf-arduino-matter-light/main/builtinLED.cpp new file mode 100644 index 000000000..9f2695b89 --- /dev/null +++ b/examples/espidf-arduino-matter-light/main/builtinLED.cpp @@ -0,0 +1,247 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. + This will implement the onboard WS2812b LED as a LED indicator + It can be used to indicate some state or status of the device + The LED can be controlled using RGB, HSV or color temperature, brightness + + In this example, the LED Indicator class is used as the Matter light accessory +*/ + +#include "builtinLED.h" + +typedef struct { + uint16_t hue; + uint8_t saturation; +} HS_color_t; + +static const HS_color_t temperatureTable[] = { + {4, 100}, {8, 100}, {11, 100}, {14, 100}, {16, 100}, {18, 100}, {20, 100}, {22, 100}, {24, 100}, {25, 100}, + {27, 100}, {28, 100}, {30, 100}, {31, 100}, {31, 95}, {30, 89}, {30, 85}, {29, 80}, {29, 76}, {29, 73}, + {29, 69}, {28, 66}, {28, 63}, {28, 60}, {28, 57}, {28, 54}, {28, 52}, {27, 49}, {27, 47}, {27, 45}, + {27, 43}, {27, 41}, {27, 39}, {27, 37}, {27, 35}, {27, 33}, {27, 31}, {27, 30}, {27, 28}, {27, 26}, + {27, 25}, {27, 23}, {27, 22}, {27, 21}, {27, 19}, {27, 18}, {27, 17}, {27, 15}, {28, 14}, {28, 13}, + {28, 12}, {29, 10}, {29, 9}, {30, 8}, {31, 7}, {32, 6}, {34, 5}, {36, 4}, {41, 3}, {49, 2}, + {0, 0}, {294, 2}, {265, 3}, {251, 4}, {242, 5}, {237, 6}, {233, 7}, {231, 8}, {229, 9}, {228, 10}, + {227, 11}, {226, 11}, {226, 12}, {225, 13}, {225, 13}, {224, 14}, {224, 14}, {224, 15}, {224, 15}, {223, 16}, + {223, 16}, {223, 17}, {223, 17}, {223, 17}, {222, 18}, {222, 18}, {222, 19}, {222, 19}, {222, 19}, {222, 19}, + {222, 20}, {222, 20}, {222, 20}, {222, 21}, {222, 21} +}; + +/* step brightness table: gamma = 2.3 */ +static const uint8_t gamma_table[MAX_PROGRESS] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, + 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, + 10, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, + 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, + 26, 27, 28, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 36, 37, + 38, 39, 40, 40, 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 86, + 87, 88, 89, 91, 92, 93, 95, 96, 97, 99, 100, 101, 103, 104, 105, 107, + 108, 110, 111, 112, 114, 115, 117, 118, 120, 121, 123, 124, 126, 128, 129, 131, + 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 149, 150, 152, 154, 156, 157, + 159, 161, 163, 164, 166, 168, 170, 172, 174, 175, 177, 179, 181, 183, 185, 187, + 189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, + 221, 223, 226, 228, 230, 232, 234, 236, 239, 241, 243, 245, 248, 250, 252, 255, +}; + +BuiltInLED::BuiltInLED() { + pin_number = (uint8_t) -1; // no pin number + state = false; // LED is off + hsv_color.value = 0; // black color +} + +BuiltInLED::~BuiltInLED(){ + end(); +} + +led_indicator_color_hsv_t BuiltInLED::rgb2hsv(led_indicator_color_rgb_t rgb) { + led_indicator_color_hsv_t hsv; + uint8_t minRGB, maxRGB; + uint8_t delta; + + minRGB = rgb.r < rgb.g ? (rgb.r < rgb.b ? rgb.r : rgb.b) : (rgb.g < rgb.b ? rgb.g : rgb.b); + maxRGB = rgb.r > rgb.g ? (rgb.r > rgb.b ? rgb.r : rgb.b) : (rgb.g > rgb.b ? rgb.g : rgb.b); + hsv.value = 0; + hsv.v = maxRGB; + delta = maxRGB - minRGB; + + if (delta == 0) { + hsv.h = 0; + hsv.s = 0; + } else { + hsv.s = delta * 255 / maxRGB; + + if (rgb.r == maxRGB) { + hsv.h = (60 * (rgb.g - rgb.b) / delta + 360) % 360; + } else if (rgb.g == maxRGB) { + hsv.h = (60 * (rgb.b - rgb.r) / delta + 120); + } else { + hsv.h = (60 * (rgb.r - rgb.g) / delta + 240); + } + } + return hsv; +} + +led_indicator_color_rgb_t BuiltInLED::hsv2rgb(led_indicator_color_hsv_t hsv) { + led_indicator_color_rgb_t rgb; + uint8_t rgb_max = hsv.v; + uint8_t rgb_min = rgb_max * (255 - hsv.s) / 255.0f; + + uint8_t i = hsv.h / 60; + uint8_t diff = hsv.h % 60; + + // RGB adjustment amount by hue + uint8_t rgb_adj = (rgb_max - rgb_min) * diff / 60; + rgb.value = 0; + switch (i) { + case 0: + rgb.r = rgb_max; + rgb.g = rgb_min + rgb_adj; + rgb.b = rgb_min; + break; + case 1: + rgb.r = rgb_max - rgb_adj; + rgb.g = rgb_max; + rgb.b = rgb_min; + break; + case 2: + rgb.r = rgb_min; + rgb.g = rgb_max; + rgb.b = rgb_min + rgb_adj; + break; + case 3: + rgb.r = rgb_min; + rgb.g = rgb_max - rgb_adj; + rgb.b = rgb_max; + break; + case 4: + rgb.r = rgb_min + rgb_adj; + rgb.g = rgb_min; + rgb.b = rgb_max; + break; + default: + rgb.r = rgb_max; + rgb.g = rgb_min; + rgb.b = rgb_max - rgb_adj; + break; + } + + // gamma correction + rgb.r = gamma_table[rgb.r]; + rgb.g = gamma_table[rgb.g]; + rgb.b = gamma_table[rgb.b]; + return rgb; +} + +void BuiltInLED::begin(uint8_t pin){ + if (pin < NUM_DIGITAL_PINS) { + pin_number = pin; + log_i("Initializing pin %d", pin); + } else { + log_e("Invalid pin (%d) number", pin); + } +} +void BuiltInLED::end(){ + state = false; + write(); // turn off the LED + if (pin_number < NUM_DIGITAL_PINS) { + if (!rmtDeinit(pin_number)) { + log_e("Failed to deinitialize RMT"); + } + } +} + +void BuiltInLED::on(){ + state = true; +} + +void BuiltInLED::off(){ + state = false; +} + +void BuiltInLED::toggle(){ + state = !state; +} + +bool BuiltInLED::getState(){ + return state; +} + +bool BuiltInLED::write(){ + led_indicator_color_rgb_t rgb_color = getRGB(); + log_d("Writing to pin %d with state = %s", pin_number, state ? "ON" : "OFF"); + log_d("HSV: %d, %d, %d", hsv_color.h, hsv_color.s, hsv_color.v); + log_d("RGB: %d, %d, %d", rgb_color.r, rgb_color.g, rgb_color.b); + if(pin_number < NUM_DIGITAL_PINS){ + if (state) { + rgbLedWrite(pin_number, rgb_color.r, rgb_color.g, rgb_color.b); + } else { + rgbLedWrite(pin_number, 0, 0, 0); + } + return true; + } else { + log_e("Invalid pin (%d) number", pin_number); + return false; + } +} + +void BuiltInLED::setBrightness(uint8_t brightness){ + hsv_color.v = brightness; +} + +uint8_t BuiltInLED::getBrightness(){ + return hsv_color.v; +} + +void BuiltInLED::setHSV(led_indicator_color_hsv_t hsv){ + if (hsv.h > MAX_HUE) { + hsv.h = MAX_HUE; + } + hsv_color.value = hsv.value; +} + +led_indicator_color_hsv_t BuiltInLED::getHSV(){ + return hsv_color; +} + +void BuiltInLED::setRGB(led_indicator_color_rgb_t rgb_color){ + hsv_color = rgb2hsv(rgb_color); +} + +led_indicator_color_rgb_t BuiltInLED::getRGB(){ + return hsv2rgb(hsv_color); +} + +void BuiltInLED::setTemperature(uint32_t temperature){ + uint16_t hue; + uint8_t saturation; + + log_d("Requested Temperature: %ld", temperature); + //hsv_color.v = gamma_table[((temperature >> 25) & 0x7F)]; + temperature &= 0xFFFFFF; + if (temperature < 600) { + hue = 0; + saturation = 100; + } else { + if (temperature > 10000) { + hue = 222; + saturation = 21 + (temperature - 10000) * 41 / 990000; + } else { + temperature -= 600; + temperature /= 100; + hue = temperatureTable[temperature].hue; + saturation = temperatureTable[temperature].saturation; + } + } + saturation = (saturation * 255) / 100; + // brightness is not changed + hsv_color.h = hue; + hsv_color.s = saturation; + log_d("Calculated Temperature: %ld, Hue: %d, Saturation: %d, Brightness: %d", temperature, hue, saturation, hsv_color.v); +} \ No newline at end of file diff --git a/examples/espidf-arduino-matter-light/main/builtinLED.h b/examples/espidf-arduino-matter-light/main/builtinLED.h new file mode 100644 index 000000000..7a2f2ec5d --- /dev/null +++ b/examples/espidf-arduino-matter-light/main/builtinLED.h @@ -0,0 +1,74 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. + This will implement the onboard WS2812b LED as a LED indicator + It can be used to indicate some state or status of the device + The LED can be controlled using RGB, HSV or color temperature, brightness + + In this example, the BuiltInLED class is used as the Matter light accessory +*/ + +#pragma once + +#include + +#define MAX_HUE 360 +#define MAX_SATURATION 255 +#define MAX_BRIGHTNESS 255 +#define MAX_PROGRESS 256 + +typedef struct { + union { + struct { + uint32_t v: 8; /*!< Brightness/Value of the LED. 0-255 */ + uint32_t s: 8; /*!< Saturation of the LED. 0-255 */ + uint32_t h: 9; /*!< Hue of the LED. 0-360 */ + }; + uint32_t value; /*!< IHSV value of the LED. */ + }; +} led_indicator_color_hsv_t; + +typedef struct { + union { + struct { + uint32_t r: 8; /*!< Red component of the LED color. Range: 0-255. */ + uint32_t g: 8; /*!< Green component of the LED color. Range: 0-255. */ + uint32_t b: 8; /*!< Blue component of the LED color. Range: 0-255. */ + }; + uint32_t value; /*!< Combined RGB value of the LED color. */ + }; +} led_indicator_color_rgb_t; + +class BuiltInLED { +private: + uint8_t pin_number; + bool state; + led_indicator_color_hsv_t hsv_color; + +public: + BuiltInLED(); + ~BuiltInLED(); + + static led_indicator_color_hsv_t rgb2hsv(led_indicator_color_rgb_t rgb_value); + static led_indicator_color_rgb_t hsv2rgb(led_indicator_color_hsv_t hsv); + + void begin(uint8_t pin); + void end(); + + void on(); + void off(); + void toggle(); + bool getState(); + + bool write(); + + void setBrightness(uint8_t brightness); + uint8_t getBrightness(); + void setHSV(led_indicator_color_hsv_t hsv); + led_indicator_color_hsv_t getHSV(); + void setRGB(led_indicator_color_rgb_t color); + led_indicator_color_rgb_t getRGB(); + void setTemperature(uint32_t temperature); +}; \ No newline at end of file diff --git a/examples/espidf-arduino-matter-light/main/idf_component.yml b/examples/espidf-arduino-matter-light/main/idf_component.yml new file mode 100644 index 000000000..0caf8ffa0 --- /dev/null +++ b/examples/espidf-arduino-matter-light/main/idf_component.yml @@ -0,0 +1,7 @@ +dependencies: + espressif/esp_matter: + version: "^1.3.0" + espressif/cmake_utilities: + version: "0.*" + rules: + - if: "target in [esp32c2]" diff --git a/examples/espidf-arduino-matter-light/main/matter_accessory_driver.cpp b/examples/espidf-arduino-matter-light/main/matter_accessory_driver.cpp new file mode 100644 index 000000000..8e3cc7ec4 --- /dev/null +++ b/examples/espidf-arduino-matter-light/main/matter_accessory_driver.cpp @@ -0,0 +1,95 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include +#include +#include "builtinLED.h" +#include "matter_accessory_driver.h" + +/* Do any conversions/remapping for the actual value here */ +esp_err_t light_accessory_set_power(void *led, uint8_t val) +{ + BuiltInLED *builtinLED = (BuiltInLED *) led; + esp_err_t err = ESP_OK; + if (val) { + builtinLED->on(); + } else { + builtinLED->off(); + } + if (!builtinLED->write()) { + err = ESP_FAIL; + } + log_i("LED set power: %d", val); + return err; +} + +esp_err_t light_accessory_set_brightness(void *led, uint8_t val) +{ + esp_err_t err = ESP_OK; + BuiltInLED *builtinLED = (BuiltInLED *) led; + int value = REMAP_TO_RANGE(val, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS); + + builtinLED->setBrightness(value); + if (!builtinLED->write()) { + err = ESP_FAIL; + } + log_i("LED set brightness: %d", value); + return err; +} + +esp_err_t light_accessory_set_hue(void *led, uint8_t val) +{ + esp_err_t err = ESP_OK; + BuiltInLED *builtinLED = (BuiltInLED *) led; + int value = REMAP_TO_RANGE(val, MATTER_HUE, STANDARD_HUE); + led_indicator_color_hsv_t hsv = builtinLED->getHSV(); + hsv.h = value; + builtinLED->setHSV(hsv); + if (!builtinLED->write()) { + err = ESP_FAIL; + } + log_i("LED set hue: %d", value); + return err; +} + +esp_err_t light_accessory_set_saturation(void *led, uint8_t val) +{ + esp_err_t err = ESP_OK; + BuiltInLED *builtinLED = (BuiltInLED *) led; + int value = REMAP_TO_RANGE(val, MATTER_SATURATION, STANDARD_SATURATION); + led_indicator_color_hsv_t hsv = builtinLED->getHSV(); + hsv.s = value; + builtinLED->setHSV(hsv); + if (!builtinLED->write()) { + err = ESP_FAIL; + } + log_i("LED set saturation: %d", value); + return err; +} + +esp_err_t light_accessory_set_temperature(void *led, uint16_t val) +{ + esp_err_t err = ESP_OK; + BuiltInLED *builtinLED = (BuiltInLED *) led; + uint32_t value = REMAP_TO_RANGE_INVERSE(val, STANDARD_TEMPERATURE_FACTOR); + builtinLED->setTemperature(value); + if (!builtinLED->write()) { + err = ESP_FAIL; + } + log_i("LED set temperature: %ld", value); + return err; +} + +app_driver_handle_t light_accessory_init() +{ + /* Initialize led */ + static BuiltInLED builtinLED; + + const uint8_t pin = WS2812_PIN; // set your board WS2812b pin here + builtinLED.begin(pin); + return (app_driver_handle_t) &builtinLED; +} diff --git a/examples/espidf-arduino-matter-light/main/matter_accessory_driver.h b/examples/espidf-arduino-matter-light/main/matter_accessory_driver.h new file mode 100644 index 000000000..8d816c799 --- /dev/null +++ b/examples/espidf-arduino-matter-light/main/matter_accessory_driver.h @@ -0,0 +1,47 @@ +#include +#include + +// set your board WS2812b pin here (e.g. 48 is the default pin for the ESP32-S3 devkit) +#ifndef CONFIG_WS2812_PIN +#define WS2812_PIN 48 // ESP32-S3 DevKitC built-in LED +#else +#define WS2812_PIN CONFIG_WS2812_PIN // From sdkconfig.defaults. +#endif + +#ifndef RGB_BUILTIN +#define RGB_BUILTIN WS2812_PIN +#endif + +// Set your board button pin here (e.g. 0 is the default pin for the ESP32-S3 devkit) +#ifndef CONFIG_BUTTON_PIN +#define BUTTON_PIN 0 // ESP32-S3 DevKitC built-in button +#else +#define BUTTON_PIN CONFIG_BUTTON_PIN // From sdkconfig.defaults. +#endif + +/** Standard max values (used for remapping attributes) */ +#define STANDARD_BRIGHTNESS 255 +#define STANDARD_HUE 360 +#define STANDARD_SATURATION 255 +#define STANDARD_TEMPERATURE_FACTOR 1000000 + +/** Matter max values (used for remapping attributes) */ +#define MATTER_BRIGHTNESS 254 +#define MATTER_HUE 254 +#define MATTER_SATURATION 254 +#define MATTER_TEMPERATURE_FACTOR 1000000 + +/** Default attribute values used during initialization */ +#define DEFAULT_POWER true +#define DEFAULT_BRIGHTNESS 64 +#define DEFAULT_HUE 128 +#define DEFAULT_SATURATION 254 + +typedef void *app_driver_handle_t; + +esp_err_t light_accessory_set_power(void *led, uint8_t val); +esp_err_t light_accessory_set_brightness(void *led, uint8_t val); +esp_err_t light_accessory_set_hue(void *led, uint8_t val); +esp_err_t light_accessory_set_saturation(void *led, uint8_t val); +esp_err_t light_accessory_set_temperature(void *led, uint16_t val); +app_driver_handle_t light_accessory_init(); \ No newline at end of file diff --git a/examples/espidf-arduino-matter-light/main/matter_light.cpp b/examples/espidf-arduino-matter-light/main/matter_light.cpp new file mode 100644 index 000000000..5f3898e84 --- /dev/null +++ b/examples/espidf-arduino-matter-light/main/matter_light.cpp @@ -0,0 +1,421 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include "matter_accessory_driver.h" + +#include + +#include +#include +#include + +#include +#include + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include +#include "esp_openthread_types.h" + +#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \ + { \ + .radio_mode = RADIO_MODE_NATIVE, \ + } + +#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \ + { \ + .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ + } + +#define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \ + { \ + .storage_partition_name = "nvs", .netif_queue_size = 10, .task_queue_size = 10, \ + } +#endif + +// set your board button pin here +const uint8_t button_gpio = BUTTON_PIN; // GPIO BOOT Button + +uint16_t light_endpoint_id = 0; + +using namespace esp_matter; +using namespace esp_matter::attribute; +using namespace esp_matter::endpoint; +using namespace chip::app::Clusters; + +constexpr auto k_timeout_seconds = 300; + +#if CONFIG_ENABLE_ENCRYPTED_OTA +extern const char decryption_key_start[] asm("_binary_esp_image_encryption_key_pem_start"); +extern const char decryption_key_end[] asm("_binary_esp_image_encryption_key_pem_end"); + +static const char *s_decryption_key = decryption_key_start; +static const uint16_t s_decryption_key_len = decryption_key_end - decryption_key_start; +#endif // CONFIG_ENABLE_ENCRYPTED_OTA + +bool isAccessoryCommissioned() { + return chip::Server::GetInstance().GetFabricTable().FabricCount() > 0; +} + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +bool isWifiConnected() { + return chip::DeviceLayer::ConnectivityMgr().IsWiFiStationConnected(); +} +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +bool isThreadConnected() { + return chip::DeviceLayer::ConnectivityMgr().IsThreadAttached(); +} +#endif + +static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) +{ + switch (event->Type) { + case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: + log_i("Interface %s Address changed", + event->InterfaceIpAddressChanged.Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV4_Assigned ? + "IPv4" : "IPV6" ); + break; + + case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: + log_i("Commissioning complete"); + break; + + case chip::DeviceLayer::DeviceEventType::kFailSafeTimerExpired: + log_i("Commissioning failed, fail safe timer expired"); + break; + + case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStarted: + log_i("Commissioning session started"); + break; + + case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStopped: + log_i("Commissioning session stopped"); + break; + + case chip::DeviceLayer::DeviceEventType::kCommissioningWindowOpened: + log_i("Commissioning window opened"); + break; + + case chip::DeviceLayer::DeviceEventType::kCommissioningWindowClosed: + log_i("Commissioning window closed"); + break; + + case chip::DeviceLayer::DeviceEventType::kFabricRemoved: + { + log_i("Fabric removed successfully"); + if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0) + { + chip::CommissioningWindowManager & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager(); + constexpr auto kTimeoutSeconds = chip::System::Clock::Seconds16(k_timeout_seconds); + if (!commissionMgr.IsCommissioningWindowOpen()) + { + /* After removing last fabric, this example does not remove the Wi-Fi credentials + * and still has IP connectivity so, only advertising on DNS-SD. + */ + CHIP_ERROR err = commissionMgr.OpenBasicCommissioningWindow(kTimeoutSeconds, + chip::CommissioningWindowAdvertisement::kDnssdOnly); + if (err != CHIP_NO_ERROR) + { + log_e("Failed to open commissioning window, err:%" CHIP_ERROR_FORMAT, err.Format()); + } + } + } + break; + } + + case chip::DeviceLayer::DeviceEventType::kFabricWillBeRemoved: + log_i("Fabric will be removed"); + break; + + case chip::DeviceLayer::DeviceEventType::kFabricUpdated: + log_i("Fabric is updated"); + break; + + case chip::DeviceLayer::DeviceEventType::kFabricCommitted: + log_i("Fabric is committed"); + break; + + case chip::DeviceLayer::DeviceEventType::kBLEDeinitialized: + log_i("BLE deinitialized and memory reclaimed"); + break; + + default: + break; + } +} + +esp_err_t matter_light_attribute_update(app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id, + uint32_t attribute_id, esp_matter_attr_val_t *val) +{ + esp_err_t err = ESP_OK; + if (endpoint_id == light_endpoint_id) { + void *led = (void *)driver_handle; + if (cluster_id == OnOff::Id) { + if (attribute_id == OnOff::Attributes::OnOff::Id) { + err = light_accessory_set_power(led, val->val.b); + } + } else if (cluster_id == LevelControl::Id) { + if (attribute_id == LevelControl::Attributes::CurrentLevel::Id) { + err = light_accessory_set_brightness(led, val->val.u8); + } + } else if (cluster_id == ColorControl::Id) { + if (attribute_id == ColorControl::Attributes::CurrentHue::Id) { + err = light_accessory_set_hue(led, val->val.u8); + } else if (attribute_id == ColorControl::Attributes::CurrentSaturation::Id) { + err = light_accessory_set_saturation(led, val->val.u8); + } else if (attribute_id == ColorControl::Attributes::ColorTemperatureMireds::Id) { + err = light_accessory_set_temperature(led, val->val.u16); + } + } + } + return err; +} + +esp_err_t matter_light_set_defaults(uint16_t endpoint_id) +{ + esp_err_t err = ESP_OK; + + void *led = endpoint::get_priv_data(endpoint_id); + node_t *node = node::get(); + endpoint_t *endpoint = endpoint::get(node, endpoint_id); + cluster_t *cluster = NULL; + attribute_t *attribute = NULL; + esp_matter_attr_val_t val = esp_matter_invalid(NULL); + + /* Setting brightness */ + cluster = cluster::get(endpoint, LevelControl::Id); + attribute = attribute::get(cluster, LevelControl::Attributes::CurrentLevel::Id); + attribute::get_val(attribute, &val); + err |= light_accessory_set_brightness(led, val.val.u8); + + /* Setting color */ + cluster = cluster::get(endpoint, ColorControl::Id); + attribute = attribute::get(cluster, ColorControl::Attributes::ColorMode::Id); + attribute::get_val(attribute, &val); + if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kCurrentHueAndCurrentSaturation) { + /* Setting hue */ + attribute = attribute::get(cluster, ColorControl::Attributes::CurrentHue::Id); + attribute::get_val(attribute, &val); + err |= light_accessory_set_hue(led, val.val.u8); + /* Setting saturation */ + attribute = attribute::get(cluster, ColorControl::Attributes::CurrentSaturation::Id); + attribute::get_val(attribute, &val); + err |= light_accessory_set_saturation(led, val.val.u8); + } else if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kColorTemperature) { + /* Setting temperature */ + attribute = attribute::get(cluster, ColorControl::Attributes::ColorTemperatureMireds::Id); + attribute::get_val(attribute, &val); + err |= light_accessory_set_temperature(led, val.val.u16); + } else { + log_e("Color mode not supported"); + } + + /* Setting power */ + cluster = cluster::get(endpoint, OnOff::Id); + attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id); + attribute::get_val(attribute, &val); + err |= light_accessory_set_power(led, val.val.b); + + return err; +} + +void button_driver_init() +{ + /* Initialize button */ + pinMode(button_gpio, INPUT_PULLUP); +} + +// This callback is called for every attribute update. The callback implementation shall +// handle the desired attributes and return an appropriate error code. If the attribute +// is not of your interest, please do not return an error code and strictly return ESP_OK. +static esp_err_t app_attribute_update_cb(attribute::callback_type_t type, uint16_t endpoint_id, uint32_t cluster_id, + uint32_t attribute_id, esp_matter_attr_val_t *val, void *priv_data) +{ + esp_err_t err = ESP_OK; + + if (type == PRE_UPDATE) { + /* Driver update */ + app_driver_handle_t driver_handle = (app_driver_handle_t)priv_data; + err = matter_light_attribute_update(driver_handle, endpoint_id, cluster_id, attribute_id, val); + } + + return err; +} + +// This callback is invoked when clients interact with the Identify Cluster. +// In the callback implementation, an endpoint can identify itself. (e.g., by flashing an LED or light). +static esp_err_t app_identification_cb(identification::callback_type_t type, uint16_t endpoint_id, uint8_t effect_id, + uint8_t effect_variant, void *priv_data) +{ + log_i("Identification callback: type: %u, effect: %u, variant: %u", type, effect_id, effect_variant); + return ESP_OK; +} + +void setup() +{ + esp_err_t err = ESP_OK; + + /* Initialize driver */ + app_driver_handle_t light_handle = light_accessory_init(); + button_driver_init(); + + /* Create a Matter node and add the mandatory Root Node device type on endpoint 0 */ + node::config_t node_config; + + // node handle can be used to add/modify other endpoints. + node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb); + if (node == nullptr) { + log_e("Failed to create Matter node"); + abort(); + } + + extended_color_light::config_t light_config; + light_config.on_off.on_off = DEFAULT_POWER; + light_config.on_off.lighting.start_up_on_off = nullptr; + light_config.level_control.current_level = DEFAULT_BRIGHTNESS; + light_config.level_control.lighting.start_up_current_level = DEFAULT_BRIGHTNESS; + light_config.color_control.color_mode = (uint8_t)ColorControl::ColorMode::kColorTemperature; + light_config.color_control.enhanced_color_mode = (uint8_t)ColorControl::ColorMode::kColorTemperature; + light_config.color_control.color_temperature.startup_color_temperature_mireds = nullptr; + + // endpoint handles can be used to add/modify clusters. + endpoint_t *endpoint = extended_color_light::create(node, &light_config, ENDPOINT_FLAG_NONE, light_handle); + if (endpoint == nullptr) { + log_e("Failed to create extended color light endpoint"); + abort(); + } + + light_endpoint_id = endpoint::get_id(endpoint); + log_i("Light created with endpoint_id %d", light_endpoint_id); + + /* Mark deferred persistence for some attributes that might be changed rapidly */ + cluster_t *level_control_cluster = cluster::get(endpoint, LevelControl::Id); + attribute_t *current_level_attribute = attribute::get(level_control_cluster, LevelControl::Attributes::CurrentLevel::Id); + attribute::set_deferred_persistence(current_level_attribute); + + cluster_t *color_control_cluster = cluster::get(endpoint, ColorControl::Id); + attribute_t *current_x_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentX::Id); + attribute::set_deferred_persistence(current_x_attribute); + attribute_t *current_y_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentY::Id); + attribute::set_deferred_persistence(current_y_attribute); + attribute_t *color_temp_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::ColorTemperatureMireds::Id); + attribute::set_deferred_persistence(color_temp_attribute); + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + /* Set OpenThread platform config */ + esp_openthread_platform_config_t config = { + .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), + .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), + }; + set_openthread_platform_config(&config); +#endif + + /* Matter start */ + err = esp_matter::start(app_event_cb); + if (err != ESP_OK) { + log_e("Failed to start Matter, err:%d", err); + abort(); + } + +#if CONFIG_ENABLE_ENCRYPTED_OTA + err = esp_matter_ota_requestor_encrypted_init(s_decryption_key, s_decryption_key_len); + if (err != ESP_OK) { + log_e("Failed to initialized the encrypted OTA, err: %d", err); + abort(); + } +#endif // CONFIG_ENABLE_ENCRYPTED_OTA + +#if CONFIG_ENABLE_CHIP_SHELL + esp_matter::console::diagnostics_register_commands(); + esp_matter::console::wifi_register_commands(); +#if CONFIG_OPENTHREAD_CLI + esp_matter::console::otcli_register_commands(); +#endif + esp_matter::console::init(); +#endif +} + +void loop() { + static uint32_t button_time_stamp = 0; + static bool button_state = false; + static bool started = false; + + if(!isAccessoryCommissioned()) { + log_w("Accessory not commissioned yet. Waiting for commissioning."); +#ifdef RGB_BUILTIN + rgbLedWrite(RGB_BUILTIN, 48, 0, 20); // Purple indicates accessory not commissioned +#endif + delay(5000); + return; + } + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + if (!isWifiConnected()) { + log_w("Wi-Fi not connected yet. Waiting for connection."); +#ifdef RGB_BUILTIN + rgbLedWrite(RGB_BUILTIN, 48, 20, 0); // Orange indicates accessory not connected to Wi-Fi +#endif + delay(5000); + return; + } +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + if (!isThreadConnected()) { + log_w("Thread not connected yet. Waiting for connection."); +#ifdef RGB_BUILTIN + rgbLedWrite(RGB_BUILTIN, 0, 20, 48); // Blue indicates accessory not connected to Trhead +#endif + delay(5000); + return; + } +#endif + + // Once all network connections are established, the accessory is ready for use + // Run it only once + if (!started) { + log_i("Accessory is commissioned and connected to Wi-Fi. Ready for use."); + started = true; + // Starting driver with default values + matter_light_set_defaults(light_endpoint_id); + } + + // Check if the button is pressed and toggle the light right away + if (digitalRead(button_gpio) == LOW && !button_state) { + // deals with button debounce + button_time_stamp = millis(); // record the time while the button is pressed. + button_state = true; // pressed. + + // Toggle button is pressed - toggle the light + log_i("Toggle button pressed"); + + endpoint_t *endpoint = endpoint::get(node::get(), light_endpoint_id); + cluster_t *cluster = cluster::get(endpoint, OnOff::Id); + attribute_t *attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id); + + esp_matter_attr_val_t val = esp_matter_invalid(NULL); + attribute::get_val(attribute, &val); + val.val.b = !val.val.b; + attribute::update(light_endpoint_id, OnOff::Id, OnOff::Attributes::OnOff::Id, &val); + } + + // Check if the button is released and handle the factory reset + uint32_t time_diff = millis() - button_time_stamp; + if (button_state && time_diff > 100 && digitalRead(button_gpio) == HIGH) { + button_state = false; // released. It can be pressed again after 100ms debounce. + + // Factory reset is triggered if the button is pressed for more than 10 seconds + if (time_diff > 10000) { + log_i("Factory reset triggered. Light will retored to factory settings."); + esp_matter::factory_reset(); + } + } + + delay(50); // WDT is happier with a delay +} diff --git a/examples/espidf-arduino-matter-light/partitions.csv b/examples/espidf-arduino-matter-light/partitions.csv new file mode 100644 index 000000000..ffe5f242e --- /dev/null +++ b/examples/espidf-arduino-matter-light/partitions.csv @@ -0,0 +1,10 @@ +# Name, Type, SubType, Offset, Size, Flags +# Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table +esp_secure_cert, 0x3F, ,0xd000, 0x2000, encrypted +nvs, data, nvs, 0x10000, 0xC000, +nvs_keys, data, nvs_keys,, 0x1000, encrypted +otadata, data, ota, , 0x2000 +phy_init, data, phy, , 0x1000, +ota_0, app, ota_0, 0x20000, 0x1E0000, +ota_1, app, ota_1, 0x200000, 0x1E0000, +fctry, data, nvs, 0x3E0000, 0x6000 diff --git a/examples/espidf-arduino-matter-light/platformio.ini b/examples/espidf-arduino-matter-light/platformio.ini new file mode 100644 index 000000000..2434a84f1 --- /dev/null +++ b/examples/espidf-arduino-matter-light/platformio.ini @@ -0,0 +1,28 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + + +[platformio] +src_dir = main + +[env] +platform = espressif32 +framework = arduino, espidf +board_build.partitions = partitions.csv +monitor_speed = 115200 + + +[env:esp32s3] +board = esp32-s3-devkitc-1 +board_build.embed_txtfiles = + managed_components/espressif__esp_insights/server_certs/https_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt diff --git a/examples/espidf-arduino-matter-light/sdkconfig.defaults b/examples/espidf-arduino-matter-light/sdkconfig.defaults new file mode 100644 index 000000000..517a05a2e --- /dev/null +++ b/examples/espidf-arduino-matter-light/sdkconfig.defaults @@ -0,0 +1,66 @@ +# Arduino Settings +CONFIG_FREERTOS_HZ=1000 +CONFIG_AUTOSTART_ARDUINO=y + +# Log Levels +# Boot Messages - Log level +CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y +# Arduino Log Level +CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_VERBOSE=y +# IDF Log Level +CONFIG_LOG_DEFAULT_LEVEL_WARN=y + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y + +#disable BT connection reattempt +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n + +#enable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0xC000 + +# Disable chip shell +CONFIG_ENABLE_CHIP_SHELL=n + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# Button +CONFIG_BUTTON_PERIOD_TIME_MS=20 +CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 + +# disable softap by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n + +# Disable DS Peripheral +CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n + +# Use compact attribute storage mode +CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + +# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1) +# unique local addresses for fabrics(MAX_FABRIC), a link local address(1) +CONFIG_LWIP_IPV6_NUM_ADDRESSES=6 + + +# ESP32-S3-DevKitC-1 Settings +# Buttons +CONFIG_BSP_BUTTONS_NUM=1 +CONFIG_BSP_BUTTON_1_TYPE_GPIO=y +CONFIG_BSP_BUTTON_1_GPIO=0 +CONFIG_BSP_BUTTON_1_LEVEL=0 +# LEDs +CONFIG_BSP_LEDS_NUM=1 +CONFIG_BSP_LED_TYPE_RGB=y +CONFIG_BSP_LED_RGB_GPIO=48 +CONFIG_BSP_LED_RGB_BACKEND_RMT=y \ No newline at end of file diff --git a/examples/espidf-arduino-matter-light/sdkconfig.defaults.c6_thread b/examples/espidf-arduino-matter-light/sdkconfig.defaults.c6_thread new file mode 100644 index 000000000..389c72c4b --- /dev/null +++ b/examples/espidf-arduino-matter-light/sdkconfig.defaults.c6_thread @@ -0,0 +1,80 @@ +CONFIG_IDF_TARGET="esp32c6" + +# Arduino Settings +CONFIG_FREERTOS_HZ=1000 +CONFIG_AUTOSTART_ARDUINO=y + +# Log Levels +# Boot Messages - Log level +CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y +# Arduino Log Level +CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO=y +# IDF Log Level +CONFIG_LOG_DEFAULT_LEVEL_ERROR=y + +# Default to 921600 baud when flashing and monitoring device +CONFIG_ESPTOOLPY_BAUD_921600B=y +CONFIG_ESPTOOLPY_BAUD=921600 +CONFIG_ESPTOOLPY_COMPRESSED=y +CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y + +# libsodium +CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y + +# NIMBLE +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_EXT_ADV=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=n + +# FreeRTOS should use legacy API +CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y + +# Enable OpenThread +CONFIG_OPENTHREAD_ENABLED=y +CONFIG_OPENTHREAD_SRP_CLIENT=y +CONFIG_OPENTHREAD_DNS_CLIENT=y +CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC=n +CONFIG_OPENTHREAD_LOG_LEVEL_NOTE=y +CONFIG_OPENTHREAD_CLI=n + +# Disable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=n + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" + +# LwIP config for OpenThread +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 +CONFIG_LWIP_MULTICAST_PING=y + +# MDNS platform +CONFIG_USE_MINIMAL_MDNS=n +CONFIG_ENABLE_EXTENDED_DISCOVERY=y + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=n + +# Disable STA and AP for ESP32C6 +CONFIG_ENABLE_WIFI_STATION=n +CONFIG_ENABLE_WIFI_AP=n + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=n + +# Disable persist subscriptions +CONFIG_ENABLE_PERSIST_SUBSCRIPTIONS=n + +# MRP configs +CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL_FOR_THREAD=5000 +CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL_FOR_THREAD=5000 +CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST_FOR_THREAD=5000 +CONFIG_MRP_MAX_RETRANS=3 + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + diff --git a/examples/espidf-arduino-matter-light/sdkconfig.defaults.esp32c3 b/examples/espidf-arduino-matter-light/sdkconfig.defaults.esp32c3 new file mode 100644 index 000000000..f534f3b7d --- /dev/null +++ b/examples/espidf-arduino-matter-light/sdkconfig.defaults.esp32c3 @@ -0,0 +1,64 @@ +CONFIG_IDF_TARGET="esp32c3" + +# Arduino Settings +CONFIG_FREERTOS_HZ=1000 +CONFIG_AUTOSTART_ARDUINO=y + +# Log Levels +# Boot Messages - Log level +CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y +# Arduino Log Level +CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO=y +# IDF Log Level +CONFIG_LOG_DEFAULT_LEVEL_ERROR=y + +# Default to 921600 baud when flashing and monitoring device +CONFIG_ESPTOOLPY_BAUD_921600B=y +CONFIG_ESPTOOLPY_BAUD=921600 +CONFIG_ESPTOOLPY_COMPRESSED=y +CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y + +#disable BT connection reattempt +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n + +#enable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0xC000 + +# Disable chip shell +CONFIG_ENABLE_CHIP_SHELL=n + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=n + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# disable softap by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n +CONFIG_ENABLE_WIFI_STATION=y +CONFIG_ENABLE_WIFI_AP=n + +# Disable DS Peripheral +CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n + +# Use compact attribute storage mode +CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + +# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1) +# unique local addresses for fabrics(MAX_FABRIC), a link local address(1) +CONFIG_LWIP_IPV6_NUM_ADDRESSES=6 diff --git a/examples/espidf-arduino-matter-light/sdkconfig.defaults.esp32c6 b/examples/espidf-arduino-matter-light/sdkconfig.defaults.esp32c6 new file mode 100644 index 000000000..301ee1a4e --- /dev/null +++ b/examples/espidf-arduino-matter-light/sdkconfig.defaults.esp32c6 @@ -0,0 +1,79 @@ +CONFIG_IDF_TARGET="esp32c6" + +# Arduino Settings +CONFIG_FREERTOS_HZ=1000 +CONFIG_AUTOSTART_ARDUINO=y + +# Log Levels +# Boot Messages - Log level +CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y +# Arduino Log Level +CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO=y +# IDF Log Level +CONFIG_LOG_DEFAULT_LEVEL_ERROR=y + +# Default to 921600 baud when flashing and monitoring device +CONFIG_ESPTOOLPY_BAUD_921600B=y +CONFIG_ESPTOOLPY_BAUD=921600 +CONFIG_ESPTOOLPY_COMPRESSED=y +CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y + +#disable BT connection reattempt +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n + +#enable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0xC000 + +# Disable chip shell +CONFIG_ENABLE_CHIP_SHELL=n + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=n + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# disable softap by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n +CONFIG_ENABLE_WIFI_STATION=y +CONFIG_ENABLE_WIFI_AP=n + +# Disable DS Peripheral +CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n + +# Use compact attribute storage mode +CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + +# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1) +# unique local addresses for fabrics(MAX_FABRIC), a link local address(1) +CONFIG_LWIP_IPV6_NUM_ADDRESSES=6 + +# libsodium +CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y + +# NIMBLE +CONFIG_BT_NIMBLE_EXT_ADV=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=y + +# FreeRTOS should use legacy API +CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y + +# Use minimal mDNS +CONFIG_USE_MINIMAL_MDNS=y +CONFIG_ENABLE_EXTENDED_DISCOVERY=y diff --git a/examples/espidf-arduino-matter-light/sdkconfig.defaults.esp32s3 b/examples/espidf-arduino-matter-light/sdkconfig.defaults.esp32s3 new file mode 100644 index 000000000..c7ecfa771 --- /dev/null +++ b/examples/espidf-arduino-matter-light/sdkconfig.defaults.esp32s3 @@ -0,0 +1,64 @@ +CONFIG_IDF_TARGET="esp32s3" + +# Arduino Settings +CONFIG_FREERTOS_HZ=1000 +CONFIG_AUTOSTART_ARDUINO=y + +# Log Levels +# Boot Messages - Log level +CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y +# Arduino Log Level +CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO=y +# IDF Log Level +CONFIG_LOG_DEFAULT_LEVEL_ERROR=y + +# Default to 921600 baud when flashing and monitoring device +CONFIG_ESPTOOLPY_BAUD_921600B=y +CONFIG_ESPTOOLPY_BAUD=921600 +CONFIG_ESPTOOLPY_COMPRESSED=y +CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y + +#disable BT connection reattempt +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n + +#enable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0xC000 + +# Disable chip shell +CONFIG_ENABLE_CHIP_SHELL=n + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=n + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# disable softap by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n +CONFIG_ENABLE_WIFI_STATION=y +CONFIG_ENABLE_WIFI_AP=n + +# Disable DS Peripheral +CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n + +# Use compact attribute storage mode +CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + +# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1) +# unique local addresses for fabrics(MAX_FABRIC), a link local address(1) +CONFIG_LWIP_IPV6_NUM_ADDRESSES=6 diff --git a/examples/espidf-ulp-pulse/test/README b/examples/espidf-arduino-matter-light/test/README similarity index 62% rename from examples/espidf-ulp-pulse/test/README rename to examples/espidf-arduino-matter-light/test/README index df5066e64..9b1e87bc6 100644 --- a/examples/espidf-ulp-pulse/test/README +++ b/examples/espidf-arduino-matter-light/test/README @@ -1,5 +1,5 @@ -This directory is intended for PIO Unit Testing and project tests. +This directory is intended for PlatformIO Test Runner and project tests. Unit Testing is a software testing method by which individual units of source code, sets of one or more MCU program modules together with associated @@ -7,5 +7,5 @@ control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use. Unit testing finds problems early in the development cycle. -More information about PIO Unit Testing: -- https://docs.platformio.org/page/plus/unit-testing.html +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/examples/espidf-arduino-wifiscan/.travis.yml b/examples/espidf-arduino-wifiscan/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-arduino-wifiscan/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-arduino-wifiscan/platformio.ini b/examples/espidf-arduino-wifiscan/platformio.ini index 6f6d15335..3dea0eabf 100644 --- a/examples/espidf-arduino-wifiscan/platformio.ini +++ b/examples/espidf-arduino-wifiscan/platformio.ini @@ -11,9 +11,12 @@ platform = espressif32 framework = arduino, espidf monitor_speed = 115200 - -[env:esp32dev] -board = esp32dev +board_build.esp-idf.preserve_source_file_extension = yes +board_build.embed_txtfiles = + managed_components/espressif__esp_insights/server_certs/https_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt [env:esp-wrover-kit] board = esp-wrover-kit diff --git a/examples/espidf-arduino-wifiscan/sdkconfig.defaults b/examples/espidf-arduino-wifiscan/sdkconfig.defaults index f67b30bf1..b902509e1 100644 --- a/examples/espidf-arduino-wifiscan/sdkconfig.defaults +++ b/examples/espidf-arduino-wifiscan/sdkconfig.defaults @@ -3,6 +3,10 @@ CONFIG_AUTOSTART_ARDUINO=y CONFIG_FREERTOS_HZ=1000 CONFIG_MBEDTLS_PSK_MODES=y CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y # Example config CONFIG_EXAMPLE_WIFI_SSID="MYSSID" CONFIG_EXAMPLE_WIFI_PASSWORD="MYPASS" diff --git a/examples/espidf-ble-eddystone/.gitignore b/examples/espidf-ble-eddystone/.gitignore deleted file mode 100644 index 03f4a3c19..000000000 --- a/examples/espidf-ble-eddystone/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.pio diff --git a/examples/espidf-ble-eddystone/.travis.yml b/examples/espidf-ble-eddystone/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-ble-eddystone/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-ble-eddystone/CMakeLists.txt b/examples/espidf-ble-eddystone/CMakeLists.txt deleted file mode 100644 index 9c5943ef0..000000000 --- a/examples/espidf-ble-eddystone/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# 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(ble_eddystone_demo) diff --git a/examples/espidf-ble-eddystone/README.md b/examples/espidf-ble-eddystone/README.md deleted file mode 100644 index 95ad3377c..000000000 --- a/examples/espidf-ble-eddystone/README.md +++ /dev/null @@ -1,27 +0,0 @@ -How to build PlatformIO based project -===================================== - -1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) -2. Download [development platform with examples](https://github.com/platformio/platform-espressif32/archive/develop.zip) -3. Extract ZIP archive -4. Run these commands: - -```shell -# Change directory to example -$ cd platform-espressif32/examples/espidf-ble-eddystone - -# Build project -$ pio run - -# Upload firmware -$ pio run --target upload - -# Build specific environment -$ pio run -e esp32dev - -# Upload firmware for the specific environment -$ pio run -e esp32dev --target upload - -# Clean build files -$ pio run --target clean -``` \ No newline at end of file diff --git a/examples/espidf-ble-eddystone/sdkconfig.defaults b/examples/espidf-ble-eddystone/sdkconfig.defaults deleted file mode 100644 index 00fb52113..000000000 --- a/examples/espidf-ble-eddystone/sdkconfig.defaults +++ /dev/null @@ -1,6 +0,0 @@ -# Override some defaults so BT stack is enabled -# and WiFi disabled by default in this example -CONFIG_BT_ENABLED=y -CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y -CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n -CONFIG_BTDM_CTRL_MODE_BTDM=n diff --git a/examples/espidf-ble-eddystone/src/CMakeLists.txt b/examples/espidf-ble-eddystone/src/CMakeLists.txt deleted file mode 100644 index 0820e85fc..000000000 --- a/examples/espidf-ble-eddystone/src/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -idf_component_register(SRCS "esp_eddystone_api.c" - "esp_eddystone_demo.c" - INCLUDE_DIRS "") -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/examples/espidf-ble-eddystone/src/esp_eddystone_api.c b/examples/espidf-ble-eddystone/src/esp_eddystone_api.c deleted file mode 100644 index 283211650..000000000 --- a/examples/espidf-ble-eddystone/src/esp_eddystone_api.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ - - -/**************************************************************************** -* -* This file is used to decode eddystone information. -* -****************************************************************************/ - -#include -#include -#include -#include - -#include "esp_err.h" -#include "esp_gap_ble_api.h" -#include "esp_eddystone_protocol.h" -#include "esp_eddystone_api.h" - - -/* Declare static functions */ -static esp_err_t esp_eddystone_uid_received(const uint8_t* buf, uint8_t len, esp_eddystone_result_t* res); -static esp_err_t esp_eddystone_url_received(const uint8_t* buf, uint8_t len, esp_eddystone_result_t* res); -static char* esp_eddystone_resolve_url_scheme(const uint8_t* url_start, const uint8_t* url_end); -static esp_err_t esp_eddystone_tlm_received(const uint8_t* buf, uint8_t len, esp_eddystone_result_t* res); -static esp_err_t esp_eddystone_get_inform(const uint8_t* buf, uint8_t len, esp_eddystone_result_t* res); - -/* Eddystone-URL scheme prefixes */ -static const char* eddystone_url_prefix[4] = { - "http://www.", - "https://www.", - "http://", - "https://" -}; - -/* Eddystone-URL HTTP URL encoding */ -static const char* eddystone_url_encoding[14] = { - ".com/", - ".org/", - ".edu/", - ".net/", - ".info/", - ".biz/", - ".gov/", - ".com", - ".org", - ".edu", - ".net", - ".info", - ".biz", - ".gov" - }; - -/****************** Eddystone-UID ************** -Byte offset Field Description - 0 Frame Type Value = 0x00 - 1 Ranging Data Calibrated Tx power at 0 m - 2 NID[0] 10-byte Namespace - 3 NID[1] - 4 NID[2] - 5 NID[3] - 6 NID[4] - 7 NID[5] - 8 NID[6] - 9 NID[7] - 10 NID[8] - 11 NID[9] - 12 BID[0] 6-byte Instance - 13 BID[1] - 14 BID[2] - 15 BID[3] - 16 BID[4] - 17 BID[5] - 18 RFU Reserved for future use, must be0x00 - 19 RFU Reserved for future use, must be0x00 -*********************************************/ -/* decode and store received UID */ -static esp_err_t esp_eddystone_uid_received(const uint8_t* buf, uint8_t len, esp_eddystone_result_t* res) -{ - uint8_t pos = 0; - //1-byte Ranging Data + 10-byte Namespace + 6-byte Instance - if((len != EDDYSTONE_UID_DATA_LEN) && (len != (EDDYSTONE_UID_RFU_LEN+EDDYSTONE_UID_DATA_LEN))) { - //ERROR:uid len wrong - return -1; - } - res->inform.uid.ranging_data = buf[pos++]; - for(int i=0; iinform.uid.namespace_id[i] = buf[pos++]; - } - for(int i=0; iinform.uid.instance_id[i] = buf[pos++]; - } - return 0; -} - -/* resolve received URL to url_res pointer */ -static char* esp_eddystone_resolve_url_scheme(const uint8_t *url_start, const uint8_t *url_end) -{ - int pos = 0; - static char url_buf[100] = {0}; - const uint8_t *p = url_start; - - pos += sprintf(&url_buf[pos], "%s", eddystone_url_prefix[*p++]); - - for (; p <= url_end; p++) { - if (esp_eddystone_is_char_invalid((*p))) { - pos += sprintf(&url_buf[pos], "%s", eddystone_url_encoding[*p]); - } else { - pos += sprintf(&url_buf[pos], "%c", *p); - } - } - return url_buf; -} - -/************************** Eddystone-URL ************* -Frame Specification - Byte offset Field Description - 0 Frame Type Value = 0x10 - 1 TX Power Calibrated Tx power at 0 m - 2 URL Scheme Encoded Scheme Prefix - 3+ Encoded URL Length 1-17 -*******************************************************/ -/* decode and store received URL, the pointer url_res points to the resolved url */ -static esp_err_t esp_eddystone_url_received(const uint8_t* buf, uint8_t len, esp_eddystone_result_t* res) -{ - char *url_res = NULL; - uint8_t pos = 0; - if(len-EDDYSTONE_URL_TX_POWER_LEN > EDDYSTONE_URL_MAX_LEN) { - //ERROR:too long url - return -1; - } - res->inform.url.tx_power = buf[pos++]; - url_res = esp_eddystone_resolve_url_scheme(buf+pos, buf+len-1); - memcpy(&res->inform.url.url, url_res, strlen(url_res)); - res->inform.url.url[strlen(url_res)] = '\0'; - return 0; -} - -/****************** eddystone-tlm *************** - * Unencrypted TLM Frame Specification -Byte offset Field Description - 0 Frame Type Value = 0x20 - 1 Version TLM version, value = 0x00 - 2 VBATT[0] Battery voltage, 1 mV/bit - 3 VBATT[1] - 4 TEMP[0] Beacon temperature - 5 TEMP[1] - 6 ADV_CNT[0] Advertising PDU count - 7 ADV_CNT[1] - 8 ADV_CNT[2] - 9 ADV_CNT[3] - 10 SEC_CNT[0] Time since power-on or reboot - 11 SEC_CNT[1] - 12 SEC_CNT[2] - 13 SEC_CNT[3] -************************************************/ -/* decode and store received TLM */ -static esp_err_t esp_eddystone_tlm_received(const uint8_t* buf, uint8_t len, esp_eddystone_result_t* res) -{ - uint8_t pos = 0; - if(len > EDDYSTONE_TLM_DATA_LEN) { - //ERROR:TLM too long - return -1; - } - res->inform.tlm.version = buf[pos++]; - res->inform.tlm.battery_voltage = big_endian_read_16(buf, pos); - pos += 2; - uint16_t temp = big_endian_read_16(buf, pos); - int8_t temp_integral = (int8_t)((temp >> 8) & 0xff); - float temp_decimal = (temp & 0xff) / 256.0; - res->inform.tlm.temperature = temp_integral + temp_decimal; - pos += 2; - res->inform.tlm.adv_count = big_endian_read_32(buf, pos); - pos += 4; - res->inform.tlm.time = big_endian_read_32(buf, pos); - return 0; -} - -static esp_err_t esp_eddystone_get_inform(const uint8_t* buf, uint8_t len, esp_eddystone_result_t* res) -{ - static esp_err_t ret=-1; - switch(res->common.frame_type) - { - case EDDYSTONE_FRAME_TYPE_UID: { - ret = esp_eddystone_uid_received(buf, len, res); - break; - } - case EDDYSTONE_FRAME_TYPE_URL: { - ret = esp_eddystone_url_received(buf, len, res); - break; - } - case EDDYSTONE_FRAME_TYPE_TLM: { - ret = esp_eddystone_tlm_received(buf, len, res); - break; - } - default: - break; - } - return ret; -} - -esp_err_t esp_eddystone_decode(const uint8_t* buf, uint8_t len, esp_eddystone_result_t* res) -{ - if (len == 0 || buf == NULL || res == NULL) { - return -1; - } - uint8_t pos=0; - while(res->common.srv_data_type != EDDYSTONE_SERVICE_UUID) - { - pos++; - if(pos >= len ) { - return -1; - } - uint8_t ad_type = buf[pos++]; - switch(ad_type) - { - case ESP_BLE_AD_TYPE_FLAG: { - res->common.flags = buf[pos++]; - break; - } - case ESP_BLE_AD_TYPE_16SRV_CMPL: { - uint16_t uuid = little_endian_read_16(buf, pos); - if(uuid != EDDYSTONE_SERVICE_UUID) { - return -1; - } - res->common.srv_uuid = uuid; - pos += 2; - break; - } - case ESP_BLE_AD_TYPE_SERVICE_DATA: { - uint16_t type = little_endian_read_16(buf, pos); - pos += 2; - uint8_t frame_type = buf[pos++]; - if(type != EDDYSTONE_SERVICE_UUID || !(frame_type == EDDYSTONE_FRAME_TYPE_UID || frame_type == EDDYSTONE_FRAME_TYPE_URL || - frame_type == EDDYSTONE_FRAME_TYPE_TLM)) { - return -1; - } - res->common.srv_data_type = type; - res->common.frame_type = frame_type; - break; - } - default: - break; - } - } - return esp_eddystone_get_inform(buf+pos, len-pos, res); -} diff --git a/examples/espidf-ble-eddystone/src/esp_eddystone_api.h b/examples/espidf-ble-eddystone/src/esp_eddystone_api.h deleted file mode 100644 index 752044f67..000000000 --- a/examples/espidf-ble-eddystone/src/esp_eddystone_api.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ - - -#ifndef __ESP_EDDYSTONE_API_H__ -#define __ESP_EDDYSTONE_API_H__ - -typedef struct { - struct { - uint8_t flags; /* -#include -#include - -#include "esp_bt.h" -#include "nvs_flash.h" -#include "esp_log.h" -#include "esp_bt_defs.h" -#include "esp_bt_main.h" -#include "esp_gatt_defs.h" -#include "esp_gattc_api.h" -#include "esp_gap_ble_api.h" -#include "freertos/FreeRTOS.h" - -#include "esp_eddystone_protocol.h" -#include "esp_eddystone_api.h" - -static const char* DEMO_TAG = "EDDYSTONE_DEMO"; - -/* declare static functions */ -static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param); -static void esp_eddystone_show_inform(const esp_eddystone_result_t* res); - -static esp_ble_scan_params_t ble_scan_params = { - .scan_type = BLE_SCAN_TYPE_ACTIVE, - .own_addr_type = BLE_ADDR_TYPE_PUBLIC, - .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, - .scan_interval = 0x50, - .scan_window = 0x30, - .scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE -}; - -static void esp_eddystone_show_inform(const esp_eddystone_result_t* res) -{ - switch(res->common.frame_type) - { - case EDDYSTONE_FRAME_TYPE_UID: { - ESP_LOGI(DEMO_TAG, "Eddystone UID inform:"); - ESP_LOGI(DEMO_TAG, "Measured power(RSSI at 0m distance):%d dbm", res->inform.uid.ranging_data); - ESP_LOGI(DEMO_TAG, "EDDYSTONE_DEMO: Namespace ID:0x"); - esp_log_buffer_hex(DEMO_TAG, res->inform.uid.namespace_id, 10); - ESP_LOGI(DEMO_TAG, "EDDYSTONE_DEMO: Instance ID:0x"); - esp_log_buffer_hex(DEMO_TAG, res->inform.uid.instance_id, 6); - break; - } - case EDDYSTONE_FRAME_TYPE_URL: { - ESP_LOGI(DEMO_TAG, "Eddystone URL inform:"); - ESP_LOGI(DEMO_TAG, "Measured power(RSSI at 0m distance):%d dbm", res->inform.url.tx_power); - ESP_LOGI(DEMO_TAG, "URL: %s", res->inform.url.url); - break; - } - case EDDYSTONE_FRAME_TYPE_TLM: { - ESP_LOGI(DEMO_TAG, "Eddystone TLM inform:"); - ESP_LOGI(DEMO_TAG, "version: %d", res->inform.tlm.version); - ESP_LOGI(DEMO_TAG, "battery voltage: %d mV", res->inform.tlm.battery_voltage); - ESP_LOGI(DEMO_TAG, "beacon temperature in degrees Celsius: %6.1f", res->inform.tlm.temperature); - ESP_LOGI(DEMO_TAG, "adv pdu count since power-up: %d", res->inform.tlm.adv_count); - ESP_LOGI(DEMO_TAG, "time since power-up: %d s", (res->inform.tlm.time)/10); - break; - } - default: - break; - } -} - -static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param) -{ - esp_err_t err; - - switch(event) - { - case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: { - uint32_t duration = 0; - esp_ble_gap_start_scanning(duration); - break; - } - case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: { - if((err = param->scan_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) { - ESP_LOGE(DEMO_TAG,"Scan start failed: %s", esp_err_to_name(err)); - } - else { - ESP_LOGI(DEMO_TAG,"Start scanning..."); - } - break; - } - case ESP_GAP_BLE_SCAN_RESULT_EVT: { - esp_ble_gap_cb_param_t* scan_result = (esp_ble_gap_cb_param_t*)param; - switch(scan_result->scan_rst.search_evt) - { - case ESP_GAP_SEARCH_INQ_RES_EVT: { - esp_eddystone_result_t eddystone_res; - memset(&eddystone_res, 0, sizeof(eddystone_res)); - esp_err_t ret = esp_eddystone_decode(scan_result->scan_rst.ble_adv, scan_result->scan_rst.adv_data_len, &eddystone_res); - if (ret) { - // error:The received data is not an eddystone frame packet or a correct eddystone frame packet. - // just return - return; - } else { - // The received adv data is a correct eddystone frame packet. - // Here, we get the eddystone infomation in eddystone_res, we can use the data in res to do other things. - // For example, just print them: - ESP_LOGI(DEMO_TAG, "--------Eddystone Found----------"); - esp_log_buffer_hex("EDDYSTONE_DEMO: Device address:", scan_result->scan_rst.bda, ESP_BD_ADDR_LEN); - ESP_LOGI(DEMO_TAG, "RSSI of packet:%d dbm", scan_result->scan_rst.rssi); - esp_eddystone_show_inform(&eddystone_res); - } - break; - } - default: - break; - } - break; - } - case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:{ - if((err = param->scan_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS) { - ESP_LOGE(DEMO_TAG,"Scan stop failed: %s", esp_err_to_name(err)); - } - else { - ESP_LOGI(DEMO_TAG,"Stop scan successfully"); - } - break; - } - default: - break; - } -} - -void esp_eddystone_appRegister(void) -{ - esp_err_t status; - - ESP_LOGI(DEMO_TAG,"Register callback"); - - /*= 0x00 && ch <= 0x20) || (ch >= 0x7f && ch <= 0xff); -} - -#endif /* __ESP_EDDYSTONE_PROTOCOL_H__ */ diff --git a/examples/arduino-ble5-advertising/.gitignore b/examples/espidf-blink/.gitignore similarity index 100% rename from examples/arduino-ble5-advertising/.gitignore rename to examples/espidf-blink/.gitignore diff --git a/examples/espidf-ulp-pulse/CMakeLists.txt b/examples/espidf-blink/CMakeLists.txt similarity index 74% rename from examples/espidf-ulp-pulse/CMakeLists.txt rename to examples/espidf-blink/CMakeLists.txt index f0c74a151..a347b9736 100644 --- a/examples/espidf-ulp-pulse/CMakeLists.txt +++ b/examples/espidf-blink/CMakeLists.txt @@ -1,3 +1,3 @@ cmake_minimum_required(VERSION 3.16.0) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(espidf-ulp-pulse-new) +project(espidf-blink) diff --git a/examples/espidf-ulp-adc/README.md b/examples/espidf-blink/README.md similarity index 91% rename from examples/espidf-ulp-adc/README.md rename to examples/espidf-blink/README.md index abe2df482..1fbbba65a 100644 --- a/examples/espidf-ulp-adc/README.md +++ b/examples/espidf-blink/README.md @@ -8,7 +8,7 @@ How to build PlatformIO based project ```shell # Change directory to example -$ cd platform-espressif32/examples/espidf-ulp-adc +$ cd platform-espressif32/examples/espidf-blink # Build project $ pio run @@ -24,4 +24,4 @@ $ pio run -e esp32dev --target upload # Clean build files $ pio run --target clean -``` +``` \ No newline at end of file diff --git a/examples/espidf-blink/include/README b/examples/espidf-blink/include/README new file mode 100644 index 000000000..194dcd432 --- /dev/null +++ b/examples/espidf-blink/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/espidf-blink/lib/README b/examples/espidf-blink/lib/README new file mode 100644 index 000000000..bb6727c81 --- /dev/null +++ b/examples/espidf-blink/lib/README @@ -0,0 +1,77 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | + +# Blink Example + +(See the README.md file in the upper level 'examples' directory for more information about examples.) + +This example demonstrates how to blink a LED using GPIO or using the [led_strip](https://components.espressif.com/component/espressif/led_strip) component for the addressable LED, i.e. [WS2812](http://www.world-semi.com/Certifications/WS2812B.html). + +The `led_strip` is installed via [component manager](main/idf_component.yml). + +## How to Use Example + +Before project configuration and build, be sure to set the correct chip target using `idf.py set-target `. + +### Hardware Required + +* A development board with Espressif SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) +* A USB cable for Power supply and programming + +Some development boards use an addressable LED instead of a regular one. These development boards include: + +| Board | LED type | Pin | +| -------------------- | -------------------- | -------------------- | +| ESP32-C3-DevKitC-1 | Addressable | GPIO8 | +| ESP32-C3-DevKitM-1 | Addressable | GPIO8 | +| ESP32-S2-DevKitM-1 | Addressable | GPIO18 | +| ESP32-S2-Saola-1 | Addressable | GPIO18 | +| ESP32-S3-DevKitC-1 | Addressable | GPIO48 | + +See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it. + +### Configure the Project + +Open the project configuration menu (`idf.py menuconfig`). + +In the `Example Configuration` menu: + +* Select the LED type in the `Blink LED type` option. + * Use `GPIO` for regular LED blink. +* Set the GPIO number used for the signal in the `Blink GPIO number` option. +* Set the blinking period in the `Blink period in ms` option. + +### Build and Flash + +Run `idf.py -p PORT flash monitor` to build, flash and monitor the project. + +(To exit the serial monitor, type ``Ctrl-]``.) + +See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects. + +## Example Output + +As you run the example, you will see the LED blinking, according to the previously defined period. For the addressable LED, you can also change the LED color by setting the `led_strip_set_pixel(led_strip, 0, 16, 16, 16);` (LED Strip, Pixel Number, Red, Green, Blue) with values from 0 to 255 in the [source file](main/blink_example_main.c). + +```text +I (315) example: Example configured to blink addressable LED! +I (325) example: Turning the LED OFF! +I (1325) example: Turning the LED ON! +I (2325) example: Turning the LED OFF! +I (3325) example: Turning the LED ON! +I (4325) example: Turning the LED OFF! +I (5325) example: Turning the LED ON! +I (6325) example: Turning the LED OFF! +I (7325) example: Turning the LED ON! +I (8325) example: Turning the LED OFF! +``` + +Note: The color order could be different according to the LED model. + +The pixel number indicates the pixel position in the LED strip. For a single LED, use 0. + +## Troubleshooting + +* If the LED isn't blinking, check the GPIO or the LED type selection in the `Example Configuration` menu. + +For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. \ No newline at end of file diff --git a/examples/espidf-blink/platformio.ini b/examples/espidf-blink/platformio.ini new file mode 100644 index 000000000..44b4ff9a1 --- /dev/null +++ b/examples/espidf-blink/platformio.ini @@ -0,0 +1,39 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32dev] +platform = espressif32 +framework = espidf +board = esp32dev +monitor_speed = 115200 +build_flags = + ; https://docs.espressif.com/projects/esp-idf/en/latest/get-started/get-started-wrover-kit.html#rgb-led + -D CONFIG_BLINK_GPIO=2 + -D CONFIG_BLINK_LED_GPIO=2 + -D CONFIG_BLINK_PERIOD=1000 + +[env:esp32-c2-devkitm-1] +platform = espressif32 +framework = espidf +board = esp32-c2-devkitm-1 +monitor_speed = 115200 +build_flags = + -D CONFIG_BLINK_GPIO=8 + -D CONFIG_BLINK_LED_GPIO=8 + -D CONFIG_BLINK_PERIOD=1000 + +[env:esp32-c6-devkitc-1] +platform = espressif32 +framework = espidf +board = esp32-c6-devkitc-1 +monitor_speed = 115200 +build_flags = + -D CONFIG_BLINK_GPIO=2 + -D CONFIG_BLINK_LED_GPIO=2 + -D CONFIG_BLINK_PERIOD=1000 diff --git a/examples/espidf-blink/sdkconfig.defaults b/examples/espidf-blink/sdkconfig.defaults new file mode 100644 index 000000000..eda3b11f3 --- /dev/null +++ b/examples/espidf-blink/sdkconfig.defaults @@ -0,0 +1,4 @@ +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y diff --git a/examples/espidf-blink/src/CMakeLists.txt b/examples/espidf-blink/src/CMakeLists.txt new file mode 100644 index 000000000..413c3b514 --- /dev/null +++ b/examples/espidf-blink/src/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "blink.c" + INCLUDE_DIRS ".") \ No newline at end of file diff --git a/examples/espidf-blink/src/blink.c b/examples/espidf-blink/src/blink.c new file mode 100644 index 000000000..a4cde01e7 --- /dev/null +++ b/examples/espidf-blink/src/blink.c @@ -0,0 +1,91 @@ +/* Blink Example + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "driver/gpio.h" +#include "esp_log.h" +//#include "led_strip.h" +#include "sdkconfig.h" + +static const char *TAG = "example"; + +/* Use project configuration menu (idf.py menuconfig) to choose the GPIO to blink, + or you can edit the following line and set a number here. +*/ +#define BLINK_GPIO CONFIG_BLINK_GPIO + +static uint8_t s_led_state = 0; + +#ifdef CONFIG_BLINK_LED_RMT + +static led_strip_handle_t led_strip; + +static void blink_led(void) +{ + /* If the addressable LED is enabled */ + if (s_led_state) { + /* Set the LED pixel using RGB from 0 (0%) to 255 (100%) for each color */ + led_strip_set_pixel(led_strip, 0, 16, 16, 16); + /* Refresh the strip to send data */ + led_strip_refresh(led_strip); + } else { + /* Set all LED off to clear all pixels */ + led_strip_clear(led_strip); + } +} + +static void configure_led(void) +{ + ESP_LOGI(TAG, "Example configured to blink addressable LED!"); + /* LED strip initialization with the GPIO and pixels number*/ + led_strip_config_t strip_config = { + .strip_gpio_num = BLINK_GPIO, + .max_leds = 1, // at least one LED on board + }; + led_strip_rmt_config_t rmt_config = { + .resolution_hz = 10 * 1000 * 1000, // 10MHz + }; + ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip)); + /* Set all LED off to clear all pixels */ + led_strip_clear(led_strip); +} + +#elif CONFIG_BLINK_LED_GPIO + +static void blink_led(void) +{ + /* Set the GPIO level according to the state (LOW or HIGH)*/ + gpio_set_level(BLINK_GPIO, s_led_state); +} + +static void configure_led(void) +{ + ESP_LOGI(TAG, "Example configured to blink GPIO LED!"); + gpio_reset_pin(BLINK_GPIO); + /* Set the GPIO as a push/pull output */ + gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); +} + +#endif + +void app_main(void) +{ + + /* Configure the peripheral according to the LED type */ + configure_led(); + + while (1) { + ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF"); + blink_led(); + /* Toggle the LED state */ + s_led_state = !s_led_state; + vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS); + } +} diff --git a/examples/espidf-ulp-adc/test/README b/examples/espidf-blink/test/README similarity index 100% rename from examples/espidf-ulp-adc/test/README rename to examples/espidf-blink/test/README diff --git a/examples/espidf-coap-server/.travis.yml b/examples/espidf-coap-server/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-coap-server/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-coap-server/platformio.ini b/examples/espidf-coap-server/platformio.ini index 78383c341..c26b3222a 100644 --- a/examples/espidf-coap-server/platformio.ini +++ b/examples/espidf-coap-server/platformio.ini @@ -16,11 +16,5 @@ board_build.embed_txtfiles = src/certs/coap_server.crt src/certs/coap_server.key -[env:nano32] -board = nano32 - [env:esp-wrover-kit] board = esp-wrover-kit - -[env:esp32dev] -board = esp32dev diff --git a/examples/espidf-exceptions/.travis.yml b/examples/espidf-exceptions/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-exceptions/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-exceptions/platformio.ini b/examples/espidf-exceptions/platformio.ini index a6c3cff92..a4031d38f 100644 --- a/examples/espidf-exceptions/platformio.ini +++ b/examples/espidf-exceptions/platformio.ini @@ -12,11 +12,5 @@ platform = espressif32 framework = espidf monitor_speed = 115200 -[env:esp32dev] -board = esp32dev - [env:esp-wrover-kit] board = esp-wrover-kit - -[env:lolin32] -board = lolin32 diff --git a/examples/espidf-hello-world/.travis.yml b/examples/espidf-hello-world/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-hello-world/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-hello-world/platformio.ini b/examples/espidf-hello-world/platformio.ini index 44102cc88..226510eb1 100644 --- a/examples/espidf-hello-world/platformio.ini +++ b/examples/espidf-hello-world/platformio.ini @@ -20,8 +20,3 @@ board = esp32-s2-kaluga-1 [env:esp32-c3-devkitm-1] board = esp32-c3-devkitm-1 - -[env:esp32-c6-devkitc-1] -board = esp32-c6-devkitc-1 -board_build.cmake_extra_args = - -DSDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32c6" diff --git a/examples/espidf-hello-world/sdkconfig.defaults.esp32c6 b/examples/espidf-hello-world/sdkconfig.defaults.esp32c6 deleted file mode 100644 index 6c73965bc..000000000 --- a/examples/espidf-hello-world/sdkconfig.defaults.esp32c6 +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y -CONFIG_ESPTOOLPY_FLASHSIZE="8MB" diff --git a/examples/espidf-http-request/.travis.yml b/examples/espidf-http-request/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-http-request/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-http-request/platformio.ini b/examples/espidf-http-request/platformio.ini index 38756e618..75537f7a6 100644 --- a/examples/espidf-http-request/platformio.ini +++ b/examples/espidf-http-request/platformio.ini @@ -15,11 +15,5 @@ monitor_speed = 115200 [env:esp32dev] board = esp32dev -[env:nano32] -board = nano32 - -[env:espea32] -board = espea32 - [env:esp32-s2-saola-1] board = esp32-s2-saola-1 diff --git a/examples/espidf-peripherals-uart/.travis.yml b/examples/espidf-peripherals-uart/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-peripherals-uart/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-peripherals-uart/platformio.ini b/examples/espidf-peripherals-uart/platformio.ini index 84e7f72d8..b004a1b2f 100644 --- a/examples/espidf-peripherals-uart/platformio.ini +++ b/examples/espidf-peripherals-uart/platformio.ini @@ -12,11 +12,5 @@ platform = espressif32 framework = espidf monitor_speed = 115200 -[env:pocket_32] -board = pocket_32 - [env:odroid_esp32] board = odroid_esp32 - -[env:featheresp32] -board = featheresp32 diff --git a/examples/espidf-peripherals-usb/.travis.yml b/examples/espidf-peripherals-usb/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-peripherals-usb/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-storage-sdcard/.travis.yml b/examples/espidf-storage-sdcard/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-storage-sdcard/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-storage-sdcard/platformio.ini b/examples/espidf-storage-sdcard/platformio.ini index 112293123..66f1b78d2 100644 --- a/examples/espidf-storage-sdcard/platformio.ini +++ b/examples/espidf-storage-sdcard/platformio.ini @@ -12,11 +12,5 @@ platform = espressif32 framework = espidf monitor_speed = 115200 -[env:esp32thing] -board = esp32thing - -[env:esp32-gateway] -board = esp32-gateway - [env:heltec_wifi_kit_32] board = heltec_wifi_kit_32 diff --git a/examples/espidf-storage-spiffs/.gitignore b/examples/espidf-storage-spiffs/.gitignore deleted file mode 100644 index 03f4a3c19..000000000 --- a/examples/espidf-storage-spiffs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.pio diff --git a/examples/espidf-storage-spiffs/README.md b/examples/espidf-storage-spiffs/README.md deleted file mode 100644 index 214f9ba67..000000000 --- a/examples/espidf-storage-spiffs/README.md +++ /dev/null @@ -1,24 +0,0 @@ -How to build PlatformIO based project -===================================== - -1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) -2. Download [development platform with examples](https://github.com/platformio/platform-espressif32/archive/develop.zip) -3. Extract ZIP archive -4. Run these commands: - -```shell -# Change directory to example -$ cd platform-espressif32/examples/espidf-storage-spiffs - -# Build project -$ pio run - -# Upload firmware -$ pio run --target upload - -# Upload SPIFFS image -$ pio run --target uploadfs - -# Clean build files -$ pio run --target clean -``` diff --git a/examples/espidf-storage-spiffs/data/hello.txt b/examples/espidf-storage-spiffs/data/hello.txt deleted file mode 100644 index 5a8367719..000000000 --- a/examples/espidf-storage-spiffs/data/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello World from SPIFFS. diff --git a/examples/espidf-storage-spiffs/partitions_example.csv b/examples/espidf-storage-spiffs/partitions_example.csv deleted file mode 100644 index 92db904e0..000000000 --- a/examples/espidf-storage-spiffs/partitions_example.csv +++ /dev/null @@ -1,6 +0,0 @@ -# Name, Type, SubType, Offset, Size, Flags -# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap -nvs, data, nvs, 0x9000, 0x6000, -phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 1M, -spiffs, data, spiffs, , 0xF0000, diff --git a/examples/espidf-storage-spiffs/sdkconfig.defaults b/examples/espidf-storage-spiffs/sdkconfig.defaults deleted file mode 100644 index b9bb0c0a5..000000000 --- a/examples/espidf-storage-spiffs/sdkconfig.defaults +++ /dev/null @@ -1,3 +0,0 @@ -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_example.csv" -CONFIG_PARTITION_TABLE_FILENAME="partitions_example.csv" diff --git a/examples/espidf-storage-spiffs/src/CMakeLists.txt b/examples/espidf-storage-spiffs/src/CMakeLists.txt deleted file mode 100644 index c480915ab..000000000 --- a/examples/espidf-storage-spiffs/src/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -idf_component_register(SRCS "spiffs_example_main.c" - INCLUDE_DIRS ".") diff --git a/examples/espidf-storage-spiffs/src/Kconfig.projbuild b/examples/espidf-storage-spiffs/src/Kconfig.projbuild deleted file mode 100644 index eadd67909..000000000 --- a/examples/espidf-storage-spiffs/src/Kconfig.projbuild +++ /dev/null @@ -1,9 +0,0 @@ -menu "SPIFFS Example menu" - - config EXAMPLE_SPIFFS_CHECK_ON_START - bool "Run SPIFFS_check on every start-up" - default y - help - If this config item is set, esp_spiffs_check() will be run on every start-up. - Slow on large flash sizes. -endmenu diff --git a/examples/espidf-storage-spiffs/src/spiffs_example_main.c b/examples/espidf-storage-spiffs/src/spiffs_example_main.c deleted file mode 100644 index 32cc17686..000000000 --- a/examples/espidf-storage-spiffs/src/spiffs_example_main.c +++ /dev/null @@ -1,127 +0,0 @@ -/* SPIFFS filesystem example. - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ - -#include -#include -#include -#include -#include "esp_err.h" -#include "esp_log.h" -#include "esp_spiffs.h" - -static const char *TAG = "example"; - -void app_main(void) -{ - ESP_LOGI(TAG, "Initializing SPIFFS"); - - esp_vfs_spiffs_conf_t conf = { - .base_path = "/spiffs", - .partition_label = NULL, - .max_files = 5, - .format_if_mount_failed = true - }; - - // Use settings defined above to initialize and mount SPIFFS filesystem. - // Note: esp_vfs_spiffs_register is an all-in-one convenience function. - esp_err_t ret = esp_vfs_spiffs_register(&conf); - - if (ret != ESP_OK) { - if (ret == ESP_FAIL) { - ESP_LOGE(TAG, "Failed to mount or format filesystem"); - } else if (ret == ESP_ERR_NOT_FOUND) { - ESP_LOGE(TAG, "Failed to find SPIFFS partition"); - } else { - ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret)); - } - return; - } - -#ifdef CONFIG_EXAMPLE_SPIFFS_CHECK_ON_START - ESP_LOGI(TAG, "Performing SPIFFS_check()."); - ret = esp_spiffs_check(conf.partition_label); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "SPIFFS_check() failed (%s)", esp_err_to_name(ret)); - return; - } else { - ESP_LOGI(TAG, "SPIFFS_check() successful"); - } -#endif - - size_t total = 0, used = 0; - ret = esp_spiffs_info(conf.partition_label, &total, &used); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s). Formatting...", esp_err_to_name(ret)); - esp_spiffs_format(conf.partition_label); - return; - } else { - ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used); - } - -# - // Check consistency of reported partiton size info. - if (used > total) { - ESP_LOGW(TAG, "Number of used bytes cannot be larger than total. Performing SPIFFS_check()."); - ret = esp_spiffs_check(conf.partition_label); - // Could be also used to mend broken files, to clean unreferenced pages, etc. - // More info at https://github.com/pellepl/spiffs/wiki/FAQ#powerlosses-contd-when-should-i-run-spiffs_check - if (ret != ESP_OK) { - ESP_LOGE(TAG, "SPIFFS_check() failed (%s)", esp_err_to_name(ret)); - return; - } else { - ESP_LOGI(TAG, "SPIFFS_check() successful"); - } - } - - // Use POSIX and C standard library functions to work with files. - // First create a file. - ESP_LOGI(TAG, "Opening file"); - FILE* f = fopen("/spiffs/hello.txt", "w"); - if (f == NULL) { - ESP_LOGE(TAG, "Failed to open file for writing"); - return; - } - fprintf(f, "Hello World!\n"); - fclose(f); - ESP_LOGI(TAG, "File written"); - - // Check if destination file exists before renaming - struct stat st; - if (stat("/spiffs/foo.txt", &st) == 0) { - // Delete it if it exists - unlink("/spiffs/foo.txt"); - } - - // Rename original file - ESP_LOGI(TAG, "Renaming file"); - if (rename("/spiffs/hello.txt", "/spiffs/foo.txt") != 0) { - ESP_LOGE(TAG, "Rename failed"); - return; - } - - // Open renamed file for reading - ESP_LOGI(TAG, "Reading file"); - f = fopen("/spiffs/foo.txt", "r"); - if (f == NULL) { - ESP_LOGE(TAG, "Failed to open file for reading"); - return; - } - char line[64]; - fgets(line, sizeof(line), f); - fclose(f); - // strip newline - char* pos = strchr(line, '\n'); - if (pos) { - *pos = '\0'; - } - ESP_LOGI(TAG, "Read from file: '%s'", line); - - // All done, unmount partition and disable SPIFFS - esp_vfs_spiffs_unregister(conf.partition_label); - ESP_LOGI(TAG, "SPIFFS unmounted"); -} diff --git a/examples/espidf-ulp-adc/.gitignore b/examples/espidf-ulp-adc/.gitignore deleted file mode 100644 index 03f4a3c19..000000000 --- a/examples/espidf-ulp-adc/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.pio diff --git a/examples/espidf-ulp-adc/.travis.yml b/examples/espidf-ulp-adc/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-ulp-adc/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-ulp-adc/main/ulp_adc_example_main.c b/examples/espidf-ulp-adc/main/ulp_adc_example_main.c deleted file mode 100644 index 882128329..000000000 --- a/examples/espidf-ulp-adc/main/ulp_adc_example_main.c +++ /dev/null @@ -1,108 +0,0 @@ -/* ULP Example - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ - -#include -#include -#include -#include "esp_sleep.h" -#include "soc/rtc_cntl_reg.h" -#include "soc/sens_reg.h" -#include "driver/gpio.h" -#include "driver/rtc_io.h" -#include "ulp.h" -#include "ulp_main.h" -#include "esp_adc/adc_oneshot.h" -#include "ulp/example_config.h" -#include "ulp_adc.h" - -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" - -extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start"); -extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end"); - -/* This function is called once after power-on reset, to load ULP program into - * RTC memory and configure the ADC. - */ -static void init_ulp_program(void); - -/* This function is called every time before going into deep sleep. - * It starts the ULP program and resets measurement counter. - */ -static void start_ulp_program(void); - -void app_main(void) -{ - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not ULP wakeup\n"); - init_ulp_program(); - } else { - printf("Deep sleep wakeup\n"); - printf("ULP did %"PRIu32" measurements since last reset\n", ulp_sample_counter & UINT16_MAX); - printf("Thresholds: low=%"PRIu32" high=%"PRIu32"\n", ulp_low_thr, ulp_high_thr); - ulp_last_result &= UINT16_MAX; - printf("Value=%"PRIu32" was %s threshold\n", ulp_last_result, - ulp_last_result < ulp_low_thr ? "below" : "above"); - } - printf("Entering deep sleep\n\n"); - start_ulp_program(); - ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup() ); - -#if !CONFIG_IDF_TARGET_ESP32 - /* RTC peripheral power domain needs to be kept on to keep SAR ADC related configs during sleep */ - esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); -#endif - - esp_deep_sleep_start(); -} - -static void init_ulp_program(void) -{ - esp_err_t err = ulp_load_binary(0, ulp_main_bin_start, - (ulp_main_bin_end - ulp_main_bin_start) / sizeof(uint32_t)); - ESP_ERROR_CHECK(err); - - ulp_adc_cfg_t cfg = { - .adc_n = EXAMPLE_ADC_UNIT, - .channel = EXAMPLE_ADC_CHANNEL, - .width = EXAMPLE_ADC_WIDTH, - .atten = EXAMPLE_ADC_ATTEN, - .ulp_mode = ADC_ULP_MODE_FSM, - }; - - ESP_ERROR_CHECK(ulp_adc_init(&cfg)); - - ulp_low_thr = EXAMPLE_ADC_LOW_TRESHOLD; - ulp_high_thr = EXAMPLE_ADC_HIGH_TRESHOLD; - - /* Set ULP wake up period to 20ms */ - ulp_set_wakeup_period(0, 20000); - -#if CONFIG_IDF_TARGET_ESP32 - /* Disconnect GPIO12 and GPIO15 to remove current drain through - * pullup/pulldown resistors on modules which have these (e.g. ESP32-WROVER) - * GPIO12 may be pulled high to select flash voltage. - */ - rtc_gpio_isolate(GPIO_NUM_12); - rtc_gpio_isolate(GPIO_NUM_15); -#endif // CONFIG_IDF_TARGET_ESP32 - - esp_deep_sleep_disable_rom_logging(); // suppress boot messages -} - -static void start_ulp_program(void) -{ - /* Reset sample counter */ - ulp_sample_counter = 0; - - /* Start the program */ - esp_err_t err = ulp_run(&ulp_entry - RTC_SLOW_MEM); - ESP_ERROR_CHECK(err); -} diff --git a/examples/espidf-ulp-adc/ulp/adc.S b/examples/espidf-ulp-adc/ulp/adc.S deleted file mode 100644 index b96f51c3b..000000000 --- a/examples/espidf-ulp-adc/ulp/adc.S +++ /dev/null @@ -1,120 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ -/* ULP Example: using ADC in deep sleep - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. - - This file contains assembly code which runs on the ULP. - - ULP wakes up to run this code at a certain period, determined by the values - in SENS_ULP_CP_SLEEP_CYCx_REG registers. On each wake up, the program - measures input voltage on the given ADC channel 'adc_oversampling_factor' - times. Measurements are accumulated and average value is calculated. - Average value is compared to the two thresholds: 'low_thr' and 'high_thr'. - If the value is less than 'low_thr' or more than 'high_thr', ULP wakes up - the chip from deep sleep. -*/ - -/* ULP assembly files are passed through C preprocessor first, so include directives - and C macros may be used in these files - */ -#include "soc/rtc_cntl_reg.h" -#include "soc/soc_ulp.h" -#include "example_config.h" - - .set adc_channel, EXAMPLE_ADC_CHANNEL - - /* Configure the number of ADC samples to average on each measurement. - For convenience, make it a power of 2. */ - .set adc_oversampling_factor_log, 2 - .set adc_oversampling_factor, (1 << adc_oversampling_factor_log) - - /* Define variables, which go into .bss section (zero-initialized data) */ - .bss - - /* Low threshold of ADC reading. - Set by the main program. */ - .global low_thr -low_thr: - .long 0 - - /* High threshold of ADC reading. - Set by the main program. */ - .global high_thr -high_thr: - .long 0 - - /* Counter of measurements done */ - .global sample_counter -sample_counter: - .long 0 - - .global last_result -last_result: - .long 0 - - /* Code goes into .text section */ - .text - .global entry -entry: - /* increment sample counter */ - move r3, sample_counter - ld r2, r3, 0 - add r2, r2, 1 - st r2, r3, 0 - - /* do measurements using ADC */ - /* r0 will be used as accumulator */ - move r0, 0 - /* initialize the loop counter */ - stage_rst -measure: - /* measure and add value to accumulator */ - adc r1, 0, adc_channel + 1 - add r0, r0, r1 - /* increment loop counter and check exit condition */ - stage_inc 1 - jumps measure, adc_oversampling_factor, lt - - /* divide accumulator by adc_oversampling_factor. - Since it is chosen as a power of two, use right shift */ - rsh r0, r0, adc_oversampling_factor_log - /* averaged value is now in r0; store it into last_result */ - move r3, last_result - st r0, r3, 0 - - /* compare with low_thr; wake up if value < low_thr */ - move r3, low_thr - ld r3, r3, 0 - sub r3, r0, r3 - jump wake_up, ov - - /* compare with high_thr; wake up if value > high_thr */ - move r3, high_thr - ld r3, r3, 0 - sub r3, r3, r0 - jump wake_up, ov - - /* value within range, end the program */ - .global exit -exit: - halt - - .global wake_up -wake_up: - /* Check if the system can be woken up */ - READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_RDY_FOR_WAKEUP) - and r0, r0, 1 - jump exit, eq - - /* Wake up the SoC, end program */ - wake - WRITE_RTC_FIELD(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN, 0) - halt diff --git a/examples/espidf-ulp-adc/ulp/example_config.h b/examples/espidf-ulp-adc/ulp/example_config.h deleted file mode 100644 index baa86dd84..000000000 --- a/examples/espidf-ulp-adc/ulp/example_config.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ -#pragma once - -/* Ints are used here to be able to include the file in assembly as well */ -#define EXAMPLE_ADC_CHANNEL 6 // ADC_CHANNEL_6, GPIO34 on ESP32, GPIO7 on ESP32-S3 -#define EXAMPLE_ADC_UNIT 0 // ADC_UNIT_1 -#define EXAMPLE_ADC_ATTEN 3 // ADC_ATTEN_DB_11 -#define EXAMPLE_ADC_WIDTH 0 // ADC_BITWIDTH_DEFAULT - -/* Set low and high thresholds, approx. 1.35V - 1.75V*/ -#define EXAMPLE_ADC_LOW_TRESHOLD 1500 -#define EXAMPLE_ADC_HIGH_TRESHOLD 2000 diff --git a/examples/espidf-ulp-lp/CMakeLists.txt b/examples/espidf-ulp-lp/CMakeLists.txt new file mode 100644 index 000000000..3db148b2a --- /dev/null +++ b/examples/espidf-ulp-lp/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(lp_core_pulse_counter) diff --git a/examples/espidf-ulp-lp/README.md b/examples/espidf-ulp-lp/README.md new file mode 100644 index 000000000..32318f0dc --- /dev/null +++ b/examples/espidf-ulp-lp/README.md @@ -0,0 +1,51 @@ +| Supported Targets | ESP32-C6 | +| ----------------- | -------- | + +This example demonstrates how to program the ULP Core coprocessor to count pulses on an IO while the main CPUs are either running some other code or are in deep sleep. See the README.md file in the upper level 'examples' directory for more information about examples. + +At runtime, the main code running on the ESP (found in lp_core_pulse_counter_example_main.c) loads ULP program into the `RTC_SLOW_MEM` memory region using `ulp_lp_core_load_binary` function. Main code configures the ULP program by setting up values of some variables and then starts it using `ulp_lp_core_run`. Once the ULP program is started, it monitors the IO pin for pulses. + +When the ULP program finds an edge in the input signal, it performs debouncing and increments the variable maintaining the total edge count. Once the edge count reaches certain value, ULP triggers wake up from deep sleep. Note that the ULP program keeps running and monitoring the input signal even when the SoC is woken up. + +### Hardware Required + +To run this example, you should have a development board based on any of the chips listed in the supported targets table at the top and a host machine with a serial input connection. + +#### Pin Assignment: + +**Note:** The following pin assignments are used by default. + + +| | Uart Tx | Pulse Count Input | +| ----------------------- | ------- | ----------------- | +| ESP32-C6 | GPIO5 | GPIO6 | +| Host machine | Rx | N/A | + + +## Example Output + +The log output from the serial monitor connected to the main core should indicate that the LP core and the LP UART peripheral have been successfully initialized. The main CPU would then enter deep sleep mode. + +```bash +Using pin 6 as pulse counter input +ULP will wake up processor after every 10 pulses +Not a ULP wakeup, initializing it! +Entering in deep sleep +... +rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT) +... +ULP woke up the main CPU! +Pulse count: 11 +Entering in deep sleep +``` + +The log output from the serial monitor connected to the LP core should display output as below - + +```bash +LP Core pulse counter started +Pulse count: 10, wake-up main CPU +``` + +## Troubleshooting + +(For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you as soon as possible.) diff --git a/examples/espidf-ulp-pulse/platformio.ini b/examples/espidf-ulp-lp/platformio.ini similarity index 66% rename from examples/espidf-ulp-pulse/platformio.ini rename to examples/espidf-ulp-lp/platformio.ini index cb1573370..2dd34c531 100644 --- a/examples/espidf-ulp-pulse/platformio.ini +++ b/examples/espidf-ulp-lp/platformio.ini @@ -5,9 +5,14 @@ ; Library options: dependencies, extra library storages ; ; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html +; http://docs.platformio.org/page/projectconf.html -[env:esp32dev] +[env:esp32-c6] platform = espressif32 framework = espidf -board = esp32dev +board = esp32-c6-devkitc-1 + +[env:esp32-p4] +platform = espressif32 +framework = espidf +board = esp32-p4 diff --git a/examples/espidf-ulp-lp/pytest_lp_core_pcnt.py b/examples/espidf-ulp-lp/pytest_lp_core_pcnt.py new file mode 100644 index 000000000..a4d8c0c2e --- /dev/null +++ b/examples/espidf-ulp-lp/pytest_lp_core_pcnt.py @@ -0,0 +1,30 @@ +# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 +import logging + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32c6 +@pytest.mark.esp32p4 +@pytest.mark.generic +def test_lp_core_pcnt(dut: Dut) -> None: + + res = dut.expect(r'ULP will wake up processor after every (\d+) pulses') + wakeup_limit = res.group(1).decode('utf-8') + assert (int(wakeup_limit) > 0) + logging.info(f'Wake-up limit: {wakeup_limit} pulses') + + dut.expect_exact('Not a ULP wakeup, initializing it!') + dut.expect_exact('Entering in deep sleep') + + dut.expect_exact('ULP woke up the main CPU!') + + res = dut.expect(r'Pulse count: (\d+)') + pulse_count = res.group(1).decode('utf-8') + logging.info(f'Pulse count: {pulse_count}') + + # Check that pulse count is correct, we could have gotten pulses between triggering + # the wakeup signal and printing the count, but it should at be equal to or greater + assert (int(pulse_count) >= int(wakeup_limit)) diff --git a/examples/espidf-ulp-pulse/sdkconfig.defaults b/examples/espidf-ulp-lp/sdkconfig.defaults similarity index 61% rename from examples/espidf-ulp-pulse/sdkconfig.defaults rename to examples/espidf-ulp-lp/sdkconfig.defaults index 1dffd2c78..054ff6c32 100644 --- a/examples/espidf-ulp-pulse/sdkconfig.defaults +++ b/examples/espidf-ulp-lp/sdkconfig.defaults @@ -1,10 +1,11 @@ -# Enable ULP +# +# Ultra Low Power (ULP) Co-processor +# CONFIG_ULP_COPROC_ENABLED=y -CONFIG_ULP_COPROC_TYPE_FSM=y -CONFIG_ULP_COPROC_RESERVE_MEM=1024 +CONFIG_ULP_COPROC_TYPE_LP_CORE=y +CONFIG_ULP_COPROC_RESERVE_MEM=8128 # Set log level to Warning to produce clean output CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y CONFIG_BOOTLOADER_LOG_LEVEL=2 CONFIG_LOG_DEFAULT_LEVEL_WARN=y CONFIG_LOG_DEFAULT_LEVEL=2 -CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y diff --git a/examples/espidf-ulp-adc/main/CMakeLists.txt b/examples/espidf-ulp-lp/src/CMakeLists.txt similarity index 55% rename from examples/espidf-ulp-adc/main/CMakeLists.txt rename to examples/espidf-ulp-lp/src/CMakeLists.txt index d8758a909..b3825ab7b 100644 --- a/examples/espidf-ulp-adc/main/CMakeLists.txt +++ b/examples/espidf-ulp-lp/src/CMakeLists.txt @@ -1,23 +1,23 @@ -idf_component_register(SRCS "ulp_adc_example_main.c" - INCLUDE_DIRS "" - REQUIRES soc nvs_flash ulp driver esp_adc) +idf_component_register(SRCS "lp_core_pulse_counter_example_main.c" + INCLUDE_DIRS ".") + # # ULP support additions to component CMakeLists.txt. # # 1. The ULP app name must be unique (if multiple components use ULP). set(ulp_app_name ulp_main) # -# 2. Specify all assembly source files. +# 2. Specify all C and Assembly source files. # Files should be placed into a separate directory (in this case, ulp/), # which should not be added to COMPONENT_SRCS. -set(ulp_s_sources "../ulp/adc.S") +set(ulp_sources "../ulp/main.c") + # # 3. List all the component source files which include automatically # generated ULP export file, ${ulp_app_name}.h: -set(ulp_exp_dep_srcs "ulp_adc_example_main.c") +set(ulp_exp_dep_srcs "lp_core_pulse_counter_example_main.c") + # # 4. Call function to build ULP binary and embed in project using the argument # values above. -ulp_embed_binary(${ulp_app_name} "${ulp_s_sources}" "${ulp_exp_dep_srcs}") - -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") +ulp_embed_binary(${ulp_app_name} "${ulp_sources}" "${ulp_exp_dep_srcs}") diff --git a/examples/espidf-ulp-lp/src/Kconfig.projbuild b/examples/espidf-ulp-lp/src/Kconfig.projbuild new file mode 100644 index 000000000..88618cecb --- /dev/null +++ b/examples/espidf-ulp-lp/src/Kconfig.projbuild @@ -0,0 +1,20 @@ +menu "Example Configuration" + config EXAMPLE_PULSE_COUNT_PIN + int "Input pin for the pulse counter" + default 6 + help + GPIO pin used as the input for the pulse counter + + config EXAMPLE_PULSE_COUNT_WAKEUP_LIMIT + int "Wake-up pulse count limit" + default 10 + help + Number of pulses counted after which the ULP will wake up the main CPU + + config EXAMPLE_PULSE_COUNT_SIMULATE + bool "Simulate pulses on input pin" + default n + help + The ULP will periodically toggle the input pin to simulate pulses + +endmenu diff --git a/examples/espidf-ulp-lp/src/lp_core_pulse_counter_example_main.c b/examples/espidf-ulp-lp/src/lp_core_pulse_counter_example_main.c new file mode 100644 index 000000000..65bef47be --- /dev/null +++ b/examples/espidf-ulp-lp/src/lp_core_pulse_counter_example_main.c @@ -0,0 +1,85 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +/* LP core gpio example + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include +#include +#include "esp_sleep.h" +#include "driver/gpio.h" +#include "driver/rtc_io.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "ulp_lp_core.h" +#include "ulp_main.h" +#include "lp_core_uart.h" + +extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start"); +extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end"); + + +static void init_ulp_program(void); + +void app_main(void) +{ + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + + /* Initialize selected GPIO as RTC IO, enable input/output, disable pullup and pulldown */ + printf("Using pin %d as pulse counter input\n", CONFIG_EXAMPLE_PULSE_COUNT_PIN); + rtc_gpio_init(CONFIG_EXAMPLE_PULSE_COUNT_PIN); + rtc_gpio_set_direction(CONFIG_EXAMPLE_PULSE_COUNT_PIN, RTC_GPIO_MODE_INPUT_OUTPUT); + rtc_gpio_pulldown_dis(CONFIG_EXAMPLE_PULSE_COUNT_PIN); + rtc_gpio_pullup_dis(CONFIG_EXAMPLE_PULSE_COUNT_PIN); + + printf("ULP will wake up processor after every %d pulses\n", CONFIG_EXAMPLE_PULSE_COUNT_WAKEUP_LIMIT); + + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); + /* not a wakeup from ULP, load the firmware */ + if (cause != ESP_SLEEP_WAKEUP_ULP) { + printf("Not a ULP wakeup, initializing it! \n"); + init_ulp_program(); + } else { + printf("ULP woke up the main CPU!\n"); + printf("Pulse count: %"PRIu32"\n", ulp_pulse_count); + } + + /* Go back to sleep, only the ULP will run */ + printf("Entering in deep sleep\n\n"); + + /* Small delay to ensure the messages are printed */ + ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup()); + + esp_deep_sleep_start(); +} + +static void init_ulp_program(void) +{ + lp_core_uart_cfg_t uart_cfg = LP_CORE_UART_DEFAULT_CONFIG(); + + ESP_ERROR_CHECK(lp_core_uart_init(&uart_cfg)); + + esp_err_t err = ulp_lp_core_load_binary(ulp_main_bin_start, (ulp_main_bin_end - ulp_main_bin_start)); + ESP_ERROR_CHECK(err); + + /* Start the program */ + ulp_lp_core_cfg_t cfg = { + .wakeup_source = ULP_LP_CORE_WAKEUP_SOURCE_HP_CPU, + }; + + err = ulp_lp_core_run(&cfg); + ESP_ERROR_CHECK(err); +} diff --git a/examples/espidf-ulp-lp/ulp/main.c b/examples/espidf-ulp-lp/ulp/main.c new file mode 100644 index 000000000..6a45c04cb --- /dev/null +++ b/examples/espidf-ulp-lp/ulp/main.c @@ -0,0 +1,64 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include +#include +#include "sdkconfig.h" +#include "ulp_lp_core.h" +#include "ulp_lp_core_utils.h" +#include "ulp_lp_core_gpio.h" +#include "ulp_lp_core_interrupts.h" +#include "ulp_lp_core_print.h" +#include "riscv/csr.h" + +#define DEBOUNCE_INTERVAL_CYCLES 10 // 10 cycles is about 0.625 us at 16 MHz + +#define SIMULATED_PULSE_FREQUENCY_HZ 2 +#define SIMULATED_PULSE_DELAY_US (1000000 / SIMULATED_PULSE_FREQUENCY_HZ) / 2 + +uint32_t pulse_count; +static uint32_t last_trigger_time_cycles; + +void LP_CORE_ISR_ATTR ulp_lp_core_lp_io_intr_handler(void) +{ + ulp_lp_core_gpio_clear_intr_status(); + uint32_t trigger_time_cycles = RV_READ_CSR(mcycle); + /* Do some simple debouncing, do not count spurious pulses */ + if (trigger_time_cycles - last_trigger_time_cycles > DEBOUNCE_INTERVAL_CYCLES) { + pulse_count++; + last_trigger_time_cycles = trigger_time_cycles; + } + + if (pulse_count % CONFIG_EXAMPLE_PULSE_COUNT_WAKEUP_LIMIT == 0) { + lp_core_printf("Pulse count: %d, wake-up main CPU\n", pulse_count); + ulp_lp_core_wakeup_main_processor(); + } + +} + + + +int main (void) +{ + lp_core_printf("LP Core pulse counter started\n"); + ulp_lp_core_intr_enable(); + ulp_lp_core_gpio_intr_enable(CONFIG_EXAMPLE_PULSE_COUNT_PIN, LP_IO_INTR_POSEDGE); + + while(1) { + +#if CONFIG_EXAMPLE_PULSE_COUNT_SIMULATE + /* No external device connected to generate pulses, we simulate them ourselves instead */ + ulp_lp_core_delay_us(SIMULATED_PULSE_DELAY_US); + ulp_lp_core_gpio_set_level(CONFIG_EXAMPLE_PULSE_COUNT_PIN, 1); + ulp_lp_core_delay_us(SIMULATED_PULSE_DELAY_US); + ulp_lp_core_gpio_set_level(CONFIG_EXAMPLE_PULSE_COUNT_PIN, 0); +#else + /* Put CPU into a wait state to reduce power consumption while waiting for pulses */ + ulp_lp_core_wait_for_intr(); +#endif //CONFIG_EXAMPLE_PULSE_COUNT_SIMULATE + } + + return 0; +} diff --git a/examples/espidf-ulp-pulse/.gitignore b/examples/espidf-ulp-pulse/.gitignore deleted file mode 100644 index 03f4a3c19..000000000 --- a/examples/espidf-ulp-pulse/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.pio diff --git a/examples/espidf-ulp-pulse/.travis.yml b/examples/espidf-ulp-pulse/.travis.yml deleted file mode 100644 index 7c486f183..000000000 --- a/examples/espidf-ulp-pulse/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-ulp-pulse/README.md b/examples/espidf-ulp-pulse/README.md deleted file mode 100644 index 96ffb18c1..000000000 --- a/examples/espidf-ulp-pulse/README.md +++ /dev/null @@ -1,27 +0,0 @@ -How to build PlatformIO based project -===================================== - -1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) -2. Download [development platform with examples](https://github.com/platformio/platform-espressif32/archive/develop.zip) -3. Extract ZIP archive -4. Run these commands: - -```shell -# Change directory to example -$ cd platform-espressif32/examples/espidf-ulp-pulse - -# Build project -$ pio run - -# Upload firmware -$ pio run --target upload - -# Build specific environment -$ pio run -e esp32dev - -# Upload firmware for the specific environment -$ pio run -e esp32dev --target upload - -# Clean build files -$ pio run --target clean -``` diff --git a/examples/espidf-ulp-pulse/ulp/wake_up.S b/examples/espidf-ulp-pulse/ulp/wake_up.S deleted file mode 100644 index 34b80b411..000000000 --- a/examples/espidf-ulp-pulse/ulp/wake_up.S +++ /dev/null @@ -1,16 +0,0 @@ -/* ULP assembly files are passed through C preprocessor first, so include directives - and C macros may be used in these files - */ -#include "soc/rtc_cntl_reg.h" -#include "soc/soc_ulp.h" - - .global wake_up -wake_up: - /* Check if the system can be woken up */ - READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_RDY_FOR_WAKEUP) - and r0, r0, 1 - jump wake_up, eq - - /* Wake up the SoC, end program */ - wake - halt diff --git a/examples/espidf-ulp-adc/CMakeLists.txt b/examples/espidf-ulp-riscv/CMakeLists.txt similarity index 88% rename from examples/espidf-ulp-adc/CMakeLists.txt rename to examples/espidf-ulp-riscv/CMakeLists.txt index 7037f86d8..d49885b79 100644 --- a/examples/espidf-ulp-adc/CMakeLists.txt +++ b/examples/espidf-ulp-riscv/CMakeLists.txt @@ -3,4 +3,4 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(ulp-adc-example) \ No newline at end of file +project(ulp_riscv_example) diff --git a/examples/espidf-ulp-riscv/README.md b/examples/espidf-ulp-riscv/README.md new file mode 100644 index 000000000..bfe9e639b --- /dev/null +++ b/examples/espidf-ulp-riscv/README.md @@ -0,0 +1,31 @@ +| Supported Targets | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | + +# ULP-RISC-V simple example with GPIO Polling: + +This example demonstrates how to program the ULP-RISC-V coprocessor to poll a gpio and wakeup the main CPU when it changes its state; + +ULP program written in C can be found across `ulp/main.c`. The build system compiles and links this program, converts it into binary format, and embeds it into the .rodata section of the ESP-IDF application. + +At runtime, the application running inside the main CPU loads ULP program into the `RTC_SLOW_MEM` memory region using `ulp_riscv_load_binary` function. The main code then configures the ULP wakeup period and starts the coprocessor by using `ulp_riscv_run`. Once the ULP program is started, it runs periodically, with the period set by the main program. The main program enables ULP wakeup source and puts the chip into deep sleep mode. + +When the ULP program finds an state changing in the pin, it saves the current state and sends a wakeup signal to the main CPU. + +Upon wakeup, the main program prints the current level of the measured gpio and go back to the deep sleep. + +In this example the input signal is connected to GPIO0. Note that this pin was chosen because most development boards have a button connected to it, so the pulses to be counted can be generated by pressing the button. For real world applications this is not a good choice of a pin, because GPIO0 also acts as a bootstrapping pin. To change the pin number, check the ESP32-S2 Chip Pin List document and adjust `gpio_num` and `ulp_io_number` variables in main.c. + + +## Example output + +``` +Not a ULP wakeup, initializing it! +Entering in deep sleep + +... + +ULP-RISC-V woke up the main CPU! +ULP-RISC-V read changes in GPIO_0 current is: High +Entering in deep sleep + +``` \ No newline at end of file diff --git a/examples/espidf-ulp-riscv/example_test.py b/examples/espidf-ulp-riscv/example_test.py new file mode 100644 index 000000000..cce2c6e01 --- /dev/null +++ b/examples/espidf-ulp-riscv/example_test.py @@ -0,0 +1,48 @@ +from __future__ import unicode_literals + +import re +import time + +import tiny_test_fw +import ttfw_idf +from tiny_test_fw import DUT + + +@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32s2', 'esp32s3']) +def test_examples_ulp_riscv(env, extra_data): # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument + dut = env.get_dut('ulp_riscv', 'examples/system/ulp_riscv/gpio') + dut.start_app() + + dut.expect_all('Not a ULP-RISC-V wakeup, initializing it!', + 'Entering in deep sleep', + timeout=30) + + # Give the chip time to enter deepsleep + time.sleep(1) + + # Run two times to make sure device sleep + # and wake up properly + for i in range(0, 2): + # Set GPIO0 using DTR + dut.port_inst.setDTR(i % 2 == 0) + + dut.expect('ULP-RISC-V woke up the main CPU!', timeout=5) + + # Check GPIO state + state = 'Low' if i % 2 == 0 else 'High' + dut.expect(re.compile(r'ULP-RISC-V read changes in GPIO_0 current is: %s' % state), timeout=5) + + # Go back to sleep + dut.expect('Entering in deep sleep', timeout=5) + + try: + # We expect a timeout here, otherwise it means that + # the main CPU woke up unexpectedly! + dut.expect('ULP-RISC-V woke up the main CPU!', timeout=20) + raise Exception('Main CPU woke up unexpectedly!') + except DUT.ExpectTimeout: + pass + + +if __name__ == '__main__': + test_examples_ulp_riscv() diff --git a/examples/espidf-ulp-riscv/main/CMakeLists.txt b/examples/espidf-ulp-riscv/main/CMakeLists.txt new file mode 100644 index 000000000..b2f277f2e --- /dev/null +++ b/examples/espidf-ulp-riscv/main/CMakeLists.txt @@ -0,0 +1,27 @@ +# Set usual component variables +set(COMPONENT_SRCS "ulp_riscv_example_main.c") +set(COMPONENT_ADD_INCLUDEDIRS "") +set(COMPONENT_REQUIRES soc nvs_flash ulp driver) + +register_component() + +# +# ULP support additions to component CMakeLists.txt. +# +# 1. The ULP app name must be unique (if multiple components use ULP). +set(ulp_app_name ulp_${COMPONENT_NAME}) +# +# 2. Specify all C and Assembly source files. +# Files should be placed into a separate directory (in this case, ulp/), +# which should not be added to COMPONENT_SRCS. +set(ulp_riscv_sources "../ulp/main.c") + +# +# 3. List all the component source files which include automatically +# generated ULP export file, ${ulp_app_name}.h: +set(ulp_exp_dep_srcs "ulp_riscv_example_main.c") + +# +# 4. Call function to build ULP binary and embed in project using the argument +# values above. +ulp_embed_binary(${ulp_app_name} "${ulp_riscv_sources}" "${ulp_exp_dep_srcs}") diff --git a/examples/espidf-ulp-riscv/main/ulp_riscv_example_main.c b/examples/espidf-ulp-riscv/main/ulp_riscv_example_main.c new file mode 100644 index 000000000..42fb16b11 --- /dev/null +++ b/examples/espidf-ulp-riscv/main/ulp_riscv_example_main.c @@ -0,0 +1,74 @@ +/* ULP riscv DS18B20 1wire temperature sensor example + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include +#include "esp_sleep.h" +#include "soc/rtc_cntl_reg.h" +#include "soc/sens_reg.h" +#include "soc/rtc_periph.h" +#include "driver/gpio.h" +#include "driver/rtc_io.h" +#include "ulp_riscv.h" +#include "ulp_main.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start"); +extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end"); + +static void init_ulp_program(void); + +void app_main(void) +{ + /* Initialize selected GPIO as RTC IO, enable input, disable pullup and pulldown */ + rtc_gpio_init(GPIO_NUM_0); + rtc_gpio_set_direction(GPIO_NUM_0, RTC_GPIO_MODE_INPUT_ONLY); + rtc_gpio_pulldown_dis(GPIO_NUM_0); + rtc_gpio_pullup_dis(GPIO_NUM_0); + rtc_gpio_hold_en(GPIO_NUM_0); + + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); + /* not a wakeup from ULP, load the firmware */ + if (cause != ESP_SLEEP_WAKEUP_ULP) { + printf("Not a ULP-RISC-V wakeup, initializing it! \n"); + init_ulp_program(); + } + + /* ULP Risc-V read and detected a change in GPIO_0, prints */ + if (cause == ESP_SLEEP_WAKEUP_ULP) { + printf("ULP-RISC-V woke up the main CPU! \n"); + printf("ULP-RISC-V read changes in GPIO_0 current is: %s \n", + (bool)(ulp_gpio_level_previous == 0) ? "Low" : "High" ); + + } + + /* Go back to sleep, only the ULP Risc-V will run */ + printf("Entering in deep sleep\n\n"); + + /* Small delay to ensure the messages are printed */ + vTaskDelay(100); + + ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup()); + esp_deep_sleep_start(); +} + +static void init_ulp_program(void) +{ + esp_err_t err = ulp_riscv_load_binary(ulp_main_bin_start, (ulp_main_bin_end - ulp_main_bin_start)); + ESP_ERROR_CHECK(err); + + /* The first argument is the period index, which is not used by the ULP-RISC-V timer + * The second argument is the period in microseconds, which gives a wakeup time period of: 20ms + */ + ulp_set_wakeup_period(0, 20000); + + /* Start the program */ + err = ulp_riscv_run(); + ESP_ERROR_CHECK(err); +} \ No newline at end of file diff --git a/examples/espidf-ulp-adc/platformio.ini b/examples/espidf-ulp-riscv/platformio.ini similarity index 66% rename from examples/espidf-ulp-adc/platformio.ini rename to examples/espidf-ulp-riscv/platformio.ini index 9d7ba651a..2cc98730b 100644 --- a/examples/espidf-ulp-adc/platformio.ini +++ b/examples/espidf-ulp-riscv/platformio.ini @@ -5,12 +5,17 @@ ; Library options: dependencies, extra library storages ; ; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html +; http://docs.platformio.org/page/projectconf.html [platformio] src_dir = main -[env:esp32dev] +[env:esp32-s2] platform = espressif32 framework = espidf -board = esp32dev +board = esp32-s2-saola-1 + +[env:esp32-s3] +platform = espressif32 +framework = espidf +board = esp32-s3-devkitc-1 diff --git a/examples/espidf-ulp-riscv/sdkconfig.defaults b/examples/espidf-ulp-riscv/sdkconfig.defaults new file mode 100644 index 000000000..302c87aa9 --- /dev/null +++ b/examples/espidf-ulp-riscv/sdkconfig.defaults @@ -0,0 +1,5 @@ +# Set log level to Warning to produce clean output +CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y +CONFIG_BOOTLOADER_LOG_LEVEL=2 +CONFIG_LOG_DEFAULT_LEVEL_WARN=y +CONFIG_LOG_DEFAULT_LEVEL=2 diff --git a/examples/espidf-ulp-riscv/sdkconfig.defaults.esp32s2 b/examples/espidf-ulp-riscv/sdkconfig.defaults.esp32s2 new file mode 100644 index 000000000..039f3584c --- /dev/null +++ b/examples/espidf-ulp-riscv/sdkconfig.defaults.esp32s2 @@ -0,0 +1,7 @@ +# Enable ULP +CONFIG_ESP32S2_ULP_COPROC_ENABLED=y +CONFIG_ESP32S2_ULP_COPROC_RISCV=y +CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM=4096 +CONFIG_ULP_COPROC_ENABLED=y +CONFIG_ULP_COPROC_RESERVE_MEM=4096 +CONFIG_ULP_COPROC_TYPE_RISCV=y \ No newline at end of file diff --git a/examples/espidf-ulp-riscv/sdkconfig.defaults.esp32s3 b/examples/espidf-ulp-riscv/sdkconfig.defaults.esp32s3 new file mode 100644 index 000000000..df96a349d --- /dev/null +++ b/examples/espidf-ulp-riscv/sdkconfig.defaults.esp32s3 @@ -0,0 +1,7 @@ +# Enable ULP +CONFIG_ESP32S3_ULP_COPROC_ENABLED=y +CONFIG_ESP32S3_ULP_COPROC_RISCV=y +CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=4096 +CONFIG_ULP_COPROC_ENABLED=y +CONFIG_ULP_COPROC_RESERVE_MEM=4096 +CONFIG_ULP_COPROC_TYPE_RISCV=y diff --git a/examples/espidf-ulp-riscv/ulp/main.c b/examples/espidf-ulp-riscv/ulp/main.c new file mode 100644 index 000000000..91e8a3d22 --- /dev/null +++ b/examples/espidf-ulp-riscv/ulp/main.c @@ -0,0 +1,41 @@ +/* ULP-RISC-V example + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. + + This code runs on ULP-RISC-V coprocessor +*/ + +#include +#include +#include +#include "ulp_riscv.h" +#include "ulp_riscv_utils.h" +#include "ulp_riscv_gpio.h" + +static bool gpio_level = false; + +/* this variable will be exported as a public symbol, visible from main CPU: */ +bool gpio_level_previous = false; + +int main (void) +{ + gpio_level = (bool)ulp_riscv_gpio_get_level(GPIO_NUM_0); + gpio_level_previous = gpio_level; + + while(1) { + gpio_level = (bool)ulp_riscv_gpio_get_level(GPIO_NUM_0); + + /* Wakes up the main CPU if pin changed its state */ + if(gpio_level != gpio_level_previous) { + gpio_level_previous = gpio_level; + ulp_riscv_wakeup_main_processor(); + break; + } + } + /* ulp_riscv_halt() is called automatically when main exits */ + return 0; +} diff --git a/examples/espidf-storage-spiffs/CMakeLists.txt b/examples/espidf-ulp/CMakeLists.txt similarity index 91% rename from examples/espidf-storage-spiffs/CMakeLists.txt rename to examples/espidf-ulp/CMakeLists.txt index 1894b31ca..13c487bc5 100644 --- a/examples/espidf-storage-spiffs/CMakeLists.txt +++ b/examples/espidf-ulp/CMakeLists.txt @@ -3,4 +3,4 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(spiffs) +project(ulp_example) diff --git a/examples/espidf-ulp/Makefile b/examples/espidf-ulp/Makefile new file mode 100644 index 000000000..b9b17e5ef --- /dev/null +++ b/examples/espidf-ulp/Makefile @@ -0,0 +1,8 @@ +# +# This is a project Makefile. It is assumed the directory this Makefile resides in is a +# project subdirectory. +# + +PROJECT_NAME := ulp_example + +include $(IDF_PATH)/make/project.mk diff --git a/examples/espidf-ulp/README.md b/examples/espidf-ulp/README.md new file mode 100644 index 000000000..afb7c6c45 --- /dev/null +++ b/examples/espidf-ulp/README.md @@ -0,0 +1,57 @@ +| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | + +# ULP Pulse Counting Example + +This example demonstrates how to program the ULP FSM coprocessor to count pulses on an IO while the main CPUs are either running some other code or are in deep sleep. See the README.md file in the upper level 'examples' directory for more information about examples. + +ULP program written in assembly can be found across `ulp/pulse_cnt.S` and `ulp/wake_up.S` (demonstrating multiple ULP source files). The build system assembles and links this program, converts it into binary format, and embeds it into the .rodata section of the ESP-IDF application. + +At runtime, the main code running on the ESP32 (found in main.c) loads ULP program into the `RTC_SLOW_MEM` memory region using `ulp_load_binary` function. Main code configures the ULP program by setting up values of some variables and then starts it using `ulp_run`. Once the ULP program is started, it runs periodically, with the period set by the main program. The main program enables ULP wakeup source and puts the chip into deep sleep mode. + +When the ULP program finds an edge in the input signal, it performs debouncing and increments the variable maintaining the total edge count. Once the edge count reaches certain value (set by the main program), ULP triggers wake up from deep sleep. Note that the ULP program keeps running and monitoring the input signal even when the SoC is woken up. + +Upon wakeup, the main program saves total edge count into NVS and returns to deep sleep. + +In this example the input signal is connected to GPIO0. Note that this pin was chosen because most development boards have a button connected to it, so the pulses to be counted can be generated by pressing the button. For real world applications this is not a good choice of a pin, because GPIO0 also acts as a bootstrapping pin. To change the pin number, check the ESP32 Chip Pin List document and adjust `gpio_num` and `ulp_io_number` variables in main.c. + +In this example, the `CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP` Kconfig option is used, which allows you to reduce the boot time of the bootloader during waking up from deep sleep. The bootloader stores in rtc memory the address of a running partition and uses it when it wakes up. This example allows you to skip all image checks and speed up the boot. + +## Example output + +``` +Not ULP wakeup, initializing ULP +Entering deep sleep + +ULP wakeup, saving pulse count +Read pulse count from NVS: 384 +Pulse count from ULP: 5 +Wrote updated pulse count to NVS: 389 +Entering deep sleep + +ULP wakeup, saving pulse count +Read pulse count from NVS: 389 +Pulse count from ULP: 5 +Wrote updated pulse count to NVS: 394 +Entering deep sleep + +ULP wakeup, saving pulse count +Read pulse count from NVS: 394 +Pulse count from ULP: 6 +Wrote updated pulse count to NVS: 400 +Entering deep sleep + +ULP wakeup, saving pulse count +Read pulse count from NVS: 400 +Pulse count from ULP: 5 +Wrote updated pulse count to NVS: 405 +Entering deep sleep +``` + +Note that in one case the pulse count captured by the ULP program is 6, even though the `edge_count_to_wake_up` variable is set to 10 by the main program. This shows that the ULP program keeps track of pulses while the main CPUs are starting up, so when pulses are sent rapidly it is possible to register more pulses between wake up and entry into app_main. + +With the default configuration (20ms ULP wakeup period), average current consumption in deep sleep mode is 16uA. + +## Typical current consumption + +![CurrentConsumption](image/ulp_power_graph.png) diff --git a/examples/espidf-ulp/example_test.py b/examples/espidf-ulp/example_test.py new file mode 100644 index 000000000..4c7840e71 --- /dev/null +++ b/examples/espidf-ulp/example_test.py @@ -0,0 +1,45 @@ +from __future__ import unicode_literals + +import re +import time + +import ttfw_idf +from tiny_test_fw import Utility + + +@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32']) +def test_examples_ulp(env, extra_data): + + dut = env.get_dut('ulp', 'examples/system/ulp_fsm/ulp') + dut.start_app() + + dut.expect_all('Not ULP wakeup, initializing ULP', + 'Entering deep sleep', + timeout=30) + + def generate_gpio0_events(): + for _ in range(5): + dut.port_inst.setDTR(True) # Pulling GPIO0 low using DTR + time.sleep(0.25) + dut.port_inst.setDTR(False) + time.sleep(0.25) + + nvs_value = None + for _ in range(5): + generate_gpio0_events() + dut.expect('ULP wakeup, saving pulse count', timeout=5) + Utility.console_log('Woke up...') + init_count = int(dut.expect(re.compile(r'Read pulse count from NVS:\s+(\d+)'), timeout=5)[0], 10) + assert nvs_value in (init_count, None), ('Read count is {} and previously written value is {}' + ''.format(init_count, nvs_value)) + inc = int(dut.expect(re.compile(r'Pulse count from ULP:\s+(\d+)'), timeout=5)[0], 10) + assert inc in (5, 6), 'pulse count is {}'.format(inc) + new_count = int(dut.expect(re.compile(r'Wrote updated pulse count to NVS:\s+(\d+)'), timeout=5)[0], 10) + assert init_count + inc == new_count, '{} + {} != {}'.format(init_count, inc, new_count) + nvs_value = new_count + Utility.console_log('Pulse count written to NVS: {}. Entering deep sleep...'.format(nvs_value)) + dut.expect('Entering deep sleep', timeout=5) + + +if __name__ == '__main__': + test_examples_ulp() diff --git a/examples/espidf-ulp/image/ulp_power_graph.png b/examples/espidf-ulp/image/ulp_power_graph.png new file mode 100644 index 000000000..79dfb10dd Binary files /dev/null and b/examples/espidf-ulp/image/ulp_power_graph.png differ diff --git a/examples/espidf-ulp-pulse/src/CMakeLists.txt b/examples/espidf-ulp/main/CMakeLists.txt old mode 100644 new mode 100755 similarity index 90% rename from examples/espidf-ulp-pulse/src/CMakeLists.txt rename to examples/espidf-ulp/main/CMakeLists.txt index cea7e85e2..6ded342e1 --- a/examples/espidf-ulp-pulse/src/CMakeLists.txt +++ b/examples/espidf-ulp/main/CMakeLists.txt @@ -5,7 +5,7 @@ idf_component_register(SRCS "ulp_example_main.c" # ULP support additions to component CMakeLists.txt. # # 1. The ULP app name must be unique (if multiple components use ULP). -set(ulp_app_name ulp_main) +set(ulp_app_name ulp_${COMPONENT_NAME}) # # 2. Specify all assembly source files. # Files should be placed into a separate directory (in this case, ulp/), @@ -19,5 +19,3 @@ set(ulp_exp_dep_srcs "ulp_example_main.c") # 4. Call function to build ULP binary and embed in project using the argument # values above. ulp_embed_binary(${ulp_app_name} "${ulp_s_sources}" "${ulp_exp_dep_srcs}") - -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/examples/espidf-ulp-pulse/src/ulp_example_main.c b/examples/espidf-ulp/main/ulp_example_main.c old mode 100644 new mode 100755 similarity index 88% rename from examples/espidf-ulp-pulse/src/ulp_example_main.c rename to examples/espidf-ulp/main/ulp_example_main.c index c7cac8783..226ebef2e --- a/examples/espidf-ulp-pulse/src/ulp_example_main.c +++ b/examples/espidf-ulp/main/ulp_example_main.c @@ -8,6 +8,7 @@ */ #include +#include #include "esp_sleep.h" #include "nvs.h" #include "nvs_flash.h" @@ -16,7 +17,13 @@ #include "soc/rtc_periph.h" #include "driver/gpio.h" #include "driver/rtc_io.h" -#include "ulp.h" +#if CONFIG_IDF_TARGET_ESP32 +#include "esp32/ulp.h" +#elif CONFIG_IDF_TARGET_ESP32S2 +#include "esp32s2/ulp.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/ulp.h" +#endif #include "ulp_main.h" extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start"); @@ -97,27 +104,27 @@ static void init_ulp_program(void) static void update_pulse_count(void) { - const char* namespace = "plusecnt"; + const char* nvs_namespace = "plusecnt"; const char* count_key = "count"; ESP_ERROR_CHECK( nvs_flash_init() ); nvs_handle_t handle; - ESP_ERROR_CHECK( nvs_open(namespace, NVS_READWRITE, &handle)); + ESP_ERROR_CHECK( nvs_open(nvs_namespace, NVS_READWRITE, &handle)); uint32_t pulse_count = 0; esp_err_t err = nvs_get_u32(handle, count_key, &pulse_count); assert(err == ESP_OK || err == ESP_ERR_NVS_NOT_FOUND); - printf("Read pulse count from NVS: %5d\n", pulse_count); + printf("Read pulse count from NVS: %5" PRIu32"\n", pulse_count); /* ULP program counts signal edges, convert that to the number of pulses */ uint32_t pulse_count_from_ulp = (ulp_edge_count & UINT16_MAX) / 2; /* In case of an odd number of edges, keep one until next time */ ulp_edge_count = ulp_edge_count % 2; - printf("Pulse count from ULP: %5d\n", pulse_count_from_ulp); + printf("Pulse count from ULP: %5" PRIu32"\n", pulse_count_from_ulp); /* Save the new pulse count to NVS */ pulse_count += pulse_count_from_ulp; ESP_ERROR_CHECK(nvs_set_u32(handle, count_key, pulse_count)); ESP_ERROR_CHECK(nvs_commit(handle)); nvs_close(handle); - printf("Wrote updated pulse count to NVS: %5d\n", pulse_count); + printf("Wrote updated pulse count to NVS: %5" PRIu32"\n", pulse_count); } diff --git a/examples/espidf-storage-spiffs/platformio.ini b/examples/espidf-ulp/platformio.ini similarity index 59% rename from examples/espidf-storage-spiffs/platformio.ini rename to examples/espidf-ulp/platformio.ini index 9185e89ba..55cf15bb7 100644 --- a/examples/espidf-storage-spiffs/platformio.ini +++ b/examples/espidf-ulp/platformio.ini @@ -5,11 +5,22 @@ ; Library options: dependencies, extra library storages ; ; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html +; http://docs.platformio.org/page/projectconf.html + +[platformio] +src_dir = main [env:esp32dev] platform = espressif32 framework = espidf board = esp32dev -monitor_speed = 115200 -board_build.partitions = partitions_example.csv + +[env:esp32-s2] +platform = espressif32 +framework = espidf +board = esp32-s2-saola-1 + +[env:esp32-s3] +platform = espressif32 +framework = espidf +board = esp32-s3-devkitc-1 diff --git a/examples/espidf-ulp-adc/sdkconfig.defaults b/examples/espidf-ulp/sdkconfig.defaults similarity index 100% rename from examples/espidf-ulp-adc/sdkconfig.defaults rename to examples/espidf-ulp/sdkconfig.defaults diff --git a/examples/espidf-ulp/sdkconfig.defaults.esp32 b/examples/espidf-ulp/sdkconfig.defaults.esp32 new file mode 100644 index 000000000..be391d8c4 --- /dev/null +++ b/examples/espidf-ulp/sdkconfig.defaults.esp32 @@ -0,0 +1,3 @@ +# Enable ULP +CONFIG_ESP32_ULP_COPROC_ENABLED=y +CONFIG_ESP32_ULP_COPROC_RESERVE_MEM=1024 diff --git a/examples/espidf-ulp/sdkconfig.defaults.esp32s2 b/examples/espidf-ulp/sdkconfig.defaults.esp32s2 new file mode 100644 index 000000000..5175d2b6c --- /dev/null +++ b/examples/espidf-ulp/sdkconfig.defaults.esp32s2 @@ -0,0 +1,3 @@ +# Enable ULP +CONFIG_ESP32S2_ULP_COPROC_ENABLED=y +CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM=1024 diff --git a/examples/espidf-ulp/sdkconfig.defaults.esp32s3 b/examples/espidf-ulp/sdkconfig.defaults.esp32s3 new file mode 100644 index 000000000..f63dcae20 --- /dev/null +++ b/examples/espidf-ulp/sdkconfig.defaults.esp32s3 @@ -0,0 +1,3 @@ +# Enable ULP +CONFIG_ESP32S3_ULP_COPROC_ENABLED=y +CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=1024 diff --git a/examples/espidf-ulp-pulse/ulp/pulse_cnt.S b/examples/espidf-ulp/ulp/pulse_cnt.S old mode 100644 new mode 100755 similarity index 100% rename from examples/espidf-ulp-pulse/ulp/pulse_cnt.S rename to examples/espidf-ulp/ulp/pulse_cnt.S diff --git a/examples/espidf-ulp/ulp/wake_up.S b/examples/espidf-ulp/ulp/wake_up.S new file mode 100755 index 000000000..f6bf8fa3b --- /dev/null +++ b/examples/espidf-ulp/ulp/wake_up.S @@ -0,0 +1,30 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +/* ULP assembly files are passed through C preprocessor first, so include directives + and C macros may be used in these files + */ +#include "soc/rtc_cntl_reg.h" +#include "soc/soc_ulp.h" +#include "sdkconfig.h" + + .global wake_up +wake_up: + /* Check if the system is in sleep mode */ +#if CONFIG_IDF_TARGET_ESP32 + READ_RTC_REG(RTC_CNTL_LOW_POWER_ST_REG, 27, 1) +#else + READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_MAIN_STATE_IN_IDLE) +#endif + move r1, r0 + /* Check if the system can be woken up */ + READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_RDY_FOR_WAKEUP) + /* If the system is in normal mode or if the system is in sleep mode with ready for wakeup set, we can signal the main CPU to wakeup */ + or r0, r0, r1 + jump wake_up, eq + + /* Wake up the SoC, end program */ + wake + halt diff --git a/examples/tasmota_platformio_override.ini b/examples/tasmota_platformio_override.ini new file mode 100644 index 000000000..cb7be7b3d --- /dev/null +++ b/examples/tasmota_platformio_override.ini @@ -0,0 +1,53 @@ +[platformio] +default_envs = tasmota32-hybrid + +[env:tasmota32_base] +platform = file://. + +[env:tasmota32-hybrid] +extends = env:tasmota32_base +board = esp32 +build_flags = ${env:tasmota32_base.build_flags} + -DHTTPCLIENT_NOSECURE + -DUPDATE_NOCRYPT +lib_ignore = ${env:tasmota32_base.lib_ignore} + Micro-RTSP + epdiy + BLE + BluetoothSerial + SimpleBLE + WiFiProv + ESP_I2S + ESP_NOW + ESP_SR + Insights + Matter + OpenThread + RainMaker + SPIFFS + USB + NetworkClientSecure + Zigbee +custom_sdkconfig = https://raw.githubusercontent.com/pioarduino/sdkconfig/refs/heads/main/sdkconfig_tasmota_esp32 + '# CONFIG_ETH_USE_ESP32_EMAC is not set' + '# CONFIG_ETH_PHY_INTERFACE_RMII is not set' + '# CONFIG_ETH_RMII_CLK_INPUT is not set' + '# CONFIG_ETH_RMII_CLK_IN_GPIO is not set' +custom_component_remove = espressif/esp_hosted + espressif/esp_wifi_remote + espressif/esp-dsp + espressif/network_provisioning + espressif/esp-zboss-lib + espressif/esp-zigbee-lib + espressif/esp_rainmaker + espressif/rmaker_common + espressif/esp_insights + espressif/esp_diag_data_store + espressif/esp_diagnostics + espressif/cbor + espressif/qrcode + espressif/esp-sr + espressif/libsodium + espressif/esp-modbus + chmorgan/esp-libhelix-mp3 + espressif/esp32-camera diff --git a/platform.json b/platform.json index 78cc059cf..476ca1330 100644 --- a/platform.json +++ b/platform.json @@ -1,7 +1,7 @@ { "name": "espressif32", "title": "Espressif 32", - "description": "ESP32 is a series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and Bluetooth. ESP32 integrates an antenna switch, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules.", + "description": "Espressif Systems is a privately held fabless semiconductor company. They provide wireless communications and Wi-Fi chips which are widely used in mobile devices and the Internet of Things applications.", "homepage": "https://espressif.com/", "license": "Apache-2.0", "keywords": [ @@ -12,16 +12,15 @@ "RISC-V" ], "engines": { - "platformio": "^6" + "platformio": ">=6.1.16" }, "repository": { "type": "git", - "url": "https://github.com/platformio/platform-espressif32.git" + "url": "https://github.com/pioarduino/platform-espressif32.git" }, - "version": "6.7.0", + "version": "54.03.20", "frameworks": { "arduino": { - "package": "framework-arduinoespressif32", "script": "builder/frameworks/arduino.py" }, "espidf": { @@ -30,71 +29,64 @@ } }, "packages": { - "toolchain-xtensa-esp32": { - "type": "toolchain", + "framework-arduinoespressif32": { + "type": "framework", + "optional": true, "owner": "espressif", - "version": "8.4.0+2021r2-patch5" + "version": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esp32-3.2.0.zip" }, - "toolchain-xtensa-esp32s2": { - "type": "toolchain", + "framework-arduinoespressif32-libs": { + "type": "framework", "optional": true, "owner": "espressif", - "version": "8.4.0+2021r2-patch5" + "version": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip" }, - "toolchain-xtensa-esp32s3": { - "type": "toolchain", + "framework-arduino-c2-skeleton-lib": { + "type": "framework", "optional": true, "owner": "espressif", - "version": "8.4.0+2021r2-patch5" + "version": "https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc3/c2_arduino_compile_skeleton.zip" }, - "toolchain-riscv32-esp": { - "type": "toolchain", + "framework-espidf": { + "type": "framework", "optional": true, - "owner": "espressif", - "version": "8.4.0+2021r2-patch5", - "optionalVersions": ["13.2.0+20230928"] + "owner": "pioarduino", + "version": "https://github.com/pioarduino/esp-idf/releases/download/v5.4.1/esp-idf-v5.4.1.zip" }, "toolchain-xtensa-esp-elf": { "type": "toolchain", "optional": true, "owner": "platformio", - "version": "13.2.0+20230928" + "version": "14.2.0+20241119" }, - "toolchain-esp32ulp": { + "toolchain-riscv32-esp": { "type": "toolchain", "optional": true, "owner": "platformio", - "version": "~1.23500.0" + "version": "14.2.0+20241119" }, - "tool-xtensa-esp-elf-gdb": { - "type": "debugger", + "toolchain-esp32ulp": { + "type": "toolchain", "optional": true, - "owner": "espressif", - "version": "~12.1.0" + "owner": "platformio", + "version": "~1.23800.0" }, - "tool-riscv32-esp-elf-gdb": { + "tool-xtensa-esp-elf-gdb": { "type": "debugger", "optional": true, - "owner": "espressif", - "version": "~12.1.0" - }, - "framework-arduinoespressif32": { - "type": "framework", - "optional": true, "owner": "platformio", - "version": "~3.20017.0" + "version": "14.2.0+20240403" }, - "framework-espidf": { - "type": "framework", + "tool-riscv32-esp-elf-gdb": { + "type": "debugger", "optional": true, "owner": "platformio", - "version": "~3.50202.0", - "optionalVersions": ["~3.40407.0"] + "version": "14.2.0+20240403" }, "tool-esptoolpy": { "type": "uploader", - "owner": "platformio", - "version": "~1.40501.0" + "owner": "pioarduino", + "version": "https://github.com/pioarduino/esptool/releases/download/v4.8.9/esptool.zip" }, "tool-dfuutil-arduino": { "type": "uploader", @@ -108,43 +100,47 @@ "owner": "platformio", "version": "~2.1100.0" }, - "tool-mkspiffs": { + "tool-mklittlefs": { + "type": "uploader", + "owner": "tasmota", + "version": "^3.2.0" + }, + "tool-mkfatfs": { "type": "uploader", "optional": true, "owner": "platformio", - "version": "~2.230.0" + "version": "~2.0.0" }, - "tool-mklittlefs": { + "tool-mkspiffs": { "type": "uploader", "optional": true, "owner": "platformio", - "version": "~1.203.0" + "version": "~2.230.0" }, - "tool-mkfatfs": { - "type": "uploader", + "tool-cppcheck": { "optional": true, "owner": "platformio", - "version": "~2.0.0" + "version": "~1.21100" }, - "tool-cmake": { + "tool-clangtidy": { "optional": true, "owner": "platformio", - "version": "~3.16.0" + "version": "^1.190100.0" }, - "tool-ninja": { + "tool-pvs-studio": { "optional": true, "owner": "platformio", - "version": "^1.7.0" + "version": "^7.18.59866" }, - "tool-mconf": { + "tool-cmake": { "optional": true, "owner": "platformio", - "version": "~1.4060000.0" + "version": "~3.30.2" }, - "tool-idf": { + "tool-ninja": { "optional": true, "owner": "platformio", - "version": "~1.0.1" + "version": "^1.7.0" } } } diff --git a/platform.py b/platform.py index e0537875e..e1b3273c8 100644 --- a/platform.py +++ b/platform.py @@ -17,11 +17,17 @@ import sys import json import re +import requests from platformio.public import PlatformBase, to_unix_path IS_WINDOWS = sys.platform.startswith("win") +# Set Platformio env var to use windows_amd64 for all windows architectures +# only windows_amd64 native espressif toolchains are available +# needs platformio core >= 6.1.16b2 or pioarduino core 6.1.16+test +if IS_WINDOWS: + os.environ["PLATFORMIO_SYSTEM_TYPE"] = "windows_amd64" class Espressif32Platform(PlatformBase): @@ -31,10 +37,29 @@ def configure_default_packages(self, variables, targets): board_config = self.board_config(variables.get("board")) mcu = variables.get("board_build.mcu", board_config.get("build.mcu", "esp32")) + board_sdkconfig = variables.get("board_espidf.custom_sdkconfig", board_config.get("espidf.custom_sdkconfig", "")) + core_variant_board = ''.join(variables.get("board_build.extra_flags", board_config.get("build.extra_flags", ""))) + core_variant_board = core_variant_board.replace("-D", " ") + core_variant_build = (''.join(variables.get("build_flags", []))).replace("-D", " ") frameworks = variables.get("pioframework", []) + if "arduino" in frameworks: + self.packages["framework-arduinoespressif32"]["optional"] = False + self.packages["framework-arduinoespressif32-libs"]["optional"] = False + + if variables.get("custom_sdkconfig") is not None or len(str(board_sdkconfig)) > 3: + frameworks.append("espidf") + self.packages["framework-espidf"]["optional"] = False + if mcu == "esp32c2": + self.packages["framework-arduino-c2-skeleton-lib"]["optional"] = False + + # Enable check tools only when "check_tool" is active + for p in self.packages: + if p in ("tool-cppcheck", "tool-clangtidy", "tool-pvs-studio"): + self.packages[p]["optional"] = False if str(variables.get("check_tool")).strip("['']") in p else True + if "buildfs" in targets: - filesystem = variables.get("board_build.filesystem", "spiffs") + filesystem = variables.get("board_build.filesystem", "littlefs") if filesystem == "littlefs": self.packages["tool-mklittlefs"]["optional"] = False elif filesystem == "fatfs": @@ -46,111 +71,45 @@ def configure_default_packages(self, variables, targets): if os.path.isdir("ulp"): self.packages["toolchain-esp32ulp"]["optional"] = False + if "downloadfs" in targets: + filesystem = variables.get("board_build.filesystem", "littlefs") + if filesystem == "littlefs": + # Use Tasmota mklittlefs v4.0.0 to unpack, older version is incompatible + self.packages["tool-mklittlefs"]["version"] = "~4.0.0" + # Currently only Arduino Nano ESP32 uses the dfuutil tool as uploader if variables.get("board") == "arduino_nano_esp32": self.packages["tool-dfuutil-arduino"]["optional"] = False else: del self.packages["tool-dfuutil-arduino"] - build_core = variables.get( - "board_build.core", board_config.get("build.core", "arduino") - ).lower() - - if frameworks == ["arduino"] and build_core == "esp32": - # In case the upstream Arduino framework is specified in the configuration - # file then we need to dynamically extract toolchain versions from the - # Arduino index file. This feature can be disabled via a special option: - if ( - variables.get( - "board_build.arduino.upstream_packages", - board_config.get("build.arduino.upstream_packages", "yes"), - ).lower() - == "yes" - ): - package_version = self.packages["framework-arduinoespressif32"][ - "version" - ] - - url_items = urllib.parse.urlparse(package_version) - # Only GitHub repositories support dynamic packages - if ( - url_items.scheme in ("http", "https") - and url_items.netloc.startswith("github") - and url_items.path.endswith(".git") - ): - try: - self.configure_upstream_arduino_packages(url_items) - except Exception as e: - sys.stderr.write( - "Error! Failed to extract upstream toolchain" - "configurations:\n%s\n" % str(e) - ) - sys.stderr.write( - "You can disable this feature via the " - "`board_build.arduino.upstream_packages = no` setting in " - "your `platformio.ini` file.\n" - ) - sys.exit(1) - + # Starting from v12, Espressif's toolchains are shipped without + # bundled GDB. Instead, it's distributed as separate packages for Xtensa + # and RISC-V targets. + for gdb_package in ("tool-xtensa-esp-elf-gdb", "tool-riscv32-esp-elf-gdb"): + self.packages[gdb_package]["optional"] = False + # if IS_WINDOWS: + # Note: On Windows GDB v12 is not able to + # launch a GDB server in pipe mode while v11 works fine + # self.packages[gdb_package]["version"] = "~11.2.0" + + # Common packages for IDF and mixed Arduino+IDF projects if "espidf" in frameworks: - if frameworks == ["espidf"]: - # Starting from v12, Espressif's toolchains are shipped without - # bundled GDB. Instead, it's distributed as separate packages for Xtensa - # and RISC-V targets. Currently only IDF depends on the latest toolchain - for gdb_package in ("tool-xtensa-esp-elf-gdb", "tool-riscv32-esp-elf-gdb"): - self.packages[gdb_package]["optional"] = False - if IS_WINDOWS: - # Note: On Windows GDB v12 is not able to - # launch a GDB server in pipe mode while v11 works fine - self.packages[gdb_package]["version"] = "~11.2.0" - - # Common packages for IDF and mixed Arduino+IDF projects + self.packages["toolchain-esp32ulp"]["optional"] = False for p in self.packages: - if p in ("tool-cmake", "tool-ninja", "toolchain-esp32ulp"): + if p in ("tool-scons", "tool-cmake", "tool-ninja"): self.packages[p]["optional"] = False - elif p in ("tool-mconf", "tool-idf") and IS_WINDOWS: - self.packages[p]["optional"] = False - - if "arduino" in frameworks: - # Downgrade the IDF version for mixed Arduino+IDF projects - self.packages["framework-espidf"]["version"] = "~3.40407.0" - # Delete the latest toolchain packages from config - self.packages.pop("toolchain-xtensa-esp-elf", None) - else: - # Disable old toolchain packages and use the latest - # available for IDF v5.0 - for target in ( - "xtensa-esp32", - "xtensa-esp32s2", - "xtensa-esp32s3", - ): - self.packages.pop("toolchain-%s" % target, None) - - if mcu in ("esp32c3", "esp32c6"): - self.packages.pop("toolchain-xtensa-esp-elf", None) - else: - self.packages["toolchain-xtensa-esp-elf"][ - "optional" - ] = False - - # Pull the latest RISC-V toolchain from PlatformIO organization - self.packages["toolchain-riscv32-esp"]["owner"] = "platformio" - self.packages["toolchain-riscv32-esp"][ - "version" - ] = "13.2.0+20230928" - - if "arduino" in frameworks: - # Disable standalone GDB packages for Arduino and Arduino/IDF projects - for gdb_package in ("tool-xtensa-esp-elf-gdb", "tool-riscv32-esp-elf-gdb"): - self.packages.pop(gdb_package, None) + # elif p in ("tool-mconf", "tool-idf") and IS_WINDOWS: + # self.packages[p]["optional"] = False - for available_mcu in ("esp32", "esp32s2", "esp32s3"): - if available_mcu == mcu: - self.packages["toolchain-xtensa-%s" % mcu]["optional"] = False - else: - self.packages.pop("toolchain-xtensa-%s" % available_mcu, None) + if mcu in ("esp32", "esp32s2", "esp32s3"): + self.packages["toolchain-xtensa-esp-elf"]["optional"] = False + else: + self.packages.pop("toolchain-xtensa-esp-elf", None) - if mcu in ("esp32s2", "esp32s3", "esp32c3", "esp32c6"): + if mcu in ("esp32s2", "esp32s3", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"): + if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"): + self.packages.pop("toolchain-esp32ulp", None) # RISC-V based toolchain for ESP32C3, ESP32C6 ESP32S2, ESP32S3 ULP self.packages["toolchain-riscv32-esp"]["optional"] = False @@ -194,8 +153,7 @@ def _add_dynamic_options(self, board): # A special case for the Kaluga board that has a separate interface config if board.id == "esp32-s2-kaluga-1": supported_debug_tools.append("ftdi") - - if board.get("build.mcu", "") in ("esp32c3", "esp32c6", "esp32s3"): + if board.get("build.mcu", "") in ("esp32c3", "esp32c6", "esp32s3", "esp32h2"): supported_debug_tools.append("esp-builtin") upload_protocol = board.manifest.get("upload", {}).get("protocol") @@ -268,7 +226,6 @@ def _add_dynamic_options(self, board): # Avoid erasing Arduino Nano bootloader by preloading app binary if board.id == "arduino_nano_esp32": debug["tools"][link]["load_cmds"] = "preload" - board.manifest["debug"] = debug return board @@ -304,113 +261,3 @@ def configure_debug_session(self, debug_config): ) ) debug_config.load_cmds = load_cmds - - @staticmethod - def extract_toolchain_versions(tool_deps): - def _parse_version(original_version): - assert original_version - version_patterns = ( - r"^gcc(?P\d+)_(?P\d+)_(?P\d+)-esp-(?P.+)$", - r"^esp-(?P.+)-(?P\d+)\.(?P\d+)\.?(?P\d+)$", - r"^esp-(?P\d+)\.(?P\d+)\.(?P\d+)(_(?P.+))?$", - ) - for pattern in version_patterns: - match = re.search(pattern, original_version) - if match: - result = "%s.%s.%s" % ( - match.group("MAJOR"), - match.group("MINOR"), - match.group("PATCH"), - ) - if match.group("EXTRA"): - result = result + "+%s" % match.group("EXTRA") - return result - - raise ValueError("Bad package version `%s`" % original_version) - - if not tool_deps: - raise ValueError( - ("Failed to extract tool dependencies from the remote package file") - ) - - toolchain_remap = { - "xtensa-esp32-elf-gcc": "toolchain-xtensa-esp32", - "xtensa-esp32s2-elf-gcc": "toolchain-xtensa-esp32s2", - "xtensa-esp32s3-elf-gcc": "toolchain-xtensa-esp32s3", - "riscv32-esp-elf-gcc": "toolchain-riscv32-esp", - } - - result = dict() - for tool in tool_deps: - if tool["name"] in toolchain_remap: - result[toolchain_remap[tool["name"]]] = _parse_version(tool["version"]) - - return result - - @staticmethod - def parse_tool_dependencies(index_data): - for package in index_data.get("packages", []): - if package["name"] == "esp32": - for platform in package["platforms"]: - if platform["name"] == "esp32": - return platform["toolsDependencies"] - - return [] - - @staticmethod - def download_remote_package_index(url_items): - def _prepare_url_for_index_file(url_items): - tag = "master" - if url_items.fragment: - tag = url_items.fragment - return ( - "https://raw.githubusercontent.com/%s/" - "%s/package/package_esp32_index.template.json" - % (url_items.path.replace(".git", ""), tag) - ) - - index_file_url = _prepare_url_for_index_file(url_items) - - try: - from platformio.public import fetch_http_content - content = fetch_http_content(index_file_url) - except ImportError: - import requests - content = requests.get(index_file_url, timeout=5).text - - return json.loads(content) - - def configure_arduino_toolchains(self, package_index): - if not package_index: - return - - toolchain_packages = self.extract_toolchain_versions( - self.parse_tool_dependencies(package_index) - ) - for toolchain_package, version in toolchain_packages.items(): - if toolchain_package not in self.packages: - self.packages[toolchain_package] = dict() - self.packages[toolchain_package]["version"] = version - self.packages[toolchain_package]["owner"] = "espressif" - self.packages[toolchain_package]["type"] = "toolchain" - - def configure_upstream_arduino_packages(self, url_items): - framework_index_file = os.path.join( - self.get_package_dir("framework-arduinoespressif32") or "", - "package", - "package_esp32_index.template.json", - ) - - # Detect whether the remote is already cloned - if os.path.isfile(framework_index_file) and os.path.isdir( - os.path.join( - self.get_package_dir("framework-arduinoespressif32") or "", ".git" - ) - ): - with open(framework_index_file) as fp: - self.configure_arduino_toolchains(json.load(fp)) - else: - print("Configuring toolchain packages from a remote source...") - self.configure_arduino_toolchains( - self.download_remote_package_index(url_items) - )