sta-core/include/sta/hal/gpio_pin.hpp
2022-05-08 03:11:12 +02:00

69 lines
1.1 KiB
C++

/**
* @file
* @brief Wrapper for HAL GPIO pins.
*/
#ifndef STA_HAL_GPIO_PIN_HPP
#define STA_HAL_GPIO_PIN_HPP
/**
* @defgroup halGPIO GPIO
* @ingroup hal
* @brief HAL GPIO module
*/
#ifdef DOXYGEN
/**
* @def STA_HAL_GPIO_ENABLE
* @brief Enable module.
*
* @ingroup halBuildConfig
*/
# define STA_HAL_GPIO_ENABLE
#endif // DOXYGEN
#include <sta/config.hpp>
#ifdef STA_HAL_GPIO_ENABLE
#include <sta/intf/gpio_pin.hpp>
#include <sta/hal.hpp>
namespace sta
{
/**
* @brief Container for HAL GPIO Pin objects.
*
* @ingroup halGPIO
*/
class HalGpioPin : public GpioPin
{
public:
HalGpioPin(GPIO_TypeDef * port, uint16_t pin);
void setState(GpioPinState state) override;
GPIO_TypeDef * getPort() const;
uint16_t getPin() const;
uint8_t getIndex() const;
private:
GPIO_TypeDef * port_; /**< GPIO port */
uint16_t pin_; /**< GPIO pin */
};
}
/**
* @brief Create HalGpioPin object from pin label.
*
* @param label Pin label
*
* @ingroup halGPIO
*/
#define STA_HAL_GPIO_PIN(label) sta::HalGpioPin{label##_GPIO_Port, label##_Pin}
#endif // STA_HAL_GPIO_ENABLE
#endif // STA_HAL_GPIO_PIN_HPP