Skip to content

Commit 70a1b26

Browse files
committed
ADC: Avoid re-initialising ADC.
Only init the ADC if it's not already running. In MicroPython this could trounce an already initialised and configured ADC, and would disable the temperature sensor if it had been enabled by a user before initialising any of the affected libraries.
1 parent bff6bd0 commit 70a1b26

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

drivers/analog/analog.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace pimoroni {
1111
public:
1212
Analog(uint pin, float amplifier_gain = 1.0f, float resistor = 0.0f, float offset = 0.0f) :
1313
pin(pin), amplifier_gain(amplifier_gain), resistor(resistor), offset(offset) {
14-
adc_init();
14+
if (!(adc_hw->cs & ADC_CS_EN_BITS)) adc_init();
1515

1616
//Make sure GPIO is high-impedance, no pullups etc
1717
adc_gpio_init(pin);

libraries/adcfft/adcfft.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void ADCFFT::init() {
4747

4848
// Initialize the ADC harware
4949
// (resets it, enables the clock, spins until the hardware is ready)
50-
adc_init();
50+
if (!(adc_hw->cs & ADC_CS_EN_BITS)) adc_init();
5151

5252
// Select analog mux input (0...3 are GPIO 26, 27, 28, 29; 4 is temp sensor)
5353
adc_select_input(adc_channel);

libraries/cosmic_unicorn/cosmic_unicorn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace pimoroni {
149149
}
150150

151151
// setup light sensor adc
152-
adc_init();
152+
if (!(adc_hw->cs & ADC_CS_EN_BITS)) adc_init();
153153
adc_gpio_init(LIGHT_SENSOR);
154154

155155
gpio_init(COLUMN_CLOCK); gpio_set_dir(COLUMN_CLOCK, GPIO_OUT); gpio_put(COLUMN_CLOCK, false);

libraries/galactic_unicorn/galactic_unicorn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace pimoroni {
149149
}
150150

151151
// setup light sensor adc
152-
adc_init();
152+
if (!(adc_hw->cs & ADC_CS_EN_BITS)) adc_init();
153153
adc_gpio_init(LIGHT_SENSOR);
154154

155155
gpio_init(COLUMN_CLOCK); gpio_set_dir(COLUMN_CLOCK, GPIO_OUT); gpio_put(COLUMN_CLOCK, false);

libraries/stellar_unicorn/stellar_unicorn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace pimoroni {
149149
}
150150

151151
// setup light sensor adc
152-
adc_init();
152+
if (!(adc_hw->cs & ADC_CS_EN_BITS)) adc_init();
153153
adc_gpio_init(LIGHT_SENSOR);
154154

155155
gpio_init(COLUMN_CLOCK); gpio_set_dir(COLUMN_CLOCK, GPIO_OUT); gpio_put(COLUMN_CLOCK, false);

0 commit comments

Comments
 (0)