Expand description
Opening a LoRa radio on a Linux board.
On a Raspberry Pi or any Linux board a radio module’s SPI bus is a file such as
/dev/spidev0.0, and its reset and BUSY pins are lines on a GPIO chip such as
/dev/gpiochip0. open_sx126x and open_sx127x open them through the Linux
backends of pamoja-hal, reset the chip, and hand it back as a LinuxRadio, so a
gateway, a Python script, or a C# service drives a radio with no bus code of its own.
The kernel’s SPI interface has to be turned on first; on a Raspberry Pi that is
dtparam=spi=on in config.txt.
Only Linux has spidev and the GPIO character device. Everywhere else this module still
builds and LinuxRadio still names a type, but opening a radio returns
OpenError::Unsupported, so a program and the language bindings compile on any
platform and say plainly where no radio can be reached.
§Examples
use pamoja_lora::LinkSettings;
use pamoja_radios::linux::{self, Wiring};
use pamoja_radios::radio::RadioConfig;
use pamoja_radios::sx127x::config::PaOutput;
use pamoja_radios::sx127x::Board;
// An RFM95W on the Raspberry Pi's SPI0, chip select CE0, with its reset pin on GPIO25.
let wiring = Wiring::new("/dev/spidev0.0", "/dev/gpiochip0", 25);
let mut radio = linux::open_sx127x(&wiring, Board::new(PaOutput::PaBoost))?;
radio.configure(RadioConfig::new(868_100_000, LinkSettings::new(9, 125_000), 14))?;
let airtime_us = radio.transmit(b"21.5")?;
println!("sent in {airtime_us} us");Structs§
- Wiring
- Where a radio module is wired on a Linux board.
Enums§
- Open
Error - Why a radio could not be opened.
- Unavailable
- The bus, line, and delay of a platform with no spidev or GPIO character device.
Constants§
- CONSUMER
- The name the kernel shows as holding a radio’s GPIO lines, which
gpioinfoprints. - DEFAULT_
SPI_ HZ - The SPI clock a radio is opened at unless its wiring names another, in hertz.
- SPI_
MODE - The SPI mode both families take: CPOL 0 and CPHA 0, the clock idling low and data sampled on its rising edge, as section 8.2 of the SX126x family’s datasheets gives it and as RadioLib opens both families.
Functions§
- open_
sx126x - Opens an SX1261, SX1262, SX1268, or LLCC68 module and resets it.
- open_
sx127x - Opens an SX1276, SX1277, SX1278, or SX1279 module, such as an RFM95W, and resets it into LoRa mode.
Type Aliases§
- BusError
- Why the SPI device or a GPIO line could not be opened.
- Delay
- The delay a radio’s driver waits with: the process sleeping.
- Line
- A GPIO line a radio’s reset or BUSY pin is on: a line of the GPIO character device.
- Linux
Radio - A radio opened on a Linux board.
- Spi
- The SPI device a radio is opened on: the kernel’s spidev device.
- SpiError
- What the SPI device reports when a transfer fails.