SX1261/2/8 and LLCC68 LoRa radio driver

Driver for the SX1261/2/8 and LLCC68 LoRa radio device. More...

Detailed Description

Driver for the SX1261/2/8 and LLCC68 LoRa radio device.

Modules

 SX1261/2/8 and LLCC68 internal functions
 Internal functions for the SX1261/2/8 and LLCC68.
 

Files

file  sx126x.h
 
file  sx126x_netdev.h
 Netdev driver definitions for SX1261/2/8 and LLCC68 driver.
 
file  sx126x_params.h
 Default configuration.
 

Data Structures

struct  sx126x_params_t
 Device initialization parameters. More...
 
struct  sx126x
 Device descriptor for the driver. More...
 

Macros

#define CONFIG_SX126X_DEFAULT_SYNC_WORD   0x12
 Configure the LoRa sync word. More...
 
#define SX126X_SINGLE
 Whether there's only one variant of this driver at compile time or not. More...
 
#define SX126X_IRQ_MASK_ALL
 Mask of all available interrupts. More...
 

Typedefs

typedef struct sx126x sx126x_t
 

Enumerations

enum  sx126x_rf_mode_t { SX126X_RF_MODE_RX , SX126X_RF_MODE_TX_LPA , SX126X_RF_MODE_TX_HPA }
 RF switch states.
 
enum  sx126x_type_t {
  SX126X_TYPE_SX1261 , SX126X_TYPE_SX1262 , SX126X_TYPE_SX1268 , SX126X_TYPE_LLCC68 ,
  SX126X_TYPE_STM32WL
}
 Used to identify if its a generic SPI module. More...
 
enum  sx126x_dio2_mode_t { SX126X_DIO2_UNUSED , SX126X_DIO2_IRQ , SX126X_DIO2_RF_SWITCH }
 Dio2 pin mode. More...
 
enum  sx126x_dio3_mode_t { SX126X_DIO3_UNUSED , SX126X_DIO3_IRQ , SX126X_DIO3_TCXO }
 Dio3 pin mode. More...
 

Functions

void sx126x_setup (sx126x_t *dev, const sx126x_params_t *params, uint8_t index)
 Setup the radio device. More...
 
int sx126x_init (sx126x_t *dev)
 Initialize the given device. More...
 
static int sx126x_symbol_to_msec (sx126x_t *dev, uint16_t symbols)
 Converts symbol value to time in milliseconds. More...
 
uint32_t sx126x_get_channel (const sx126x_t *dev)
 Gets the channel RF frequency. More...
 
void sx126x_set_channel (sx126x_t *dev, uint32_t freq)
 Sets the channel RF frequency. More...
 
uint8_t sx126x_get_bandwidth (const sx126x_t *dev)
 Gets the LoRa bandwidth. More...
 
void sx126x_set_bandwidth (sx126x_t *dev, uint8_t bandwidth)
 Sets the LoRa bandwidth. More...
 
uint8_t sx126x_get_spreading_factor (const sx126x_t *dev)
 Gets the LoRa spreading factor. More...
 
void sx126x_set_spreading_factor (sx126x_t *dev, uint8_t sf)
 Sets the LoRa spreading factor. More...
 
uint8_t sx126x_get_coding_rate (const sx126x_t *dev)
 Gets the LoRa coding rate. More...
 
void sx126x_set_coding_rate (sx126x_t *dev, uint8_t cr)
 Sets the LoRa coding rate. More...
 
void sx126x_set_tx_power (sx126x_t *dev, int8_t power_dbm, sx126x_ramp_time_t ramp_time)
 Sets the TX power and ramp time. More...
 
uint8_t sx126x_get_lora_payload_length (const sx126x_t *dev)
 Gets the payload length. More...
 
void sx126x_set_lora_payload_length (sx126x_t *dev, uint8_t len)
 Sets the payload length. More...
 
bool sx126x_get_lora_crc (const sx126x_t *dev)
 Checks if CRC verification mode is enabled. More...
 
void sx126x_set_lora_crc (sx126x_t *dev, bool crc)
 Enable/Disable CRC verification mode. More...
 
bool sx126x_get_lora_implicit_header (const sx126x_t *dev)
 Gets the LoRa implicit header mode. More...
 
void sx126x_set_lora_implicit_header (sx126x_t *dev, bool mode)
 Sets LoRa implicit header mode. More...
 
uint16_t sx126x_get_lora_preamble_length (const sx126x_t *dev)
 Gets the LoRa preamble length. More...
 
void sx126x_set_lora_preamble_length (sx126x_t *dev, uint16_t preamble)
 Sets the LoRa preamble length. More...
 
