From 297744102c146a935c6b156359f9cf688ad09692 Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Mon, 20 Dec 2021 10:57:38 +0800 Subject: [PATCH 1/2] [esp32] Add lighting example --- .../esp32/main/Kconfig.projbuild | 2 +- examples/lighting-app/esp32/.gitignore | 3 + examples/lighting-app/esp32/CMakeLists.txt | 35 +++ examples/lighting-app/esp32/README.md | 124 +++++++++++ .../esp32/main/CHIPDeviceManager.cpp | 106 +++++++++ .../lighting-app/esp32/main/CMakeLists.txt | 59 +++++ .../esp32/main/DeviceCallbacks.cpp | 203 ++++++++++++++++++ .../lighting-app/esp32/main/Kconfig.projbuild | 109 ++++++++++ .../lighting-app/esp32/main/LEDWidget.cpp | 113 ++++++++++ .../esp32/main/include/CHIPDeviceManager.h | 122 +++++++++++ .../esp32/main/include/DeviceCallbacks.h | 48 +++++ .../esp32/main/include/LEDWidget.h | 56 +++++ examples/lighting-app/esp32/main/main.cpp | 86 ++++++++ examples/lighting-app/esp32/partitions.csv | 6 + .../lighting-app/esp32/sdkconfig.defaults | 41 ++++ .../esp32/third_party/connectedhomeip | 1 + 16 files changed, 1113 insertions(+), 1 deletion(-) create mode 100644 examples/lighting-app/esp32/.gitignore create mode 100644 examples/lighting-app/esp32/CMakeLists.txt create mode 100644 examples/lighting-app/esp32/README.md create mode 100644 examples/lighting-app/esp32/main/CHIPDeviceManager.cpp create mode 100644 examples/lighting-app/esp32/main/CMakeLists.txt create mode 100644 examples/lighting-app/esp32/main/DeviceCallbacks.cpp create mode 100644 examples/lighting-app/esp32/main/Kconfig.projbuild create mode 100644 examples/lighting-app/esp32/main/LEDWidget.cpp create mode 100644 examples/lighting-app/esp32/main/include/CHIPDeviceManager.h create mode 100644 examples/lighting-app/esp32/main/include/DeviceCallbacks.h create mode 100644 examples/lighting-app/esp32/main/include/LEDWidget.h create mode 100644 examples/lighting-app/esp32/main/main.cpp create mode 100644 examples/lighting-app/esp32/partitions.csv create mode 100644 examples/lighting-app/esp32/sdkconfig.defaults create mode 120000 examples/lighting-app/esp32/third_party/connectedhomeip diff --git a/examples/all-clusters-app/esp32/main/Kconfig.projbuild b/examples/all-clusters-app/esp32/main/Kconfig.projbuild index 0960168aadca4a..307b7f6ccb83bc 100644 --- a/examples/all-clusters-app/esp32/main/Kconfig.projbuild +++ b/examples/all-clusters-app/esp32/main/Kconfig.projbuild @@ -40,7 +40,7 @@ menu "Demo" bool "M5Stack" depends on IDF_TARGET_ESP32 config DEVICE_TYPE_ESP32_C3_DEVKITM - bool "EXP32C3-DevKitM" + bool "ESP32C3-DevKitM" depends on IDF_TARGET_ESP32C3 endchoice diff --git a/examples/lighting-app/esp32/.gitignore b/examples/lighting-app/esp32/.gitignore new file mode 100644 index 00000000000000..a90ab6f1e57d5a --- /dev/null +++ b/examples/lighting-app/esp32/.gitignore @@ -0,0 +1,3 @@ +/build/ +/sdkconfig +/sdkconfig.old diff --git a/examples/lighting-app/esp32/CMakeLists.txt b/examples/lighting-app/esp32/CMakeLists.txt new file mode 100644 index 00000000000000..dff200257ea9ad --- /dev/null +++ b/examples/lighting-app/esp32/CMakeLists.txt @@ -0,0 +1,35 @@ +# +# Copyright (c) 2021 Project CHIP Authors +# All rights reserved. +# +# 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. + +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake) + +set(EXTRA_COMPONENT_DIRS + "${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components" + "${CMAKE_CURRENT_LIST_DIR}/../../common/QRCode" + "${IDF_PATH}/examples/common_components" +) + +project(chip-light-app) + +# C++17 is required for RPC build. +idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND) +idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND) + +flashing_script() diff --git a/examples/lighting-app/esp32/README.md b/examples/lighting-app/esp32/README.md new file mode 100644 index 00000000000000..99a847938d8d63 --- /dev/null +++ b/examples/lighting-app/esp32/README.md @@ -0,0 +1,124 @@ +# Matter ESP32 Lighting Example + +This example demonstrates the Matter Lighting application on ESP platforms. + +--- + +- [Matter ESP32 Lighting Example](#matter-esp32-lighting-example) + - [Supported Devices](#supported-devices) + - [Building the Example Application](#building-the-example-application) + - [Commissioning over BLE using chip-tool](#commissioning-over-ble-using-chip-tool) + - [Cluster Control](#cluster-control) + +--- + +## Supported Devices + +The demo application is intended to work on following categories of ESP32 +devices: + +- [ESP32-DevKitC](https://www.espressif.com/en/products/hardware/esp32-devkitc/overview) +- [ESP32-WROVER-KIT_V4.1](https://www.espressif.com/en/products/hardware/esp-wrover-kit/overview) +- [ESP32C3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitm-1.html). +- [ESP32S3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitm-1.html). + +## Building the Example Application + +Building the example application requires the use of the Espressif IoT +Development Framework ([ESP-IDF](https://github.com/espressif/esp-idf)). + +The VSCode devcontainer has these components pre-installed, so you can skip this +step. To install these components manually, follow these steps: + +- Clone the Espressif ESP-IDF and checkout + [v4.4-beta1 pre-release](https://github.com/espressif/esp-idf/releases/tag/v4.4-beta1) + + $ mkdir ${HOME}/tools + $ cd ${HOME}/tools + $ git clone https://github.com/espressif/esp-idf.git + $ cd esp-idf + $ git checkout v4.4-beta1 + $ git submodule update --init + $ ./install.sh + +- Install ninja-build + + $ sudo apt-get install ninja-build + +Currently building in VSCode _and_ deploying from native is not supported, so +make sure the IDF_PATH has been exported(See the manual setup steps above). + +- Setting up the environment + + $ cd ${HOME}/tools/esp-idf + $ ./install.sh + $ . ./export.sh + $ cd {path-to-connectedhomeip} + + To download and install packages. + + $ source ./scripts/bootstrap.sh + $ source ./scripts/activate.sh + + If packages are already installed then simply activate them. + + $ source ./scripts/activate.sh + +- Target Set + + $ idf.py set-target esp32 + or + $ idf.py set-target esp32c3 + or + $ idf.py set-target esp32s3 + +- To build the demo application. + + $ idf.py build + +- After building the application, to flash it outside of VSCode, connect your + device via USB. Then run the following command to flash the demo application + onto the device and then monitor its output. If necessary, replace + `/dev/tty.SLAB_USBtoUART`(MacOS) with the correct USB device name for your + system(like `/dev/ttyUSB0` on Linux). Note that sometimes you might have to + press and hold the `boot` button on the device while it's trying to connect + before flashing. + + $ idf.py -p /dev/tty.SLAB_USBtoUART flash monitor + + Note: Some users might have to install the + [VCP driver](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers) + before the device shows up on `/dev/tty`. + +- Quit the monitor by hitting `Ctrl+]`. + + Note: You can see a menu of various monitor commands by hitting + `Ctrl+t Ctrl+h` while the monitor is running. + +- If desired, the monitor can be run again like so: + + $ idf.py -p /dev/tty.SLAB_USBtoUART monitor + +## Commissioning over BLE using chip-tool + +- Please build the standalone chip-tool as described [here](../../chip-tool) +- Commissioning the Lighting device + + $ ./out/debug/chip-tool pairing ble-wifi 12345 20202021 3840 + +## Cluster Control + +- After successful commissioning, use the OnOff cluster command to control the + OnOff attribute. This allows you to toggle a parameter implemented by the + device to be On or Off. + + $ ./out/debug/chip-tool onoff on 12345 1 + +- On + [ESP32C3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitm-1.html) + or + [ESP32S3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitm-1.html) + board, there is an on-board RGB-LED. Use ColorControl cluster command to + control the color attributes: + + $ ./out/debug/chip-tool colorcontrol move-to-hue-and-saturation 240 100 0 0 0 12345 1 diff --git a/examples/lighting-app/esp32/main/CHIPDeviceManager.cpp b/examples/lighting-app/esp32/main/CHIPDeviceManager.cpp new file mode 100644 index 00000000000000..f0dec73f04e17b --- /dev/null +++ b/examples/lighting-app/esp32/main/CHIPDeviceManager.cpp @@ -0,0 +1,106 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * This file implements the CHIP Device Interface that is used by + * applications to interact with the CHIP stack + * + */ + +#include + +#include "CHIPDeviceManager.h" +#include +#include +#include +#include +#include +#include + +using namespace ::chip; + +namespace chip { + +namespace DeviceManager { + +using namespace ::chip::DeviceLayer; + +void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg) +{ + CHIPDeviceManagerCallbacks * cb = reinterpret_cast(arg); + if (cb != nullptr) + { + cb->DeviceEventCallback(event, reinterpret_cast(cb)); + } +} + +CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb) +{ + CHIP_ERROR err; + mCB = cb; + RendezvousInformationFlags flags = RendezvousInformationFlags(CONFIG_RENDEZVOUS_MODE); + + // Initialize the CHIP stack. + err = PlatformMgr().InitChipStack(); + SuccessOrExit(err); + + if (flags.Has(RendezvousInformationFlag::kBLE)) + { + ConnectivityMgr().SetBLEAdvertisingEnabled(true); + } + else if (flags.Has(RendezvousInformationFlag::kSoftAP)) + { + // TODO(cecille): Fix for the case where BLE and SoftAP are both enabled.` + ConnectivityMgr().SetBLEAdvertisingEnabled(false); + ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled); + } + else + { + // If rendezvous is bypassed, enable SoftAP so that the device can still + // be communicated with via its SoftAP as needed. + ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled); + } + + err = Platform::MemoryInit(); + SuccessOrExit(err); + + // Register a function to receive events from the CHIP device layer. Note that calls to + // this function will happen on the CHIP event loop thread, not the app_main thread. + PlatformMgr().AddEventHandler(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast(cb)); + + // Start a task to run the CHIP Device event loop. + err = PlatformMgr().StartEventLoopTask(); + SuccessOrExit(err); + +exit: + return err; +} +} // namespace DeviceManager +} // namespace chip + +void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type, + uint16_t size, uint8_t * value) +{ + chip::DeviceManager::CHIPDeviceManagerCallbacks * cb = + chip::DeviceManager::CHIPDeviceManager::GetInstance().GetCHIPDeviceManagerCallbacks(); + if (cb != nullptr) + { + cb->PostAttributeChangeCallback(attributePath.mEndpointId, attributePath.mClusterId, attributePath.mAttributeId, mask, type, + size, value); + } +} diff --git a/examples/lighting-app/esp32/main/CMakeLists.txt b/examples/lighting-app/esp32/main/CMakeLists.txt new file mode 100644 index 00000000000000..f4a667cd42fb53 --- /dev/null +++ b/examples/lighting-app/esp32/main/CMakeLists.txt @@ -0,0 +1,59 @@ +# +# Copyright (c) 2021 Project CHIP Authors +# All rights reserved. +# +# 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. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) + +idf_component_register(PRIV_INCLUDE_DIRS + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/color_format" + "${CMAKE_CURRENT_LIST_DIR}/include" + SRC_DIRS + "${CMAKE_CURRENT_LIST_DIR}" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app/zap-generated" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/route_hook" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/color_format" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/reporting" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/administrator-commissioning-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/basic" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/bindings" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/descriptor" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/diagnostic-logs-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/color-control-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ethernet-network-diagnostics-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/fixed-label-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/general-commissioning-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/general-diagnostics-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/identify-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/level-control" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/network-commissioning-old" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/occupancy-sensor-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/on-off-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-configuration-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/software-diagnostics-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/switch-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/thread-network-diagnostics-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/user-label-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/wifi-network-diagnostics-server" + PRIV_REQUIRES chip QRCode bt led_strip) + +set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) +target_compile_options(${COMPONENT_LIB} PRIVATE "-DLWIP_IPV6_SCOPES=0" "-DCHIP_HAVE_CONFIG_H") diff --git a/examples/lighting-app/esp32/main/DeviceCallbacks.cpp b/examples/lighting-app/esp32/main/DeviceCallbacks.cpp new file mode 100644 index 00000000000000..f1697ec10da1e6 --- /dev/null +++ b/examples/lighting-app/esp32/main/DeviceCallbacks.cpp @@ -0,0 +1,203 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +/** + * @file DeviceCallbacks.cpp + * + * Implements all the callbacks to the application from the CHIP Stack + * + **/ + +#include "DeviceCallbacks.h" +#include "LEDWidget.h" + +#include "esp_err.h" +#include "esp_heap_caps.h" +#include "esp_log.h" +#include "route_hook/esp_route_hook.h" +#include +#include +#include +#include +#include + +static const char * TAG = "light-app-callbacks"; + +extern LEDWidget AppLED; + +using namespace chip; +using namespace chip::Inet; +using namespace chip::System; +using namespace chip::DeviceLayer; +using namespace chip::app::Clusters; + +void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg) +{ + switch (event->Type) + { + case DeviceEventType::kInternetConnectivityChange: + OnInternetConnectivityChange(event); + break; + + case DeviceEventType::kSessionEstablished: + OnSessionEstablished(event); + break; + + case DeviceEventType::kCHIPoBLEConnectionEstablished: + ESP_LOGI(TAG, "CHIPoBLE connection established"); + break; + + case DeviceEventType::kCHIPoBLEConnectionClosed: + ESP_LOGI(TAG, "CHIPoBLE disconnected"); + break; + + case DeviceEventType::kCommissioningComplete: + ESP_LOGI(TAG, "Commissioning complete"); + break; + + case DeviceEventType::kInterfaceIpAddressChanged: + if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || + (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) + { + // MDNS server restart on any ip assignment: if link local ipv6 is configured, that + // will not trigger a 'internet connectivity change' as there is no internet + // connectivity. MDNS still wants to refresh its listening interfaces to include the + // newly selected address. + chip::app::DnssdServer::Instance().StartServer(); + } + if (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned) + { + ESP_ERROR_CHECK(esp_route_hook_init(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"))); + } + break; + } + + ESP_LOGI(TAG, "Current free heap: %zu\n", heap_caps_get_free_size(MALLOC_CAP_8BIT)); +} + +void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId, uint8_t mask, + uint8_t type, uint16_t size, uint8_t * value) +{ + ESP_LOGI(TAG, "PostAttributeChangeCallback - Cluster ID: '0x%04x', EndPoint ID: '0x%02x', Attribute ID: '0x%04x'", clusterId, + endpointId, attributeId); + + switch (clusterId) + { + case OnOff::Id: + OnOnOffPostAttributeChangeCallback(endpointId, attributeId, value); + break; + + case LevelControl::Id: + OnLevelControlAttributeChangeCallback(endpointId, attributeId, value); + break; + +#if CONFIG_LED_TYPE_RMT + case ColorControl::Id: + OnColorControlAttributeChangeCallback(endpointId, attributeId, value); + break; +#endif + + default: + ESP_LOGI(TAG, "Unhandled cluster ID: %d", clusterId); + break; + } + + ESP_LOGI(TAG, "Current free heap: %zu\n", heap_caps_get_free_size(MALLOC_CAP_8BIT)); +} + +void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) +{ + if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) + { + ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT); + chip::app::DnssdServer::Instance().StartServer(); + } + else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost) + { + ESP_LOGE(TAG, "Lost IPv4 connectivity..."); + } + if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established) + { + ESP_LOGI(TAG, "IPv6 Server ready..."); + chip::app::DnssdServer::Instance().StartServer(); + } + else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost) + { + ESP_LOGE(TAG, "Lost IPv6 connectivity..."); + } +} + +void DeviceCallbacks::OnSessionEstablished(const ChipDeviceEvent * event) +{ + if (event->SessionEstablished.IsCommissioner) + { + ESP_LOGI(TAG, "Commissioner detected!"); + } +} + +void DeviceCallbacks::OnOnOffPostAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value) +{ + VerifyOrExit(attributeId == OnOff::Attributes::OnOff::Id, ESP_LOGI(TAG, "Unhandled Attribute ID: '0x%04x", attributeId)); + VerifyOrExit(endpointId == 1, ESP_LOGE(TAG, "Unexpected EndPoint ID: `0x%02x'", endpointId)); + + AppLED.Set(*value); + +exit: + return; +} + +void DeviceCallbacks::OnLevelControlAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value) +{ + VerifyOrExit(attributeId == LevelControl::Attributes::CurrentLevel::Id, + ESP_LOGI(TAG, "Unhandled Attribute ID: '0x%04x", attributeId)); + VerifyOrExit(endpointId == 1, ESP_LOGE(TAG, "Unexpected EndPoint ID: `0x%02x'", endpointId)); + + AppLED.SetBrightness(*value); + +exit: + return; +} + +// Currently ColorControl cluster is supported for ESP32C3_DEVKITM and ESP32S3_DEVKITM which have an on-board RGB-LED +#if CONFIG_LED_TYPE_RMT +void DeviceCallbacks::OnColorControlAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value) +{ + uint8_t hue, saturation; + + VerifyOrExit(attributeId == ColorControl::Attributes::CurrentHue::Id || + attributeId == ColorControl::Attributes::CurrentSaturation::Id, + ESP_LOGI(TAG, "Unhandled AttributeId ID: '0x%04x", attributeId)); + VerifyOrExit(endpointId == 1, ESP_LOGE(TAG, "Unexpected EndPoint ID: `0x%02x'", endpointId)); + + if (attributeId == ColorControl::Attributes::CurrentHue::Id) + { + hue = *value; + emberAfReadServerAttribute(endpointId, ColorControl::Id, ColorControl::Attributes::CurrentSaturation::Id, &saturation, + sizeof(uint8_t)); + } + else + { + saturation = *value; + emberAfReadServerAttribute(endpointId, ColorControl::Id, ColorControl::Attributes::CurrentHue::Id, &hue, sizeof(uint8_t)); + } + AppLED.SetColor(hue, saturation); + +exit: + return; +} +#endif // CONFIG_LED_TYPE_RMT diff --git a/examples/lighting-app/esp32/main/Kconfig.projbuild b/examples/lighting-app/esp32/main/Kconfig.projbuild new file mode 100644 index 00000000000000..839c53f3997d5c --- /dev/null +++ b/examples/lighting-app/esp32/main/Kconfig.projbuild @@ -0,0 +1,109 @@ +# +# Copyright (c) 2021 Project CHIP Authors +# All rights reserved. +# +# 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. +# +# Description: +# Configuration options CHIP ESP32 demo application. +# + +menu "Demo" + + choice + prompt "Device Type" + default DEVICE_TYPE_ESP32_DEVKITC if IDF_TARGET_ESP32 + default DEVICE_TYPE_ESP32_C3_DEVKITM if IDF_TARGET_ESP32C3 + default DEVICE_TYPE_ESP32_S3_DEVKITM if IDF_TARGET_ESP32S3 + help + Specifies the type of ESP32 device. + + Note that the "ESP32-DevKitC" choice is compatible with a number of clone devices + available from third-party manufacturers. + + config DEVICE_TYPE_ESP32_DEVKITC + bool "ESP32-DevKitC" + depends on IDF_TARGET_ESP32 + config DEVICE_TYPE_ESP32_WROVER_KIT + bool "ESP32-WROVER-KIT_V4.1" + depends on IDF_TARGET_ESP32 + config DEVICE_TYPE_ESP32_C3_DEVKITM + bool "ESP32C3-DevKitM" + depends on IDF_TARGET_ESP32C3 + config DEVICE_TYPE_ESP32_S3_DEVKITM + bool "ESP32S3-DevKitM" + depends on IDF_TARGET_ESP32S3 + endchoice + + choice LED_TYPE + prompt "LED type" + default LED_TYPE_RMT if DEVICE_TYPE_ESP32_C3_DEVKITM || DEVICE_TYPE_ESP32_S3_DEVKITM + default LED_TYPE_GPIO + help + Defines the default LED type used in the example + + config LED_TYPE_GPIO + bool "GPIO" + config LED_TYPE_RMT + bool "RMT - Addressable LED" + endchoice + + config LED_RMT_CHANNEL + depends on LED_TYPE_RMT + int "RMT Channel" + range 0 7 + default 0 + help + Set the RMT peripheral channel. + ESP32 RMT channel from 0 to 7 + ESP32-S3 RMT channel from 0 to 3 + ESP32-C3 RMT channel from 0 to 1 + + config LED_GPIO + int "LED GPIO number" + range 0 48 + default 26 if DEVICE_TYPE_ESP32_WROVER_KIT + default 8 if DEVICE_TYPE_ESP32_C3_DEVKITM + default 48 if DEVICE_TYPE_ESP32_S3_DEVKITM + default 5 + help + GPIO number (IOxx) to blink on and off or the RMT signal for the addressable LED. + + choice + prompt "Rendezvous Mode" + default RENDEZVOUS_MODE_BLE + help + Specifies the Rendezvous mode of the peripheral. + + config RENDEZVOUS_MODE_BYPASS + bool "Bypass" + config RENDEZVOUS_MODE_WIFI + bool "Wi-Fi" + config RENDEZVOUS_MODE_BLE + bool "BLE" + config RENDEZVOUS_MODE_THREAD + bool "Thread" + config RENDEZVOUS_MODE_ETHERNET + bool "Ethernet" + endchoice + + config RENDEZVOUS_MODE + int + range 0 8 + default 0 if RENDEZVOUS_MODE_BYPASS + default 1 if RENDEZVOUS_MODE_WIFI + default 2 if RENDEZVOUS_MODE_BLE + default 4 if RENDEZVOUS_MODE_THREAD + default 8 if RENDEZVOUS_MODE_ETHERNET + +endmenu diff --git a/examples/lighting-app/esp32/main/LEDWidget.cpp b/examples/lighting-app/esp32/main/LEDWidget.cpp new file mode 100644 index 00000000000000..57a1fba9c3ed8e --- /dev/null +++ b/examples/lighting-app/esp32/main/LEDWidget.cpp @@ -0,0 +1,113 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * 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. + */ + +#include "LEDWidget.h" +#include "color_format.h" + +void LEDWidget::Init(void) +{ + mState = false; + mBrightness = UINT8_MAX; + +#if CONFIG_LED_TYPE_RMT + rmt_config_t config = RMT_DEFAULT_CONFIG_TX((gpio_num_t) CONFIG_LED_GPIO, (rmt_channel_t) CONFIG_LED_RMT_CHANNEL); + led_strip_config_t strip_config = LED_STRIP_DEFAULT_CONFIG(1, (led_strip_dev_t) config.channel); + + config.clk_div = 2; + rmt_config(&config); + rmt_driver_install(config.channel, 0, 0); + + mStrip = led_strip_new_rmt_ws2812(&strip_config); + mHue = 0; + mSaturation = 0; +#else + mGPIONum = (gpio_num_t) CONFIG_LED_GPIO; + ledc_timer_config_t ledc_timer = { + .speed_mode = LEDC_LOW_SPEED_MODE, // timer mode + .duty_resolution = LEDC_TIMER_8_BIT, // resolution of PWM duty + .timer_num = LEDC_TIMER_1, // timer index + .freq_hz = 5000, // frequency of PWM signal + .clk_cfg = LEDC_AUTO_CLK, // Auto select the source clock + }; + ledc_timer_config(&ledc_timer); + ledc_channel_config_t ledc_channel = { + .gpio_num = mGPIONum, + .speed_mode = LEDC_LOW_SPEED_MODE, + .channel = LEDC_CHANNEL_0, + .intr_type = LEDC_INTR_DISABLE, + .timer_sel = LEDC_TIMER_1, + .duty = 0, + .hpoint = 0, + }; + ledc_channel_config(&ledc_channel); +#endif // CONFIG_LED_TYPE_RMT +} + +void LEDWidget::Set(bool state) +{ + if (state == mState) + return; + + mState = state; + + DoSet(); +} + +void LEDWidget::SetBrightness(uint8_t brightness) +{ + if (brightness == mBrightness) + return; + + mBrightness = brightness; + + DoSet(); +} + +#if CONFIG_LED_TYPE_RMT +void LEDWidget::SetColor(uint8_t Hue, uint8_t Saturation) +{ + if (Hue == mHue && Saturation == mSaturation) + return; + + mHue = Hue; + mSaturation = Saturation; + + DoSet(); +} +#endif // CONFIG_LED_TYPE_RMT + +void LEDWidget::DoSet(void) +{ + uint8_t brightness = mState ? mBrightness : 0; + +#if CONFIG_LED_TYPE_RMT + if (mStrip) + { + HsvColor_t hsv = { mHue, mSaturation, brightness }; + RgbColor_t rgb = HsvToRgb(hsv); + + mStrip->set_pixel(mStrip, 0, rgb.r, rgb.g, rgb.b); + mStrip->refresh(mStrip, 100); + } +#else + if (mGPIONum < GPIO_NUM_MAX) + { + ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, brightness); + ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); + } +#endif // CONFIG_LED_TYPE_RMT +} diff --git a/examples/lighting-app/esp32/main/include/CHIPDeviceManager.h b/examples/lighting-app/esp32/main/include/CHIPDeviceManager.h new file mode 100644 index 00000000000000..e3f71df1c84c63 --- /dev/null +++ b/examples/lighting-app/esp32/main/include/CHIPDeviceManager.h @@ -0,0 +1,122 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * This file contains definitions for the CHIP DeviceManager Interface + * + * This object will co-ordinate multiple activities such as + * initialisation, rendezvous, session mgmt and other such + * activities within the CHIP stack. This is a singleton object. + */ + +#pragma once + +#include +#include +#include + +#include + +#include +#include + +#include + +namespace chip { +namespace DeviceManager { + +/** + * @brief + * This class provides a skeleton for all the callback functions. The functions will be + * called by other objects within the CHIP stack for specific events. + * Applications interested in receiving specific callbacks can specialize this class and handle + * these events in their implementation of this class. + */ +class DLL_EXPORT CHIPDeviceManagerCallbacks +{ +public: + /** + * @brief + * Called when CHIP Device events (PublicEventTypes) are triggered. + * + * @param event ChipDeviceEvent that occurred + * @param arg arguments specific to the event, if any + */ + virtual void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); + /** + * @brief + * Called after an attribute has been changed + * + * @param endpoint endpoint id + * @param clusterID cluster id + * @param attributeId attribute id that was changed + * @param mask mask of the attribute + * @param manufacturerCode manufacturer code + * @param type attribute type + * @param size size of the attribute + * @param value pointer to the new value + */ + virtual void PostAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId, + uint8_t mask, uint8_t type, uint16_t size, uint8_t * value) + {} + virtual ~CHIPDeviceManagerCallbacks() {} +}; + +/** + * @brief + * A common class that drives other components of the CHIP stack + */ +class DLL_EXPORT CHIPDeviceManager +{ +public: + CHIPDeviceManager(const CHIPDeviceManager &) = delete; + CHIPDeviceManager(const CHIPDeviceManager &&) = delete; + CHIPDeviceManager & operator=(const CHIPDeviceManager &) = delete; + + static CHIPDeviceManager & GetInstance() + { + static CHIPDeviceManager instance; + return instance; + } + + /** + * @brief + * Initialise CHIPDeviceManager + * + * @param cb Application's instance of the CHIPDeviceManagerCallbacks for consuming events + */ + CHIP_ERROR Init(CHIPDeviceManagerCallbacks * cb); + /** + * @brief + * Fetch a pointer to the registered CHIPDeviceManagerCallbacks object. + * + */ + CHIPDeviceManagerCallbacks * GetCHIPDeviceManagerCallbacks() { return mCB; } + + /** + * Use internally for registration of the ChipDeviceEvents + */ + static void CommonDeviceEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); + +private: + CHIPDeviceManagerCallbacks * mCB = nullptr; + CHIPDeviceManager() {} +}; + +} // namespace DeviceManager +} // namespace chip diff --git a/examples/lighting-app/esp32/main/include/DeviceCallbacks.h b/examples/lighting-app/esp32/main/include/DeviceCallbacks.h new file mode 100644 index 00000000000000..31ca1dfa738cd5 --- /dev/null +++ b/examples/lighting-app/esp32/main/include/DeviceCallbacks.h @@ -0,0 +1,48 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +/** + * @file DeviceCallbacks.h + * + * Implementations for the DeviceManager callbacks for this application + * + **/ + +#pragma once + +#include "CHIPDeviceManager.h" +#include +#include + +class DeviceCallbacks : public chip::DeviceManager::CHIPDeviceManagerCallbacks +{ +public: + virtual void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); + virtual void PostAttributeChangeCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, chip::AttributeId attributeId, + uint8_t mask, uint8_t type, uint16_t size, uint8_t * value); + +private: + void OnInternetConnectivityChange(const chip::DeviceLayer::ChipDeviceEvent * event); + void OnSessionEstablished(const chip::DeviceLayer::ChipDeviceEvent * event); + void OnIdentifyPostAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value); + void OnOnOffPostAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value); + void OnLevelControlAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value); +#if CONFIG_LED_TYPE_RMT + void OnColorControlAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value); +#endif +}; diff --git a/examples/lighting-app/esp32/main/include/LEDWidget.h b/examples/lighting-app/esp32/main/include/LEDWidget.h new file mode 100644 index 00000000000000..c60ee9271c207c --- /dev/null +++ b/examples/lighting-app/esp32/main/include/LEDWidget.h @@ -0,0 +1,56 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * 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 "driver/gpio.h" + +#if CONFIG_LED_TYPE_RMT +#include "driver/rmt.h" +#include "led_strip.h" +#else +#include "driver/ledc.h" +#include "hal/ledc_types.h" +#endif + +class LEDWidget +{ +public: + void Init(void); + + void Set(bool state); + + void SetBrightness(uint8_t brightness); + +#if CONFIG_LED_TYPE_RMT + void SetColor(uint8_t Hue, uint8_t Saturation); +#endif + +private: + bool mState; + uint8_t mBrightness; + +#if CONFIG_LED_TYPE_RMT + uint8_t mHue; + uint8_t mSaturation; + led_strip_t * mStrip; +#else + gpio_num_t mGPIONum; +#endif + + void DoSet(void); +}; diff --git a/examples/lighting-app/esp32/main/main.cpp b/examples/lighting-app/esp32/main/main.cpp new file mode 100644 index 00000000000000..5a703183850757 --- /dev/null +++ b/examples/lighting-app/esp32/main/main.cpp @@ -0,0 +1,86 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * 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. + */ + +#include "CHIPDeviceManager.h" +#include "DeviceCallbacks.h" +#include "LEDWidget.h" + +#include "esp_log.h" +#include "esp_spi_flash.h" +#include "esp_system.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "nvs_flash.h" +#include "shell_extension/launch.h" +#include +#include +#include +#include + +using namespace ::chip; +using namespace ::chip::Credentials; +using namespace ::chip::DeviceManager; +using namespace ::chip::DeviceLayer; + +LEDWidget AppLED; + +static const char * TAG = "light-app"; + +static DeviceCallbacks EchoCallbacks; + +static void InitServer(intptr_t context) +{ + // Print QR Code URL + PrintOnboardingCodes(chip::RendezvousInformationFlags(CONFIG_RENDEZVOUS_MODE)); + + chip::Server::GetInstance().Init(); + + // Initialize device attestation config + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +} + +extern "C" void app_main() +{ + // Initialize the ESP NVS layer. + esp_err_t err = nvs_flash_init(); + if (err != ESP_OK) + { + ESP_LOGE(TAG, "nvs_flash_init() failed: %s", esp_err_to_name(err)); + return; + } + + ESP_LOGI(TAG, "=================================================="); + ESP_LOGI(TAG, "chip-esp32-light-example starting"); + ESP_LOGI(TAG, "=================================================="); + +#if CONFIG_ENABLE_CHIP_SHELL + chip::LaunchShell(); +#endif + + CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance(); + + CHIP_ERROR error = deviceMgr.Init(&EchoCallbacks); + if (error != CHIP_NO_ERROR) + { + ESP_LOGE(TAG, "device.Init() failed: %s", ErrorStr(error)); + return; + } + + AppLED.Init(); + + chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, reinterpret_cast(nullptr)); +} diff --git a/examples/lighting-app/esp32/partitions.csv b/examples/lighting-app/esp32/partitions.csv new file mode 100644 index 00000000000000..b338ff11a11589 --- /dev/null +++ b/examples/lighting-app/esp32/partitions.csv @@ -0,0 +1,6 @@ +# Name, Type, SubType, Offset, Size, Flags +# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap +nvs, data, nvs, , 0x6000, +phy_init, data, phy, , 0x1000, +# Factory partition size about 1.9MB +factory, app, factory, , 1945K, diff --git a/examples/lighting-app/esp32/sdkconfig.defaults b/examples/lighting-app/esp32/sdkconfig.defaults new file mode 100644 index 00000000000000..85e84a2001e385 --- /dev/null +++ b/examples/lighting-app/esp32/sdkconfig.defaults @@ -0,0 +1,41 @@ +# +# Copyright (c) 2021 Project CHIP Authors +# All rights reserved. +# +# 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. +# +# Description: +# Some useful defaults for the demo app configuration. +# + +# 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 + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y + +#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" + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y diff --git a/examples/lighting-app/esp32/third_party/connectedhomeip b/examples/lighting-app/esp32/third_party/connectedhomeip new file mode 120000 index 00000000000000..11a54ed360106c --- /dev/null +++ b/examples/lighting-app/esp32/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../../ \ No newline at end of file From 73fb8c3aeb58a1b74c701e80bf78d9d08e9212a5 Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Wed, 5 Jan 2022 11:45:49 +0800 Subject: [PATCH 2/2] [esp32] Enable light example compilation in CI --- .github/workflows/examples-esp32.yaml | 5 ++++- examples/lighting-app/esp32/CMakeLists.txt | 2 +- scripts/build/build/targets.py | 1 + scripts/build/builders/esp32.py | 5 +++++ .../build/testdata/all_targets_except_host.txt | 1 + .../build/testdata/build_all_except_host.txt | 18 ++++++++++++++++++ .../testdata/glob_star_targets_except_host.txt | 1 + 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.github/workflows/examples-esp32.yaml b/.github/workflows/examples-esp32.yaml index 54298cf4320eb5..decbb6af143bb3 100644 --- a/.github/workflows/examples-esp32.yaml +++ b/.github/workflows/examples-esp32.yaml @@ -26,7 +26,7 @@ jobs: # TODO ESP32 https://github.com/project-chip/connectedhomeip/issues/1510 esp32: name: ESP32 - timeout-minutes: 95 + timeout-minutes: 105 runs-on: ubuntu-latest if: github.actor != 'restyled-io[bot]' @@ -90,6 +90,9 @@ jobs: - name: Build example Pigweed App timeout-minutes: 10 run: scripts/examples/esp_example.sh pigweed-app sdkconfig.defaults + - name: Build example Lighting App + timeout-minutes: 10 + run: scripts/examples/esp_example.sh lighting-app sdkconfig.defaults - name: Build example Lock App timeout-minutes: 10 run: scripts/examples/esp_example.sh lock-app sdkconfig.defaults diff --git a/examples/lighting-app/esp32/CMakeLists.txt b/examples/lighting-app/esp32/CMakeLists.txt index dff200257ea9ad..3c73988719f27e 100644 --- a/examples/lighting-app/esp32/CMakeLists.txt +++ b/examples/lighting-app/esp32/CMakeLists.txt @@ -26,7 +26,7 @@ set(EXTRA_COMPONENT_DIRS "${IDF_PATH}/examples/common_components" ) -project(chip-light-app) +project(chip-lighting-app) # C++17 is required for RPC build. idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND) diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index e7d87bd84cfca4..34b6eb2218352f 100644 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -217,6 +217,7 @@ def Esp32Targets(): yield devkitc.Extend('all-clusters', app=Esp32App.ALL_CLUSTERS) yield devkitc.Extend('all-clusters-ipv6only', app=Esp32App.ALL_CLUSTERS, enable_ipv4=False) yield devkitc.Extend('shell', app=Esp32App.SHELL) + yield devkitc.Extend('light', app=Esp32App.LIGHT) yield devkitc.Extend('lock', app=Esp32App.LOCK) yield devkitc.Extend('bridge', app=Esp32App.BRIDGE) yield devkitc.Extend('temperature-measurement', app=Esp32App.TEMPERATURE_MEASUREMENT) diff --git a/scripts/build/builders/esp32.py b/scripts/build/builders/esp32.py index e99ab8e291b1b7..0647bea7b7a5a9 100644 --- a/scripts/build/builders/esp32.py +++ b/scripts/build/builders/esp32.py @@ -30,6 +30,7 @@ class Esp32Board(Enum): class Esp32App(Enum): ALL_CLUSTERS = auto() + LIGHT = auto() LOCK = auto() SHELL = auto() BRIDGE = auto() @@ -40,6 +41,8 @@ class Esp32App(Enum): def ExamplePath(self): if self == Esp32App.ALL_CLUSTERS: return 'examples/all-clusters-app' + elif self == Esp32App.LIGHT: + return 'examples/lighting-app' elif self == Esp32App.LOCK: return 'examples/lock-app' elif self == Esp32App.SHELL: @@ -57,6 +60,8 @@ def ExamplePath(self): def AppNamePrefix(self): if self == Esp32App.ALL_CLUSTERS: return 'chip-all-clusters-app' + elif self == Esp32App.LIGHT: + return 'chip-lighting-app' elif self == Esp32App.LOCK: return 'chip-lock-app' elif self == Esp32App.SHELL: diff --git a/scripts/build/testdata/all_targets_except_host.txt b/scripts/build/testdata/all_targets_except_host.txt index 49e67f381a020d..d57be9ffa95dd3 100644 --- a/scripts/build/testdata/all_targets_except_host.txt +++ b/scripts/build/testdata/all_targets_except_host.txt @@ -64,6 +64,7 @@ esp32-c3devkit-all-clusters esp32-devkitc-all-clusters esp32-devkitc-all-clusters-ipv6only esp32-devkitc-bridge +esp32-devkitc-light esp32-devkitc-lock esp32-devkitc-shell esp32-devkitc-temperature-measurement diff --git a/scripts/build/testdata/build_all_except_host.txt b/scripts/build/testdata/build_all_except_host.txt index 349750e4921865..dc2667b3769282 100644 --- a/scripts/build/testdata/build_all_except_host.txt +++ b/scripts/build/testdata/build_all_except_host.txt @@ -332,6 +332,17 @@ bash -c 'source $IDF_PATH/export.sh; source scripts/activate.sh; export SDKCONFIG_DEFAULTS={out}/esp32-devkitc-bridge/sdkconfig.defaults idf.py -C examples/bridge-app/esp32 -B {out}/esp32-devkitc-bridge reconfigure' +# Generating esp32-devkitc-light +mkdir -p {out}/esp32-devkitc-light + +cp examples/lighting-app/esp32/sdkconfig.defaults {out}/esp32-devkitc-light/sdkconfig.defaults + +rm -f examples/lighting-app/esp32/sdkconfig + +bash -c 'source $IDF_PATH/export.sh; source scripts/activate.sh; +export SDKCONFIG_DEFAULTS={out}/esp32-devkitc-light/sdkconfig.defaults +idf.py -C examples/lighting-app/esp32 -B {out}/esp32-devkitc-light reconfigure' + # Generating esp32-devkitc-lock mkdir -p {out}/esp32-devkitc-lock @@ -970,6 +981,13 @@ bash -c 'source $IDF_PATH/export.sh; source scripts/activate.sh; export SDKCONFIG_DEFAULTS={out}/esp32-devkitc-bridge/sdkconfig.defaults idf.py -C examples/bridge-app/esp32 -B {out}/esp32-devkitc-bridge build' +rm -f examples/lighting-app/esp32/sdkconfig + +# Building esp32-devkitc-light +bash -c 'source $IDF_PATH/export.sh; source scripts/activate.sh; +export SDKCONFIG_DEFAULTS={out}/esp32-devkitc-light/sdkconfig.defaults +idf.py -C examples/lighting-app/esp32 -B {out}/esp32-devkitc-light build' + rm -f examples/lock-app/esp32/sdkconfig # Building esp32-devkitc-lock diff --git a/scripts/build/testdata/glob_star_targets_except_host.txt b/scripts/build/testdata/glob_star_targets_except_host.txt index e95ba534e53536..4e35246d9f2abf 100644 --- a/scripts/build/testdata/glob_star_targets_except_host.txt +++ b/scripts/build/testdata/glob_star_targets_except_host.txt @@ -22,6 +22,7 @@ esp32-c3devkit-all-clusters esp32-devkitc-all-clusters esp32-devkitc-all-clusters-ipv6only esp32-devkitc-bridge +esp32-devkitc-light esp32-devkitc-lock esp32-devkitc-shell esp32-devkitc-temperature-measurement