aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf52840/src/bin/lora_cad.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/nrf52840/src/bin/lora_cad.rs')
-rw-r--r--examples/nrf52840/src/bin/lora_cad.rs97
1 files changed, 0 insertions, 97 deletions
diff --git a/examples/nrf52840/src/bin/lora_cad.rs b/examples/nrf52840/src/bin/lora_cad.rs
deleted file mode 100644
index 38e6d6197..000000000
--- a/examples/nrf52840/src/bin/lora_cad.rs
+++ /dev/null
@@ -1,97 +0,0 @@
1//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
2//! Other nrf/sx126x combinations may work with appropriate pin modifications.
3//! It demonstrates LORA CAD functionality.
4#![no_std]
5#![no_main]
6#![macro_use]
7#![feature(type_alias_impl_trait)]
8
9use defmt::*;
10use embassy_executor::Spawner;
11use embassy_lora::iv::GenericSx126xInterfaceVariant;
12use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
13use embassy_nrf::{bind_interrupts, peripherals, spim};
14use embassy_time::{Delay, Timer};
15use lora_phy::mod_params::*;
16use lora_phy::sx1261_2::SX1261_2;
17use lora_phy::LoRa;
18use {defmt_rtt as _, panic_probe as _};
19
20const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region
21
22bind_interrupts!(struct Irqs {
23 SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
24});
25
26#[embassy_executor::main]
27async fn main(_spawner: Spawner) {
28 let p = embassy_nrf::init(Default::default());
29 let mut spi_config = spim::Config::default();
30 spi_config.frequency = spim::Frequency::M16;
31
32 let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
33
34 let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
35 let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
36 let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
37 let busy = Input::new(p.P1_14.degrade(), Pull::Down);
38 let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
39 let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
40
41 let iv =
42 GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
43
44 let mut lora = {
45 match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await {
46 Ok(l) => l,
47 Err(err) => {
48 info!("Radio error = {}", err);
49 return;
50 }
51 }
52 };
53
54 let mut debug_indicator = Output::new(p.P1_03, Level::Low, OutputDrive::Standard);
55 let mut start_indicator = Output::new(p.P1_04, Level::Low, OutputDrive::Standard);
56
57 start_indicator.set_high();
58 Timer::after_secs(5).await;
59 start_indicator.set_low();
60
61 let mdltn_params = {
62 match lora.create_modulation_params(
63 SpreadingFactor::_10,
64 Bandwidth::_250KHz,
65 CodingRate::_4_8,
66 LORA_FREQUENCY_IN_HZ,
67 ) {
68 Ok(mp) => mp,
69 Err(err) => {
70 info!("Radio error = {}", err);
71 return;
72 }
73 }
74 };
75
76 match lora.prepare_for_cad(&mdltn_params, true).await {
77 Ok(()) => {}
78 Err(err) => {
79 info!("Radio error = {}", err);
80 return;
81 }
82 };
83
84 match lora.cad().await {
85 Ok(cad_activity_detected) => {
86 if cad_activity_detected {
87 info!("cad successful with activity detected")
88 } else {
89 info!("cad successful without activity detected")
90 }
91 debug_indicator.set_high();
92 Timer::after_secs(5).await;
93 debug_indicator.set_low();
94 }
95 Err(err) => info!("cad unsuccessful = {}", err),
96 }
97}