diff options
57 files changed, 135 insertions, 2448 deletions
diff --git a/cyw43/Cargo.toml b/cyw43/Cargo.toml index 789e3ab05..3e37a8cd1 100644 --- a/cyw43/Cargo.toml +++ b/cyw43/Cargo.toml | |||
| @@ -23,7 +23,7 @@ cortex-m = "0.7.6" | |||
| 23 | cortex-m-rt = "0.7.0" | 23 | cortex-m-rt = "0.7.0" |
| 24 | futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } | 24 | futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } |
| 25 | 25 | ||
| 26 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-rc.1" } | 26 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-rc.2" } |
| 27 | num_enum = { version = "0.5.7", default-features = false } | 27 | num_enum = { version = "0.5.7", default-features = false } |
| 28 | 28 | ||
| 29 | [package.metadata.embassy_docs] | 29 | [package.metadata.embassy_docs] |
diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml index 11e47acb8..52ecd5c71 100644 --- a/embassy-embedded-hal/Cargo.toml +++ b/embassy-embedded-hal/Cargo.toml | |||
| @@ -25,8 +25,8 @@ embassy-time = { version = "0.1.5", path = "../embassy-time", optional = true } | |||
| 25 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = [ | 25 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = [ |
| 26 | "unproven", | 26 | "unproven", |
| 27 | ] } | 27 | ] } |
| 28 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } | 28 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } |
| 29 | embedded-hal-async = { version = "=1.0.0-rc.1", optional = true } | 29 | embedded-hal-async = { version = "=1.0.0-rc.2", optional = true } |
| 30 | embedded-storage = "0.3.0" | 30 | embedded-storage = "0.3.0" |
| 31 | embedded-storage-async = { version = "0.4.0", optional = true } | 31 | embedded-storage-async = { version = "0.4.0", optional = true } |
| 32 | nb = "1.0.0" | 32 | nb = "1.0.0" |
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs index 17d5f3676..b4f53c623 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs | |||
| @@ -63,6 +63,10 @@ where | |||
| 63 | CS: OutputPin, | 63 | CS: OutputPin, |
| 64 | { | 64 | { |
| 65 | async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { | 65 | async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { |
| 66 | if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { | ||
| 67 | return Err(SpiDeviceError::DelayNotSupported); | ||
| 68 | } | ||
| 69 | |||
| 66 | let mut bus = self.bus.lock().await; | 70 | let mut bus = self.bus.lock().await; |
| 67 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 71 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| 68 | 72 | ||
| @@ -74,12 +78,12 @@ where | |||
| 74 | Operation::Transfer(read, write) => bus.transfer(read, write).await, | 78 | Operation::Transfer(read, write) => bus.transfer(read, write).await, |
| 75 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, | 79 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, |
| 76 | #[cfg(not(feature = "time"))] | 80 | #[cfg(not(feature = "time"))] |
| 77 | Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), | 81 | Operation::DelayNs(_) => unreachable!(), |
| 78 | #[cfg(feature = "time")] | 82 | #[cfg(feature = "time")] |
| 79 | Operation::DelayUs(us) => match bus.flush().await { | 83 | Operation::DelayNs(ns) => match bus.flush().await { |
| 80 | Err(e) => Err(e), | 84 | Err(e) => Err(e), |
| 81 | Ok(()) => { | 85 | Ok(()) => { |
| 82 | embassy_time::Timer::after_micros(*us as _).await; | 86 | embassy_time::Timer::after_nanos(*ns as _).await; |
| 83 | Ok(()) | 87 | Ok(()) |
| 84 | } | 88 | } |
| 85 | }, | 89 | }, |
| @@ -137,6 +141,10 @@ where | |||
| 137 | CS: OutputPin, | 141 | CS: OutputPin, |
| 138 | { | 142 | { |
| 139 | async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { | 143 | async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { |
| 144 | if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { | ||
| 145 | return Err(SpiDeviceError::DelayNotSupported); | ||
| 146 | } | ||
| 147 | |||
| 140 | let mut bus = self.bus.lock().await; | 148 | let mut bus = self.bus.lock().await; |
| 141 | bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; | 149 | bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; |
| 142 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 150 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| @@ -149,12 +157,12 @@ where | |||
| 149 | Operation::Transfer(read, write) => bus.transfer(read, write).await, | 157 | Operation::Transfer(read, write) => bus.transfer(read, write).await, |
| 150 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, | 158 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, |
| 151 | #[cfg(not(feature = "time"))] | 159 | #[cfg(not(feature = "time"))] |
| 152 | Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), | 160 | Operation::DelayNs(_) => unreachable!(), |
| 153 | #[cfg(feature = "time")] | 161 | #[cfg(feature = "time")] |
| 154 | Operation::DelayUs(us) => match bus.flush().await { | 162 | Operation::DelayNs(ns) => match bus.flush().await { |
| 155 | Err(e) => Err(e), | 163 | Err(e) => Err(e), |
| 156 | Ok(()) => { | 164 | Ok(()) => { |
| 157 | embassy_time::Timer::after_micros(*us as _).await; | 165 | embassy_time::Timer::after_nanos(*ns as _).await; |
| 158 | Ok(()) | 166 | Ok(()) |
| 159 | } | 167 | } |
| 160 | }, | 168 | }, |
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs index 2b67862ea..59b65bfbd 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs | |||
| @@ -55,8 +55,8 @@ where | |||
| 55 | CS: OutputPin, | 55 | CS: OutputPin, |
| 56 | { | 56 | { |
| 57 | fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { | 57 | fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { |
| 58 | if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { | 58 | if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { |
| 59 | return Err(SpiDeviceError::DelayUsNotSupported); | 59 | return Err(SpiDeviceError::DelayNotSupported); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | self.bus.lock(|bus| { | 62 | self.bus.lock(|bus| { |
| @@ -69,10 +69,10 @@ where | |||
| 69 | Operation::Transfer(read, write) => bus.transfer(read, write), | 69 | Operation::Transfer(read, write) => bus.transfer(read, write), |
| 70 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), | 70 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), |
| 71 | #[cfg(not(feature = "time"))] | 71 | #[cfg(not(feature = "time"))] |
| 72 | Operation::DelayUs(_) => unreachable!(), | 72 | Operation::DelayNs(_) => unreachable!(), |
| 73 | #[cfg(feature = "time")] | 73 | #[cfg(feature = "time")] |
| 74 | Operation::DelayUs(us) => { | 74 | Operation::DelayNs(ns) => { |
| 75 | embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); | 75 | embassy_time::block_for(embassy_time::Duration::from_nanos(*ns as _)); |
| 76 | Ok(()) | 76 | Ok(()) |
| 77 | } | 77 | } |
| 78 | }); | 78 | }); |
| @@ -165,8 +165,8 @@ where | |||
| 165 | CS: OutputPin, | 165 | CS: OutputPin, |
| 166 | { | 166 | { |
| 167 | fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { | 167 | fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { |
| 168 | if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { | 168 | if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { |
| 169 | return Err(SpiDeviceError::DelayUsNotSupported); | 169 | return Err(SpiDeviceError::DelayNotSupported); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | self.bus.lock(|bus| { | 172 | self.bus.lock(|bus| { |
| @@ -180,10 +180,10 @@ where | |||
| 180 | Operation::Transfer(read, write) => bus.transfer(read, write), | 180 | Operation::Transfer(read, write) => bus.transfer(read, write), |
| 181 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), | 181 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), |
| 182 | #[cfg(not(feature = "time"))] | 182 | #[cfg(not(feature = "time"))] |
| 183 | Operation::DelayUs(_) => unreachable!(), | 183 | Operation::DelayNs(_) => unreachable!(), |
| 184 | #[cfg(feature = "time")] | 184 | #[cfg(feature = "time")] |
| 185 | Operation::DelayUs(us) => { | 185 | Operation::DelayNs(ns) => { |
| 186 | embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); | 186 | embassy_time::block_for(embassy_time::Duration::from_nanos(*ns as _)); |
| 187 | Ok(()) | 187 | Ok(()) |
| 188 | } | 188 | } |
| 189 | }); | 189 | }); |
diff --git a/embassy-embedded-hal/src/shared_bus/mod.rs b/embassy-embedded-hal/src/shared_bus/mod.rs index b0159ac09..ab96df134 100644 --- a/embassy-embedded-hal/src/shared_bus/mod.rs +++ b/embassy-embedded-hal/src/shared_bus/mod.rs | |||
| @@ -39,8 +39,8 @@ pub enum SpiDeviceError<BUS, CS> { | |||
| 39 | Spi(BUS), | 39 | Spi(BUS), |
| 40 | /// Setting the value of the Chip Select (CS) pin failed. | 40 | /// Setting the value of the Chip Select (CS) pin failed. |
| 41 | Cs(CS), | 41 | Cs(CS), |
| 42 | /// DelayUs operations are not supported when the `time` Cargo feature is not enabled. | 42 | /// Delay operations are not supported when the `time` Cargo feature is not enabled. |
| 43 | DelayUsNotSupported, | 43 | DelayNotSupported, |
| 44 | /// The SPI bus could not be configured. | 44 | /// The SPI bus could not be configured. |
| 45 | Config, | 45 | Config, |
| 46 | } | 46 | } |
| @@ -54,7 +54,7 @@ where | |||
| 54 | match self { | 54 | match self { |
| 55 | Self::Spi(e) => e.kind(), | 55 | Self::Spi(e) => e.kind(), |
| 56 | Self::Cs(_) => spi::ErrorKind::Other, | 56 | Self::Cs(_) => spi::ErrorKind::Other, |
| 57 | Self::DelayUsNotSupported => spi::ErrorKind::Other, | 57 | Self::DelayNotSupported => spi::ErrorKind::Other, |
| 58 | Self::Config => spi::ErrorKind::Other, | 58 | Self::Config => spi::ErrorKind::Other, |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
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/embassy-net-adin1110/Cargo.toml b/embassy-net-adin1110/Cargo.toml index 3f016160d..3dbbee44d 100644 --- a/embassy-net-adin1110/Cargo.toml +++ b/embassy-net-adin1110/Cargo.toml | |||
| @@ -13,16 +13,16 @@ edition = "2021" | |||
| 13 | heapless = "0.8" | 13 | heapless = "0.8" |
| 14 | defmt = { version = "0.3", optional = true } | 14 | defmt = { version = "0.3", optional = true } |
| 15 | log = { version = "0.4", default-features = false, optional = true } | 15 | log = { version = "0.4", default-features = false, optional = true } |
| 16 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } | 16 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } |
| 17 | embedded-hal-async = { version = "=1.0.0-rc.1" } | 17 | embedded-hal-async = { version = "=1.0.0-rc.2" } |
| 18 | embedded-hal-bus = { version = "=0.1.0-rc.1", features = ["async"] } | 18 | embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } |
| 19 | embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } | 19 | embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } |
| 20 | embassy-time = { version = "0.1.5", path = "../embassy-time" } | 20 | embassy-time = { version = "0.1.5", path = "../embassy-time" } |
| 21 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } | 21 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } |
| 22 | bitfield = "0.14.0" | 22 | bitfield = "0.14.0" |
| 23 | 23 | ||
| 24 | [dev-dependencies] | 24 | [dev-dependencies] |
| 25 | embedded-hal-mock = { version = "=0.10.0-rc.1", features = ["embedded-hal-async", "eh1"] } | 25 | embedded-hal-mock = { git = "https://github.com/Dirbaio/embedded-hal-mock", rev = "c5c4dca18e043e6386aee02173f61a65fea3981e", features = ["embedded-hal-async", "eh1"] } |
| 26 | crc = "3.0.1" | 26 | crc = "3.0.1" |
| 27 | env_logger = "0.10" | 27 | env_logger = "0.10" |
| 28 | critical-section = { version = "1.1.2", features = ["std"] } | 28 | critical-section = { version = "1.1.2", features = ["std"] } |
diff --git a/embassy-net-adin1110/src/lib.rs b/embassy-net-adin1110/src/lib.rs index 331c596df..e4a3cb209 100644 --- a/embassy-net-adin1110/src/lib.rs +++ b/embassy-net-adin1110/src/lib.rs | |||
| @@ -729,7 +729,7 @@ mod tests { | |||
| 729 | use core::convert::Infallible; | 729 | use core::convert::Infallible; |
| 730 | 730 | ||
| 731 | use embedded_hal_1::digital::{ErrorType, OutputPin}; | 731 | use embedded_hal_1::digital::{ErrorType, OutputPin}; |
| 732 | use embedded_hal_async::delay::DelayUs; | 732 | use embedded_hal_async::delay::DelayNs; |
| 733 | use embedded_hal_bus::spi::ExclusiveDevice; | 733 | use embedded_hal_bus::spi::ExclusiveDevice; |
| 734 | use embedded_hal_mock::common::Generic; | 734 | use embedded_hal_mock::common::Generic; |
| 735 | use embedded_hal_mock::eh1::spi::{Mock as SpiMock, Transaction as SpiTransaction}; | 735 | use embedded_hal_mock::eh1::spi::{Mock as SpiMock, Transaction as SpiTransaction}; |
| @@ -760,7 +760,11 @@ mod tests { | |||
| 760 | // see https://github.com/rust-embedded/embedded-hal/pull/462#issuecomment-1560014426 | 760 | // see https://github.com/rust-embedded/embedded-hal/pull/462#issuecomment-1560014426 |
| 761 | struct MockDelay {} | 761 | struct MockDelay {} |
| 762 | 762 | ||
| 763 | impl DelayUs for MockDelay { | 763 | impl DelayNs for MockDelay { |
| 764 | async fn delay_ns(&mut self, _ns: u32) { | ||
| 765 | todo!() | ||
| 766 | } | ||
| 767 | |||
| 764 | async fn delay_us(&mut self, _us: u32) { | 768 | async fn delay_us(&mut self, _us: u32) { |
| 765 | todo!() | 769 | todo!() |
| 766 | } | 770 | } |
diff --git a/embassy-net-enc28j60/Cargo.toml b/embassy-net-enc28j60/Cargo.toml index ea2ed1f77..eda699d9f 100644 --- a/embassy-net-enc28j60/Cargo.toml +++ b/embassy-net-enc28j60/Cargo.toml | |||
| @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0" | |||
| 8 | edition = "2021" | 8 | edition = "2021" |
| 9 | 9 | ||
| 10 | [dependencies] | 10 | [dependencies] |
| 11 | embedded-hal = { version = "1.0.0-rc.1" } | 11 | embedded-hal = { version = "1.0.0-rc.2" } |
| 12 | embedded-hal-async = { version = "=1.0.0-rc.1" } | 12 | embedded-hal-async = { version = "=1.0.0-rc.2" } |
| 13 | embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" } | 13 | embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" } |
| 14 | embassy-time = { version = "0.1.5", path = "../embassy-time" } | 14 | embassy-time = { version = "0.1.5", path = "../embassy-time" } |
| 15 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } | 15 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } |
diff --git a/embassy-net-esp-hosted/Cargo.toml b/embassy-net-esp-hosted/Cargo.toml index e86be4455..6b325c806 100644 --- a/embassy-net-esp-hosted/Cargo.toml +++ b/embassy-net-esp-hosted/Cargo.toml | |||
| @@ -12,8 +12,8 @@ embassy-sync = { version = "0.4.0", path = "../embassy-sync"} | |||
| 12 | embassy-futures = { version = "0.1.0", path = "../embassy-futures"} | 12 | embassy-futures = { version = "0.1.0", path = "../embassy-futures"} |
| 13 | embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel"} | 13 | embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel"} |
| 14 | 14 | ||
| 15 | embedded-hal = { version = "1.0.0-rc.1" } | 15 | embedded-hal = { version = "1.0.0-rc.2" } |
| 16 | embedded-hal-async = { version = "=1.0.0-rc.1" } | 16 | embedded-hal-async = { version = "=1.0.0-rc.2" } |
| 17 | 17 | ||
| 18 | noproto = { git="https://github.com/embassy-rs/noproto", rev = "f5e6d1f325b6ad4e344f60452b09576e24671f62", default-features = false, features = ["derive"] } | 18 | noproto = { git="https://github.com/embassy-rs/noproto", rev = "f5e6d1f325b6ad4e344f60452b09576e24671f62", default-features = false, features = ["derive"] } |
| 19 | #noproto = { version = "0.1", path = "/home/dirbaio/noproto", default-features = false, features = ["derive"] } | 19 | #noproto = { version = "0.1", path = "/home/dirbaio/noproto", default-features = false, features = ["derive"] } |
diff --git a/embassy-net-ppp/Cargo.toml b/embassy-net-ppp/Cargo.toml index 273dccbc2..7119ebd57 100644 --- a/embassy-net-ppp/Cargo.toml +++ b/embassy-net-ppp/Cargo.toml | |||
| @@ -15,7 +15,7 @@ log = ["dep:log", "ppproto/log"] | |||
| 15 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
| 16 | log = { version = "0.4.14", optional = true } | 16 | log = { version = "0.4.14", optional = true } |
| 17 | 17 | ||
| 18 | embedded-io-async = { version = "0.6.0" } | 18 | embedded-io-async = { version = "0.6.1" } |
| 19 | embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } | 19 | embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } |
| 20 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } | 20 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } |
| 21 | ppproto = { version = "0.1.2"} | 21 | ppproto = { version = "0.1.2"} |
diff --git a/embassy-net-wiznet/Cargo.toml b/embassy-net-wiznet/Cargo.toml index 0cc086b7e..187f3e299 100644 --- a/embassy-net-wiznet/Cargo.toml +++ b/embassy-net-wiznet/Cargo.toml | |||
| @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0" | |||
| 8 | edition = "2021" | 8 | edition = "2021" |
| 9 | 9 | ||
| 10 | [dependencies] | 10 | [dependencies] |
| 11 | embedded-hal = { version = "1.0.0-rc.1" } | 11 | embedded-hal = { version = "1.0.0-rc.2" } |
| 12 | embedded-hal-async = { version = "=1.0.0-rc.1" } | 12 | embedded-hal-async = { version = "=1.0.0-rc.2" } |
| 13 | embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } | 13 | embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } |
| 14 | embassy-time = { version = "0.1.5", path = "../embassy-time" } | 14 | embassy-time = { version = "0.1.5", path = "../embassy-time" } |
| 15 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } | 15 | embassy-futures = { version = "0.1.0", path = "../embassy-futures" } |
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index ef66078cb..fe8344f5b 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml | |||
| @@ -54,7 +54,7 @@ smoltcp = { git = "https://github.com/smoltcp-rs/smoltcp.git", rev = "b57e2f9e70 | |||
| 54 | embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" } | 54 | embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" } |
| 55 | embassy-time = { version = "0.1.5", path = "../embassy-time" } | 55 | embassy-time = { version = "0.1.5", path = "../embassy-time" } |
| 56 | embassy-sync = { version = "0.4.0", path = "../embassy-sync" } | 56 | embassy-sync = { version = "0.4.0", path = "../embassy-sync" } |
| 57 | embedded-io-async = { version = "0.6.0", optional = true } | 57 | embedded-io-async = { version = "0.6.1", optional = true } |
| 58 | 58 | ||
| 59 | managed = { version = "0.8.0", default-features = false, features = [ "map" ] } | 59 | managed = { version = "0.8.0", default-features = false, features = [ "map" ] } |
| 60 | heapless = { version = "0.8", default-features = false } | 60 | heapless = { version = "0.8", default-features = false } |
| @@ -63,4 +63,4 @@ generic-array = { version = "0.14.4", default-features = false } | |||
| 63 | stable_deref_trait = { version = "1.2.0", default-features = false } | 63 | stable_deref_trait = { version = "1.2.0", default-features = false } |
| 64 | futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } | 64 | futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } |
| 65 | atomic-pool = "1.0" | 65 | atomic-pool = "1.0" |
| 66 | embedded-nal-async = { version = "0.7", optional = true } | 66 | embedded-nal-async = { version = "0.7.1", optional = true } |
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 60e03d859..a75a94f02 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml | |||
| @@ -101,10 +101,10 @@ embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } | |||
| 101 | embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optional=true } | 101 | embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optional=true } |
| 102 | 102 | ||
| 103 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } | 103 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } |
| 104 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} | 104 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} |
| 105 | embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} | 105 | embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} |
| 106 | embedded-io = { version = "0.6.0" } | 106 | embedded-io = { version = "0.6.0" } |
| 107 | embedded-io-async = { version = "0.6.0", optional = true } | 107 | embedded-io-async = { version = "0.6.1", optional = true } |
| 108 | 108 | ||
| 109 | defmt = { version = "0.3", optional = true } | 109 | defmt = { version = "0.3", optional = true } |
| 110 | log = { version = "0.4.14", optional = true } | 110 | log = { version = "0.4.14", optional = true } |
diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index eb79cfd35..35ea77f03 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml | |||
| @@ -76,7 +76,7 @@ critical-section = "1.1" | |||
| 76 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 76 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 77 | chrono = { version = "0.4", default-features = false, optional = true } | 77 | chrono = { version = "0.4", default-features = false, optional = true } |
| 78 | embedded-io = { version = "0.6.0" } | 78 | embedded-io = { version = "0.6.0" } |
| 79 | embedded-io-async = { version = "0.6.0", optional = true } | 79 | embedded-io-async = { version = "0.6.1", optional = true } |
| 80 | embedded-storage = { version = "0.3" } | 80 | embedded-storage = { version = "0.3" } |
| 81 | embedded-storage-async = { version = "0.4.0", optional = true } | 81 | embedded-storage-async = { version = "0.4.0", optional = true } |
| 82 | rand_core = "0.6.4" | 82 | rand_core = "0.6.4" |
| @@ -85,9 +85,9 @@ fixed = "1.23.1" | |||
| 85 | rp-pac = { version = "6" } | 85 | rp-pac = { version = "6" } |
| 86 | 86 | ||
| 87 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } | 87 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } |
| 88 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} | 88 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} |
| 89 | embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} | 89 | embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} |
| 90 | embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true} | 90 | embedded-hal-nb = { version = "=1.0.0-rc.2", optional = true} |
| 91 | 91 | ||
| 92 | pio-proc = {version= "0.2" } | 92 | pio-proc = {version= "0.2" } |
| 93 | pio = {version= "0.2.1" } | 93 | pio = {version= "0.2.1" } |
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 292902ac7..535357fcc 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -42,9 +42,9 @@ embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optiona | |||
| 42 | embassy-executor = { version = "0.3.3", path = "../embassy-executor", optional = true } | 42 | embassy-executor = { version = "0.3.3", path = "../embassy-executor", optional = true } |
| 43 | 43 | ||
| 44 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } | 44 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } |
| 45 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} | 45 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} |
| 46 | embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} | 46 | embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} |
| 47 | embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true} | 47 | embedded-hal-nb = { version = "=1.0.0-rc.2", optional = true} |
| 48 | 48 | ||
| 49 | embedded-storage = "0.3.0" | 49 | embedded-storage = "0.3.0" |
| 50 | embedded-storage-async = { version = "0.4.0", optional = true } | 50 | embedded-storage-async = { version = "0.4.0", optional = true } |
| @@ -65,7 +65,7 @@ nb = "1.0.0" | |||
| 65 | stm32-fmc = "0.3.0" | 65 | stm32-fmc = "0.3.0" |
| 66 | cfg-if = "1.0.0" | 66 | cfg-if = "1.0.0" |
| 67 | embedded-io = { version = "0.6.0" } | 67 | embedded-io = { version = "0.6.0" } |
| 68 | embedded-io-async = { version = "0.6.0", optional = true } | 68 | embedded-io-async = { version = "0.6.1", optional = true } |
| 69 | chrono = { version = "^0.4", default-features = false, optional = true} | 69 | chrono = { version = "^0.4", default-features = false, optional = true} |
| 70 | bit_field = "0.10.2" | 70 | bit_field = "0.10.2" |
| 71 | document-features = "0.2.7" | 71 | document-features = "0.2.7" |
diff --git a/embassy-sync/Cargo.toml b/embassy-sync/Cargo.toml index e395389aa..ffcd13d9f 100644 --- a/embassy-sync/Cargo.toml +++ b/embassy-sync/Cargo.toml | |||
| @@ -35,7 +35,7 @@ futures-util = { version = "0.3.17", default-features = false } | |||
| 35 | critical-section = "1.1" | 35 | critical-section = "1.1" |
| 36 | heapless = "0.8" | 36 | heapless = "0.8" |
| 37 | cfg-if = "1.0.0" | 37 | cfg-if = "1.0.0" |
| 38 | embedded-io-async = { version = "0.6.0", optional = true } | 38 | embedded-io-async = { version = "0.6.1", optional = true } |
| 39 | 39 | ||
| 40 | [dev-dependencies] | 40 | [dev-dependencies] |
| 41 | futures-executor = { version = "0.3.17", features = [ "thread-pool" ] } | 41 | futures-executor = { version = "0.3.17", features = [ "thread-pool" ] } |
diff --git a/embassy-time/CHANGELOG.md b/embassy-time/CHANGELOG.md index 1421d76a9..9625b8909 100644 --- a/embassy-time/CHANGELOG.md +++ b/embassy-time/CHANGELOG.md | |||
| @@ -22,8 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
| 22 | 22 | ||
| 23 | ## 0.1.3 - 2023-08-28 | 23 | ## 0.1.3 - 2023-08-28 |
| 24 | 24 | ||
| 25 | - Update `embedded-hal-async` to `1.0.0-rc.1` | 25 | - Update `embedded-hal-async` to `1.0.0-rc.2` |
| 26 | - Update `embedded-hal v1` to `1.0.0-rc.1` | 26 | - Update `embedded-hal v1` to `1.0.0-rc.2` |
| 27 | 27 | ||
| 28 | ## 0.1.2 - 2023-07-05 | 28 | ## 0.1.2 - 2023-07-05 |
| 29 | 29 | ||
diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 3cabb2371..570e0efa7 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml | |||
| @@ -242,8 +242,8 @@ defmt = { version = "0.3", optional = true } | |||
| 242 | log = { version = "0.4.14", optional = true } | 242 | log = { version = "0.4.14", optional = true } |
| 243 | 243 | ||
| 244 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } | 244 | embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } |
| 245 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} | 245 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} |
| 246 | embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} | 246 | embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} |
| 247 | 247 | ||
| 248 | futures-util = { version = "0.3.17", default-features = false } | 248 | futures-util = { version = "0.3.17", default-features = false } |
| 249 | critical-section = "1.1" | 249 | critical-section = "1.1" |
diff --git a/embassy-time/src/delay.rs b/embassy-time/src/delay.rs index be962747c..aab56b1f1 100644 --- a/embassy-time/src/delay.rs +++ b/embassy-time/src/delay.rs | |||
| @@ -18,7 +18,11 @@ pub struct Delay; | |||
| 18 | mod eh1 { | 18 | mod eh1 { |
| 19 | use super::*; | 19 | use super::*; |
| 20 | 20 | ||
| 21 | impl embedded_hal_1::delay::DelayUs for Delay { | 21 | impl embedded_hal_1::delay::DelayNs for Delay { |
| 22 | fn delay_ns(&mut self, ns: u32) { | ||
| 23 | block_for(Duration::from_nanos(ns as u64)) | ||
| 24 | } | ||
| 25 | |||
| 22 | fn delay_us(&mut self, us: u32) { | 26 | fn delay_us(&mut self, us: u32) { |
| 23 | block_for(Duration::from_micros(us as u64)) | 27 | block_for(Duration::from_micros(us as u64)) |
| 24 | } | 28 | } |
| @@ -34,13 +38,17 @@ mod eha { | |||
| 34 | use super::*; | 38 | use super::*; |
| 35 | use crate::Timer; | 39 | use crate::Timer; |
| 36 | 40 | ||
| 37 | impl embedded_hal_async::delay::DelayUs for Delay { | 41 | impl embedded_hal_async::delay::DelayNs for Delay { |
| 38 | async fn delay_us(&mut self, micros: u32) { | 42 | async fn delay_ns(&mut self, ns: u32) { |
| 39 | Timer::after_micros(micros as _).await | 43 | Timer::after_nanos(ns as _).await |
| 44 | } | ||
| 45 | |||
| 46 | async fn delay_us(&mut self, us: u32) { | ||
| 47 | Timer::after_micros(us as _).await | ||
| 40 | } | 48 | } |
| 41 | 49 | ||
| 42 | async fn delay_ms(&mut self, millis: u32) { | 50 | async fn delay_ms(&mut self, ms: u32) { |
| 43 | Timer::after_millis(millis as _).await | 51 | Timer::after_millis(ms as _).await |
| 44 | } | 52 | } |
| 45 | } | 53 | } |
| 46 | } | 54 | } |
diff --git a/embassy-time/src/duration.rs b/embassy-time/src/duration.rs index 8366455be..647d208e3 100644 --- a/embassy-time/src/duration.rs +++ b/embassy-time/src/duration.rs | |||
| @@ -2,6 +2,7 @@ use core::fmt; | |||
| 2 | use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; | 2 | use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; |
| 3 | 3 | ||
| 4 | use super::{GCD_1K, GCD_1M, TICK_HZ}; | 4 | use super::{GCD_1K, GCD_1M, TICK_HZ}; |
| 5 | use crate::GCD_1G; | ||
| 5 | 6 | ||
| 6 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] | 7 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] |
| 7 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 8 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -61,6 +62,14 @@ impl Duration { | |||
| 61 | } | 62 | } |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 65 | /// Creates a duration from the specified number of nanoseconds, rounding up. | ||
| 66 | /// NOTE: Delays this small may be inaccurate. | ||
| 67 | pub const fn from_nanos(micros: u64) -> Duration { | ||
| 68 | Duration { | ||
| 69 | ticks: div_ceil(micros * (TICK_HZ / GCD_1G), 1_000_000_000 / GCD_1G), | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 64 | /// Creates a duration from the specified number of seconds, rounding down. | 73 | /// Creates a duration from the specified number of seconds, rounding down. |
| 65 | pub const fn from_secs_floor(secs: u64) -> Duration { | 74 | pub const fn from_secs_floor(secs: u64) -> Duration { |
| 66 | Duration { ticks: secs * TICK_HZ } | 75 | Duration { ticks: secs * TICK_HZ } |
diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs index a90368d59..a0f6e3824 100644 --- a/embassy-time/src/lib.rs +++ b/embassy-time/src/lib.rs | |||
| @@ -52,6 +52,7 @@ const fn gcd(a: u64, b: u64) -> u64 { | |||
| 52 | 52 | ||
| 53 | pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000); | 53 | pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000); |
| 54 | pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000); | 54 | pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000); |
| 55 | pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000); | ||
| 55 | 56 | ||
| 56 | #[cfg(feature = "defmt-timestamp-uptime")] | 57 | #[cfg(feature = "defmt-timestamp-uptime")] |
| 57 | defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } | 58 | defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } |
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index ee2423daf..574d715da 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs | |||
| @@ -74,6 +74,15 @@ impl Timer { | |||
| 74 | Self::after(Duration::from_ticks(ticks)) | 74 | Self::after(Duration::from_ticks(ticks)) |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | /// Expire after the specified number of nanoseconds. | ||
| 78 | /// | ||
| 79 | /// This method is a convenience wrapper for calling `Timer::after(Duration::from_nanos())`. | ||
| 80 | /// For more details, refer to [`Timer::after()`] and [`Duration::from_nanos()`]. | ||
| 81 | #[inline] | ||
| 82 | pub fn after_nanos(nanos: u64) -> Self { | ||
| 83 | Self::after(Duration::from_nanos(nanos)) | ||
| 84 | } | ||
| 85 | |||
| 77 | /// Expire after the specified number of microseconds. | 86 | /// Expire after the specified number of microseconds. |
| 78 | /// | 87 | /// |
| 79 | /// This method is a convenience wrapper for calling `Timer::after(Duration::from_micros())`. | 88 | /// This method is a convenience wrapper for calling `Timer::after(Duration::from_micros())`. |
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml index df5b1f3b5..d9b22a4d2 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] |
| @@ -36,11 +32,7 @@ embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defm | |||
| 36 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], optional = true } | 32 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], optional = true } |
| 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.1", 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 | ||
| @@ -57,9 +49,9 @@ rand = { version = "0.8.4", default-features = false } | |||
| 57 | embedded-storage = "0.3.0" | 49 | embedded-storage = "0.3.0" |
| 58 | usbd-hid = "0.6.0" | 50 | usbd-hid = "0.6.0" |
| 59 | serde = { version = "1.0.136", default-features = false } | 51 | serde = { version = "1.0.136", default-features = false } |
| 60 | embedded-hal = { version = "1.0.0-rc.1" } | 52 | embedded-hal = { version = "1.0.0-rc.2" } |
| 61 | embedded-hal-async = { version = "1.0.0-rc.1", optional = true } | 53 | embedded-hal-async = { version = "1.0.0-rc.2", optional = true } |
| 62 | embedded-hal-bus = { version = "0.1.0-rc.1" } | 54 | embedded-hal-bus = { version = "0.1.0-rc.2" } |
| 63 | num-integer = { version = "0.1.45", default-features = false } | 55 | num-integer = { version = "0.1.45", default-features = false } |
| 64 | microfft = "0.5.0" | 56 | microfft = "0.5.0" |
| 65 | 57 | ||
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/nrf5340/Cargo.toml b/examples/nrf5340/Cargo.toml index 032ec9806..25ae97496 100644 --- a/examples/nrf5340/Cargo.toml +++ b/examples/nrf5340/Cargo.toml | |||
| @@ -37,7 +37,7 @@ embassy-net = { version = "0.2.0", path = "../../embassy-net", features = [ | |||
| 37 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = [ | 37 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = [ |
| 38 | "defmt", | 38 | "defmt", |
| 39 | ] } | 39 | ] } |
| 40 | embedded-io-async = { version = "0.6.0" } | 40 | embedded-io-async = { version = "0.6.1" } |
| 41 | 41 | ||
| 42 | defmt = "0.3" | 42 | defmt = "0.3" |
| 43 | defmt-rtt = "0.4" | 43 | defmt-rtt = "0.4" |
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 7e752bad2..e0e0d8a78 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 | ||
| @@ -42,10 +38,10 @@ smart-leds = "0.3.0" | |||
| 42 | heapless = "0.8" | 38 | heapless = "0.8" |
| 43 | usbd-hid = "0.6.1" | 39 | usbd-hid = "0.6.1" |
| 44 | 40 | ||
| 45 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } | 41 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } |
| 46 | embedded-hal-async = "1.0.0-rc.1" | 42 | embedded-hal-async = "1.0.0-rc.2" |
| 47 | embedded-hal-bus = { version = "0.1.0-rc.1", features = ["async"] } | 43 | embedded-hal-bus = { version = "0.1.0-rc.2", features = ["async"] } |
| 48 | embedded-io-async = { version = "0.6.0", features = ["defmt-03"] } | 44 | embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } |
| 49 | embedded-storage = { version = "0.3" } | 45 | embedded-storage = { version = "0.3" } |
| 50 | static_cell = { version = "2", features = ["nightly"]} | 46 | static_cell = { version = "2", features = ["nightly"]} |
| 51 | portable-atomic = { version = "1.5", features = ["critical-section"] } | 47 | portable-atomic = { version = "1.5", features = ["critical-section"] } |
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/std/Cargo.toml b/examples/std/Cargo.toml index 75ed74b57..2a59fd693 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml | |||
| @@ -11,8 +11,8 @@ embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["lo | |||
| 11 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "medium-ip", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6"] } | 11 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "medium-ip", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6"] } |
| 12 | embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" } | 12 | embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" } |
| 13 | embassy-net-ppp = { version = "0.1.0", path = "../../embassy-net-ppp", features = ["log"]} | 13 | embassy-net-ppp = { version = "0.1.0", path = "../../embassy-net-ppp", features = ["log"]} |
| 14 | embedded-io-async = { version = "0.6.0" } | 14 | embedded-io-async = { version = "0.6.1" } |
| 15 | embedded-io-adapters = { version = "0.6.0", features = ["futures-03"] } | 15 | embedded-io-adapters = { version = "0.6.1", features = ["futures-03"] } |
| 16 | critical-section = { version = "1.1", features = ["std"] } | 16 | critical-section = { version = "1.1", features = ["std"] } |
| 17 | 17 | ||
| 18 | async-io = "1.6.0" | 18 | async-io = "1.6.0" |
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 772d873c7..8cee6d231 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml | |||
| @@ -20,7 +20,7 @@ cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-sing | |||
| 20 | cortex-m-rt = "0.7.0" | 20 | cortex-m-rt = "0.7.0" |
| 21 | embedded-hal = "0.2.6" | 21 | embedded-hal = "0.2.6" |
| 22 | embedded-io = { version = "0.6.0" } | 22 | embedded-io = { version = "0.6.0" } |
| 23 | embedded-io-async = { version = "0.6.0" } | 23 | embedded-io-async = { version = "0.6.1" } |
| 24 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 24 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 25 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 25 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 26 | heapless = { version = "0.8", default-features = false } | 26 | heapless = { version = "0.8", default-features = false } |
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index d418f8132..8fe2f2892 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml | |||
| @@ -11,7 +11,7 @@ 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 = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 13 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } | 13 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } |
| 14 | embedded-io-async = { version = "0.6.0" } | 14 | embedded-io-async = { version = "0.6.1" } |
| 15 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 15 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 16 | 16 | ||
| 17 | defmt = "0.3" | 17 | defmt = "0.3" |
diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml index e8d17cee0..db34005a0 100644 --- a/examples/stm32h5/Cargo.toml +++ b/examples/stm32h5/Cargo.toml | |||
| @@ -11,7 +11,7 @@ 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 = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } |
| 13 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6"] } | 13 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6"] } |
| 14 | embedded-io-async = { version = "0.6.0" } | 14 | embedded-io-async = { version = "0.6.1" } |
| 15 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 15 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 16 | 16 | ||
| 17 | defmt = "0.3" | 17 | defmt = "0.3" |
| @@ -20,9 +20,9 @@ defmt-rtt = "0.4" | |||
| 20 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 20 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 21 | cortex-m-rt = "0.7.0" | 21 | cortex-m-rt = "0.7.0" |
| 22 | embedded-hal = "0.2.6" | 22 | embedded-hal = "0.2.6" |
| 23 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } | 23 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } |
| 24 | embedded-hal-async = { version = "=1.0.0-rc.1" } | 24 | embedded-hal-async = { version = "=1.0.0-rc.2" } |
| 25 | embedded-nal-async = { version = "0.7" } | 25 | embedded-nal-async = { version = "0.7.1" } |
| 26 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 26 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 27 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 27 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 28 | heapless = { version = "0.8", default-features = false } | 28 | heapless = { version = "0.8", default-features = false } |
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index 05523d00c..2fe88dfaf 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml | |||
| @@ -11,7 +11,7 @@ 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 = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } |
| 13 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6", "dns"] } | 13 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6", "dns"] } |
| 14 | embedded-io-async = { version = "0.6.0" } | 14 | embedded-io-async = { version = "0.6.1" } |
| 15 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 15 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 16 | 16 | ||
| 17 | defmt = "0.3" | 17 | defmt = "0.3" |
| @@ -20,9 +20,9 @@ defmt-rtt = "0.4" | |||
| 20 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 20 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 21 | cortex-m-rt = "0.7.0" | 21 | cortex-m-rt = "0.7.0" |
| 22 | embedded-hal = "0.2.6" | 22 | embedded-hal = "0.2.6" |
| 23 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } | 23 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } |
| 24 | embedded-hal-async = { version = "=1.0.0-rc.1" } | 24 | embedded-hal-async = { version = "=1.0.0-rc.2" } |
| 25 | embedded-nal-async = { version = "0.7" } | 25 | embedded-nal-async = { version = "0.7.1" } |
| 26 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 26 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 27 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 27 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 28 | heapless = { version = "0.8", default-features = false } | 28 | heapless = { version = "0.8", default-features = false } |
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index 2b89ac275..15f7afe9c 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,17 +14,13 @@ 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" |
| 25 | 20 | ||
| 26 | embedded-storage = "0.3.0" | 21 | embedded-storage = "0.3.0" |
| 27 | embedded-io = { version = "0.6.0" } | 22 | embedded-io = { version = "0.6.0" } |
| 28 | embedded-io-async = { version = "0.6.0", optional = true } | 23 | embedded-io-async = { version = "0.6.1", optional = true } |
| 29 | 24 | ||
| 30 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 25 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 31 | cortex-m-rt = "0.7.0" | 26 | cortex-m-rt = "0.7.0" |
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/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index f4eaf647b..350e6e260 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml | |||
| @@ -15,7 +15,7 @@ embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defm | |||
| 15 | embassy-net-adin1110 = { version = "0.2.0", path = "../../embassy-net-adin1110" } | 15 | embassy-net-adin1110 = { version = "0.2.0", path = "../../embassy-net-adin1110" } |
| 16 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "udp", "tcp", "dhcpv4", "medium-ethernet"] } | 16 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "udp", "tcp", "dhcpv4", "medium-ethernet"] } |
| 17 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 17 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 18 | embedded-io-async = { version = "0.6.0", features = ["defmt-03"] } | 18 | embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } |
| 19 | embedded-io = { version = "0.6.0", features = ["defmt-03"] } | 19 | embedded-io = { version = "0.6.0", features = ["defmt-03"] } |
| 20 | 20 | ||
| 21 | defmt = "0.3" | 21 | defmt = "0.3" |
| @@ -24,9 +24,9 @@ defmt-rtt = "0.4" | |||
| 24 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 24 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 25 | cortex-m-rt = "0.7.0" | 25 | cortex-m-rt = "0.7.0" |
| 26 | embedded-hal = "0.2.6" | 26 | embedded-hal = "0.2.6" |
| 27 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } | 27 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } |
| 28 | embedded-hal-async = { version = "=1.0.0-rc.1" } | 28 | embedded-hal-async = { version = "=1.0.0-rc.2" } |
| 29 | embedded-hal-bus = { version = "=0.1.0-rc.1", features = ["async"] } | 29 | embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } |
| 30 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 30 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 31 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 31 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 32 | heapless = { version = "0.8", default-features = false } | 32 | heapless = { version = "0.8", default-features = false } |
diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index 1b9b026ff..7bca51ad1 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml | |||
| @@ -25,7 +25,7 @@ embedded-hal = "0.2.6" | |||
| 25 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 25 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 26 | heapless = { version = "0.8", default-features = false } | 26 | heapless = { version = "0.8", default-features = false } |
| 27 | rand_core = { version = "0.6.3", default-features = false } | 27 | rand_core = { version = "0.6.3", default-features = false } |
| 28 | embedded-io-async = { version = "0.6.0" } | 28 | embedded-io-async = { version = "0.6.1" } |
| 29 | static_cell = { version = "2", features = ["nightly"]} | 29 | static_cell = { version = "2", features = ["nightly"]} |
| 30 | 30 | ||
| 31 | [profile.release] | 31 | [profile.release] |
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 | } | ||
diff --git a/tests/nrf/Cargo.toml b/tests/nrf/Cargo.toml index fd7568816..70bb17c14 100644 --- a/tests/nrf/Cargo.toml +++ b/tests/nrf/Cargo.toml | |||
| @@ -12,12 +12,12 @@ embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["de | |||
| 12 | embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-16384", "integrated-timers"] } | 12 | embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-16384", "integrated-timers"] } |
| 13 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] } | 13 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] } |
| 14 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } | 14 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } |
| 15 | embedded-io-async = { version = "0.6.0", features = ["defmt-03"] } | 15 | embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } |
| 16 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } | 16 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } |
| 17 | embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } | 17 | embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } |
| 18 | embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] } | 18 | embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] } |
| 19 | embedded-hal-async = { version = "1.0.0-rc.1" } | 19 | embedded-hal-async = { version = "1.0.0-rc.2" } |
| 20 | embedded-hal-bus = { version = "0.1.0-rc.1", features = ["async"] } | 20 | embedded-hal-bus = { version = "0.1.0-rc.2", features = ["async"] } |
| 21 | static_cell = { version = "2", features = [ "nightly" ] } | 21 | static_cell = { version = "2", features = [ "nightly" ] } |
| 22 | perf-client = { path = "../perf-client" } | 22 | perf-client = { path = "../perf-client" } |
| 23 | 23 | ||
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index fc434a026..d69bd7952 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml | |||
| @@ -24,12 +24,12 @@ defmt-rtt = "0.4" | |||
| 24 | cortex-m = { version = "0.7.6" } | 24 | cortex-m = { version = "0.7.6" } |
| 25 | cortex-m-rt = "0.7.0" | 25 | cortex-m-rt = "0.7.0" |
| 26 | embedded-hal = "0.2.6" | 26 | embedded-hal = "0.2.6" |
| 27 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } | 27 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } |
| 28 | embedded-hal-async = { version = "=1.0.0-rc.1" } | 28 | embedded-hal-async = { version = "=1.0.0-rc.2" } |
| 29 | embedded-hal-bus = { version = "=0.1.0-rc.1", features = ["async"] } | 29 | embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } |
| 30 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 30 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 31 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 31 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 32 | embedded-io-async = { version = "0.6.0" } | 32 | embedded-io-async = { version = "0.6.1" } |
| 33 | embedded-storage = { version = "0.3" } | 33 | embedded-storage = { version = "0.3" } |
| 34 | static_cell = { version = "2", features = ["nightly"]} | 34 | static_cell = { version = "2", features = ["nightly"]} |
| 35 | portable-atomic = { version = "1.5", features = ["critical-section"] } | 35 | portable-atomic = { version = "1.5", features = ["critical-section"] } |
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 8c2cfdf5c..ba72c6421 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -63,8 +63,8 @@ defmt-rtt = "0.4" | |||
| 63 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 63 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 64 | cortex-m-rt = "0.7.0" | 64 | cortex-m-rt = "0.7.0" |
| 65 | embedded-hal = "0.2.6" | 65 | embedded-hal = "0.2.6" |
| 66 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } | 66 | embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } |
| 67 | embedded-hal-async = { version = "=1.0.0-rc.1" } | 67 | embedded-hal-async = { version = "=1.0.0-rc.2" } |
| 68 | micromath = "2.0.0" | 68 | micromath = "2.0.0" |
| 69 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 69 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 70 | rand_core = { version = "0.6", default-features = false } | 70 | rand_core = { version = "0.6", default-features = false } |
