17#ifndef SPICONTROLLER_HPP
18#define SPICONTROLLER_HPP
28using OpenFunc = int (*)(
const char *, int, ...);
43 bool openDevice(
const std::string &device)
override;
45 void writeByte(uint8_t address, uint8_t data)
override;
46 uint8_t
readByte(uint8_t address)
override;
47 void spiTransfer(
const uint8_t *tx, uint8_t *rx,
size_t length)
override;
Definition of the ISPIController interface.
int(*)(const char *, int,...) OpenFunc
int(*)(int, unsigned long,...) IoctlFunc
Interface for the SPI controller.
static constexpr uint32_t DefaultSpeedHz
void configure(uint8_t mode, uint8_t bits, uint32_t speed) override
Configure the SPI device.
IoctlFunc m_ioctlFunc
Function pointer to the ioctl function.
SPIController(IoctlFunc ioctlFunc=::ioctl, OpenFunc openFunc=::open, CloseFunc closeFunc=::close)
Construct a new SPIController::SPIController object.
uint8_t mode
Mode of the SPI communication.
CloseFunc m_closeFunc
Function pointer to the close function.
static constexpr uint8_t DefaultMode
uint8_t readByte(uint8_t address) override
Read a byte from the SPI device.
void closeDevice() override
Close the SPI device.
int spi_fd
File descriptor of the SPI device.
void spiTransfer(const uint8_t *tx, uint8_t *rx, size_t length) override
Transfer data over SPI.
void writeByte(uint8_t address, uint8_t data) override
Write a byte to the SPI device.
bool openDevice(const std::string &device) override
Open the SPI device.
uint8_t bits
Number of bits per word.
static constexpr uint8_t DefaultBitsPerWord
uint32_t speed
Speed of the SPI communication.
OpenFunc m_openFunc
Function pointer to the open function.
~SPIController() override
Destroy the SPIController::SPIController object.