From: Jan "Yenya" Kasprzak Date: Thu, 14 Mar 2013 19:20:48 +0000 (+0100) Subject: adc: fix the button adc number X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=commitdiff_plain;h=91af506996bba7fdcaeffcf31dcbb2f1e7f46ab2 adc: fix the button adc number ... and use symbolic constants in the switch statement to avoid this kind of bugs in the future. --- diff --git a/firmware/adc.c b/firmware/adc.c index 6db036a..9cc1374 100644 --- a/firmware/adc.c +++ b/firmware/adc.c @@ -6,7 +6,7 @@ #define AMBIENT_ADC N_PWMLEDS #define BATTERY_ADC (N_PWMLEDS + 1) #define ADC1_GAIN20 (N_PWMLEDS + 2) -#define BUTTON_ADC (N_PWMLEDS + 2) +#define BUTTON_ADC (N_PWMLEDS + 3) #define NUM_ADCS 7 volatile static unsigned char current_adc; @@ -32,19 +32,19 @@ static void inline setup_mux(unsigned char n) ADMUX = _BV(REFS1) | _BV(MUX2); sum_shift = PWMLED_ADC_SHIFT; break; - case 3: // ambient light: 1.1V, ADC5 (PA6), single-ended + case AMBIENT_ADC: // ambient light: 1.1V, ADC5 (PA6), single-ended ADMUX = _BV(REFS1) | _BV(MUX2) | _BV(MUX0); sum_shift = 3; // 3 measurements break; - case 4: // batt voltage: 1.1V, ADC6 (PA7), single-ended + case BATTERY_ADC: // batt voltage: 1.1V, ADC6 (PA7), single-ended ADMUX = _BV(REFS1) | _BV(MUX2) | _BV(MUX1); sum_shift = 0; // 1 measurement break; - case 5: // gain stage offset: 1.1V, ADC1,1, gain 20 + case ADC1_GAIN20: // gain stage offset: 1.1V, ADC1,1, gain 20 ADMUX = _BV(REFS1) | _BV(MUX3) | _BV(MUX2) | _BV(MUX0); sum_shift = 0; // 1 measurement break; - case 6: // buttons: 1.1V, ADC3, single-ended + case BUTTON_ADC: // buttons: 1.1V, ADC3, single-ended PORTA |= _BV(PA3); // +5V to the voltage splitter ADMUX = _BV(REFS1) | _BV(MUX1) | _BV(MUX0); sum_shift = 0;