diff --git a/.codespellrc b/.codespellrc index 756f7e9503b..d3b9b45cb1e 100644 --- a/.codespellrc +++ b/.codespellrc @@ -1,7 +1,7 @@ [codespell] # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check/.codespellrc # In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: -ignore-words-list = ba,licence,ot,dout,als,exten +ignore-words-list = ba,licence,ot,dout,als,exten,emac skip = ./.git,./.licenses,__pycache__,.clang-format,.codespellrc,.editorconfig,.flake8,.prettierignore,.yamllint.yml,.gitignore,boards.txt,platform.txt,programmers.txt builtin = clear,informal,en-GB_to_en-US check-filenames = diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000000..75a2b46d619 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,79 @@ +# CODEOWNERS for ESP32 Arduino Core + +# This file is used to specify the code owners for the ESP32 Arduino Core. +# Read more about CODEOWNERS: +# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners +# Note that order matters. The last matching pattern will be used. + +# The default owners are the active developers of the ESP32 Arduino Core. +# Refrain from using @espressif/arduino-esp32 to avoid spamming non-developers with review requests. +* @espressif/arduino-devs + +# CI +/.github/ @lucasssvaz @me-no-dev @P-R-O-C-H-Y +/tests/ @lucasssvaz @P-R-O-C-H-Y + +# Tools +/tools/ @me-no-dev +/tools/pre-commit/ @lucasssvaz +/tools/add_lib.sh @P-R-O-C-H-Y + +# Pre-commit +/.* @lucasssvaz # Files in root directory that start with a dot. + +# Git Files +/.gitignore @espressif/arduino-devs +/.gitmodules @espressif/arduino-devs + +# Documentation +/docs/ @pedrominatel +/.github/ISSUE_TEMPLATE/ @pedrominatel +/.github/PULL_REQUEST_TEMPLATE.md @pedrominatel +/.readthedocs.yaml @pedrominatel +/*.md @pedrominatel + +# Boards +/variants/ @P-R-O-C-H-Y +/boards.txt @P-R-O-C-H-Y + +# Arduino as Component +/idf_component_examples/ @SuGlider +/idf_component.yml @SuGlider @me-no-dev +/CMakeLists.txt @SuGlider @me-no-dev +/Kconfig.projbuild @SuGlider @me-no-dev + +# Build System +/package.json @me-no-dev +/platform.txt @me-no-dev +/programmers.txt @me-no-dev +/package/ @me-no-dev + +# Libraries +/libraries/ArduinoOTA/ @me-no-dev +/libraries/AsyncUDP/ @me-no-dev +/libraries/BLE/ @lucasssvaz @SuGlider +/libraries/ESP_I2S/ @me-no-dev +/libraries/ESP_NOW/ @P-R-O-C-H-Y @lucasssvaz +/libraries/ESP_SR/ @me-no-dev +/libraries/ESPmDNS/ @me-no-dev +/libraries/Ethernet/ @me-no-dev +/libraries/Matter/ @SuGlider +/libraries/NetBIOS/ @me-no-dev +/libraries/Network/ @me-no-dev +/libraries/OpenThread/ @SuGlider +/libraries/PPP/ @me-no-dev +/libraries/SPI/ @me-no-dev +/libraries/Update/ @me-no-dev +/libraries/USB/ @SuGlider @me-no-dev +/libraries/WiFi/ @me-no-dev +/libraries/WiFiProv/ @me-no-dev +/libraries/Wire/ @me-no-dev +/libraries/Zigbee/ @P-R-O-C-H-Y + +# CI JSON +# Keep this after other libraries and tests to avoid being overridden. +**/ci.json @lucasssvaz + +# The CODEOWNERS file should be owned by the developers of the ESP32 Arduino Core. +# Leave this entry as the last one to avoid being overridden. +/.github/CODEOWNERS @espressif/arduino-devs diff --git a/.github/ISSUE_TEMPLATE/Feature-request.yml b/.github/ISSUE_TEMPLATE/Feature-request.yml index 0788288036c..8849a407a39 100644 --- a/.github/ISSUE_TEMPLATE/Feature-request.yml +++ b/.github/ISSUE_TEMPLATE/Feature-request.yml @@ -5,6 +5,7 @@ body: - type: markdown attributes: value: | + * Please note that we can only process feature requests reported in English to ensure effective communication and support. Feature requests written in other languages will be closed, with a request to rewrite them in English. * We welcome any ideas or feature requests! It is helpful if you can explain exactly why the feature would be useful. * There are usually some outstanding feature requests in the [existing issues list](https://github.com/espressif/arduino-esp32/issues?q=is%3Aopen+is%3Aissue+label%3A%22Type%3A+Feature+request%22), feel free to add comments to them. * If you would like to contribute, please read the [contributions guide](https://docs.espressif.com/projects/arduino-esp32/en/latest/contributing.html). diff --git a/.github/ISSUE_TEMPLATE/Issue-report.yml b/.github/ISSUE_TEMPLATE/Issue-report.yml index a902184f06b..9dba5e0ca8f 100644 --- a/.github/ISSUE_TEMPLATE/Issue-report.yml +++ b/.github/ISSUE_TEMPLATE/Issue-report.yml @@ -5,6 +5,7 @@ body: - type: markdown attributes: value: | + * Please note that we can only process issues reported in English to ensure effective communication and support. Issues written in other languages will be closed, with a request to rewrite them in English. * Before reporting a new issue please check and search in [List of existing issues](https://github.com/espressif/arduino-esp32/issues?q=is%3Aissue) * Please check [Online Documentation](https://docs.espressif.com/projects/arduino-esp32/en/latest/index.html) * Take a look on [Troubleshooting guide](https://docs.espressif.com/projects/arduino-esp32/en/latest/troubleshooting.html) @@ -39,8 +40,11 @@ body: label: Version description: What version of Arduino ESP32 are you running? If possible, consider updating to the latest version. options: - - latest master (checkout manually) + - latest stable Release (if not listed below) - latest development Release Candidate (RC-X) + - latest master (checkout manually) + - v3.2.0 + - v3.1.3 - v3.1.2 - v3.1.1 - v3.1.0 diff --git a/.github/scripts/on-push-idf.sh b/.github/scripts/on-push-idf.sh new file mode 100644 index 00000000000..72e7c7f574e --- /dev/null +++ b/.github/scripts/on-push-idf.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +CHECK_REQUIREMENTS="./components/arduino-esp32/.github/scripts/sketch_utils.sh check_requirements" + +# Export IDF environment +. ${IDF_PATH}/export.sh + +# Find all examples in ./components/arduino-esp32/idf_component_examples +idf_component_examples=$(find ./components/arduino-esp32/idf_component_examples -mindepth 1 -maxdepth 1 -type d) + +for example in $idf_component_examples; do + if [ -f "$example"/ci.json ]; then + # If the target is listed as false, skip the sketch. Otherwise, include it. + is_target=$(jq -r --arg target "$IDF_TARGET" '.targets[$target]' "$example"/ci.json) + if [[ "$is_target" == "false" ]]; then + printf "\n\033[93mSkipping %s for target %s\033[0m\n\n" "$example" "$IDF_TARGET" + continue + fi + fi + + idf.py -C "$example" set-target "$IDF_TARGET" + + has_requirements=$(${CHECK_REQUIREMENTS} "$example" "$example/sdkconfig") + if [ "$has_requirements" -eq 0 ]; then + printf "\n\033[93m%s does not meet the requirements for %s. Skipping...\033[0m\n\n" "$example" "$IDF_TARGET" + continue + fi + + printf "\n\033[95mBuilding %s\033[0m\n\n" "$example" + idf.py -C "$example" -DEXTRA_COMPONENT_DIRS="$PWD/components" build +done diff --git a/.github/scripts/on-release.sh b/.github/scripts/on-release.sh index 242cee93d0b..275c74f8ea5 100755 --- a/.github/scripts/on-release.sh +++ b/.github/scripts/on-release.sh @@ -35,6 +35,8 @@ PACKAGE_JSON_MERGE="$GITHUB_WORKSPACE/.github/scripts/merge_packages.py" PACKAGE_JSON_TEMPLATE="$GITHUB_WORKSPACE/package/package_esp32_index.template.json" PACKAGE_JSON_DEV="package_esp32_dev_index.json" PACKAGE_JSON_REL="package_esp32_index.json" +PACKAGE_JSON_DEV_CN="package_esp32_dev_index_cn.json" +PACKAGE_JSON_REL_CN="package_esp32_index_cn.json" echo "Event: $GITHUB_EVENT_NAME, Repo: $GITHUB_REPOSITORY, Path: $GITHUB_WORKSPACE, Ref: $GITHUB_REF" echo "Action: $action, Branch: $RELEASE_BRANCH, ID: $RELEASE_ID" @@ -339,9 +341,15 @@ jq_arg=".packages[0].platforms[0].version = \"$RELEASE_TAG\" | \ # Generate package JSONs echo "Generating $PACKAGE_JSON_DEV ..." cat "$PACKAGE_JSON_TEMPLATE" | jq "$jq_arg" > "$OUTPUT_DIR/$PACKAGE_JSON_DEV" +# On MacOS the sed command won't skip the first match. Use gsed instead. +sed '0,/github\.com\//!s|github\.com/|dl.espressif.cn/github_assets/|g' "$OUTPUT_DIR/$PACKAGE_JSON_DEV" > "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN" +python "$SCRIPTS_DIR/release_append_cn.py" "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN" if [ "$RELEASE_PRE" == "false" ]; then echo "Generating $PACKAGE_JSON_REL ..." cat "$PACKAGE_JSON_TEMPLATE" | jq "$jq_arg" > "$OUTPUT_DIR/$PACKAGE_JSON_REL" + # On MacOS the sed command won't skip the first match. Use gsed instead. + sed '0,/github\.com\//!s|github\.com/|dl.espressif.cn/github_assets/|g' "$OUTPUT_DIR/$PACKAGE_JSON_REL" > "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN" + python "$SCRIPTS_DIR/release_append_cn.py" "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN" fi # Figure out the last release or pre-release @@ -373,12 +381,14 @@ echo if [ -n "$prev_any_release" ] && [ "$prev_any_release" != "null" ]; then echo "Merging with JSON from $prev_any_release ..." merge_package_json "$prev_any_release/$PACKAGE_JSON_DEV" "$OUTPUT_DIR/$PACKAGE_JSON_DEV" + merge_package_json "$prev_any_release/$PACKAGE_JSON_DEV_CN" "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN" fi if [ "$RELEASE_PRE" == "false" ]; then if [ -n "$prev_release" ] && [ "$prev_release" != "null" ]; then echo "Merging with JSON from $prev_release ..." merge_package_json "$prev_release/$PACKAGE_JSON_REL" "$OUTPUT_DIR/$PACKAGE_JSON_REL" + merge_package_json "$prev_release/$PACKAGE_JSON_REL_CN" "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN" fi fi @@ -388,6 +398,8 @@ echo "Installing arduino-cli ..." export PATH="/home/runner/bin:$PATH" source "${SCRIPTS_DIR}/install-arduino-cli.sh" +# For the Chinese mirror, we can't test the package JSONs as the Chinese mirror might not be updated yet. + echo "Testing $PACKAGE_JSON_DEV install ..." echo "Installing esp32 ..." @@ -445,11 +457,15 @@ fi echo "Uploading $PACKAGE_JSON_DEV ..." echo "Download URL: $(git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_DEV")" echo "Pages URL: $(git_safe_upload_to_pages "$PACKAGE_JSON_DEV" "$OUTPUT_DIR/$PACKAGE_JSON_DEV")" +echo "Download CN URL: $(git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN")" +echo "Pages CN URL: $(git_safe_upload_to_pages "$PACKAGE_JSON_DEV_CN" "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN")" echo if [ "$RELEASE_PRE" == "false" ]; then echo "Uploading $PACKAGE_JSON_REL ..." echo "Download URL: $(git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_REL")" echo "Pages URL: $(git_safe_upload_to_pages "$PACKAGE_JSON_REL" "$OUTPUT_DIR/$PACKAGE_JSON_REL")" + echo "Download CN URL: $(git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN")" + echo "Pages CN URL: $(git_safe_upload_to_pages "$PACKAGE_JSON_REL_CN" "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN")" echo fi diff --git a/.github/scripts/package_esptool.sh b/.github/scripts/package_esptool.sh new file mode 100755 index 00000000000..32b87b277e9 --- /dev/null +++ b/.github/scripts/package_esptool.sh @@ -0,0 +1,129 @@ +#!/bin/bash + +set -euo pipefail + +# Check version argument +if [[ $# -ne 3 ]]; then + echo "Usage: $0 " + echo "Example: $0 5.0.dev1 /tmp/esptool /tmp/esptool-5.0.dev1.json" + exit 1 +fi + +VERSION=$1 +BASE_FOLDER=$2 +JSON_PATH=$3 + +export COPYFILE_DISABLE=1 + +shopt -s nullglob # So for loop doesn't run if no matches + +# Function to update JSON for a given host +function update_json_for_host { + local host=$1 + local archive=$2 + + # Extract the old url from the JSON for this host, then replace only the filename + old_url=$(jq -r --arg host "$host" ' + .packages[].tools[] | select(.name == "esptool_py") | .systems[] | select(.host == $host) | .url // empty + ' "$tmp_json") + if [[ -n "$old_url" ]]; then + base_url="${old_url%/*}" + url="$base_url/$archive" + else + echo "No old url found for $host" + exit 1 + fi + + archiveFileName="$archive" + checksum="SHA-256:$(shasum -a 256 "$archive" | awk '{print $1}')" + size=$(stat -f%z "$archive") + + # Use jq to update the JSON + jq --arg host "$host" \ + --arg url "$url" \ + --arg archiveFileName "$archiveFileName" \ + --arg checksum "$checksum" \ + --arg size "$size" \ + ' + .packages[].tools[] + |= if .name == "esptool_py" then + .systems = ( + ((.systems // []) | map(select(.host != $host))) + [{ + host: $host, + url: $url, + archiveFileName: $archiveFileName, + checksum: $checksum, + size: $size + }] + ) + else + . + end + ' "$tmp_json" > "$tmp_json.new" && mv "$tmp_json.new" "$tmp_json" +} + +cd "$BASE_FOLDER" + +# Delete all archives before starting +rm -f esptool-*.tar.gz esptool-*.zip + +for dir in esptool-*; do + # Check if directory exists and is a directory + if [[ ! -d "$dir" ]]; then + continue + fi + + base="${dir#esptool-}" + + # Add 'linux-' prefix if base doesn't contain linux/macos/win64 + if [[ "$base" != *linux* && "$base" != *macos* && "$base" != *win64* ]]; then + base="linux-${base}" + fi + + if [[ "$dir" == esptool-win* ]]; then + # Windows zip archive + zipfile="esptool-v${VERSION}-${base}.zip" + echo "Creating $zipfile from $dir ..." + zip -r "$zipfile" "$dir" + else + # Non-Windows: set permissions and tar.gz archive + tarfile="esptool-v${VERSION}-${base}.tar.gz" + echo "Setting permissions and creating $tarfile from $dir ..." + chmod -R u=rwx,g=rx,o=rx "$dir" + tar -cvzf "$tarfile" "$dir" + fi +done + +# After the for loop, update the JSON for each archive +# Create a temporary JSON file to accumulate changes +tmp_json="${JSON_PATH}.tmp" +cp "$JSON_PATH" "$tmp_json" + +for archive in esptool-v"${VERSION}"-*.tar.gz esptool-v"${VERSION}"-*.zip; do + [ -f "$archive" ] || continue + + echo "Updating JSON for $archive" + + # Determine host from archive name + case "$archive" in + *linux-amd64*) host="x86_64-pc-linux-gnu" ;; + *linux-armv7*) host="arm-linux-gnueabihf" ;; + *linux-aarch64*) host="aarch64-linux-gnu" ;; + *macos-amd64*) host="x86_64-apple-darwin" ;; + *macos-arm64*) host="arm64-apple-darwin" ;; + *win64*) hosts=("x86_64-mingw32" "i686-mingw32") ;; + *) echo "Unknown host for $archive"; continue ;; + esac + + # For win64, loop over both hosts; otherwise, use a single host + if [[ "$archive" == *win64* ]]; then + for host in "${hosts[@]}"; do + update_json_for_host "$host" "$archive" + done + else + update_json_for_host "$host" "$archive" + fi +done + +# After all archives are processed, move the temporary JSON to the final file +mv "$tmp_json" "$JSON_PATH" diff --git a/.github/scripts/release_append_cn.py b/.github/scripts/release_append_cn.py new file mode 100755 index 00000000000..b29fe0c31ba --- /dev/null +++ b/.github/scripts/release_append_cn.py @@ -0,0 +1,56 @@ + +#!/usr/bin/env python3 + +# Arduino IDE provides by default a package file for the ESP32. This causes version conflicts +# when the user tries to use the JSON file with the Chinese mirrors. +# +# The downside is that the Arduino IDE will always warn the user that updates are available as it +# will consider the version from the Chinese mirrors as a pre-release version. +# +# This script is used to append "-cn" to all versions in the package_esp32_index_cn.json file so that +# the user can select the Chinese mirrors without conflicts. +# +# If Arduino ever stops providing the package_esp32_index.json file by default, +# this script can be removed and the tags reverted. + +import json + +def append_cn_to_versions(obj): + if isinstance(obj, dict): + # dfu-util comes from arduino.cc and not from the Chinese mirrors, so we skip it + if obj.get("name") == "dfu-util": + return + + for key, value in obj.items(): + if key == "version" and isinstance(value, str): + if not value.endswith("-cn"): + obj[key] = value + "-cn" + else: + append_cn_to_versions(value) + + elif isinstance(obj, list): + for item in obj: + append_cn_to_versions(item) + +def process_json_file(input_path, output_path=None): + with open(input_path, "r", encoding="utf-8") as f: + data = json.load(f) + + append_cn_to_versions(data) + + if output_path is None: + output_path = input_path + + with open(output_path, "w", encoding="utf-8") as f: + json.dump(data, f, indent=2) + + print(f"Updated JSON written to {output_path}") + +if __name__ == "__main__": + import sys + if len(sys.argv) < 2: + print("Usage: python release_append_cn.py input.json [output.json]") + else: + input_file = sys.argv[1] + output_file = sys.argv[2] if len(sys.argv) > 2 else None + process_json_file(input_file, output_file) diff --git a/.github/scripts/sketch_utils.sh b/.github/scripts/sketch_utils.sh index e536da50111..befea255e0b 100755 --- a/.github/scripts/sketch_utils.sh +++ b/.github/scripts/sketch_utils.sh @@ -16,7 +16,7 @@ function check_requirements { # check_requirements local requirements_or if [ ! -f "$sdkconfig_path" ] || [ ! -f "$sketchdir/ci.json" ]; then - echo "ERROR: sdkconfig or ci.json not found" 1>&2 + echo "WARNING: sdkconfig or ci.json not found. Assuming requirements are met." 1>&2 # Return 1 on error to force the sketch to be built and fail. This way the # CI will fail and the user will know that the sketch has a problem. else diff --git a/.github/workflows/publishsizes.yml b/.github/workflows/publishsizes.yml index 69c18cf1835..fad2418668c 100644 --- a/.github/workflows/publishsizes.yml +++ b/.github/workflows/publishsizes.yml @@ -44,16 +44,17 @@ jobs: gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact do IFS=$'\t' read name url <<< "$artifact" - gh api $url > "$name.zip" - unzip -j "$name.zip" -d "temp_$name" - if [[ "$name" == "pr_number" ]]; then - mv "temp_$name"/* sizes-report - elif [[ "$name" == "pr_cli"* ]]; then - mv "temp_$name"/* sizes-report/pr - else - mv "temp_$name"/* sizes-report + # Only process pr_number and pr_cli_compile artifacts + if [[ "$name" == "pr_number" || "$name" =~ ^pr_cli_compile_[0-9]+$ ]]; then + gh api $url > "$name.zip" + unzip -o -j "$name.zip" -d "temp_$name" + if [[ "$name" == "pr_number" ]]; then + mv "temp_$name"/* sizes-report + elif [[ "$name" =~ ^pr_cli_compile_[0-9]+$ ]]; then + mv "temp_$name"/* sizes-report/pr + fi + rm -r "temp_$name" fi - rm -r "temp_$name" done echo "Contents of parent directory:" ls -R .. @@ -65,7 +66,7 @@ jobs: path: ./artifacts/sizes-report/pr_num.txt - name: Report results - uses: P-R-O-C-H-Y/report-size-deltas@2043188c68f483a7b50527c4eacf609d05bb67a5 # sizes_v2 + uses: P-R-O-C-H-Y/report-size-deltas@bea91d2c99ca80c88a883b39b1c4012f00ec3d09 # sizes_v2 with: sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }} github-token: ${{ env.GITHUB_TOKEN }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index d98da24fc07..c8b8ddc2127 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -31,6 +31,7 @@ on: - "!libraries/**.properties" - "!libraries/**.py" - "package/**" + - "idf_component_examples/**" - "tools/**.py" - "platform.txt" - "programmers.txt" @@ -45,7 +46,6 @@ on: - "!.github/scripts/tests_*" - "!.github/scripts/upload_*" - "variants/esp32/**/*" - - "variants/esp32c2/**/*" - "variants/esp32c3/**/*" - "variants/esp32c6/**/*" - "variants/esp32h2/**/*" @@ -124,7 +124,7 @@ jobs: - 'idf_component.yml' - 'Kconfig.projbuild' - 'CMakeLists.txt' - - "variants/esp32c2/**/*" + - "idf_component_examples/**" - name: Set chunks id: set-chunks @@ -267,15 +267,23 @@ jobs: submodules: recursive path: components/arduino-esp32 + - name: Setup jq + uses: dcarbone/install-jq-action@e397bd87438d72198f81efd21f876461183d383a # v3.0.1 + - name: Build env: IDF_TARGET: ${{ matrix.idf_target }} shell: bash run: | - . ${IDF_PATH}/export.sh - idf.py create-project test - echo CONFIG_FREERTOS_HZ=1000 > test/sdkconfig.defaults - idf.py -C test -DEXTRA_COMPONENT_DIRS=$PWD/components build + chmod a+x ./components/arduino-esp32/.github/scripts/* + ./components/arduino-esp32/.github/scripts/on-push-idf.sh + + - name: Upload generated sdkconfig files for debugging + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + if: always() + with: + name: sdkconfig-${{ matrix.idf_target }} + path: ./components/arduino-esp32/idf_component_examples/**/sdkconfig # Save artifacts to gh-pages save-master-artifacts: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f80261422b0..0d425c46eae 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ default_language_version: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v5.0.0" + rev: "cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b" # v5.0.0 hooks: # Generic checks - id: check-case-conflict @@ -39,15 +39,8 @@ repos: ^package\/.*$ ) - - repo: https://github.com/codespell-project/codespell - rev: "v2.3.0" - hooks: - # Spell checking - - id: codespell - exclude: ^.*\.(svd|SVD)$ - - repo: https://github.com/pre-commit/mirrors-clang-format - rev: "v18.1.3" + rev: "f6446549e5e97ec9665b9b03e75b87b445857f9a" # v18.1.3 hooks: # C/C++ formatting - id: clang-format @@ -55,7 +48,7 @@ repos: exclude: ^.*\/build_opt\.h$ - repo: https://github.com/psf/black-pre-commit-mirror - rev: "24.10.0" + rev: "a4920527036bb9a3f3e6055d595849d67d0da066" # 25.1.0 hooks: # Python formatting - id: black @@ -63,7 +56,7 @@ repos: args: [--line-length=120] #From the arduino code style. Add as argument rather than creating a new config file. - repo: https://github.com/PyCQA/flake8 - rev: "7.1.1" + rev: "16f5f28a384f0781bebb37a08aa45e65b9526c50" # 7.2.0 hooks: # Python linting - id: flake8 @@ -74,21 +67,28 @@ repos: - flake8-simplify - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v3.1.0" + rev: "ffb6a759a979008c0e6dff86e39f4745a2d9eac4" # v3.1.0 hooks: # YAML formatting - id: prettier types_or: [yaml] + - repo: https://github.com/codespell-project/codespell + rev: "63c8f8312b7559622c0d82815639671ae42132ac" # v2.4.1 + hooks: + # Spell checking + - id: codespell + exclude: ^.*\.(svd|SVD)$ + - repo: https://github.com/shellcheck-py/shellcheck-py - rev: "v0.10.0.1" + rev: "a23f6b85d0fdd5bb9d564e2579e678033debbdff" # v0.10.0.1 hooks: # Bash linting - id: shellcheck types: [shell] - repo: https://github.com/openstack/bashate - rev: "2.1.1" + rev: "fbd7c2534c2701351c603ff700ddf08202430a31" # 2.1.1 hooks: # Bash formatting - id: bashate @@ -96,15 +96,15 @@ repos: args: ["-i", "E006"] # Ignore E006: Line too long - repo: https://github.com/errata-ai/vale - rev: "v3.9.1" + rev: "dc4c47923788a413fb5677de6e3370d514aecb78" # v3.11.2 hooks: # Sync vale styles and lint markdown and reStructuredText - id: vale name: vale-sync - language_version: "1.21.6" + language_version: "1.23.2" pass_filenames: false args: [sync] types_or: [markdown, rst] - id: vale - language_version: "1.21.6" + language_version: "1.23.2" types_or: [markdown, rst] diff --git a/CMakeLists.txt b/CMakeLists.txt index 7539601d9e5..e8f44ac5ee0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,6 +165,7 @@ set(ARDUINO_LIBRARY_LittleFS_SRCS libraries/LittleFS/src/LittleFS.cpp) set(ARDUINO_LIBRARY_NetBIOS_SRCS libraries/NetBIOS/src/NetBIOS.cpp) set(ARDUINO_LIBRARY_OpenThread_SRCS + libraries/OpenThread/src/OThread.cpp libraries/OpenThread/src/OThreadCLI.cpp libraries/OpenThread/src/OThreadCLI_Util.cpp) @@ -300,6 +301,10 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS libraries/Zigbee/src/ep/ZigbeeGateway.cpp libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.cpp + libraries/Zigbee/src/ep/ZigbeePM25Sensor.cpp + libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.cpp + libraries/Zigbee/src/ep/ZigbeeBinary.cpp + libraries/Zigbee/src/ep/ZigbeePowerOutlet.cpp ) set(ARDUINO_LIBRARY_BLE_SRCS diff --git a/boards.txt b/boards.txt index f0df27762c2..b51a8840757 100644 --- a/boards.txt +++ b/boards.txt @@ -282,6 +282,15 @@ esp32p4.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 esp32p4.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9.9MB FATFS) esp32p4.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB esp32p4.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +esp32p4.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) +esp32p4.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB +esp32p4.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 +esp32p4.menu.PartitionScheme.app5M_little24M_32MB=32M Flash (4.8MB APP/22MB LittleFS) +esp32p4.menu.PartitionScheme.app5M_little24M_32MB.build.partitions=large_littlefs_32MB +esp32p4.menu.PartitionScheme.app5M_little24M_32MB.upload.maximum_size=4718592 +esp32p4.menu.PartitionScheme.app13M_data7M_32MB=32M Flash (13MB APP/6.75MB SPIFFS) +esp32p4.menu.PartitionScheme.app13M_data7M_32MB.build.partitions=default_32MB +esp32p4.menu.PartitionScheme.app13M_data7M_32MB.upload.maximum_size=13107200 esp32p4.menu.PartitionScheme.custom=Custom esp32p4.menu.PartitionScheme.custom.build.partitions= esp32p4.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -314,6 +323,8 @@ esp32p4.menu.FlashSize.2M.build.flash_size=2MB esp32p4.menu.FlashSize.2M.build.partitions=minimal esp32p4.menu.FlashSize.16M=16MB (128Mb) esp32p4.menu.FlashSize.16M.build.flash_size=16MB +esp32p4.menu.FlashSize.32M=32MB (256Mb) +esp32p4.menu.FlashSize.32M.build.flash_size=32MB esp32p4.menu.UploadSpeed.921600=921600 esp32p4.menu.UploadSpeed.921600.upload.speed=921600 @@ -449,7 +460,7 @@ esp32h2.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 #esp32h2.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 #esp32h2.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB #esp32h2.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -#esp32h2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +#esp32h2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32h2.menu.PartitionScheme.zigbee_2MB=Zigbee 2MB with spiffs esp32h2.menu.PartitionScheme.zigbee_2MB.build.partitions=zigbee_2MB esp32h2.menu.PartitionScheme.zigbee_2MB.upload.maximum_size=1310720 @@ -647,7 +658,7 @@ esp32c6.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ota esp32c6.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32c6.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32c6.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32c6.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32c6.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32c6.menu.PartitionScheme.zigbee_2MB=Zigbee 2MB with spiffs esp32c6.menu.PartitionScheme.zigbee_2MB.build.partitions=zigbee_2MB esp32c6.menu.PartitionScheme.zigbee_2MB.upload.maximum_size=1310720 @@ -933,7 +944,7 @@ esp32s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ota esp32s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32s3.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) esp32s3.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB esp32s3.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -1110,7 +1121,7 @@ esp32c3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ota esp32c3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32c3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32c3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32c3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32c3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32c3.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs esp32c3.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr esp32c3.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720 @@ -1318,7 +1329,7 @@ esp32s2.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ota esp32s2.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32s2.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32s2.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32s2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32s2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32s2.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs esp32s2.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr esp32s2.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720 @@ -1501,7 +1512,7 @@ esp32.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ota esp32.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs esp32.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr esp32.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720 @@ -1681,7 +1692,7 @@ esp32da.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ota esp32da.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32da.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32da.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32da.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32da.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32da.menu.PartitionScheme.custom=Custom esp32da.menu.PartitionScheme.custom.build.partitions= esp32da.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -2144,7 +2155,7 @@ esp32s3-octal.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_ esp32s3-octal.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32s3-octal.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32s3-octal.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32s3-octal.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32s3-octal.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32s3-octal.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) esp32s3-octal.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB esp32s3-octal.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -2731,7 +2742,7 @@ esp32wroverkit.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB esp32wroverkit.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32wroverkit.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32wroverkit.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32wroverkit.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32wroverkit.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32wroverkit.menu.CPUFreq.240=240MHz (WiFi/BT) esp32wroverkit.menu.CPUFreq.240.build.f_cpu=240000000L @@ -2966,7 +2977,7 @@ aventen_s3_sync.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4M aventen_s3_sync.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 aventen_s3_sync.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB aventen_s3_sync.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -aventen_s3_sync.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +aventen_s3_sync.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 aventen_s3_sync.menu.CPUFreq.240=240MHz (WiFi) aventen_s3_sync.menu.CPUFreq.240.build.f_cpu=240000000L @@ -3643,6 +3654,155 @@ um_bling.menu.EraseFlash.all.upload.erase_cmd=-e ############################################################## +um_edges3_d.name=UM EdgeS3[D] +um_edges3_d.vid.0=0x303a +um_edges3_d.pid.0=0x82DC +um_edges3_d.upload_port.0.vid=0x303a +um_edges3_d.upload_port.0.pid=0x82DC + +um_edges3_d.bootloader.tool=esptool_py +um_edges3_d.bootloader.tool.default=esptool_py + +um_edges3_d.upload.tool=esptool_py +um_edges3_d.upload.tool.default=esptool_py +um_edges3_d.upload.tool.network=esp_ota + +um_edges3_d.upload.maximum_size=1310720 +um_edges3_d.upload.maximum_data_size=327680 +um_edges3_d.upload.flags= +um_edges3_d.upload.extra_flags= +um_edges3_d.upload.use_1200bps_touch=false +um_edges3_d.upload.wait_for_upload_port=false + +um_edges3_d.serial.disableDTR=false +um_edges3_d.serial.disableRTS=false + +um_edges3_d.build.tarch=xtensa +um_edges3_d.build.bootloader_addr=0x0 +um_edges3_d.build.target=esp32s3 +um_edges3_d.build.mcu=esp32s3 +um_edges3_d.build.core=esp32 +um_edges3_d.build.variant=um_edges3_d +um_edges3_d.build.board=EDGES3D + +um_edges3_d.build.usb_mode=1 +um_edges3_d.build.cdc_on_boot=1 +um_edges3_d.build.msc_on_boot=0 +um_edges3_d.build.dfu_on_boot=0 +um_edges3_d.build.f_cpu=240000000L +um_edges3_d.build.flash_size=8MB +um_edges3_d.build.flash_freq=80m +um_edges3_d.build.flash_mode=dio +um_edges3_d.build.boot=qio +um_edges3_d.build.partitions=default +um_edges3_d.build.defines= +um_edges3_d.build.loop_core= +um_edges3_d.build.event_core= +um_edges3_d.build.flash_type=qio +um_edges3_d.build.psram_type=qspi +um_edges3_d.build.memory_type=qio_qspi + +um_edges3_d.menu.LoopCore.1=Core 1 +um_edges3_d.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +um_edges3_d.menu.LoopCore.0=Core 0 +um_edges3_d.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +um_edges3_d.menu.EventsCore.1=Core 1 +um_edges3_d.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +um_edges3_d.menu.EventsCore.0=Core 0 +um_edges3_d.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +um_edges3_d.menu.USBMode.hwcdc=Hardware CDC and JTAG +um_edges3_d.menu.USBMode.hwcdc.build.usb_mode=1 +um_edges3_d.menu.USBMode.default=USB-OTG (TinyUSB) +um_edges3_d.menu.USBMode.default.build.usb_mode=0 + +um_edges3_d.menu.CDCOnBoot.cdc=Enabled +um_edges3_d.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +um_edges3_d.menu.CDCOnBoot.default=Disabled +um_edges3_d.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +um_edges3_d.menu.MSCOnBoot.default=Disabled +um_edges3_d.menu.MSCOnBoot.default.build.msc_on_boot=0 +um_edges3_d.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +um_edges3_d.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +um_edges3_d.menu.DFUOnBoot.default=Disabled +um_edges3_d.menu.DFUOnBoot.default.build.dfu_on_boot=0 +um_edges3_d.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +um_edges3_d.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +um_edges3_d.menu.UploadMode.cdc.upload.wait_for_upload_port=true +um_edges3_d.menu.UploadMode.default=UART0 / Hardware CDC +um_edges3_d.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +um_edges3_d.menu.UploadMode.cdc.upload.use_1200bps_touch=true +um_edges3_d.menu.UploadMode.default.upload.use_1200bps_touch=false +um_edges3_d.menu.UploadMode.default.upload.wait_for_upload_port=false + +um_edges3_d.menu.PSRAM.enabled=Enabled +um_edges3_d.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +um_edges3_d.menu.PSRAM.disabled=Disabled +um_edges3_d.menu.PSRAM.disabled.build.defines= + +um_edges3_d.menu.PartitionScheme.default_8MB=Default (3MB APP/1.5MB SPIFFS) +um_edges3_d.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +um_edges3_d.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 + +um_edges3_d.menu.CPUFreq.240=240MHz (WiFi) +um_edges3_d.menu.CPUFreq.240.build.f_cpu=240000000L +um_edges3_d.menu.CPUFreq.160=160MHz (WiFi) +um_edges3_d.menu.CPUFreq.160.build.f_cpu=160000000L +um_edges3_d.menu.CPUFreq.80=80MHz (WiFi) +um_edges3_d.menu.CPUFreq.80.build.f_cpu=80000000L +um_edges3_d.menu.CPUFreq.40=40MHz +um_edges3_d.menu.CPUFreq.40.build.f_cpu=40000000L +um_edges3_d.menu.CPUFreq.20=20MHz +um_edges3_d.menu.CPUFreq.20.build.f_cpu=20000000L +um_edges3_d.menu.CPUFreq.10=10MHz +um_edges3_d.menu.CPUFreq.10.build.f_cpu=10000000L + +um_edges3_d.menu.FlashMode.qio=QIO +um_edges3_d.menu.FlashMode.qio.build.flash_mode=dio +um_edges3_d.menu.FlashMode.qio.build.boot=qio +um_edges3_d.menu.FlashMode.dio=DIO +um_edges3_d.menu.FlashMode.dio.build.flash_mode=dio +um_edges3_d.menu.FlashMode.dio.build.boot=dio + +um_edges3_d.menu.UploadSpeed.921600=921600 +um_edges3_d.menu.UploadSpeed.921600.upload.speed=921600 +um_edges3_d.menu.UploadSpeed.115200=115200 +um_edges3_d.menu.UploadSpeed.115200.upload.speed=115200 +um_edges3_d.menu.UploadSpeed.256000.windows=256000 +um_edges3_d.menu.UploadSpeed.256000.upload.speed=256000 +um_edges3_d.menu.UploadSpeed.230400.windows.upload.speed=256000 +um_edges3_d.menu.UploadSpeed.230400=230400 +um_edges3_d.menu.UploadSpeed.230400.upload.speed=230400 +um_edges3_d.menu.UploadSpeed.460800.linux=460800 +um_edges3_d.menu.UploadSpeed.460800.macosx=460800 +um_edges3_d.menu.UploadSpeed.460800.upload.speed=460800 +um_edges3_d.menu.UploadSpeed.512000.windows=512000 +um_edges3_d.menu.UploadSpeed.512000.upload.speed=512000 + +um_edges3_d.menu.DebugLevel.none=None +um_edges3_d.menu.DebugLevel.none.build.code_debug=0 +um_edges3_d.menu.DebugLevel.error=Error +um_edges3_d.menu.DebugLevel.error.build.code_debug=1 +um_edges3_d.menu.DebugLevel.warn=Warn +um_edges3_d.menu.DebugLevel.warn.build.code_debug=2 +um_edges3_d.menu.DebugLevel.info=Info +um_edges3_d.menu.DebugLevel.info.build.code_debug=3 +um_edges3_d.menu.DebugLevel.debug=Debug +um_edges3_d.menu.DebugLevel.debug.build.code_debug=4 +um_edges3_d.menu.DebugLevel.verbose=Verbose +um_edges3_d.menu.DebugLevel.verbose.build.code_debug=5 + +um_edges3_d.menu.EraseFlash.none=Disabled +um_edges3_d.menu.EraseFlash.none.upload.erase_cmd= +um_edges3_d.menu.EraseFlash.all=Enabled +um_edges3_d.menu.EraseFlash.all.upload.erase_cmd=-e + +############################################################## + um_feathers2.name=UM FeatherS2 um_feathers2.vid.0=0x239A um_feathers2.pid.0=0x80AB @@ -4735,6 +4895,163 @@ um_pros3.menu.EraseFlash.all.upload.erase_cmd=-e ############################################################## +um_squixl.name=UM SQUIXL +um_squixl.vid.0=0x303a +um_squixl.pid.0=0x82DF +um_squixl.upload_port.0.vid=0x303a +um_squixl.upload_port.0.pid=0x82DF + +um_squixl.bootloader.tool=esptool_py +um_squixl.bootloader.tool.default=esptool_py + +um_squixl.upload.tool=esptool_py +um_squixl.upload.tool.default=esptool_py +um_squixl.upload.tool.network=esp_ota + +um_squixl.upload.maximum_size=1310720 +um_squixl.upload.maximum_data_size=327680 +um_squixl.upload.flags= +um_squixl.upload.extra_flags= +um_squixl.upload.use_1200bps_touch=false +um_squixl.upload.wait_for_upload_port=false + +um_squixl.serial.disableDTR=false +um_squixl.serial.disableRTS=false + +um_squixl.build.tarch=xtensa +um_squixl.build.bootloader_addr=0x0 +um_squixl.build.target=esp32s3 +um_squixl.build.mcu=esp32s3 +um_squixl.build.core=esp32 +um_squixl.build.variant=um_squixl +um_squixl.build.board=SQUIXL + +um_squixl.build.usb_mode=1 +um_squixl.build.cdc_on_boot=1 +um_squixl.build.msc_on_boot=0 +um_squixl.build.dfu_on_boot=0 +um_squixl.build.f_cpu=240000000L +um_squixl.build.flash_size=16MB +um_squixl.build.flash_freq=80m +um_squixl.build.flash_mode=dio +um_squixl.build.boot=qio +um_squixl.build.partitions=default +um_squixl.build.defines= +um_squixl.build.loop_core= +um_squixl.build.event_core= +um_squixl.build.flash_type=qio +um_squixl.build.psram_type=opi +um_squixl.build.memory_type=qio_opi + +um_squixl.menu.LoopCore.1=Core 1 +um_squixl.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +um_squixl.menu.LoopCore.0=Core 0 +um_squixl.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +um_squixl.menu.EventsCore.1=Core 1 +um_squixl.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +um_squixl.menu.EventsCore.0=Core 0 +um_squixl.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +um_squixl.menu.USBMode.hwcdc=Hardware CDC and JTAG +um_squixl.menu.USBMode.hwcdc.build.usb_mode=1 +um_squixl.menu.USBMode.default=USB-OTG (TinyUSB) +um_squixl.menu.USBMode.default.build.usb_mode=0 + +um_squixl.menu.CDCOnBoot.cdc=Enabled +um_squixl.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +um_squixl.menu.CDCOnBoot.default=Disabled +um_squixl.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +um_squixl.menu.MSCOnBoot.default=Disabled +um_squixl.menu.MSCOnBoot.default.build.msc_on_boot=0 +um_squixl.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +um_squixl.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +um_squixl.menu.DFUOnBoot.default=Disabled +um_squixl.menu.DFUOnBoot.default.build.dfu_on_boot=0 +um_squixl.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +um_squixl.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +um_squixl.menu.UploadMode.cdc.upload.wait_for_upload_port=true +um_squixl.menu.UploadMode.default=UART0 / Hardware CDC +um_squixl.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +um_squixl.menu.UploadMode.cdc.upload.use_1200bps_touch=true +um_squixl.menu.UploadMode.default.upload.use_1200bps_touch=false +um_squixl.menu.UploadMode.default.upload.wait_for_upload_port=false + +um_squixl.menu.PSRAM.opi=OPI PSRAM +um_squixl.menu.PSRAM.opi.build.defines=-DBOARD_HAS_PSRAM +um_squixl.menu.PSRAM.opi.build.psram_type=opi + +um_squixl.menu.PartitionScheme.default_16MB=Default (6.25MB APP/3.43MB SPIFFS) +um_squixl.menu.PartitionScheme.default_16MB.build.partitions=default_16MB +um_squixl.menu.PartitionScheme.default_16MB.upload.maximum_size=6553600 +um_squixl.menu.PartitionScheme.large_spiffs=Large SPIFFS (4.5MB APP/6.93MB SPIFFS) +um_squixl.menu.PartitionScheme.large_spiffs.build.partitions=large_spiffs_16MB +um_squixl.menu.PartitionScheme.large_spiffs.upload.maximum_size=4718592 +um_squixl.menu.PartitionScheme.app3M_fat9M_16MB=FFAT (3MB APP/9MB FATFS) +um_squixl.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +um_squixl.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +um_squixl.menu.PartitionScheme.fatflash=Large FFAT (2MB APP/12.5MB FATFS) +um_squixl.menu.PartitionScheme.fatflash.build.partitions=ffat +um_squixl.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 + +um_squixl.menu.CPUFreq.240=240MHz (WiFi) +um_squixl.menu.CPUFreq.240.build.f_cpu=240000000L +um_squixl.menu.CPUFreq.160=160MHz (WiFi) +um_squixl.menu.CPUFreq.160.build.f_cpu=160000000L +um_squixl.menu.CPUFreq.80=80MHz (WiFi) +um_squixl.menu.CPUFreq.80.build.f_cpu=80000000L +um_squixl.menu.CPUFreq.40=40MHz +um_squixl.menu.CPUFreq.40.build.f_cpu=40000000L +um_squixl.menu.CPUFreq.20=20MHz +um_squixl.menu.CPUFreq.20.build.f_cpu=20000000L +um_squixl.menu.CPUFreq.10=10MHz +um_squixl.menu.CPUFreq.10.build.f_cpu=10000000L + +um_squixl.menu.FlashMode.qio=QIO +um_squixl.menu.FlashMode.qio.build.flash_mode=dio +um_squixl.menu.FlashMode.qio.build.boot=qio +um_squixl.menu.FlashMode.dio=DIO +um_squixl.menu.FlashMode.dio.build.flash_mode=dio +um_squixl.menu.FlashMode.dio.build.boot=dio + +um_squixl.menu.UploadSpeed.921600=921600 +um_squixl.menu.UploadSpeed.921600.upload.speed=921600 +um_squixl.menu.UploadSpeed.115200=115200 +um_squixl.menu.UploadSpeed.115200.upload.speed=115200 +um_squixl.menu.UploadSpeed.256000.windows=256000 +um_squixl.menu.UploadSpeed.256000.upload.speed=256000 +um_squixl.menu.UploadSpeed.230400.windows.upload.speed=256000 +um_squixl.menu.UploadSpeed.230400=230400 +um_squixl.menu.UploadSpeed.230400.upload.speed=230400 +um_squixl.menu.UploadSpeed.460800.linux=460800 +um_squixl.menu.UploadSpeed.460800.macosx=460800 +um_squixl.menu.UploadSpeed.460800.upload.speed=460800 +um_squixl.menu.UploadSpeed.512000.windows=512000 +um_squixl.menu.UploadSpeed.512000.upload.speed=512000 + +um_squixl.menu.DebugLevel.none=None +um_squixl.menu.DebugLevel.none.build.code_debug=0 +um_squixl.menu.DebugLevel.error=Error +um_squixl.menu.DebugLevel.error.build.code_debug=1 +um_squixl.menu.DebugLevel.warn=Warn +um_squixl.menu.DebugLevel.warn.build.code_debug=2 +um_squixl.menu.DebugLevel.info=Info +um_squixl.menu.DebugLevel.info.build.code_debug=3 +um_squixl.menu.DebugLevel.debug=Debug +um_squixl.menu.DebugLevel.debug.build.code_debug=4 +um_squixl.menu.DebugLevel.verbose=Verbose +um_squixl.menu.DebugLevel.verbose.build.code_debug=5 + +um_squixl.menu.EraseFlash.none=Disabled +um_squixl.menu.EraseFlash.none.upload.erase_cmd= +um_squixl.menu.EraseFlash.all=Enabled +um_squixl.menu.EraseFlash.all.upload.erase_cmd=-e + +############################################################## + um_tinypico.name=UM TinyPICO um_tinypico.bootloader.tool=esptool_py @@ -4896,7 +5213,7 @@ um_tinyc6.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_o um_tinyc6.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 um_tinyc6.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB um_tinyc6.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -um_tinyc6.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +um_tinyc6.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 um_tinyc6.menu.PartitionScheme.zigbee=Zigbee 4MB with spiffs um_tinyc6.menu.PartitionScheme.zigbee.build.partitions=zigbee um_tinyc6.menu.PartitionScheme.zigbee.upload.maximum_size=1310720 @@ -5590,7 +5907,7 @@ lilygo_t_display_s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmake lilygo_t_display_s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 lilygo_t_display_s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB lilygo_t_display_s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -lilygo_t_display_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +lilygo_t_display_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 lilygo_t_display_s3.menu.DebugLevel.none=None lilygo_t_display_s3.menu.DebugLevel.none.build.code_debug=0 @@ -5712,7 +6029,7 @@ lilygo_t_eth_lite.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_ lilygo_t_eth_lite.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 lilygo_t_eth_lite.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB lilygo_t_eth_lite.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -lilygo_t_eth_lite.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +lilygo_t_eth_lite.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 lilygo_t_eth_lite.menu.DebugLevel.none=None lilygo_t_eth_lite.menu.DebugLevel.none.build.code_debug=0 @@ -6007,12 +6324,12 @@ twatchs3.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) twatchs3.menu.UploadMode.cdc.upload.use_1200bps_touch=true twatchs3.menu.UploadMode.cdc.upload.wait_for_upload_port=true -twatchs3.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) -twatchs3.menu.PartitionScheme.fatflash.build.partitions=ffat -twatchs3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 twatchs3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9.9MB FATFS) twatchs3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB twatchs3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +twatchs3.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) +twatchs3.menu.PartitionScheme.fatflash.build.partitions=ffat +twatchs3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 twatchs3.menu.PartitionScheme.rainmaker=RainMaker twatchs3.menu.PartitionScheme.rainmaker.build.partitions=rainmaker twatchs3.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 @@ -6076,6 +6393,10 @@ twatchs3.menu.Revision.Radio_SX1280=Radio-SX1280 twatchs3.menu.Revision.Radio_SX1280.build.board=LILYGO_LORA_SX1280 twatchs3.menu.Revision.Radio_CC1101=Radio-CC1101 twatchs3.menu.Revision.Radio_CC1101.build.board=LILYGO_LORA_CC1101 +twatchs3.menu.Revision.Radio_LR1121=Radio-LR1121 +twatchs3.menu.Revision.Radio_LR1121.build.board=LILYGO_LORA_LR1121 +twatchs3.menu.Revision.Radio_SI4432=Radio-SI4432 +twatchs3.menu.Revision.Radio_SI4432.build.board=LILYGO_LORA_SI4432 ############################################################## @@ -6231,13 +6552,16 @@ twatch_ultra.menu.EraseFlash.none.upload.erase_cmd= twatch_ultra.menu.EraseFlash.all=Enabled twatch_ultra.menu.EraseFlash.all.upload.erase_cmd=-e -twatch_ultra.menu.Revision.Radio_SX1280=Radio-SX1280 -twatch_ultra.menu.Revision.Radio_SX1280.build.board=LILYGO_LORA_SX1280 twatch_ultra.menu.Revision.Radio_SX1262=Radio-SX1262 twatch_ultra.menu.Revision.Radio_SX1262.build.board=LILYGO_LORA_SX1262 +twatch_ultra.menu.Revision.Radio_SX1280=Radio-SX1280 +twatch_ultra.menu.Revision.Radio_SX1280.build.board=LILYGO_LORA_SX1280 twatch_ultra.menu.Revision.Radio_CC1101=Radio-CC1101 twatch_ultra.menu.Revision.Radio_CC1101.build.board=LILYGO_LORA_CC1101 - +twatch_ultra.menu.Revision.Radio_LR1121=Radio-LR1121 +twatch_ultra.menu.Revision.Radio_LR1121.build.board=LILYGO_LORA_LR1121 +twatch_ultra.menu.Revision.Radio_SI4432=Radio-SI4432 +twatch_ultra.menu.Revision.Radio_SI4432.build.board=LILYGO_LORA_SI4432 ############################################################## @@ -6393,12 +6717,16 @@ tlora_pager.menu.EraseFlash.all=Enabled tlora_pager.menu.EraseFlash.all.upload.erase_cmd=-e -tlora_pager.menu.Revision.Radio_SX1280=Radio-SX1280 -tlora_pager.menu.Revision.Radio_SX1280.build.board=LILYGO_LORA_SX1280 tlora_pager.menu.Revision.Radio_SX1262=Radio-SX1262 tlora_pager.menu.Revision.Radio_SX1262.build.board=LILYGO_LORA_SX1262 +tlora_pager.menu.Revision.Radio_SX1280=Radio-SX1280 +tlora_pager.menu.Revision.Radio_SX1280.build.board=LILYGO_LORA_SX1280 tlora_pager.menu.Revision.Radio_CC1101=Radio-CC1101 tlora_pager.menu.Revision.Radio_CC1101.build.board=LILYGO_LORA_CC1101 +tlora_pager.menu.Revision.Radio_LR1121=Radio-LR1121 +tlora_pager.menu.Revision.Radio_LR1121.build.board=LILYGO_LORA_LR1121 +tlora_pager.menu.Revision.Radio_SI4432=Radio-SI4432 +tlora_pager.menu.Revision.Radio_SI4432.build.board=LILYGO_LORA_SI4432 ############################################################## @@ -8057,7 +8385,7 @@ sparkfun_esp32c6_thing_plus.menu.PartitionScheme.rainmaker_4MB.build.partitions= sparkfun_esp32c6_thing_plus.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 sparkfun_esp32c6_thing_plus.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB sparkfun_esp32c6_thing_plus.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -sparkfun_esp32c6_thing_plus.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +sparkfun_esp32c6_thing_plus.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 sparkfun_esp32c6_thing_plus.menu.PartitionScheme.zigbee=Zigbee 4MB with spiffs sparkfun_esp32c6_thing_plus.menu.PartitionScheme.zigbee.build.partitions=zigbee sparkfun_esp32c6_thing_plus.menu.PartitionScheme.zigbee.upload.maximum_size=1310720 @@ -8467,7 +8795,7 @@ sparkfun_esp32_iot_redboard.menu.PartitionScheme.rainmaker_4MB.build.partitions= sparkfun_esp32_iot_redboard.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 sparkfun_esp32_iot_redboard.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB sparkfun_esp32_iot_redboard.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -sparkfun_esp32_iot_redboard.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +sparkfun_esp32_iot_redboard.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 sparkfun_esp32_iot_redboard.menu.CPUFreq.240=240MHz (WiFi/BT) sparkfun_esp32_iot_redboard.menu.CPUFreq.240.build.f_cpu=240000000L @@ -8647,7 +8975,7 @@ sparkfun_esp32c6_qwiic_pocket.menu.PartitionScheme.rainmaker_4MB.build.partition sparkfun_esp32c6_qwiic_pocket.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 sparkfun_esp32c6_qwiic_pocket.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB sparkfun_esp32c6_qwiic_pocket.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -sparkfun_esp32c6_qwiic_pocket.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +sparkfun_esp32c6_qwiic_pocket.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 sparkfun_esp32c6_qwiic_pocket.menu.PartitionScheme.zigbee=Zigbee 4MB with spiffs sparkfun_esp32c6_qwiic_pocket.menu.PartitionScheme.zigbee.build.partitions=zigbee sparkfun_esp32c6_qwiic_pocket.menu.PartitionScheme.zigbee.upload.maximum_size=1310720 @@ -8981,7 +9309,7 @@ nina_w10.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ot nina_w10.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 nina_w10.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB nina_w10.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -nina_w10.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +nina_w10.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 nina_w10.menu.CPUFreq.240=240MHz (WiFi/BT) nina_w10.menu.CPUFreq.240.build.f_cpu=240000000L @@ -9192,7 +9520,7 @@ nora_w10.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ot nora_w10.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 nora_w10.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB nora_w10.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -nora_w10.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +nora_w10.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 nora_w10.menu.CPUFreq.240=240MHz (WiFi) nora_w10.menu.CPUFreq.240.build.f_cpu=240000000L @@ -10164,7 +10492,7 @@ lolin_s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ot lolin_s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 lolin_s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB lolin_s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -lolin_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +lolin_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 lolin_s3.menu.CPUFreq.240=240MHz (WiFi) lolin_s3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -10664,7 +10992,7 @@ lolin_s3_pro.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_n lolin_s3_pro.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 lolin_s3_pro.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB lolin_s3_pro.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -lolin_s3_pro.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +lolin_s3_pro.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 lolin_s3_pro.menu.CPUFreq.240=240MHz (WiFi) lolin_s3_pro.menu.CPUFreq.240.build.f_cpu=240000000L @@ -12044,7 +12372,7 @@ dfrobot_firebeetle2_esp32e.menu.PartitionScheme.rainmaker_4MB.build.partitions=r dfrobot_firebeetle2_esp32e.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 dfrobot_firebeetle2_esp32e.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB dfrobot_firebeetle2_esp32e.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -dfrobot_firebeetle2_esp32e.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +dfrobot_firebeetle2_esp32e.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 dfrobot_firebeetle2_esp32e.menu.CPUFreq.240=240MHz (WiFi/BT) dfrobot_firebeetle2_esp32e.menu.CPUFreq.240.build.f_cpu=240000000L @@ -12297,7 +12625,7 @@ dfrobot_firebeetle2_esp32s3.menu.PartitionScheme.rainmaker_4MB.build.partitions= dfrobot_firebeetle2_esp32s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 dfrobot_firebeetle2_esp32s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB dfrobot_firebeetle2_esp32s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -dfrobot_firebeetle2_esp32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +dfrobot_firebeetle2_esp32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 dfrobot_firebeetle2_esp32s3.menu.CPUFreq.240=240MHz (WiFi) dfrobot_firebeetle2_esp32s3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -12658,7 +12986,7 @@ dfrobot_romeo_esp32s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainma dfrobot_romeo_esp32s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 dfrobot_romeo_esp32s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB dfrobot_romeo_esp32s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -dfrobot_romeo_esp32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +dfrobot_romeo_esp32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 dfrobot_romeo_esp32s3.menu.CPUFreq.240=240MHz (WiFi) dfrobot_romeo_esp32s3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -12706,6 +13034,212 @@ dfrobot_romeo_esp32s3.menu.EraseFlash.none.upload.erase_cmd= dfrobot_romeo_esp32s3.menu.EraseFlash.all=Enabled dfrobot_romeo_esp32s3.menu.EraseFlash.all.upload.erase_cmd=-e +############################################################## +dfrobot_lorawan_esp32s3.name=DFRobot LoRaWAN ESP32-S3 +#dfrobot_lorawan_esp32s3.vid.0=0x303a +#dfrobot_lorawan_esp32s3.pid.0=0x1001 + +dfrobot_lorawan_esp32s3.bootloader.tool=esptool_py +dfrobot_lorawan_esp32s3.bootloader.tool.default=esptool_py + +dfrobot_lorawan_esp32s3.upload.tool=esptool_py +dfrobot_lorawan_esp32s3.upload.tool.default=esptool_py +dfrobot_lorawan_esp32s3.upload.tool.network=esp_ota + +dfrobot_lorawan_esp32s3.upload.speed=921600 +dfrobot_lorawan_esp32s3.upload.erase_cmd= +dfrobot_lorawan_esp32s3.upload.maximum_size=1310720 +dfrobot_lorawan_esp32s3.upload.maximum_data_size=327680 +dfrobot_lorawan_esp32s3.upload.flags= +dfrobot_lorawan_esp32s3.upload.extra_flags= +dfrobot_lorawan_esp32s3.upload.use_1200bps_touch=false +dfrobot_lorawan_esp32s3.upload.wait_for_upload_port=false + +dfrobot_lorawan_esp32s3.serial.disableDTR=false +dfrobot_lorawan_esp32s3.serial.disableRTS=false + +dfrobot_lorawan_esp32s3.build.tarch=xtensa +dfrobot_lorawan_esp32s3.build.bootloader_addr=0x0 +dfrobot_lorawan_esp32s3.build.target=esp32s3 +dfrobot_lorawan_esp32s3.build.mcu=esp32s3 +dfrobot_lorawan_esp32s3.build.core=esp32 +dfrobot_lorawan_esp32s3.build.variant=dfrobot_lorawan_esp32s3 +dfrobot_lorawan_esp32s3.build.board=DFROBOT_LORAWAN_ESP32S3 +dfrobot_lorawan_esp32s3.build.usb_mode=1 +dfrobot_lorawan_esp32s3.build.cdc_on_boot=1 +dfrobot_lorawan_esp32s3.build.msc_on_boot=0 +dfrobot_lorawan_esp32s3.build.dfu_on_boot=0 +dfrobot_lorawan_esp32s3.build.f_cpu=240000000L +dfrobot_lorawan_esp32s3.build.flash_size=4MB +dfrobot_lorawan_esp32s3.build.flash_freq=80m +dfrobot_lorawan_esp32s3.build.flash_mode=dio +dfrobot_lorawan_esp32s3.build.boot=qio +dfrobot_lorawan_esp32s3.build.boot_freq=80m +dfrobot_lorawan_esp32s3.build.partitions=default +dfrobot_lorawan_esp32s3.build.defines=-D{build.band} +dfrobot_lorawan_esp32s3.build.loop_core= +dfrobot_lorawan_esp32s3.build.event_core= +dfrobot_lorawan_esp32s3.build.psram_type=qspi +dfrobot_lorawan_esp32s3.build.memory_type={build.flash_type}_{build.psram_type} +dfrobot_lorawan_esp32s3.build.region= + +dfrobot_lorawan_esp32s3.menu.FlashMode.qio=QIO 80MHz +dfrobot_lorawan_esp32s3.menu.FlashMode.qio.build.flash_mode=dio +dfrobot_lorawan_esp32s3.menu.FlashMode.qio.build.boot=qio +dfrobot_lorawan_esp32s3.menu.FlashMode.qio.build.boot_freq=80m +dfrobot_lorawan_esp32s3.menu.FlashMode.qio.build.flash_freq=80m +dfrobot_lorawan_esp32s3.menu.FlashMode.qio.build.flash_type=qio +dfrobot_lorawan_esp32s3.menu.FlashMode.qio120=QIO 120MHz +dfrobot_lorawan_esp32s3.menu.FlashMode.qio120.build.flash_mode=dio +dfrobot_lorawan_esp32s3.menu.FlashMode.qio120.build.boot=qio +dfrobot_lorawan_esp32s3.menu.FlashMode.qio120.build.boot_freq=120m +dfrobot_lorawan_esp32s3.menu.FlashMode.qio120.build.flash_freq=80m +dfrobot_lorawan_esp32s3.menu.FlashMode.qio120.build.flash_type=qio +dfrobot_lorawan_esp32s3.menu.FlashMode.dio=DIO 80MHz +dfrobot_lorawan_esp32s3.menu.FlashMode.dio.build.flash_mode=dio +dfrobot_lorawan_esp32s3.menu.FlashMode.dio.build.boot=dio +dfrobot_lorawan_esp32s3.menu.FlashMode.dio.build.boot_freq=80m +dfrobot_lorawan_esp32s3.menu.FlashMode.dio.build.flash_freq=80m +dfrobot_lorawan_esp32s3.menu.FlashMode.dio.build.flash_type=qio + +dfrobot_lorawan_esp32s3.menu.FlashSize.4M=4MB (32Mb) +dfrobot_lorawan_esp32s3.menu.FlashSize.4M.build.flash_size=4MB + +dfrobot_lorawan_esp32s3.menu.LoopCore.1=Core 1 +dfrobot_lorawan_esp32s3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +dfrobot_lorawan_esp32s3.menu.LoopCore.0=Core 0 +dfrobot_lorawan_esp32s3.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +dfrobot_lorawan_esp32s3.menu.EventsCore.1=Core 1 +dfrobot_lorawan_esp32s3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +dfrobot_lorawan_esp32s3.menu.EventsCore.0=Core 0 +dfrobot_lorawan_esp32s3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 +dfrobot_lorawan_esp32s3.menu.USBMode.hwcdc=Hardware CDC and JTAG +dfrobot_lorawan_esp32s3.menu.USBMode.hwcdc.build.usb_mode=1 +dfrobot_lorawan_esp32s3.menu.USBMode.default=USB-OTG (TinyUSB) +dfrobot_lorawan_esp32s3.menu.USBMode.default.build.usb_mode=0 + +dfrobot_lorawan_esp32s3.menu.CDCOnBoot.default=Disabled +dfrobot_lorawan_esp32s3.menu.CDCOnBoot.default.build.cdc_on_boot=0 +dfrobot_lorawan_esp32s3.menu.CDCOnBoot.cdc=Enabled +dfrobot_lorawan_esp32s3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 + +dfrobot_lorawan_esp32s3.menu.MSCOnBoot.default=Disabled +dfrobot_lorawan_esp32s3.menu.MSCOnBoot.default.build.msc_on_boot=0 +dfrobot_lorawan_esp32s3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +dfrobot_lorawan_esp32s3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +dfrobot_lorawan_esp32s3.menu.DFUOnBoot.default=Disabled +dfrobot_lorawan_esp32s3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +dfrobot_lorawan_esp32s3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +dfrobot_lorawan_esp32s3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +dfrobot_lorawan_esp32s3.menu.UploadMode.default=UART0 / Hardware CDC +dfrobot_lorawan_esp32s3.menu.UploadMode.default.upload.use_1200bps_touch=false +dfrobot_lorawan_esp32s3.menu.UploadMode.default.upload.wait_for_upload_port=false +dfrobot_lorawan_esp32s3.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +dfrobot_lorawan_esp32s3.menu.UploadMode.cdc.upload.use_1200bps_touch=true +dfrobot_lorawan_esp32s3.menu.UploadMode.cdc.upload.wait_for_upload_port=true + +dfrobot_lorawan_esp32s3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +dfrobot_lorawan_esp32s3.menu.PartitionScheme.default.build.partitions=default +dfrobot_lorawan_esp32s3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +dfrobot_lorawan_esp32s3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +dfrobot_lorawan_esp32s3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +dfrobot_lorawan_esp32s3.menu.PartitionScheme.minimal.build.partitions=minimal +dfrobot_lorawan_esp32s3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +dfrobot_lorawan_esp32s3.menu.PartitionScheme.no_ota.build.partitions=no_ota +dfrobot_lorawan_esp32s3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +dfrobot_lorawan_esp32s3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +dfrobot_lorawan_esp32s3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +dfrobot_lorawan_esp32s3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +dfrobot_lorawan_esp32s3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +dfrobot_lorawan_esp32s3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +dfrobot_lorawan_esp32s3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +dfrobot_lorawan_esp32s3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +dfrobot_lorawan_esp32s3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +dfrobot_lorawan_esp32s3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +dfrobot_lorawan_esp32s3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +dfrobot_lorawan_esp32s3.menu.PartitionScheme.huge_app.build.partitions=huge_app +dfrobot_lorawan_esp32s3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +dfrobot_lorawan_esp32s3.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +dfrobot_lorawan_esp32s3.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +dfrobot_lorawan_esp32s3.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +dfrobot_lorawan_esp32s3.menu.PartitionScheme.rainmaker=RainMaker 4MB +dfrobot_lorawan_esp32s3.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +dfrobot_lorawan_esp32s3.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 +dfrobot_lorawan_esp32s3.menu.PartitionScheme.rainmaker_4MB=RainMaker 4MB No OTA +dfrobot_lorawan_esp32s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ota +dfrobot_lorawan_esp32s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 + + +dfrobot_lorawan_esp32s3.menu.CPUFreq.240=240MHz (WiFi) +dfrobot_lorawan_esp32s3.menu.CPUFreq.240.build.f_cpu=240000000L +dfrobot_lorawan_esp32s3.menu.CPUFreq.160=160MHz (WiFi) +dfrobot_lorawan_esp32s3.menu.CPUFreq.160.build.f_cpu=160000000L +dfrobot_lorawan_esp32s3.menu.CPUFreq.80=80MHz (WiFi) +dfrobot_lorawan_esp32s3.menu.CPUFreq.80.build.f_cpu=80000000L +dfrobot_lorawan_esp32s3.menu.CPUFreq.40=40MHz +dfrobot_lorawan_esp32s3.menu.CPUFreq.40.build.f_cpu=40000000L +dfrobot_lorawan_esp32s3.menu.CPUFreq.20=20MHz +dfrobot_lorawan_esp32s3.menu.CPUFreq.20.build.f_cpu=20000000L +dfrobot_lorawan_esp32s3.menu.CPUFreq.10=10MHz +dfrobot_lorawan_esp32s3.menu.CPUFreq.10.build.f_cpu=10000000L + +dfrobot_lorawan_esp32s3.menu.UploadSpeed.921600=921600 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.921600.upload.speed=921600 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.115200=115200 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.115200.upload.speed=115200 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.256000.windows=256000 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.256000.upload.speed=256000 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.230400.windows.upload.speed=256000 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.230400=230400 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.230400.upload.speed=230400 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.460800.linux=460800 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.460800.macosx=460800 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.460800.upload.speed=460800 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.512000.windows=512000 +dfrobot_lorawan_esp32s3.menu.UploadSpeed.512000.upload.speed=512000 + +dfrobot_lorawan_esp32s3.menu.DebugLevel.none=None +dfrobot_lorawan_esp32s3.menu.DebugLevel.none.build.code_debug=0 +dfrobot_lorawan_esp32s3.menu.DebugLevel.error=Error +dfrobot_lorawan_esp32s3.menu.DebugLevel.error.build.code_debug=1 +dfrobot_lorawan_esp32s3.menu.DebugLevel.warn=Warn +dfrobot_lorawan_esp32s3.menu.DebugLevel.warn.build.code_debug=2 +dfrobot_lorawan_esp32s3.menu.DebugLevel.info=Info +dfrobot_lorawan_esp32s3.menu.DebugLevel.info.build.code_debug=3 +dfrobot_lorawan_esp32s3.menu.DebugLevel.debug=Debug +dfrobot_lorawan_esp32s3.menu.DebugLevel.debug.build.code_debug=4 +dfrobot_lorawan_esp32s3.menu.DebugLevel.verbose=Verbose +dfrobot_lorawan_esp32s3.menu.DebugLevel.verbose.build.code_debug=5 + +dfrobot_lorawan_esp32s3.menu.EraseFlash.none=Disabled +dfrobot_lorawan_esp32s3.menu.EraseFlash.none.upload.erase_cmd= +dfrobot_lorawan_esp32s3.menu.EraseFlash.all=Enabled +dfrobot_lorawan_esp32s3.menu.EraseFlash.all.upload.erase_cmd=-e + +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.0=REGION_EU868 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.0.build.band=REGION_EU868 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.1=REGION_EU433 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.1.build.band=REGION_EU433 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.2=REGION_CN470 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.2.build.band=REGION_CN470 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.3=REGION_US915 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.3.build.band=REGION_US915 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.4=REGION_AU915 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.4.build.band=REGION_AU915 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.5=REGION_CN779 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.5.build.band=REGION_CN779 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.6=REGION_AS923 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.6.build.band=REGION_AS923 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.7=REGION_KR920 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.7.build.band=REGION_KR920 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.8=REGION_IN865 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.8.build.band=REGION_IN865 +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.9=REGION_US915_HYBRID +dfrobot_lorawan_esp32s3.menu.LORAWAN_REGION.9.build.band=REGION_US915_HYBRID + ############################################################## firebeetle32.name=FireBeetle-ESP32 @@ -17342,6 +17876,140 @@ sparklemotionmini.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator/router) sparklemotionmini.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR sparklemotionmini.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api.zczr -lzboss_stack.zczr -lzboss_port.remote +############################################################## +# Adafruit Sparkle Motion Stick w/ESP32 + +sparklemotionstick.name=Adafruit Sparkle Motion Stick (ESP32) + +sparklemotionstick.bootloader.tool=esptool_py +sparklemotionstick.bootloader.tool.default=esptool_py + +sparklemotionstick.upload.tool=esptool_py +sparklemotionstick.upload.tool.default=esptool_py +sparklemotionstick.upload.tool.network=esp_ota + +sparklemotionstick.upload.maximum_size=1310720 +sparklemotionstick.upload.maximum_data_size=327680 +sparklemotionstick.upload.flags= +sparklemotionstick.upload.extra_flags= + +sparklemotionstick.serial.disableDTR=true +sparklemotionstick.serial.disableRTS=true + +sparklemotionstick.build.tarch=xtensa +sparklemotionstick.build.bootloader_addr=0x1000 +sparklemotionstick.build.target=esp32 +sparklemotionstick.build.mcu=esp32 +sparklemotionstick.build.core=esp32 +sparklemotionstick.build.variant=adafruit_sparklemotionstick_esp32 +sparklemotionstick.build.board=SPARKLEMOTIONSTICK_ESP32 + +sparklemotionstick.build.f_cpu=240000000L +sparklemotionstick.build.flash_size=4MB +sparklemotionstick.build.flash_freq=80m +sparklemotionstick.build.flash_mode=dio +sparklemotionstick.build.boot=dio +sparklemotionstick.build.partitions=default +sparklemotionstick.build.defines= +sparklemotionstick.build.loop_core= +sparklemotionstick.build.event_core= + +sparklemotionstick.menu.LoopCore.1=Core 1 +sparklemotionstick.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +sparklemotionstick.menu.LoopCore.0=Core 0 +sparklemotionstick.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +sparklemotionstick.menu.EventsCore.1=Core 1 +sparklemotionstick.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +sparklemotionstick.menu.EventsCore.0=Core 0 +sparklemotionstick.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +sparklemotionstick.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +sparklemotionstick.menu.PartitionScheme.default.build.partitions=default +sparklemotionstick.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +sparklemotionstick.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +sparklemotionstick.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +sparklemotionstick.menu.PartitionScheme.minimal.build.partitions=minimal +sparklemotionstick.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +sparklemotionstick.menu.PartitionScheme.no_ota.build.partitions=no_ota +sparklemotionstick.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +sparklemotionstick.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +sparklemotionstick.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +sparklemotionstick.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +sparklemotionstick.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +sparklemotionstick.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +sparklemotionstick.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +sparklemotionstick.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +sparklemotionstick.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +sparklemotionstick.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +sparklemotionstick.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +sparklemotionstick.menu.PartitionScheme.huge_app.build.partitions=huge_app +sparklemotionstick.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +sparklemotionstick.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +sparklemotionstick.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +sparklemotionstick.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 + +sparklemotionstick.menu.CPUFreq.240=240MHz (WiFi/BT) +sparklemotionstick.menu.CPUFreq.240.build.f_cpu=240000000L +sparklemotionstick.menu.CPUFreq.160=160MHz (WiFi/BT) +sparklemotionstick.menu.CPUFreq.160.build.f_cpu=160000000L +sparklemotionstick.menu.CPUFreq.80=80MHz (WiFi/BT) +sparklemotionstick.menu.CPUFreq.80.build.f_cpu=80000000L +sparklemotionstick.menu.CPUFreq.40=40MHz +sparklemotionstick.menu.CPUFreq.40.build.f_cpu=40000000L +sparklemotionstick.menu.CPUFreq.20=20MHz +sparklemotionstick.menu.CPUFreq.20.build.f_cpu=20000000L +sparklemotionstick.menu.CPUFreq.10=10MHz +sparklemotionstick.menu.CPUFreq.10.build.f_cpu=10000000L + +sparklemotionstick.menu.FlashFreq.80=80MHz +sparklemotionstick.menu.FlashFreq.80.build.flash_freq=80m +sparklemotionstick.menu.FlashFreq.40=40MHz +sparklemotionstick.menu.FlashFreq.40.build.flash_freq=40m + +sparklemotionstick.menu.FlashSize.4M=4MB (32Mb) +sparklemotionstick.menu.FlashSize.4M.build.flash_size=4MB + +sparklemotionstick.menu.UploadSpeed.921600=921600 +sparklemotionstick.menu.UploadSpeed.921600.upload.speed=921600 +sparklemotionstick.menu.UploadSpeed.115200=115200 +sparklemotionstick.menu.UploadSpeed.115200.upload.speed=115200 +sparklemotionstick.menu.UploadSpeed.256000.windows=256000 +sparklemotionstick.menu.UploadSpeed.256000.upload.speed=256000 +sparklemotionstick.menu.UploadSpeed.230400.windows.upload.speed=256000 +sparklemotionstick.menu.UploadSpeed.230400=230400 +sparklemotionstick.menu.UploadSpeed.230400.upload.speed=230400 +sparklemotionstick.menu.UploadSpeed.460800.linux=460800 +sparklemotionstick.menu.UploadSpeed.460800.macosx=460800 +sparklemotionstick.menu.UploadSpeed.460800.upload.speed=460800 +sparklemotionstick.menu.UploadSpeed.512000.windows=512000 +sparklemotionstick.menu.UploadSpeed.512000.upload.speed=512000 + +sparklemotionstick.menu.DebugLevel.none=None +sparklemotionstick.menu.DebugLevel.none.build.code_debug=0 +sparklemotionstick.menu.DebugLevel.error=Error +sparklemotionstick.menu.DebugLevel.error.build.code_debug=1 +sparklemotionstick.menu.DebugLevel.warn=Warn +sparklemotionstick.menu.DebugLevel.warn.build.code_debug=2 +sparklemotionstick.menu.DebugLevel.info=Info +sparklemotionstick.menu.DebugLevel.info.build.code_debug=3 +sparklemotionstick.menu.DebugLevel.debug=Debug +sparklemotionstick.menu.DebugLevel.debug.build.code_debug=4 +sparklemotionstick.menu.DebugLevel.verbose=Verbose +sparklemotionstick.menu.DebugLevel.verbose.build.code_debug=5 + +sparklemotionstick.menu.EraseFlash.none=Disabled +sparklemotionstick.menu.EraseFlash.none.upload.erase_cmd= +sparklemotionstick.menu.EraseFlash.all=Enabled +sparklemotionstick.menu.EraseFlash.all.upload.erase_cmd=-e + +sparklemotionstick.menu.ZigbeeMode.default=Disabled +sparklemotionstick.menu.ZigbeeMode.default.build.zigbee_mode= +sparklemotionstick.menu.ZigbeeMode.default.build.zigbee_libs= +sparklemotionstick.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator/router) +sparklemotionstick.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR +sparklemotionstick.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api.zczr -lzboss_stack.zczr -lzboss_port.remote + ############################################################## nodemcu-32s.name=NodeMCU-32S @@ -17725,7 +18393,7 @@ nologo_esp32s3_pico.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmake nologo_esp32s3_pico.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 nologo_esp32s3_pico.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB nologo_esp32s3_pico.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -nologo_esp32s3_pico.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +nologo_esp32s3_pico.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 nologo_esp32s3_pico.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) nologo_esp32s3_pico.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB nologo_esp32s3_pico.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -18444,7 +19112,7 @@ esp32-poe.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_o esp32-poe.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32-poe.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32-poe.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32-poe.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32-poe.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32-poe.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs esp32-poe.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr esp32-poe.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720 @@ -18587,7 +19255,7 @@ esp32-poe-iso.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_ esp32-poe-iso.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32-poe-iso.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32-poe-iso.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32-poe-iso.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32-poe-iso.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32-poe-iso.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs esp32-poe-iso.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr esp32-poe-iso.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720 @@ -18865,7 +19533,7 @@ esp32s2-devkitlipo.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker esp32s2-devkitlipo.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32s2-devkitlipo.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32s2-devkitlipo.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32s2-devkitlipo.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32s2-devkitlipo.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32s2-devkitlipo.menu.PartitionScheme.custom=Custom esp32s2-devkitlipo.menu.PartitionScheme.custom.build.partitions= esp32s2-devkitlipo.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -19060,7 +19728,7 @@ esp32s2-devkitlipo-usb.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainm esp32s2-devkitlipo-usb.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32s2-devkitlipo-usb.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32s2-devkitlipo-usb.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32s2-devkitlipo-usb.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32s2-devkitlipo-usb.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32s2-devkitlipo-usb.menu.PartitionScheme.custom=Custom esp32s2-devkitlipo-usb.menu.PartitionScheme.custom.build.partitions= esp32s2-devkitlipo-usb.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -19315,7 +19983,7 @@ esp32s3-devkitlipo.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker esp32s3-devkitlipo.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32s3-devkitlipo.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32s3-devkitlipo.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32s3-devkitlipo.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32s3-devkitlipo.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32s3-devkitlipo.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) esp32s3-devkitlipo.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB esp32s3-devkitlipo.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -19473,7 +20141,7 @@ esp32c3-devkitlipo.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker esp32c3-devkitlipo.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32c3-devkitlipo.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32c3-devkitlipo.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32c3-devkitlipo.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32c3-devkitlipo.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32c3-devkitlipo.menu.PartitionScheme.custom=Custom esp32c3-devkitlipo.menu.PartitionScheme.custom.build.partitions= esp32c3-devkitlipo.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -19646,7 +20314,7 @@ esp32c6-evb.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no esp32c6-evb.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32c6-evb.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32c6-evb.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32c6-evb.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32c6-evb.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32c6-evb.menu.PartitionScheme.zigbee=Zigbee 4MB with spiffs esp32c6-evb.menu.PartitionScheme.zigbee.build.partitions=zigbee esp32c6-evb.menu.PartitionScheme.zigbee.upload.maximum_size=1310720 @@ -19829,7 +20497,7 @@ esp32h2-devkitlipo.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=314 #esp32h2-devkitlipo.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 #esp32h2-devkitlipo.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB #esp32h2-devkitlipo.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -#esp32h2-devkitlipo.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +#esp32h2-devkitlipo.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32h2-devkitlipo.menu.PartitionScheme.zigbee=Zigbee 4MB with spiffs esp32h2-devkitlipo.menu.PartitionScheme.zigbee.build.partitions=zigbee esp32h2-devkitlipo.menu.PartitionScheme.zigbee.upload.maximum_size=1310720 @@ -20004,7 +20672,7 @@ esp32-sbc-fabgl.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4M esp32-sbc-fabgl.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 esp32-sbc-fabgl.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB esp32-sbc-fabgl.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -esp32-sbc-fabgl.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +esp32-sbc-fabgl.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 esp32-sbc-fabgl.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs esp32-sbc-fabgl.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr esp32-sbc-fabgl.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720 @@ -20247,7 +20915,7 @@ m5stack_core.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_n m5stack_core.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_core.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_core.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_core.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_core.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_core.menu.PartitionScheme.custom=Custom m5stack_core.menu.PartitionScheme.custom.build.partitions= m5stack_core.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -20423,7 +21091,7 @@ m5stack_fire.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_n m5stack_fire.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_fire.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_fire.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_fire.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_fire.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_fire.menu.PartitionScheme.custom=Custom m5stack_fire.menu.PartitionScheme.custom.build.partitions= m5stack_fire.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -20597,7 +21265,7 @@ m5stack_core2.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_ m5stack_core2.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_core2.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_core2.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_core2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_core2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_core2.menu.PartitionScheme.custom=Custom m5stack_core2.menu.PartitionScheme.custom.build.partitions= m5stack_core2.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -20771,7 +21439,7 @@ m5stack_tough.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_ m5stack_tough.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_tough.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_tough.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_tough.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_tough.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_tough.menu.PartitionScheme.custom=Custom m5stack_tough.menu.PartitionScheme.custom.build.partitions= m5stack_tough.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -20938,7 +21606,7 @@ m5stack_station.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4M m5stack_station.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_station.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_station.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_station.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_station.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_station.menu.PartitionScheme.custom=Custom m5stack_station.menu.PartitionScheme.custom.build.partitions= m5stack_station.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -21417,7 +22085,7 @@ m5stack_stickc_plus2.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmak m5stack_stickc_plus2.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_stickc_plus2.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_stickc_plus2.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_stickc_plus2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_stickc_plus2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_stickc_plus2.menu.PartitionScheme.custom=Custom m5stack_stickc_plus2.menu.PartitionScheme.custom.build.partitions= m5stack_stickc_plus2.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -21824,7 +22492,7 @@ m5stack_atoms3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB m5stack_atoms3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_atoms3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_atoms3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_atoms3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_atoms3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_atoms3.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) m5stack_atoms3.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB m5stack_atoms3.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -22057,7 +22725,7 @@ m5stack_cores3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB m5stack_cores3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_cores3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_cores3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_cores3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_cores3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_cores3.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) m5stack_cores3.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB m5stack_cores3.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -22599,7 +23267,7 @@ m5stack_unit_cams3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker m5stack_unit_cams3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_unit_cams3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_unit_cams3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_unit_cams3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_unit_cams3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_unit_cams3.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) m5stack_unit_cams3.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB m5stack_unit_cams3.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -22896,7 +23564,7 @@ m5stack_paper.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_ m5stack_paper.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_paper.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_paper.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_paper.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_paper.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_paper.menu.PartitionScheme.custom=Custom m5stack_paper.menu.PartitionScheme.custom.build.partitions= m5stack_paper.menu.PartitionScheme.custom.upload.maximum_size=16777216 @@ -23614,7 +24282,7 @@ m5stack_stamp_s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4 m5stack_stamp_s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_stamp_s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_stamp_s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_stamp_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_stamp_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_stamp_s3.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) m5stack_stamp_s3.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB m5stack_stamp_s3.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -23851,7 +24519,7 @@ m5stack_capsule.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4M m5stack_capsule.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_capsule.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_capsule.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_capsule.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_capsule.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_capsule.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) m5stack_capsule.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB m5stack_capsule.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -24091,7 +24759,7 @@ m5stack_cardputer.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_ m5stack_cardputer.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_cardputer.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_cardputer.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_cardputer.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_cardputer.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_cardputer.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) m5stack_cardputer.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB m5stack_cardputer.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -24328,7 +24996,7 @@ m5stack_dial.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_n m5stack_dial.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_dial.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_dial.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_dial.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_dial.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_dial.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) m5stack_dial.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB m5stack_dial.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -24565,7 +25233,7 @@ m5stack_dinmeter.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4 m5stack_dinmeter.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 m5stack_dinmeter.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB m5stack_dinmeter.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -m5stack_dinmeter.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +m5stack_dinmeter.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 m5stack_dinmeter.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) m5stack_dinmeter.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB m5stack_dinmeter.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 @@ -28390,7 +29058,7 @@ bpi_leaf_s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no bpi_leaf_s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 bpi_leaf_s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB bpi_leaf_s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -bpi_leaf_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +bpi_leaf_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 bpi_leaf_s3.menu.CPUFreq.240=240MHz (WiFi) bpi_leaf_s3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -29147,7 +29815,7 @@ fri3d_2024_esp32s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker fri3d_2024_esp32s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 fri3d_2024_esp32s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB fri3d_2024_esp32s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -fri3d_2024_esp32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +fri3d_2024_esp32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 fri3d_2024_esp32s3.menu.CPUFreq.240=240MHz (WiFi) fri3d_2024_esp32s3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -30856,16 +31524,16 @@ wifiduino32c3.build.target=esp wifiduino32c3.build.mcu=esp32c3 wifiduino32c3.build.core=esp32 wifiduino32c3.build.variant=wifiduinov2 -wifiduino32c3.build.board=WiFiduinoV2 +wifiduino32c3.build.board=WIFIDUINOV2 wifiduino32c3.build.bootloader_addr=0x0 wifiduino32c3.build.cdc_on_boot=0 wifiduino32c3.build.f_cpu=160000000L wifiduino32c3.build.flash_size=4MB wifiduino32c3.build.flash_freq=80m -wifiduino32c3.build.flash_mode=qio -wifiduino32c3.build.boot=qio -wifiduino32c3.build.partitions=default +wifiduino32c3.build.flash_mode=dio +wifiduino32c3.build.boot=dio +wifiduino32c3.build.partitions=no_ota wifiduino32c3.build.defines= wifiduino32c3.menu.CDCOnBoot.default=Disabled @@ -30873,6 +31541,9 @@ wifiduino32c3.menu.CDCOnBoot.default.build.cdc_on_boot=0 wifiduino32c3.menu.CDCOnBoot.cdc=Enabled wifiduino32c3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +wifiduino32c3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +wifiduino32c3.menu.PartitionScheme.no_ota.build.partitions=no_ota +wifiduino32c3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 wifiduino32c3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) wifiduino32c3.menu.PartitionScheme.default.build.partitions=default wifiduino32c3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -30882,9 +31553,6 @@ wifiduino32c3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB wifiduino32c3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 wifiduino32c3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) wifiduino32c3.menu.PartitionScheme.minimal.build.partitions=minimal -wifiduino32c3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) -wifiduino32c3.menu.PartitionScheme.no_ota.build.partitions=no_ota -wifiduino32c3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 wifiduino32c3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) wifiduino32c3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g wifiduino32c3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 @@ -30914,7 +31582,7 @@ wifiduino32c3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_ wifiduino32c3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 wifiduino32c3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB wifiduino32c3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -wifiduino32c3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +wifiduino32c3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 wifiduino32c3.menu.CPUFreq.160=160MHz (WiFi) wifiduino32c3.menu.CPUFreq.160.build.f_cpu=160000000L @@ -30927,12 +31595,12 @@ wifiduino32c3.menu.CPUFreq.20.build.f_cpu=20000000L wifiduino32c3.menu.CPUFreq.10=10MHz wifiduino32c3.menu.CPUFreq.10.build.f_cpu=10000000L -wifiduino32c3.menu.FlashMode.qio=QIO -wifiduino32c3.menu.FlashMode.qio.build.flash_mode=dio -wifiduino32c3.menu.FlashMode.qio.build.boot=qio wifiduino32c3.menu.FlashMode.dio=DIO wifiduino32c3.menu.FlashMode.dio.build.flash_mode=dio wifiduino32c3.menu.FlashMode.dio.build.boot=dio +wifiduino32c3.menu.FlashMode.qio=QIO +wifiduino32c3.menu.FlashMode.qio.build.flash_mode=dio +wifiduino32c3.menu.FlashMode.qio.build.boot=qio wifiduino32c3.menu.FlashFreq.80=80MHz wifiduino32c3.menu.FlashFreq.80.build.flash_freq=80m @@ -31008,34 +31676,34 @@ wifiduino32s3.build.target=esp32s3 wifiduino32s3.build.mcu=esp32s3 wifiduino32s3.build.core=esp32 wifiduino32s3.build.variant=wifiduino32s3 -wifiduino32s3.build.board=WiFiduino32S3 +wifiduino32s3.build.board=WIFIDUINO32S3 wifiduino32s3.build.usb_mode=1 wifiduino32s3.build.cdc_on_boot=0 wifiduino32s3.build.msc_on_boot=0 wifiduino32s3.build.dfu_on_boot=0 wifiduino32s3.build.f_cpu=240000000L -wifiduino32s3.build.flash_size=4MB +wifiduino32s3.build.flash_size=16MB wifiduino32s3.build.flash_freq=80m wifiduino32s3.build.flash_mode=dio wifiduino32s3.build.boot=qio wifiduino32s3.build.boot_freq=80m -wifiduino32s3.build.partitions=default +wifiduino32s3.build.partitions=app3M_fat9M_16MB wifiduino32s3.build.defines= wifiduino32s3.build.loop_core= wifiduino32s3.build.event_core= -wifiduino32s3.build.psram_type=qspi +wifiduino32s3.build.psram_type=opi wifiduino32s3.build.memory_type={build.boot}_{build.psram_type} +wifiduino32s3.menu.PSRAM.opi=OPI PSRAM +wifiduino32s3.menu.PSRAM.opi.build.defines=-DBOARD_HAS_PSRAM +wifiduino32s3.menu.PSRAM.opi.build.psram_type=opi wifiduino32s3.menu.PSRAM.disabled=Disabled wifiduino32s3.menu.PSRAM.disabled.build.defines= wifiduino32s3.menu.PSRAM.disabled.build.psram_type=qspi wifiduino32s3.menu.PSRAM.enabled=QSPI PSRAM wifiduino32s3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM wifiduino32s3.menu.PSRAM.enabled.build.psram_type=qspi -wifiduino32s3.menu.PSRAM.opi=OPI PSRAM -wifiduino32s3.menu.PSRAM.opi.build.defines=-DBOARD_HAS_PSRAM -wifiduino32s3.menu.PSRAM.opi.build.psram_type=opi wifiduino32s3.menu.FlashMode.qio=QIO 80MHz wifiduino32s3.menu.FlashMode.qio.build.flash_mode=dio @@ -31058,12 +31726,10 @@ wifiduino32s3.menu.FlashMode.opi.build.boot=opi wifiduino32s3.menu.FlashMode.opi.build.boot_freq=80m wifiduino32s3.menu.FlashMode.opi.build.flash_freq=80m -wifiduino32s3.menu.FlashSize.4M=4MB (32Mb) -wifiduino32s3.menu.FlashSize.4M.build.flash_size=4MB -wifiduino32s3.menu.FlashSize.8M=8MB (64Mb) -wifiduino32s3.menu.FlashSize.8M.build.flash_size=8MB wifiduino32s3.menu.FlashSize.16M=16MB (128Mb) wifiduino32s3.menu.FlashSize.16M.build.flash_size=16MB +wifiduino32s3.menu.FlashSize.8M=8MB (64Mb) +wifiduino32s3.menu.FlashSize.8M.build.flash_size=8MB #wifiduino32s3.menu.FlashSize.32M=32MB (256Mb) #wifiduino32s3.menu.FlashSize.32M.build.flash_size=32MB @@ -31104,6 +31770,9 @@ wifiduino32s3.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) wifiduino32s3.menu.UploadMode.cdc.upload.use_1200bps_touch=true wifiduino32s3.menu.UploadMode.cdc.upload.wait_for_upload_port=true +wifiduino32s3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9.9MB FATFS) +wifiduino32s3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +wifiduino32s3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 wifiduino32s3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) wifiduino32s3.menu.PartitionScheme.default.build.partitions=default wifiduino32s3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -31134,9 +31803,6 @@ wifiduino32s3.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 wifiduino32s3.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) wifiduino32s3.menu.PartitionScheme.fatflash.build.partitions=ffat wifiduino32s3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 -wifiduino32s3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9.9MB FATFS) -wifiduino32s3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB -wifiduino32s3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 wifiduino32s3.menu.PartitionScheme.rainmaker=RainMaker 4MB wifiduino32s3.menu.PartitionScheme.rainmaker.build.partitions=rainmaker wifiduino32s3.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 @@ -31145,7 +31811,7 @@ wifiduino32s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_ wifiduino32s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 wifiduino32s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB wifiduino32s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -wifiduino32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +wifiduino32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 wifiduino32s3.menu.CPUFreq.240=240MHz (WiFi) wifiduino32s3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -32358,7 +33024,7 @@ kb32.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ota kb32.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 kb32.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB kb32.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -kb32.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +kb32.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 kb32.menu.CPUFreq.240=240MHz (WiFi/BT) kb32.menu.CPUFreq.240.build.f_cpu=240000000L @@ -32536,7 +33202,7 @@ deneyapkart.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no deneyapkart.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 deneyapkart.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB deneyapkart.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -deneyapkart.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +deneyapkart.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 deneyapkart.menu.CPUFreq.240=240MHz (WiFi/BT) deneyapkart.menu.CPUFreq.240.build.f_cpu=240000000L @@ -32714,7 +33380,7 @@ deneyapkart1A.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_ deneyapkart1A.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 deneyapkart1A.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB deneyapkart1A.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -deneyapkart1A.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +deneyapkart1A.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 deneyapkart1A.menu.CPUFreq.240=240MHz (WiFi/BT) deneyapkart1A.menu.CPUFreq.240.build.f_cpu=240000000L @@ -32977,7 +33643,7 @@ deneyapkart1Av2.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4M deneyapkart1Av2.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 deneyapkart1Av2.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB deneyapkart1Av2.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -deneyapkart1Av2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +deneyapkart1Av2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 deneyapkart1Av2.menu.CPUFreq.240=240MHz (WiFi) deneyapkart1Av2.menu.CPUFreq.240.build.f_cpu=240000000L @@ -33146,7 +33812,7 @@ deneyapmini.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no deneyapmini.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 deneyapmini.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB deneyapmini.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -deneyapmini.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +deneyapmini.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 deneyapmini.menu.CPUFreq.240=240MHz (WiFi) deneyapmini.menu.CPUFreq.240.build.f_cpu=240000000L @@ -33336,7 +34002,7 @@ deneyapminiv2.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_ deneyapminiv2.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 deneyapminiv2.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB deneyapminiv2.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -deneyapminiv2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +deneyapminiv2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 deneyapminiv2.menu.CPUFreq.240=240MHz (WiFi) deneyapminiv2.menu.CPUFreq.240.build.f_cpu=240000000L @@ -33505,7 +34171,7 @@ deneyapkartg.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_n deneyapkartg.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 deneyapkartg.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB deneyapkartg.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -deneyapkartg.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +deneyapkartg.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 deneyapkartg.menu.CPUFreq.160=160MHz (WiFi) deneyapkartg.menu.CPUFreq.160.build.f_cpu=160000000L @@ -34253,7 +34919,7 @@ tamc_termod_s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB tamc_termod_s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 tamc_termod_s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB tamc_termod_s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -tamc_termod_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +tamc_termod_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 tamc_termod_s3.menu.CPUFreq.240=240MHz (WiFi) tamc_termod_s3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -34951,7 +35617,7 @@ XIAO_ESP32C3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_n XIAO_ESP32C3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 XIAO_ESP32C3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB XIAO_ESP32C3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -XIAO_ESP32C3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +XIAO_ESP32C3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 XIAO_ESP32C3.menu.CPUFreq.160=160MHz (WiFi) XIAO_ESP32C3.menu.CPUFreq.160.build.f_cpu=160000000L @@ -35385,12 +36051,12 @@ XIAO_ESP32S3_Plus.build.cdc_on_boot=1 XIAO_ESP32S3_Plus.build.msc_on_boot=0 XIAO_ESP32S3_Plus.build.dfu_on_boot=0 XIAO_ESP32S3_Plus.build.f_cpu=240000000L -XIAO_ESP32S3_Plus.build.flash_size=8MB +XIAO_ESP32S3_Plus.build.flash_size=16MB XIAO_ESP32S3_Plus.build.flash_freq=80m XIAO_ESP32S3_Plus.build.flash_mode=dio XIAO_ESP32S3_Plus.build.boot=qio XIAO_ESP32S3_Plus.build.boot_freq=80m -XIAO_ESP32S3_Plus.build.partitions=default_8MB +XIAO_ESP32S3_Plus.build.partitions=ffat XIAO_ESP32S3_Plus.build.defines= XIAO_ESP32S3_Plus.build.loop_core= XIAO_ESP32S3_Plus.build.event_core= @@ -35427,8 +36093,6 @@ XIAO_ESP32S3_Plus.menu.FlashMode.dio.build.boot=dio XIAO_ESP32S3_Plus.menu.FlashMode.dio.build.boot_freq=80m XIAO_ESP32S3_Plus.menu.FlashMode.dio.build.flash_freq=80m -XIAO_ESP32S3_Plus.menu.FlashSize.8M=8MB (64Mb) -XIAO_ESP32S3_Plus.menu.FlashSize.8M.build.flash_size=8MB XIAO_ESP32S3_Plus.menu.FlashSize.16M=16MB (128Mb) XIAO_ESP32S3_Plus.menu.FlashSize.16M.build.flash_size=16MB @@ -36687,7 +37351,7 @@ unphone8.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ot unphone8.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 unphone8.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB unphone8.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -unphone8.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +unphone8.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 unphone8.menu.PartitionScheme.max_app_8MB=Maximum APP (7.9MB APP No OTA/No FS) unphone8.menu.PartitionScheme.max_app_8MB.build.partitions=max_app_8MB @@ -36843,7 +37507,7 @@ unphone9.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ot unphone9.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 unphone9.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB unphone9.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -unphone9.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +unphone9.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 unphone9.menu.PartitionScheme.max_app_8MB=Maximum APP (7.9MB APP No OTA/No FS) unphone9.menu.PartitionScheme.max_app_8MB.build.partitions=max_app_8MB @@ -37572,7 +38236,7 @@ VALTRACK_V4_VTS_ESP32_C3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rai VALTRACK_V4_VTS_ESP32_C3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 VALTRACK_V4_VTS_ESP32_C3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB VALTRACK_V4_VTS_ESP32_C3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -VALTRACK_V4_VTS_ESP32_C3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +VALTRACK_V4_VTS_ESP32_C3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 VALTRACK_V4_VTS_ESP32_C3.menu.CPUFreq.160=160MHz (WiFi) VALTRACK_V4_VTS_ESP32_C3.menu.CPUFreq.160.build.f_cpu=160000000L @@ -37723,7 +38387,7 @@ VALTRACK_V4_MFW_ESP32_C3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rai VALTRACK_V4_MFW_ESP32_C3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 VALTRACK_V4_MFW_ESP32_C3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB VALTRACK_V4_MFW_ESP32_C3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -VALTRACK_V4_MFW_ESP32_C3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +VALTRACK_V4_MFW_ESP32_C3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 VALTRACK_V4_MFW_ESP32_C3.menu.CPUFreq.160=160MHz (WiFi) VALTRACK_V4_MFW_ESP32_C3.menu.CPUFreq.160.build.f_cpu=160000000L @@ -37954,7 +38618,7 @@ Edgebox-ESP-100.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4M Edgebox-ESP-100.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 Edgebox-ESP-100.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB Edgebox-ESP-100.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -Edgebox-ESP-100.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +Edgebox-ESP-100.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 Edgebox-ESP-100.menu.CPUFreq.240=240MHz (WiFi) Edgebox-ESP-100.menu.CPUFreq.240.build.f_cpu=240000000L @@ -38324,7 +38988,7 @@ nebulas3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ot nebulas3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 nebulas3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB nebulas3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -nebulas3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +nebulas3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 nebulas3.menu.CPUFreq.240=240MHz (WiFi) nebulas3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -38550,7 +39214,7 @@ lionbits3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_o lionbits3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 lionbits3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB lionbits3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -lionbits3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +lionbits3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 lionbits3.menu.CPUFreq.240=240MHz (WiFi) lionbits3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -39848,7 +40512,7 @@ atd147_s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_o atd147_s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 atd147_s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB atd147_s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -atd147_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +atd147_s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 atd147_s3.menu.CPUFreq.240=240MHz (WiFi) atd147_s3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -40031,7 +40695,7 @@ atd35s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ota atd35s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 atd35s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB atd35s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -atd35s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +atd35s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 atd35s3.menu.CPUFreq.240=240MHz (WiFi) atd35s3.menu.CPUFreq.240.build.f_cpu=240000000L @@ -40932,11 +41596,6 @@ Geekble_ESP32C3.build.boot=qio Geekble_ESP32C3.build.partitions=default Geekble_ESP32C3.build.defines= -Geekble_ESP32C3.menu.CDCOnBoot.default=Enabled -Geekble_ESP32C3.menu.CDCOnBoot.default.build.cdc_on_boot=1 -Geekble_ESP32C3.menu.CDCOnBoot.cdc=Disabled -Geekble_ESP32C3.menu.CDCOnBoot.cdc.build.cdc_on_boot=0 - Geekble_ESP32C3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) Geekble_ESP32C3.menu.PartitionScheme.default.build.partitions=default Geekble_ESP32C3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -40957,39 +41616,6 @@ Geekble_ESP32C3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) Geekble_ESP32C3.menu.PartitionScheme.huge_app.build.partitions=huge_app Geekble_ESP32C3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 -Geekble_ESP32C3.menu.CPUFreq.160=160MHz (WiFi) (Default) -Geekble_ESP32C3.menu.CPUFreq.160.build.f_cpu=160000000L -Geekble_ESP32C3.menu.CPUFreq.80=80MHz (WiFi) -Geekble_ESP32C3.menu.CPUFreq.80.build.f_cpu=80000000L -Geekble_ESP32C3.menu.CPUFreq.40=40MHz -Geekble_ESP32C3.menu.CPUFreq.40.build.f_cpu=40000000L -Geekble_ESP32C3.menu.CPUFreq.20=20MHz -Geekble_ESP32C3.menu.CPUFreq.20.build.f_cpu=20000000L -Geekble_ESP32C3.menu.CPUFreq.10=10MHz -Geekble_ESP32C3.menu.CPUFreq.10.build.f_cpu=10000000L - -Geekble_ESP32C3.menu.FlashMode.qio=QIO (Default) -Geekble_ESP32C3.menu.FlashMode.qio.build.flash_mode=dio -Geekble_ESP32C3.menu.FlashMode.qio.build.boot=qio -Geekble_ESP32C3.menu.FlashMode.dio=DIO -Geekble_ESP32C3.menu.FlashMode.dio.build.flash_mode=dio -Geekble_ESP32C3.menu.FlashMode.dio.build.boot=dio -Geekble_ESP32C3.menu.FlashMode.qout=QOUT -Geekble_ESP32C3.menu.FlashMode.qout.build.flash_mode=dout -Geekble_ESP32C3.menu.FlashMode.qout.build.boot=qout -Geekble_ESP32C3.menu.FlashMode.dout=DOUT -Geekble_ESP32C3.menu.FlashMode.dout.build.flash_mode=dout - -Geekble_ESP32C3.menu.FlashFreq.80=80MHz (Default) -Geekble_ESP32C3.menu.FlashFreq.80.build.flash_freq=80m -Geekble_ESP32C3.menu.FlashFreq.40=40MHz -Geekble_ESP32C3.menu.FlashFreq.40.build.flash_freq=40m - -Geekble_ESP32C3.menu.FlashSize.4M=4MB (Default) -Geekble_ESP32C3.menu.FlashSize.4M.build.flash_size=4MB -Geekble_ESP32C3.menu.FlashSize.2M=2MB -Geekble_ESP32C3.menu.FlashSize.2M.build.flash_size=2MB - Geekble_ESP32C3.menu.UploadSpeed.921600=921600 (Default) Geekble_ESP32C3.menu.UploadSpeed.921600.upload.speed=921600 Geekble_ESP32C3.menu.UploadSpeed.115200=115200 @@ -41121,6 +41747,13 @@ Geekble_Nano_ESP32S3.menu.PartitionScheme.custom=Custom Geekble_Nano_ESP32S3.menu.PartitionScheme.custom.build.partitions= Geekble_Nano_ESP32S3.menu.PartitionScheme.custom.upload.maximum_size=16777216 +Geekble_Nano_ESP32S3.menu.PSRAM.disabled=Disabled +Geekble_Nano_ESP32S3.menu.PSRAM.disabled.build.defines= +Geekble_Nano_ESP32S3.menu.PSRAM.disabled.build.psram_type=qspi +Geekble_Nano_ESP32S3.menu.PSRAM.enabled=Enabled +Geekble_Nano_ESP32S3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +Geekble_Nano_ESP32S3.menu.PSRAM.enabled.build.psram_type=qspi + Geekble_Nano_ESP32S3.menu.DebugLevel.none=None Geekble_Nano_ESP32S3.menu.DebugLevel.none.build.code_debug=0 Geekble_Nano_ESP32S3.menu.DebugLevel.error=Error @@ -41660,7 +42293,7 @@ waveshare_esp32_s3_touch_lcd_169.menu.PartitionScheme.rainmaker.build.partitions waveshare_esp32_s3_touch_lcd_169.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_lcd_169.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_169.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_169.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_169.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_169.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_lcd_169.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_lcd_169.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -41859,7 +42492,7 @@ waveshare_esp32_s3_touch_amoled_18.menu.PartitionScheme.rainmaker.build.partitio waveshare_esp32_s3_touch_amoled_18.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_amoled_18.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_amoled_18.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_amoled_18.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_amoled_18.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_amoled_18.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_amoled_18.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_amoled_18.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -42058,7 +42691,7 @@ waveshare_esp32_s3_lcd_169.menu.PartitionScheme.rainmaker.build.partitions=rainm waveshare_esp32_s3_lcd_169.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_lcd_169.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_lcd_169.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_lcd_169.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_lcd_169.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_lcd_169.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_lcd_169.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_lcd_169.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -42571,7 +43204,7 @@ aslcanx2.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ot aslcanx2.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 aslcanx2.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB aslcanx2.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -aslcanx2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +aslcanx2.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 aslcanx2.menu.CPUFreq.240=240MHz (WiFi) aslcanx2.menu.CPUFreq.240.build.f_cpu=240000000L @@ -43120,8 +43753,8 @@ alfredo-nou3.upload.maximum_size=3342336 alfredo-nou3.upload.maximum_data_size=327680 alfredo-nou3.upload.flags= alfredo-nou3.upload.extra_flags= -alfredo-nou3.upload.use_1200bps_touch=false -alfredo-nou3.upload.wait_for_upload_port=false +alfredo-nou3.upload.use_1200bps_touch=true +alfredo-nou3.upload.wait_for_upload_port=true alfredo-nou3.serial.disableDTR=false alfredo-nou3.serial.disableRTS=false @@ -43134,7 +43767,7 @@ alfredo-nou3.build.core=esp32 alfredo-nou3.build.variant=alfredo-nou3 alfredo-nou3.build.board=ALFREDO_NOU3 -alfredo-nou3.build.usb_mode=1 +alfredo-nou3.build.usb_mode=0 alfredo-nou3.build.cdc_on_boot=1 alfredo-nou3.build.msc_on_boot=0 alfredo-nou3.build.dfu_on_boot=0 @@ -43161,10 +43794,10 @@ alfredo-nou3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 alfredo-nou3.menu.EventsCore.0=Core 0 alfredo-nou3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 -alfredo-nou3.menu.USBMode.default=Hardware CDC and JTAG -alfredo-nou3.menu.USBMode.default.build.usb_mode=1 -alfredo-nou3.menu.USBMode.usbotg=USB-OTG (TinyUSB) -alfredo-nou3.menu.USBMode.usbotg.build.usb_mode=0 +alfredo-nou3.menu.USBMode.default=USB-OTG (TinyUSB) +alfredo-nou3.menu.USBMode.default.build.usb_mode=0 +alfredo-nou3.menu.USBMode.hwcdc=Hardware CDC and JTAG +alfredo-nou3.menu.USBMode.hwcdc.build.usb_mode=1 alfredo-nou3.menu.CDCOnBoot.cdc=Enabled alfredo-nou3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 @@ -43181,12 +43814,12 @@ alfredo-nou3.menu.DFUOnBoot.default.build.dfu_on_boot=0 alfredo-nou3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) alfredo-nou3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 -alfredo-nou3.menu.UploadMode.default=UART0 / Hardware CDC -alfredo-nou3.menu.UploadMode.default.upload.use_1200bps_touch=false -alfredo-nou3.menu.UploadMode.default.upload.wait_for_upload_port=false alfredo-nou3.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) alfredo-nou3.menu.UploadMode.cdc.upload.use_1200bps_touch=true alfredo-nou3.menu.UploadMode.cdc.upload.wait_for_upload_port=true +alfredo-nou3.menu.UploadMode.default=UART0 / Hardware CDC +alfredo-nou3.menu.UploadMode.default.upload.use_1200bps_touch=false +alfredo-nou3.menu.UploadMode.default.upload.wait_for_upload_port=false alfredo-nou3.menu.PartitionScheme.default_8MB=Default (3MB APP/1.5MB SPIFFS) alfredo-nou3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB @@ -43266,20 +43899,22 @@ alfredo-nou3.menu.EraseFlash.all=Enabled alfredo-nou3.menu.EraseFlash.all.upload.erase_cmd=-e ############################################################## -codecell.name=CodeCell -codecell.vid.0=0x303a -codecell.pid.0=0x1002 -codecell.upload_port.0.vid=0x303a -codecell.upload_port.0.pid=0x1002 +codecell.name=CodeCell C3 codecell.bootloader.tool=esptool_py +codecell.bootloader.tool.default=esptool_py + codecell.upload.tool=esptool_py -codecell.upload.maximum_size=4194304 +codecell.upload.tool.default=esptool_py +codecell.upload.tool.network=esp_ota + +codecell.upload.maximum_size=1310720 codecell.upload.maximum_data_size=327680 +codecell.upload.flags= +codecell.upload.extra_flags= codecell.upload.use_1200bps_touch=false codecell.upload.wait_for_upload_port=false -codecell.upload.speed=921600 codecell.serial.disableDTR=false codecell.serial.disableRTS=false @@ -43288,8 +43923,9 @@ codecell.build.target=esp codecell.build.mcu=esp32c3 codecell.build.core=esp32 codecell.build.variant=codecell -codecell.build.board=ESP32C3_DEV +codecell.build.board=CODECELLC3 codecell.build.bootloader_addr=0x0 + codecell.build.cdc_on_boot=1 codecell.build.f_cpu=160000000L codecell.build.flash_size=4MB @@ -43297,13 +43933,118 @@ codecell.build.flash_freq=80m codecell.build.flash_mode=qio codecell.build.boot=qio codecell.build.partitions=default +codecell.build.defines= + + +codecell.menu.JTAGAdapter.default=Disabled +codecell.menu.JTAGAdapter.default.build.copy_jtag_files=0 +codecell.menu.JTAGAdapter.builtin=Integrated USB JTAG +codecell.menu.JTAGAdapter.builtin.build.openocdscript=esp32c3-builtin.cfg +codecell.menu.JTAGAdapter.builtin.build.copy_jtag_files=1 +codecell.menu.JTAGAdapter.external=FTDI Adapter +codecell.menu.JTAGAdapter.external.build.openocdscript=esp32c3-ftdi.cfg +codecell.menu.JTAGAdapter.external.build.copy_jtag_files=1 +codecell.menu.JTAGAdapter.bridge=ESP USB Bridge +codecell.menu.JTAGAdapter.bridge.build.openocdscript=esp32c3-bridge.cfg +codecell.menu.JTAGAdapter.bridge.build.copy_jtag_files=1 + +codecell.menu.CDCOnBoot.default=Enabled +codecell.menu.CDCOnBoot.default.build.cdc_on_boot=0 +codecell.menu.CDCOnBoot.cdc=Enabled +codecell.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 codecell.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) -codecell.menu.CPUFreq.160=160MHz +codecell.menu.PartitionScheme.default.build.partitions=default +codecell.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +codecell.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +codecell.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +codecell.menu.PartitionScheme.minimal.build.partitions=minimal +codecell.menu.PartitionScheme.no_fs=No FS 4MB (2MB APP x2) +codecell.menu.PartitionScheme.no_fs.build.partitions=no_fs +codecell.menu.PartitionScheme.no_fs.upload.maximum_size=2031616 +codecell.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +codecell.menu.PartitionScheme.no_ota.build.partitions=no_ota +codecell.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +codecell.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +codecell.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +codecell.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +codecell.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +codecell.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +codecell.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +codecell.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +codecell.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +codecell.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +codecell.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +codecell.menu.PartitionScheme.huge_app.build.partitions=huge_app +codecell.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +codecell.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +codecell.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +codecell.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +codecell.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) +codecell.menu.PartitionScheme.fatflash.build.partitions=ffat +codecell.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 +codecell.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9.9MB FATFS) +codecell.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB +codecell.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 +codecell.menu.PartitionScheme.rainmaker=RainMaker 4MB +codecell.menu.PartitionScheme.rainmaker.build.partitions=rainmaker +codecell.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 +codecell.menu.PartitionScheme.rainmaker_4MB=RainMaker 4MB No OTA +codecell.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_4MB_no_ota +codecell.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 +codecell.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB +codecell.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB +codecell.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 +codecell.menu.PartitionScheme.zigbee_zczr=Zigbee ZCZR 4MB with spiffs +codecell.menu.PartitionScheme.zigbee_zczr.build.partitions=zigbee_zczr +codecell.menu.PartitionScheme.zigbee_zczr.upload.maximum_size=1310720 +codecell.menu.PartitionScheme.zigbee_zczr_8MB=Zigbee ZCZR 8MB with spiffs +codecell.menu.PartitionScheme.zigbee_zczr_8MB.build.partitions=zigbee_zczr_8MB +codecell.menu.PartitionScheme.zigbee_zczr_8MB.upload.maximum_size=3407872 +codecell.menu.PartitionScheme.custom=Custom +codecell.menu.PartitionScheme.custom.build.partitions= +codecell.menu.PartitionScheme.custom.upload.maximum_size=16777216 + +codecell.menu.CPUFreq.160=160MHz (WiFi) +codecell.menu.CPUFreq.160.build.f_cpu=160000000L +codecell.menu.CPUFreq.80=80MHz (WiFi) +codecell.menu.CPUFreq.80.build.f_cpu=80000000L +codecell.menu.CPUFreq.40=40MHz +codecell.menu.CPUFreq.40.build.f_cpu=40000000L +codecell.menu.CPUFreq.20=20MHz +codecell.menu.CPUFreq.20.build.f_cpu=20000000L +codecell.menu.CPUFreq.10=10MHz +codecell.menu.CPUFreq.10.build.f_cpu=10000000L + codecell.menu.FlashMode.qio=QIO +codecell.menu.FlashMode.qio.build.flash_mode=dio +codecell.menu.FlashMode.qio.build.boot=qio +codecell.menu.FlashMode.dio=DIO +codecell.menu.FlashMode.dio.build.flash_mode=dio +codecell.menu.FlashMode.dio.build.boot=dio + codecell.menu.FlashFreq.80=80MHz +codecell.menu.FlashFreq.80.build.flash_freq=80m +codecell.menu.FlashFreq.40=40MHz +codecell.menu.FlashFreq.40.build.flash_freq=40m + codecell.menu.FlashSize.4M=4MB (32Mb) +codecell.menu.FlashSize.4M.build.flash_size=4MB + codecell.menu.UploadSpeed.921600=921600 +codecell.menu.UploadSpeed.921600.upload.speed=921600 +codecell.menu.UploadSpeed.115200=115200 +codecell.menu.UploadSpeed.115200.upload.speed=115200 +codecell.menu.UploadSpeed.256000.windows=256000 +codecell.menu.UploadSpeed.256000.upload.speed=256000 +codecell.menu.UploadSpeed.230400.windows.upload.speed=256000 +codecell.menu.UploadSpeed.230400=230400 +codecell.menu.UploadSpeed.230400.upload.speed=230400 +codecell.menu.UploadSpeed.460800.linux=460800 +codecell.menu.UploadSpeed.460800.macosx=460800 +codecell.menu.UploadSpeed.460800.upload.speed=460800 +codecell.menu.UploadSpeed.512000.windows=512000 +codecell.menu.UploadSpeed.512000.upload.speed=512000 codecell.menu.DebugLevel.none=None codecell.menu.DebugLevel.none.build.code_debug=0 @@ -43323,6 +44064,12 @@ codecell.menu.EraseFlash.none.upload.erase_cmd= codecell.menu.EraseFlash.all=Enabled codecell.menu.EraseFlash.all.upload.erase_cmd=-e +codecell.menu.ZigbeeMode.default=Disabled +codecell.menu.ZigbeeMode.default.build.zigbee_mode= +codecell.menu.ZigbeeMode.default.build.zigbee_libs= +codecell.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator/router) +codecell.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR +codecell.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api.zczr -lzboss_stack.zczr -lzboss_port.remote ############################################################## jczn_2432s028r.name=ESP32-2432S028R CYD @@ -43624,7 +44371,7 @@ waveshare_esp32_s3_touch_amoled_241.menu.PartitionScheme.rainmaker.build.partiti waveshare_esp32_s3_touch_amoled_241.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_amoled_241.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_amoled_241.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_amoled_241.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_amoled_241.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_amoled_241.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_amoled_241.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_amoled_241.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -43829,7 +44576,7 @@ waveshare_esp32_s3_touch_lcd_43.menu.PartitionScheme.rainmaker.build.partitions= waveshare_esp32_s3_touch_lcd_43.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_lcd_43.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_43.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_43.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_43.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_43.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_lcd_43.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_lcd_43.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -44028,7 +44775,7 @@ waveshare_esp32_s3_touch_lcd_43B.menu.PartitionScheme.rainmaker.build.partitions waveshare_esp32_s3_touch_lcd_43B.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_lcd_43B.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_43B.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_43B.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_43B.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_43B.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_lcd_43B.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_lcd_43B.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -44232,7 +44979,7 @@ waveshare_esp32_s3_touch_lcd_7.menu.PartitionScheme.rainmaker.build.partitions=r waveshare_esp32_s3_touch_lcd_7.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_lcd_7.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_7.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_7.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_7.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_7.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_lcd_7.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_lcd_7.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -44431,7 +45178,7 @@ waveshare_esp32_s3_touch_lcd_5.menu.PartitionScheme.rainmaker.build.partitions=r waveshare_esp32_s3_touch_lcd_5.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_lcd_5.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_5.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_5.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_5.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_5.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_lcd_5.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_lcd_5.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -44630,7 +45377,7 @@ waveshare_esp32_s3_touch_lcd_5B.menu.PartitionScheme.rainmaker.build.partitions= waveshare_esp32_s3_touch_lcd_5B.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_lcd_5B.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_5B.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_5B.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_5B.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_5B.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_lcd_5B.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_lcd_5B.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -44829,7 +45576,7 @@ waveshare_esp32_s3_touch_lcd_4.menu.PartitionScheme.rainmaker.build.partitions=r waveshare_esp32_s3_touch_lcd_4.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_lcd_4.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_4.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_4.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_4.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_4.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_lcd_4.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_lcd_4.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -45037,7 +45784,7 @@ waveshare_esp32_s3_touch_lcd_185.menu.PartitionScheme.default_8MB.build.partitio waveshare_esp32_s3_touch_lcd_185.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 waveshare_esp32_s3_touch_lcd_185.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_185.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_185.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_185.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_185.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) waveshare_esp32_s3_touch_lcd_185.menu.PartitionScheme.default.build.partitions=default waveshare_esp32_s3_touch_lcd_185.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -45614,7 +46361,7 @@ waveshare_esp32_s3_lcd_185.menu.PartitionScheme.default_8MB.build.partitions=def waveshare_esp32_s3_lcd_185.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 waveshare_esp32_s3_lcd_185.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_lcd_185.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_lcd_185.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_lcd_185.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_lcd_185.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) waveshare_esp32_s3_lcd_185.menu.PartitionScheme.default.build.partitions=default waveshare_esp32_s3_lcd_185.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -45851,7 +46598,7 @@ waveshare_esp32_s3_touch_lcd_146.menu.PartitionScheme.default_8MB.build.partitio waveshare_esp32_s3_touch_lcd_146.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 waveshare_esp32_s3_touch_lcd_146.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_146.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_146.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_146.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_146.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) waveshare_esp32_s3_touch_lcd_146.menu.PartitionScheme.default.build.partitions=default waveshare_esp32_s3_touch_lcd_146.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -46088,7 +46835,7 @@ waveshare_esp32_s3_lcd_146.menu.PartitionScheme.default_8MB.build.partitions=def waveshare_esp32_s3_lcd_146.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 waveshare_esp32_s3_lcd_146.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_lcd_146.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_lcd_146.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_lcd_146.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_lcd_146.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) waveshare_esp32_s3_lcd_146.menu.PartitionScheme.default.build.partitions=default waveshare_esp32_s3_lcd_146.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -46325,7 +47072,7 @@ waveshare_esp32_s3_touch_lcd_185_box.menu.PartitionScheme.default_8MB.build.part waveshare_esp32_s3_touch_lcd_185_box.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 waveshare_esp32_s3_touch_lcd_185_box.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_185_box.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_185_box.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_185_box.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_185_box.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) waveshare_esp32_s3_touch_lcd_185_box.menu.PartitionScheme.default.build.partitions=default waveshare_esp32_s3_touch_lcd_185_box.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -46558,7 +47305,7 @@ waveshare_esp32_s3_lcd_147.menu.PartitionScheme.default_8MB.build.partitions=def waveshare_esp32_s3_lcd_147.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 waveshare_esp32_s3_lcd_147.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_lcd_147.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_lcd_147.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_lcd_147.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_lcd_147.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) waveshare_esp32_s3_lcd_147.menu.PartitionScheme.default.build.partitions=default waveshare_esp32_s3_lcd_147.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -46795,7 +47542,7 @@ waveshare_esp32_s3_touch_lcd_21.menu.PartitionScheme.default_8MB.build.partition waveshare_esp32_s3_touch_lcd_21.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 waveshare_esp32_s3_touch_lcd_21.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_21.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_21.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_21.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_21.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) waveshare_esp32_s3_touch_lcd_21.menu.PartitionScheme.default.build.partitions=default waveshare_esp32_s3_touch_lcd_21.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -47032,7 +47779,7 @@ waveshare_esp32_s3_touch_lcd_28.menu.PartitionScheme.default_8MB.build.partition waveshare_esp32_s3_touch_lcd_28.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 waveshare_esp32_s3_touch_lcd_28.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_lcd_28.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_lcd_28.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_lcd_28.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_lcd_28.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) waveshare_esp32_s3_touch_lcd_28.menu.PartitionScheme.default.build.partitions=default waveshare_esp32_s3_touch_lcd_28.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) @@ -47266,7 +48013,7 @@ waveshare_esp32_s3_relay_6ch.menu.PartitionScheme.default_8MB.build.partitions=d waveshare_esp32_s3_relay_6ch.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 waveshare_esp32_s3_relay_6ch.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_relay_6ch.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_relay_6ch.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_relay_6ch.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_relay_6ch.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9.9MB FATFS) waveshare_esp32_s3_relay_6ch.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB waveshare_esp32_s3_relay_6ch.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728 @@ -47506,7 +48253,7 @@ waveshare_esp32_s3_touch_amoled_164.menu.PartitionScheme.rainmaker.build.partiti waveshare_esp32_s3_touch_amoled_164.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_amoled_164.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_amoled_164.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_amoled_164.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_amoled_164.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_amoled_164.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_amoled_164.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_amoled_164.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -47708,7 +48455,7 @@ waveshare_esp32_s3_touch_amoled_143.menu.PartitionScheme.rainmaker.build.partiti waveshare_esp32_s3_touch_amoled_143.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_amoled_143.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_amoled_143.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_amoled_143.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_amoled_143.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_amoled_143.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_amoled_143.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_amoled_143.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -47910,7 +48657,7 @@ waveshare_esp32_s3_touch_amoled_191.menu.PartitionScheme.rainmaker.build.partiti waveshare_esp32_s3_touch_amoled_191.menu.PartitionScheme.rainmaker.upload.maximum_size=1966080 waveshare_esp32_s3_touch_amoled_191.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB waveshare_esp32_s3_touch_amoled_191.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -waveshare_esp32_s3_touch_amoled_191.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +waveshare_esp32_s3_touch_amoled_191.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 waveshare_esp32_s3_touch_amoled_191.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS) waveshare_esp32_s3_touch_amoled_191.menu.PartitionScheme.fatflash.build.partitions=ffat waveshare_esp32_s3_touch_amoled_191.menu.PartitionScheme.fatflash.upload.maximum_size=2097152 @@ -49059,6 +49806,216 @@ yb_esp32s3_eth.menu.EraseFlash.none.upload.erase_cmd= yb_esp32s3_eth.menu.EraseFlash.all=Enabled yb_esp32s3_eth.menu.EraseFlash.all.upload.erase_cmd=-e +############################################################## + +yb_esp32s3_drv.name=YelloByte YB-ESP32-S3-DRV + +yb_esp32s3_drv.bootloader.tool=esptool_py +yb_esp32s3_drv.bootloader.tool.default=esptool_py + +yb_esp32s3_drv.upload.tool=esptool_py +yb_esp32s3_drv.upload.tool.default=esptool_py +yb_esp32s3_drv.upload.tool.network=esp_ota + +yb_esp32s3_drv.upload.maximum_size=1310720 +yb_esp32s3_drv.upload.maximum_data_size=327680 +yb_esp32s3_drv.upload.flags= +yb_esp32s3_drv.upload.extra_flags= +yb_esp32s3_drv.upload.use_1200bps_touch=false +yb_esp32s3_drv.upload.wait_for_upload_port=false + +yb_esp32s3_drv.serial.disableDTR=false +yb_esp32s3_drv.serial.disableRTS=false + +yb_esp32s3_drv.build.tarch=xtensa +yb_esp32s3_drv.build.bootloader_addr=0x0 +yb_esp32s3_drv.build.target=esp32s3 +yb_esp32s3_drv.build.mcu=esp32s3 +yb_esp32s3_drv.build.core=esp32 +yb_esp32s3_drv.build.variant=yb_esp32s3_drv +yb_esp32s3_drv.build.board=YB_ESP32S3_DRV + +yb_esp32s3_drv.build.usb_mode=1 +yb_esp32s3_drv.build.cdc_on_boot=1 +yb_esp32s3_drv.build.msc_on_boot=0 +yb_esp32s3_drv.build.dfu_on_boot=0 +yb_esp32s3_drv.build.f_cpu=240000000L +yb_esp32s3_drv.build.flash_size=8MB +yb_esp32s3_drv.build.flash_freq=80m +yb_esp32s3_drv.build.flash_mode=dio +yb_esp32s3_drv.build.boot=qio +yb_esp32s3_drv.build.partitions=default +yb_esp32s3_drv.build.defines= +yb_esp32s3_drv.build.loop_core= +yb_esp32s3_drv.build.event_core= +yb_esp32s3_drv.build.flash_type=qio +yb_esp32s3_drv.build.psram_type=qspi +yb_esp32s3_drv.build.memory_type={build.flash_type}_{build.psram_type} + +yb_esp32s3_drv.menu.JTAGAdapter.default=Disabled +yb_esp32s3_drv.menu.JTAGAdapter.default.build.copy_jtag_files=0 +yb_esp32s3_drv.menu.JTAGAdapter.builtin=Integrated USB JTAG +yb_esp32s3_drv.menu.JTAGAdapter.builtin.build.openocdscript=esp32s3-builtin.cfg +yb_esp32s3_drv.menu.JTAGAdapter.builtin.build.copy_jtag_files=1 +yb_esp32s3_drv.menu.JTAGAdapter.external=FTDI Adapter +yb_esp32s3_drv.menu.JTAGAdapter.external.build.openocdscript=esp32s3-ftdi.cfg +yb_esp32s3_drv.menu.JTAGAdapter.external.build.copy_jtag_files=1 +yb_esp32s3_drv.menu.JTAGAdapter.bridge=ESP USB Bridge +yb_esp32s3_drv.menu.JTAGAdapter.bridge.build.openocdscript=esp32s3-bridge.cfg +yb_esp32s3_drv.menu.JTAGAdapter.bridge.build.copy_jtag_files=1 + +yb_esp32s3_drv.menu.LoopCore.1=Core 1 +yb_esp32s3_drv.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +yb_esp32s3_drv.menu.LoopCore.0=Core 0 +yb_esp32s3_drv.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +yb_esp32s3_drv.menu.EventsCore.1=Core 1 +yb_esp32s3_drv.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +yb_esp32s3_drv.menu.EventsCore.0=Core 0 +yb_esp32s3_drv.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +yb_esp32s3_drv.menu.USBMode.hwcdc=Hardware CDC and JTAG +yb_esp32s3_drv.menu.USBMode.hwcdc.build.usb_mode=1 +yb_esp32s3_drv.menu.USBMode.default=USB-OTG (TinyUSB) +yb_esp32s3_drv.menu.USBMode.default.build.usb_mode=0 + +yb_esp32s3_drv.menu.CDCOnBoot.cdc=Enabled +yb_esp32s3_drv.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 +yb_esp32s3_drv.menu.CDCOnBoot.default=Disabled +yb_esp32s3_drv.menu.CDCOnBoot.default.build.cdc_on_boot=0 + +yb_esp32s3_drv.menu.MSCOnBoot.default=Disabled +yb_esp32s3_drv.menu.MSCOnBoot.default.build.msc_on_boot=0 +yb_esp32s3_drv.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +yb_esp32s3_drv.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +yb_esp32s3_drv.menu.DFUOnBoot.default=Disabled +yb_esp32s3_drv.menu.DFUOnBoot.default.build.dfu_on_boot=0 +yb_esp32s3_drv.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +yb_esp32s3_drv.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +yb_esp32s3_drv.menu.UploadMode.default=UART0 / Hardware CDC +yb_esp32s3_drv.menu.UploadMode.default.upload.use_1200bps_touch=false +yb_esp32s3_drv.menu.UploadMode.default.upload.wait_for_upload_port=false +yb_esp32s3_drv.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +yb_esp32s3_drv.menu.UploadMode.cdc.upload.use_1200bps_touch=true +yb_esp32s3_drv.menu.UploadMode.cdc.upload.wait_for_upload_port=true + +yb_esp32s3_drv.menu.PSRAM.enabled=QSPI PSRAM +yb_esp32s3_drv.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +yb_esp32s3_drv.menu.PSRAM.enabled.build.psram_type=qspi +yb_esp32s3_drv.menu.PSRAM.disabled=Disabled +yb_esp32s3_drv.menu.PSRAM.disabled.build.defines= +yb_esp32s3_drv.menu.PSRAM.disabled.build.psram_type=qspi +yb_esp32s3_drv.menu.PSRAM.opi=OPI PSRAM +yb_esp32s3_drv.menu.PSRAM.opi.build.defines=-DBOARD_HAS_PSRAM +yb_esp32s3_drv.menu.PSRAM.opi.build.psram_type=opi + +yb_esp32s3_drv.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +yb_esp32s3_drv.menu.PartitionScheme.default.build.partitions=default +yb_esp32s3_drv.menu.PartitionScheme.default_8MB=8M with spiffs (3MB APP/1.5MB SPIFFS) +yb_esp32s3_drv.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +yb_esp32s3_drv.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 +yb_esp32s3_drv.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +yb_esp32s3_drv.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +yb_esp32s3_drv.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS) +yb_esp32s3_drv.menu.PartitionScheme.minimal.build.partitions=minimal +yb_esp32s3_drv.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS) +yb_esp32s3_drv.menu.PartitionScheme.no_ota.build.partitions=no_ota +yb_esp32s3_drv.menu.PartitionScheme.no_ota.upload.maximum_size=2097152 +yb_esp32s3_drv.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS) +yb_esp32s3_drv.menu.PartitionScheme.noota_3g.build.partitions=noota_3g +yb_esp32s3_drv.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576 +yb_esp32s3_drv.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS) +yb_esp32s3_drv.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat +yb_esp32s3_drv.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152 +yb_esp32s3_drv.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS) +yb_esp32s3_drv.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat +yb_esp32s3_drv.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576 +yb_esp32s3_drv.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS) +yb_esp32s3_drv.menu.PartitionScheme.huge_app.build.partitions=huge_app +yb_esp32s3_drv.menu.PartitionScheme.huge_app.upload.maximum_size=3145728 +yb_esp32s3_drv.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) +yb_esp32s3_drv.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs +yb_esp32s3_drv.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080 +yb_esp32s3_drv.menu.PartitionScheme.max_app_8MB=Maximum APP (7.9MB APP No OTA/No FS) +yb_esp32s3_drv.menu.PartitionScheme.max_app_8MB.build.partitions=max_app_8MB +yb_esp32s3_drv.menu.PartitionScheme.max_app_8MB.upload.maximum_size=8257536 + +yb_esp32s3_drv.menu.CPUFreq.240=240MHz (WiFi) +yb_esp32s3_drv.menu.CPUFreq.240.build.f_cpu=240000000L +yb_esp32s3_drv.menu.CPUFreq.160=160MHz (WiFi) +yb_esp32s3_drv.menu.CPUFreq.160.build.f_cpu=160000000L +yb_esp32s3_drv.menu.CPUFreq.80=80MHz (WiFi) +yb_esp32s3_drv.menu.CPUFreq.80.build.f_cpu=80000000L +yb_esp32s3_drv.menu.CPUFreq.40=40MHz +yb_esp32s3_drv.menu.CPUFreq.40.build.f_cpu=40000000L +yb_esp32s3_drv.menu.CPUFreq.20=20MHz +yb_esp32s3_drv.menu.CPUFreq.20.build.f_cpu=20000000L +yb_esp32s3_drv.menu.CPUFreq.10=10MHz +yb_esp32s3_drv.menu.CPUFreq.10.build.f_cpu=10000000L + +yb_esp32s3_drv.menu.FlashMode.qio=QIO 80MHz +yb_esp32s3_drv.menu.FlashMode.qio.build.flash_mode=dio +yb_esp32s3_drv.menu.FlashMode.qio.build.boot=qio +yb_esp32s3_drv.menu.FlashMode.qio.build.boot_freq=80m +yb_esp32s3_drv.menu.FlashMode.qio.build.flash_freq=80m +yb_esp32s3_drv.menu.FlashMode.qio120=QIO 120MHz +yb_esp32s3_drv.menu.FlashMode.qio120.build.flash_mode=dio +yb_esp32s3_drv.menu.FlashMode.qio120.build.boot=qio +yb_esp32s3_drv.menu.FlashMode.qio120.build.boot_freq=120m +yb_esp32s3_drv.menu.FlashMode.qio120.build.flash_freq=80m +yb_esp32s3_drv.menu.FlashMode.dio=DIO 80MHz +yb_esp32s3_drv.menu.FlashMode.dio.build.flash_mode=dio +yb_esp32s3_drv.menu.FlashMode.dio.build.boot=dio +yb_esp32s3_drv.menu.FlashMode.dio.build.boot_freq=80m +yb_esp32s3_drv.menu.FlashMode.dio.build.flash_freq=80m +yb_esp32s3_drv.menu.FlashMode.opi=OPI 80MHz +yb_esp32s3_drv.menu.FlashMode.opi.build.flash_mode=dout +yb_esp32s3_drv.menu.FlashMode.opi.build.boot=opi +yb_esp32s3_drv.menu.FlashMode.opi.build.boot_freq=80m +yb_esp32s3_drv.menu.FlashMode.opi.build.flash_freq=80m + +yb_esp32s3_drv.menu.FlashSize.4M=4MB (32Mb) +yb_esp32s3_drv.menu.FlashSize.4M.build.flash_size=4MB +yb_esp32s3_drv.menu.FlashSize.8M=8MB (64Mb) +yb_esp32s3_drv.menu.FlashSize.8M.build.flash_size=8MB +yb_esp32s3_drv.menu.FlashSize.16M=16MB (128Mb) +yb_esp32s3_drv.menu.FlashSize.16M.build.flash_size=16MB + +yb_esp32s3_drv.menu.UploadSpeed.921600=921600 +yb_esp32s3_drv.menu.UploadSpeed.921600.upload.speed=921600 +yb_esp32s3_drv.menu.UploadSpeed.115200=115200 +yb_esp32s3_drv.menu.UploadSpeed.115200.upload.speed=115200 +yb_esp32s3_drv.menu.UploadSpeed.256000.windows=256000 +yb_esp32s3_drv.menu.UploadSpeed.256000.upload.speed=256000 +yb_esp32s3_drv.menu.UploadSpeed.230400.windows.upload.speed=256000 +yb_esp32s3_drv.menu.UploadSpeed.230400=230400 +yb_esp32s3_drv.menu.UploadSpeed.230400.upload.speed=230400 +yb_esp32s3_drv.menu.UploadSpeed.460800.linux=460800 +yb_esp32s3_drv.menu.UploadSpeed.460800.macosx=460800 +yb_esp32s3_drv.menu.UploadSpeed.460800.upload.speed=460800 +yb_esp32s3_drv.menu.UploadSpeed.512000.windows=512000 +yb_esp32s3_drv.menu.UploadSpeed.512000.upload.speed=512000 + +yb_esp32s3_drv.menu.DebugLevel.none=None +yb_esp32s3_drv.menu.DebugLevel.none.build.code_debug=0 +yb_esp32s3_drv.menu.DebugLevel.error=Error +yb_esp32s3_drv.menu.DebugLevel.error.build.code_debug=1 +yb_esp32s3_drv.menu.DebugLevel.warn=Warn +yb_esp32s3_drv.menu.DebugLevel.warn.build.code_debug=2 +yb_esp32s3_drv.menu.DebugLevel.info=Info +yb_esp32s3_drv.menu.DebugLevel.info.build.code_debug=3 +yb_esp32s3_drv.menu.DebugLevel.debug=Debug +yb_esp32s3_drv.menu.DebugLevel.debug.build.code_debug=4 +yb_esp32s3_drv.menu.DebugLevel.verbose=Verbose +yb_esp32s3_drv.menu.DebugLevel.verbose.build.code_debug=5 + +yb_esp32s3_drv.menu.EraseFlash.none=Disabled +yb_esp32s3_drv.menu.EraseFlash.none.upload.erase_cmd= +yb_esp32s3_drv.menu.EraseFlash.all=Enabled +yb_esp32s3_drv.menu.EraseFlash.all.upload.erase_cmd=-e + ############################################################## # Huidu HD-WF2 - esp32-s3 HUB75 driver board # https://www.hdwell.com/Product/index46.html @@ -49518,7 +50475,7 @@ cyobot_v2_esp32s3.menu.PartitionScheme.rainmaker_4MB.build.partitions=rainmaker_ cyobot_v2_esp32s3.menu.PartitionScheme.rainmaker_4MB.upload.maximum_size=4038656 cyobot_v2_esp32s3.menu.PartitionScheme.rainmaker_8MB=RainMaker 8MB cyobot_v2_esp32s3.menu.PartitionScheme.rainmaker_8MB.build.partitions=rainmaker_8MB -cyobot_v2_esp32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4116480 +cyobot_v2_esp32s3.menu.PartitionScheme.rainmaker_8MB.upload.maximum_size=4096000 cyobot_v2_esp32s3.menu.PartitionScheme.app5M_fat24M_32MB=32M Flash (4.8MB APP/22MB FATFS) cyobot_v2_esp32s3.menu.PartitionScheme.app5M_fat24M_32MB.build.partitions=large_fat_32MB cyobot_v2_esp32s3.menu.PartitionScheme.app5M_fat24M_32MB.upload.maximum_size=4718592 diff --git a/cores/esp32/Arduino.h b/cores/esp32/Arduino.h index d21089cc3fe..9048249a873 100644 --- a/cores/esp32/Arduino.h +++ b/cores/esp32/Arduino.h @@ -41,7 +41,6 @@ #include "extra_attr.h" #include "pins_arduino.h" -#include "io_pin_remap.h" #include "esp32-hal.h" #define PI 3.1415926535897932384626433832795 @@ -251,4 +250,8 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); void noTone(uint8_t _pin); #endif /* __cplusplus */ + +// must be applied last as it overrides some of the above +#include "io_pin_remap.h" + #endif /* _ESP32_CORE_ARDUINO_H_ */ diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index 170e323a035..062317d9f53 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -603,6 +603,7 @@ void HWCDC::setDebugOutput(bool en) { } else { ets_install_putc2(NULL); } + ets_install_putc1(NULL); // closes UART log output } #if ARDUINO_USB_MODE && ARDUINO_USB_CDC_ON_BOOT // Hardware JTAG CDC selected diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 76135691411..6d762da21fb 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -607,6 +607,24 @@ bool HardwareSerial::setMode(SerialMode mode) { return uartSetMode(_uart, mode); } +// Sets the UART Clock Source based on the compatible SoC options +// This method must be called before starting UART using begin(), otherwise it won't have any effect. +// Clock Source Options are: +// UART_CLK_SRC_DEFAULT :: any SoC - it will set whatever IDF defines as the default UART Clock Source +// UART_CLK_SRC_APB :: ESP32, ESP32-S2, ESP32-C3 and ESP32-S3 +// UART_CLK_SRC_PLL :: ESP32-C2, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2 and ESP32-P4 +// UART_CLK_SRC_XTAL :: ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2, ESP32-S3 and ESP32-P4 +// UART_CLK_SRC_RTC :: ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2, ESP32-S3 and ESP32-P4 +// UART_CLK_SRC_REF_TICK :: ESP32 and ESP32-S2 +// Note: CLK_SRC_PLL Freq depends on the SoC - ESP32-C2 has 40MHz, ESP32-H2 has 48MHz and ESP32-C5, C6, C61 and P4 has 80MHz +// Note: ESP32-C6, C61, ESP32-P4 and ESP32-C5 have LP UART that will use only RTC_FAST or XTAL/2 as Clock Source +bool HardwareSerial::setClockSource(SerialClkSrc clkSrc) { + if (_uart) { + log_e("No Clock Source change was done. This function must be called before beginning UART%d.", _uart_nr); + return false; + } + return uartSetClockSource(_uart_nr, (uart_sclk_t)clkSrc); +} // minimum total RX Buffer size is the UART FIFO space (128 bytes for most SoC) + 1. IDF imposition. // LP UART has FIFO of 16 bytes size_t HardwareSerial::setRxBufferSize(size_t new_size) { diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index b1f6df17724..e974f112701 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -96,6 +96,29 @@ typedef enum { UART_PARITY_ERROR } hardwareSerial_error_t; +typedef enum { + UART_CLK_SRC_DEFAULT = UART_SCLK_DEFAULT, +#if SOC_UART_SUPPORT_APB_CLK + UART_CLK_SRC_APB = UART_SCLK_APB, +#endif +#if SOC_UART_SUPPORT_PLL_F40M_CLK + UART_CLK_SRC_PLL = UART_SCLK_PLL_F40M, +#elif SOC_UART_SUPPORT_PLL_F80M_CLK + UART_CLK_SRC_PLL = UART_SCLK_PLL_F80M, +#elif CONFIG_IDF_TARGET_ESP32H2 + UART_CLK_SRC_PLL = UART_SCLK_PLL_F48M, +#endif +#if SOC_UART_SUPPORT_XTAL_CLK + UART_CLK_SRC_XTAL = UART_SCLK_XTAL, +#endif +#if SOC_UART_SUPPORT_RTC_CLK + UART_CLK_SRC_RTC = UART_SCLK_RTC, +#endif +#if SOC_UART_SUPPORT_REF_TICK + UART_CLK_SRC_REF_TICK = UART_SCLK_REF_TICK, +#endif +} SerialClkSrc; + #ifndef ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE #ifndef CONFIG_ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE #define ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE 2048 @@ -344,6 +367,17 @@ class HardwareSerial : public Stream { // UART_MODE_RS485_COLLISION_DETECT = 0x03 mode: RS485 collision detection UART mode (used for test purposes) // UART_MODE_RS485_APP_CTRL = 0x04 mode: application control RS485 UART mode (used for test purposes) bool setMode(SerialMode mode); + // Used to set the UART clock source mode. It must be set before calling begin(), otherwise it won't have any effect. + // Not all clock source are available to every SoC. The compatible option are listed here: + // UART_CLK_SRC_DEFAULT :: any SoC - it will set whatever IDF defines as the default UART Clock Source + // UART_CLK_SRC_APB :: ESP32, ESP32-S2, ESP32-C3 and ESP32-S3 + // UART_CLK_SRC_PLL :: ESP32-C2, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2 and ESP32-P4 + // UART_CLK_SRC_XTAL :: ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2, ESP32-S3 and ESP32-P4 + // UART_CLK_SRC_RTC :: ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2, ESP32-S3 and ESP32-P4 + // UART_CLK_SRC_REF_TICK :: ESP32 and ESP32-S2 + // Note: CLK_SRC_PLL Freq depends on the SoC - ESP32-C2 has 40MHz, ESP32-H2 has 48MHz and ESP32-C5, C6, C61 and P4 has 80MHz + // Note: ESP32-C6, C61, ESP32-P4 and ESP32-C5 have LP UART that will use only RTC_FAST or XTAL/2 as Clock Source + bool setClockSource(SerialClkSrc clkSrc); size_t setRxBufferSize(size_t new_size); size_t setTxBufferSize(size_t new_size); diff --git a/cores/esp32/USB.cpp b/cores/esp32/USB.cpp index 8fdd7a3ab71..269e9a76cb3 100644 --- a/cores/esp32/USB.cpp +++ b/cores/esp32/USB.cpp @@ -100,6 +100,7 @@ static bool tinyusb_device_suspended = false; void tud_mount_cb(void) { tinyusb_device_mounted = true; arduino_usb_event_data_t p; + p.suspend.remote_wakeup_en = 0; arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_STARTED_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); } @@ -107,6 +108,7 @@ void tud_mount_cb(void) { void tud_umount_cb(void) { tinyusb_device_mounted = false; arduino_usb_event_data_t p; + p.suspend.remote_wakeup_en = 0; arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_STOPPED_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); } @@ -123,6 +125,7 @@ void tud_suspend_cb(bool remote_wakeup_en) { void tud_resume_cb(void) { tinyusb_device_suspended = false; arduino_usb_event_data_t p; + p.suspend.remote_wakeup_en = 0; arduino_usb_event_post(ARDUINO_USB_EVENTS, ARDUINO_USB_RESUME_EVENT, &p, sizeof(arduino_usb_event_data_t), portMAX_DELAY); } diff --git a/cores/esp32/USBCDC.cpp b/cores/esp32/USBCDC.cpp index 945021a79e2..c7bb4582d4f 100644 --- a/cores/esp32/USBCDC.cpp +++ b/cores/esp32/USBCDC.cpp @@ -455,6 +455,7 @@ void USBCDC::setDebugOutput(bool en) { } else { ets_install_putc2(NULL); } + ets_install_putc1(NULL); // closes UART log output } USBCDC::operator bool() const { diff --git a/cores/esp32/esp32-hal-bt.c b/cores/esp32/esp32-hal-bt.c index 5f1148bd492..5d512d448a3 100644 --- a/cores/esp32/esp32-hal-bt.c +++ b/cores/esp32/esp32-hal-bt.c @@ -15,7 +15,7 @@ #include "esp32-hal-bt.h" #if SOC_BT_SUPPORTED -#ifdef CONFIG_BT_ENABLED +#if defined(CONFIG_BT_BLUEDROID_ENABLED) && __has_include("esp_bt.h") #if CONFIG_IDF_TARGET_ESP32 bool btInUse() { diff --git a/cores/esp32/esp32-hal-cpu.c b/cores/esp32/esp32-hal-cpu.c index 1ffde860792..b80e24c2b0f 100644 --- a/cores/esp32/esp32-hal-cpu.c +++ b/cores/esp32/esp32-hal-cpu.c @@ -26,6 +26,8 @@ #include "soc/efuse_reg.h" #include "esp32-hal.h" #include "esp32-hal-cpu.h" +#include "hal/timer_ll.h" +#include "esp_private/systimer.h" #include "esp_system.h" #ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ @@ -173,7 +175,9 @@ static uint32_t calculateApb(rtc_cpu_freq_config_t *conf) { #endif } +#if defined(CONFIG_IDF_TARGET_ESP32) && !defined(LACT_MODULE) && !defined(LACT_TICKS_PER_US) void esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us); //private in IDF +#endif bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz) { rtc_cpu_freq_config_t conf, cconf; @@ -246,7 +250,13 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz) { //Update APB Freq REG rtc_clk_apb_freq_update(apb); //Update esp_timer divisor +#if CONFIG_IDF_TARGET_ESP32 +#if defined(LACT_MODULE) && defined(LACT_TICKS_PER_US) + timer_ll_set_lact_clock_prescale(TIMER_LL_GET_HW(LACT_MODULE), apb / MHZ / LACT_TICKS_PER_US); +#else esp_timer_impl_update_apb_freq(apb / MHZ); +#endif +#endif } #endif //Update FreeRTOS Tick Divisor diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index c681be077b3..90ad1e7f36d 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -185,7 +185,7 @@ extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin) { #endif // RGB_BUILTIN // This work when the pin is set as GPIO and in INPUT mode. For all other pin functions, it may return inconsistent response if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL) { - log_w("IO %i is not set as GPIO. digitalRead() may return an inconsistent value."); + log_w("IO %i is not set as GPIO. digitalRead() may return an inconsistent value.", pin); } return gpio_get_level((gpio_num_t)pin); } diff --git a/cores/esp32/esp32-hal-i2c-slave.c b/cores/esp32/esp32-hal-i2c-slave.c index 46c3a4d58c2..9d39c1c783d 100644 --- a/cores/esp32/esp32-hal-i2c-slave.c +++ b/cores/esp32/esp32-hal-i2c-slave.c @@ -335,10 +335,12 @@ esp_err_t i2cSlaveInit(uint8_t num, int sda, int scl, uint16_t slaveID, uint32_t } #endif // !defined(CONFIG_IDF_TARGET_ESP32P4) - i2c_ll_slave_init(i2c->dev); #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) + i2c_ll_set_mode(i2c->dev, I2C_BUS_MODE_SLAVE); + i2c_ll_enable_pins_open_drain(i2c->dev, true); i2c_ll_enable_fifo_mode(i2c->dev, true); #else + i2c_ll_slave_init(i2c->dev); i2c_ll_slave_set_fifo_mode(i2c->dev, true); #endif i2c_ll_set_slave_addr(i2c->dev, slaveID, false); diff --git a/cores/esp32/esp32-hal-ledc.c b/cores/esp32/esp32-hal-ledc.c index 0a3ec5a60c7..18b722f80a2 100644 --- a/cores/esp32/esp32-hal-ledc.c +++ b/cores/esp32/esp32-hal-ledc.c @@ -22,6 +22,9 @@ #include "soc/gpio_sig_map.h" #include "esp_rom_gpio.h" #include "hal/ledc_ll.h" +#if SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED +#include +#endif #ifdef SOC_LEDC_SUPPORT_HS_MODE #define LEDC_CHANNELS (SOC_LEDC_CHANNEL_NUM << 1) @@ -45,6 +48,93 @@ typedef struct { ledc_periph_t ledc_handle = {0}; +// Helper function to find a timer with matching frequency and resolution +static bool find_matching_timer(uint8_t speed_mode, uint32_t freq, uint8_t resolution, uint8_t *timer_num) { + log_d("Searching for timer with freq=%u, resolution=%u", freq, resolution); + // Check all channels to find one with matching frequency and resolution + for (uint8_t i = 0; i < SOC_GPIO_PIN_COUNT; i++) { + if (!perimanPinIsValid(i)) { + continue; + } + peripheral_bus_type_t type = perimanGetPinBusType(i); + if (type == ESP32_BUS_TYPE_LEDC) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(i, ESP32_BUS_TYPE_LEDC); + if (bus != NULL && (bus->channel / SOC_LEDC_CHANNEL_NUM) == speed_mode && bus->freq_hz == freq && bus->channel_resolution == resolution) { + log_d("Found matching timer %u for freq=%u, resolution=%u", bus->timer_num, freq, resolution); + *timer_num = bus->timer_num; + return true; + } + } + } + log_d("No matching timer found for freq=%u, resolution=%u", freq, resolution); + return false; +} + +// Helper function to find an unused timer +static bool find_free_timer(uint8_t speed_mode, uint8_t *timer_num) { + // Check which timers are in use + uint8_t used_timers = 0; + for (uint8_t i = 0; i < SOC_GPIO_PIN_COUNT; i++) { + if (!perimanPinIsValid(i)) { + continue; + } + peripheral_bus_type_t type = perimanGetPinBusType(i); + if (type == ESP32_BUS_TYPE_LEDC) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(i, ESP32_BUS_TYPE_LEDC); + if (bus != NULL && (bus->channel / SOC_LEDC_CHANNEL_NUM) == speed_mode) { + log_d("Timer %u is in use by channel %u", bus->timer_num, bus->channel); + used_timers |= (1 << bus->timer_num); + } + } + } + + // Find first unused timer + for (uint8_t i = 0; i < SOC_LEDC_TIMER_NUM; i++) { + if (!(used_timers & (1 << i))) { + log_d("Found free timer %u", i); + *timer_num = i; + return true; + } + } + log_e("No free timers available"); + return false; +} + +// Helper function to remove a channel from a timer and clear timer if no channels are using it +static void remove_channel_from_timer(uint8_t speed_mode, uint8_t timer_num, uint8_t channel) { + log_d("Removing channel %u from timer %u in speed_mode %u", channel, timer_num, speed_mode); + + // Check if any other channels are using this timer + bool timer_in_use = false; + for (uint8_t i = 0; i < SOC_GPIO_PIN_COUNT; i++) { + if (!perimanPinIsValid(i)) { + continue; + } + peripheral_bus_type_t type = perimanGetPinBusType(i); + if (type == ESP32_BUS_TYPE_LEDC) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(i, ESP32_BUS_TYPE_LEDC); + if (bus != NULL && (bus->channel / SOC_LEDC_CHANNEL_NUM) == speed_mode && bus->timer_num == timer_num && bus->channel != channel) { + log_d("Timer %u is still in use by channel %u", timer_num, bus->channel); + timer_in_use = true; + break; + } + } + } + + if (!timer_in_use) { + log_d("No other channels using timer %u, deconfiguring timer", timer_num); + // Stop the timer + ledc_timer_pause(speed_mode, timer_num); + // Deconfigure the timer + ledc_timer_config_t ledc_timer; + memset((void *)&ledc_timer, 0, sizeof(ledc_timer_config_t)); + ledc_timer.speed_mode = speed_mode; + ledc_timer.timer_num = timer_num; + ledc_timer.deconfigure = true; + ledc_timer_config(&ledc_timer); + } +} + static bool fade_initialized = false; static ledc_clk_cfg_t clock_source = LEDC_DEFAULT_CLK; @@ -81,6 +171,8 @@ static bool ledcDetachBus(void *bus) { } pinMatrixOutDetach(handle->pin, false, false); if (!channel_found) { + uint8_t group = (handle->channel / SOC_LEDC_CHANNEL_NUM); + remove_channel_from_timer(group, handle->timer_num, handle->channel % SOC_LEDC_CHANNEL_NUM); ledc_handle.used_channels &= ~(1UL << handle->channel); } free(handle); @@ -117,32 +209,59 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c return false; } - uint8_t group = (channel / 8), timer = ((channel / 2) % 4); + uint8_t group = (channel / SOC_LEDC_CHANNEL_NUM); + uint8_t timer = 0; bool channel_used = ledc_handle.used_channels & (1UL << channel); + if (channel_used) { log_i("Channel %u is already set up, given frequency and resolution will be ignored", channel); - if (ledc_set_pin(pin, group, channel % 8) != ESP_OK) { + if (ledc_set_pin(pin, group, channel % SOC_LEDC_CHANNEL_NUM) != ESP_OK) { log_e("Attaching pin to already used channel failed!"); return false; } } else { - ledc_timer_config_t ledc_timer = {.speed_mode = group, .timer_num = timer, .duty_resolution = resolution, .freq_hz = freq, .clk_cfg = clock_source}; - if (ledc_timer_config(&ledc_timer) != ESP_OK) { - log_e("ledc setup failed!"); - return false; + // Find a timer with matching frequency and resolution, or a free timer + if (!find_matching_timer(group, freq, resolution, &timer)) { + if (!find_free_timer(group, &timer)) { + log_w("No free timers available for speed mode %u", group); + return false; + } + + // Configure the timer if we're using a new one + ledc_timer_config_t ledc_timer; + memset((void *)&ledc_timer, 0, sizeof(ledc_timer_config_t)); + ledc_timer.speed_mode = group; + ledc_timer.timer_num = timer; + ledc_timer.duty_resolution = resolution; + ledc_timer.freq_hz = freq; + ledc_timer.clk_cfg = clock_source; + + if (ledc_timer_config(&ledc_timer) != ESP_OK) { + log_e("ledc setup failed!"); + return false; + } } - uint32_t duty = ledc_get_duty(group, (channel % 8)); + uint32_t duty = ledc_get_duty(group, (channel % SOC_LEDC_CHANNEL_NUM)); + + ledc_channel_config_t ledc_channel; + memset((void *)&ledc_channel, 0, sizeof(ledc_channel_config_t)); + ledc_channel.speed_mode = group; + ledc_channel.channel = (channel % SOC_LEDC_CHANNEL_NUM); + ledc_channel.timer_sel = timer; + ledc_channel.intr_type = LEDC_INTR_DISABLE; + ledc_channel.gpio_num = pin; + ledc_channel.duty = duty; + ledc_channel.hpoint = 0; - ledc_channel_config_t ledc_channel = { - .speed_mode = group, .channel = (channel % 8), .timer_sel = timer, .intr_type = LEDC_INTR_DISABLE, .gpio_num = pin, .duty = duty, .hpoint = 0 - }; ledc_channel_config(&ledc_channel); } ledc_channel_handle_t *handle = (ledc_channel_handle_t *)malloc(sizeof(ledc_channel_handle_t)); handle->pin = pin; handle->channel = channel; + handle->timer_num = timer; + handle->freq_hz = freq; #ifndef SOC_LEDC_SUPPORT_FADE_STOP handle->lock = NULL; #endif @@ -158,7 +277,7 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c ledc_handle.used_channels |= 1UL << channel; } - if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_LEDC, (void *)handle, group, channel)) { + if (!perimanSetPinBus(pin, ESP32_BUS_TYPE_LEDC, (void *)handle, channel, timer)) { ledcDetachBus((void *)handle); return false; } @@ -175,14 +294,40 @@ bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) { } uint8_t channel = __builtin_ctz(free_channel); // Convert the free_channel bit to channel number - return ledcAttachChannel(pin, freq, resolution, channel); + // Try the first available channel + if (ledcAttachChannel(pin, freq, resolution, channel)) { + return true; + } + +#ifdef SOC_LEDC_SUPPORT_HS_MODE + // If first attempt failed and HS mode is supported, try to find a free channel in group 1 + if ((channel / SOC_LEDC_CHANNEL_NUM) == 0) { // First attempt was in group 0 + log_d("LEDC: Group 0 channel %u failed, trying to find a free channel in group 1", channel); + // Find free channels specifically in group 1 + uint32_t group1_mask = ((1UL << SOC_LEDC_CHANNEL_NUM) - 1) << SOC_LEDC_CHANNEL_NUM; + int group1_free_channel = (~ledc_handle.used_channels) & group1_mask; + if (group1_free_channel != 0) { + uint8_t group1_channel = __builtin_ctz(group1_free_channel); + if (ledcAttachChannel(pin, freq, resolution, group1_channel)) { + return true; + } + } + } +#endif + + log_e( + "No free timers available for freq=%u, resolution=%u. To attach a new channel, use the same frequency and resolution as an already attached channel to " + "share its timer.", + freq, resolution + ); + return false; } bool ledcWrite(uint8_t pin, uint32_t duty) { ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); if (bus != NULL) { - uint8_t group = (bus->channel / 8), channel = (bus->channel % 8); + uint8_t group = (bus->channel / SOC_LEDC_CHANNEL_NUM), channel = (bus->channel % SOC_LEDC_CHANNEL_NUM); //Fixing if all bits in resolution is set = LEDC FULL ON uint32_t max_duty = (1 << bus->channel_resolution) - 1; @@ -191,8 +336,14 @@ bool ledcWrite(uint8_t pin, uint32_t duty) { duty = max_duty + 1; } - ledc_set_duty(group, channel, duty); - ledc_update_duty(group, channel); + if (ledc_set_duty(group, channel, duty) != ESP_OK) { + log_e("ledc_set_duty failed"); + return false; + } + if (ledc_update_duty(group, channel) != ESP_OK) { + log_e("ledc_update_duty failed"); + return false; + } return true; } @@ -205,7 +356,11 @@ bool ledcWriteChannel(uint8_t channel, uint32_t duty) { log_e("Channel %u is not available (maximum %u) or not used!", channel, LEDC_CHANNELS); return false; } - uint8_t group = (channel / 8), timer = ((channel / 2) % 4); + uint8_t group = (channel / SOC_LEDC_CHANNEL_NUM); + ledc_timer_t timer; + + // Get the actual timer being used by this channel + ledc_ll_get_channel_timer(LEDC_LL_GET_HW(), group, (channel % SOC_LEDC_CHANNEL_NUM), &timer); //Fixing if all bits in resolution is set = LEDC FULL ON uint32_t resolution = 0; @@ -217,8 +372,14 @@ bool ledcWriteChannel(uint8_t channel, uint32_t duty) { duty = max_duty + 1; } - ledc_set_duty(group, channel, duty); - ledc_update_duty(group, channel); + if (ledc_set_duty(group, channel, duty) != ESP_OK) { + log_e("ledc_set_duty failed"); + return false; + } + if (ledc_update_duty(group, channel) != ESP_OK) { + log_e("ledc_update_duty failed"); + return false; + } return true; } @@ -227,7 +388,7 @@ uint32_t ledcRead(uint8_t pin) { ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); if (bus != NULL) { - uint8_t group = (bus->channel / 8), channel = (bus->channel % 8); + uint8_t group = (bus->channel / SOC_LEDC_CHANNEL_NUM), channel = (bus->channel % SOC_LEDC_CHANNEL_NUM); return ledc_get_duty(group, channel); } return 0; @@ -239,8 +400,8 @@ uint32_t ledcReadFreq(uint8_t pin) { if (!ledcRead(pin)) { return 0; } - uint8_t group = (bus->channel / 8), timer = ((bus->channel / 2) % 4); - return ledc_get_freq(group, timer); + uint8_t group = (bus->channel / SOC_LEDC_CHANNEL_NUM); + return ledc_get_freq(group, bus->timer_num); } return 0; } @@ -254,9 +415,15 @@ uint32_t ledcWriteTone(uint8_t pin, uint32_t freq) { return 0; } - uint8_t group = (bus->channel / 8), timer = ((bus->channel / 2) % 4); + uint8_t group = (bus->channel / SOC_LEDC_CHANNEL_NUM); - ledc_timer_config_t ledc_timer = {.speed_mode = group, .timer_num = timer, .duty_resolution = 10, .freq_hz = freq, .clk_cfg = clock_source}; + ledc_timer_config_t ledc_timer; + memset((void *)&ledc_timer, 0, sizeof(ledc_timer_config_t)); + ledc_timer.speed_mode = group; + ledc_timer.timer_num = bus->timer_num; + ledc_timer.duty_resolution = 10; + ledc_timer.freq_hz = freq; + ledc_timer.clk_cfg = clock_source; if (ledc_timer_config(&ledc_timer) != ESP_OK) { log_e("ledcWriteTone configuration failed!"); @@ -264,7 +431,7 @@ uint32_t ledcWriteTone(uint8_t pin, uint32_t freq) { } bus->channel_resolution = 10; - uint32_t res_freq = ledc_get_freq(group, timer); + uint32_t res_freq = ledc_get_freq(group, bus->timer_num); ledcWrite(pin, 0x1FF); return res_freq; } @@ -305,16 +472,22 @@ uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution) { log_e("LEDC pin %u - resolution is zero or it is too big (maximum %u)", pin, LEDC_MAX_BIT_WIDTH); return 0; } - uint8_t group = (bus->channel / 8), timer = ((bus->channel / 2) % 4); + uint8_t group = (bus->channel / SOC_LEDC_CHANNEL_NUM); - ledc_timer_config_t ledc_timer = {.speed_mode = group, .timer_num = timer, .duty_resolution = resolution, .freq_hz = freq, .clk_cfg = clock_source}; + ledc_timer_config_t ledc_timer; + memset((void *)&ledc_timer, 0, sizeof(ledc_timer_config_t)); + ledc_timer.speed_mode = group; + ledc_timer.timer_num = bus->timer_num; + ledc_timer.duty_resolution = resolution; + ledc_timer.freq_hz = freq; + ledc_timer.clk_cfg = clock_source; if (ledc_timer_config(&ledc_timer) != ESP_OK) { log_e("ledcChangeFrequency failed!"); return 0; } bus->channel_resolution = resolution; - return ledc_get_freq(group, timer); + return ledc_get_freq(group, bus->timer_num); } return 0; } @@ -325,12 +498,14 @@ bool ledcOutputInvert(uint8_t pin, bool out_invert) { gpio_set_level(pin, out_invert); #ifdef CONFIG_IDF_TARGET_ESP32P4 - esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT_PAD_OUT0_IDX + ((bus->channel) % 8), out_invert, 0); + esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT_PAD_OUT0_IDX + ((bus->channel) % SOC_LEDC_CHANNEL_NUM), out_invert, 0); #else #ifdef SOC_LEDC_SUPPORT_HS_MODE - esp_rom_gpio_connect_out_signal(pin, ((bus->channel / 8 == 0) ? LEDC_HS_SIG_OUT0_IDX : LEDC_LS_SIG_OUT0_IDX) + ((bus->channel) % 8), out_invert, 0); + esp_rom_gpio_connect_out_signal( + pin, ((bus->channel / SOC_LEDC_CHANNEL_NUM == 0) ? LEDC_HS_SIG_OUT0_IDX : LEDC_LS_SIG_OUT0_IDX) + ((bus->channel) % SOC_LEDC_CHANNEL_NUM), out_invert, 0 + ); #else - esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT0_IDX + ((bus->channel) % 8), out_invert, 0); + esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT0_IDX + ((bus->channel) % SOC_LEDC_CHANNEL_NUM), out_invert, 0); #endif #endif // ifdef CONFIG_IDF_TARGET_ESP32P4 return true; @@ -377,7 +552,7 @@ static bool ledcFadeConfig(uint8_t pin, uint32_t start_duty, uint32_t target_dut } #endif #endif - uint8_t group = (bus->channel / 8), channel = (bus->channel % 8); + uint8_t group = (bus->channel / SOC_LEDC_CHANNEL_NUM), channel = (bus->channel % SOC_LEDC_CHANNEL_NUM); // Initialize fade service. if (!fade_initialized) { @@ -434,6 +609,161 @@ bool ledcFadeWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_ return ledcFadeConfig(pin, start_duty, target_duty, max_fade_time_ms, userFunc, arg); } +#ifdef SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED +// Default gamma factor for gamma correction (common value for LEDs) +static float ledcGammaFactor = 2.8; +// Gamma correction LUT support +static const float *ledcGammaLUT = NULL; +static uint16_t ledcGammaLUTSize = 0; +// Global variable to store current resolution for gamma callback +static uint8_t ledcGammaResolution = 13; + +bool ledcSetGammaTable(const float *gamma_table, uint16_t size) { + if (gamma_table == NULL || size == 0) { + log_e("Invalid gamma table or size"); + return false; + } + ledcGammaLUT = gamma_table; + ledcGammaLUTSize = size; + log_i("Custom gamma LUT set with %u entries", size); + return true; +} + +void ledcClearGammaTable(void) { + ledcGammaLUT = NULL; + ledcGammaLUTSize = 0; + log_i("Gamma LUT cleared, using mathematical calculation"); +} + +void ledcSetGammaFactor(float factor) { + ledcGammaFactor = factor; +} + +// Gamma correction calculator function +static uint32_t ledcGammaCorrection(uint32_t duty) { + if (duty == 0) { + return 0; + } + + uint32_t max_duty = (1U << ledcGammaResolution) - 1; + if (duty >= (1U << ledcGammaResolution)) { + return max_duty; + } + + // Use LUT if provided, otherwise use mathematical calculation + if (ledcGammaLUT != NULL && ledcGammaLUTSize > 0) { + // LUT-based gamma correction + uint32_t lut_index = (duty * (ledcGammaLUTSize - 1)) / max_duty; + if (lut_index >= ledcGammaLUTSize) { + lut_index = ledcGammaLUTSize - 1; + } + + float corrected_normalized = ledcGammaLUT[lut_index]; + return (uint32_t)(corrected_normalized * max_duty); + } else { + // Mathematical gamma correction + double normalized = (double)duty / (1U << ledcGammaResolution); + double corrected = pow(normalized, ledcGammaFactor); + return (uint32_t)(corrected * (1U << ledcGammaResolution)); + } +} + +static bool ledcFadeGammaConfig(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void *), void *arg) { + ledc_channel_handle_t *bus = (ledc_channel_handle_t *)perimanGetPinBus(pin, ESP32_BUS_TYPE_LEDC); + if (bus != NULL) { + +#ifndef SOC_LEDC_SUPPORT_FADE_STOP +#if !CONFIG_DISABLE_HAL_LOCKS + if (bus->lock == NULL) { + bus->lock = xSemaphoreCreateBinary(); + if (bus->lock == NULL) { + log_e("xSemaphoreCreateBinary failed"); + return false; + } + xSemaphoreGive(bus->lock); + } + //acquire lock + if (xSemaphoreTake(bus->lock, 0) != pdTRUE) { + log_e("LEDC Fade is still running on pin %u! SoC does not support stopping fade.", pin); + return false; + } +#endif +#endif + uint8_t group = (bus->channel / SOC_LEDC_CHANNEL_NUM), channel = (bus->channel % SOC_LEDC_CHANNEL_NUM); + + // Initialize fade service. + if (!fade_initialized) { + ledc_fade_func_install(0); + fade_initialized = true; + } + + bus->fn = (voidFuncPtr)userFunc; + bus->arg = arg; + + ledc_cbs_t callbacks = {.fade_cb = ledcFnWrapper}; + ledc_cb_register(group, channel, &callbacks, (void *)bus); + + // Prepare gamma curve fade parameters + ledc_fade_param_config_t fade_params[SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX]; + uint32_t actual_fade_ranges = 0; + + // Use a moderate number of linear segments for smooth gamma curve + const uint32_t linear_fade_segments = 12; + + // Set the global resolution for gamma correction + ledcGammaResolution = bus->channel_resolution; + + // Fill multi-fade parameter list using ESP-IDF API + esp_err_t err = ledc_fill_multi_fade_param_list( + group, channel, start_duty, target_duty, linear_fade_segments, max_fade_time_ms, ledcGammaCorrection, SOC_LEDC_GAMMA_CURVE_FADE_RANGE_MAX, fade_params, + &actual_fade_ranges + ); + + if (err != ESP_OK) { + log_e("ledc_fill_multi_fade_param_list failed: %s", esp_err_to_name(err)); + return false; + } + + // Apply the gamma-corrected start duty + uint32_t gamma_start_duty = ledcGammaCorrection(start_duty); + + // Set multi-fade parameters + err = ledc_set_multi_fade(group, channel, gamma_start_duty, fade_params, actual_fade_ranges); + if (err != ESP_OK) { + log_e("ledc_set_multi_fade failed: %s", esp_err_to_name(err)); + return false; + } + + // Start the gamma curve fade + err = ledc_fade_start(group, channel, LEDC_FADE_NO_WAIT); + if (err != ESP_OK) { + log_e("ledc_fade_start failed: %s", esp_err_to_name(err)); + return false; + } + + log_d("Gamma curve fade started on pin %u: %u -> %u over %dms", pin, start_duty, target_duty, max_fade_time_ms); + + } else { + log_e("Pin %u is not attached to LEDC. Call ledcAttach first!", pin); + return false; + } + return true; +} + +bool ledcFadeGamma(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms) { + return ledcFadeGammaConfig(pin, start_duty, target_duty, max_fade_time_ms, NULL, NULL); +} + +bool ledcFadeGammaWithInterrupt(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, voidFuncPtr userFunc) { + return ledcFadeGammaConfig(pin, start_duty, target_duty, max_fade_time_ms, (voidFuncPtrArg)userFunc, NULL); +} + +bool ledcFadeGammaWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void *), void *arg) { + return ledcFadeGammaConfig(pin, start_duty, target_duty, max_fade_time_ms, userFunc, arg); +} + +#endif /* SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED */ + static uint8_t analog_resolution = 8; static int analog_frequency = 1000; void analogWrite(uint8_t pin, int value) { diff --git a/cores/esp32/esp32-hal-ledc.h b/cores/esp32/esp32-hal-ledc.h index 5b44aaad452..1663b884a3f 100644 --- a/cores/esp32/esp32-hal-ledc.h +++ b/cores/esp32/esp32-hal-ledc.h @@ -51,6 +51,8 @@ typedef struct { uint8_t pin; // Pin assigned to channel uint8_t channel; // Channel number uint8_t channel_resolution; // Resolution of channel + uint8_t timer_num; // Timer number used by this channel + uint32_t freq_hz; // Frequency configured for this channel voidFuncPtr fn; void *arg; #ifndef SOC_LEDC_SUPPORT_FADE_STOP @@ -230,6 +232,85 @@ bool ledcFadeWithInterrupt(uint8_t pin, uint32_t start_duty, uint32_t target_dut */ bool ledcFadeWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void *), void *arg); +//Gamma Curve Fade functions - only available on supported chips +#ifdef SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED + +/** + * @brief Set a custom gamma correction lookup table for gamma curve fading. + * The LUT should contain normalized values (0.0 to 1.0) representing + * the gamma-corrected brightness curve. + * + * @param gamma_table Pointer to array of float values (0.0 to 1.0) + * @param size Number of entries in the lookup table + * + * @return true if gamma table was successfully set, false otherwise. + * + * @note The LUT array must remain valid for as long as gamma fading is used. + * Larger tables provide smoother transitions but use more memory. + */ +bool ledcSetGammaTable(const float *gamma_table, uint16_t size); + +/** + * @brief Clear the current gamma correction lookup table. + * After calling this, gamma correction will use mathematical + * calculation with the default gamma factor (2.8). + */ +void ledcClearGammaTable(void); + +/** + * @brief Set the gamma factor for gamma correction. + * + * @param factor Gamma factor to use for gamma correction. + */ +void ledcSetGammaFactor(float factor); + +/** + * @brief Setup and start a gamma curve fade on a given LEDC pin. + * Gamma correction makes LED brightness changes appear more gradual to human eyes. + * + * @param pin GPIO pin + * @param start_duty initial duty cycle of the fade + * @param target_duty target duty cycle of the fade + * @param max_fade_time_ms maximum fade time in milliseconds + * + * @return true if gamma fade was successfully set and started, false otherwise. + * + * @note This function is only available on ESP32 variants that support gamma curve fading. + */ +bool ledcFadeGamma(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms); + +/** + * @brief Setup and start a gamma curve fade on a given LEDC pin with a callback function. + * + * @param pin GPIO pin + * @param start_duty initial duty cycle of the fade + * @param target_duty target duty cycle of the fade + * @param max_fade_time_ms maximum fade time in milliseconds + * @param userFunc callback function to be called after fade is finished + * + * @return true if gamma fade was successfully set and started, false otherwise. + * + * @note This function is only available on ESP32 variants that support gamma curve fading. + */ +bool ledcFadeGammaWithInterrupt(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void)); + +/** + * @brief Setup and start a gamma curve fade on a given LEDC pin with a callback function and argument. + * + * @param pin GPIO pin + * @param start_duty initial duty cycle of the fade + * @param target_duty target duty cycle of the fade + * @param max_fade_time_ms maximum fade time in milliseconds + * @param userFunc callback function to be called after fade is finished + * @param arg argument to be passed to the callback function + * + * @return true if gamma fade was successfully set and started, false otherwise. + * + * @note This function is only available on ESP32 variants that support gamma curve fading. + */ +bool ledcFadeGammaWithInterruptArg(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void *), void *arg); +#endif // SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED + #ifdef __cplusplus } #endif diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 50e2973d27a..aadd08ceffc 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -25,9 +25,9 @@ #include "esp_ota_ops.h" #endif //CONFIG_APP_ROLLBACK_ENABLE #include "esp_private/startup_internal.h" -#if defined(CONFIG_BT_ENABLED) && SOC_BT_SUPPORTED +#if defined(CONFIG_BT_BLUEDROID_ENABLED) && SOC_BT_SUPPORTED && __has_include("esp_bt.h") #include "esp_bt.h" -#endif //CONFIG_BT_ENABLED +#endif //CONFIG_BT_BLUEDROID_ENABLED #include #include "soc/rtc.h" #if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4) @@ -243,7 +243,7 @@ bool verifyRollbackLater() { } #endif -#ifdef CONFIG_BT_ENABLED +#ifdef CONFIG_BT_BLUEDROID_ENABLED #if CONFIG_IDF_TARGET_ESP32 //overwritten in esp32-hal-bt.c bool btInUse() __attribute__((weak)); @@ -305,7 +305,7 @@ void initArduino() { if (err) { log_e("Failed to initialize NVS! Error: %u", err); } -#if defined(CONFIG_BT_ENABLED) && SOC_BT_SUPPORTED +#if defined(CONFIG_BT_BLUEDROID_ENABLED) && SOC_BT_SUPPORTED if (!btInUse()) { esp_bt_controller_mem_release(ESP_BT_MODE_BTDM); } diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index e3877b5ff48..7bca1a1b529 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -206,7 +206,8 @@ bool rmtSetCarrier(int pin, bool carrier_en, bool carrier_level, uint32_t freque log_w("GPIO %d - RMT Carrier must be a float percentage from 0 to 1. Setting to 50%.", pin); duty_percent = 0.5; } - rmt_carrier_config_t carrier_cfg = {0}; + rmt_carrier_config_t carrier_cfg; + memset((void *)&carrier_cfg, 0, sizeof(rmt_carrier_config_t)); carrier_cfg.duty_cycle = duty_percent; // duty cycle carrier_cfg.frequency_hz = carrier_en ? frequency_Hz : 0; // carrier frequency in Hz carrier_cfg.flags.polarity_active_low = carrier_level; // carrier modulation polarity level @@ -313,7 +314,8 @@ static bool _rmtWrite(int pin, rmt_data_t *data, size_t num_rmt_symbols, bool bl return false; } - rmt_transmit_config_t transmit_cfg = {0}; // loop mode disabled + rmt_transmit_config_t transmit_cfg; // loop mode disabled + memset((void *)&transmit_cfg, 0, sizeof(rmt_transmit_config_t)); bool retCode = true; RMT_MUTEX_LOCK(bus); @@ -380,6 +382,7 @@ static bool _rmtRead(int pin, rmt_data_t *data, size_t *num_rmt_symbols, bool wa // request reading RMT Channel Data rmt_receive_config_t receive_config; + memset((void *)&receive_config, 0, sizeof(rmt_receive_config_t)); receive_config.signal_range_min_ns = bus->signal_range_min_ns; receive_config.signal_range_max_ns = bus->signal_range_max_ns; @@ -530,6 +533,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_ if (channel_direction == RMT_TX_MODE) { // TX Channel rmt_tx_channel_config_t tx_cfg; + memset((void *)&tx_cfg, 0, sizeof(rmt_tx_channel_config_t)); tx_cfg.gpio_num = pin; // CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F80M for C6 -- CLK_XTAL for H2 tx_cfg.clk_src = RMT_CLK_SRC_DEFAULT; @@ -559,6 +563,7 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_ } else { // RX Channel rmt_rx_channel_config_t rx_cfg; + memset((void *)&rx_cfg, 0, sizeof(rmt_rx_channel_config_t)); rx_cfg.gpio_num = pin; // CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F80M for C6 -- CLK_XTAL for H2 rx_cfg.clk_src = RMT_CLK_SRC_DEFAULT; @@ -585,7 +590,8 @@ bool rmtInit(int pin, rmt_ch_dir_t channel_direction, rmt_reserve_memsize_t mem_ } // allocate memory for the RMT Copy encoder - rmt_copy_encoder_config_t copy_encoder_config = {}; + rmt_copy_encoder_config_t copy_encoder_config; + memset((void *)©_encoder_config, 0, sizeof(rmt_copy_encoder_config_t)); if (rmt_new_copy_encoder(©_encoder_config, &bus->rmt_copy_encoder_h) != ESP_OK) { log_e("GPIO %d - RMT Encoder Memory Allocation error.", pin); goto Err; diff --git a/cores/esp32/esp32-hal-spi.c b/cores/esp32/esp32-hal-spi.c index 80928309670..d39aceb5f8d 100644 --- a/cores/esp32/esp32-hal-spi.c +++ b/cores/esp32/esp32-hal-spi.c @@ -74,20 +74,20 @@ struct spi_struct_t { int8_t miso; int8_t mosi; int8_t ss; + bool ss_invert; }; #if CONFIG_IDF_TARGET_ESP32S2 // ESP32S2 -#define SPI_COUNT (3) +#define SPI_COUNT (2) -#define SPI_CLK_IDX(p) ((p == 0) ? SPICLK_OUT_MUX_IDX : ((p == 1) ? FSPICLK_OUT_MUX_IDX : ((p == 2) ? SPI3_CLK_OUT_MUX_IDX : 0))) -#define SPI_MISO_IDX(p) ((p == 0) ? SPIQ_OUT_IDX : ((p == 1) ? FSPIQ_OUT_IDX : ((p == 2) ? SPI3_Q_OUT_IDX : 0))) -#define SPI_MOSI_IDX(p) ((p == 0) ? SPID_IN_IDX : ((p == 1) ? FSPID_IN_IDX : ((p == 2) ? SPI3_D_IN_IDX : 0))) +#define SPI_CLK_IDX(p) ((p == 0) ? FSPICLK_OUT_MUX_IDX : ((p == 1) ? SPI3_CLK_OUT_MUX_IDX : 0)) +#define SPI_MISO_IDX(p) ((p == 0) ? FSPIQ_OUT_IDX : ((p == 1) ? SPI3_Q_OUT_IDX : 0)) +#define SPI_MOSI_IDX(p) ((p == 0) ? FSPID_IN_IDX : ((p == 1) ? SPI3_D_IN_IDX : 0)) -#define SPI_SPI_SS_IDX(n) ((n == 0) ? SPICS0_OUT_IDX : ((n == 1) ? SPICS1_OUT_IDX : 0)) -#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS0_OUT_IDX : ((n == 1) ? SPI3_CS1_OUT_IDX : ((n == 2) ? SPI3_CS2_OUT_IDX : SPI3_CS0_OUT_IDX))) -#define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : ((n == 2) ? FSPICS2_OUT_IDX : FSPICS0_OUT_IDX))) -#define SPI_SS_IDX(p, n) ((p == 0) ? SPI_SPI_SS_IDX(n) : ((p == 1) ? SPI_SPI_SS_IDX(n) : ((p == 2) ? SPI_HSPI_SS_IDX(n) : 0))) +#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS0_OUT_IDX : ((n == 1) ? SPI3_CS1_OUT_IDX : ((n == 2) ? SPI3_CS2_OUT_IDX : 0))) +#define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : ((n == 2) ? FSPICS2_OUT_IDX : 0))) +#define SPI_SS_IDX(p, n) ((p == 0) ? SPI_FSPI_SS_IDX(n) : ((p == 1) ? SPI_HSPI_SS_IDX(n) : 0)) #elif CONFIG_IDF_TARGET_ESP32S3 // ESP32S3 @@ -97,8 +97,8 @@ struct spi_struct_t { #define SPI_MISO_IDX(p) ((p == 0) ? FSPIQ_OUT_IDX : ((p == 1) ? SPI3_Q_OUT_IDX : 0)) #define SPI_MOSI_IDX(p) ((p == 0) ? FSPID_IN_IDX : ((p == 1) ? SPI3_D_IN_IDX : 0)) -#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS0_OUT_IDX : ((n == 1) ? SPI3_CS1_OUT_IDX : 0)) -#define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : 0)) +#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS0_OUT_IDX : ((n == 1) ? SPI3_CS1_OUT_IDX : ((n == 2) ? SPI3_CS2_OUT_IDX : 0))) +#define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : ((n == 2) ? FSPICS2_OUT_IDX : 0))) #define SPI_SS_IDX(p, n) ((p == 0) ? SPI_FSPI_SS_IDX(n) : ((p == 1) ? SPI_HSPI_SS_IDX(n) : 0)) #elif CONFIG_IDF_TARGET_ESP32P4 @@ -150,24 +150,20 @@ struct spi_struct_t { #define SPI_MUTEX_UNLOCK() // clang-format off static spi_t _spi_bus_array[] = { -#if CONFIG_IDF_TARGET_ESP32S2 - {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 1, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 2, -1, -1, -1, -1} -#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1, -1, -1, -1, -1} +#if CONFIG_IDF_TARGET_ESP32S2 ||CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4 + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1, false}, + {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1, -1, -1, -1, -1, false} #elif CONFIG_IDF_TARGET_ESP32C2 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1} + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1, false} #elif CONFIG_IDF_TARGET_ESP32C3 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1} + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1, false} #elif CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - {(spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1} + {(spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1, false} #else - {(volatile spi_dev_t *)(DR_REG_SPI0_BASE), 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 1, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 2, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 3, -1, -1, -1, -1} + {(volatile spi_dev_t *)(DR_REG_SPI0_BASE), 0, -1, -1, -1, -1, false}, + {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 1, -1, -1, -1, -1, false}, + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 2, -1, -1, -1, -1, false}, + {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 3, -1, -1, -1, -1, false} #endif }; // clang-format on @@ -178,23 +174,19 @@ static spi_t _spi_bus_array[] = { #define SPI_MUTEX_UNLOCK() xSemaphoreGive(spi->lock) static spi_t _spi_bus_array[] = { -#if CONFIG_IDF_TARGET_ESP32S2 - {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 1, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 2, -1, -1, -1, -1} -#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1, -1, -1, -1, -1} +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4 + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1, false}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1, -1, -1, -1, -1, false} #elif CONFIG_IDF_TARGET_ESP32C2 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1} + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1, false} #elif CONFIG_IDF_TARGET_ESP32C3 - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1} + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1, false} #elif CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 - {(spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1} + {(spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1, false} #else - {(volatile spi_dev_t *)(DR_REG_SPI0_BASE), NULL, 0, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 1, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 2, -1, -1, -1, -1}, - {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 3, -1, -1, -1, -1} + {(volatile spi_dev_t *)(DR_REG_SPI0_BASE), NULL, 0, -1, -1, -1, -1, false}, + {(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 1, -1, -1, -1, -1, false}, + {(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 2, -1, -1, -1, -1, false}, + {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 3, -1, -1, -1, -1, false} #endif }; #endif @@ -365,7 +357,7 @@ bool spiAttachSS(spi_t *spi, uint8_t ss_num, int8_t ss) { return false; } pinMode(ss, OUTPUT); - pinMatrixOutAttach(ss, SPI_SS_IDX(spi->num, ss_num), false, false); + pinMatrixOutAttach(ss, SPI_SS_IDX(spi->num, ss_num), spi->ss_invert, false); spiEnableSSPins(spi, (1 << ss_num)); spi->ss = ss; if (!perimanSetPinBus(ss, ESP32_BUS_TYPE_SPI_MASTER_SS, (void *)(spi->num + 1), spi->num, -1)) { @@ -435,6 +427,12 @@ void spiSSDisable(spi_t *spi) { SPI_MUTEX_UNLOCK(); } +void spiSSInvert(spi_t *spi, bool invert) { + if (spi) { + spi->ss_invert = invert; + } +} + void spiSSSet(spi_t *spi) { if (!spi) { return; @@ -614,6 +612,7 @@ void spiStopBus(spi_t *spi) { spi_t *spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder) { if (spi_num >= SPI_COUNT) { + log_e("SPI bus index %d is out of range", spi_num); return NULL; } diff --git a/cores/esp32/esp32-hal-spi.h b/cores/esp32/esp32-hal-spi.h index b77abff7854..0284fea8829 100644 --- a/cores/esp32/esp32-hal-spi.h +++ b/cores/esp32/esp32-hal-spi.h @@ -27,19 +27,13 @@ extern "C" { #include #define SPI_HAS_TRANSACTION - -#ifdef CONFIG_IDF_TARGET_ESP32S2 -#define FSPI 1 //SPI 1 bus. ESP32S2: for external memory only (can use the same data lines but different SS) -#define HSPI 2 //SPI 2 bus. ESP32S2: external memory or device - it can be matrixed to any pins -#define SPI2 2 // Another name for ESP32S2 SPI 2 -#define SPI3 3 //SPI 3 bus. ESP32S2: device only - it can be matrixed to any pins -#elif CONFIG_IDF_TARGET_ESP32 +#ifdef CONFIG_IDF_TARGET_ESP32 #define FSPI 1 //SPI 1 bus attached to the flash (can use the same data lines but different SS) #define HSPI 2 //SPI 2 bus normally mapped to pins 12 - 15, but can be matrixed to any pins #define VSPI 3 //SPI 3 bus normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins #else -#define FSPI 0 -#define HSPI 1 +#define FSPI 0 // ESP32C2, C3, C6, H2, S2, S3, P4 - SPI 2 bus +#define HSPI 1 // ESP32S2, S3, P4 - SPI 3 bus #endif // This defines are not representing the real Divider of the ESP32 @@ -97,6 +91,8 @@ void spiSSSet(spi_t *spi); void spiSSClear(spi_t *spi); void spiWaitReady(spi_t *spi); +//invert hardware SS +void spiSSInvert(spi_t *spi, bool invert); uint32_t spiGetClockDiv(spi_t *spi); uint8_t spiGetDataMode(spi_t *spi); diff --git a/cores/esp32/esp32-hal-tinyusb.c b/cores/esp32/esp32-hal-tinyusb.c index 0991e08d27f..30a827baa01 100644 --- a/cores/esp32/esp32-hal-tinyusb.c +++ b/cores/esp32/esp32-hal-tinyusb.c @@ -466,9 +466,6 @@ __attribute__((weak)) int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint __attribute__((weak)) int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize) { return -1; } -__attribute__((weak)) bool tud_msc_is_writable_cb(uint8_t lun) { - return false; -} #endif #if CFG_TUD_NCM __attribute__((weak)) bool tud_network_recv_cb(const uint8_t *src, uint16_t size) { diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 75e2da013ea..21fe88b57fb 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -32,10 +32,11 @@ #include "driver/gpio.h" #include "hal/gpio_hal.h" #include "esp_rom_gpio.h" +#include "esp_private/gpio.h" #include "driver/rtc_io.h" #include "driver/lp_io.h" -#include "soc/uart_periph.h" +#include "soc/uart_pins.h" #include "esp_private/uart_share_hw_ctrl.h" static int s_uart_debug_nr = 0; // UART number for debug output @@ -58,6 +59,7 @@ struct uart_struct_t { uint16_t _rx_buffer_size, _tx_buffer_size; // UART RX and TX buffer sizes bool _inverted; // UART inverted signal uint8_t _rxfifo_full_thrhd; // UART RX FIFO full threshold + int8_t _uart_clock_source; // UART Clock Source used when it is started using uartBegin() }; #if CONFIG_DISABLE_HAL_LOCKS @@ -66,21 +68,21 @@ struct uart_struct_t { #define UART_MUTEX_UNLOCK() static uart_t _uart_bus_array[] = { - {0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #if SOC_UART_NUM > 1 - {1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #endif #if SOC_UART_NUM > 2 - {2, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {2, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #endif #if SOC_UART_NUM > 3 - {3, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {3, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #endif #if SOC_UART_NUM > 4 - {4, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {4, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #endif #if SOC_UART_NUM > 5 - {5, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {5, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #endif }; @@ -95,21 +97,21 @@ static uart_t _uart_bus_array[] = { xSemaphoreGive(uart->lock) static uart_t _uart_bus_array[] = { - {NULL, 0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {NULL, 0, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #if SOC_UART_NUM > 1 - {NULL, 1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {NULL, 1, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #endif #if SOC_UART_NUM > 2 - {NULL, 2, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {NULL, 2, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #endif #if SOC_UART_NUM > 3 - {NULL, 3, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {NULL, 3, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #endif #if SOC_UART_NUM > 4 - {NULL, 4, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {NULL, 4, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #endif #if SOC_UART_NUM > 5 - {NULL, 5, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0}, + {NULL, 5, false, 0, NULL, -1, -1, -1, -1, 0, 0, 0, 0, false, 0, -1}, #endif }; @@ -293,6 +295,128 @@ static bool _uartDetachBus_RTS(void *busptr) { return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, bus->_rtsPin); } +static bool _uartTrySetIomuxPin(uart_port_t uart_num, int io_num, uint32_t idx) { + // Store a pointer to the default pin, to optimize access to its fields. + const uart_periph_sig_t *upin = &uart_periph_signal[uart_num].pins[idx]; + + // In theory, if default_gpio is -1, iomux_func should also be -1, but let's be safe and test both. + if (upin->iomux_func == -1 || upin->default_gpio == -1 || upin->default_gpio != io_num) { + return false; + } + + // Assign the correct function to the GPIO. + if (upin->iomux_func == -1) { + log_e("IO#%d has bad IOMUX internal information. Switching to GPIO Matrix UART function.", io_num); + return false; + } + if (uart_num < SOC_UART_HP_NUM) { + gpio_iomux_out(io_num, upin->iomux_func, false); + // If the pin is input, we also have to redirect the signal, in order to bypass the GPIO matrix. + if (upin->input) { + gpio_iomux_in(io_num, upin->signal); + } + } +#if (SOC_UART_LP_NUM >= 1) && (SOC_RTCIO_PIN_COUNT >= 1) + else { + if (upin->input) { + rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_INPUT_ONLY); + } else { + rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_OUTPUT_ONLY); + } + rtc_gpio_init(io_num); + rtc_gpio_iomux_func_sel(io_num, upin->iomux_func); + } +#endif + return true; +} + +static esp_err_t _uartInternalSetPin(uart_port_t uart_num, int tx_io_num, int rx_io_num, int rts_io_num, int cts_io_num) { + // Since an IO cannot route peripheral signals via IOMUX and GPIO matrix at the same time, + // if tx and rx share the same IO, both signals need to be routed to IOs through GPIO matrix + bool tx_rx_same_io = (tx_io_num == rx_io_num); + + // In the following statements, if the io_num is negative, no need to configure anything. + if (tx_io_num >= 0) { +#if CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND || CONFIG_PM_SLP_DISABLE_GPIO + // In such case, IOs are going to switch to sleep configuration (isolate) when entering sleep for power saving reason + // But TX IO in isolate state could write garbled data to the other end + // Therefore, we should disable the switch of the TX pin to sleep configuration + gpio_sleep_sel_dis(tx_io_num); +#endif + if (tx_rx_same_io || !_uartTrySetIomuxPin(uart_num, tx_io_num, SOC_UART_TX_PIN_IDX)) { + if (uart_num < SOC_UART_HP_NUM) { + gpio_func_sel(tx_io_num, PIN_FUNC_GPIO); + esp_rom_gpio_connect_out_signal(tx_io_num, UART_PERIPH_SIGNAL(uart_num, SOC_UART_TX_PIN_IDX), 0, 0); + // output enable is set inside esp_rom_gpio_connect_out_signal func after the signal is connected + // (output enabled too early may cause unnecessary level change at the pad) + } +#if SOC_LP_GPIO_MATRIX_SUPPORTED + else { + rtc_gpio_init(tx_io_num); // set as a LP_GPIO pin + lp_gpio_connect_out_signal(tx_io_num, UART_PERIPH_SIGNAL(uart_num, SOC_UART_TX_PIN_IDX), 0, 0); + // output enable is set inside lp_gpio_connect_out_signal func after the signal is connected + } +#endif + } + } + + if (rx_io_num >= 0) { +#if CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND || CONFIG_PM_SLP_DISABLE_GPIO + // In such case, IOs are going to switch to sleep configuration (isolate) when entering sleep for power saving reason + // But RX IO in isolate state could receive garbled data into FIFO, which is not desired + // Therefore, we should disable the switch of the RX pin to sleep configuration + gpio_sleep_sel_dis(rx_io_num); +#endif + if (tx_rx_same_io || !_uartTrySetIomuxPin(uart_num, rx_io_num, SOC_UART_RX_PIN_IDX)) { + if (uart_num < SOC_UART_HP_NUM) { + gpio_input_enable(rx_io_num); + esp_rom_gpio_connect_in_signal(rx_io_num, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), 0); + } +#if SOC_LP_GPIO_MATRIX_SUPPORTED + else { + rtc_gpio_mode_t mode = (tx_rx_same_io ? RTC_GPIO_MODE_INPUT_OUTPUT : RTC_GPIO_MODE_INPUT_ONLY); + rtc_gpio_set_direction(rx_io_num, mode); + if (!tx_rx_same_io) { // set the same pin again as a LP_GPIO will overwrite connected out_signal, not desired, so skip + rtc_gpio_init(rx_io_num); // set as a LP_GPIO pin + } + lp_gpio_connect_in_signal(rx_io_num, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), 0); + } +#endif + } + } + + if (rts_io_num >= 0 && !_uartTrySetIomuxPin(uart_num, rts_io_num, SOC_UART_RTS_PIN_IDX)) { + if (uart_num < SOC_UART_HP_NUM) { + gpio_func_sel(rts_io_num, PIN_FUNC_GPIO); + esp_rom_gpio_connect_out_signal(rts_io_num, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RTS_PIN_IDX), 0, 0); + // output enable is set inside esp_rom_gpio_connect_out_signal func after the signal is connected + } +#if SOC_LP_GPIO_MATRIX_SUPPORTED + else { + rtc_gpio_init(rts_io_num); // set as a LP_GPIO pin + lp_gpio_connect_out_signal(rts_io_num, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RTS_PIN_IDX), 0, 0); + // output enable is set inside lp_gpio_connect_out_signal func after the signal is connected + } +#endif + } + + if (cts_io_num >= 0 && !_uartTrySetIomuxPin(uart_num, cts_io_num, SOC_UART_CTS_PIN_IDX)) { + if (uart_num < SOC_UART_HP_NUM) { + gpio_pullup_en(cts_io_num); + gpio_input_enable(cts_io_num); + esp_rom_gpio_connect_in_signal(cts_io_num, UART_PERIPH_SIGNAL(uart_num, SOC_UART_CTS_PIN_IDX), 0); + } +#if SOC_LP_GPIO_MATRIX_SUPPORTED + else { + rtc_gpio_set_direction(cts_io_num, RTC_GPIO_MODE_INPUT_ONLY); + rtc_gpio_init(cts_io_num); // set as a LP_GPIO pin + lp_gpio_connect_in_signal(cts_io_num, UART_PERIPH_SIGNAL(uart_num, SOC_UART_CTS_PIN_IDX), 0); + } +#endif + } + return ESP_OK; +} + // Attach function for UART // connects the IO Pad, set Paripheral Manager and internal UART structure data static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin) { @@ -305,7 +429,7 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t //log_v("attaching UART%d pins: prev,new RX(%d,%d) TX(%d,%d) CTS(%d,%d) RTS(%d,%d)", uart_num, // uart->_rxPin, rxPin, uart->_txPin, txPin, uart->_ctsPin, ctsPin, uart->_rtsPin, rtsPin); vTaskDelay(10); - // IDF uart_set_pin() checks if the pin is used within LP UART and if it is a valid RTC IO pin + // IDF _uartInternalSetPin() checks if the pin is used within LP UART and if it is a valid RTC IO pin // No need for Arduino Layer to check it again bool retCode = true; if (rxPin >= 0) { @@ -314,7 +438,7 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t perimanClearPinBus(rxPin); } // connect RX Pad - bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + bool ret = ESP_OK == _uartInternalSetPin(uart->num, UART_PIN_NO_CHANGE, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); #if SOC_UART_LP_NUM >= 1 if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM ret &= lp_uart_config_io(uart->num, rxPin, RTC_GPIO_MODE_INPUT_ONLY, SOC_UART_RX_PIN_IDX); @@ -337,7 +461,7 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t perimanClearPinBus(txPin); } // connect TX Pad - bool ret = ESP_OK == uart_set_pin(uart->num, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + bool ret = ESP_OK == _uartInternalSetPin(uart->num, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); #if SOC_UART_LP_NUM >= 1 if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM ret &= lp_uart_config_io(uart->num, txPin, RTC_GPIO_MODE_OUTPUT_ONLY, SOC_UART_TX_PIN_IDX); @@ -360,7 +484,7 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t perimanClearPinBus(ctsPin); } // connect CTS Pad - bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, ctsPin); + bool ret = ESP_OK == _uartInternalSetPin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, ctsPin); #if SOC_UART_LP_NUM >= 1 if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM ret &= lp_uart_config_io(uart->num, ctsPin, RTC_GPIO_MODE_INPUT_ONLY, SOC_UART_CTS_PIN_IDX); @@ -383,7 +507,7 @@ static bool _uartAttachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t perimanClearPinBus(rtsPin); } // connect RTS Pad - bool ret = ESP_OK == uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin, UART_PIN_NO_CHANGE); + bool ret = ESP_OK == _uartInternalSetPin(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin, UART_PIN_NO_CHANGE); #if SOC_UART_LP_NUM >= 1 if (ret && uart_num >= SOC_UART_HP_NUM) { // it is a LP UART NUM ret &= lp_uart_config_io(uart->num, rtsPin, RTC_GPIO_MODE_OUTPUT_ONLY, SOC_UART_RTS_PIN_IDX); @@ -664,30 +788,40 @@ uart_t *uartBegin( rxfifo_full_thrhd = uart_config.rx_flow_ctrl_thresh; // makes sure that it will be set correctly in the struct uart_config.baud_rate = baudrate; #if SOC_UART_LP_NUM >= 1 - if (uart_nr >= SOC_UART_HP_NUM) { // it is a LP UART NUM - uart_config.lp_source_clk = LP_UART_SCLK_DEFAULT; // use default LP clock - log_v("Setting UART%d to use LP clock", uart_nr); + if (uart_nr >= SOC_UART_HP_NUM) { // it is a LP UART NUM + if (uart->_uart_clock_source > 0) { + uart_config.lp_source_clk = (soc_periph_lp_uart_clk_src_t)uart->_uart_clock_source; // use user defined LP UART clock + log_v("Setting UART%d to user defined LP clock source (%d) ", uart_nr, uart->_uart_clock_source); + } else { + uart_config.lp_source_clk = LP_UART_SCLK_DEFAULT; // use default LP clock + log_v("Setting UART%d to Default LP clock source", uart_nr); + } } else -#endif +#endif // SOC_UART_LP_NUM >= 1 { - // there is an issue when returning from light sleep with the C6 and H2: the uart baud rate is not restored - // therefore, uart clock source will set to XTAL for all SoC that support it. This fix solves the C6|H2 issue. + if (uart->_uart_clock_source >= 0) { + uart_config.source_clk = (soc_module_clk_t)uart->_uart_clock_source; // use user defined HP UART clock + log_v("Setting UART%d to user defined HP clock source (%d) ", uart_nr, uart->_uart_clock_source); + } else { + // there is an issue when returning from light sleep with the C6 and H2: the uart baud rate is not restored + // therefore, uart clock source will set to XTAL for all SoC that support it. This fix solves the C6|H2 issue. #if SOC_UART_SUPPORT_XTAL_CLK - uart_config.source_clk = UART_SCLK_XTAL; // valid for C2, S3, C3, C6, H2 and P4 - log_v("Setting UART%d to use XTAL clock", uart_nr); + uart_config.source_clk = UART_SCLK_XTAL; // valid for C2, S3, C3, C6, H2 and P4 + log_v("Setting UART%d to use XTAL clock", uart_nr); #elif SOC_UART_SUPPORT_REF_TICK - if (baudrate <= REF_TICK_BAUDRATE_LIMIT) { - uart_config.source_clk = UART_SCLK_REF_TICK; // valid for ESP32, S2 - MAX supported baud rate is 250 Kbps - log_v("Setting UART%d to use REF_TICK clock", uart_nr); - } else { - uart_config.source_clk = UART_SCLK_APB; // baudrate may change with the APB Frequency! - log_v("Setting UART%d to use APB clock", uart_nr); - } + if (baudrate <= REF_TICK_BAUDRATE_LIMIT) { + uart_config.source_clk = UART_SCLK_REF_TICK; // valid for ESP32, S2 - MAX supported baud rate is 250 Kbps + log_v("Setting UART%d to use REF_TICK clock", uart_nr); + } else { + uart_config.source_clk = UART_SCLK_APB; // baudrate may change with the APB Frequency! + log_v("Setting UART%d to use APB clock", uart_nr); + } #else - // Default CLK Source: CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F40M for C2 -- CLK_PLL_F48M for H2 -- CLK_PLL_F80M for C6 - uart_config.source_clk = UART_SCLK_DEFAULT; // baudrate may change with the APB Frequency! - log_v("Setting UART%d to use DEFAULT clock", uart_nr); -#endif + // Default CLK Source: CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F40M for C2 -- CLK_PLL_F48M for H2 -- CLK_PLL_F80M for C6|P4 + uart_config.source_clk = UART_SCLK_DEFAULT; // baudrate may change with the APB Frequency! + log_v("Setting UART%d to use DEFAULT clock", uart_nr); +#endif // SOC_UART_SUPPORT_XTAL_CLK + } } UART_MUTEX_LOCK(); @@ -716,6 +850,14 @@ uart_t *uartBegin( uart->_tx_buffer_size = tx_buffer_size; uart->has_peek = false; uart->peek_byte = 0; +#if SOC_UART_LP_NUM >= 1 + if (uart_nr >= SOC_UART_HP_NUM) { + uart->_uart_clock_source = uart_config.lp_source_clk; + } else +#endif + { + uart->_uart_clock_source = uart_config.source_clk; + } } UART_MUTEX_UNLOCK(); @@ -975,22 +1117,52 @@ bool uartSetBaudRate(uart_t *uart, uint32_t baud_rate) { return false; } bool retCode = true; - UART_MUTEX_LOCK(); -#if SOC_UART_SUPPORT_XTAL_CLK // ESP32-S3, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-H2 and ESP32-P4 - soc_module_clk_t newClkSrc = UART_SCLK_XTAL; + soc_module_clk_t newClkSrc = UART_SCLK_DEFAULT; + int8_t previousClkSrc = uart->_uart_clock_source; #if SOC_UART_LP_NUM >= 1 if (uart->num >= SOC_UART_HP_NUM) { // it is a LP UART NUM - newClkSrc = LP_UART_SCLK_DEFAULT; // use default LP clock + if (uart->_uart_clock_source > 0) { + newClkSrc = (soc_periph_lp_uart_clk_src_t)uart->_uart_clock_source; // use user defined LP UART clock + log_v("Setting UART%d to user defined LP clock source (%d) ", uart->num, newClkSrc); + } else { + newClkSrc = LP_UART_SCLK_DEFAULT; // use default LP clock + log_v("Setting UART%d to Default LP clock source", uart->num); + } + } else +#endif // SOC_UART_LP_NUM >= 1 + { + if (uart->_uart_clock_source >= 0) { + newClkSrc = (soc_module_clk_t)uart->_uart_clock_source; // use user defined HP UART clock + log_v("Setting UART%d to use HP clock source (%d) ", uart->num, newClkSrc); + } else { + // there is an issue when returning from light sleep with the C6 and H2: the uart baud rate is not restored + // therefore, uart clock source will set to XTAL for all SoC that support it. This fix solves the C6|H2 issue. +#if SOC_UART_SUPPORT_XTAL_CLK + newClkSrc = UART_SCLK_XTAL; // valid for C2, S3, C3, C6, H2 and P4 + log_v("Setting UART%d to use XTAL clock", uart->num); +#elif SOC_UART_SUPPORT_REF_TICK + if (baud_rate <= REF_TICK_BAUDRATE_LIMIT) { + newClkSrc = UART_SCLK_REF_TICK; // valid for ESP32, S2 - MAX supported baud rate is 250 Kbps + log_v("Setting UART%d to use REF_TICK clock", uart->num); + } else { + newClkSrc = UART_SCLK_APB; // baudrate may change with the APB Frequency! + log_v("Setting UART%d to use APB clock", uart->num); + } +#else + // Default CLK Source: CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F40M for C2 -- CLK_PLL_F48M for H2 -- CLK_PLL_F80M for C6|P4 + // using newClkSrc = UART_SCLK_DEFAULT as defined in the variable declaration + log_v("Setting UART%d to use DEFAULT clock", uart->num); +#endif // SOC_UART_SUPPORT_XTAL_CLK + } } -#endif - // ESP32-P4 demands an atomic operation for setting the clock source - HP_UART_SRC_CLK_ATOMIC() { - uart_ll_set_sclk(UART_LL_GET_HW(uart->num), newClkSrc); + UART_MUTEX_LOCK(); + // if necessary, set the correct UART Clock Source before changing the baudrate + if (previousClkSrc < 0 || previousClkSrc != newClkSrc) { + HP_UART_SRC_CLK_ATOMIC() { + uart_ll_set_sclk(UART_LL_GET_HW(uart->num), newClkSrc); + } + uart->_uart_clock_source = newClkSrc; } -#else // ESP32, ESP32-S2 - soc_module_clk_t newClkSrc = baud_rate <= REF_TICK_BAUDRATE_LIMIT ? SOC_MOD_CLK_REF_TICK : SOC_MOD_CLK_APB; - uart_ll_set_sclk(UART_LL_GET_HW(uart->num), newClkSrc); -#endif if (uart_set_baudrate(uart->num, baud_rate) == ESP_OK) { log_v("Setting UART%d baud rate to %ld.", uart->num, baud_rate); uart->_baudrate = baud_rate; @@ -1084,6 +1256,31 @@ bool uartSetMode(uart_t *uart, uart_mode_t mode) { return retCode; } +// this function will set the uart clock source +// it must be called before uartBegin(), otherwise it won't change any thing. +bool uartSetClockSource(uint8_t uartNum, uart_sclk_t clkSrc) { + if (uartNum >= SOC_UART_NUM) { + log_e("UART%d is invalid. This device has %d UARTs, from 0 to %d.", uartNum, SOC_UART_NUM, SOC_UART_NUM - 1); + return false; + } + uart_t *uart = &_uart_bus_array[uartNum]; +#if SOC_UART_LP_NUM >= 1 + if (uart->num >= SOC_UART_HP_NUM) { + switch (clkSrc) { + case UART_SCLK_XTAL: uart->_uart_clock_source = LP_UART_SCLK_XTAL_D2; break; + case UART_SCLK_RTC: uart->_uart_clock_source = LP_UART_SCLK_LP_FAST; break; + case UART_SCLK_DEFAULT: + default: uart->_uart_clock_source = LP_UART_SCLK_DEFAULT; + } + } else +#endif + { + uart->_uart_clock_source = clkSrc; + } + //log_i("UART%d set clock source to %d", uart->num, uart->_uart_clock_source); + return true; +} + void uartSetDebug(uart_t *uart) { // LP UART is not supported for debug if (uart == NULL || uart->num >= SOC_UART_HP_NUM) { @@ -1112,7 +1309,7 @@ int log_printfv(const char *format, va_list arg) { return 0; } } -/* + /* // This causes dead locks with logging in specific cases and also with C++ constructors that may send logs #if !CONFIG_DISABLE_HAL_LOCKS if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){ @@ -1120,16 +1317,8 @@ int log_printfv(const char *format, va_list arg) { } #endif */ -#if (ARDUINO_USB_CDC_ON_BOOT == 1 && ARDUINO_USB_MODE == 0) || CONFIG_IDF_TARGET_ESP32C3 \ - || ((CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32P4) && ARDUINO_USB_CDC_ON_BOOT == 1) vsnprintf(temp, len + 1, format, arg); ets_printf("%s", temp); -#else - int wlen = vsnprintf(temp, len + 1, format, arg); - for (int i = 0; i < wlen; i++) { - ets_write_char_uart(temp[i]); - } -#endif /* // This causes dead locks with logging and also with constructors that may send logs #if !CONFIG_DISABLE_HAL_LOCKS @@ -1317,39 +1506,9 @@ unsigned long uartDetectBaudrate(uart_t *uart) { } /* - These functions are for testing purpose only and can be used in Arduino Sketches - Those are used in the UART examples -*/ - -/* - This is intended to make an internal loopback connection using IOMUX - The function uart_internal_loopback() shall be used right after Arduino Serial.begin(...) - This code "replaces" the physical wiring for connecting TX <--> RX in a loopback -*/ - -// gets the right TX or RX SIGNAL, based on the UART number from gpio_sig_map.h -#ifdef CONFIG_IDF_TARGET_ESP32P4 -#define UART_TX_SIGNAL(uartNumber) \ - (uartNumber == UART_NUM_0 \ - ? UART0_TXD_PAD_OUT_IDX \ - : (uartNumber == UART_NUM_1 \ - ? UART1_TXD_PAD_OUT_IDX \ - : (uartNumber == UART_NUM_2 ? UART2_TXD_PAD_OUT_IDX : (uartNumber == UART_NUM_3 ? UART3_TXD_PAD_OUT_IDX : UART4_TXD_PAD_OUT_IDX)))) -#define UART_RX_SIGNAL(uartNumber) \ - (uartNumber == UART_NUM_0 \ - ? UART0_RXD_PAD_IN_IDX \ - : (uartNumber == UART_NUM_1 \ - ? UART1_RXD_PAD_IN_IDX \ - : (uartNumber == UART_NUM_2 ? UART2_RXD_PAD_IN_IDX : (uartNumber == UART_NUM_3 ? UART3_RXD_PAD_IN_IDX : UART4_RXD_PAD_IN_IDX)))) -#else -#if SOC_UART_HP_NUM > 2 -#define UART_TX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0TXD_OUT_IDX : (uartNumber == UART_NUM_1 ? U1TXD_OUT_IDX : U2TXD_OUT_IDX)) -#define UART_RX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0RXD_IN_IDX : (uartNumber == UART_NUM_1 ? U1RXD_IN_IDX : U2RXD_IN_IDX)) -#else -#define UART_TX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0TXD_OUT_IDX : U1TXD_OUT_IDX) -#define UART_RX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0RXD_IN_IDX : U1RXD_IN_IDX) -#endif -#endif // ifdef CONFIG_IDF_TARGET_ESP32P4 + * These functions are for testing purposes only and can be used in Arduino Sketches. + * They are utilized in the UART examples and CI. + */ /* This function internally binds defined UARTs TX signal with defined RX pin of any UART (same or different). @@ -1361,7 +1520,14 @@ void uart_internal_loopback(uint8_t uartNum, int8_t rxPin) { log_e("UART%d is not supported for loopback or RX pin %d is invalid.", uartNum, rxPin); return; } - esp_rom_gpio_connect_out_signal(rxPin, UART_TX_SIGNAL(uartNum), false, false); +#if 0 // leave this code here for future reference and need + // forces rxPin to use GPIO Matrix and setup the pin to receive UART TX Signal - IDF 5.4.1 Change with uart_release_pin() + gpio_func_sel((gpio_num_t)rxPin, PIN_FUNC_GPIO); + gpio_pullup_en((gpio_num_t)rxPin); + gpio_input_enable((gpio_num_t)rxPin); + esp_rom_gpio_connect_in_signal(rxPin, uart_periph_signal[uartNum].pins[SOC_UART_RX_PIN_IDX].signal, false); +#endif + esp_rom_gpio_connect_out_signal(rxPin, uart_periph_signal[uartNum].pins[SOC_UART_TX_PIN_IDX].signal, false, false); } /* diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index 4d686fdd23d..41b005aa151 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -97,6 +97,19 @@ bool uartSetHwFlowCtrlMode(uart_t *uart, uart_hw_flowcontrol_t mode, uint8_t thr // UART_MODE_RS485_APP_CTRL = 0x04 mode: application control RS485 UART mode (used for test purposes) bool uartSetMode(uart_t *uart, uart_mode_t mode); +// Used to set the UART clock source mode. It must be set before calling uartBegin(), otherwise it won't have any effect. +// Not all clock source are available to every SoC. The compatible option are listed here: +// UART_SCLK_DEFAULT :: any SoC - it will set whatever IDF defines as the default UART Clock Source +// UART_SCLK_APB :: ESP32, ESP32-S2, ESP32-C3 and ESP32-S3 +// UART_SCLK_PLL_F80M :: ESP32-C5, ESP32-C6, ESP32-C61 and ESP32-P4 +// UART_SCLK_PLL_F40M :: ESP32-C2 +// UART_SCLK_PLL_F48M :: ESP32-H2 +// UART_SCLK_XTAL :: ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2, ESP32-S3 and ESP32-P4 +// UART_SCLK_RTC :: ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2, ESP32-S3 and ESP32-P4 +// UART_SCLK_REF_TICK :: ESP32 and ESP32-S2 +// Note: ESP32-C6, C61, ESP32-P4 and ESP32-C5 have LP UART that will use only LP_UART_SCLK_LP_FAST (RTC_FAST) or LP_UART_SCLK_XTAL_D2 (XTAL/2) as Clock Source +bool uartSetClockSource(uint8_t uartNum, uart_sclk_t clkSrc); + void uartStartDetectBaudrate(uart_t *uart); unsigned long uartDetectBaudrate(uart_t *uart); diff --git a/docs/conf_common.py b/docs/conf_common.py index 676cca899d5..6945c0d190d 100644 --- a/docs/conf_common.py +++ b/docs/conf_common.py @@ -2,6 +2,12 @@ from esp_docs.conf_docs import * # noqa: F403,F401 +# Used for substituting variables in the documentation +rst_prolog = """ +.. |version| replace:: 3.2.0 +.. |idf_version| replace:: 5.4 +""" + languages = ["en"] # idf_targets = [ @@ -27,6 +33,7 @@ extensions += [ # noqa: F405 "sphinx_copybutton", "sphinx_tabs.tabs", + "sphinx_substitution_extensions", # For allowing substitutions inside code blocks "esp_docs.esp_extensions.dummy_build_system", ] diff --git a/docs/en/contributing.rst b/docs/en/contributing.rst index 4093c60ec64..7a7b99894eb 100644 --- a/docs/en/contributing.rst +++ b/docs/en/contributing.rst @@ -15,6 +15,9 @@ Before Contributing Before sending us a Pull Request, please consider this: +* All contributions must be written in English to ensure effective communication and support. + Pull Requests written in other languages will be closed, with a request to rewrite them in English. + * Is the contribution entirely your own work, or is it already licensed under an LGPL 2.1 compatible Open Source License? If not, cannot accept it. @@ -219,7 +222,7 @@ Documentation ------------- If you are contributing to the documentation, please follow the instructions described in the -`documentation guidelines `_ to properly format and test your changes. +`documentation guidelines `_ to properly format and test your changes. Testing and CI -------------- @@ -432,7 +435,7 @@ Documentation Checks ^^^^^^^^^^^^^^^^^^^^ The CI also checks the documentation for any compilation errors. This is important to ensure that the documentation layout is not broken. -To build the documentation locally, please refer to the `documentation guidelines `_. +To build the documentation locally, please refer to the `documentation guidelines `_. Code Style Checks ^^^^^^^^^^^^^^^^^ diff --git a/docs/en/esp-idf_component.rst b/docs/en/esp-idf_component.rst index f38dc44ec0c..13542cc3c87 100644 --- a/docs/en/esp-idf_component.rst +++ b/docs/en/esp-idf_component.rst @@ -14,9 +14,9 @@ For a simplified method, see `Installing using Boards Manager `_. -.. note:: Latest Arduino Core ESP32 version (3.0.X) is now compatible with `ESP-IDF v5.1 `_. Please consider this compatibility when using Arduino as a component in ESP-IDF. +.. note:: Latest Arduino Core ESP32 version (|version|) is now compatible with ESP-IDF v\ |idf_version|\ . Please consider this compatibility when using Arduino as a component in ESP-IDF. -For easiest use of Arduino framework as a ESP-IDF component, you can use the `IDF Component Manager `_ to add the Arduino component to your project. +For easiest use of Arduino framework as a ESP-IDF component, you can use the `IDF Component Manager `_ to add the Arduino component to your project. This will automatically clone the repository and its submodules. You can find the Arduino component in the `ESP Registry `_ together with dependencies list and examples. Installation @@ -32,14 +32,16 @@ Installing using IDF Component Manager To add the Arduino component to your project using the IDF Component Manager, run the following command in your project directory: .. code-block:: bash + :substitutions: - idf.py add-dependency "espressif/arduino-esp32^3.0.2" + idf.py add-dependency "espressif/arduino-esp32^|version|" Or you can start a new project from a template with the Arduino component: .. code-block:: bash + :substitutions: - idf.py create-project-from-example "espressif/arduino-esp32^3.0.2:hello_world" + idf.py create-project-from-example "espressif/arduino-esp32^|version|:hello_world" Manual installation of Arduino framework **************************************** diff --git a/docs/en/guides/core_compatibility.rst b/docs/en/guides/core_compatibility.rst index cb530ac5e7c..8b6a8e79d26 100644 --- a/docs/en/guides/core_compatibility.rst +++ b/docs/en/guides/core_compatibility.rst @@ -9,28 +9,28 @@ Welcome to the compatibility guide for library developers aiming to support mult Code Adaptations ---------------- -To ensure compatibility with both versions of the ESP32 Arduino core, developers should utilize conditional compilation directives in their code. Below is an example of how to conditionally include code based on the ESP32 Arduino core version:: +To ensure compatibility with both versions of the ESP32 Arduino core, developers should utilize conditional compilation directives in their code. Below is an example of how to conditionally include code based on the ESP32 Arduino core version: - .. code-block:: cpp +.. code-block:: cpp - #ifdef ESP_ARDUINO_VERSION_MAJOR - #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) - // Code for version 3.x - #else - // Code for version 2.x - #endif - #else - // Code for version 1.x - #endif + #ifdef ESP_ARDUINO_VERSION_MAJOR + #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) + // Code for version 3.x + #else + // Code for version 2.x + #endif + #else + // Code for version 1.x + #endif Version Print ------------- -To easily print the ESP32 Arduino core version at runtime, developers can use the `ESP_ARDUINO_VERSION_STR` macro. Below is an example of how to print the ESP32 Arduino core version:: +To easily print the ESP32 Arduino core version at runtime, developers can use the `ESP_ARDUINO_VERSION_STR` macro. Below is an example of how to print the ESP32 Arduino core version: - .. code-block:: cpp +.. code-block:: cpp - Serial.printf(" ESP32 Arduino core version: %s\n", ESP_ARDUINO_VERSION_STR); + Serial.printf(" ESP32 Arduino core version: %s\n", ESP_ARDUINO_VERSION_STR); API Differences --------------- diff --git a/docs/en/guides/docs_contributing.rst b/docs/en/guides/docs_contributing.rst index 20dc4c84cab..13f08c47618 100644 --- a/docs/en/guides/docs_contributing.rst +++ b/docs/en/guides/docs_contributing.rst @@ -49,11 +49,11 @@ Before starting your collaboration, you need to get the documentation source cod Requirements ************ -To properly work with the documentation, you need to install some packages in your system. +To build the documentation properly, you need to install some packages in your system. Note that depending on +your system, you may need to use a virtual environment to install the packages. .. code-block:: - pip install -U Sphinx pip install -r requirements.txt The requirements file is under the ``docs`` folder. @@ -62,17 +62,14 @@ Using Visual Studio Code ************************ If you are using the Visual Studio Code, you can install some extensions to help you while writing documentation. +For reStructuredText, you can install the `reStructuredText Pack `_ extension. -`reStructuredText Pack `_ - -We also recommend you install to grammar check extension to help you to review English grammar. - -`Grammarly `_ +We also recommend you to install some grammar check extension to help you to review English grammar. Building ******** -To build the documentation and generate the HTML files, you can use the following command inside the ``docs`` folder. After a successful build, you can check the files inside the `_build/en/generic/html` folder. +To build the documentation and generate the HTML files, you can use the following command inside the ``docs`` folder. After a successful build, you can check the files inside the ``_build/en/generic/html`` folder. .. code-block:: diff --git a/docs/en/index.rst b/docs/en/index.rst index 1314a8fc78d..89fc7e3bd6e 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -3,6 +3,7 @@ Welcome to ESP32 Arduino Core's documentation ############################################# Here you will find all the relevant information about the project. +This documentation is valid for the Arduino Core for ESP32 version |version| based on ESP-IDF |idf_version|. .. note:: This is a work in progress documentation and we will appreciate your help! We are looking for contributors! diff --git a/docs/en/installing.rst b/docs/en/installing.rst index d5392d4b5ec..3ca0881c398 100644 --- a/docs/en/installing.rst +++ b/docs/en/installing.rst @@ -10,6 +10,11 @@ Before Installing We recommend you install the support using your favorite IDE, but other options are available depending on your operating system. To install Arduino-ESP32 support, you can use one of the following options. +.. note:: + Users in China might have troubles with connection and download speeds using GitHub. Please use our Jihulab mirror as the repository source: + + ``https://jihulab.com/esp-mirror/espressif/arduino-esp32.git`` + Installing using Arduino IDE ---------------------------- @@ -32,6 +37,16 @@ This is the way to install Arduino-ESP32 directly from the Arduino IDE. https://espressif.github.io/arduino-esp32/package_esp32_dev_index.json +Users in China might have troubles with connection and download speeds using the links above. Please use our Jihulab mirror: + +- Stable release link:: + + https://jihulab.com/esp-mirror/espressif/arduino-esp32/-/raw/gh-pages/package_esp32_index_cn.json + +- Development release link:: + + https://jihulab.com/esp-mirror/espressif/arduino-esp32/-/raw/gh-pages/package_esp32_dev_index_cn.json + .. note:: Starting with the Arduino IDE version 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, macOS, and Linux. @@ -55,6 +70,8 @@ To start the installation process using the Boards Manager, follow these steps: :figclass: align-center - Open Boards Manager from Tools > Board menu and install *esp32* platform (and do not forget to select your ESP32 board from Tools > Board menu after installation). + Users in China must select the package version with the "-cn" suffix and perform updates manually. + Automatic updates are not supported in this region, as they target the default package without the "-cn" suffix, resulting in download failures. .. figure:: ../_static/install_guide_boards_manager_esp32.png :align: center diff --git a/docs/en/lib_builder.rst b/docs/en/lib_builder.rst index e7edb331fd3..a8126c18edc 100644 --- a/docs/en/lib_builder.rst +++ b/docs/en/lib_builder.rst @@ -293,8 +293,9 @@ You have two options to run the Docker image to build the libraries. Manually or To run the Docker image manually, use the following command from the root of the ``arduino-esp32`` repository: .. code-block:: bash + :substitutions: - docker run --rm -it -v $PWD:/arduino-esp32 -e TERM=xterm-256color espressif/esp32-arduino-lib-builder:release-v5.1 + docker run --rm -it -v $PWD:/arduino-esp32 -e TERM=xterm-256color espressif/esp32-arduino-lib-builder:release-v|idf_version| This will start the Lib Builder UI for compiling the libraries. The above command explained: @@ -304,7 +305,7 @@ This will start the Lib Builder UI for compiling the libraries. The above comman - ``-t`` Allocate a pseudo-TTY; - ``-e TERM=xterm-256color``: Optional. Sets the terminal type to ``xterm-256color`` to display colors correctly; - ``-v $PWD:/arduino-esp32``: Optional. Mounts the current folder at ``/arduino-esp32`` inside the container. If not provided, the container will not copy the compiled libraries to the host machine; -- ``espressif/esp32-arduino-lib-builder:release-v5.1``: uses Docker image ``espressif/esp32-arduino-lib-builder`` with tag ``release-v5.1``. +- :substitution-code:`espressif/esp32-arduino-lib-builder:release-v|idf_version|`: uses Docker image ``espressif/esp32-arduino-lib-builder`` with tag :substitution-code:`release-v|idf_version|`. The ``latest`` tag is implicitly added by Docker when no tag is specified. It is recommended to use a specific version tag to ensure reproducibility of the build process. .. warning:: @@ -324,24 +325,27 @@ By default the docker container will run the user interface script. If you want For example, to run a terminal inside the container, you can run: .. code-block:: bash + :substitutions: - docker run -it espressif/esp32-arduino-lib-builder:release-v5.1 /bin/bash + docker run -it espressif/esp32-arduino-lib-builder:release-v|idf_version| /bin/bash Running the Docker image using the provided run script will depend on the host OS. Use the following command from the root of the ``arduino-esp32`` repository to execute the image in a Linux or macOS environment for -the ``release-v5.1`` tag: +the :substitution-code:`release-v|idf_version|` tag: .. code-block:: bash + :substitutions: - curl -LJO https://raw.githubusercontent.com/espressif/esp32-arduino-lib-builder/refs/heads/release/v5.1/tools/docker/run.sh + curl -LJO https://raw.githubusercontent.com/espressif/esp32-arduino-lib-builder/refs/heads/release/v|idf_version|/tools/docker/run.sh chmod +x run.sh ./run.sh $PWD For Windows, use the following command in PowerShell from the root of the ``arduino-esp32`` repository: .. code-block:: powershell + :substitutions: - Invoke-WebRequest -Uri "https://raw.githubusercontent.com/espressif/esp32-arduino-lib-builder/refs/heads/release/v5.1/tools/docker/run.ps1" -OutFile "run.ps1" + Invoke-WebRequest -Uri "https://raw.githubusercontent.com/espressif/esp32-arduino-lib-builder/refs/heads/release/v|idf_version|/tools/docker/run.ps1" -OutFile "run.ps1" .\run.ps1 $pwd As the script is unsigned, you may need to change the execution policy of the current session before running the script. diff --git a/docs/en/troubleshooting.rst b/docs/en/troubleshooting.rst index f6a241729f5..ea9a6db94d6 100644 --- a/docs/en/troubleshooting.rst +++ b/docs/en/troubleshooting.rst @@ -14,6 +14,23 @@ Installing Here are the common issues during the installation. +Slow or unstable downloads +************************** + +Users in China might have troubles with connection and download speeds using GitHub. Please use our Jihulab mirror as the repository source: + +`https://jihulab.com/esp-mirror/espressif/arduino-esp32.git `_ + +JSON files for the boards manager are available here: + +- Stable release:: + + https://jihulab.com/esp-mirror/espressif/arduino-esp32/-/raw/gh-pages/package_esp32_index_cn.json + +- Development release:: + + https://jihulab.com/esp-mirror/espressif/arduino-esp32/-/raw/gh-pages/package_esp32_dev_index_cn.json + Building -------- diff --git a/docs/requirements.txt b/docs/requirements.txt index d3017fb5adc..ef2ab88cb65 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,7 @@ +sphinx==4.5.0 esp-docs>=1.4.0 sphinx-copybutton==0.5.0 sphinx-tabs==3.2.0 numpydoc==1.5.0 standard-imghdr==3.13.0 +Sphinx-Substitution-Extensions==2022.2.16 diff --git a/idf_component.yml b/idf_component.yml index 967c4ecf0f6..450929a4067 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -68,6 +68,8 @@ dependencies: # RainMaker Start (Fixed versions, because Matter supports only Insights 1.0.1) espressif/network_provisioning: version: "1.0.2" + rules: + - if: "target != esp32c2" espressif/esp_rainmaker: version: "1.5.2" rules: @@ -103,11 +105,11 @@ dependencies: rules: - if: "target in [esp32s3]" espressif/esp_hosted: - version: "^0.0.25" + version: "^2.0.12" rules: - if: "target == esp32p4" espressif/esp_wifi_remote: - version: "^0.4.1" + version: "^0.13.0" rules: - if: "target == esp32p4" espressif/libsodium: diff --git a/idf_component_examples/.gitignore b/idf_component_examples/.gitignore new file mode 100644 index 00000000000..6052fd4e70b --- /dev/null +++ b/idf_component_examples/.gitignore @@ -0,0 +1,4 @@ +build/ +managed_components/ +dependencies.lock +sdkconfig diff --git a/idf_component_examples/esp_matter_light/CMakeLists.txt b/idf_component_examples/esp_matter_light/CMakeLists.txt index 16a7533f2a5..1430df8ff78 100644 --- a/idf_component_examples/esp_matter_light/CMakeLists.txt +++ b/idf_component_examples/esp_matter_light/CMakeLists.txt @@ -8,6 +8,7 @@ set(PROJECT_VER_NUMBER 1) # This should be done before using the IDF_TARGET variable. include($ENV{IDF_PATH}/tools/cmake/project.cmake) +idf_build_set_property(MINIMAL_BUILD ON) project(arduino_managed_component_light) # WARNING: This is just an example for using key for decrypting the encrypted OTA image @@ -20,7 +21,7 @@ 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(CXX_COMPILE_OPTIONS "-std=gnu++2a;-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 diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 06a22cdceac..b0173f6a437 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -59,15 +59,22 @@ 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 The project will download all necessary components, including the Arduino Core. -Run `idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults..idf" -p flash monitor` +Execute this sequence: + ` using linux rm command or Windows rmdir command` + `idf.py set-target ` + `idf.py -D SDKCONFIG_DEFAULTS="sdkconfig_file1;sdkconfig_file2;sdkconfig_fileX" -p flash monitor` Example for ESP32-S3/Linux | macOS: ``` -idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32s3" -p /dev/ttyACM0 flash monitor +rm -rf build +idf.py set-target esp32s3 +idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults" -p /dev/ttyACM0 flash monitor ``` Example for ESP32-C3/Windows: ``` -idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32c3" -p com3 flash monitor +rmdir /s/q build +idf.py set-target esp32c3 +idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults" -p com3 flash monitor ``` It may be necessary to delete some folders and files before running `idf.py` @@ -95,11 +102,15 @@ In order to build the application that will use Thread Networking instead of Wi- Example for ESP32-C6/Linux | macOS: ``` -idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p /dev/ttyACM0 flash monitor +rm -rf build +idf.py set-target esp32c6 +idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.c6_thread" -p /dev/ttyACM0 flash monitor ``` Example for ESP32-C6/Windows: ``` -idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p com3 flash monitor +rmdir /s/q build +idf.py set-targt esp32c6 +idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.c6_thread" -p com3 flash monitor ``` It may be necessary to delete some folders and files before running `idf.py` diff --git a/idf_component_examples/esp_matter_light/ci.json b/idf_component_examples/esp_matter_light/ci.json new file mode 100644 index 00000000000..f23a085285d --- /dev/null +++ b/idf_component_examples/esp_matter_light/ci.json @@ -0,0 +1,11 @@ +{ + "targets": { + "esp32c2": false, + "esp32s2": false + }, + "requires": [ + "CONFIG_SOC_WIFI_SUPPORTED=y", + "CONFIG_ESP_MATTER_ENABLE_DATA_MODEL=y", + "CONFIG_MBEDTLS_HKDF_C=y" + ] +} diff --git a/idf_component_examples/esp_matter_light/main/Kconfig.projbuild b/idf_component_examples/esp_matter_light/main/Kconfig.projbuild index 6e6abcb7fcf..3e0a35c5e15 100644 --- a/idf_component_examples/esp_matter_light/main/Kconfig.projbuild +++ b/idf_component_examples/esp_matter_light/main/Kconfig.projbuild @@ -3,100 +3,40 @@ menu "Light Matter Accessory" config BUTTON_PIN int prompt "Button 1 GPIO" - default ENV_GPIO_BOOT_BUTTON + default 9 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6 + default 0 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 + default 8 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6 + default 48 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_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_RANGE_MAX + int + default 19 if IDF_TARGET_ESP32C3 + default 30 if IDF_TARGET_ESP32C6 + default 48 - config ENV_GPIO_IN_RANGE_MAX - int - default ENV_GPIO_RANGE_MAX + 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 + config ENV_GPIO_OUT_RANGE_MAX + int + default ENV_GPIO_RANGE_MAX endmenu diff --git a/idf_component_examples/esp_matter_light/main/idf_component.yml b/idf_component_examples/esp_matter_light/main/idf_component.yml index 2b4ae4b34a4..e0286324591 100644 --- a/idf_component_examples/esp_matter_light/main/idf_component.yml +++ b/idf_component_examples/esp_matter_light/main/idf_component.yml @@ -1,9 +1,9 @@ dependencies: espressif/esp_matter: - version: "^1.3.0" + version: ">=1.3.0" # Adds Arduino Core from GitHub repository using main branch espressif/arduino-esp32: - version: "^3.0.5" + version: ">=3.0.5" override_path: "../../../" pre_release: true diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 b/idf_component_examples/esp_matter_light/sdkconfig.defaults similarity index 98% rename from idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 rename to idf_component_examples/esp_matter_light/sdkconfig.defaults index df6d6b0d585..43871661856 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults @@ -1,5 +1,3 @@ -CONFIG_IDF_TARGET="esp32c3" - # Arduino Settings CONFIG_FREERTOS_HZ=1000 CONFIG_AUTOSTART_ARDUINO=y diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 index f228f3158c8..9fe589613ef 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 @@ -1,68 +1,5 @@ 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 Requester -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 diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 deleted file mode 100644 index 9c1aa36b6c9..00000000000 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 +++ /dev/null @@ -1,64 +0,0 @@ -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 Requester -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/idf_component_examples/hello_world/CMakeLists.txt b/idf_component_examples/hello_world/CMakeLists.txt index 664d45871d0..af087cf42b6 100644 --- a/idf_component_examples/hello_world/CMakeLists.txt +++ b/idf_component_examples/hello_world/CMakeLists.txt @@ -5,4 +5,6 @@ cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +idf_build_set_property(MINIMAL_BUILD ON) project(main) diff --git a/idf_component_examples/hw_cdc_hello_world/CMakeLists.txt b/idf_component_examples/hw_cdc_hello_world/CMakeLists.txt index 16bb1063af3..1c3971f4dbf 100644 --- a/idf_component_examples/hw_cdc_hello_world/CMakeLists.txt +++ b/idf_component_examples/hw_cdc_hello_world/CMakeLists.txt @@ -9,4 +9,5 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) list(APPEND compile_definitions "ARDUINO_USB_CDC_ON_BOOT=1") list(APPEND compile_definitions "ARDUINO_USB_MODE=1") +idf_build_set_property(MINIMAL_BUILD ON) project(hw_cdc_hello_world) diff --git a/idf_component_examples/hw_cdc_hello_world/ci.json b/idf_component_examples/hw_cdc_hello_world/ci.json new file mode 100644 index 00000000000..80669afc2cc --- /dev/null +++ b/idf_component_examples/hw_cdc_hello_world/ci.json @@ -0,0 +1,5 @@ +{ + "requires": [ + "CONFIG_SOC_USB_SERIAL_JTAG_SUPPORTED=y" + ] +} diff --git a/libraries/AsyncUDP/src/AsyncUDP.cpp b/libraries/AsyncUDP/src/AsyncUDP.cpp index f44cc839c97..cab9c951921 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.cpp +++ b/libraries/AsyncUDP/src/AsyncUDP.cpp @@ -682,6 +682,8 @@ static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adap } bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl, tcpip_adapter_if_t tcpip_if) { + ip_addr_t bind_addr; + if (!ip_addr_ismulticast(addr)) { return false; } @@ -690,7 +692,18 @@ bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl return false; } - if (!listen(NULL, port)) { +#if CONFIG_LWIP_IPV6 + if (IP_IS_V6(addr)) { + IP_SET_TYPE(&bind_addr, IPADDR_TYPE_V6); + ip6_addr_set_any(&bind_addr.u_addr.ip6); + } else { +#endif + IP_SET_TYPE(&bind_addr, IPADDR_TYPE_V4); + ip4_addr_set_any(&bind_addr.u_addr.ip4); +#if CONFIG_LWIP_IPV6 + } +#endif + if (!listen(&bind_addr, port)) { return false; } diff --git a/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino b/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino index d956dc14ad3..7759aa09a1c 100644 --- a/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino +++ b/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino @@ -34,8 +34,9 @@ void handleNotFound() { void setup() { Serial.begin(115200); - WiFi.mode(WIFI_AP); - WiFi.softAP("ESP32-DNSServer"); + WiFi.AP.begin(); + WiFi.AP.create("ESP32-DNSServer"); + WiFi.AP.enableDhcpCaptivePortal(); // by default DNSServer is started serving any "*" domain name. It will reply // AccessPoint's IP to all DNS request (this is required for Captive Portal detection) diff --git a/libraries/DNSServer/src/DNSServer.cpp b/libraries/DNSServer/src/DNSServer.cpp index 28cf89d6ede..1f74c96c733 100644 --- a/libraries/DNSServer/src/DNSServer.cpp +++ b/libraries/DNSServer/src/DNSServer.cpp @@ -111,16 +111,22 @@ void DNSServer::_handleUDP(AsyncUDPPacket &pkt) { // will reply with IP only to "*" or if domain matches without www. subdomain if (dnsHeader.OPCode == DNS_OPCODE_QUERY && requestIncludesOnlyOneQuestion(dnsHeader) && (_domainName.isEmpty() || getDomainNameWithoutWwwPrefix(static_cast(dnsQuestion.QName), dnsQuestion.QNameLength) == _domainName)) { - replyWithIP(pkt, dnsHeader, dnsQuestion); + + // Qtype = A (1) or ANY (255): send an A record otherwise an empty response + if (ntohs(dnsQuestion.QType) == 1 || ntohs(dnsQuestion.QType) == 255) { + replyWithIP(pkt, dnsHeader, dnsQuestion); + } else { + replyWithNoAnsw(pkt, dnsHeader, dnsQuestion); + } return; } - // otherwise reply with custom code replyWithCustomCode(pkt, dnsHeader); } bool DNSServer::requestIncludesOnlyOneQuestion(DNSHeader &dnsHeader) { - return ntohs(dnsHeader.QDCount) == 1 && dnsHeader.ANCount == 0 && dnsHeader.NSCount == 0 && dnsHeader.ARCount == 0; + dnsHeader.ARCount = 0; // We assume that if ARCount !=0 there is a EDNS OPT packet, just ignore + return ntohs(dnsHeader.QDCount) == 1 && dnsHeader.ANCount == 0 && dnsHeader.NSCount == 0; } String DNSServer::getDomainNameWithoutWwwPrefix(const unsigned char *start, size_t len) { @@ -139,7 +145,6 @@ String DNSServer::getDomainNameWithoutWwwPrefix(const unsigned char *start, size void DNSServer::replyWithIP(AsyncUDPPacket &req, DNSHeader &dnsHeader, DNSQuestion &dnsQuestion) { AsyncUDPMessage rpl; - // Change the type of message to a response and set the number of answers equal to // the number of questions in the header dnsHeader.QR = DNS_QR_RESPONSE; @@ -187,3 +192,76 @@ void DNSServer::replyWithCustomCode(AsyncUDPPacket &req, DNSHeader &dnsHeader) { rpl.write(reinterpret_cast(&dnsHeader), sizeof(DNSHeader)); _udp.sendTo(rpl, req.remoteIP(), req.remotePort()); } + +void DNSServer::replyWithNoAnsw(AsyncUDPPacket &req, DNSHeader &dnsHeader, DNSQuestion &dnsQuestion) { + + dnsHeader.QR = DNS_QR_RESPONSE; + dnsHeader.ANCount = 0; + dnsHeader.NSCount = htons(1); + + AsyncUDPMessage rpl; + rpl.write(reinterpret_cast(&dnsHeader), sizeof(DNSHeader)); + + // Write the question + rpl.write(dnsQuestion.QName, dnsQuestion.QNameLength); + rpl.write((uint8_t *)&dnsQuestion.QType, 2); + rpl.write((uint8_t *)&dnsQuestion.QClass, 2); + + // An empty answer contains an authority section with a SOA, + // We take the name of the query as the root of the zone for which the SOA is generated + // and use a value of DNS_MINIMAL_TTL seconds in order to minimize negative caching + // Write the authority section: + // The SOA RR's ownername is set equal to the query name, and we use made up names for + // the MNAME and RNAME - it doesn't really matter from a protocol perspective - as for + // a no such QTYPE answer only the timing fields are used. + // a protocol perspective - it + // Use DNS name compression : instead of repeating the name in this RNAME occurrence, + // set the two MSB of the byte corresponding normally to the length to 1. The following + // 14 bits must be used to specify the offset of the domain name in the message + // (<255 here so the first byte has the 6 LSB at 0) + rpl.write((uint8_t)0xC0); + rpl.write((uint8_t)DNS_OFFSET_DOMAIN_NAME); + + // DNS type A : host address, DNS class IN for INternet, returning an IPv4 address + uint16_t answerType = htons(DNS_TYPE_SOA), answerClass = htons(DNS_CLASS_IN); + uint32_t Serial = htonl(DNS_SOA_SERIAL); // Date type serial based on the date this piece of code was written + uint32_t Refresh = htonl(DNS_SOA_REFRESH); // These timers don't matter, we don't serve zone transfers + uint32_t Retry = htonl(DNS_SOA_RETRY); + uint32_t Expire = htonl(DNS_SOA_EXPIRE); + uint32_t MinTTL = htonl(DNS_MINIMAL_TTL); // See RFC2308 section 5 + char MLabel[] = DNS_SOA_MNAME_LABEL; + char RLabel[] = DNS_SOA_RNAME_LABEL; + char PostFixLabel[] = DNS_SOA_POSTFIX_LABEL; + + // 4 accounts for len fields and for both rname + // and lname and their postfix labels and there are 5 32 bit fields + + uint16_t RdataLength = htons((uint16_t)(strlen(MLabel) + strlen(RLabel) + 2 * strlen(PostFixLabel) + 4 + 5 * sizeof(Serial))); + + rpl.write((unsigned char *)&answerType, 2); + rpl.write((unsigned char *)&answerClass, 2); + rpl.write((unsigned char *)&MinTTL, 4); // DNS Time To Live + + rpl.write((unsigned char *)&RdataLength, 2); + + rpl.write((uint8_t)strlen(MLabel)); + rpl.write((unsigned char *)&MLabel, strlen(MLabel)); + + rpl.write((unsigned char *)&PostFixLabel, strlen(PostFixLabel)); + rpl.write((uint8_t)0); + // rpl.write((uint8_t)0xC0); + // rpl.write((uint8_t)DNS_OFFSET_DOMAIN_NAME); + + rpl.write((uint8_t)strlen(RLabel)); + rpl.write((unsigned char *)&RLabel, strlen(RLabel)); + rpl.write((unsigned char *)&PostFixLabel, strlen(PostFixLabel)); + rpl.write((uint8_t)0); + + rpl.write((unsigned char *)&Serial, 4); + rpl.write((unsigned char *)&Refresh, 4); + rpl.write((unsigned char *)&Retry, 4); + rpl.write((unsigned char *)&Expire, 4); + rpl.write((unsigned char *)&MinTTL, 4); + + _udp.sendTo(rpl, req.remoteIP(), req.remotePort()); +} diff --git a/libraries/DNSServer/src/DNSServer.h b/libraries/DNSServer/src/DNSServer.h index dfd9a45604d..f2716defc7d 100644 --- a/libraries/DNSServer/src/DNSServer.h +++ b/libraries/DNSServer/src/DNSServer.h @@ -9,6 +9,26 @@ #define DNS_OFFSET_DOMAIN_NAME DNS_HEADER_SIZE // Offset in bytes to reach the domain name labels in the DNS message #define DNS_DEFAULT_PORT 53 +#define DNS_SOA_MNAME_LABEL "ns" +#define DNS_SOA_RNAME_LABEL "esp32" +// The POSTFIX_LABEL will be concatenated to the RName and MName Label label +// do not use a multilabel name here. "local" is a good choice as it is reserved for +// local use by IANA +// The postfix label is defined as an array of characters that follows the +// definition of RFC1035 3.1 +// for instance, a postfix of example.com would be defined as: +// #define DNS_SOA_POSTFIX_LABEL {'\7', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '\3', 'c', 'o', 'm', '\0'} +#define DNS_SOA_POSTFIX_LABEL \ + { '\5', 'l', 'o', 'c', 'a', 'l', '\0' } +// From the following values only the MINIMAL_TTL has relevance +// in the context of client-server protocol interactions. +// The other values are arbitrary chosen as they are only relevant for +// in a zone-transfer scenario. +#define DNS_SOA_SERIAL 2025052900 // Arbitrary serial (format: YYYYMMDDnn) +#define DNS_SOA_REFRESH 100000 // Arbitrary (seconds) +#define DNS_SOA_RETRY 10000 // Arbitrary (seconds) +#define DNS_SOA_EXPIRE 1000000 // Arbitrary (seconds) +#define DNS_MINIMAL_TTL 5 // Time to live for negative answers RFC2308 enum class DNSReplyCode : uint16_t { NoError = 0, FormError = 1, @@ -179,5 +199,7 @@ class DNSServer { inline bool requestIncludesOnlyOneQuestion(DNSHeader &dnsHeader); void replyWithIP(AsyncUDPPacket &req, DNSHeader &dnsHeader, DNSQuestion &dnsQuestion); inline void replyWithCustomCode(AsyncUDPPacket &req, DNSHeader &dnsHeader); + inline void replyWithNoAnsw(AsyncUDPPacket &req, DNSHeader &dnsHeader, DNSQuestion &dnsQuestion); + void _handleUDP(AsyncUDPPacket &pkt); }; diff --git a/libraries/ESP32/examples/AnalogOut/LEDCGammaFade/LEDCGammaFade.ino b/libraries/ESP32/examples/AnalogOut/LEDCGammaFade/LEDCGammaFade.ino new file mode 100644 index 00000000000..4ca6c136ddf --- /dev/null +++ b/libraries/ESP32/examples/AnalogOut/LEDCGammaFade/LEDCGammaFade.ino @@ -0,0 +1,111 @@ +/* LEDC Gamma Curve Fade Arduino Example + + This example demonstrates gamma curve fading on ESP32 variants that support it. + Gamma correction makes LED brightness changes appear more gradual and natural + to human eyes compared to linear fading. + + Two methods are supported: + 1. Using a pre-computed Gamma Look-Up Table (LUT) for better performance + 2. Using mathematical gamma correction with a gamma factor + + Supported chips: ESP32-C6, ESP32-C5, ESP32-H2, ESP32-P4 and future chips with Gamma Fade support + + Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/) +*/ + +// use 12 bit precision for LEDC timer +#define LEDC_TIMER_12_BIT 12 + +// use 5000 Hz as a LEDC base frequency +#define LEDC_BASE_FREQ 5000 + +// define starting duty, target duty and maximum fade time +#define LEDC_START_DUTY (0) +#define LEDC_TARGET_DUTY (4095) +#define LEDC_FADE_TIME (2000) + +// gamma factor for mathematical calculation +#define LEDC_GAMMA_FACTOR (2.6) + +// use gamma LUT for better performance instead of mathematical calculation (gamma factor) +#define USE_GAMMA_LUT 1 + +// fade LED pins +const uint8_t ledPinR = 4; +const uint8_t ledPinG = 5; +const uint8_t ledPinB = 6; + +uint8_t fade_ended = 0; // status of LED gamma fade +bool fade_in = true; + +#ifdef USE_GAMMA_LUT +// Custom Gamma LUT demonstration with 101 steps (Brightness 0 - 100% gamma correction look up table (gamma = 2.6)) +// Y = B ^ 2.6 - Pre-computed LUT to save runtime computation +static const float ledcGammaLUT[101] = { + 0.000000, 0.000006, 0.000038, 0.000110, 0.000232, 0.000414, 0.000666, 0.000994, 0.001406, 0.001910, 0.002512, 0.003218, 0.004035, 0.004969, 0.006025, + 0.007208, 0.008525, 0.009981, 0.011580, 0.013328, 0.015229, 0.017289, 0.019512, 0.021902, 0.024465, 0.027205, 0.030125, 0.033231, 0.036527, 0.040016, + 0.043703, 0.047593, 0.051688, 0.055993, 0.060513, 0.065249, 0.070208, 0.075392, 0.080805, 0.086451, 0.092333, 0.098455, 0.104821, 0.111434, 0.118298, + 0.125416, 0.132792, 0.140428, 0.148329, 0.156498, 0.164938, 0.173653, 0.182645, 0.191919, 0.201476, 0.211321, 0.221457, 0.231886, 0.242612, 0.253639, + 0.264968, 0.276603, 0.288548, 0.300805, 0.313378, 0.326268, 0.339480, 0.353016, 0.366879, 0.381073, 0.395599, 0.410461, 0.425662, 0.441204, 0.457091, + 0.473325, 0.489909, 0.506846, 0.524138, 0.541789, 0.559801, 0.578177, 0.596920, 0.616032, 0.635515, 0.655374, 0.675610, 0.696226, 0.717224, 0.738608, + 0.760380, 0.782542, 0.805097, 0.828048, 0.851398, 0.875148, 0.899301, 0.923861, 0.948829, 0.974208, 1.000000, +}; +#endif + +void ARDUINO_ISR_ATTR LED_FADE_ISR() { + fade_ended += 1; +} + +void setup() { + // Initialize serial communication at 115200 bits per second: + Serial.begin(115200); + + // Setup timer with given frequency, resolution and attach it to a led pin with auto-selected channel + ledcAttach(ledPinR, LEDC_BASE_FREQ, LEDC_TIMER_12_BIT); + ledcAttach(ledPinG, LEDC_BASE_FREQ, LEDC_TIMER_12_BIT); + ledcAttach(ledPinB, LEDC_BASE_FREQ, LEDC_TIMER_12_BIT); + +#if USE_GAMMA_LUT // Use default gamma LUT for better performance + ledcSetGammaTable(ledcGammaLUT, 101); +#else // Use mathematical gamma correction (default, more flexible) + ledcSetGammaFactor(LEDC_GAMMA_FACTOR); // This is optional to set custom gamma factor (default is 2.8) +#endif + + // Setup and start gamma curve fade on led (duty from 0 to 4095) + ledcFadeGamma(ledPinR, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME); + ledcFadeGamma(ledPinG, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME); + ledcFadeGamma(ledPinB, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME); + Serial.println("LED Gamma Fade on started."); + + // Wait for fade to end + delay(LEDC_FADE_TIME); + + // Setup and start gamma curve fade off led and use ISR (duty from 4095 to 0) + ledcFadeGammaWithInterrupt(ledPinR, LEDC_TARGET_DUTY, LEDC_START_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + ledcFadeGammaWithInterrupt(ledPinG, LEDC_TARGET_DUTY, LEDC_START_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + ledcFadeGammaWithInterrupt(ledPinB, LEDC_TARGET_DUTY, LEDC_START_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + Serial.println("LED Gamma Fade off started."); +} + +void loop() { + // Check if fade_ended flag was set to true in ISR + if (fade_ended == 3) { + Serial.println("LED gamma fade ended"); + fade_ended = 0; + + // Check what gamma fade should be started next + if (fade_in) { + ledcFadeGammaWithInterrupt(ledPinR, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + ledcFadeGammaWithInterrupt(ledPinG, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + ledcFadeGammaWithInterrupt(ledPinB, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + Serial.println("LED Gamma Fade in started."); + fade_in = false; + } else { + ledcFadeGammaWithInterrupt(ledPinR, LEDC_TARGET_DUTY, LEDC_START_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + ledcFadeGammaWithInterrupt(ledPinG, LEDC_TARGET_DUTY, LEDC_START_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + ledcFadeGammaWithInterrupt(ledPinB, LEDC_TARGET_DUTY, LEDC_START_DUTY, LEDC_FADE_TIME, LED_FADE_ISR); + Serial.println("LED Gamma Fade out started."); + fade_in = true; + } + } +} diff --git a/libraries/ESP32/examples/AnalogOut/LEDCGammaFade/ci.json b/libraries/ESP32/examples/AnalogOut/LEDCGammaFade/ci.json new file mode 100644 index 00000000000..a9d8603b7bf --- /dev/null +++ b/libraries/ESP32/examples/AnalogOut/LEDCGammaFade/ci.json @@ -0,0 +1,5 @@ +{ + "requires": [ + "CONFIG_SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED=y" + ] +} diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp index 81d643e37ac..cc924bd5b3b 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp +++ b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp @@ -478,6 +478,7 @@ static esp_err_t status_handler(httpd_req_t *req) { p += sprintf(p, "\"raw_gma\":%u,", s->status.raw_gma); p += sprintf(p, "\"lenc\":%u,", s->status.lenc); p += sprintf(p, "\"hmirror\":%u,", s->status.hmirror); + p += sprintf(p, "\"vflip\":%u,", s->status.vflip); p += sprintf(p, "\"dcw\":%u,", s->status.dcw); p += sprintf(p, "\"colorbar\":%u", s->status.colorbar); #if CONFIG_LED_ILLUMINATOR_ENABLED diff --git a/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino b/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino index 17e7af290bf..5d0406aee0e 100644 --- a/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino +++ b/libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino @@ -1,4 +1,4 @@ -// Copyright 2023 Espressif Systems (Shanghai) PTE LTD +// Copyright 2025 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. @@ -35,14 +35,11 @@ rmt_data_t my_data[256]; rmt_data_t data[256]; -static EventGroupHandle_t events; - #define RMT_FREQ 10000000 // tick time is 100ns -#define RMT_NUM_EXCHANGED_DATA 30 +#define RMT_NUM_EXCHANGED_DATA 32 void setup() { Serial.begin(115200); - events = xEventGroupCreate(); if (!rmtInit(RMT_TX_PIN, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, RMT_FREQ)) { Serial.println("init sender failed\n"); @@ -50,25 +47,41 @@ void setup() { if (!rmtInit(RMT_RX_PIN, RMT_RX_MODE, RMT_MEM_RX, RMT_FREQ)) { Serial.println("init receiver failed\n"); } + Serial.println(); + Serial.println("RMT tick set to: 100ns"); // End of transmission shall be detected when line is idle for 2us = 20*100ns rmtSetRxMaxThreshold(RMT_RX_PIN, 20); // Disable Glitch filter rmtSetRxMinThreshold(RMT_RX_PIN, 0); - Serial.println("real tick set to: 100ns"); - Serial.printf("\nPlease connect GPIO %d to GPIO %d, now.\n", RMT_TX_PIN, RMT_RX_PIN); -} - -void loop() { - // Init data - int i; - for (i = 0; i < 255; i++) { - data[i].val = 0x80010001 + ((i % 13) << 16) + 13 - (i % 13); + // create multiple pulses with different width to be sent + for (int i = 0; i < 255; i++) { + data[i].level0 = 1; // HIGH + data[i].duration0 = 1 + 13 - (i % 13); // number of Tick on High + data[i].level1 = 0; // LOW + data[i].duration1 = 1 + (i % 13); // number of Ticks on Low my_data[i].val = 0; } data[255].val = 0; + Serial.println(); + Serial.println("===================================================================================================="); + Serial.println("Preloaded Data that will sent (time in 0.1us):"); + // Printout the received data plus the original values + for (int i = 0; i < RMT_NUM_EXCHANGED_DATA; i++) { + Serial.printf("%08lx=[%c 0x%02x|%c 0x%02x] ", data[i].val, data[i].level0 ? 'H' : 'L', data[i].duration0, data[i].level1 ? 'H' : 'L', data[i].duration1); + if (!((i + 1) % 4)) { + Serial.println(); + } + } + Serial.println("===================================================================================================="); + Serial.printf("Please connect GPIO %d to GPIO %d, now.", RMT_TX_PIN, RMT_RX_PIN); + Serial.println(); + Serial.println(); +} + +void loop() { // Start an async data read size_t rx_num_symbols = RMT_NUM_EXCHANGED_DATA; rmtReadAsync(RMT_RX_PIN, my_data, &rx_num_symbols); @@ -84,13 +97,13 @@ void loop() { Serial.printf("Got %d RMT symbols\n", rx_num_symbols); // Printout the received data plus the original values - for (i = 0; i < 60; i++) { + for (int i = 0; i < RMT_NUM_EXCHANGED_DATA; i++) { Serial.printf("%08lx=%08lx ", my_data[i].val, data[i].val); if (!((i + 1) % 4)) { - Serial.println(""); + Serial.println(); } } - Serial.println("\n"); + Serial.println(); - delay(500); + delay(2000); } diff --git a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino index 8c2b8db3cd1..1cdd2224ea5 100644 --- a/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino +++ b/libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino @@ -1,4 +1,4 @@ -// Copyright 2023 Espressif Systems (Shanghai) PTE LTD +// Copyright 2025 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. @@ -13,16 +13,16 @@ // limitations under the License. /** - * @brief This example demonstrate how to use RMT to just blink a regular LED (GPIO) - * It uses all the different RMT Writing APIs to blink the LED by hardware, not being - * necessary the regular Blink code in Arduino. - * - * The output is the Blinking LED in the GPIO and a serial output describing what is - * going on, along the execution. - * - * The circuit is just a LED and a resistor of 270 ohms connected to the GPIO - * GPIO ---> resistor 270 ohms ---> + LED - ---> GND - */ + @brief This example demonstrate how to use RMT to just blink a regular LED (GPIO) + It uses all the different RMT Writing APIs to blink the LED by hardware, not being + necessary the regular Blink code in Arduino. + + The output is the Blinking LED in the GPIO and a serial output describing what is + going on, along the execution. + + The circuit is just a LED and a resistor of 270 ohms connected to the GPIO + GPIO ---> resistor 270 ohms ---> + LED - ---> GND +*/ #define BLINK_GPIO 2 @@ -232,7 +232,7 @@ void RMT_Mixed_Write_Blink() { Serial.println("===> rmtWrite() (Blocking Mode) to Blink the LED."); Serial.println("Blinking at 500ms on + 500ms off :: 4 blinks"); for (uint8_t i = 0; i < 4; i++) { - if (!rmtWrite(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 2, RMT_WAIT_FOR_EVER)) { + if (!rmtWrite(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 1, RMT_WAIT_FOR_EVER)) { Serial.println("===> rmtWrite Blink 0.5s Error!"); } } @@ -240,7 +240,7 @@ void RMT_Mixed_Write_Blink() { Serial.println("===> rmtWriteAsync() (Non-Blocking Mode) to Blink the LED."); Serial.println("Blinking at 250ms on + 250ms off :: 5 blinks"); for (uint8_t i = 0; i < 5; i++) { - if (!rmtWriteAsync(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 2)) { + if (!rmtWriteAsync(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 1)) { Serial.println("===> rmtWrite Blink 0.25s Error!"); } // wait (blocks) until all the data is sent out @@ -267,9 +267,11 @@ void RMT_Loop_Write_Blink() { Serial.println("===> rmtWriteLooping Blink 0.25s Error!"); } delay(5000); + Serial.println("Blinking OFF for 2 seconds"); - if (!rmtWriteLooping(BLINK_GPIO, NULL, 0)) { - Serial.println("===> rmtWriteLooping Blink OFF Error!"); + rmt_data_t blink_STOP_rmt_data[] = {{0, 0, 0, 0}}; + if (!rmtWrite(BLINK_GPIO, blink_STOP_rmt_data, RMT_SYMBOLS_OF(blink_STOP_rmt_data), RMT_WAIT_FOR_EVER)) { + Serial.println("===> rmtWrite Blink STOP Error!"); } delay(2000); } @@ -278,19 +280,19 @@ void RMT_Single_Write_Blocking_Blink() { Serial.println("Using RMT Writing and its Completion to blink an LED."); Serial.println("Blinking at 1s on + 1s off :: 2 blinks"); for (uint8_t i = 0; i < 2; i++) { - if (!rmtWrite(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 2, RMT_WAIT_FOR_EVER)) { + if (!rmtWrite(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 1, RMT_WAIT_FOR_EVER)) { Serial.println("===> rmtWrite Blink 1s Error!"); } } Serial.println("Blinking at 500ms on + 500ms off :: 4 blinks"); for (uint8_t i = 0; i < 4; i++) { - if (!rmtWrite(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 2, RMT_WAIT_FOR_EVER)) { + if (!rmtWrite(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 1, RMT_WAIT_FOR_EVER)) { Serial.println("===> rmtWrite Blink 0.5s Error!"); } } Serial.println("Blinking at 250ms on + 250ms off :: 8 blinks"); for (uint8_t i = 0; i < 8; i++) { - if (!rmtWrite(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 2, RMT_WAIT_FOR_EVER)) { + if (!rmtWrite(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 1, RMT_WAIT_FOR_EVER)) { Serial.println("===> rmtWrite Blink 0.25s Error!"); } } @@ -302,7 +304,7 @@ void RMT_Write_Aync_Non_Blocking_Blink() { Serial.println("Using RMT Async Writing and its Completion to blink an LED."); Serial.println("Blinking at 1s on + 1s off :: 5 blinks"); for (uint8_t i = 0; i < 5; i++) { - if (!rmtWriteAsync(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 2)) { + if (!rmtWriteAsync(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 1)) { Serial.println("===> rmtWrite Blink 1s Error!"); } // wait (blocks) until all the data is sent out @@ -310,7 +312,7 @@ void RMT_Write_Aync_Non_Blocking_Blink() { } Serial.println("Blinking at 500ms on + 500ms off :: 5 blinks"); for (uint8_t i = 0; i < 5; i++) { - if (!rmtWriteAsync(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 2)) { + if (!rmtWriteAsync(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 1)) { Serial.println("===> rmtWrite Blink 0.5s Error!"); } // wait (blocks) until all the data is sent out @@ -318,7 +320,7 @@ void RMT_Write_Aync_Non_Blocking_Blink() { } Serial.println("Blinking at 250ms on + 250ms off :: 5 blinks"); for (uint8_t i = 0; i < 5; i++) { - if (!rmtWriteAsync(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 2)) { + if (!rmtWriteAsync(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 1)) { Serial.println("===> rmtWrite Blink 0.25s Error!"); } // wait (blocks) until all the data is sent out @@ -345,7 +347,6 @@ void setup() { RMT_Mixed_Write_Blink(); Serial.println("End of Mixed Calls testing"); - delay(1000); Serial.println("\n==============================="); Serial.println("Starting a Blinking sequence..."); diff --git a/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino b/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino index 64d15d3d916..35d2da5c199 100644 --- a/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino +++ b/libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino @@ -21,6 +21,15 @@ If UART receives less than 120 bytes, it will wait RX Timeout to understand that the bus is IDLE and then copy the data from the FIFO to the Arduino internal buffer, making it available to the Arduino API. + There is an important detail about how HardwareSerial works using ESP32 and ESP32-S2: + If the baud rate is lower than 250,000, it will select REF_TICK as clock source in order to avoid that + the baud rate may change when the CPU Frequency is changed. Default UART clock source is APB, which changes + when CPU clock source is also changed. But when it selects REF_TICK as UART clock source, RX Timeout is limited to 1. + Therefore, in order to change the ESP32/ESP32-S2 RX Timeout it is necessary to fix the UART Clock Source to APB. + + In the case of the other SoC, such as ESP32-S3, C3, C6, H2 and P4, there is no such RX Timeout limitation. + Those will set the UART Source Clock as XTAL, which allows the baud rate to be high and it is steady, not + changing with the CPU Frequency. */ #include @@ -45,6 +54,12 @@ void setup() { // UART1 will have its RX<->TX cross connected // GPIO4 <--> GPIO5 using external wire +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 + // UART_CLK_SRC_APB will allow higher values of RX Timeout + // default for ESP32 and ESP32-S2 is REF_TICK which limits the RX Timeout to 1 + // setClockSource() must be called before begin() + Serial1.setClockSource(UART_CLK_SRC_APB); +#endif Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3 #if USE_INTERNAL_PIN_LOOPBACK uart_internal_loopback(TEST_UART, RXPIN); diff --git a/libraries/ESP32/examples/Serial/onReceiveExample/onReceiveExample.ino b/libraries/ESP32/examples/Serial/onReceiveExample/onReceiveExample.ino index fe66b07b875..17d800b3b39 100644 --- a/libraries/ESP32/examples/Serial/onReceiveExample/onReceiveExample.ino +++ b/libraries/ESP32/examples/Serial/onReceiveExample/onReceiveExample.ino @@ -5,20 +5,20 @@ void HardwareSerial::onReceive(OnReceiveCb function, bool onlyOnTimeout = false) It is possible to register an UART callback function that will be called - every time that UART receives data and an associated interrupt is generated. + every time that UART receives data and an associated UART interrupt is generated. - In summary, HardwareSerial::onReceive() works like an RX Interrupt callback, that can be adjusted - using HardwareSerial::setRxFIFOFull() and HardwareSerial::setRxTimeout(). + In summary, HardwareSerial::onReceive() works like an RX Interrupt callback, that + can be adjusted using HardwareSerial::setRxFIFOFull() and HardwareSerial::setRxTimeout(). - OnReceive will be called, while receiving a stream of data, when every 120 bytes are received (default FIFO Full), - which may not help in case that the application needs to get all data at once before processing it. - Therefore, a way to make it work is by detecting the end of a stream transmission. This can be based on a protocol - or based on timeout with the UART line in idle (no data received - this is the case of this example). + In case that is not changed or it is set to , the callback function is + executed whenever any event happens first (FIFO Full or RX Timeout). + OnReceive will be called when every 120 bytes are received(default FIFO Full), + or when RX Timeout occurs after 1 UART symbol by default. - In some cases, it is necessary to wait for receiving all the data before processing it and parsing the - UART input. This example demonstrates a way to create a String with all data received from UART0 and - signaling it using a Mutex for another task to process it. This example uses a timeout of 500ms as a way to - know when the reception of data has finished. + This example demonstrates a way to create a String with all data received from UART0 only + after RX Timeout. This example uses an RX timeout of about 3.5 Symbols as a way to know + when the reception of data has finished. + In order to achieve it, the sketch sets to . The onReceive() callback is called whenever the RX ISR is triggered. It can occur because of two possible events: @@ -34,90 +34,73 @@ 2- UART RX Timeout: it happens, based on a timeout equivalent to a number of symbols at the current baud rate. If the UART line is idle for this timeout, it will raise an interrupt. - This time can be changed by HardwareSerial::setRxTimeout(uint8_t rxTimeout) + This time can be changed by HardwareSerial::setRxTimeout(uint8_t rxTimeout). + is bound to the clock source. + In order to use it properly, ESP32 and ESP32-S2 shall set the UART Clock Source to APB. When any of those two interrupts occur, IDF UART driver will copy FIFO data to its internal RingBuffer and then Arduino can read such data. At the same time, Arduino Layer will execute the callback function defined with HardwareSerial::onReceive(). - parameter (default false) can be used by the application to tell Arduino to - only execute the callback when the second event above happens (Rx Timeout). At this time all - received data will be available to be read by the Arduino application. But if the number of - received bytes is higher than the FIFO space, it will generate an error of FIFO overflow. - In order to avoid such problem, the application shall set an appropriate RX buffer size using + parameter can be used by the application to tell Arduino to only execute + the callback when Rx Timeout happens, by setting it to . + At this time all received data will be available to be read by the Arduino application. + The application shall set an appropriate RX buffer size using HardwareSerial::setRxBufferSize(size_t new_size) before executing begin() for the Serial port. -*/ -// this will make UART0 work in any case (using or not USB) -#if ARDUINO_USB_CDC_ON_BOOT -#define UART0 Serial0 -#else -#define UART0 Serial -#endif + MODBUS timeout of 3.5 symbol is based on these documents: + https://www.automation.com/en-us/articles/2012-1/introduction-to-modbus + https://minimalmodbus.readthedocs.io/en/stable/serialcommunication.html +*/ // global variable to keep the results from onReceive() String uart_buffer = ""; -// a pause of a half second in the UART transmission is considered the end of transmission. -const uint32_t communicationTimeout_ms = 500; - -// Create a mutex for the access to uart_buffer -// only one task can read/write it at a certain time -SemaphoreHandle_t uart_buffer_Mutex = NULL; - -// UART_RX_IRQ will be executed as soon as data is received by the UART -// This is a callback function executed from a high priority -// task created when onReceive() is used +// The Modbus RTU standard prescribes a silent period corresponding to 3.5 characters between each +// message, to be able to figure out where one message ends and the next one starts. +const uint32_t modbusRxTimeoutLimit = 4; +const uint32_t baudrate = 19200; + +// UART_RX_IRQ will be executed as soon as data is received by the UART and an RX Timeout occurs +// This is a callback function executed from a high priority monitor task +// All data will be buffered into RX Buffer, which may have its size set to whatever necessary void UART0_RX_CB() { - // take the mutex, waits forever until loop() finishes its processing - if (xSemaphoreTake(uart_buffer_Mutex, portMAX_DELAY)) { - uint32_t now = millis(); // tracks timeout - while ((millis() - now) < communicationTimeout_ms) { - if (UART0.available()) { - uart_buffer += (char)UART0.read(); - now = millis(); // reset the timer - } - } - // releases the mutex for data processing - xSemaphoreGive(uart_buffer_Mutex); + while (Serial0.available()) { + uart_buffer += (char)Serial0.read(); } } // setup() and loop() are functions executed by a low priority task // Therefore, there are 2 tasks running when using onReceive() void setup() { - UART0.begin(115200); - - // creates a mutex object to control access to uart_buffer - uart_buffer_Mutex = xSemaphoreCreateMutex(); - if (uart_buffer_Mutex == NULL) { - log_e("Error creating Mutex. Sketch will fail."); - while (true) { - UART0.println("Mutex error (NULL). Program halted."); - delay(2000); - } - } - - UART0.onReceive(UART0_RX_CB); // sets the callback function - UART0.println("Send data to UART0 in order to activate the RX callback"); + // Using Serial0 will work in any case (using or not USB CDC on Boot) +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 + // UART_CLK_SRC_APB will allow higher values of RX Timeout + // default for ESP32 and ESP32-S2 is REF_TICK which limits the RX Timeout to 1 + // setClockSource() must be called before begin() + Serial0.setClockSource(UART_CLK_SRC_APB); +#endif + // the amount of data received or waiting to be proessed shall not exceed this limit of 1024 bytes + Serial0.setRxBufferSize(1024); // default is 256 bytes + Serial0.begin(baudrate); // default pins and default mode 8N1 (8 bits data, no parity bit, 1 stopbit) + // set RX Timeout based on UART symbols ~ 3.5 symbols of 11 bits (MODBUS standard) ~= 2 ms at 19200 + Serial0.setRxTimeout(modbusRxTimeoutLimit); // 4 symbols at 19200 8N1 is about 2.08 ms (40 bits) + // sets the callback function that will be executed only after RX Timeout + Serial0.onReceive(UART0_RX_CB, true); + Serial0.println("Send data using Serial Monitor in order to activate the RX callback"); } uint32_t counter = 0; void loop() { + // String is filled by the UART Callback whenever data is received and RX Timeout occurs if (uart_buffer.length() > 0) { - // signals that the onReceive function shall not change uart_buffer while processing - if (xSemaphoreTake(uart_buffer_Mutex, portMAX_DELAY)) { - // process the received data from UART0 - example, just print it beside a counter - UART0.print("["); - UART0.print(counter++); - UART0.print("] ["); - UART0.print(uart_buffer.length()); - UART0.print(" bytes] "); - UART0.println(uart_buffer); - uart_buffer = ""; // reset uart_buffer for the next UART reading - // releases the mutex for more data to be received - xSemaphoreGive(uart_buffer_Mutex); - } + // process the received data from Serial - example, just print it beside a counter + Serial0.print("["); + Serial0.print(counter++); + Serial0.print("] ["); + Serial0.print(uart_buffer.length()); + Serial0.print(" bytes] "); + Serial0.println(uart_buffer); + uart_buffer = ""; // reset uart_buffer for the next UART reading } - UART0.println("Sleeping for 1 second..."); - delay(1000); + delay(1); } diff --git a/libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino b/libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino index 935aa4bc50f..bba7d4f4d9d 100644 --- a/libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino +++ b/libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino @@ -24,10 +24,17 @@ 2nd September 2021 Lucas Saavedra Vaz (lucasssvaz) 22nd December 2023 + anon + 10nd February 2025 */ #include +// The GPIO pins are not fixed, most other pins could be used for the I2S function. +#define I2S_LRC 25 +#define I2S_BCLK 5 +#define I2S_DIN 26 + const int frequency = 440; // frequency of square wave in Hz const int amplitude = 500; // amplitude of square wave const int sampleRate = 8000; // sample rate in Hz @@ -36,10 +43,10 @@ i2s_data_bit_width_t bps = I2S_DATA_BIT_WIDTH_16BIT; i2s_mode_t mode = I2S_MODE_STD; i2s_slot_mode_t slot = I2S_SLOT_MODE_STEREO; -const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave +const unsigned int halfWavelength = sampleRate / frequency / 2; // half wavelength of square wave int32_t sample = amplitude; // current sample value -int count = 0; +unsigned int count = 0; I2SClass i2s; @@ -47,6 +54,8 @@ void setup() { Serial.begin(115200); Serial.println("I2S simple tone"); + i2s.setPins(I2S_BCLK, I2S_LRC, I2S_DIN); + // start I2S at the sample rate with 16-bits per sample if (!i2s.begin(mode, sampleRate, bps, slot)) { Serial.println("Failed to initialize I2S!"); @@ -60,8 +69,13 @@ void loop() { sample = -1 * sample; } - i2s.write(sample); // Right channel - i2s.write(sample); // Left channel + // Left channel, the low 8 bits then high 8 bits + i2s.write(sample); + i2s.write(sample >> 8); + + // Right channel, the low 8 bits then high 8 bits + i2s.write(sample); + i2s.write(sample >> 8); // increment the counter for the next sample count++; diff --git a/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino b/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino index 6ee7dc6f846..025a53c913b 100644 --- a/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino +++ b/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino @@ -58,7 +58,7 @@ public: uint32_t msg_count = 0; // Create a broadcast peer object -ESP_NOW_Broadcast_Peer broadcast_peer(ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, NULL); +ESP_NOW_Broadcast_Peer broadcast_peer(ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, nullptr); /* Main */ diff --git a/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino b/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino index 5f1a8bd8807..e61524b64f9 100644 --- a/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino +++ b/libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino @@ -52,7 +52,8 @@ public: /* Global Variables */ // List of all the masters. It will be populated when a new master is registered -std::vector masters; +// Note: Using pointers instead of objects to prevent dangling pointers when the vector reallocates +std::vector masters; /* Callbacks */ @@ -62,13 +63,14 @@ void register_new_master(const esp_now_recv_info_t *info, const uint8_t *data, i Serial.printf("Unknown peer " MACSTR " sent a broadcast message\n", MAC2STR(info->src_addr)); Serial.println("Registering the peer as a master"); - ESP_NOW_Peer_Class new_master(info->src_addr, ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, NULL); - - masters.push_back(new_master); - if (!masters.back().add_peer()) { + ESP_NOW_Peer_Class *new_master = new ESP_NOW_Peer_Class(info->src_addr, ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, nullptr); + if (!new_master->add_peer()) { Serial.println("Failed to register the new master"); + delete new_master; return; } + masters.push_back(new_master); + Serial.printf("Successfully registered master " MACSTR " (total masters: %zu)\n", MAC2STR(new_master->addr()), masters.size()); } else { // The slave will only receive broadcast messages log_v("Received a unicast message from " MACSTR, MAC2STR(info->src_addr)); @@ -103,11 +105,23 @@ void setup() { } // Register the new peer callback - ESP_NOW.onNewPeer(register_new_master, NULL); + ESP_NOW.onNewPeer(register_new_master, nullptr); Serial.println("Setup complete. Waiting for a master to broadcast a message..."); } void loop() { - delay(1000); + // Print debug information every 10 seconds + static unsigned long last_debug = 0; + if (millis() - last_debug > 10000) { + last_debug = millis(); + Serial.printf("Registered masters: %zu\n", masters.size()); + for (size_t i = 0; i < masters.size(); i++) { + if (masters[i]) { + Serial.printf(" Master %zu: " MACSTR "\n", i, MAC2STR(masters[i]->addr())); + } + } + } + + delay(100); } diff --git a/libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino b/libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino index 48ea6b731ce..6731340c922 100644 --- a/libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino +++ b/libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino @@ -123,7 +123,7 @@ public: } bool send_message(const uint8_t *data, size_t len) { - if (data == NULL || len == 0) { + if (data == nullptr || len == 0) { log_e("Data to be sent is NULL or has a length of 0"); return false; } @@ -169,9 +169,12 @@ public: /* Peers */ -std::vector peers; // Create a vector to store the peer pointers -ESP_NOW_Network_Peer broadcast_peer(ESP_NOW.BROADCAST_ADDR, 0, NULL); // Register the broadcast peer (no encryption support for the broadcast address) -ESP_NOW_Network_Peer *master_peer = nullptr; // Pointer to peer that is the master +// Create a vector to store the peer pointers +std::vector peers; +// Register the broadcast peer (no encryption support for the broadcast address) +ESP_NOW_Network_Peer broadcast_peer(ESP_NOW.BROADCAST_ADDR, 0, nullptr); +// Pointer to the peer that is the master +ESP_NOW_Network_Peer *master_peer = nullptr; /* Helper functions */ @@ -279,7 +282,7 @@ void setup() { } // Register the callback to be called when a new peer is found - ESP_NOW.onNewPeer(register_new_peer, NULL); + ESP_NOW.onNewPeer(register_new_peer, nullptr); Serial.println("Setup complete. Broadcasting own priority to find the master..."); memset(&new_msg, 0, sizeof(new_msg)); diff --git a/libraries/ESP_NOW/src/ESP32_NOW.cpp b/libraries/ESP_NOW/src/ESP32_NOW.cpp index 6fd3ff0a0b1..25a5609e8db 100644 --- a/libraries/ESP_NOW/src/ESP32_NOW.cpp +++ b/libraries/ESP_NOW/src/ESP32_NOW.cpp @@ -9,12 +9,12 @@ #include "esp32-hal.h" #include "esp_wifi.h" -static void (*new_cb)(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) = NULL; -static void *new_arg = NULL; // * tx_arg = NULL, * rx_arg = NULL, +static void (*new_cb)(const esp_now_recv_info_t *info, const uint8_t *data, int len, void *arg) = nullptr; +static void *new_arg = nullptr; // * tx_arg = nullptr, * rx_arg = nullptr, static bool _esp_now_has_begun = false; static ESP_NOW_Peer *_esp_now_peers[ESP_NOW_MAX_TOTAL_PEER_NUM]; -static esp_err_t _esp_now_add_peer(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk, ESP_NOW_Peer *_peer = NULL) { +static esp_err_t _esp_now_add_peer(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk, ESP_NOW_Peer *_peer = nullptr) { log_v(MACSTR, MAC2STR(mac_addr)); if (esp_now_is_peer_exist(mac_addr)) { log_e("Peer Already Exists"); @@ -26,16 +26,16 @@ static esp_err_t _esp_now_add_peer(const uint8_t *mac_addr, uint8_t channel, wif memcpy(peer.peer_addr, mac_addr, ESP_NOW_ETH_ALEN); peer.channel = channel; peer.ifidx = iface; - peer.encrypt = lmk != NULL; + peer.encrypt = lmk != nullptr; if (lmk) { memcpy(peer.lmk, lmk, ESP_NOW_KEY_LEN); } esp_err_t result = esp_now_add_peer(&peer); if (result == ESP_OK) { - if (_peer != NULL) { + if (_peer != nullptr) { for (uint8_t i = 0; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) { - if (_esp_now_peers[i] == NULL) { + if (_esp_now_peers[i] == nullptr) { _esp_now_peers[i] = _peer; return ESP_OK; } @@ -67,8 +67,8 @@ static esp_err_t _esp_now_del_peer(const uint8_t *mac_addr) { } for (uint8_t i = 0; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) { - if (_esp_now_peers[i] != NULL && memcmp(mac_addr, _esp_now_peers[i]->addr(), ESP_NOW_ETH_ALEN) == 0) { - _esp_now_peers[i] = NULL; + if (_esp_now_peers[i] != nullptr && memcmp(mac_addr, _esp_now_peers[i]->addr(), ESP_NOW_ETH_ALEN) == 0) { + _esp_now_peers[i] = nullptr; break; } } @@ -87,7 +87,7 @@ static esp_err_t _esp_now_modify_peer(const uint8_t *mac_addr, uint8_t channel, memcpy(peer.peer_addr, mac_addr, ESP_NOW_ETH_ALEN); peer.channel = channel; peer.ifidx = iface; - peer.encrypt = lmk != NULL; + peer.encrypt = lmk != nullptr; if (lmk) { memcpy(peer.lmk, lmk, ESP_NOW_KEY_LEN); } @@ -111,17 +111,17 @@ static void _esp_now_rx_cb(const esp_now_recv_info_t *info, const uint8_t *data, bool broadcast = memcmp(info->des_addr, ESP_NOW.BROADCAST_ADDR, ESP_NOW_ETH_ALEN) == 0; log_v("%s from " MACSTR ", data length : %u", broadcast ? "Broadcast" : "Unicast", MAC2STR(info->src_addr), len); log_buf_v(data, len); - if (!esp_now_is_peer_exist(info->src_addr) && new_cb != NULL) { + if (!esp_now_is_peer_exist(info->src_addr) && new_cb != nullptr) { log_v("Calling new_cb, peer not found."); new_cb(info, data, len, new_arg); return; } //find the peer and call it's callback for (uint8_t i = 0; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) { - if (_esp_now_peers[i] != NULL) { + if (_esp_now_peers[i] != nullptr) { log_v("Checking peer " MACSTR, MAC2STR(_esp_now_peers[i]->addr())); } - if (_esp_now_peers[i] != NULL && memcmp(info->src_addr, _esp_now_peers[i]->addr(), ESP_NOW_ETH_ALEN) == 0) { + if (_esp_now_peers[i] != nullptr && memcmp(info->src_addr, _esp_now_peers[i]->addr(), ESP_NOW_ETH_ALEN) == 0) { log_v("Calling onReceive"); _esp_now_peers[i]->onReceive(data, len, broadcast); return; @@ -133,7 +133,7 @@ static void _esp_now_tx_cb(const uint8_t *mac_addr, esp_now_send_status_t status log_v(MACSTR " : %s", MAC2STR(mac_addr), (status == ESP_NOW_SEND_SUCCESS) ? "SUCCESS" : "FAILED"); //find the peer and call it's callback for (uint8_t i = 0; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) { - if (_esp_now_peers[i] != NULL && memcmp(mac_addr, _esp_now_peers[i]->addr(), ESP_NOW_ETH_ALEN) == 0) { + if (_esp_now_peers[i] != nullptr && memcmp(mac_addr, _esp_now_peers[i]->addr(), ESP_NOW_ETH_ALEN) == 0) { _esp_now_peers[i]->onSent(status == ESP_NOW_SEND_SUCCESS); return; } @@ -197,7 +197,7 @@ bool ESP_NOW_Class::end() { } //remove all peers for (uint8_t i = 0; i < ESP_NOW_MAX_TOTAL_PEER_NUM; i++) { - if (_esp_now_peers[i] != NULL) { + if (_esp_now_peers[i] != nullptr) { removePeer(*_esp_now_peers[i]); } } @@ -249,7 +249,7 @@ size_t ESP_NOW_Class::write(const uint8_t *data, size_t len) { if (len > ESP_NOW_MAX_DATA_LEN) { len = ESP_NOW_MAX_DATA_LEN; } - esp_err_t result = esp_now_send(NULL, data, len); + esp_err_t result = esp_now_send(nullptr, data, len); if (result == ESP_OK) { return len; } else if (result == ESP_ERR_ESPNOW_NOT_INIT) { @@ -292,7 +292,7 @@ ESP_NOW_Peer::ESP_NOW_Peer(const uint8_t *mac_addr, uint8_t channel, wifi_interf } chan = channel; ifc = iface; - encrypt = lmk != NULL; + encrypt = lmk != nullptr; if (encrypt) { memcpy(key, lmk, 16); } @@ -305,7 +305,7 @@ bool ESP_NOW_Peer::add() { if (added) { return true; } - if (_esp_now_add_peer(mac, chan, ifc, encrypt ? key : NULL, this) != ESP_OK) { + if (_esp_now_add_peer(mac, chan, ifc, encrypt ? key : nullptr, this) != ESP_OK) { return false; } log_v("Peer added - " MACSTR, MAC2STR(mac)); @@ -350,7 +350,7 @@ bool ESP_NOW_Peer::setChannel(uint8_t channel) { if (!_esp_now_has_begun || !added) { return true; } - return _esp_now_modify_peer(mac, chan, ifc, encrypt ? key : NULL) == ESP_OK; + return _esp_now_modify_peer(mac, chan, ifc, encrypt ? key : nullptr) == ESP_OK; } wifi_interface_t ESP_NOW_Peer::getInterface() const { @@ -362,7 +362,7 @@ bool ESP_NOW_Peer::setInterface(wifi_interface_t iface) { if (!_esp_now_has_begun || !added) { return true; } - return _esp_now_modify_peer(mac, chan, ifc, encrypt ? key : NULL) == ESP_OK; + return _esp_now_modify_peer(mac, chan, ifc, encrypt ? key : nullptr) == ESP_OK; } bool ESP_NOW_Peer::isEncrypted() const { @@ -370,14 +370,14 @@ bool ESP_NOW_Peer::isEncrypted() const { } bool ESP_NOW_Peer::setKey(const uint8_t *lmk) { - encrypt = lmk != NULL; + encrypt = lmk != nullptr; if (encrypt) { memcpy(key, lmk, 16); } if (!_esp_now_has_begun || !added) { return true; } - return _esp_now_modify_peer(mac, chan, ifc, encrypt ? key : NULL) == ESP_OK; + return _esp_now_modify_peer(mac, chan, ifc, encrypt ? key : nullptr) == ESP_OK; } size_t ESP_NOW_Peer::send(const uint8_t *data, int len) { diff --git a/libraries/ESP_NOW/src/ESP32_NOW.h b/libraries/ESP_NOW/src/ESP32_NOW.h index efba9243aee..5940cfa2221 100644 --- a/libraries/ESP_NOW/src/ESP32_NOW.h +++ b/libraries/ESP_NOW/src/ESP32_NOW.h @@ -20,7 +20,7 @@ class ESP_NOW_Class : public Print { ESP_NOW_Class(); ~ESP_NOW_Class(); - bool begin(const uint8_t *pmk = NULL /* 16 bytes */); + bool begin(const uint8_t *pmk = nullptr /* 16 bytes */); bool end(); int getTotalPeerCount(); @@ -50,7 +50,7 @@ class ESP_NOW_Peer { bool remove(); size_t send(const uint8_t *data, int len); - ESP_NOW_Peer(const uint8_t *mac_addr, uint8_t channel = 0, wifi_interface_t iface = WIFI_IF_AP, const uint8_t *lmk = NULL); + ESP_NOW_Peer(const uint8_t *mac_addr, uint8_t channel = 0, wifi_interface_t iface = WIFI_IF_AP, const uint8_t *lmk = nullptr); public: virtual ~ESP_NOW_Peer() {} diff --git a/libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp b/libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp index 5603da2ba13..edd6e32aacc 100644 --- a/libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp +++ b/libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp @@ -18,11 +18,11 @@ ESP_NOW_Serial_Class::ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk, bool remove_on_fail) : ESP_NOW_Peer(mac_addr, channel, iface, lmk) { - tx_ring_buf = NULL; - rx_queue = NULL; - tx_sem = NULL; + tx_ring_buf = nullptr; + rx_queue = nullptr; + tx_sem = nullptr; queued_size = 0; - queued_buff = NULL; + queued_buff = nullptr; resend_count = 0; _remove_on_fail = remove_on_fail; } @@ -34,7 +34,7 @@ ESP_NOW_Serial_Class::~ESP_NOW_Serial_Class() { size_t ESP_NOW_Serial_Class::setTxBufferSize(size_t tx_queue_len) { if (tx_ring_buf) { vRingbufferDelete(tx_ring_buf); - tx_ring_buf = NULL; + tx_ring_buf = nullptr; } if (!tx_queue_len) { return 0; @@ -49,7 +49,7 @@ size_t ESP_NOW_Serial_Class::setTxBufferSize(size_t tx_queue_len) { size_t ESP_NOW_Serial_Class::setRxBufferSize(size_t rx_queue_len) { if (rx_queue) { vQueueDelete(rx_queue); - rx_queue = NULL; + rx_queue = nullptr; } if (!rx_queue_len) { return 0; @@ -65,7 +65,7 @@ bool ESP_NOW_Serial_Class::begin(unsigned long baud) { if (!ESP_NOW.begin() || !add()) { return false; } - if (tx_sem == NULL) { + if (tx_sem == nullptr) { tx_sem = xSemaphoreCreateBinary(); //xSemaphoreTake(tx_sem, 0); xSemaphoreGive(tx_sem); @@ -79,22 +79,22 @@ void ESP_NOW_Serial_Class::end() { remove(); setRxBufferSize(0); setTxBufferSize(0); - if (tx_sem != NULL) { + if (tx_sem != nullptr) { vSemaphoreDelete(tx_sem); - tx_sem = NULL; + tx_sem = nullptr; } } //Stream int ESP_NOW_Serial_Class::available(void) { - if (rx_queue == NULL) { + if (rx_queue == nullptr) { return 0; } return uxQueueMessagesWaiting(rx_queue); } int ESP_NOW_Serial_Class::peek(void) { - if (rx_queue == NULL) { + if (rx_queue == nullptr) { return -1; } uint8_t c; @@ -105,7 +105,7 @@ int ESP_NOW_Serial_Class::peek(void) { } int ESP_NOW_Serial_Class::read(void) { - if (rx_queue == NULL) { + if (rx_queue == nullptr) { return -1; } uint8_t c = 0; @@ -116,7 +116,7 @@ int ESP_NOW_Serial_Class::read(void) { } size_t ESP_NOW_Serial_Class::read(uint8_t *buffer, size_t size) { - if (rx_queue == NULL) { + if (rx_queue == nullptr) { return -1; } uint8_t c = 0; @@ -128,11 +128,11 @@ size_t ESP_NOW_Serial_Class::read(uint8_t *buffer, size_t size) { } void ESP_NOW_Serial_Class::flush() { - if (tx_ring_buf == NULL) { + if (tx_ring_buf == nullptr) { return; } UBaseType_t uxItemsWaiting = 0; - vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); + vRingbufferGetInfo(tx_ring_buf, nullptr, nullptr, nullptr, nullptr, &uxItemsWaiting); if (uxItemsWaiting) { // Now trigger the ISR to read data from the ring buffer. if (xSemaphoreTake(tx_sem, 0) == pdTRUE) { @@ -141,13 +141,13 @@ void ESP_NOW_Serial_Class::flush() { } while (uxItemsWaiting) { delay(5); - vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); + vRingbufferGetInfo(tx_ring_buf, nullptr, nullptr, nullptr, nullptr, &uxItemsWaiting); } } //RX callback void ESP_NOW_Serial_Class::onReceive(const uint8_t *data, size_t len, bool broadcast) { - if (rx_queue == NULL) { + if (rx_queue == nullptr) { return; } for (uint32_t i = 0; i < len; i++) { @@ -165,7 +165,7 @@ void ESP_NOW_Serial_Class::onReceive(const uint8_t *data, size_t len, bool broad //Print int ESP_NOW_Serial_Class::availableForWrite() { //return ESP_NOW_MAX_DATA_LEN; - if (tx_ring_buf == NULL) { + if (tx_ring_buf == nullptr) { return 0; } return xRingbufferGetCurFreeSize(tx_ring_buf); @@ -178,7 +178,7 @@ size_t ESP_NOW_Serial_Class::tryToSend() { //_onSent will not be called anymore //the data is lost in this case vRingbufferReturnItem(tx_ring_buf, queued_buff); - queued_buff = NULL; + queued_buff = nullptr; xSemaphoreGive(tx_sem); end(); } @@ -188,12 +188,12 @@ size_t ESP_NOW_Serial_Class::tryToSend() { bool ESP_NOW_Serial_Class::checkForTxData() { //do we have something that failed the last time? resend_count = 0; - if (queued_buff == NULL) { + if (queued_buff == nullptr) { queued_buff = (uint8_t *)xRingbufferReceiveUpTo(tx_ring_buf, &queued_size, 0, ESP_NOW_MAX_DATA_LEN); } else { log_d(MACSTR " : PREVIOUS", MAC2STR(addr())); } - if (queued_buff != NULL) { + if (queued_buff != nullptr) { return tryToSend() > 0; } //log_d(MACSTR ": EMPTY", MAC2STR(addr())); @@ -203,7 +203,7 @@ bool ESP_NOW_Serial_Class::checkForTxData() { size_t ESP_NOW_Serial_Class::write(const uint8_t *buffer, size_t size, uint32_t timeout) { log_v(MACSTR ", size %u", MAC2STR(addr()), size); - if (tx_sem == NULL || tx_ring_buf == NULL || !added) { + if (tx_sem == nullptr || tx_ring_buf == nullptr || !added) { return 0; } size_t space = availableForWrite(); @@ -249,12 +249,12 @@ size_t ESP_NOW_Serial_Class::write(const uint8_t *buffer, size_t size, uint32_t //TX Done Callback void ESP_NOW_Serial_Class::onSent(bool success) { log_v(MACSTR " : %s", MAC2STR(addr()), success ? "OK" : "FAIL"); - if (tx_sem == NULL || tx_ring_buf == NULL || !added) { + if (tx_sem == nullptr || tx_ring_buf == nullptr || !added) { return; } if (success) { vRingbufferReturnItem(tx_ring_buf, queued_buff); - queued_buff = NULL; + queued_buff = nullptr; //send next packet? //log_d(MACSTR ": NEXT", MAC2STR(addr())); checkForTxData(); @@ -269,7 +269,7 @@ void ESP_NOW_Serial_Class::onSent(bool success) { //resend limit reached //the data is lost in this case vRingbufferReturnItem(tx_ring_buf, queued_buff); - queued_buff = NULL; + queued_buff = nullptr; log_e(MACSTR " : RE-SEND_MAX[%u]", MAC2STR(addr()), resend_count); //if we are not able to send the data and remove_on_fail is set, remove the peer if (_remove_on_fail) { diff --git a/libraries/ESP_NOW/src/ESP32_NOW_Serial.h b/libraries/ESP_NOW/src/ESP32_NOW_Serial.h index 7cc43d85ef8..5ccb7763ec2 100644 --- a/libraries/ESP_NOW/src/ESP32_NOW_Serial.h +++ b/libraries/ESP_NOW/src/ESP32_NOW_Serial.h @@ -28,7 +28,9 @@ class ESP_NOW_Serial_Class : public Stream, public ESP_NOW_Peer { size_t tryToSend(); public: - ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface = WIFI_IF_AP, const uint8_t *lmk = NULL, bool remove_on_fail = false); + ESP_NOW_Serial_Class( + const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface = WIFI_IF_AP, const uint8_t *lmk = nullptr, bool remove_on_fail = false + ); ~ESP_NOW_Serial_Class(); size_t setRxBufferSize(size_t); size_t setTxBufferSize(size_t); diff --git a/libraries/ESP_SR/src/esp32-hal-sr.c b/libraries/ESP_SR/src/esp32-hal-sr.c index 06db7236541..eb87ef636c1 100644 --- a/libraries/ESP_SR/src/esp32-hal-sr.c +++ b/libraries/ESP_SR/src/esp32-hal-sr.c @@ -192,6 +192,7 @@ static void audio_feed_task(void *arg) { /* Feed samples of an audio stream to the AFE_SR */ g_sr_data->afe_handle->feed(g_sr_data->afe_data, audio_buffer); + vTaskDelay(2); } vTaskDelete(NULL); } diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.cpp b/libraries/HTTPUpdate/src/HTTPUpdate.cpp index 1eda0a4f7e5..b463ffe2e83 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.cpp +++ b/libraries/HTTPUpdate/src/HTTPUpdate.cpp @@ -356,6 +356,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤ log_e("Content-Length was 0 or wasn't set by Server?!\n"); } break; + case HTTP_CODE_NO_CONTENT: case HTTP_CODE_NOT_MODIFIED: ///< Not Modified (No updates) ret = HTTP_UPDATE_NO_UPDATES; diff --git a/libraries/Matter/examples/MatterEvents/MatterEvents.ino b/libraries/Matter/examples/MatterEvents/MatterEvents.ino new file mode 100644 index 00000000000..dac599bf9fa --- /dev/null +++ b/libraries/Matter/examples/MatterEvents/MatterEvents.ino @@ -0,0 +1,168 @@ +// Copyright 2025 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 + +// 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 + +// List of Matter Endpoints for this Node +// On/Off Light Endpoint +MatterOnOffLight OnOffLight; + +// This function is called when a Matter event occurs +void onMatterEvent(matterEvent_t eventType, const chip::DeviceLayer::ChipDeviceEvent *eventInfo) { + // Print the event type to Serial + Serial.print("===> Got a Matter Event: "); + switch (eventType) { + case MATTER_WIFI_CONNECTIVITY_CHANGE: Serial.println("WiFi Connectivity Change"); break; + case MATTER_THREAD_CONNECTIVITY_CHANGE: Serial.println("Thread Connectivity Change"); break; + case MATTER_INTERNET_CONNECTIVITY_CHANGE: + { + bool newIPAddress = false; + Serial.print("Internet Connectivity Change :: "); + if (eventInfo->InternetConnectivityChange.IPv4 != chip::DeviceLayer::ConnectivityChange::kConnectivity_NoChange) { + Serial.print("IPv4 Connectivity: "); + switch (eventInfo->InternetConnectivityChange.IPv4) { + case chip::DeviceLayer::ConnectivityChange::kConnectivity_Established: + { + newIPAddress = true; + break; + } + case chip::DeviceLayer::ConnectivityChange::kConnectivity_Lost: Serial.println("Lost"); break; + default: Serial.println("Unknown"); break; + } + } + if (eventInfo->InternetConnectivityChange.IPv6 != chip::DeviceLayer::ConnectivityChange::kConnectivity_NoChange) { + Serial.print("IPv6 Connectivity: "); + switch (eventInfo->InternetConnectivityChange.IPv6) { + case chip::DeviceLayer::ConnectivityChange::kConnectivity_Established: + { + newIPAddress = true; + break; + } + case chip::DeviceLayer::ConnectivityChange::kConnectivity_Lost: Serial.println("Lost"); break; + default: Serial.println("Unknown"); break; + } + } + // Print the IP address if it was established + if (newIPAddress) { + Serial.print("Established - IP Address: "); + char ipAddressStr[chip::Transport::PeerAddress::kMaxToStringSize]; + eventInfo->InternetConnectivityChange.ipAddress.ToString(ipAddressStr); + Serial.println(ipAddressStr); + } + break; + } + case MATTER_SERVICE_CONNECTIVITY_CHANGE: Serial.println("Service Connectivity Change"); break; + case MATTER_SERVICE_PROVISIONING_CHANGE: Serial.println("Service Provisioning Change"); break; + case MATTER_TIME_SYNC_CHANGE: Serial.println("Time Sync Change"); break; + case MATTER_CHIPOBLE_CONNECTION_ESTABLISHED: Serial.println("CHIPoBLE Connection Established"); break; + case MATTER_CHIPOBLE_CONNECTION_CLOSED: Serial.println("CHIPoBLE Connection Closed"); break; + case MATTER_CLOSE_ALL_BLE_CONNECTIONS: Serial.println("Close All BLE Connections"); break; + case MATTER_WIFI_DEVICE_AVAILABLE: Serial.println("WiFi Device Available"); break; + case MATTER_OPERATIONAL_NETWORK_STARTED: Serial.println("Operational Network Started"); break; + case MATTER_THREAD_STATE_CHANGE: Serial.println("Thread State Change"); break; + case MATTER_THREAD_INTERFACE_STATE_CHANGE: Serial.println("Thread Interface State Change"); break; + case MATTER_CHIPOBLE_ADVERTISING_CHANGE: Serial.println("CHIPoBLE Advertising Change"); break; + case MATTER_INTERFACE_IP_ADDRESS_CHANGED: + switch (eventInfo->InterfaceIpAddressChanged.Type) { + case chip::DeviceLayer::InterfaceIpChangeType::kIpV4_Assigned: Serial.println("IPv4 Address Assigned"); break; + case chip::DeviceLayer::InterfaceIpChangeType::kIpV4_Lost: Serial.println("IPv4 Address Lost"); break; + case chip::DeviceLayer::InterfaceIpChangeType::kIpV6_Assigned: Serial.println("IPv6 Address Assigned"); break; + case chip::DeviceLayer::InterfaceIpChangeType::kIpV6_Lost: Serial.println("IPv6 Address Lost"); break; + } + break; + case MATTER_COMMISSIONING_COMPLETE: Serial.println("Commissioning Complete"); break; + case MATTER_FAIL_SAFE_TIMER_EXPIRED: Serial.println("Fail Safe Timer Expired"); break; + case MATTER_OPERATIONAL_NETWORK_ENABLED: Serial.println("Operational Network Enabled"); break; + case MATTER_DNSSD_INITIALIZED: Serial.println("DNS-SD Initialized"); break; + case MATTER_DNSSD_RESTART_NEEDED: Serial.println("DNS-SD Restart Needed"); break; + case MATTER_BINDINGS_CHANGED_VIA_CLUSTER: Serial.println("Bindings Changed Via Cluster"); break; + case MATTER_OTA_STATE_CHANGED: Serial.println("OTA State Changed"); break; + case MATTER_SERVER_READY: Serial.println("Server Ready"); break; + case MATTER_BLE_DEINITIALIZED: Serial.println("BLE Deinitialized"); break; + case MATTER_COMMISSIONING_SESSION_STARTED: Serial.println("Commissioning Session Started"); break; + case MATTER_COMMISSIONING_SESSION_STOPPED: Serial.println("Commissioning Session Stopped"); break; + case MATTER_COMMISSIONING_WINDOW_OPEN: Serial.println("Commissioning Window Opened"); break; + case MATTER_COMMISSIONING_WINDOW_CLOSED: Serial.println("Commissioning Window Closed"); break; + case MATTER_FABRIC_WILL_BE_REMOVED: Serial.println("Fabric Will Be Removed"); break; + case MATTER_FABRIC_REMOVED: Serial.println("Fabric Removed"); break; + case MATTER_FABRIC_COMMITTED: Serial.println("Fabric Committed"); break; + case MATTER_FABRIC_UPDATED: Serial.println("Fabric Updated"); break; + case MATTER_ESP32_SPECIFIC_EVENT: Serial.println("Sending ESP32 Platform Specific Events"); break; + case MATTER_ESP32_PUBLIC_SPECIFIC_EVENT: Serial.println("Next Event Has Populated EventInfo"); break; + default: + // If the event type is not recognized, print "Unknown" and the event ID + Serial.println("Unknown, EventID = 0x" + String(eventType, HEX)); + break; + } +} + +void setup() { + Serial.begin(115200); + while (!Serial) { + delay(10); // Wait for Serial to initialize + } + + // We start by connecting to a WiFi network + Serial.print("Connecting to "); + Serial.println(ssid); + // Manually connect to WiFi + WiFi.enableIPv6(true); // Enable IPv6 if needed + 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 at least one Matter EndPoint + OnOffLight.begin(); + + // Set the Matter Event Callback + Matter.onEvent(onMatterEvent); + // Matter beginning - Last step, after all EndPoints are initialized + Matter.begin(); + Serial.println("Starting Matter Commission Test..."); +} + +void loop() { + // Check Matter Commissioning state + 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. + while (!Matter.isDeviceCommissioned()) { + delay(5000); + Serial.println("Matter Fabric not commissioned yet. Waiting for commissioning."); + } + } + Serial.println("Matter Node is commissioned and connected to Wi-Fi."); + Serial.println("====> Decommissioning in 60 seconds. <===="); + delay(60000); + Matter.decommission(); + Serial.println("Matter Node is decommissioned. Commissioning widget shall start over."); +} diff --git a/libraries/Matter/examples/MatterEvents/ci.json b/libraries/Matter/examples/MatterEvents/ci.json new file mode 100644 index 00000000000..556a8a9ee6b --- /dev/null +++ b/libraries/Matter/examples/MatterEvents/ci.json @@ -0,0 +1,7 @@ +{ + "fqbn_append": "PartitionScheme=huge_app", + "requires": [ + "CONFIG_SOC_WIFI_SUPPORTED=y", + "CONFIG_ESP_MATTER_ENABLE_DATA_MODEL=y" + ] +} diff --git a/libraries/Matter/keywords.txt b/libraries/Matter/keywords.txt index a63d9a65acb..68aaebb1d4d 100644 --- a/libraries/Matter/keywords.txt +++ b/libraries/Matter/keywords.txt @@ -36,6 +36,8 @@ EndPointSpeedCB KEYWORD1 EndPointOnOffCB KEYWORD1 EndPointBrightnessCB KEYWORD1 EndPointRGBColorCB KEYWORD1 +matterEvent_t KEYWORD1 +matterEventCB KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) @@ -108,6 +110,7 @@ onChangeMode KEYWORD2 onChangeLocalTemperature KEYWORD2 onChangeCoolingSetpoint KEYWORD2 onChangeHeatingSetpoint KEYWORD2 +onEvent KEYWORD2 ####################################### # Constants (LITERAL1) @@ -144,5 +147,37 @@ THERMOSTAT_MODE_OFF LITERAL1 THERMOSTAT_MODE_AUTO LITERAL1 THERMOSTAT_MODE_COOL LITERAL1 THERMOSTAT_MODE_HEAT LITERAL1 -THERMOSTAT_AUTO_MODE_DISABLED LITERAL1 -THERMOSTAT_AUTO_MODE_ENABLED LITERAL1 +MATTER_WIFI_CONNECTIVITY_CHANGE LITERAL1 +MATTER_THREAD_CONNECTIVITY_CHANGE LITERAL1 +MATTER_INTERNET_CONNECTIVITY_CHANGE LITERAL1 +MATTER_SERVICE_CONNECTIVITY_CHANGE LITERAL1 +MATTER_SERVICE_PROVISIONING_CHANGE LITERAL1 +MATTER_TIME_SYNC_CHANGE LITERAL1 +MATTER_CHIPOBLE_CONNECTION_ESTABLISHED LITERAL1 +MATTER_CHIPOBLE_CONNECTION_CLOSED LITERAL1 +MATTER_CLOSE_ALL_BLE_CONNECTIONS LITERAL1 +MATTER_WIFI_DEVICE_AVAILABLE LITERAL1 +MATTER_OPERATIONAL_NETWORK_STARTED LITERAL1 +MATTER_THREAD_STATE_CHANGE LITERAL1 +MATTER_THREAD_INTERFACE_STATE_CHANGE LITERAL1 +MATTER_CHIPOBLE_ADVERTISING_CHANGE LITERAL1 +MATTER_INTERFACE_IP_ADDRESS_CHANGED LITERAL1 +MATTER_COMMISSIONING_COMPLETE LITERAL1 +MATTER_FAIL_SAFE_TIMER_EXPIRED LITERAL1 +MATTER_OPERATIONAL_NETWORK_ENABLED LITERAL1 +MATTER_DNSSD_INITIALIZED LITERAL1 +MATTER_DNSSD_RESTART_NEEDED LITERAL1 +MATTER_BINDINGS_CHANGED_VIA_CLUSTER LITERAL1 +MATTER_OTA_STATE_CHANGED LITERAL1 +MATTER_SERVER_READY LITERAL1 +MATTER_BLE_DEINITIALIZED LITERAL1 +MATTER_ESP32_SPECIFIC_EVENT LITERAL1 +MATTER_COMMISSIONING_SESSION_STARTED LITERAL1 +MATTER_COMMISSIONING_SESSION_STOPPED LITERAL1 +MATTER_COMMISSIONING_WINDOW_OPEN LITERAL1 +MATTER_COMMISSIONING_WINDOW_CLOSED LITERAL1 +MATTER_FABRIC_WILL_BE_REMOVED LITERAL1 +MATTER_FABRIC_REMOVED LITERAL1 +MATTER_FABRIC_COMMITTED LITERAL1 +MATTER_FABRIC_UPDATED LITERAL1 +MATTER_ESP32_PUBLIC_SPECIFIC_EVENT LITERAL1 diff --git a/libraries/Matter/src/Matter.cpp b/libraries/Matter/src/Matter.cpp index af7c4c8657e..b16edfd85c1 100644 --- a/libraries/Matter/src/Matter.cpp +++ b/libraries/Matter/src/Matter.cpp @@ -28,7 +28,8 @@ constexpr auto k_timeout_seconds = 300; static bool _matter_has_started = false; static node::config_t node_config; -static node_t *deviceNode = NULL; +static node_t *deviceNode = nullptr; +ArduinoMatter::matterEventCB ArduinoMatter::_matterEventCB = nullptr; // 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 @@ -42,7 +43,7 @@ static esp_err_t app_attribute_update_cb( switch (type) { case PRE_UPDATE: // Callback before updating the value in the database log_v("Attribute update callback: PRE_UPDATE"); - if (ep != NULL) { + if (ep != nullptr) { err = ep->attributeChangeCB(endpoint_id, cluster_id, attribute_id, val) ? ESP_OK : ESP_FAIL; } break; @@ -78,7 +79,7 @@ static esp_err_t app_identification_cb(identification::callback_type_t type, uin identifyIsActive = false; log_v("Identification callback: STOP"); } - if (ep != NULL) { + if (ep != nullptr) { err = ep->endpointIdentifyCB(endpoint_id, identifyIsActive) ? ESP_OK : ESP_FAIL; } @@ -89,21 +90,21 @@ static esp_err_t app_identification_cb(identification::callback_type_t type, uin static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { switch (event->Type) { case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: - log_i( + log_d( "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::kCommissioningComplete: log_d("Commissioning complete"); break; + case chip::DeviceLayer::DeviceEventType::kFailSafeTimerExpired: log_d("Commissioning failed, fail safe timer expired"); break; + case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStarted: log_d("Commissioning session started"); break; + case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStopped: log_d("Commissioning session stopped"); break; + case chip::DeviceLayer::DeviceEventType::kCommissioningWindowOpened: log_d("Commissioning window opened"); break; + case chip::DeviceLayer::DeviceEventType::kCommissioningWindowClosed: log_d("Commissioning window closed"); break; case chip::DeviceLayer::DeviceEventType::kFabricRemoved: { - log_i("Fabric removed successfully"); + log_d("Fabric removed successfully"); if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0) { - log_i("No fabric left, opening commissioning window"); + log_d("No fabric left, opening commissioning window"); chip::CommissioningWindowManager &commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager(); constexpr auto kTimeoutSeconds = chip::System::Clock::Seconds16(k_timeout_seconds); if (!commissionMgr.IsCommissioningWindowOpen()) { @@ -116,12 +117,16 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { } 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; + case chip::DeviceLayer::DeviceEventType::kFabricWillBeRemoved: log_d("Fabric will be removed"); break; + case chip::DeviceLayer::DeviceEventType::kFabricUpdated: log_d("Fabric is updated"); break; + case chip::DeviceLayer::DeviceEventType::kFabricCommitted: log_d("Fabric is committed"); break; + case chip::DeviceLayer::DeviceEventType::kBLEDeinitialized: log_d("BLE deinitialized and memory reclaimed"); break; default: break; } + // Check if the user-defined callback is set + if (ArduinoMatter::_matterEventCB != nullptr) { + ArduinoMatter::_matterEventCB(static_cast(event->Type), event); + } } void ArduinoMatter::_init() { diff --git a/libraries/Matter/src/Matter.h b/libraries/Matter/src/Matter.h index e54ceb47e5e..682a0498076 100644 --- a/libraries/Matter/src/Matter.h +++ b/libraries/Matter/src/Matter.h @@ -34,10 +34,136 @@ #include #include +// Matter Event types used when there is a user callback for Matter Events +enum matterEvent_t { + // Starting from 0x8000, these events are public and can be used by applications. + // Defined in CHIPDeviceEvent.h + + // WiFi Connectivity Change: Signals a change in connectivity of the device's WiFi station interface. + MATTER_WIFI_CONNECTIVITY_CHANGE = (uint16_t)chip::DeviceLayer::DeviceEventType::kWiFiConnectivityChange, + + // Thread Connectivity Change: Signals a change in connectivity of the device's Thread interface. + MATTER_THREAD_CONNECTIVITY_CHANGE = (uint16_t)chip::DeviceLayer::DeviceEventType::kThreadConnectivityChange, + + // Internet Connectivity Change: Signals a change in the device's ability to communicate via the Internet. + MATTER_INTERNET_CONNECTIVITY_CHANGE = (uint16_t)chip::DeviceLayer::DeviceEventType::kInternetConnectivityChange, + + // Service Connectivity Change: Signals a change in the device's ability to communicate with a chip-enabled service. + MATTER_SERVICE_CONNECTIVITY_CHANGE = (uint16_t)chip::DeviceLayer::DeviceEventType::kServiceConnectivityChange, + + // Service Provisioning Change: Signals a change to the device's service provisioning state. + MATTER_SERVICE_PROVISIONING_CHANGE = (uint16_t)chip::DeviceLayer::DeviceEventType::kServiceProvisioningChange, + + // Time Sync Change: Signals a change to the device's real time clock synchronization state. + MATTER_TIME_SYNC_CHANGE = (uint16_t)chip::DeviceLayer::DeviceEventType::kTimeSyncChange, + + // CHIPoBLE Connection Established: Signals that an external entity has established a new + // CHIPoBLE connection with the device. + MATTER_CHIPOBLE_CONNECTION_ESTABLISHED = (uint16_t)chip::DeviceLayer::DeviceEventType::kCHIPoBLEConnectionEstablished, + + // CHIPoBLE Connection Closed: Signals that an external entity has closed existing CHIPoBLE + // connection with the device. + MATTER_CHIPOBLE_CONNECTION_CLOSED = (uint16_t)chip::DeviceLayer::DeviceEventType::kCHIPoBLEConnectionClosed, + + // Request BLE connections to be closed. This is used in the supportsConcurrentConnection = False case. + MATTER_CLOSE_ALL_BLE_CONNECTIONS = (uint16_t)chip::DeviceLayer::DeviceEventType::kCloseAllBleConnections, + + // WiFi Device Available: When supportsConcurrentConnection = False, the ConnectNetwork + // command cannot start until the BLE device is closed and the Operation Network device (e.g. WiFi) has been started. + MATTER_WIFI_DEVICE_AVAILABLE = (uint16_t)chip::DeviceLayer::DeviceEventType::kWiFiDeviceAvailable, + + MATTER_OPERATIONAL_NETWORK_STARTED = (uint16_t)chip::DeviceLayer::DeviceEventType::kOperationalNetworkStarted, + + // Thread State Change: Signals that a state change has occurred in the Thread stack. + MATTER_THREAD_STATE_CHANGE = (uint16_t)chip::DeviceLayer::DeviceEventType::kThreadStateChange, + + // Thread Interface State Change: Signals that the state of the Thread network interface has changed. + MATTER_THREAD_INTERFACE_STATE_CHANGE = (uint16_t)chip::DeviceLayer::DeviceEventType::kThreadInterfaceStateChange, + + // CHIPoBLE Advertising Change: Signals that the state of CHIPoBLE advertising has changed. + MATTER_CHIPOBLE_ADVERTISING_CHANGE = (uint16_t)chip::DeviceLayer::DeviceEventType::kCHIPoBLEAdvertisingChange, + + // Interface IP Address Changed: IP address availability - either ipv4 or ipv6 + // addresses assigned to the underlying wifi/ethernet interface. + MATTER_INTERFACE_IP_ADDRESS_CHANGED = (uint16_t)chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged, + + // Commissioning Complete: Commissioning has completed by a call to the general + // commissioning cluster command. + MATTER_COMMISSIONING_COMPLETE = (uint16_t)chip::DeviceLayer::DeviceEventType::kCommissioningComplete, + + // Fail Safe Timer Expired: Signals that the fail-safe timer expired before + // the CommissioningComplete command was successfully invoked. + MATTER_FAIL_SAFE_TIMER_EXPIRED = (uint16_t)chip::DeviceLayer::DeviceEventType::kFailSafeTimerExpired, + + // Operational Network Enabled. + MATTER_OPERATIONAL_NETWORK_ENABLED = (uint16_t)chip::DeviceLayer::DeviceEventType::kOperationalNetworkEnabled, + + // DNS-SD Initialized: Signals that DNS-SD has been initialized and is ready to operate. + MATTER_DNSSD_INITIALIZED = (uint16_t)chip::DeviceLayer::DeviceEventType::kDnssdInitialized, + + // DNS-SD Restart Needed: Signals that DNS-SD backend was restarted and services must be published again. + MATTER_DNSSD_RESTART_NEEDED = (uint16_t)chip::DeviceLayer::DeviceEventType::kDnssdRestartNeeded, + + // Bindings Changed Via Cluster: Signals that bindings were updated. + MATTER_BINDINGS_CHANGED_VIA_CLUSTER = (uint16_t)chip::DeviceLayer::DeviceEventType::kBindingsChangedViaCluster, + + // OTA State Changed: Signals that the state of the OTA engine changed. + MATTER_OTA_STATE_CHANGED = (uint16_t)chip::DeviceLayer::DeviceEventType::kOtaStateChanged, + + // Server Ready: Server initialization has completed. Signals that all server components have been initialized + // and the node is ready to establish connections with other nodes. This event can be used to trigger on-boot actions + // that require sending messages to other nodes. + MATTER_SERVER_READY = (uint16_t)chip::DeviceLayer::DeviceEventType::kServerReady, + + // BLE Deinitialized: Signals that BLE stack is deinitialized and memory reclaimed + MATTER_BLE_DEINITIALIZED = (uint16_t)chip::DeviceLayer::DeviceEventType::kBLEDeinitialized, + + // Starting ESP32 Platform Specific Events from 0x9000 + MATTER_ESP32_SPECIFIC_EVENT, // value is previous + 1 + + // Commissioning Session Started: Signals that Commissioning session has started + MATTER_COMMISSIONING_SESSION_STARTED = (uint16_t)chip::DeviceLayer::DeviceEventType::kCommissioningSessionStarted, + + // Commissioning Session Stopped: Signals that Commissioning session has stopped + MATTER_COMMISSIONING_SESSION_STOPPED = (uint16_t)chip::DeviceLayer::DeviceEventType::kCommissioningSessionStopped, + + // Commissioning Window Opened: Signals that Commissioning window is now opened + MATTER_COMMISSIONING_WINDOW_OPEN = (uint16_t)chip::DeviceLayer::DeviceEventType::kCommissioningWindowOpened, + + // Commissioning Window Closed: Signals that Commissioning window is now closed + MATTER_COMMISSIONING_WINDOW_CLOSED = (uint16_t)chip::DeviceLayer::DeviceEventType::kCommissioningWindowClosed, + + // Fabric Will Be Removed: Signals that a fabric is about to be deleted. This allows actions to be taken that need the + // fabric to still be around before we delete it + MATTER_FABRIC_WILL_BE_REMOVED = (uint16_t)chip::DeviceLayer::DeviceEventType::kFabricWillBeRemoved, + + // Fabric Has Been Removed: Signals that a fabric is effectively deleted + MATTER_FABRIC_REMOVED = (uint16_t)chip::DeviceLayer::DeviceEventType::kFabricRemoved, + + // Fabric Has Been Committed: Signals that a fabric in Fabric Table is persisted to storage, by CommitPendingFabricData + MATTER_FABRIC_COMMITTED = (uint16_t)chip::DeviceLayer::DeviceEventType::kFabricCommitted, + + // Fabric Has Been Updated: Signals that operational credentials are changed, which may not be persistent. + // Can be used to affect what is needed for UpdateNOC prior to commit + MATTER_FABRIC_UPDATED = (uint16_t)chip::DeviceLayer::DeviceEventType::kFabricUpdated, + + // ESP32 Matter Events: These are custom ESP32 Matter events as defined in CHIPDevicePlatformEvent.h. + MATTER_ESP32_PUBLIC_SPECIFIC_EVENT = (uint16_t)chip::DeviceLayer::DeviceEventType::kRange_PublicPlatformSpecific, // ESPSystemEvent +}; + using namespace esp_matter; class ArduinoMatter { public: + // Matter Event Callback type + using matterEventCB = std::function; + // Matter Event Callback + static matterEventCB _matterEventCB; + // set the Matter Event Callback + static void onEvent(matterEventCB cb) { + _matterEventCB = cb; + } + static inline String getManualPairingCode() { // return the pairing code for manual pairing return String("34970112332"); diff --git a/libraries/Matter/src/MatterEndPoint.h b/libraries/Matter/src/MatterEndPoint.h index 5baa4747d18..95d3d3c08df 100644 --- a/libraries/Matter/src/MatterEndPoint.h +++ b/libraries/Matter/src/MatterEndPoint.h @@ -41,22 +41,22 @@ class MatterEndPoint { esp_matter::attribute_t *getAttribute(uint32_t cluster_id, uint32_t attribute_id) { if (endpoint_id == 0) { log_e("Endpoint ID is not set"); - return NULL; + return nullptr; } endpoint_t *endpoint = endpoint::get(node::get(), endpoint_id); - if (endpoint == NULL) { + if (endpoint == nullptr) { log_e("Endpoint [%d] not found", endpoint_id); - return NULL; + return nullptr; } cluster_t *cluster = cluster::get(endpoint, cluster_id); - if (cluster == NULL) { + if (cluster == nullptr) { log_e("Cluster [%d] not found", cluster_id); - return NULL; + return nullptr; } esp_matter::attribute_t *attribute = attribute::get(cluster, attribute_id); - if (attribute == NULL) { + if (attribute == nullptr) { log_e("Attribute [%d] not found", attribute_id); - return NULL; + return nullptr; } return attribute; } @@ -64,7 +64,7 @@ class MatterEndPoint { // get the value of an attribute from its cluster id and attribute it bool getAttributeVal(uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *attrVal) { esp_matter::attribute_t *attribute = getAttribute(cluster_id, attribute_id); - if (attribute == NULL) { + if (attribute == nullptr) { return false; } if (attribute::get_val(attribute, attrVal) == ESP_OK) { @@ -78,7 +78,7 @@ class MatterEndPoint { // set the value of an attribute from its cluster id and attribute it bool setAttributeVal(uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *attrVal) { esp_matter::attribute_t *attribute = getAttribute(cluster_id, attribute_id); - if (attribute == NULL) { + if (attribute == nullptr) { return false; } if (attribute::set_val(attribute, attrVal) == ESP_OK) { @@ -117,6 +117,6 @@ class MatterEndPoint { protected: uint16_t endpoint_id = 0; - EndPointIdentifyCB _onEndPointIdentifyCB = NULL; + EndPointIdentifyCB _onEndPointIdentifyCB = nullptr; }; #endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */ diff --git a/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp b/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp index 87917e58b8f..b24c9f1adc3 100644 --- a/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp +++ b/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp @@ -315,9 +315,10 @@ int NetworkClientSecure::available() { } uint8_t NetworkClientSecure::connected() { - uint8_t dummy = 0; - read(&dummy, 0); - + if (_connected) { + uint8_t dummy = 0; + read(&dummy, 0); + } return _connected; } diff --git a/libraries/OpenThread/README.md b/libraries/OpenThread/README.md index cd9deb9ebf6..8d0386f34fb 100644 --- a/libraries/OpenThread/README.md +++ b/libraries/OpenThread/README.md @@ -1,9 +1,177 @@ | Supported Targets | ESP32-C6 | ESP32-H2 | | ----------------- | -------- | -------- | -# ESP32 Arduino OpenThreadCLI +# General View -The `OpenThreadCLI` class is an Arduino API for interacting with the OpenThread Command Line Interface (CLI). It allows you to manage and configure the Thread stack using a command-line interface. +This Arduino OpenThread Library allows using ESP OpenThread implementation using CLI and/or Native OpenThread API. + +The Library implements 3 C++ Classes: +- `OThread` Class for Native OpenThread API +- `OThreadCLI` Class for CLI OpenThread API +- `DataSet` Class for OpenThread dataset manipulation using Native `OThread` Class + +# ESP32 Arduino OpenThread Native + +The `OThread` class provides methods for managing the OpenThread instance and controlling the Thread network. It allows you to initialize, start, stop, and manage the Thread network using native OpenThread APIs. + +## Class Definition + +```cpp +class OpenThread { + public: + static bool otStarted; // Indicates whether the OpenThread stack is running. + + // Get the current Thread device role (e.g., Leader, Router, Child, etc.). + static ot_device_role_t otGetDeviceRole(); + + // Get the current Thread device role as a string. + static const char *otGetStringDeviceRole(); + + // Print network information (e.g., network name, channel, PAN ID) to the specified stream. + static void otPrintNetworkInformation(Stream &output); + + OpenThread(); + ~OpenThread(); + + // Returns true if the OpenThread stack is running. + operator bool() const; + + // Initialize the OpenThread stack. + static void begin(bool OThreadAutoStart = true); + + // Deinitialize the OpenThread stack. + static void end(); + + // Start the Thread network. + void start(); + + // Stop the Thread network. + void stop(); + + // Bring up the Thread network interface (equivalent to "ifconfig up"). + void networkInterfaceUp(); + + // Bring down the Thread network interface (equivalent to "ifconfig down"). + void networkInterfaceDown(); + + // Commit a dataset to the OpenThread instance. + void commitDataSet(const DataSet &dataset); + +private: + static otInstance *mInstance; // Pointer to the OpenThread instance. + DataSet mCurrentDataSet; // Current dataset being used by the OpenThread instance. +}; + +extern OpenThread OThread; +``` +## Class Overview + +The `OThread` class provides a simple and intuitive interface for managing the OpenThread stack and Thread network. It abstracts the complexity of the OpenThread APIs and provides Arduino-style methods for common operations. + +## Public Methods +### Initialization and Deinitialization +- `begin(bool OThreadAutoStart = true)`: Initializes the OpenThread stack. If `OThreadAutoStart` is `true`, the Thread network will start automatically using NVS data. +- `end()`: Deinitializes the OpenThread stack and releases resources. +### Thread Network Control +- `start()`: Starts the Thread network. This is equivalent to the CLI command "thread start". +- `stop()`: Stops the Thread network. This is equivalent to the CLI command "thread stop". +### Network Interface Control +- `networkInterfaceUp()`: Brings up the Thread network interface. This is equivalent to the CLI command "ifconfig up". +- `networkInterfaceDown()`: Brings down the Thread network interface. This is equivalent to the CLI command "ifconfig down". +### Dataset Management +- `commitDataSet(const DataSet &dataset)`: Commits a dataset to the OpenThread instance. This is used to configure the Thread network with specific parameters (e.g., network name, channel, PAN ID). +### Network Information +- `otGetDeviceRole()`: Returns the current Thread device role as an `ot_device_role_t` enum (e.g., `OT_ROLE_LEADER`, `OT_ROLE_ROUTER`). +- `otGetStringDeviceRole()`: Returns the current Thread device role as a string (e.g., "Leader", "Router"). +- `otPrintNetworkInformation(Stream &output)`: Prints the current network information (e.g., network name, channel, PAN ID) to the specified stream. + +## Key Features +- **Initialization and Cleanup**: Easily initialize and deinitialize the OpenThread stack. +- **Network Control**: Start and stop the Thread network with simple method calls. +- **Dataset Management**: Configure the Thread network using the `DataSet` class and commit it to the OpenThread instance. +- **Network Information**: Retrieve and print the current network information and device role. + +## Notes +- The `OThread` class is designed to simplify the use of OpenThread APIs in Arduino sketches. +- It works seamlessly with the DataSet class for managing Thread network configurations. +- Ensure that the OpenThread stack is initialized (`OThread.begin()`) before calling other methods. + +This documentation provides a comprehensive overview of the `OThread` class, its methods, and example usage. It is designed to help developers quickly integrate OpenThread functionality into their Arduino projects. + +# DataSet Class + +The `DataSet` class provides a structured way to manage and configure Thread network datasets using native OpenThread APIs. It allows you to set and retrieve network parameters such as the network name, channel, PAN ID, and more. The `DataSet` class works seamlessly with the `OThread` class to apply these configurations to the OpenThread instance. + +## Class Definition + +```cpp +class DataSet { +public: + DataSet(); + void clear(); + void initNew(); + const otOperationalDataset &getDataset() const; + + // Setters + void setNetworkName(const char *name); + void setExtendedPanId(const uint8_t *extPanId); + void setNetworkKey(const uint8_t *key); + void setChannel(uint8_t channel); + void setPanId(uint16_t panId); + + // Getters + const char *getNetworkName() const; + const uint8_t *getExtendedPanId() const; + const uint8_t *getNetworkKey() const; + uint8_t getChannel() const; + uint16_t getPanId() const; + + // Apply the dataset to the OpenThread instance + void apply(otInstance *instance); + +private: + otOperationalDataset mDataset; // Internal representation of the dataset +}; +``` + +## Class Overview +The DataSet` class simplifies the management of Thread network datasets by providing intuitive methods for setting, retrieving, and applying network parameters. It abstracts the complexity of the OpenThread dataset APIs and provides Arduino-style methods for common operations. + +## Public Methods +### Initialization +- `DataSet()`: Constructor that initializes an empty dataset. +- `void clear()`: Clears the dataset, resetting all fields to their default values. +- `void initNew()`: Initializes a new dataset with default values (equivalent to the CLI command dataset init new). +### Setters +- `void setNetworkName(const char *name)`: Sets the network name. +- `void setExtendedPanId(const uint8_t *extPanId)`: Sets the extended PAN ID. +- `void setNetworkKey(const uint8_t *key)`: Sets the network key. +- `void setChannel(uint8_t channel)`: Sets the channel. +- `void setPanId(uint16_t panId)`: Sets the PAN ID. +### Getters +- `const char *getNetworkName() const`: Retrieves the network name. +- `const uint8_t *getExtendedPanId() const`: Retrieves the extended PAN ID. +- `const uint8_t *getNetworkKey() const`: Retrieves the network key. +- `uint8_t getChannel() const`: Retrieves the channel. +- `uint16_t getPanId() const`: Retrieves the PAN ID. +### Dataset Application +- `void apply(otInstance *instance)`: Applies the dataset to the specified OpenThread instance. + +## Key Features +- **Dataset Initialization**: Easily initialize a new dataset with default values using initNew(). +- **Custom Configuration**: Set custom network parameters such as the network name, channel, and PAN ID using setter methods. +- **Dataset Application**: Apply the configured dataset to the OpenThread instance using apply(). + +** Notes +- The `DataSet` class is designed to work seamlessly with the `OThread` class for managing Thread network configurations. +- Ensure that the OpenThread stack is initialized (`OThread.begin()`) before applying a dataset. +- The initNew()`` method provides default values for the dataset, which can be customized using the setter methods. + +This documentation provides a comprehensive overview of the `DataSet` class, its methods, and example usage. It is designed to help developers easily manage Thread network configurations in their Arduino projects. + +# OpenThreadCLI Class + +The `OpenThreadCLI` class is an Arduino API for interacting with the OpenThread Command Line Interface (CLI). It allows you to send commands to the OpenThread stack and receive responses. This class is designed to simplify the use of OpenThread CLI commands in Arduino sketches. There is one main class called `OpenThreadCLI` and a global object used to operate OpenThread CLI, called `OThreadCLI`.\ Some [helper functions](helper_functions.md) were made available for working with the OpenThread CLI environment. @@ -20,7 +188,7 @@ Below are the details of the class: class OpenThreadCLI : public Stream { private: static size_t setBuffer(QueueHandle_t &queue, size_t len); - bool otStarted = false; + static bool otCLIStarted = false; public: OpenThreadCLI(); @@ -59,14 +227,35 @@ extern OpenThreadCLI OThreadCLI; - You can customize the console behavior by adjusting parameters such as echoback and buffer sizes. ## Public Methods +### Initialization and Deinitialization +- `begin()`: Initializes the OpenThread stack (optional auto-start). +- `end()`: Deinitializes the OpenThread stack and releases resources. +### Console Management - `startConsole(Stream& otStream, bool echoback = true, const char* prompt = "ot> ")`: Starts the OpenThread console with the specified stream, echoback option, and prompt. - `stopConsole()`: Stops the OpenThread console. - `setPrompt(char* prompt)`: Changes the console prompt (set to NULL for an empty prompt). - `setEchoBack(bool echoback)`: Changes the console echoback option. - `setStream(Stream& otStream)`: Changes the console Stream object. - `onReceive(OnReceiveCb_t func)`: Sets a callback function to handle complete lines of output from the OT CLI. -- `begin(bool OThreadAutoStart = true)`: Initializes the OpenThread stack (optional auto-start). -- `end()`: Deinitializes the OpenThread stack. +### Buffer Management - `setTxBufferSize(size_t tx_queue_len)`: Sets the transmit buffer size (default is 256 bytes). - `setRxBufferSize(size_t rx_queue_len)`: Sets the receive buffer size (default is 1024 bytes). -- `write(uint8_t)`, `available()`, `read()`, `peek()`, `flush()`: Standard Stream methods implementation for OpenThread CLI object. +### Stream Methods +- `write(uint8_t)`: Writes a byte to the CLI. +- `available()`: Returns the number of bytes available to read. +- `read()`: Reads a byte from the CLI. +- `peek()`: Returns the next byte without removing it from the buffer. +- `flush()`: Flushes the CLI buffer. + +## Key Features +- **Arduino Stream Compatibility**: Inherits from the Stream class, making it compatible with Arduino's standard I/O functions. +- **Customizable Console**: Allows customization of the CLI prompt, echoback behavior, and buffer sizes. +- **Callback Support**: Provides a callback mechanism to handle CLI responses asynchronously. +- **Seamless Integration**: Designed to work seamlessly with the OThread and DataSet classes + +## Notes +- The `OThreadCLI` class is designed to simplify the use of OpenThread CLI commands in Arduino sketches. +- It works seamlessly with the `OThread` and `DataSet` classes for managing Thread networks. +- Ensure that the OpenThread stack is initialized (`OThreadCLI.begin()`) before starting the CLI console. + +This documentation provides a comprehensive overview of the `OThreadCLI` class, its methods, and example usage. It is designed to help developers easily integrate OpenThread CLI functionality into their Arduino projects. diff --git a/libraries/OpenThread/examples/COAP/coap_lamp/ci.json b/libraries/OpenThread/examples/CLI/COAP/coap_lamp/ci.json similarity index 100% rename from libraries/OpenThread/examples/COAP/coap_lamp/ci.json rename to libraries/OpenThread/examples/CLI/COAP/coap_lamp/ci.json diff --git a/libraries/OpenThread/examples/COAP/coap_lamp/coap_lamp.ino b/libraries/OpenThread/examples/CLI/COAP/coap_lamp/coap_lamp.ino similarity index 95% rename from libraries/OpenThread/examples/COAP/coap_lamp/coap_lamp.ino rename to libraries/OpenThread/examples/CLI/COAP/coap_lamp/coap_lamp.ino index 51483bb4c7c..bcaf8ae9793 100644 --- a/libraries/OpenThread/examples/COAP/coap_lamp/coap_lamp.ino +++ b/libraries/OpenThread/examples/CLI/COAP/coap_lamp/coap_lamp.ino @@ -75,18 +75,18 @@ bool otDeviceSetup(const char **otSetupCmds, uint8_t nCmds1, const char **otCoap Serial.println("OpenThread started.\r\nWaiting for activating correct Device Role."); // wait for the expected Device Role to start uint8_t tries = 24; // 24 x 2.5 sec = 1 min - while (tries && otGetDeviceRole() != expectedRole) { + while (tries && OThread.otGetDeviceRole() != expectedRole) { Serial.print("."); delay(2500); tries--; } Serial.println(); if (!tries) { - log_e("Sorry, Device Role failed by timeout! Current Role: %s.", otGetStringDeviceRole()); + log_e("Sorry, Device Role failed by timeout! Current Role: %s.", OThread.otGetStringDeviceRole()); rgbLedWrite(RGB_BUILTIN, 255, 0, 0); // RED ... failed! return false; } - Serial.printf("Device is %s.\r\n", otGetStringDeviceRole()); + Serial.printf("Device is %s.\r\n", OThread.otGetStringDeviceRole()); for (i = 0; i < nCmds2; i++) { if (!otExecCommand(otCoapCmds[i * 2], otCoapCmds[i * 2 + 1])) { break; @@ -151,7 +151,8 @@ void setup() { Serial.begin(115200); // LED starts RED, indicating not connected to Thread network. rgbLedWrite(RGB_BUILTIN, 64, 0, 0); - OThreadCLI.begin(false); // No AutoStart is necessary + OThread.begin(false); // No AutoStart is necessary + OThreadCLI.begin(); OThreadCLI.setTimeout(250); // waits 250ms for the OpenThread CLI response setupNode(); // LED goes Green when all is ready and Red when failed. diff --git a/libraries/OpenThread/examples/COAP/coap_switch/ci.json b/libraries/OpenThread/examples/CLI/COAP/coap_switch/ci.json similarity index 100% rename from libraries/OpenThread/examples/COAP/coap_switch/ci.json rename to libraries/OpenThread/examples/CLI/COAP/coap_switch/ci.json diff --git a/libraries/OpenThread/examples/COAP/coap_switch/coap_switch.ino b/libraries/OpenThread/examples/CLI/COAP/coap_switch/coap_switch.ino similarity index 95% rename from libraries/OpenThread/examples/COAP/coap_switch/coap_switch.ino rename to libraries/OpenThread/examples/CLI/COAP/coap_switch/coap_switch.ino index aac5db0bc82..bacac47ddeb 100644 --- a/libraries/OpenThread/examples/COAP/coap_switch/coap_switch.ino +++ b/libraries/OpenThread/examples/CLI/COAP/coap_switch/coap_switch.ino @@ -69,18 +69,18 @@ bool otDeviceSetup( Serial.println("OpenThread started.\r\nWaiting for activating correct Device Role."); // wait for the expected Device Role to start uint8_t tries = 24; // 24 x 2.5 sec = 1 min - while (tries && otGetDeviceRole() != expectedRole1 && otGetDeviceRole() != expectedRole2) { + while (tries && OThread.otGetDeviceRole() != expectedRole1 && OThread.otGetDeviceRole() != expectedRole2) { Serial.print("."); delay(2500); tries--; } Serial.println(); if (!tries) { - log_e("Sorry, Device Role failed by timeout! Current Role: %s.", otGetStringDeviceRole()); + log_e("Sorry, Device Role failed by timeout! Current Role: %s.", OThread.otGetStringDeviceRole()); rgbLedWrite(RGB_BUILTIN, 255, 0, 0); // RED ... failed! return false; } - Serial.printf("Device is %s.\r\n", otGetStringDeviceRole()); + Serial.printf("Device is %s.\r\n", OThread.otGetStringDeviceRole()); for (i = 0; i < nCmds2; i++) { if (!otExecCommand(otCoapCmds[i * 2], otCoapCmds[i * 2 + 1])) { break; @@ -176,7 +176,8 @@ void setup() { Serial.begin(115200); // LED starts RED, indicating not connected to Thread network. rgbLedWrite(RGB_BUILTIN, 64, 0, 0); - OThreadCLI.begin(false); // No AutoStart is necessary + OThread.begin(false); // No AutoStart is necessary + OThreadCLI.begin(); OThreadCLI.setTimeout(250); // waits 250ms for the OpenThread CLI response setupNode(); // LED goes and keeps Blue when all is ready and Red when failed. diff --git a/libraries/OpenThread/examples/SimpleCLI/SimpleCLI.ino b/libraries/OpenThread/examples/CLI/SimpleCLI/SimpleCLI.ino similarity index 89% rename from libraries/OpenThread/examples/SimpleCLI/SimpleCLI.ino rename to libraries/OpenThread/examples/CLI/SimpleCLI/SimpleCLI.ino index feef800c0fa..dec3aaeb218 100644 --- a/libraries/OpenThread/examples/SimpleCLI/SimpleCLI.ino +++ b/libraries/OpenThread/examples/CLI/SimpleCLI/SimpleCLI.ino @@ -1,4 +1,4 @@ -// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// Copyright 2025 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. @@ -26,7 +26,8 @@ void setup() { Serial.begin(115200); - OThreadCLI.begin(false); // No AutoStart - fresh start + OThread.begin(false); // No AutoStart - fresh start + OThreadCLI.begin(); Serial.println("OpenThread CLI started - type 'help' for a list of commands."); OThreadCLI.startConsole(Serial); } diff --git a/libraries/OpenThread/examples/SimpleCLI/ci.json b/libraries/OpenThread/examples/CLI/SimpleCLI/ci.json similarity index 100% rename from libraries/OpenThread/examples/SimpleCLI/ci.json rename to libraries/OpenThread/examples/CLI/SimpleCLI/ci.json diff --git a/libraries/OpenThread/examples/SimpleNode/SimpleNode.ino b/libraries/OpenThread/examples/CLI/SimpleNode/SimpleNode.ino similarity index 82% rename from libraries/OpenThread/examples/SimpleNode/SimpleNode.ino rename to libraries/OpenThread/examples/CLI/SimpleNode/SimpleNode.ino index 95bf7a2401a..d17b692cc74 100644 --- a/libraries/OpenThread/examples/SimpleNode/SimpleNode.ino +++ b/libraries/OpenThread/examples/CLI/SimpleNode/SimpleNode.ino @@ -1,4 +1,4 @@ -// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// Copyright 2025 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. @@ -35,12 +35,13 @@ void setup() { Serial.begin(115200); - OThreadCLI.begin(); // AutoStart using Thread default settings - otPrintNetworkInformation(Serial); // Print Current Thread Network Information + OThread.begin(); // AutoStart using Thread default settings + OThreadCLI.begin(); + OThread.otPrintNetworkInformation(Serial); // Print Current Thread Network Information } void loop() { Serial.print("Thread Node State: "); - Serial.println(otGetStringDeviceRole()); + Serial.println(OThread.otGetStringDeviceRole()); delay(5000); } diff --git a/libraries/OpenThread/examples/SimpleNode/ci.json b/libraries/OpenThread/examples/CLI/SimpleNode/ci.json similarity index 100% rename from libraries/OpenThread/examples/SimpleNode/ci.json rename to libraries/OpenThread/examples/CLI/SimpleNode/ci.json diff --git a/libraries/OpenThread/examples/SimpleThreadNetwork/ExtendedRouterNode/ExtendedRouterNode.ino b/libraries/OpenThread/examples/CLI/SimpleThreadNetwork/ExtendedRouterNode/ExtendedRouterNode.ino similarity index 89% rename from libraries/OpenThread/examples/SimpleThreadNetwork/ExtendedRouterNode/ExtendedRouterNode.ino rename to libraries/OpenThread/examples/CLI/SimpleThreadNetwork/ExtendedRouterNode/ExtendedRouterNode.ino index 4fc8a921584..40f046aeab5 100644 --- a/libraries/OpenThread/examples/SimpleThreadNetwork/ExtendedRouterNode/ExtendedRouterNode.ino +++ b/libraries/OpenThread/examples/CLI/SimpleThreadNetwork/ExtendedRouterNode/ExtendedRouterNode.ino @@ -1,4 +1,4 @@ -// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// Copyright 2025 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. @@ -22,7 +22,8 @@ bool otStatus = true; void setup() { Serial.begin(115200); - OThreadCLI.begin(false); // No AutoStart - fresh start + OThread.begin(false); // No AutoStart - fresh start + OThreadCLI.begin(); Serial.println("Setting up OpenThread Node as Router/Child"); Serial.println("Make sure the Leader Node is already running"); @@ -39,7 +40,7 @@ void setup() { } // wait for the node to enter in the router state uint32_t timeout = millis() + 90000; // waits 90 seconds to - while (otGetDeviceRole() != OT_ROLE_CHILD && otGetDeviceRole() != OT_ROLE_ROUTER) { + while (OThread.otGetDeviceRole() != OT_ROLE_CHILD && OThread.otGetDeviceRole() != OT_ROLE_ROUTER) { Serial.print("."); if (millis() > timeout) { Serial.println("\r\n\t===> Timeout! Failed."); @@ -70,7 +71,7 @@ void loop() { if (otStatus) { Serial.println("Thread NetworkInformation: "); Serial.println("---------------------------"); - otPrintNetworkInformation(Serial); + OThread.otPrintNetworkInformation(Serial); Serial.println("---------------------------"); } else { Serial.println("Some OpenThread operation has failed..."); diff --git a/libraries/OpenThread/examples/SimpleThreadNetwork/ExtendedRouterNode/ci.json b/libraries/OpenThread/examples/CLI/SimpleThreadNetwork/ExtendedRouterNode/ci.json similarity index 100% rename from libraries/OpenThread/examples/SimpleThreadNetwork/ExtendedRouterNode/ci.json rename to libraries/OpenThread/examples/CLI/SimpleThreadNetwork/ExtendedRouterNode/ci.json diff --git a/libraries/OpenThread/examples/SimpleThreadNetwork/LeaderNode/LeaderNode.ino b/libraries/OpenThread/examples/CLI/SimpleThreadNetwork/LeaderNode/LeaderNode.ino similarity index 93% rename from libraries/OpenThread/examples/SimpleThreadNetwork/LeaderNode/LeaderNode.ino rename to libraries/OpenThread/examples/CLI/SimpleThreadNetwork/LeaderNode/LeaderNode.ino index 7b709717692..a945a5c8f77 100644 --- a/libraries/OpenThread/examples/SimpleThreadNetwork/LeaderNode/LeaderNode.ino +++ b/libraries/OpenThread/examples/CLI/SimpleThreadNetwork/LeaderNode/LeaderNode.ino @@ -1,4 +1,4 @@ -// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// Copyright 2025 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. @@ -35,7 +35,8 @@ otInstance *aInstance = NULL; void setup() { Serial.begin(115200); - OThreadCLI.begin(false); // No AutoStart - fresh start + OThread.begin(false); // No AutoStart - fresh start + OThreadCLI.begin(); Serial.println(); Serial.println("Setting up OpenThread Node as Leader"); aInstance = esp_openthread_get_instance(); @@ -51,11 +52,11 @@ void setup() { void loop() { Serial.println("============================================="); Serial.print("Thread Node State: "); - Serial.println(otGetStringDeviceRole()); + Serial.println(OThread.otGetStringDeviceRole()); // Native OpenThread API calls: // wait until the node become Child or Router - if (otGetDeviceRole() == OT_ROLE_LEADER) { + if (OThread.otGetDeviceRole() == OT_ROLE_LEADER) { // Network Name const char *networkName = otThreadGetNetworkName(aInstance); Serial.printf("Network Name: %s\r\n", networkName); diff --git a/libraries/OpenThread/examples/SimpleThreadNetwork/LeaderNode/ci.json b/libraries/OpenThread/examples/CLI/SimpleThreadNetwork/LeaderNode/ci.json similarity index 100% rename from libraries/OpenThread/examples/SimpleThreadNetwork/LeaderNode/ci.json rename to libraries/OpenThread/examples/CLI/SimpleThreadNetwork/LeaderNode/ci.json diff --git a/libraries/OpenThread/examples/SimpleThreadNetwork/RouterNode/RouterNode.ino b/libraries/OpenThread/examples/CLI/SimpleThreadNetwork/RouterNode/RouterNode.ino similarity index 92% rename from libraries/OpenThread/examples/SimpleThreadNetwork/RouterNode/RouterNode.ino rename to libraries/OpenThread/examples/CLI/SimpleThreadNetwork/RouterNode/RouterNode.ino index 45475fa0c6a..f802bd7ef01 100644 --- a/libraries/OpenThread/examples/SimpleThreadNetwork/RouterNode/RouterNode.ino +++ b/libraries/OpenThread/examples/CLI/SimpleThreadNetwork/RouterNode/RouterNode.ino @@ -1,4 +1,4 @@ -// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// Copyright 2025 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. @@ -34,7 +34,8 @@ otInstance *aInstance = NULL; void setup() { Serial.begin(115200); - OThreadCLI.begin(false); // No AutoStart - fresh start + OThread.begin(false); // No AutoStart - fresh start + OThreadCLI.begin(); Serial.println(); Serial.println("Setting up OpenThread Node as Router/Child"); Serial.println("Make sure the Leader Node is already running"); @@ -51,11 +52,11 @@ void setup() { void loop() { Serial.println("============================================="); Serial.print("Thread Node State: "); - Serial.println(otGetStringDeviceRole()); + Serial.println(OThread.otGetStringDeviceRole()); // Native OpenThread API calls: // wait until the node become Child or Router - if (otGetDeviceRole() == OT_ROLE_CHILD || otGetDeviceRole() == OT_ROLE_ROUTER) { + if (OThread.otGetDeviceRole() == OT_ROLE_CHILD || OThread.otGetDeviceRole() == OT_ROLE_ROUTER) { // Network Name const char *networkName = otThreadGetNetworkName(aInstance); Serial.printf("Network Name: %s\r\n", networkName); diff --git a/libraries/OpenThread/examples/SimpleThreadNetwork/RouterNode/ci.json b/libraries/OpenThread/examples/CLI/SimpleThreadNetwork/RouterNode/ci.json similarity index 100% rename from libraries/OpenThread/examples/SimpleThreadNetwork/RouterNode/ci.json rename to libraries/OpenThread/examples/CLI/SimpleThreadNetwork/RouterNode/ci.json diff --git a/libraries/OpenThread/examples/ThreadScan/ThreadScan.ino b/libraries/OpenThread/examples/CLI/ThreadScan/ThreadScan.ino similarity index 89% rename from libraries/OpenThread/examples/ThreadScan/ThreadScan.ino rename to libraries/OpenThread/examples/CLI/ThreadScan/ThreadScan.ino index 9d0074bb180..87c29339fb7 100644 --- a/libraries/OpenThread/examples/ThreadScan/ThreadScan.ino +++ b/libraries/OpenThread/examples/CLI/ThreadScan/ThreadScan.ino @@ -1,4 +1,4 @@ -// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// Copyright 2025 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. @@ -27,7 +27,8 @@ void setup() { Serial.begin(115200); - OThreadCLI.begin(true); // For scanning, AutoStart must be active, any setup + OThread.begin(true); // For scanning, AutoStart must be active, any setup + OThreadCLI.begin(); OThreadCLI.setTimeout(100); // Set a timeout for the CLI response Serial.println(); Serial.println("This sketch will continuously scan the Thread Local Network and all devices IEEE 802.15.4 compatible"); @@ -41,7 +42,7 @@ void loop() { Serial.println("Scan Failed..."); } delay(5000); - if (otGetDeviceRole() < OT_ROLE_CHILD) { + if (OThread.otGetDeviceRole() < OT_ROLE_CHILD) { Serial.println(); Serial.println("This device has not started Thread yet, bypassing Discovery Scan"); return; diff --git a/libraries/OpenThread/examples/ThreadScan/ci.json b/libraries/OpenThread/examples/CLI/ThreadScan/ci.json similarity index 100% rename from libraries/OpenThread/examples/ThreadScan/ci.json rename to libraries/OpenThread/examples/CLI/ThreadScan/ci.json diff --git a/libraries/OpenThread/examples/onReceive/ci.json b/libraries/OpenThread/examples/CLI/onReceive/ci.json similarity index 100% rename from libraries/OpenThread/examples/onReceive/ci.json rename to libraries/OpenThread/examples/CLI/onReceive/ci.json diff --git a/libraries/OpenThread/examples/onReceive/onReceive.ino b/libraries/OpenThread/examples/CLI/onReceive/onReceive.ino similarity index 96% rename from libraries/OpenThread/examples/onReceive/onReceive.ino rename to libraries/OpenThread/examples/CLI/onReceive/onReceive.ino index b37c2fc7931..f53cc33f5ec 100644 --- a/libraries/OpenThread/examples/onReceive/onReceive.ino +++ b/libraries/OpenThread/examples/CLI/onReceive/onReceive.ino @@ -39,7 +39,8 @@ void otReceivedLine() { void setup() { Serial.begin(115200); - OThreadCLI.begin(); // AutoStart + OThread.begin(); // AutoStart + OThreadCLI.begin(); OThreadCLI.onReceive(otReceivedLine); } diff --git a/libraries/OpenThread/examples/Native/SimpleThreadNetwork/LeaderNode/LeaderNode.ino b/libraries/OpenThread/examples/Native/SimpleThreadNetwork/LeaderNode/LeaderNode.ino new file mode 100644 index 00000000000..dfea9776838 --- /dev/null +++ b/libraries/OpenThread/examples/Native/SimpleThreadNetwork/LeaderNode/LeaderNode.ino @@ -0,0 +1,34 @@ +#include "OThread.h" + +OpenThread threadLeaderNode; +DataSet dataset; + +void setup() { + Serial.begin(115200); + + // Start OpenThread Stack - false for not using NVS dataset information + threadLeaderNode.begin(false); + + // Create a new Thread Network Dataset for a Leader Node + dataset.initNew(); + // Configure the dataset + dataset.setNetworkName("ESP_OpenThread"); + uint8_t extPanId[OT_EXT_PAN_ID_SIZE] = {0xDE, 0xAD, 0x00, 0xBE, 0xEF, 0x00, 0xCA, 0xFE}; + dataset.setExtendedPanId(extPanId); + uint8_t networkKey[OT_NETWORK_KEY_SIZE] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; + dataset.setNetworkKey(networkKey); + dataset.setChannel(15); + dataset.setPanId(0x1234); + + // Apply the dataset and start the network + threadLeaderNode.commitDataSet(dataset); + threadLeaderNode.networkInterfaceUp(); + threadLeaderNode.start(); +} + +void loop() { + // Print network information every 5 seconds + Serial.println("=============================================="); + threadLeaderNode.otPrintNetworkInformation(Serial); + delay(5000); +} diff --git a/libraries/OpenThread/examples/Native/SimpleThreadNetwork/LeaderNode/ci.json b/libraries/OpenThread/examples/Native/SimpleThreadNetwork/LeaderNode/ci.json new file mode 100644 index 00000000000..2ee6af3490e --- /dev/null +++ b/libraries/OpenThread/examples/Native/SimpleThreadNetwork/LeaderNode/ci.json @@ -0,0 +1,6 @@ +{ + "requires": [ + "CONFIG_OPENTHREAD_ENABLED=y", + "CONFIG_SOC_IEEE802154_SUPPORTED=y" + ] +} diff --git a/libraries/OpenThread/examples/Native/SimpleThreadNetwork/RouterNode/RouterNode.ino b/libraries/OpenThread/examples/Native/SimpleThreadNetwork/RouterNode/RouterNode.ino new file mode 100644 index 00000000000..5ffa535ad51 --- /dev/null +++ b/libraries/OpenThread/examples/Native/SimpleThreadNetwork/RouterNode/RouterNode.ino @@ -0,0 +1,29 @@ +#include "OThread.h" + +OpenThread threadChildNode; +DataSet dataset; + +void setup() { + Serial.begin(115200); + + // Start OpenThread Stack - false for not using NVS dataset information + threadChildNode.begin(false); + + // clear dataset + dataset.clear(); + // Configure the dataset with the same Network Key of the Leader Node + uint8_t networkKey[OT_NETWORK_KEY_SIZE] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; + dataset.setNetworkKey(networkKey); + + // Apply the dataset and start the network + threadChildNode.commitDataSet(dataset); + threadChildNode.networkInterfaceUp(); + threadChildNode.start(); +} + +void loop() { + // Print network information every 5 seconds + Serial.println("=============================================="); + threadChildNode.otPrintNetworkInformation(Serial); + delay(5000); +} diff --git a/libraries/OpenThread/examples/Native/SimpleThreadNetwork/RouterNode/ci.json b/libraries/OpenThread/examples/Native/SimpleThreadNetwork/RouterNode/ci.json new file mode 100644 index 00000000000..2ee6af3490e --- /dev/null +++ b/libraries/OpenThread/examples/Native/SimpleThreadNetwork/RouterNode/ci.json @@ -0,0 +1,6 @@ +{ + "requires": [ + "CONFIG_OPENTHREAD_ENABLED=y", + "CONFIG_SOC_IEEE802154_SUPPORTED=y" + ] +} diff --git a/libraries/OpenThread/keywords.txt b/libraries/OpenThread/keywords.txt index d7193de188d..b62c2c23ddc 100644 --- a/libraries/OpenThread/keywords.txt +++ b/libraries/OpenThread/keywords.txt @@ -7,7 +7,10 @@ ####################################### OThreadCLI KEYWORD1 +OThread KEYWORD1 OpenThreadCLI KEYWORD1 +OpenThread KEYWORD1 +DataSet KEYWORD1 ot_cmd_return_t KEYWORD1 ot_device_role_t KEYWORD1 @@ -35,6 +38,27 @@ otGetRespCmd KEYWORD2 otExecCommand KEYWORD2 otPrintRespCLI KEYWORD2 otPrintNetworkInformation KEYWORD2 +clear KEYWORD2 +initNew KEYWORD2 +getDataset KEYWORD2 +setNetworkName KEYWORD2 +getNetworkName KEYWORD2 +setExtendedPanId KEYWORD2 +getExtendedPanId KEYWORD2 +setNetworkKey KEYWORD2 +getNetworkKey KEYWORD2 +setChannel KEYWORD2 +getChannel KEYWORD2 +setPanId KEYWORD2 +getPanId KEYWORD2 +apply KEYWORD2 +otStarted KEYWORD2 +otCLIStarted KEYWORD2 +start KEYWORD2 +stop KEYWORD2 +networkInterfaceUp KEYWORD2 +networkInterfaceDown KEYWORD2 +commitDataSet KEYWORD2 ####################################### # Constants (LITERAL1) @@ -45,3 +69,5 @@ OT_ROLE_DETACHED LITERAL1 OT_ROLE_CHILD LITERAL1 OT_ROLE_ROUTER LITERAL1 OT_ROLE_LEADER LITERAL1 +OT_EXT_PAN_ID_SIZE LITERAL1 +OT_NETWORK_KEY_SIZE LITERAL1 diff --git a/libraries/OpenThread/src/OThread.cpp b/libraries/OpenThread/src/OThread.cpp new file mode 100644 index 00000000000..7714d870cce --- /dev/null +++ b/libraries/OpenThread/src/OThread.cpp @@ -0,0 +1,366 @@ +#include "OThread.h" +#if SOC_IEEE802154_SUPPORTED +#if CONFIG_OPENTHREAD_ENABLED + +#include "esp_err.h" +#include "esp_event.h" +#include "esp_netif.h" +#include "esp_netif_types.h" +#include "esp_vfs_eventfd.h" + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "freertos/queue.h" + +#include "esp_netif_net_stack.h" +#include "esp_openthread_netif_glue.h" +#include "lwip/netif.h" + +static esp_openthread_platform_config_t ot_native_config; +static esp_netif_t *openthread_netif = NULL; + +const char *otRoleString[] = { + "Disabled", ///< The Thread stack is disabled. + "Detached", ///< Not currently participating in a Thread network/partition. + "Child", ///< The Thread Child role. + "Router", ///< The Thread Router role. + "Leader", ///< The Thread Leader role. + "Unknown", ///< Unknown role, not initialized or not started. +}; + +static TaskHandle_t s_ot_task = NULL; +#if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM +static struct netif *ot_lwip_netif = NULL; +#endif + +#if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM +extern "C" int lwip_hook_ip6_input(struct pbuf *p, struct netif *inp) { + if (ot_lwip_netif && ot_lwip_netif == inp) { + return 0; + } + if (ip6_addr_isany_val(inp->ip6_addr[0].u_addr.ip6)) { + // We don't have an LL address -> eat this packet here, so it won't get accepted on input netif + pbuf_free(p); + return 1; + } + return 0; +} +#endif + +static void ot_task_worker(void *aContext) { + esp_vfs_eventfd_config_t eventfd_config = { + .max_fds = 3, + }; + bool err = false; + if (ESP_OK != esp_event_loop_create_default()) { + log_e("Failed to create OpentThread event loop"); + err = true; + } + if (!err && ESP_OK != esp_netif_init()) { + log_e("Failed to initialize OpentThread netif"); + err = true; + } + if (!err && ESP_OK != esp_vfs_eventfd_register(&eventfd_config)) { + log_e("Failed to register OpentThread eventfd"); + err = true; + } + + // Initialize the OpenThread stack + if (!err && ESP_OK != esp_openthread_init(&ot_native_config)) { + log_e("Failed to initialize OpenThread stack"); + err = true; + } + if (!err) { + // Initialize the esp_netif bindings + esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD(); + openthread_netif = esp_netif_new(&cfg); +#if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM + // Get LwIP Netif + if (openthread_netif != NULL) { + ot_lwip_netif = (struct netif *)esp_netif_get_netif_impl(openthread_netif); + if (ot_lwip_netif == NULL) { + log_e("Failed to get OpenThread LwIP netif"); + } + } +#endif + } + if (!err && openthread_netif == NULL) { + log_e("Failed to create OpenThread esp_netif"); + err = true; + } + if (!err && ESP_OK != esp_netif_attach(openthread_netif, esp_openthread_netif_glue_init(&ot_native_config))) { + log_e("Failed to attach OpenThread esp_netif"); + err = true; + } + if (!err && ESP_OK != esp_netif_set_default_netif(openthread_netif)) { + log_e("Failed to set default OpenThread esp_netif"); + err = true; + } + if (!err) { + // only returns in case there is an OpenThread Stack failure... + esp_openthread_launch_mainloop(); + } + // Clean up + esp_openthread_netif_glue_deinit(); + esp_netif_destroy(openthread_netif); + esp_vfs_eventfd_unregister(); + vTaskDelete(NULL); +} + +// DataSet Implementation +DataSet::DataSet() { + memset(&mDataset, 0, sizeof(mDataset)); +} + +void DataSet::clear() { + memset(&mDataset, 0, sizeof(mDataset)); +} + +void DataSet::initNew() { + otInstance *mInstance = esp_openthread_get_instance(); + if (!mInstance) { + log_e("OpenThread not started. Please begin() it before initializing a new dataset."); + return; + } + clear(); + otDatasetCreateNewNetwork(mInstance, &mDataset); +} + +const otOperationalDataset &DataSet::getDataset() const { + return mDataset; +} + +void DataSet::setNetworkName(const char *name) { + strncpy(mDataset.mNetworkName.m8, name, sizeof(mDataset.mNetworkName.m8)); + mDataset.mComponents.mIsNetworkNamePresent = true; +} + +void DataSet::setExtendedPanId(const uint8_t *extPanId) { + memcpy(mDataset.mExtendedPanId.m8, extPanId, OT_EXT_PAN_ID_SIZE); + mDataset.mComponents.mIsExtendedPanIdPresent = true; +} + +void DataSet::setNetworkKey(const uint8_t *key) { + memcpy(mDataset.mNetworkKey.m8, key, OT_NETWORK_KEY_SIZE); + mDataset.mComponents.mIsNetworkKeyPresent = true; +} + +void DataSet::setChannel(uint8_t channel) { + mDataset.mChannel = channel; + mDataset.mComponents.mIsChannelPresent = true; +} + +void DataSet::setPanId(uint16_t panId) { + mDataset.mPanId = panId; + mDataset.mComponents.mIsPanIdPresent = true; +} + +const char *DataSet::getNetworkName() const { + return mDataset.mNetworkName.m8; +} + +const uint8_t *DataSet::getExtendedPanId() const { + return mDataset.mExtendedPanId.m8; +} + +const uint8_t *DataSet::getNetworkKey() const { + return mDataset.mNetworkKey.m8; +} + +uint8_t DataSet::getChannel() const { + return mDataset.mChannel; +} + +uint16_t DataSet::getPanId() const { + return mDataset.mPanId; +} + +void DataSet::apply(otInstance *instance) { + otDatasetSetActive(instance, &mDataset); +} + +// OpenThread Implementation +bool OpenThread::otStarted = false; + +otInstance *OpenThread::mInstance = nullptr; +OpenThread::OpenThread() {} + +OpenThread::~OpenThread() { + end(); +} + +OpenThread::operator bool() const { + return otStarted; +} + +void OpenThread::begin(bool OThreadAutoStart) { + if (otStarted) { + log_w("OpenThread already started"); + return; + } + + memset(&ot_native_config, 0, sizeof(esp_openthread_platform_config_t)); + ot_native_config.radio_config.radio_mode = RADIO_MODE_NATIVE; + ot_native_config.host_config.host_connection_mode = HOST_CONNECTION_MODE_NONE; + ot_native_config.port_config.storage_partition_name = "nvs"; + ot_native_config.port_config.netif_queue_size = 10; + ot_native_config.port_config.task_queue_size = 10; + + // Initialize OpenThread stack + xTaskCreate(ot_task_worker, "ot_main_loop", 10240, NULL, 20, &s_ot_task); + if (s_ot_task == NULL) { + log_e("Error: Failed to create OpenThread task"); + return; + } + log_d("OpenThread task created successfully"); + // get the OpenThread instance that will be used for all operations + mInstance = esp_openthread_get_instance(); + if (!mInstance) { + log_e("Error: Failed to initialize OpenThread instance"); + end(); + return; + } + // starts Thread with default dataset from NVS or from IDF default settings + if (OThreadAutoStart) { + otOperationalDatasetTlvs dataset; + otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset); + // error = OT_ERROR_FAILED; // teste para forçar NULL dataset + if (error != OT_ERROR_NONE) { + log_i("Failed to get active NVS dataset from OpenThread"); + } else { + log_i("Got active NVS dataset from OpenThread"); + } + esp_err_t err = esp_openthread_auto_start((error == OT_ERROR_NONE) ? &dataset : NULL); + if (err != ESP_OK) { + log_i("Failed to AUTO start OpenThread"); + } else { + log_i("AUTO start OpenThread done"); + } + } + otStarted = true; +} + +void OpenThread::end() { + if (s_ot_task != NULL) { + vTaskDelete(s_ot_task); + s_ot_task = NULL; + // Clean up + esp_openthread_deinit(); + esp_openthread_netif_glue_deinit(); +#if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM + ot_lwip_netif = NULL; +#endif + esp_netif_destroy(openthread_netif); + esp_vfs_eventfd_unregister(); + } + otStarted = false; +} + +void OpenThread::start() { + if (!mInstance) { + log_w("Error: OpenThread instance not initialized"); + return; + } + otThreadSetEnabled(mInstance, true); + log_d("Thread network started"); +} + +void OpenThread::stop() { + if (!mInstance) { + log_w("Error: OpenThread instance not initialized"); + return; + } + otThreadSetEnabled(mInstance, false); + log_d("Thread network stopped"); +} + +void OpenThread::networkInterfaceUp() { + if (!mInstance) { + log_w("Error: OpenThread instance not initialized"); + return; + } + // Enable the Thread interface (equivalent to CLI Command "ifconfig up") + otError error = otIp6SetEnabled(mInstance, true); + if (error != OT_ERROR_NONE) { + log_e("Error: Failed to enable Thread interface (error code: %d)\n", error); + } + log_d("OpenThread Network Interface is up"); +} + +void OpenThread::networkInterfaceDown() { + if (!mInstance) { + log_w("Error: OpenThread instance not initialized"); + return; + } + // Disable the Thread interface (equivalent to CLI Command "ifconfig down") + otError error = otIp6SetEnabled(mInstance, false); + if (error != OT_ERROR_NONE) { + log_e("Error: Failed to disable Thread interface (error code: %d)\n", error); + } + log_d("OpenThread Network Interface is down"); +} + +void OpenThread::commitDataSet(const DataSet &dataset) { + if (!mInstance) { + log_w("Error: OpenThread instance not initialized"); + return; + } + // Commit the dataset as the active dataset + otError error = otDatasetSetActive(mInstance, &(dataset.getDataset())); + if (error != OT_ERROR_NONE) { + log_e("Error: Failed to commit dataset (error code: %d)\n", error); + return; + } + log_d("Dataset committed successfully"); +} + +ot_device_role_t OpenThread::otGetDeviceRole() { + if (!mInstance) { + log_w("Error: OpenThread instance not initialized"); + return OT_ROLE_DISABLED; + } + return (ot_device_role_t)otThreadGetDeviceRole(mInstance); +} + +const char *OpenThread::otGetStringDeviceRole() { + return otRoleString[otGetDeviceRole()]; +} + +void OpenThread::otPrintNetworkInformation(Stream &output) { + if (!mInstance) { + log_w("Error: OpenThread instance not initialized"); + return; + } + + output.printf("Role: %s", otGetStringDeviceRole()); + output.println(); + output.printf("RLOC16: 0x%04x", otThreadGetRloc16(mInstance)); // RLOC16 + output.println(); + output.printf("Network Name: %s", otThreadGetNetworkName(mInstance)); + output.println(); + output.printf("Channel: %d", otLinkGetChannel(mInstance)); + output.println(); + output.printf("PAN ID: 0x%04x", otLinkGetPanId(mInstance)); + output.println(); + + const otExtendedPanId *extPanId = otThreadGetExtendedPanId(mInstance); + output.print("Extended PAN ID: "); + for (int i = 0; i < OT_EXT_PAN_ID_SIZE; i++) { + output.printf("%02x", extPanId->m8[i]); + } + output.println(); + + otNetworkKey networkKey; + otThreadGetNetworkKey(mInstance, &networkKey); + output.print("Network Key: "); + for (int i = 0; i < OT_NETWORK_KEY_SIZE; i++) { + output.printf("%02x", networkKey.m8[i]); + } + output.println(); +} + +OpenThread OThread; + +#endif /* CONFIG_OPENTHREAD_ENABLED */ +#endif /* SOC_IEEE802154_SUPPORTED */ diff --git a/libraries/OpenThread/src/OThread.h b/libraries/OpenThread/src/OThread.h new file mode 100644 index 00000000000..359d581bb9d --- /dev/null +++ b/libraries/OpenThread/src/OThread.h @@ -0,0 +1,107 @@ +// 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. + +#pragma once +#include "soc/soc_caps.h" +#include "sdkconfig.h" +#if SOC_IEEE802154_SUPPORTED +#if CONFIG_OPENTHREAD_ENABLED + +#include +#include +#include +#include +#include +#include +#include + +typedef enum { + OT_ROLE_DISABLED = 0, ///< The Thread stack is disabled. + OT_ROLE_DETACHED = 1, ///< Not currently participating in a Thread network/partition. + OT_ROLE_CHILD = 2, ///< The Thread Child role. + OT_ROLE_ROUTER = 3, ///< The Thread Router role. + OT_ROLE_LEADER = 4, ///< The Thread Leader role. +} ot_device_role_t; +extern const char *otRoleString[]; + +class DataSet { +public: + DataSet(); + void clear(); + void initNew(); + const otOperationalDataset &getDataset() const; + + // Setters + void setNetworkName(const char *name); + void setExtendedPanId(const uint8_t *extPanId); + void setNetworkKey(const uint8_t *key); + void setChannel(uint8_t channel); + void setPanId(uint16_t panId); + + // Getters + const char *getNetworkName() const; + const uint8_t *getExtendedPanId() const; + const uint8_t *getNetworkKey() const; + uint8_t getChannel() const; + uint16_t getPanId() const; + + // Apply the dataset to the OpenThread instance + void apply(otInstance *instance); + +private: + otOperationalDataset mDataset; +}; + +class OpenThread { +public: + static bool otStarted; + static ot_device_role_t otGetDeviceRole(); + static const char *otGetStringDeviceRole(); + static void otPrintNetworkInformation(Stream &output); + + OpenThread(); + ~OpenThread(); + // returns true if OpenThread Stack is running + operator bool() const; + + // Initialize OpenThread + static void begin(bool OThreadAutoStart = true); + + // Initialize OpenThread + static void end(); + + // Start the Thread network + void start(); + + // Stop the Thread network + void stop(); + + // Start Thread Network Interface + void networkInterfaceUp(); + + // Stop Thread Network Interface + void networkInterfaceDown(); + + // Set the dataset + void commitDataSet(const DataSet &dataset); + +private: + static otInstance *mInstance; + DataSet mCurrentDataSet; +}; + +extern OpenThread OThread; + +#endif /* CONFIG_OPENTHREAD_ENABLED */ +#endif /* SOC_IEEE802154_SUPPORTED */ diff --git a/libraries/OpenThread/src/OThreadCLI.cpp b/libraries/OpenThread/src/OThreadCLI.cpp index 85ba03563e8..2f0f97a0539 100644 --- a/libraries/OpenThread/src/OThreadCLI.cpp +++ b/libraries/OpenThread/src/OThreadCLI.cpp @@ -33,18 +33,12 @@ #include "esp_netif_net_stack.h" #include "lwip/netif.h" +bool OpenThreadCLI::otCLIStarted = false; static TaskHandle_t s_cli_task = NULL; static TaskHandle_t s_console_cli_task = NULL; static QueueHandle_t rx_queue = NULL; static QueueHandle_t tx_queue = NULL; -static esp_openthread_platform_config_t ot_native_config; -static TaskHandle_t s_ot_task = NULL; -static esp_netif_t *openthread_netif = NULL; -#if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM -static struct netif *ot_lwip_netif = NULL; -#endif - #define OT_CLI_MAX_LINE_LENGTH 512 typedef struct { @@ -53,21 +47,7 @@ typedef struct { String prompt; OnReceiveCb_t responseCallBack; } ot_cli_console_t; -static ot_cli_console_t otConsole = {NULL, false, (const char *)NULL, NULL}; - -#if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM -extern "C" int lwip_hook_ip6_input(struct pbuf *p, struct netif *inp) { - if (ot_lwip_netif && ot_lwip_netif == inp) { - return 0; - } - if (ip6_addr_isany_val(inp->ip6_addr[0].u_addr.ip6)) { - // We don't have an LL address -> eat this packet here, so it won't get accepted on input netif - pbuf_free(p); - return 1; - } - return 0; -} -#endif +static ot_cli_console_t otConsole = {nullptr, false, (const char *)nullptr, nullptr}; // process the CLI commands sent to the OpenThread stack static void ot_cli_loop(void *context) { @@ -131,7 +111,7 @@ static int ot_cli_output_callback(void *context, const char *format, va_list arg } // if there is a user callback function in place, it shall have the priority // to process/consume the Stream data received from OpenThread CLI, which is available in its RX Buffer - if (otConsole.responseCallBack != NULL) { + if (otConsole.responseCallBack != nullptr) { otConsole.responseCallBack(); } } @@ -205,7 +185,7 @@ void OpenThreadCLI::setEchoBack(bool echoback) { } void OpenThreadCLI::setPrompt(char *prompt) { - otConsole.prompt = prompt; // NULL will make the prompt not visible + otConsole.prompt = prompt; // nullptr can make the prompt not visible } void OpenThreadCLI::setStream(Stream &otStream) { @@ -213,12 +193,12 @@ void OpenThreadCLI::setStream(Stream &otStream) { } void OpenThreadCLI::onReceive(OnReceiveCb_t func) { - otConsole.responseCallBack = func; // NULL will set it off + otConsole.responseCallBack = func; // nullptr will set it off } // Stream object shall be already started and configured before calling this function void OpenThreadCLI::startConsole(Stream &otStream, bool echoback, const char *prompt) { - if (!otStarted) { + if (!otCLIStarted) { log_e("OpenThread CLI has not started. Please begin() it before starting the console."); return; } @@ -226,7 +206,7 @@ void OpenThreadCLI::startConsole(Stream &otStream, bool echoback, const char *pr if (s_console_cli_task == NULL) { otConsole.cliStream = &otStream; otConsole.echoback = echoback; - otConsole.prompt = prompt; // NULL will invalidate the String + otConsole.prompt = prompt; // nullptr will invalidate the String // it will run in the same priority (1) as the Arduino setup()/loop() task xTaskCreate(ot_cli_console_worker, "ot_cli_console", 4096, &otConsole, 1, &s_console_cli_task); } else { @@ -242,12 +222,6 @@ void OpenThreadCLI::stopConsole() { } OpenThreadCLI::OpenThreadCLI() { - memset(&ot_native_config, 0, sizeof(esp_openthread_platform_config_t)); - ot_native_config.radio_config.radio_mode = RADIO_MODE_NATIVE; - ot_native_config.host_config.host_connection_mode = HOST_CONNECTION_MODE_NONE; - ot_native_config.port_config.storage_partition_name = "nvs"; - ot_native_config.port_config.netif_queue_size = 10; - ot_native_config.port_config.task_queue_size = 10; //sTxString = ""; } @@ -256,79 +230,19 @@ OpenThreadCLI::~OpenThreadCLI() { } OpenThreadCLI::operator bool() const { - return otStarted; + return otCLIStarted; } -static void ot_task_worker(void *aContext) { - esp_vfs_eventfd_config_t eventfd_config = { - .max_fds = 3, - }; - bool err = false; - if (ESP_OK != esp_event_loop_create_default()) { - log_e("Failed to create OpentThread event loop"); - err = true; - } - if (!err && ESP_OK != esp_netif_init()) { - log_e("Failed to initialize OpentThread netif"); - err = true; - } - if (!err && ESP_OK != esp_vfs_eventfd_register(&eventfd_config)) { - log_e("Failed to register OpentThread eventfd"); - err = true; - } - - // Initialize the OpenThread stack - if (!err && ESP_OK != esp_openthread_init(&ot_native_config)) { - log_e("Failed to initialize OpenThread stack"); - err = true; - } - if (!err) { - // Initialize the OpenThread cli - otCliInit(esp_openthread_get_instance(), ot_cli_output_callback, NULL); - - // Initialize the esp_netif bindings - esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD(); - openthread_netif = esp_netif_new(&cfg); -#if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM - // Get LwIP Netif - if (openthread_netif != NULL) { - ot_lwip_netif = (struct netif *)esp_netif_get_netif_impl(openthread_netif); - if (ot_lwip_netif == NULL) { - log_e("Failed to get OpenThread LwIP netif"); - } - } -#endif - } - if (!err && openthread_netif == NULL) { - log_e("Failed to create OpenThread esp_netif"); - err = true; - } - if (!err && ESP_OK != esp_netif_attach(openthread_netif, esp_openthread_netif_glue_init(&ot_native_config))) { - log_e("Failed to attach OpenThread esp_netif"); - err = true; - } - if (!err && ESP_OK != esp_netif_set_default_netif(openthread_netif)) { - log_e("Failed to set default OpenThread esp_netif"); - err = true; - } - if (!err) { - // only returns in case there is an OpenThread Stack failure... - esp_openthread_launch_mainloop(); - } - // Clean up - esp_openthread_netif_glue_deinit(); - esp_netif_destroy(openthread_netif); - esp_vfs_eventfd_unregister(); - vTaskDelete(NULL); -} - -void OpenThreadCLI::begin(bool OThreadAutoStart) { - if (otStarted) { +void OpenThreadCLI::begin() { + if (otCLIStarted) { log_w("OpenThread CLI already started. Please end() it before starting again."); return; } - xTaskCreate(ot_task_worker, "ot_main_loop", 10240, NULL, 20, &s_ot_task); + if (!OpenThread::otStarted) { + log_w("OpenThread not started. Please begin() it before starting CLI."); + return; + } //RX Buffer default has 1024 bytes if not preset if (rx_queue == NULL) { @@ -342,55 +256,29 @@ void OpenThreadCLI::begin(bool OThreadAutoStart) { log_e("HW CDC RX Buffer error"); } } + xTaskCreate(ot_cli_loop, "ot_cli", 4096, xTaskGetCurrentTaskHandle(), 2, &s_cli_task); + // Initialize the OpenThread cli + otCliInit(esp_openthread_get_instance(), ot_cli_output_callback, NULL); - // starts Thread with default dataset from NVS or from IDF default settings - if (OThreadAutoStart) { - otOperationalDatasetTlvs dataset; - otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset); - // error = OT_ERROR_FAILED; // teste para forçar NULL dataset - if (error != OT_ERROR_NONE) { - log_i("Failed to get active NVS dataset from OpenThread"); - } else { - log_i("Got active NVS dataset from OpenThread"); - } - esp_err_t err = esp_openthread_auto_start((error == OT_ERROR_NONE) ? &dataset : NULL); - if (err != ESP_OK) { - log_i("Failed to AUTO start OpenThread"); - } else { - log_i("AUTO start OpenThread done"); - } - } - otStarted = true; + otCLIStarted = true; return; } void OpenThreadCLI::end() { - if (!otStarted) { + if (!otCLIStarted) { log_w("OpenThread CLI already stopped. Please begin() it before stopping again."); return; } - if (s_ot_task != NULL) { - vTaskDelete(s_ot_task); - // Clean up - esp_openthread_deinit(); - esp_openthread_netif_glue_deinit(); -#if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM - ot_lwip_netif = NULL; -#endif - esp_netif_destroy(openthread_netif); - esp_vfs_eventfd_unregister(); - } if (s_cli_task != NULL) { vTaskDelete(s_cli_task); + s_cli_task = NULL; } - if (s_console_cli_task != NULL) { - vTaskDelete(s_console_cli_task); - } + stopConsole(); esp_event_loop_delete_default(); setRxBufferSize(0); setTxBufferSize(0); - otStarted = false; + otCLIStarted = false; } size_t OpenThreadCLI::write(uint8_t c) { diff --git a/libraries/OpenThread/src/OThreadCLI.h b/libraries/OpenThread/src/OThreadCLI.h index bc8dc5d2b19..788edc2709b 100644 --- a/libraries/OpenThread/src/OThreadCLI.h +++ b/libraries/OpenThread/src/OThreadCLI.h @@ -21,7 +21,6 @@ #include "esp_openthread.h" #include "esp_openthread_cli.h" #include "esp_openthread_lock.h" -#include "esp_openthread_netif_glue.h" #include "esp_openthread_types.h" #include "openthread/cli.h" @@ -31,13 +30,14 @@ #include "openthread/dataset_ftd.h" #include "Arduino.h" +#include "OThread.h" typedef std::function OnReceiveCb_t; class OpenThreadCLI : public Stream { private: static size_t setBuffer(QueueHandle_t &queue, size_t len); - bool otStarted = false; + static bool otCLIStarted; public: OpenThreadCLI(); @@ -53,7 +53,7 @@ class OpenThreadCLI : public Stream { void setStream(Stream &otStream); // changes the console Stream object void onReceive(OnReceiveCb_t func); // called on a complete line of output from OT CLI, as OT Response - void begin(bool OThreadAutoStart = true); + void begin(); void end(); // default size is 256 bytes diff --git a/libraries/OpenThread/src/OThreadCLI_Util.cpp b/libraries/OpenThread/src/OThreadCLI_Util.cpp index d21daa1effc..aad435107bb 100644 --- a/libraries/OpenThread/src/OThreadCLI_Util.cpp +++ b/libraries/OpenThread/src/OThreadCLI_Util.cpp @@ -19,26 +19,6 @@ #include "OThreadCLI_Util.h" #include -static const char *otRoleString[] = { - "Disabled", ///< The Thread stack is disabled. - "Detached", ///< Not currently participating in a Thread network/partition. - "Child", ///< The Thread Child role. - "Router", ///< The Thread Router role. - "Leader", ///< The Thread Leader role. -}; - -ot_device_role_t otGetDeviceRole() { - if (!OThreadCLI) { - return OT_ROLE_DISABLED; - } - otInstance *instance = esp_openthread_get_instance(); - return (ot_device_role_t)otThreadGetDeviceRole(instance); -} - -const char *otGetStringDeviceRole() { - return otRoleString[otGetDeviceRole()]; -} - bool otGetRespCmd(const char *cmd, char *resp, uint32_t respTimeout) { if (!OThreadCLI) { return false; @@ -174,7 +154,7 @@ bool otPrintRespCLI(const char *cmd, Stream &output, uint32_t respTimeout) { return true; } -void otPrintNetworkInformation(Stream &output) { +void otCLIPrintNetworkInformation(Stream &output) { if (!OThreadCLI) { return; } diff --git a/libraries/OpenThread/src/OThreadCLI_Util.h b/libraries/OpenThread/src/OThreadCLI_Util.h index 1ab2e061dfc..116b886e095 100644 --- a/libraries/OpenThread/src/OThreadCLI_Util.h +++ b/libraries/OpenThread/src/OThreadCLI_Util.h @@ -18,25 +18,14 @@ #if SOC_IEEE802154_SUPPORTED #if CONFIG_OPENTHREAD_ENABLED -typedef enum { - OT_ROLE_DISABLED = 0, ///< The Thread stack is disabled. - OT_ROLE_DETACHED = 1, ///< Not currently participating in a Thread network/partition. - OT_ROLE_CHILD = 2, ///< The Thread Child role. - OT_ROLE_ROUTER = 3, ///< The Thread Router role. - OT_ROLE_LEADER = 4, ///< The Thread Leader role. -} ot_device_role_t; - typedef struct { int errorCode; String errorMessage; } ot_cmd_return_t; -ot_device_role_t otGetDeviceRole(); -const char *otGetStringDeviceRole(); bool otGetRespCmd(const char *cmd, char *resp = NULL, uint32_t respTimeout = 5000); bool otExecCommand(const char *cmd, const char *arg, ot_cmd_return_t *returnCode = NULL); bool otPrintRespCLI(const char *cmd, Stream &output, uint32_t respTimeout); -void otPrintNetworkInformation(Stream &output); #endif /* CONFIG_OPENTHREAD_ENABLED */ #endif /* SOC_IEEE802154_SUPPORTED */ diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index eaec2483053..2d646276d87 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -27,7 +27,9 @@ bool SDFS::begin(uint8_t ssPin, SPIClass &spi, uint32_t frequency, const char *m return true; } - spi.begin(); + if (!spi.begin()) { + return false; + } _pdrv = sdcard_init(ssPin, &spi, frequency); if (_pdrv == 0xFF) { diff --git a/libraries/SPI/src/SPI.cpp b/libraries/SPI/src/SPI.cpp index 35e52f43e4d..7d8d44320a6 100644 --- a/libraries/SPI/src/SPI.cpp +++ b/libraries/SPI/src/SPI.cpp @@ -63,9 +63,9 @@ SPIClass::~SPIClass() { #endif } -void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) { +bool SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) { if (_spi) { - return; + return true; } if (!_div) { @@ -74,7 +74,8 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) { _spi = spiStartBus(_spi_num, _div, SPI_MODE0, SPI_MSBFIRST); if (!_spi) { - return; + log_e("SPI bus %d start failed.", _spi_num); + return false; } if (sck == -1 && miso == -1 && mosi == -1 && ss == -1) { @@ -110,10 +111,11 @@ void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) { if (_mosi >= 0 && !spiAttachMOSI(_spi, _mosi)) { goto err; } - return; + return true; err: log_e("Attaching pins to SPI failed."); + return false; } void SPIClass::end() { @@ -144,6 +146,12 @@ void SPIClass::setHwCs(bool use) { _use_hw_ss = use; } +void SPIClass::setSSInvert(bool invert) { + if (_spi) { + spiSSInvert(_spi, invert); + } +} + void SPIClass::setFrequency(uint32_t freq) { SPI_PARAM_LOCK(); //check if last freq changed diff --git a/libraries/SPI/src/SPI.h b/libraries/SPI/src/SPI.h index adb3d1bc11f..6c300e53df2 100644 --- a/libraries/SPI/src/SPI.h +++ b/libraries/SPI/src/SPI.h @@ -61,10 +61,11 @@ class SPIClass { public: SPIClass(uint8_t spi_bus = HSPI); ~SPIClass(); - void begin(int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1, int8_t ss = -1); + bool begin(int8_t sck = -1, int8_t miso = -1, int8_t mosi = -1, int8_t ss = -1); void end(); void setHwCs(bool use); + void setSSInvert(bool invert); //use before setHwCS for change to be used by setHwCs void setBitOrder(uint8_t bitOrder); void setDataMode(uint8_t dataMode); void setFrequency(uint32_t freq); diff --git a/libraries/USB/src/USBHIDConsumerControl.h b/libraries/USB/src/USBHIDConsumerControl.h index e65e529a77b..7a59c70b6b1 100644 --- a/libraries/USB/src/USBHIDConsumerControl.h +++ b/libraries/USB/src/USBHIDConsumerControl.h @@ -37,10 +37,14 @@ #define CONSUMER_CONTROL_WIRELESS_RADIO_SLIDER_SWITCH 0x00C8 // Media Control -#define CONSUMER_CONTROL_PLAY_PAUSE 0x00CD +#define CONSUMER_CONTROL_RECORD 0x00B2 +#define CONSUMER_CONTROL_FAST_FORWARD 0x00B3 +#define CONSUMER_CONTROL_REWIND 0x00B4 #define CONSUMER_CONTROL_SCAN_NEXT 0x00B5 #define CONSUMER_CONTROL_SCAN_PREVIOUS 0x00B6 #define CONSUMER_CONTROL_STOP 0x00B7 +#define CONSUMER_CONTROL_EJECT 0x00B8 +#define CONSUMER_CONTROL_PLAY_PAUSE 0x00CD #define CONSUMER_CONTROL_VOLUME 0x00E0 #define CONSUMER_CONTROL_MUTE 0x00E2 #define CONSUMER_CONTROL_BASS 0x00E3 diff --git a/libraries/USB/src/keyboardLayout/KeyboardLayout.h b/libraries/USB/src/keyboardLayout/KeyboardLayout.h index 0ef69dc7ab9..ee6b6b4e11e 100644 --- a/libraries/USB/src/keyboardLayout/KeyboardLayout.h +++ b/libraries/USB/src/keyboardLayout/KeyboardLayout.h @@ -5,7 +5,7 @@ only in Keyboard.cpp and the keyboard layout files. Layout files map ASCII character codes to keyboard scan codes (technically, to USB HID Usage codes), possibly altered by the SHIFT or ALT_GR modifiers. - Non-ACSII characters (anything outside the 7-bit range NUL..DEL) are + Non-ASCII characters (anything outside the 7-bit range NUL..DEL) are not supported. == Creating your own layout == diff --git a/libraries/WiFi/src/AP.cpp b/libraries/WiFi/src/AP.cpp index 0e7839764ea..a649c3898cb 100644 --- a/libraries/WiFi/src/AP.cpp +++ b/libraries/WiFi/src/AP.cpp @@ -305,6 +305,45 @@ bool APClass::enableNAPT(bool enable) { return true; } +bool APClass::enableDhcpCaptivePortal() { + esp_err_t err = ESP_OK; + static char captiveportal_uri[32] = { + 0, + }; + + if (!started()) { + log_e("AP must be first started to enable DHCP Captive Portal"); + return false; + } + + // Create Captive Portal URL: http://192.168.0.4 + strcpy(captiveportal_uri, "http://"); + strcat(captiveportal_uri, String(localIP()).c_str()); + + // Stop DHCPS + err = esp_netif_dhcps_stop(_esp_netif); + if (err && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) { + log_e("DHCPS Stop Failed! 0x%04x: %s", err, esp_err_to_name(err)); + return false; + } + + // Enable DHCP Captive Portal + err = esp_netif_dhcps_option(_esp_netif, ESP_NETIF_OP_SET, ESP_NETIF_CAPTIVEPORTAL_URI, captiveportal_uri, strlen(captiveportal_uri)); + if (err) { + log_e("Could not set enable DHCP Captive Portal! 0x%x: %s", err, esp_err_to_name(err)); + return false; + } + + // Start DHCPS + err = esp_netif_dhcps_start(_esp_netif); + if (err) { + log_e("DHCPS Start Failed! 0x%04x: %s", err, esp_err_to_name(err)); + return false; + } + + return true; +} + String APClass::SSID(void) const { if (!started()) { return String(); diff --git a/libraries/WiFi/src/WiFiAP.h b/libraries/WiFi/src/WiFiAP.h index 540ec87f44f..2b7ce469801 100644 --- a/libraries/WiFi/src/WiFiAP.h +++ b/libraries/WiFi/src/WiFiAP.h @@ -53,6 +53,7 @@ class APClass : public NetworkInterface { bool bandwidth(wifi_bandwidth_t bandwidth); bool enableNAPT(bool enable = true); + bool enableDhcpCaptivePortal(); String SSID(void) const; uint8_t stationCount(); diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index aa994963514..bddcb5fd448 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -252,13 +252,23 @@ static bool wifiHostedInit() { if (!hosted_initialized) { hosted_initialized = true; struct esp_hosted_sdio_config conf = INIT_DEFAULT_HOST_SDIO_CONFIG(); +#ifdef BOARD_HAS_SDIO_ESP_HOSTED + conf.pin_clk.pin = BOARD_SDIO_ESP_HOSTED_CLK; + conf.pin_cmd.pin = BOARD_SDIO_ESP_HOSTED_CMD; + conf.pin_d0.pin = BOARD_SDIO_ESP_HOSTED_D0; + conf.pin_d1.pin = BOARD_SDIO_ESP_HOSTED_D1; + conf.pin_d2.pin = BOARD_SDIO_ESP_HOSTED_D2; + conf.pin_d3.pin = BOARD_SDIO_ESP_HOSTED_D3; + conf.pin_reset.pin = BOARD_SDIO_ESP_HOSTED_RESET; +#else conf.pin_clk.pin = CONFIG_ESP_SDIO_PIN_CLK; conf.pin_cmd.pin = CONFIG_ESP_SDIO_PIN_CMD; conf.pin_d0.pin = CONFIG_ESP_SDIO_PIN_D0; conf.pin_d1.pin = CONFIG_ESP_SDIO_PIN_D1; conf.pin_d2.pin = CONFIG_ESP_SDIO_PIN_D2; conf.pin_d3.pin = CONFIG_ESP_SDIO_PIN_D3; - //conf.pin_rst.pin = CONFIG_ESP_SDIO_GPIO_RESET_SLAVE; + conf.pin_reset.pin = CONFIG_ESP_SDIO_GPIO_RESET_SLAVE; +#endif // esp_hosted_sdio_set_config() will fail on second attempt but here temporarily to not cause exception on reinit if (esp_hosted_sdio_set_config(&conf) != ESP_OK || esp_hosted_init() != ESP_OK) { log_e("esp_hosted_init failed!"); @@ -602,9 +612,9 @@ bool WiFiGenericClass::mode(wifi_mode_t m) { #else #define WIFI_PROTOCOL_DEFAULT (WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N) #endif - uint8_t current_protocol = 0; + uint32_t current_protocol = 0; if (m & WIFI_MODE_STA) { - err = esp_wifi_get_protocol(WIFI_IF_STA, ¤t_protocol); + err = esp_wifi_get_protocol(WIFI_IF_STA, (uint8_t *)¤t_protocol); if (err == ESP_OK && current_protocol == WIFI_PROTOCOL_LR) { log_v("Disabling long range on STA"); err = esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_DEFAULT); @@ -614,7 +624,7 @@ bool WiFiGenericClass::mode(wifi_mode_t m) { } } if (m & WIFI_MODE_AP) { - err = esp_wifi_get_protocol(WIFI_IF_AP, ¤t_protocol); + err = esp_wifi_get_protocol(WIFI_IF_AP, (uint8_t *)¤t_protocol); if (err == ESP_OK && current_protocol == WIFI_PROTOCOL_LR) { log_v("Disabling long range on AP"); err = esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_DEFAULT); diff --git a/libraries/Zigbee/examples/Zigbee_Analog_Input_Output/Zigbee_Analog_Input_Output.ino b/libraries/Zigbee/examples/Zigbee_Analog_Input_Output/Zigbee_Analog_Input_Output.ino index e31407cc8be..f1cc54bda64 100644 --- a/libraries/Zigbee/examples/Zigbee_Analog_Input_Output/Zigbee_Analog_Input_Output.ino +++ b/libraries/Zigbee/examples/Zigbee_Analog_Input_Output/Zigbee_Analog_Input_Output.ino @@ -26,8 +26,8 @@ * Modified by Pat Clay */ -#ifndef ZIGBEE_MODE_ED -#error "Zigbee end device mode is not selected in Tools->Zigbee mode" +#ifndef ZIGBEE_MODE_ZCZR +#error "Zigbee coordinator/router device mode is not selected in Tools->Zigbee mode" #endif #include "Zigbee.h" @@ -39,6 +39,9 @@ uint8_t analogPin = A0; uint8_t button = BOOT_PIN; ZigbeeAnalog zbAnalogDevice = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER); +ZigbeeAnalog zbAnalogTemp = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER + 1); +ZigbeeAnalog zbAnalogFan = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER + 2); +ZigbeeAnalog zbAnalogPercent = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER + 3); void onAnalogOutputChange(float analog_output) { Serial.printf("Received analog output change: %.1f\r\n", analog_output); @@ -57,19 +60,51 @@ void setup() { // Optional: set Zigbee device name and model zbAnalogDevice.setManufacturerAndModel("Espressif", "ZigbeeAnalogDevice"); - // Add analog clusters to Zigbee Analog according your needs + // Set up analog input zbAnalogDevice.addAnalogInput(); + zbAnalogDevice.setAnalogInputApplication(ESP_ZB_ZCL_AI_POWER_IN_WATTS_CONSUMPTION); + zbAnalogDevice.setAnalogInputDescription("Power Consumption (Watts)"); + zbAnalogDevice.setAnalogInputResolution(0.01); + + // Set up analog output zbAnalogDevice.addAnalogOutput(); + zbAnalogDevice.setAnalogOutputApplication(ESP_ZB_ZCL_AI_RPM_OTHER); + zbAnalogDevice.setAnalogOutputDescription("Fan Speed (RPM)"); + zbAnalogDevice.setAnalogOutputResolution(1); + + // Set the min and max values for the analog output which is used by HA to limit the range of the analog output + zbAnalogDevice.setAnalogOutputMinMax(-10000, 10000); //-10000 to 10000 RPM // If analog output cluster is added, set callback function for analog output change zbAnalogDevice.onAnalogOutputChange(onAnalogOutputChange); + // Set up analog input + zbAnalogTemp.addAnalogInput(); + zbAnalogTemp.setAnalogInputApplication(ESP_ZB_ZCL_AI_TEMPERATURE_OTHER); + zbAnalogTemp.setAnalogInputDescription("Temperature"); + zbAnalogTemp.setAnalogInputResolution(0.1); + + // Set up analog input + zbAnalogFan.addAnalogInput(); + zbAnalogFan.setAnalogInputApplication(ESP_ZB_ZCL_AI_RPM_OTHER); + zbAnalogFan.setAnalogInputDescription("RPM"); + zbAnalogFan.setAnalogInputResolution(1); + + // Set up analog input + zbAnalogPercent.addAnalogInput(); + zbAnalogPercent.setAnalogInputApplication(ESP_ZB_ZCL_AI_PERCENTAGE_OTHER); + zbAnalogPercent.setAnalogInputDescription("Percentage"); + zbAnalogPercent.setAnalogInputResolution(0.01); + // Add endpoints to Zigbee Core Zigbee.addEndpoint(&zbAnalogDevice); + Zigbee.addEndpoint(&zbAnalogTemp); + Zigbee.addEndpoint(&zbAnalogFan); + Zigbee.addEndpoint(&zbAnalogPercent); Serial.println("Starting Zigbee..."); - // When all EPs are registered, start Zigbee in End Device mode - if (!Zigbee.begin()) { + // When all EPs are registered, start Zigbee in Router Device mode + if (!Zigbee.begin(ZIGBEE_ROUTER)) { Serial.println("Zigbee failed to start!"); Serial.println("Rebooting..."); ESP.restart(); @@ -95,9 +130,15 @@ void loop() { float analog = (float)analogRead(analogPin); Serial.printf("Updating analog input to %.1f\r\n", analog); zbAnalogDevice.setAnalogInput(analog); + zbAnalogTemp.setAnalogInput(analog / 100); + zbAnalogFan.setAnalogInput(analog); + zbAnalogPercent.setAnalogInput(analog / 10); // Analog input supports reporting zbAnalogDevice.reportAnalogInput(); + zbAnalogTemp.reportAnalogInput(); + zbAnalogFan.reportAnalogInput(); + zbAnalogPercent.reportAnalogInput(); } // Checking button for factory reset and reporting @@ -114,6 +155,9 @@ void loop() { Zigbee.factoryReset(); } } + // For demonstration purposes, increment the analog output value by 100 + zbAnalogDevice.setAnalogOutput(zbAnalogDevice.getAnalogOutput() + 100); + zbAnalogDevice.reportAnalogOutput(); } delay(100); } diff --git a/libraries/Zigbee/examples/Zigbee_Analog_Input_Output/ci.json b/libraries/Zigbee/examples/Zigbee_Analog_Input_Output/ci.json index ceacc367801..15d6190e4ae 100644 --- a/libraries/Zigbee/examples/Zigbee_Analog_Input_Output/ci.json +++ b/libraries/Zigbee/examples/Zigbee_Analog_Input_Output/ci.json @@ -1,7 +1,6 @@ { - "fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed", + "fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr", "requires": [ - "CONFIG_SOC_IEEE802154_SUPPORTED=y", "CONFIG_ZB_ENABLED=y" ] } diff --git a/libraries/Zigbee/examples/Zigbee_Binary_Input/README.md b/libraries/Zigbee/examples/Zigbee_Binary_Input/README.md new file mode 100644 index 00000000000..6ca3aac7119 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Binary_Input/README.md @@ -0,0 +1,75 @@ +# Arduino-ESP32 Zigbee Binary Input Example + +This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) binary input device with two different applications: HVAC fan status and security zone armed status. + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## Binary Input Functions + + * The example implements two binary inputs: + - HVAC Fan Status: Reports the current state of a fan + - Security Zone Armed: Reports the armed state of a security zone + * By clicking the button (BOOT) on this board, it will toggle both binary inputs and immediately send a report of their states to the network. + * Holding the button for more than 3 seconds will trigger a factory reset of the Zigbee device. + +## Hardware Required + +* A USB cable for power supply and programming + +### Configure the Project + +The example uses the following default pins: +* Button: `BOOT_PIN` (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 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. +* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`. + +## Troubleshooting + +If the End device flashed with this example 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`. +* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack. + +By default, the coordinator network is closed after rebooting or flashing new firmware. +To open the network you have 2 options: + +* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`. +* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join. + +***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/libraries/Zigbee/examples/Zigbee_Binary_Input/Zigbee_Binary_Input.ino b/libraries/Zigbee/examples/Zigbee_Binary_Input/Zigbee_Binary_Input.ino new file mode 100644 index 00000000000..de0cf606dcd --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Binary_Input/Zigbee_Binary_Input.ino @@ -0,0 +1,112 @@ +// Copyright 2025 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 Zigbee binary input device. + * + * The example demonstrates how to use Zigbee library to create an end device binary sensor device. + * + * 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 binary sensor device configuration */ +#define BINARY_DEVICE_ENDPOINT_NUMBER 1 + +uint8_t binaryPin = A0; +uint8_t button = BOOT_PIN; + +ZigbeeBinary zbBinaryFan = ZigbeeBinary(BINARY_DEVICE_ENDPOINT_NUMBER); +ZigbeeBinary zbBinaryZone = ZigbeeBinary(BINARY_DEVICE_ENDPOINT_NUMBER + 1); + +bool binaryStatus = false; + +void setup() { + Serial.begin(115200); + Serial.println("Starting..."); + + // Init button switch + pinMode(button, INPUT_PULLUP); + + // Set analog resolution to 10 bits + analogReadResolution(10); + + // Optional: set Zigbee device name and model + zbBinaryFan.setManufacturerAndModel("Espressif", "ZigbeeBinarySensor"); + + // Set up binary fan status input (HVAC) + zbBinaryFan.addBinaryInput(); + zbBinaryFan.setBinaryInputApplication(BINARY_INPUT_APPLICATION_TYPE_HVAC_FAN_STATUS); + zbBinaryFan.setBinaryInputDescription("Fan Status"); + + // Set up binary zone armed input (Security) + zbBinaryZone.addBinaryInput(); + zbBinaryZone.setBinaryInputApplication(BINARY_INPUT_APPLICATION_TYPE_SECURITY_ZONE_ARMED); + zbBinaryZone.setBinaryInputDescription("Zone Armed"); + + // Add endpoints to Zigbee Core + Zigbee.addEndpoint(&zbBinaryFan); + Zigbee.addEndpoint(&zbBinaryZone); + + Serial.println("Starting Zigbee..."); + // When all EPs are registered, start Zigbee in End Device mode + if (!Zigbee.begin()) { + Serial.println("Zigbee failed to start!"); + Serial.println("Rebooting..."); + ESP.restart(); + } else { + Serial.println("Zigbee started successfully!"); + } + Serial.println("Connecting to network"); + while (!Zigbee.connected()) { + Serial.print("."); + delay(100); + } + Serial.println("Connected"); +} + +void loop() { + // Checking button for factory reset and reporting + 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 binary input + binaryStatus = !binaryStatus; + zbBinaryFan.setBinaryInput(binaryStatus); + zbBinaryZone.setBinaryInput(binaryStatus); + zbBinaryFan.reportBinaryInput(); + zbBinaryZone.reportBinaryInput(); + } + delay(100); +} diff --git a/libraries/Zigbee/examples/Zigbee_Binary_Input/ci.json b/libraries/Zigbee/examples/Zigbee_Binary_Input/ci.json new file mode 100644 index 00000000000..ceacc367801 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Binary_Input/ci.json @@ -0,0 +1,7 @@ +{ + "fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed", + "requires": [ + "CONFIG_SOC_IEEE802154_SUPPORTED=y", + "CONFIG_ZB_ENABLED=y" + ] +} diff --git a/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor/README.md b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor/README.md new file mode 100644 index 00000000000..fe032049c90 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor/README.md @@ -0,0 +1,87 @@ +# Arduino-ESP32 Zigbee AC Electrical Measurement Example + +This example shows how to configure the Zigbee router device and use it as a Home Automation (HA) AC electrical measurement device that reports voltage, current, power, and frequency measurements. + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## AC Electrical Measurement Functions + + * After this board first starts up, it would be configured locally to report AC electrical measurements: + - AC voltage in volts (0-300.00 V) + - AC current in amps (0-10.000 A) + - AC power in watts (0-3200.0 W) + - AC frequency in hertz (0-65.000 Hz) + * Holding the button (BOOT) for more than 3 seconds will trigger a factory reset of the device. + * The device reports measurements every 2 seconds with simulated values. + +## Measurement Precision + +The example demonstrates how to set up proper measurement precision using multiplier and divisor values: + * Voltage: 1/100 = 0.01 V (1 unit = 10 mV) + * Current: 1/1000 = 0.001 A (1 unit = 1 mA) + * Power: 1/10 = 0.1 W (1 unit = 100 mW) + * Frequency: 1/1000 = 0.001 Hz (1 unit = 1 mHz) + +These settings ensure accurate reporting of measurements with proper decimal precision in the Zigbee network. + +## Hardware Required + +* A USB cable for power supply and programming + +### Configure the Project + +Set the ADC GPIO by changing the `analogPin` variable. By default, it's the pin `A0`. +Set the Button GPIO by changing the `button` variable. By default, it's the pin `BOOT_PIN` (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 Router Zigbee mode: `Tools -> Zigbee mode: Zigbee 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 verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`. + +## Troubleshooting + +If the Router device flashed with this example is not connecting to the coordinator, erase the flash of the Router 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`. +* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack. + +By default, the coordinator network is closed after rebooting or flashing new firmware. +To open the network you have 2 options: + +* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`. +* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join. + +***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/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor/Zigbee_Electrical_AC_Sensor.ino b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor/Zigbee_Electrical_AC_Sensor.ino new file mode 100644 index 00000000000..9e8656119d6 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor/Zigbee_Electrical_AC_Sensor.ino @@ -0,0 +1,162 @@ +// Copyright 2025 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 Zigbee electrical AC measurement device. + * + * The example demonstrates how to use Zigbee library to create a router device that measures + * AC electrical parameters like voltage, current, power, power factor and frequency. + * + * 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/) + */ + +// Recommended to use Router mode, as this type of device is expected to be mains powered. +#ifndef ZIGBEE_MODE_ZCZR +#error "Zigbee coordinator/router mode is not selected in Tools->Zigbee mode" +#endif + +#include "Zigbee.h" + +/* Zigbee AC measurement device configuration */ +#define AC_ELECTRICAL_MEASUREMENT_ENDPOINT_NUMBER 1 + +uint8_t analogPin = A0; +uint8_t button = BOOT_PIN; + +ZigbeeElectricalMeasurement zbElectricalMeasurement = ZigbeeElectricalMeasurement(AC_ELECTRICAL_MEASUREMENT_ENDPOINT_NUMBER); + +void onAnalogOutputChange(float analog_output) { + Serial.printf("Received analog output change: %.1f\r\n", analog_output); +} + +void setup() { + Serial.begin(115200); + Serial.println("Starting..."); + + // Init button switch + pinMode(button, INPUT_PULLUP); + + // Set analog resolution to 10 bits + analogReadResolution(10); + + // Optional: set Zigbee device name and model + zbElectricalMeasurement.setManufacturerAndModel("Espressif", "ZigbeeElectricalMeasurementAC"); + + // Add analog clusters to Zigbee Analog according your needs + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_POWER_FACTOR, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.addACMeasurement( + ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC + ); // frequency is not phase specific (shared) + + // Optional: set Multiplier/Divisor for the measurements + zbElectricalMeasurement.setACMultiplierDivisor(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, 1, 100); // 1/100 = 0.01V (1 unit of measurement = 0.01V = 10mV) + zbElectricalMeasurement.setACMultiplierDivisor(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, 1, 1000); // 1/1000 = 0.001A (1 unit of measurement = 0.001A = 1mA) + zbElectricalMeasurement.setACMultiplierDivisor(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, 1, 10); // 1/10 = 0.1W (1 unit of measurement = 0.1W = 100mW) + zbElectricalMeasurement.setACMultiplierDivisor(ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, 1, 1000); // 1/1000 = 0.001Hz (1 unit of measurement = 0.001Hz = 1mHz) + + // Optional: set Min/max values for the measurements + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_A, 0, 30000); // 0-300.00V + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_A, 0, 10000); // 0-10.000A + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_A, 0, 32000); // 0-3200.0W + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC, 0, 65000); // 0-65.000Hz + + // Optional: set power factor for the measurements + zbElectricalMeasurement.setACPowerFactor(ZIGBEE_AC_PHASE_TYPE_A, 98); // 100 = 1.00, 0 = 0.00, -100 = -1.00 + + // Add endpoints to Zigbee Core + Zigbee.addEndpoint(&zbElectricalMeasurement); + + Serial.println("Starting Zigbee..."); + // When all EPs are registered, start Zigbee in Router mode + if (!Zigbee.begin(ZIGBEE_ROUTER)) { + Serial.println("Zigbee failed to start!"); + Serial.println("Rebooting..."); + ESP.restart(); + } else { + Serial.println("Zigbee started successfully!"); + } + Serial.println("Connecting to network"); + while (!Zigbee.connected()) { + Serial.print("."); + delay(100); + } + Serial.println("Connected"); + + // Optional: Add reporting for AC measurements (this is overridden by HomeAssistant ZHA if used as a Zigbee coordinator) + zbElectricalMeasurement.setACReporting( + ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_A, 0, 30, 10 + ); // report every 30 seconds if value changes by 10 (0.1V) + zbElectricalMeasurement.setACReporting( + ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_A, 0, 30, 100 + ); // report every 30 seconds if value changes by 10 (0.1A) + zbElectricalMeasurement.setACReporting( + ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_A, 0, 30, 10 + ); // report every 30 seconds if value changes by 10 (1W) + zbElectricalMeasurement.setACReporting( + ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC, 0, 30, 100 + ); // report every 30 seconds if value changes by 100 (0.1Hz) +} + +void loop() { + static uint32_t timeCounter = 0; + + static uint8_t randomizer = 0; + // Read ADC value as current to demonstrate the measurements and update the electrical measurement values every 2s + if (!(timeCounter++ % 20)) { // delaying for 100ms x 20 = 2s + uint16_t voltage = 23000 + randomizer; // 230.00 V + uint16_t current = analogReadMilliVolts(analogPin); // demonstrates 0-3.3A + int16_t power = ((voltage / 100) * (current / 1000) * 10); //calculate power in W + uint16_t frequency = 50135; // 50.000 Hz + Serial.printf("Updating AC voltage to %d (0.01V), current to %d (mA), power to %d (0.1W), frequency to %d (mHz)\r\n", voltage, current, power, frequency); + + // Update the measurements + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_A, voltage); + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_A, current); + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_A, power); + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC, frequency); + + // Report the measurements + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC); + + randomizer += 10; + } + + // Checking button for factory reset and reporting + 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(); + } + } + } + delay(100); +} diff --git a/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor/ci.json b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor/ci.json new file mode 100644 index 00000000000..15d6190e4ae --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor/ci.json @@ -0,0 +1,6 @@ +{ + "fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr", + "requires": [ + "CONFIG_ZB_ENABLED=y" + ] +} diff --git a/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase/README.md b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase/README.md new file mode 100644 index 00000000000..3714a05fa4f --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase/README.md @@ -0,0 +1,87 @@ +# Arduino-ESP32 Zigbee AC Electrical MultiPhase Measurement Example + +This example shows how to configure the Zigbee router device and use it as a Home Automation (HA) AC electrical measurement device that reports voltage, current, power, and frequency measurements across three phases. + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## AC Electrical Measurement Functions + + * After this board first starts up, it would be configured locally to report AC electrical measurements: + - AC voltage in volts (0-300.00 V) for each phase (A, B, C) + - AC current in amps (0-10.000 A) for each phase (A, B, C) + - AC power in watts (0-3200.0 W) for each phase (A, B, C) + - AC frequency in hertz (0-65.000 Hz) shared across all phases + * Holding the button (BOOT) for more than 3 seconds will trigger a factory reset of the device. + * The device reports measurements every 2 seconds with simulated values. + +## Measurement Precision + +The example demonstrates how to set up proper measurement precision using multiplier and divisor values: + * Voltage: 1/100 = 0.01 V (1 unit = 10 mV) + * Current: 1/1000 = 0.001 A (1 unit = 1 mA) + * Power: 1/10 = 0.1 W (1 unit = 100 mW) + * Frequency: 1/1000 = 0.001 Hz (1 unit = 1 mHz) + +These settings ensure accurate reporting of measurements with proper decimal precision in the Zigbee network. + +## Hardware Required + +* A USB cable for power supply and programming + +### Configure the Project + +Set the ADC GPIO by changing the `analogPin` variable. By default, it's the pin `A0`. +Set the Button GPIO by changing the `button` variable. By default, it's the pin `BOOT_PIN` (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 Router Zigbee mode: `Tools -> Zigbee mode: Zigbee 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 verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`. + +## Troubleshooting + +If the Router device flashed with this example is not connecting to the coordinator, erase the flash of the Router 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`. +* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack. + +By default, the coordinator network is closed after rebooting or flashing new firmware. +To open the network you have 2 options: + +* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`. +* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join. + +***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/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase/Zigbee_Electrical_AC_Sensor_MultiPhase.ino b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase/Zigbee_Electrical_AC_Sensor_MultiPhase.ino new file mode 100644 index 00000000000..e219113468e --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase/Zigbee_Electrical_AC_Sensor_MultiPhase.ino @@ -0,0 +1,192 @@ +// Copyright 2025 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 Zigbee electrical AC measurement device with multi-phase support. + * + * The example demonstrates how to use Zigbee library to create a router device that measures + * AC electrical parameters like voltage, current, power, power factor and frequency across + * three phases (A, B, C). This allows monitoring of three-phase power systems commonly used + * in industrial and commercial applications. + * + * The device measures: + * - Per phase: voltage, current, power, power factor + * - Shared: frequency (common across all phases) + * + * 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/) + */ + +// Recommended to use Router mode, as this type of device is expected to be mains powered. +#ifndef ZIGBEE_MODE_ZCZR +#error "Zigbee coordinator/router mode is not selected in Tools->Zigbee mode" +#endif + +#include "Zigbee.h" + +/* Zigbee AC measurement device configuration */ +#define AC_ELECTRICAL_MEASUREMENT_ENDPOINT_NUMBER 1 + +uint8_t analogPin = A0; +uint8_t button = BOOT_PIN; + +ZigbeeElectricalMeasurement zbElectricalMeasurement = ZigbeeElectricalMeasurement(AC_ELECTRICAL_MEASUREMENT_ENDPOINT_NUMBER); + +void onAnalogOutputChange(float analog_output) { + Serial.printf("Received analog output change: %.1f\r\n", analog_output); +} + +void setup() { + Serial.begin(115200); + Serial.println("Starting..."); + + // Init button switch + pinMode(button, INPUT_PULLUP); + + // Set analog resolution to 10 bits + analogReadResolution(10); + + // Optional: set Zigbee device name and model + zbElectricalMeasurement.setManufacturerAndModel("Espressif", "ZigbeeElectricalMeasurementAC"); + + // Add analog clusters to Zigbee Analog according your needs + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_A); + + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_B); + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_B); + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_B); + + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_C); + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_C); + zbElectricalMeasurement.addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_C); + + zbElectricalMeasurement.addACMeasurement( + ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC + ); // frequency is not phase specific (shared) + + // Recommended: set Multiplier/Divisor for the measurements (common for all phases) + zbElectricalMeasurement.setACMultiplierDivisor(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, 1, 100); // 1/100 = 0.01V (1 unit of measurement = 0.01V = 10mV) + zbElectricalMeasurement.setACMultiplierDivisor(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, 1, 1000); // 1/1000 = 0.001A (1 unit of measurement = 0.001A = 1mA) + zbElectricalMeasurement.setACMultiplierDivisor(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, 1, 10); // 1/10 = 0.1W (1 unit of measurement = 0.1W = 100mW) + zbElectricalMeasurement.setACMultiplierDivisor(ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, 1, 1000); // 1/1000 = 0.001Hz (1 unit of measurement = 0.001Hz = 1mHz) + + // Optional: set Min/max values for the measurements + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_A, 0, 30000); // 0-300.00V + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_A, 0, 10000); // 0-10.000A + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_A, 0, 32000); // 0-3200.0W + + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_B, 0, 30000); // 0-300.00V + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_B, 0, 10000); // 0-10.000A + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_B, 0, 32000); // 0-3200.0W + + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_C, 0, 30000); // 0-300.00V + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_C, 0, 10000); // 0-10.000A + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_C, 0, 32000); // 0-3200.0W + + zbElectricalMeasurement.setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC, 0, 65000); // 0-65.000Hz + + // Add endpoints to Zigbee Core + Zigbee.addEndpoint(&zbElectricalMeasurement); + + Serial.println("Starting Zigbee..."); + // When all EPs are registered, start Zigbee in Router mode + if (!Zigbee.begin(ZIGBEE_ROUTER)) { + Serial.println("Zigbee failed to start!"); + Serial.println("Rebooting..."); + ESP.restart(); + } else { + Serial.println("Zigbee started successfully!"); + } + Serial.println("Connecting to network"); + while (!Zigbee.connected()) { + Serial.print("."); + delay(100); + } + Serial.println("Connected"); +} + +void loop() { + static uint32_t timeCounter = 0; + static uint8_t randomizer = 0; + // Read ADC value and update the analog value every 2s + if (!(timeCounter++ % 20)) { // delaying for 100ms x 20 = 2s + uint16_t voltage = 23000 + randomizer; // 230.00 V + uint16_t current = analogReadMilliVolts(analogPin); // demonstrates approx 0-3.3A + int16_t power = ((voltage / 100) * (current / 1000) * 10); //calculate power in W + uint16_t frequency = 50135; // 50.000 Hz + Serial.printf("Updating AC voltage to %d (0.01V), current to %d (mA), power to %d (0.1W), frequency to %d (mHz)\r\n", voltage, current, power, frequency); + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_A, voltage); + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_A, current); + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_A, power); + + // Phase B demonstrates phase shift + current += 500; + voltage += 500; + power = ((voltage / 100) * (current / 1000) * 10); //calculate power in W + + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_B, voltage); + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_B, current); + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_B, power); + + // Phase C demonstrates phase shift + current += 500; + voltage += 500; + power = ((voltage / 100) * (current / 1000) * 10); //calculate power in W + + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_C, voltage); + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_C, current); + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_C, power); + + zbElectricalMeasurement.setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC, frequency); + + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_A); + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_A); + + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_B); + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_B); + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_B); + + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE, ZIGBEE_AC_PHASE_TYPE_C); + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT, ZIGBEE_AC_PHASE_TYPE_C); + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_POWER, ZIGBEE_AC_PHASE_TYPE_C); + + zbElectricalMeasurement.reportAC(ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY, ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC); + + randomizer += 10; + } + + // Checking button for factory reset and reporting + 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(); + } + } + } + delay(100); +} diff --git a/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase/ci.json b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase/ci.json new file mode 100644 index 00000000000..15d6190e4ae --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase/ci.json @@ -0,0 +1,6 @@ +{ + "fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr", + "requires": [ + "CONFIG_ZB_ENABLED=y" + ] +} diff --git a/libraries/Zigbee/examples/Zigbee_Electrical_DC_Sensor/README.md b/libraries/Zigbee/examples/Zigbee_Electrical_DC_Sensor/README.md new file mode 100644 index 00000000000..e8922fc1a79 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Electrical_DC_Sensor/README.md @@ -0,0 +1,85 @@ +# Arduino-ESP32 Zigbee DC Electrical Measurement Example + +This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) DC electrical measurement device that reports voltage, current, and power measurements. + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## DC Electrical Measurement Functions + + * After this board first starts up, it would be configured locally to report DC electrical measurements: + - DC voltage in millivolts (0-5000 mV) + - DC current in milliamps (0-1000 mA) + - DC power in milliwatts (0-5000 mW) + * Holding the button (BOOT) for more than 3 seconds will trigger a factory reset of the device. + * The device reports measurements every 30 seconds if the value changes by more than the configured delta. + +## Measurement Precision + +The example demonstrates how to set up proper measurement precision using multiplier and divisor values: + * Voltage: 1/1000 = 0.001 V (1 unit = 1 mV) + * Current: 1/1000 = 0.001 A (1 unit = 1 mA) + * Power: 1/1000 = 0.001 W (1 unit = 1 mW) + +These settings ensure accurate reporting of measurements with proper decimal precision in the Zigbee network. + +## Hardware Required + +* A USB cable for power supply and programming + +### Configure the Project + +Set the ADC GPIO by changing the `analogPin` variable. By default, it's the pin `A0`. +Set the Button GPIO by changing the `button` variable. By default, it's the pin `BOOT_PIN` (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 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. +* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`. + +## Troubleshooting + +If the End device flashed with this example 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`. +* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack. + +By default, the coordinator network is closed after rebooting or flashing new firmware. +To open the network you have 2 options: + +* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`. +* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join. + +***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/libraries/Zigbee/examples/Zigbee_Electrical_DC_Sensor/Zigbee_Electrical_DC_Sensor.ino b/libraries/Zigbee/examples/Zigbee_Electrical_DC_Sensor/Zigbee_Electrical_DC_Sensor.ino new file mode 100644 index 00000000000..4324a7b3ce5 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Electrical_DC_Sensor/Zigbee_Electrical_DC_Sensor.ino @@ -0,0 +1,137 @@ +// Copyright 2025 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 a Zigbee DC electrical measurement sensor. + * + * The example shows how to use the Zigbee library to create an end device that measures + * DC voltage, current and power using the Electrical Measurement cluster. + * + * The device reports: + * - DC voltage in millivolts (0-5000mV) + * - DC current in milliamps (0-1000mA) + * - DC power in milliwatts (0-5000mW) + * + * 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 DC measurement device configuration */ +#define DC_ELECTRICAL_MEASUREMENT_ENDPOINT_NUMBER 1 + +uint8_t analogPin = A0; +uint8_t button = BOOT_PIN; + +ZigbeeElectricalMeasurement zbElectricalMeasurement = ZigbeeElectricalMeasurement(DC_ELECTRICAL_MEASUREMENT_ENDPOINT_NUMBER); + +void setup() { + Serial.begin(115200); + Serial.println("Starting..."); + + // Init button switch + pinMode(button, INPUT_PULLUP); + + // Set analog resolution to 10 bits + analogReadResolution(10); + + // Optional: set Zigbee device name and model + zbElectricalMeasurement.setManufacturerAndModel("Espressif", "ZigbeeElectricalMeasurementDC"); + + // Add analog clusters to Zigbee Analog according your needs + zbElectricalMeasurement.addDCMeasurement(ZIGBEE_DC_MEASUREMENT_TYPE_VOLTAGE); + zbElectricalMeasurement.addDCMeasurement(ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT); + zbElectricalMeasurement.addDCMeasurement(ZIGBEE_DC_MEASUREMENT_TYPE_POWER); + + // // Optional: set Min/max values for the measurements + zbElectricalMeasurement.setDCMinMaxValue(ZIGBEE_DC_MEASUREMENT_TYPE_VOLTAGE, 0, 5000); // 0-5.000V + zbElectricalMeasurement.setDCMinMaxValue(ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT, 0, 1000); // 0-1.000A + zbElectricalMeasurement.setDCMinMaxValue(ZIGBEE_DC_MEASUREMENT_TYPE_POWER, 0, 5000); // 0-5.000W + + // // Optional: set Multiplier/Divisor for the measurements + zbElectricalMeasurement.setDCMultiplierDivisor(ZIGBEE_DC_MEASUREMENT_TYPE_VOLTAGE, 1, 1000); // 1/1000 = 0.001V (1 unit of measurement = 0.001V = 1mV) + zbElectricalMeasurement.setDCMultiplierDivisor(ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT, 1, 1000); // 1/1000 = 0.001A (1 unit of measurement = 0.001A = 1mA) + zbElectricalMeasurement.setDCMultiplierDivisor(ZIGBEE_DC_MEASUREMENT_TYPE_POWER, 1, 1000); // 1/1000 = 0.001W (1 unit of measurement = 0.001W = 1mW) + + // Add endpoints to Zigbee Core + Zigbee.addEndpoint(&zbElectricalMeasurement); + + Serial.println("Starting Zigbee..."); + // When all EPs are registered, start Zigbee in End Device mode + if (!Zigbee.begin()) { + Serial.println("Zigbee failed to start!"); + Serial.println("Rebooting..."); + ESP.restart(); + } else { + Serial.println("Zigbee started successfully!"); + } + Serial.println("Connecting to network"); + while (!Zigbee.connected()) { + Serial.print("."); + delay(100); + } + Serial.println("Connected"); + + // Optional: Add reporting for DC measurements (this is overridden by HomeAssistant ZHA if connected to its network) + zbElectricalMeasurement.setDCReporting(ZIGBEE_DC_MEASUREMENT_TYPE_VOLTAGE, 0, 30, 10); // report every 30 seconds if value changes by 10 (0.1V) + zbElectricalMeasurement.setDCReporting(ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT, 0, 30, 10); // report every 30 seconds if value changes by 10 (0.1A) + zbElectricalMeasurement.setDCReporting(ZIGBEE_DC_MEASUREMENT_TYPE_POWER, 0, 30, 10); // report every 30 seconds if value changes by 10 (0.1W) +} + +void loop() { + static uint32_t timeCounter = 0; + static uint8_t randomizer = 0; + // Read ADC value and update the analog value every 2s + if (!(timeCounter++ % 20)) { // delaying for 100ms x 20 = 2s + int16_t voltage_mv = (int16_t)(analogReadMilliVolts(analogPin)); + int16_t current_ma = randomizer; //0-255mA + int16_t power_mw = voltage_mv * current_ma / 1000; //calculate power in mW + Serial.printf("Updating DC voltage to %d mV, current to %d mA, power to %d mW\r\n", voltage_mv, current_ma, power_mw); + zbElectricalMeasurement.setDCMeasurement(ZIGBEE_DC_MEASUREMENT_TYPE_VOLTAGE, voltage_mv); + zbElectricalMeasurement.setDCMeasurement(ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT, current_ma); + zbElectricalMeasurement.setDCMeasurement(ZIGBEE_DC_MEASUREMENT_TYPE_POWER, power_mw); + // Analog input supports reporting + zbElectricalMeasurement.reportDC(ZIGBEE_DC_MEASUREMENT_TYPE_VOLTAGE); + zbElectricalMeasurement.reportDC(ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT); + zbElectricalMeasurement.reportDC(ZIGBEE_DC_MEASUREMENT_TYPE_POWER); + + randomizer += 10; + } + + // Checking button for factory reset and reporting + 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(); + } + } + } + delay(100); +} diff --git a/libraries/Zigbee/examples/Zigbee_Electrical_DC_Sensor/ci.json b/libraries/Zigbee/examples/Zigbee_Electrical_DC_Sensor/ci.json new file mode 100644 index 00000000000..ceacc367801 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Electrical_DC_Sensor/ci.json @@ -0,0 +1,7 @@ +{ + "fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed", + "requires": [ + "CONFIG_SOC_IEEE802154_SUPPORTED=y", + "CONFIG_ZB_ENABLED=y" + ] +} diff --git a/libraries/Zigbee/examples/Zigbee_On_Off_MultiSwitch/README.md b/libraries/Zigbee/examples/Zigbee_On_Off_MultiSwitch/README.md new file mode 100644 index 00000000000..7ec806a5a62 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_On_Off_MultiSwitch/README.md @@ -0,0 +1,110 @@ +# Arduino-ESP32 Zigbee Multi-Switch Example + +This example demonstrates how to configure a Zigbee device as a multi-switch controller that can control up to three different Zigbee lights independently. The switch can operate in either coordinator or router mode, making it compatible with Home Assistant integration. + +# 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 multi-switch controller +* One or more Zigbee light devices (loaded with Zigbee_On_Off_Light example) +* A USB cable for power supply and programming + +### Configure the Project + +The example uses the BOOT button (pin 9) on ESP32-C6 and ESP32-H2 as the physical switch input. The switch can be configured to operate in two modes: + +1. **Coordinator Mode**: For running your own Zigbee network +2. **Router Mode**: For Home Assistant integration + +#### 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 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 verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose` + +## Features + +The multi-switch example provides the following functionality: + +1. **Light Configuration** + - Configure up to 3 different lights using their endpoint and IEEE address + - Configuration is stored in NVS (Non-Volatile Storage) and persists after power loss + - Remove configured lights when needed + +2. **Control Commands** + - Control all bound lights simultaneously: + - Turn all bound lights ON + - Turn all bound lights OFF + - Toggle all bound lights + - Control individual lights (1-3): + - Turn light ON + - Turn light OFF + - Toggle light + +3. **Network Management** + - Factory reset capability + - Open network for device joining + - View bound devices and current light configurations + +## Serial Commands + +The example accepts the following commands through the serial interface: + +* `config` - Configure a new light (requires light number, endpoint, and IEEE address) +* `remove` - Remove a configured light +* `on` - Turn all bound lights ON +* `off` - Turn all bound lights OFF +* `toggle` - Toggle all bound lights +* `1on`, `2on`, `3on` - Turn individual light ON +* `1off`, `2off`, `3off` - Turn individual light OFF +* `1toggle`, `2toggle`, `3toggle` - Toggle individual light +* `freset` - Perform factory reset +* `open_network` - Open network for device joining (only for coordinator role) + +## Troubleshooting + +If the End device flashed with the example `Zigbee_On_Off_Light` 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_On_Off_Light` example sketch call `Zigbee.factoryReset()` + +By default, the coordinator network is closed after rebooting or flashing new firmware. +To open the network you have 2 options: + +* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time)` before calling `Zigbee.begin()` +* In application you can anytime call `Zigbee.openNetwork(time)` to open the network for devices to join + +***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/libraries/Zigbee/examples/Zigbee_On_Off_MultiSwitch/Zigbee_On_Off_MultiSwitch.ino b/libraries/Zigbee/examples/Zigbee_On_Off_MultiSwitch/Zigbee_On_Off_MultiSwitch.ino new file mode 100644 index 00000000000..63e342b2cd0 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_On_Off_MultiSwitch/Zigbee_On_Off_MultiSwitch.ino @@ -0,0 +1,274 @@ +// Copyright 2025 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 multi-light switch. + * + * The example demonstrates how to use Zigbee library to control multiple light bulbs. + * The light bulbs are Zigbee devices, which are controlled by a Zigbee coordinator/router (Multi-Switch). + * Settings are stored in NVS to not be lost after power loss. + * Configuring and controlling the lights is done via serial input. + * + * 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" +#include + +#define ZIGBEE_ROLE ZIGBEE_ROUTER // ZIGBEE_ROUTER for HomeAssistant integration, ZIGBEE_COORDINATOR for running own network + +/* Zigbee switch configuration */ +#define SWITCH_ENDPOINT_NUMBER 1 + +uint8_t button = BOOT_PIN; + +ZigbeeSwitch zbSwitch = ZigbeeSwitch(SWITCH_ENDPOINT_NUMBER); + +int buttonState; +int lastButtonState = LOW; +unsigned long lastDebounceTime = 0; // the last time the output pin was toggled +unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers + +// To be stored in NVS to not be lost after power loss +Preferences prefs; + +zb_device_params_t light_1; +zb_device_params_t light_2; +zb_device_params_t light_3; + +void storeLightParams(zb_device_params_t *light, int light_number) { + char key[10]; + snprintf(key, sizeof(key), "light_%d", light_number); + prefs.putBytes(key, light, sizeof(zb_device_params_t)); +} + +void loadLightParams(zb_device_params_t *light, int light_number) { + char key[10]; + snprintf(key, sizeof(key), "light_%d", light_number); + prefs.getBytes(key, light, sizeof(zb_device_params_t)); +} + +/********************* Arduino functions **************************/ +void setup() { + Serial.begin(115200); + + // Initialize Preferences + prefs.begin("lights", false); // false means read/write mode + + // Load saved light parameters + loadLightParams(&light_1, 1); + loadLightParams(&light_2, 2); + loadLightParams(&light_3, 3); + + // Init button switch + pinMode(button, INPUT_PULLUP); + + // Set Zigbee device name and model + zbSwitch.setManufacturerAndModel("Espressif", "ZBMultiSwitch"); + + // Set binding settings depending on the role + if (ZIGBEE_ROLE == ZIGBEE_COORDINATOR) { + zbSwitch.allowMultipleBinding(true); // To allow binding multiple lights to the switch + } else { + zbSwitch.setManualBinding(true); //Set manual binding to true, so binding is done on Home Assistant side + } + + // Add endpoint to Zigbee Core + Serial.println("Adding ZigbeeSwitch endpoint to Zigbee Core"); + Zigbee.addEndpoint(&zbSwitch); + + // When all EPs are registered, start Zigbee with given role + if (!Zigbee.begin(ZIGBEE_ROLE)) { + 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() { + // Handle button switch in loop() + if (digitalRead(button) == LOW) { // Push button pressed + // Key debounce handling + while (digitalRead(button) == LOW) { + delay(50); + } + // Print bound devices + Serial.println("Bound devices:"); + zbSwitch.printBoundDevices(Serial); + Serial.println("Lights configured:"); + Serial.printf("Light 1: %d %s\n", light_1.endpoint, Zigbee.formatIEEEAddress(light_1.ieee_addr)); + Serial.printf("Light 2: %d %s\n", light_2.endpoint, Zigbee.formatIEEEAddress(light_2.ieee_addr)); + Serial.printf("Light 3: %d %s\n", light_3.endpoint, Zigbee.formatIEEEAddress(light_3.ieee_addr)); + } + // Handle serial input to configure and control the lights + if (Serial.available()) { + String command = Serial.readString(); + Serial.println("Command: " + command); + + if (command == "config") { + //wait for light number, endpoint and ieee address + Serial.println("Enter light number (1-3):"); + while (!Serial.available()) { + delay(100); + } + int light_number = Serial.parseInt(); + Serial.println("Enter endpoint:"); + while (!Serial.available()) { + delay(100); + } + int endpoint = Serial.parseInt(); + Serial.println("Enter ieee address:"); + while (!Serial.available()) { + delay(100); + } + String ieee_address = Serial.readStringUntil('\n'); + ieee_address.trim(); + //convert ieee address to uint8_t array (format in string is 00:00:00:00:00:00:00:00) + uint8_t ieee_address_array[8]; + int index = 0; + bool valid = true; + + // Check if the string has the correct format (8 hex pairs with colons) + if (ieee_address.length() != 23) { // 8 pairs * 2 + 7 colons + Serial.println("Invalid IEEE address format. Expected format: 00:00:00:00:00:00:00:00"); + valid = false; + } else { + for (int i = 0; i < ieee_address.length() && index < 8 && valid; i += 3) { + // Check for colon at expected positions + if (i > 0 && ieee_address.charAt(i - 1) != ':') { + valid = false; + break; + } + // Convert two hex characters to a byte + char hex[3] = {ieee_address.charAt(i), ieee_address.charAt(i + 1), '\0'}; + char *endptr; + long value = strtol(hex, &endptr, 16); + if (*endptr != '\0' || value < 0 || value > 255) { + valid = false; + break; + } + // Store bytes in reverse order to match Zigbee standard + ieee_address_array[7 - index++] = (uint8_t)value; + } + } + + if (!valid || index != 8) { + Serial.println("Invalid IEEE address. Please enter a valid address in format: 00:00:00:00:00:00:00:00"); + return; + } + //set the light parameters + if (light_number == 1) { + light_1.endpoint = endpoint; + memcpy(light_1.ieee_addr, ieee_address_array, 8); + storeLightParams(&light_1, 1); + } else if (light_number == 2) { + light_2.endpoint = endpoint; + memcpy(light_2.ieee_addr, ieee_address_array, 8); + storeLightParams(&light_2, 2); + } else if (light_number == 3) { + light_3.endpoint = endpoint; + memcpy(light_3.ieee_addr, ieee_address_array, 8); + storeLightParams(&light_3, 3); + } + Serial.printf("Light %d configured\n", light_number); + } else if (command == "remove") { + //wait for light number + Serial.println("Enter light number (1-3):"); + while (!Serial.available()) { + delay(100); + } + int light_number = Serial.parseInt(); + uint8_t ieee_address_empty[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + if (light_number == 1) { + light_1.endpoint = 0; + memcpy(light_1.ieee_addr, ieee_address_empty, 8); + storeLightParams(&light_1, 1); + } else if (light_number == 2) { + light_2.endpoint = 0; + memcpy(light_2.ieee_addr, ieee_address_empty, 8); + storeLightParams(&light_2, 2); + } else if (light_number == 3) { + light_3.endpoint = 0; + memcpy(light_3.ieee_addr, ieee_address_empty, 8); + storeLightParams(&light_3, 3); + } + Serial.printf("Light %d removed\n", light_number); + } else if (command == "on") { + Serial.println(" --> SIG Input : All Lights ON"); + zbSwitch.lightOn(); + } else if (command == "off") { + Serial.println(" --> SIG Input : All Lights OFF"); + zbSwitch.lightOff(); + } else if (command == "toggle") { + Serial.println(" --> SIG Input : All Lights Toggle"); + zbSwitch.lightToggle(); + } else if (command == "1on") { + Serial.println(" --> SIG Input : Light 1 ON"); + zbSwitch.lightOn(light_1.endpoint, light_1.ieee_addr); + } else if (command == "1off") { + Serial.println(" --> SIG Input : Light 1 OFF"); + zbSwitch.lightOff(light_1.endpoint, light_1.ieee_addr); + } else if (command == "1toggle") { + Serial.println(" --> SIG Input : Light 1 Toggle"); + zbSwitch.lightToggle(light_1.endpoint, light_1.ieee_addr); + } else if (command == "2on") { + Serial.println(" --> SIG Input : Light 2 ON"); + zbSwitch.lightOn(light_2.endpoint, light_2.ieee_addr); + } else if (command == "2off") { + Serial.println(" --> SIG Input : Light 2 OFF"); + zbSwitch.lightOff(light_2.endpoint, light_2.ieee_addr); + } else if (command == "2toggle") { + Serial.println(" --> SIG Input : Light 2 Toggle"); + zbSwitch.lightToggle(light_2.endpoint, light_2.ieee_addr); + } else if (command == "3on") { + Serial.println(" --> SIG Input : Light 3 ON"); + zbSwitch.lightOn(light_3.endpoint, light_3.ieee_addr); + } else if (command == "3off") { + Serial.println(" --> SIG Input : Light 3 OFF"); + zbSwitch.lightOff(light_3.endpoint, light_3.ieee_addr); + } else if (command == "3toggle") { + Serial.println(" --> SIG Input : Light 3 Toggle"); + zbSwitch.lightToggle(light_3.endpoint, light_3.ieee_addr); + } else if (command == "freset") { + Serial.println(" --> SIG Input : Factory Reset!"); + delay(1500); + Zigbee.factoryReset(); + } else if (command == "open_network") { + Serial.println(" --> SIG Input : Open Network"); + if (ZIGBEE_ROLE == ZIGBEE_COORDINATOR) { + Zigbee.openNetwork(180); + } else { + Serial.println("Open network is only available for coordinator role"); + } + } else { + Serial.println("Unknown command"); + } + } +} diff --git a/libraries/Zigbee/examples/Zigbee_On_Off_MultiSwitch/ci.json b/libraries/Zigbee/examples/Zigbee_On_Off_MultiSwitch/ci.json new file mode 100644 index 00000000000..e79a477da11 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_On_Off_MultiSwitch/ci.json @@ -0,0 +1,6 @@ +{ + "fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr", + "requires": [ + "CONFIG_SOC_IEEE802154_SUPPORTED=y" + ] +} diff --git a/libraries/Zigbee/examples/Zigbee_PM25_Sensor/README.md b/libraries/Zigbee/examples/Zigbee_PM25_Sensor/README.md new file mode 100644 index 00000000000..51bf11459b7 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_PM25_Sensor/README.md @@ -0,0 +1,72 @@ +# Arduino-ESP32 PM2.5 Sensor + +This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) simple sensor device type with particulate matter (PM2.5) measuring + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## Pressure + Flow Sensor Functions + + * After this board first starts up, it would be configured locally to report the PM2.5 on every 30 seconds. + * By clicking the button (BOOT) on this board, this board will immediately send a report of the current PM2.5 to the network. + +## Hardware Required + +* A USB cable for power supply and programming + +### Configure the Project + +In this example, the internal temperature sensor is used to demonstrate reading of the PM2.5 sensors. +Set the Button GPIO by changing the `button` variable. By default, it's the pin `BOOT_PIN` (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 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. +* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`. + +## Troubleshooting + +If the End device flashed with this example 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`. +* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack. + +By default, the coordinator network is closed after rebooting or flashing new firmware. +To open the network you have 2 options: + +* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`. +* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join. + +***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/libraries/Zigbee/examples/Zigbee_PM25_Sensor/Zigbee_PM25_Sensor.ino b/libraries/Zigbee/examples/Zigbee_PM25_Sensor/Zigbee_PM25_Sensor.ino new file mode 100644 index 00000000000..a98d697f700 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_PM25_Sensor/Zigbee_PM25_Sensor.ino @@ -0,0 +1,109 @@ +// 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 Zigbee PM2.5 sensor. + * + * The example demonstrates how to use Zigbee library to create a end device PM2.5 sensor. + * + * 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 PM2.5 sensor configuration */ +#define PM2_5_SENSOR_ENDPOINT_NUMBER 1 +uint8_t button = BOOT_PIN; + +ZigbeePM25Sensor zbPM25Sensor = ZigbeePM25Sensor(PM2_5_SENSOR_ENDPOINT_NUMBER); + +void setup() { + Serial.begin(115200); + + // Init button switch + pinMode(button, INPUT_PULLUP); + + // Optional: set Zigbee device name and model + zbPM25Sensor.setManufacturerAndModel("Espressif", "ZigbeePM25Sensor"); + + // Set minimum and maximum PM2.5 measurement value in µg/m³ + zbPM25Sensor.setMinMaxValue(0, 350); + + // Set tolerance for PM2.5 measurement in µg/m³ + zbPM25Sensor.setTolerance(0.1); + + // Add endpoints to Zigbee Core + Zigbee.addEndpoint(&zbPM25Sensor); + + Serial.println("Starting Zigbee..."); + // When all EPs are registered, start Zigbee in End Device mode + if (!Zigbee.begin()) { + Serial.println("Zigbee failed to start!"); + Serial.println("Rebooting..."); + ESP.restart(); + } else { + Serial.println("Zigbee started successfully!"); + } + Serial.println("Connecting to network"); + while (!Zigbee.connected()) { + Serial.print("."); + delay(100); + } + Serial.println(); + + // Set reporting interval for PM2.5 measurement to be done every 30 seconds, must be called after Zigbee.begin() + // min_interval and max_interval in seconds, delta (PM2.5 change in µg/m³) + // if min = 1 and max = 0, reporting is sent only when PM2.5 changes by delta + // if min = 0 and max = 10, reporting is sent every 10 seconds or when PM2.5 changes by delta + // if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of delta change + zbPM25Sensor.setReporting(0, 30, 0); +} + +void loop() { + static uint32_t timeCounter = 0; + // Read PM2.5 sensor every 2s + if (!(timeCounter++ % 20)) { // delaying for 100ms x 20 = 2s + // Read sensor value - here is chip temperature used + 50 as a dummy value for demonstration + float pm25_value = 50.5 + temperatureRead(); + Serial.printf("Updating PM2.5 sensor value to %0.1f µg/m³\r\n", pm25_value); + zbPM25Sensor.setPM25(pm25_value); + } + + // Checking button for factory reset and reporting + 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(); + } + } + zbPM25Sensor.report(); + } + delay(100); +} diff --git a/libraries/Zigbee/examples/Zigbee_PM25_Sensor/ci.json b/libraries/Zigbee/examples/Zigbee_PM25_Sensor/ci.json new file mode 100644 index 00000000000..ceacc367801 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_PM25_Sensor/ci.json @@ -0,0 +1,7 @@ +{ + "fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed", + "requires": [ + "CONFIG_SOC_IEEE802154_SUPPORTED=y", + "CONFIG_ZB_ENABLED=y" + ] +} diff --git a/libraries/Zigbee/examples/Zigbee_Power_Outlet/README.md b/libraries/Zigbee/examples/Zigbee_Power_Outlet/README.md new file mode 100644 index 00000000000..996aa36d1a3 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Power_Outlet/README.md @@ -0,0 +1,61 @@ +@ -0,0 +1,68 @@ +# Arduino-ESP32 Zigbee On/Off Power Outlet Example + +This example shows how to configure Zigbee Router device and use it as a Home Automation (HA) on/off power outlet. + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## Hardware Required + +* A USB cable for power supply and programming. + +### Configure the Project + +Set the Button GPIO by changing the `button` 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 ZCZR 4MB with spiffs`. +* Select the COM port: `Tools -> Port: xxx where the `xxx` is the detected COM port. +* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`. + +## Troubleshooting + +If the device flashed with the example `Zigbee_Power_Outlet` is not connecting to the coordinator, erase the flash of the device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator or do some big changes in the application code. +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_Power_Outlet` example sketch call `Zigbee.factoryReset();`. + +***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/libraries/Zigbee/examples/Zigbee_Power_Outlet/Zigbee_Power_Outlet.ino b/libraries/Zigbee/examples/Zigbee_Power_Outlet/Zigbee_Power_Outlet.ino new file mode 100644 index 00000000000..d9fe1b7aefe --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Power_Outlet/Zigbee_Power_Outlet.ino @@ -0,0 +1,101 @@ +// Copyright 2025 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 power outlet. + * + * The example demonstrates how to use Zigbee library to create a end device power outlet. + * The power outlet 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 Ludovic Boué (https://github.com/lboue) + */ + +#ifndef ZIGBEE_MODE_ZCZR +#error "Zigbee router mode is not selected in Tools->Zigbee mode" +#endif + +#include "Zigbee.h" + +/* Zigbee power outlet configuration */ +#define ZIGBEE_OUTLET_ENDPOINT 1 +uint8_t led = RGB_BUILTIN; +uint8_t button = BOOT_PIN; + +ZigbeePowerOutlet zbOutlet = ZigbeePowerOutlet(ZIGBEE_OUTLET_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 + zbOutlet.setManufacturerAndModel("Espressif", "ZBPowerOutlet"); + + // Set callback function for power outlet change + zbOutlet.onPowerOutletChange(setLED); + + //Add endpoint to Zigbee Core + Serial.println("Adding ZigbeePowerOutlet endpoint to Zigbee Core"); + Zigbee.addEndpoint(&zbOutlet); + + // When all EPs are registered, start Zigbee. By default acts as ZIGBEE_END_DEVICE + if (!Zigbee.begin(ZIGBEE_ROUTER)) { + 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 state by pressing the button + zbOutlet.setState(!zbOutlet.getPowerOutletState()); + } + delay(100); +} diff --git a/libraries/Zigbee/examples/Zigbee_Power_Outlet/ci.json b/libraries/Zigbee/examples/Zigbee_Power_Outlet/ci.json new file mode 100644 index 00000000000..23decd7127c --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Power_Outlet/ci.json @@ -0,0 +1,7 @@ +{ + "fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr", + "requires": [ + "CONFIG_SOC_IEEE802154_SUPPORTED=y", + "CONFIG_ZB_ENABLED=y" + ] +} diff --git a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino index 3eefd973dd2..e9d08d32175 100644 --- a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino +++ b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino @@ -85,9 +85,9 @@ void setup() { // Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C) zbTempSensor.setTolerance(1); - // Set power source to battery and set battery percentage to measured value (now 100% for demonstration) - // The value can be also updated by calling zbTempSensor.setBatteryPercentage(percentage) anytime - zbTempSensor.setPowerSource(ZB_POWER_SOURCE_BATTERY, 100); + // Set power source to battery, battery percentage and battery voltage (now 100% and 3.5V for demonstration) + // The value can be also updated by calling zbTempSensor.setBatteryPercentage(percentage) or zbTempSensor.setBatteryVoltage(voltage) anytime after Zigbee.begin() + zbTempSensor.setPowerSource(ZB_POWER_SOURCE_BATTERY, 100, 35); // Add humidity cluster to the temperature sensor device with min, max and tolerance values zbTempSensor.addHumiditySensor(0, 100, 1); diff --git a/libraries/Zigbee/examples/Zigbee_Thermostat/Zigbee_Thermostat.ino b/libraries/Zigbee/examples/Zigbee_Thermostat/Zigbee_Thermostat.ino index 7cdf45ef711..6f5934f791d 100644 --- a/libraries/Zigbee/examples/Zigbee_Thermostat/Zigbee_Thermostat.ino +++ b/libraries/Zigbee/examples/Zigbee_Thermostat/Zigbee_Thermostat.ino @@ -34,7 +34,8 @@ #include "Zigbee.h" /* Zigbee thermostat configuration */ -#define THERMOSTAT_ENDPOINT_NUMBER 5 +#define THERMOSTAT_ENDPOINT_NUMBER 1 +#define USE_RECEIVE_TEMP_WITH_SOURCE 1 uint8_t button = BOOT_PIN; ZigbeeThermostat zbThermostat = ZigbeeThermostat(THERMOSTAT_ENDPOINT_NUMBER); @@ -48,13 +49,28 @@ float sensor_tolerance; struct tm timeinfo = {}; // Time structure for Time cluster /****************** Temperature sensor handling *******************/ -void recieveSensorTemp(float temperature) { +#if USE_RECEIVE_TEMP_WITH_SOURCE == 0 +void receiveSensorTemp(float temperature) { Serial.printf("Temperature sensor value: %.2f°C\n", temperature); sensor_temp = temperature; } +#else +void receiveSensorTempWithSource(float temperature, uint8_t src_endpoint, esp_zb_zcl_addr_t src_address) { + if (src_address.addr_type == ESP_ZB_ZCL_ADDR_TYPE_SHORT) { + Serial.printf("Temperature sensor value: %.2f°C from endpoint %d, address 0x%04x\n", temperature, src_endpoint, src_address.u.short_addr); + } else { + Serial.printf( + "Temperature sensor value: %.2f°C from endpoint %d, address %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", temperature, src_endpoint, + src_address.u.ieee_addr[7], src_address.u.ieee_addr[6], src_address.u.ieee_addr[5], src_address.u.ieee_addr[4], src_address.u.ieee_addr[3], + src_address.u.ieee_addr[2], src_address.u.ieee_addr[1], src_address.u.ieee_addr[0] + ); + } + sensor_temp = temperature; +} +#endif -void recieveSensorConfig(float min_temp, float max_temp, float tolerance) { - Serial.printf("Temperature sensor settings: min %.2f°C, max %.2f°C, tolerance %.2f°C\n", min_temp, max_temp, tolerance); +void receiveSensorConfig(float min_temp, float max_temp, float tolerance) { + Serial.printf("Temperature sensor config: min %.2f°C, max %.2f°C, tolerance %.2f°C\n", min_temp, max_temp, tolerance); sensor_min_temp = min_temp; sensor_max_temp = max_temp; sensor_tolerance = tolerance; @@ -66,9 +82,15 @@ void setup() { // Init button switch pinMode(button, INPUT_PULLUP); - // Set callback functions for temperature and configuration receive - zbThermostat.onTempRecieve(recieveSensorTemp); - zbThermostat.onConfigRecieve(recieveSensorConfig); +// Set callback function for receiving temperature from sensor - Use only one option +#if USE_RECEIVE_TEMP_WITH_SOURCE == 0 + zbThermostat.onTempReceive(receiveSensorTemp); // If you bound only one sensor or you don't need to know the source of the temperature +#else + zbThermostat.onTempReceiveWithSource(receiveSensorTempWithSource); +#endif + + // Set callback function for receiving sensor configuration + zbThermostat.onConfigReceive(receiveSensorConfig); //Optional: set Zigbee device name and model zbThermostat.setManufacturerAndModel("Espressif", "ZigbeeThermostat"); @@ -107,19 +129,30 @@ void setup() { Serial.println(); - // Get temperature sensor configuration - zbThermostat.getSensorSettings(); + // Get temperature sensor configuration for all bound sensors by endpoint number and address + std::list boundSensors = zbThermostat.getBoundDevices(); + for (const auto &device : boundSensors) { + Serial.println("--------------------------------"); + if (device->short_addr == 0x0000 || device->short_addr == 0xFFFF) { //End devices never have 0x0000 short address or 0xFFFF group address + Serial.printf( + "Device on endpoint %d, IEEE Address: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\r\n", device->endpoint, 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] + ); + zbThermostat.getSensorSettings(device->endpoint, device->ieee_addr); + } else { + Serial.printf("Device on endpoint %d, short address: 0x%x\r\n", device->endpoint, device->short_addr); + zbThermostat.getSensorSettings(device->endpoint, device->short_addr); + } + } } void loop() { // Handle button switch in loop() if (digitalRead(button) == LOW) { // Push button pressed - // Key debounce handling while (digitalRead(button) == LOW) { delay(50); } - // Set reporting interval for temperature sensor zbThermostat.setTemperatureReporting(0, 10, 2); } @@ -130,5 +163,6 @@ void loop() { last_print = millis(); int temp_percent = (int)((sensor_temp - sensor_min_temp) / (sensor_max_temp - sensor_min_temp) * 100); Serial.printf("Loop temperature info: %.2f°C (%d %%)\n", sensor_temp, temp_percent); + zbThermostat.printBoundDevices(Serial); } } diff --git a/libraries/Zigbee/keywords.txt b/libraries/Zigbee/keywords.txt index 586d2bdc677..556b6408ea2 100644 --- a/libraries/Zigbee/keywords.txt +++ b/libraries/Zigbee/keywords.txt @@ -30,6 +30,7 @@ ZigbeeRangeExtender KEYWORD1 ZigbeeVibrationSensor KEYWORD1 ZigbeeWindowCovering KEYWORD1 ZigbeeIlluminanceSensor KEYWORD1 +ZigbeePowerOutlet KEYWORD1 # Other zigbee_role_t KEYWORD1 @@ -106,6 +107,7 @@ setLightColor KEYWORD2 # ZigbeeThermostat onTempRecieve KEYWORD2 onConfigRecieve KEYWORD2 +onTempReceiveWithSource KEYWORD2 getTemperature KEYWORD2 getSensorSettings KEYWORD2 setTemperatureReporting KEYWORD2 @@ -141,14 +143,21 @@ setSensorType KEYWORD2 setCarbonDioxide KEYWORD2 # ZigbeeAnalog -addAnalogValue KEYWORD2 addAnalogInput KEYWORD2 addAnalogOutput KEYWORD2 onAnalogOutputChange KEYWORD2 -setAnalogValue KEYWORD2 setAnalogInput KEYWORD2 +setAnalogOutput KEYWORD2 +getAnalogOutput KEYWORD2 reportAnalogInput KEYWORD2 +reportAnalogOutput KEYWORD2 setAnalogInputReporting KEYWORD2 +setAnalogInputApplication KEYWORD2 +setAnalogInputDescription KEYWORD2 +setAnalogInputResolution KEYWORD2 +setAnalogOutputApplication KEYWORD2 +setAnalogOutputDescription KEYWORD2 +setAnalogOutputResolution KEYWORD2 # ZigbeeCarbonDioxideSensor setCarbonDioxide KEYWORD2 @@ -190,4 +199,4 @@ ZIGBEE_DEFAULT_COORDINATOR_CONFIG LITERAL1 ZIGBEE_DEFAULT_RADIO_CONFIG LITERAL1 ZIGBEE_DEFAULT_UART_RCP_RADIO_CONFIG LITERAL1 ZIGBEE_DEFAULT_HOST_CONFIG LITERAL1 -ZB_ARRAY_LENTH LITERAL1 +ZB_ARRAY_LENGHT LITERAL1 diff --git a/libraries/Zigbee/src/Zigbee.h b/libraries/Zigbee/src/Zigbee.h index ea42e9dd41a..b2e2e5dd027 100644 --- a/libraries/Zigbee/src/Zigbee.h +++ b/libraries/Zigbee/src/Zigbee.h @@ -7,23 +7,33 @@ #include "ZigbeeEP.h" // Endpoints -#include "ep/ZigbeeLight.h" +//// Switches +#include "ep/ZigbeeColorDimmerSwitch.h" #include "ep/ZigbeeSwitch.h" -#include "ep/ZigbeeDimmableLight.h" +//// Lights #include "ep/ZigbeeColorDimmableLight.h" -#include "ep/ZigbeeColorDimmerSwitch.h" -#include "ep/ZigbeeTempSensor.h" +#include "ep/ZigbeeDimmableLight.h" +#include "ep/ZigbeeLight.h" +//// Controllers #include "ep/ZigbeeThermostat.h" -#include "ep/ZigbeePressureSensor.h" +////Outlets +#include "ep/ZigbeePowerOutlet.h" +//// Sensors #include "ep/ZigbeeAnalog.h" -#include "ep/ZigbeeFlowSensor.h" -#include "ep/ZigbeeOccupancySensor.h" -#include "ep/ZigbeeIlluminanceSensor.h" +#include "ep/ZigbeeBinary.h" #include "ep/ZigbeeCarbonDioxideSensor.h" #include "ep/ZigbeeContactSwitch.h" #include "ep/ZigbeeDoorWindowHandle.h" -#include "ep/ZigbeeWindowCovering.h" +#include "ep/ZigbeeElectricalMeasurement.h" +#include "ep/ZigbeeFlowSensor.h" +#include "ep/ZigbeeIlluminanceSensor.h" +#include "ep/ZigbeeOccupancySensor.h" +#include "ep/ZigbeePM25Sensor.h" +#include "ep/ZigbeePressureSensor.h" +#include "ep/ZigbeeTempSensor.h" #include "ep/ZigbeeVibrationSensor.h" -#include "ep/ZigbeeRangeExtender.h" -#include "ep/ZigbeeGateway.h" #include "ep/ZigbeeWindSpeedSensor.h" +#include "ep/ZigbeeWindowCovering.h" +//// Other +#include "ep/ZigbeeGateway.h" +#include "ep/ZigbeeRangeExtender.h" diff --git a/libraries/Zigbee/src/ZigbeeCore.cpp b/libraries/Zigbee/src/ZigbeeCore.cpp index b93542159a6..c49dedb221f 100644 --- a/libraries/Zigbee/src/ZigbeeCore.cpp +++ b/libraries/Zigbee/src/ZigbeeCore.cpp @@ -5,6 +5,7 @@ #include "ZigbeeHandlers.cpp" #include "Arduino.h" +#include #ifdef __cplusplus extern "C" { @@ -30,6 +31,7 @@ ZigbeeCore::ZigbeeCore() { _connected = false; _scan_duration = 3; // default scan duration _rx_on_when_idle = true; + _debug = false; if (!lock) { lock = xSemaphoreCreateBinary(); if (lock == NULL) { @@ -40,6 +42,7 @@ ZigbeeCore::ZigbeeCore() { //forward declaration static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message); +bool zb_apsde_data_indication_handler(esp_zb_apsde_data_ind_t ind); bool ZigbeeCore::begin(esp_zb_cfg_t *role_cfg, bool erase_nvs) { if (!zigbeeInit(role_cfg, erase_nvs)) { @@ -173,6 +176,9 @@ bool ZigbeeCore::zigbeeInit(esp_zb_cfg_t *zb_cfg, bool erase_nvs) { return false; } + // Register APSDATA INDICATION handler to catch bind/unbind requests + esp_zb_aps_data_indication_handler_register(zb_apsde_data_indication_handler); + //Erase NVRAM before creating connection to new Coordinator if (erase_nvs) { esp_zb_nvram_erase_at_start(true); @@ -223,6 +229,13 @@ void ZigbeeCore::openNetwork(uint8_t time) { } } +void ZigbeeCore::closeNetwork() { + if (started()) { + log_v("Closing network"); + esp_zb_bdb_close_network(); + } +} + static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) { ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); } @@ -234,6 +247,9 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { esp_zb_app_signal_type_t sig_type = (esp_zb_app_signal_type_t)*p_sg_p; //coordinator variables esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL; + esp_zb_zdo_signal_leave_params_t *leave_params = NULL; + //router variables + esp_zb_zdo_signal_device_update_params_t *dev_update_params = NULL; //main switch switch (sig_type) { @@ -267,7 +283,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { } else { // Save the channel mask to NVRAM in case of reboot which may be on a different channel after a change in the network Zigbee.setNVRAMChannelMask(1 << esp_zb_get_current_channel()); - Zigbee._connected = true; + Zigbee._connected = true; // Coordinator is always connected } Zigbee.searchBindings(); } @@ -287,6 +303,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0], esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address() ); + Zigbee._connected = true; esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); } else { log_i("Restart network formation (status: %s)", esp_err_to_name(err_status)); @@ -340,20 +357,60 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { */ // for each endpoint in the list call the findEndpoint function if not bounded or allowed to bind multiple devices for (std::list::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) { - if (!(*it)->bound() || (*it)->epAllowMultipleBinding()) { - // Check if the device is already bound - bool found = false; - // Get the list of devices bound to the EP - std::list bound_devices = (*it)->getBoundDevices(); - for (std::list::iterator device = bound_devices.begin(); device != bound_devices.end(); ++device) { - if (((*device)->short_addr == dev_annce_params->device_short_addr) || (memcmp((*device)->ieee_addr, dev_annce_params->ieee_addr, 8) == 0)) { - found = true; - log_d("Device already bound to endpoint %d", (*it)->getEndpoint()); - break; + log_d("Checking endpoint %d", (*it)->getEndpoint()); + if (!(*it)->epUseManualBinding()) { + if (!(*it)->bound() || (*it)->epAllowMultipleBinding()) { + // Check if the device is already bound + bool found = false; + // Get the list of devices bound to the EP + std::list bound_devices = (*it)->getBoundDevices(); + for (std::list::iterator device = bound_devices.begin(); device != bound_devices.end(); ++device) { + if (((*device)->short_addr == dev_annce_params->device_short_addr) || (memcmp((*device)->ieee_addr, dev_annce_params->ieee_addr, 8) == 0)) { + found = true; + log_d("Device already bound to endpoint %d", (*it)->getEndpoint()); + break; + } + } + if (!found) { + log_d("Device not bound to endpoint %d and it is free to bound!", (*it)->getEndpoint()); + (*it)->findEndpoint(&cmd_req); + log_d("Endpoint %d is searching for device", (*it)->getEndpoint()); + break; // Only one endpoint per device } } - if (!found) { - (*it)->findEndpoint(&cmd_req); + } + } + } + break; + case ESP_ZB_ZDO_SIGNAL_DEVICE_UPDATE: // Router + if ((zigbee_role_t)Zigbee.getRole() == ZIGBEE_ROUTER) { + dev_update_params = (esp_zb_zdo_signal_device_update_params_t *)esp_zb_app_signal_get_params(p_sg_p); + log_i("New device commissioned or rejoined (short: 0x%04hx)", dev_update_params->short_addr); + esp_zb_zdo_match_desc_req_param_t cmd_req; + cmd_req.dst_nwk_addr = dev_update_params->short_addr; + cmd_req.addr_of_interest = dev_update_params->short_addr; + // for each endpoint in the list call the findEndpoint function if not bounded or allowed to bind multiple devices + for (std::list::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) { + log_d("Checking endpoint %d", (*it)->getEndpoint()); + if (!(*it)->epUseManualBinding()) { + if (!(*it)->bound() || (*it)->epAllowMultipleBinding()) { + // Check if the device is already bound + bool found = false; + // Get the list of devices bound to the EP + std::list bound_devices = (*it)->getBoundDevices(); + for (std::list::iterator device = bound_devices.begin(); device != bound_devices.end(); ++device) { + if (((*device)->short_addr == dev_update_params->short_addr) || (memcmp((*device)->ieee_addr, dev_update_params->long_addr, 8) == 0)) { + found = true; + log_d("Device already bound to endpoint %d", (*it)->getEndpoint()); + break; + } + } + log_d("Device not bound to endpoint %d and it is free to bound!", (*it)->getEndpoint()); + if (!found) { + (*it)->findEndpoint(&cmd_req); + log_d("Endpoint %d is searching for device", (*it)->getEndpoint()); + break; // Only one endpoint per device + } } } } @@ -371,15 +428,47 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { } break; case ESP_ZB_ZDO_SIGNAL_LEAVE: // End Device + Router - // Device was removed from the network, factory reset the device + // Received signal to leave the network if ((zigbee_role_t)Zigbee.getRole() != ZIGBEE_COORDINATOR) { - Zigbee.factoryReset(true); + leave_params = (esp_zb_zdo_signal_leave_params_t *)esp_zb_app_signal_get_params(p_sg_p); + log_v("Signal to leave the network, leave type: %d", leave_params->leave_type); + if (leave_params->leave_type == ESP_ZB_NWK_LEAVE_TYPE_RESET) { // Leave without rejoin -> Factory reset + log_i("Leave without rejoin, factory reset the device"); + Zigbee.factoryReset(true); + } else { // Leave with rejoin -> Rejoin the network, only reboot the device + log_i("Leave with rejoin, only reboot the device"); + ESP.restart(); + } } break; default: log_v("ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, esp_err_to_name(err_status)); break; } } +// APS DATA INDICATION HANDLER to catch bind/unbind requests +bool zb_apsde_data_indication_handler(esp_zb_apsde_data_ind_t ind) { + if (Zigbee.getDebugMode()) { + log_d("APSDE INDICATION - Received APSDE-DATA indication, status: %d", ind.status); + log_d( + "APSDE INDICATION - dst_endpoint: %d, src_endpoint: %d, dst_addr_mode: %d, src_addr_mode: %d, cluster_id: 0x%04x, asdu_length: %d", ind.dst_endpoint, + ind.src_endpoint, ind.dst_addr_mode, ind.src_addr_mode, ind.cluster_id, ind.asdu_length + ); + log_d( + "APSDE INDICATION - dst_short_addr: 0x%04x, src_short_addr: 0x%04x, profile_id: 0x%04x, security_status: %d, lqi: %d, rx_time: %d", ind.dst_short_addr, + ind.src_short_addr, ind.profile_id, ind.security_status, ind.lqi, ind.rx_time + ); + } + if (ind.status == 0x00) { + // Catch bind/unbind requests to update the bound devices list + if (ind.cluster_id == 0x21 || ind.cluster_id == 0x22) { + Zigbee.searchBindings(); + } + } else { + log_e("APSDE INDICATION - Invalid status of APSDE-DATA indication, error code: %d", ind.status); + } + return false; //False to let the stack process the message as usual +} + void ZigbeeCore::factoryReset(bool restart) { if (restart) { log_v("Factory resetting Zigbee stack, device will reboot"); @@ -444,63 +533,194 @@ void ZigbeeCore::scanDelete() { _scan_status = ZB_SCAN_FAILED; } -// Recall bounded devices from the binding table after reboot +// Recall bounded devices from the binding table after reboot or when requested void ZigbeeCore::bindingTableCb(const esp_zb_zdo_binding_table_info_t *table_info, void *user_ctx) { - bool done = true; esp_zb_zdo_mgmt_bind_param_t *req = (esp_zb_zdo_mgmt_bind_param_t *)user_ctx; esp_zb_zdp_status_t zdo_status = (esp_zb_zdp_status_t)table_info->status; log_d("Binding table callback for address 0x%04x with status %d", req->dst_addr, zdo_status); + if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { // Print binding table log simple log_d("Binding table info: total %d, index %d, count %d", table_info->total, table_info->index, table_info->count); if (table_info->total == 0) { log_d("No binding table entries found"); + // Clear all bound devices since there are no entries + for (std::list::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) { + log_d("Clearing bound devices for EP %d", (*it)->getEndpoint()); + (*it)->clearBoundDevices(); + } free(req); return; } + // Create a set to track found devices using both short and IEEE addresses + struct DeviceIdentifier { + uint8_t endpoint; + uint16_t short_addr; + esp_zb_ieee_addr_t ieee_addr; + bool is_ieee; + + bool operator<(const DeviceIdentifier &other) const { + if (endpoint != other.endpoint) { + return endpoint < other.endpoint; + } + if (is_ieee != other.is_ieee) { + return is_ieee < other.is_ieee; + } + if (is_ieee) { + return memcmp(ieee_addr, other.ieee_addr, sizeof(esp_zb_ieee_addr_t)) < 0; + } + return short_addr < other.short_addr; + } + }; + static std::set found_devices; + static std::vector all_records; + + // If this is the first chunk (index 0), clear the previous data + if (table_info->index == 0) { + found_devices.clear(); + all_records.clear(); + } + + // Add current records to our collection esp_zb_zdo_binding_table_record_t *record = table_info->record; for (int i = 0; i < table_info->count; i++) { log_d( - "Binding table record: src_endp %d, dst_endp %d, cluster_id 0x%04x, dst_addr_mode %d", record->src_endp, record->dst_endp, record->cluster_id, + "Processing record %d: src_endp %d, dst_endp %d, cluster_id 0x%04x, dst_addr_mode %d", i, record->src_endp, record->dst_endp, record->cluster_id, record->dst_addr_mode ); + all_records.push_back(*record); + record = record->next; + } - zb_device_params_t *device = (zb_device_params_t *)calloc(1, sizeof(zb_device_params_t)); - device->endpoint = record->dst_endp; - if (record->dst_addr_mode == ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT || record->dst_addr_mode == ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT) { - device->short_addr = record->dst_address.addr_short; - } else { //ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT - memcpy(device->ieee_addr, record->dst_address.addr_long, sizeof(esp_zb_ieee_addr_t)); + // If this is not the last chunk, request the next one + if (table_info->index + table_info->count < table_info->total) { + log_d("Requesting next chunk of binding table (current index: %d, count: %d, total: %d)", table_info->index, table_info->count, table_info->total); + req->start_index = table_info->index + table_info->count; + esp_zb_zdo_binding_table_req(req, bindingTableCb, req); + } else { + // This is the last chunk, process all records + log_d("Processing final chunk of binding table, total records: %d", all_records.size()); + for (const auto &record : all_records) { + + DeviceIdentifier dev_id; + dev_id.endpoint = record.src_endp; + dev_id.is_ieee = (record.dst_addr_mode == ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT); + + if (dev_id.is_ieee) { + memcpy(dev_id.ieee_addr, record.dst_address.addr_long, sizeof(esp_zb_ieee_addr_t)); + dev_id.short_addr = 0xFFFF; // Invalid short address + } else { + dev_id.short_addr = record.dst_address.addr_short; + memset(dev_id.ieee_addr, 0, sizeof(esp_zb_ieee_addr_t)); + } + + // Track this device as found + found_devices.insert(dev_id); } - // Add to list of bound devices of proper endpoint + // Now process each endpoint and update its bound devices for (std::list::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) { - if ((*it)->getEndpoint() == record->src_endp) { - (*it)->addBoundDevice(device); - log_d( - "Device bound to EP %d -> device endpoint: %d, short addr: 0x%04x, ieee addr: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", record->src_endp, - device->endpoint, device->short_addr, 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] - ); + log_d("Processing endpoint %d", (*it)->getEndpoint()); + std::list bound_devices = (*it)->getBoundDevices(); + std::list devices_to_remove; + + // First, identify devices that need to be removed + for (std::list::iterator dev_it = bound_devices.begin(); dev_it != bound_devices.end(); ++dev_it) { + DeviceIdentifier dev_id; + dev_id.endpoint = (*it)->getEndpoint(); + + // Create both short and IEEE address identifiers for the device + bool found = false; + + // Check if device exists with short address + if ((*dev_it)->short_addr != 0xFFFF) { + dev_id.is_ieee = false; + dev_id.short_addr = (*dev_it)->short_addr; + memset(dev_id.ieee_addr, 0, sizeof(esp_zb_ieee_addr_t)); + if (found_devices.find(dev_id) != found_devices.end()) { + found = true; + } + } + + // Check if device exists with IEEE address + if (!found) { + dev_id.is_ieee = true; + memcpy(dev_id.ieee_addr, (*dev_it)->ieee_addr, sizeof(esp_zb_ieee_addr_t)); + dev_id.short_addr = 0xFFFF; + if (found_devices.find(dev_id) != found_devices.end()) { + found = true; + } + } + + if (!found) { + devices_to_remove.push_back(*dev_it); + } + } + + // Remove devices that are no longer in the binding table + for (std::list::iterator dev_it = devices_to_remove.begin(); dev_it != devices_to_remove.end(); ++dev_it) { + (*it)->removeBoundDevice(*dev_it); + free(*dev_it); + } + + // Now add new devices from the binding table + for (const auto &record : all_records) { + if (record.src_endp == (*it)->getEndpoint()) { + log_d("Processing binding record for EP %d", record.src_endp); + zb_device_params_t *device = (zb_device_params_t *)calloc(1, sizeof(zb_device_params_t)); + if (!device) { + log_e("Failed to allocate memory for device params"); + continue; + } + device->endpoint = record.dst_endp; + + bool is_ieee = (record.dst_addr_mode == ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT); + if (is_ieee) { + memcpy(device->ieee_addr, record.dst_address.addr_long, sizeof(esp_zb_ieee_addr_t)); + device->short_addr = 0xFFFF; + } else { + device->short_addr = record.dst_address.addr_short; + memset(device->ieee_addr, 0, sizeof(esp_zb_ieee_addr_t)); + } + + // Check if device already exists + bool device_exists = false; + for (std::list::iterator dev_it = bound_devices.begin(); dev_it != bound_devices.end(); ++dev_it) { + if (is_ieee) { + if (memcmp((*dev_it)->ieee_addr, device->ieee_addr, sizeof(esp_zb_ieee_addr_t)) == 0) { + device_exists = true; + break; + } + } else { + if ((*dev_it)->short_addr == device->short_addr) { + device_exists = true; + break; + } + } + } + + if (!device_exists) { + (*it)->addBoundDevice(device); + log_d( + "Device bound to EP %d -> device endpoint: %d, %s: %s", record.src_endp, device->endpoint, is_ieee ? "ieee addr" : "short addr", + is_ieee ? formatIEEEAddress(device->ieee_addr) : formatShortAddress(device->short_addr) + ); + } else { + log_d("Device already exists, freeing allocated memory"); + free(device); // Free the device if it already exists + } + } } } - record = record->next; - } - // Continue reading the binding table - if (table_info->index + table_info->count < table_info->total) { - /* There are unreported binding table entries, request for them. */ - req->start_index = table_info->index + table_info->count; - esp_zb_zdo_binding_table_req(req, bindingTableCb, req); - done = false; + // Print bound devices + log_d("Filling bounded devices finished"); + free(req); } - } - - if (done) { - // Print bound devices - log_d("Filling bounded devices finished"); + } else { + log_e("Binding table request failed with status: %d", zdo_status); free(req); } } diff --git a/libraries/Zigbee/src/ZigbeeCore.h b/libraries/Zigbee/src/ZigbeeCore.h index 06c3ec4551a..69c91c63ac4 100644 --- a/libraries/Zigbee/src/ZigbeeCore.h +++ b/libraries/Zigbee/src/ZigbeeCore.h @@ -8,6 +8,7 @@ #include "esp_zigbee_core.h" #include "zdo/esp_zigbee_zdo_common.h" +#include "aps/esp_zigbee_aps.h" #include #include #include "ZigbeeEP.h" @@ -100,6 +101,7 @@ class ZigbeeCore { uint8_t _open_network; zigbee_scan_result_t *_scan_result; SemaphoreHandle_t lock; + bool _debug; bool zigbeeInit(esp_zb_cfg_t *zb_cfg, bool erase_nvs); static void scanCompleteCallback(esp_zb_zdp_status_t zdo_status, uint8_t count, esp_zb_network_descriptor_t *nwk_descriptor); @@ -156,6 +158,7 @@ class ZigbeeCore { } void setRebootOpenNetwork(uint8_t time); void openNetwork(uint8_t time); + void closeNetwork(); //scan_duration Time spent scanning each channel, in units of ((1 << scan_duration) + 1) * a beacon time. (15.36 microseconds) void scanNetworks(uint32_t channel_mask = ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK, uint8_t scan_duration = 5); @@ -166,8 +169,29 @@ class ZigbeeCore { void factoryReset(bool restart = true); + void setDebugMode(bool debug) { + _debug = debug; + } + bool getDebugMode() { + return _debug; + } + // Friend function declaration to allow access to private members friend void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct); + friend bool zb_apsde_data_indication_handler(esp_zb_apsde_data_ind_t ind); + + // Helper functions for formatting addresses + static inline const char *formatIEEEAddress(const esp_zb_ieee_addr_t addr) { + static char buf[24]; + snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", addr[7], addr[6], addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]); + return buf; + } + + static inline const char *formatShortAddress(uint16_t addr) { + static char buf[7]; + snprintf(buf, sizeof(buf), "0x%04X", addr); + return buf; + } }; extern ZigbeeCore Zigbee; diff --git a/libraries/Zigbee/src/ZigbeeEP.cpp b/libraries/Zigbee/src/ZigbeeEP.cpp index e7d507dc441..efddbdd0368 100644 --- a/libraries/Zigbee/src/ZigbeeEP.cpp +++ b/libraries/Zigbee/src/ZigbeeEP.cpp @@ -7,11 +7,6 @@ #include "esp_zigbee_cluster.h" #include "zcl/esp_zigbee_zcl_power_config.h" -bool ZigbeeEP::_is_bound = false; -bool ZigbeeEP::_allow_multiple_binding = false; - -//TODO: is_bound and allow_multiple_binding to make not static - /* Zigbee End Device Class */ ZigbeeEP::ZigbeeEP(uint8_t endpoint) { _endpoint = endpoint; @@ -19,7 +14,12 @@ ZigbeeEP::ZigbeeEP(uint8_t endpoint) { _ep_config.endpoint = 0; _cluster_list = nullptr; _on_identify = nullptr; + _read_model = NULL; + _read_manufacturer = NULL; _time_status = 0; + _is_bound = false; + _use_manual_binding = false; + _allow_multiple_binding = false; if (!lock) { lock = xSemaphoreCreateBinary(); if (lock == NULL) { @@ -33,16 +33,23 @@ void ZigbeeEP::setVersion(uint8_t version) { } bool ZigbeeEP::setManufacturerAndModel(const char *name, const char *model) { + // Allocate a new array of size length + 2 (1 for the length, 1 for null terminator) + char zb_name[ZB_MAX_NAME_LENGTH + 2]; + char zb_model[ZB_MAX_NAME_LENGTH + 2]; + // Convert manufacturer to ZCL string size_t name_length = strlen(name); size_t model_length = strlen(model); - if (name_length > 32 || model_length > 32) { + if (name_length > ZB_MAX_NAME_LENGTH || model_length > ZB_MAX_NAME_LENGTH) { log_e("Manufacturer or model name is too long"); return false; } - // Allocate a new array of size length + 2 (1 for the length, 1 for null terminator) - char *zb_name = new char[name_length + 2]; - char *zb_model = new char[model_length + 2]; + // Get and check the basic cluster + esp_zb_attribute_list_t *basic_cluster = esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + if (basic_cluster == nullptr) { + log_e("Failed to get basic cluster"); + return false; + } // Store the length as the first element zb_name[0] = static_cast(name_length); // Cast size_t to char zb_model[0] = static_cast(model_length); @@ -52,9 +59,7 @@ bool ZigbeeEP::setManufacturerAndModel(const char *name, const char *model) { // Null-terminate the array zb_name[name_length + 1] = '\0'; zb_model[model_length + 1] = '\0'; - - // Get the basic cluster and update the manufacturer and model attributes - esp_zb_attribute_list_t *basic_cluster = esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + // Update the manufacturer and model attributes esp_err_t ret_name = esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (void *)zb_name); if (ret_name != ESP_OK) { log_e("Failed to set manufacturer: 0x%x: %s", ret_name, esp_err_to_name(ret_name)); @@ -63,12 +68,10 @@ bool ZigbeeEP::setManufacturerAndModel(const char *name, const char *model) { if (ret_model != ESP_OK) { log_e("Failed to set model: 0x%x: %s", ret_model, esp_err_to_name(ret_model)); } - delete[] zb_name; - delete[] zb_model; return ret_name == ESP_OK && ret_model == ESP_OK; } -bool ZigbeeEP::setPowerSource(zb_power_source_t power_source, uint8_t battery_percentage) { +bool ZigbeeEP::setPowerSource(zb_power_source_t power_source, uint8_t battery_percentage, uint8_t battery_voltage) { esp_zb_attribute_list_t *basic_cluster = esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); esp_err_t ret = esp_zb_cluster_update_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID, (void *)&power_source); if (ret != ESP_OK) { @@ -88,6 +91,11 @@ bool ZigbeeEP::setPowerSource(zb_power_source_t power_source, uint8_t battery_pe log_e("Failed to add battery percentage attribute: 0x%x: %s", ret, esp_err_to_name(ret)); return false; } + ret = esp_zb_power_config_cluster_add_attr(power_config_cluster, ESP_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_ID, (void *)&battery_voltage); + if (ret != ESP_OK) { + log_e("Failed to add battery voltage attribute: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } ret = esp_zb_cluster_list_add_power_config_cluster(_cluster_list, power_config_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); if (ret != ESP_OK) { log_e("Failed to add power config cluster: 0x%x: %s", ret, esp_err_to_name(ret)); @@ -120,9 +128,24 @@ bool ZigbeeEP::setBatteryPercentage(uint8_t percentage) { return true; } +bool ZigbeeEP::setBatteryVoltage(uint8_t voltage) { + esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS; + esp_zb_lock_acquire(portMAX_DELAY); + ret = esp_zb_zcl_set_attribute_val( + _endpoint, ESP_ZB_ZCL_CLUSTER_ID_POWER_CONFIG, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_ID, &voltage, false + ); + esp_zb_lock_release(); + if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Failed to set battery voltage: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret)); + return false; + } + log_v("Battery voltage updated"); + return true; +} + bool ZigbeeEP::reportBatteryPercentage() { /* Send report attributes command */ - esp_zb_zcl_report_attr_cmd_t report_attr_cmd; + esp_zb_zcl_report_attr_cmd_t report_attr_cmd = {0}; report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID; report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; @@ -143,7 +166,7 @@ bool ZigbeeEP::reportBatteryPercentage() { char *ZigbeeEP::readManufacturer(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_addr_t ieee_addr) { /* Read peer Manufacture Name & Model Identifier */ - esp_zb_zcl_read_attr_cmd_t read_req; + esp_zb_zcl_read_attr_cmd_t read_req = {0}; if (short_addr != 0) { read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; @@ -160,13 +183,13 @@ char *ZigbeeEP::readManufacturer(uint8_t endpoint, uint16_t short_addr, esp_zb_i uint16_t attributes[] = { ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, }; - read_req.attr_number = ZB_ARRAY_LENTH(attributes); + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); read_req.attr_field = attributes; - if (_read_manufacturer != nullptr) { + if (_read_manufacturer != NULL) { free(_read_manufacturer); } - _read_manufacturer = nullptr; + _read_manufacturer = NULL; esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_read_attr_cmd_req(&read_req); @@ -181,7 +204,7 @@ char *ZigbeeEP::readManufacturer(uint8_t endpoint, uint16_t short_addr, esp_zb_i char *ZigbeeEP::readModel(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_addr_t ieee_addr) { /* Read peer Manufacture Name & Model Identifier */ - esp_zb_zcl_read_attr_cmd_t read_req; + esp_zb_zcl_read_attr_cmd_t read_req = {0}; if (short_addr != 0) { read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; @@ -198,13 +221,13 @@ char *ZigbeeEP::readModel(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_add uint16_t attributes[] = { ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, }; - read_req.attr_number = ZB_ARRAY_LENTH(attributes); + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); read_req.attr_field = attributes; - if (_read_model != nullptr) { + if (_read_model != NULL) { free(_read_model); } - _read_model = nullptr; + _read_model = NULL; esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_read_attr_cmd_req(&read_req); @@ -245,20 +268,28 @@ void ZigbeeEP::zbReadBasicCluster(const esp_zb_zcl_attribute_t *attribute) { /* Basic cluster attributes */ if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data.value) { zbstring_t *zbstr = (zbstring_t *)attribute->data.value; - char *string = (char *)malloc(zbstr->len + 1); - memcpy(string, zbstr->data, zbstr->len); - string[zbstr->len] = '\0'; - log_i("Peer Manufacturer is \"%s\"", string); - _read_manufacturer = string; + _read_manufacturer = (char *)malloc(zbstr->len + 1); + if (_read_manufacturer == NULL) { + log_e("Failed to allocate memory for manufacturer data"); + xSemaphoreGive(lock); + return; + } + memcpy(_read_manufacturer, zbstr->data, zbstr->len); + _read_manufacturer[zbstr->len] = '\0'; + log_i("Peer Manufacturer is \"%s\"", _read_manufacturer); xSemaphoreGive(lock); } if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data.value) { zbstring_t *zbstr = (zbstring_t *)attribute->data.value; - char *string = (char *)malloc(zbstr->len + 1); - memcpy(string, zbstr->data, zbstr->len); - string[zbstr->len] = '\0'; - log_i("Peer Model is \"%s\"", string); - _read_model = string; + _read_model = (char *)malloc(zbstr->len + 1); + if (_read_model == NULL) { + log_e("Failed to allocate memory for model data"); + xSemaphoreGive(lock); + return; + } + memcpy(_read_model, zbstr->data, zbstr->len); + _read_model[zbstr->len] = '\0'; + log_i("Peer Model is \"%s\"", _read_model); xSemaphoreGive(lock); } } @@ -344,7 +375,7 @@ bool ZigbeeEP::setTimezone(int32_t gmt_offset) { tm ZigbeeEP::getTime(uint8_t endpoint, int32_t short_addr, esp_zb_ieee_addr_t ieee_addr) { /* Read peer time */ - esp_zb_zcl_read_attr_cmd_t read_req; + esp_zb_zcl_read_attr_cmd_t read_req = {0}; if (short_addr >= 0) { read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; @@ -355,7 +386,7 @@ tm ZigbeeEP::getTime(uint8_t endpoint, int32_t short_addr, esp_zb_ieee_addr_t ie } uint16_t attributes[] = {ESP_ZB_ZCL_ATTR_TIME_TIME_ID}; - read_req.attr_number = ZB_ARRAY_LENTH(attributes); + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); read_req.attr_field = attributes; read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TIME; @@ -396,7 +427,7 @@ tm ZigbeeEP::getTime(uint8_t endpoint, int32_t short_addr, esp_zb_ieee_addr_t ie int32_t ZigbeeEP::getTimezone(uint8_t endpoint, int32_t short_addr, esp_zb_ieee_addr_t ieee_addr) { /* Read peer timezone */ - esp_zb_zcl_read_attr_cmd_t read_req; + esp_zb_zcl_read_attr_cmd_t read_req = {0}; if (short_addr >= 0) { read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; @@ -407,7 +438,7 @@ int32_t ZigbeeEP::getTimezone(uint8_t endpoint, int32_t short_addr, esp_zb_ieee_ } uint16_t attributes[] = {ESP_ZB_ZCL_ATTR_TIME_TIME_ZONE_ID}; - read_req.attr_number = ZB_ARRAY_LENTH(attributes); + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); read_req.attr_field = attributes; read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TIME; @@ -512,7 +543,7 @@ static void findOTAServer(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t } void ZigbeeEP::requestOTAUpdate() { - esp_zb_zdo_match_desc_req_param_t req; + esp_zb_zdo_match_desc_req_param_t req = {0}; uint16_t cluster_list[] = {ESP_ZB_ZCL_CLUSTER_ID_OTA_UPGRADE}; /* Match the OTA server of coordinator */ @@ -529,6 +560,54 @@ void ZigbeeEP::requestOTAUpdate() { esp_zb_lock_release(); } +void ZigbeeEP::removeBoundDevice(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { + log_d( + "Attempting to remove device with endpoint %d and IEEE address %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", endpoint, ieee_addr[7], ieee_addr[6], ieee_addr[5], + ieee_addr[4], ieee_addr[3], ieee_addr[2], ieee_addr[1], ieee_addr[0] + ); + + for (std::list::iterator it = _bound_devices.begin(); it != _bound_devices.end(); ++it) { + if ((*it)->endpoint == endpoint && memcmp((*it)->ieee_addr, ieee_addr, sizeof(esp_zb_ieee_addr_t)) == 0) { + log_d("Found matching device, removing it"); + _bound_devices.erase(it); + if (_bound_devices.empty()) { + _is_bound = false; + } + return; + } + } + log_w("No matching device found for removal"); +} + +void ZigbeeEP::removeBoundDevice(zb_device_params_t *device) { + if (!device) { + log_e("Invalid device parameters provided"); + return; + } + + log_d( + "Attempting to remove device with endpoint %d, short address 0x%04x, IEEE address %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", device->endpoint, + device->short_addr, 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] + ); + + for (std::list::iterator it = _bound_devices.begin(); it != _bound_devices.end(); ++it) { + bool endpoint_matches = ((*it)->endpoint == device->endpoint); + bool short_addr_matches = (device->short_addr != 0xFFFF && (*it)->short_addr == device->short_addr); + bool ieee_addr_matches = (memcmp((*it)->ieee_addr, device->ieee_addr, sizeof(esp_zb_ieee_addr_t)) == 0); + + if (endpoint_matches && (short_addr_matches || ieee_addr_matches)) { + log_d("Found matching device by %s, removing it", short_addr_matches ? "short address" : "IEEE address"); + _bound_devices.erase(it); + if (_bound_devices.empty()) { + _is_bound = false; + } + return; + } + } + log_w("No matching device found for removal"); +} + const char *ZigbeeEP::esp_zb_zcl_status_to_name(esp_zb_zcl_status_t status) { switch (status) { case ESP_ZB_ZCL_STATUS_SUCCESS: return "Success"; diff --git a/libraries/Zigbee/src/ZigbeeEP.h b/libraries/Zigbee/src/ZigbeeEP.h index bd142344929..a3217cbd066 100644 --- a/libraries/Zigbee/src/ZigbeeEP.h +++ b/libraries/Zigbee/src/ZigbeeEP.h @@ -12,7 +12,7 @@ #define ZB_CMD_TIMEOUT 10000 // 10 seconds #define OTA_UPGRADE_QUERY_INTERVAL (1 * 60) // 1 hour = 60 minutes -#define ZB_ARRAY_LENTH(arr) (sizeof(arr) / sizeof(arr[0])) +#define ZB_ARRAY_LENGHT(arr) (sizeof(arr) / sizeof(arr[0])) #define RGB_TO_XYZ(r, g, b, X, Y, Z) \ { \ @@ -41,6 +41,10 @@ typedef enum { /* Zigbee End Device Class */ class ZigbeeEP { public: + // constants and limits + static constexpr size_t ZB_MAX_NAME_LENGTH = 32; + + // constructors and destructor ZigbeeEP(uint8_t endpoint = 10); ~ZigbeeEP() {} @@ -62,12 +66,15 @@ class ZigbeeEP { return _bound_devices; } - static bool bound() { + bool bound() { return _is_bound; } - static void allowMultipleBinding(bool bind) { + void allowMultipleBinding(bool bind) { _allow_multiple_binding = bind; } + void setManualBinding(bool bind) { + _use_manual_binding = bind; + } // Set Manufacturer name and model bool setManufacturerAndModel(const char *name, const char *model); @@ -77,9 +84,10 @@ class ZigbeeEP { char *readModel(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_addr_t ieee_addr); // Set Power source and battery percentage for battery powered devices - bool setPowerSource(zb_power_source_t power_source, uint8_t percentage = 255); - bool setBatteryPercentage(uint8_t percentage); - bool reportBatteryPercentage(); + bool setPowerSource(zb_power_source_t power_source, uint8_t percentage = 0xff, uint8_t voltage = 0xff); // voltage in 100mV + bool setBatteryPercentage(uint8_t percentage); // 0-100 % + bool setBatteryVoltage(uint8_t voltage); // voltage in 100mV (example value 35 for 3.5V) + bool reportBatteryPercentage(); // battery voltage is not reportable attribute // Set time bool addTimeCluster(tm time = {}, int32_t gmt_offset = 0); // gmt offset in seconds @@ -93,6 +101,9 @@ class ZigbeeEP { bool epAllowMultipleBinding() { return _allow_multiple_binding; } + bool epUseManualBinding() { + return _use_manual_binding; + } // OTA methods /** @@ -120,7 +131,7 @@ class ZigbeeEP { // list of all handlers function calls, to be override by EPs implementation virtual void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) {}; - virtual void zbAttributeRead(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute) {}; + virtual void zbAttributeRead(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute, uint8_t src_endpoint, esp_zb_zcl_addr_t src_address) {}; virtual void zbReadBasicCluster(const esp_zb_zcl_attribute_t *attribute); //already implemented virtual void zbIdentify(const esp_zb_zcl_set_attr_value_message_t *message); virtual void zbWindowCoveringMovementCmd(const esp_zb_zcl_window_covering_movement_message_t *message) {}; @@ -133,6 +144,14 @@ class ZigbeeEP { _is_bound = true; } + virtual void removeBoundDevice(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr); + virtual void removeBoundDevice(zb_device_params_t *device); + + virtual void clearBoundDevices() { + _bound_devices.clear(); + _is_bound = false; + } + void onIdentify(void (*callback)(uint16_t)) { _on_identify = callback; } @@ -152,8 +171,9 @@ class ZigbeeEP { esp_zb_ha_standard_devices_t _device_id; esp_zb_endpoint_config_t _ep_config; esp_zb_cluster_list_t *_cluster_list; - static bool _is_bound; - static bool _allow_multiple_binding; + bool _is_bound; + bool _allow_multiple_binding; + bool _use_manual_binding; std::list _bound_devices; SemaphoreHandle_t lock; zb_power_source_t _power_source; diff --git a/libraries/Zigbee/src/ZigbeeHandlers.cpp b/libraries/Zigbee/src/ZigbeeHandlers.cpp index eeeb1e8013a..5d54e459058 100644 --- a/libraries/Zigbee/src/ZigbeeHandlers.cpp +++ b/libraries/Zigbee/src/ZigbeeHandlers.cpp @@ -108,7 +108,9 @@ static esp_err_t zb_attribute_reporting_handler(const esp_zb_zcl_report_attr_mes // List through all Zigbee EPs and call the callback function, with the message for (std::list::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) { if (message->dst_endpoint == (*it)->getEndpoint()) { - (*it)->zbAttributeRead(message->cluster, &message->attribute); //method zbAttributeRead must be implemented in specific EP class + (*it)->zbAttributeRead( + message->cluster, &message->attribute, message->src_endpoint, message->src_address + ); //method zbAttributeRead must be implemented in specific EP class } } return ESP_OK; @@ -142,7 +144,9 @@ static esp_err_t zb_cmd_read_attr_resp_handler(const esp_zb_zcl_cmd_read_attr_re } else if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_TIME) { (*it)->zbReadTimeCluster(&variable->attribute); //method zbReadTimeCluster implemented in the common EP class } else { - (*it)->zbAttributeRead(message->info.cluster, &variable->attribute); //method zbAttributeRead must be implemented in specific EP class + (*it)->zbAttributeRead( + message->info.cluster, &variable->attribute, message->info.src_endpoint, message->info.src_address + ); //method zbAttributeRead must be implemented in specific EP class } } variable = variable->next; diff --git a/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp b/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp index a95668b7afe..309739d54c9 100644 --- a/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeAnalog.cpp @@ -1,5 +1,6 @@ #include "ZigbeeAnalog.h" #if CONFIG_ZB_ENABLED +#include ZigbeeAnalog::ZigbeeAnalog(uint8_t endpoint) : ZigbeeEP(endpoint) { _device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID; @@ -13,17 +14,119 @@ ZigbeeAnalog::ZigbeeAnalog(uint8_t endpoint) : ZigbeeEP(endpoint) { } bool ZigbeeAnalog::addAnalogInput() { - esp_err_t ret = esp_zb_cluster_list_add_analog_input_cluster(_cluster_list, esp_zb_analog_input_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_attribute_list_t *esp_zb_analog_input_cluster = esp_zb_analog_input_cluster_create(NULL); + + // Create default description for Analog Input + char default_description[] = "\x0C" + "Analog Input"; + uint32_t application_type = 0x00000000 | (ESP_ZB_ZCL_AI_GROUP_ID << 24); + float resolution = 0.1; // Default resolution of 0.1 + float min = -FLT_MAX; // Default min value for float + float max = FLT_MAX; // Default max value for float + + esp_err_t ret = esp_zb_analog_input_cluster_add_attr(esp_zb_analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_DESCRIPTION_ID, (void *)default_description); + if (ret != ESP_OK) { + log_e("Failed to add description attribute: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_analog_input_cluster_add_attr(esp_zb_analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_APPLICATION_TYPE_ID, (void *)&application_type); + if (ret != ESP_OK) { + log_e("Failed to add application type attribute: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_analog_input_cluster_add_attr(esp_zb_analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_RESOLUTION_ID, (void *)&resolution); + if (ret != ESP_OK) { + log_e("Failed to add resolution attribute: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_analog_input_cluster_add_attr(esp_zb_analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_MIN_PRESENT_VALUE_ID, (void *)&min); + if (ret != ESP_OK) { + log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_analog_input_cluster_add_attr(esp_zb_analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_MAX_PRESENT_VALUE_ID, (void *)&max); + if (ret != ESP_OK) { + log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_cluster_list_add_analog_input_cluster(_cluster_list, esp_zb_analog_input_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); if (ret != ESP_OK) { log_e("Failed to add Analog Input cluster: 0x%x: %s", ret, esp_err_to_name(ret)); return false; } + _analog_clusters |= ANALOG_INPUT; return true; } +// Check esp_zigbee_zcl_analog_input.h for application type values +bool ZigbeeAnalog::setAnalogInputApplication(uint32_t application_type) { + if (!(_analog_clusters & ANALOG_INPUT)) { + log_e("Analog Input cluster not added"); + return false; + } + + // Add the Analog Input group ID (0x00) to the application type + uint32_t application_type_value = (ESP_ZB_ZCL_AI_GROUP_ID << 24) | application_type; + + esp_zb_attribute_list_t *analog_input_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_APPLICATION_TYPE_ID, (void *)&application_type_value); + if (ret != ESP_OK) { + log_e("Failed to set AI application type: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + bool ZigbeeAnalog::addAnalogOutput() { - esp_err_t ret = esp_zb_cluster_list_add_analog_output_cluster(_cluster_list, esp_zb_analog_output_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_attribute_list_t *esp_zb_analog_output_cluster = esp_zb_analog_output_cluster_create(NULL); + + // Create default description for Analog Output + char default_description[] = "\x0D" + "Analog Output"; + uint32_t application_type = 0x00000000 | (ESP_ZB_ZCL_AO_GROUP_ID << 24); + float resolution = 1; // Default resolution of 1 + float min = -FLT_MAX; // Default min value for float + float max = FLT_MAX; // Default max value for float + + esp_err_t ret = + esp_zb_analog_output_cluster_add_attr(esp_zb_analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_DESCRIPTION_ID, (void *)default_description); + if (ret != ESP_OK) { + log_e("Failed to add description attribute: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_analog_output_cluster_add_attr(esp_zb_analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_APPLICATION_TYPE_ID, (void *)&application_type); + if (ret != ESP_OK) { + log_e("Failed to add application type attribute: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_analog_output_cluster_add_attr(esp_zb_analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_RESOLUTION_ID, (void *)&resolution); + if (ret != ESP_OK) { + log_e("Failed to add resolution attribute: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_analog_output_cluster_add_attr(esp_zb_analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_MIN_PRESENT_VALUE_ID, (void *)&min); + if (ret != ESP_OK) { + log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_analog_output_cluster_add_attr(esp_zb_analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_MAX_PRESENT_VALUE_ID, (void *)&max); + if (ret != ESP_OK) { + log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_cluster_list_add_analog_output_cluster(_cluster_list, esp_zb_analog_output_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); if (ret != ESP_OK) { log_e("Failed to add Analog Output cluster: 0x%x: %s", ret, esp_err_to_name(ret)); return false; @@ -32,12 +135,32 @@ bool ZigbeeAnalog::addAnalogOutput() { return true; } +// Check esp_zigbee_zcl_analog_output.h for application type values +bool ZigbeeAnalog::setAnalogOutputApplication(uint32_t application_type) { + if (!(_analog_clusters & ANALOG_OUTPUT)) { + log_e("Analog Output cluster not added"); + return false; + } + + // Add the Analog Output group ID (0x00) to the application type + uint32_t application_type_value = (ESP_ZB_ZCL_AO_GROUP_ID << 24) | application_type; + + esp_zb_attribute_list_t *analog_output_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_APPLICATION_TYPE_ID, (void *)&application_type_value); + if (ret != ESP_OK) { + log_e("Failed to set AO application type: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + //set attribute method -> method overridden in child class void ZigbeeAnalog::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) { if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT) { if (message->attribute.id == ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_PRESENT_VALUE_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_SINGLE) { - float analog_output = *(float *)message->attribute.data.value; - analogOutputChanged(analog_output); + _output_state = *(float *)message->attribute.data.value; + analogOutputChanged(); } else { log_w("Received message ignored. Attribute ID: %d not supported for Analog Output", message->attribute.id); } @@ -46,9 +169,9 @@ void ZigbeeAnalog::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *mes } } -void ZigbeeAnalog::analogOutputChanged(float analog_output) { +void ZigbeeAnalog::analogOutputChanged() { if (_on_analog_output_change) { - _on_analog_output_change(analog_output); + _on_analog_output_change(_output_state); } else { log_w("No callback function set for analog output change"); } @@ -73,6 +196,26 @@ bool ZigbeeAnalog::setAnalogInput(float analog) { return true; } +bool ZigbeeAnalog::setAnalogOutput(float analog) { + esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS; + _output_state = analog; + analogOutputChanged(); + + log_v("Updating analog output to %.2f", analog); + /* Update analog output */ + esp_zb_lock_acquire(portMAX_DELAY); + ret = esp_zb_zcl_set_attribute_val( + _endpoint, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_PRESENT_VALUE_ID, &_output_state, false + ); + esp_zb_lock_release(); + + if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Failed to set analog output: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret)); + return false; + } + return true; +} + bool ZigbeeAnalog::reportAnalogInput() { /* Send report attributes command */ esp_zb_zcl_report_attr_cmd_t report_attr_cmd; @@ -94,6 +237,27 @@ bool ZigbeeAnalog::reportAnalogInput() { return true; } +bool ZigbeeAnalog::reportAnalogOutput() { + /* Send report attributes command */ + esp_zb_zcl_report_attr_cmd_t report_attr_cmd; + report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; + report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_PRESENT_VALUE_ID; + report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; + report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT; + report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; + + esp_zb_lock_acquire(portMAX_DELAY); + esp_err_t ret = esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); + esp_zb_lock_release(); + if (ret != ESP_OK) { + log_e("Failed to send Analog Output report: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + log_v("Analog Output report sent"); + return true; +} + bool ZigbeeAnalog::setAnalogInputReporting(uint16_t min_interval, uint16_t max_interval, float delta) { esp_zb_zcl_reporting_info_t reporting_info; memset(&reporting_info, 0, sizeof(esp_zb_zcl_reporting_info_t)); @@ -120,4 +284,180 @@ bool ZigbeeAnalog::setAnalogInputReporting(uint16_t min_interval, uint16_t max_i return true; } +bool ZigbeeAnalog::setAnalogInputDescription(const char *description) { + if (!(_analog_clusters & ANALOG_INPUT)) { + log_e("Analog Input cluster not added"); + return false; + } + + // Allocate a new array of size length + 2 (1 for the length, 1 for null terminator) + char zb_description[ZB_MAX_NAME_LENGTH + 2]; + + // Convert description to ZCL string + size_t description_length = strlen(description); + if (description_length > ZB_MAX_NAME_LENGTH) { + log_e("Description is too long"); + return false; + } + + // Get and check the analog input cluster + esp_zb_attribute_list_t *analog_input_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + if (analog_input_cluster == nullptr) { + log_e("Failed to get analog input cluster"); + return false; + } + + // Store the length as the first element + zb_description[0] = static_cast(description_length); // Cast size_t to char + // Use memcpy to copy the characters to the result array + memcpy(zb_description + 1, description, description_length); + // Null-terminate the array + zb_description[description_length + 1] = '\0'; + + // Update the description attribute + esp_err_t ret = esp_zb_cluster_update_attr(analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_DESCRIPTION_ID, (void *)zb_description); + if (ret != ESP_OK) { + log_e("Failed to set description: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeAnalog::setAnalogOutputDescription(const char *description) { + if (!(_analog_clusters & ANALOG_OUTPUT)) { + log_e("Analog Output cluster not added"); + return false; + } + + // Allocate a new array of size length + 2 (1 for the length, 1 for null terminator) + char zb_description[ZB_MAX_NAME_LENGTH + 2]; + + // Convert description to ZCL string + size_t description_length = strlen(description); + if (description_length > ZB_MAX_NAME_LENGTH) { + log_e("Description is too long"); + return false; + } + + // Get and check the analog output cluster + esp_zb_attribute_list_t *analog_output_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + if (analog_output_cluster == nullptr) { + log_e("Failed to get analog output cluster"); + return false; + } + + // Store the length as the first element + zb_description[0] = static_cast(description_length); // Cast size_t to char + // Use memcpy to copy the characters to the result array + memcpy(zb_description + 1, description, description_length); + // Null-terminate the array + zb_description[description_length + 1] = '\0'; + + // Update the description attribute + esp_err_t ret = esp_zb_cluster_update_attr(analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_DESCRIPTION_ID, (void *)zb_description); + if (ret != ESP_OK) { + log_e("Failed to set description: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeAnalog::setAnalogInputResolution(float resolution) { + if (!(_analog_clusters & ANALOG_INPUT)) { + log_e("Analog Input cluster not added"); + return false; + } + + esp_zb_attribute_list_t *analog_input_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + if (analog_input_cluster == nullptr) { + log_e("Failed to get analog input cluster"); + return false; + } + + esp_err_t ret = esp_zb_cluster_update_attr(analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_RESOLUTION_ID, (void *)&resolution); + if (ret != ESP_OK) { + log_e("Failed to set resolution: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeAnalog::setAnalogOutputResolution(float resolution) { + if (!(_analog_clusters & ANALOG_OUTPUT)) { + log_e("Analog Output cluster not added"); + return false; + } + + esp_zb_attribute_list_t *analog_output_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + if (analog_output_cluster == nullptr) { + log_e("Failed to get analog output cluster"); + return false; + } + + esp_err_t ret = esp_zb_cluster_update_attr(analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_RESOLUTION_ID, (void *)&resolution); + if (ret != ESP_OK) { + log_e("Failed to set resolution: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeAnalog::setAnalogOutputMinMax(float min, float max) { + if (!(_analog_clusters & ANALOG_OUTPUT)) { + log_e("Analog Output cluster not added"); + return false; + } + + esp_zb_attribute_list_t *analog_output_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + if (analog_output_cluster == nullptr) { + log_e("Failed to get analog output cluster"); + return false; + } + + esp_err_t ret = esp_zb_cluster_update_attr(analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_MIN_PRESENT_VALUE_ID, (void *)&min); + if (ret != ESP_OK) { + log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_cluster_update_attr(analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_MAX_PRESENT_VALUE_ID, (void *)&max); + if (ret != ESP_OK) { + log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeAnalog::setAnalogInputMinMax(float min, float max) { + if (!(_analog_clusters & ANALOG_INPUT)) { + log_e("Analog Input cluster not added"); + return false; + } + + esp_zb_attribute_list_t *analog_input_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + if (analog_input_cluster == nullptr) { + log_e("Failed to get analog input cluster"); + return false; + } + + esp_err_t ret = esp_zb_cluster_update_attr(analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_MIN_PRESENT_VALUE_ID, (void *)&min); + if (ret != ESP_OK) { + log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_cluster_update_attr(analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_MAX_PRESENT_VALUE_ID, (void *)&max); + if (ret != ESP_OK) { + log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + #endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeeAnalog.h b/libraries/Zigbee/src/ep/ZigbeeAnalog.h index 03fbc678b6e..5218a0b7d60 100644 --- a/libraries/Zigbee/src/ep/ZigbeeAnalog.h +++ b/libraries/Zigbee/src/ep/ZigbeeAnalog.h @@ -31,16 +31,37 @@ class ZigbeeAnalog : public ZigbeeEP { bool addAnalogInput(); bool addAnalogOutput(); + // Set the application type and description for the analog input + bool setAnalogInputApplication(uint32_t application_type); // Check esp_zigbee_zcl_analog_input.h for application type values + bool setAnalogInputDescription(const char *description); + bool setAnalogInputResolution(float resolution); + + // Set the application type and description for the analog output + bool setAnalogOutputApplication(uint32_t application_type); // Check esp_zigbee_zcl_analog_output.h for application type values + bool setAnalogOutputDescription(const char *description); + bool setAnalogOutputResolution(float resolution); + + // Set the min and max values for the analog Input/Output + bool setAnalogOutputMinMax(float min, float max); + bool setAnalogInputMinMax(float min, float max); + // Use to set a cb function to be called on analog output change void onAnalogOutputChange(void (*callback)(float analog)) { _on_analog_output_change = callback; } - // Set the analog input value + // Set the Analog Input/Output value bool setAnalogInput(float analog); + bool setAnalogOutput(float analog); + + // Get the Analog Output value + float getAnalogOutput() { + return _output_state; + } - // Report Analog Input value + // Report Analog Input/Output bool reportAnalogInput(); + bool reportAnalogOutput(); // Set reporting for Analog Input bool setAnalogInputReporting(uint16_t min_interval, uint16_t max_interval, float delta); @@ -49,9 +70,10 @@ class ZigbeeAnalog : public ZigbeeEP { void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) override; void (*_on_analog_output_change)(float); - void analogOutputChanged(float analog_output); + void analogOutputChanged(); uint8_t _analog_clusters; + float _output_state; }; #endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeeBinary.cpp b/libraries/Zigbee/src/ep/ZigbeeBinary.cpp new file mode 100644 index 00000000000..aa37ceb3020 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeeBinary.cpp @@ -0,0 +1,144 @@ +#include "ZigbeeBinary.h" +#if CONFIG_ZB_ENABLED + +ZigbeeBinary::ZigbeeBinary(uint8_t endpoint) : ZigbeeEP(endpoint) { + _device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID; + + //Create basic binary sensor clusters without configuration + _cluster_list = esp_zb_zcl_cluster_list_create(); + esp_zb_cluster_list_add_basic_cluster(_cluster_list, esp_zb_basic_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_cluster_list_add_identify_cluster(_cluster_list, esp_zb_identify_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + + _ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID, .app_device_version = 0}; +} + +bool ZigbeeBinary::addBinaryInput() { + esp_zb_attribute_list_t *esp_zb_binary_input_cluster = esp_zb_binary_input_cluster_create(NULL); + + // Create default description for Binary Input + char default_description[] = "\x0C" + "Binary Input"; + uint32_t application_type = 0x00000000 | (0x03 << 24); // Group ID 0x03 + + esp_err_t ret = esp_zb_binary_input_cluster_add_attr(esp_zb_binary_input_cluster, ESP_ZB_ZCL_ATTR_BINARY_INPUT_DESCRIPTION_ID, (void *)default_description); + if (ret != ESP_OK) { + log_e("Failed to add description attribute: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_binary_input_cluster_add_attr(esp_zb_binary_input_cluster, ESP_ZB_ZCL_ATTR_BINARY_INPUT_APPLICATION_TYPE_ID, (void *)&application_type); + if (ret != ESP_OK) { + log_e("Failed to add application type attribute: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + ret = esp_zb_cluster_list_add_binary_input_cluster(_cluster_list, esp_zb_binary_input_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + if (ret != ESP_OK) { + log_e("Failed to add Binary Input cluster: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + _binary_clusters |= BINARY_INPUT; + return true; +} + +// Check Zigbee Cluster Specification 3.14.11.19.4 Binary Inputs (BI) Types for application type values +bool ZigbeeBinary::setBinaryInputApplication(uint32_t application_type) { + if (!(_binary_clusters & BINARY_INPUT)) { + log_e("Binary Input cluster not added"); + return false; + } + + // Add the Binary Input group ID (0x03) to the application type + uint32_t application_type_value = (0x03 << 24) | application_type; + + esp_zb_attribute_list_t *binary_input_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BINARY_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(binary_input_cluster, ESP_ZB_ZCL_ATTR_BINARY_INPUT_APPLICATION_TYPE_ID, (void *)&application_type_value); + if (ret != ESP_OK) { + log_e("Failed to set Binary Input application type: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeBinary::setBinaryInput(bool input) { + esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS; + if (!(_binary_clusters & BINARY_INPUT)) { + log_e("Binary Input cluster not added"); + return false; + } + log_d("Setting binary input to %d", input); + esp_zb_lock_acquire(portMAX_DELAY); + ret = esp_zb_zcl_set_attribute_val( + _endpoint, ESP_ZB_ZCL_CLUSTER_ID_BINARY_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID, &input, false + ); + esp_zb_lock_release(); + if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Failed to set binary input: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeBinary::reportBinaryInput() { + /* Send report attributes command */ + esp_zb_zcl_report_attr_cmd_t report_attr_cmd; + report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; + report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID; + report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; + report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_BINARY_INPUT; + report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; + + esp_zb_lock_acquire(portMAX_DELAY); + esp_err_t ret = esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); + esp_zb_lock_release(); + if (ret != ESP_OK) { + log_e("Failed to send Binary Input report: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + log_v("Binary Input report sent"); + return true; +} + +bool ZigbeeBinary::setBinaryInputDescription(const char *description) { + if (!(_binary_clusters & BINARY_INPUT)) { + log_e("Binary Input cluster not added"); + return false; + } + + // Allocate a new array of size length + 2 (1 for the length, 1 for null terminator) + char zb_description[ZB_MAX_NAME_LENGTH + 2]; + + // Convert description to ZCL string + size_t description_length = strlen(description); + if (description_length > ZB_MAX_NAME_LENGTH) { + log_e("Description is too long"); + return false; + } + + // Get and check the binary input cluster + esp_zb_attribute_list_t *binary_input_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BINARY_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + if (binary_input_cluster == nullptr) { + log_e("Failed to get binary input cluster"); + return false; + } + + // Store the length as the first element + zb_description[0] = static_cast(description_length); // Cast size_t to char + // Use memcpy to copy the characters to the result array + memcpy(zb_description + 1, description, description_length); + // Null-terminate the array + zb_description[description_length + 1] = '\0'; + + // Update the description attribute + esp_err_t ret = esp_zb_cluster_update_attr(binary_input_cluster, ESP_ZB_ZCL_ATTR_BINARY_INPUT_DESCRIPTION_ID, (void *)zb_description); + if (ret != ESP_OK) { + log_e("Failed to set description: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +#endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeeBinary.h b/libraries/Zigbee/src/ep/ZigbeeBinary.h new file mode 100644 index 00000000000..5a543604970 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeeBinary.h @@ -0,0 +1,85 @@ +/* Class of Zigbee Binary sensor endpoint inherited from common EP class */ + +#pragma once + +#include "soc/soc_caps.h" +#include "sdkconfig.h" +#if CONFIG_ZB_ENABLED + +#include "ZigbeeEP.h" +#include "ha/esp_zigbee_ha_standard.h" + +//enum for bits set to check what analog cluster were added +enum zigbee_binary_clusters { + BINARY_INPUT = 1, + BINARY_OUTPUT = 2 +}; + +// HVAC application types for Binary Input (more can be found in Zigbee Cluster Specification 3.14.11.19.4 Binary Inputs (BI) Types) +#define BINARY_INPUT_APPLICATION_TYPE_HVAC_BOILER_STATUS 0x00000003 // Type 0x00, Index 0x0003 +#define BINARY_INPUT_APPLICATION_TYPE_HVAC_CHILLER_STATUS 0x00000013 // Type 0x00, Index 0x0013 +#define BINARY_INPUT_APPLICATION_TYPE_HVAC_OCCUPANCY 0x00000031 // Type 0x00, Index 0x0031 +#define BINARY_INPUT_APPLICATION_TYPE_HVAC_FAN_STATUS 0x00000035 // Type 0x00, Index 0x0035 +#define BINARY_INPUT_APPLICATION_TYPE_HVAC_FILTER_STATUS 0x00000036 // Type 0x00, Index 0x0036 +#define BINARY_INPUT_APPLICATION_TYPE_HVAC_HEATING_ALARM 0x0000003E // Type 0x00, Index 0x003E +#define BINARY_INPUT_APPLICATION_TYPE_HVAC_COOLING_ALARM 0x0000001D // Type 0x00, Index 0x001D +#define BINARY_INPUT_APPLICATION_TYPE_HVAC_UNIT_ENABLE 0x00000090 // Type 0x00, Index 0x0090 +#define BINARY_INPUT_APPLICATION_TYPE_HVAC_OTHER 0x0000FFFF // Type 0x00, Index 0xFFFF + +// Security application types for Binary Input +#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_GLASS_BREAKAGE_DETECTION_0 0x01000000 // Type 0x01, Index 0x0000 +#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_INTRUSION_DETECTION 0x01000001 // Type 0x01, Index 0x0001 +#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_MOTION_DETECTION 0x01000002 // Type 0x01, Index 0x0002 +#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_GLASS_BREAKAGE_DETECTION_1 0x01000003 // Type 0x01, Index 0x0003 +#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_ZONE_ARMED 0x01000004 // Type 0x01, Index 0x0004 +#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_GLASS_BREAKAGE_DETECTION_2 0x01000005 // Type 0x01, Index 0x0005 +#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_SMOKE_DETECTION 0x01000006 // Type 0x01, Index 0x0006 +#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_CARBON_DIOXIDE_DETECTION 0x01000007 // Type 0x01, Index 0x0007 +#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_HEAT_DETECTION 0x01000008 // Type 0x01, Index 0x0008 +#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_OTHER 0x0100FFFF // Type 0x01, Index 0xFFFF + +typedef struct zigbee_binary_cfg_s { + esp_zb_basic_cluster_cfg_t basic_cfg; + esp_zb_identify_cluster_cfg_t identify_cfg; + // esp_zb_binary_output_cluster_cfg_t binary_output_cfg; + esp_zb_binary_input_cluster_cfg_t binary_input_cfg; +} zigbee_binary_cfg_t; + +class ZigbeeBinary : public ZigbeeEP { +public: + ZigbeeBinary(uint8_t endpoint); + ~ZigbeeBinary() {} + + // Add binary cluster + bool addBinaryInput(); + // bool addBinaryOutput(); + + // Set the application type and description for the binary input + bool setBinaryInputApplication(uint32_t application_type); // Check esp_zigbee_zcl_binary_input.h for application type values + bool setBinaryInputDescription(const char *description); + + // Set the application type and description for the binary output + // bool setBinaryOutputApplication(uint32_t application_type); // Check esp_zigbee_zcl_binary_output.h for application type values + // bool setBinaryOutputDescription(const char *description); + + // Use to set a cb function to be called on binary output change + // void onBinaryOutputChange(void (*callback)(bool binary_output)) { + // _on_binary_output_change = callback; + // } + + // Set the binary input value + bool setBinaryInput(bool input); + + // Report Binary Input value + bool reportBinaryInput(); + +private: + // void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) override; + + // void (*_on_binary_output_change)(bool); + // void binaryOutputChanged(bool binary_output); + + uint8_t _binary_clusters; +}; + +#endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeeColorDimmerSwitch.cpp b/libraries/Zigbee/src/ep/ZigbeeColorDimmerSwitch.cpp index 68f287153cb..f795ed1a3c8 100644 --- a/libraries/Zigbee/src/ep/ZigbeeColorDimmerSwitch.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeColorDimmerSwitch.cpp @@ -6,7 +6,8 @@ ZigbeeColorDimmerSwitch *ZigbeeColorDimmerSwitch::_instance = nullptr; ZigbeeColorDimmerSwitch::ZigbeeColorDimmerSwitch(uint8_t endpoint) : ZigbeeEP(endpoint) { _device_id = ESP_ZB_HA_COLOR_DIMMER_SWITCH_DEVICE_ID; - _instance = this; // Set the static pointer to this instance + _instance = this; // Set the static pointer to this instance + _device = nullptr; // Initialize light pointer to null esp_zb_color_dimmable_switch_cfg_t switch_cfg = ESP_ZB_DEFAULT_COLOR_DIMMABLE_SWITCH_CONFIG(); _cluster_list = esp_zb_color_dimmable_switch_clusters_create(&switch_cfg); @@ -17,44 +18,64 @@ ZigbeeColorDimmerSwitch::ZigbeeColorDimmerSwitch(uint8_t endpoint) : ZigbeeEP(en } void ZigbeeColorDimmerSwitch::bindCb(esp_zb_zdp_status_t zdo_status, void *user_ctx) { + ZigbeeColorDimmerSwitch *instance = static_cast(user_ctx); if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { log_i("Bound successfully!"); - if (user_ctx) { - zb_device_params_t *light = (zb_device_params_t *)user_ctx; + if (instance->_device) { + zb_device_params_t *light = (zb_device_params_t *)instance->_device; log_i("The light originating from address(0x%x) on endpoint(%d)", light->short_addr, light->endpoint); - _instance->_bound_devices.push_back(light); + log_d("Light bound to a switch on EP %d", instance->_endpoint); + instance->_bound_devices.push_back(light); } - _is_bound = true; + instance->_is_bound = true; } else { - log_e("Binding failed!"); + instance->_device = nullptr; + } +} + +void ZigbeeColorDimmerSwitch::bindCbWrapper(esp_zb_zdp_status_t zdo_status, void *user_ctx) { + ZigbeeColorDimmerSwitch *instance = static_cast(user_ctx); + if (instance) { + log_d("bindCbWrapper on EP %d", instance->_endpoint); + instance->bindCb(zdo_status, user_ctx); + } +} + +void ZigbeeColorDimmerSwitch::findCbWrapper(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) { + ZigbeeColorDimmerSwitch *instance = static_cast(user_ctx); + if (instance) { + log_d("findCbWrapper on EP %d", instance->_endpoint); + instance->findCb(zdo_status, addr, endpoint, user_ctx); } } void ZigbeeColorDimmerSwitch::findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) { + ZigbeeColorDimmerSwitch *instance = static_cast(user_ctx); if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { log_d("Found light endpoint"); - esp_zb_zdo_bind_req_param_t bind_req; + esp_zb_zdo_bind_req_param_t bind_req = {0}; zb_device_params_t *light = (zb_device_params_t *)malloc(sizeof(zb_device_params_t)); light->endpoint = endpoint; light->short_addr = addr; esp_zb_ieee_address_by_short(light->short_addr, light->ieee_addr); esp_zb_get_long_address(bind_req.src_address); - bind_req.src_endp = *((uint8_t *)user_ctx); //_endpoint; + bind_req.src_endp = instance->_endpoint; bind_req.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_ON_OFF; bind_req.dst_addr_mode = ESP_ZB_ZDO_BIND_DST_ADDR_MODE_64_BIT_EXTENDED; memcpy(bind_req.dst_address_u.addr_long, light->ieee_addr, sizeof(esp_zb_ieee_addr_t)); bind_req.dst_endp = endpoint; bind_req.req_dst_addr = esp_zb_get_short_address(); + instance->_device = light; log_v("Try to bind on/off control of dimmable light"); - esp_zb_zdo_device_bind_req(&bind_req, bindCb, NULL); + esp_zb_zdo_device_bind_req(&bind_req, ZigbeeColorDimmerSwitch::bindCbWrapper, NULL); bind_req.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL; log_v("Try to bind level control of dimmable light"); - esp_zb_zdo_device_bind_req(&bind_req, bindCb, NULL); + esp_zb_zdo_device_bind_req(&bind_req, ZigbeeColorDimmerSwitch::bindCbWrapper, NULL); bind_req.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL; log_v("Try to bind color control of dimmable light"); - esp_zb_zdo_device_bind_req(&bind_req, bindCb, (void *)light); + esp_zb_zdo_device_bind_req(&bind_req, ZigbeeColorDimmerSwitch::bindCbWrapper, this); } else { - log_v("No color dimmable light endpoint found"); + log_d("No color dimmable light endpoint found"); } } @@ -70,13 +91,13 @@ void ZigbeeColorDimmerSwitch::findEndpoint(esp_zb_zdo_match_desc_req_param_t *cm .num_out_clusters = 3, .cluster_list = cluster_list, }; - esp_zb_zdo_match_cluster(&color_dimmable_light_req, findCb, &_endpoint); + esp_zb_zdo_match_cluster(&color_dimmable_light_req, ZigbeeColorDimmerSwitch::findCbWrapper, this); } // Methods to control the light void ZigbeeColorDimmerSwitch::lightToggle() { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID; @@ -91,7 +112,7 @@ void ZigbeeColorDimmerSwitch::lightToggle() { void ZigbeeColorDimmerSwitch::lightToggle(uint16_t group_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; @@ -107,7 +128,7 @@ void ZigbeeColorDimmerSwitch::lightToggle(uint16_t group_addr) { void ZigbeeColorDimmerSwitch::lightToggle(uint8_t endpoint, uint16_t short_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; @@ -124,7 +145,7 @@ void ZigbeeColorDimmerSwitch::lightToggle(uint8_t endpoint, uint16_t short_addr) void ZigbeeColorDimmerSwitch::lightToggle(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; @@ -144,7 +165,7 @@ void ZigbeeColorDimmerSwitch::lightToggle(uint8_t endpoint, esp_zb_ieee_addr_t i void ZigbeeColorDimmerSwitch::lightOn() { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_ON_ID; @@ -159,7 +180,7 @@ void ZigbeeColorDimmerSwitch::lightOn() { void ZigbeeColorDimmerSwitch::lightOn(uint16_t group_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; @@ -175,7 +196,7 @@ void ZigbeeColorDimmerSwitch::lightOn(uint16_t group_addr) { void ZigbeeColorDimmerSwitch::lightOn(uint8_t endpoint, uint16_t short_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; @@ -192,7 +213,7 @@ void ZigbeeColorDimmerSwitch::lightOn(uint8_t endpoint, uint16_t short_addr) { void ZigbeeColorDimmerSwitch::lightOn(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; @@ -212,7 +233,7 @@ void ZigbeeColorDimmerSwitch::lightOn(uint8_t endpoint, esp_zb_ieee_addr_t ieee_ void ZigbeeColorDimmerSwitch::lightOff() { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_OFF_ID; @@ -227,7 +248,7 @@ void ZigbeeColorDimmerSwitch::lightOff() { void ZigbeeColorDimmerSwitch::lightOff(uint16_t group_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; @@ -243,7 +264,7 @@ void ZigbeeColorDimmerSwitch::lightOff(uint16_t group_addr) { void ZigbeeColorDimmerSwitch::lightOff(uint8_t endpoint, uint16_t short_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; @@ -260,7 +281,7 @@ void ZigbeeColorDimmerSwitch::lightOff(uint8_t endpoint, uint16_t short_addr) { void ZigbeeColorDimmerSwitch::lightOff(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; @@ -280,7 +301,7 @@ void ZigbeeColorDimmerSwitch::lightOff(uint8_t endpoint, esp_zb_ieee_addr_t ieee void ZigbeeColorDimmerSwitch::lightOffWithEffect(uint8_t effect_id, uint8_t effect_variant) { if (_is_bound) { - esp_zb_zcl_on_off_off_with_effect_cmd_t cmd_req; + esp_zb_zcl_on_off_off_with_effect_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.effect_id = effect_id; @@ -296,7 +317,7 @@ void ZigbeeColorDimmerSwitch::lightOffWithEffect(uint8_t effect_id, uint8_t effe void ZigbeeColorDimmerSwitch::lightOnWithSceneRecall() { if (_is_bound) { - esp_zb_zcl_on_off_on_with_recall_global_scene_cmd_t cmd_req; + esp_zb_zcl_on_off_on_with_recall_global_scene_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; log_v("Sending 'light on with scene recall' command"); @@ -310,7 +331,7 @@ void ZigbeeColorDimmerSwitch::lightOnWithSceneRecall() { void ZigbeeColorDimmerSwitch::lightOnWithTimedOff(uint8_t on_off_control, uint16_t time_on, uint16_t time_off) { if (_is_bound) { - esp_zb_zcl_on_off_on_with_timed_off_cmd_t cmd_req; + esp_zb_zcl_on_off_on_with_timed_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.on_off_control = on_off_control; //TODO: Test how it works, then maybe change API @@ -327,7 +348,7 @@ void ZigbeeColorDimmerSwitch::lightOnWithTimedOff(uint8_t on_off_control, uint16 void ZigbeeColorDimmerSwitch::setLightLevel(uint8_t level) { if (_is_bound) { - esp_zb_zcl_move_to_level_cmd_t cmd_req; + esp_zb_zcl_move_to_level_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.level = level; @@ -343,7 +364,7 @@ void ZigbeeColorDimmerSwitch::setLightLevel(uint8_t level) { void ZigbeeColorDimmerSwitch::setLightLevel(uint8_t level, uint16_t group_addr) { if (_is_bound) { - esp_zb_zcl_move_to_level_cmd_t cmd_req; + esp_zb_zcl_move_to_level_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; @@ -360,7 +381,7 @@ void ZigbeeColorDimmerSwitch::setLightLevel(uint8_t level, uint16_t group_addr) void ZigbeeColorDimmerSwitch::setLightLevel(uint8_t level, uint8_t endpoint, uint16_t short_addr) { if (_is_bound) { - esp_zb_zcl_move_to_level_cmd_t cmd_req; + esp_zb_zcl_move_to_level_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; @@ -378,7 +399,7 @@ void ZigbeeColorDimmerSwitch::setLightLevel(uint8_t level, uint8_t endpoint, uin void ZigbeeColorDimmerSwitch::setLightLevel(uint8_t level, uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { if (_is_bound) { - esp_zb_zcl_move_to_level_cmd_t cmd_req; + esp_zb_zcl_move_to_level_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; @@ -401,7 +422,7 @@ void ZigbeeColorDimmerSwitch::setLightColor(uint8_t red, uint8_t green, uint8_t if (_is_bound) { espXyColor_t xy_color = espRgbToXYColor(red, green, blue); - esp_zb_zcl_color_move_to_color_cmd_t cmd_req; + esp_zb_zcl_color_move_to_color_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.color_x = xy_color.x; @@ -420,7 +441,7 @@ void ZigbeeColorDimmerSwitch::setLightColor(uint8_t red, uint8_t green, uint8_t if (_is_bound) { espXyColor_t xy_color = espRgbToXYColor(red, green, blue); - esp_zb_zcl_color_move_to_color_cmd_t cmd_req; + esp_zb_zcl_color_move_to_color_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; @@ -440,7 +461,7 @@ void ZigbeeColorDimmerSwitch::setLightColor(uint8_t red, uint8_t green, uint8_t if (_is_bound) { espXyColor_t xy_color = espRgbToXYColor(red, green, blue); - esp_zb_zcl_color_move_to_color_cmd_t cmd_req; + esp_zb_zcl_color_move_to_color_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; @@ -461,7 +482,7 @@ void ZigbeeColorDimmerSwitch::setLightColor(uint8_t red, uint8_t green, uint8_t if (_is_bound) { espXyColor_t xy_color = espRgbToXYColor(red, green, blue); - esp_zb_zcl_color_move_to_color_cmd_t cmd_req; + esp_zb_zcl_color_move_to_color_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; diff --git a/libraries/Zigbee/src/ep/ZigbeeColorDimmerSwitch.h b/libraries/Zigbee/src/ep/ZigbeeColorDimmerSwitch.h index dbe50a20230..ada1f75fbb4 100644 --- a/libraries/Zigbee/src/ep/ZigbeeColorDimmerSwitch.h +++ b/libraries/Zigbee/src/ep/ZigbeeColorDimmerSwitch.h @@ -47,10 +47,13 @@ class ZigbeeColorDimmerSwitch : public ZigbeeEP { private: // save instance of the class in order to use it in static functions static ZigbeeColorDimmerSwitch *_instance; + zb_device_params_t *_device; void findEndpoint(esp_zb_zdo_match_desc_req_param_t *cmd_req); - static void bindCb(esp_zb_zdp_status_t zdo_status, void *user_ctx); - static void findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx); + void bindCb(esp_zb_zdp_status_t zdo_status, void *user_ctx); + void findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx); + static void bindCbWrapper(esp_zb_zdp_status_t zdo_status, void *user_ctx); + static void findCbWrapper(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx); void calculateXY(uint8_t red, uint8_t green, uint8_t blue, uint16_t &x, uint16_t &y); }; diff --git a/libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.cpp b/libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.cpp new file mode 100644 index 00000000000..8fa456c967a --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.cpp @@ -0,0 +1,979 @@ +#include "ZigbeeElectricalMeasurement.h" +#if CONFIG_ZB_ENABLED + +// Workaround for wrong name in ZCL header +#define ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_ID ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DCPOWER_ID + +esp_zb_cluster_list_t *zigbee_electrical_measurement_clusters_create(zigbee_electrical_measurement_cfg_t *electrical_measurement) { + esp_zb_basic_cluster_cfg_t *basic_cfg = electrical_measurement ? &(electrical_measurement->basic_cfg) : NULL; + esp_zb_identify_cluster_cfg_t *identify_cfg = electrical_measurement ? &(electrical_measurement->identify_cfg) : NULL; + esp_zb_electrical_meas_cluster_cfg_t *electrical_measurement_cfg = electrical_measurement ? &(electrical_measurement->electrical_measurement_cfg) : NULL; + esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create(); + esp_zb_cluster_list_add_basic_cluster(cluster_list, esp_zb_basic_cluster_create(basic_cfg), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_identify_cluster_create(identify_cfg), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_cluster_list_add_electrical_meas_cluster( + cluster_list, esp_zb_electrical_meas_cluster_create(electrical_measurement_cfg), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE + ); + return cluster_list; +} + +ZigbeeElectricalMeasurement::ZigbeeElectricalMeasurement(uint8_t endpoint) : ZigbeeEP(endpoint) { + _device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID; + + //Create custom pressure sensor configuration + zigbee_electrical_measurement_cfg_t electrical_measurement_cfg = ZIGBEE_DEFAULT_ELECTRICAL_MEASUREMENT_CONFIG(); + _cluster_list = zigbee_electrical_measurement_clusters_create(&electrical_measurement_cfg); + + _ep_config = { + .endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_METER_INTERFACE_DEVICE_ID, .app_device_version = 0 + }; +} + +/* DC MEASUREMENT */ + +bool ZigbeeElectricalMeasurement::addDCMeasurement(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type) { + esp_zb_attribute_list_t *electrical_measurement_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + + // Set the DC measurement type bit in the measurement type attribute + measure_type |= ESP_ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_MEASUREMENT; + esp_zb_cluster_update_attr(electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASUREMENT_TYPE_ID, &measure_type); + + int16_t default_min = -32767; + int16_t default_max = 32767; + int16_t default_measurement = 0; + uint16_t default_multiplier = 1; + uint16_t default_divisor = 1; + + esp_err_t ret = ESP_OK; + // Add the DC Voltage attributes + if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_VOLTAGE) { + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_ID, (void *)&default_measurement + ); + if (ret != ESP_OK) { + log_e("Failed to add DC voltage: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = + esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MIN_ID, (void *)&default_min); + if (ret != ESP_OK) { + log_e("Failed to add DC voltage min: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = + esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MAX_ID, (void *)&default_max); + if (ret != ESP_OK) { + log_e("Failed to add DC voltage max: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MULTIPLIER_ID, (void *)&default_multiplier + ); + if (ret != ESP_OK) { + log_e("Failed to add DC voltage multiplier: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_DIVISOR_ID, (void *)&default_divisor + ); + if (ret != ESP_OK) { + log_e("Failed to add DC voltage divisor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + + } else if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT) { + // Add the DC Current attributes + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_ID, (void *)&default_measurement + ); + if (ret != ESP_OK) { + log_e("Failed to add DC current: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = + esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_MIN_ID, (void *)&default_min); + if (ret != ESP_OK) { + log_e("Failed to add DC current min: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = + esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_MAX_ID, (void *)&default_max); + if (ret != ESP_OK) { + log_e("Failed to add DC current max: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_MULTIPLIER_ID, (void *)&default_multiplier + ); + if (ret != ESP_OK) { + log_e("Failed to add DC current multiplier: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_DIVISOR_ID, (void *)&default_divisor + ); + if (ret != ESP_OK) { + log_e("Failed to add DC current divisor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + } else { //(measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_POWER) + // Add the DC Power attributes + ret = + esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_ID, (void *)&default_measurement); + if (ret != ESP_OK) { + log_e("Failed to add DC power: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_MIN_ID, (void *)&default_min); + if (ret != ESP_OK) { + log_e("Failed to add DC power min: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_MAX_ID, (void *)&default_max); + if (ret != ESP_OK) { + log_e("Failed to add DC power max: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_MULTIPLIER_ID, (void *)&default_multiplier + ); + if (ret != ESP_OK) { + log_e("Failed to add DC power multiplier: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_DIVISOR_ID, (void *)&default_divisor + ); + if (ret != ESP_OK) { + log_e("Failed to add DC power divisor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + } + return true; +} + +bool ZigbeeElectricalMeasurement::setDCMinMaxValue(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type, int16_t min, int16_t max) { + esp_zb_attribute_list_t *electrical_measurement_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + + esp_zb_zcl_electrical_measurement_attr_t attr_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MIN_ID; + esp_zb_zcl_electrical_measurement_attr_t attr_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MAX_ID; + if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT) { + attr_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_MIN_ID; + attr_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_MAX_ID; + } else if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_POWER) { + attr_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_MIN_ID; + attr_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_MAX_ID; + } + esp_err_t ret = ESP_OK; + ret = esp_zb_cluster_update_attr(electrical_measurement_cluster, attr_min, (void *)&min); + if (ret != ESP_OK) { + log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_cluster_update_attr(electrical_measurement_cluster, attr_max, (void *)&max); + if (ret != ESP_OK) { + log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeElectricalMeasurement::setDCMultiplierDivisor(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type, uint16_t multiplier, uint16_t divisor) { + esp_zb_attribute_list_t *electrical_measurement_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + + esp_zb_zcl_electrical_measurement_attr_t attr_multiplier = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MULTIPLIER_ID; + esp_zb_zcl_electrical_measurement_attr_t attr_divisor = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_DIVISOR_ID; + + if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT) { + attr_multiplier = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_MULTIPLIER_ID; + attr_divisor = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_DIVISOR_ID; + } else if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_POWER) { + attr_multiplier = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_MULTIPLIER_ID; + attr_divisor = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_DIVISOR_ID; + } + + esp_err_t ret = ESP_OK; + ret = esp_zb_cluster_update_attr(electrical_measurement_cluster, attr_multiplier, (void *)&multiplier); + if (ret != ESP_OK) { + log_e("Failed to set multiplier: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_cluster_update_attr(electrical_measurement_cluster, attr_divisor, (void *)&divisor); + if (ret != ESP_OK) { + log_e("Failed to set divisor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeElectricalMeasurement::setDCReporting(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type, uint16_t min_interval, uint16_t max_interval, int16_t delta) { + uint16_t attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_ID; + if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT) { + attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_ID; + } else if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_POWER) { + attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_ID; + } + + esp_zb_zcl_reporting_info_t reporting_info; + memset(&reporting_info, 0, sizeof(esp_zb_zcl_reporting_info_t)); + reporting_info.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV; + reporting_info.ep = _endpoint; + reporting_info.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT; + reporting_info.cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE; + reporting_info.attr_id = attr_id; + reporting_info.u.send_info.min_interval = min_interval; + reporting_info.u.send_info.max_interval = max_interval; + reporting_info.u.send_info.def_min_interval = min_interval; + reporting_info.u.send_info.def_max_interval = max_interval; + reporting_info.u.send_info.delta.s16 = delta; + reporting_info.dst.profile_id = ESP_ZB_AF_HA_PROFILE_ID; + reporting_info.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; + esp_zb_lock_acquire(portMAX_DELAY); + esp_err_t ret = esp_zb_zcl_update_reporting_info(&reporting_info); + esp_zb_lock_release(); + if (ret != ESP_OK) { + log_e("Failed to set reporting: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeElectricalMeasurement::setDCMeasurement(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type, int16_t measurement) { + esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS; + + esp_zb_zcl_electrical_measurement_attr_t attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_ID; + if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT) { + attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_ID; + } else if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_POWER) { + attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_ID; + } + + log_v("Updating DC measurement value..."); + /* Update DC sensor measured value */ + log_d("Setting DC measurement to %d", measurement); + esp_zb_lock_acquire(portMAX_DELAY); + ret = esp_zb_zcl_set_attribute_val(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, attr_id, &measurement, false); + esp_zb_lock_release(); + if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Failed to set DC measurement: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeElectricalMeasurement::reportDC(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type) { + uint16_t attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_ID; + if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT) { + attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_ID; + } else if (measurement_type == ZIGBEE_DC_MEASUREMENT_TYPE_POWER) { + attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_ID; + } + /* Send report attributes command */ + esp_zb_zcl_report_attr_cmd_t report_attr_cmd; + report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; + report_attr_cmd.attributeID = attr_id; + report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; + report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT; + report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; + + esp_zb_lock_acquire(portMAX_DELAY); + esp_err_t ret = esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); + esp_zb_lock_release(); + if (ret != ESP_OK) { + log_e("Failed to send DC report: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + log_v("DC report sent"); + return true; +} + +/* AC MEASUREMENT */ + +bool ZigbeeElectricalMeasurement::addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, ZIGBEE_AC_PHASE_TYPE phase_type) { + esp_zb_attribute_list_t *electrical_measurement_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + // Non phase specific dont need any bit set + break; + case ZIGBEE_AC_PHASE_TYPE_A: measure_type |= ESP_ZB_ZCL_ELECTRICAL_MEASUREMENT_PHASE_A_MEASUREMENT; break; + case ZIGBEE_AC_PHASE_TYPE_B: measure_type |= ESP_ZB_ZCL_ELECTRICAL_MEASUREMENT_PHASE_B_MEASUREMENT; break; + case ZIGBEE_AC_PHASE_TYPE_C: measure_type |= ESP_ZB_ZCL_ELECTRICAL_MEASUREMENT_PHASE_C_MEASUREMENT; break; + default: log_e("Invalid phase type"); break; + } + // Set Active measurement bit for active power and power factor, otherwise no bit needed for voltage, current + if (measurement_type == ZIGBEE_AC_MEASUREMENT_TYPE_POWER || measurement_type == ZIGBEE_AC_MEASUREMENT_TYPE_POWER_FACTOR) { + measure_type |= ESP_ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_MEASUREMENT; // Active power is used + } + // Update the measurement type attribute + esp_zb_cluster_update_attr(electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASUREMENT_TYPE_ID, &measure_type); + + // Default values for AC measurements + [[maybe_unused]] + int16_t default_ac_power_min = -32767; + [[maybe_unused]] + int16_t default_ac_power_max = 32767; + [[maybe_unused]] + int16_t default_ac_power_measurement = 0; + [[maybe_unused]] + uint16_t default_ac_min = 0x0000; + [[maybe_unused]] + uint16_t default_ac_max = 0xffff; + [[maybe_unused]] + uint16_t default_ac_measurement = 0x0000; + [[maybe_unused]] + uint16_t default_ac_multiplier = 1; + [[maybe_unused]] + uint16_t default_ac_divisor = 1; + [[maybe_unused]] + int8_t default_ac_power_factor = 100; + + esp_err_t ret = ESP_OK; + + // AC Frequency + if (measurement_type == ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY) { // No phase specific + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_ID, (void *)&default_ac_measurement + ); + if (ret != ESP_OK) { + log_e("Failed to add DC voltage: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_MIN_ID, (void *)&default_ac_min + ); + if (ret != ESP_OK) { + log_e("Failed to add DC voltage min: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_MAX_ID, (void *)&default_ac_max + ); + if (ret != ESP_OK) { + log_e("Failed to add DC voltage max: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_MULTIPLIER_ID, (void *)&default_ac_multiplier + ); + if (ret != ESP_OK) { + log_e("Failed to add DC voltage multiplier: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_DIVISOR_ID, (void *)&default_ac_divisor + ); + if (ret != ESP_OK) { + log_e("Failed to add DC voltage divisor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; + } + // Add the AC Voltage attributes + else if (measurement_type == ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE) { + esp_zb_zcl_electrical_measurement_attr_t attr_voltage = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_ID; + esp_zb_zcl_electrical_measurement_attr_t attr_voltage_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_ID; + esp_zb_zcl_electrical_measurement_attr_t attr_voltage_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_ID; + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: + // already set + break; + case ZIGBEE_AC_PHASE_TYPE_B: + attr_voltage = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHB_ID; + attr_voltage_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_PH_B_ID; + attr_voltage_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_PH_B_ID; + break; + case ZIGBEE_AC_PHASE_TYPE_C: + attr_voltage = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHC_ID; + attr_voltage_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_PH_C_ID; + attr_voltage_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_PH_C_ID; + break; + default: log_e("Invalid phase type"); return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, attr_voltage, (void *)&default_ac_measurement); + if (ret != ESP_OK) { + log_e("Failed to add AC voltage: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, attr_voltage_min, (void *)&default_ac_min); + if (ret != ESP_OK) { + log_e("Failed to add AC voltage min: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, attr_voltage_max, (void *)&default_ac_max); + if (ret != ESP_OK) { + log_e("Failed to add AC voltage max: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + if (!ac_volt_mult_div_set) { + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACVOLTAGE_MULTIPLIER_ID, (void *)&default_ac_multiplier + ); + if (ret != ESP_OK) { + log_e("Failed to add AC voltage multiplier: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACVOLTAGE_DIVISOR_ID, (void *)&default_ac_divisor + ); + if (ret != ESP_OK) { + log_e("Failed to add AC voltage divisor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ac_volt_mult_div_set = true; // Set flag to true, so we dont add the attributes again + } + } + // Add the AC Current attributes + else if (measurement_type == ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT) { + esp_zb_zcl_electrical_measurement_attr_t attr_current = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_ID; + esp_zb_zcl_electrical_measurement_attr_t attr_current_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_ID; + esp_zb_zcl_electrical_measurement_attr_t attr_current_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_ID; + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: + // already set + break; + case ZIGBEE_AC_PHASE_TYPE_B: + attr_current = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHB_ID; + attr_current_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_PH_B_ID; + attr_current_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_PH_B_ID; + break; + case ZIGBEE_AC_PHASE_TYPE_C: + attr_current = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHC_ID; + attr_current_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_PH_C_ID; + attr_current_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_PH_C_ID; + break; + default: log_e("Invalid phase type"); return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, attr_current, (void *)&default_ac_measurement); + if (ret != ESP_OK) { + log_e("Failed to add AC current: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, attr_current_min, (void *)&default_ac_min); + if (ret != ESP_OK) { + log_e("Failed to add AC current min: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, attr_current_max, (void *)&default_ac_max); + if (ret != ESP_OK) { + log_e("Failed to add AC current max: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + if (!ac_current_mult_div_set) { + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACCURRENT_MULTIPLIER_ID, (void *)&default_ac_multiplier + ); + if (ret != ESP_OK) { + log_e("Failed to add AC current multiplier: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACCURRENT_DIVISOR_ID, (void *)&default_ac_divisor + ); + if (ret != ESP_OK) { + log_e("Failed to add AC current divisor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ac_current_mult_div_set = true; // Set flag to true, so we dont add the attributes again + } + } + // Add the AC Power attributes + else if (measurement_type == ZIGBEE_AC_MEASUREMENT_TYPE_POWER) { + esp_zb_zcl_electrical_measurement_attr_t attr_power = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_ID; + esp_zb_zcl_electrical_measurement_attr_t attr_power_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_ID; + esp_zb_zcl_electrical_measurement_attr_t attr_power_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_ID; + + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: + // already set + break; + case ZIGBEE_AC_PHASE_TYPE_B: + attr_power = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHB_ID; + attr_power_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_PH_B_ID; + attr_power_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_PH_B_ID; + break; + case ZIGBEE_AC_PHASE_TYPE_C: + attr_power = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHC_ID; + attr_power_min = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_PH_C_ID; + attr_power_max = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_PH_C_ID; + break; + default: log_e("Invalid phase type"); return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, attr_power, (void *)&default_ac_measurement); + if (ret != ESP_OK) { + log_e("Failed to add AC power: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, attr_power_min, (void *)&default_ac_min); + if (ret != ESP_OK) { + log_e("Failed to add AC power min: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, attr_power_max, (void *)&default_ac_max); + if (ret != ESP_OK) { + log_e("Failed to add AC power max: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + if (!ac_power_mult_div_set) { + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACPOWER_MULTIPLIER_ID, (void *)&default_ac_multiplier + ); + if (ret != ESP_OK) { + log_e("Failed to add AC power multiplier: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr( + electrical_measurement_cluster, ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACPOWER_DIVISOR_ID, (void *)&default_ac_divisor + ); + if (ret != ESP_OK) { + log_e("Failed to add AC power divisor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ac_power_mult_div_set = true; // Set flag to true, so we dont add the attributes again + } + } else { //(measurement_type == ZIGBEE_AC_MEASUREMENT_TYPE_POWER_FACTOR) + esp_zb_zcl_electrical_measurement_attr_t attr_power_factor = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_ID; + + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: + // already set + break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_power_factor = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_PH_B_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_power_factor = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_PH_C_ID; break; + default: log_e("Invalid phase type"); return false; + } + ret = esp_zb_electrical_meas_cluster_add_attr(electrical_measurement_cluster, attr_power_factor, (void *)&default_ac_power_factor); + if (ret != ESP_OK) { + log_e("Failed to add AC power factor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + } + return true; +} + +bool ZigbeeElectricalMeasurement::setACMinMaxValue( + ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, ZIGBEE_AC_PHASE_TYPE phase_type, int32_t min_value, int32_t max_value +) { + uint16_t attr_min_id = 0; + uint16_t attr_max_id = 0; + + // Check min/max values are valid for the measurement type + switch (measurement_type) { + case ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE: + case ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT: + case ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY: + if (min_value < 0 || min_value > UINT16_MAX || max_value < 0 || max_value > UINT16_MAX) { + log_e("AC measurement min/max values must be between 0 and %u (got min=%d, max=%d)", UINT16_MAX, min_value, max_value); + return false; + } + break; + + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER: + if (min_value < INT16_MIN || min_value > INT16_MAX || max_value < INT16_MIN || max_value > INT16_MAX) { + log_e("AC power min/max values must be between %d and %d (got min=%d, max=%d)", INT16_MIN, INT16_MAX, min_value, max_value); + return false; + } + break; + + default: log_e("Invalid measurement type"); return false; + } + + [[maybe_unused]] + int16_t int16_min_value = (int16_t)min_value; + [[maybe_unused]] + int16_t int16_max_value = (int16_t)max_value; + [[maybe_unused]] + uint16_t uint16_min_value = (uint16_t)min_value; + [[maybe_unused]] + uint16_t uint16_max_value = (uint16_t)max_value; + + //TODO: Log info about min and max values for different measurement types + switch (measurement_type) { + case ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: + attr_min_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_ID; + attr_max_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_ID; + break; + case ZIGBEE_AC_PHASE_TYPE_B: + attr_min_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_PH_B_ID; + attr_max_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_PH_B_ID; + break; + case ZIGBEE_AC_PHASE_TYPE_C: + attr_min_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_PH_C_ID; + attr_max_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_PH_C_ID; + break; + default: log_e("Invalid phase type"); return false; + } + break; + + case ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: + attr_min_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_ID; + attr_max_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_ID; + break; + case ZIGBEE_AC_PHASE_TYPE_B: + attr_min_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_PH_B_ID; + attr_max_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_PH_B_ID; + break; + case ZIGBEE_AC_PHASE_TYPE_C: + attr_min_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_PH_C_ID; + attr_max_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_PH_C_ID; + break; + default: log_e("Invalid phase type"); return false; + } + break; + + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: + attr_min_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_ID; + attr_max_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_ID; + break; + case ZIGBEE_AC_PHASE_TYPE_B: + attr_min_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_PH_B_ID; + attr_max_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_PH_B_ID; + break; + case ZIGBEE_AC_PHASE_TYPE_C: + attr_min_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_PH_C_ID; + attr_max_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_PH_C_ID; + break; + default: log_e("Invalid phase type"); return false; + } + break; + + default: log_e("Invalid measurement type"); return false; + } + esp_zb_attribute_list_t *electrical_measurement_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + + esp_err_t ret = ESP_OK; + ret = esp_zb_cluster_update_attr(electrical_measurement_cluster, attr_min_id, (void *)&min_value); + if (ret != ESP_OK) { + log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_cluster_update_attr(electrical_measurement_cluster, attr_max_id, (void *)&max_value); + if (ret != ESP_OK) { + log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeElectricalMeasurement::setACMultiplierDivisor(ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, uint16_t multiplier, uint16_t divisor) { + uint16_t attr_multiplier = 0; + uint16_t attr_divisor = 0; + + switch (measurement_type) { + case ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE: + attr_multiplier = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACVOLTAGE_MULTIPLIER_ID; + attr_divisor = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACVOLTAGE_DIVISOR_ID; + break; + case ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT: + attr_multiplier = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACCURRENT_MULTIPLIER_ID; + attr_divisor = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACCURRENT_DIVISOR_ID; + break; + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER: + attr_multiplier = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACPOWER_MULTIPLIER_ID; + attr_divisor = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACPOWER_DIVISOR_ID; + break; + case ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY: + attr_multiplier = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_MULTIPLIER_ID; + attr_divisor = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_DIVISOR_ID; + break; + default: log_e("Invalid measurement type"); return false; + } + esp_zb_attribute_list_t *electrical_measurement_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + + esp_err_t ret = ESP_OK; + ret = esp_zb_cluster_update_attr(electrical_measurement_cluster, attr_multiplier, (void *)&multiplier); + if (ret != ESP_OK) { + log_e("Failed to set multiplier: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_cluster_update_attr(electrical_measurement_cluster, attr_divisor, (void *)&divisor); + if (ret != ESP_OK) { + log_e("Failed to set divisor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeElectricalMeasurement::setACPowerFactor(ZIGBEE_AC_PHASE_TYPE phase_type, int8_t power_factor) { + uint16_t attr_id = 0; + + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_PH_B_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_PH_C_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + + esp_zb_attribute_list_t *electrical_measurement_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + + esp_err_t ret = ESP_OK; + ret = esp_zb_cluster_update_attr(electrical_measurement_cluster, attr_id, (void *)&power_factor); + if (ret != ESP_OK) { + log_e("Failed to set power factor: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} +bool ZigbeeElectricalMeasurement::setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, ZIGBEE_AC_PHASE_TYPE phase_type, int32_t value) { + esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS; + uint16_t attr_id = 0; + + // Check value is valid for the measurement type + switch (measurement_type) { + case ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE: + case ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT: + case ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY: + if (value < 0 || value > UINT16_MAX) { + log_e("AC measurement value must be between 0 and %u (got %d)", UINT16_MAX, value); + return false; + } + break; + + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER: + if (value < INT16_MIN || value > INT16_MAX) { + log_e("AC power value must be between %d and %d (got %d)", INT16_MIN, INT16_MAX, value); + return false; + } + break; + + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER_FACTOR: + if (value < -100 || value > 100) { + log_e("AC power factor value must be between -100 and 100 (got %d)", value); + return false; + } + break; + + default: log_e("Invalid measurement type"); return false; + } + // Convert value to appropriate type based on measurement type + uint16_t uint16_value = (uint16_t)value; + int16_t int16_value = (int16_t)value; + int8_t int8_value = (int8_t)value; + + switch (measurement_type) { + case ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHB_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHC_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + // Use uint16_t for voltage + log_v("Updating AC voltage measurement value..."); + log_d("Setting AC voltage to %u", uint16_value); + esp_zb_lock_acquire(portMAX_DELAY); + ret = + esp_zb_zcl_set_attribute_val(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, attr_id, &uint16_value, false); + esp_zb_lock_release(); + break; + + case ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHB_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHC_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + // Use uint16_t for current + log_v("Updating AC current measurement value..."); + log_d("Setting AC current to %u", uint16_value); + esp_zb_lock_acquire(portMAX_DELAY); + ret = + esp_zb_zcl_set_attribute_val(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, attr_id, &uint16_value, false); + esp_zb_lock_release(); + break; + + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHB_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHC_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + // Use int16_t for power + log_v("Updating AC power measurement value..."); + log_d("Setting AC power to %d", int16_value); + esp_zb_lock_acquire(portMAX_DELAY); + ret = esp_zb_zcl_set_attribute_val(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, attr_id, &int16_value, false); + esp_zb_lock_release(); + break; + + case ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY: + attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_ID; + // Use uint16_t for frequency + log_v("Updating AC frequency measurement value..."); + log_d("Setting AC frequency to %u", uint16_value); + esp_zb_lock_acquire(portMAX_DELAY); + ret = + esp_zb_zcl_set_attribute_val(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, attr_id, &uint16_value, false); + esp_zb_lock_release(); + break; + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER_FACTOR: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_PH_B_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_PH_C_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + // Use int8_t for power factor + log_v("Updating AC power factor measurement value..."); + log_d("Setting AC power factor to %d", int8_value); + esp_zb_lock_acquire(portMAX_DELAY); + ret = esp_zb_zcl_set_attribute_val(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, attr_id, &int8_value, false); + esp_zb_lock_release(); + break; + default: log_e("Invalid measurement type"); return false; + } + + if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Failed to set AC measurement: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeElectricalMeasurement::setACReporting( + ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, ZIGBEE_AC_PHASE_TYPE phase_type, uint16_t min_interval, uint16_t max_interval, int32_t delta +) { + uint16_t attr_id = 0; + + // Convert value to appropriate type based on measurement type + uint16_t uint16_delta = (uint16_t)delta; + int16_t int16_delta = (int16_t)delta; + + switch (measurement_type) { + case ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHB_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHC_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + break; + case ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHB_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHC_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + break; + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHB_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHC_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + break; + case ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_ID; break; + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER_FACTOR: log_e("Power factor attribute reporting not supported by zigbee specification"); return false; + default: log_e("Invalid measurement type"); return false; + } + + esp_zb_zcl_reporting_info_t reporting_info; + memset(&reporting_info, 0, sizeof(esp_zb_zcl_reporting_info_t)); + reporting_info.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV; + reporting_info.ep = _endpoint; + reporting_info.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT; + reporting_info.cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE; + reporting_info.attr_id = attr_id; + reporting_info.u.send_info.min_interval = min_interval; + reporting_info.u.send_info.max_interval = max_interval; + reporting_info.u.send_info.def_min_interval = min_interval; + reporting_info.u.send_info.def_max_interval = max_interval; + if (measurement_type == ZIGBEE_AC_MEASUREMENT_TYPE_POWER) { + reporting_info.u.send_info.delta.s16 = int16_delta; + } else { + reporting_info.u.send_info.delta.u16 = uint16_delta; + } + reporting_info.dst.profile_id = ESP_ZB_AF_HA_PROFILE_ID; + reporting_info.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; + esp_zb_lock_acquire(portMAX_DELAY); + esp_err_t ret = esp_zb_zcl_update_reporting_info(&reporting_info); + esp_zb_lock_release(); + if (ret != ESP_OK) { + log_e("Failed to set reporting: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeeElectricalMeasurement::reportAC(ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, ZIGBEE_AC_PHASE_TYPE phase_type) { + uint16_t attr_id = 0; + + switch (measurement_type) { + case ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHB_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHC_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + break; + case ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHB_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHC_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + break; + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER: + switch (phase_type) { + case ZIGBEE_AC_PHASE_TYPE_A: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_ID; break; + case ZIGBEE_AC_PHASE_TYPE_B: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHB_ID; break; + case ZIGBEE_AC_PHASE_TYPE_C: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHC_ID; break; + case ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC: + default: log_e("Invalid phase type"); return false; + } + break; + case ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY: attr_id = ESP_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_ID; break; + case ZIGBEE_AC_MEASUREMENT_TYPE_POWER_FACTOR: log_e("Power factor attribute reporting not supported by zigbee specification"); return false; + default: log_e("Invalid measurement type"); return false; + } + /* Send report attributes command */ + esp_zb_zcl_report_attr_cmd_t report_attr_cmd; + report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; + report_attr_cmd.attributeID = attr_id; + report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; + report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT; + report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; + + esp_zb_lock_acquire(portMAX_DELAY); + esp_err_t ret = esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); + esp_zb_lock_release(); + if (ret != ESP_OK) { + log_e("Failed to send AC report: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + log_v("AC report sent"); + return true; +} + +#endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.h b/libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.h new file mode 100644 index 00000000000..74d4a718fe2 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.h @@ -0,0 +1,105 @@ +/* Class of Zigbee Pressure sensor endpoint inherited from common EP class */ + +#pragma once + +#include "soc/soc_caps.h" +#include "sdkconfig.h" +#if CONFIG_ZB_ENABLED + +#include "ZigbeeEP.h" +#include "ha/esp_zigbee_ha_standard.h" + +// clang-format off +#define ZIGBEE_DEFAULT_ELECTRICAL_MEASUREMENT_CONFIG() \ + { \ + .basic_cfg = \ + { \ + .zcl_version = ESP_ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE, \ + .power_source = ESP_ZB_ZCL_BASIC_POWER_SOURCE_DEFAULT_VALUE, \ + }, \ + .identify_cfg = \ + { \ + .identify_time = ESP_ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE, \ + }, \ + .electrical_measurement_cfg = \ + { \ + .measured_type = 0x00, \ + }, \ + } +// clang-format on + +enum ZIGBEE_DC_MEASUREMENT_TYPE { + ZIGBEE_DC_MEASUREMENT_TYPE_VOLTAGE = 0x0001, + ZIGBEE_DC_MEASUREMENT_TYPE_CURRENT = 0x0002, + ZIGBEE_DC_MEASUREMENT_TYPE_POWER = 0x0003, +}; + +enum ZIGBEE_AC_MEASUREMENT_TYPE { + ZIGBEE_AC_MEASUREMENT_TYPE_VOLTAGE = 0x0001, + ZIGBEE_AC_MEASUREMENT_TYPE_CURRENT = 0x0002, + ZIGBEE_AC_MEASUREMENT_TYPE_POWER = 0x0003, + ZIGBEE_AC_MEASUREMENT_TYPE_POWER_FACTOR = 0x0004, + ZIGBEE_AC_MEASUREMENT_TYPE_FREQUENCY = 0x0005, +}; + +enum ZIGBEE_AC_PHASE_TYPE { + ZIGBEE_AC_PHASE_TYPE_NON_SPECIFIC = 0x0000, + ZIGBEE_AC_PHASE_TYPE_A = 0x0001, + ZIGBEE_AC_PHASE_TYPE_B = 0x0002, + ZIGBEE_AC_PHASE_TYPE_C = 0x0003, +}; + +typedef struct zigbee_electrical_measurement_cfg_s { + esp_zb_basic_cluster_cfg_t basic_cfg; + esp_zb_identify_cluster_cfg_t identify_cfg; + esp_zb_electrical_meas_cluster_cfg_t electrical_measurement_cfg; +} zigbee_electrical_measurement_cfg_t; + +class ZigbeeElectricalMeasurement : public ZigbeeEP { +public: + ZigbeeElectricalMeasurement(uint8_t endpoint); + ~ZigbeeElectricalMeasurement() {} + + /** + * @brief DC measurement methods + */ + // Add a DC measurement type + bool addDCMeasurement(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type); + // Set the DC measurement value for the given measurement type + bool setDCMeasurement(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type, int16_t value); + // Set the DC min and max value for the given measurement type + bool setDCMinMaxValue(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type, int16_t min, int16_t max); + // Set the DC multiplier and divisor for the given measurement type + bool setDCMultiplierDivisor(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type, uint16_t multiplier, uint16_t divisor); + // Set the DC reporting interval for the given measurement type in seconds and delta (measurement change) + bool setDCReporting(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type, uint16_t min_interval, uint16_t max_interval, int16_t delta); + // Report the DC measurement value for the given measurement type + bool reportDC(ZIGBEE_DC_MEASUREMENT_TYPE measurement_type); + + /** + * @brief AC measurement methods + */ + // Add an AC measurement type for selected phase type + bool addACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, ZIGBEE_AC_PHASE_TYPE phase_type); + // Set the AC measurement value for the given measurement type and phase type (uint16_t for voltage, current and frequency, int32_t for power) + bool setACMeasurement(ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, ZIGBEE_AC_PHASE_TYPE phase_type, int32_t value); + // Set the AC min and max value for the given measurement type and phase type (uint16_t for voltage, current and frequency, int32_t for power) + bool setACMinMaxValue(ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, ZIGBEE_AC_PHASE_TYPE phase_type, int32_t min, int32_t max); + // Set the AC multiplier and divisor for the given measurement type (common for all phases) + bool setACMultiplierDivisor(ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, uint16_t multiplier, uint16_t divisor); + // Set the AC power factor for the given phase type (-100 to 100 %) + bool setACPowerFactor(ZIGBEE_AC_PHASE_TYPE phase_type, int8_t power_factor); + // Set the AC reporting interval for the given measurement type and phase type in seconds and delta (measurement change - uint16_t for voltage, current and frequency, int32_t for power) + bool + setACReporting(ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, ZIGBEE_AC_PHASE_TYPE phase_type, uint16_t min_interval, uint16_t max_interval, int32_t delta); + // Report the AC measurement value for the given measurement type and phase type + bool reportAC(ZIGBEE_AC_MEASUREMENT_TYPE measurement_type, ZIGBEE_AC_PHASE_TYPE phase_type); + +private: + uint32_t measure_type = 0x0000; + bool ac_volt_mult_div_set = false; + bool ac_current_mult_div_set = false; + bool ac_power_mult_div_set = false; +}; + +#endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeePM25Sensor.cpp b/libraries/Zigbee/src/ep/ZigbeePM25Sensor.cpp new file mode 100644 index 00000000000..d25d15e5de3 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeePM25Sensor.cpp @@ -0,0 +1,118 @@ +#include "ZigbeePM25Sensor.h" +#if CONFIG_ZB_ENABLED + +esp_zb_cluster_list_t *zigbee_pm2_5_sensor_clusters_create(zigbee_pm2_5_sensor_cfg_t *pm2_5_sensor) { + esp_zb_basic_cluster_cfg_t *basic_cfg = pm2_5_sensor ? &(pm2_5_sensor->basic_cfg) : NULL; + esp_zb_identify_cluster_cfg_t *identify_cfg = pm2_5_sensor ? &(pm2_5_sensor->identify_cfg) : NULL; + esp_zb_pm2_5_measurement_cluster_cfg_t *pm2_5_meas_cfg = pm2_5_sensor ? &(pm2_5_sensor->pm2_5_meas_cfg) : NULL; + esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create(); + esp_zb_cluster_list_add_basic_cluster(cluster_list, esp_zb_basic_cluster_create(basic_cfg), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_identify_cluster_create(identify_cfg), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_cluster_list_add_pm2_5_measurement_cluster(cluster_list, esp_zb_pm2_5_measurement_cluster_create(pm2_5_meas_cfg), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + return cluster_list; +} + +ZigbeePM25Sensor::ZigbeePM25Sensor(uint8_t endpoint) : ZigbeeEP(endpoint) { + _device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID; + + //Create custom PM2.5 sensor configuration + zigbee_pm2_5_sensor_cfg_t pm2_5_sensor_cfg = ZIGBEE_DEFAULT_PM2_5_SENSOR_CONFIG(); + _cluster_list = zigbee_pm2_5_sensor_clusters_create(&pm2_5_sensor_cfg); + + _ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID, .app_device_version = 0}; +} + +bool ZigbeePM25Sensor::setMinMaxValue(float min, float max) { + esp_zb_attribute_list_t *pm2_5_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_PM2_5_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(pm2_5_measure_cluster, ESP_ZB_ZCL_ATTR_PM2_5_MEASUREMENT_MIN_MEASURED_VALUE_ID, (void *)&min); + if (ret != ESP_OK) { + log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + ret = esp_zb_cluster_update_attr(pm2_5_measure_cluster, ESP_ZB_ZCL_ATTR_PM2_5_MEASUREMENT_MAX_MEASURED_VALUE_ID, (void *)&max); + if (ret != ESP_OK) { + log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeePM25Sensor::setTolerance(float tolerance) { + esp_zb_attribute_list_t *pm2_5_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_PM2_5_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_pm2_5_measurement_cluster_add_attr(pm2_5_measure_cluster, ESP_ZB_ZCL_ATTR_PM2_5_MEASUREMENT_TOLERANCE_ID, (void *)&tolerance); + if (ret != ESP_OK) { + log_e("Failed to set tolerance: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeePM25Sensor::setReporting(uint16_t min_interval, uint16_t max_interval, float delta) { + esp_zb_zcl_reporting_info_t reporting_info; + memset(&reporting_info, 0, sizeof(esp_zb_zcl_reporting_info_t)); + reporting_info.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV; + reporting_info.ep = _endpoint; + reporting_info.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_PM2_5_MEASUREMENT; + reporting_info.cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE; + reporting_info.attr_id = ESP_ZB_ZCL_ATTR_PM2_5_MEASUREMENT_MEASURED_VALUE_ID; + reporting_info.u.send_info.min_interval = min_interval; + reporting_info.u.send_info.max_interval = max_interval; + reporting_info.u.send_info.def_min_interval = min_interval; + reporting_info.u.send_info.def_max_interval = max_interval; + // reporting_info.u.send_info.delta.u16 = (uint16_t)(delta * 100); // Convert delta to ZCL uint16_t + reporting_info.dst.profile_id = ESP_ZB_AF_HA_PROFILE_ID; + reporting_info.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; + float delta_f = delta; + memcpy(&reporting_info.u.send_info.delta.s32, &delta_f, sizeof(float)); + + esp_zb_lock_acquire(portMAX_DELAY); + esp_err_t ret = esp_zb_zcl_update_reporting_info(&reporting_info); + esp_zb_lock_release(); + if (ret != ESP_OK) { + log_e("Failed to set reporting: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeePM25Sensor::setPM25(float pm25) { + esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS; + log_v("Updating PM2.5 sensor value..."); + /* Update PM2.5 sensor measured value */ + log_d("Setting PM2.5 to %0.1f", pm25); + esp_zb_lock_acquire(portMAX_DELAY); + ret = esp_zb_zcl_set_attribute_val( + _endpoint, ESP_ZB_ZCL_CLUSTER_ID_PM2_5_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_PM2_5_MEASUREMENT_MEASURED_VALUE_ID, &pm25, false + ); + esp_zb_lock_release(); + if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Failed to set PM2.5: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret)); + return false; + } + return true; +} + +bool ZigbeePM25Sensor::report() { + /* Send report attributes command */ + esp_zb_zcl_report_attr_cmd_t report_attr_cmd; + report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; + report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_PM2_5_MEASUREMENT_MEASURED_VALUE_ID; + report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI; + report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_PM2_5_MEASUREMENT; + report_attr_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC; + + esp_zb_lock_acquire(portMAX_DELAY); + esp_err_t ret = esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); + esp_zb_lock_release(); + if (ret != ESP_OK) { + log_e("Failed to send PM2.5 report: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + log_v("PM2.5 report sent"); + return true; +} + +#endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeePM25Sensor.h b/libraries/Zigbee/src/ep/ZigbeePM25Sensor.h new file mode 100644 index 00000000000..344f3e1f479 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeePM25Sensor.h @@ -0,0 +1,60 @@ +/* Class of Zigbee PM2.5 sensor endpoint inherited from common EP class */ + +#pragma once + +#include "soc/soc_caps.h" +#include "sdkconfig.h" +#if CONFIG_ZB_ENABLED + +#include "ZigbeeEP.h" +#include "ha/esp_zigbee_ha_standard.h" + +// clang-format off +#define ZIGBEE_DEFAULT_PM2_5_SENSOR_CONFIG() \ + { \ + .basic_cfg = \ + { \ + .zcl_version = ESP_ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE, \ + .power_source = ESP_ZB_ZCL_BASIC_POWER_SOURCE_DEFAULT_VALUE, \ + }, \ + .identify_cfg = \ + { \ + .identify_time = ESP_ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE, \ + }, \ + .pm2_5_meas_cfg = \ + { \ + .measured_value = 0.0, \ + .min_measured_value = 0.0, \ + .max_measured_value = 500.0, \ + }, \ + } +// clang-format on + +typedef struct zigbee_pm2_5_sensor_cfg_s { + esp_zb_basic_cluster_cfg_t basic_cfg; + esp_zb_identify_cluster_cfg_t identify_cfg; + esp_zb_pm2_5_measurement_cluster_cfg_t pm2_5_meas_cfg; +} zigbee_pm2_5_sensor_cfg_t; + +class ZigbeePM25Sensor : public ZigbeeEP { +public: + ZigbeePM25Sensor(uint8_t endpoint); + ~ZigbeePM25Sensor() {} + + // Set the PM2.5 value in 0.1 µg/m³ + bool setPM25(float pm25); + + // Set the min and max value for the PM2.5 sensor in 0.1 µg/m³ + bool setMinMaxValue(float min, float max); + + // Set the tolerance value for the PM2.5 sensor in 0.1 µg/m³ + bool setTolerance(float tolerance); + + // Set the reporting interval for PM2.5 measurement in seconds and delta (PM2.5 change in 0.1 µg/m³) + bool setReporting(uint16_t min_interval, uint16_t max_interval, float delta); + + // Report the PM2.5 value + bool report(); +}; + +#endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeePowerOutlet.cpp b/libraries/Zigbee/src/ep/ZigbeePowerOutlet.cpp new file mode 100644 index 00000000000..b96ba672c04 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeePowerOutlet.cpp @@ -0,0 +1,58 @@ +#include "ZigbeePowerOutlet.h" +#if CONFIG_ZB_ENABLED + +ZigbeePowerOutlet::ZigbeePowerOutlet(uint8_t endpoint) : ZigbeeEP(endpoint) { + _device_id = ESP_ZB_HA_MAINS_POWER_OUTLET_DEVICE_ID; + + esp_zb_mains_power_outlet_cfg_t outlet_cfg = ESP_ZB_DEFAULT_MAINS_POWER_OUTLET_CONFIG(); + _cluster_list = esp_zb_mains_power_outlet_clusters_create(&outlet_cfg); + _ep_config = { + .endpoint = endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_MAINS_POWER_OUTLET_DEVICE_ID, .app_device_version = 0 + }; + log_v("Outlet endpoint created %d", _endpoint); +} + +//set attribute method -> method overridden in child class +void ZigbeePowerOutlet::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) { + //check the data and call right method + if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) { + if (message->attribute.id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_BOOL) { + _current_state = *(bool *)message->attribute.data.value; + stateChanged(); + } else { + log_w("Received message ignored. Attribute ID: %d not supported for On/Off Outlet", message->attribute.id); + } + } else { + log_w("Received message ignored. Cluster ID: %d not supported for On/Off Outlet", message->info.cluster); + } +} + +void ZigbeePowerOutlet::stateChanged() { + if (_on_state_change) { + _on_state_change(_current_state); + } else { + log_w("No callback function set for outlet change"); + } +} + +bool ZigbeePowerOutlet::setState(bool state) { + esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS; + _current_state = state; + stateChanged(); + + log_v("Updating on/off outlet state to %d", state); + /* Update on/off outlet state */ + esp_zb_lock_acquire(portMAX_DELAY); + ret = esp_zb_zcl_set_attribute_val( + _endpoint, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID, &_current_state, false + ); + esp_zb_lock_release(); + + if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Failed to set outlet state: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret)); + return false; + } + return true; +} + +#endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeePowerOutlet.h b/libraries/Zigbee/src/ep/ZigbeePowerOutlet.h new file mode 100644 index 00000000000..1ddb19587c7 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeePowerOutlet.h @@ -0,0 +1,41 @@ +/* Class of Zigbee On/Off Power outlet endpoint inherited from common EP class */ + +#pragma once + +#include "soc/soc_caps.h" +#include "sdkconfig.h" +#if CONFIG_ZB_ENABLED + +#include "ZigbeeEP.h" +#include "ha/esp_zigbee_ha_standard.h" + +class ZigbeePowerOutlet : public ZigbeeEP { +public: + ZigbeePowerOutlet(uint8_t endpoint); + ~ZigbeePowerOutlet() {} + + // Use to set a cb function to be called on outlet change + void onPowerOutletChange(void (*callback)(bool)) { + _on_state_change = callback; + } + // Use to restore outlet state + void restoreState() { + stateChanged(); + } + // Use to control outlet state + bool setState(bool state); + // Use to get outlet state + bool getPowerOutletState() { + return _current_state; + } + +private: + void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) override; + //callback function to be called on outlet change + void (*_on_state_change)(bool); + void stateChanged(); + + bool _current_state; +}; + +#endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeeSwitch.cpp b/libraries/Zigbee/src/ep/ZigbeeSwitch.cpp index 86c68ae1870..68e7a7430cc 100644 --- a/libraries/Zigbee/src/ep/ZigbeeSwitch.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeSwitch.cpp @@ -7,6 +7,7 @@ ZigbeeSwitch *ZigbeeSwitch::_instance = nullptr; ZigbeeSwitch::ZigbeeSwitch(uint8_t endpoint) : ZigbeeEP(endpoint) { _device_id = ESP_ZB_HA_ON_OFF_SWITCH_DEVICE_ID; _instance = this; // Set the static pointer to this instance + _device = nullptr; esp_zb_on_off_switch_cfg_t switch_cfg = ESP_ZB_DEFAULT_ON_OFF_SWITCH_CONFIG(); _cluster_list = esp_zb_on_off_switch_clusters_create(&switch_cfg); @@ -15,34 +16,62 @@ ZigbeeSwitch::ZigbeeSwitch(uint8_t endpoint) : ZigbeeEP(endpoint) { } void ZigbeeSwitch::bindCb(esp_zb_zdp_status_t zdo_status, void *user_ctx) { + ZigbeeSwitch *instance = static_cast(user_ctx); if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { log_i("Bound successfully!"); - if (user_ctx) { - zb_device_params_t *light = (zb_device_params_t *)user_ctx; + if (instance->_device) { + zb_device_params_t *light = (zb_device_params_t *)instance->_device; log_i("The light originating from address(0x%x) on endpoint(%d)", light->short_addr, light->endpoint); - _instance->_bound_devices.push_back(light); + log_d("Light bound to a switch on EP %d", instance->_endpoint); + instance->_bound_devices.push_back(light); } - _is_bound = true; + instance->_is_bound = true; + } else { + instance->_device = nullptr; + } +} + +void ZigbeeSwitch::bindCbWrapper(esp_zb_zdp_status_t zdo_status, void *user_ctx) { + ZigbeeSwitch *instance = static_cast(user_ctx); + if (instance) { + log_d("bindCbWrapper on EP %d", instance->_endpoint); + instance->bindCb(zdo_status, user_ctx); + } +} + +// Static wrapper for findCb +void ZigbeeSwitch::findCbWrapper(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) { + ZigbeeSwitch *instance = static_cast(user_ctx); + if (instance) { + log_d("findCbWrapper on EP %d", instance->_endpoint); + instance->findCb(zdo_status, addr, endpoint, user_ctx); } } void ZigbeeSwitch::findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) { + ZigbeeSwitch *instance = static_cast(user_ctx); if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { log_d("Found light endpoint"); - esp_zb_zdo_bind_req_param_t bind_req; + esp_zb_zdo_bind_req_param_t bind_req = {0}; zb_device_params_t *light = (zb_device_params_t *)malloc(sizeof(zb_device_params_t)); light->endpoint = endpoint; light->short_addr = addr; esp_zb_ieee_address_by_short(light->short_addr, light->ieee_addr); + log_d("Light found: short address(0x%x), endpoint(%d)", light->short_addr, light->endpoint); + esp_zb_get_long_address(bind_req.src_address); - bind_req.src_endp = *((uint8_t *)user_ctx); //_endpoint; + bind_req.src_endp = instance->_endpoint; bind_req.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_ON_OFF; bind_req.dst_addr_mode = ESP_ZB_ZDO_BIND_DST_ADDR_MODE_64_BIT_EXTENDED; memcpy(bind_req.dst_address_u.addr_long, light->ieee_addr, sizeof(esp_zb_ieee_addr_t)); bind_req.dst_endp = endpoint; bind_req.req_dst_addr = esp_zb_get_short_address(); - log_i("Try to bind On/Off"); - esp_zb_zdo_device_bind_req(&bind_req, bindCb, (void *)light); + log_v("Try to bind On/Off"); + //save light params in the class + instance->_device = light; + + log_d("Find callback on EP %d", instance->_endpoint); + esp_zb_zdo_device_bind_req(&bind_req, ZigbeeSwitch::bindCbWrapper, this); } else { log_d("No light endpoint found"); } @@ -59,13 +88,13 @@ void ZigbeeSwitch::findEndpoint(esp_zb_zdo_match_desc_req_param_t *cmd_req) { .num_out_clusters = 1, .cluster_list = cluster_list, }; - esp_zb_zdo_match_cluster(&on_off_req, findCb, &_endpoint); + esp_zb_zdo_match_cluster(&on_off_req, ZigbeeSwitch::findCbWrapper, this); } // Methods to control the light void ZigbeeSwitch::lightToggle() { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_TOGGLE_ID; @@ -80,7 +109,7 @@ void ZigbeeSwitch::lightToggle() { void ZigbeeSwitch::lightToggle(uint16_t group_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; @@ -96,7 +125,7 @@ void ZigbeeSwitch::lightToggle(uint16_t group_addr) { void ZigbeeSwitch::lightToggle(uint8_t endpoint, uint16_t short_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; @@ -113,7 +142,7 @@ void ZigbeeSwitch::lightToggle(uint8_t endpoint, uint16_t short_addr) { void ZigbeeSwitch::lightToggle(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; @@ -133,7 +162,7 @@ void ZigbeeSwitch::lightToggle(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { void ZigbeeSwitch::lightOn() { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_ON_ID; @@ -148,7 +177,7 @@ void ZigbeeSwitch::lightOn() { void ZigbeeSwitch::lightOn(uint16_t group_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; @@ -164,7 +193,7 @@ void ZigbeeSwitch::lightOn(uint16_t group_addr) { void ZigbeeSwitch::lightOn(uint8_t endpoint, uint16_t short_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; @@ -181,7 +210,7 @@ void ZigbeeSwitch::lightOn(uint8_t endpoint, uint16_t short_addr) { void ZigbeeSwitch::lightOn(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; @@ -201,7 +230,7 @@ void ZigbeeSwitch::lightOn(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { void ZigbeeSwitch::lightOff() { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.on_off_cmd_id = ESP_ZB_ZCL_CMD_ON_OFF_OFF_ID; @@ -216,7 +245,7 @@ void ZigbeeSwitch::lightOff() { void ZigbeeSwitch::lightOff(uint16_t group_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; @@ -232,7 +261,7 @@ void ZigbeeSwitch::lightOff(uint16_t group_addr) { void ZigbeeSwitch::lightOff(uint8_t endpoint, uint16_t short_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; @@ -249,7 +278,7 @@ void ZigbeeSwitch::lightOff(uint8_t endpoint, uint16_t short_addr) { void ZigbeeSwitch::lightOff(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { if (_is_bound) { - esp_zb_zcl_on_off_cmd_t cmd_req; + esp_zb_zcl_on_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.zcl_basic_cmd.dst_endpoint = endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; @@ -269,7 +298,7 @@ void ZigbeeSwitch::lightOff(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { void ZigbeeSwitch::lightOffWithEffect(uint8_t effect_id, uint8_t effect_variant) { if (_is_bound) { - esp_zb_zcl_on_off_off_with_effect_cmd_t cmd_req; + esp_zb_zcl_on_off_off_with_effect_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.effect_id = effect_id; @@ -285,7 +314,7 @@ void ZigbeeSwitch::lightOffWithEffect(uint8_t effect_id, uint8_t effect_variant) void ZigbeeSwitch::lightOnWithSceneRecall() { if (_is_bound) { - esp_zb_zcl_on_off_on_with_recall_global_scene_cmd_t cmd_req; + esp_zb_zcl_on_off_on_with_recall_global_scene_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; log_v("Sending 'light on with scene recall' command"); @@ -298,7 +327,7 @@ void ZigbeeSwitch::lightOnWithSceneRecall() { } void ZigbeeSwitch::lightOnWithTimedOff(uint8_t on_off_control, uint16_t time_on, uint16_t time_off) { if (_is_bound) { - esp_zb_zcl_on_off_on_with_timed_off_cmd_t cmd_req; + esp_zb_zcl_on_off_on_with_timed_off_cmd_t cmd_req = {0}; cmd_req.zcl_basic_cmd.src_endpoint = _endpoint; cmd_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; cmd_req.on_off_control = on_off_control; //TODO: Test how it works, then maybe change API diff --git a/libraries/Zigbee/src/ep/ZigbeeSwitch.h b/libraries/Zigbee/src/ep/ZigbeeSwitch.h index 5c527bec6e3..0e7011c3312 100644 --- a/libraries/Zigbee/src/ep/ZigbeeSwitch.h +++ b/libraries/Zigbee/src/ep/ZigbeeSwitch.h @@ -37,10 +37,12 @@ class ZigbeeSwitch : public ZigbeeEP { private: // save instance of the class in order to use it in static functions static ZigbeeSwitch *_instance; - + zb_device_params_t *_device; void findEndpoint(esp_zb_zdo_match_desc_req_param_t *cmd_req); - static void bindCb(esp_zb_zdp_status_t zdo_status, void *user_ctx); - static void findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx); + void bindCb(esp_zb_zdp_status_t zdo_status, void *user_ctx); + void findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx); + static void findCbWrapper(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx); + static void bindCbWrapper(esp_zb_zdp_status_t zdo_status, void *user_ctx); }; #endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeeThermostat.cpp b/libraries/Zigbee/src/ep/ZigbeeThermostat.cpp index 357bcaed1bc..f3bfd7d981b 100644 --- a/libraries/Zigbee/src/ep/ZigbeeThermostat.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeThermostat.cpp @@ -10,7 +10,8 @@ ZigbeeThermostat *ZigbeeThermostat::_instance = nullptr; ZigbeeThermostat::ZigbeeThermostat(uint8_t endpoint) : ZigbeeEP(endpoint) { _device_id = ESP_ZB_HA_THERMOSTAT_DEVICE_ID; - _instance = this; // Set the static pointer to this instance + _instance = this; // Set the static pointer to this instance + _device = nullptr; // Initialize sensor pointer to null //use custom config to avoid narrowing error -> must be fixed in zigbee-sdk esp_zb_thermostat_cfg_t thermostat_cfg = ZB_DEFAULT_THERMOSTAT_CONFIG(); @@ -29,24 +30,42 @@ ZigbeeThermostat::ZigbeeThermostat(uint8_t endpoint) : ZigbeeEP(endpoint) { } void ZigbeeThermostat::bindCb(esp_zb_zdp_status_t zdo_status, void *user_ctx) { + ZigbeeThermostat *instance = static_cast(user_ctx); if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { - if (user_ctx) { - zb_device_params_t *sensor = (zb_device_params_t *)user_ctx; - log_i("The temperature sensor originating from address(0x%x) on endpoint(%d)", sensor->short_addr, sensor->endpoint); - _instance->_bound_devices.push_back(sensor); - } else { - log_v("Local binding success"); + log_i("Bound successfully!"); + if (instance->_device) { + zb_device_params_t *sensor = (zb_device_params_t *)instance->_device; + log_i("The sensor originating from address(0x%x) on endpoint(%d)", sensor->short_addr, sensor->endpoint); + log_d("Sensor bound to thermostat on EP %d", instance->_endpoint); + instance->_bound_devices.push_back(sensor); } - _is_bound = true; + instance->_is_bound = true; } else { - log_e("Binding failed!"); + instance->_device = nullptr; + } +} + +void ZigbeeThermostat::bindCbWrapper(esp_zb_zdp_status_t zdo_status, void *user_ctx) { + ZigbeeThermostat *instance = static_cast(user_ctx); + if (instance) { + log_d("bindCbWrapper on EP %d", instance->_endpoint); + instance->bindCb(zdo_status, user_ctx); + } +} + +void ZigbeeThermostat::findCbWrapper(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) { + ZigbeeThermostat *instance = static_cast(user_ctx); + if (instance) { + log_d("findCbWrapper on EP %d", instance->_endpoint); + instance->findCb(zdo_status, addr, endpoint, user_ctx); } } void ZigbeeThermostat::findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) { + ZigbeeThermostat *instance = static_cast(user_ctx); if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { log_i("Found temperature sensor"); - esp_zb_zdo_bind_req_param_t bind_req; + esp_zb_zdo_bind_req_param_t bind_req = {0}; /* Store the information of the remote device */ zb_device_params_t *sensor = (zb_device_params_t *)malloc(sizeof(zb_device_params_t)); sensor->endpoint = endpoint; @@ -56,37 +75,34 @@ void ZigbeeThermostat::findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uin /* 1. Send binding request to the sensor */ bind_req.req_dst_addr = addr; - log_d("Request temperature sensor to bind us"); - - /* populate the src information of the binding */ memcpy(bind_req.src_address, sensor->ieee_addr, sizeof(esp_zb_ieee_addr_t)); bind_req.src_endp = endpoint; bind_req.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; - log_d("Bind temperature sensor"); - - /* populate the dst information of the binding */ bind_req.dst_addr_mode = ESP_ZB_ZDO_BIND_DST_ADDR_MODE_64_BIT_EXTENDED; esp_zb_get_long_address(bind_req.dst_address_u.addr_long); - bind_req.dst_endp = *((uint8_t *)user_ctx); //_endpoint; + bind_req.dst_endp = instance->_endpoint; log_i("Request temperature sensor to bind us"); - esp_zb_zdo_device_bind_req(&bind_req, bindCb, NULL); + esp_zb_zdo_device_bind_req(&bind_req, ZigbeeThermostat::bindCbWrapper, NULL); /* 2. Send binding request to self */ bind_req.req_dst_addr = esp_zb_get_short_address(); /* populate the src information of the binding */ esp_zb_get_long_address(bind_req.src_address); - bind_req.src_endp = *((uint8_t *)user_ctx); //_endpoint; + bind_req.src_endp = instance->_endpoint; bind_req.cluster_id = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; - - /* populate the dst information of the binding */ bind_req.dst_addr_mode = ESP_ZB_ZDO_BIND_DST_ADDR_MODE_64_BIT_EXTENDED; memcpy(bind_req.dst_address_u.addr_long, sensor->ieee_addr, sizeof(esp_zb_ieee_addr_t)); bind_req.dst_endp = endpoint; + log_i("Try to bind Temperature Measurement"); + //save sensor params in the class + instance->_device = sensor; - log_i("Bind temperature sensor"); - esp_zb_zdo_device_bind_req(&bind_req, bindCb, (void *)sensor); + log_d("Find callback on EP %d", instance->_endpoint); + esp_zb_zdo_device_bind_req(&bind_req, ZigbeeThermostat::bindCbWrapper, this); + } else { + log_d("No temperature sensor endpoint found"); } } @@ -96,34 +112,41 @@ void ZigbeeThermostat::findEndpoint(esp_zb_zdo_match_desc_req_param_t *param) { param->num_in_clusters = 1; param->num_out_clusters = 0; param->cluster_list = cluster_list; - esp_zb_zdo_match_cluster(param, findCb, &_endpoint); + esp_zb_zdo_match_cluster(param, ZigbeeThermostat::findCbWrapper, this); } -void ZigbeeThermostat::zbAttributeRead(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute) { +void ZigbeeThermostat::zbAttributeRead(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute, uint8_t src_endpoint, esp_zb_zcl_addr_t src_address) { static uint8_t read_config = 0; if (cluster_id == ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT) { if (attribute->id == ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_S16) { int16_t value = attribute->data.value ? *(int16_t *)attribute->data.value : 0; - if (_on_temp_recieve) { - _on_temp_recieve(zb_s16_to_temperature(value)); + if (_on_temp_receive) { + _on_temp_receive(zb_s16_to_temperature(value)); + } + if (_on_temp_receive_with_source) { + _on_temp_receive_with_source(zb_s16_to_temperature(value), src_endpoint, src_address); } } if (attribute->id == ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_S16) { int16_t min_value = attribute->data.value ? *(int16_t *)attribute->data.value : 0; _min_temp = zb_s16_to_temperature(min_value); read_config++; + log_d("Received min temperature: %.2f°C from endpoint %d", _min_temp, src_endpoint); } if (attribute->id == ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_S16) { int16_t max_value = attribute->data.value ? *(int16_t *)attribute->data.value : 0; _max_temp = zb_s16_to_temperature(max_value); read_config++; + log_d("Received max temperature: %.2f°C from endpoint %d", _max_temp, src_endpoint); } if (attribute->id == ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_U16) { uint16_t tolerance = attribute->data.value ? *(uint16_t *)attribute->data.value : 0; _tolerance = 1.0 * tolerance / 100; read_config++; + log_d("Received tolerance: %.2f°C from endpoint %d", _tolerance, src_endpoint); } if (read_config == 3) { + log_d("All config attributes processed"); read_config = 0; xSemaphoreGive(lock); } @@ -131,14 +154,14 @@ void ZigbeeThermostat::zbAttributeRead(uint16_t cluster_id, const esp_zb_zcl_att } void ZigbeeThermostat::getTemperature() { - /* Send "read attributes" command to the bound sensor */ - esp_zb_zcl_read_attr_cmd_t read_req; + /* Send "read attributes" command to all bound sensors */ + esp_zb_zcl_read_attr_cmd_t read_req = {0}; read_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; read_req.zcl_basic_cmd.src_endpoint = _endpoint; read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; uint16_t attributes[] = {ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID}; - read_req.attr_number = ZB_ARRAY_LENTH(attributes); + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); read_req.attr_field = attributes; log_i("Sending 'read temperature' command"); @@ -147,9 +170,68 @@ void ZigbeeThermostat::getTemperature() { esp_zb_lock_release(); } +void ZigbeeThermostat::getTemperature(uint16_t group_addr) { + /* Send "read attributes" command to the group */ + esp_zb_zcl_read_attr_cmd_t read_req = {0}; + read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; + read_req.zcl_basic_cmd.src_endpoint = _endpoint; + read_req.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; + read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + + uint16_t attributes[] = {ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID}; + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); + read_req.attr_field = attributes; + + log_i("Sending 'read temperature' command to group address 0x%x", group_addr); + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_read_attr_cmd_req(&read_req); + esp_zb_lock_release(); +} + +void ZigbeeThermostat::getTemperature(uint8_t endpoint, uint16_t short_addr) { + /* Send "read attributes" command to specific endpoint */ + esp_zb_zcl_read_attr_cmd_t read_req = {0}; + read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; + read_req.zcl_basic_cmd.src_endpoint = _endpoint; + read_req.zcl_basic_cmd.dst_endpoint = endpoint; + read_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; + read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + + uint16_t attributes[] = {ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID}; + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); + read_req.attr_field = attributes; + + log_i("Sending 'read temperature' command to endpoint %d, address 0x%x", endpoint, short_addr); + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_read_attr_cmd_req(&read_req); + esp_zb_lock_release(); +} + +void ZigbeeThermostat::getTemperature(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { + /* Send "read attributes" command to specific endpoint */ + esp_zb_zcl_read_attr_cmd_t read_req = {0}; + read_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; + read_req.zcl_basic_cmd.src_endpoint = _endpoint; + read_req.zcl_basic_cmd.dst_endpoint = endpoint; + read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + memcpy(read_req.zcl_basic_cmd.dst_addr_u.addr_long, ieee_addr, sizeof(esp_zb_ieee_addr_t)); + + uint16_t attributes[] = {ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID}; + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); + read_req.attr_field = attributes; + + log_i( + "Sending 'read temperature' command to endpoint %d, ieee address %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", endpoint, ieee_addr[7], ieee_addr[6], + ieee_addr[5], ieee_addr[4], ieee_addr[3], ieee_addr[2], ieee_addr[1], ieee_addr[0] + ); + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_read_attr_cmd_req(&read_req); + esp_zb_lock_release(); +} + void ZigbeeThermostat::getSensorSettings() { - /* Send "read attributes" command to the bound sensor */ - esp_zb_zcl_read_attr_cmd_t read_req; + /* Send "read attributes" command to all bound sensors */ + esp_zb_zcl_read_attr_cmd_t read_req = {0}; read_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; read_req.zcl_basic_cmd.src_endpoint = _endpoint; read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; @@ -157,10 +239,39 @@ void ZigbeeThermostat::getSensorSettings() { uint16_t attributes[] = { ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID }; - read_req.attr_number = ZB_ARRAY_LENTH(attributes); + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); read_req.attr_field = attributes; - log_i("Sending 'read temperature' command"); + log_i("Sending 'read sensor settings' command"); + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_read_attr_cmd_req(&read_req); + esp_zb_lock_release(); + + //Take semaphore to wait for response of all attributes + if (xSemaphoreTake(lock, ZB_CMD_TIMEOUT) != pdTRUE) { + log_e("Error while reading attributes"); + return; + } else { + //Call the callback function when all attributes are read + _on_config_receive(_min_temp, _max_temp, _tolerance); + } +} + +void ZigbeeThermostat::getSensorSettings(uint16_t group_addr) { + /* Send "read attributes" command to the group */ + esp_zb_zcl_read_attr_cmd_t read_req = {0}; + read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; + read_req.zcl_basic_cmd.src_endpoint = _endpoint; + read_req.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; + read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + + uint16_t attributes[] = { + ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID + }; + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); + read_req.attr_field = attributes; + + log_i("Sending 'read sensor settings' command to group address 0x%x", group_addr); esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zcl_read_attr_cmd_req(&read_req); esp_zb_lock_release(); @@ -171,13 +282,76 @@ void ZigbeeThermostat::getSensorSettings() { return; } else { //Call the callback function when all attributes are read - _on_config_recieve(_min_temp, _max_temp, _tolerance); + _on_config_receive(_min_temp, _max_temp, _tolerance); + } +} + +void ZigbeeThermostat::getSensorSettings(uint8_t endpoint, uint16_t short_addr) { + /* Send "read attributes" command to specific endpoint */ + esp_zb_zcl_read_attr_cmd_t read_req = {0}; + read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; + read_req.zcl_basic_cmd.src_endpoint = _endpoint; + read_req.zcl_basic_cmd.dst_endpoint = endpoint; + read_req.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; + read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + + uint16_t attributes[] = { + ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID + }; + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); + read_req.attr_field = attributes; + + log_i("Sending 'read sensor settings' command to endpoint %d, address 0x%x", endpoint, short_addr); + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_read_attr_cmd_req(&read_req); + esp_zb_lock_release(); + + //Take semaphore to wait for response of all attributes + if (xSemaphoreTake(lock, ZB_CMD_TIMEOUT) != pdTRUE) { + log_e("Error while reading attributes"); + return; + } else { + //Call the callback function when all attributes are read + _on_config_receive(_min_temp, _max_temp, _tolerance); + } +} + +void ZigbeeThermostat::getSensorSettings(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr) { + /* Send "read attributes" command to specific endpoint */ + esp_zb_zcl_read_attr_cmd_t read_req = {0}; + read_req.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; + read_req.zcl_basic_cmd.src_endpoint = _endpoint; + read_req.zcl_basic_cmd.dst_endpoint = endpoint; + read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + memcpy(read_req.zcl_basic_cmd.dst_addr_u.addr_long, ieee_addr, sizeof(esp_zb_ieee_addr_t)); + + uint16_t attributes[] = { + ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID + }; + read_req.attr_number = ZB_ARRAY_LENGHT(attributes); + read_req.attr_field = attributes; + + log_i( + "Sending 'read sensor settings' command to endpoint %d, ieee address %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", endpoint, ieee_addr[7], ieee_addr[6], + ieee_addr[5], ieee_addr[4], ieee_addr[3], ieee_addr[2], ieee_addr[1], ieee_addr[0] + ); + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_read_attr_cmd_req(&read_req); + esp_zb_lock_release(); + + //Take semaphore to wait for response of all attributes + if (xSemaphoreTake(lock, ZB_CMD_TIMEOUT) != pdTRUE) { + log_e("Error while reading attributes"); + return; + } else { + //Call the callback function when all attributes are read + _on_config_receive(_min_temp, _max_temp, _tolerance); } } void ZigbeeThermostat::setTemperatureReporting(uint16_t min_interval, uint16_t max_interval, float delta) { - /* Send "configure report attribute" command to the bound sensor */ - esp_zb_zcl_config_report_cmd_t report_cmd; + /* Send "configure report attribute" command to all bound sensors */ + esp_zb_zcl_config_report_cmd_t report_cmd = {0}; report_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; report_cmd.zcl_basic_cmd.src_endpoint = _endpoint; report_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; @@ -190,10 +364,10 @@ void ZigbeeThermostat::setTemperatureReporting(uint16_t min_interval, uint16_t m .attrType = ESP_ZB_ZCL_ATTR_TYPE_S16, .min_interval = min_interval, .max_interval = max_interval, - .reportable_change = &report_change, + .reportable_change = (void *)&report_change, }, }; - report_cmd.record_number = ZB_ARRAY_LENTH(records); + report_cmd.record_number = ZB_ARRAY_LENGHT(records); report_cmd.record_field = records; log_i("Sending 'configure reporting' command"); @@ -202,4 +376,93 @@ void ZigbeeThermostat::setTemperatureReporting(uint16_t min_interval, uint16_t m esp_zb_lock_release(); } +void ZigbeeThermostat::setTemperatureReporting(uint16_t group_addr, uint16_t min_interval, uint16_t max_interval, float delta) { + /* Send "configure report attribute" command to the group */ + esp_zb_zcl_config_report_cmd_t report_cmd = {0}; + report_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT; + report_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_cmd.zcl_basic_cmd.dst_addr_u.addr_short = group_addr; + report_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + + int16_t report_change = (int16_t)delta * 100; + esp_zb_zcl_config_report_record_t records[] = { + { + .direction = ESP_ZB_ZCL_REPORT_DIRECTION_SEND, + .attributeID = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, + .attrType = ESP_ZB_ZCL_ATTR_TYPE_S16, + .min_interval = min_interval, + .max_interval = max_interval, + .reportable_change = (void *)&report_change, + }, + }; + report_cmd.record_number = ZB_ARRAY_LENGHT(records); + report_cmd.record_field = records; + + log_i("Sending 'configure reporting' command to group address 0x%x", group_addr); + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_config_report_cmd_req(&report_cmd); + esp_zb_lock_release(); +} + +void ZigbeeThermostat::setTemperatureReporting(uint8_t endpoint, uint16_t short_addr, uint16_t min_interval, uint16_t max_interval, float delta) { + /* Send "configure report attribute" command to specific endpoint */ + esp_zb_zcl_config_report_cmd_t report_cmd = {0}; + report_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; + report_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_cmd.zcl_basic_cmd.dst_endpoint = endpoint; + report_cmd.zcl_basic_cmd.dst_addr_u.addr_short = short_addr; + report_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + + int16_t report_change = (int16_t)delta * 100; + esp_zb_zcl_config_report_record_t records[] = { + { + .direction = ESP_ZB_ZCL_REPORT_DIRECTION_SEND, + .attributeID = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, + .attrType = ESP_ZB_ZCL_ATTR_TYPE_S16, + .min_interval = min_interval, + .max_interval = max_interval, + .reportable_change = (void *)&report_change, + }, + }; + report_cmd.record_number = ZB_ARRAY_LENGHT(records); + report_cmd.record_field = records; + + log_i("Sending 'configure reporting' command to endpoint %d, address 0x%x", endpoint, short_addr); + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_config_report_cmd_req(&report_cmd); + esp_zb_lock_release(); +} + +void ZigbeeThermostat::setTemperatureReporting(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr, uint16_t min_interval, uint16_t max_interval, float delta) { + /* Send "configure report attribute" command to specific endpoint */ + esp_zb_zcl_config_report_cmd_t report_cmd = {0}; + report_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT; + report_cmd.zcl_basic_cmd.src_endpoint = _endpoint; + report_cmd.zcl_basic_cmd.dst_endpoint = endpoint; + report_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + memcpy(report_cmd.zcl_basic_cmd.dst_addr_u.addr_long, ieee_addr, sizeof(esp_zb_ieee_addr_t)); + + int16_t report_change = (int16_t)delta * 100; + esp_zb_zcl_config_report_record_t records[] = { + { + .direction = ESP_ZB_ZCL_REPORT_DIRECTION_SEND, + .attributeID = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, + .attrType = ESP_ZB_ZCL_ATTR_TYPE_S16, + .min_interval = min_interval, + .max_interval = max_interval, + .reportable_change = (void *)&report_change, + }, + }; + report_cmd.record_number = ZB_ARRAY_LENGHT(records); + report_cmd.record_field = records; + + log_i( + "Sending 'configure reporting' command to endpoint %d, ieee address %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", endpoint, ieee_addr[7], ieee_addr[6], + ieee_addr[5], ieee_addr[4], ieee_addr[3], ieee_addr[2], ieee_addr[1], ieee_addr[0] + ); + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_config_report_cmd_req(&report_cmd); + esp_zb_lock_release(); +} + #endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeeThermostat.h b/libraries/Zigbee/src/ep/ZigbeeThermostat.h index 7895115e1d1..c10a9d7f974 100644 --- a/libraries/Zigbee/src/ep/ZigbeeThermostat.h +++ b/libraries/Zigbee/src/ep/ZigbeeThermostat.h @@ -34,32 +34,50 @@ class ZigbeeThermostat : public ZigbeeEP { ZigbeeThermostat(uint8_t endpoint); ~ZigbeeThermostat() {} - void onTempRecieve(void (*callback)(float)) { - _on_temp_recieve = callback; + void onTempReceive(void (*callback)(float)) { + _on_temp_receive = callback; } - void onConfigRecieve(void (*callback)(float, float, float)) { - _on_config_recieve = callback; + void onTempReceiveWithSource(void (*callback)(float, uint8_t, esp_zb_zcl_addr_t)) { + _on_temp_receive_with_source = callback; + } + void onConfigReceive(void (*callback)(float, float, float)) { + _on_config_receive = callback; } void getTemperature(); + void getTemperature(uint16_t group_addr); + void getTemperature(uint8_t endpoint, uint16_t short_addr); + void getTemperature(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr); + void getSensorSettings(); + void getSensorSettings(uint16_t group_addr); + void getSensorSettings(uint8_t endpoint, uint16_t short_addr); + void getSensorSettings(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr); + void setTemperatureReporting(uint16_t min_interval, uint16_t max_interval, float delta); + void setTemperatureReporting(uint16_t group_addr, uint16_t min_interval, uint16_t max_interval, float delta); + void setTemperatureReporting(uint8_t endpoint, uint16_t short_addr, uint16_t min_interval, uint16_t max_interval, float delta); + void setTemperatureReporting(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr, uint16_t min_interval, uint16_t max_interval, float delta); private: // save instance of the class in order to use it in static functions static ZigbeeThermostat *_instance; + zb_device_params_t *_device; - void (*_on_temp_recieve)(float); - void (*_on_config_recieve)(float, float, float); + void (*_on_temp_receive)(float); + void (*_on_temp_receive_with_source)(float, uint8_t, esp_zb_zcl_addr_t); + void (*_on_config_receive)(float, float, float); float _min_temp; float _max_temp; float _tolerance; void findEndpoint(esp_zb_zdo_match_desc_req_param_t *cmd_req); - static void bindCb(esp_zb_zdp_status_t zdo_status, void *user_ctx); - static void findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx); + void bindCb(esp_zb_zdp_status_t zdo_status, void *user_ctx); + void findCb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx); + static void bindCbWrapper(esp_zb_zdp_status_t zdo_status, void *user_ctx); + static void findCbWrapper(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx); - void zbAttributeRead(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute) override; + void zbAttributeRead(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute, uint8_t src_endpoint, esp_zb_zcl_addr_t src_address) override; }; #endif // CONFIG_ZB_ENABLED diff --git a/package/package_esp32_index.template.json b/package/package_esp32_index.template.json index 19254d11682..9c1516dbacd 100644 --- a/package/package_esp32_index.template.json +++ b/package/package_esp32_index.template.json @@ -51,7 +51,7 @@ { "packager": "esp32", "name": "esp32-arduino-libs", - "version": "idf-release_v5.4-2f7dcd86-v1" + "version": "idf-release_v5.4-f0f2980d-v1" }, { "packager": "esp32", @@ -76,12 +76,12 @@ { "packager": "esp32", "name": "openocd-esp32", - "version": "v0.12.0-esp32-20241016" + "version": "v0.12.0-esp32-20250422" }, { "packager": "esp32", "name": "esptool_py", - "version": "4.9.dev3" + "version": "5.0.dev1" }, { "packager": "esp32", @@ -104,63 +104,63 @@ "tools": [ { "name": "esp32-arduino-libs", - "version": "idf-release_v5.4-2f7dcd86-v1", + "version": "idf-release_v5.4-f0f2980d-v1", "systems": [ { "host": "i686-mingw32", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "checksum": "SHA-256:11f1271fe5e2857155d90384690069e4d33f0f97a4c04e7474b29a7cbc7ededd", - "size": "352347498" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "checksum": "SHA-256:b1a77c83634111d78a356f1d1756dc815eeeb91605c5d8714a0db7cccbd0bede", + "size": "353978504" }, { "host": "x86_64-mingw32", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "checksum": "SHA-256:11f1271fe5e2857155d90384690069e4d33f0f97a4c04e7474b29a7cbc7ededd", - "size": "352347498" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "checksum": "SHA-256:b1a77c83634111d78a356f1d1756dc815eeeb91605c5d8714a0db7cccbd0bede", + "size": "353978504" }, { "host": "arm64-apple-darwin", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "checksum": "SHA-256:11f1271fe5e2857155d90384690069e4d33f0f97a4c04e7474b29a7cbc7ededd", - "size": "352347498" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "checksum": "SHA-256:b1a77c83634111d78a356f1d1756dc815eeeb91605c5d8714a0db7cccbd0bede", + "size": "353978504" }, { "host": "x86_64-apple-darwin", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "checksum": "SHA-256:11f1271fe5e2857155d90384690069e4d33f0f97a4c04e7474b29a7cbc7ededd", - "size": "352347498" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "checksum": "SHA-256:b1a77c83634111d78a356f1d1756dc815eeeb91605c5d8714a0db7cccbd0bede", + "size": "353978504" }, { "host": "x86_64-pc-linux-gnu", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "checksum": "SHA-256:11f1271fe5e2857155d90384690069e4d33f0f97a4c04e7474b29a7cbc7ededd", - "size": "352347498" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "checksum": "SHA-256:b1a77c83634111d78a356f1d1756dc815eeeb91605c5d8714a0db7cccbd0bede", + "size": "353978504" }, { "host": "i686-pc-linux-gnu", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "checksum": "SHA-256:11f1271fe5e2857155d90384690069e4d33f0f97a4c04e7474b29a7cbc7ededd", - "size": "352347498" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "checksum": "SHA-256:b1a77c83634111d78a356f1d1756dc815eeeb91605c5d8714a0db7cccbd0bede", + "size": "353978504" }, { "host": "aarch64-linux-gnu", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "checksum": "SHA-256:11f1271fe5e2857155d90384690069e4d33f0f97a4c04e7474b29a7cbc7ededd", - "size": "352347498" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "checksum": "SHA-256:b1a77c83634111d78a356f1d1756dc815eeeb91605c5d8714a0db7cccbd0bede", + "size": "353978504" }, { "host": "arm-linux-gnueabihf", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-2f7dcd86-v1.zip", - "checksum": "SHA-256:11f1271fe5e2857155d90384690069e4d33f0f97a4c04e7474b29a7cbc7ededd", - "size": "352347498" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.4/esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.4-f0f2980d-v1.zip", + "checksum": "SHA-256:b1a77c83634111d78a356f1d1756dc815eeeb91605c5d8714a0db7cccbd0bede", + "size": "353978504" } ] }, @@ -414,111 +414,111 @@ }, { "name": "openocd-esp32", - "version": "v0.12.0-esp32-20241016", + "version": "v0.12.0-esp32-20250422", "systems": [ { "host": "x86_64-pc-linux-gnu", - "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20241016/openocd-esp32-linux-amd64-0.12.0-esp32-20241016.tar.gz", - "archiveFileName": "openocd-esp32-linux-amd64-0.12.0-esp32-20241016.tar.gz", - "checksum": "SHA-256:e82b0f036dc99244bead5f09a86e91bb2365cbcd1122ac68261e5647942485df", - "size": "2398717" + "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20250422/openocd-esp32-linux-amd64-0.12.0-esp32-20250422.tar.gz", + "archiveFileName": "openocd-esp32-linux-amd64-0.12.0-esp32-20250422.tar.gz", + "checksum": "SHA-256:eb1fa9b21c65b45a2200af6dcc2914e32335d37b6dbbd181778dcc0dc025e70a", + "size": "2445546" }, { "host": "aarch64-linux-gnu", - "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20241016/openocd-esp32-linux-arm64-0.12.0-esp32-20241016.tar.gz", - "archiveFileName": "openocd-esp32-linux-arm64-0.12.0-esp32-20241016.tar.gz", - "checksum": "SHA-256:8f8daf5bd22ec5d2fa9257b0862ec33da18ee677e023fb9a9eb17f74ce208c76", - "size": "2271584" + "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20250422/openocd-esp32-linux-arm64-0.12.0-esp32-20250422.tar.gz", + "archiveFileName": "openocd-esp32-linux-arm64-0.12.0-esp32-20250422.tar.gz", + "checksum": "SHA-256:f70334a9b12a75b4d943e09fa5db30973037c39dbb54d6fa9f1a7118228b3d1c", + "size": "2330926" }, { "host": "arm-linux-gnueabihf", - "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20241016/openocd-esp32-linux-armel-0.12.0-esp32-20241016.tar.gz", - "archiveFileName": "openocd-esp32-linux-armel-0.12.0-esp32-20241016.tar.gz", - "checksum": "SHA-256:bc9c020ecf20e2000f76cffa44305fd5bc44d2e688ea78cce423399d33f19767", - "size": "2414206" + "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20250422/openocd-esp32-linux-armel-0.12.0-esp32-20250422.tar.gz", + "archiveFileName": "openocd-esp32-linux-armel-0.12.0-esp32-20250422.tar.gz", + "checksum": "SHA-256:4ac34d6fd1af86aeda87c8318732f8d691c300c285c7fd2f5037c432c63fbbb3", + "size": "2470732" }, { "host": "x86_64-apple-darwin", - "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20241016/openocd-esp32-macos-0.12.0-esp32-20241016.tar.gz", - "archiveFileName": "openocd-esp32-macos-0.12.0-esp32-20241016.tar.gz", - "checksum": "SHA-256:02a2dffe801a2d005fa9e614d80ff8173395b2cb0b5d3118d0229d094a9946a7", - "size": "2508089" + "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20250422/openocd-esp32-macos-0.12.0-esp32-20250422.tar.gz", + "archiveFileName": "openocd-esp32-macos-0.12.0-esp32-20250422.tar.gz", + "checksum": "SHA-256:9186a7a06304c6d9201cbce4ee3c7099b393bf8d329cda17a68874f92308f6ce", + "size": "2548730" }, { "host": "arm64-apple-darwin", - "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20241016/openocd-esp32-macos-arm64-0.12.0-esp32-20241016.tar.gz", - "archiveFileName": "openocd-esp32-macos-arm64-0.12.0-esp32-20241016.tar.gz", - "checksum": "SHA-256:c382f9e884d6565cb6089bff5f200f4810994667d885f062c3d3c5625a0fa9d6", - "size": "2552569" + "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20250422/openocd-esp32-macos-arm64-0.12.0-esp32-20250422.tar.gz", + "archiveFileName": "openocd-esp32-macos-arm64-0.12.0-esp32-20250422.tar.gz", + "checksum": "SHA-256:2cc39318d52f393233ff1f777871aebe5b97b3fbad29556a238489263401b774", + "size": "2593819" }, { "host": "i686-mingw32", - "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20241016/openocd-esp32-win32-0.12.0-esp32-20241016.zip", - "archiveFileName": "openocd-esp32-win32-0.12.0-esp32-20241016.zip", - "checksum": "SHA-256:3b5d615e0a72cc771a45dd469031312d5881c01d7b6bc9edb29b8b6bda8c2e90", - "size": "2946244" + "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20250422/openocd-esp32-win32-0.12.0-esp32-20250422.zip", + "archiveFileName": "openocd-esp32-win32-0.12.0-esp32-20250422.zip", + "checksum": "SHA-256:ecb4f8533fa9098d10000f5f7e8b8eaa8591015b824b481078ddb2b37e7aa6f2", + "size": "2988859" }, { "host": "x86_64-mingw32", - "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20241016/openocd-esp32-win64-0.12.0-esp32-20241016.zip", - "archiveFileName": "openocd-esp32-win64-0.12.0-esp32-20241016.zip", - "checksum": "SHA-256:5e7b2fd1947d3a8625f6a11db7a2340cf2f41ff4c61284c022c7d7c32b18780a", - "size": "2946244" + "url": "https://github.com/espressif/openocd-esp32/releases/download/v0.12.0-esp32-20250422/openocd-esp32-win64-0.12.0-esp32-20250422.zip", + "archiveFileName": "openocd-esp32-win64-0.12.0-esp32-20250422.zip", + "checksum": "SHA-256:e9eae8e1a8d0e030cd81dcb08394a9137cb7338a6211dfabcdbdfb37b58c5a23", + "size": "2988858" } ] }, { "name": "esptool_py", - "version": "4.9.dev3", + "version": "5.0.dev1", "systems": [ { - "host": "x86_64-pc-linux-gnu", - "url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-linux-amd64.tar.gz", - "archiveFileName": "esptool-v4.9.dev3-linux-amd64.tar.gz", - "checksum": "SHA-256:4ecaf51836cbf4ea3c19840018bfef3b0b8cd8fc3c95f6e1e043ca5bbeab9bf0", - "size": "64958202" + "host": "aarch64-linux-gnu", + "url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-linux-aarch64.tar.gz", + "archiveFileName": "esptool-v5.0.dev1-linux-aarch64.tar.gz", + "checksum": "SHA-256:bfafa7a7723ebbabfd8b6e3ca5ae00bfead0331de923754aeddb43b2c116a078", + "size": "58241736" }, { - "host": "arm-linux-gnueabihf", - "url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-linux-armv7.tar.gz", - "archiveFileName": "esptool-v4.9.dev3-linux-armv7.tar.gz", - "checksum": "SHA-256:fff818573bce483ee793ac83c8211f6abf764aa3350f198228859f696a0a0b36", - "size": "31530030" + "host": "x86_64-pc-linux-gnu", + "url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-linux-amd64.tar.gz", + "archiveFileName": "esptool-v5.0.dev1-linux-amd64.tar.gz", + "checksum": "SHA-256:acd0486e96586b99d053a1479acbbbfcae8667227c831cdc53a171f9ccfa27ee", + "size": "100740042" }, { - "host": "aarch64-linux-gnu", - "url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-linux-aarch64.tar.gz", - "archiveFileName": "esptool-v4.9.dev3-linux-aarch64.tar.gz", - "checksum": "SHA-256:5b274bdff2f62e6a07c3c1dfa51b1128924621f661747eca3dbe0f77972f2f06", - "size": "33663882" + "host": "arm-linux-gnueabihf", + "url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-linux-armv7.tar.gz", + "archiveFileName": "esptool-v5.0.dev1-linux-armv7.tar.gz", + "checksum": "SHA-256:ea77a38681506761bbb7b0b39c130811ed565667b67ebbdb4d6dcc6cb6e07368", + "size": "53451939" }, { "host": "x86_64-apple-darwin", - "url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-macos-amd64.tar.gz", - "archiveFileName": "esptool-v4.9.dev3-macos-amd64.tar.gz", - "checksum": "SHA-256:c733c83b58fcf5f642fbb2fddb8ff24640c2c785126cba0821fb70c4a5ceea7a", - "size": "32767836" + "url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-macos-amd64.tar.gz", + "archiveFileName": "esptool-v5.0.dev1-macos-amd64.tar.gz", + "checksum": "SHA-256:900a8e90731208bee96647e0e207a43612b9452c2120c4fdc0ff4c6be226257b", + "size": "59631998" }, { "host": "arm64-apple-darwin", - "url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-macos-arm64.tar.gz", - "archiveFileName": "esptool-v4.9.dev3-macos-arm64.tar.gz", - "checksum": "SHA-256:83c195a15981e6a5e7a130db2ccfb21e2d8093912e5b003681f9a5abadd71af7", - "size": "30121441" + "url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-macos-arm64.tar.gz", + "archiveFileName": "esptool-v5.0.dev1-macos-arm64.tar.gz", + "checksum": "SHA-256:3653f4de73cb4fc6a25351eaf663708e91c65ae3265d75bd54ca4315a4350bb4", + "size": "56349992" }, { - "host": "i686-mingw32", - "url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-win64.zip", - "archiveFileName": "esptool-v4.9.dev3-win64.zip", - "checksum": "SHA-256:890051a4fdc684ff6f4af18d0bb27d274ca940ee0eef716a9455f8c64b25b215", - "size": "36072564" + "host": "x86_64-mingw32", + "url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-win64.zip", + "archiveFileName": "esptool-v5.0.dev1-win64.zip", + "checksum": "SHA-256:1e8fd89645daf94f2d4406ec73c9004e617ea921079515f9fd749205eece4d6d", + "size": "59102658" }, { - "host": "x86_64-mingw32", - "url": "https://github.com/espressif/arduino-esp32/releases/download/3.1.0-RC3/esptool-v4.9.dev3-win64.zip", - "archiveFileName": "esptool-v4.9.dev3-win64.zip", - "checksum": "SHA-256:890051a4fdc684ff6f4af18d0bb27d274ca940ee0eef716a9455f8c64b25b215", - "size": "36072564" + "host": "i686-mingw32", + "url": "https://github.com/espressif/arduino-esp32/releases/download/3.2.0/esptool-v5.0.dev1-win64.zip", + "archiveFileName": "esptool-v5.0.dev1-win64.zip", + "checksum": "SHA-256:1e8fd89645daf94f2d4406ec73c9004e617ea921079515f9fd749205eece4d6d", + "size": "59102658" } ] }, diff --git a/platform.txt b/platform.txt index 65be05b3bf4..8c7f4432377 100644 --- a/platform.txt +++ b/platform.txt @@ -119,7 +119,7 @@ recipe.hooks.prebuild.2.pattern.windows=cmd /c if not exist "{build.path}\partit recipe.hooks.prebuild.3.pattern.windows=cmd /c if not exist "{build.path}\partitions.csv" COPY "{runtime.platform.path}\tools\partitions\{build.partitions}.csv" "{build.path}\partitions.csv" # Check if custom bootloader exist: source > variant > build.boot -recipe.hooks.prebuild.4.pattern_args=--chip {build.mcu} elf2image --flash_mode {build.flash_mode} --flash_freq {build.img_freq} --flash_size {build.flash_size} -o +recipe.hooks.prebuild.4.pattern_args=--chip {build.mcu} elf2image --flash-mode {build.flash_mode} --flash-freq {build.img_freq} --flash-size {build.flash_size} -o recipe.hooks.prebuild.4.pattern=/usr/bin/env bash -c "[ -f "{build.source.path}"/bootloader.bin ] && cp -f "{build.source.path}"/bootloader.bin "{build.path}"/{build.project_name}.bootloader.bin || ( [ -f "{build.variant.path}"/{build.custom_bootloader}.bin ] && cp "{build.variant.path}"/{build.custom_bootloader}.bin "{build.path}"/{build.project_name}.bootloader.bin || "{tools.esptool_py.path}"/{tools.esptool_py.cmd} {recipe.hooks.prebuild.4.pattern_args} "{build.path}"/{build.project_name}.bootloader.bin "{compiler.sdk.path}"/bin/bootloader_{build.boot}_{build.boot_freq}.elf )" recipe.hooks.prebuild.4.pattern.windows=cmd /c IF EXIST "{build.source.path}\bootloader.bin" ( COPY /y "{build.source.path}\bootloader.bin" "{build.path}\{build.project_name}.bootloader.bin" ) ELSE ( IF EXIST "{build.variant.path}\{build.custom_bootloader}.bin" ( COPY "{build.variant.path}\{build.custom_bootloader}.bin" "{build.path}\{build.project_name}.bootloader.bin" ) ELSE ( "{tools.esptool_py.path}\{tools.esptool_py.cmd}" {recipe.hooks.prebuild.4.pattern_args} "{build.path}\{build.project_name}.bootloader.bin" "{compiler.sdk.path}\bin\bootloader_{build.boot}_{build.boot_freq}.elf" ) ) @@ -163,7 +163,7 @@ recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.f recipe.objcopy.partitions.bin.pattern={tools.gen_esp32part.cmd} -q "{build.path}/partitions.csv" "{build.path}/{build.project_name}.partitions.bin" ## Create bin -recipe.objcopy.bin.pattern_args=--chip {build.mcu} elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.img_freq}" --flash_size "{build.flash_size}" --elf-sha256-offset 0xb0 -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf" +recipe.objcopy.bin.pattern_args=--chip {build.mcu} elf2image --flash-mode "{build.flash_mode}" --flash-freq "{build.img_freq}" --flash-size "{build.flash_size}" --elf-sha256-offset 0xb0 -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf" recipe.objcopy.bin.pattern="{tools.esptool_py.path}/{tools.esptool_py.cmd}" {recipe.objcopy.bin.pattern_args} ## Create Insights Firmware Package @@ -176,7 +176,7 @@ recipe.hooks.objcopy.postobjcopy.2.pattern=/usr/bin/env bash -c "[ ! -d "{build. recipe.hooks.objcopy.postobjcopy.2.pattern.windows=cmd /c if exist "{build.path}\libraries\ESP_SR" if exist "{compiler.sdk.path}\esp_sr\srmodels.bin" COPY /y "{compiler.sdk.path}\esp_sr\srmodels.bin" "{build.path}\srmodels.bin" # Create merged binary -recipe.hooks.objcopy.postobjcopy.3.pattern_args=--chip {build.mcu} merge_bin -o "{build.path}/{build.project_name}.merged.bin" --fill-flash-size {build.flash_size} --flash_mode keep --flash_freq keep --flash_size keep {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin" +recipe.hooks.objcopy.postobjcopy.3.pattern_args=--chip {build.mcu} merge-bin -o "{build.path}/{build.project_name}.merged.bin" --pad-to-size {build.flash_size} --flash-mode keep --flash-freq keep --flash-size keep {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin" recipe.hooks.objcopy.postobjcopy.3.pattern="{tools.esptool_py.path}/{tools.esptool_py.cmd}" {recipe.hooks.objcopy.postobjcopy.3.pattern_args} ## Save bin @@ -285,14 +285,14 @@ debug.additional_config=debug_config.{build.mcu} tools.esptool_py.upload.protocol=serial tools.esptool_py.upload.params.verbose= tools.esptool_py.upload.params.quiet= -tools.esptool_py.upload.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset write_flash {upload.erase_cmd} -z --flash_mode keep --flash_freq keep --flash_size keep {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin" {upload.extra_flags} +tools.esptool_py.upload.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default-reset --after hard-reset write-flash {upload.erase_cmd} -z --flash-mode keep --flash-freq keep --flash-size keep {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin" {upload.extra_flags} tools.esptool_py.upload.pattern="{path}/{cmd}" {upload.pattern_args} ## Program Application ## ------------------- tools.esptool_py.program.params.verbose= tools.esptool_py.program.params.quiet= -tools.esptool_py.program.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset write_flash -z --flash_mode keep --flash_freq keep --flash_size keep 0x10000 "{build.path}/{build.project_name}.bin" +tools.esptool_py.program.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default-reset --after hard-reset write-flash -z --flash-mode keep --flash-freq keep --flash-size keep 0x10000 "{build.path}/{build.project_name}.bin" tools.esptool_py.program.pattern="{path}/{cmd}" {program.pattern_args} ## Erase Chip (before burning the bootloader) @@ -300,7 +300,7 @@ tools.esptool_py.program.pattern="{path}/{cmd}" {program.pattern_args} tools.esptool_py.erase.protocol=serial tools.esptool_py.erase.params.verbose= tools.esptool_py.erase.params.quiet= -tools.esptool_py.erase.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset erase_flash +tools.esptool_py.erase.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default-reset --after hard-reset erase-flash tools.esptool_py.erase.pattern="{path}/{cmd}" {erase.pattern_args} ## Burn Bootloader diff --git a/tests/validation/nvs/nvs.ino b/tests/validation/nvs/nvs.ino index 20b5b460098..12c640c65b0 100644 --- a/tests/validation/nvs/nvs.ino +++ b/tests/validation/nvs/nvs.ino @@ -1,35 +1,139 @@ +#include #include +struct TestData { + uint8_t id; + uint16_t value; +}; + Preferences preferences; +void validate_types() { + assert(preferences.getType("char") == PT_I8); + assert(preferences.getType("uchar") == PT_U8); + assert(preferences.getType("short") == PT_I16); + assert(preferences.getType("ushort") == PT_U16); + assert(preferences.getType("int") == PT_I32); + assert(preferences.getType("uint") == PT_U32); + assert(preferences.getType("long") == PT_I32); + assert(preferences.getType("ulong") == PT_U32); + assert(preferences.getType("long64") == PT_I64); + assert(preferences.getType("ulong64") == PT_U64); + assert(preferences.getType("float") == PT_BLOB); + assert(preferences.getType("double") == PT_BLOB); + assert(preferences.getType("bool") == PT_U8); + assert(preferences.getType("str") == PT_STR); + assert(preferences.getType("strLen") == PT_STR); + assert(preferences.getType("struct") == PT_BLOB); +} + +// Function to increment string values +void incrementStringValues(String &val_string, char *val_string_buf, size_t buf_size) { + // Extract the number from string and increment it + val_string = "str" + String(val_string.substring(3).toInt() + 1); + + // Extract the number from strLen and increment it + String strLen_str = String(val_string_buf); + int strLen_num = strLen_str.substring(6).toInt(); + snprintf(val_string_buf, buf_size, "strLen%d", strLen_num + 1); +} + void setup() { Serial.begin(115200); - while (!Serial) { ; } preferences.begin("my-app", false); - // Get the counter value, if the key does not exist, return a default value of 0 - unsigned int counter = preferences.getUInt("counter", 0); + // Get the preferences value and if not exists, use default parameter + char val_char = preferences.getChar("char", 'A'); + unsigned char val_uchar = preferences.getUChar("uchar", 0); + int16_t val_short = preferences.getShort("short", 0); + uint16_t val_ushort = preferences.getUShort("ushort", 0); + int32_t val_int = preferences.getInt("int", 0); + uint32_t val_uint = preferences.getUInt("uint", 0); + int64_t val_long = preferences.getLong("long", 0); + uint32_t val_ulong = preferences.getULong("ulong", 0); + int64_t val_long64 = preferences.getLong64("long64", 0); + uint64_t val_ulong64 = preferences.getULong64("ulong64", 0); + float val_float = preferences.getFloat("float", 0.0f); + double val_double = preferences.getDouble("double", 0.0); + bool val_bool = preferences.getBool("bool", false); - // Print the counter to Serial Monitor - Serial.printf("Current counter value: %u\n", counter); + // Strings + String val_string = preferences.getString("str", "str0"); + char val_string_buf[20] = "strLen0"; + preferences.getString("strLen", val_string_buf, sizeof(val_string_buf)); - // Increase counter by 1 - counter++; + // Structure data + TestData test_data = {0, 0}; - // Store the counter to the Preferences - preferences.putUInt("counter", counter); + size_t struct_size = preferences.getBytes("struct", &test_data, sizeof(test_data)); + if (struct_size == 0) { + // First time - set initial values using parameter names + test_data.id = 1; + test_data.value = 100; + } - // Close the Preferences - preferences.end(); + Serial.printf("Values from Preferences: "); + Serial.printf("char: %c | uchar: %u | short: %d | ushort: %u | int: %ld | uint: %lu | ", val_char, val_uchar, val_short, val_ushort, val_int, val_uint); + Serial.printf("long: %lld | ulong: %lu | long64: %lld | ulong64: %llu | ", val_long, val_ulong, val_long64, val_ulong64); + Serial.printf( + "float: %.2f | double: %.2f | bool: %s | str: %s | strLen: %s | struct: {id:%u,val:%u}\n", val_float, val_double, val_bool ? "true" : "false", + val_string.c_str(), val_string_buf, test_data.id, test_data.value + ); - // Wait 1 second - delay(1000); + // Increment the values + val_char += 1; // Increment char A -> B + val_uchar += 1; + val_short += 1; + val_ushort += 1; + val_int += 1; + val_uint += 1; + val_long += 1; + val_ulong += 1; + val_long64 += 1; + val_ulong64 += 1; + val_float += 1.1f; + val_double += 1.1; + val_bool = !val_bool; // Toggle boolean value + + // Increment string values using function + incrementStringValues(val_string, val_string_buf, sizeof(val_string_buf)); + + test_data.id += 1; + test_data.value += 10; + + // Store the updated values back to Preferences + preferences.putChar("char", val_char); + preferences.putUChar("uchar", val_uchar); + preferences.putShort("short", val_short); + preferences.putUShort("ushort", val_ushort); + preferences.putInt("int", val_int); + preferences.putUInt("uint", val_uint); + preferences.putLong("long", val_long); + preferences.putULong("ulong", val_ulong); + preferences.putLong64("long64", val_long64); + preferences.putULong64("ulong64", val_ulong64); + preferences.putFloat("float", val_float); + preferences.putDouble("double", val_double); + preferences.putBool("bool", val_bool); + preferences.putString("str", val_string); + preferences.putString("strLen", val_string_buf); + preferences.putBytes("struct", &test_data, sizeof(test_data)); - // Restart ESP + // Check if the keys exist + assert(preferences.isKey("char")); + assert(preferences.isKey("struct")); + + // Validate the types of the keys + validate_types(); + + // Close the Preferences, wait and restart + preferences.end(); + Serial.flush(); + delay(1000); ESP.restart(); } diff --git a/tests/validation/nvs/test_nvs.py b/tests/validation/nvs/test_nvs.py index 424095a49ba..7f595b8e93d 100644 --- a/tests/validation/nvs/test_nvs.py +++ b/tests/validation/nvs/test_nvs.py @@ -4,11 +4,23 @@ def test_nvs(dut): LOGGER = logging.getLogger(__name__) - LOGGER.info("Expecting counter value 0") - dut.expect_exact("Current counter value: 0") + LOGGER.info("Expecting default values from Preferences") + dut.expect_exact( + "Values from Preferences: char: A | uchar: 0 | short: 0 | ushort: 0 | int: 0 | uint: 0 | long: 0 | ulong: 0 | " + "long64: 0 | ulong64: 0 | float: 0.00 | double: 0.00 | bool: false | str: str0 | strLen: strLen0 | " + "struct: {id:1,val:100}" + ) - LOGGER.info("Expecting counter value 1") - dut.expect_exact("Current counter value: 1") + LOGGER.info("Expecting updated preferences for the first time") + dut.expect_exact( + "Values from Preferences: char: B | uchar: 1 | short: 1 | ushort: 1 | int: 1 | uint: 1 | long: 1 | ulong: 1 | " + "long64: 1 | ulong64: 1 | float: 1.10 | double: 1.10 | bool: true | str: str1 | strLen: strLen1 | " + "struct: {id:2,val:110}" + ) - LOGGER.info("Expecting counter value 2") - dut.expect_exact("Current counter value: 2") + LOGGER.info("Expecting updated preferences for the second time") + dut.expect_exact( + "Values from Preferences: char: C | uchar: 2 | short: 2 | ushort: 2 | int: 2 | uint: 2 | long: 2 | ulong: 2 | " + "long64: 2 | ulong64: 2 | float: 2.20 | double: 2.20 | bool: false | str: str2 | strLen: strLen2 | " + "struct: {id:3,val:120}" + ) diff --git a/tools/gen_esp32part.exe b/tools/gen_esp32part.exe index 5bd12c6360d..2e7b1001bb0 100644 Binary files a/tools/gen_esp32part.exe and b/tools/gen_esp32part.exe differ diff --git a/tools/gen_esp32part.py b/tools/gen_esp32part.py index ffa740a36e0..959b3188a0a 100755 --- a/tools/gen_esp32part.py +++ b/tools/gen_esp32part.py @@ -7,11 +7,8 @@ # See https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/partition-tables.html # for explanation of partition table structure and uses. # -# SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2016-2025 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 - -from __future__ import division, print_function, unicode_literals - import argparse import binascii import errno @@ -22,26 +19,34 @@ import sys MAX_PARTITION_LENGTH = 0xC00 # 3K for partition data (96 entries) leaves 1K in a 4K sector for signature -MD5_PARTITION_BEGIN = b"\xEB\xEB" + b"\xFF" * 14 # The first 2 bytes are like magic numbers for MD5 sum +MD5_PARTITION_BEGIN = b"\xeb\xeb" + b"\xff" * 14 # The first 2 bytes are like magic numbers for MD5 sum PARTITION_TABLE_SIZE = 0x1000 # Size of partition table MIN_PARTITION_SUBTYPE_APP_OTA = 0x10 NUM_PARTITION_SUBTYPE_APP_OTA = 16 +MIN_PARTITION_SUBTYPE_APP_TEE = 0x30 +NUM_PARTITION_SUBTYPE_APP_TEE = 2 SECURE_NONE = None SECURE_V1 = "v1" SECURE_V2 = "v2" -__version__ = "1.2" +__version__ = "1.5" APP_TYPE = 0x00 DATA_TYPE = 0x01 +BOOTLOADER_TYPE = 0x02 +PARTITION_TABLE_TYPE = 0x03 TYPES = { + "bootloader": BOOTLOADER_TYPE, + "partition_table": PARTITION_TABLE_TYPE, "app": APP_TYPE, "data": DATA_TYPE, } +NVS_RW_MIN_PARTITION_SIZE = 0x3000 + def get_ptype_as_int(ptype): """Convert a string which might be numeric or the name of a partition type to an integer""" @@ -56,6 +61,15 @@ def get_ptype_as_int(ptype): # Keep this map in sync with esp_partition_subtype_t enum in esp_partition.h SUBTYPES = { + BOOTLOADER_TYPE: { + "primary": 0x00, + "ota": 0x01, + "recovery": 0x02, + }, + PARTITION_TABLE_TYPE: { + "primary": 0x00, + "ota": 0x01, + }, APP_TYPE: { "factory": 0x00, "test": 0x20, @@ -72,6 +86,7 @@ def get_ptype_as_int(ptype): "fat": 0x81, "spiffs": 0x82, "littlefs": 0x83, + "tee_ota": 0x90, }, } @@ -90,6 +105,8 @@ def get_subtype_as_int(ptype, subtype): ALIGNMENT = { APP_TYPE: 0x10000, DATA_TYPE: 0x1000, + BOOTLOADER_TYPE: 0x1000, + PARTITION_TABLE_TYPE: 0x1000, } @@ -98,14 +115,18 @@ def get_alignment_offset_for_type(ptype): def get_alignment_size_for_type(ptype): - if ptype == APP_TYPE and secure == SECURE_V1: - # For secure boot v1 case, app partition must be 64K aligned - # signature block (68 bytes) lies at the very end of 64K block - return 0x10000 - if ptype == APP_TYPE and secure == SECURE_V2: - # For secure boot v2 case, app partition must be 4K aligned - # signature block (4K) is kept after padding the unsigned image to 64K boundary - return 0x1000 + if ptype == APP_TYPE: + if secure == SECURE_V1: + # For secure boot v1 case, app partition must be 64K aligned + # signature block (68 bytes) lies at the very end of 64K block + return 0x10000 + elif secure == SECURE_V2: + # For secure boot v2 case, app partition must be 4K aligned + # signature block (4K) is kept after padding the unsigned image to 64K boundary + return 0x1000 + else: + # For no secure boot enabled case, app partition must be 4K aligned (min. flash erase size) + return 0x1000 # No specific size alignment requirement as such return 0x1 @@ -115,6 +136,10 @@ def get_partition_type(ptype): return APP_TYPE if ptype == "data": return DATA_TYPE + if ptype == "bootloader": + return BOOTLOADER_TYPE + if ptype == "partition_table": + return PARTITION_TABLE_TYPE raise InputError("Invalid partition type") @@ -134,6 +159,8 @@ def add_extra_subtypes(csv): md5sum = True secure = SECURE_NONE offset_part_table = 0 +primary_bootloader_offset = None +recovery_bootloader_offset = None def status(msg): @@ -165,7 +192,7 @@ def from_file(cls, f): return cls.from_csv(data), False @classmethod - def from_csv(cls, csv_contents): # noqa: C901 + def from_csv(cls, csv_contents): res = PartitionTable() lines = csv_contents.splitlines() @@ -194,6 +221,11 @@ def expand_vars(f): # fix up missing offsets & negative sizes last_end = offset_part_table + PARTITION_TABLE_SIZE # first offset after partition table for e in res: + is_primary_bootloader = e.type == BOOTLOADER_TYPE and e.subtype == SUBTYPES[e.type]["primary"] + is_primary_partition_table = e.type == PARTITION_TABLE_TYPE and e.subtype == SUBTYPES[e.type]["primary"] + if is_primary_bootloader or is_primary_partition_table: + # They do not participate in the restoration of missing offsets + continue if e.offset is not None and e.offset < last_end: if e == res[0]: raise InputError( @@ -203,8 +235,8 @@ def expand_vars(f): ) else: raise InputError( - "CSV Error at line %d: Partitions overlap. Partition sets offset 0x%x. Previous partition ends 0x%x" # noqa: E501 - % (e.line_no, e.offset, last_end) + "CSV Error at line %d: Partitions overlap. Partition sets offset 0x%x. " + "Previous partition ends 0x%x" % (e.line_no, e.offset, last_end) ) if e.offset is None: pad_to = get_alignment_offset_for_type(e.type) @@ -246,14 +278,14 @@ def find_by_name(self, name): return p return None - def verify(self): # noqa: C901 + def verify(self): # verify each partition individually for p in self: p.verify() # check on duplicate name names = [p.name for p in self] - duplicates = set(n for n in names if names.count(n) > 1) # noqa: C401 + duplicates = {n for n in names if names.count(n) > 1} # print sorted duplicate partitions by name if len(duplicates) != 0: @@ -267,9 +299,12 @@ def verify(self): # noqa: C901 last = None for p in sorted(self, key=lambda x: x.offset): if p.offset < offset_part_table + PARTITION_TABLE_SIZE: - raise InputError( - "Partition offset 0x%x is below 0x%x" % (p.offset, offset_part_table + PARTITION_TABLE_SIZE) - ) + is_primary_bootloader = p.type == BOOTLOADER_TYPE and p.subtype == SUBTYPES[p.type]["primary"] + is_primary_partition_table = p.type == PARTITION_TABLE_TYPE and p.subtype == SUBTYPES[p.type]["primary"] + if not (is_primary_bootloader or is_primary_partition_table): + raise InputError( + "Partition offset 0x%x is below 0x%x" % (p.offset, offset_part_table + PARTITION_TABLE_SIZE) + ) if last is not None and p.offset < last.offset + last.size: raise InputError( "Partition at 0x%x overlaps 0x%x-0x%x" % (p.offset, last.offset, last.offset + last.size - 1) @@ -282,7 +317,8 @@ def verify(self): # noqa: C901 for p in otadata_duplicates: critical("%s" % (p.to_csv())) raise InputError( - 'Found multiple otadata partitions. Only one partition can be defined with type="data"(1) and subtype="ota"(0).' # noqa: E501 + "Found multiple otadata partitions. Only one partition can be defined with " + 'type="data"(1) and subtype="ota"(0).' ) if len(otadata_duplicates) == 1 and otadata_duplicates[0].size != 0x2000: @@ -290,6 +326,23 @@ def verify(self): # noqa: C901 critical("%s" % (p.to_csv())) raise InputError("otadata partition must have size = 0x2000") + # Above checks but for TEE otadata + otadata_duplicates = [ + p for p in self if p.type == TYPES["data"] and p.subtype == SUBTYPES[DATA_TYPE]["tee_ota"] + ] + if len(otadata_duplicates) > 1: + for p in otadata_duplicates: + critical("%s" % (p.to_csv())) + raise InputError( + "Found multiple TEE otadata partitions. Only one partition can be defined with " + 'type="data"(1) and subtype="tee_ota"(0x90).' + ) + + if len(otadata_duplicates) == 1 and otadata_duplicates[0].size != 0x2000: + p = otadata_duplicates[0] + critical("%s" % (p.to_csv())) + raise InputError("TEE otadata partition must have size = 0x2000") + def flash_size(self): """Return the size that partitions will occupy in flash (ie the offset the last partition ends at) @@ -321,7 +374,7 @@ def from_binary(cls, b): data = b[o : o + 32] if len(data) != 32: raise InputError("Partition table length must be a multiple of 32 bytes") - if data == b"\xFF" * 32: + if data == b"\xff" * 32: return result # got end marker if md5sum and data[:2] == MD5_PARTITION_BEGIN[:2]: # check only the magic number part if data[16:] == md5.digest(): @@ -342,7 +395,7 @@ def to_binary(self): result += MD5_PARTITION_BEGIN + hashlib.md5(result).digest() if len(result) >= MAX_PARTITION_LENGTH: raise InputError("Binary partition table length (%d) longer than max" % len(result)) - result += b"\xFF" * (MAX_PARTITION_LENGTH - len(result)) # pad the sector, for signing + result += b"\xff" * (MAX_PARTITION_LENGTH - len(result)) # pad the sector, for signing return result def to_csv(self, simple_formatting=False): @@ -352,16 +405,20 @@ def to_csv(self, simple_formatting=False): class PartitionDefinition(object): - MAGIC_BYTES = b"\xAA\x50" + MAGIC_BYTES = b"\xaa\x50" # dictionary maps flag name (as used in CSV flags list, property name) # to bit set in flags words in binary format - FLAGS = {"encrypted": 0} + FLAGS = {"encrypted": 0, "readonly": 1} # add subtypes for the 16 OTA slot values ("ota_XX, etc.") for ota_slot in range(NUM_PARTITION_SUBTYPE_APP_OTA): SUBTYPES[TYPES["app"]]["ota_%d" % ota_slot] = MIN_PARTITION_SUBTYPE_APP_OTA + ota_slot + # add subtypes for the 2 TEE OTA slot values ("tee_XX, etc.") + for tee_slot in range(NUM_PARTITION_SUBTYPE_APP_TEE): + SUBTYPES[TYPES["app"]]["tee_%d" % tee_slot] = MIN_PARTITION_SUBTYPE_APP_TEE + tee_slot + def __init__(self): self.name = "" self.type = None @@ -369,6 +426,7 @@ def __init__(self): self.offset = None self.size = None self.encrypted = False + self.readonly = False @classmethod def from_csv(cls, line, line_no): @@ -381,8 +439,8 @@ def from_csv(cls, line, line_no): res.name = fields[0] res.type = res.parse_type(fields[1]) res.subtype = res.parse_subtype(fields[2]) - res.offset = res.parse_address(fields[3]) - res.size = res.parse_address(fields[4]) + res.offset = res.parse_address(fields[3], res.type, res.subtype) + res.size = res.parse_size(fields[4], res.type) if res.size is None: raise InputError("Size field can't be empty") @@ -452,12 +510,36 @@ def parse_subtype(self, strval): return SUBTYPES[DATA_TYPE]["undefined"] return parse_int(strval, SUBTYPES.get(self.type, {})) - def parse_address(self, strval): + def parse_size(self, strval, ptype): + if ptype == BOOTLOADER_TYPE: + if primary_bootloader_offset is None: + raise InputError("Primary bootloader offset is not defined. Please use --primary-bootloader-offset") + return offset_part_table - primary_bootloader_offset + if ptype == PARTITION_TABLE_TYPE: + return PARTITION_TABLE_SIZE if strval == "": return None # PartitionTable will fill in default return parse_int(strval) - def verify(self): # noqa: C901 + def parse_address(self, strval, ptype, psubtype): + if ptype == BOOTLOADER_TYPE: + if psubtype == SUBTYPES[ptype]["primary"]: + if primary_bootloader_offset is None: + raise InputError("Primary bootloader offset is not defined. Please use --primary-bootloader-offset") + return primary_bootloader_offset + if psubtype == SUBTYPES[ptype]["recovery"]: + if recovery_bootloader_offset is None: + raise InputError( + "Recovery bootloader offset is not defined. Please use --recovery-bootloader-offset" + ) + return recovery_bootloader_offset + if ptype == PARTITION_TABLE_TYPE and psubtype == SUBTYPES[ptype]["primary"]: + return offset_part_table + if strval == "": + return None # PartitionTable will fill in default + return parse_int(strval) + + def verify(self): if self.type is None: raise ValidationError(self, "Type field is not set") if self.subtype is None: @@ -469,7 +551,7 @@ def verify(self): # noqa: C901 offset_align = get_alignment_offset_for_type(self.type) if self.offset % offset_align: raise ValidationError(self, "Offset 0x%x is not aligned to 0x%x" % (self.offset, offset_align)) - if self.type == APP_TYPE and secure is not SECURE_NONE: + if self.type == APP_TYPE: size_align = get_alignment_size_for_type(self.type) if self.size % size_align: raise ValidationError(self, "Size 0x%x is not aligned to 0x%x" % (self.size, size_align)) @@ -489,6 +571,23 @@ def verify(self): # noqa: C901 % (self.name, self.type, self.subtype) ) + always_rw_data_subtypes = [SUBTYPES[DATA_TYPE]["ota"], SUBTYPES[DATA_TYPE]["coredump"]] + if self.type == TYPES["data"] and self.subtype in always_rw_data_subtypes and self.readonly is True: + raise ValidationError( + self, + "'%s' partition of type %s and subtype %s is always read-write and cannot be read-only" + % (self.name, self.type, self.subtype), + ) + + if self.type == TYPES["data"] and self.subtype == SUBTYPES[DATA_TYPE]["nvs"]: + if self.size < NVS_RW_MIN_PARTITION_SIZE and self.readonly is False: + raise ValidationError( + self, + """'%s' partition of type %s and subtype %s of this size (0x%x) must be flagged as 'readonly' \ +(the size of read/write NVS has to be at least 0x%x)""" + % (self.name, self.type, self.subtype, self.size, NVS_RW_MIN_PARTITION_SIZE), + ) + STRUCT_FORMAT = b"<2sBBLL16sL" @classmethod @@ -574,11 +673,13 @@ def parse_int(v, keywords={}): raise InputError("Value '%s' is not valid. Known keywords: %s" % (v, ", ".join(keywords))) -def main(): # noqa: C901 +def main(): global quiet global md5sum global offset_part_table global secure + global primary_bootloader_offset + global recovery_bootloader_offset parser = argparse.ArgumentParser(description="ESP32 partition table utility") parser.add_argument( @@ -600,6 +701,8 @@ def main(): # noqa: C901 ) parser.add_argument("--quiet", "-q", help="Don't print non-critical status messages to stderr", action="store_true") parser.add_argument("--offset", "-o", help="Set offset partition table", default="0x8000") + parser.add_argument("--primary-bootloader-offset", help="Set primary bootloader offset", default=None) + parser.add_argument("--recovery-bootloader-offset", help="Set recovery bootloader offset", default=None) parser.add_argument( "--secure", help="Require app partitions to be suitable for secure boot", @@ -622,6 +725,15 @@ def main(): # noqa: C901 md5sum = not args.disable_md5sum secure = args.secure offset_part_table = int(args.offset, 0) + if args.primary_bootloader_offset is not None: + primary_bootloader_offset = int(args.primary_bootloader_offset, 0) + if primary_bootloader_offset >= offset_part_table: + raise InputError( + f"Unsupported configuration. Primary bootloader must be below partition table. " + f"Check --primary-bootloader-offset={primary_bootloader_offset:#x} and --offset={offset_part_table:#x}" + ) + if args.recovery_bootloader_offset is not None: + recovery_bootloader_offset = int(args.recovery_bootloader_offset, 0) if args.extra_partition_subtypes: add_extra_subtypes(args.extra_partition_subtypes) @@ -647,7 +759,7 @@ def main(): # noqa: C901 if input_is_binary: output = table.to_csv() - with sys.stdout if args.output == "-" else open(args.output, "w") as f: + with sys.stdout if args.output == "-" else open(args.output, "w", encoding="utf-8") as f: f.write(output) else: output = table.to_binary() diff --git a/tools/partitions/rainmaker_8MB.csv b/tools/partitions/rainmaker_8MB.csv index 6d65333063f..6bad399968c 100644 --- a/tools/partitions/rainmaker_8MB.csv +++ b/tools/partitions/rainmaker_8MB.csv @@ -1,7 +1,7 @@ # Name, Type, SubType, Offset, Size, Flags nvs, data, nvs, 0x9000, 0x5000, otadata, data, ota, 0xe000, 0x2000, -ota_0, app, ota_0, 0x10000, 0x3ED000, -ota_1, app, ota_1, 0x3FD000, 0x3ED000, +ota_0, app, ota_0, 0x10000, 0x3EA000, +ota_1, app, ota_1, 0x400000, 0x3EA000, fctry, data, nvs, 0x7EA000, 0x6000, coredump, data, coredump,0x7F0000, 0x10000, diff --git a/tools/pioarduino-build.py b/tools/pioarduino-build.py index 3335a716888..b6a0c0435c5 100644 --- a/tools/pioarduino-build.py +++ b/tools/pioarduino-build.py @@ -99,11 +99,11 @@ def generate_bootloader_image(bootloader_elf): "--chip", build_mcu, "elf2image", - "--flash_mode", + "--flash-mode", "${__get_board_flash_mode(__env__)}", - "--flash_freq", + "--flash-freq", "${__get_board_f_image(__env__)}", - "--flash_size", + "--flash-size", board_config.get("upload.flash_size", "4MB"), "-o", "$TARGET", diff --git a/variants/Geekble_ESP32C3/pins_arduino.h b/variants/Geekble_ESP32C3/pins_arduino.h index 660313ce849..56bda115a7e 100644 --- a/variants/Geekble_ESP32C3/pins_arduino.h +++ b/variants/Geekble_ESP32C3/pins_arduino.h @@ -22,6 +22,13 @@ static const uint8_t MOSI = 6; static const uint8_t MISO = 5; static const uint8_t SCK = 4; +static const uint8_t D5 = 5; +static const uint8_t D6 = 6; +static const uint8_t D7 = 7; +static const uint8_t D8 = 8; +static const uint8_t D9 = 9; +static const uint8_t D10 = 10; + static const uint8_t A0 = 0; static const uint8_t A1 = 1; static const uint8_t A2 = 2; diff --git a/variants/XIAO_ESP32S3_Plus/pins_arduino.h b/variants/XIAO_ESP32S3_Plus/pins_arduino.h index fb887287e35..de1c6093d44 100644 --- a/variants/XIAO_ESP32S3_Plus/pins_arduino.h +++ b/variants/XIAO_ESP32S3_Plus/pins_arduino.h @@ -4,7 +4,7 @@ #include #define USB_VID 0x2886 -#define USB_PID 0x0056 +#define USB_PID 0x0063 static const uint8_t LED_BUILTIN = 21; #define BUILTIN_LED LED_BUILTIN // backward compatibility diff --git a/variants/adafruit_sparklemotionstick_esp32/pins_arduino.h b/variants/adafruit_sparklemotionstick_esp32/pins_arduino.h new file mode 100644 index 00000000000..e0d94821736 --- /dev/null +++ b/variants/adafruit_sparklemotionstick_esp32/pins_arduino.h @@ -0,0 +1,40 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +// User LED +static const uint8_t LED_BUILTIN = 4; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + +// Neopixel +static const uint8_t PIN_NEOPIXEL = 18; +// RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API rgbLedWrite() and digitalWrite() for blinking +#define RGB_BUILTIN (PIN_NEOPIXEL + SOC_GPIO_PIN_COUNT) +#define RGB_BRIGHTNESS 64 + +static const uint8_t TX = 25; // not broken out, defined to fix compilation +static const uint8_t RX = 26; // not broken out, defined to fix compilation + +#define TX1 TX +#define RX1 RX + +static const uint8_t SDA = 13; // not broken out, defined to fix compilation +static const uint8_t SCL = 15; // not broken out, defined to fix compilation + +static const uint8_t SS = 19; // not broken out, defined to fix compilation +static const uint8_t MOSI = 21; // output to drive dotstars +static const uint8_t SCK = 22; // output to drive dotstars +static const uint8_t MISO = 23; // not broken out, defined to fix compilation + +static const uint8_t A0 = 2; // not broken out, defined to fix compilation + +// internal switch +static const uint8_t BUTTON = 0; + +static const uint8_t DAC1 = 25; // not broken out, defined to fix compilation +static const uint8_t DAC2 = 26; // not broken out, defined to fix compilation + +#endif /* Pins_Arduino_h */ diff --git a/variants/alfredo-nou3/pins_arduino.h b/variants/alfredo-nou3/pins_arduino.h index 88bdbea0bb1..8b5a7d51b9f 100644 --- a/variants/alfredo-nou3/pins_arduino.h +++ b/variants/alfredo-nou3/pins_arduino.h @@ -1,6 +1,7 @@ #ifndef Pins_Arduino_h #define Pins_Arduino_h +#include #define USB_VID 0xAFD0 #define USB_PID 0x0003 #define USB_MANUFACTURER "Alfredo" diff --git a/variants/dfrobot_lorawan_esp32s3/pins_arduino.h b/variants/dfrobot_lorawan_esp32s3/pins_arduino.h new file mode 100644 index 00000000000..c690cac069f --- /dev/null +++ b/variants/dfrobot_lorawan_esp32s3/pins_arduino.h @@ -0,0 +1,34 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define LED_BUILTIN 21 + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 8; +static const uint8_t SCL = 9; + +#define LORA_ANTPWR 42 //RXEN +#define LORA_RST 41 //RST +#define LORA_BUSY 40 //BUSY +#define LORA_DIO1 4 //DIO + +static const uint8_t LORA_SS = 10; +static const uint8_t LORA_MOSI = 6; +static const uint8_t LORA_MISO = 5; +static const uint8_t LORA_SCK = 7; + +static const uint8_t SS = 17; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; + +#define TFT_DC 14 +#define TFT_CS 17 +#define TFT_RST 15 +#define TFT_BL 16 // Backlight pin + +#endif /* Pins_Arduino_h */ diff --git a/variants/lilygo_tlora_pager/pins_arduino.h b/variants/lilygo_tlora_pager/pins_arduino.h index 1a1d8e5da3f..fb57b5d493f 100644 --- a/variants/lilygo_tlora_pager/pins_arduino.h +++ b/variants/lilygo_tlora_pager/pins_arduino.h @@ -8,7 +8,7 @@ #endif #define USB_VID 0x303a -#define USB_PID 0x82D1 +#define USB_PID 0x82D4 #define USB_MANUFACTURER "LILYGO" #define USB_PRODUCT "T-LoRa-Pager" @@ -20,9 +20,9 @@ static const uint8_t TX = 43; static const uint8_t RX = 44; -//BHI260,PCF85063,BQ25896,DRV2605L,ES8311 share I2C Bus -static const uint8_t SDA = 2; -static const uint8_t SCL = 3; +// BHI260,PCF85063,BQ25896,DRV2605L,ES8311 share I2C Bus +static const uint8_t SDA = 3; +static const uint8_t SCL = 2; // Default sd cs pin static const uint8_t SS = SD_CS; @@ -75,16 +75,18 @@ static const uint8_t SCK = 35; #define DISP_BL (42) // External expansion chip IO definition -#define EXPANDS_DRV_EN (0) -#define EXPANDS_AMP_EN (1) -#define EXPANDS_KB_RST (2) -#define EXPANDS_LORA_EN (3) -#define EXPANDS_GPS_EN (4) -#define EXPANDS_NFC_EN (5) -#define EXPANDS_DISP_RST (6) -#define EXPANDS_GPS_RST (7) -#define EXPANDS_KB_EN (8) -#define EXPANDS_GPIO_EN (9) +#define EXPANDS_DRV_EN (0) +#define EXPANDS_AMP_EN (1) +#define EXPANDS_KB_RST (2) +#define EXPANDS_LORA_EN (3) +#define EXPANDS_GPS_EN (4) +#define EXPANDS_NFC_EN (5) +#define EXPANDS_GPS_RST (7) +#define EXPANDS_KB_EN (8) +#define EXPANDS_GPIO_EN (9) +#define EXPANDS_SD_DET (10) +#define EXPANDS_SD_PULLEN (11) +#define EXPANDS_SD_EN (12) // Peripheral definition exists #define USING_AUDIO_CODEC diff --git a/variants/lilygo_twatch_s3/pins_arduino.h b/variants/lilygo_twatch_s3/pins_arduino.h index b184dc9ba17..05543de27c5 100644 --- a/variants/lilygo_twatch_s3/pins_arduino.h +++ b/variants/lilygo_twatch_s3/pins_arduino.h @@ -44,7 +44,7 @@ static const uint8_t TX = 42; static const uint8_t RX = 41; -//BHI260,PCF85063,AXP2101,DRV2605L,PN532 share I2C Bus +// BMA423,PCF8563,AXP2101,DRV2605L share I2C Bus static const uint8_t SDA = 10; static const uint8_t SCL = 11; diff --git a/variants/lilygo_twatch_ultra/pins_arduino.h b/variants/lilygo_twatch_ultra/pins_arduino.h index c90c1ba584e..91797e687fa 100644 --- a/variants/lilygo_twatch_ultra/pins_arduino.h +++ b/variants/lilygo_twatch_ultra/pins_arduino.h @@ -22,6 +22,7 @@ #define DISP_D3 (45) #define DISP_SCK (40) #define DISP_CS (41) +#define DISP_RST (37) #define DISP_TE (6) // Interrupt IO port @@ -47,9 +48,9 @@ static const uint8_t TX = 43; static const uint8_t RX = 44; -//BHI260,PCF85063,AXP2101,DRV2605L,PN532 share I2C Bus -static const uint8_t SDA = 2; -static const uint8_t SCL = 3; +// BHI260,PCF85063,AXP2101,DRV2605L share I2C Bus +static const uint8_t SDA = 3; +static const uint8_t SCL = 2; // Default sd cs pin static const uint8_t SS = SD_CS; @@ -76,8 +77,8 @@ static const uint8_t SCK = 35; // External expansion chip IO definition #define EXPANDS_DRV_EN (6) #define EXPANDS_DISP_EN (7) -#define EXPANDS_TOUCH_RST (10) -#define EXPANDS_DISP_RST (11) +#define EXPANDS_TOUCH_RST (8) +#define EXPANDS_SD_DET (10) // Peripheral definition exists #define USING_XL9555_EXPANDS diff --git a/variants/um_edges3_d/pins_arduino.h b/variants/um_edges3_d/pins_arduino.h new file mode 100644 index 00000000000..f54ceb52ea7 --- /dev/null +++ b/variants/um_edges3_d/pins_arduino.h @@ -0,0 +1,46 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define USB_VID 0x303A +#define USB_PID 0x82DC +#define USB_MANUFACTURER "Unexpected Maker" +#define USB_PRODUCT "EdgeS3[D]" +#define USB_SERIAL "" + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 8; +static const uint8_t SCL = 9; + +static const uint8_t SS = 34; +static const uint8_t MOSI = 35; +static const uint8_t MISO = 37; +static const uint8_t SDO = 35; +static const uint8_t SDI = 37; +static const uint8_t SCK = 36; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; + +#endif /* Pins_Arduino_h */ diff --git a/variants/um_squixl/pins_arduino.h b/variants/um_squixl/pins_arduino.h new file mode 100644 index 00000000000..4546cdb124a --- /dev/null +++ b/variants/um_squixl/pins_arduino.h @@ -0,0 +1,23 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define USB_VID 0x303A +#define USB_PID 0x82DF +#define USB_MANUFACTURER "Unexpected Maker" +#define USB_PRODUCT "SQUiXL" +#define USB_SERIAL "" + +static const uint8_t SDA = 1; +static const uint8_t SCL = 2; + +static const uint8_t SS = 42; +static const uint8_t MOSI = 46; +static const uint8_t MISO = 41; +static const uint8_t SDO = 46; +static const uint8_t SDI = 41; +static const uint8_t SCK = 45; + +#endif /* Pins_Arduino_h */ diff --git a/variants/wifiduino32s3/pins_arduino.h b/variants/wifiduino32s3/pins_arduino.h index d26e415910e..4fc08139c0e 100644 --- a/variants/wifiduino32s3/pins_arduino.h +++ b/variants/wifiduino32s3/pins_arduino.h @@ -2,43 +2,57 @@ #define Pins_Arduino_h #include - -#define USB_VID 0x303a -#define USB_PID 0x1001 - -// No USER LED or NeoLED - -static const uint8_t TX = 45; +#include "soc/soc_caps.h" + +#define USB_VID 0x303a +#define USB_PID 0x1001 +#define USB_MANUFACTURER "openjumper" +#define USB_PRODUCT "Wifiduino32-S3" +#define USB_SERIAL "" // Empty string for MAC address + +// Some boards have too low voltage on this pin (board design bug) +// Use different pin with 3V and connect with 48 +// and change this setup for the chosen pin (for example 38) +#define PIN_RGB_LED 48 +// BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_RGB_LED; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +// RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API rgbLedWrite() +#define RGB_BUILTIN LED_BUILTIN +#define RGB_BRIGHTNESS 64 + +static const uint8_t TX = 43; static const uint8_t RX = 44; static const uint8_t SDA = 4; static const uint8_t SCL = 5; -static const uint8_t SS = 46; -static const uint8_t MOSI = 3; -static const uint8_t MISO = 20; -static const uint8_t SCK = 19; +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; -static const uint8_t A0 = 7; -static const uint8_t A1 = 6; +static const uint8_t A0 = 0; +static const uint8_t A1 = 1; static const uint8_t A2 = 2; -static const uint8_t A3 = 1; +static const uint8_t A3 = 3; static const uint8_t A4 = 4; static const uint8_t A5 = 5; static const uint8_t D0 = 44; -static const uint8_t D1 = 45; -static const uint8_t D2 = 42; -static const uint8_t D3 = 41; -static const uint8_t D4 = 0; -static const uint8_t D5 = 45; -static const uint8_t D6 = 48; -static const uint8_t D7 = 47; +static const uint8_t D1 = 43; +static const uint8_t D2 = 45; +static const uint8_t D3 = 46; +static const uint8_t D4 = 47; +static const uint8_t D5 = 48; +static const uint8_t D6 = 18; +static const uint8_t D7 = 17; static const uint8_t D8 = 21; -static const uint8_t D9 = 14; -static const uint8_t D10 = 46; -static const uint8_t D11 = 3; -static const uint8_t D12 = 20; -static const uint8_t D13 = 19; +static const uint8_t D9 = 42; +static const uint8_t D10 = 41; +static const uint8_t D11 = 40; +static const uint8_t D12 = 38; +static const uint8_t D13 = 39; #endif /* Pins_Arduino_h */ diff --git a/variants/yb_esp32s3_drv/pins_arduino.h b/variants/yb_esp32s3_drv/pins_arduino.h new file mode 100644 index 00000000000..06de47e50f4 --- /dev/null +++ b/variants/yb_esp32s3_drv/pins_arduino.h @@ -0,0 +1,60 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303A +#define USB_PID 0x1001 + +static const uint8_t LED_BUILTIN = 47; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 8; +static const uint8_t SCL = 9; + +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; + +// 2 connectors (X, Y) with 4 driver channels each +static const uint8_t X1 = 35; +static const uint8_t X2 = 36; +static const uint8_t X3 = 37; +static const uint8_t X4 = 38; +static const uint8_t Y1 = 4; +static const uint8_t Y2 = 5; +static const uint8_t Y3 = 6; +static const uint8_t Y4 = 7; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 8; +static const uint8_t A4 = 9; +static const uint8_t A5 = 10; +static const uint8_t A6 = 11; +static const uint8_t A7 = 12; +static const uint8_t A8 = 13; +static const uint8_t A9 = 14; +static const uint8_t A10 = 15; +static const uint8_t A11 = 16; +static const uint8_t A12 = 17; +static const uint8_t A13 = 18; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +#endif /* Pins_Arduino_h */ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy