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/bin/lora_p2p_send.rs | |
| parent | b4bc9ac028568dfb3896dfb00cbd1e181863fd64 (diff) | |
Move embassy-lora, lora examples to lora-phy repo.
Diffstat (limited to 'examples/nrf52840/src/bin/lora_p2p_send.rs')
| -rw-r--r-- | examples/nrf52840/src/bin/lora_p2p_send.rs | 102 |
1 files changed, 0 insertions, 102 deletions
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 | } | ||
