components/driver/esp32s2/adc.c
/**
 * @brief Set ADC module controller.
 *        There are five SAR ADC controllers:
 *        Two digital controller: Continuous conversion mode (DMA). High performance with multiple channel scan modes;
 *        Two RTC controller: Single conversion modes (Polling). For low power purpose working during deep sleep;
 *        the other is dedicated for Power detect (PWDET / PKDET), Only support ADC2.
 *
 * @note  Only ADC2 support arbiter to switch controllers automatically. Access to the ADC is based on the priority of the controller.
 * @note  For ADC1, Controller access is mutually exclusive.
 *
 * @param adc_unit ADC unit.
 * @param ctrl ADC controller, Refer to `adc_ll_controller_t`.
 *
 * @return
 *      - ESP_OK Success
 */
@brief Set ADC module controller.
There are five SAR ADC controllers:
Two digital controller: Continuous conversion mode (DMA). High performance with multiple channel scan modes;
Two RTC controller: Single conversion modes (Polling). For low power purpose working during deep sleep;
the other is dedicated for Power detect (PWDET / PKDET), Only support ADC2.

@note  Only ADC2 support arbiter to switch controllers automatically. Access to the ADC is based on the priority of the controller.
@note  For ADC1, Controller access is mutually exclusive.

@param adc_unit ADC unit.
@param ctrl ADC controller, Refer to `adc_ll_controller_t`.

@return
- ESP_OK Success
@brief Set ADC module controller . There are five SAR ADC controllers : Two digital controller : Continuous conversion mode ( DMA ) . High performance with multiple channel scan modes ; Two RTC controller : Single conversion modes ( Polling ) . For low power purpose working during deep sleep ; the other is dedicated for Power detect ( PWDET / PKDET ) Only support ADC2 . @note Only ADC2 support arbiter to switch controllers automatically . Access to the ADC is based on the priority of the controller . @note For ADC1 Controller access is mutually exclusive . @param adc_unit ADC unit . @param ctrl ADC controller Refer to ` adc_ll_controller_t ` . @return - ESP_OK Success
esp_err_t adc_set_controller(adc_unit_t adc_unit, adc_ll_controller_t ctrl)
{
    adc_arbiter_t config = {0};
    adc_arbiter_t cfg = ADC_ARBITER_CONFIG_DEFAULT();
    if (adc_unit & ADC_UNIT_1) {
        adc_hal_set_controller(ADC_NUM_1, ctrl);
    }
    if (adc_unit & ADC_UNIT_2) {
        adc_hal_set_controller(ADC_NUM_2, ctrl);
        switch (ctrl) {
        case ADC2_CTRL_FORCE_PWDET:
            config.pwdet_pri = 2;
            config.mode = ADC_ARB_MODE_SHIELD;
            adc_hal_arbiter_config(&config);
            adc_hal_set_controller(ADC_NUM_2, ADC2_CTRL_PWDET);
            break;
        case ADC2_CTRL_FORCE_RTC:
            config.rtc_pri = 2;
            config.mode = ADC_ARB_MODE_SHIELD;
            adc_hal_arbiter_config(&config);
            adc_hal_set_controller(ADC_NUM_2, ADC_CTRL_RTC);
            break;
        case ADC2_CTRL_FORCE_ULP:
            config.rtc_pri = 2;
            config.mode = ADC_ARB_MODE_SHIELD;
            adc_hal_arbiter_config(&config);
            adc_hal_set_controller(ADC_NUM_2, ADC_CTRL_ULP);
            break;
        case ADC2_CTRL_FORCE_DIG:
            config.dig_pri = 2;
            config.mode = ADC_ARB_MODE_SHIELD;
            adc_hal_arbiter_config(&config);
            adc_hal_set_controller(ADC_NUM_2, ADC_CTRL_DIG);
            break;
        default:
            adc_hal_arbiter_config(&cfg);
            break;
        }
    }
    return ESP_OK;
}
esp_err_t adc_set_controller ( adc_unit_t adc_unit , adc_ll_controller_t ctrl ) { adc_arbiter_t config = { 0 } ; adc_arbiter_t cfg = ADC_ARBITER_CONFIG_DEFAULT ( ) ; if ( adc_unit & ADC_UNIT_1 ) { adc_hal_set_controller ( ADC_NUM_1 , ctrl ) ; } if ( adc_unit & ADC_UNIT_2 ) { adc_hal_set_controller ( ADC_NUM_2 , ctrl ) ; switch ( ctrl ) { case ADC2_CTRL_FORCE_PWDET : config . pwdet_pri = 2 ; config . mode = ADC_ARB_MODE_SHIELD ; adc_hal_arbiter_config ( & config ) ; adc_hal_set_controller ( ADC_NUM_2 , ADC2_CTRL_PWDET ) ; break ; case ADC2_CTRL_FORCE_RTC : config . rtc_pri = 2 ; config . mode = ADC_ARB_MODE_SHIELD ; adc_hal_arbiter_config ( & config ) ; adc_hal_set_controller ( ADC_NUM_2 , ADC_CTRL_RTC ) ; break ; case ADC2_CTRL_FORCE_ULP : config . rtc_pri = 2 ; config . mode = ADC_ARB_MODE_SHIELD ; adc_hal_arbiter_config ( & config ) ; adc_hal_set_controller ( ADC_NUM_2 , ADC_CTRL_ULP ) ; break ; case ADC2_CTRL_FORCE_DIG : config . dig_pri = 2 ; config . mode = ADC_ARB_MODE_SHIELD ; adc_hal_arbiter_config ( & config ) ; adc_hal_set_controller ( ADC_NUM_2 , ADC_CTRL_DIG ) ; break ; default : adc_hal_arbiter_config ( & cfg ) ; break ; } } return ESP_OK ; }
@brief Set ADC module controller.
@brief Set ADC module controller .