sta-core/src/hal/gpio_pin.cpp
2022-05-02 13:37:44 +02:00

38 lines
631 B
C++

#include <sta/hal/gpio_pin.hpp>
#ifdef STA_HAL_GPIO_ENABLE
#include <sta/assert.hpp>
namespace sta
{
HalGpioPin::HalGpioPin(GPIO_TypeDef * port, uint16_t pin)
: port_{port}, pin_{pin}
{
STA_ASSERT(port != nullptr);
}
void HalGpioPin::setState(GpioPinState state)
{
HAL_GPIO_WritePin(port_, pin_, (state == GpioPinState::LOW) ? GPIO_PIN_RESET : GPIO_PIN_SET);
}
GPIO_TypeDef * HalGpioPin::getPort() const
{
return port_;
}
uint16_t HalGpioPin::getPin() const
{
return pin_;
}
uint8_t HalGpioPin::getIndex() const
{
return GPIO_GET_INDEX(port_);
}
} // namespace sta
#endif // STA_HAL_GPIO_ENABLE