RadioLib
Universal wireless communication library for Arduino
Loading...
Searching...
No Matches
SX128x Class Reference

Base class for SX128x series. All derived classes for SX128x (e.g. SX1280 or SX1281) inherit from this base class. This class should not be instantiated directly from Arduino sketch, only from its derived classes. More...

#include <SX128x.h>

Inheritance diagram for SX128x:
PhysicalLayer SX1281 SX1280 SX1282

Public Member Functions

 SX128x (Module *mod)
 Default constructor.
int16_t begin (const ConfigLoRa_t &config)
 Initialization method for LoRa modem.
int16_t beginGFSK (const ConfigFSK_t &config)
 Initialization method for GFSK modem.
int16_t beginBLE (const ConfigBLE_t &config)
 Initialization method for BLE modem.
int16_t beginFLRC (const ConfigFLRC_t &config)
 Initialization method for FLRC modem.
int16_t reset (bool verify=true)
 Reset method. Will reset the chip to the default state using RST pin.
int16_t transmit (const uint8_t *data, size_t len, uint8_t addr=0) override
 Blocking binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer.
int16_t receive (uint8_t *data, size_t len, RadioLibTime_t timeout=0) override
 Blocking binary receive method. Overloads for string-based transmissions are implemented in PhysicalLayer.
int16_t transmitDirect (uint32_t frf=0) override
 Starts direct mode transmission.
int16_t receiveDirect () override
 Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as SX128x series does not support direct mode reception. Will always return RADIOLIB_ERR_UNKNOWN.
int16_t scanChannel () override
 Performs scan for LoRa transmission in the current channel. Detects both preamble and payload.
int16_t scanChannel (const ChannelScanConfig_t &config) override
 Performs scan for LoRa transmission in the current channel. Detects both preamble and payload.
int16_t sleep () override
 Sets the module to sleep mode. To wake the device up, call standby(). Overload for PhysicalLayer compatibility.
int16_t sleep (bool retainConfig)
 Sets the module to sleep mode. To wake the device up, call standby().
int16_t standby () override
 Sets the module to standby mode (overload for PhysicalLayer compatibility). Uses 13 MHz RC oscillator by default, or external oscillator if standbyXOSC is set to true.
int16_t standby (uint8_t mode) override
 Sets the module to standby mode.
int16_t standby (uint8_t mode, bool wakeup)
 Sets the module to standby mode.
void setDio1Action (void(*func)(void))
 Sets interrupt service routine to call when DIO1 activates.
void clearDio1Action ()
 Clears interrupt service routine to call when DIO1 activates.
int16_t finishTransmit () override
 Clean up after transmission is done.
int16_t startReceive () override
 Interrupt-driven receive method with default parameters. Implemented for compatibility with PhysicalLayer.
uint16_t getIrqStatus ()
 Reads the current IRQ status.
int16_t readData (uint8_t *data, size_t len) override
 Reads data received after calling startReceive method. When the packet length is not known in advance, getPacketLength method must be called BEFORE calling readData!
int16_t finishReceive () override
 Clean up after reception is done.
uint32_t getIrqFlags () override
 Read currently active IRQ flags.
int16_t setIrqFlags (uint32_t irq) override
 Set interrupt on DIO1 to be sent on a specific IRQ bit (e.g. RxTimeout, CadDone).
int16_t clearIrqFlags (uint32_t irq) override
 Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone).
int16_t startChannelScan () override
 Interrupt-driven channel activity detection method. DIO1 will be activated when LoRa preamble is detected, or upon timeout.
int16_t startChannelScan (const ChannelScanConfig_t &cfg) override
 Interrupt-driven channel activity detection method. DIO1 will be activated when LoRa preamble is detected, or upon timeout.
int16_t getChannelScanResult () override
 Read the channel scan result.
int16_t setFrequency (uint32_t freq) override
 Sets carrier frequency. Allowed values are in range from 2400 to 2500 MHz.
int16_t setBandwidth (uint32_t bw) override
 Sets LoRa bandwidth. Allowed values are 203125, 406250, 812500 and 1625000 Hz.
int16_t setSpreadingFactor (uint8_t sf) override
 Sets LoRa spreading factor. Allowed values range from 5 to 12.
int16_t setCodingRate (uint8_t cr, bool longInterleaving=false) override
 Sets LoRa coding rate denominator. Allowed values range from 4 to 8. Note that a value of 4 means no coding, is undocumented and not recommended without your own FEC.
int16_t setOutputPower (int8_t power) override
 Sets output power. Allowed values are in range from -18 to 13 dBm.
int16_t setModem (ModemType_t modem) override
 Set modem for the radio to use. Will perform full reset and reconfigure the radio using its default parameters.
int16_t getModem (ModemType_t *modem) override
 Get modem currently in use by the radio.
int16_t getMode (RadioModeType_t *mode) override
 Read the operating mode the radio is in, as the chip reports it. Unlike PhysicalLayer::stagedMode, which is what was last asked of the radio, this reads the hardware, so a caller can tell a radio that has left a mode on its own - a receive that did not survive a frame, or a chip that lost its state - from one that is still in it.
