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
andembedded-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
Protocol | Description | Use Cases |
---|---|---|
LoRa | Long Range, low power | IoT sensors, smart agriculture |
BLE | Bluetooth Low Energy | Beacon applications, proximity sensing |
FLRC | Fast Long Range Communication | High data rate applications |
FSK | Frequency Shift Keying | General purpose digital communications |
OOK | On-Off Keying | Simple remote control applications |
ZigBee | IEEE 802.15.4 | Home automation, industrial IoT |
Z-Wave | Z-Wave protocol | Smart home devices |
LR-FHSS | Long Range Frequency Hopping | Robust long-range communication |
WMBus | Wireless M-Bus | Smart metering applications |
WiSUN | Wi-SUN standard | Smart grid, utility networks |
Sigfox | BPSK TX, FSK RX | IoT 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:
§Async Mode (Recommended)
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 commandsstatus
- Status and interrupt handlingsystem
- 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 failedSpi
- SPI communication errorCmdFail
- LR2021 command execution failedCmdErr
- Invalid command sent to LR2021BusyTimeout
- Timeout waiting for busy pinInvalidSize
- 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§
- Busy
Async - Busy
Blocking - CmdBuffer
- Command Buffer:
- Lr2021
- LR2021 Device
Enums§
- Lr2021
Error - 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