|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Software SPI master class for driving GPIO expanders via bit-banging. More...
#include <IoExpanderSPI.hpp>
Public Member Functions | |
| IoExpanderSPI () | |
| Construct a new IoExpanderSPI object. | |
| ~IoExpanderSPI ()=default | |
| Destroy the IoExpanderSPI object. | |
| bool | beginSPI (IoExpanderBase &base, int mosi, int miso, int sck, int cs) |
| Initialize the software SPI interface. | |
| void | setBitOrder (uint8_t order) |
| Set the bit order for SPI transfers. | |
| uint8_t | transfer8 (uint8_t val) |
| Transfer 8 bits over SPI. | |
| uint16_t | transfer9 (uint16_t val) |
| Transfer 9 bits over SPI. | |
| uint32_t | transferDataBits (uint32_t val, uint32_t bits) |
| Transfer an arbitrary number of bits over SPI. | |
Software SPI master class for driving GPIO expanders via bit-banging.
This class implements a software SPI master using the pin control functions provided by any IoExpanderBase-derived class. It allows expanders without dedicated hardware SPI to be controlled via general-purpose I/O pins.
Definition at line 44 of file IoExpanderSPI.hpp.
|
inline |
Construct a new IoExpanderSPI object.
Initializes all pin numbers to -1 (unused) and bit order to 0 (MSB first).
Definition at line 52 of file IoExpanderSPI.hpp.
|
default |
Destroy the IoExpanderSPI object.
|
inline |
Initialize the software SPI interface.
Configures the specified pins for SPI operation using the provided expander instance. MOSI and SCK are mandatory and set as outputs; CS is optional (if not -1) and set as output high; MISO is optional and set as input if provided.
| base | Reference to the IoExpanderBase instance used for pin control. |
| mosi | MOSI pin number (must be specified). |
| miso | MISO pin number (set to -1 if not used). |
| sck | SCK pin number (must be specified). |
| cs | Chip select pin number (set to -1 if not used). |
Definition at line 75 of file IoExpanderSPI.hpp.
References IoExpanderBase::digitalWrite(), IoExpanderBase::pinMode(), and SENSORLIB_LOG_E.
|
inline |
Set the bit order for SPI transfers.
| order | 0 for MSB first, 1 for LSB first. Only the least significant bit is used; any other bits are ignored. |
Definition at line 110 of file IoExpanderSPI.hpp.
|
inline |
Transfer 8 bits over SPI.
| val | 8-bit data to send. |
Definition at line 121 of file IoExpanderSPI.hpp.
References transferDataBits().
|
inline |
Transfer 9 bits over SPI.
Useful for devices requiring 9-bit transfers (e.g., certain sensors).
| val | 9-bit data to send (only lower 9 bits are used). |
Definition at line 134 of file IoExpanderSPI.hpp.
References transferDataBits().
|
inline |
Transfer an arbitrary number of bits over SPI.
Performs a full-duplex software SPI transfer of the specified number of bits. The data is shifted out MSB-first or LSB-first according to the current bit order.
| val | Data to send (only the lower 'bits' bits are used). |
| bits | Number of bits to transfer (1-32). |
Definition at line 149 of file IoExpanderSPI.hpp.
References IoExpanderBase::digitalRead(), IoExpanderBase::digitalWrite(), i, and SENSORLIB_LOG_E.
Referenced by transfer8(), and transfer9().