RadioHead
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RHSPIDriver Class Reference

Base class for RadioHead drivers that use the SPI bus to communicate with its transport hardware. More...

#include <RHSPIDriver.h>

Inheritance diagram for RHSPIDriver:
RHGenericDriver RH_RF22 RH_RF24 RH_RF69 RH_RF95 RH_SX126x RH_ABZ RH_STM32WLx

Public Member Functions

 RHSPIDriver (uint8_t slaveSelectPin=SS, RHGenericSPI &spi=hardware_spi)
 
bool init ()
 
uint8_t spiRead (uint8_t reg)
 
uint8_t spiWrite (uint8_t reg, uint8_t val)
 
uint8_t spiBurstRead (uint8_t reg, uint8_t *dest, uint8_t len)
 
uint8_t spiBurstWrite (uint8_t reg, const uint8_t *src, uint8_t len)
 
void setSlaveSelectPin (uint8_t slaveSelectPin)
 
void spiUsingInterrupt (uint8_t interruptNumber)
 
- Public Member Functions inherited from RHGenericDriver
 RHGenericDriver ()
 Constructor.
 
virtual ~RHGenericDriver ()
 Generic destructor to prevent warnings when objects are dynamically allocated.
 
virtual bool available ()=0
 
virtual bool recv (uint8_t *buf, uint8_t *len)=0
 
virtual bool send (const uint8_t *data, uint8_t len)=0
 
virtual uint8_t maxMessageLength ()=0
 
virtual void waitAvailable (uint16_t polldelay=0)
 
virtual bool waitPacketSent ()
 
virtual bool waitPacketSent (uint16_t timeout)
 
virtual bool waitAvailableTimeout (uint16_t timeout, uint16_t polldelay=0)
 
virtual bool waitCAD ()
 
void setCADTimeout (unsigned long cad_timeout)
 
virtual bool isChannelActive ()
 
virtual void setThisAddress (uint8_t thisAddress)
 
virtual void setHeaderTo (uint8_t to)
 
virtual void setHeaderFrom (uint8_t from)
 
virtual void setHeaderId (uint8_t id)
 
virtual void setHeaderFlags (uint8_t set, uint8_t clear=RH_FLAGS_APPLICATION_SPECIFIC)
 
virtual void setPromiscuous (bool promiscuous)
 
virtual uint8_t headerTo ()
 
virtual uint8_t headerFrom ()
 
virtual uint8_t headerId ()
 
virtual uint8_t headerFlags ()
 
virtual int16_t lastRssi ()
 
virtual RHMode mode ()
 
virtual void setMode (RHMode mode)
 Sets the operating mode of the transport.
 
virtual bool sleep ()
 
virtual uint16_t rxBad ()
 
virtual uint16_t rxGood ()
 
virtual uint16_t txGood ()
 

Protected Member Functions

virtual void beginTransaction ()
 
virtual void endTransaction ()
 
virtual void selectSlave ()
 
virtual void deselectSlave ()
 

Protected Attributes

RHGenericSPI_spi
 Reference to the RHGenericSPI instance to use to transfer data with the SPI device.
 
uint8_t _slaveSelectPin
 The pin number of the Slave Select pin that is used to select the desired device.
 
- Protected Attributes inherited from RHGenericDriver
volatile RHMode _mode
 The current transport operating mode.
 
uint8_t _thisAddress
 This node id.
 
bool _promiscuous
 Whether the transport is in promiscuous mode.
 
volatile uint8_t _rxHeaderTo
 TO header in the last received mesasge.
 
volatile uint8_t _rxHeaderFrom
 FROM header in the last received mesasge.
 
volatile uint8_t _rxHeaderId
 ID header in the last received mesasge.
 
volatile uint8_t _rxHeaderFlags
 FLAGS header in the last received mesasge.
 
uint8_t _txHeaderTo
 TO header to send in all messages.
 
uint8_t _txHeaderFrom
 FROM header to send in all messages.
 
uint8_t _txHeaderId
 ID header to send in all messages.
 
uint8_t _txHeaderFlags
 FLAGS header to send in all messages.
 
volatile int16_t _lastRssi
 The value of the last received RSSI value, in some transport specific units.
 
volatile uint16_t _rxBad
 Count of the number of bad messages (eg bad checksum etc) received.
 
volatile uint16_t _rxGood
 Count of the number of successfully transmitted messaged.
 
