osd-contiki/platform/osd-merkur/dev/adc.h

53 lines
1 KiB
C
Raw Normal View History

2013-02-19 10:22:48 +01:00
#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 ();
}
2013-02-19 10:22:48 +01:00
int readADC(uint8_t pin);
long readVcc();
int readInternalTemp(void);
void analogReference(uint8_t mode);
2013-02-19 10:22:48 +01:00
#endif /* __ADC_ARCH_H__ */