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 3be632e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
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
26 changes: 26 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 @@ -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;
}

0 comments on commit 3be632e

Please sign in to comment.