RadioLib
Universal wireless communication library for Arduino
|
Implements all common low-level methods to control the wireless module. Every module class contains one private instance of this class. More...
#include <Module.h>
Public Member Functions | |
Module (RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio=RADIOLIB_NC) | |
Default constructor. More... | |
Module (const Module &mod) | |
Copy constructor. More... | |
Module & | operator= (const Module &mod) |
Overload for assignment operator. More... | |
void | init () |
Initialize low-level module control. | |
void | term () |
Terminate low-level module control. | |
int16_t | SPIgetRegValue (uint8_t reg, uint8_t msb=7, uint8_t lsb=0) |
SPI read method that automatically masks unused bits. This method is the preferred SPI read mechanism. More... | |
int16_t | SPIsetRegValue (uint8_t reg, uint8_t value, uint8_t msb=7, uint8_t lsb=0, uint8_t checkInterval=2, uint8_t checkMask=0xFF) |
Overwrite-safe SPI write method with verification. This method is the preferred SPI write mechanism. More... | |
void | SPIreadRegisterBurst (uint8_t reg, uint8_t numBytes, uint8_t *inBytes) |
SPI burst read method. More... | |
uint8_t | SPIreadRegister (uint8_t reg) |
SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead. More... | |
void | SPIwriteRegisterBurst (uint8_t reg, uint8_t *data, uint8_t numBytes) |
SPI burst write method. More... | |
void | SPIwriteRegister (uint8_t reg, uint8_t data) |
SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead. More... | |
void | SPItransfer (uint8_t cmd, uint8_t reg, uint8_t *dataOut, uint8_t *dataIn, uint8_t numBytes) |
SPI single transfer method. More... | |
RADIOLIB_PIN_TYPE | getCs () const |
Access method to get the pin number of SPI chip select. More... | |
RADIOLIB_PIN_TYPE | getIrq () const |
Access method to get the pin number of interrupt/GPIO. More... | |
RADIOLIB_PIN_TYPE | getRst () const |
Access method to get the pin number of hardware reset pin. More... | |
RADIOLIB_PIN_TYPE | getGpio () const |
Access method to get the pin number of second interrupt/GPIO. More... | |
void | setRfSwitchPins (RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) |
Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! More... | |
void | setRfSwitchState (RADIOLIB_PIN_STATUS rxPinState, RADIOLIB_PIN_STATUS txPinState) |
Set RF switch state. More... | |
void | pinMode (RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_MODE mode) |
Arduino core pinMode override that checks RADIOLIB_NC as alias for unused pin. More... | |
void | digitalWrite (RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_STATUS value) |
Arduino core digitalWrite override that checks RADIOLIB_NC as alias for unused pin. More... | |
RADIOLIB_PIN_STATUS | digitalRead (RADIOLIB_PIN_TYPE pin) |
Arduino core digitalWrite override that checks RADIOLIB_NC as alias for unused pin. More... | |
void | tone (RADIOLIB_PIN_TYPE pin, uint16_t value, uint32_t duration=0) |
Arduino core tone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone. More... | |
void | noTone (RADIOLIB_PIN_TYPE pin) |
Arduino core noTone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone. More... | |
void | attachInterrupt (RADIOLIB_PIN_TYPE interruptNum, void(*userFunc)(void), RADIOLIB_INTERRUPT_STATUS mode) |
Arduino core attachInterrupt override. More... | |
void | detachInterrupt (RADIOLIB_PIN_TYPE interruptNum) |
Arduino core detachInterrupt override. More... | |
void | yield () |
Arduino core yield override. | |
void | delay (uint32_t ms) |
Arduino core delay override. More... | |
void | delayMicroseconds (uint32_t us) |
Arduino core delayMicroseconds override. More... | |
uint32_t | millis () |
Arduino core millis override. | |
uint32_t | micros () |
Arduino core micros override. | |
uint32_t | pulseIn (RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_STATUS state, uint32_t timeout) |
Arduino core pulseIn override. | |
void | begin () |
Arduino core SPI begin override. | |
void | beginTransaction () |
Arduino core SPI beginTransaction override. | |
uint8_t | transfer (uint8_t b) |
Arduino core SPI transfer override. | |
void | endTransaction () |
Arduino core SPI endTransaction override. | |
void | end () |
Arduino core SPI end override. | |
virtual void | SPIbeginTransaction () |
virtual uint8_t | SPItransfer (uint8_t b) |
virtual void | SPIendTransaction () |
void | regdump (uint8_t start, uint8_t len) |
Function to dump device registers as hex into the debug port. More... | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_PIN_MODE) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_DIGITAL_WRITE) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_DIGITAL_READ) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_TONE) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_NO_TONE) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_ATTACH_INTERRUPT) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_DETACH_INTERRUPT) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_YIELD) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_DELAY) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_DELAY_MICROSECONDS) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_MILLIS) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_MICROS) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_PULSE_IN) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_SPI_BEGIN) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_SPI_TRANSFER) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_SPI_END_TRANSACTION) | |
RADIOLIB_GENERATE_CALLBACK (RADIOLIB_CB_ARGS_SPI_END) | |
Static Public Member Functions | |
static uint8_t | flipBits (uint8_t b) |
Function to reflect bits within a byte. | |
static uint16_t | flipBits16 (uint16_t i) |
Function to reflect bits within an integer. | |
static void | hexdump (uint8_t *data, size_t len) |
Function to dump data as hex into the debug port. More... | |
Public Attributes | |
uint8_t | SPIreadCommand = 0b00000000 |
Basic SPI read command. Defaults to 0x00. | |
uint8_t | SPIwriteCommand = 0b10000000 |
Basic SPI write command. Defaults to 0x80. | |
Implements all common low-level methods to control the wireless module. Every module class contains one private instance of this class.
Module::Module | ( | RADIOLIB_PIN_TYPE | cs, |
RADIOLIB_PIN_TYPE | irq, | ||
RADIOLIB_PIN_TYPE | rst, | ||
RADIOLIB_PIN_TYPE | gpio = RADIOLIB_NC |
||
) |
Default constructor.
cs | Pin to be used as chip select. |
irq | Pin to be used as interrupt/GPIO. |
rst | Pin to be used as hardware reset for the module. |
gpio | Pin to be used as additional interrupt/GPIO. |
void Module::attachInterrupt | ( | RADIOLIB_PIN_TYPE | interruptNum, |
void(*)(void) | userFunc, | ||
RADIOLIB_INTERRUPT_STATUS | mode | ||
) |
Arduino core attachInterrupt override.
interruptNum | Interrupt number. |
userFunc | Interrupt service routine. |
mode | Pin hcange direction. |
void Module::delay | ( | uint32_t | ms | ) |
Arduino core delay override.
ms | Delay length in milliseconds. |
void Module::delayMicroseconds | ( | uint32_t | us | ) |
Arduino core delayMicroseconds override.
us | Delay length in microseconds. |
void Module::detachInterrupt | ( | RADIOLIB_PIN_TYPE | interruptNum | ) |
Arduino core detachInterrupt override.
interruptNum | Interrupt number. |
RADIOLIB_PIN_STATUS Module::digitalRead | ( | RADIOLIB_PIN_TYPE | pin | ) |
Arduino core digitalWrite override that checks RADIOLIB_NC as alias for unused pin.
pin | Pin to read from. |
void Module::digitalWrite | ( | RADIOLIB_PIN_TYPE | pin, |
RADIOLIB_PIN_STATUS | value | ||
) |
Arduino core digitalWrite override that checks RADIOLIB_NC as alias for unused pin.
pin | Pin to write to. |
value | Whether to set the pin high or low. |
|
inline |
Access method to get the pin number of SPI chip select.
|
inline |
Access method to get the pin number of second interrupt/GPIO.
|
inline |
Access method to get the pin number of interrupt/GPIO.
|
inline |
Access method to get the pin number of hardware reset pin.
|
static |
Function to dump data as hex into the debug port.
data | Data to dump. |
len | Number of bytes to dump. |
void Module::noTone | ( | RADIOLIB_PIN_TYPE | pin | ) |
Arduino core noTone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone.
pin | Pin to write to. |
Overload for assignment operator.
frame | rvalue Module. |
void Module::pinMode | ( | RADIOLIB_PIN_TYPE | pin, |
RADIOLIB_PIN_MODE | mode | ||
) |
Arduino core pinMode override that checks RADIOLIB_NC as alias for unused pin.
pin | Pin to change the mode of. |
mode | Which mode to set. |
void Module::regdump | ( | uint8_t | start, |
uint8_t | len | ||
) |
Function to dump device registers as hex into the debug port.
start | First address to dump. |
len | Number of bytes to dump. |
void Module::setRfSwitchPins | ( | RADIOLIB_PIN_TYPE | rxEn, |
RADIOLIB_PIN_TYPE | txEn | ||
) |
Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch!
rxEn | RX enable pin. |
txEn | TX enable pin. |
void Module::setRfSwitchState | ( | RADIOLIB_PIN_STATUS | rxPinState, |
RADIOLIB_PIN_STATUS | txPinState | ||
) |
Set RF switch state.
rxPinState | Pin state to set on Tx enable pin (usually high to transmit). |
txPinState | Pin state to set on Rx enable pin (usually high to receive). |
int16_t Module::SPIgetRegValue | ( | uint8_t | reg, |
uint8_t | msb = 7 , |
||
uint8_t | lsb = 0 |
||
) |
SPI read method that automatically masks unused bits. This method is the preferred SPI read mechanism.
reg | Address of SPI register to read. |
msb | Most significant bit of the register variable. Bits above this one will be masked out. |
lsb | Least significant bit of the register variable. Bits below this one will be masked out. |
uint8_t Module::SPIreadRegister | ( | uint8_t | reg | ) |
SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead.
reg | Address of SPI register to read. |
void Module::SPIreadRegisterBurst | ( | uint8_t | reg, |
uint8_t | numBytes, | ||
uint8_t * | inBytes | ||
) |
SPI burst read method.
reg | Address of SPI register to read. |
numBytes | Number of bytes that will be read. |
inBytes | Pointer to array that will hold the read data. |
int16_t Module::SPIsetRegValue | ( | uint8_t | reg, |
uint8_t | value, | ||
uint8_t | msb = 7 , |
||
uint8_t | lsb = 0 , |
||
uint8_t | checkInterval = 2 , |
||
uint8_t | checkMask = 0xFF |
||
) |
Overwrite-safe SPI write method with verification. This method is the preferred SPI write mechanism.
reg | Address of SPI register to write. |
value | Single byte value that will be written to the SPI register. |
msb | Most significant bit of the register variable. Bits above this one will not be affected by the write operation. |
lsb | Least significant bit of the register variable. Bits below this one will not be affected by the write operation. |
checkInterval | Number of milliseconds between register writing and verification reading. Some registers need up to 10ms to process the change. |
checkMask | Mask of bits to check, only bits set to 1 will be verified. |
void Module::SPItransfer | ( | uint8_t | cmd, |
uint8_t | reg, | ||
uint8_t * | dataOut, | ||
uint8_t * | dataIn, | ||
uint8_t | numBytes | ||
) |
SPI single transfer method.
cmd | SPI access command (read/write/burst/...). |
reg | Address of SPI register to transfer to/from. |
dataOut | Data that will be transfered from master to slave. |
dataIn | Data that was transfered from slave to master. |
numBytes | Number of bytes to transfer. |
void Module::SPIwriteRegister | ( | uint8_t | reg, |
uint8_t | data | ||
) |
SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead.
reg | Address of SPI register to write. |
data | Value that will be written to the register. |
void Module::SPIwriteRegisterBurst | ( | uint8_t | reg, |
uint8_t * | data, | ||
uint8_t | numBytes | ||
) |
SPI burst write method.
reg | Address of SPI register to write. |
data | Pointer to array that holds the data that will be written. |
numBytes | Number of bytes that will be written. |
void Module::tone | ( | RADIOLIB_PIN_TYPE | pin, |
uint16_t | value, | ||
uint32_t | duration = 0 |
||
) |
Arduino core tone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone.
pin | Pin to write to. |
value | Frequency to output. |