diff --git a/include/sta/gpio_pin.hpp b/include/sta/gpio_pin.hpp index 82ce7ec..c3ef231 100644 --- a/include/sta/gpio_pin.hpp +++ b/include/sta/gpio_pin.hpp @@ -21,8 +21,8 @@ namespace sta */ enum class GpioPinState { - LOW, - HIGH + GPIO_LOW, + GPIO_HIGH }; /** diff --git a/include/sta/raspi/gpio_pin.hpp b/include/sta/raspi/gpio_pin.hpp new file mode 100644 index 0000000..6230b1c --- /dev/null +++ b/include/sta/raspi/gpio_pin.hpp @@ -0,0 +1,42 @@ +#ifndef STA_CORE_RASPI_GPIO_PIN_HPP +#define STA_CORE_RASPI_GPIO_PIN_HPP + +// Only enable module on Raspi platform w/ HAL GPIO module enabled +#include +#ifdef STA_PLATFORM_RASPI +# include +# define STA_RASPI_GPIO_ENABLED +#endif // STA_PLATFORM_RASPI + +#if defined(STA_RASPI_GPIO_ENABLED) || defined(DOXYGEN) + +#include +#include + +namespace sta +{ + class RaspiGpioPin : GpioPin + { + public: + enum class GpioMode { + GPIO_OUTPUT, + GPIO_INPUT + }; + + /** + * @param pin Pin index + * @param mode The mode of the GPIO pin. Either INPUT or OUTPUT + */ + RaspiGpioPin(uint8_t pin, GpioMode mode); + + void setState(GpioPinState state) override; + + private: + uint8_t pin_; + GpioMode mode_; + }; +} // namespace sta + +#endif // STA_RASPI_GPIO_ENABLED + +#endif // STA_CORE_RASPI_GPIO_PIN_HPP \ No newline at end of file diff --git a/include/sta/raspi/hal.hpp b/include/sta/raspi/hal.hpp index 900715e..f3e008b 100644 --- a/include/sta/raspi/hal.hpp +++ b/include/sta/raspi/hal.hpp @@ -1,13 +1,8 @@ #ifndef STA_CORE_RASPI_HAL_HPP #define STA_CORE_RASPI_HAL_HPP -namespace sta { - -B -A -A -D -D -} +#include +#include +#include #endif //STA_CORE_RASPI_HAL_HPP diff --git a/include/sta/raspi/spi.hpp b/include/sta/raspi/spi.hpp new file mode 100644 index 0000000..9758b19 --- /dev/null +++ b/include/sta/raspi/spi.hpp @@ -0,0 +1,19 @@ +#ifndef STA_CORE_RASPI_SPI_HPP +#define STA_CORE_RASPI_SPI_HPP + +#include + +namespace sta +{ + class RaspiSPI : SPI + { + + }; + + class RaspiSPIDevice : SPIDevice + { + + }; +} // namespace sta + +#endif // STA_CORE_RASPI_HPP \ No newline at end of file diff --git a/src/raspi/gpio_pin.cpp b/src/raspi/gpio_pin.cpp new file mode 100644 index 0000000..a15fa43 --- /dev/null +++ b/src/raspi/gpio_pin.cpp @@ -0,0 +1,21 @@ +#include +#ifdef STA_RASPI_GPIO_ENABLED + +#include +#include + +namespace sta +{ + RaspiGpioPin::RaspiGpioPin(uint8_t pin, GpioMode mode) : pin_{pin}, mode_{mode} + { + pinMode(pin, mode == GpioMode::GPIO_INPUT ? INPUT : OUTPUT); + } + + void RaspiGpioPin::setState(GpioPinState state) + { + digitalWrite(pin_, state == GpioPinState::GPIO_LOW ? LOW : HIGH); + } +} // namespace sta + + +#endif // STA_ARDUINO_GPIO_ENABLED \ No newline at end of file