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

using namespace bsp;

/**** Private definitions ****/
/**** Private constants ****/
/**** Private variables ****/
/**** Private function declarations ****/

/**** Public function definitions ****/
bsp::DigitalIn::DigitalIn(uint8_t gpio_ch, uint8_t inverted, uint8_t init_value)
{
	this->gpio_ch = gpio_ch;
	this->invert = inverted;
	
	if(init_value) this->last_read = DIN_HIGH;
	else this->last_read = DIN_LOW;
}

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

uint8_t bsp::DigitalIn::read(void)
{
	uint8_t lvl = mcu::gpio_read(this->gpio_ch);
	
	if(this->invert) lvl = util::invert(lvl);
	
	if(lvl>0) this->last_read = DIN_HIGH;
	else this->last_read = DIN_LOW;
	
	return this->last_read;
}

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