volatile uint16_t _txGood
 Count of the number of bad messages (correct checksum etc) received.
 
volatile bool _cad
 Channel activity detected.
 
unsigned int _cad_timeout
 Channel activity timeout in ms.
 

Additional Inherited Members

- Public Types inherited from RHGenericDriver
enum  RHMode {
  RHModeInitialising = 0 , RHModeSleep , RHModeIdle , RHModeTx ,
  RHModeRx , RHModeCad
}
 Defines different operating modes for the transport hardware. More...
 
- Static Public Member Functions inherited from RHGenericDriver
static void printBuffer (const char *prompt, const uint8_t *buf, uint8_t len)
 

Detailed Description

Base class for RadioHead drivers that use the SPI bus to communicate with its transport hardware.

This class can be subclassed by Drivers that require to use the SPI bus. It can be configured to use either the RHHardwareSPI class (if there is one available on the platform) of the bitbanged RHSoftwareSPI class. The default behaviour is to use a pre-instantiated built-in RHHardwareSPI interface.

SPI bus access is protected by ATOMIC_BLOCK_START and ATOMIC_BLOCK_END, which will ensure interrupts are disabled during access.

The read and write routines implement commonly used SPI conventions: specifically that the MSB of the first byte transmitted indicates that it is a write and the remaining bits indicate the rehgister to access) This can be overriden in subclasses if necessaryor an alternative class, RHNRFSPIDriver can be used to access devices like Nordic NRF series radios, which have different requirements.

Application developers are not expected to instantiate this class directly: it is for the use of Driver developers.

Constructor & Destructor Documentation

◆ RHSPIDriver()

RHSPIDriver::RHSPIDriver ( uint8_t  slaveSelectPin = SS,
RHGenericSPI spi = hardware_spi 
)

Constructor

Parameters
[in]slaveSelectPinThe controler pin to use to select the desired SPI device. This pin will be driven LOW during SPI communications with the SPI device that uis iused by this Driver. If slaveSelectPin is 0xff, then the pin will not be initialised or activated by this class.
[in]spiReference to the SPI interface to use. The default is to use a default built-in Hardware interface.

Member Function Documentation

◆ beginTransaction()

void RHSPIDriver::beginTransaction ( )
protectedvirtual

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(). Selects the slave with selectSlave()

References _spi, and RHGenericSPI::beginTransaction().

Referenced by RH_SX126x::getCommand(), RH_SX126x::getStatus(), RH_SX126x::readBuffer(), RH_SX126x::readRegisters(), RH_SX126x::sendCommand(), RH_SX126x::sendCommand(), spiBurstRead(), spiBurstWrite(), spiRead(), spiWrite(), RH_SX126x::writeBuffer(), and RH_SX126x::writeRegisters().

◆ deselectSlave()

void RHSPIDriver::deselectSlave ( )
protectedvirtual

Reimplemented in RH_ABZ.

◆ endTransaction()

void RHSPIDriver::endTransaction ( )
protectedvirtual

◆ init()

bool RHSPIDriver::init ( )
virtual

Initialise the Driver transport hardware and software. Make sure the Driver is properly configured before calling init().

Returns
true if initialisation succeeded.

Reimplemented from RHGenericDriver.

References _slaveSelectPin, _spi, and RHGenericSPI::begin().

Referenced by RH_RF22::init(), RH_RF24::init(), RH_RF69::init(), RH_RF95::init(), and RH_SX126x::init().

◆ selectSlave()

void RHSPIDriver::selectSlave ( )
protectedvirtual

Reimplemented in RH_ABZ.

◆ setSlaveSelectPin()

void RHSPIDriver::setSlaveSelectPin ( uint8_t  slaveSelectPin)

Set or change the pin to be used for SPI slave select. This can be called at any time to change the pin that will be used for slave select in subsquent SPI operations.

Parameters
[in]slaveSelectPinThe pin to use

References _slaveSelectPin.

◆ spiBurstRead()

uint8_t RH_INTERRUPT_ATTR RHSPIDriver::spiBurstRead ( uint8_t  reg,
uint8_t *  dest,
uint8_t  len 
)

Reads a number of consecutive registers from the SPI device using burst read mode

Parameters
[in]regRegister number of the first register
[in]destArray to write the register values to. Must be at least len bytes
[in]lenNumber of bytes to read
Returns
Some devices return a status byte during the first data transfer. This byte is returned. it may or may not be meaningfule depending on the the type of device being accessed.

