mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Rework SPI device interface
This commit is contained in:
parent
99eb7e79fd
commit
7c0c05d296
@ -4,6 +4,7 @@
|
||||
#ifndef STA_SPI_DEVICE_HPP
|
||||
#define STA_SPI_DEVICE_HPP
|
||||
|
||||
#include <sta/intf/gpio_pin.hpp>
|
||||
#include <sta/intf/spi_interface.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
@ -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
|
||||
|
@ -1,14 +1,15 @@
|
||||
#include <sta/intf/spi_device.hpp>
|
||||
#include <sta/spi_device.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user