Skip to content

Commit

Permalink
rp2/machine_adc: Only initialise the ADC periph if not already enabled.
Browse files Browse the repository at this point in the history
Otherwise it resets the ADC peripheral each time a new ADC object is
constructed, which can reset other state that has already been set up.

See issue #6833.

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge authored and pfalcon committed Mar 16, 2021
1 parent 4ff836c commit c621dc3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ports/rp2/machine_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ STATIC mp_obj_t machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, s
}
}

adc_init();
// Initialise the ADC peripheral if it's not already running.
if (!(adc_hw->cs & ADC_CS_EN_BITS)) {
adc_init();
}

if (ADC_IS_VALID_GPIO(channel)) {
// Configure the GPIO pin in ADC mode.
Expand Down

0 comments on commit c621dc3

Please sign in to comment.