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