Add SPI device interface

This commit is contained in:
Henrik Stickann
2022-04-09 21:22:14 +02:00
parent 4140a07307
commit 3abe36ec81
2 changed files with 150 additions and 0 deletions

56
src/spi_device.cpp Normal file
View File

@@ -0,0 +1,56 @@
#include <sta/spi_device.hpp>
namespace sta
{
SpiDevice::SpiDevice(SpiInterface * intf)
: intf_{intf}
{}
void SpiDevice::beginTransmission()
{
// Acquire SPI access and activate device
intf_->acquire();
select();
}
void SpiDevice::endTransmission()
{
// Deactivate device and release SPI access
deselect();
intf_->release();
}
// Forward I/O operations to SPI interface
void SpiDevice::transfer(uint8_t data)
{
intf_->transfer(data);
}
void SpiDevice::transfer(const uint8_t * data, size_t size)
{
intf_->transfer(data, size);
}
void SpiDevice::transfer16(uint16_t data)
{
intf_->transfer16(data);
}
void SpiDevice::fill(uint8_t value, size_t count)
{
intf_->fill(value, count);
}
void SpiDevice::fill32(uint32_t value, size_t count)
{
intf_->fill32(value, count);
}
void SpiDevice::receive(uint8_t * buffer, size_t size)
{
intf_->receive(buffer, size);
}
} // namespace sta