mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-12 01:25:59 +00:00
Rework SPI device interface
This commit is contained in:
parent
99eb7e79fd
commit
7c0c05d296
@ -4,6 +4,7 @@
|
|||||||
#ifndef STA_SPI_DEVICE_HPP
|
#ifndef STA_SPI_DEVICE_HPP
|
||||||
#define STA_SPI_DEVICE_HPP
|
#define STA_SPI_DEVICE_HPP
|
||||||
|
|
||||||
|
#include <sta/intf/gpio_pin.hpp>
|
||||||
#include <sta/intf/spi_interface.hpp>
|
#include <sta/intf/spi_interface.hpp>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@ -20,8 +21,9 @@ namespace sta
|
|||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @param intf SPI hardware interface
|
* @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.
|
* @brief Activate device via CS pin.
|
||||||
*/
|
*/
|
||||||
virtual void select() = 0;
|
void select();
|
||||||
/**
|
/**
|
||||||
* @brief Deactivate device via CS pin.
|
* @brief Deactivate device via CS pin.
|
||||||
*/
|
*/
|
||||||
virtual void deselect() = 0;
|
void deselect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SpiInterface * intf_; /**< SPI hardware interface */
|
SpiInterface * intf_; /**< SPI hardware interface */
|
||||||
|
GpioPin * csPin_; /**< Chip select pin */
|
||||||
};
|
};
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
@ -1,14 +1,15 @@
|
|||||||
#include <sta/intf/spi_device.hpp>
|
#include <sta/spi_device.hpp>
|
||||||
|
|
||||||
#include <sta/assert.hpp>
|
#include <sta/assert.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
SpiDevice::SpiDevice(SpiInterface * intf)
|
SpiDevice::SpiDevice(SpiInterface * intf, GpioPin * csPin)
|
||||||
: intf_{intf}
|
: intf_{intf}, csPin_{csPin}
|
||||||
{
|
{
|
||||||
STA_ASSERT(intf != nullptr);
|
STA_ASSERT(intf != nullptr);
|
||||||
|
STA_ASSERT(csPin != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpiDevice::beginTransmission()
|
void SpiDevice::beginTransmission()
|
||||||
@ -73,4 +74,15 @@ namespace sta
|
|||||||
{
|
{
|
||||||
return intf_->settings();
|
return intf_->settings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SpiDevice::select()
|
||||||
|
{
|
||||||
|
csPin_->setState(GpioPinState::LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpiDevice::deselect()
|
||||||
|
{
|
||||||
|
csPin_->setState(GpioPinState::HIGH);
|
||||||
|
}
|
||||||
} // namespace sta
|
} // namespace sta
|
Loading…
x
Reference in New Issue
Block a user