]> www.fi.muni.cz Git - bike-lights.git/blobdiff - firmware/adc.c
adc: always-running ADC
[bike-lights.git] / firmware / adc.c
index fa0782c4248c6ee67917901cc1340dedfefea087..b7dad0ad59b31a940acecec248c91fd14ba8b2aa 100644 (file)
@@ -51,15 +51,15 @@ static void inline setup_mux(unsigned char n)
 
 static void start_next_adc()
 {
-       if (current_adc > 0) {
+       if (current_adc > 0)
                current_adc--;
-               // set up mux, start one-shot conversion
-               setup_mux(current_adc);
-               ADCSRA |= _BV(ADSC);
-       } else {
-               current_adc = NUM_ADCS;
+       else
                // TODO: kick the watchdog here.
-       }
+               current_adc = NUM_ADCS-1;
+
+       // set up mux, start one-shot conversion
+       setup_mux(current_adc);
+       ADCSRA |= _BV(ADSC);
 }
 
 void init_adc()
@@ -100,6 +100,8 @@ void init_adc()
        }
 
        ADCSRA |= _BV(ADIE); // enable IRQ
+
+       start_next_adc();
 }
 
 void susp_adc()
@@ -151,13 +153,3 @@ ISR(ADC_vect) { // IRQ handler
        start_next_adc();
 }
 
-void timer_start_adcs()
-{
-       if (current_adc == NUM_ADCS) // Don't start if in progress
-               start_next_adc();
-#if 0
-       else
-               log_byte(0x99);
-#endif
-}
-