2019-02-09 21:33:45 +01:00
|
|
|
/*
|
|
|
|
* adc.h
|
|
|
|
*
|
|
|
|
* Created on: 08.02.2019
|
|
|
|
* Author: julian
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ADC_H_
|
|
|
|
#define ADC_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
typedef uint16_t adc_sample_t;
|
|
|
|
|
2019-02-13 00:05:52 +01:00
|
|
|
#define ADC_BUFFER_SIZE 5
|
|
|
|
|
2019-02-09 21:33:45 +01:00
|
|
|
typedef struct {
|
2019-02-13 00:05:52 +01:00
|
|
|
|
2019-02-09 21:33:45 +01:00
|
|
|
} adc_buffer_t;
|
|
|
|
|
|
|
|
typedef struct adc {
|
2019-02-13 00:05:52 +01:00
|
|
|
adc_sample_t buffer[ADC_BUFFER_SIZE];
|
2019-02-09 21:33:45 +01:00
|
|
|
|
2019-02-13 00:05:52 +01:00
|
|
|
volatile uint8_t current_channel;
|
|
|
|
uint8_t * channel_map;
|
2019-02-09 21:33:45 +01:00
|
|
|
} adc_t;
|
|
|
|
|
|
|
|
// the adc instance
|
2019-02-13 00:05:52 +01:00
|
|
|
extern adc_t adc;
|
2019-02-09 21:33:45 +01:00
|
|
|
|
2019-02-13 00:05:52 +01:00
|
|
|
void adc_init(uint8_t * channels);
|
2019-02-09 21:33:45 +01:00
|
|
|
|
2019-02-13 00:05:52 +01:00
|
|
|
#define adc_start() ADCSRA |= (1<<ADIE) | (1<<ADSC)
|
|
|
|
#define adc_stop() ADCSRA &= ~(1<<ADIE)
|
2019-02-09 21:33:45 +01:00
|
|
|
|
|
|
|
#endif /* ADC_H_ */
|