#ifndef MCPADC_H
#define MCPADC_H

#define ADC_ENABLE_18_BIT_MODE 0

#define ADC_GAIN_1 0x00
#define ADC_GAIN_2 0x01
#define ADC_GAIN_4 0x02
#define ADC_GAIN_8 0x03

#define ADC_BITS_12 0x00
#define ADC_BITS_14 0x04
#define ADC_BITS_16 0x08
#if ADC_ENABLE_18_BIT_MODE
# define ADC_BITS_18 0x0c
#endif

#define ADC_CONV_SINGLE 0x00
#define ADC_CONV_CONT 0x10

/* sets the mcp adc to the specified mode
 * valid modes are obtained by oring one of each group (ADC_GAIN_*, ADC_BITS_* and ADC_CONV_*) together
 */
void mcpadc_init(uint8_t mode);

/* tests if the adc has a new sample
 * returns nonzero if new data is aviable, 0 otherwise
 */
uint8_t mcpadc_has_new_data(void);

/* returns the most recent sample result of the adc
 * !! return type depends on defines
 */
#if ADC_ENABLE_18_BIT_MODE
int32_t mcpadc_get_data(void);
#else
int16_t mcpadc_get_data(void);
#endif

/* instructs the adc to take a new sample now
 * has no effect if the current mode includes ADC_CONV_CONT
 */
void mcpadc_start_conv(void);

#endif
