Hello,
while looking for details of ADC handling implementation I found, that the function adc_gpio_init() clears both IE (Input Enable) and OD (Output Disable). Does it mean that the pin/pad serviced by ADC is allowed to output signals? Is it correct?
The funtion adc_gpio_init() calls first a function gpio_set_function() to set the bits IE=1 and OD=0, which makes perfect sense for generic gpio_set_function().
Later the funtion adc_gpio_init() calls gpio_set_input_enabled(gpio, false) to set the IE=0.
So the result is IE=0 and OD=0, which I'm not sure is correct.
Listing of the relevant functions:
while looking for details of ADC handling implementation I found, that the function adc_gpio_init() clears both IE (Input Enable) and OD (Output Disable). Does it mean that the pin/pad serviced by ADC is allowed to output signals? Is it correct?
The funtion adc_gpio_init() calls first a function gpio_set_function() to set the bits IE=1 and OD=0, which makes perfect sense for generic gpio_set_function().
Later the funtion adc_gpio_init() calls gpio_set_input_enabled(gpio, false) to set the IE=0.
So the result is IE=0 and OD=0, which I'm not sure is correct.
Listing of the relevant functions:
Code:
/// \tag::gpio_set_function[]// Select function for this GPIO, and ensure input/output are enabled at the pad.// This also clears the input/output/irq override bits.void gpio_set_function(uint gpio, gpio_function_t fn) { check_gpio_param(gpio); invalid_params_if(HARDWARE_GPIO, ((uint32_t)fn << IO_BANK0_GPIO0_CTRL_FUNCSEL_LSB) & ~IO_BANK0_GPIO0_CTRL_FUNCSEL_BITS); // Set input enable on, output disable off hw_write_masked(&pads_bank0_hw->io[gpio], PADS_BANK0_GPIO0_IE_BITS, PADS_BANK0_GPIO0_IE_BITS | PADS_BANK0_GPIO0_OD_BITS ); // Zero all fields apart from fsel; we want this IO to do what the peripheral tells it. // This doesn't affect e.g. pullup/pulldown, as these are in pad controls. io_bank0_hw->io[gpio].ctrl = fn << IO_BANK0_GPIO0_CTRL_FUNCSEL_LSB;#if !PICO_RP2040 // Remove pad isolation now that the correct peripheral is in control of the pad hw_clear_bits(&pads_bank0_hw->io[gpio], PADS_BANK0_GPIO0_ISO_BITS);#endif/*! \brief Initialise the gpio for use as an ADC pin * \ingroup hardware_adc * * Prepare a GPIO for use with ADC by disabling all digital functions. * * \param gpio The GPIO number to use. Allowable GPIO numbers are 26 to 29 inclusive on RP2040 or RP2350A, 40-48 inclusive on RP2350B */static inline void adc_gpio_init(uint gpio) { invalid_params_if(HARDWARE_ADC, gpio < ADC_BASE_PIN || gpio >= ADC_BASE_PIN + NUM_ADC_CHANNELS - 1); // Select NULL function to make output driver hi-Z gpio_set_function(gpio, GPIO_FUNC_NULL); // Also disable digital pulls and digital receiver gpio_disable_pulls(gpio); gpio_set_input_enabled(gpio, false);}Statistics: Posted by kukurice — Sun May 11, 2025 9:35 pm