48 lines
890 B
C
48 lines
890 B
C
#include <avr/io.h>
|
|
#include <avr/interrupt.h>
|
|
#include "analogin.h"
|
|
#include "configuration.h"
|
|
|
|
//#define ADC_RESULT (ADCL | (ADCH << 8))
|
|
|
|
volatile unsigned char _current_pin;
|
|
volatile unsigned char _continue_at;
|
|
|
|
void
|
|
analogin_init(void)
|
|
{
|
|
_current_pin = 0;
|
|
|
|
ADMUX = _BV(REFS0);
|
|
ADCSRA = _BV(ADEN)
|
|
| _BV(ADATE)
|
|
| _BV(ADIE)
|
|
| _BV(ADSC)
|
|
// XXX
|
|
// This is only for testing (maybe I will keep it a little)
|
|
// (or do something with configure.... idk)
|
|
// Sets the prescaler to 128, we might need more time to transmit
|
|
// the data.
|
|
| _BV(ADPS0)
|
|
| _BV(ADPS1)
|
|
| _BV(ADPS2);
|
|
ADCSRB = 0;
|
|
sei();
|
|
}
|
|
|
|
ISR(ADC_vect, ISR_NOBLOCK)
|
|
{
|
|
int ADC_RESULT, last_pin;
|
|
|
|
ADC_RESULT = ADCL;
|
|
ADC_RESULT |= ADCH << 8;
|
|
|
|
last_pin = (_current_pin + 3) % 4;
|
|
|
|
_current_pin = (_current_pin + 1) % 4;
|
|
ADMUX &= 0xf0;
|
|
ADMUX |= _current_pin;
|
|
|
|
on_channel_measured(last_pin, ADC_RESULT);
|
|
}
|