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 | |
| parent | b4bc9ac028568dfb3896dfb00cbd1e181863fd64 (diff) | |
Move embassy-lora, lora examples to lora-phy repo.
24 files changed, 1 insertions, 2353 deletions
diff --git a/embassy-lora/Cargo.toml b/embassy-lora/Cargo.toml deleted file mode 100644 index f2ba379b2..000000000 --- a/embassy-lora/Cargo.toml +++ /dev/null | |||
| @@ -1,31 +0,0 @@ | |||
| 1 | [package] | ||
| 2 | name = "embassy-lora" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [package.metadata.embassy_docs] | ||
| 8 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-lora-v$VERSION/embassy-lora/src/" | ||
| 9 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-lora/src/" | ||
| 10 | features = ["stm32wl", "embassy-stm32?/stm32wl55jc-cm4", "embassy-stm32?/unstable-pac", "time", "defmt"] | ||
| 11 | target = "thumbv7em-none-eabi" | ||
| 12 | |||
| 13 | [features] | ||
| 14 | stm32wl = ["dep:embassy-stm32"] | ||
| 15 | time = ["embassy-time", "lorawan-device"] | ||
| 16 | defmt = ["dep:defmt", "lorawan-device/defmt"] | ||
| 17 | |||
| 18 | [dependencies] | ||
| 19 | |||
| 20 | defmt = { version = "0.3", optional = true } | ||
| 21 | log = { version = "0.4.14", optional = true } | ||
| 22 | |||
| 23 | embassy-time = { version = "0.1.5", path = "../embassy-time", optional = true } | ||
| 24 | embassy-sync = { version = "0.4.0", path = "../embassy-sync" } | ||
| 25 | embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } | ||
| 26 | embedded-hal-async = { version = "=1.0.0-rc.1" } | ||
| 27 | embedded-hal = { version = "0.2", features = ["unproven"] } | ||
| 28 | |||
| 29 | futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } | ||
| 30 | lora-phy = { version = "2" } | ||
| 31 | lorawan-device = { version = "0.11.0", default-features = false, features = ["async"], optional = true } | ||
diff --git a/embassy-lora/src/fmt.rs b/embassy-lora/src/fmt.rs deleted file mode 100644 index 78e583c1c..000000000 --- a/embassy-lora/src/fmt.rs +++ /dev/null | |||
| @@ -1,258 +0,0 @@ | |||
| 1 | #![macro_use] | ||
| 2 | #![allow(unused_macros)] | ||
| 3 | |||
| 4 | use core::fmt::{Debug, Display, LowerHex}; | ||
| 5 | |||
| 6 | #[cfg(all(feature = "defmt", feature = "log"))] | ||
| 7 | compile_error!("You may not enable both `defmt` and `log` features."); | ||
| 8 | |||
| 9 | macro_rules! assert { | ||
| 10 | ($($x:tt)*) => { | ||
| 11 | { | ||
| 12 | #[cfg(not(feature = "defmt"))] | ||
| 13 | ::core::assert!($($x)*); | ||
| 14 | #[cfg(feature = "defmt")] | ||
| 15 | ::defmt::assert!($($x)*); | ||
| 16 | } | ||
| 17 | }; | ||
| 18 | } | ||
| 19 | |||
| 20 | macro_rules! assert_eq { | ||
| 21 | ($($x:tt)*) => { | ||
| 22 | { | ||
| 23 | #[cfg(not(feature = "defmt"))] | ||
| 24 | ::core::assert_eq!($($x)*); | ||
| 25 | #[cfg(feature = "defmt")] | ||
| 26 | ::defmt::assert_eq!($($x)*); | ||
| 27 | } | ||
| 28 | }; | ||
| 29 | } | ||
| 30 | |||
| 31 | macro_rules! assert_ne { | ||
| 32 | ($($x:tt)*) => { | ||
| 33 | { | ||
| 34 | #[cfg(not(feature = "defmt"))] | ||
| 35 | ::core::assert_ne!($($x)*); | ||
| 36 | #[cfg(feature = "defmt")] | ||
| 37 | ::defmt::assert_ne!($($x)*); | ||
| 38 | } | ||
| 39 | }; | ||
| 40 | } | ||
| 41 | |||
| 42 | macro_rules! debug_assert { | ||
| 43 | ($($x:tt)*) => { | ||
| 44 | { | ||
| 45 | #[cfg(not(feature = "defmt"))] | ||
| 46 | ::core::debug_assert!($($x)*); | ||
| 47 | #[cfg(feature = "defmt")] | ||
| 48 | ::defmt::debug_assert!($($x)*); | ||
| 49 | } | ||
| 50 | }; | ||
| 51 | } | ||
| 52 | |||
| 53 | macro_rules! debug_assert_eq { | ||
| 54 | ($($x:tt)*) => { | ||
| 55 | { | ||
| 56 | #[cfg(not(feature = "defmt"))] | ||
| 57 | ::core::debug_assert_eq!($($x)*); | ||
| 58 | #[cfg(feature = "defmt")] | ||
| 59 | ::defmt::debug_assert_eq!($($x)*); | ||
| 60 | } | ||
| 61 | }; | ||
| 62 | } | ||
| 63 | |||
| 64 | macro_rules! debug_assert_ne { | ||
| 65 | ($($x:tt)*) => { | ||
| 66 | { | ||
| 67 | #[cfg(not(feature = "defmt"))] | ||
| 68 | ::core::debug_assert_ne!($($x)*); | ||
| 69 | #[cfg(feature = "defmt")] | ||
| 70 | ::defmt::debug_assert_ne!($($x)*); | ||
| 71 | } | ||
| 72 | }; | ||
| 73 | } | ||
| 74 | |||
| 75 | macro_rules! todo { | ||
| 76 | ($($x:tt)*) => { | ||
| 77 | { | ||
| 78 | #[cfg(not(feature = "defmt"))] | ||
| 79 | ::core::todo!($($x)*); | ||
| 80 | #[cfg(feature = "defmt")] | ||
| 81 | ::defmt::todo!($($x)*); | ||
| 82 | } | ||
| 83 | }; | ||
| 84 | } | ||
| 85 | |||
| 86 | #[cfg(not(feature = "defmt"))] | ||
| 87 | macro_rules! unreachable { | ||
| 88 | ($($x:tt)*) => { | ||
| 89 | ::core::unreachable!($($x)*) | ||
| 90 | }; | ||
| 91 | } | ||
| 92 | |||
| 93 | #[cfg(feature = "defmt")] | ||
| 94 | macro_rules! unreachable { | ||
| 95 | ($($x:tt)*) => { | ||
| 96 | ::defmt::unreachable!($($x)*) | ||
| 97 | }; | ||
| 98 | } | ||
| 99 | |||
| 100 | macro_rules! panic { | ||
| 101 | ($($x:tt)*) => { | ||
| 102 | { | ||
| 103 | #[cfg(not(feature = "defmt"))] | ||
| 104 | ::core::panic!($($x)*); | ||
| 105 | #[cfg(feature = "defmt")] | ||
| 106 | ::defmt::panic!($($x)*); | ||
| 107 | } | ||
| 108 | }; | ||
| 109 | } | ||
| 110 | |||
| 111 | macro_rules! trace { | ||
| 112 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 113 | { | ||
| 114 | #[cfg(feature = "log")] | ||
| 115 | ::log::trace!($s $(, $x)*); | ||
| 116 | #[cfg(feature = "defmt")] | ||
| 117 | ::defmt::trace!($s $(, $x)*); | ||
| 118 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 119 | let _ = ($( & $x ),*); | ||
| 120 | } | ||
| 121 | }; | ||
| 122 | } | ||
| 123 | |||
| 124 | macro_rules! debug { | ||
| 125 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 126 | { | ||
| 127 | #[cfg(feature = "log")] | ||
| 128 | ::log::debug!($s $(, $x)*); | ||
| 129 | #[cfg(feature = "defmt")] | ||
| 130 | ::defmt::debug!($s $(, $x)*); | ||
| 131 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 132 | let _ = ($( & $x ),*); | ||
| 133 | } | ||
| 134 | }; | ||
| 135 | } | ||
| 136 | |||
| 137 | macro_rules! info { | ||
| 138 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 139 | { | ||
| 140 | #[cfg(feature = "log")] | ||
| 141 | ::log::info!($s $(, $x)*); | ||
| 142 | #[cfg(feature = "defmt")] | ||
| 143 | ::defmt::info!($s $(, $x)*); | ||
| 144 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 145 | let _ = ($( & $x ),*); | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | |||
| 150 | macro_rules! warn { | ||
| 151 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 152 | { | ||
| 153 | #[cfg(feature = "log")] | ||
| 154 | ::log::warn!($s $(, $x)*); | ||
| 155 | #[cfg(feature = "defmt")] | ||
| 156 | ::defmt::warn!($s $(, $x)*); | ||
| 157 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 158 | let _ = ($( & $x ),*); | ||
| 159 | } | ||
| 160 | }; | ||
| 161 | } | ||
| 162 | |||
| 163 | macro_rules! error { | ||
| 164 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 165 | { | ||
| 166 | #[cfg(feature = "log")] | ||
| 167 | ::log::error!($s $(, $x)*); | ||
| 168 | #[cfg(feature = "defmt")] | ||
| 169 | ::defmt::error!($s $(, $x)*); | ||
| 170 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 171 | let _ = ($( & $x ),*); | ||
| 172 | } | ||
| 173 | }; | ||
| 174 | } | ||
| 175 | |||
| 176 | #[cfg(feature = "defmt")] | ||
| 177 | macro_rules! unwrap { | ||
| 178 | ($($x:tt)*) => { | ||
| 179 | ::defmt::unwrap!($($x)*) | ||
| 180 | }; | ||
| 181 | } | ||
| 182 | |||
| 183 | #[cfg(not(feature = "defmt"))] | ||
| 184 | macro_rules! unwrap { | ||
| 185 | ($arg:expr) => { | ||
| 186 | match $crate::fmt::Try::into_result($arg) { | ||
| 187 | ::core::result::Result::Ok(t) => t, | ||
| 188 | ::core::result::Result::Err(e) => { | ||
| 189 | ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | }; | ||
| 193 | ($arg:expr, $($msg:expr),+ $(,)? ) => { | ||
| 194 | match $crate::fmt::Try::into_result($arg) { | ||
| 195 | ::core::result::Result::Ok(t) => t, | ||
| 196 | ::core::result::Result::Err(e) => { | ||
| 197 | ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); | ||
| 198 | } | ||
| 199 | } | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
| 204 | pub struct NoneError; | ||
| 205 | |||
| 206 | pub trait Try { | ||
| 207 | type Ok; | ||
| 208 | type Error; | ||
| 209 | fn into_result(self) -> Result<Self::Ok, Self::Error>; | ||
| 210 | } | ||
| 211 | |||
| 212 | impl<T> Try for Option<T> { | ||
| 213 | type Ok = T; | ||
| 214 | type Error = NoneError; | ||
| 215 | |||
| 216 | #[inline] | ||
| 217 | fn into_result(self) -> Result<T, NoneError> { | ||
| 218 | self.ok_or(NoneError) | ||
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 222 | impl<T, E> Try for Result<T, E> { | ||
| 223 | type Ok = T; | ||
| 224 | type Error = E; | ||
| 225 | |||
| 226 | #[inline] | ||
| 227 | fn into_result(self) -> Self { | ||
| 228 | self | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | #[allow(unused)] | ||
| 233 | pub(crate) struct Bytes<'a>(pub &'a [u8]); | ||
| 234 | |||
| 235 | impl<'a> Debug for Bytes<'a> { | ||
| 236 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| 237 | write!(f, "{:#02x?}", self.0) | ||
| 238 | } | ||
| 239 | } | ||
| 240 | |||
| 241 | impl<'a> Display for Bytes<'a> { | ||
| 242 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| 243 | write!(f, "{:#02x?}", self.0) | ||
| 244 | } | ||
| 245 | } | ||
| 246 | |||
| 247 | impl<'a> LowerHex for Bytes<'a> { | ||
| 248 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| 249 | write!(f, "{:#02x?}", self.0) | ||
| 250 | } | ||
| 251 | } | ||
| 252 | |||
| 253 | #[cfg(feature = "defmt")] | ||
| 254 | impl<'a> defmt::Format for Bytes<'a> { | ||
| 255 | fn format(&self, fmt: defmt::Formatter) { | ||
| 256 | defmt::write!(fmt, "{:02x}", self.0) | ||
| 257 | } | ||
| 258 | } | ||
diff --git a/embassy-lora/src/iv.rs b/embassy-lora/src/iv.rs deleted file mode 100644 index d22beb337..000000000 --- a/embassy-lora/src/iv.rs +++ /dev/null | |||
| @@ -1,317 +0,0 @@ | |||
| 1 | #[cfg(feature = "stm32wl")] | ||
| 2 | use embassy_stm32::interrupt; | ||
| 3 | #[cfg(feature = "stm32wl")] | ||
| 4 | use embassy_stm32::interrupt::InterruptExt; | ||
| 5 | #[cfg(feature = "stm32wl")] | ||
| 6 | use embassy_stm32::pac; | ||
| 7 | #[cfg(feature = "stm32wl")] | ||
| 8 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 9 | #[cfg(feature = "stm32wl")] | ||
| 10 | use embassy_sync::signal::Signal; | ||
| 11 | use embedded_hal::digital::v2::OutputPin; | ||
| 12 | use embedded_hal_async::delay::DelayUs; | ||
| 13 | use embedded_hal_async::digital::Wait; | ||
| 14 | use lora_phy::mod_params::RadioError::*; | ||
| 15 | use lora_phy::mod_params::{BoardType, RadioError}; | ||
| 16 | use lora_phy::mod_traits::InterfaceVariant; | ||
| 17 | |||
| 18 | /// Interrupt handler. | ||
| 19 | #[cfg(feature = "stm32wl")] | ||
| 20 | pub struct InterruptHandler {} | ||
| 21 | |||
| 22 | #[cfg(feature = "stm32wl")] | ||
| 23 | impl interrupt::typelevel::Handler<interrupt::typelevel::SUBGHZ_RADIO> for InterruptHandler { | ||
| 24 | unsafe fn on_interrupt() { | ||
| 25 | interrupt::SUBGHZ_RADIO.disable(); | ||
| 26 | IRQ_SIGNAL.signal(()); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | #[cfg(feature = "stm32wl")] | ||
| 31 | static IRQ_SIGNAL: Signal<CriticalSectionRawMutex, ()> = Signal::new(); | ||
| 32 | |||
| 33 | #[cfg(feature = "stm32wl")] | ||
| 34 | /// Base for the InterfaceVariant implementation for an stm32wl/sx1262 combination | ||
| 35 | pub struct Stm32wlInterfaceVariant<CTRL> { | ||
| 36 | board_type: BoardType, | ||
| 37 | rf_switch_rx: Option<CTRL>, | ||
| 38 | rf_switch_tx: Option<CTRL>, | ||
| 39 | } | ||
| 40 | |||
| 41 | #[cfg(feature = "stm32wl")] | ||
| 42 | impl<'a, CTRL> Stm32wlInterfaceVariant<CTRL> | ||
| 43 | where | ||
| 44 | CTRL: OutputPin, | ||
| 45 | { | ||
| 46 | /// Create an InterfaceVariant instance for an stm32wl/sx1262 combination | ||
| 47 | pub fn new( | ||
| 48 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::SUBGHZ_RADIO, InterruptHandler>, | ||
| 49 | rf_switch_rx: Option<CTRL>, | ||
| 50 | rf_switch_tx: Option<CTRL>, | ||
| 51 | ) -> Result<Self, RadioError> { | ||
| 52 | interrupt::SUBGHZ_RADIO.disable(); | ||
| 53 | Ok(Self { | ||
| 54 | board_type: BoardType::Stm32wlSx1262, // updated when associated with a specific LoRa board | ||
| 55 | rf_switch_rx, | ||
| 56 | rf_switch_tx, | ||
| 57 | }) | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | #[cfg(feature = "stm32wl")] | ||
| 62 | impl<CTRL> InterfaceVariant for Stm32wlInterfaceVariant<CTRL> | ||
| 63 | where | ||
| 64 | CTRL: OutputPin, | ||
| 65 | { | ||
| 66 | fn set_board_type(&mut self, board_type: BoardType) { | ||
| 67 | self.board_type = board_type; | ||
| 68 | } | ||
| 69 | async fn set_nss_low(&mut self) -> Result<(), RadioError> { | ||
| 70 | pac::PWR.subghzspicr().modify(|w| w.set_nss(false)); | ||
| 71 | Ok(()) | ||
| 72 | } | ||
| 73 | async fn set_nss_high(&mut self) -> Result<(), RadioError> { | ||
| 74 | pac::PWR.subghzspicr().modify(|w| w.set_nss(true)); | ||
| 75 | Ok(()) | ||
| 76 | } | ||
| 77 | async fn reset(&mut self, _delay: &mut impl DelayUs) -> Result<(), RadioError> { | ||
| 78 | pac::RCC.csr().modify(|w| w.set_rfrst(true)); | ||
| 79 | pac::RCC.csr().modify(|w| w.set_rfrst(false)); | ||
| 80 | Ok(()) | ||
| 81 | } | ||
| 82 | async fn wait_on_busy(&mut self) -> Result<(), RadioError> { | ||
| 83 | while pac::PWR.sr2().read().rfbusys() {} | ||
| 84 | Ok(()) | ||
| 85 | } | ||
| 86 | |||
| 87 | async fn await_irq(&mut self) -> Result<(), RadioError> { | ||
| 88 | unsafe { interrupt::SUBGHZ_RADIO.enable() }; | ||
| 89 | IRQ_SIGNAL.wait().await; | ||
| 90 | Ok(()) | ||
| 91 | } | ||
| 92 | |||
| 93 | async fn enable_rf_switch_rx(&mut self) -> Result<(), RadioError> { | ||
| 94 | match &mut self.rf_switch_tx { | ||
| 95 | Some(pin) => pin.set_low().map_err(|_| RfSwitchTx)?, | ||
| 96 | None => (), | ||
| 97 | }; | ||
| 98 | match &mut self.rf_switch_rx { | ||
| 99 | Some(pin) => pin.set_high().map_err(|_| RfSwitchRx), | ||
| 100 | None => Ok(()), | ||
| 101 | } | ||
| 102 | } | ||
| 103 | async fn enable_rf_switch_tx(&mut self) -> Result<(), RadioError> { | ||
| 104 | match &mut self.rf_switch_rx { | ||
| 105 | Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, | ||
| 106 | None => (), | ||
| 107 | }; | ||
| 108 | match &mut self.rf_switch_tx { | ||
| 109 | Some(pin) => pin.set_high().map_err(|_| RfSwitchTx), | ||
| 110 | None => Ok(()), | ||
| 111 | } | ||
| 112 | } | ||
| 113 | async fn disable_rf_switch(&mut self) -> Result<(), RadioError> { | ||
| 114 | match &mut self.rf_switch_rx { | ||
| 115 | Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, | ||
| 116 | None => (), | ||
| 117 | }; | ||
| 118 | match &mut self.rf_switch_tx { | ||
| 119 | Some(pin) => pin.set_low().map_err(|_| RfSwitchTx), | ||
| 120 | None => Ok(()), | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | /// Base for the InterfaceVariant implementation for an stm32l0/sx1276 combination | ||
| 126 | pub struct Stm32l0InterfaceVariant<CTRL, WAIT> { | ||
| 127 | board_type: BoardType, | ||
| 128 | nss: CTRL, | ||
| 129 | reset: CTRL, | ||
| 130 | irq: WAIT, | ||
| 131 | rf_switch_rx: Option<CTRL>, | ||
| 132 | rf_switch_tx: Option<CTRL>, | ||
| 133 | } | ||
| 134 | |||
| 135 | impl<CTRL, WAIT> Stm32l0InterfaceVariant<CTRL, WAIT> | ||
| 136 | where | ||
| 137 | CTRL: OutputPin, | ||
| 138 | WAIT: Wait, | ||
| 139 | { | ||
| 140 | /// Create an InterfaceVariant instance for an stm32l0/sx1276 combination | ||
| 141 | pub fn new( | ||
| 142 | nss: CTRL, | ||
| 143 | reset: CTRL, | ||
| 144 | irq: WAIT, | ||
| 145 | rf_switch_rx: Option<CTRL>, | ||
| 146 | rf_switch_tx: Option<CTRL>, | ||
| 147 | ) -> Result<Self, RadioError> { | ||
| 148 | Ok(Self { | ||
| 149 | board_type: BoardType::Stm32l0Sx1276, // updated when associated with a specific LoRa board | ||
| 150 | nss, | ||
| 151 | reset, | ||
| 152 | irq, | ||
| 153 | rf_switch_rx, | ||
| 154 | rf_switch_tx, | ||
| 155 | }) | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | impl<CTRL, WAIT> InterfaceVariant for Stm32l0InterfaceVariant<CTRL, WAIT> | ||
| 160 | where | ||
| 161 | CTRL: OutputPin, | ||
| 162 | WAIT: Wait, | ||
| 163 | { | ||
| 164 | fn set_board_type(&mut self, board_type: BoardType) { | ||
| 165 | self.board_type = board_type; | ||
| 166 | } | ||
| 167 | async fn set_nss_low(&mut self) -> Result<(), RadioError> { | ||
| 168 | self.nss.set_low().map_err(|_| NSS) | ||
| 169 | } | ||
| 170 | async fn set_nss_high(&mut self) -> Result<(), RadioError> { | ||
| 171 | self.nss.set_high().map_err(|_| NSS) | ||
| 172 | } | ||
| 173 | async fn reset(&mut self, delay: &mut impl DelayUs) -> Result<(), RadioError> { | ||
| 174 | delay.delay_ms(10).await; | ||
| 175 | self.reset.set_low().map_err(|_| Reset)?; | ||
| 176 | delay.delay_ms(10).await; | ||
| 177 | self.reset.set_high().map_err(|_| Reset)?; | ||
| 178 | delay.delay_ms(10).await; | ||
| 179 | Ok(()) | ||
| 180 | } | ||
| 181 | async fn wait_on_busy(&mut self) -> Result<(), RadioError> { | ||
| 182 | Ok(()) | ||
| 183 | } | ||
| 184 | async fn await_irq(&mut self) -> Result<(), RadioError> { | ||
| 185 | self.irq.wait_for_high().await.map_err(|_| Irq) | ||
| 186 | } | ||
| 187 | |||
| 188 | async fn enable_rf_switch_rx(&mut self) -> Result<(), RadioError> { | ||
| 189 | match &mut self.rf_switch_tx { | ||
| 190 | Some(pin) => pin.set_low().map_err(|_| RfSwitchTx)?, | ||
| 191 | None => (), | ||
| 192 | }; | ||
| 193 | match &mut self.rf_switch_rx { | ||
| 194 | Some(pin) => pin.set_high().map_err(|_| RfSwitchRx), | ||
| 195 | None => Ok(()), | ||
| 196 | } | ||
| 197 | } | ||
| 198 | async fn enable_rf_switch_tx(&mut self) -> Result<(), RadioError> { | ||
| 199 | match &mut self.rf_switch_rx { | ||
| 200 | Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, | ||
| 201 | None => (), | ||
| 202 | }; | ||
| 203 | match &mut self.rf_switch_tx { | ||
| 204 | Some(pin) => pin.set_high().map_err(|_| RfSwitchTx), | ||
| 205 | None => Ok(()), | ||
| 206 | } | ||
| 207 | } | ||
| 208 | async fn disable_rf_switch(&mut self) -> Result<(), RadioError> { | ||
| 209 | match &mut self.rf_switch_rx { | ||
| 210 | Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, | ||
| 211 | None => (), | ||
| 212 | }; | ||
| 213 | match &mut self.rf_switch_tx { | ||
| 214 | Some(pin) => pin.set_low().map_err(|_| RfSwitchTx), | ||
| 215 | None => Ok(()), | ||
| 216 | } | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | /// Base for the InterfaceVariant implementation for a generic Sx126x LoRa board | ||
| 221 | pub struct GenericSx126xInterfaceVariant<CTRL, WAIT> { | ||
| 222 | board_type: BoardType, | ||
| 223 | nss: CTRL, | ||
| 224 | reset: CTRL, | ||
| 225 | dio1: WAIT, | ||
| 226 | busy: WAIT, | ||
| 227 | rf_switch_rx: Option<CTRL>, | ||
| 228 | rf_switch_tx: Option<CTRL>, | ||
| 229 | } | ||
| 230 | |||
| 231 | impl<CTRL, WAIT> GenericSx126xInterfaceVariant<CTRL, WAIT> | ||
| 232 | where | ||
| 233 | CTRL: OutputPin, | ||
| 234 | WAIT: Wait, | ||
| 235 | { | ||
| 236 | /// Create an InterfaceVariant instance for an nrf52840/sx1262 combination | ||
| 237 | pub fn new( | ||
| 238 | nss: CTRL, | ||
| 239 | reset: CTRL, | ||
| 240 | dio1: WAIT, | ||
| 241 | busy: WAIT, | ||
| 242 | rf_switch_rx: Option<CTRL>, | ||
| 243 | rf_switch_tx: Option<CTRL>, | ||
| 244 | ) -> Result<Self, RadioError> { | ||
| 245 | Ok(Self { | ||
| 246 | board_type: BoardType::Rak4631Sx1262, // updated when associated with a specific LoRa board | ||
| 247 | nss, | ||
| 248 | reset, | ||
| 249 | dio1, | ||
| 250 | busy, | ||
| 251 | rf_switch_rx, | ||
| 252 | rf_switch_tx, | ||
| 253 | }) | ||
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 257 | impl<CTRL, WAIT> InterfaceVariant for GenericSx126xInterfaceVariant<CTRL, WAIT> | ||
| 258 | where | ||
| 259 | CTRL: OutputPin, | ||
| 260 | WAIT: Wait, | ||
| 261 | { | ||
| 262 | fn set_board_type(&mut self, board_type: BoardType) { | ||
| 263 | self.board_type = board_type; | ||
| 264 | } | ||
| 265 | async fn set_nss_low(&mut self) -> Result<(), RadioError> { | ||
| 266 | self.nss.set_low().map_err(|_| NSS) | ||
| 267 | } | ||
| 268 | async fn set_nss_high(&mut self) -> Result<(), RadioError> { | ||
| 269 | self.nss.set_high().map_err(|_| NSS) | ||
| 270 | } | ||
| 271 | async fn reset(&mut self, delay: &mut impl DelayUs) -> Result<(), RadioError> { | ||
| 272 | delay.delay_ms(10).await; | ||
| 273 | self.reset.set_low().map_err(|_| Reset)?; | ||
| 274 | delay.delay_ms(20).await; | ||
| 275 | self.reset.set_high().map_err(|_| Reset)?; | ||
| 276 | delay.delay_ms(10).await; | ||
| 277 | Ok(()) | ||
| 278 | } | ||
| 279 | async fn wait_on_busy(&mut self) -> Result<(), RadioError> { | ||
| 280 | self.busy.wait_for_low().await.map_err(|_| Busy) | ||
| 281 | } | ||
| 282 | async fn await_irq(&mut self) -> Result<(), RadioError> { | ||
| 283 | self.dio1.wait_for_high().await.map_err(|_| DIO1)?; | ||
| 284 | Ok(()) | ||
| 285 | } | ||
| 286 | |||
| 287 | async fn enable_rf_switch_rx(&mut self) -> Result<(), RadioError> { | ||
| 288 | match &mut self.rf_switch_tx { | ||
| 289 | Some(pin) => pin.set_low().map_err(|_| RfSwitchTx)?, | ||
| 290 | None => (), | ||
| 291 | }; | ||
| 292 | match &mut self.rf_switch_rx { | ||
| 293 | Some(pin) => pin.set_high().map_err(|_| RfSwitchRx), | ||
| 294 | None => Ok(()), | ||
| 295 | } | ||
| 296 | } | ||
| 297 | async fn enable_rf_switch_tx(&mut self) -> Result<(), RadioError> { | ||
| 298 | match &mut self.rf_switch_rx { | ||
| 299 | Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, | ||
| 300 | None => (), | ||
| 301 | }; | ||
| 302 | match &mut self.rf_switch_tx { | ||
| 303 | Some(pin) => pin.set_high().map_err(|_| RfSwitchTx), | ||
| 304 | None => Ok(()), | ||
| 305 | } | ||
| 306 | } | ||
| 307 | async fn disable_rf_switch(&mut self) -> Result<(), RadioError> { | ||
| 308 | match &mut self.rf_switch_rx { | ||
| 309 | Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, | ||
| 310 | None => (), | ||
| 311 | }; | ||
| 312 | match &mut self.rf_switch_tx { | ||
| 313 | Some(pin) => pin.set_low().map_err(|_| RfSwitchTx), | ||
| 314 | None => Ok(()), | ||
| 315 | } | ||
| 316 | } | ||
| 317 | } | ||
diff --git a/embassy-lora/src/lib.rs b/embassy-lora/src/lib.rs deleted file mode 100644 index 653c98253..000000000 --- a/embassy-lora/src/lib.rs +++ /dev/null | |||
| @@ -1,40 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![feature(async_fn_in_trait, impl_trait_projections)] | ||
| 3 | #![allow(stable_features, unknown_lints, async_fn_in_trait)] | ||
| 4 | //! embassy-lora holds LoRa-specific functionality. | ||
| 5 | |||
| 6 | pub(crate) mod fmt; | ||
| 7 | |||
| 8 | /// interface variants required by the external lora physical layer crate (lora-phy) | ||
| 9 | pub mod iv; | ||
| 10 | |||
| 11 | #[cfg(feature = "time")] | ||
| 12 | use embassy_time::{Duration, Instant, Timer}; | ||
| 13 | |||
| 14 | /// A convenience timer to use with the LoRaWAN crate | ||
| 15 | #[cfg(feature = "time")] | ||
| 16 | pub struct LoraTimer { | ||
| 17 | start: Instant, | ||
| 18 | } | ||
| 19 | |||
| 20 | #[cfg(feature = "time")] | ||
| 21 | impl LoraTimer { | ||
| 22 | pub fn new() -> Self { | ||
| 23 | Self { start: Instant::now() } | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | #[cfg(feature = "time")] | ||
| 28 | impl lorawan_device::async_device::radio::Timer for LoraTimer { | ||
| 29 | fn reset(&mut self) { | ||
| 30 | self.start = Instant::now(); | ||
| 31 | } | ||
| 32 | |||
| 33 | async fn at(&mut self, millis: u64) { | ||
| 34 | Timer::at(self.start + Duration::from_millis(millis)).await | ||
| 35 | } | ||
| 36 | |||
| 37 | async fn delay_ms(&mut self, millis: u64) { | ||
| 38 | Timer::after_millis(millis).await | ||
| 39 | } | ||
| 40 | } | ||
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml index df5b1f3b5..88e8d58d1 100644 --- a/examples/nrf52840/Cargo.toml +++ b/examples/nrf52840/Cargo.toml | |||
| @@ -21,10 +21,6 @@ nightly = [ | |||
| 21 | "embedded-io-async", | 21 | "embedded-io-async", |
| 22 | "embedded-hal-bus/async", | 22 | "embedded-hal-bus/async", |
| 23 | "embassy-net", | 23 | "embassy-net", |
| 24 | "embassy-lora", | ||
| 25 | "lora-phy", | ||
| 26 | "lorawan-device", | ||
| 27 | "lorawan", | ||
| 28 | ] | 24 | ] |
| 29 | 25 | ||
| 30 | [dependencies] | 26 | [dependencies] |
| @@ -37,10 +33,6 @@ embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defm | |||
| 37 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } | 33 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } |
| 38 | embedded-io = { version = "0.6.0", features = ["defmt-03"] } | 34 | embedded-io = { version = "0.6.0", features = ["defmt-03"] } |
| 39 | embedded-io-async = { version = "0.6.0", optional = true, features = ["defmt-03"] } | 35 | embedded-io-async = { version = "0.6.0", optional = true, features = ["defmt-03"] } |
| 40 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true } | ||
| 41 | lora-phy = { version = "2", optional = true } | ||
| 42 | lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"], optional = true } | ||
| 43 | lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"], optional = true } | ||
| 44 | embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"], optional = true } | 36 | embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"], optional = true } |
| 45 | embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"], optional = true } | 37 | embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"], optional = true } |
| 46 | 38 | ||
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 | } | ||
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 7e752bad2..1012a8b5f 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml | |||
| @@ -16,10 +16,6 @@ embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defm | |||
| 16 | embassy-net-wiznet = { version = "0.1.0", path = "../../embassy-net-wiznet", features = ["defmt"] } | 16 | embassy-net-wiznet = { version = "0.1.0", path = "../../embassy-net-wiznet", features = ["defmt"] } |
| 17 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 17 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 18 | embassy-usb-logger = { version = "0.1.0", path = "../../embassy-usb-logger" } | 18 | embassy-usb-logger = { version = "0.1.0", path = "../../embassy-usb-logger" } |
| 19 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"] } | ||
| 20 | lora-phy = { version = "2" } | ||
| 21 | lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"] } | ||
| 22 | lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"] } | ||
| 23 | cyw43 = { path = "../../cyw43", features = ["defmt", "firmware-logs"] } | 19 | cyw43 = { path = "../../cyw43", features = ["defmt", "firmware-logs"] } |
| 24 | cyw43-pio = { path = "../../cyw43-pio", features = ["defmt", "overclock"] } | 20 | cyw43-pio = { path = "../../cyw43-pio", features = ["defmt", "overclock"] } |
| 25 | 21 | ||
diff --git a/examples/rp/src/bin/lora_lorawan.rs b/examples/rp/src/bin/lora_lorawan.rs deleted file mode 100644 index e7e81863e..000000000 --- a/examples/rp/src/bin/lora_lorawan.rs +++ /dev/null | |||
| @@ -1,74 +0,0 @@ | |||
| 1 | //! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. | ||
| 2 | //! It demonstrates LoRaWAN join functionality. | ||
| 3 | |||
| 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_rp::gpio::{Input, Level, Output, Pin, Pull}; | ||
| 14 | use embassy_rp::spi::{Config, Spi}; | ||
| 15 | use embassy_time::Delay; | ||
| 16 | use lora_phy::mod_params::*; | ||
| 17 | use lora_phy::sx1261_2::SX1261_2; | ||
| 18 | use lora_phy::LoRa; | ||
| 19 | use lorawan::default_crypto::DefaultFactory as Crypto; | ||
| 20 | use lorawan_device::async_device::lora_radio::LoRaRadio; | ||
| 21 | use lorawan_device::async_device::{region, Device, JoinMode}; | ||
| 22 | use lorawan_device::{AppEui, AppKey, DevEui}; | ||
| 23 | use {defmt_rtt as _, panic_probe as _}; | ||
| 24 | |||
| 25 | const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region | ||
| 26 | |||
| 27 | #[embassy_executor::main] | ||
| 28 | async fn main(_spawner: Spawner) { | ||
| 29 | let p = embassy_rp::init(Default::default()); | ||
| 30 | |||
| 31 | let miso = p.PIN_12; | ||
| 32 | let mosi = p.PIN_11; | ||
| 33 | let clk = p.PIN_10; | ||
| 34 | let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); | ||
| 35 | |||
| 36 | let nss = Output::new(p.PIN_3.degrade(), Level::High); | ||
| 37 | let reset = Output::new(p.PIN_15.degrade(), Level::High); | ||
| 38 | let dio1 = Input::new(p.PIN_20.degrade(), Pull::None); | ||
| 39 | let busy = Input::new(p.PIN_2.degrade(), Pull::None); | ||
| 40 | |||
| 41 | let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap(); | ||
| 42 | |||
| 43 | let lora = { | ||
| 44 | match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, spi, iv), true, Delay).await { | ||
| 45 | Ok(l) => l, | ||
| 46 | Err(err) => { | ||
| 47 | info!("Radio error = {}", err); | ||
| 48 | return; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | }; | ||
| 52 | |||
| 53 | let radio = LoRaRadio::new(lora); | ||
| 54 | let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); | ||
| 55 | let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), embassy_rp::clocks::RoscRng); | ||
| 56 | |||
| 57 | defmt::info!("Joining LoRaWAN network"); | ||
| 58 | |||
| 59 | // TODO: Adjust the EUI and Keys according to your network credentials | ||
| 60 | match device | ||
| 61 | .join(&JoinMode::OTAA { | ||
| 62 | deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 63 | appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 64 | appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 65 | }) | ||
| 66 | .await | ||
| 67 | { | ||
| 68 | Ok(()) => defmt::info!("LoRaWAN network joined"), | ||
| 69 | Err(err) => { | ||
| 70 | info!("Radio error = {}", err); | ||
| 71 | return; | ||
| 72 | } | ||
| 73 | }; | ||
| 74 | } | ||
diff --git a/examples/rp/src/bin/lora_p2p_receive.rs b/examples/rp/src/bin/lora_p2p_receive.rs deleted file mode 100644 index d5843fdcd..000000000 --- a/examples/rp/src/bin/lora_p2p_receive.rs +++ /dev/null | |||
| @@ -1,108 +0,0 @@ | |||
| 1 | //! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. | ||
| 2 | //! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example. | ||
| 3 | |||
| 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_rp::gpio::{Input, Level, Output, Pin, Pull}; | ||
| 13 | use embassy_rp::spi::{Config, Spi}; | ||
| 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 | #[embassy_executor::main] | ||
| 23 | async fn main(_spawner: Spawner) { | ||
| 24 | let p = embassy_rp::init(Default::default()); | ||
| 25 | |||
| 26 | let miso = p.PIN_12; | ||
| 27 | let mosi = p.PIN_11; | ||
| 28 | let clk = p.PIN_10; | ||
| 29 | let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); | ||
| 30 | |||
| 31 | let nss = Output::new(p.PIN_3.degrade(), Level::High); | ||
| 32 | let reset = Output::new(p.PIN_15.degrade(), Level::High); | ||
| 33 | let dio1 = Input::new(p.PIN_20.degrade(), Pull::None); | ||
| 34 | let busy = Input::new(p.PIN_2.degrade(), Pull::None); | ||
| 35 | |||
| 36 | let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap(); | ||
| 37 | |||
| 38 | let mut lora = { | ||
| 39 | match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, spi, iv), false, Delay).await { | ||
| 40 | Ok(l) => l, | ||
| 41 | Err(err) => { | ||
| 42 | info!("Radio error = {}", err); | ||
| 43 | return; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | }; | ||
| 47 | |||
| 48 | let mut debug_indicator = Output::new(p.PIN_25, Level::Low); | ||
| 49 | |||
| 50 | let mut receiving_buffer = [00u8; 100]; | ||
| 51 | |||
| 52 | let mdltn_params = { | ||
| 53 | match lora.create_modulation_params( | ||
| 54 | SpreadingFactor::_10, | ||
| 55 | Bandwidth::_250KHz, | ||
| 56 | CodingRate::_4_8, | ||
| 57 | LORA_FREQUENCY_IN_HZ, | ||
| 58 | ) { | ||
| 59 | Ok(mp) => mp, | ||
| 60 | Err(err) => { | ||
| 61 | info!("Radio error = {}", err); | ||
| 62 | return; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | }; | ||
| 66 | |||
| 67 | let rx_pkt_params = { | ||
| 68 | match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) { | ||
| 69 | Ok(pp) => pp, | ||
| 70 | Err(err) => { | ||
| 71 | info!("Radio error = {}", err); | ||
| 72 | return; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | }; | ||
| 76 | |||
| 77 | match lora | ||
| 78 | .prepare_for_rx(&mdltn_params, &rx_pkt_params, None, None, false) | ||
| 79 | .await | ||
| 80 | { | ||
| 81 | Ok(()) => {} | ||
| 82 | Err(err) => { | ||
| 83 | info!("Radio error = {}", err); | ||
| 84 | return; | ||
| 85 | } | ||
| 86 | }; | ||
| 87 | |||
| 88 | loop { | ||
| 89 | receiving_buffer = [00u8; 100]; | ||
| 90 | match lora.rx(&rx_pkt_params, &mut receiving_buffer).await { | ||
| 91 | Ok((received_len, _rx_pkt_status)) => { | ||
| 92 | if (received_len == 3) | ||
| 93 | && (receiving_buffer[0] == 0x01u8) | ||
| 94 | && (receiving_buffer[1] == 0x02u8) | ||
| 95 | && (receiving_buffer[2] == 0x03u8) | ||
| 96 | { | ||
| 97 | info!("rx successful"); | ||
| 98 | debug_indicator.set_high(); | ||
| 99 | Timer::after_secs(5).await; | ||
| 100 | debug_indicator.set_low(); | ||
| 101 | } else { | ||
| 102 | info!("rx unknown packet"); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | Err(err) => info!("rx unsuccessful = {}", err), | ||
| 106 | } | ||
| 107 | } | ||
| 108 | } | ||
diff --git a/examples/rp/src/bin/lora_p2p_send.rs b/examples/rp/src/bin/lora_p2p_send.rs deleted file mode 100644 index 94bdb4e92..000000000 --- a/examples/rp/src/bin/lora_p2p_send.rs +++ /dev/null | |||
| @@ -1,96 +0,0 @@ | |||
| 1 | //! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. | ||
| 2 | //! It demonstrates LORA P2P send functionality. | ||
| 3 | |||
| 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_rp::gpio::{Input, Level, Output, Pin, Pull}; | ||
| 13 | use embassy_rp::spi::{Config, Spi}; | ||
| 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 | #[embassy_executor::main] | ||
| 23 | async fn main(_spawner: Spawner) { | ||
| 24 | let p = embassy_rp::init(Default::default()); | ||
| 25 | |||
| 26 | let miso = p.PIN_12; | ||
| 27 | let mosi = p.PIN_11; | ||
| 28 | let clk = p.PIN_10; | ||
| 29 | let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); | ||
| 30 | |||
| 31 | let nss = Output::new(p.PIN_3.degrade(), Level::High); | ||
| 32 | let reset = Output::new(p.PIN_15.degrade(), Level::High); | ||
| 33 | let dio1 = Input::new(p.PIN_20.degrade(), Pull::None); | ||
| 34 | let busy = Input::new(p.PIN_2.degrade(), Pull::None); | ||
| 35 | |||
| 36 | let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap(); | ||
| 37 | |||
| 38 | let mut lora = { | ||
| 39 | match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, spi, iv), false, Delay).await { | ||
| 40 | Ok(l) => l, | ||
| 41 | Err(err) => { | ||
| 42 | info!("Radio error = {}", err); | ||
| 43 | return; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | }; | ||
| 47 | |||
| 48 | let mdltn_params = { | ||
| 49 | match lora.create_modulation_params( | ||
| 50 | SpreadingFactor::_10, | ||
| 51 | Bandwidth::_250KHz, | ||
| 52 | CodingRate::_4_8, | ||
| 53 | LORA_FREQUENCY_IN_HZ, | ||
| 54 | ) { | ||
| 55 | Ok(mp) => mp, | ||
| 56 | Err(err) => { | ||
| 57 | info!("Radio error = {}", err); | ||
| 58 | return; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | }; | ||
| 62 | |||
| 63 | let mut tx_pkt_params = { | ||
| 64 | match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) { | ||
| 65 | Ok(pp) => pp, | ||
| 66 | Err(err) => { | ||
| 67 | info!("Radio error = {}", err); | ||
| 68 | return; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | }; | ||
| 72 | |||
| 73 | match lora.prepare_for_tx(&mdltn_params, 20, false).await { | ||
| 74 | Ok(()) => {} | ||
| 75 | Err(err) => { | ||
| 76 | info!("Radio error = {}", err); | ||
| 77 | return; | ||
| 78 | } | ||
| 79 | }; | ||
| 80 | |||
| 81 | let buffer = [0x01u8, 0x02u8, 0x03u8]; | ||
| 82 | match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await { | ||
| 83 | Ok(()) => { | ||
| 84 | info!("TX DONE"); | ||
| 85 | } | ||
| 86 | Err(err) => { | ||
| 87 | info!("Radio error = {}", err); | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | }; | ||
| 91 | |||
| 92 | match lora.sleep(false).await { | ||
| 93 | Ok(()) => info!("Sleep successful"), | ||
| 94 | Err(err) => info!("Sleep unsuccessful = {}", err), | ||
| 95 | } | ||
| 96 | } | ||
diff --git a/examples/rp/src/bin/lora_p2p_send_multicore.rs b/examples/rp/src/bin/lora_p2p_send_multicore.rs deleted file mode 100644 index ccf44987c..000000000 --- a/examples/rp/src/bin/lora_p2p_send_multicore.rs +++ /dev/null | |||
| @@ -1,133 +0,0 @@ | |||
| 1 | //! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. | ||
| 2 | //! It demonstrates LORA P2P send functionality using the second core, with data provided by the first core. | ||
| 3 | |||
| 4 | #![no_std] | ||
| 5 | #![no_main] | ||
| 6 | #![macro_use] | ||
| 7 | #![feature(type_alias_impl_trait)] | ||
| 8 | |||
| 9 | use defmt::*; | ||
| 10 | use embassy_executor::Executor; | ||
| 11 | use embassy_lora::iv::GenericSx126xInterfaceVariant; | ||
| 12 | use embassy_rp::gpio::{AnyPin, Input, Level, Output, Pin, Pull}; | ||
| 13 | use embassy_rp::multicore::{spawn_core1, Stack}; | ||
| 14 | use embassy_rp::peripherals::SPI1; | ||
| 15 | use embassy_rp::spi::{Async, Config, Spi}; | ||
| 16 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 17 | use embassy_sync::channel::Channel; | ||
| 18 | use embassy_time::{Delay, Timer}; | ||
| 19 | use lora_phy::mod_params::*; | ||
| 20 | use lora_phy::sx1261_2::SX1261_2; | ||
| 21 | use lora_phy::LoRa; | ||
| 22 | use static_cell::StaticCell; | ||
| 23 | use {defmt_rtt as _, panic_probe as _}; | ||
| 24 | |||
| 25 | static mut CORE1_STACK: Stack<4096> = Stack::new(); | ||
| 26 | static EXECUTOR0: StaticCell<Executor> = StaticCell::new(); | ||
| 27 | static EXECUTOR1: StaticCell<Executor> = StaticCell::new(); | ||
| 28 | static CHANNEL: Channel<CriticalSectionRawMutex, [u8; 3], 1> = Channel::new(); | ||
| 29 | |||
| 30 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 31 | |||
| 32 | #[cortex_m_rt::entry] | ||
| 33 | fn main() -> ! { | ||
| 34 | let p = embassy_rp::init(Default::default()); | ||
| 35 | |||
| 36 | let miso = p.PIN_12; | ||
| 37 | let mosi = p.PIN_11; | ||
| 38 | let clk = p.PIN_10; | ||
| 39 | let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); | ||
| 40 | |||
| 41 | let nss = Output::new(p.PIN_3.degrade(), Level::High); | ||
| 42 | let reset = Output::new(p.PIN_15.degrade(), Level::High); | ||
| 43 | let dio1 = Input::new(p.PIN_20.degrade(), Pull::None); | ||
| 44 | let busy = Input::new(p.PIN_2.degrade(), Pull::None); | ||
| 45 | |||
| 46 | let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap(); | ||
| 47 | |||
| 48 | spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || { | ||
| 49 | let executor1 = EXECUTOR1.init(Executor::new()); | ||
| 50 | executor1.run(|spawner| unwrap!(spawner.spawn(core1_task(spi, iv)))); | ||
| 51 | }); | ||
| 52 | |||
| 53 | let executor0 = EXECUTOR0.init(Executor::new()); | ||
| 54 | executor0.run(|spawner| unwrap!(spawner.spawn(core0_task()))); | ||
| 55 | } | ||
| 56 | |||
| 57 | #[embassy_executor::task] | ||
| 58 | async fn core0_task() { | ||
| 59 | info!("Hello from core 0"); | ||
| 60 | loop { | ||
| 61 | CHANNEL.send([0x01u8, 0x02u8, 0x03u8]).await; | ||
| 62 | Timer::after_millis(60 * 1000).await; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | #[embassy_executor::task] | ||
| 67 | async fn core1_task( | ||
| 68 | spi: Spi<'static, SPI1, Async>, | ||
| 69 | iv: GenericSx126xInterfaceVariant<Output<'static, AnyPin>, Input<'static, AnyPin>>, | ||
| 70 | ) { | ||
| 71 | info!("Hello from core 1"); | ||
| 72 | |||
| 73 | let mut lora = { | ||
| 74 | match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, spi, iv), false, Delay).await { | ||
| 75 | Ok(l) => l, | ||
| 76 | Err(err) => { | ||
| 77 | info!("Radio error = {}", err); | ||
| 78 | return; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | |||
| 83 | let mdltn_params = { | ||
| 84 | match lora.create_modulation_params( | ||
| 85 | SpreadingFactor::_10, | ||
| 86 | Bandwidth::_250KHz, | ||
| 87 | CodingRate::_4_8, | ||
| 88 | LORA_FREQUENCY_IN_HZ, | ||
| 89 | ) { | ||
| 90 | Ok(mp) => mp, | ||
| 91 | Err(err) => { | ||
| 92 | info!("Radio error = {}", err); | ||
| 93 | return; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | }; | ||
| 97 | |||
| 98 | let mut tx_pkt_params = { | ||
| 99 | match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) { | ||
| 100 | Ok(pp) => pp, | ||
| 101 | Err(err) => { | ||
| 102 | info!("Radio error = {}", err); | ||
| 103 | return; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | }; | ||
| 107 | |||
| 108 | loop { | ||
| 109 | let buffer: [u8; 3] = CHANNEL.receive().await; | ||
| 110 | match lora.prepare_for_tx(&mdltn_params, 20, false).await { | ||
| 111 | Ok(()) => {} | ||
| 112 | Err(err) => { | ||
| 113 | info!("Radio error = {}", err); | ||
| 114 | return; | ||
| 115 | } | ||
| 116 | }; | ||
| 117 | |||
| 118 | match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await { | ||
| 119 | Ok(()) => { | ||
| 120 | info!("TX DONE"); | ||
| 121 | } | ||
| 122 | Err(err) => { | ||
| 123 | info!("Radio error = {}", err); | ||
| 124 | return; | ||
| 125 | } | ||
| 126 | }; | ||
| 127 | |||
| 128 | match lora.sleep(false).await { | ||
| 129 | Ok(()) => info!("Sleep successful"), | ||
| 130 | Err(err) => info!("Sleep unsuccessful = {}", err), | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index 2b89ac275..2ba58c3d0 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml | |||
| @@ -6,8 +6,7 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [features] | 7 | [features] |
| 8 | default = ["nightly"] | 8 | default = ["nightly"] |
| 9 | nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstable-traits", "embassy-executor/nightly", | 9 | nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstable-traits", "embassy-executor/nightly", "dep:embedded-io-async"] |
| 10 | "embassy-lora", "lora-phy", "lorawan-device", "lorawan", "dep:embedded-io-async"] | ||
| 11 | 10 | ||
| 12 | [dependencies] | 11 | [dependencies] |
| 13 | # Change stm32l072cz to your chip name, if necessary. | 12 | # Change stm32l072cz to your chip name, if necessary. |
| @@ -15,10 +14,6 @@ embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [" | |||
| 15 | embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["defmt"] } | 14 | embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["defmt"] } |
| 16 | embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 15 | embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 17 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 16 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 18 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true } | ||
| 19 | lora-phy = { version = "2", optional = true } | ||
| 20 | lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"], optional = true } | ||
| 21 | lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"], optional = true } | ||
| 22 | 17 | ||
| 23 | defmt = "0.3" | 18 | defmt = "0.3" |
| 24 | defmt-rtt = "0.4" | 19 | defmt-rtt = "0.4" |
diff --git a/examples/stm32l0/src/bin/lora_cad.rs b/examples/stm32l0/src/bin/lora_cad.rs deleted file mode 100644 index 8ca9e8b22..000000000 --- a/examples/stm32l0/src/bin/lora_cad.rs +++ /dev/null | |||
| @@ -1,97 +0,0 @@ | |||
| 1 | //! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio. | ||
| 2 | //! It demonstrates LORA P2P CAD functionality. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_lora::iv::Stm32l0InterfaceVariant; | ||
| 11 | use embassy_stm32::exti::{Channel, ExtiInput}; | ||
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; | ||
| 13 | use embassy_stm32::spi; | ||
| 14 | use embassy_stm32::time::khz; | ||
| 15 | use embassy_time::{Delay, Timer}; | ||
| 16 | use lora_phy::mod_params::*; | ||
| 17 | use lora_phy::sx1276_7_8_9::SX1276_7_8_9; | ||
| 18 | use lora_phy::LoRa; | ||
| 19 | use {defmt_rtt as _, panic_probe as _}; | ||
| 20 | |||
| 21 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 22 | |||
| 23 | #[embassy_executor::main] | ||
| 24 | async fn main(_spawner: Spawner) { | ||
| 25 | let mut config = embassy_stm32::Config::default(); | ||
| 26 | config.rcc.hsi = true; | ||
| 27 | config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI; | ||
| 28 | let p = embassy_stm32::init(config); | ||
| 29 | |||
| 30 | let mut spi_config = spi::Config::default(); | ||
| 31 | spi_config.frequency = khz(200); | ||
| 32 | |||
| 33 | // SPI for sx1276 | ||
| 34 | let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config); | ||
| 35 | |||
| 36 | let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); | ||
| 37 | let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); | ||
| 38 | |||
| 39 | let irq_pin = Input::new(p.PB4.degrade(), Pull::Up); | ||
| 40 | let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade()); | ||
| 41 | |||
| 42 | let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap(); | ||
| 43 | |||
| 44 | let mut lora = { | ||
| 45 | match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, 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.PB5, Level::Low, Speed::Low); | ||
| 55 | let mut start_indicator = Output::new(p.PB6, Level::Low, Speed::Low); | ||
| 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/stm32l0/src/bin/lora_lorawan.rs b/examples/stm32l0/src/bin/lora_lorawan.rs deleted file mode 100644 index 4365c4cf6..000000000 --- a/examples/stm32l0/src/bin/lora_lorawan.rs +++ /dev/null | |||
| @@ -1,85 +0,0 @@ | |||
| 1 | //! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio. | ||
| 2 | //! It demonstrates LoRaWAN join functionality. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_lora::iv::Stm32l0InterfaceVariant; | ||
| 11 | use embassy_lora::LoraTimer; | ||
| 12 | use embassy_stm32::exti::{Channel, ExtiInput}; | ||
| 13 | use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; | ||
| 14 | use embassy_stm32::rng::Rng; | ||
| 15 | use embassy_stm32::time::khz; | ||
| 16 | use embassy_stm32::{bind_interrupts, peripherals, rng, spi}; | ||
| 17 | use embassy_time::Delay; | ||
| 18 | use lora_phy::mod_params::*; | ||
| 19 | use lora_phy::sx1276_7_8_9::SX1276_7_8_9; | ||
| 20 | use lora_phy::LoRa; | ||
| 21 | use lorawan::default_crypto::DefaultFactory as Crypto; | ||
| 22 | use lorawan_device::async_device::lora_radio::LoRaRadio; | ||
| 23 | use lorawan_device::async_device::{region, Device, JoinMode}; | ||
| 24 | use lorawan_device::{AppEui, AppKey, DevEui}; | ||
| 25 | use {defmt_rtt as _, panic_probe as _}; | ||
| 26 | |||
| 27 | bind_interrupts!(struct Irqs { | ||
| 28 | RNG_LPUART1 => rng::InterruptHandler<peripherals::RNG>; | ||
| 29 | }); | ||
| 30 | |||
| 31 | const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region | ||
| 32 | |||
| 33 | #[embassy_executor::main] | ||
| 34 | async fn main(_spawner: Spawner) { | ||
| 35 | let mut config = embassy_stm32::Config::default(); | ||
| 36 | config.rcc.hsi = true; | ||
| 37 | config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI; | ||
| 38 | let p = embassy_stm32::init(config); | ||
| 39 | |||
| 40 | let mut spi_config = spi::Config::default(); | ||
| 41 | spi_config.frequency = khz(200); | ||
| 42 | |||
| 43 | // SPI for sx1276 | ||
| 44 | let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config); | ||
| 45 | |||
| 46 | let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); | ||
| 47 | let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); | ||
| 48 | |||
| 49 | let irq_pin = Input::new(p.PB4.degrade(), Pull::Up); | ||
| 50 | let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade()); | ||
| 51 | |||
| 52 | let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap(); | ||
| 53 | |||
| 54 | let lora = { | ||
| 55 | match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, iv), true, Delay).await { | ||
| 56 | Ok(l) => l, | ||
| 57 | Err(err) => { | ||
| 58 | info!("Radio error = {}", err); | ||
| 59 | return; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | }; | ||
| 63 | |||
| 64 | let radio = LoRaRadio::new(lora); | ||
| 65 | let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); | ||
| 66 | let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs)); | ||
| 67 | |||
| 68 | defmt::info!("Joining LoRaWAN network"); | ||
| 69 | |||
| 70 | // TODO: Adjust the EUI and Keys according to your network credentials | ||
| 71 | match device | ||
| 72 | .join(&JoinMode::OTAA { | ||
| 73 | deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 74 | appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 75 | appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 76 | }) | ||
| 77 | .await | ||
| 78 | { | ||
| 79 | Ok(()) => defmt::info!("LoRaWAN network joined"), | ||
| 80 | Err(err) => { | ||
| 81 | info!("Radio error = {}", err); | ||
| 82 | return; | ||
| 83 | } | ||
| 84 | }; | ||
| 85 | } | ||
diff --git a/examples/stm32l0/src/bin/lora_p2p_receive.rs b/examples/stm32l0/src/bin/lora_p2p_receive.rs deleted file mode 100644 index 0627ac087..000000000 --- a/examples/stm32l0/src/bin/lora_p2p_receive.rs +++ /dev/null | |||
| @@ -1,119 +0,0 @@ | |||
| 1 | //! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio. | ||
| 2 | //! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_lora::iv::Stm32l0InterfaceVariant; | ||
| 11 | use embassy_stm32::exti::{Channel, ExtiInput}; | ||
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; | ||
| 13 | use embassy_stm32::spi; | ||
| 14 | use embassy_stm32::time::khz; | ||
| 15 | use embassy_time::{Delay, Timer}; | ||
| 16 | use lora_phy::mod_params::*; | ||
| 17 | use lora_phy::sx1276_7_8_9::SX1276_7_8_9; | ||
| 18 | use lora_phy::LoRa; | ||
| 19 | use {defmt_rtt as _, panic_probe as _}; | ||
| 20 | |||
| 21 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 22 | |||
| 23 | #[embassy_executor::main] | ||
| 24 | async fn main(_spawner: Spawner) { | ||
| 25 | let mut config = embassy_stm32::Config::default(); | ||
| 26 | config.rcc.hsi = true; | ||
| 27 | config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI; | ||
| 28 | let p = embassy_stm32::init(config); | ||
| 29 | |||
| 30 | let mut spi_config = spi::Config::default(); | ||
| 31 | spi_config.frequency = khz(200); | ||
| 32 | |||
| 33 | // SPI for sx1276 | ||
| 34 | let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config); | ||
| 35 | |||
| 36 | let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); | ||
| 37 | let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); | ||
| 38 | |||
| 39 | let irq_pin = Input::new(p.PB4.degrade(), Pull::Up); | ||
| 40 | let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade()); | ||
| 41 | |||
| 42 | let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap(); | ||
| 43 | |||
| 44 | let mut lora = { | ||
| 45 | match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, 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.PB5, Level::Low, Speed::Low); | ||
| 55 | let mut start_indicator = Output::new(p.PB6, Level::Low, Speed::Low); | ||
| 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/stm32l0/src/bin/lora_p2p_send.rs b/examples/stm32l0/src/bin/lora_p2p_send.rs deleted file mode 100644 index 4f12cadc8..000000000 --- a/examples/stm32l0/src/bin/lora_p2p_send.rs +++ /dev/null | |||
| @@ -1,102 +0,0 @@ | |||
| 1 | //! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio. | ||
| 2 | //! It demonstrates LORA P2P send functionality. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_lora::iv::Stm32l0InterfaceVariant; | ||
| 11 | use embassy_stm32::exti::{Channel, ExtiInput}; | ||
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; | ||
| 13 | use embassy_stm32::spi; | ||
| 14 | use embassy_stm32::time::khz; | ||
| 15 | use embassy_time::Delay; | ||
| 16 | use lora_phy::mod_params::*; | ||
| 17 | use lora_phy::sx1276_7_8_9::SX1276_7_8_9; | ||
| 18 | use lora_phy::LoRa; | ||
| 19 | use {defmt_rtt as _, panic_probe as _}; | ||
| 20 | |||
| 21 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 22 | |||
| 23 | #[embassy_executor::main] | ||
| 24 | async fn main(_spawner: Spawner) { | ||
| 25 | let mut config = embassy_stm32::Config::default(); | ||
| 26 | config.rcc.hsi = true; | ||
| 27 | config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI; | ||
| 28 | let p = embassy_stm32::init(config); | ||
| 29 | |||
| 30 | let mut spi_config = spi::Config::default(); | ||
| 31 | spi_config.frequency = khz(200); | ||
| 32 | |||
| 33 | // SPI for sx1276 | ||
| 34 | let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config); | ||
| 35 | |||
| 36 | let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); | ||
| 37 | let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); | ||
| 38 | |||
| 39 | let irq_pin = Input::new(p.PB4.degrade(), Pull::Up); | ||
| 40 | let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade()); | ||
| 41 | |||
| 42 | let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap(); | ||
| 43 | |||
| 44 | let mut lora = { | ||
| 45 | match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, 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, 17, true).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 | } | ||
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml index 645ca84d3..4f608fcf1 100644 --- a/examples/stm32wl/Cargo.toml +++ b/examples/stm32wl/Cargo.toml | |||
| @@ -11,10 +11,6 @@ embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["de | |||
| 11 | embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 12 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } |
| 14 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } | ||
| 15 | lora-phy = { version = "2" } | ||
| 16 | lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"] } | ||
| 17 | lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"] } | ||
| 18 | 14 | ||
| 19 | defmt = "0.3" | 15 | defmt = "0.3" |
| 20 | defmt-rtt = "0.4" | 16 | defmt-rtt = "0.4" |
diff --git a/examples/stm32wl/src/bin/lora_lorawan.rs b/examples/stm32wl/src/bin/lora_lorawan.rs deleted file mode 100644 index 348e3cdce..000000000 --- a/examples/stm32wl/src/bin/lora_lorawan.rs +++ /dev/null | |||
| @@ -1,95 +0,0 @@ | |||
| 1 | //! This example runs on a STM32WL board, which has a builtin Semtech Sx1262 radio. | ||
| 2 | //! It demonstrates LoRaWAN join functionality. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait, async_fn_in_trait)] | ||
| 7 | #![allow(stable_features, unknown_lints, async_fn_in_trait)] | ||
| 8 | |||
| 9 | use defmt::info; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant}; | ||
| 12 | use embassy_lora::LoraTimer; | ||
| 13 | use embassy_stm32::gpio::{Level, Output, Pin, Speed}; | ||
| 14 | use embassy_stm32::rng::{self, Rng}; | ||
| 15 | use embassy_stm32::spi::Spi; | ||
| 16 | use embassy_stm32::time::Hertz; | ||
| 17 | use embassy_stm32::{bind_interrupts, peripherals}; | ||
| 18 | use embassy_time::Delay; | ||
| 19 | use lora_phy::mod_params::*; | ||
| 20 | use lora_phy::sx1261_2::SX1261_2; | ||
| 21 | use lora_phy::LoRa; | ||
| 22 | use lorawan::default_crypto::DefaultFactory as Crypto; | ||
| 23 | use lorawan_device::async_device::lora_radio::LoRaRadio; | ||
| 24 | use lorawan_device::async_device::{region, Device, JoinMode}; | ||
| 25 | use lorawan_device::{AppEui, AppKey, DevEui}; | ||
| 26 | use {defmt_rtt as _, panic_probe as _}; | ||
| 27 | |||
| 28 | const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region | ||
| 29 | |||
| 30 | bind_interrupts!(struct Irqs{ | ||
| 31 | SUBGHZ_RADIO => InterruptHandler; | ||
| 32 | RNG => rng::InterruptHandler<peripherals::RNG>; | ||
| 33 | }); | ||
| 34 | |||
| 35 | #[embassy_executor::main] | ||
| 36 | async fn main(_spawner: Spawner) { | ||
| 37 | let mut config = embassy_stm32::Config::default(); | ||
| 38 | { | ||
| 39 | use embassy_stm32::rcc::*; | ||
| 40 | config.rcc.hse = Some(Hse { | ||
| 41 | freq: Hertz(32_000_000), | ||
| 42 | mode: HseMode::Bypass, | ||
| 43 | prescaler: HsePrescaler::DIV1, | ||
| 44 | }); | ||
| 45 | config.rcc.mux = ClockSrc::PLL1_R; | ||
| 46 | config.rcc.pll = Some(Pll { | ||
| 47 | source: PllSource::HSE, | ||
| 48 | prediv: PllPreDiv::DIV2, | ||
| 49 | mul: PllMul::MUL6, | ||
| 50 | divp: None, | ||
| 51 | divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG | ||
| 52 | divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2) | ||
| 53 | }); | ||
| 54 | } | ||
| 55 | let p = embassy_stm32::init(config); | ||
| 56 | |||
| 57 | let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); | ||
| 58 | |||
| 59 | // Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx | ||
| 60 | let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High); | ||
| 61 | let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High); | ||
| 62 | let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High); | ||
| 63 | let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap(); | ||
| 64 | |||
| 65 | let lora = { | ||
| 66 | match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), true, Delay).await { | ||
| 67 | Ok(l) => l, | ||
| 68 | Err(err) => { | ||
| 69 | info!("Radio error = {}", err); | ||
| 70 | return; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | }; | ||
| 74 | let radio = LoRaRadio::new(lora); | ||
| 75 | let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); | ||
| 76 | let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs)); | ||
| 77 | |||
| 78 | defmt::info!("Joining LoRaWAN network"); | ||
| 79 | |||
| 80 | // TODO: Adjust the EUI and Keys according to your network credentials | ||
| 81 | match device | ||
| 82 | .join(&JoinMode::OTAA { | ||
| 83 | deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 84 | appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 85 | appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 86 | }) | ||
| 87 | .await | ||
| 88 | { | ||
| 89 | Ok(()) => defmt::info!("LoRaWAN network joined"), | ||
| 90 | Err(err) => { | ||
| 91 | info!("Radio error = {}", err); | ||
| 92 | return; | ||
| 93 | } | ||
| 94 | }; | ||
| 95 | } | ||
diff --git a/examples/stm32wl/src/bin/lora_p2p_receive.rs b/examples/stm32wl/src/bin/lora_p2p_receive.rs deleted file mode 100644 index c643ddb15..000000000 --- a/examples/stm32wl/src/bin/lora_p2p_receive.rs +++ /dev/null | |||
| @@ -1,133 +0,0 @@ | |||
| 1 | //! This example runs on the STM32WL board, which has a builtin Semtech Sx1262 radio. | ||
| 2 | //! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait, async_fn_in_trait)] | ||
| 7 | #![allow(stable_features, unknown_lints, async_fn_in_trait)] | ||
| 8 | |||
| 9 | use defmt::info; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant}; | ||
| 12 | use embassy_stm32::bind_interrupts; | ||
| 13 | use embassy_stm32::gpio::{Level, Output, Pin, Speed}; | ||
| 14 | use embassy_stm32::spi::Spi; | ||
| 15 | use embassy_stm32::time::Hertz; | ||
| 16 | use embassy_time::{Delay, Timer}; | ||
| 17 | use lora_phy::mod_params::*; | ||
| 18 | use lora_phy::sx1261_2::SX1261_2; | ||
| 19 | use lora_phy::LoRa; | ||
| 20 | use {defmt_rtt as _, panic_probe as _}; | ||
| 21 | |||
| 22 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 23 | |||
| 24 | bind_interrupts!(struct Irqs{ | ||
| 25 | SUBGHZ_RADIO => InterruptHandler; | ||
| 26 | }); | ||
| 27 | |||
| 28 | #[embassy_executor::main] | ||
| 29 | async fn main(_spawner: Spawner) { | ||
| 30 | let mut config = embassy_stm32::Config::default(); | ||
| 31 | { | ||
| 32 | use embassy_stm32::rcc::*; | ||
| 33 | config.rcc.hse = Some(Hse { | ||
| 34 | freq: Hertz(32_000_000), | ||
| 35 | mode: HseMode::Bypass, | ||
| 36 | prescaler: HsePrescaler::DIV1, | ||
| 37 | }); | ||
| 38 | config.rcc.mux = ClockSrc::PLL1_R; | ||
| 39 | config.rcc.pll = Some(Pll { | ||
| 40 | source: PllSource::HSE, | ||
| 41 | prediv: PllPreDiv::DIV2, | ||
| 42 | mul: PllMul::MUL6, | ||
| 43 | divp: None, | ||
| 44 | divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG | ||
| 45 | divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2) | ||
| 46 | }); | ||
| 47 | } | ||
| 48 | let p = embassy_stm32::init(config); | ||
| 49 | |||
| 50 | let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); | ||
| 51 | |||
| 52 | // Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx | ||
| 53 | let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High); | ||
| 54 | let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High); | ||
| 55 | let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High); | ||
| 56 | let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap(); | ||
| 57 | |||
| 58 | let mut lora = { | ||
| 59 | match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), false, Delay).await { | ||
| 60 | Ok(l) => l, | ||
| 61 | Err(err) => { | ||
| 62 | info!("Radio error = {}", err); | ||
| 63 | return; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | }; | ||
| 67 | |||
| 68 | let mut debug_indicator = Output::new(p.PB9, Level::Low, Speed::Low); | ||
| 69 | let mut start_indicator = Output::new(p.PB15, Level::Low, Speed::Low); | ||
| 70 | |||
| 71 | start_indicator.set_high(); | ||
| 72 | Timer::after_secs(5).await; | ||
| 73 | start_indicator.set_low(); | ||
| 74 | |||
| 75 | let mut receiving_buffer = [00u8; 100]; | ||
| 76 | |||
| 77 | let mdltn_params = { | ||
| 78 | match lora.create_modulation_params( | ||
| 79 | SpreadingFactor::_10, | ||
| 80 | Bandwidth::_250KHz, | ||
| 81 | CodingRate::_4_8, | ||
| 82 | LORA_FREQUENCY_IN_HZ, | ||
| 83 | ) { | ||
| 84 | Ok(mp) => mp, | ||
| 85 | Err(err) => { | ||
| 86 | info!("Radio error = {}", err); | ||
| 87 | return; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | }; | ||
| 91 | |||
| 92 | let rx_pkt_params = { | ||
| 93 | match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) { | ||
| 94 | Ok(pp) => pp, | ||
| 95 | Err(err) => { | ||
| 96 | info!("Radio error = {}", err); | ||
| 97 | return; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | }; | ||
| 101 | |||
| 102 | match lora | ||
| 103 | .prepare_for_rx(&mdltn_params, &rx_pkt_params, None, None, false) | ||
| 104 | .await | ||
| 105 | { | ||
| 106 | Ok(()) => {} | ||
| 107 | Err(err) => { | ||
| 108 | info!("Radio error = {}", err); | ||
| 109 | return; | ||
| 110 | } | ||
| 111 | }; | ||
| 112 | |||
| 113 | loop { | ||
| 114 | receiving_buffer = [00u8; 100]; | ||
| 115 | match lora.rx(&rx_pkt_params, &mut receiving_buffer).await { | ||
| 116 | Ok((received_len, _rx_pkt_status)) => { | ||
| 117 | if (received_len == 3) | ||
| 118 | && (receiving_buffer[0] == 0x01u8) | ||
| 119 | && (receiving_buffer[1] == 0x02u8) | ||
| 120 | && (receiving_buffer[2] == 0x03u8) | ||
| 121 | { | ||
| 122 | info!("rx successful"); | ||
| 123 | debug_indicator.set_high(); | ||
| 124 | Timer::after_secs(5).await; | ||
| 125 | debug_indicator.set_low(); | ||
| 126 | } else { | ||
| 127 | info!("rx unknown packet"); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | Err(err) => info!("rx unsuccessful = {}", err), | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
diff --git a/examples/stm32wl/src/bin/lora_p2p_send.rs b/examples/stm32wl/src/bin/lora_p2p_send.rs deleted file mode 100644 index 7fe8cea3e..000000000 --- a/examples/stm32wl/src/bin/lora_p2p_send.rs +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | //! This example runs on a STM32WL board, which has a builtin Semtech Sx1262 radio. | ||
| 2 | //! It demonstrates LORA P2P send functionality. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait, async_fn_in_trait)] | ||
| 7 | #![allow(stable_features, unknown_lints, async_fn_in_trait)] | ||
| 8 | |||
| 9 | use defmt::info; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant}; | ||
| 12 | use embassy_stm32::bind_interrupts; | ||
| 13 | use embassy_stm32::gpio::{Level, Output, Pin, Speed}; | ||
| 14 | use embassy_stm32::spi::Spi; | ||
| 15 | use embassy_stm32::time::Hertz; | ||
| 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 {defmt_rtt as _, panic_probe as _}; | ||
| 21 | |||
| 22 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 23 | |||
| 24 | bind_interrupts!(struct Irqs{ | ||
| 25 | SUBGHZ_RADIO => InterruptHandler; | ||
| 26 | }); | ||
| 27 | |||
| 28 | #[embassy_executor::main] | ||
| 29 | async fn main(_spawner: Spawner) { | ||
| 30 | let mut config = embassy_stm32::Config::default(); | ||
| 31 | { | ||
| 32 | use embassy_stm32::rcc::*; | ||
| 33 | config.rcc.hse = Some(Hse { | ||
| 34 | freq: Hertz(32_000_000), | ||
| 35 | mode: HseMode::Bypass, | ||
| 36 | prescaler: HsePrescaler::DIV1, | ||
| 37 | }); | ||
| 38 | config.rcc.mux = ClockSrc::PLL1_R; | ||
| 39 | config.rcc.pll = Some(Pll { | ||
| 40 | source: PllSource::HSE, | ||
| 41 | prediv: PllPreDiv::DIV2, | ||
| 42 | mul: PllMul::MUL6, | ||
| 43 | divp: None, | ||
| 44 | divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG | ||
| 45 | divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2) | ||
| 46 | }); | ||
| 47 | } | ||
| 48 | let p = embassy_stm32::init(config); | ||
| 49 | |||
| 50 | let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); | ||
| 51 | |||
| 52 | // Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx | ||
| 53 | let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High); | ||
| 54 | let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High); | ||
| 55 | let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High); | ||
| 56 | let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap(); | ||
| 57 | |||
| 58 | let mut lora = { | ||
| 59 | match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), false, Delay).await { | ||
| 60 | Ok(l) => l, | ||
| 61 | Err(err) => { | ||
| 62 | info!("Radio error = {}", err); | ||
| 63 | return; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | }; | ||
| 67 | |||
| 68 | let mdltn_params = { | ||
| 69 | match lora.create_modulation_params( | ||
| 70 | SpreadingFactor::_10, | ||
| 71 | Bandwidth::_250KHz, | ||
| 72 | CodingRate::_4_8, | ||
| 73 | LORA_FREQUENCY_IN_HZ, | ||
| 74 | ) { | ||
| 75 | Ok(mp) => mp, | ||
| 76 | Err(err) => { | ||
| 77 | info!("Radio error = {}", err); | ||
| 78 | return; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | |||
| 83 | let mut tx_pkt_params = { | ||
| 84 | match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) { | ||
| 85 | Ok(pp) => pp, | ||
| 86 | Err(err) => { | ||
| 87 | info!("Radio error = {}", err); | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | }; | ||
| 92 | |||
| 93 | match lora.prepare_for_tx(&mdltn_params, 20, false).await { | ||
| 94 | Ok(()) => {} | ||
| 95 | Err(err) => { | ||
| 96 | info!("Radio error = {}", err); | ||
| 97 | return; | ||
| 98 | } | ||
| 99 | }; | ||
| 100 | |||
| 101 | let buffer = [0x01u8, 0x02u8, 0x03u8]; | ||
| 102 | match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await { | ||
| 103 | Ok(()) => { | ||
| 104 | info!("TX DONE"); | ||
| 105 | } | ||
| 106 | Err(err) => { | ||
| 107 | info!("Radio error = {}", err); | ||
| 108 | return; | ||
| 109 | } | ||
| 110 | }; | ||
| 111 | |||
| 112 | match lora.sleep(false).await { | ||
| 113 | Ok(()) => info!("Sleep successful"), | ||
| 114 | Err(err) => info!("Sleep unsuccessful = {}", err), | ||
| 115 | } | ||
| 116 | } | ||
