diff --git a/fw/accel.c b/fw/accel.c index 1f45d66..018df41 100644 --- a/fw/accel.c +++ b/fw/accel.c @@ -50,6 +50,19 @@ static inline void adcsra(bool start) } +uint16_t measure_ref(bool gnd) +{ + while (ADCSRA & (1 << ADSC)); + adcsra(0); + ADMUX = + 1 << REFS0 | /* Vref is AVcc */ + (gnd ? 15 : 14); /* GND (0 V) or Vbg (1.1 V) */ + adcsra(1); + while (ADCSRA & (1 << ADSC)); + return ADC; +} + + ISR(ADC_vect) { uint16_t v; diff --git a/fw/accel.h b/fw/accel.h index e5c22bc..06c8f0d 100644 --- a/fw/accel.h +++ b/fw/accel.h @@ -21,6 +21,7 @@ extern void (*sample)(bool x, uint16_t v); +uint16_t measure_ref(bool gnd); void accel_start(void); #endif /* !ACCEL_H */