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

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

#include <RHNRFSPIDriver.h>

Inheritance diagram for RHNRFSPIDriver:
RHGenericDriver RH_CC110 RH_MRF89 RH_NRF24 RH_NRF905

Public Member Functions

 RHNRFSPIDriver (uint8_t slaveSelectPin=SS, RHGenericSPI &spi=hardware_spi)
 
bool init ()
 
uint8_t spiCommand (uint8_t command)
 
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 ()
 Signal the end of an SPI transaction.
 

Protected Attributes

RHGenericSPI_spi
 Reference to the RHGenericSPI instance to use to trasnfer data with teh 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 NRF family 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 dfault 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 use SPI conventions as used by Nordic NRF radios and otehr devices, but these can be overriden in subclasses if necessary.

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

Constructor & Destructor Documentation

◆ RHNRFSPIDriver()

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

Constructor

Parameters
[in]slaveSelectPinThe controller 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.
[in]spiReference to the SPI interface to use. The default is to use a default built-in Hardware interface.

Member Function Documentation

◆ beginTransaction()

void RHNRFSPIDriver::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().

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

Referenced by spiBurstRead(), spiBurstWrite(), spiCommand(), spiRead(), and spiWrite().

◆ init()

bool RHNRFSPIDriver::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_CC110::init(), RH_MRF89::init(), RH_NRF24::init(), and RH_NRF905::init().

◆ setSlaveSelectPin()

void RHNRFSPIDriver::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.

Referenced by RH_MRF89::spiReadData(), RH_MRF89::spiReadRegister(), RH_MRF89::spiWriteData(), RH_MRF89::spiWriteData(), and RH_MRF89::spiWriteRegister().

◆ spiBurstRead()

uint8_t RHNRFSPIDriver::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_NRF24::available(), RH_NRF905::available(), RH_CC110::handleInterrupt(), RH_NRF24::spiBurstReadRegister(), and RH_NRF905::spiBurstReadRegister().

◆ spiBurstWrite()

uint8_t RHNRFSPIDriver::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_NRF24::send(), RH_NRF905::send(), RH_NRF905::setNetworkAddress(), RH_CC110::spiBurstWriteRegister(), RH_NRF24::spiBurstWriteRegister(), and RH_NRF905::spiBurstWriteRegister().

◆ spiCommand()

uint8_t RHNRFSPIDriver::spiCommand ( uint8_t  command)

Sends a single command to the device

Parameters
[in]commandThe command code to send to the device.
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_NRF24::flushRx(), RH_NRF24::flushTx(), RH_CC110::handleInterrupt(), RH_CC110::handleOverFlows(), RH_CC110::init(), RH_CC110::setModeIdle(), RH_CC110::setModeRx(), RH_CC110::setModeTx(), RH_CC110::sleep(), RH_MRF89::spiReadData(), RH_MRF89::spiWriteData(), RH_CC110::statusRead(), RH_NRF24::statusRead(), and RH_NRF905::statusRead().

◆ spiRead()

uint8_t RHNRFSPIDriver::spiRead ( uint8_t  reg)

Reads a single register from the SPI device

Parameters
[in]regRegister number
Returns
The value of the register

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

Referenced by RH_NRF24::available(), RH_CC110::spiBurstReadRegister(), RH_CC110::spiReadRegister(), RH_MRF89::spiReadRegister(), RH_NRF24::spiReadRegister(), and RH_NRF905::spiReadRegister().

◆ spiUsingInterrupt()

void RHNRFSPIDriver::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_CC110::init(), and RH_MRF89::init().

◆ spiWrite()

uint8_t RHNRFSPIDriver::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_NRF24::init(), RH_CC110::spiWriteRegister(), RH_MRF89::spiWriteRegister(), RH_NRF24::spiWriteRegister(), and RH_NRF905::spiWriteRegister().


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