From a6ac5b33c9aa7fc600d5f0773e38374983860b28 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 13 Sep 2017 17:27:45 +0800 Subject: [PATCH] feat(rtc): open adc*(dac)_pad_get_io_num functions to public. --- components/driver/include/driver/adc.h | 26 +++++++++++++ components/driver/include/driver/dac.h | 13 +++++++ components/driver/rtc_module.c | 51 ++++++++++++++++++++++++-- 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/components/driver/include/driver/adc.h b/components/driver/include/driver/adc.h index 799001ddb..cbd2e28df 100644 --- a/components/driver/include/driver/adc.h +++ b/components/driver/include/driver/adc.h @@ -112,6 +112,19 @@ typedef enum { ADC_I2S_DATA_SRC_MAX, } adc_i2s_source_t; +/** + * @brief Get the gpio number of a specific ADC1 channel. + * + * @param channel Channel to get the gpio number + * + * @param gpio_num output buffer to hold the gpio number + * + * @return + * - ESP_OK if success + * - ESP_ERR_INVALID_ARG if channal not valid + */ +esp_err_t adc1_pad_get_io_num(adc1_channel_t channel, gpio_num_t *gpio_num); + /** * @brief Configure ADC1 capture width, meanwhile enable output invert for ADC1. * The configuration is for all channels of ADC1 @@ -273,6 +286,19 @@ void adc1_ulp_enable(); */ int hall_sensor_read(); +/** + * @brief Get the gpio number of a specific ADC2 channel. + * + * @param channel Channel to get the gpio number + * + * @param gpio_num output buffer to hold the gpio number + * + * @return + * - ESP_OK if success + * - ESP_ERR_INVALID_ARG if channal not valid + */ +esp_err_t adc2_pad_get_io_num(adc2_channel_t channel, gpio_num_t *gpio_num); + /** * @brief Output ADC2 reference voltage to gpio 25 or 26 or 27 * diff --git a/components/driver/include/driver/dac.h b/components/driver/include/driver/dac.h index a5563bb82..f921d98f1 100644 --- a/components/driver/include/driver/dac.h +++ b/components/driver/include/driver/dac.h @@ -29,6 +29,19 @@ typedef enum { DAC_CHANNEL_MAX, } dac_channel_t; +/** + * @brief Get the gpio number of a specific DAC channel. + * + * @param channel Channel to get the gpio number + * + * @param gpio_num output buffer to hold the gpio number + * + * @return + * - ESP_OK if success + * - ESP_ERR_INVALID_ARG if channal not valid + */ +esp_err_t dac_pad_get_io_num(dac_channel_t channel, gpio_num_t *gpio_num); + /** @cond */ /** * @brief Set DAC output voltage. diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index 75561be77..749feda29 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -905,9 +905,9 @@ esp_err_t touch_pad_filter_delete() /*--------------------------------------------------------------- ADC ---------------------------------------------------------------*/ -static esp_err_t adc1_pad_get_io_num(adc1_channel_t channel, gpio_num_t *gpio_num) +esp_err_t adc1_pad_get_io_num(adc1_channel_t channel, gpio_num_t *gpio_num) { - RTC_MODULE_CHECK(channel < ADC1_CHANNEL_MAX, "ADC Channel Err", ESP_ERR_INVALID_ARG); + RTC_MODULE_CHECK(channel < ADC1_CHANNEL_MAX, "ADC1 Channel Err", ESP_ERR_INVALID_ARG); switch (channel) { case ADC1_CHANNEL_0: @@ -1263,6 +1263,51 @@ void adc1_ulp_enable(void) portEXIT_CRITICAL(&rtc_spinlock); } +/*--------------------------------------------------------------- + ADC2 +---------------------------------------------------------------*/ +esp_err_t adc2_pad_get_io_num(adc2_channel_t channel, gpio_num_t *gpio_num) +{ + RTC_MODULE_CHECK(channel < ADC2_CHANNEL_MAX, "ADC2 Channel Err", ESP_ERR_INVALID_ARG); + + switch (channel) { + case ADC2_CHANNEL_0: + *gpio_num = ADC2_CHANNEL_0_GPIO_NUM; + break; + case ADC2_CHANNEL_1: + *gpio_num = ADC2_CHANNEL_1_GPIO_NUM; + break; + case ADC2_CHANNEL_2: + *gpio_num = ADC2_CHANNEL_2_GPIO_NUM; + break; + case ADC2_CHANNEL_3: + *gpio_num = ADC2_CHANNEL_3_GPIO_NUM; + break; + case ADC2_CHANNEL_4: + *gpio_num = ADC2_CHANNEL_4_GPIO_NUM; + break; + case ADC2_CHANNEL_5: + *gpio_num = ADC2_CHANNEL_5_GPIO_NUM; + break; + case ADC2_CHANNEL_6: + *gpio_num = ADC2_CHANNEL_6_GPIO_NUM; + break; + case ADC2_CHANNEL_7: + *gpio_num = ADC2_CHANNEL_7_GPIO_NUM; + break; + case ADC2_CHANNEL_8: + *gpio_num = ADC2_CHANNEL_8_GPIO_NUM; + break; + case ADC2_CHANNEL_9: + *gpio_num = ADC2_CHANNEL_9_GPIO_NUM; + break; + default: + return ESP_ERR_INVALID_ARG; + } + + return ESP_OK; +} + esp_err_t adc2_vref_to_gpio(gpio_num_t gpio) { int channel; @@ -1303,7 +1348,7 @@ esp_err_t adc2_vref_to_gpio(gpio_num_t gpio) /*--------------------------------------------------------------- DAC ---------------------------------------------------------------*/ -static esp_err_t dac_pad_get_io_num(dac_channel_t channel, gpio_num_t *gpio_num) +esp_err_t dac_pad_get_io_num(dac_channel_t channel, gpio_num_t *gpio_num) { RTC_MODULE_CHECK((channel >= DAC_CHANNEL_1) && (channel < DAC_CHANNEL_MAX), DAC_ERR_STR_CHANNEL_ERROR, ESP_ERR_INVALID_ARG); RTC_MODULE_CHECK(gpio_num, "Param null", ESP_ERR_INVALID_ARG);