RadioHead
Public Types | Public Member Functions | Protected Attributes | List of all members
RHGenericSPI Class Referenceabstract

Base class for SPI interfaces. More...

#include <RHGenericSPI.h>

Inheritance diagram for RHGenericSPI:
RHHardwareSPI RHSoftwareSPI

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.
 

Detailed Description

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:

Member Enumeration Documentation

◆ BitOrder

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.

◆ DataMode

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.

◆ Frequency

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.

Enumerator
Frequency1MHz 

SPI bus frequency close to 1MHz.

Frequency2MHz 

SPI bus frequency close to 2MHz.

Frequency4MHz 

SPI bus frequency close to 4MHz.

Frequency8MHz 

SPI bus frequency close to 8MHz.

Frequency16MHz 

SPI bus frequency close to 16MHz.

Constructor & Destructor Documentation

◆ RHGenericSPI()

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

Parameters
[in]frequencyOne of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency is mapped to the closest available bus frequency on the platform.
[in]bitOrderSelect the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or RHGenericSPI::BitOrderLSBFirst.
[in]dataModeSelects the SPI bus data mode. One of RHGenericSPI::DataMode

Member Function Documentation

◆ attachInterrupt()

virtual void RHGenericSPI::attachInterrupt ( )
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

◆ begin()

virtual void RHGenericSPI::begin ( )
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().

◆ beginTransaction()

virtual void RHGenericSPI::beginTransaction ( )
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().

◆ detachInterrupt()

virtual void RHGenericSPI::detachInterrupt ( )
inlinevirtual

Disable SPI interrupts (if supported) This can be used to diable the SPI interrupt in slaves where that is supported.

◆ end()

virtual void RHGenericSPI::end ( )
pure virtual

Disables the SPI bus (leaving pin modes unchanged). Call this after you have finished using the SPI interface

Implemented in RHSoftwareSPI.

◆ endTransaction()

virtual void RHGenericSPI::endTransaction ( )
inlinevirtual

◆ setBitOrder()

void RHGenericSPI::setBitOrder ( BitOrder  bitOrder)
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).

Parameters
[in]bitOrderBit order to be used: one of RHGenericSPI::BitOrder

References _bitOrder.

◆ setDataMode()

void RHGenericSPI::setDataMode ( DataMode  dataMode)
virtual

Sets the SPI data mode: that is, clock polarity and phase. See the Wikipedia article on SPI for details.

Parameters
[in]dataModeThe mode to use: one of RHGenericSPI::DataMode

References _dataMode.

◆ setFrequency()

void RHGenericSPI::setFrequency ( Frequency  frequency)
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).

Parameters
[in]frequencyThe data rate to use: one of RHGenericSPI::Frequency

References _frequency.

Referenced by RH_MRF89::init(), RH_NRF24::init(), and RH_NRF905::init().

◆ transfer()

virtual uint8_t RHGenericSPI::transfer ( uint8_t  data)
pure virtual

◆ usingInterrupt()

virtual void RHGenericSPI::usingInterrupt ( uint8_t  interruptNumber)
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

Parameters
[in]interruptNumberThe number of the interrupt

Referenced by RHNRFSPIDriver::spiUsingInterrupt(), and RHSPIDriver::spiUsingInterrupt().


The documentation for this class was generated from the following files: