Move embassy-lora, lora examples to lora-phy repo.
This commit is contained in:
@ -21,10 +21,6 @@ nightly = [
|
||||
"embedded-io-async",
|
||||
"embedded-hal-bus/async",
|
||||
"embassy-net",
|
||||
"embassy-lora",
|
||||
"lora-phy",
|
||||
"lorawan-device",
|
||||
"lorawan",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
@ -37,10 +33,6 @@ embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defm
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true }
|
||||
embedded-io = { version = "0.6.0", features = ["defmt-03"] }
|
||||
embedded-io-async = { version = "0.6.0", optional = true, features = ["defmt-03"] }
|
||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true }
|
||||
lora-phy = { version = "2", optional = true }
|
||||
lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"], optional = true }
|
||||
lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"], optional = true }
|
||||
embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"], optional = true }
|
||||
embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"], optional = true }
|
||||
|
||||
|
@ -1,97 +0,0 @@
|
||||
//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
|
||||
//! Other nrf/sx126x combinations may work with appropriate pin modifications.
|
||||
//! It demonstrates LORA CAD functionality.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
|
||||
use embassy_nrf::{bind_interrupts, peripherals, spim};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
use lora_phy::LoRa;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut spi_config = spim::Config::default();
|
||||
spi_config.frequency = spim::Frequency::M16;
|
||||
|
||||
let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
|
||||
|
||||
let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
|
||||
let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
|
||||
let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
|
||||
let busy = Input::new(p.P1_14.degrade(), Pull::Down);
|
||||
let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
|
||||
let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
|
||||
|
||||
let iv =
|
||||
GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
|
||||
|
||||
let mut lora = {
|
||||
match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await {
|
||||
Ok(l) => l,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut debug_indicator = Output::new(p.P1_03, Level::Low, OutputDrive::Standard);
|
||||
let mut start_indicator = Output::new(p.P1_04, Level::Low, OutputDrive::Standard);
|
||||
|
||||
start_indicator.set_high();
|
||||
Timer::after_secs(5).await;
|
||||
start_indicator.set_low();
|
||||
|
||||
let mdltn_params = {
|
||||
match lora.create_modulation_params(
|
||||
SpreadingFactor::_10,
|
||||
Bandwidth::_250KHz,
|
||||
CodingRate::_4_8,
|
||||
LORA_FREQUENCY_IN_HZ,
|
||||
) {
|
||||
Ok(mp) => mp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
match lora.prepare_for_cad(&mdltn_params, true).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match lora.cad().await {
|
||||
Ok(cad_activity_detected) => {
|
||||
if cad_activity_detected {
|
||||
info!("cad successful with activity detected")
|
||||
} else {
|
||||
info!("cad successful without activity detected")
|
||||
}
|
||||
debug_indicator.set_high();
|
||||
Timer::after_secs(5).await;
|
||||
debug_indicator.set_low();
|
||||
}
|
||||
Err(err) => info!("cad unsuccessful = {}", err),
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
|
||||
//! Other nrf/sx126x combinations may work with appropriate pin modifications.
|
||||
//! It demonstrates LoRaWAN join functionality.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
||||
use embassy_lora::LoraTimer;
|
||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
|
||||
use embassy_nrf::rng::Rng;
|
||||
use embassy_nrf::{bind_interrupts, peripherals, rng, spim};
|
||||
use embassy_time::Delay;
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
use lora_phy::LoRa;
|
||||
use lorawan::default_crypto::DefaultFactory as Crypto;
|
||||
use lorawan_device::async_device::lora_radio::LoRaRadio;
|
||||
use lorawan_device::async_device::{region, Device, JoinMode};
|
||||
use lorawan_device::{AppEui, AppKey, DevEui};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
|
||||
RNG => rng::InterruptHandler<peripherals::RNG>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut spi_config = spim::Config::default();
|
||||
spi_config.frequency = spim::Frequency::M16;
|
||||
|
||||
let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
|
||||
|
||||
let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
|
||||
let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
|
||||
let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
|
||||
let busy = Input::new(p.P1_14.degrade(), Pull::Down);
|
||||
let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
|
||||
let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
|
||||
|
||||
let iv =
|
||||
GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
|
||||
|
||||
let lora = {
|
||||
match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), true, Delay).await {
|
||||
Ok(l) => l,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let radio = LoRaRadio::new(lora);
|
||||
let region: region::Configuration = region::Configuration::new(LORAWAN_REGION);
|
||||
let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs));
|
||||
|
||||
defmt::info!("Joining LoRaWAN network");
|
||||
|
||||
// TODO: Adjust the EUI and Keys according to your network credentials
|
||||
match device
|
||||
.join(&JoinMode::OTAA {
|
||||
deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]),
|
||||
appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]),
|
||||
appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(()) => defmt::info!("LoRaWAN network joined"),
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
|
||||
//! Other nrf/sx126x combinations may work with appropriate pin modifications.
|
||||
//! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
|
||||
use embassy_nrf::{bind_interrupts, peripherals, spim};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
use lora_phy::LoRa;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut spi_config = spim::Config::default();
|
||||
spi_config.frequency = spim::Frequency::M16;
|
||||
|
||||
let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
|
||||
|
||||
let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
|
||||
let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
|
||||
let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
|
||||
let busy = Input::new(p.P1_14.degrade(), Pull::Down);
|
||||
let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
|
||||
let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
|
||||
|
||||
let iv =
|
||||
GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
|
||||
|
||||
let mut lora = {
|
||||
match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await {
|
||||
Ok(l) => l,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut debug_indicator = Output::new(p.P1_03, Level::Low, OutputDrive::Standard);
|
||||
let mut start_indicator = Output::new(p.P1_04, Level::Low, OutputDrive::Standard);
|
||||
|
||||
start_indicator.set_high();
|
||||
Timer::after_secs(5).await;
|
||||
start_indicator.set_low();
|
||||
|
||||
let mut receiving_buffer = [00u8; 100];
|
||||
|
||||
let mdltn_params = {
|
||||
match lora.create_modulation_params(
|
||||
SpreadingFactor::_10,
|
||||
Bandwidth::_250KHz,
|
||||
CodingRate::_4_8,
|
||||
LORA_FREQUENCY_IN_HZ,
|
||||
) {
|
||||
Ok(mp) => mp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let rx_pkt_params = {
|
||||
match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) {
|
||||
Ok(pp) => pp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
match lora
|
||||
.prepare_for_rx(&mdltn_params, &rx_pkt_params, None, None, false)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
loop {
|
||||
receiving_buffer = [00u8; 100];
|
||||
match lora.rx(&rx_pkt_params, &mut receiving_buffer).await {
|
||||
Ok((received_len, _rx_pkt_status)) => {
|
||||
if (received_len == 3)
|
||||
&& (receiving_buffer[0] == 0x01u8)
|
||||
&& (receiving_buffer[1] == 0x02u8)
|
||||
&& (receiving_buffer[2] == 0x03u8)
|
||||
{
|
||||
info!("rx successful");
|
||||
debug_indicator.set_high();
|
||||
Timer::after_secs(5).await;
|
||||
debug_indicator.set_low();
|
||||
} else {
|
||||
info!("rx unknown packet");
|
||||
}
|
||||
}
|
||||
Err(err) => info!("rx unsuccessful = {}", err),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
|
||||
//! Other nrf/sx126x combinations may work with appropriate pin modifications.
|
||||
//! It demonstrates LoRa Rx duty cycle functionality in conjunction with the lora_p2p_send example.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
|
||||
use embassy_nrf::{bind_interrupts, peripherals, spim};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
use lora_phy::LoRa;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut spi_config = spim::Config::default();
|
||||
spi_config.frequency = spim::Frequency::M16;
|
||||
|
||||
let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
|
||||
|
||||
let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
|
||||
let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
|
||||
let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
|
||||
let busy = Input::new(p.P1_14.degrade(), Pull::Down);
|
||||
let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
|
||||
let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
|
||||
|
||||
let iv =
|
||||
GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
|
||||
|
||||
let mut lora = {
|
||||
match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await {
|
||||
Ok(l) => l,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut debug_indicator = Output::new(p.P1_03, Level::Low, OutputDrive::Standard);
|
||||
let mut start_indicator = Output::new(p.P1_04, Level::Low, OutputDrive::Standard);
|
||||
|
||||
start_indicator.set_high();
|
||||
Timer::after_secs(5).await;
|
||||
start_indicator.set_low();
|
||||
|
||||
let mut receiving_buffer = [00u8; 100];
|
||||
|
||||
let mdltn_params = {
|
||||
match lora.create_modulation_params(
|
||||
SpreadingFactor::_10,
|
||||
Bandwidth::_250KHz,
|
||||
CodingRate::_4_8,
|
||||
LORA_FREQUENCY_IN_HZ,
|
||||
) {
|
||||
Ok(mp) => mp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let rx_pkt_params = {
|
||||
match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) {
|
||||
Ok(pp) => pp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// See "RM0453 Reference manual STM32WL5x advanced Arm®-based 32-bit MCUs with sub-GHz radio solution" for the best explanation of Rx duty cycle processing.
|
||||
match lora
|
||||
.prepare_for_rx(
|
||||
&mdltn_params,
|
||||
&rx_pkt_params,
|
||||
None,
|
||||
Some(&DutyCycleParams {
|
||||
rx_time: 300_000, // 300_000 units * 15.625 us/unit = 4.69 s
|
||||
sleep_time: 200_000, // 200_000 units * 15.625 us/unit = 3.13 s
|
||||
}),
|
||||
false,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
receiving_buffer = [00u8; 100];
|
||||
match lora.rx(&rx_pkt_params, &mut receiving_buffer).await {
|
||||
Ok((received_len, _rx_pkt_status)) => {
|
||||
if (received_len == 3)
|
||||
&& (receiving_buffer[0] == 0x01u8)
|
||||
&& (receiving_buffer[1] == 0x02u8)
|
||||
&& (receiving_buffer[2] == 0x03u8)
|
||||
{
|
||||
info!("rx successful");
|
||||
debug_indicator.set_high();
|
||||
Timer::after_secs(5).await;
|
||||
debug_indicator.set_low();
|
||||
} else {
|
||||
info!("rx unknown packet")
|
||||
}
|
||||
}
|
||||
Err(err) => info!("rx unsuccessful = {}", err),
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
|
||||
//! Other nrf/sx126x combinations may work with appropriate pin modifications.
|
||||
//! It demonstrates LORA P2P send functionality.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
|
||||
use embassy_nrf::{bind_interrupts, peripherals, spim};
|
||||
use embassy_time::Delay;
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
use lora_phy::LoRa;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut spi_config = spim::Config::default();
|
||||
spi_config.frequency = spim::Frequency::M16;
|
||||
|
||||
let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
|
||||
|
||||
let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
|
||||
let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
|
||||
let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
|
||||
let busy = Input::new(p.P1_14.degrade(), Pull::Down);
|
||||
let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
|
||||
let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
|
||||
|
||||
let iv =
|
||||
GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
|
||||
|
||||
let mut lora = {
|
||||
match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await {
|
||||
Ok(l) => l,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mdltn_params = {
|
||||
match lora.create_modulation_params(
|
||||
SpreadingFactor::_10,
|
||||
Bandwidth::_250KHz,
|
||||
CodingRate::_4_8,
|
||||
LORA_FREQUENCY_IN_HZ,
|
||||
) {
|
||||
Ok(mp) => mp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut tx_pkt_params = {
|
||||
match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) {
|
||||
Ok(pp) => pp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
match lora.prepare_for_tx(&mdltn_params, 20, false).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let buffer = [0x01u8, 0x02u8, 0x03u8];
|
||||
match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await {
|
||||
Ok(()) => {
|
||||
info!("TX DONE");
|
||||
}
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match lora.sleep(false).await {
|
||||
Ok(()) => info!("Sleep successful"),
|
||||
Err(err) => info!("Sleep unsuccessful = {}", err),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user