skullc-peripherals/Src/peripherals_io.cpp

45 lines
684 B
C++

/*
* IO.cpp
*
* Created on: Feb 24, 2021
* Author: erki
*/
#include <peripherals_io.hpp>
#include "peripherals_utility.hpp"
namespace Peripherals
{
IO::IO(GPIO_TypeDef* port, const unsigned short pin)
: port(port)
, pin(std::uint16_t(pin))
{ }
void IO::Set(const bool state)
{
HAL_GPIO_WritePin(port, pin, GPIO_PinState(state));
}
void IO::Toggle()
{
HAL_GPIO_TogglePin(port, pin);
}
bool IO::Read()
{
return bool(HAL_GPIO_ReadPin(port, pin));
}
#ifdef PERIPHERALS_USE_DELAY_US
void IO::SetDelayUs(const bool state, const std::uint32_t micros)
{
HAL_GPIO_WritePin(port, pin, GPIO_PinState(state));
DelayUs(micros);
}
#endif
} /* namespace Peripherals */