No description
Find a file
faicel 0995edfcf4
All checks were successful
Create prerelease tag on dev / tag_prerelease (push) Successful in 7s
Create Forgejo release on tag / release_on_tag (push) Successful in 1m5s
Merge pull request 'fix lint' (#8) from update_package into dev
Reviewed-on: #8
2026-07-02 10:39:47 +00:00
.cargo fix enforce-branch 2026-04-05 15:01:21 +02:00
.forgejo/workflows Refactor CI workflows to simplify Cargo registry authentication by removing redundant configuration steps in enforce-branch-flow.yml and publish-on-tag.yml, while maintaining the use of "Bearer" tokens for enhanced security. 2026-04-06 07:03:06 +02:00
scripts init 2026-03-08 13:02:41 +01:00
src fix lint 2026-07-02 12:28:58 +02:00
.gitignore Update version to 0.1.1, add CHANGELOG.md to .gitignore, and change read_version method to public in sx1278 module. 2026-03-11 09:41:53 +01:00
Cargo.lock add seleep mode 2026-07-02 12:12:17 +02:00
Cargo.toml add seleep mode 2026-07-02 12:12:17 +02:00
CHANGELOG.md add seleep mode 2026-07-02 12:12:17 +02:00
LICENSE init 2026-03-08 13:02:41 +01:00
README.md add seleep mode 2026-07-02 12:12:17 +02:00

lora

no_std Rust driver for LoRa radio modules based on the SX1278 chip. It provides SPI-based control for transmission and reception with configurable operating modes, optional payload compression, and cooperative TX cancellation.

Features

  • no_std — Suitable for embedded targets without the standard library.
  • SX1278 support — Register-level driver for frequency, modem config, FIFO, and IRQ handling.
  • Operating modesTransmitter, Receiver, Transceiver, Manual, and ReceiverSingle.
  • Deep sleepdeep_sleep() and wake_from_deep_sleep() for minimal chip power consumption (~0.2 µA).
  • TX/RX — Blocking send() and receive() with configurable timeouts; RSSI and SNR in receive results.
  • Compression — Payload compression/decompression (via the tools crate) for smaller over-the-air packets.
  • Cooperative cancellation — Optional atomic flag to cancel an ongoing transmission from another task or IRQ.
  • DIO0 IRQ — Optional binding of an atomic flag for TX_DONE/RX_DONE to integrate with your GPIO interrupt handler.

Cargo features

Feature Description
sx1278 Enables the SX1278 controller and public API.
test-support Enables embedded-hal-mock for unit tests.

Enable at least sx1278 for normal use:

[dependencies]
lora = { version = "0.1", registry = "forgejo", features = ["sx1278"] }

For publishing or depending from a Forgejo registry, add the forgejo registry and the tools dependency as in this crates Cargo.toml.

Usage example

use embedded_hal::delay::DelayNs;
use embedded_hal::digital::OutputPin;
use embedded_hal::spi::SpiBus;
use lora::sx1278::{Controller, Mode};

// SPI, NSS, and RST are your embedded_hal implementations (owned by the controller).
let mut controller = Controller::new(spi, nss, rst, &mut delay, Mode::Transceiver)?;
controller.set_frequency(433_000_000, &mut delay); // 433 MHz

// Send a message (blocking until TX_DONE or timeout).
controller.send(&message[..], &mut delay)?;

// Receive into a buffer (blocking until RX_DONE or timeout).
let result = controller.receive(&mut buffer[..], &mut delay)?;
// result.size, result.rssi (dBm), result.snr (dB)

// Put the radio in deep sleep when idle (configuration is retained).
controller.deep_sleep(&mut delay);

// send(), receive(), and handle_dio0_irq() wake the chip automatically.
// Call wake_from_deep_sleep() only if you need RX active before the next operation.
controller.wake_from_deep_sleep(&mut delay);

Project structure

lora/
├── src/
│   ├── lib.rs           # Crate root; re-exports error and sx1278
│   ├── error/           # LoRaError and error types
│   │   ├── mod.rs
│   │   └── model.rs
│   └── sx1278/          # SX1278 driver (feature-gated)
│       ├── mod.rs       # Controller, Mode, ReceiveResult, TxTimeoutConfig
│       ├── registers.rs # Register addresses, modes, IRQ masks, constants
│       └── tests/       # Unit tests (send, receive, set_frequency, set_mode, version, etc.)
├── scripts/
│   └── test.sh          # Runs cargo test with sx1278 feature
├── Cargo.toml
├── LICENSE
└── README.md

Dependencies

  • embedded-hal 1.x — SPI, delay, and output pin traits.
  • ufmt — Optional formatting in no_std.
  • tools (Forgejo registry) — Register read/write and compression; requires registry = "forgejo" and a configured Forgejo Cargo registry.
  • lzss — Used for compression (default-features = false).

Building and testing

# Build with SX1278 support
cargo build --features sx1278

# Run tests (uses embedded-hal-mock)
cargo test --features sx1278

# Or use the project script
./scripts/test.sh

Status

  • Version: 0.1.0
  • Driver: SX1278 register interface, init, send, receive, set_frequency, set_mode, read_version.
  • Tests: Unit tests for init, send (including timeout and cancellation), receive (including CRC and buffer size), set_frequency, set_mode, and version read.

License

Personal Use Only — Non-Commercial. See LICENSE for full terms and disclaimers. Commercial use requires written permission from the copyright holder.