References _spi, beginTransaction(), endTransaction(), and RHGenericSPI::transfer().

Referenced by RH_RF22::handleInterrupt(), RH_RF95::handleInterrupt(), RH_RF22::readNextFragment(), and RH_RF22::wutRead().

◆ spiBurstWrite()

uint8_t RH_INTERRUPT_ATTR RHSPIDriver::spiBurstWrite ( uint8_t  reg,
const uint8_t *  src,
uint8_t  len 
)

Write a number of consecutive registers using burst write mode

Parameters
[in]regRegister number of the first register
[in]srcArray of new register values to write. Must be at least len bytes
[in]lenNumber of bytes to write
Returns
Some devices return a status byte during the first data transfer. This byte is returned. it may or may not be meaningfule depending on the the type of device being accessed.

References _spi, beginTransaction(), endTransaction(), and RHGenericSPI::transfer().

Referenced by RH_RF95::send(), RH_RF22::sendNextFragment(), RH_RF69::setEncryptionKey(), RH_RF22::setModemRegisters(), RH_RF69::setModemRegisters(), RH_RF22::setSyncWords(), RH_RF69::setSyncWords(), and RH_RF22::setWutPeriod().

◆ spiRead()

uint8_t RH_INTERRUPT_ATTR RHSPIDriver::spiRead ( uint8_t  reg)

◆ spiUsingInterrupt()

void RHSPIDriver::spiUsingInterrupt ( uint8_t  interruptNumber)

Set the SPI interrupt number If SPI transactions can occur within an interrupt, tell the low level SPI interface which interrupt is used

Parameters
[in]interruptNumberthe interrupt number

References _spi, and RHGenericSPI::usingInterrupt().

Referenced by RH_RF22::init(), RH_RF24::init(), RH_RF69::init(), RH_RF95::setupInterruptHandler(), and RH_SX126x::setupInterruptHandler().

◆ spiWrite()

uint8_t RH_INTERRUPT_ATTR RHSPIDriver::spiWrite ( uint8_t  reg,
uint8_t  val 
)

Writes a single byte to the SPI device

Parameters
[in]regRegister number
[in]valThe value to write
Returns
Some devices return a status byte during the first data transfer. This byte is returned. it may or may not be meaningfule depending on the the type of device being accessed.

References _spi, beginTransaction(), endTransaction(), and RHGenericSPI::transfer().

Referenced by RH_RF22::adcRead(), RH_RF95::enableTCXO(), RH_RF95::handleInterrupt(), RH_RF22::init(), RH_RF69::init(), RH_RF95::init(), RH_RF95::isChannelActive(), RH_RF22::reset(), RH_RF22::resetFifos(), RH_RF22::resetRxFifo(), RH_RF22::resetTxFifo(), RH_RF69::rssiRead(), RH_RF22::send(), RH_RF95::send(), RH_RF95::setCodingRate4(), RH_RF69::setEncryptionKey(), RH_RF22::setFHChannel(), RH_RF22::setFHStepSize(), RH_RF95::setFrequency(), RH_RF22::setFrequency(), RH_RF69::setFrequency(), RH_RF22::setGpioReversed(), RH_RF95::setLowDatarate(), RH_RF69::setModeIdle(), RH_RF95::setModeIdle(), RH_RF22::setModemRegisters(), RH_RF69::setModemRegisters(), RH_RF95::setModemRegisters(), RH_RF69::setModeRx(), RH_RF95::setModeRx(), RH_RF69::setModeTx(), RH_RF95::setModeTx(), RH_RF22::setOpMode(), RH_RF69::setOpMode(), RH_RF95::setPayloadCRC(), RH_RF69::setPreambleLength(), RH_RF95::setPreambleLength(), RH_RF22::setPreambleLength(), RH_RF22::setPromiscuous(), RH_RF95::setSignalBandwidth(), RH_RF95::setSpreadingFactor(), RH_RF69::setSyncWords(), RH_RF22::setThisAddress(), RH_RF69::setTxPower(), RH_RF95::setTxPower(), RH_RF22::setTxPower(), RH_RF69::sleep(), RH_RF95::sleep(), RH_RF22::startTransmit(), RH_RF69::temperatureRead(), and RH_RF22::temperatureRead().


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