mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-09-28 21:17:33 +00:00
Add HAL SPI implementation
This commit is contained in:
70
src/hal/spi.cpp
Normal file
70
src/hal/spi.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <sta/hal/spi.hpp>
|
||||
|
||||
#ifdef STA_HAL_SPI_ENABLE
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
HalSpiInterface::HalSpiInterface(SPI_HandleTypeDef * handle, Mutex * mutex /* = nullptr */)
|
||||
: SpiInterface(mutex), handle_{handle}
|
||||
{}
|
||||
|
||||
|
||||
void HalSpiInterface::transfer(uint8_t data)
|
||||
{
|
||||
HAL_SPI_Transmit(handle_, &data, 1, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
void HalSpiInterface::transfer(const uint8_t * data, size_t size)
|
||||
{
|
||||
HAL_SPI_Transmit(handle_, const_cast<uint8_t *>(data), size, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
|
||||
void HalSpiInterface::transfer16(uint16_t value)
|
||||
{
|
||||
HAL_SPI_Transmit(handle_, reinterpret_cast<uint8_t *>(&value), 2, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
|
||||
void HalSpiInterface::fill(uint8_t value, size_t count)
|
||||
{
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
transfer(value);
|
||||
}
|
||||
}
|
||||
|
||||
void HalSpiInterface::fill32(uint32_t value, size_t count)
|
||||
{
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
HAL_SPI_Transmit(handle_, reinterpret_cast<uint8_t *>(&value), 4, HAL_MAX_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HalSpiInterface::receive(uint8_t * data, size_t size)
|
||||
{
|
||||
HAL_SPI_Receive(handle_, data, size, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
HalSpiDevice::HalSpiDevice(SpiInterface * intf, HalGpioPin csPin)
|
||||
: SpiDevice(intf), csPin_{csPin}
|
||||
{}
|
||||
|
||||
void HalSpiDevice::select()
|
||||
{
|
||||
STA_HAL_GPIO_PIN_WRITE(csPin_, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void HalSpiDevice::deselect()
|
||||
{
|
||||
STA_HAL_GPIO_PIN_WRITE(csPin_, GPIO_PIN_SET);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_HAL_SPI_ENABLE
|
Reference in New Issue
Block a user