RadioHead
|
Base class for RadioHead drivers that use the SPI bus to communicate with its NRF family transport hardware. More...
#include <RHNRFSPIDriver.h>
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) |
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.
RHNRFSPIDriver::RHNRFSPIDriver | ( | uint8_t | slaveSelectPin = SS , |
RHGenericSPI & | spi = hardware_spi |
||
) |
Constructor
[in] | slaveSelectPin | The 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] | spi | Reference to the SPI interface to use. The default is to use a default built-in Hardware interface. |
|
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().
|
virtual |
Initialise the Driver transport hardware and software. Make sure the Driver is properly configured before calling init().
Reimplemented from RHGenericDriver.
References _slaveSelectPin, _spi, and RHGenericSPI::begin().
Referenced by RH_CC110::init(), RH_MRF89::init(), RH_NRF24::init(), and RH_NRF905::init().
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.
[in] | slaveSelectPin | The pin to use |
References _slaveSelectPin.
Referenced by RH_MRF89::spiReadData(), RH_MRF89::spiReadRegister(), RH_MRF89::spiWriteData(), RH_MRF89::spiWriteData(), and RH_MRF89::spiWriteRegister().
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
[in] | reg | Register number of the first register |
[in] | dest | Array to write the register values to. Must be at least len bytes |
[in] | len | Number of bytes to read |
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().
uint8_t RHNRFSPIDriver::spiBurstWrite | ( | uint8_t | reg, |
const uint8_t * | src, | ||
uint8_t | len | ||
) |
Write a number of consecutive registers using burst write mode
[in] | reg | Register number of the first register |
[in] | src | Array of new register values to write. Must be at least len bytes |
[in] | len | Number of bytes to write |
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().
uint8_t RHNRFSPIDriver::spiCommand | ( | uint8_t | command | ) |
Sends a single command to the device
[in] | command | The command code to send to the device. |
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().
uint8_t RHNRFSPIDriver::spiRead | ( | uint8_t | reg | ) |
Reads a single register from the SPI device
[in] | reg | Register number |
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().
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
[in] | interruptNumber | the interrupt number |
References _spi, and RHGenericSPI::usingInterrupt().
Referenced by RH_CC110::init(), and RH_MRF89::init().
uint8_t RHNRFSPIDriver::spiWrite | ( | uint8_t | reg, |
uint8_t | val | ||
) |
Writes a single byte to the SPI device
[in] | reg | Register number |
[in] | val | The value to write |
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().