mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-02 09:21:54 +00:00
78 lines
1.3 KiB
C++
78 lines
1.3 KiB
C++
#include <sta/spi_device.hpp>
|
|
|
|
#include <sta/assert.hpp>
|
|
|
|
|
|
namespace sta
|
|
{
|
|
SpiDevice::SpiDevice(SpiInterface * intf)
|
|
: intf_{intf}
|
|
{
|
|
STA_ASSERT(intf != nullptr);
|
|
}
|
|
|
|
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 * buffer, size_t size)
|
|
{
|
|
STA_ASSERT(buffer != nullptr);
|
|
|
|
intf_->transfer(buffer, size);
|
|
}
|
|
|
|
void SpiDevice::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size)
|
|
{
|
|
STA_ASSERT(txBuffer != nullptr);
|
|
STA_ASSERT(rxBuffer != nullptr);
|
|
STA_ASSERT(size != 0);
|
|
|
|
intf_->transfer(txBuffer, rxBuffer, size);
|
|
}
|
|
|
|
void SpiDevice::transfer16(uint16_t data)
|
|
{
|
|
intf_->transfer16(data);
|
|
}
|
|
|
|
void SpiDevice::fill(uint8_t value, size_t count)
|
|
{
|
|
STA_ASSERT(count != 0);
|
|
|
|
intf_->fill(value, count);
|
|
}
|
|
|
|
void SpiDevice::fill32(uint32_t value, size_t count)
|
|
{
|
|
STA_ASSERT(count != 0);
|
|
|
|
intf_->fill32(value, count);
|
|
}
|
|
|
|
void SpiDevice::receive(uint8_t * buffer, size_t size)
|
|
{
|
|
STA_ASSERT(buffer != nullptr);
|
|
|
|
intf_->receive(buffer, size);
|
|
}
|
|
} // namespace sta
|