mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-09-28 21:17:33 +00:00
Add asserts. Fix formating
This commit is contained in:
@@ -2,12 +2,16 @@
|
||||
|
||||
#ifdef STA_HAL_GPIO_ENABLE
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
HalGpioPin::HalGpioPin(GPIO_TypeDef * port, uint16_t pin)
|
||||
: port_{port}, pin_{pin}
|
||||
{}
|
||||
{
|
||||
STA_ASSERT(port != nullptr);
|
||||
}
|
||||
|
||||
void HalGpioPin::setState(GpioPinState state)
|
||||
{
|
||||
|
@@ -2,12 +2,16 @@
|
||||
|
||||
#ifdef STA_HAL_SPI_ENABLE
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
HalSpiInterface::HalSpiInterface(SPI_HandleTypeDef * handle, Mutex * mutex /* = nullptr */)
|
||||
: SpiInterface(mutex), handle_{handle}
|
||||
{}
|
||||
{
|
||||
STA_ASSERT(handle != nullptr);
|
||||
}
|
||||
|
||||
|
||||
void HalSpiInterface::transfer(uint8_t data)
|
||||
@@ -17,11 +21,17 @@ namespace sta
|
||||
|
||||
void HalSpiInterface::transfer(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(buffer != nullptr);
|
||||
|
||||
HAL_SPI_Transmit(handle_, const_cast<uint8_t *>(buffer), size, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
void HalSpiInterface::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(txBuffer != nullptr);
|
||||
STA_ASSERT(rxBuffer != nullptr);
|
||||
STA_ASSERT(size != 0);
|
||||
|
||||
HAL_SPI_TransmitReceive(handle_, const_cast<uint8_t *>(txBuffer), rxBuffer, size, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
@@ -36,6 +46,8 @@ namespace sta
|
||||
|
||||
void HalSpiInterface::fill(uint8_t value, size_t count)
|
||||
{
|
||||
STA_ASSERT(count != 0);
|
||||
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
transfer(value);
|
||||
@@ -45,6 +57,7 @@ namespace sta
|
||||
void HalSpiInterface::fill32(uint32_t value, size_t count)
|
||||
{
|
||||
static_assert(sizeof(uint32_t) == 4);
|
||||
STA_ASSERT(count != 0);
|
||||
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
@@ -53,9 +66,11 @@ namespace sta
|
||||
}
|
||||
|
||||
|
||||
void HalSpiInterface::receive(uint8_t * data, size_t size)
|
||||
void HalSpiInterface::receive(uint8_t * buffer, size_t size)
|
||||
{
|
||||
HAL_SPI_Receive(handle_, data, size, HAL_MAX_DELAY);
|
||||
STA_ASSERT(buffer != nullptr);
|
||||
|
||||
HAL_SPI_Receive(handle_, buffer, size, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -2,16 +2,22 @@
|
||||
|
||||
#ifdef STA_HAL_UART_ENABLE
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
HalUART::HalUART(UART_HandleTypeDef * handle)
|
||||
: handle_{handle}
|
||||
{}
|
||||
{
|
||||
STA_ASSERT(handle != nullptr);
|
||||
}
|
||||
|
||||
|
||||
void HalUART::write(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(buffer != nullptr);
|
||||
|
||||
HAL_UART_Transmit(handle_, const_cast<uint8_t *>(buffer), size, HAL_MAX_DELAY);
|
||||
}
|
||||
} // namespace sta
|
||||
|
@@ -1,11 +1,15 @@
|
||||
#include <sta/spi_device.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
SpiDevice::SpiDevice(SpiInterface * intf)
|
||||
: intf_{intf}
|
||||
{}
|
||||
{
|
||||
STA_ASSERT(intf != nullptr);
|
||||
}
|
||||
|
||||
void SpiDevice::beginTransmission()
|
||||
{
|
||||
@@ -29,13 +33,19 @@ namespace sta
|
||||
intf_->transfer(data);
|
||||
}
|
||||
|
||||
void SpiDevice::transfer(const uint8_t * data, size_t size)
|
||||
void SpiDevice::transfer(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
intf_->transfer(data, 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);
|
||||
}
|
||||
|
||||
@@ -46,16 +56,22 @@ namespace sta
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user