From 7c0c05d296ce3f9a15e17717bb128a9e4a3ec4e1 Mon Sep 17 00:00:00 2001 From: Henrik Stickann <4376396-Mithradir@users.noreply.gitlab.com> Date: Mon, 9 May 2022 21:12:59 +0200 Subject: [PATCH] Rework SPI device interface --- include/sta/{intf => }/spi_device.hpp | 9 ++++++--- src/{intf => }/spi_device.cpp | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) rename include/sta/{intf => }/spi_device.hpp (90%) rename src/{intf => }/spi_device.cpp (80%) diff --git a/include/sta/intf/spi_device.hpp b/include/sta/spi_device.hpp similarity index 90% rename from include/sta/intf/spi_device.hpp rename to include/sta/spi_device.hpp index 768b03b..88770cb 100644 --- a/include/sta/intf/spi_device.hpp +++ b/include/sta/spi_device.hpp @@ -4,6 +4,7 @@ #ifndef STA_SPI_DEVICE_HPP #define STA_SPI_DEVICE_HPP +#include #include #include @@ -20,8 +21,9 @@ namespace sta public: /** * @param intf SPI hardware interface + * @param pin Chip select pin */ - SpiDevice(SpiInterface * intf); + SpiDevice(SpiInterface * intf, GpioPin * csPin); /** @@ -94,14 +96,15 @@ namespace sta /** * @brief Activate device via CS pin. */ - virtual void select() = 0; + void select(); /** * @brief Deactivate device via CS pin. */ - virtual void deselect() = 0; + void deselect(); private: SpiInterface * intf_; /**< SPI hardware interface */ + GpioPin * csPin_; /**< Chip select pin */ }; } // namespace sta diff --git a/src/intf/spi_device.cpp b/src/spi_device.cpp similarity index 80% rename from src/intf/spi_device.cpp rename to src/spi_device.cpp index 748d252..75fdec5 100644 --- a/src/intf/spi_device.cpp +++ b/src/spi_device.cpp @@ -1,14 +1,15 @@ -#include +#include #include namespace sta { - SpiDevice::SpiDevice(SpiInterface * intf) - : intf_{intf} + SpiDevice::SpiDevice(SpiInterface * intf, GpioPin * csPin) + : intf_{intf}, csPin_{csPin} { STA_ASSERT(intf != nullptr); + STA_ASSERT(csPin != nullptr); } void SpiDevice::beginTransmission() @@ -73,4 +74,15 @@ namespace sta { return intf_->settings(); } + + + void SpiDevice::select() + { + csPin_->setState(GpioPinState::LOW); + } + + void SpiDevice::deselect() + { + csPin_->setState(GpioPinState::HIGH); + } } // namespace sta