Skip to content

Commit

Permalink
ADC: Avoid re-initialising ADC.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Gadgetoid committed Jun 4, 2023
1 parent bff6bd0 commit 70a1b26
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion drivers/analog/analog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace pimoroni {
public:
Analog(uint pin, float amplifier_gain = 1.0f, float resistor = 0.0f, float offset = 0.0f) :
pin(pin), amplifier_gain(amplifier_gain), resistor(resistor), offset(offset) {
adc_init();
if (!(adc_hw->cs & ADC_CS_EN_BITS)) adc_init();

//Make sure GPIO is high-impedance, no pullups etc
adc_gpio_init(pin);
Expand Down
2 changes: 1 addition & 1 deletion libraries/adcfft/adcfft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void ADCFFT::init() {

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

// Select analog mux input (0...3 are GPIO 26, 27, 28, 29; 4 is temp sensor)
adc_select_input(adc_channel);
Expand Down
2 changes: 1 addition & 1 deletion libraries/cosmic_unicorn/cosmic_unicorn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ namespace pimoroni {
}

// setup light sensor adc
adc_init();
if (!(adc_hw->cs & ADC_CS_EN_BITS)) adc_init();
adc_gpio_init(LIGHT_SENSOR);

gpio_init(COLUMN_CLOCK); gpio_set_dir(COLUMN_CLOCK, GPIO_OUT); gpio_put(COLUMN_CLOCK, false);
Expand Down
2 changes: 1 addition & 1 deletion libraries/galactic_unicorn/galactic_unicorn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ namespace pimoroni {
}

// setup light sensor adc
adc_init();
if (!(adc_hw->cs & ADC_CS_EN_BITS)) adc_init();
adc_gpio_init(LIGHT_SENSOR);

gpio_init(COLUMN_CLOCK); gpio_set_dir(COLUMN_CLOCK, GPIO_OUT); gpio_put(COLUMN_CLOCK, false);
Expand Down
2 changes: 1 addition & 1 deletion libraries/stellar_unicorn/stellar_unicorn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ namespace pimoroni {
}

// setup light sensor adc
adc_init();
if (!(adc_hw->cs & ADC_CS_EN_BITS)) adc_init();
adc_gpio_init(LIGHT_SENSOR);

gpio_init(COLUMN_CLOCK); gpio_set_dir(COLUMN_CLOCK, GPIO_OUT); gpio_put(COLUMN_CLOCK, false);
Expand Down

0 comments on commit 70a1b26

Please sign in to comment.