pull/58/head
Alex Voinea 2021-07-12 17:42:32 +03:00 committed by DRracer
parent 55637e6055
commit 4281e89e5d
3 changed files with 26 additions and 3 deletions

View File

@ -1,9 +1,31 @@
#include "adc.h"
#include <avr/io.h>
namespace hal {
namespace adc {
uint16_t ReadADC(uint8_t adc) { return 0; }
void Init() {
ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
ADMUX |= (1 << REFS0);
ADCSRA |= (1 << ADEN);
}
uint16_t ReadADC(uint8_t channel) {
uint8_t admux = ADMUX;
admux &= ~0x1F;
admux |= channel & 0x07;
ADMUX = admux;
uint8_t adcsrb = ADCSRB;
adcsrb &= ~(1 << MUX5);
adcsrb |= (channel & 0x08) << 1;
ADCSRB = adcsrb;
ADCSRA |= (1 << ADSC);
while (ADCSRA & (1 << ADSC));
return ADC;
}
} // namespace adc
} // namespace hal

View File

@ -7,7 +7,8 @@ namespace hal {
namespace adc {
/// ADC access routines
uint16_t ReadADC(uint8_t adc);
void Init();
uint16_t ReadADC(uint8_t channel);
} // namespace adc
} // namespace hal

View File

@ -137,7 +137,7 @@ void setup() {
ml::leds.SetMode(1, ml::Color::green, ml::Mode::on);
ml::leds.Step();
// adc::Init();
adc::Init();
ml::leds.SetMode(0, ml::Color::green, ml::Mode::on);
ml::leds.Step();
}