Skip to content

Commit

Permalink
Merge branch 'bugfix/button_adc_issue' into 'master'
Browse files Browse the repository at this point in the history
button: resolved ADC issue

See merge request ae_group/esp-iot-solution!881
  • Loading branch information
leeebo committed Nov 13, 2023
2 parents 946b4ff + f27c58e commit a3a1caf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
6 changes: 5 additions & 1 deletion components/button/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

## v3.1.3 - 2023-11-13

* Resolved issue 'ADC_ATTEN_DB_11 is deprecated'.

## v3.1.2 - 2023-10-24

### bugfix
Expand Down Expand Up @@ -84,5 +88,5 @@

### Enhancements:

* Support custom button
* Support custom button
* Add BUTTON_PRESS_REPEAT_DONE event
7 changes: 5 additions & 2 deletions components/button/button_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ static const char *TAG = "adc button";
#define DEFAULT_VREF 1100
#define NO_OF_SAMPLES CONFIG_ADC_BUTTON_SAMPLE_TIMES //Multisampling

/*!< Using atten bigger than 6db by default, it will be 11db or 12db in different target */
#define DEFAULT_ADC_ATTEN (ADC_ATTEN_DB_6 + 1)

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#define ADC_BUTTON_WIDTH SOC_ADC_RTC_MAX_BITWIDTH
#define ADC1_BUTTON_CHANNEL_MAX SOC_ADC_MAX_CHANNEL_NUM
#define ADC_BUTTON_ATTEN ADC_ATTEN_DB_11
#define ADC_BUTTON_ATTEN DEFAULT_ADC_ATTEN
#else
#define ADC_BUTTON_WIDTH ADC_WIDTH_MAX-1
#define ADC1_BUTTON_CHANNEL_MAX ADC1_CHANNEL_MAX
#define ADC_BUTTON_ATTEN ADC_ATTEN_DB_11
#define ADC_BUTTON_ATTEN DEFAULT_ADC_ATTEN
#endif
#define ADC_BUTTON_ADC_UNIT ADC_UNIT_1
#define ADC_BUTTON_MAX_CHANNEL CONFIG_ADC_BUTTON_MAX_CHANNEL
Expand Down
2 changes: 1 addition & 1 deletion components/button/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.1.2"
version: "3.1.3"
description: GPIO and ADC button driver
url: https://github.com/espressif/esp-iot-solution/tree/master/components/button
repository: https://github.com/espressif/esp-iot-solution.git
Expand Down
16 changes: 8 additions & 8 deletions components/button/include/button_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {

/**
* @brief adc button configuration
*
*
*/
typedef struct {
uint8_t adc_channel; /**< Channel of ADC */
Expand All @@ -37,9 +37,9 @@ typedef struct {

/**
* @brief Initialize gpio button
*
*
* @param config pointer of configuration struct
*
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG Arguments is NULL.
Expand All @@ -50,10 +50,10 @@ esp_err_t button_adc_init(const button_adc_config_t *config);

/**
* @brief Deinitialize gpio button
*
*
* @param channel ADC channel
* @param button_index Button index on the channel
*
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG Arguments is invalid.
Expand All @@ -62,10 +62,10 @@ esp_err_t button_adc_deinit(uint8_t channel, int button_index);

/**
* @brief Get the adc button level
*
*
* @param button_index It is compressed by ADC channel and button index, use the macro ADC_BUTTON_COMBINE to generate. It will be treated as a uint32_t variable.
*
* @return
*
* @return
* - 0 Not pressed
* - 1 Pressed
*/
Expand Down
3 changes: 2 additions & 1 deletion components/button/test_apps/main/button_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ TEST_CASE("adc button idf5 drive test", "[button][iot]")
};
esp_err_t ret = adc_oneshot_new_unit(&init_config, &adc1_handle);
TEST_ASSERT_TRUE(ret == ESP_OK);
adc_calibration_init(ADC_UNIT_1, ADC_ATTEN_DB_11, &adc1_cali_handle);
/*!< use atten 11db or 12db */
adc_calibration_init(ADC_UNIT_1, 3, &adc1_cali_handle);

/** ESP32-S3-Korvo board */
const uint16_t vol[6] = {380, 820, 1180, 1570, 1980, 2410};
Expand Down
1 change: 1 addition & 0 deletions tools/build_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
r'This clock source will be affected by the DFS of the power management',
r'The current IDF version does not support using the gptimer API',
r'DeprecationWarning: pkg_resources is deprecated as an API',
r'\'ADC_ATTEN_DB_11\' is deprecated',
]

def _get_idf_version():
Expand Down

0 comments on commit a3a1caf

Please sign in to comment.