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.
pull/786/head
Phil Howard 2023-06-01 22:46:11 +01:00
rodzic bff6bd023e
commit 70a1b26041
5 zmienionych plików z 5 dodań i 5 usunięć

Wyświetl plik

@ -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);

Wyświetl plik

@ -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);

Wyświetl plik

@ -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);

Wyświetl plik

@ -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);

Wyświetl plik

@ -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);