Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion components/button/button_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ uint8_t button_adc_get_key_level(button_driver_t *button_driver)
return BUTTON_INACTIVE;
}

static uint32_t button_adc_get_channel(button_driver_t *button_driver)
{
button_adc_obj *adc_btn = __containerof(button_driver, button_adc_obj, base);
return adc_btn->ch;
}

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_err_t ret = ESP_OK;
Expand Down Expand Up @@ -314,6 +320,7 @@ esp_err_t iot_button_new_adc_device(const button_config_t *button_config, const
adc_btn->ch = adc_config->adc_channel;
adc_btn->index = adc_config->button_index;
adc_btn->base.get_key_level = button_adc_get_key_level;
adc_btn->base.get_hardware_data = button_adc_get_channel;
adc_btn->base.del = button_adc_del;
ret = iot_button_create(button_config, &adc_btn->base, ret_button);
ESP_GOTO_ON_FALSE(ret == ESP_OK, ESP_FAIL, err, TAG, "Create button failed");
Expand All @@ -324,4 +331,4 @@ esp_err_t iot_button_new_adc_device(const button_config_t *button_config, const
free(adc_btn);
}
return ret;
}
}
7 changes: 7 additions & 0 deletions components/button/button_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ static uint8_t button_gpio_get_key_level(button_driver_t *button_driver)
return level == gpio_btn->active_level ? 1 : 0;
}

static int button_gpio_get_pin(button_driver_t *button_driver)
{
button_gpio_obj *gpio_btn = __containerof(button_driver, button_gpio_obj, base);
return (int)gpio_btn->gpio_num;
}

static esp_err_t button_gpio_enable_gpio_wakeup(uint32_t gpio_num, uint8_t active_level, bool enable)
{
esp_err_t ret;
Expand Down Expand Up @@ -135,6 +141,7 @@ esp_err_t iot_button_new_gpio_device(const button_config_t *button_config, const
}

gpio_btn->base.get_key_level = button_gpio_get_key_level;
gpio_btn->base.get_hardware_data = button_gpio_get_pin;
gpio_btn->base.del = button_gpio_del;

ret = iot_button_create(button_config, &gpio_btn->base, ret_button);
Expand Down
10 changes: 10 additions & 0 deletions components/button/include/iot_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ esp_err_t iot_button_set_param(button_handle_t btn_handle, button_param_t param,
*/
uint8_t iot_button_get_key_level(button_handle_t btn_handle);

/** @brief Get button hardware gpio pin or adc channel number.
*
* @param btn_handle Button handle
*
* @return Depends button type:
* - BUTTON_GPIO: pin number
* - BUTTON_ADC: channel number
*/
int iot_button_get_hardware_data(button_handle_t btn_handle);

/**
* @brief resume button timer, if button timer is stopped. Make sure iot_button_create() is called before calling this API.
*
Expand Down
3 changes: 3 additions & 0 deletions components/button/interface/button_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ struct button_driver_t {
/*!< (necessary) Get key level */
uint8_t (*get_key_level)(button_driver_t *button_driver);

/*!< (optional) Get hardware data */
int (*get_hardware_data)(button_driver_t *button_driver);

/*!< (optional) Enter Power Save cb */
esp_err_t (*enter_power_save)(button_driver_t *button_driver);

Expand Down
10 changes: 10 additions & 0 deletions components/button/iot_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,16 @@ uint8_t iot_button_get_key_level(button_handle_t btn_handle)
return level;
}

int iot_button_get_hardware_data(button_handle_t btn_handle)
{
BTN_CHECK(NULL != btn_handle, "Pointer of handle is invalid", 0);
button_dev_t *btn = (button_dev_t *) btn_handle;
if (btn->driver->get_hardware_data) {
return btn->driver->get_hardware_data(btn->driver);
}
return -1;
}

esp_err_t iot_button_resume(void)
{
if (!g_button_timer_handle) {
Expand Down