/**** Includes ****/
#include "../utils/utils.h"
#include "mcu/mcu_hal.h"
#include "ain.h"

using namespace bsp;

/**** Private definitions ****/
/**** Private constants ****/
/**** Private variables ****/
/**** Private function declarations ****/
/**** Public function definitions ****/
bsp::AnalogIn::AnalogIn(void)
{
	return;
}

bsp::AnalogIn::~AnalogIn(void)
{
	return;
}

void bsp::AnalogIn::init(uint8_t adc_ch)
{
	this->adc_ch = adc_ch;
	this->mul = DEF_AIN_MUL;
	this->div = DEF_AIN_DIV;
	this->offset = DEF_AIN_OFFSET;
	this->last_read = 0;
}


uint16_t bsp::AnalogIn::read(void)
{
	//Read ADC
	uint16_t raw = mcu::adc_read(this->adc_ch);
	
	//Convert to mV
	this->last_read = util::convert_muldivoff(raw, this->mul, this->div, this->offset);
	
	return this->last_read;
}

/**** Private function definitions ****/

