From bf037b03ecb0b162439bbff77f2badc421629a6a Mon Sep 17 00:00:00 2001 From: Henrik Stickann <4376396-Mithradir@users.noreply.gitlab.com> Date: Sat, 9 Apr 2022 21:47:55 +0200 Subject: [PATCH] Add HAL GPIO pin implementation --- include/sta/hal/gpio_pin.hpp | 45 ++++++++++++++++++++++++++++++++++++ src/hal/gpio_pin.cpp | 19 +++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 include/sta/hal/gpio_pin.hpp create mode 100644 src/hal/gpio_pin.cpp diff --git a/include/sta/hal/gpio_pin.hpp b/include/sta/hal/gpio_pin.hpp new file mode 100644 index 0000000..a580635 --- /dev/null +++ b/include/sta/hal/gpio_pin.hpp @@ -0,0 +1,45 @@ +/** + * @brief Wrapper for HAL GPIO pins. + * + * Defined STA_HAL_GPIO_ENABLE in to enable. + */ +#ifndef STA_HAL_GPIO_PIN_HPP +#define STA_HAL_GPIO_PIN_HPP + +#include +#ifdef STA_HAL_GPIO_ENABLE + +#include + +#include + + +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 diff --git a/src/hal/gpio_pin.cpp b/src/hal/gpio_pin.cpp new file mode 100644 index 0000000..6a23c87 --- /dev/null +++ b/src/hal/gpio_pin.cpp @@ -0,0 +1,19 @@ +#include + +#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