int16_t setPreambleLength (size_t len, size_t detLen=0) override
 Sets preamble length for currently active modem. Allowed values range from 1 to 65535.
int16_t checkDataRate (DataRate_t dr, ModemType_t modem=RADIOLIB_MODEM_NONE) override
 Check the data rate can be configured by this module.
int16_t setBitRate (uint32_t br) override
 Sets FSK or FLRC bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps (for FSK modem) or 260, 325, 520, 650, 1000 and 1300 (for FLRC modem).
int16_t setFrequencyDeviation (uint32_t freqDev) override
 Sets FSK frequency deviation. Allowed values range from 0 to 3200 kHz.
int16_t setDataShaping (uint8_t sh) override
 Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.
int16_t setSyncWord (uint8_t *sync, size_t len) override
 Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long.
int16_t setSyncWord (uint8_t syncWord, uint8_t controlBits=0x44)
 Sets LoRa sync word.
int16_t setCRC (uint8_t len, uint32_t initial=0x1D0F, uint16_t polynomial=0x1021)
 Sets CRC configuration.
int16_t setWhitening (bool enabled)
 Sets whitening parameters, not available for LoRa or FLRC modem.
int16_t setAccessAddress (uint32_t addr)
 Sets BLE access address.
int16_t setHighSensitivityMode (bool enable)
 Enables or disables receiver high sensitivity mode.
int16_t setGainControl (uint8_t gain=0)
 Enables or disables receiver manual gain control.
float getRSSI () override
 Gets RSSI (Received Signal Strength Indicator) of the last received packet.
float getRSSI (bool packet)
 Gets RSSI (Received Signal Strength Indicator).
float getSNR () override
 Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa or ranging modem.
int32_t getFrequencyError ()
 Gets frequency error of the latest received packet.
size_t getPacketLength (bool update=true) override
 Query modem for the packet length of received payload.
size_t getPacketLength (bool update, uint8_t *offset)
 Query modem for the packet length of received payload and Rx buffer offset.
int16_t getLoRaRxHeaderInfo (uint8_t *cr, bool *hasCRC)
 Get LoRa header information from last received packet. Only valid in explicit header mode.
int16_t fixedPacketLengthMode (uint8_t len=RADIOLIB_SX128X_MAX_PACKET_LENGTH)
 Set modem in fixed packet length mode. Available in GFSK and FLRC modes only.
int16_t variablePacketLengthMode (uint8_t maxLen=RADIOLIB_SX128X_MAX_PACKET_LENGTH)
 Set modem in variable packet length mode. Available in GFSK and FLRC modes only.
RadioLibTime_t calculateTimeOnAir (ModemType_t modem, DataRate_t dr, PacketConfig_t pc, size_t len) override
 Calculate the expected time-on-air for a given modem, data rate, packet configuration and payload size.
RadioLibTime_t getTimeOnAir (size_t len) override
 Get expected time-on-air for a given size of payload.
RadioLibTime_t calculateRxTimeout (RadioLibTime_t timeoutUs) override
 Calculate the timeout value for this specific module / series (in number of symbols or units of time).
int16_t implicitHeader (size_t len)
 Set implicit header mode for future reception/transmission.
int16_t explicitHeader ()
 Set explicit header mode for future reception/transmission.
int16_t setEncoding (uint8_t encoding) override
 Sets transmission encoding. Serves only as alias for PhysicalLayer compatibility.
void setRfSwitchPins (uint32_t rxEn, uint32_t txEn)
 Some modules contain external RF switch controlled by pins. This function gives RadioLib control over those pins to automatically switch between various modes: When idle both pins will be LOW, during TX the txEn pin will be HIGH, during RX the rxPin will be HIGH.
