mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-12-16 16:48:04 +00:00
Rename SPI classes
This commit is contained in:
107
include/sta/spi/spi.hpp
Normal file
107
include/sta/spi/spi.hpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief SPI bus software interface.
|
||||
*/
|
||||
#ifndef STA_CORE_SPI_SPI_HPP
|
||||
#define STA_CORE_SPI_SPI_HPP
|
||||
|
||||
#include <sta/mutex.hpp>
|
||||
#include <sta/spi/settings.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Interface class for %SPI hardware.
|
||||
*
|
||||
* Represents a single %SPI bus that can be shared by multiple devices.
|
||||
*
|
||||
* @ingroup sta_core_spi
|
||||
*/
|
||||
class SPI
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param settings %SPI bus settings
|
||||
* @param mutex Mutex object for managing shared access. Pass nullptr for no access control
|
||||
*/
|
||||
SPI(const SPISettings & settings, Mutex * mutex = nullptr);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send single byte of data.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @param buffer Source buffer
|
||||
* @param size Number of bytes to transfer
|
||||
*/
|
||||
virtual void transfer(const uint8_t * buffer, size_t size) = 0;
|
||||
/**
|
||||
* @brief Send and receive data simultaneously.
|
||||
*
|
||||
* @param txBuffer Send buffer
|
||||
* @param rxBuffer Receive buffer
|
||||
* @param size Number of bytes to transfer
|
||||
*/
|
||||
virtual void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) = 0;
|
||||
/**
|
||||
* @brief Read incoming data to buffer.
|
||||
*
|
||||
* @param buffer Destination buffer
|
||||
* @param size Number of bytes to read
|
||||
*/
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Acquire usage rights to use the interface.
|
||||
*
|
||||
* Must be called before any I/O operations are executed.
|
||||
*/
|
||||
virtual void acquire();
|
||||
/**
|
||||
* @brief Release usage rights for interface.
|
||||
*
|
||||
* Must be called after last I/O operation.
|
||||
*/
|
||||
virtual void release();
|
||||
|
||||
private:
|
||||
SPISettings settings_; /**< %SPI settings */
|
||||
Mutex * mutex_; /**< Mutex object */
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_CORE_SPI_SPI_HPP
|
||||
Reference in New Issue
Block a user