41 lines
834 B
C++
41 lines
834 B
C++
/**** Includes ****/
|
|
#include "../utils/utils.h"
|
|
#include "mcu/mcu_hal.h"
|
|
#include "din.h"
|
|
|
|
using namespace board;
|
|
|
|
/**** Private definitions ****/
|
|
/**** Private constants ****/
|
|
/**** Private variables ****/
|
|
/**** Private function declarations ****/
|
|
|
|
/**** Public function definitions ****/
|
|
board::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;
|
|
}
|
|
|
|
board::DigitalIn::~DigitalIn(void)
|
|
{
|
|
return;
|
|
}
|
|
|
|
uint8_t board::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 ****/
|