bool sx126x_get_lora_iq_invert (const sx126x_t *dev)
 Checks if the LoRa inverted IQ mode is enabled/disabled. More...
 
void sx126x_set_lora_iq_invert (sx126x_t *dev, bool iq_invert)
 Enable/disable the LoRa IQ inverted mode. More...
 

Macro Definition Documentation

◆ CONFIG_SX126X_DEFAULT_SYNC_WORD

#define CONFIG_SX126X_DEFAULT_SYNC_WORD   0x12

Configure the LoRa sync word.

The sync word for sx126x is 16 bits long. Private networks should use 0x1424. Public networks should use 0x3444. Using the driver API you only configure 2 nibbles Y and Z to form a sync word 0xY4Z4. The default chip value is 0x12 (0x1424).

See https://blog.classycode.com/lora-sync-word-compatibility-between-sx127x-and-sx126x-460324d1787a for more information and a comparison with sx127x.

Definition at line 49 of file sx126x.h.

◆ SX126X_IRQ_MASK_ALL

#define SX126X_IRQ_MASK_ALL
Value:
(SX126X_IRQ_TX_DONE | SX126X_IRQ_RX_DONE | \
SX126X_IRQ_PREAMBLE_DETECTED | SX126X_IRQ_SYNC_WORD_VALID | \
SX126X_IRQ_HEADER_VALID | SX126X_IRQ_HEADER_ERROR | \
SX126X_IRQ_CRC_ERROR | SX126X_IRQ_CAD_DONE | \
SX126X_IRQ_CAD_DETECTED | SX126X_IRQ_TIMEOUT)

Mask of all available interrupts.

Definition at line 118 of file sx126x.h.

◆ SX126X_SINGLE

#define SX126X_SINGLE
Value:
(( \
IS_USED(MODULE_SX1261) \
+ IS_USED(MODULE_SX1262) \
+ IS_USED(MODULE_SX1268) \
+ IS_USED(MODULE_LLCC68) \
+ IS_USED(MODULE_SX126X_STM32WL) \
) == 1)
#define IS_USED(module)
Checks whether a module is being used or not.
Definition: modules.h:70

Whether there's only one variant of this driver at compile time or not.

Definition at line 70 of file sx126x.h.

Typedef Documentation

◆ sx126x_t

typedef struct sx126x sx126x_t
  • Note
    Forward declaration of the SX126x device descriptor

Definition at line 1 of file sx126x.h.

Enumeration Type Documentation

◆ sx126x_dio2_mode_t

Dio2 pin mode.

Enumerator
SX126X_DIO2_UNUSED 

Not used.

SX126X_DIO2_IRQ 

IRQ pin (ToDo)

SX126X_DIO2_RF_SWITCH 

RF switch control pin.

Definition at line 100 of file sx126x.h.

◆ sx126x_dio3_mode_t

Dio3 pin mode.

Enumerator
SX126X_DIO3_UNUSED 

Not used.

SX126X_DIO3_IRQ 

IRQ pin (ToDo)

SX126X_DIO3_TCXO 

TCXO control pin.

Definition at line 109 of file sx126x.h.

◆ sx126x_type_t

Used to identify if its a generic SPI module.

Variant of the SX126x driver.

Definition at line 89 of file sx126x.h.

Function Documentation

◆ sx126x_get_bandwidth()

uint8_t sx126x_get_bandwidth ( const sx126x_t dev)

Gets the LoRa bandwidth.

Parameters
[in]devDevice descriptor of the driver
Returns
the bandwidth

◆ sx126x_get_channel()

uint32_t sx126x_get_channel ( const sx126x_t dev)

Gets the channel RF frequency.

Parameters
[in]devDevice descriptor of the driver
Returns
The channel frequency

◆ sx126x_get_coding_rate()

uint8_t sx126x_get_coding_rate ( const sx126x_t dev)

Gets the LoRa coding rate.

Parameters
[in]devDevice descriptor of the driver
Returns
the current LoRa coding rate

◆ sx126x_get_lora_crc()

bool sx126x_get_lora_crc ( const sx126x_t dev)

Checks if CRC verification mode is enabled.

Parameters
[in]devDevice descriptor of the driver
Returns
the LoRa single mode

◆ sx126x_get_lora_implicit_header()

bool sx126x_get_lora_implicit_header ( const sx126x_t dev)

Gets the LoRa implicit header mode.

Parameters
[in]devDevice descriptor of the driver
Returns
the LoRa implicit mode

◆ sx126x_get_lora_iq_invert()

bool sx126x_get_lora_iq_invert ( const sx126x_t dev)

