mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Rework SPI interfaces
This commit is contained in:
parent
4504ee9c3b
commit
a468133c97
@ -23,6 +23,7 @@ namespace sta
|
||||
*/
|
||||
SpiDevice(SpiInterface * intf);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Start transmission with device.
|
||||
*
|
||||
@ -36,12 +37,19 @@ namespace sta
|
||||
*/
|
||||
void endTransmission();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send single byte of data.
|
||||
*
|
||||
* @param value 8-bit value
|
||||
*/
|
||||
void transfer(uint8_t value);
|
||||
/**
|
||||
* @brief Send two bytes of data.
|
||||
*
|
||||
* @param value 16-bit value
|
||||
*/
|
||||
void transfer16(uint16_t data);
|
||||
/**
|
||||
* @brief Send data from buffer.
|
||||
*
|
||||
@ -58,11 +66,13 @@ namespace sta
|
||||
*/
|
||||
void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size);
|
||||
/**
|
||||
* @brief Send two bytes of data.
|
||||
* @brief Read incoming data to buffer.
|
||||
*
|
||||
* @param value 16-bit value
|
||||
* @param buffer Destination buffer
|
||||
* @param size Number of bytes to read
|
||||
*/
|
||||
void transfer16(uint16_t data);
|
||||
void receive(uint8_t * buffer, size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send byte value repeatedly.
|
||||
@ -71,21 +81,6 @@ namespace sta
|
||||
* @param count Number of repetitions
|
||||
*/
|
||||
void fill(uint8_t value, size_t count);
|
||||
/**
|
||||
* @brief Send 32-bit value repeatedly.
|
||||
*
|
||||
* @param value 32-bit value to repeat
|
||||
* @param count Number of repetitions
|
||||
*/
|
||||
void fill32(uint32_t value, size_t count);
|
||||
|
||||
/**
|
||||
* @brief Read incoming data to buffer.
|
||||
*
|
||||
* @param buffer Destination buffer
|
||||
* @param size Number of bytes to read
|
||||
*/
|
||||
void receive(uint8_t * buffer, size_t size);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,7 @@ namespace sta
|
||||
* @param settings SPI interface settings
|
||||
* @param mutex Mutex object for managing shared access. Pass nullptr for no access control
|
||||
*/
|
||||
SpiInterface(const SpiSettings & settings, Mutex * mutex = nullptr);
|
||||
SpiInterface(Mutex * mutex = nullptr);
|
||||
|
||||
|
||||
/**
|
||||
@ -32,6 +32,12 @@ namespace sta
|
||||
* @param value 8-bit value
|
||||
*/
|
||||
virtual void transfer(uint8_t value) = 0;
|
||||
/**
|
||||
* @brief Send two bytes of data.
|
||||
*
|
||||
* @param value 16-bit value
|
||||
*/
|
||||
virtual void transfer16(uint16_t value) = 0;
|
||||
/**
|
||||
* @brief Send data from buffer.
|
||||
*
|
||||
@ -47,29 +53,6 @@ namespace sta
|
||||
* @param size Number of bytes to transfer
|
||||
*/
|
||||
virtual void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) = 0;
|
||||
|
||||
/**
|
||||
* @brief Send two bytes of data.
|
||||
*
|
||||
* @param value 16-bit value
|
||||
*/
|
||||
virtual void transfer16(uint16_t value) = 0;
|
||||
|
||||
/**
|
||||
* @brief Send byte value repeatedly.
|
||||
*
|
||||
* @param value 8-bit value to repeat
|
||||
* @param count Number of repetitions
|
||||
*/
|
||||
virtual void fill(uint8_t value, size_t count) = 0;
|
||||
/**
|
||||
* @brief Send 32-bit value repeatedly.
|
||||
*
|
||||
* @param value 32-bit value to repeat
|
||||
* @param count Number of repetitions
|
||||
*/
|
||||
virtual void fill32(uint32_t value, size_t count) = 0;
|
||||
|
||||
/**
|
||||
* @brief Read incoming data to buffer.
|
||||
*
|
||||
@ -79,12 +62,21 @@ namespace sta
|
||||
virtual void receive(uint8_t * buffer, size_t size) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send byte value repeatedly.
|
||||
*
|
||||
* @param value 8-bit value to repeat
|
||||
* @param count Number of repetitions
|
||||
*/
|
||||
virtual void fill(uint8_t value, size_t count) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get SPI interface settings.
|
||||
*
|
||||
* @return SPI settings
|
||||
*/
|
||||
const SpiSettings & settings() const;
|
||||
virtual const SpiSettings & settings() const = 0;
|
||||
|
||||
|
||||
/**
|
||||
@ -101,7 +93,6 @@ namespace sta
|
||||
virtual void release();
|
||||
|
||||
private:
|
||||
SpiSettings settings_; /** SPI settings */
|
||||
Mutex * mutex_; /**< Mutex object */
|
||||
};
|
||||
} // namespace sta
|
||||
|
@ -28,8 +28,8 @@ namespace sta
|
||||
|
||||
enum class SpiDataSize
|
||||
{
|
||||
BIT_8,
|
||||
BIT_16
|
||||
SIZE_8,
|
||||
SIZE_16
|
||||
};
|
||||
|
||||
enum class SpiBitOrder
|
||||
@ -40,14 +40,14 @@ namespace sta
|
||||
|
||||
enum class SpiBaudRatePrescaler
|
||||
{
|
||||
BRP_2,
|
||||
BRP_4,
|
||||
BRP_8,
|
||||
BRP_16,
|
||||
BRP_32,
|
||||
BRP_64,
|
||||
BRP_128,
|
||||
BRP_256
|
||||
DIV_2,
|
||||
DIV_4,
|
||||
DIV_8,
|
||||
DIV_16,
|
||||
DIV_32,
|
||||
DIV_64,
|
||||
DIV_128,
|
||||
DIV_256
|
||||
};
|
||||
|
||||
|
||||
@ -56,9 +56,7 @@ namespace sta
|
||||
SpiMode mode;
|
||||
SpiDataSize dataSize;
|
||||
SpiBitOrder bitOrder;
|
||||
|
||||
uint32_t clkSpeed;
|
||||
SpiBaudRatePrescaler baudRatePrescaler; /**< Subject to change */
|
||||
};
|
||||
|
||||
|
||||
|
@ -33,6 +33,11 @@ namespace sta
|
||||
intf_->transfer(data);
|
||||
}
|
||||
|
||||
void SpiDevice::transfer16(uint16_t data)
|
||||
{
|
||||
intf_->transfer16(data);
|
||||
}
|
||||
|
||||
void SpiDevice::transfer(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(buffer != nullptr);
|
||||
@ -49,9 +54,11 @@ namespace sta
|
||||
intf_->transfer(txBuffer, rxBuffer, size);
|
||||
}
|
||||
|
||||
void SpiDevice::transfer16(uint16_t data)
|
||||
void SpiDevice::receive(uint8_t * buffer, size_t size)
|
||||
{
|
||||
intf_->transfer16(data);
|
||||
STA_ASSERT(buffer != nullptr);
|
||||
|
||||
intf_->receive(buffer, size);
|
||||
}
|
||||
|
||||
void SpiDevice::fill(uint8_t value, size_t count)
|
||||
@ -61,19 +68,6 @@ namespace sta
|
||||
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);
|
||||
}
|
||||
|
||||
const SpiSettings & SpiDevice::settings() const
|
||||
{
|
||||
|
@ -3,15 +3,10 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
SpiInterface::SpiInterface(const SpiSettings & settings, Mutex * mutex /* = nullptr */)
|
||||
: settings_{settings}, mutex_{mutex}
|
||||
SpiInterface::SpiInterface(Mutex * mutex /* = nullptr */)
|
||||
: mutex_{mutex}
|
||||
{}
|
||||
|
||||
const SpiSettings & SpiInterface::settings() const
|
||||
{
|
||||
return settings_;
|
||||
}
|
||||
|
||||
void SpiInterface::acquire()
|
||||
{
|
||||
if (mutex_ != nullptr)
|
||||
|
Loading…
x
Reference in New Issue
Block a user