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 2c1ccd38dd
commit 768163a9da
40 changed files with 256 additions and 175 deletions
@@ -16,10 +16,18 @@
static const char *TAG = "button_driver_hollow"; 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"); 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) 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; 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"); ESP_LOGI(TAG, "Button register callback");
return ESP_OK; 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"); ESP_LOGI(TAG, "Button unregister callback");
return ESP_OK; return ESP_OK;
@@ -35,11 +35,34 @@ typedef enum {
BUTTON_PRESS_REPEAT_DONE, BUTTON_PRESS_REPEAT_DONE,
BUTTON_SINGLE_CLICK, BUTTON_SINGLE_CLICK,
BUTTON_DOUBLE_CLICK, BUTTON_DOUBLE_CLICK,
BUTTON_MULTIPLE_CLICK,
BUTTON_LONG_PRESS_START, BUTTON_LONG_PRESS_START,
BUTTON_LONG_PRESS_HOLD, BUTTON_LONG_PRESS_HOLD,
BUTTON_LONG_PRESS_UP,
BUTTON_PRESS_END,
BUTTON_EVENT_MAX, BUTTON_EVENT_MAX,
BUTTON_NONE_PRESS,
} button_event_t; } 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 * @brief Supported button type
@@ -55,23 +78,27 @@ typedef enum {
* *
*/ */
typedef struct { 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 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 */
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 */
} button_config_t; } button_config_t;
/** /**
* @brief Create a button * @brief Create a GPIO button
* *
* @param config pointer of button configuration, must corresponding the button type * @param config pointer of button configuration, must corresponding the button type
* *
* @return A handle to the created button, or NULL in case of error. * @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 * @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 btn_handle A button handle to register
* @param event Button event * @param event Button event
* @param event_args Button event arguments
* @param cb Callback function. * @param cb Callback function.
* @param usr_data user data * @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_OK on success
* - ESP_ERR_INVALID_ARG Arguments is invalid. * - 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. * @brief Unregister the button event callback function.
* *
* @param btn_handle A button handle to unregister * @param btn_handle A button handle to unregister
* @param event Button event * @param event Button event
* @param event_args Button event arguments
* *
* @return * @return
* - ESP_OK on success * - ESP_OK on success
* - ESP_ERR_INVALID_ARG Arguments is invalid. * - 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. * @brief how many Callbacks are still registered.
@@ -1,3 +1,3 @@
## IDF Component Manager Manifest File ## IDF Component Manager Manifest File
dependencies: dependencies:
espressif/button: "=3.5.0" espressif/button: "^4"
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h> #include <esp_log.h>
#include <iot_button.h> #include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h> #include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_5 #define LED_GPIO_PIN GPIO_NUM_5
@@ -28,14 +30,11 @@ led_driver_config_t led_driver_get_config()
return config; return config;
} }
button_config_t button_driver_get_config() button_gpio_config_t button_driver_get_config()
{ {
button_config_t config = { button_gpio_config_t config = {
.type = BUTTON_TYPE_GPIO, .gpio_num = BUTTON_GPIO_PIN,
.gpio_button_config = { .active_level = 0,
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
}; };
return config; return config;
} }
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h> #include <esp_log.h>
#include <iot_button.h> #include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h> #include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_8 #define LED_GPIO_PIN GPIO_NUM_8
@@ -30,14 +32,11 @@ led_driver_config_t led_driver_get_config()
return config; return config;
} }
button_config_t button_driver_get_config() button_gpio_config_t button_driver_get_config()
{ {
button_config_t config = { button_gpio_config_t config = {
.type = BUTTON_TYPE_GPIO, .gpio_num = BUTTON_GPIO_PIN,
.gpio_button_config = { .active_level = 0,
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
}; };
return config; return config;
} }
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h> #include <esp_log.h>
#include <iot_button.h> #include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h> #include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_8 #define LED_GPIO_PIN GPIO_NUM_8
@@ -29,14 +31,11 @@ led_driver_config_t led_driver_get_config()
return config; return config;
} }
button_config_t button_driver_get_config() button_gpio_config_t button_driver_get_config()
{ {
button_config_t config = { button_gpio_config_t config = {
.type = BUTTON_TYPE_GPIO, .gpio_num = BUTTON_GPIO_PIN,
.gpio_button_config = { .active_level = 0,
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
}; };
return config; return config;
} }
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h> #include <esp_log.h>
#include <iot_button.h> #include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h> #include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_8 #define LED_GPIO_PIN GPIO_NUM_8
@@ -30,14 +32,11 @@ led_driver_config_t led_driver_get_config()
return config; return config;
} }
button_config_t button_driver_get_config() button_gpio_config_t button_driver_get_config()
{ {
button_config_t config = { button_gpio_config_t config = {
.type = BUTTON_TYPE_GPIO, .gpio_num = BUTTON_GPIO_PIN,
.gpio_button_config = { .active_level = 0,
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
}; };
return config; return config;
} }
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h> #include <esp_log.h>
#include <iot_button.h> #include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h> #include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_8 #define LED_GPIO_PIN GPIO_NUM_8
@@ -28,14 +30,11 @@ led_driver_config_t led_driver_get_config()
return config; return config;
} }
button_config_t button_driver_get_config() button_gpio_config_t button_driver_get_config()
{ {
button_config_t config = { button_gpio_config_t config = {
.type = BUTTON_TYPE_GPIO, .gpio_num = BUTTON_GPIO_PIN,
.gpio_button_config = { .active_level = 0,
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
}; };
return config; return config;
} }
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h> #include <esp_log.h>
#include <iot_button.h> #include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h> #include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_38 #define LED_GPIO_PIN GPIO_NUM_38
@@ -28,14 +30,11 @@ led_driver_config_t led_driver_get_config()
return config; return config;
} }
button_config_t button_driver_get_config() button_gpio_config_t button_driver_get_config()
{ {
button_config_t config = { button_gpio_config_t config = {
.type = BUTTON_TYPE_GPIO, .gpio_num = BUTTON_GPIO_PIN,
.gpio_button_config = { .active_level = 0,
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
}; };
return config; return config;
} }
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h> #include <esp_log.h>
#include <iot_button.h> #include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h> #include <led_driver.h>
#define LED_GPIO_PIN GPIO_NUM_8 #define LED_GPIO_PIN GPIO_NUM_8
@@ -28,14 +30,11 @@ led_driver_config_t led_driver_get_config()
return config; return config;
} }
button_config_t button_driver_get_config() button_gpio_config_t button_driver_get_config()
{ {
button_config_t config = { button_gpio_config_t config = {
.type = BUTTON_TYPE_GPIO, .gpio_num = BUTTON_GPIO_PIN,
.gpio_button_config = { .active_level = 0,
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
}; };
return config; return config;
} }
+3 -2
View File
@@ -13,15 +13,16 @@
#pragma once #pragma once
#include <iot_button.h>
#include <led_driver.h> #include <led_driver.h>
#include <iot_button.h>
#include <button_gpio.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
led_driver_config_t led_driver_get_config(); 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 #ifdef __cplusplus
} }
+6 -7
View File
@@ -13,6 +13,8 @@
#include <esp_log.h> #include <esp_log.h>
#include <iot_button.h> #include <iot_button.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <led_driver.h> #include <led_driver.h>
#define LED_GPIO_PIN 32 /* PIN_NUM_BCKL for M5Stack TFT */ #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; return config;
} }
button_config_t button_driver_get_config() button_gpio_config_t button_driver_get_config()
{ {
button_config_t config = { button_gpio_config_t config = {
.type = BUTTON_TYPE_GPIO, .gpio_num = BUTTON_GPIO_PIN,
.gpio_button_config = { .active_level = 0,
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
}; };
return config; return config;
} }
@@ -9,11 +9,12 @@
#include <string.h> #include <string.h>
#include "math.h" #include "math.h"
#include "driver/gpio.h"
#include "esp_err.h" #include "esp_err.h"
#include "esp_timer.h" #include "esp_timer.h"
#include "fan_hal_bldc.h" #include "driver/gpio.h"
#include "iot_button.h" #include "iot_button.h"
#include "button_gpio.h"
#include "fan_hal_bldc.h"
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S3 #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S3
#define PI 3.14159265f #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) esp_err_t hal_bldc_button_ctrl_init(gpio_num_t pin)
{ {
button_config_t cfg = { /* Initialize button */
.type = BUTTON_TYPE_GPIO, button_handle_t btn = NULL;
.gpio_button_config = { const button_config_t btn_cfg = {0};
.gpio_num = pin, const button_gpio_config_t btn_gpio_cfg = {
.active_level = 0, .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; return ESP_FAIL;
} }
@@ -1,6 +1,6 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"
@@ -6,19 +6,18 @@
CONDITIONS OF ANY KIND, either express or implied. CONDITIONS OF ANY KIND, either express or implied.
*/ */
#include <esp_log.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <device.h> #include <esp_log.h>
#include <esp_matter.h> #include <esp_matter.h>
#include <esp_matter_console.h> #include <esp_matter_console.h>
#include <led_driver.h>
#include <app_priv.h> #include <app_priv.h>
#include <app/server/Server.h> #include <app/server/Server.h>
#include "app/CommandPathParams.h" #include "app/CommandPathParams.h"
#include <device.h>
using namespace chip::app::Clusters; using namespace chip::app::Clusters;
using namespace esp_matter; using namespace esp_matter;
@@ -353,9 +352,16 @@ app_driver_handle_t app_driver_light_init()
app_driver_handle_t app_driver_button_init() app_driver_handle_t app_driver_button_init()
{ {
/* Initialize button */ /* Initialize button */
button_config_t config = button_driver_get_config(); button_handle_t handle = NULL;
button_handle_t handle = iot_button_create(&config); const button_config_t btn_cfg = {0};
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL); 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 #if CONFIG_ENABLE_CHIP_SHELL
app_driver_register_commands(); 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; button_handle_t button_handle = (button_handle_t)handle;
esp_err_t err = ESP_OK; 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_LONG_PRESS_HOLD, NULL, 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_PRESS_UP, NULL, button_factory_reset_released_cb, NULL);
return err; return err;
} }
+1 -1
View File
@@ -14,7 +14,7 @@
* *
* Register factory reset functionality on a button. * 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 ESP_OK on success.
* @return error in case of failure. * @return error in case of failure.
+2 -2
View File
@@ -181,8 +181,8 @@ app_driver_handle_t app_driver_button_init()
/* Initialize button */ /* Initialize button */
button_handle_t btns[BSP_BUTTON_NUM]; button_handle_t btns[BSP_BUTTON_NUM];
ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, 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));
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_LONG_PRESS_START, NULL, factory_reset_badge, NULL));
return (app_driver_handle_t)btns[0]; return (app_driver_handle_t)btns[0];
} }
+1 -1
View File
@@ -1,5 +1,5 @@
dependencies: dependencies:
espressif/esp_bsp_devkit: espressif/esp_bsp_devkit:
version: "^1.0.0" version: "^3"
espressif/led_strip: espressif/led_strip:
version: "^2.0.0" version: "^2.0.0"
+2 -2
View File
@@ -1,10 +1,10 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"
esp_bsp_devkit: esp_bsp_devkit:
version: "^1.0.0" version: "^3"
espressif/led_strip: espressif/led_strip:
version: "^2.0.0" version: "^2.0.0"
+26 -15
View File
@@ -15,6 +15,7 @@
#include <app_priv.h> #include <app_priv.h>
#include <iot_button.h> #include <iot_button.h>
#include <button_gpio.h>
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S3 #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S3
#define BUTTON_GPIO_PIN GPIO_NUM_0 #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) app_driver_handle_t app_driver_button_init(gpio_button * button)
{ {
button_config_t config = { /* Initialize button */
.type = BUTTON_TYPE_GPIO, button_handle_t handle = NULL;
.gpio_button_config = { const button_config_t btn_cfg = {0};
.gpio_num = BUTTON_GPIO_PIN,
.active_level = 0,
}
};
if (button != NULL) { if (button != NULL) {
config.type = button_type_t::BUTTON_TYPE_GPIO; const button_gpio_config_t btn_gpio_cfg = {
config.gpio_button_config.gpio_num = button->GPIO_PIN_VALUE; .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 #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 #endif
#if CONFIG_GENERIC_SWITCH_TYPE_MOMENTARY #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_DOWN, NULL, 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_UP, NULL, 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, NULL, 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_REPEAT_DONE, NULL, app_driver_button_multipress_complete, button);
#endif #endif
return (app_driver_handle_t)handle; return (app_driver_handle_t)handle;
} }
@@ -1,8 +1,8 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"
espressif/button: "=3.5.0" espressif/button: "^4"
+15 -9
View File
@@ -6,12 +6,13 @@
#include <esp_log.h> #include <esp_log.h>
#include <esp_matter.h> #include <esp_matter.h>
#include <iot_button.h>
#include <sdkconfig.h> #include <sdkconfig.h>
#include <app/icd/server/ICDNotifier.h> #include <app/icd/server/ICDNotifier.h>
#include <app_priv.h> #include <app_priv.h>
#include <iot_button.h>
#include <button_gpio.h>
#ifdef CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON #ifdef CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON
using namespace chip::app::Clusters; 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() app_driver_handle_t app_driver_button_init()
{ {
/* Initialize button */ /* Initialize button */
button_config_t config; button_handle_t handle = NULL;
memset(&config, 0, sizeof(button_config_t)); const button_config_t btn_cfg = {0};
config.type = BUTTON_TYPE_GPIO; const button_gpio_config_t btn_gpio_cfg = {
config.gpio_button_config.gpio_num = CONFIG_USER_ACTIVE_MODE_TRIGGER_BUTTON_PIN; .gpio_num = CONFIG_USER_ACTIVE_MODE_TRIGGER_BUTTON_PIN,
config.gpio_button_config.active_level = 0; .active_level = 0,
config.gpio_button_config.enable_power_save = true; .enable_power_save = true,
button_handle_t handle = iot_button_create(&config); };
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; return (app_driver_handle_t)handle;
} }
+1 -1
View File
@@ -1,3 +1,3 @@
dependencies: dependencies:
espressif/button: espressif/button:
version: "^3.4.0" version: "^4"
+14 -6
View File
@@ -10,12 +10,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <device.h>
#include <esp_matter.h> #include <esp_matter.h>
#include <led_driver.h>
#include <app_priv.h> #include <app_priv.h>
#include <device.h>
#include <led_driver.h>
#include <button_gpio.h>
using namespace chip::app::Clusters; using namespace chip::app::Clusters;
using namespace esp_matter; using namespace esp_matter;
@@ -146,8 +147,15 @@ app_driver_handle_t app_driver_light_init()
app_driver_handle_t app_driver_button_init() app_driver_handle_t app_driver_button_init()
{ {
/* Initialize button */ /* Initialize button */
button_config_t config = button_driver_get_config(); button_handle_t handle = NULL;
button_handle_t handle = iot_button_create(&config); const button_config_t btn_cfg = {0};
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL); 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; return (app_driver_handle_t)handle;
} }
+1 -1
View File
@@ -1,6 +1,6 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"
+1 -1
View File
@@ -321,7 +321,7 @@ app_driver_handle_t app_driver_switch_init()
button_handle_t btns[BSP_BUTTON_NUM]; button_handle_t btns[BSP_BUTTON_NUM];
ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, 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 */ /* Other initializations */
#if CONFIG_ENABLE_CHIP_SHELL #if CONFIG_ENABLE_CHIP_SHELL
+2 -2
View File
@@ -1,10 +1,10 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"
esp_bsp_devkit: esp_bsp_devkit:
version: "^1.0.0" version: "^3"
espressif/led_strip: espressif/led_strip:
version: "^2.0.0" version: "^2.0.0"
+3 -3
View File
@@ -214,8 +214,8 @@ app_driver_handle_t app_driver_button_init()
/* Initialize button */ /* Initialize button */
button_handle_t btns[BSP_BUTTON_NUM]; button_handle_t btns[BSP_BUTTON_NUM];
ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, 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));
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_LONG_PRESS_HOLD, NULL, 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_UP, NULL, button_factory_reset_released_cb, NULL));
return (app_driver_handle_t)btns[0]; return (app_driver_handle_t)btns[0];
} }
@@ -1,6 +1,6 @@
dependencies: dependencies:
esp_bsp_devkit: esp_bsp_devkit:
version: "^1.0.0" version: "^3"
espressif/led_strip: espressif/led_strip:
version: "^2.0.0" version: "^2.0.0"
espressif/esp_rainmaker: espressif/esp_rainmaker:
@@ -190,7 +190,7 @@ app_driver_handle_t app_driver_button_init()
/* Initialize button */ /* Initialize button */
button_handle_t btns[BSP_BUTTON_NUM]; button_handle_t btns[BSP_BUTTON_NUM];
ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, 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]; return (app_driver_handle_t)btns[0];
} }
@@ -1,11 +1,11 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"
esp_bsp_devkit: esp_bsp_devkit:
version: "^1.0.0" version: "^3"
espressif/led_strip: espressif/led_strip:
version: "^2.0.0" version: "^2.0.0"
espressif/esp_matter: espressif/esp_matter:
@@ -6,19 +6,21 @@
CONDITIONS OF ANY KIND, either express or implied. CONDITIONS OF ANY KIND, either express or implied.
*/ */
#include <bsp/esp-bsp.h>
#include <esp_log.h>
#include <iot_button.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "bsp/esp_bsp_devkit.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "soc/gpio_num.h" #include "soc/gpio_num.h"
#include <esp_log.h>
#include <bsp/esp-bsp.h>
#include "bsp/esp_bsp_devkit.h"
#include "support/CodeUtils.h" #include "support/CodeUtils.h"
#include <esp_matter.h> #include <esp_matter.h>
#include <app_priv.h> #include <app_priv.h>
#include <button_gpio.h>
#include <iot_button.h>
using namespace chip::app::Clusters; using namespace chip::app::Clusters;
using namespace esp_matter; using namespace esp_matter;
@@ -115,14 +117,16 @@ app_driver_handle_t app_driver_button_init(gpio_num_t * reset_gpio)
/* Initialize button */ /* Initialize button */
app_driver_handle_t reset_handle = NULL; app_driver_handle_t reset_handle = NULL;
#ifdef CONFIG_USER_BUTTON #ifdef CONFIG_USER_BUTTON
button_config_t config = { const button_config_t btn_cfg = {0};
.type = BUTTON_TYPE_GPIO, const button_gpio_config_t btn_gpio_cfg = {
.gpio_button_config = { .gpio_num = CONFIG_USER_BUTTON_GPIO,
.gpio_num = CONFIG_USER_BUTTON_GPIO, .active_level = CONFIG_USER_BUTTON_LEVEL,
.active_level = CONFIG_USER_BUTTON_LEVEL,
}
}; };
reset_handle = (app_driver_handle_t)iot_button_create(&config);
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 #else
button_handle_t bsp_buttons[BSP_BUTTON_NUM]; button_handle_t bsp_buttons[BSP_BUTTON_NUM];
int btn_cnt = 0;// will contain # of buttons that were created by BSP int btn_cnt = 0;// will contain # of buttons that were created by BSP
@@ -1,8 +1,8 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"
esp_bsp_devkit: esp_bsp_devkit:
version: "1.0.0" version: "^3"
+2 -2
View File
@@ -1,10 +1,10 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"
espressif/esp_bsp_devkit: espressif/esp_bsp_devkit:
version: "^1.0.0" version: "^3"
espressif/led_strip: espressif/led_strip:
version: "^2.0.0" version: "^2.0.0"
@@ -6,15 +6,14 @@
CONDITIONS OF ANY KIND, either express or implied. CONDITIONS OF ANY KIND, either express or implied.
*/ */
#include <esp_log.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <device.h> #include <esp_log.h>
#include <esp_matter.h> #include <esp_matter.h>
#include <led_driver.h>
#include <app_priv.h> #include <app_priv.h>
#include <device.h>
using namespace chip::app::Clusters; using namespace chip::app::Clusters;
using namespace esp_matter; 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() app_driver_handle_t app_driver_button_init()
{ {
/* Initialize button */ /* Initialize button */
button_config_t config = button_driver_get_config(); button_handle_t handle = NULL;
button_handle_t handle = iot_button_create(&config); const button_config_t btn_cfg = {0};
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL); 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; return (app_driver_handle_t)handle;
} }
@@ -1,6 +1,6 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"
+2 -2
View File
@@ -1,8 +1,8 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"
esp_bsp_generic: 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. CONDITIONS OF ANY KIND, either express or implied.
*/ */
#include <esp_log.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <device.h> #include <esp_log.h>
#include <esp_matter.h> #include <esp_matter.h>
#include <led_driver.h>
#include <app_reset.h> #include <app_reset.h>
#include <app_priv.h> #include <app_priv.h>
#include <device.h>
using namespace chip::app::Clusters; using namespace chip::app::Clusters;
using namespace esp_matter; using namespace esp_matter;
@@ -161,8 +160,15 @@ app_driver_handle_t app_driver_light_init()
app_driver_handle_t app_driver_button_init() app_driver_handle_t app_driver_button_init()
{ {
/* Initialize button */ /* Initialize button */
button_config_t config = button_driver_get_config(); button_handle_t handle = NULL;
button_handle_t handle = iot_button_create(&config); const button_config_t btn_cfg = {0};
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL); 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; return (app_driver_handle_t)handle;
} }
+1 -1
View File
@@ -1,6 +1,6 @@
dependencies: dependencies:
espressif/cmake_utilities: espressif/cmake_utilities:
version: 0.* version: "^1"
rules: # will add "optional_component" only when all if clauses are True rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0" - if: "idf_version >=5.0"
- if: "target in [esp32c2]" - if: "target in [esp32c2]"