Update to rust-lorawan with afit support
This commit is contained in:
parent
224eaaf797
commit
63941432e3
10 changed files with 142 additions and 186 deletions
|
@ -38,5 +38,5 @@ futures = { version = "0.3.17", default-features = false, features = [ "async-aw
|
||||||
embedded-hal = { version = "0.2", features = ["unproven"] }
|
embedded-hal = { version = "0.2", features = ["unproven"] }
|
||||||
bit_field = { version = "0.10" }
|
bit_field = { version = "0.10" }
|
||||||
|
|
||||||
lorawan-device = { version = "0.8.0", default-features = false, features = ["async"] }
|
lorawan-device = { version = "0.8.0", git = "https://github.com/ivajloip/rust-lorawan.git", rev = "7d3eb40bc2412536c846cea40caff25198b6b068", default-features = false, features = ["async"] }
|
||||||
lorawan = { version = "0.7.1", default-features = false }
|
lorawan = { version = "0.7.1", git = "https://github.com/ivajloip/rust-lorawan.git", rev = "7d3eb40bc2412536c846cea40caff25198b6b068", default-features = false }
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(async_fn_in_trait, impl_trait_projections)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
//! embassy-lora is a collection of async radio drivers that integrate with the lorawan-device
|
//! embassy-lora is a collection of async radio drivers that integrate with the lorawan-device
|
||||||
//! crate's async LoRaWAN MAC implementation.
|
//! crate's async LoRaWAN MAC implementation.
|
||||||
|
|
||||||
|
@ -34,13 +35,11 @@ impl lorawan_device::async_device::radio::Timer for LoraTimer {
|
||||||
self.start = Instant::now();
|
self.start = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
type AtFuture<'m> = impl core::future::Future<Output = ()> + 'm;
|
async fn at(&mut self, millis: u64) {
|
||||||
fn at<'m>(&'m mut self, millis: u64) -> Self::AtFuture<'m> {
|
Timer::at(self.start + Duration::from_millis(millis)).await
|
||||||
Timer::at(self.start + Duration::from_millis(millis))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DelayFuture<'m> = impl core::future::Future<Output = ()> + 'm;
|
async fn delay_ms(&mut self, millis: u64) {
|
||||||
fn delay_ms<'m>(&'m mut self, millis: u64) -> Self::DelayFuture<'m> {
|
Timer::after(Duration::from_millis(millis)).await
|
||||||
Timer::after(Duration::from_millis(millis))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//! A radio driver integration for the radio found on STM32WL family devices.
|
//! A radio driver integration for the radio found on STM32WL family devices.
|
||||||
use core::future::{poll_fn, Future};
|
use core::future::poll_fn;
|
||||||
use core::task::Poll;
|
use core::task::Poll;
|
||||||
|
|
||||||
use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
|
use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
|
||||||
|
@ -241,14 +241,12 @@ fn configure_radio(radio: &mut SubGhz<'_, NoDma, NoDma>, config: SubGhzRadioConf
|
||||||
impl<'d, RS: RadioSwitch> PhyRxTx for SubGhzRadio<'d, RS> {
|
impl<'d, RS: RadioSwitch> PhyRxTx for SubGhzRadio<'d, RS> {
|
||||||
type PhyError = RadioError;
|
type PhyError = RadioError;
|
||||||
|
|
||||||
type TxFuture<'m> = impl Future<Output = Result<u32, Self::PhyError>> + 'm where Self: 'm;
|
async fn tx(&mut self, config: TxConfig, buf: &[u8]) -> Result<u32, Self::PhyError> {
|
||||||
fn tx<'m>(&'m mut self, config: TxConfig, buf: &'m [u8]) -> Self::TxFuture<'m> {
|
self.do_tx(config, buf).await
|
||||||
async move { self.do_tx(config, buf).await }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RxFuture<'m> = impl Future<Output = Result<(usize, RxQuality), Self::PhyError>> + 'm where Self: 'm;
|
async fn rx(&mut self, config: RfConfig, buf: &mut [u8]) -> Result<(usize, RxQuality), Self::PhyError> {
|
||||||
fn rx<'m>(&'m mut self, config: RfConfig, buf: &'m mut [u8]) -> Self::RxFuture<'m> {
|
self.do_rx(config, buf).await
|
||||||
async move { self.do_rx(config, buf).await }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use core::future::Future;
|
|
||||||
|
|
||||||
use defmt::Format;
|
use defmt::Format;
|
||||||
use embedded_hal::digital::v2::OutputPin;
|
use embedded_hal::digital::v2::OutputPin;
|
||||||
use embedded_hal_async::digital::Wait;
|
use embedded_hal_async::digital::Wait;
|
||||||
|
@ -71,16 +69,8 @@ where
|
||||||
{
|
{
|
||||||
type PhyError = RadioError<BUS>;
|
type PhyError = RadioError<BUS>;
|
||||||
|
|
||||||
type TxFuture<'m> = impl Future<Output = Result<u32, Self::PhyError>> + 'm
|
async fn tx(&mut self, config: TxConfig, buffer: &[u8]) -> Result<u32, Self::PhyError> {
|
||||||
where
|
|
||||||
SPI: 'm,
|
|
||||||
CTRL: 'm,
|
|
||||||
WAIT: 'm,
|
|
||||||
BUS: 'm;
|
|
||||||
|
|
||||||
fn tx<'m>(&'m mut self, config: TxConfig, buffer: &'m [u8]) -> Self::TxFuture<'m> {
|
|
||||||
trace!("TX START");
|
trace!("TX START");
|
||||||
async move {
|
|
||||||
self.lora
|
self.lora
|
||||||
.set_tx_config(
|
.set_tx_config(
|
||||||
config.pw,
|
config.pw,
|
||||||
|
@ -102,18 +92,13 @@ where
|
||||||
trace!("TX DONE");
|
trace!("TX DONE");
|
||||||
return Ok(0);
|
return Ok(0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
type RxFuture<'m> = impl Future<Output = Result<(usize, RxQuality), Self::PhyError>> + 'm
|
async fn rx(
|
||||||
where
|
&mut self,
|
||||||
SPI: 'm,
|
config: RfConfig,
|
||||||
CTRL: 'm,
|
receiving_buffer: &mut [u8],
|
||||||
WAIT: 'm,
|
) -> Result<(usize, RxQuality), Self::PhyError> {
|
||||||
BUS: 'm;
|
|
||||||
|
|
||||||
fn rx<'m>(&'m mut self, config: RfConfig, receiving_buffer: &'m mut [u8]) -> Self::RxFuture<'m> {
|
|
||||||
trace!("RX START");
|
trace!("RX START");
|
||||||
async move {
|
|
||||||
self.lora
|
self.lora
|
||||||
.set_rx_config(
|
.set_rx_config(
|
||||||
config.spreading_factor.into(),
|
config.spreading_factor.into(),
|
||||||
|
@ -149,5 +134,4 @@ where
|
||||||
|
|
||||||
Ok((received_len as usize, RxQuality::new(rssi, snr)))
|
Ok((received_len as usize, RxQuality::new(rssi, snr)))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use core::future::Future;
|
|
||||||
|
|
||||||
use embedded_hal::digital::v2::OutputPin;
|
use embedded_hal::digital::v2::OutputPin;
|
||||||
use embedded_hal_async::digital::Wait;
|
use embedded_hal_async::digital::Wait;
|
||||||
use embedded_hal_async::spi::*;
|
use embedded_hal_async::spi::*;
|
||||||
|
@ -88,18 +86,8 @@ where
|
||||||
{
|
{
|
||||||
type PhyError = Sx127xError;
|
type PhyError = Sx127xError;
|
||||||
|
|
||||||
type TxFuture<'m> = impl Future<Output = Result<u32, Self::PhyError>> + 'm
|
async fn tx(&mut self, config: TxConfig, buf: &[u8]) -> Result<u32, Self::PhyError> {
|
||||||
where
|
|
||||||
SPI: 'm,
|
|
||||||
CS: 'm,
|
|
||||||
RESET: 'm,
|
|
||||||
E: 'm,
|
|
||||||
I: 'm,
|
|
||||||
RFS: 'm;
|
|
||||||
|
|
||||||
fn tx<'m>(&'m mut self, config: TxConfig, buf: &'m [u8]) -> Self::TxFuture<'m> {
|
|
||||||
trace!("TX START");
|
trace!("TX START");
|
||||||
async move {
|
|
||||||
self.radio.set_mode(RadioMode::Stdby).await.ok().unwrap();
|
self.radio.set_mode(RadioMode::Stdby).await.ok().unwrap();
|
||||||
self.rfs.set_tx();
|
self.rfs.set_tx();
|
||||||
self.radio.set_tx_power(14, 0).await?;
|
self.radio.set_tx_power(14, 0).await?;
|
||||||
|
@ -133,20 +121,8 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
type RxFuture<'m> = impl Future<Output = Result<(usize, RxQuality), Self::PhyError>> + 'm
|
async fn rx(&mut self, config: RfConfig, buf: &mut [u8]) -> Result<(usize, RxQuality), Self::PhyError> {
|
||||||
where
|
|
||||||
SPI: 'm,
|
|
||||||
CS: 'm,
|
|
||||||
RESET: 'm,
|
|
||||||
E: 'm,
|
|
||||||
I: 'm,
|
|
||||||
RFS: 'm;
|
|
||||||
|
|
||||||
fn rx<'m>(&'m mut self, config: RfConfig, buf: &'m mut [u8]) -> Self::RxFuture<'m> {
|
|
||||||
trace!("RX START");
|
|
||||||
async move {
|
|
||||||
self.rfs.set_rx();
|
self.rfs.set_rx();
|
||||||
self.radio.reset_payload_length().await?;
|
self.radio.reset_payload_length().await?;
|
||||||
self.radio.set_frequency(config.frequency).await?;
|
self.radio.set_frequency(config.frequency).await?;
|
||||||
|
@ -185,7 +161,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
|
|
|
@ -20,8 +20,8 @@ embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defm
|
||||||
embedded-io = "0.4.0"
|
embedded-io = "0.4.0"
|
||||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx126x", "time", "defmt"], optional = true }
|
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx126x", "time", "defmt"], optional = true }
|
||||||
|
|
||||||
lorawan-device = { version = "0.8.0", default-features = false, features = ["async"], optional = true }
|
lorawan-device = { version = "0.8.0", git = "https://github.com/ivajloip/rust-lorawan.git", rev = "7d3eb40bc2412536c846cea40caff25198b6b068", default-features = false, features = ["async"], optional = true }
|
||||||
lorawan = { version = "0.7.1", default-features = false, features = ["default-crypto"], optional = true }
|
lorawan = { version = "0.7.1", git = "https://github.com/ivajloip/rust-lorawan.git", rev = "7d3eb40bc2412536c846cea40caff25198b6b068", default-features = false, features = ["default-crypto"], optional = true }
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.4"
|
defmt-rtt = "0.4"
|
||||||
|
|
|
@ -15,8 +15,8 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["de
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
|
||||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true}
|
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true}
|
||||||
|
|
||||||
lorawan-device = { version = "0.8.0", default-features = false, features = ["async"], optional = true }
|
lorawan-device = { version = "0.8.0", git = "https://github.com/ivajloip/rust-lorawan.git", rev = "7d3eb40bc2412536c846cea40caff25198b6b068", default-features = false, features = ["async"], optional = true }
|
||||||
lorawan = { version = "0.7.1", default-features = false, features = ["default-crypto"], optional = true }
|
lorawan = { version = "0.7.1", git = "https://github.com/ivajloip/rust-lorawan.git", rev = "7d3eb40bc2412536c846cea40caff25198b6b068", default-features = false, features = ["default-crypto"], optional = true }
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.4"
|
defmt-rtt = "0.4"
|
||||||
|
|
|
@ -45,7 +45,7 @@ async fn main(_spawner: Spawner) {
|
||||||
|
|
||||||
let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch).await.unwrap();
|
let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch).await.unwrap();
|
||||||
|
|
||||||
let region = region::EU868::default().into();
|
let region = region::Configuration::new(region::Region::EU868);
|
||||||
let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG));
|
let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG));
|
||||||
|
|
||||||
defmt::info!("Joining LoRaWAN network");
|
defmt::info!("Joining LoRaWAN network");
|
||||||
|
|
|
@ -11,8 +11,8 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["de
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti"] }
|
||||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] }
|
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] }
|
||||||
|
|
||||||
lorawan-device = { version = "0.8.0", default-features = false, features = ["async"] }
|
lorawan-device = { version = "0.8.0", git = "https://github.com/ivajloip/rust-lorawan.git", rev = "7d3eb40bc2412536c846cea40caff25198b6b068", default-features = false, features = ["async"] }
|
||||||
lorawan = { version = "0.7.1", default-features = false, features = ["default-crypto"] }
|
lorawan = { version = "0.7.1", git = "https://github.com/ivajloip/rust-lorawan.git", rev = "7d3eb40bc2412536c846cea40caff25198b6b068", default-features = false, features = ["default-crypto"] }
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.4"
|
defmt-rtt = "0.4"
|
||||||
|
|
|
@ -63,7 +63,7 @@ async fn main(_spawner: Spawner) {
|
||||||
radio_config.calibrate_image = CalibrateImage::ISM_863_870;
|
radio_config.calibrate_image = CalibrateImage::ISM_863_870;
|
||||||
let radio = SubGhzRadio::new(radio, rfs, irq, radio_config).unwrap();
|
let radio = SubGhzRadio::new(radio, rfs, irq, radio_config).unwrap();
|
||||||
|
|
||||||
let mut region: region::Configuration = region::EU868::default().into();
|
let mut region = region::Configuration::new(region::Region::EU868);
|
||||||
|
|
||||||
// NOTE: This is specific for TTN, as they have a special RX1 delay
|
// NOTE: This is specific for TTN, as they have a special RX1 delay
|
||||||
region.set_receive_delay1(5000);
|
region.set_receive_delay1(5000);
|
||||||
|
|
Loading…
Reference in a new issue