1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 9 #include <stdint.h> 10 #include <stdbool.h> 11 #include "esp_err.h" 12 #include "sdkconfig.h" 13 #include "driver/gpio.h" 14 #include "hal/adc_types.h" 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 #if CONFIG_IDF_TARGET_ESP32 21 /**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ 22 typedef enum { 23 ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO36 */ 24 ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO37 */ 25 ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO38 */ 26 ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO39 */ 27 ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO32 */ 28 ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO33 */ 29 ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO34 */ 30 ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO35 */ 31 ADC1_CHANNEL_MAX, 32 } adc1_channel_t; 33 #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // TODO ESP32-S3 channels are wrong IDF-1776 34 /**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ 35 typedef enum { 36 ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO1 */ 37 ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO2 */ 38 ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO3 */ 39 ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO4 */ 40 ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO5 */ 41 ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO6 */ 42 ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO7 */ 43 ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO8 */ 44 ADC1_CHANNEL_8, /*!< ADC1 channel 8 is GPIO9 */ 45 ADC1_CHANNEL_9, /*!< ADC1 channel 9 is GPIO10 */ 46 ADC1_CHANNEL_MAX, 47 } adc1_channel_t; 48 #elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 49 /**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ 50 typedef enum { 51 ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO0 */ 52 ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO1 */ 53 ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO2 */ 54 ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO3 */ 55 ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO4 */ 56 ADC1_CHANNEL_MAX, 57 } adc1_channel_t; 58 #endif // CONFIG_IDF_TARGET_* 59 60 #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // TODO ESP32-S3 channels are wrong IDF-1776 61 /**** `adc2_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ 62 typedef enum { 63 ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO4 (ESP32), GPIO11 (ESP32-S2) */ 64 ADC2_CHANNEL_1, /*!< ADC2 channel 1 is GPIO0 (ESP32), GPIO12 (ESP32-S2) */ 65 ADC2_CHANNEL_2, /*!< ADC2 channel 2 is GPIO2 (ESP32), GPIO13 (ESP32-S2) */ 66 ADC2_CHANNEL_3, /*!< ADC2 channel 3 is GPIO15 (ESP32), GPIO14 (ESP32-S2) */ 67 ADC2_CHANNEL_4, /*!< ADC2 channel 4 is GPIO13 (ESP32), GPIO15 (ESP32-S2) */ 68 ADC2_CHANNEL_5, /*!< ADC2 channel 5 is GPIO12 (ESP32), GPIO16 (ESP32-S2) */ 69 ADC2_CHANNEL_6, /*!< ADC2 channel 6 is GPIO14 (ESP32), GPIO17 (ESP32-S2) */ 70 ADC2_CHANNEL_7, /*!< ADC2 channel 7 is GPIO27 (ESP32), GPIO18 (ESP32-S2) */ 71 ADC2_CHANNEL_8, /*!< ADC2 channel 8 is GPIO25 (ESP32), GPIO19 (ESP32-S2) */ 72 ADC2_CHANNEL_9, /*!< ADC2 channel 9 is GPIO26 (ESP32), GPIO20 (ESP32-S2) */ 73 ADC2_CHANNEL_MAX, 74 } adc2_channel_t; 75 #elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 76 /**** `adc2_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ 77 typedef enum { 78 ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO5 */ 79 ADC2_CHANNEL_MAX, 80 } adc2_channel_t; 81 #endif 82 83 84 /** 85 * @brief ADC rtc controller attenuation option. 86 * 87 * @note This definitions are only for being back-compatible 88 */ 89 #define ADC_ATTEN_0db ADC_ATTEN_DB_0 90 #define ADC_ATTEN_2_5db ADC_ATTEN_DB_2_5 91 #define ADC_ATTEN_6db ADC_ATTEN_DB_6 92 #define ADC_ATTEN_11db ADC_ATTEN_DB_11 93 94 /** 95 * The default (max) bit width of the ADC of current version. You can also get the maximum bitwidth 96 * by `SOC_ADC_MAX_BITWIDTH` defined in soc_caps.h. 97 */ 98 #define ADC_WIDTH_BIT_DEFAULT (ADC_WIDTH_MAX-1) 99 100 //this definitions are only for being back-compatible 101 #define ADC_WIDTH_9Bit ADC_WIDTH_BIT_9 102 #define ADC_WIDTH_10Bit ADC_WIDTH_BIT_10 103 #define ADC_WIDTH_11Bit ADC_WIDTH_BIT_11 104 #define ADC_WIDTH_12Bit ADC_WIDTH_BIT_12 105 106 /** 107 * @brief ADC digital controller encode option. 108 * 109 * @deprecated The ESP32-S2 doesn't use I2S DMA. Call ``adc_digi_output_format_t`` instead. 110 */ 111 typedef enum { 112 ADC_ENCODE_12BIT, /*!< ADC to DMA data format, , [15:12]-channel [11:0]-12 bits ADC data */ 113 ADC_ENCODE_11BIT, /*!< ADC to DMA data format, [15]-unit, [14:11]-channel [10:0]-11 bits ADC data */ 114 ADC_ENCODE_MAX, 115 } adc_i2s_encode_t; 116 117 /*--------------------------------------------------------------- 118 Common setting 119 ---------------------------------------------------------------*/ 120 121 /** 122 * @brief Enable ADC power 123 * @deprecated Use adc_power_acquire and adc_power_release instead. 124 */ 125 void adc_power_on(void) __attribute__((deprecated)); 126 127 /** 128 * @brief Power off SAR ADC 129 * @deprecated Use adc_power_acquire and adc_power_release instead. 130 * This function will force power down for ADC. 131 * This function is deprecated because forcing power ADC power off may 132 * disrupt operation of other components which may be using the ADC. 133 */ 134 void adc_power_off(void) __attribute__((deprecated)); 135 136 /** 137 * @brief Increment the usage counter for ADC module. 138 * ADC will stay powered on while the counter is greater than 0. 139 * Call adc_power_release when done using the ADC. 140 */ 141 void adc_power_acquire(void); 142 143 /** 144 * @brief Decrement the usage counter for ADC module. 145 * ADC will stay powered on while the counter is greater than 0. 146 * Call this function when done using the ADC. 147 */ 148 void adc_power_release(void); 149 150 /*--------------------------------------------------------------- 151 ADC Single Read Setting 152 ---------------------------------------------------------------*/ 153 /** 154 * @brief Get the GPIO number of a specific ADC1 channel. 155 * 156 * @param channel Channel to get the GPIO number 157 * @param gpio_num output buffer to hold the GPIO number 158 * 159 * @return 160 * - ESP_OK if success 161 * - ESP_ERR_INVALID_ARG if channel not valid 162 */ 163 esp_err_t adc1_pad_get_io_num(adc1_channel_t channel, gpio_num_t *gpio_num); 164 165 /** 166 * @brief Set the attenuation of a particular channel on ADC1, and configure its associated GPIO pin mux. 167 * 168 * The default ADC voltage is for attenuation 0 dB and listed in the table below. 169 * By setting higher attenuation it is possible to read higher voltages. 170 * 171 * Due to ADC characteristics, most accurate results are obtained within the "suggested range" 172 * shown in the following table. 173 * 174 * +----------+-------------+-----------------+ 175 * | | attenuation | suggested range | 176 * | SoC | (dB) | (mV) | 177 * +==========+=============+=================+ 178 * | | 0 | 100 ~ 950 | 179 * | +-------------+-----------------+ 180 * | | 2.5 | 100 ~ 1250 | 181 * | ESP32 +-------------+-----------------+ 182 * | | 6 | 150 ~ 1750 | 183 * | +-------------+-----------------+ 184 * | | 11 | 150 ~ 2450 | 185 * +----------+-------------+-----------------+ 186 * | | 0 | 0 ~ 750 | 187 * | +-------------+-----------------+ 188 * | | 2.5 | 0 ~ 1050 | 189 * | ESP32-S2 +-------------+-----------------+ 190 * | | 6 | 0 ~ 1300 | 191 * | +-------------+-----------------+ 192 * | | 11 | 0 ~ 2500 | 193 * +----------+-------------+-----------------+ 194 * 195 * For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges. 196 * 197 * @note For any given channel, this function must be called before the first time ``adc1_get_raw()`` is called for that channel. 198 * 199 * @note This function can be called multiple times to configure multiple 200 * ADC channels simultaneously. You may call ``adc1_get_raw()`` only after configuring a channel. 201 * 202 * @param channel ADC1 channel to configure 203 * @param atten Attenuation level 204 * 205 * @return 206 * - ESP_OK success 207 * - ESP_ERR_INVALID_ARG Parameter error 208 */ 209 esp_err_t adc1_config_channel_atten(adc1_channel_t channel, adc_atten_t atten); 210 211 /** 212 * @brief Configure ADC1 capture width, meanwhile enable output invert for ADC1. 213 * The configuration is for all channels of ADC1 214 * @param width_bit Bit capture width for ADC1 215 * 216 * @return 217 * - ESP_OK success 218 * - ESP_ERR_INVALID_ARG Parameter error 219 */ 220 esp_err_t adc1_config_width(adc_bits_width_t width_bit); 221 222 /** 223 * @brief Take an ADC1 reading from a single channel. 224 * @note ESP32: 225 * When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned on, 226 * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. 227 * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. 228 * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. 229 * As a workaround, call adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), 230 * but will remove the glitches on GPIO36 and GPIO39. 231 * 232 * @note Call ``adc1_config_width()`` before the first time this 233 * function is called. 234 * 235 * @note For any given channel, adc1_config_channel_atten(channel) 236 * must be called before the first time this function is called. Configuring 237 * a new channel does not prevent a previously configured channel from being read. 238 * 239 * @param channel ADC1 channel to read 240 * 241 * @return 242 * - -1: Parameter error 243 * - Other: ADC1 channel reading. 244 */ 245 int adc1_get_raw(adc1_channel_t channel); 246 247 #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 248 //TODO IDF-3610, replace these with proper caps 249 /** 250 * @brief Set ADC data invert 251 * @param adc_unit ADC unit index 252 * @param inv_en whether enable data invert 253 * @return 254 * - ESP_OK success 255 * - ESP_ERR_INVALID_ARG Parameter error 256 */ 257 esp_err_t adc_set_data_inv(adc_unit_t adc_unit, bool inv_en); 258 259 /** 260 * @brief Set ADC source clock 261 * @param clk_div ADC clock divider, ADC clock is divided from APB clock 262 * @return 263 * - ESP_OK success 264 */ 265 esp_err_t adc_set_clk_div(uint8_t clk_div); 266 267 /** 268 * @brief Configure ADC capture width. 269 * 270 * @param adc_unit ADC unit index 271 * @param width_bit Bit capture width for ADC unit. 272 * 273 * @return 274 * - ESP_OK success 275 * - ESP_ERR_INVALID_ARG Parameter error 276 */ 277 esp_err_t adc_set_data_width(adc_unit_t adc_unit, adc_bits_width_t width_bit); 278 279 /** 280 * @brief Configure ADC1 to be usable by the ULP 281 * 282 * This function reconfigures ADC1 to be controlled by the ULP. 283 * Effect of this function can be reverted using ``adc1_get_raw()`` function. 284 * 285 * Note that adc1_config_channel_atten, ``adc1_config_width()`` functions need 286 * to be called to configure ADC1 channels, before ADC1 is used by the ULP. 287 */ 288 void adc1_ulp_enable(void); 289 #endif //#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 290 291 /** 292 * @brief Get the GPIO number of a specific ADC2 channel. 293 * 294 * @param channel Channel to get the GPIO number 295 * 296 * @param gpio_num output buffer to hold the GPIO number 297 * 298 * @return 299 * - ESP_OK if success 300 * - ESP_ERR_INVALID_ARG if channel not valid 301 */ 302 esp_err_t adc2_pad_get_io_num(adc2_channel_t channel, gpio_num_t *gpio_num); 303 304 /** 305 * @brief Configure the ADC2 channel, including setting attenuation. 306 * 307 * The default ADC voltage is for attenuation 0 dB and listed in the table below. 308 * By setting higher attenuation it is possible to read higher voltages. 309 * 310 * Due to ADC characteristics, most accurate results are obtained within the "suggested range" 311 * shown in the following table. 312 * 313 * +----------+-------------+-----------------+ 314 * | | attenuation | suggested range | 315 * | SoC | (dB) | (mV) | 316 * +==========+=============+=================+ 317 * | | 0 | 100 ~ 950 | 318 * | +-------------+-----------------+ 319 * | | 2.5 | 100 ~ 1250 | 320 * | ESP32 +-------------+-----------------+ 321 * | | 6 | 150 ~ 1750 | 322 * | +-------------+-----------------+ 323 * | | 11 | 150 ~ 2450 | 324 * +----------+-------------+-----------------+ 325 * | | 0 | 0 ~ 750 | 326 * | +-------------+-----------------+ 327 * | | 2.5 | 0 ~ 1050 | 328 * | ESP32-S2 +-------------+-----------------+ 329 * | | 6 | 0 ~ 1300 | 330 * | +-------------+-----------------+ 331 * | | 11 | 0 ~ 2500 | 332 * +----------+-------------+-----------------+ 333 * 334 * For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges. 335 * 336 * @note This function also configures the input GPIO pin mux to 337 * connect it to the ADC2 channel. It must be called before calling 338 * ``adc2_get_raw()`` for this channel. 339 * 340 * @note For any given channel, this function must be called before the first time ``adc2_get_raw()`` is called for that channel. 341 * 342 * @param channel ADC2 channel to configure 343 * @param atten Attenuation level 344 * 345 * @return 346 * - ESP_OK success 347 * - ESP_ERR_INVALID_ARG Parameter error 348 */ 349 esp_err_t adc2_config_channel_atten(adc2_channel_t channel, adc_atten_t atten); 350 351 /** 352 * @brief Take an ADC2 reading on a single channel 353 * 354 * @note ESP32: 355 * When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned on, 356 * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. 357 * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. 358 * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. 359 * As a workaround, call adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), 360 * but will remove the glitches on GPIO36 and GPIO39. 361 * 362 * 363 * @note ESP32: 364 * For a given channel, ``adc2_config_channel_atten()`` 365 * must be called before the first time this function is called. If Wi-Fi is started via ``esp_wifi_start()``, this 366 * function will always fail with ``ESP_ERR_TIMEOUT``. 367 * 368 * @note ESP32-S2: 369 * ADC2 support hardware arbiter. The arbiter is to improve the use efficiency of ADC2. After the control right is robbed by the high priority, 370 * the low priority controller will read the invalid ADC2 data. Default priority: Wi-Fi > RTC > Digital; 371 * 372 * @param channel ADC2 channel to read 373 * @param width_bit Bit capture width for ADC2 374 * @param raw_out the variable to hold the output data. 375 * 376 * @return 377 * - ESP_OK if success 378 * - ESP_ERR_TIMEOUT ADC2 is being used by other controller and the request timed out. 379 * - ESP_ERR_INVALID_STATE The controller status is invalid. Please try again. 380 */ 381 esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int *raw_out); 382 383 /** 384 * @brief Output ADC1 or ADC2's reference voltage to ``adc2_channe_t``'s IO. 385 * 386 * This function routes the internal reference voltage of ADCn to one of 387 * ADC2's channels. This reference voltage can then be manually measured 388 * for calibration purposes. 389 * 390 * @note ESP32 only supports output of ADC2's internal reference voltage. 391 * @param[in] adc_unit ADC unit index 392 * @param[in] gpio GPIO number (Only ADC2's channels IO are supported) 393 * 394 * @return 395 * - ESP_OK: v_ref successfully routed to selected GPIO 396 * - ESP_ERR_INVALID_ARG: Unsupported GPIO 397 */ 398 esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio); 399 400 /** 401 * @brief Output ADC2 reference voltage to ``adc2_channe_t``'s IO. 402 * 403 * This function routes the internal reference voltage of ADCn to one of 404 * ADC2's channels. This reference voltage can then be manually measured 405 * for calibration purposes. 406 * 407 * @deprecated Use ``adc_vref_to_gpio`` instead. 408 * 409 * @param[in] gpio GPIO number (ADC2's channels are supported) 410 * 411 * @return 412 * - ESP_OK: v_ref successfully routed to selected GPIO 413 * - ESP_ERR_INVALID_ARG: Unsupported GPIO 414 */ 415 esp_err_t adc2_vref_to_gpio(gpio_num_t gpio) __attribute__((deprecated)); 416 417 /*--------------------------------------------------------------- 418 DMA setting 419 ---------------------------------------------------------------*/ 420 /** 421 * @brief Digital ADC DMA read max timeout value, it may make the ``adc_digi_read_bytes`` block forever if the OS supports 422 */ 423 #define ADC_MAX_DELAY UINT32_MAX 424 425 /** 426 * @brief ADC DMA driver configuration 427 */ 428 typedef struct adc_digi_init_config_s { 429 uint32_t max_store_buf_size; ///< Max length of the converted data that driver can store before they are processed. 430 uint32_t conv_num_each_intr; ///< Bytes of data that can be converted in 1 interrupt. 431 uint32_t adc1_chan_mask; ///< Channel list of ADC1 to be initialized. 432 uint32_t adc2_chan_mask; ///< Channel list of ADC2 to be initialized. 433 } adc_digi_init_config_t; 434 435 /** 436 * @brief ADC digital controller settings 437 */ 438 typedef struct { 439 bool conv_limit_en; ///< To limit ADC conversion times. Conversion stops after finishing `conv_limit_num` times conversion 440 uint32_t conv_limit_num; ///< Set the upper limit of the number of ADC conversion triggers. Range: 1 ~ 255. 441 uint32_t pattern_num; ///< Number of ADC channels that will be used 442 adc_digi_pattern_config_t *adc_pattern; ///< List of configs for each ADC channel that will be used 443 uint32_t sample_freq_hz; /*!< The expected ADC sampling frequency in Hz. Range: 611Hz ~ 83333Hz 444 Fs = Fd / interval / 2 445 Fs: sampling frequency; 446 Fd: digital controller frequency, no larger than 5M for better performance 447 interval: interval between 2 measurement trigger signal, the smallest interval should not be smaller than the ADC measurement period, the largest interval should not be larger than 4095 */ 448 adc_digi_convert_mode_t conv_mode; ///< ADC DMA conversion mode, see `adc_digi_convert_mode_t`. 449 adc_digi_output_format_t format; ///< ADC DMA conversion output format, see `adc_digi_output_format_t`. 450 } adc_digi_configuration_t; 451 452 /** 453 * @brief Initialize the Digital ADC. 454 * 455 * @param init_config Pointer to Digital ADC initilization config. Refer to ``adc_digi_init_config_t``. 456 * 457 * @return 458 * - ESP_ERR_INVALID_ARG If the combination of arguments is invalid. 459 * - ESP_ERR_NOT_FOUND No free interrupt found with the specified flags 460 * - ESP_ERR_NO_MEM If out of memory 461 * - ESP_OK On success 462 */ 463 esp_err_t adc_digi_initialize(const adc_digi_init_config_t *init_config); 464 465 /** 466 * @brief Read bytes from Digital ADC through DMA. 467 * 468 * @param[out] buf Buffer to read from ADC. 469 * @param[in] length_max Expected length of data read from the ADC. 470 * @param[out] out_length Real length of data read from the ADC via this API. 471 * @param[in] timeout_ms Time to wait for data via this API, in millisecond. 472 * 473 * @return 474 * - ESP_ERR_INVALID_STATE Driver state is invalid. Usually it means the ADC sampling rate is faster than the task processing rate. 475 * - ESP_ERR_TIMEOUT Operation timed out 476 * - ESP_OK On success 477 */ 478 esp_err_t adc_digi_read_bytes(uint8_t *buf, uint32_t length_max, uint32_t *out_length, uint32_t timeout_ms); 479 480 /** 481 * @brief Start the Digital ADC and DMA peripherals. After this, the hardware starts working. 482 * 483 * @return 484 * - ESP_ERR_INVALID_STATE Driver state is invalid. 485 * - ESP_OK On success 486 */ 487 esp_err_t adc_digi_start(void); 488 489 /** 490 * @brief Stop the Digital ADC and DMA peripherals. After this, the hardware stops working. 491 * 492 * @return 493 * - ESP_ERR_INVALID_STATE Driver state is invalid. 494 * - ESP_OK On success 495 */ 496 esp_err_t adc_digi_stop(void); 497 498 /** 499 * @brief Deinitialize the Digital ADC. 500 * 501 * @return 502 * - ESP_ERR_INVALID_STATE Driver state is invalid. 503 * - ESP_OK On success 504 */ 505 esp_err_t adc_digi_deinitialize(void); 506 507 /** 508 * @brief Setting the digital controller. 509 * 510 * @param config Pointer to digital controller paramter. Refer to ``adc_digi_config_t``. 511 * 512 * @return 513 * - ESP_ERR_INVALID_STATE Driver state is invalid. 514 * - ESP_ERR_INVALID_ARG If the combination of arguments is invalid. 515 * - ESP_OK On success 516 */ 517 esp_err_t adc_digi_controller_configure(const adc_digi_configuration_t *config); 518 519 520 #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 521 //TODO IDF-3610 522 /** 523 * @brief Reset adc digital controller filter. 524 * 525 * @param idx Filter index. 526 * 527 * @return 528 * - ESP_OK Success 529 */ 530 esp_err_t adc_digi_filter_reset(adc_digi_filter_idx_t idx); 531 532 /** 533 * @brief Set adc digital controller filter configuration. 534 * 535 * @note For ESP32S2, Filter IDX0/IDX1 can only be used to filter all enabled channels of ADC1/ADC2 unit at the same time. 536 * 537 * @param idx Filter index. 538 * @param config See ``adc_digi_filter_t``. 539 * 540 * @return 541 * - ESP_OK Success 542 */ 543 esp_err_t adc_digi_filter_set_config(adc_digi_filter_idx_t idx, adc_digi_filter_t *config); 544 545 /** 546 * @brief Get adc digital controller filter configuration. 547 * 548 * @note For ESP32S2, Filter IDX0/IDX1 can only be used to filter all enabled channels of ADC1/ADC2 unit at the same time. 549 * 550 * @param idx Filter index. 551 * @param config See ``adc_digi_filter_t``. 552 * 553 * @return 554 * - ESP_OK Success 555 */ 556 esp_err_t adc_digi_filter_get_config(adc_digi_filter_idx_t idx, adc_digi_filter_t *config); 557 558 /** 559 * @brief Enable/disable adc digital controller filter. 560 * Filtering the ADC data to obtain smooth data at higher sampling rates. 561 * 562 * @note For ESP32S2, Filter IDX0/IDX1 can only be used to filter all enabled channels of ADC1/ADC2 unit at the same time. 563 * 564 * @param idx Filter index. 565 * @param enable Enable/Disable filter. 566 * 567 * @return 568 * - ESP_OK Success 569 */ 570 esp_err_t adc_digi_filter_enable(adc_digi_filter_idx_t idx, bool enable); 571 572 /** 573 * @brief Config monitor of adc digital controller. 574 * 575 * @note For ESP32S2, The monitor will monitor all the enabled channel data of the each ADC unit at the same time. 576 * 577 * @param idx Monitor index. 578 * @param config See ``adc_digi_monitor_t``. 579 * 580 * @return 581 * - ESP_OK Success 582 */ 583 esp_err_t adc_digi_monitor_set_config(adc_digi_monitor_idx_t idx, adc_digi_monitor_t *config); 584 585 /** 586 * @brief Enable/disable monitor of adc digital controller. 587 * 588 * @note For ESP32S2, The monitor will monitor all the enabled channel data of the each ADC unit at the same time. 589 * 590 * @param idx Monitor index. 591 * @param enable True or false enable monitor. 592 * 593 * @return 594 * - ESP_OK Success 595 */ 596 esp_err_t adc_digi_monitor_enable(adc_digi_monitor_idx_t idx, bool enable); 597 #endif //#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 598 599 #if CONFIG_IDF_TARGET_ESP32 600 //TODO IDF-3610 601 /** 602 * @brief Read Hall Sensor 603 * 604 * @note When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned on, 605 * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. 606 * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. 607 * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. 608 * 609 * @note The Hall Sensor uses channels 0 and 3 of ADC1. Do not configure 610 * these channels for use as ADC channels. 611 * 612 * @note The ADC1 module must be enabled by calling 613 * adc1_config_width() before calling hall_sensor_read(). ADC1 614 * should be configured for 12 bit readings, as the hall sensor 615 * readings are low values and do not cover the full range of the 616 * ADC. 617 * 618 * @return The hall sensor reading. 619 */ 620 int hall_sensor_read(void); 621 622 /*--------------------------------------------------------------- 623 To Be Deprecated TODO: IDF-3610 624 ---------------------------------------------------------------*/ 625 /** 626 * @brief Set I2S data source 627 * @param src I2S DMA data source, I2S DMA can get data from digital signals or from ADC. 628 * @return 629 * - ESP_OK success 630 */ 631 esp_err_t adc_set_i2s_data_source(adc_i2s_source_t src); 632 633 /** 634 * @brief Initialize I2S ADC mode 635 * @param adc_unit ADC unit index 636 * @param channel ADC channel index 637 * @return 638 * - ESP_OK success 639 * - ESP_ERR_INVALID_ARG Parameter error 640 */ 641 esp_err_t adc_i2s_mode_init(adc_unit_t adc_unit, adc_channel_t channel); 642 #endif 643 644 #ifdef __cplusplus 645 } 646 #endif 647