diff --git a/device_hal/button_driver/button/hollow_button/button_driver.c b/device_hal/button_driver/button/hollow_button/button_driver.c index f4e778cd0..8b601c5ef 100644 --- a/device_hal/button_driver/button/hollow_button/button_driver.c +++ b/device_hal/button_driver/button/hollow_button/button_driver.c @@ -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; diff --git a/device_hal/button_driver/button/include/iot_button.h b/device_hal/button_driver/button/include/iot_button.h index a50976fa6..82e92a80b 100644 --- a/device_hal/button_driver/button/include/iot_button.h +++ b/device_hal/button_driver/button/include/iot_button.h @@ -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. diff --git a/device_hal/button_driver/iot_button/idf_component.yml b/device_hal/button_driver/iot_button/idf_component.yml index 248147e6c..058a989eb 100644 --- a/device_hal/button_driver/iot_button/idf_component.yml +++ b/device_hal/button_driver/iot_button/idf_component.yml @@ -1,3 +1,3 @@ ## IDF Component Manager Manifest File dependencies: - espressif/button: "=2.5.0" + espressif/button: "^4" diff --git a/device_hal/device/esp32_devkit_c/device.c b/device_hal/device/esp32_devkit_c/device.c index f76c2e562..beaaf035c 100644 --- a/device_hal/device/esp32_devkit_c/device.c +++ b/device_hal/device/esp32_devkit_c/device.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include #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; } diff --git a/device_hal/device/esp32c2_devkit_m/device.c b/device_hal/device/esp32c2_devkit_m/device.c index fa8e7d1b3..30f7d3c04 100644 --- a/device_hal/device/esp32c2_devkit_m/device.c +++ b/device_hal/device/esp32c2_devkit_m/device.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include #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; } diff --git a/device_hal/device/esp32c3_devkit_m/device.c b/device_hal/device/esp32c3_devkit_m/device.c index 15d93f8f3..bc70c6e44 100644 --- a/device_hal/device/esp32c3_devkit_m/device.c +++ b/device_hal/device/esp32c3_devkit_m/device.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include #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; } diff --git a/device_hal/device/esp32c6_devkit_c/device.c b/device_hal/device/esp32c6_devkit_c/device.c index fa8e7d1b3..30f7d3c04 100644 --- a/device_hal/device/esp32c6_devkit_c/device.c +++ b/device_hal/device/esp32c6_devkit_c/device.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include #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; } diff --git a/device_hal/device/esp32h2_devkit_c/device.c b/device_hal/device/esp32h2_devkit_c/device.c index 6d5982df6..f6e874d6e 100644 --- a/device_hal/device/esp32h2_devkit_c/device.c +++ b/device_hal/device/esp32h2_devkit_c/device.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include #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; } diff --git a/device_hal/device/esp32s3_devkit_c/device.c b/device_hal/device/esp32s3_devkit_c/device.c index ab5c74f29..e616ffdc2 100644 --- a/device_hal/device/esp32s3_devkit_c/device.c +++ b/device_hal/device/esp32s3_devkit_c/device.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include #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; } diff --git a/device_hal/device/hollow/device.c b/device_hal/device/hollow/device.c index 6d5982df6..f6e874d6e 100644 --- a/device_hal/device/hollow/device.c +++ b/device_hal/device/hollow/device.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include #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; } diff --git a/device_hal/device/include/device.h b/device_hal/device/include/device.h index b419aaa48..65b02e25e 100644 --- a/device_hal/device/include/device.h +++ b/device_hal/device/include/device.h @@ -13,15 +13,16 @@ #pragma once -#include #include +#include +#include #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 } diff --git a/device_hal/device/m5stack/device.c b/device_hal/device/m5stack/device.c index aad413bc2..9c569ba39 100644 --- a/device_hal/device/m5stack/device.c +++ b/device_hal/device/m5stack/device.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include #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; } diff --git a/examples/all_device_types_app/main/driver/fan/fan_hal_bldc.c b/examples/all_device_types_app/main/driver/fan/fan_hal_bldc.c index 9003f5385..d9f5dfbbb 100644 --- a/examples/all_device_types_app/main/driver/fan/fan_hal_bldc.c +++ b/examples/all_device_types_app/main/driver/fan/fan_hal_bldc.c @@ -9,11 +9,12 @@ #include #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; } diff --git a/examples/all_device_types_app/main/idf_component.yml b/examples/all_device_types_app/main/idf_component.yml index 93d2a2fd0..6479b6348 100644 --- a/examples/all_device_types_app/main/idf_component.yml +++ b/examples/all_device_types_app/main/idf_component.yml @@ -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]" diff --git a/examples/bridge_apps/esp-now_bridge_light/main/app_driver.cpp b/examples/bridge_apps/esp-now_bridge_light/main/app_driver.cpp index 20f0ef14d..c0918e6dc 100644 --- a/examples/bridge_apps/esp-now_bridge_light/main/app_driver.cpp +++ b/examples/bridge_apps/esp-now_bridge_light/main/app_driver.cpp @@ -6,19 +6,18 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include #include #include -#include +#include #include #include -#include #include #include #include "app/CommandPathParams.h" +#include 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(); diff --git a/examples/common/app_reset/app_reset.cpp b/examples/common/app_reset/app_reset.cpp index 77803caa9..35bf89f38 100644 --- a/examples/common/app_reset/app_reset.cpp +++ b/examples/common/app_reset/app_reset.cpp @@ -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; } diff --git a/examples/common/app_reset/app_reset.h b/examples/common/app_reset/app_reset.h index ec9910065..363fb353c 100644 --- a/examples/common/app_reset/app_reset.h +++ b/examples/common/app_reset/app_reset.h @@ -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. diff --git a/examples/demo/badge/main/app_driver.cpp b/examples/demo/badge/main/app_driver.cpp index 82a0cee5f..b60aaf17a 100644 --- a/examples/demo/badge/main/app_driver.cpp +++ b/examples/demo/badge/main/app_driver.cpp @@ -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]; } diff --git a/examples/demo/badge/main/idf_component.yml b/examples/demo/badge/main/idf_component.yml index 1a2263c7c..621907505 100644 --- a/examples/demo/badge/main/idf_component.yml +++ b/examples/demo/badge/main/idf_component.yml @@ -1,5 +1,5 @@ dependencies: espressif/esp_bsp_devkit: - version: "^1.0.0" + version: "^3" espressif/led_strip: version: "^2.0.0" diff --git a/examples/door_lock/main/idf_component.yml b/examples/door_lock/main/idf_component.yml index 8bad318df..be4a6e154 100644 --- a/examples/door_lock/main/idf_component.yml +++ b/examples/door_lock/main/idf_component.yml @@ -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" diff --git a/examples/generic_switch/main/app_driver.cpp b/examples/generic_switch/main/app_driver.cpp index 5be7f458d..1a1e209e8 100644 --- a/examples/generic_switch/main/app_driver.cpp +++ b/examples/generic_switch/main/app_driver.cpp @@ -15,6 +15,7 @@ #include #include +#include #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; } diff --git a/examples/generic_switch/main/idf_component.yml b/examples/generic_switch/main/idf_component.yml index 8a96dc5f6..9edee55c4 100644 --- a/examples/generic_switch/main/idf_component.yml +++ b/examples/generic_switch/main/idf_component.yml @@ -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" diff --git a/examples/icd_app/main/app_driver.cpp b/examples/icd_app/main/app_driver.cpp index cd3ea1cde..2e92858b1 100644 --- a/examples/icd_app/main/app_driver.cpp +++ b/examples/icd_app/main/app_driver.cpp @@ -6,12 +6,13 @@ #include #include -#include #include #include #include +#include +#include #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; } diff --git a/examples/icd_app/main/idf_component.yml b/examples/icd_app/main/idf_component.yml index dedd65dc8..004fc493a 100644 --- a/examples/icd_app/main/idf_component.yml +++ b/examples/icd_app/main/idf_component.yml @@ -1,3 +1,3 @@ dependencies: espressif/button: - version: "^3.4.0" + version: "^4" diff --git a/examples/light/main/app_driver.cpp b/examples/light/main/app_driver.cpp index 739a2a4df..f0984f14d 100644 --- a/examples/light/main/app_driver.cpp +++ b/examples/light/main/app_driver.cpp @@ -10,12 +10,13 @@ #include #include -#include #include -#include - #include +#include +#include +#include + 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; } diff --git a/examples/light/main/idf_component.yml b/examples/light/main/idf_component.yml index 95ee7845b..cc568c697 100644 --- a/examples/light/main/idf_component.yml +++ b/examples/light/main/idf_component.yml @@ -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]" diff --git a/examples/light_switch/main/app_driver.cpp b/examples/light_switch/main/app_driver.cpp index 8d77c29f8..057388ea7 100644 --- a/examples/light_switch/main/app_driver.cpp +++ b/examples/light_switch/main/app_driver.cpp @@ -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 diff --git a/examples/light_switch/main/idf_component.yml b/examples/light_switch/main/idf_component.yml index 8bad318df..be4a6e154 100644 --- a/examples/light_switch/main/idf_component.yml +++ b/examples/light_switch/main/idf_component.yml @@ -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" diff --git a/examples/light_wifi_prov/main/app_driver.cpp b/examples/light_wifi_prov/main/app_driver.cpp index f66b37819..b8661c602 100644 --- a/examples/light_wifi_prov/main/app_driver.cpp +++ b/examples/light_wifi_prov/main/app_driver.cpp @@ -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]; } diff --git a/examples/light_wifi_prov/main/idf_component.yml b/examples/light_wifi_prov/main/idf_component.yml index 7b5ec5501..40283433b 100644 --- a/examples/light_wifi_prov/main/idf_component.yml +++ b/examples/light_wifi_prov/main/idf_component.yml @@ -1,6 +1,6 @@ dependencies: esp_bsp_devkit: - version: "^1.0.0" + version: "^3" espressif/led_strip: version: "^2.0.0" espressif/esp_rainmaker: diff --git a/examples/managed_component_light/main/app_driver.cpp b/examples/managed_component_light/main/app_driver.cpp index 180c1a2b6..cdc96af1d 100644 --- a/examples/managed_component_light/main/app_driver.cpp +++ b/examples/managed_component_light/main/app_driver.cpp @@ -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]; } diff --git a/examples/managed_component_light/main/idf_component.yml b/examples/managed_component_light/main/idf_component.yml index c1e6c1915..cb86d323b 100644 --- a/examples/managed_component_light/main/idf_component.yml +++ b/examples/managed_component_light/main/idf_component.yml @@ -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: diff --git a/examples/multiple_on_off_plugin_units/main/app_driver.cpp b/examples/multiple_on_off_plugin_units/main/app_driver.cpp index a78d47d1b..eba757866 100644 --- a/examples/multiple_on_off_plugin_units/main/app_driver.cpp +++ b/examples/multiple_on_off_plugin_units/main/app_driver.cpp @@ -14,6 +14,8 @@ #include #include +#include +#include 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; +} diff --git a/examples/multiple_on_off_plugin_units/main/idf_component.yml b/examples/multiple_on_off_plugin_units/main/idf_component.yml index c489c846c..098f095cf 100644 --- a/examples/multiple_on_off_plugin_units/main/idf_component.yml +++ b/examples/multiple_on_off_plugin_units/main/idf_component.yml @@ -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]" \ No newline at end of file + - if: "target in [esp32c2]" + + esp_bsp_devkit: + version: "^3" diff --git a/examples/refrigerator/main/idf_component.yml b/examples/refrigerator/main/idf_component.yml index 347126f19..a4033be52 100644 --- a/examples/refrigerator/main/idf_component.yml +++ b/examples/refrigerator/main/idf_component.yml @@ -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" diff --git a/examples/room_air_conditioner/main/app_driver.cpp b/examples/room_air_conditioner/main/app_driver.cpp index c60969bfd..88af085c9 100644 --- a/examples/room_air_conditioner/main/app_driver.cpp +++ b/examples/room_air_conditioner/main/app_driver.cpp @@ -6,15 +6,14 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include #include #include -#include +#include #include -#include #include +#include 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; } diff --git a/examples/room_air_conditioner/main/idf_component.yml b/examples/room_air_conditioner/main/idf_component.yml index 95ee7845b..cc568c697 100644 --- a/examples/room_air_conditioner/main/idf_component.yml +++ b/examples/room_air_conditioner/main/idf_component.yml @@ -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]" diff --git a/examples/sensors/main/idf_component.yml b/examples/sensors/main/idf_component.yml index 547b39ec2..b15e98a9e 100644 --- a/examples/sensors/main/idf_component.yml +++ b/examples/sensors/main/idf_component.yml @@ -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" diff --git a/examples/zap_light/main/app_driver.cpp b/examples/zap_light/main/app_driver.cpp index 13f89571b..961a0f81a 100644 --- a/examples/zap_light/main/app_driver.cpp +++ b/examples/zap_light/main/app_driver.cpp @@ -6,16 +6,15 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include #include #include -#include +#include #include -#include #include #include +#include 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; } diff --git a/examples/zap_light/main/idf_component.yml b/examples/zap_light/main/idf_component.yml index 95ee7845b..cc568c697 100644 --- a/examples/zap_light/main/idf_component.yml +++ b/examples/zap_light/main/idf_component.yml @@ -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]"