From d35125cc35d0c3137d29a037a0d19ca8b451477f Mon Sep 17 00:00:00 2001 From: dario Date: Thu, 18 Apr 2024 00:01:14 +0200 Subject: [PATCH] Added easier GPIO pin API --- include/sta/gpio_pin.hpp | 18 ++++++++++++++++++ src/gpio_pin.cpp | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/gpio_pin.cpp diff --git a/include/sta/gpio_pin.hpp b/include/sta/gpio_pin.hpp index 9a26f4c..3ab32be 100644 --- a/include/sta/gpio_pin.hpp +++ b/include/sta/gpio_pin.hpp @@ -38,6 +38,24 @@ namespace sta */ virtual void setState(GpioPinState state) = 0; + /** + * @brief Set the GPIO pin to high. + * + */ + void setHigh(); + + /** + * @brief Set the GPIO pin to low. + * + */ + void setLow(); + + /** + * @brief Set the GPIO pin to the opposite of the current state. + * + */ + void toggle(); + /** * @brief Get pin input state. * diff --git a/src/gpio_pin.cpp b/src/gpio_pin.cpp new file mode 100644 index 0000000..aafd52e --- /dev/null +++ b/src/gpio_pin.cpp @@ -0,0 +1,20 @@ +#include + + +namespace sta +{ + void GpioPin::setHigh() + { + setState(GpioPinState::GPIO_HIGH); + } + + void GpioPin::setLow() + { + setState(GpioPinState::GPIO_LOW); + } + + void GpioPin::toggle() + { + setState(getState() == GpioPinState::GPIO_HIGH ? GpioPinState::GPIO_LOW : GpioPinState::GPIO_HIGH); + } +} // namespace sta