diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-11-29 16:26:31 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-11-29 16:26:31 +0100 |
| commit | 1b9925e3da0ec42b770f736cd22325203c97cb47 (patch) | |
| tree | 2b03eb826cd9a9fce945921cff9c04a7e59f98f1 /examples/nrf52840/src | |
| parent | b4bc9ac028568dfb3896dfb00cbd1e181863fd64 (diff) | |
Move embassy-lora, lora examples to lora-phy repo.
Diffstat (limited to 'examples/nrf52840/src')
| -rw-r--r-- | examples/nrf52840/src/bin/lora_cad.rs | 97 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/lora_lorawan.rs | 82 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/lora_p2p_receive.rs | 119 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/lora_p2p_receive_duty_cycle.rs | 127 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/lora_p2p_send.rs | 102 |
5 files changed, 0 insertions, 527 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 | |||
| 9 | use defmt::*; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::GenericSx126xInterfaceVariant; | ||
| 12 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; | ||
| 13 | use embassy_nrf::{bind_interrupts, peripherals, spim}; | ||
| 14 | use embassy_time::{Delay, Timer}; | ||
| 15 | use lora_phy::mod_params::*; | ||
| 16 | use lora_phy::sx1261_2::SX1261_2; | ||
| 17 | use lora_phy::LoRa; | ||
| 18 | use {defmt_rtt as _, panic_probe as _}; | ||
| 19 | |||
| 20 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 21 | |||
| 22 | bind_interrupts!(struct Irqs { | ||
| 23 | SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>; | ||
| 24 | }); | ||
| 25 | |||
| 26 | #[embassy_executor::main] | ||
| 27 | async 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 | } | ||
diff --git a/examples/nrf52840/src/bin/lora_lorawan.rs b/examples/nrf52840/src/bin/lora_lorawan.rs deleted file mode 100644 index 666330ba1..000000000 --- a/examples/nrf52840/src/bin/lora_lorawan.rs +++ /dev/null | |||
| @@ -1,82 +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 LoRaWAN join functionality. | ||
| 4 | #![no_std] | ||
| 5 | #![no_main] | ||
| 6 | #![macro_use] | ||
| 7 | #![feature(type_alias_impl_trait)] | ||
| 8 | |||
| 9 | use defmt::*; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::GenericSx126xInterfaceVariant; | ||
| 12 | use embassy_lora::LoraTimer; | ||
| 13 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; | ||
| 14 | use embassy_nrf::rng::Rng; | ||
| 15 | use embassy_nrf::{bind_interrupts, peripherals, rng, spim}; | ||
| 16 | use embassy_time::Delay; | ||
| 17 | use lora_phy::mod_params::*; | ||
| 18 | use lora_phy::sx1261_2::SX1261_2; | ||
| 19 | use lora_phy::LoRa; | ||
| 20 | use lorawan::default_crypto::DefaultFactory as Crypto; | ||
| 21 | use lorawan_device::async_device::lora_radio::LoRaRadio; | ||
| 22 | use lorawan_device::async_device::{region, Device, JoinMode}; | ||
| 23 | use lorawan_device::{AppEui, AppKey, DevEui}; | ||
| 24 | use {defmt_rtt as _, panic_probe as _}; | ||
| 25 | |||
| 26 | const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region | ||
| 27 | |||
| 28 | bind_interrupts!(struct Irqs { | ||
| 29 | SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>; | ||
| 30 | RNG => rng::InterruptHandler<peripherals::RNG>; | ||
| 31 | }); | ||
| 32 | |||
| 33 | #[embassy_executor::main] | ||
| 34 | async fn main(_spawner: Spawner) { | ||
| 35 | let p = embassy_nrf::init(Default::default()); | ||
| 36 | let mut spi_config = spim::Config::default(); | ||
| 37 | spi_config.frequency = spim::Frequency::M16; | ||
| 38 | |||
| 39 | let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config); | ||
| 40 | |||
| 41 | let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard); | ||
| 42 | let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard); | ||
| 43 | let dio1 = Input::new(p.P1_15.degrade(), Pull::Down); | ||
| 44 | let busy = Input::new(p.P1_14.degrade(), Pull::Down); | ||
| 45 | let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard); | ||
| 46 | let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard); | ||
| 47 | |||
| 48 | let iv = | ||
| 49 | GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap(); | ||
| 50 | |||
| 51 | let lora = { | ||
| 52 | match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), true, Delay).await { | ||
| 53 | Ok(l) => l, | ||
| 54 | Err(err) => { | ||
| 55 | info!("Radio error = {}", err); | ||
| 56 | return; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | }; | ||
| 60 | |||
| 61 | let radio = LoRaRadio::new(lora); | ||
| 62 | let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); | ||
| 63 | let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs)); | ||
| 64 | |||
| 65 | defmt::info!("Joining LoRaWAN network"); | ||
| 66 | |||
| 67 | // TODO: Adjust the EUI and Keys according to your network credentials | ||
| 68 | match device | ||
| 69 | .join(&JoinMode::OTAA { | ||
| 70 | deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 71 | appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 72 | appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 73 | }) | ||
| 74 | .await | ||
| 75 | { | ||
| 76 | Ok(()) => defmt::info!("LoRaWAN network joined"), | ||
| 77 | Err(err) => { | ||
| 78 | info!("Radio error = {}", err); | ||
| 79 | return; | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
diff --git a/examples/nrf52840/src/bin/lora_p2p_receive.rs b/examples/nrf52840/src/bin/lora_p2p_receive.rs deleted file mode 100644 index 4f41e1245..000000000 --- a/examples/nrf52840/src/bin/lora_p2p_receive.rs +++ /dev/null | |||
| @@ -1,119 +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 P2P receive functionality in conjunction with the lora_p2p_send example. | ||
| 4 | #![no_std] | ||
| 5 | #![no_main] | ||
| 6 | #![macro_use] | ||
| 7 | #![feature(type_alias_impl_trait)] | ||
| 8 | |||
| 9 | use defmt::*; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::GenericSx126xInterfaceVariant; | ||
| 12 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; | ||
| 13 | use embassy_nrf::{bind_interrupts, peripherals, spim}; | ||
| 14 | use embassy_time::{Delay, Timer}; | ||
| 15 | use lora_phy::mod_params::*; | ||
| 16 | use lora_phy::sx1261_2::SX1261_2; | ||
| 17 | use lora_phy::LoRa; | ||
| 18 | use {defmt_rtt as _, panic_probe as _}; | ||
| 19 | |||
| 20 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 21 | |||
| 22 | bind_interrupts!(struct Irqs { | ||
| 23 | SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>; | ||
| 24 | }); | ||
| 25 | |||
| 26 | #[embassy_executor::main] | ||
| 27 | async 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 mut receiving_buffer = [00u8; 100]; | ||
| 62 | |||
| 63 | let mdltn_params = { | ||
| 64 | match lora.create_modulation_params( | ||
| 65 | SpreadingFactor::_10, | ||
| 66 | Bandwidth::_250KHz, | ||
| 67 | CodingRate::_4_8, | ||
| 68 | LORA_FREQUENCY_IN_HZ, | ||
| 69 | ) { | ||
| 70 | Ok(mp) => mp, | ||
| 71 | Err(err) => { | ||
| 72 | info!("Radio error = {}", err); | ||
| 73 | return; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | }; | ||
| 77 | |||
| 78 | let rx_pkt_params = { | ||
| 79 | match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) { | ||
| 80 | Ok(pp) => pp, | ||
| 81 | Err(err) => { | ||
| 82 | info!("Radio error = {}", err); | ||
| 83 | return; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | }; | ||
| 87 | |||
| 88 | match lora | ||
| 89 | .prepare_for_rx(&mdltn_params, &rx_pkt_params, None, None, false) | ||
| 90 | .await | ||
| 91 | { | ||
| 92 | Ok(()) => {} | ||
| 93 | Err(err) => { | ||
| 94 | info!("Radio error = {}", err); | ||
| 95 | return; | ||
| 96 | } | ||
| 97 | }; | ||
| 98 | |||
| 99 | loop { | ||
| 100 | receiving_buffer = [00u8; 100]; | ||
| 101 | match lora.rx(&rx_pkt_params, &mut receiving_buffer).await { | ||
| 102 | Ok((received_len, _rx_pkt_status)) => { | ||
| 103 | if (received_len == 3) | ||
| 104 | && (receiving_buffer[0] == 0x01u8) | ||
| 105 | && (receiving_buffer[1] == 0x02u8) | ||
| 106 | && (receiving_buffer[2] == 0x03u8) | ||
| 107 | { | ||
| 108 | info!("rx successful"); | ||
| 109 | debug_indicator.set_high(); | ||
| 110 | Timer::after_secs(5).await; | ||
| 111 | debug_indicator.set_low(); | ||
| 112 | } else { | ||
| 113 | info!("rx unknown packet"); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | Err(err) => info!("rx unsuccessful = {}", err), | ||
| 117 | } | ||
| 118 | } | ||
| 119 | } | ||
diff --git a/examples/nrf52840/src/bin/lora_p2p_receive_duty_cycle.rs b/examples/nrf52840/src/bin/lora_p2p_receive_duty_cycle.rs deleted file mode 100644 index 3d34f6aef..000000000 --- a/examples/nrf52840/src/bin/lora_p2p_receive_duty_cycle.rs +++ /dev/null | |||
| @@ -1,127 +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 Rx duty cycle functionality in conjunction with the lora_p2p_send example. | ||
| 4 | #![no_std] | ||
| 5 | #![no_main] | ||
| 6 | #![macro_use] | ||
| 7 | #![feature(type_alias_impl_trait)] | ||
| 8 | |||
| 9 | use defmt::*; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::GenericSx126xInterfaceVariant; | ||
| 12 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; | ||
| 13 | use embassy_nrf::{bind_interrupts, peripherals, spim}; | ||
| 14 | use embassy_time::{Delay, Timer}; | ||
| 15 | use lora_phy::mod_params::*; | ||
| 16 | use lora_phy::sx1261_2::SX1261_2; | ||
| 17 | use lora_phy::LoRa; | ||
| 18 | use {defmt_rtt as _, panic_probe as _}; | ||
| 19 | |||
| 20 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 21 | |||
| 22 | bind_interrupts!(struct Irqs { | ||
| 23 | SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>; | ||
| 24 | }); | ||
| 25 | |||
| 26 | #[embassy_executor::main] | ||
| 27 | async 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 mut receiving_buffer = [00u8; 100]; | ||
| 62 | |||
| 63 | let mdltn_params = { | ||
| 64 | match lora.create_modulation_params( | ||
| 65 | SpreadingFactor::_10, | ||
| 66 | Bandwidth::_250KHz, | ||
| 67 | CodingRate::_4_8, | ||
| 68 | LORA_FREQUENCY_IN_HZ, | ||
| 69 | ) { | ||
| 70 | Ok(mp) => mp, | ||
| 71 | Err(err) => { | ||
| 72 | info!("Radio error = {}", err); | ||
| 73 | return; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | }; | ||
| 77 | |||
| 78 | let rx_pkt_params = { | ||
| 79 | match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) { | ||
| 80 | Ok(pp) => pp, | ||
| 81 | Err(err) => { | ||
| 82 | info!("Radio error = {}", err); | ||
| 83 | return; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | }; | ||
| 87 | |||
| 88 | // 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. | ||
| 89 | match lora | ||
| 90 | .prepare_for_rx( | ||
| 91 | &mdltn_params, | ||
| 92 | &rx_pkt_params, | ||
| 93 | None, | ||
| 94 | Some(&DutyCycleParams { | ||
| 95 | rx_time: 300_000, // 300_000 units * 15.625 us/unit = 4.69 s | ||
| 96 | sleep_time: 200_000, // 200_000 units * 15.625 us/unit = 3.13 s | ||
| 97 | }), | ||
| 98 | false, | ||
| 99 | ) | ||
| 100 | .await | ||
| 101 | { | ||
| 102 | Ok(()) => {} | ||
| 103 | Err(err) => { | ||
| 104 | info!("Radio error = {}", err); | ||
| 105 | return; | ||
| 106 | } | ||
| 107 | }; | ||
| 108 | |||
| 109 | receiving_buffer = [00u8; 100]; | ||
| 110 | match lora.rx(&rx_pkt_params, &mut receiving_buffer).await { | ||
| 111 | Ok((received_len, _rx_pkt_status)) => { | ||
| 112 | if (received_len == 3) | ||
| 113 | && (receiving_buffer[0] == 0x01u8) | ||
| 114 | && (receiving_buffer[1] == 0x02u8) | ||
| 115 | && (receiving_buffer[2] == 0x03u8) | ||
| 116 | { | ||
| 117 | info!("rx successful"); | ||
| 118 | debug_indicator.set_high(); | ||
| 119 | Timer::after_secs(5).await; | ||
| 120 | debug_indicator.set_low(); | ||
| 121 | } else { | ||
| 122 | info!("rx unknown packet") | ||
| 123 | } | ||
| 124 | } | ||
| 125 | Err(err) => info!("rx unsuccessful = {}", err), | ||
| 126 | } | ||
| 127 | } | ||
diff --git a/examples/nrf52840/src/bin/lora_p2p_send.rs b/examples/nrf52840/src/bin/lora_p2p_send.rs deleted file mode 100644 index 676221a27..000000000 --- a/examples/nrf52840/src/bin/lora_p2p_send.rs +++ /dev/null | |||
| @@ -1,102 +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 P2P send functionality. | ||
| 4 | #![no_std] | ||
| 5 | #![no_main] | ||
| 6 | #![macro_use] | ||
| 7 | #![feature(type_alias_impl_trait)] | ||
| 8 | |||
| 9 | use defmt::*; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::GenericSx126xInterfaceVariant; | ||
| 12 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; | ||
| 13 | use embassy_nrf::{bind_interrupts, peripherals, spim}; | ||
| 14 | use embassy_time::Delay; | ||
| 15 | use lora_phy::mod_params::*; | ||
| 16 | use lora_phy::sx1261_2::SX1261_2; | ||
| 17 | use lora_phy::LoRa; | ||
| 18 | use {defmt_rtt as _, panic_probe as _}; | ||
| 19 | |||
| 20 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 21 | |||
| 22 | bind_interrupts!(struct Irqs { | ||
| 23 | SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>; | ||
| 24 | }); | ||
| 25 | |||
| 26 | #[embassy_executor::main] | ||
| 27 | async 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 mdltn_params = { | ||
| 55 | match lora.create_modulation_params( | ||
| 56 | SpreadingFactor::_10, | ||
| 57 | Bandwidth::_250KHz, | ||
| 58 | CodingRate::_4_8, | ||
| 59 | LORA_FREQUENCY_IN_HZ, | ||
| 60 | ) { | ||
| 61 | Ok(mp) => mp, | ||
| 62 | Err(err) => { | ||
| 63 | info!("Radio error = {}", err); | ||
| 64 | return; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | }; | ||
| 68 | |||
| 69 | let mut tx_pkt_params = { | ||
| 70 | match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) { | ||
| 71 | Ok(pp) => pp, | ||
| 72 | Err(err) => { | ||
| 73 | info!("Radio error = {}", err); | ||
| 74 | return; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | }; | ||
| 78 | |||
| 79 | match lora.prepare_for_tx(&mdltn_params, 20, false).await { | ||
| 80 | Ok(()) => {} | ||
| 81 | Err(err) => { | ||
| 82 | info!("Radio error = {}", err); | ||
| 83 | return; | ||
| 84 | } | ||
| 85 | }; | ||
| 86 | |||
| 87 | let buffer = [0x01u8, 0x02u8, 0x03u8]; | ||
| 88 | match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await { | ||
| 89 | Ok(()) => { | ||
| 90 | info!("TX DONE"); | ||
| 91 | } | ||
| 92 | Err(err) => { | ||
| 93 | info!("Radio error = {}", err); | ||
| 94 | return; | ||
| 95 | } | ||
| 96 | }; | ||
| 97 | |||
| 98 | match lora.sleep(false).await { | ||
| 99 | Ok(()) => info!("Sleep successful"), | ||
| 100 | Err(err) => info!("Sleep unsuccessful = {}", err), | ||
| 101 | } | ||
| 102 | } | ||