Checks if the LoRa inverted IQ mode is enabled/disabled.

Parameters
[in]devDevice descriptor of the driver
Returns
the LoRa IQ inverted mode

◆ sx126x_get_lora_payload_length()

uint8_t sx126x_get_lora_payload_length ( const sx126x_t dev)

Gets the payload length.

Parameters
[in]devDevice descriptor of the driver
Returns
the payload length

◆ sx126x_get_lora_preamble_length()

uint16_t sx126x_get_lora_preamble_length ( const sx126x_t dev)

Gets the LoRa preamble length.

Parameters
[in]devDevice descriptor of the driver
Returns
the preamble length

◆ sx126x_get_spreading_factor()

uint8_t sx126x_get_spreading_factor ( const sx126x_t dev)

Gets the LoRa spreading factor.

Parameters
[in]devDevice descriptor of the driver
Returns
the spreading factor

◆ sx126x_init()

int sx126x_init ( sx126x_t dev)

Initialize the given device.

Parameters
[in,out]devDevice descriptor of the driver
Returns
0 on success

◆ sx126x_set_bandwidth()

void sx126x_set_bandwidth ( sx126x_t dev,
uint8_t  bandwidth 
)

Sets the LoRa bandwidth.

Parameters
[in]devDevice descriptor of the driver
[in]bandwidthThe new bandwidth

◆ sx126x_set_channel()

void sx126x_set_channel ( sx126x_t dev,
uint32_t  freq 
)

Sets the channel RF frequency.

Parameters
[in]devDevice descriptor of the driver
[in]freqChannel RF frequency

◆ sx126x_set_coding_rate()

void sx126x_set_coding_rate ( sx126x_t dev,
uint8_t  cr 
)

Sets the LoRa coding rate.

Parameters
[in]devDevice descriptor of the driver
[in]crThe LoRa coding rate

◆ sx126x_set_lora_crc()

void sx126x_set_lora_crc ( sx126x_t dev,
bool  crc 
)

Enable/Disable CRC verification mode.

Parameters
[in]devDevice descriptor of the driver
[in]crcThe CRC check mode

◆ sx126x_set_lora_implicit_header()

void sx126x_set_lora_implicit_header ( sx126x_t dev,
bool  mode 
)

Sets LoRa implicit header mode.

Parameters
[in]devDevice descriptor of the driver
[in]modeThe header mode

◆ sx126x_set_lora_iq_invert()

void sx126x_set_lora_iq_invert ( sx126x_t dev,
bool  iq_invert 
)

Enable/disable the LoRa IQ inverted mode.

Parameters
[in]devDevice descriptor of the driver
[in]iq_invertThe LoRa IQ inverted mode

◆ sx126x_set_lora_payload_length()

void sx126x_set_lora_payload_length ( sx126x_t dev,
uint8_t  len 
)

Sets the payload length.

Parameters
[in]devDevice descriptor of the driver
[in]lenThe payload len

◆ sx126x_set_lora_preamble_length()

void sx126x_set_lora_preamble_length ( sx126x_t dev,
uint16_t  preamble 
)

Sets the LoRa preamble length.

Parameters
[in]devDevice descriptor of the driver
[in]preambleThe LoRa preamble length

◆ sx126x_set_spreading_factor()

void sx126x_set_spreading_factor ( sx126x_t dev,
uint8_t  sf 
)

Sets the LoRa spreading factor.

Parameters
[in]devDevice descriptor of the driver
[in]sfThe spreading factor

◆ sx126x_set_tx_power()

void sx126x_set_tx_power ( sx126x_t dev,
int8_t  power_dbm,
sx126x_ramp_time_t  ramp_time 
)

Sets the TX power and ramp time.

The actual transmission power may be different depending on device capabilities and board design.

Parameters
[in]devDevice descriptor of the driver
[in]power_dbmThe TX power in dBm
[in]ramp_timeThe ramp time

◆ sx126x_setup()

void sx126x_setup ( sx126x_t dev,
const sx126x_params_t params,
uint8_t  index 
)

Setup the radio device.

Parameters
[in]devDevice descriptor
[in]paramsParameters for device initialization
[in]indexIndex of params in a global parameter struct array. If initialized manually, pass a unique identifier instead.

◆ sx126x_symbol_to_msec()

static int sx126x_symbol_to_msec ( sx126x_t dev,
uint16_t  symbols 
)
inlinestatic

Converts symbol value to time in milliseconds.

Parameters
[in]devDevice descriptor of the driver
[in]symbolsSymbols
Returns
Time for symbol(s) in milliseconds

Definition at line 195 of file sx126x.h.