49 lines
869 B
C++
49 lines
869 B
C++
/**** 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(void)
|
|
{
|
|
return;
|
|
}
|
|
|
|
bsp::DigitalIn::~DigitalIn(void)
|
|
{
|
|
return;
|
|
}
|
|
|
|
void bsp::DigitalIn::init(uint8_t gpio_ch, uint8_t inverted)
|
|
{
|
|
this->gpio_ch = gpio_ch;
|
|
if(inverted == 0) this->is_inverted = 0;
|
|
else this->is_inverted = 1;
|
|
this->last_read = 0;
|
|
}
|
|
|
|
|
|
uint8_t bsp::DigitalIn::read(void)
|
|
{
|
|
// Read ADC
|
|
this->last_read = mcu::gpio_read(this->gpio_ch);
|
|
|
|
// Invert if necessary
|
|
if(this->is_inverted)
|
|
{
|
|
if(this->last_read==0) this->last_read = 1;
|
|
else this->last_read = 0;
|
|
};
|
|
|
|
return this->last_read;
|
|
}
|
|
|
|
/**** Private function definitions ****/
|
|
|