mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
63 lines
1.3 KiB
C++
63 lines
1.3 KiB
C++
/**
|
|
* @file
|
|
* @brief SPI bus peripheral device.
|
|
*/
|
|
#ifndef STA_CORE_SPI_DEVICE_HPP
|
|
#define STA_CORE_SPI_DEVICE_HPP
|
|
|
|
#include <sta/bus/device.hpp>
|
|
#include <sta/bus/spi/spi.hpp>
|
|
#include <sta/gpio_pin.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
|
|
namespace sta
|
|
{
|
|
/**
|
|
* @brief Peripheral device connected via SPI.
|
|
*
|
|
* @ingroup sta_core_spi
|
|
*/
|
|
class SPIDevice : public Device
|
|
{
|
|
public:
|
|
/**
|
|
* @param intf %SPI hardware interface
|
|
* @param csPin Chip select pin
|
|
*/
|
|
SPIDevice(SPI * intf, GpioPin * csPin);
|
|
|
|
using Device::transfer;
|
|
|
|
/**
|
|
* @brief Send and receive data simultaneously.
|
|
*
|
|
* @param txBuffer Send buffer
|
|
* @param rxBuffer Receive buffer
|
|
* @param size Number of bytes to transfer
|
|
*/
|
|
bool transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT);
|
|
|
|
/**
|
|
* @brief Get %SPI interface settings.
|
|
*
|
|
* @return SPI settings
|
|
*/
|
|
const SPISettings & settings() const;
|
|
|
|
protected:
|
|
void select() override;
|
|
|
|
void deselect() override;
|
|
|
|
private:
|
|
SPI * intf_; /**< %SPI hardware interface */
|
|
GpioPin * csPin_; /**< Chip select pin */
|
|
};
|
|
} // namespace sta
|
|
|
|
|
|
#endif // STA_CORE_SPI_DEVICE_HPP
|