osd-contiki/platform/osd-merkur/dev/adc.h
Ralf Schlatterbeck abdf6f8c6b Refactor A/D conversion in adc.c
Now the necessary settings are in adc.h. Refactored to allow repeated
ADC reads without reinitialization. Arduino allows setting
analogReference, this is now also implemented.
ADC is now initialized to sane values in apps/arduino/arduino-process.c
dev/arduino/arduino-compat.h now has all hardware independent settings
for arduino (some moved from platform/osd-merkur/dev/hw-arduino.h).
turnOffPWM re-implemented with hw_timer, removed from wiring_digital.c
ADC-specific arduino stuff moved to arduino-compat.h
Arduinos wiring_analog no longer necessary.
arduino-sketch example now reads analog inputs 1 and 5 using analogRead.
2014-11-19 13:53:32 +01:00

53 lines
1 KiB
C

#ifndef __ADC_ARCH_H__
#define __ADC_ARCH_H__
#include <avr/io.h>
/*
* Reference voltage
* The default is 1.6V reference voltage
* The selected reference voltage is the maximum voltage that can be
* measured.
* Directly provide shifted variants so we don't need to shift.
*/
#define ADC_1_5 (2<<6)
#define ADC_1_6 (3<<6)
#define ADC_1_8 (1<<6)
#define ADC_EXTERNAL (0<<6)
#define ADC_DEFAULT ADC_1_6
/* sometimes it's desirable to decouple setup / finish from sampling */
static inline void adc_setup (uint8_t ref_volt, uint8_t pin)
{
ADMUX = ref_volt | (pin & 0x7);
ADCSRA = _BV(ADEN) | _BV(ADPS0) | _BV(ADPS2);
}
static inline int adc_read (void)
{
ADCSRA |= (1 << ADSC);
loop_until_bit_is_clear (ADCSRA, ADSC);
return ADC;
}
static inline void adc_fin (void)
{
ADCSRA = 0;
ADMUX = 0;
}
static inline void adc_init (void)
{
ADCSRC = 0;
ADCSRB = 0;
adc_fin ();
}
int readADC(uint8_t pin);
long readVcc();
int readInternalTemp(void);
void analogReference(uint8_t mode);
#endif /* __ADC_ARCH_H__ */