examples: Update the button component to latest version.

- Driver specific changes for updated button component in examples.
- Updated the device_hal code for button component upgrade.
- Updated the idf_component.yml of examples to use latest version of espressif/cmake_utilities.
This commit is contained in:
shripad621git
2025-04-04 11:33:51 +05:30
parent 2d2c921f8f
commit 7557f0b87f
40 changed files with 298 additions and 164 deletions
@@ -16,10 +16,18 @@
static const char *TAG = "button_driver_hollow";
button_handle_t iot_button_create(const button_config_t *config)
esp_err_t iot_button_new_gpio_device(const button_config_t *button_config, const button_gpio_config_t *gpio_cfg, button_handle_t *ret_button)
{
ESP_LOGI(TAG, "Button create");
return NULL;
*ret_button = NULL;
return ESP_OK;
}
esp_err_t iot_button_new_adc_device(const button_config_t *button_config, const button_adc_config_t *adc_config, button_handle_t *ret_button)
{
ESP_LOGI(TAG, "Button create");
*ret_button = NULL;
return ESP_OK;
}
esp_err_t iot_button_delete(button_handle_t btn_handle)
@@ -28,13 +36,13 @@ esp_err_t iot_button_delete(button_handle_t btn_handle)
return ESP_OK;
}
esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t event, button_cb_t cb, void *usr_data)
esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t event, button_event_args_t *event_args, button_cb_t cb, void *usr_data)
{
ESP_LOGI(TAG, "Button register callback");
return ESP_OK;
}
esp_err_t iot_button_unregister_cb(button_handle_t btn_handle, button_event_t event)
esp_err_t iot_button_unregister_cb(button_handle_t btn_handle, button_event_t event, button_event_args_t *event_args)
{
ESP_LOGI(TAG, "Button unregister callback");
return ESP_OK;
@@ -35,11 +35,34 @@ typedef enum {
BUTTON_PRESS_REPEAT_DONE,
BUTTON_SINGLE_CLICK,
BUTTON_DOUBLE_CLICK,
BUTTON_MULTIPLE_CLICK,
BUTTON_LONG_PRESS_START,
BUTTON_LONG_PRESS_HOLD,
BUTTON_LONG_PRESS_UP,
BUTTON_PRESS_END,
BUTTON_EVENT_MAX,
BUTTON_NONE_PRESS,
} button_event_t;
/**
* @brief Button events arg
*
*/
typedef union {
/**
* @brief Long press time event data
*
*/
struct long_press_t {
uint16_t press_time; /**< press time(ms) for the corresponding callback to trigger */
} long_press; /**< long press struct, for event BUTTON_LONG_PRESS_START and BUTTON_LONG_PRESS_UP */
/**
* @brief Multiple clicks event data
*
*/
struct multiple_clicks_t {
uint16_t clicks; /**< number of clicks, to trigger the callback */
} multiple_clicks; /**< multiple clicks struct, for event BUTTON_MULTIPLE_CLICK */
} button_event_args_t;
/**
* @brief Supported button type
@@ -55,23 +78,27 @@ typedef enum {
*
*/
typedef struct {
button_type_t type; /**< button type, The corresponding button configuration must be filled */
uint16_t long_press_time; /**< Trigger time(ms) for long press, if 0 default to BUTTON_LONG_PRESS_TIME_MS */
uint16_t short_press_time; /**< Trigger time(ms) for short press, if 0 default to BUTTON_SHORT_PRESS_TIME_MS */
union {
button_gpio_config_t gpio_button_config; /**< gpio button configuration */
button_adc_config_t adc_button_config; /**< adc button configuration */
}; /**< button configuration */
uint16_t long_press_time; /**< Trigger time(ms) for long press, if 0 default to BUTTON_LONG_PRESS_TIME_MS */
uint16_t short_press_time; /**< Trigger time(ms) for short press, if 0 default to BUTTON_SHORT_PRESS_TIME_MS */
} button_config_t;
/**
* @brief Create a button
* @brief Create a GPIO button
*
* @param config pointer of button configuration, must corresponding the button type
*
* @return A handle to the created button, or NULL in case of error.
*/
button_handle_t iot_button_create(const button_config_t *config);
esp_err_t iot_button_new_gpio_device(const button_config_t *button_config, const button_gpio_config_t *gpio_cfg, button_handle_t *ret_button);
/**
* @brief Create a GPIO button
*
* @param config pointer of button configuration, must corresponding the button type
*
* @return A handle to the created button, or NULL in case of error.
*/
esp_err_t iot_button_new_adc_device(const button_config_t *button_config, const button_adc_config_t *adc_config, button_handle_t *ret_button);
/**
* @brief Delete a button
@@ -89,6 +116,7 @@ esp_err_t iot_button_delete(button_handle_t btn_handle);
*
* @param btn_handle A button handle to register
* @param event Button event
* @param event_args Button event arguments
* @param cb Callback function.
* @param usr_data user data
*
@@ -96,19 +124,20 @@ esp_err_t iot_button_delete(button_handle_t btn_handle);
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG Arguments is invalid.
*/
esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t event, button_cb_t cb, void *usr_data);
esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t event, button_event_args_t *event_args, button_cb_t cb, void *usr_data);
/**
* @brief Unregister the button event callback function.
*
* @param btn_handle A button handle to unregister
* @param event Button event
* @param event_args Button event arguments
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG Arguments is invalid.
*/
esp_err_t iot_button_unregister_cb(button_handle_t btn_handle, button_event_t event);
esp_err_t iot_button_unregister_cb(button_handle_t btn_handle, button_event_t event, button_event_args_t *event_args);
/**
* @brief how many Callbacks are still registered.
@@ -1,3 +1,3 @@
## IDF Component Manager Manifest File
dependencies:
espressif/button: "=2.5.0"
espressif/button: "^4"
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h>
#include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_5
@@ -28,14 +30,11 @@ led_driver_config_t led_driver_get_config()
return config;
}
button_config_t button_driver_get_config()
button_gpio_config_t button_driver_get_config()
{
button_config_t config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
button_gpio_config_t config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
};
return config;
}
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h>
#include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_8
@@ -30,14 +32,11 @@ led_driver_config_t led_driver_get_config()
return config;
}
button_config_t button_driver_get_config()
button_gpio_config_t button_driver_get_config()
{
button_config_t config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
button_gpio_config_t config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
};
return config;
}
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h>
#include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_8
@@ -29,14 +31,11 @@ led_driver_config_t led_driver_get_config()
return config;
}
button_config_t button_driver_get_config()
button_gpio_config_t button_driver_get_config()
{
button_config_t config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
button_gpio_config_t config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
};
return config;
}
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h>
#include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_8
@@ -30,14 +32,11 @@ led_driver_config_t led_driver_get_config()
return config;
}
button_config_t button_driver_get_config()
button_gpio_config_t button_driver_get_config()
{
button_config_t config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
button_gpio_config_t config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
};
return config;
}
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h>
#include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_8
@@ -28,14 +30,11 @@ led_driver_config_t led_driver_get_config()
return config;
}
button_config_t button_driver_get_config()
button_gpio_config_t button_driver_get_config()
{
button_config_t config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
button_gpio_config_t config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
};
return config;
}
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h>
#include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_38
@@ -28,14 +30,11 @@ led_driver_config_t led_driver_get_config()
return config;
}
button_config_t button_driver_get_config()
button_gpio_config_t button_driver_get_config()
{
button_config_t config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
button_gpio_config_t config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
};
return config;
}
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h>
#include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_8
@@ -28,14 +30,11 @@ led_driver_config_t led_driver_get_config()
return config;
}
button_config_t button_driver_get_config()
button_gpio_config_t button_driver_get_config()
{
button_config_t config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
button_gpio_config_t config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
};
return config;
}
+3 -2
View File
@@ -13,15 +13,16 @@
#pragma once
#include <iot_button.h>
#include <led_driver.h>
#include <iot_button.h>
#include <button_gpio.h>
#ifdef __cplusplus
extern "C" {
#endif
led_driver_config_t led_driver_get_config();
button_config_t button_driver_get_config();
button_gpio_config_t button_driver_get_config();
#ifdef __cplusplus
}
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h>
#include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h>
#define LED_GPIO_PIN 32 /* PIN_NUM_BCKL for M5Stack TFT */
@@ -28,14 +30,11 @@ led_driver_config_t led_driver_get_config()
return config;
}
button_config_t button_driver_get_config()
button_gpio_config_t button_driver_get_config()
{
button_config_t config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
button_gpio_config_t config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
};
return config;
}
@@ -9,11 +9,12 @@
#include <string.h>
#include "math.h"
#include "driver/gpio.h"
#include "esp_err.h"
#include "esp_timer.h"
#include "fan_hal_bldc.h"
#include "driver/gpio.h"
#include "iot_button.h"
#include "button_gpio.h"
#include "fan_hal_bldc.h"
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S3
#define PI 3.14159265f
@@ -67,16 +68,19 @@ static void hal_bldc_timer_cb(void *args)
esp_err_t hal_bldc_button_ctrl_init(gpio_num_t pin)
{
button_config_t cfg = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = pin,
.active_level = 0,
},
/* Initialize button */
button_handle_t btn = NULL;
const button_config_t btn_cfg = {0};
const button_gpio_config_t btn_gpio_cfg = {
.gpio_num = pin,
.active_level = 0,
};
button_handle_t btn = iot_button_create(&cfg);
if (iot_button_register_cb(btn, BUTTON_PRESS_DOWN, hal_bldc_button_ctrl, &btn) != ESP_OK) {
if (iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &btn) != ESP_OK) {
return ESP_FAIL;
}
if (iot_button_register_cb(btn, BUTTON_PRESS_DOWN, NULL, hal_bldc_button_ctrl, &btn) != ESP_OK) {
return ESP_FAIL;
}
@@ -1,6 +1,6 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
@@ -6,19 +6,18 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <esp_log.h>
#include <stdlib.h>
#include <string.h>
#include <device.h>
#include <esp_log.h>
#include <esp_matter.h>
#include <esp_matter_console.h>
#include <led_driver.h>
#include <app_priv.h>
#include <app/server/Server.h>
#include "app/CommandPathParams.h"
#include <device.h>
using namespace chip::app::Clusters;
using namespace esp_matter;
@@ -353,9 +352,16 @@ app_driver_handle_t app_driver_light_init()
app_driver_handle_t app_driver_button_init()
{
/* Initialize button */
button_config_t config = button_driver_get_config();
button_handle_t handle = iot_button_create(&config);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
button_handle_t handle = NULL;
const button_config_t btn_cfg = {0};
const button_gpio_config_t btn_gpio_cfg = button_driver_get_config();
if (iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create button device");
return NULL;
}
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, NULL, app_driver_button_toggle_cb, NULL);
#if CONFIG_ENABLE_CHIP_SHELL
app_driver_register_commands();
+2 -2
View File
@@ -42,7 +42,7 @@ esp_err_t app_reset_button_register(void *handle)
}
button_handle_t button_handle = (button_handle_t)handle;
esp_err_t err = ESP_OK;
err |= iot_button_register_cb(button_handle, BUTTON_LONG_PRESS_HOLD, button_factory_reset_pressed_cb, NULL);
err |= iot_button_register_cb(button_handle, BUTTON_PRESS_UP, button_factory_reset_released_cb, NULL);
err |= iot_button_register_cb(button_handle, BUTTON_LONG_PRESS_HOLD, NULL, button_factory_reset_pressed_cb, NULL);
err |= iot_button_register_cb(button_handle, BUTTON_PRESS_UP, NULL, button_factory_reset_released_cb, NULL);
return err;
}
+1 -1
View File
@@ -14,7 +14,7 @@
*
* Register factory reset functionality on a button.
*
* @param[in] handle Button handle returned by iot_button_create().
* @param[in] handle Button handle returned by iot_button_new_*_device().
*
* @return ESP_OK on success.
* @return error in case of failure.
+2 -2
View File
@@ -181,8 +181,8 @@ app_driver_handle_t app_driver_button_init()
/* Initialize button */
button_handle_t btns[BSP_BUTTON_NUM];
ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, BSP_BUTTON_NUM));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_LONG_PRESS_START, factory_reset_badge, NULL));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_DOWN, NULL, app_driver_button_toggle_cb, NULL));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_LONG_PRESS_START, NULL, factory_reset_badge, NULL));
return (app_driver_handle_t)btns[0];
}
+1 -1
View File
@@ -1,5 +1,5 @@
dependencies:
espressif/esp_bsp_devkit:
version: "^1.0.0"
version: "^3"
espressif/led_strip:
version: "^2.0.0"
+2 -2
View File
@@ -1,10 +1,10 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
esp_bsp_devkit:
version: "^1.0.0"
version: "^3"
espressif/led_strip:
version: "^2.0.0"
+26 -15
View File
@@ -15,6 +15,7 @@
#include <app_priv.h>
#include <iot_button.h>
#include <button_gpio.h>
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S3
#define BUTTON_GPIO_PIN GPIO_NUM_0
@@ -157,30 +158,40 @@ static void app_driver_button_multipress_complete(void *arg, void *data)
app_driver_handle_t app_driver_button_init(gpio_button * button)
{
button_config_t config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
};
/* Initialize button */
button_handle_t handle = NULL;
const button_config_t btn_cfg = {0};
if (button != NULL) {
config.type = button_type_t::BUTTON_TYPE_GPIO;
config.gpio_button_config.gpio_num = button->GPIO_PIN_VALUE;
const button_gpio_config_t btn_gpio_cfg = {
.gpio_num = button->GPIO_PIN_VALUE,
.active_level = 0,
};
if (iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create button device");
return NULL;
}
} else {
const button_gpio_config_t btn_gpio_cfg = {
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
};
if (iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create button device");
return NULL;
}
}
button_handle_t handle = iot_button_create(&config);
#if CONFIG_GENERIC_SWITCH_TYPE_LATCHING
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_switch_latched, button);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, NULL, app_driver_button_switch_latched, button);
#endif
#if CONFIG_GENERIC_SWITCH_TYPE_MOMENTARY
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_initial_pressed, button);
iot_button_register_cb(handle, BUTTON_PRESS_UP, app_driver_button_release, button);
iot_button_register_cb(handle, BUTTON_PRESS_REPEAT, app_driver_button_multipress_ongoing, button);
iot_button_register_cb(handle, BUTTON_PRESS_REPEAT_DONE, app_driver_button_multipress_complete, button);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, NULL, app_driver_button_initial_pressed, button);
iot_button_register_cb(handle, BUTTON_PRESS_UP, NULL, app_driver_button_release, button);
iot_button_register_cb(handle, BUTTON_PRESS_REPEAT, NULL, app_driver_button_multipress_ongoing, button);
iot_button_register_cb(handle, BUTTON_PRESS_REPEAT_DONE, NULL, app_driver_button_multipress_complete, button);
#endif
return (app_driver_handle_t)handle;
}
@@ -1,8 +1,8 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
espressif/button: "=2.5.0"
espressif/button: "^4"
+15 -9
View File
@@ -6,12 +6,13 @@
#include <esp_log.h>
#include <esp_matter.h>
#include <iot_button.h>
#include <sdkconfig.h>
#include <app/icd/server/ICDNotifier.h>
#include <app_priv.h>
#include <iot_button.h>
#include <button_gpio.h>
#ifdef CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON
using namespace chip::app::Clusters;
@@ -30,15 +31,20 @@ static void app_driver_button_toggle_cb(void *arg, void *data)
app_driver_handle_t app_driver_button_init()
{
/* Initialize button */
button_config_t config;
memset(&config, 0, sizeof(button_config_t));
config.type = BUTTON_TYPE_GPIO;
config.gpio_button_config.gpio_num = CONFIG_USER_ACTIVE_MODE_TRIGGER_BUTTON_PIN;
config.gpio_button_config.active_level = 0;
config.gpio_button_config.enable_power_save = true;
button_handle_t handle = iot_button_create(&config);
button_handle_t handle = NULL;
const button_config_t btn_cfg = {0};
const button_gpio_config_t btn_gpio_cfg = {
.gpio_num = CONFIG_USER_ACTIVE_MODE_TRIGGER_BUTTON_PIN,
.active_level = 0,
.enable_power_save = true,
};
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
if (iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create button device");
return NULL;
}
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, NULL, app_driver_button_toggle_cb, NULL);
return (app_driver_handle_t)handle;
}
+1 -1
View File
@@ -1,3 +1,3 @@
dependencies:
espressif/button:
version: "^3.4.0"
version: "^4"
+14 -6
View File
@@ -10,12 +10,13 @@
#include <stdlib.h>
#include <string.h>
#include <device.h>
#include <esp_matter.h>
#include <led_driver.h>
#include <app_priv.h>
#include <device.h>
#include <led_driver.h>
#include <button_gpio.h>
using namespace chip::app::Clusters;
using namespace esp_matter;
@@ -146,8 +147,15 @@ app_driver_handle_t app_driver_light_init()
app_driver_handle_t app_driver_button_init()
{
/* Initialize button */
button_config_t config = button_driver_get_config();
button_handle_t handle = iot_button_create(&config);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
button_handle_t handle = NULL;
const button_config_t btn_cfg = {0};
const button_gpio_config_t btn_gpio_cfg = button_driver_get_config();
if (iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create button device");
return NULL;
}
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, NULL, app_driver_button_toggle_cb, NULL);
return (app_driver_handle_t)handle;
}
+1 -1
View File
@@ -1,6 +1,6 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
+1 -1
View File
@@ -256,7 +256,7 @@ app_driver_handle_t app_driver_switch_init()
button_handle_t btns[BSP_BUTTON_NUM];
ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, BSP_BUTTON_NUM));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_DOWN, NULL, app_driver_button_toggle_cb, NULL));
/* Other initializations */
#if CONFIG_ENABLE_CHIP_SHELL
+2 -2
View File
@@ -1,10 +1,10 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
esp_bsp_devkit:
version: "^1.0.0"
version: "^3"
espressif/led_strip:
version: "^2.0.0"
+3 -3
View File
@@ -223,8 +223,8 @@ app_driver_handle_t app_driver_button_init()
/* Initialize button */
button_handle_t btns[BSP_BUTTON_NUM];
ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, BSP_BUTTON_NUM));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_LONG_PRESS_HOLD, button_factory_reset_pressed_cb, NULL));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_UP, button_factory_reset_released_cb, NULL));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_DOWN, NULL, app_driver_button_toggle_cb, NULL));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_LONG_PRESS_HOLD, NULL, button_factory_reset_pressed_cb, NULL));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_UP, NULL, button_factory_reset_released_cb, NULL));
return (app_driver_handle_t)btns[0];
}
@@ -1,6 +1,6 @@
dependencies:
esp_bsp_devkit:
version: "^1.0.0"
version: "^3"
espressif/led_strip:
version: "^2.0.0"
espressif/esp_rainmaker:
@@ -190,7 +190,7 @@ app_driver_handle_t app_driver_button_init()
/* Initialize button */
button_handle_t btns[BSP_BUTTON_NUM];
ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, BSP_BUTTON_NUM));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_DOWN, NULL, app_driver_button_toggle_cb, NULL));
return (app_driver_handle_t)btns[0];
}
@@ -1,11 +1,11 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
esp_bsp_devkit:
version: "^1.0.0"
version: "^3"
espressif/led_strip:
version: "^2.0.0"
espressif/esp_matter:
@@ -14,6 +14,8 @@
#include <esp_matter.h>
#include <app_priv.h>
#include <button_gpio.h>
#include <iot_button.h>
using namespace chip::app::Clusters;
using namespace esp_matter;
@@ -85,4 +87,56 @@ esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_
return err;
}
app_driver_handle_t app_driver_button_init(gpio_num_t * reset_gpio)
{
VerifyOrReturnValue((reset_gpio), (app_driver_handle_t)NULL, ESP_LOGE(TAG, "reset_gpio cannot be NULL"));
#ifdef CONFIG_USER_BUTTON
*reset_gpio = (gpio_num_t)CONFIG_USER_BUTTON_GPIO;
#elif CONFIG_BSP_BUTTONS_NUM >= 1
*reset_gpio = (gpio_num_t)BSP_BUTTON_1_IO;
#else
*reset_gpio = gpio_num_t::GPIO_NUM_NC;
return (app_driver_handle_t)NULL;
#endif
ESP_LOGI(TAG, "Initializing reset button with gpio pin %d ...", (int)*reset_gpio);
// Make sure button's IO pin isn't assigned to a plug's IO pin
for (int i = 0; i < configure_plugs; i++) {
if (plugin_unit_list[i].plug == *reset_gpio) {
ESP_LOGE(TAG, "Button's gpio pin %d is already configured for plug %d", *reset_gpio, i);
*reset_gpio = gpio_num_t::GPIO_NUM_NC;
return (app_driver_handle_t)NULL;
}
}
/* Initialize button */
app_driver_handle_t reset_handle = NULL;
#ifdef CONFIG_USER_BUTTON
const button_config_t btn_cfg = {0};
const button_gpio_config_t btn_gpio_cfg = {
.gpio_num = CONFIG_USER_BUTTON_GPIO,
.active_level = CONFIG_USER_BUTTON_LEVEL,
};
if (iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &reset_handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create button device");
return NULL;
}
#else
button_handle_t bsp_buttons[BSP_BUTTON_NUM];
int btn_cnt = 0;// will contain # of buttons that were created by BSP
bsp_iot_button_create(bsp_buttons, &btn_cnt, BSP_BUTTON_NUM);
if (btn_cnt >= 1) {
// return handle to dev board's 1st built-in button
reset_handle = (app_driver_handle_t)bsp_buttons[0];
} else {
ESP_LOGE(TAG, "bsp_iot_button_create() didn't return a usable button count: %d", btn_cnt);
}
#endif
if (!reset_handle) {
*reset_gpio = gpio_num_t::GPIO_NUM_NC;
}
return reset_handle;
}
@@ -1,6 +1,9 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
- if: "target in [esp32c2]"
esp_bsp_devkit:
version: "^3"
+2 -2
View File
@@ -1,10 +1,10 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
espressif/esp_bsp_devkit:
version: "^1.0.0"
version: "^3"
espressif/led_strip:
version: "^2.0.0"
@@ -6,15 +6,14 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <esp_log.h>
#include <stdlib.h>
#include <string.h>
#include <device.h>
#include <esp_log.h>
#include <esp_matter.h>
#include <led_driver.h>
#include <app_priv.h>
#include <device.h>
using namespace chip::app::Clusters;
using namespace esp_matter;
@@ -84,8 +83,15 @@ app_driver_handle_t app_driver_room_air_conditioner_init()
app_driver_handle_t app_driver_button_init()
{
/* Initialize button */
button_config_t config = button_driver_get_config();
button_handle_t handle = iot_button_create(&config);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
button_handle_t handle = NULL;
const button_config_t btn_cfg = {0};
const button_gpio_config_t btn_gpio_cfg = button_driver_get_config();
if (iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create button device");
return NULL;
}
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, NULL, app_driver_button_toggle_cb, NULL);
return (app_driver_handle_t)handle;
}
@@ -1,6 +1,6 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
+2 -2
View File
@@ -1,8 +1,8 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
esp_bsp_generic:
version: "^1.1.0"
version: "^3"
+12 -6
View File
@@ -6,16 +6,15 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <esp_log.h>
#include <stdlib.h>
#include <string.h>
#include <device.h>
#include <esp_log.h>
#include <esp_matter.h>
#include <led_driver.h>
#include <app_reset.h>
#include <app_priv.h>
#include <device.h>
using namespace chip::app::Clusters;
using namespace esp_matter;
@@ -161,8 +160,15 @@ app_driver_handle_t app_driver_light_init()
app_driver_handle_t app_driver_button_init()
{
/* Initialize button */
button_config_t config = button_driver_get_config();
button_handle_t handle = iot_button_create(&config);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
button_handle_t handle = NULL;
const button_config_t btn_cfg = {0};
const button_gpio_config_t btn_gpio_cfg = button_driver_get_config();
if (iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create button device");
return NULL;
}
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, NULL, app_driver_button_toggle_cb, NULL);
return (app_driver_handle_t)handle;
}
+1 -1
View File
@@ -1,6 +1,6 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
version: "^1"
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"