Skip to content

Commit

Permalink
add ADC function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lzw655 committed Aug 14, 2023
1 parent 64cb35e commit 459263a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions esp32_s3_lcd_ev_board/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
* Implementations:
* Use `esp_lcd_panel_io_additions` and `esp_lcd_gc9503` components to drive the LCD of sub_board2.
* Use `esp_codec_dev` component to handle audio chips.
* Use `button` component to handle button.
* Implement automatic detection of the LCD sub-board type
* APIs:
* Add new APIs for display in `bsp/display.h`
* Add new APIs for touch in `bsp/touch.h`
* Add new APIs for spiffs, audio in `bsp/esp32_s3_lcd_ev_board.h`
* Add new APIs for ADC in `bsp/esp32_s3_lcd_ev_board.h`
28 changes: 28 additions & 0 deletions esp32_s3_lcd_ev_board/include/bsp/esp32_s3_lcd_ev_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions esp32_s3_lcd_ev_board/src/esp32_s3_lcd_ev_board.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static i2s_chan_handle_t i2s_tx_chan = NULL;
static i2s_chan_handle_t i2s_rx_chan = NULL;
static esp_io_expander_handle_t io_expander = NULL; // IO expander tca9554 handle
static lv_indev_t *disp_indev = NULL;
static adc_oneshot_unit_handle_t bsp_adc_handle = NULL;

static const button_config_t bsp_button_config[BSP_BUTTON_NUM] = {
{
Expand Down Expand Up @@ -383,3 +384,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;
}

0 comments on commit 459263a

Please sign in to comment.