8000 rp2/machine_adc: Only initialise the ADC periph if not already enabled. · dpgeorge/micropython@7f7b4f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f7b4f2

Browse files
committed
rp2/machine_adc: Only initialise the ADC periph if not already enabled.
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 micropython#6833. Signed-off-by: Damien George <damien@micropython.org>
1 parent 78b23c3 commit 7f7b4f2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ports/rp2/machine_adc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ STATIC mp_obj_t machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, s
7878
}
7979
}
8080

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

8386
if (ADC_IS_VALID_GPIO(channel)) {
8487
// Configure the GPIO pin in ADC mode.

0 commit comments

Comments
 (0)
0