void setRfSwitchTable (const uint32_t(&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[])
 Some modules contain external RF switch controlled by pins. This function gives RadioLib control over those pins to automatically switch between various modes.
int16_t setStandbyXOSC (bool enable)
 Set standby mode to be used. XOSC standby uses more power, but allows faster switching between Rx and Tx modes.
uint8_t randomByte () override
 Dummy random method, to ensure PhysicalLayer compatibility.
int16_t invertIQ (bool enable) override
 Enable/disable inversion of the I and Q signals.
int16_t stageMode (RadioModeType_t mode, RadioModeConfig_t *cfg) override
 Stage mode of the radio to be launched later using launchMode.
int16_t launchMode () override
 Launch previously staged mode.
int16_t writeTxBuffer (const uint8_t *data, size_t len) override
 Write a payload into the transmit buffer without staging or starting a transmission. This allows the payload write, which is the slowest part of starting a transmission, to be done while the radio is busy with something else - during a channel scan, for example. The transmission is staged afterwards by calling stageMode with RADIOLIB_RADIO_MODE_TX and RadioModeConfig_t::transmit.data set to NULL, which sets the packet parameters and the IRQ mapping for the payload already in the buffer; transmit.len must still be set to its length. The buffer holds exactly this payload after the call, whether or not one was written before.
int16_t clearTxBuffer () override
 Discard a payload previously written by writeTxBuffer. On radios whose transmit buffer is simply overwritten by the next write there is nothing to discard, and this reports success without touching the radio.
void setDirectAction (void(*func)(void)) override
 Dummy method, to ensure PhysicalLayer compatibility.
void readBit (uint32_t pin) override
 Dummy method, to ensure PhysicalLayer compatibility.
int16_t transmit (const char *str, uint8_t addr=0)
 C-string transmit method.
int16_t startTransmit (const char *str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes.
virtual int16_t startTransmit (const uint8_t *data, size_t len, uint8_t addr=0)
 Interrupt-driven binary transmit method.
virtual int16_t startReceive (uint32_t timeout, RadioLibIrqFlags_t irqFlags=RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask=RADIOLIB_IRQ_RX_DEFAULT_MASK, size_t len=0)
 Interrupt-driven receive method. A DIO pin will be activated when full packet is received. Must be implemented in module class.
Public Member Functions inherited from PhysicalLayer
 PhysicalLayer ()
 Default constructor.
virtual ~PhysicalLayer ()=default
 Default destructor.
int16_t transmit (const char *str, uint8_t addr=0)
 C-string transmit method.
int16_t startTransmit (const char *str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes.
virtual int16_t setLrFhssConfig (uint8_t bw, uint8_t cr, bool narrowGrid, uint8_t hdrCount=3, uint16_t hopSeed=0x13A)
 Sets LR-FHSS configuration. Must be implemented in module class.
int16_t setOutputPowerOffset (int8_t offset)
 Sets offset of the output power. Useful for devices where the radio has an external power amplifier, or of the RF system has a known loss between the radio and the antenna. NOTE: This method must be called BEFORE any calls to radio.begin() or radio.setOutputPower() for the offset to be applied!
int16_t setOutputPowerOffset (const int8_t *lut, size_t steps)
 Sets offset of the output power. Useful for devices where the radio has an external power amplifier, or of the RF system has a known loss between the radio and the antenna. This overload allows to compensate a non-linear PA gain, dependant on the radio power output via a lookup table. NOTE: This method must be called BEFORE any calls to radio.begin() or radio.setOutputPower() for the offset to be applied!
virtual int16_t setDataRate (DataRate_t dr, ModemType_t modem=RADIOLIB_MODEM_NONE)
 Set data rate. Must be implemented in module class if the module supports it.
uint32_t getIrqMapped (RadioLibIrqFlags_t irq)
 Convert from radio-agnostic IRQ flags to radio-specific flags.
int16_t checkIrq (RadioLibIrqType_t irq)
 Check whether a specific IRQ bit is set (e.g. RxTimeout, CadDone).
int16_t setIrq (RadioLibIrqFlags_t irq)
 Set interrupt on specific IRQ bit(s) (e.g. RxTimeout, CadDone). Keep in mind that not all radio modules support all RADIOLIB_IRQ_ flags!
int16_t clearIrq (RadioLibIrqFlags_t irq)
 Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone). Keep in mind that not all radio modules support all RADIOLIB_IRQ_ flags!
int32_t random (int32_t max)
 Get truly random number in range 0 - max.
int32_t random (int32_t min, int32_t max)
 Get truly random number in range min - max.
int16_t startDirect ()
 Configure module parameters for direct modes. Must be called prior to "ham" modes like RTTY or AX.25. Only available in FSK mode.
int16_t setDirectSyncWord (uint32_t syncWord, uint8_t len)
 Set sync word to be used to determine start of packet in direct reception mode.
int16_t available ()
 Get the number of direct mode bytes currently available in buffer.
void dropSync ()
 Forcefully drop synchronization.
uint8_t read (bool drop=true)
 Get data from direct mode buffer.
virtual void setIrqAction (void(*func)(void), bool rising=true)
 Sets interrupt service routine to call when IRQ is activated.
virtual void clearIrqAction ()
 Clears interrupt service routine to call when IRQ is activated.
int16_t calculateRxDutyCycle (size_t txPreLen, size_t rxPreLen, uint16_t minSymbols, DataRate_t *dr, uint32_t *wakePeriod, uint32_t *sleepPeriod)
 Calculates sleep and wake cycles for startReceiveDutyCycle methods so that the receiver should not miss any messages. Useful only for LoRa modems.
int8_t getOutputPowerMin () const
 Get the minimum output power supported by the radio. This includes any previously configured PA offset.
int8_t getOutputPowerMax () const
 Get the maximum output power supported by the radio. This includes any previously configured PA offset.

Additional Inherited Members

Static Public Member Functions inherited from PhysicalLayer
static float getNumSymbols (DataRate_t dr, PacketConfig_t pc, size_t len)
 Convert from bytes to LoRa symbols.
Public Attributes inherited from PhysicalLayer
float freqStep
 Frequency step of the synthesizer in Hz.
size_t maxPacketLength
 Maximum length of packet that can be received by the module.
bool resetOnStartup = true
 Whether to reset the module on startup. Setting to false allows to restore radio operation by calling begin after deep sleep mode on some platforms (like ESP32).

Detailed Description

Base class for SX128x series. All derived classes for SX128x (e.g. SX1280 or SX1281) inherit from this base class. This class should not be instantiated directly from Arduino sketch, only from its derived classes.

Constructor & Destructor Documentation

◆ SX128x()

SX128x::SX128x ( Module * mod)
explicit

Default constructor.

Parameters
modInstance of Module that will be used to communicate with the radio.

Member Function Documentation

◆ begin()

int16_t SX128x::begin ( const ConfigLoRa_t & config)

Initialization method for LoRa modem.

This method initializes the LoRa modem with the specified configuration. Supports designated initializers when using C++14 or above.

Parameters
configInitialization configuration.
Returns
Status Codes

◆ beginBLE()

int16_t SX128x::beginBLE ( const ConfigBLE_t & config)

Initialization method for BLE modem.

This method initializes the BLE modem with the specified configuration. Supports designated initializers when using C++14 or above.

Parameters
configInitialization configuration.
Returns
Status Codes

◆ beginFLRC()

int16_t SX128x::beginFLRC ( const ConfigFLRC_t & config)

Initialization method for FLRC modem.

This method initializes the FLRC modem with the specified configuration. Supports designated initializers when using C++14 or above.

Parameters
configInitialization configuration.
Returns
Status Codes

◆ beginGFSK()

int16_t SX128x::beginGFSK ( const ConfigFSK_t & config)

Initialization method for GFSK modem.

This method initializes the GFSK modem with the specified configuration. Supports designated initializers when using C++14 or above.

Parameters
configInitialization configuration.
Returns
Status Codes

◆ calculateRxTimeout()

RadioLibTime_t SX128x::calculateRxTimeout ( RadioLibTime_t timeoutUs)
overridevirtual

Calculate the timeout value for this specific module / series (in number of symbols or units of time).

Parameters
timeoutUsTimeout in microseconds to listen for
Returns
Timeout value in a unit that is specific for the used module

Reimplemented from PhysicalLayer.

◆ calculateTimeOnAir()

RadioLibTime_t SX128x::calculateTimeOnAir ( ModemType_t modem,
DataRate_t dr,
PacketConfig_t pc,
size_t len )
overridevirtual

Calculate the expected time-on-air for a given modem, data rate, packet configuration and payload size.

Parameters
modemModem type.
drData rate.
pcPacket config.
lenPayload length in bytes.
Returns
Expected time-on-air in microseconds.

Reimplemented from PhysicalLayer.

◆ checkDataRate()

int16_t SX128x::checkDataRate ( DataRate_t dr,
ModemType_t modem = RADIOLIB_MODEM_NONE )
overridevirtual

Check the data rate can be configured by this module.

Parameters
drData rate struct.
modemThe modem corresponding to the requested datarate (FSK, LoRa or LR-FHSS). Defaults to currently active modem if not supplied.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ clearIrqFlags()

int16_t SX128x::clearIrqFlags ( uint32_t irq)
overridevirtual

Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone).

Parameters
irqModule-specific IRQ flags.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ clearTxBuffer()

int16_t SX128x::clearTxBuffer ( )
overridevirtual

Discard a payload previously written by writeTxBuffer. On radios whose transmit buffer is simply overwritten by the next write there is nothing to discard, and this reports success without touching the radio.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ explicitHeader()

int16_t SX128x::explicitHeader ( )

Set explicit header mode for future reception/transmission.

Parameters
lenPayload length in bytes.
Returns
Status Codes

◆ finishReceive()

int16_t SX128x::finishReceive ( )
overridevirtual

Clean up after reception is done.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ finishTransmit()

int16_t SX128x::finishTransmit ( )
overridevirtual

Clean up after transmission is done.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ fixedPacketLengthMode()

int16_t SX128x::fixedPacketLengthMode ( uint8_t len = RADIOLIB_SX128X_MAX_PACKET_LENGTH)

Set modem in fixed packet length mode. Available in GFSK and FLRC modes only.

Parameters
lenPacket length.
Returns
Status Codes

◆ getChannelScanResult()

int16_t SX128x::getChannelScanResult ( )
overridevirtual

Read the channel scan result.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ getFrequencyError()

int32_t SX128x::getFrequencyError ( )

Gets frequency error of the latest received packet.

Returns
Frequency error in Hz.

◆ getIrqFlags()

uint32_t SX128x::getIrqFlags ( )
overridevirtual

Read currently active IRQ flags.

Returns
IRQ flags.

Reimplemented from PhysicalLayer.

◆ getIrqStatus()

uint16_t SX128x::getIrqStatus ( )

Reads the current IRQ status.

Returns
IRQ status bits

◆ getLoRaRxHeaderInfo()

int16_t SX128x::getLoRaRxHeaderInfo ( uint8_t * cr,
bool * hasCRC )

Get LoRa header information from last received packet. Only valid in explicit header mode.

Parameters
crPointer to variable to store the coding rate.
hasCRCPointer to variable to store the CRC status.
Returns
Status Codes

◆ getMode()

int16_t SX128x::getMode ( RadioModeType_t * mode)
overridevirtual

Read the operating mode the radio is in, as the chip reports it. Unlike PhysicalLayer::stagedMode, which is what was last asked of the radio, this reads the hardware, so a caller can tell a radio that has left a mode on its own - a receive that did not survive a frame, or a chip that lost its state - from one that is still in it.

Parameters
modePointer to the variable to save the mode into. A mode the chip reports that has no RadioModeType_t equivalent, frequency synthesis for example, is reported as RADIOLIB_RADIO_MODE_NONE.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ getModem()

int16_t SX128x::getModem ( ModemType_t * modem)
overridevirtual

Get modem currently in use by the radio.

Parameters
modemPointer to a variable to save the retrieved configuration into.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ getPacketLength() [1/2]

size_t SX128x::getPacketLength ( bool update,
uint8_t * offset )

Query modem for the packet length of received payload and Rx buffer offset.

Parameters
updateUpdate received packet length. Will return cached value when set to false.
offsetPointer to variable to store the Rx buffer offset.
Returns
Length of last received packet in bytes.

◆ getPacketLength() [2/2]

size_t SX128x::getPacketLength ( bool update = true)
overridevirtual

Query modem for the packet length of received payload.

Parameters
updateUpdate received packet length. Will return cached value when set to false.
Returns
Length of last received packet in bytes.

Reimplemented from PhysicalLayer.

◆ getRSSI() [1/2]

float SX128x::getRSSI ( )
overridevirtual

Gets RSSI (Received Signal Strength Indicator) of the last received packet.

Returns
RSSI of the last received packet in dBm.

Reimplemented from PhysicalLayer.

◆ getRSSI() [2/2]

float SX128x::getRSSI ( bool packet)

Gets RSSI (Received Signal Strength Indicator).

Parameters
packetWhether to read last packet RSSI, or the current value.
Returns
RSSI value in dBm.

◆ getSNR()

float SX128x::getSNR ( )
overridevirtual

Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa or ranging modem.

Returns
SNR of the last received packet in dB.

Reimplemented from PhysicalLayer.

◆ getTimeOnAir()

RadioLibTime_t SX128x::getTimeOnAir ( size_t len)
overridevirtual

Get expected time-on-air for a given size of payload.

Parameters
lenPayload length in bytes.
Returns
Expected time-on-air in microseconds.

Reimplemented from PhysicalLayer.

◆ implicitHeader()

int16_t SX128x::implicitHeader ( size_t len)

Set implicit header mode for future reception/transmission.

Returns
Status Codes

◆ invertIQ()

int16_t SX128x::invertIQ ( bool enable)
overridevirtual

Enable/disable inversion of the I and Q signals.

Parameters
enableIQ inversion enabled (true) or disabled (false);
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ launchMode()

int16_t SX128x::launchMode ( )
overridevirtual

Launch previously staged mode.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ randomByte()

uint8_t SX128x::randomByte ( )
overridevirtual

Dummy random method, to ensure PhysicalLayer compatibility.

Returns
Always returns 0.

Reimplemented from PhysicalLayer.

◆ readBit()

void SX128x::readBit ( uint32_t pin)
overridevirtual

Dummy method, to ensure PhysicalLayer compatibility.

Parameters
pinIgnored.

Reimplemented from PhysicalLayer.

◆ readData()

int16_t SX128x::readData ( uint8_t * data,
size_t len )
overridevirtual

Reads data received after calling startReceive method. When the packet length is not known in advance, getPacketLength method must be called BEFORE calling readData!

Parameters
dataPointer to array to save the received binary data.
lenNumber of bytes that will be read. When set to 0, the packet length will be retrieved automatically. When more bytes than received are requested, only the number of bytes requested will be returned.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ receive()

int16_t SX128x::receive ( uint8_t * data,
size_t len,
RadioLibTime_t timeout = 0 )
overridevirtual

Blocking binary receive method. Overloads for string-based transmissions are implemented in PhysicalLayer.

Parameters
dataPointer to array to save the received binary data.
lenNumber of bytes that will be received. Must be known in advance for binary transmissions.
timeoutReception timeout in milliseconds. If set to 0, timeout period will be calculated automatically based on the radio configuration.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ receiveDirect()

int16_t SX128x::receiveDirect ( )
overridevirtual

Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as SX128x series does not support direct mode reception. Will always return RADIOLIB_ERR_UNKNOWN.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ reset()

int16_t SX128x::reset ( bool verify = true)

Reset method. Will reset the chip to the default state using RST pin.

Parameters
verifyWhether correct module startup should be verified. When set to true, RadioLib will attempt to verify the module has started correctly by repeatedly issuing setStandby command. Enabled by default.
Returns
Status Codes

◆ scanChannel() [1/2]

int16_t SX128x::scanChannel ( )
overridevirtual

Performs scan for LoRa transmission in the current channel. Detects both preamble and payload.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ scanChannel() [2/2]

int16_t SX128x::scanChannel ( const ChannelScanConfig_t & config)
overridevirtual

Performs scan for LoRa transmission in the current channel. Detects both preamble and payload.

Parameters
configCAD configuration structure.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setAccessAddress()

int16_t SX128x::setAccessAddress ( uint32_t addr)

Sets BLE access address.

Parameters
addrBLE access address.
Returns
Status Codes

◆ setBandwidth()

int16_t SX128x::setBandwidth ( uint32_t bw)
overridevirtual

Sets LoRa bandwidth. Allowed values are 203125, 406250, 812500 and 1625000 Hz.

Parameters
bwLoRa bandwidth to be set in Hz.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setBitRate()

int16_t SX128x::setBitRate ( uint32_t br)
overridevirtual

Sets FSK or FLRC bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps (for FSK modem) or 260, 325, 520, 650, 1000 and 1300 (for FLRC modem).

Parameters
brFSK/FLRC bit rate to be set in bps.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setCodingRate()

int16_t SX128x::setCodingRate ( uint8_t cr,
bool longInterleaving = false )
overridevirtual

Sets LoRa coding rate denominator. Allowed values range from 4 to 8. Note that a value of 4 means no coding, is undocumented and not recommended without your own FEC.

Parameters
crLoRa coding rate denominator to be set.
longInterleavingWhether to enable long interleaving mode. Not available for coding rate 4/7, defaults to false.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setCRC()

int16_t SX128x::setCRC ( uint8_t len,
uint32_t initial = 0x1D0F,
uint16_t polynomial = 0x1021 )

Sets CRC configuration.

Parameters
lenCRC length in bytes, Allowed values are 1, 2 or 3, set to 0 to disable CRC.
initialInitial CRC value. Defaults to 0x1D0F (CCIT CRC), not available for LoRa modem.
polynomialPolynomial for CRC calculation. Defaults to 0x1021 (CCIT CRC), not available for LoRa or BLE modem.
Returns
Status Codes

◆ setDataShaping()

int16_t SX128x::setDataShaping ( uint8_t sh)
overridevirtual

Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.

Parameters
shTime-bandwidth product of Gaussian filter to be set.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setDio1Action()

void SX128x::setDio1Action ( void(* func )(void))

Sets interrupt service routine to call when DIO1 activates.

Parameters
funcISR to call.

◆ setDirectAction()

void SX128x::setDirectAction ( void(* func )(void))
overridevirtual

Dummy method, to ensure PhysicalLayer compatibility.

Parameters
funcIgnored.

Reimplemented from PhysicalLayer.

◆ setEncoding()

int16_t SX128x::setEncoding ( uint8_t encoding)
overridevirtual

Sets transmission encoding. Serves only as alias for PhysicalLayer compatibility.

Parameters
encodingEncoding to be used. Set to 0 for NRZ, and 2 for whitening.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setFrequency()

int16_t SX128x::setFrequency ( uint32_t freq)
overridevirtual

Sets carrier frequency. Allowed values are in range from 2400 to 2500 MHz.

Parameters
freqCarrier frequency to be set in Hz.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setFrequencyDeviation()

int16_t SX128x::setFrequencyDeviation ( uint32_t freqDev)
overridevirtual

Sets FSK frequency deviation. Allowed values range from 0 to 3200 kHz.

Parameters
freqDevFSK frequency deviation to be set in Hz.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setGainControl()

int16_t SX128x::setGainControl ( uint8_t gain = 0)

Enables or disables receiver manual gain control.

Parameters
gainUse 0 for automatic gain, 1 for minimum gain and up to 13 for maximum gain.
Returns
Status Codes

◆ setHighSensitivityMode()

int16_t SX128x::setHighSensitivityMode ( bool enable)

Enables or disables receiver high sensitivity mode.

Parameters
enableTrue to enable and false to disable.
Returns
Status Codes

◆ setIrqFlags()

int16_t SX128x::setIrqFlags ( uint32_t irq)
overridevirtual

Set interrupt on DIO1 to be sent on a specific IRQ bit (e.g. RxTimeout, CadDone).

Parameters
irqModule-specific IRQ flags.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setModem()

int16_t SX128x::setModem ( ModemType_t modem)
overridevirtual

Set modem for the radio to use. Will perform full reset and reconfigure the radio using its default parameters.

Parameters
modemModem type to set - FSK, LoRa or LR-FHSS.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setOutputPower()

int16_t SX128x::setOutputPower ( int8_t power)
overridevirtual

Sets output power. Allowed values are in range from -18 to 13 dBm.

Parameters
powerOutput power to be set in dBm.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setPreambleLength()

int16_t SX128x::setPreambleLength ( size_t len,
size_t detLen = 0 )
overridevirtual

Sets preamble length for currently active modem. Allowed values range from 1 to 65535.

Parameters
lenPreamble length to be set in symbols (LoRa) or bits (FSK/BLE/FLRC).
detLenNot supported by SX128x.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setRfSwitchPins()

void SX128x::setRfSwitchPins ( uint32_t rxEn,
uint32_t txEn )

Some modules contain external RF switch controlled by pins. This function gives RadioLib control over those pins to automatically switch between various modes: When idle both pins will be LOW, during TX the txEn pin will be HIGH, during RX the rxPin will be HIGH.

Radiolib will automatically set the pin mode and value of these pins, so do not control them from the sketch.

When more than two pins or more control over the output values are needed, use the setRfSwitchTable() function.

Parameters
rxEnRX enable pin.
txEnTX enable pin.

◆ setRfSwitchTable()

void SX128x::setRfSwitchTable ( const uint32_t(&) pins[Module::RFSWITCH_MAX_PINS],
const Module::RfSwitchMode_t table[] )

Some modules contain external RF switch controlled by pins. This function gives RadioLib control over those pins to automatically switch between various modes.

Radiolib will automatically set the pin mode and value of these pins, so do not control them from the sketch.

Parameters
pinsA reference to an array of pins to control. This should always be an array of 5 elements. If you need less pins, use RADIOLIB_NC for the unused elements.
tableA reference to an array of pin values to use for each supported mode. Each element is an RfSwitchMode_T struct that lists the mode for which it applies and the values for each of the pins passed in the pins argument respectively.

The pins array will be copied into the Module object, so the original array can be deallocated after this call. However, a reference to the table array will be stored, so that array must remain valid as long RadioLib is being used.

The mode field in each table row should normally use any of the MODE_* constants from the Module::OpMode_t enum. However, some radios support additional modes and will define their own OpMode_t enum.

The length of the table is variable (to support radios that add additional modes), so the table must always be terminated with the special END_OF_MODE_TABLE value.

Normally all modes should be listed in the table, but for some radios, modes can be omitted to indicate they are not supported (e.g. when a radio has a high power and low power TX mode but external circuitry only supports low power). If applicable, this is documented in the radio class itself.

Example

For example, on a board that has an RF switch with an enable pin connected to PA0 and a TX/RX select pin connected to PA1:

// In global scope, define the pin array and mode table
static const uint32_t rfswitch_pins[] =
{PA0, PA1, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC};
static const Module::RfSwitchMode_t rfswitch_table[] = {
{Module::MODE_IDLE, {LOW, LOW}},
{Module::MODE_RX, {HIGH, LOW}},
{Module::MODE_TX, {HIGH, HIGH}},
Module::END_OF_MODE_TABLE,
};
void setup() {
...
// Then somewhere in setup, pass them to radiolib
radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
...
}
@ MODE_TX
Transmission mode.
Definition Module.h:120
@ MODE_IDLE
Idle mode.
Definition Module.h:114
@ MODE_RX
Receive mode.
Definition Module.h:117
Description of RF switch pin states for a single mode. See setRfSwitchTable for details.
Definition Module.h:90

◆ setSpreadingFactor()

int16_t SX128x::setSpreadingFactor ( uint8_t sf)
overridevirtual

Sets LoRa spreading factor. Allowed values range from 5 to 12.

Parameters
sfLoRa spreading factor to be set.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setStandbyXOSC()

int16_t SX128x::setStandbyXOSC ( bool enable)

Set standby mode to be used. XOSC standby uses more power, but allows faster switching between Rx and Tx modes.

Parameters
enableSet to true for XOSC standby, false for RC standby.
Returns
Status Codes

◆ setSyncWord() [1/2]

int16_t SX128x::setSyncWord ( uint8_t * sync,
size_t len )
overridevirtual

Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long.

Parameters
syncSync word to be set.
lenSync word length in bytes.
Returns
Status Codes
Todo
add support for multiple sync words

Reimplemented from PhysicalLayer.

◆ setSyncWord() [2/2]

int16_t SX128x::setSyncWord ( uint8_t syncWord,
uint8_t controlBits = 0x44 )

Sets LoRa sync word.

Parameters
syncWordLoRa sync word to be set.
controlBitsUndocumented control bits, required for compatibility purposes.
Returns
Status Codes

◆ setWhitening()

int16_t SX128x::setWhitening ( bool enabled)

Sets whitening parameters, not available for LoRa or FLRC modem.

Parameters
enabledSet to true to enable whitening.
Returns
Status Codes

◆ sleep() [1/2]

int16_t SX128x::sleep ( )
overridevirtual

Sets the module to sleep mode. To wake the device up, call standby(). Overload for PhysicalLayer compatibility.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ sleep() [2/2]

int16_t SX128x::sleep ( bool retainConfig)

Sets the module to sleep mode. To wake the device up, call standby().

Parameters
retainConfigSet to true to retain configuration and data buffer or to false to discard current configuration and data buffer. Defaults to true.
Returns
Status Codes

◆ stageMode()

int16_t SX128x::stageMode ( RadioModeType_t mode,
RadioModeConfig_t * cfg )
overridevirtual

Stage mode of the radio to be launched later using launchMode.

Parameters
modeRadio mode to prepare.
cfgConfiguration of this mode (mode-dependent).
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ standby() [1/3]

int16_t SX128x::standby ( )
overridevirtual

Sets the module to standby mode (overload for PhysicalLayer compatibility). Uses 13 MHz RC oscillator by default, or external oscillator if standbyXOSC is set to true.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ standby() [2/3]

int16_t SX128x::standby ( uint8_t mode)
overridevirtual

Sets the module to standby mode.

Parameters
modeOscillator to be used in standby mode. Can be set to RADIOLIB_SX128X_STANDBY_RC (13 MHz RC oscillator) or RADIOLIB_SX128X_STANDBY_XOSC (52 MHz external crystal oscillator).
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ standby() [3/3]

int16_t SX128x::standby ( uint8_t mode,
bool wakeup )

Sets the module to standby mode.

Parameters
modeOscillator to be used in standby mode. Can be set to RADIOLIB_SX128X_STANDBY_RC (13 MHz RC oscillator) or RADIOLIB_SX128X_STANDBY_XOSC (52 MHz external crystal oscillator).
wakeupWhether to force the module to wake up. Setting to true will immediately attempt to wake up the module.
Returns
Status Codes

◆ startChannelScan() [1/2]

int16_t SX128x::startChannelScan ( )
overridevirtual

Interrupt-driven channel activity detection method. DIO1 will be activated when LoRa preamble is detected, or upon timeout.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ startChannelScan() [2/2]

int16_t SX128x::startChannelScan ( const ChannelScanConfig_t & cfg)
overridevirtual

Interrupt-driven channel activity detection method. DIO1 will be activated when LoRa preamble is detected, or upon timeout.

Parameters
cfgCAD configuration structure.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ startReceive() [1/2]

int16_t SX128x::startReceive ( )
overridevirtual

Interrupt-driven receive method with default parameters. Implemented for compatibility with PhysicalLayer.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ startReceive() [2/2]

int16_t PhysicalLayer::startReceive ( uint32_t timeout,
RadioLibIrqFlags_t irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS,
RadioLibIrqFlags_t irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK,
size_t len = 0 )
virtual

Interrupt-driven receive method. A DIO pin will be activated when full packet is received. Must be implemented in module class.

Parameters
timeoutRaw timeout value. Some modules use this argument to specify operation mode (single vs. continuous receive).
irqFlagsSets the IRQ flags.
irqMaskSets the mask of IRQ flags that will trigger the radio interrupt pin.
lenPacket length, needed for some modules under special circumstances (e.g. LoRa implicit header mode).
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ startTransmit() [1/2]

int16_t PhysicalLayer::startTransmit ( const char * str,
uint8_t addr = 0 )

Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes.

Parameters
strC-string that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ startTransmit() [2/2]

int16_t PhysicalLayer::startTransmit ( const uint8_t * data,
size_t len,
uint8_t addr = 0 )
virtual

Interrupt-driven binary transmit method.

Parameters
dataBinary data that will be transmitted.
lenLength of binary data to transmit (in bytes).
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ transmit() [1/2]

int16_t PhysicalLayer::transmit ( const char * str,
uint8_t addr = 0 )

C-string transmit method.

Parameters
strC-string that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ transmit() [2/2]

int16_t SX128x::transmit ( const uint8_t * data,
size_t len,
uint8_t addr = 0 )
overridevirtual

Blocking binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer.

Parameters
dataBinary data to be sent.
lenNumber of bytes to send.
addrAddress to send the data to. Unsupported, compatibility only.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ transmitDirect()

int16_t SX128x::transmitDirect ( uint32_t frf = 0)
overridevirtual

Starts direct mode transmission.

Parameters
frfRaw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ variablePacketLengthMode()

int16_t SX128x::variablePacketLengthMode ( uint8_t maxLen = RADIOLIB_SX128X_MAX_PACKET_LENGTH)

Set modem in variable packet length mode. Available in GFSK and FLRC modes only.

Parameters
maxLenMaximum packet length.
Returns
Status Codes

◆ writeTxBuffer()

int16_t SX128x::writeTxBuffer ( const uint8_t * data,
size_t len )
overridevirtual

Write a payload into the transmit buffer without staging or starting a transmission. This allows the payload write, which is the slowest part of starting a transmission, to be done while the radio is busy with something else - during a channel scan, for example. The transmission is staged afterwards by calling stageMode with RADIOLIB_RADIO_MODE_TX and RadioModeConfig_t::transmit.data set to NULL, which sets the packet parameters and the IRQ mapping for the payload already in the buffer; transmit.len must still be set to its length. The buffer holds exactly this payload after the call, whether or not one was written before.

Parameters
dataPayload to write into the transmit buffer.
lenPayload length in bytes.
Returns
Status Codes

Reimplemented from PhysicalLayer.


The documentation for this class was generated from the following files:
  • src/modules/SX128x/SX128x.h
  • src/modules/SX128x/SX128x.cpp