From 70ffba8cc6f83f5b4df35bf6cebe97e43768eb1e Mon Sep 17 00:00:00 2001 From: Chirag Atal Date: Thu, 4 Aug 2022 13:55:48 +0530 Subject: [PATCH] app_driver: Using app_driver_handle_t instead of void pointer. --- examples/light/main/app_driver.cpp | 14 +++++++------- examples/light/main/app_main.cpp | 7 ++++--- examples/light/main/app_priv.h | 10 ++++++---- examples/light_switch/main/app_driver.cpp | 8 ++++---- examples/light_switch/main/app_main.cpp | 5 +++-- examples/light_switch/main/app_priv.h | 8 +++++--- examples/zap_light/main/app_driver.cpp | 16 ++++++++-------- examples/zap_light/main/app_main.cpp | 7 ++++--- examples/zap_light/main/app_priv.h | 10 ++++++---- 9 files changed, 47 insertions(+), 38 deletions(-) diff --git a/examples/light/main/app_driver.cpp b/examples/light/main/app_driver.cpp index f477872cc..49a7152e7 100644 --- a/examples/light/main/app_driver.cpp +++ b/examples/light/main/app_driver.cpp @@ -70,12 +70,12 @@ static void app_driver_button_toggle_cb(void *arg) attribute::update(endpoint_id, cluster_id, attribute_id, &val); } -esp_err_t app_driver_attribute_update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, - esp_matter_attr_val_t *val, void *priv_data) +esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id, + uint32_t attribute_id, esp_matter_attr_val_t *val) { esp_err_t err = ESP_OK; if (endpoint_id == light_endpoint_id) { - led_driver_handle_t handle = (led_driver_handle_t)priv_data; + led_driver_handle_t handle = (led_driver_handle_t)driver_handle; if (cluster_id == OnOff::Id) { if (attribute_id == OnOff::Attributes::OnOff::Id) { err = app_driver_light_set_power(handle, val); @@ -145,19 +145,19 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id) return err; } -void *app_driver_light_init() +app_driver_handle_t app_driver_light_init() { /* Initialize led */ led_driver_config_t config = led_driver_get_config(); led_driver_handle_t handle = led_driver_init(&config); - return (void *)handle; + return (app_driver_handle_t)handle; } -void *app_driver_button_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); - return (void *)handle; + return (app_driver_handle_t)handle; } diff --git a/examples/light/main/app_main.cpp b/examples/light/main/app_main.cpp index 1725dc539..82be6fb8a 100644 --- a/examples/light/main/app_main.cpp +++ b/examples/light/main/app_main.cpp @@ -60,7 +60,8 @@ static esp_err_t app_attribute_update_cb(attribute::callback_type_t type, uint16 if (type == PRE_UPDATE) { /* Driver update */ - err = app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val, priv_data); + app_driver_handle_t driver_handle = (app_driver_handle_t)priv_data; + err = app_driver_attribute_update(driver_handle, endpoint_id, cluster_id, attribute_id, val); } return err; @@ -74,8 +75,8 @@ extern "C" void app_main() nvs_flash_init(); /* Initialize driver */ - void *light_handle = app_driver_light_init(); - void *button_handle = app_driver_button_init(); + app_driver_handle_t light_handle = app_driver_light_init(); + app_driver_handle_t button_handle = app_driver_button_init(); app_reset_button_register(button_handle); /* Create a Matter node */ diff --git a/examples/light/main/app_priv.h b/examples/light/main/app_priv.h index 79e46c2fe..e404d5067 100644 --- a/examples/light/main/app_priv.h +++ b/examples/light/main/app_priv.h @@ -29,6 +29,8 @@ #define DEFAULT_HUE 128 #define DEFAULT_SATURATION 255 +typedef void *app_driver_handle_t; + /** Initialize the light driver * * This initializes the light driver associated with the selected board. @@ -36,7 +38,7 @@ * @return Handle on success. * @return NULL in case of failure. */ -void *app_driver_light_init(); +app_driver_handle_t app_driver_light_init(); /** Initialize the button driver * @@ -45,7 +47,7 @@ void *app_driver_light_init(); * @return Handle on success. * @return NULL in case of failure. */ -void *app_driver_button_init(); +app_driver_handle_t app_driver_button_init(); /** Driver Update * @@ -60,8 +62,8 @@ void *app_driver_button_init(); * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t app_driver_attribute_update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, - esp_matter_attr_val_t *val, void *priv_data); +esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id, + uint32_t attribute_id, esp_matter_attr_val_t *val); /** Set defaults for light driver * diff --git a/examples/light_switch/main/app_driver.cpp b/examples/light_switch/main/app_driver.cpp index 6d6371ccb..3b0dea259 100644 --- a/examples/light_switch/main/app_driver.cpp +++ b/examples/light_switch/main/app_driver.cpp @@ -129,14 +129,14 @@ static void app_driver_button_toggle_cb(void *arg) lock::chip_stack_unlock(); } -esp_err_t app_driver_attribute_update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, - esp_matter_attr_val_t *val, void *priv_data) +esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id, + uint32_t attribute_id, esp_matter_attr_val_t *val) { /* Nothing to do here */ return ESP_OK; } -void *app_driver_switch_init() +app_driver_handle_t app_driver_switch_init() { /* Initialize button */ button_config_t config = button_driver_get_config(); @@ -147,5 +147,5 @@ void *app_driver_switch_init() app_driver_register_commands(); client::set_command_callback(app_driver_client_command_callback, NULL); - return (void *)handle; + return (app_driver_handle_t)handle; } diff --git a/examples/light_switch/main/app_main.cpp b/examples/light_switch/main/app_main.cpp index 0f3ae18a2..2d57e5956 100644 --- a/examples/light_switch/main/app_main.cpp +++ b/examples/light_switch/main/app_main.cpp @@ -59,7 +59,8 @@ static esp_err_t app_attribute_update_cb(callback_type_t type, uint16_t endpoint if (type == PRE_UPDATE) { /* Driver update */ - err = app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val, priv_data); + app_driver_handle_t driver_handle = (app_driver_handle_t)priv_data; + err = app_driver_attribute_update(driver_handle, endpoint_id, cluster_id, attribute_id, val); } return err; @@ -73,7 +74,7 @@ extern "C" void app_main() nvs_flash_init(); /* Initialize driver */ - void *switch_handle = app_driver_switch_init(); + app_driver_handle_t switch_handle = app_driver_switch_init(); app_reset_button_register(switch_handle); /* Create a Matter node */ diff --git a/examples/light_switch/main/app_priv.h b/examples/light_switch/main/app_priv.h index 321aee886..2be8b19ca 100644 --- a/examples/light_switch/main/app_priv.h +++ b/examples/light_switch/main/app_priv.h @@ -11,6 +11,8 @@ #include #include +typedef void *app_driver_handle_t; + /** Initialize the switch driver * * This initializes the switch driver associated with the selected board. @@ -18,7 +20,7 @@ * @return Handle on success. * @return NULL in case of failure. */ -void *app_driver_switch_init(); +app_driver_handle_t app_driver_switch_init(); /** Driver Update * @@ -33,5 +35,5 @@ void *app_driver_switch_init(); * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t app_driver_attribute_update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, - esp_matter_attr_val_t *val, void *priv_data); +esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id, + uint32_t attribute_id, esp_matter_attr_val_t *val); diff --git a/examples/zap_light/main/app_driver.cpp b/examples/zap_light/main/app_driver.cpp index cab4e61e5..9aaf14e16 100644 --- a/examples/zap_light/main/app_driver.cpp +++ b/examples/zap_light/main/app_driver.cpp @@ -22,7 +22,7 @@ using namespace esp_matter; static const char *TAG = "app_driver"; extern uint16_t light_endpoint_id; -extern void *light_handle; +extern app_driver_handle_t light_handle; /* Do any conversions/remapping for the actual value here */ static esp_err_t app_driver_light_set_power(led_driver_handle_t handle, esp_matter_attr_val_t *val) @@ -68,12 +68,12 @@ static void app_driver_button_toggle_cb(void *arg) attribute::update(endpoint_id, cluster_id, attribute_id, &val); } -esp_err_t app_driver_attribute_update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, - esp_matter_attr_val_t *val, void *priv_data) +esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id, + uint32_t attribute_id, esp_matter_attr_val_t *val) { esp_err_t err = ESP_OK; if (endpoint_id == light_endpoint_id) { - led_driver_handle_t handle = (led_driver_handle_t)priv_data; + led_driver_handle_t handle = (led_driver_handle_t)driver_handle; if (cluster_id == OnOff::Id) { if (attribute_id == OnOff::Attributes::OnOff::Id) { err = app_driver_light_set_power(handle, val); @@ -150,19 +150,19 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id) return err; } -void *app_driver_light_init() +app_driver_handle_t app_driver_light_init() { /* Initialize led */ led_driver_config_t config = led_driver_get_config(); led_driver_handle_t handle = led_driver_init(&config); - return (void *)handle; + return (app_driver_handle_t)handle; } -void *app_driver_button_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); - return (void *)handle; + return (app_driver_handle_t)handle; } diff --git a/examples/zap_light/main/app_main.cpp b/examples/zap_light/main/app_main.cpp index 3b16fe981..d41923648 100644 --- a/examples/zap_light/main/app_main.cpp +++ b/examples/zap_light/main/app_main.cpp @@ -23,7 +23,7 @@ using namespace esp_matter::attribute; static const char *TAG = "app_main"; uint16_t light_endpoint_id = 0; -void *light_handle = NULL; +app_driver_handle_t light_handle = NULL; static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { @@ -51,7 +51,8 @@ static esp_err_t app_attribute_update_cb(callback_type_t type, uint16_t endpoint if (type == PRE_UPDATE) { /* Driver update */ - err = app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val, light_handle); + app_driver_handle_t driver_handle = light_handle; + err = app_driver_attribute_update(driver_handle, endpoint_id, cluster_id, attribute_id, val); } return err; @@ -66,7 +67,7 @@ extern "C" void app_main() /* Initialize driver */ light_handle = app_driver_light_init(); - void *button_handle = app_driver_button_init(); + app_driver_handle_t button_handle = app_driver_button_init(); app_reset_button_register(button_handle); /* Initialize matter callback */ diff --git a/examples/zap_light/main/app_priv.h b/examples/zap_light/main/app_priv.h index 85e938747..869d96a3a 100644 --- a/examples/zap_light/main/app_priv.h +++ b/examples/zap_light/main/app_priv.h @@ -23,6 +23,8 @@ #define MATTER_SATURATION 255 #define MATTER_TEMPERATURE_FACTOR 1000000 +typedef void *app_driver_handle_t; + /** Initialize the light driver * * This initializes the light driver associated with the selected board. @@ -30,7 +32,7 @@ * @return Handle on success. * @return NULL in case of failure. */ -void *app_driver_light_init(); +app_driver_handle_t app_driver_light_init(); /** Initialize the button driver * @@ -39,7 +41,7 @@ void *app_driver_light_init(); * @return Handle on success. * @return NULL in case of failure. */ -void *app_driver_button_init(); +app_driver_handle_t app_driver_button_init(); /** Driver Update * @@ -54,8 +56,8 @@ void *app_driver_button_init(); * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t app_driver_attribute_update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, - esp_matter_attr_val_t *val, void *priv_data); +esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id, + uint32_t attribute_id, esp_matter_attr_val_t *val); /** Set defaults for light driver *