mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-02 09:21:54 +00:00
Add HAL GPIO pin implementation
This commit is contained in:
parent
a068681b31
commit
bf037b03ec
45
include/sta/hal/gpio_pin.hpp
Normal file
45
include/sta/hal/gpio_pin.hpp
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @brief Wrapper for HAL GPIO pins.
|
||||
*
|
||||
* Defined STA_HAL_GPIO_ENABLE in <sta/config.hpp> to enable.
|
||||
*/
|
||||
#ifndef STA_HAL_GPIO_PIN_HPP
|
||||
#define STA_HAL_GPIO_PIN_HPP
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_HAL_GPIO_ENABLE
|
||||
|
||||
#include <sta/gpio_pin.hpp>
|
||||
|
||||
#include <main.h>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Container for HAL GPIO Pin objects.
|
||||
*/
|
||||
class HalGpioPin : public GpioPin
|
||||
{
|
||||
public:
|
||||
HalGpioPin(GPIO_TypeDef * port, uint16_t pin);
|
||||
|
||||
void setState(GpioPinState state) override;
|
||||
|
||||
private:
|
||||
GPIO_TypeDef * port_; /**< GPIO port */
|
||||
uint16_t pin_; /**< GPIO pin */
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create HalGpioPin object from pin label.
|
||||
*
|
||||
* @param label Pin label
|
||||
*/
|
||||
#define STA_HAL_GPIO_PIN(label) sta::HalGpioPin{label##_GPIO_Port, label##_Pin}
|
||||
|
||||
|
||||
#endif // STA_HAL_GPIO_ENABLE
|
||||
|
||||
#endif // STA_HAL_GPIO_PIN_HPP
|
19
src/hal/gpio_pin.cpp
Normal file
19
src/hal/gpio_pin.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include <sta/hal/gpio_pin.hpp>
|
||||
|
||||
#ifdef STA_HAL_GPIO_ENABLE
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
HalGpioPin::HalGpioPin(GPIO_TypeDef * port, uint16_t pin)
|
||||
: port_{port}, pin_{pin}
|
||||
{}
|
||||
|
||||
void HalGpioPin::setState(GpioPinState state)
|
||||
{
|
||||
HAL_GPIO_WritePin(port_, pin_, (state == GpioPinState::LOW) ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_HAL_GPIO_ENABLE
|
Loading…
x
Reference in New Issue
Block a user