RadioHead
|
Base class for SPI interfaces. More...
#include <RHGenericSPI.h>
Public Types | |
enum | DataMode { DataMode0 = 0 , DataMode1 , DataMode2 , DataMode3 } |
Defines constants for different SPI modes. More... | |
enum | Frequency { Frequency1MHz = 0 , Frequency2MHz , Frequency4MHz , Frequency8MHz , Frequency16MHz } |
Defines constants for different SPI bus frequencies. More... | |
enum | BitOrder { BitOrderMSBFirst = 0 , BitOrderLSBFirst } |
Defines constants for different SPI endianness. More... | |
Public Member Functions | |
RHGenericSPI (Frequency frequency=Frequency1MHz, BitOrder bitOrder=BitOrderMSBFirst, DataMode dataMode=DataMode0) | |
virtual uint8_t | transfer (uint8_t data)=0 |
virtual void | attachInterrupt () |
virtual void | detachInterrupt () |
virtual void | begin ()=0 |
virtual void | end ()=0 |
virtual void | setBitOrder (BitOrder bitOrder) |
virtual void | setDataMode (DataMode dataMode) |
virtual void | setFrequency (Frequency frequency) |
virtual void | beginTransaction () |
virtual void | endTransaction () |
virtual void | usingInterrupt (uint8_t interruptNumber) |
Protected Attributes | |
Frequency | _frequency |
The configure SPI Bus frequency, one of RHGenericSPI::Frequency. | |
BitOrder | _bitOrder |
Bit order, one of RHGenericSPI::BitOrder. | |
DataMode | _dataMode |
SPI bus mode, one of RHGenericSPI::DataMode. | |
Base class for SPI interfaces.
This generic abstract class is used to encapsulate hardware or software SPI interfaces for a variety of platforms. The intention is so that driver classes can be configured to use hardware or software SPI without changing the main code.
You must provide a subclass of this class to driver constructors that require SPI. A concrete subclass that encapsualates the standard Arduino hardware SPI and a bit-banged software implementation is included.
Do not directly use this class: it must be subclassed and the following abstract functions at least must be implemented:
Defines constants for different SPI endianness.
Defines constants for different SPI endianness that can be passed to setBitOrder() We need to define these in a device and platform independent way, because the SPI implementation is different on each platform.
Enumerator | |
---|---|
BitOrderMSBFirst | SPI MSB first. |
BitOrderLSBFirst | SPI LSB first. |
Defines constants for different SPI modes.
Defines constants for different SPI modes that can be passed to the constructor or setMode() We need to define these in a device and platform independent way, because the SPI implementation is different on each platform.
Enumerator | |
---|---|
DataMode0 | SPI Mode 0: CPOL = 0, CPHA = 0. |
DataMode1 | SPI Mode 1: CPOL = 0, CPHA = 1. |
DataMode2 | SPI Mode 2: CPOL = 1, CPHA = 0. |
DataMode3 | SPI Mode 3: CPOL = 1, CPHA = 1. |
Defines constants for different SPI bus frequencies.
Defines constants for different SPI bus frequencies that can be passed to setFrequency(). The frequency you get may not be exactly the one according to the name. We need to define these in a device and platform independent way, because the SPI implementation is different on each platform.
RHGenericSPI::RHGenericSPI | ( | Frequency | frequency = Frequency1MHz , |
BitOrder | bitOrder = BitOrderMSBFirst , |
||
DataMode | dataMode = DataMode0 |
||
) |
Constructor Creates an instance of an abstract SPI interface. Do not use this contructor directly: you must instead use on of the concrete subclasses provided such as RHHardwareSPI or RHSoftwareSPI
[in] | frequency | One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency is mapped to the closest available bus frequency on the platform. |
[in] | bitOrder | Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or RHGenericSPI::BitOrderLSBFirst. |
[in] | dataMode | Selects the SPI bus data mode. One of RHGenericSPI::DataMode |
|
inlinevirtual |
SPI Configuration methods Enable SPI interrupts (if supported) This can be used in an SPI slave to indicate when an SPI message has been received
|
pure virtual |
Initialise the SPI library. Call this after configuring and before using the SPI library
Implemented in RHSoftwareSPI.
Referenced by RHNRFSPIDriver::init(), and RHSPIDriver::init().
|
inlinevirtual |
Signal the start of an SPI transaction that must not be interrupted by other SPI actions In subclasses that support transactions this will ensure that other SPI transactions are blocked until this one is completed by endTransaction(). Base does nothing Might be overridden in subclass
Referenced by RHNRFSPIDriver::beginTransaction(), RHSPIDriver::beginTransaction(), RH_RF24::command(), RH_RF24::frr_read(), RH_RF69::readFifo(), RH_RF24::readNextFragment(), RH_RF69::send(), RH_MRF89::spiWriteData(), and RH_RF24::writeTxFifo().
|
inlinevirtual |
Disable SPI interrupts (if supported) This can be used to diable the SPI interrupt in slaves where that is supported.
|
pure virtual |
Disables the SPI bus (leaving pin modes unchanged). Call this after you have finished using the SPI interface
Implemented in RHSoftwareSPI.
|
inlinevirtual |
Signal the end of an SPI transaction Base does nothing Might be overridden in subclass
Referenced by RH_RF24::command(), RHNRFSPIDriver::endTransaction(), RHSPIDriver::endTransaction(), RH_RF24::frr_read(), RH_RF69::readFifo(), RH_RF24::readNextFragment(), RH_RF69::send(), RH_MRF89::spiWriteData(), and RH_RF24::writeTxFifo().
|
virtual |
Sets the bit order the SPI interface will use Sets the order of the bits shifted out of and into the SPI bus, either LSBFIRST (least-significant bit first) or MSBFIRST (most-significant bit first).
[in] | bitOrder | Bit order to be used: one of RHGenericSPI::BitOrder |
References _bitOrder.
|
virtual |
Sets the SPI data mode: that is, clock polarity and phase. See the Wikipedia article on SPI for details.
[in] | dataMode | The mode to use: one of RHGenericSPI::DataMode |
References _dataMode.
|
virtual |
Sets the SPI clock divider relative to the system clock. On AVR based boards, the dividers available are 2, 4, 8, 16, 32, 64 or 128. The default setting is SPI_CLOCK_DIV4, which sets the SPI clock to one-quarter the frequency of the system clock (4 Mhz for the boards at 16 MHz).
[in] | frequency | The data rate to use: one of RHGenericSPI::Frequency |
References _frequency.
Referenced by RH_MRF89::init(), RH_NRF24::init(), and RH_NRF905::init().
|
pure virtual |
Transfer a single octet to and from the SPI interface
[in] | data | The octet to send |
Implemented in RHSoftwareSPI.
Referenced by RH_RF24::command(), RH_RF24::frr_read(), RH_SX126x::getCommand(), RH_SX126x::getStatus(), RH_SX126x::readBuffer(), RH_RF69::readFifo(), RH_RF24::readNextFragment(), RH_SX126x::readRegisters(), RH_RF69::send(), RH_SX126x::sendCommand(), RH_SX126x::sendCommand(), RHNRFSPIDriver::spiBurstRead(), RHSPIDriver::spiBurstRead(), RHNRFSPIDriver::spiBurstWrite(), RHSPIDriver::spiBurstWrite(), RHNRFSPIDriver::spiCommand(), RHNRFSPIDriver::spiRead(), RHSPIDriver::spiRead(), RHNRFSPIDriver::spiWrite(), RHSPIDriver::spiWrite(), RH_MRF89::spiWriteData(), RH_SX126x::writeBuffer(), RH_SX126x::writeRegisters(), and RH_RF24::writeTxFifo().
|
inlinevirtual |
Specify the interrupt number of the interrupt that will use SPI transactions Tells the SPI support software that SPI transactions will occur with the interrupt handler assocated with interruptNumber Base does nothing Might be overridden in subclass
[in] | interruptNumber | The number of the interrupt |
Referenced by RHNRFSPIDriver::spiUsingInterrupt(), and RHSPIDriver::spiUsingInterrupt().