-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'on_off_plugin_unit' into 'main'
Multiple On Off plugin units example See merge request app-frameworks/esp-matter!786
- Loading branch information
Showing
21 changed files
with
1,055 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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) | ||
|
||
if(NOT DEFINED ENV{ESP_MATTER_PATH}) | ||
message(FATAL_ERROR "Please set ESP_MATTER_PATH to the path of esp-matter repo") | ||
endif(NOT DEFINED ENV{ESP_MATTER_PATH}) | ||
|
||
set(PROJECT_VER "1.0") | ||
set(PROJECT_VER_NUMBER 1) | ||
|
||
set(ESP_MATTER_PATH $ENV{ESP_MATTER_PATH}) | ||
set(MATTER_SDK_PATH ${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip) | ||
|
||
# This should be done before using the IDF_TARGET variable. | ||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
include(${ESP_MATTER_PATH}/examples/common/cmake_common/components_include.cmake) | ||
|
||
set(EXTRA_COMPONENT_DIRS | ||
"${MATTER_SDK_PATH}/config/esp32/components" | ||
"${ESP_MATTER_PATH}/components" | ||
${extra_components_dirs_append}) | ||
|
||
project(multiple_on_off_plugin_units) | ||
|
||
# WARNING: This is just an example for using key for decrypting the encrypted OTA image | ||
# Please do not use it as is. | ||
if(CONFIG_ENABLE_ENCRYPTED_OTA) | ||
target_add_binary_data(light.elf "esp_image_encryption_key.pem" TEXT) | ||
endif() | ||
|
||
if(CONFIG_IDF_TARGET_ESP32C2) | ||
include(relinker) | ||
endif() | ||
|
||
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DCHIP_HAVE_CONFIG_H;-Wno-overloaded-virtual" APPEND) | ||
idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND) | ||
# For RISCV chips, project_include.cmake sets -Wno-format, but does not clear various | ||
# flags that depend on -Wformat | ||
idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Multiple On Off plugin unit | ||
|
||
This example demonstrates the creation of a Multiple On-Off Plugin Unit, where multiple endpoints are mapped to GPIO pins. | ||
|
||
## Plugin Manager Configuration | ||
Three default on-off plugin units have been created. You can create similar plugin units. | ||
|
||
To update the existing CONFIG_GPIO_PLUG values, follow these steps: | ||
|
||
1. Open a terminal. | ||
1. Run the following command to access the configuration menu: | ||
`idf.py menuconfig` | ||
1. Navigate to the "Plugin manager" menu. | ||
1. Update the GPIO pin number values (**Use only available GPIO pins as per the target chip**). | ||
|
||
|
||
You can update maximum configurable plugin units from same menu. | ||
|
||
See the [docs](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html) for more information about building and flashing the firmware. | ||
|
||
## 1. Additional Environment Setup | ||
|
||
No additional setup is required. | ||
|
||
## 2. Post Commissioning Setup | ||
|
||
No additional setup is required. | ||
|
||
## 3. Device Performance | ||
|
||
### 3.1 Memory usage | ||
|
||
The following is the Memory and Flash Usage. | ||
|
||
- `Bootup` == Device just finished booting up. Device is not | ||
commissionined or connected to wifi yet. | ||
- `After Commissioning` == Device is conneted to wifi and is also | ||
commissioned and is rebooted. | ||
- device used: esp32c3_devkit_m | ||
- tested on: | ||
[6a244a7](https://github.com/espressif/esp-matter/commit/6a244a7b1e5c70b0aa1bf57254f19718b0755d95) | ||
(2022-06-16) | ||
|
||
| | Bootup | After Commissioning | | ||
|:- |:-: |:-: | | ||
|**Free Internal Memory** | 212KB |127KB | | ||
|
||
**Flash Usage**: Firmware binary size: 1.40MB | ||
|
||
This should give you a good idea about the amount of free memory that is | ||
available for you to run your application's code. | ||
|
||
Applications that do not require BLE post commissioning, can disable it using app_ble_disable() once commissioning is complete. It is not done explicitly because of a known issue with esp32c3 and will be fixed with the next IDF release (v4.4.2). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
idf_component_register(SRC_DIRS "." | ||
PRIV_INCLUDE_DIRS "." "${ESP_MATTER_PATH}/examples/common/utils") | ||
|
||
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) | ||
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") |
25 changes: 25 additions & 0 deletions
25
examples/multiple_on_off_plugin_units/main/Kconfig.projbuild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
menu "Plugin manager" | ||
config MAX_CONFIGURABLE_PLUGS | ||
int "Maximum virtual configurable plugs" | ||
default 5 | ||
range 1 16 | ||
|
||
config GPIO_PLUG_1 | ||
int "GPIO pin number for plug 1" | ||
default 3 if IDF_TARGET_ESP32S3 | ||
default 2 if !IDF_TARGET_ESP32S3 | ||
help | ||
Set GPIO pin value for target chip to create plugin unit | ||
|
||
config GPIO_PLUG_2 | ||
int "GPIO pin number for plug 2" | ||
default 4 | ||
help | ||
Set GPIO pin value for target chip to create plugin unit | ||
|
||
config GPIO_PLUG_3 | ||
int "GPIO pin number for plug 3" | ||
default 5 | ||
help | ||
Set GPIO pin value for target chip to create plugin unit | ||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
This example code is in the Public Domain (or CC0 licensed, at your option.) | ||
Unless required by applicable law or agreed to in writing, this | ||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
CONDITIONS OF ANY KIND, either express or implied. | ||
*/ | ||
|
||
#include <esp_log.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "driver/gpio.h" | ||
|
||
#include <esp_matter.h> | ||
|
||
#include <app_priv.h> | ||
|
||
using namespace chip::app::Clusters; | ||
using namespace esp_matter; | ||
|
||
static const char *TAG = "app_driver"; | ||
|
||
static esp_err_t app_driver_update_gpio_value(gpio_num_t pin, bool value) | ||
{ | ||
esp_err_t err = ESP_OK; | ||
|
||
err = gpio_set_level(pin, value); | ||
if (err != ESP_OK) { | ||
ESP_LOGE(TAG, "Failed to set GPIO level"); | ||
return ESP_FAIL; | ||
} else { | ||
ESP_LOGI(TAG, "GPIO pin : %d set to %d", pin, value); | ||
} | ||
return err; | ||
} | ||
|
||
esp_err_t app_driver_plugin_unit_init(const gpio_plug* plug) | ||
{ | ||
esp_err_t err = ESP_OK; | ||
|
||
gpio_reset_pin(plug->GPIO_PIN_VALUE); | ||
|
||
err = gpio_set_direction(plug->GPIO_PIN_VALUE, GPIO_MODE_OUTPUT); | ||
if (err != ESP_OK) { | ||
ESP_LOGE(TAG, "Unable to set GPIO OUTPUT mode"); | ||
return ESP_FAIL; | ||
} | ||
|
||
err = gpio_set_level(plug->GPIO_PIN_VALUE, 0); | ||
if (err != ESP_OK) { | ||
ESP_LOGI(TAG, "Unable to set GPIO level"); | ||
} | ||
return err; | ||
} | ||
|
||
// Return GPIO pin from plug-endpoint mapping list | ||
gpio_num_t get_gpio(uint16_t endpoint_id) | ||
{ | ||
gpio_num_t gpio_pin = GPIO_NUM_NC; | ||
for (int i = 0; i < s_configure_plugs; i++) { | ||
if (s_plugin_unit_list[i].endpoint_id == endpoint_id) { | ||
gpio_pin = s_plugin_unit_list[i].plug; | ||
} | ||
} | ||
return gpio_pin; | ||
} | ||
|
||
|
||
esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id, | ||
uint32_t attribute_id, esp_matter_attr_val_t *val) | ||
{ | ||
esp_err_t err = ESP_OK; | ||
|
||
if (cluster_id == OnOff::Id) { | ||
if (attribute_id == OnOff::Attributes::OnOff::Id) { | ||
gpio_num_t gpio_pin = get_gpio(endpoint_id); | ||
if (gpio_pin != GPIO_NUM_NC) { | ||
err = app_driver_update_gpio_value(gpio_pin, val->val.b); | ||
} else { | ||
ESP_LOGE(TAG, "GPIO pin mapping for endpoint_id: %d not found", endpoint_id); | ||
return ESP_FAIL; | ||
} | ||
} | ||
} | ||
return err; | ||
} | ||
|
||
|
Oops, something went wrong.