diff --git a/esp32_s3_lcd_ev_board/include/bsp/esp32_s3_lcd_ev_board.h b/esp32_s3_lcd_ev_board/include/bsp/esp32_s3_lcd_ev_board.h index 056cb5ff..3c6318c6 100644 --- a/esp32_s3_lcd_ev_board/include/bsp/esp32_s3_lcd_ev_board.h +++ b/esp32_s3_lcd_ev_board/include/bsp/esp32_s3_lcd_ev_board.h @@ -493,6 +493,34 @@ __attribute__((deprecated("use espressif/button API instead"))); */ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int btn_array_size); +/************************************************************************************************** + * + * ADC interface + * + * After initialization of ADC, use `adc_handle` when using ADC driver. + * + **************************************************************************************************/ +#define BSP_ADC_UNIT ADC_UNIT_1 + +/** + * @brief Initialize ADC + * + * The ADC can be initialized inside BSP, when needed. + * + * @param[out] adc_handle Returned ADC handle + */ +esp_err_t bsp_adc_initialize(void); + + +/** + * @brief Get ADC handle + * + * @note This function is available only in IDF5 and higher + * + * @return ADC handle + */ +adc_oneshot_unit_handle_t bsp_adc_get_handle(void); + #ifdef __cplusplus } #endif diff --git a/esp32_s3_lcd_ev_board/src/esp32_s3_lcd_ev_board.c b/esp32_s3_lcd_ev_board/src/esp32_s3_lcd_ev_board.c index 4fa61685..85b13278 100644 --- a/esp32_s3_lcd_ev_board/src/esp32_s3_lcd_ev_board.c +++ b/esp32_s3_lcd_ev_board/src/esp32_s3_lcd_ev_board.c @@ -383,3 +383,29 @@ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int b } return ret; } + +/************************************************************************************************** + * + * ADC Funciton + * + **************************************************************************************************/ +esp_err_t bsp_adc_initialize(void) +{ + /* ADC was initialized before */ + if (bsp_adc_handle != NULL) { + return ESP_OK; + } + + /* Initialize ADC */ + const adc_oneshot_unit_init_cfg_t init_config1 = { + .unit_id = BSP_ADC_UNIT, + }; + BSP_ERROR_CHECK_RETURN_ERR(adc_oneshot_new_unit(&init_config1, &bsp_adc_handle)); + + return ESP_OK; +} + +adc_oneshot_unit_handle_t bsp_adc_get_handle(void) +{ + return bsp_adc_handle; +}