mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-12 01:25:59 +00:00
116 lines
2.7 KiB
C++
116 lines
2.7 KiB
C++
/**
|
|
* @file
|
|
* @brief SPI bus peripheral device.
|
|
*/
|
|
#ifndef STA_CORE_SPI_DEVICE_HPP
|
|
#define STA_CORE_SPI_DEVICE_HPP
|
|
|
|
#include <sta/gpio_pin.hpp>
|
|
#include <sta/spi/spi.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
|
|
namespace sta
|
|
{
|
|
/**
|
|
* @brief Peripheral device connected via SPI.
|
|
*
|
|
* @ingroup sta_core_spi
|
|
*/
|
|
class SPIDevice
|
|
{
|
|
public:
|
|
/**
|
|
* @param intf %SPI hardware interface
|
|
* @param csPin Chip select pin
|
|
*/
|
|
SPIDevice(SPI * intf, GpioPin * csPin);
|
|
|
|
|
|
/**
|
|
* @brief Start transmission with device.
|
|
*
|
|
* Must be called before any I/O operations.
|
|
*/
|
|
void beginTransmission();
|
|
/**
|
|
* @brief End transmission with device.
|
|
*
|
|
* Must be called after last I/O operation.
|
|
*/
|
|
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 value);
|
|
/**
|
|
* @brief Send data from buffer.
|
|
*
|
|
* @param buffer Source buffer
|
|
* @param size Number of bytes to transfer
|
|
*/
|
|
void transfer(const uint8_t * buffer, size_t size);
|
|
/**
|
|
* @brief Send and receive data simultaneously.
|
|
*
|
|
* @param txBuffer Send buffer
|
|
* @param rxBuffer Receive buffer
|
|
* @param size Number of bytes to transfer
|
|
*/
|
|
void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size);
|
|
/**
|
|
* @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);
|
|
|
|
|
|
/**
|
|
* @brief Send byte value repeatedly.
|
|
*
|
|
* @param value 8-bit value to repeat
|
|
* @param count Number of repetitions
|
|
*/
|
|
void fill(uint8_t value, size_t count);
|
|
|
|
|
|
/**
|
|
* @brief Get %SPI interface settings.
|
|
*
|
|
* @return SPI settings
|
|
*/
|
|
const SpiSettings & settings() const;
|
|
|
|
|
|
/**
|
|
* @brief Activate device via CS pin.
|
|
*/
|
|
void select();
|
|
/**
|
|
* @brief Deactivate device via CS pin.
|
|
*/
|
|
void deselect();
|
|
|
|
private:
|
|
SPI * intf_; /**< %SPI hardware interface */
|
|
GpioPin * csPin_; /**< Chip select pin */
|
|
};
|
|
} // namespace sta
|
|
|
|
|
|
#endif // STA_CORE_SPI_DEVICE_HPP
|