Crate lr2021

Crate lr2021 

Source
Expand description

§LR2021 Driver

An async, no_std Rust driver for the Semtech LR2021 transceiver.

The LR2021 is a versatile dual band (sub-GHz and 2.4GHz) radio transceiver that supports multiple communication protocols and modulation schemes, making it suitable for a wide range of IoT and wireless applications.

§Features

  • Async/await support - Built on embassy-time for efficient async operations
  • no_std compatible - Suitable for embedded systems with minimal overhead
  • Multiple radio protocols - Support for LoRa, BLE, FLRC, FSK, OOK, ZigBee, Z-Wave, LR-FHSS, WMBus, WiSUN, and Sigfox
  • Flexible busy pin handling - Both blocking polling and async interrupt-based modes
  • HAL abstraction - Uses embedded-hal and embedded-hal-async traits for hardware portability
  • Comprehensive error handling - Detailed error types for robust error management
  • Optimized SPI communication - Efficient command buffering and status management

§Supported Protocols

ProtocolDescriptionUse Cases
LoRaLong Range, low powerIoT sensors, smart agriculture
BLEBluetooth Low EnergyBeacon applications, proximity sensing
FLRCFast Long Range CommunicationHigh data rate applications
FSKFrequency Shift KeyingGeneral purpose digital communications
OOKOn-Off KeyingSimple remote control applications
ZigBeeIEEE 802.15.4Home automation, industrial IoT
Z-WaveZ-Wave protocolSmart home devices
LR-FHSSLong Range Frequency HoppingRobust long-range communication
WMBusWireless M-BusSmart metering applications
WiSUNWi-SUN standardSmart grid, utility networks
SigfoxBPSK TX, FSK RXIoT sensors

§Hardware Requirements

  • SPI interface - For command and data communication with the LR2021
  • Reset pin - GPIO output pin connected to the LR2021’s reset line (active low)
  • Busy pin - GPIO input pin connected to the LR2021’s busy signal
  • NSS pin - SPI chip select pin (GPIO output)

§Driver Modes

The driver supports two modes for handling the busy pin:

Uses the embedded-hal-async Wait trait for efficient interrupt-based waiting:

let radio = Lr2021::new(reset_pin, busy_pin, spi_device, nss_pin);

§Blocking Mode

Polls the busy pin in a loop (less efficient but works with any GPIO):

let radio = Lr2021::new_blocking(reset_pin, busy_pin, spi_device, nss_pin);

§Architecture

The driver is organized into several modules:

  • cmd - Low-level command interface and protocol-specific commands
  • status - Status and interrupt handling
  • system - System-level operations (reset, sleep, etc.)
  • radio - Common radio operations
  • Protocol modules: lora, ble, flrc, fsk, ook, zigbee, zwave, etc.

§Error Handling

The driver uses the Lr2021Error enum for error reporting:

  • Pin - GPIO pin operation failed
  • Spi - SPI communication error
  • CmdFail - LR2021 command execution failed
  • CmdErr - Invalid command sent to LR2021
  • BusyTimeout - Timeout waiting for busy pin
  • InvalidSize - Command size exceeds buffer limits

§Cargo Features

  • defmt - Enable defmt logging support for debugging

§Examples

A few examples are available on the Github repository lr2021-apps. It implements some simple demonstration for a few protocols, using a Nucleo board.

Re-exports§

pub use cmd::RxBw;
pub use cmd::PulseShape;

Modules§

ble
API related to BLE operations
bpsk_tx
cmd
flrc
API related to FLRC operations
fsk
API related to FSK operations
lora
API related to LoRa operations
lrfhss
ook
API related to OOK operations
radio
Radio control and RF management API
raw
API related to Raw IQ Operation
status
system
System control and chip management API
wisun
wmbus
zigbee
zwave
API related to Z-Wave operations

Structs§

BusyAsync
BusyBlocking
CmdBuffer
Command Buffer:
Lr2021
LR2021 Device

Enums§

Lr2021Error
Error using the LR2021

Traits§

BusyPin
Sealed trait to implement two flavor of the driver where the busy pin can be either a simple input or one implemeting the Wait trait