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" cortex-m-rt = "0.7.0" futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } -embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-rc.1" } +embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-rc.2" } num_enum = { version = "0.5.7", default-features = false } [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 } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = [ "unproven", ] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true } embedded-storage = "0.3.0" embedded-storage-async = { version = "0.4.0", optional = true } 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 CS: OutputPin, { async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); + } + let mut bus = self.bus.lock().await; self.cs.set_low().map_err(SpiDeviceError::Cs)?; @@ -74,12 +78,12 @@ where Operation::Transfer(read, write) => bus.transfer(read, write).await, Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, #[cfg(not(feature = "time"))] - Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => match bus.flush().await { + Operation::DelayNs(ns) => match bus.flush().await { Err(e) => Err(e), Ok(()) => { - embassy_time::Timer::after_micros(*us as _).await; + embassy_time::Timer::after_nanos(*ns as _).await; Ok(()) } }, @@ -137,6 +141,10 @@ where CS: OutputPin, { async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); + } + let mut bus = self.bus.lock().await; bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; self.cs.set_low().map_err(SpiDeviceError::Cs)?; @@ -149,12 +157,12 @@ where Operation::Transfer(read, write) => bus.transfer(read, write).await, Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, #[cfg(not(feature = "time"))] - Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => match bus.flush().await { + Operation::DelayNs(ns) => match bus.flush().await { Err(e) => Err(e), Ok(()) => { - embassy_time::Timer::after_micros(*us as _).await; + embassy_time::Timer::after_nanos(*ns as _).await; Ok(()) } }, 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 CS: OutputPin, { fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { - if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { - return Err(SpiDeviceError::DelayUsNotSupported); + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); } self.bus.lock(|bus| { @@ -69,10 +69,10 @@ where Operation::Transfer(read, write) => bus.transfer(read, write), Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), #[cfg(not(feature = "time"))] - Operation::DelayUs(_) => unreachable!(), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => { - embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); + Operation::DelayNs(ns) => { + embassy_time::block_for(embassy_time::Duration::from_nanos(*ns as _)); Ok(()) } }); @@ -165,8 +165,8 @@ where CS: OutputPin, { fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { - if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { - return Err(SpiDeviceError::DelayUsNotSupported); + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); } self.bus.lock(|bus| { @@ -180,10 +180,10 @@ where Operation::Transfer(read, write) => bus.transfer(read, write), Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), #[cfg(not(feature = "time"))] - Operation::DelayUs(_) => unreachable!(), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => { - embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); + Operation::DelayNs(ns) => { + embassy_time::block_for(embassy_time::Duration::from_nanos(*ns as _)); Ok(()) } }); 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 { Spi(BUS), /// Setting the value of the Chip Select (CS) pin failed. Cs(CS), - /// DelayUs operations are not supported when the `time` Cargo feature is not enabled. - DelayUsNotSupported, + /// Delay operations are not supported when the `time` Cargo feature is not enabled. + DelayNotSupported, /// The SPI bus could not be configured. Config, } @@ -54,7 +54,7 @@ where match self { Self::Spi(e) => e.kind(), Self::Cs(_) => spi::ErrorKind::Other, - Self::DelayUsNotSupported => spi::ErrorKind::Other, + Self::DelayNotSupported => spi::ErrorKind::Other, Self::Config => spi::ErrorKind::Other, } } 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 @@ -[package] -name = "embassy-lora" -version = "0.1.0" -edition = "2021" -license = "MIT OR Apache-2.0" - -[package.metadata.embassy_docs] -src_base = "https://github.com/embassy-rs/embassy/blob/embassy-lora-v$VERSION/embassy-lora/src/" -src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-lora/src/" -features = ["stm32wl", "embassy-stm32?/stm32wl55jc-cm4", "embassy-stm32?/unstable-pac", "time", "defmt"] -target = "thumbv7em-none-eabi" - -[features] -stm32wl = ["dep:embassy-stm32"] -time = ["embassy-time", "lorawan-device"] -defmt = ["dep:defmt", "lorawan-device/defmt"] - -[dependencies] - -defmt = { version = "0.3", optional = true } -log = { version = "0.4.14", optional = true } - -embassy-time = { version = "0.1.5", path = "../embassy-time", optional = true } -embassy-sync = { version = "0.4.0", path = "../embassy-sync" } -embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-hal = { version = "0.2", features = ["unproven"] } - -futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } -lora-phy = { version = "2" } -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 @@ -#![macro_use] -#![allow(unused_macros)] - -use core::fmt::{Debug, Display, LowerHex}; - -#[cfg(all(feature = "defmt", feature = "log"))] -compile_error!("You may not enable both `defmt` and `log` features."); - -macro_rules! assert { - ($($x:tt)*) => { - { - #[cfg(not(feature = "defmt"))] - ::core::assert!($($x)*); - #[cfg(feature = "defmt")] - ::defmt::assert!($($x)*); - } - }; -} - -macro_rules! assert_eq { - ($($x:tt)*) => { - { - #[cfg(not(feature = "defmt"))] - ::core::assert_eq!($($x)*); - #[cfg(feature = "defmt")] - ::defmt::assert_eq!($($x)*); - } - }; -} - -macro_rules! assert_ne { - ($($x:tt)*) => { - { - #[cfg(not(feature = "defmt"))] - ::core::assert_ne!($($x)*); - #[cfg(feature = "defmt")] - ::defmt::assert_ne!($($x)*); - } - }; -} - -macro_rules! debug_assert { - ($($x:tt)*) => { - { - #[cfg(not(feature = "defmt"))] - ::core::debug_assert!($($x)*); - #[cfg(feature = "defmt")] - ::defmt::debug_assert!($($x)*); - } - }; -} - -macro_rules! debug_assert_eq { - ($($x:tt)*) => { - { - #[cfg(not(feature = "defmt"))] - ::core::debug_assert_eq!($($x)*); - #[cfg(feature = "defmt")] - ::defmt::debug_assert_eq!($($x)*); - } - }; -} - -macro_rules! debug_assert_ne { - ($($x:tt)*) => { - { - #[cfg(not(feature = "defmt"))] - ::core::debug_assert_ne!($($x)*); - #[cfg(feature = "defmt")] - ::defmt::debug_assert_ne!($($x)*); - } - }; -} - -macro_rules! todo { - ($($x:tt)*) => { - { - #[cfg(not(feature = "defmt"))] - ::core::todo!($($x)*); - #[cfg(feature = "defmt")] - ::defmt::todo!($($x)*); - } - }; -} - -#[cfg(not(feature = "defmt"))] -macro_rules! unreachable { - ($($x:tt)*) => { - ::core::unreachable!($($x)*) - }; -} - -#[cfg(feature = "defmt")] -macro_rules! unreachable { - ($($x:tt)*) => { - ::defmt::unreachable!($($x)*) - }; -} - -macro_rules! panic { - ($($x:tt)*) => { - { - #[cfg(not(feature = "defmt"))] - ::core::panic!($($x)*); - #[cfg(feature = "defmt")] - ::defmt::panic!($($x)*); - } - }; -} - -macro_rules! trace { - ($s:literal $(, $x:expr)* $(,)?) => { - { - #[cfg(feature = "log")] - ::log::trace!($s $(, $x)*); - #[cfg(feature = "defmt")] - ::defmt::trace!($s $(, $x)*); - #[cfg(not(any(feature = "log", feature="defmt")))] - let _ = ($( & $x ),*); - } - }; -} - -macro_rules! debug { - ($s:literal $(, $x:expr)* $(,)?) => { - { - #[cfg(feature = "log")] - ::log::debug!($s $(, $x)*); - #[cfg(feature = "defmt")] - ::defmt::debug!($s $(, $x)*); - #[cfg(not(any(feature = "log", feature="defmt")))] - let _ = ($( & $x ),*); - } - }; -} - -macro_rules! info { - ($s:literal $(, $x:expr)* $(,)?) => { - { - #[cfg(feature = "log")] - ::log::info!($s $(, $x)*); - #[cfg(feature = "defmt")] - ::defmt::info!($s $(, $x)*); - #[cfg(not(any(feature = "log", feature="defmt")))] - let _ = ($( & $x ),*); - } - }; -} - -macro_rules! warn { - ($s:literal $(, $x:expr)* $(,)?) => { - { - #[cfg(feature = "log")] - ::log::warn!($s $(, $x)*); - #[cfg(feature = "defmt")] - ::defmt::warn!($s $(, $x)*); - #[cfg(not(any(feature = "log", feature="defmt")))] - let _ = ($( & $x ),*); - } - }; -} - -macro_rules! error { - ($s:literal $(, $x:expr)* $(,)?) => { - { - #[cfg(feature = "log")] - ::log::error!($s $(, $x)*); - #[cfg(feature = "defmt")] - ::defmt::error!($s $(, $x)*); - #[cfg(not(any(feature = "log", feature="defmt")))] - let _ = ($( & $x ),*); - } - }; -} - -#[cfg(feature = "defmt")] -macro_rules! unwrap { - ($($x:tt)*) => { - ::defmt::unwrap!($($x)*) - }; -} - -#[cfg(not(feature = "defmt"))] -macro_rules! unwrap { - ($arg:expr) => { - match $crate::fmt::Try::into_result($arg) { - ::core::result::Result::Ok(t) => t, - ::core::result::Result::Err(e) => { - ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); - } - } - }; - ($arg:expr, $($msg:expr),+ $(,)? ) => { - match $crate::fmt::Try::into_result($arg) { - ::core::result::Result::Ok(t) => t, - ::core::result::Result::Err(e) => { - ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); - } - } - } -} - -#[derive(Debug, Copy, Clone, Eq, PartialEq)] -pub struct NoneError; - -pub trait Try { - type Ok; - type Error; - fn into_result(self) -> Result; -} - -impl Try for Option { - type Ok = T; - type Error = NoneError; - - #[inline] - fn into_result(self) -> Result { - self.ok_or(NoneError) - } -} - -impl Try for Result { - type Ok = T; - type Error = E; - - #[inline] - fn into_result(self) -> Self { - self - } -} - -#[allow(unused)] -pub(crate) struct Bytes<'a>(pub &'a [u8]); - -impl<'a> Debug for Bytes<'a> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "{:#02x?}", self.0) - } -} - -impl<'a> Display for Bytes<'a> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "{:#02x?}", self.0) - } -} - -impl<'a> LowerHex for Bytes<'a> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "{:#02x?}", self.0) - } -} - -#[cfg(feature = "defmt")] -impl<'a> defmt::Format for Bytes<'a> { - fn format(&self, fmt: defmt::Formatter) { - defmt::write!(fmt, "{:02x}", self.0) - } -} 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 @@ -#[cfg(feature = "stm32wl")] -use embassy_stm32::interrupt; -#[cfg(feature = "stm32wl")] -use embassy_stm32::interrupt::InterruptExt; -#[cfg(feature = "stm32wl")] -use embassy_stm32::pac; -#[cfg(feature = "stm32wl")] -use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; -#[cfg(feature = "stm32wl")] -use embassy_sync::signal::Signal; -use embedded_hal::digital::v2::OutputPin; -use embedded_hal_async::delay::DelayUs; -use embedded_hal_async::digital::Wait; -use lora_phy::mod_params::RadioError::*; -use lora_phy::mod_params::{BoardType, RadioError}; -use lora_phy::mod_traits::InterfaceVariant; - -/// Interrupt handler. -#[cfg(feature = "stm32wl")] -pub struct InterruptHandler {} - -#[cfg(feature = "stm32wl")] -impl interrupt::typelevel::Handler for InterruptHandler { - unsafe fn on_interrupt() { - interrupt::SUBGHZ_RADIO.disable(); - IRQ_SIGNAL.signal(()); - } -} - -#[cfg(feature = "stm32wl")] -static IRQ_SIGNAL: Signal = Signal::new(); - -#[cfg(feature = "stm32wl")] -/// Base for the InterfaceVariant implementation for an stm32wl/sx1262 combination -pub struct Stm32wlInterfaceVariant { - board_type: BoardType, - rf_switch_rx: Option, - rf_switch_tx: Option, -} - -#[cfg(feature = "stm32wl")] -impl<'a, CTRL> Stm32wlInterfaceVariant -where - CTRL: OutputPin, -{ - /// Create an InterfaceVariant instance for an stm32wl/sx1262 combination - pub fn new( - _irq: impl interrupt::typelevel::Binding, - rf_switch_rx: Option, - rf_switch_tx: Option, - ) -> Result { - interrupt::SUBGHZ_RADIO.disable(); - Ok(Self { - board_type: BoardType::Stm32wlSx1262, // updated when associated with a specific LoRa board - rf_switch_rx, - rf_switch_tx, - }) - } -} - -#[cfg(feature = "stm32wl")] -impl InterfaceVariant for Stm32wlInterfaceVariant -where - CTRL: OutputPin, -{ - fn set_board_type(&mut self, board_type: BoardType) { - self.board_type = board_type; - } - async fn set_nss_low(&mut self) -> Result<(), RadioError> { - pac::PWR.subghzspicr().modify(|w| w.set_nss(false)); - Ok(()) - } - async fn set_nss_high(&mut self) -> Result<(), RadioError> { - pac::PWR.subghzspicr().modify(|w| w.set_nss(true)); - Ok(()) - } - async fn reset(&mut self, _delay: &mut impl DelayUs) -> Result<(), RadioError> { - pac::RCC.csr().modify(|w| w.set_rfrst(true)); - pac::RCC.csr().modify(|w| w.set_rfrst(false)); - Ok(()) - } - async fn wait_on_busy(&mut self) -> Result<(), RadioError> { - while pac::PWR.sr2().read().rfbusys() {} - Ok(()) - } - - async fn await_irq(&mut self) -> Result<(), RadioError> { - unsafe { interrupt::SUBGHZ_RADIO.enable() }; - IRQ_SIGNAL.wait().await; - Ok(()) - } - - async fn enable_rf_switch_rx(&mut self) -> Result<(), RadioError> { - match &mut self.rf_switch_tx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchTx)?, - None => (), - }; - match &mut self.rf_switch_rx { - Some(pin) => pin.set_high().map_err(|_| RfSwitchRx), - None => Ok(()), - } - } - async fn enable_rf_switch_tx(&mut self) -> Result<(), RadioError> { - match &mut self.rf_switch_rx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, - None => (), - }; - match &mut self.rf_switch_tx { - Some(pin) => pin.set_high().map_err(|_| RfSwitchTx), - None => Ok(()), - } - } - async fn disable_rf_switch(&mut self) -> Result<(), RadioError> { - match &mut self.rf_switch_rx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, - None => (), - }; - match &mut self.rf_switch_tx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchTx), - None => Ok(()), - } - } -} - -/// Base for the InterfaceVariant implementation for an stm32l0/sx1276 combination -pub struct Stm32l0InterfaceVariant { - board_type: BoardType, - nss: CTRL, - reset: CTRL, - irq: WAIT, - rf_switch_rx: Option, - rf_switch_tx: Option, -} - -impl Stm32l0InterfaceVariant -where - CTRL: OutputPin, - WAIT: Wait, -{ - /// Create an InterfaceVariant instance for an stm32l0/sx1276 combination - pub fn new( - nss: CTRL, - reset: CTRL, - irq: WAIT, - rf_switch_rx: Option, - rf_switch_tx: Option, - ) -> Result { - Ok(Self { - board_type: BoardType::Stm32l0Sx1276, // updated when associated with a specific LoRa board - nss, - reset, - irq, - rf_switch_rx, - rf_switch_tx, - }) - } -} - -impl InterfaceVariant for Stm32l0InterfaceVariant -where - CTRL: OutputPin, - WAIT: Wait, -{ - fn set_board_type(&mut self, board_type: BoardType) { - self.board_type = board_type; - } - async fn set_nss_low(&mut self) -> Result<(), RadioError> { - self.nss.set_low().map_err(|_| NSS) - } - async fn set_nss_high(&mut self) -> Result<(), RadioError> { - self.nss.set_high().map_err(|_| NSS) - } - async fn reset(&mut self, delay: &mut impl DelayUs) -> Result<(), RadioError> { - delay.delay_ms(10).await; - self.reset.set_low().map_err(|_| Reset)?; - delay.delay_ms(10).await; - self.reset.set_high().map_err(|_| Reset)?; - delay.delay_ms(10).await; - Ok(()) - } - async fn wait_on_busy(&mut self) -> Result<(), RadioError> { - Ok(()) - } - async fn await_irq(&mut self) -> Result<(), RadioError> { - self.irq.wait_for_high().await.map_err(|_| Irq) - } - - async fn enable_rf_switch_rx(&mut self) -> Result<(), RadioError> { - match &mut self.rf_switch_tx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchTx)?, - None => (), - }; - match &mut self.rf_switch_rx { - Some(pin) => pin.set_high().map_err(|_| RfSwitchRx), - None => Ok(()), - } - } - async fn enable_rf_switch_tx(&mut self) -> Result<(), RadioError> { - match &mut self.rf_switch_rx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, - None => (), - }; - match &mut self.rf_switch_tx { - Some(pin) => pin.set_high().map_err(|_| RfSwitchTx), - None => Ok(()), - } - } - async fn disable_rf_switch(&mut self) -> Result<(), RadioError> { - match &mut self.rf_switch_rx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, - None => (), - }; - match &mut self.rf_switch_tx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchTx), - None => Ok(()), - } - } -} - -/// Base for the InterfaceVariant implementation for a generic Sx126x LoRa board -pub struct GenericSx126xInterfaceVariant { - board_type: BoardType, - nss: CTRL, - reset: CTRL, - dio1: WAIT, - busy: WAIT, - rf_switch_rx: Option, - rf_switch_tx: Option, -} - -impl GenericSx126xInterfaceVariant -where - CTRL: OutputPin, - WAIT: Wait, -{ - /// Create an InterfaceVariant instance for an nrf52840/sx1262 combination - pub fn new( - nss: CTRL, - reset: CTRL, - dio1: WAIT, - busy: WAIT, - rf_switch_rx: Option, - rf_switch_tx: Option, - ) -> Result { - Ok(Self { - board_type: BoardType::Rak4631Sx1262, // updated when associated with a specific LoRa board - nss, - reset, - dio1, - busy, - rf_switch_rx, - rf_switch_tx, - }) - } -} - -impl InterfaceVariant for GenericSx126xInterfaceVariant -where - CTRL: OutputPin, - WAIT: Wait, -{ - fn set_board_type(&mut self, board_type: BoardType) { - self.board_type = board_type; - } - async fn set_nss_low(&mut self) -> Result<(), RadioError> { - self.nss.set_low().map_err(|_| NSS) - } - async fn set_nss_high(&mut self) -> Result<(), RadioError> { - self.nss.set_high().map_err(|_| NSS) - } - async fn reset(&mut self, delay: &mut impl DelayUs) -> Result<(), RadioError> { - delay.delay_ms(10).await; - self.reset.set_low().map_err(|_| Reset)?; - delay.delay_ms(20).await; - self.reset.set_high().map_err(|_| Reset)?; - delay.delay_ms(10).await; - Ok(()) - } - async fn wait_on_busy(&mut self) -> Result<(), RadioError> { - self.busy.wait_for_low().await.map_err(|_| Busy) - } - async fn await_irq(&mut self) -> Result<(), RadioError> { - self.dio1.wait_for_high().await.map_err(|_| DIO1)?; - Ok(()) - } - - async fn enable_rf_switch_rx(&mut self) -> Result<(), RadioError> { - match &mut self.rf_switch_tx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchTx)?, - None => (), - }; - match &mut self.rf_switch_rx { - Some(pin) => pin.set_high().map_err(|_| RfSwitchRx), - None => Ok(()), - } - } - async fn enable_rf_switch_tx(&mut self) -> Result<(), RadioError> { - match &mut self.rf_switch_rx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, - None => (), - }; - match &mut self.rf_switch_tx { - Some(pin) => pin.set_high().map_err(|_| RfSwitchTx), - None => Ok(()), - } - } - async fn disable_rf_switch(&mut self) -> Result<(), RadioError> { - match &mut self.rf_switch_rx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?, - None => (), - }; - match &mut self.rf_switch_tx { - Some(pin) => pin.set_low().map_err(|_| RfSwitchTx), - None => Ok(()), - } - } -} 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 @@ -#![no_std] -#![feature(async_fn_in_trait, impl_trait_projections)] -#![allow(stable_features, unknown_lints, async_fn_in_trait)] -//! embassy-lora holds LoRa-specific functionality. - -pub(crate) mod fmt; - -/// interface variants required by the external lora physical layer crate (lora-phy) -pub mod iv; - -#[cfg(feature = "time")] -use embassy_time::{Duration, Instant, Timer}; - -/// A convenience timer to use with the LoRaWAN crate -#[cfg(feature = "time")] -pub struct LoraTimer { - start: Instant, -} - -#[cfg(feature = "time")] -impl LoraTimer { - pub fn new() -> Self { - Self { start: Instant::now() } - } -} - -#[cfg(feature = "time")] -impl lorawan_device::async_device::radio::Timer for LoraTimer { - fn reset(&mut self) { - self.start = Instant::now(); - } - - async fn at(&mut self, millis: u64) { - Timer::at(self.start + Duration::from_millis(millis)).await - } - - async fn delay_ms(&mut self, millis: u64) { - Timer::after_millis(millis).await - } -} 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" heapless = "0.8" defmt = { version = "0.3", optional = true } log = { version = "0.4", default-features = false, optional = true } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-hal-bus = { version = "=0.1.0-rc.1", features = ["async"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } embassy-time = { version = "0.1.5", path = "../embassy-time" } embassy-futures = { version = "0.1.0", path = "../embassy-futures" } bitfield = "0.14.0" [dev-dependencies] -embedded-hal-mock = { version = "=0.10.0-rc.1", features = ["embedded-hal-async", "eh1"] } +embedded-hal-mock = { git = "https://github.com/Dirbaio/embedded-hal-mock", rev = "c5c4dca18e043e6386aee02173f61a65fea3981e", features = ["embedded-hal-async", "eh1"] } crc = "3.0.1" env_logger = "0.10" 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 { use core::convert::Infallible; use embedded_hal_1::digital::{ErrorType, OutputPin}; - use embedded_hal_async::delay::DelayUs; + use embedded_hal_async::delay::DelayNs; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_hal_mock::common::Generic; use embedded_hal_mock::eh1::spi::{Mock as SpiMock, Transaction as SpiTransaction}; @@ -760,7 +760,11 @@ mod tests { // see https://github.com/rust-embedded/embedded-hal/pull/462#issuecomment-1560014426 struct MockDelay {} - impl DelayUs for MockDelay { + impl DelayNs for MockDelay { + async fn delay_ns(&mut self, _ns: u32) { + todo!() + } + async fn delay_us(&mut self, _us: u32) { todo!() } 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" edition = "2021" [dependencies] -embedded-hal = { version = "1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } +embedded-hal = { version = "1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" } embassy-time = { version = "0.1.5", path = "../embassy-time" } 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"} embassy-futures = { version = "0.1.0", path = "../embassy-futures"} embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel"} -embedded-hal = { version = "1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } +embedded-hal = { version = "1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } noproto = { git="https://github.com/embassy-rs/noproto", rev = "f5e6d1f325b6ad4e344f60452b09576e24671f62", default-features = false, features = ["derive"] } #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"] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } embassy-futures = { version = "0.1.0", path = "../embassy-futures" } 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" edition = "2021" [dependencies] -embedded-hal = { version = "1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } +embedded-hal = { version = "1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } embassy-time = { version = "0.1.5", path = "../embassy-time" } 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 embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" } embassy-time = { version = "0.1.5", path = "../embassy-time" } embassy-sync = { version = "0.4.0", path = "../embassy-sync" } -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } managed = { version = "0.8.0", default-features = false, features = [ "map" ] } heapless = { version = "0.8", default-features = false } @@ -63,4 +63,4 @@ generic-array = { version = "0.14.4", default-features = false } stable_deref_trait = { version = "1.2.0", default-features = false } futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } atomic-pool = "1.0" -embedded-nal-async = { version = "0.7", optional = true } +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" } embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optional=true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} embedded-io = { version = "0.6.0" } -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } defmt = { version = "0.3", optional = true } 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" futures = { version = "0.3.17", default-features = false, features = ["async-await"] } chrono = { version = "0.4", default-features = false, optional = true } embedded-io = { version = "0.6.0" } -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } embedded-storage = { version = "0.3" } embedded-storage-async = { version = "0.4.0", optional = true } rand_core = "0.6.4" @@ -85,9 +85,9 @@ fixed = "1.23.1" rp-pac = { version = "6" } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} -embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true} +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} +embedded-hal-nb = { version = "=1.0.0-rc.2", optional = true} pio-proc = {version= "0.2" } 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 embassy-executor = { version = "0.3.3", path = "../embassy-executor", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} -embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true} +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} +embedded-hal-nb = { version = "=1.0.0-rc.2", optional = true} embedded-storage = "0.3.0" embedded-storage-async = { version = "0.4.0", optional = true } @@ -65,7 +65,7 @@ nb = "1.0.0" stm32-fmc = "0.3.0" cfg-if = "1.0.0" embedded-io = { version = "0.6.0" } -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } chrono = { version = "^0.4", default-features = false, optional = true} bit_field = "0.10.2" 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 } critical-section = "1.1" heapless = "0.8" cfg-if = "1.0.0" -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } [dev-dependencies] 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 ## 0.1.3 - 2023-08-28 -- Update `embedded-hal-async` to `1.0.0-rc.1` -- Update `embedded-hal v1` to `1.0.0-rc.1` +- Update `embedded-hal-async` to `1.0.0-rc.2` +- Update `embedded-hal v1` to `1.0.0-rc.2` ## 0.1.2 - 2023-07-05 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 } log = { version = "0.4.14", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} futures-util = { version = "0.3.17", default-features = false } 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; mod eh1 { use super::*; - impl embedded_hal_1::delay::DelayUs for Delay { + impl embedded_hal_1::delay::DelayNs for Delay { + fn delay_ns(&mut self, ns: u32) { + block_for(Duration::from_nanos(ns as u64)) + } + fn delay_us(&mut self, us: u32) { block_for(Duration::from_micros(us as u64)) } @@ -34,13 +38,17 @@ mod eha { use super::*; use crate::Timer; - impl embedded_hal_async::delay::DelayUs for Delay { - async fn delay_us(&mut self, micros: u32) { - Timer::after_micros(micros as _).await + impl embedded_hal_async::delay::DelayNs for Delay { + async fn delay_ns(&mut self, ns: u32) { + Timer::after_nanos(ns as _).await } - async fn delay_ms(&mut self, millis: u32) { - Timer::after_millis(millis as _).await + async fn delay_us(&mut self, us: u32) { + Timer::after_micros(us as _).await + } + + async fn delay_ms(&mut self, ms: u32) { + Timer::after_millis(ms as _).await } } } 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; use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; use super::{GCD_1K, GCD_1M, TICK_HZ}; +use crate::GCD_1G; #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -61,6 +62,14 @@ impl Duration { } } + /// Creates a duration from the specified number of nanoseconds, rounding up. + /// NOTE: Delays this small may be inaccurate. + pub const fn from_nanos(micros: u64) -> Duration { + Duration { + ticks: div_ceil(micros * (TICK_HZ / GCD_1G), 1_000_000_000 / GCD_1G), + } + } + /// Creates a duration from the specified number of seconds, rounding down. pub const fn from_secs_floor(secs: u64) -> Duration { 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 { pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000); pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000); +pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000); #[cfg(feature = "defmt-timestamp-uptime")] 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 { Self::after(Duration::from_ticks(ticks)) } + /// Expire after the specified number of nanoseconds. + /// + /// This method is a convenience wrapper for calling `Timer::after(Duration::from_nanos())`. + /// For more details, refer to [`Timer::after()`] and [`Duration::from_nanos()`]. + #[inline] + pub fn after_nanos(nanos: u64) -> Self { + Self::after(Duration::from_nanos(nanos)) + } + /// Expire after the specified number of microseconds. /// /// 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 = [ "embedded-io-async", "embedded-hal-bus/async", "embassy-net", - "embassy-lora", - "lora-phy", - "lorawan-device", - "lorawan", ] [dependencies] @@ -36,11 +32,7 @@ embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defm embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], optional = true } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } embedded-io = { version = "0.6.0", features = ["defmt-03"] } -embedded-io-async = { version = "0.6.0", optional = true, features = ["defmt-03"] } -embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true } -lora-phy = { version = "2", optional = true } -lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"], optional = true } -lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"], optional = true } +embedded-io-async = { version = "0.6.1", optional = true, features = ["defmt-03"] } embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"], optional = true } embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"], optional = true } @@ -57,9 +49,9 @@ rand = { version = "0.8.4", default-features = false } embedded-storage = "0.3.0" usbd-hid = "0.6.0" serde = { version = "1.0.136", default-features = false } -embedded-hal = { version = "1.0.0-rc.1" } -embedded-hal-async = { version = "1.0.0-rc.1", optional = true } -embedded-hal-bus = { version = "0.1.0-rc.1" } +embedded-hal = { version = "1.0.0-rc.2" } +embedded-hal-async = { version = "1.0.0-rc.2", optional = true } +embedded-hal-bus = { version = "0.1.0-rc.2" } num-integer = { version = "0.1.45", default-features = false } microfft = "0.5.0" 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 @@ -//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio. -//! Other nrf/sx126x combinations may work with appropriate pin modifications. -//! It demonstrates LORA CAD functionality. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::GenericSx126xInterfaceVariant; -use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; -use embassy_nrf::{bind_interrupts, peripherals, spim}; -use embassy_time::{Delay, Timer}; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -bind_interrupts!(struct Irqs { - SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler; -}); - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let mut spi_config = spim::Config::default(); - spi_config.frequency = spim::Frequency::M16; - - let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config); - - let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard); - let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard); - let dio1 = Input::new(p.P1_15.degrade(), Pull::Down); - let busy = Input::new(p.P1_14.degrade(), Pull::Down); - let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard); - let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard); - - let iv = - GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap(); - - let mut lora = { - match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut debug_indicator = Output::new(p.P1_03, Level::Low, OutputDrive::Standard); - let mut start_indicator = Output::new(p.P1_04, Level::Low, OutputDrive::Standard); - - start_indicator.set_high(); - Timer::after_secs(5).await; - start_indicator.set_low(); - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - match lora.prepare_for_cad(&mdltn_params, true).await { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - match lora.cad().await { - Ok(cad_activity_detected) => { - if cad_activity_detected { - info!("cad successful with activity detected") - } else { - info!("cad successful without activity detected") - } - debug_indicator.set_high(); - Timer::after_secs(5).await; - debug_indicator.set_low(); - } - Err(err) => info!("cad unsuccessful = {}", err), - } -} 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 @@ -//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio. -//! Other nrf/sx126x combinations may work with appropriate pin modifications. -//! It demonstrates LoRaWAN join functionality. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::GenericSx126xInterfaceVariant; -use embassy_lora::LoraTimer; -use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; -use embassy_nrf::rng::Rng; -use embassy_nrf::{bind_interrupts, peripherals, rng, spim}; -use embassy_time::Delay; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use lorawan::default_crypto::DefaultFactory as Crypto; -use lorawan_device::async_device::lora_radio::LoRaRadio; -use lorawan_device::async_device::{region, Device, JoinMode}; -use lorawan_device::{AppEui, AppKey, DevEui}; -use {defmt_rtt as _, panic_probe as _}; - -const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region - -bind_interrupts!(struct Irqs { - SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler; - RNG => rng::InterruptHandler; -}); - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let mut spi_config = spim::Config::default(); - spi_config.frequency = spim::Frequency::M16; - - let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config); - - let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard); - let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard); - let dio1 = Input::new(p.P1_15.degrade(), Pull::Down); - let busy = Input::new(p.P1_14.degrade(), Pull::Down); - let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard); - let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard); - - let iv = - GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap(); - - let lora = { - match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), true, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let radio = LoRaRadio::new(lora); - let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); - let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs)); - - defmt::info!("Joining LoRaWAN network"); - - // TODO: Adjust the EUI and Keys according to your network credentials - match device - .join(&JoinMode::OTAA { - deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]), - appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]), - appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), - }) - .await - { - Ok(()) => defmt::info!("LoRaWAN network joined"), - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; -} 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 @@ -//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio. -//! Other nrf/sx126x combinations may work with appropriate pin modifications. -//! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::GenericSx126xInterfaceVariant; -use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; -use embassy_nrf::{bind_interrupts, peripherals, spim}; -use embassy_time::{Delay, Timer}; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -bind_interrupts!(struct Irqs { - SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler; -}); - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let mut spi_config = spim::Config::default(); - spi_config.frequency = spim::Frequency::M16; - - let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config); - - let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard); - let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard); - let dio1 = Input::new(p.P1_15.degrade(), Pull::Down); - let busy = Input::new(p.P1_14.degrade(), Pull::Down); - let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard); - let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard); - - let iv = - GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap(); - - let mut lora = { - match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut debug_indicator = Output::new(p.P1_03, Level::Low, OutputDrive::Standard); - let mut start_indicator = Output::new(p.P1_04, Level::Low, OutputDrive::Standard); - - start_indicator.set_high(); - Timer::after_secs(5).await; - start_indicator.set_low(); - - let mut receiving_buffer = [00u8; 100]; - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let rx_pkt_params = { - match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) { - Ok(pp) => pp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - match lora - .prepare_for_rx(&mdltn_params, &rx_pkt_params, None, None, false) - .await - { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - loop { - receiving_buffer = [00u8; 100]; - match lora.rx(&rx_pkt_params, &mut receiving_buffer).await { - Ok((received_len, _rx_pkt_status)) => { - if (received_len == 3) - && (receiving_buffer[0] == 0x01u8) - && (receiving_buffer[1] == 0x02u8) - && (receiving_buffer[2] == 0x03u8) - { - info!("rx successful"); - debug_indicator.set_high(); - Timer::after_secs(5).await; - debug_indicator.set_low(); - } else { - info!("rx unknown packet"); - } - } - Err(err) => info!("rx unsuccessful = {}", err), - } - } -} 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 @@ -//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio. -//! Other nrf/sx126x combinations may work with appropriate pin modifications. -//! It demonstrates LoRa Rx duty cycle functionality in conjunction with the lora_p2p_send example. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::GenericSx126xInterfaceVariant; -use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; -use embassy_nrf::{bind_interrupts, peripherals, spim}; -use embassy_time::{Delay, Timer}; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -bind_interrupts!(struct Irqs { - SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler; -}); - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let mut spi_config = spim::Config::default(); - spi_config.frequency = spim::Frequency::M16; - - let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config); - - let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard); - let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard); - let dio1 = Input::new(p.P1_15.degrade(), Pull::Down); - let busy = Input::new(p.P1_14.degrade(), Pull::Down); - let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard); - let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard); - - let iv = - GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap(); - - let mut lora = { - match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut debug_indicator = Output::new(p.P1_03, Level::Low, OutputDrive::Standard); - let mut start_indicator = Output::new(p.P1_04, Level::Low, OutputDrive::Standard); - - start_indicator.set_high(); - Timer::after_secs(5).await; - start_indicator.set_low(); - - let mut receiving_buffer = [00u8; 100]; - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let rx_pkt_params = { - match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) { - Ok(pp) => pp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - // 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. - match lora - .prepare_for_rx( - &mdltn_params, - &rx_pkt_params, - None, - Some(&DutyCycleParams { - rx_time: 300_000, // 300_000 units * 15.625 us/unit = 4.69 s - sleep_time: 200_000, // 200_000 units * 15.625 us/unit = 3.13 s - }), - false, - ) - .await - { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - receiving_buffer = [00u8; 100]; - match lora.rx(&rx_pkt_params, &mut receiving_buffer).await { - Ok((received_len, _rx_pkt_status)) => { - if (received_len == 3) - && (receiving_buffer[0] == 0x01u8) - && (receiving_buffer[1] == 0x02u8) - && (receiving_buffer[2] == 0x03u8) - { - info!("rx successful"); - debug_indicator.set_high(); - Timer::after_secs(5).await; - debug_indicator.set_low(); - } else { - info!("rx unknown packet") - } - } - Err(err) => info!("rx unsuccessful = {}", err), - } -} 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 @@ -//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio. -//! Other nrf/sx126x combinations may work with appropriate pin modifications. -//! It demonstrates LORA P2P send functionality. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::GenericSx126xInterfaceVariant; -use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull}; -use embassy_nrf::{bind_interrupts, peripherals, spim}; -use embassy_time::Delay; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -bind_interrupts!(struct Irqs { - SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler; -}); - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_nrf::init(Default::default()); - let mut spi_config = spim::Config::default(); - spi_config.frequency = spim::Frequency::M16; - - let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config); - - let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard); - let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard); - let dio1 = Input::new(p.P1_15.degrade(), Pull::Down); - let busy = Input::new(p.P1_14.degrade(), Pull::Down); - let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard); - let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard); - - let iv = - GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap(); - - let mut lora = { - match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut tx_pkt_params = { - match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) { - Ok(pp) => pp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - match lora.prepare_for_tx(&mdltn_params, 20, false).await { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - let buffer = [0x01u8, 0x02u8, 0x03u8]; - match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await { - Ok(()) => { - info!("TX DONE"); - } - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - match lora.sleep(false).await { - Ok(()) => info!("Sleep successful"), - Err(err) => info!("Sleep unsuccessful = {}", err), - } -} 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 = [ embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = [ "defmt", ] } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } defmt = "0.3" 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 embassy-net-wiznet = { version = "0.1.0", path = "../../embassy-net-wiznet", features = ["defmt"] } embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } embassy-usb-logger = { version = "0.1.0", path = "../../embassy-usb-logger" } -embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"] } -lora-phy = { version = "2" } -lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"] } -lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"] } cyw43 = { path = "../../cyw43", features = ["defmt", "firmware-logs"] } cyw43-pio = { path = "../../cyw43-pio", features = ["defmt", "overclock"] } @@ -42,10 +38,10 @@ smart-leds = "0.3.0" heapless = "0.8" usbd-hid = "0.6.1" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = "1.0.0-rc.1" -embedded-hal-bus = { version = "0.1.0-rc.1", features = ["async"] } -embedded-io-async = { version = "0.6.0", features = ["defmt-03"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = "1.0.0-rc.2" +embedded-hal-bus = { version = "0.1.0-rc.2", features = ["async"] } +embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } embedded-storage = { version = "0.3" } static_cell = { version = "2", features = ["nightly"]} 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 @@ -//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. -//! It demonstrates LoRaWAN join functionality. - -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::GenericSx126xInterfaceVariant; -use embassy_lora::LoraTimer; -use embassy_rp::gpio::{Input, Level, Output, Pin, Pull}; -use embassy_rp::spi::{Config, Spi}; -use embassy_time::Delay; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use lorawan::default_crypto::DefaultFactory as Crypto; -use lorawan_device::async_device::lora_radio::LoRaRadio; -use lorawan_device::async_device::{region, Device, JoinMode}; -use lorawan_device::{AppEui, AppKey, DevEui}; -use {defmt_rtt as _, panic_probe as _}; - -const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_rp::init(Default::default()); - - let miso = p.PIN_12; - let mosi = p.PIN_11; - let clk = p.PIN_10; - let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); - - let nss = Output::new(p.PIN_3.degrade(), Level::High); - let reset = Output::new(p.PIN_15.degrade(), Level::High); - let dio1 = Input::new(p.PIN_20.degrade(), Pull::None); - let busy = Input::new(p.PIN_2.degrade(), Pull::None); - - let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap(); - - let lora = { - match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, spi, iv), true, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let radio = LoRaRadio::new(lora); - let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); - let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), embassy_rp::clocks::RoscRng); - - defmt::info!("Joining LoRaWAN network"); - - // TODO: Adjust the EUI and Keys according to your network credentials - match device - .join(&JoinMode::OTAA { - deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]), - appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]), - appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), - }) - .await - { - Ok(()) => defmt::info!("LoRaWAN network joined"), - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; -} 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 @@ -//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. -//! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example. - -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::GenericSx126xInterfaceVariant; -use embassy_rp::gpio::{Input, Level, Output, Pin, Pull}; -use embassy_rp::spi::{Config, Spi}; -use embassy_time::{Delay, Timer}; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_rp::init(Default::default()); - - let miso = p.PIN_12; - let mosi = p.PIN_11; - let clk = p.PIN_10; - let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); - - let nss = Output::new(p.PIN_3.degrade(), Level::High); - let reset = Output::new(p.PIN_15.degrade(), Level::High); - let dio1 = Input::new(p.PIN_20.degrade(), Pull::None); - let busy = Input::new(p.PIN_2.degrade(), Pull::None); - - let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap(); - - let mut lora = { - match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, spi, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut debug_indicator = Output::new(p.PIN_25, Level::Low); - - let mut receiving_buffer = [00u8; 100]; - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let rx_pkt_params = { - match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) { - Ok(pp) => pp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - match lora - .prepare_for_rx(&mdltn_params, &rx_pkt_params, None, None, false) - .await - { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - loop { - receiving_buffer = [00u8; 100]; - match lora.rx(&rx_pkt_params, &mut receiving_buffer).await { - Ok((received_len, _rx_pkt_status)) => { - if (received_len == 3) - && (receiving_buffer[0] == 0x01u8) - && (receiving_buffer[1] == 0x02u8) - && (receiving_buffer[2] == 0x03u8) - { - info!("rx successful"); - debug_indicator.set_high(); - Timer::after_secs(5).await; - debug_indicator.set_low(); - } else { - info!("rx unknown packet"); - } - } - Err(err) => info!("rx unsuccessful = {}", err), - } - } -} 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 @@ -//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. -//! It demonstrates LORA P2P send functionality. - -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::GenericSx126xInterfaceVariant; -use embassy_rp::gpio::{Input, Level, Output, Pin, Pull}; -use embassy_rp::spi::{Config, Spi}; -use embassy_time::Delay; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_rp::init(Default::default()); - - let miso = p.PIN_12; - let mosi = p.PIN_11; - let clk = p.PIN_10; - let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); - - let nss = Output::new(p.PIN_3.degrade(), Level::High); - let reset = Output::new(p.PIN_15.degrade(), Level::High); - let dio1 = Input::new(p.PIN_20.degrade(), Pull::None); - let busy = Input::new(p.PIN_2.degrade(), Pull::None); - - let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap(); - - let mut lora = { - match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, spi, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut tx_pkt_params = { - match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) { - Ok(pp) => pp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - match lora.prepare_for_tx(&mdltn_params, 20, false).await { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - let buffer = [0x01u8, 0x02u8, 0x03u8]; - match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await { - Ok(()) => { - info!("TX DONE"); - } - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - match lora.sleep(false).await { - Ok(()) => info!("Sleep successful"), - Err(err) => info!("Sleep unsuccessful = {}", err), - } -} 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 @@ -//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio. -//! It demonstrates LORA P2P send functionality using the second core, with data provided by the first core. - -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Executor; -use embassy_lora::iv::GenericSx126xInterfaceVariant; -use embassy_rp::gpio::{AnyPin, Input, Level, Output, Pin, Pull}; -use embassy_rp::multicore::{spawn_core1, Stack}; -use embassy_rp::peripherals::SPI1; -use embassy_rp::spi::{Async, Config, Spi}; -use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; -use embassy_sync::channel::Channel; -use embassy_time::{Delay, Timer}; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use static_cell::StaticCell; -use {defmt_rtt as _, panic_probe as _}; - -static mut CORE1_STACK: Stack<4096> = Stack::new(); -static EXECUTOR0: StaticCell = StaticCell::new(); -static EXECUTOR1: StaticCell = StaticCell::new(); -static CHANNEL: Channel = Channel::new(); - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -#[cortex_m_rt::entry] -fn main() -> ! { - let p = embassy_rp::init(Default::default()); - - let miso = p.PIN_12; - let mosi = p.PIN_11; - let clk = p.PIN_10; - let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); - - let nss = Output::new(p.PIN_3.degrade(), Level::High); - let reset = Output::new(p.PIN_15.degrade(), Level::High); - let dio1 = Input::new(p.PIN_20.degrade(), Pull::None); - let busy = Input::new(p.PIN_2.degrade(), Pull::None); - - let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap(); - - spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || { - let executor1 = EXECUTOR1.init(Executor::new()); - executor1.run(|spawner| unwrap!(spawner.spawn(core1_task(spi, iv)))); - }); - - let executor0 = EXECUTOR0.init(Executor::new()); - executor0.run(|spawner| unwrap!(spawner.spawn(core0_task()))); -} - -#[embassy_executor::task] -async fn core0_task() { - info!("Hello from core 0"); - loop { - CHANNEL.send([0x01u8, 0x02u8, 0x03u8]).await; - Timer::after_millis(60 * 1000).await; - } -} - -#[embassy_executor::task] -async fn core1_task( - spi: Spi<'static, SPI1, Async>, - iv: GenericSx126xInterfaceVariant, Input<'static, AnyPin>>, -) { - info!("Hello from core 1"); - - let mut lora = { - match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, spi, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut tx_pkt_params = { - match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) { - Ok(pp) => pp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - loop { - let buffer: [u8; 3] = CHANNEL.receive().await; - match lora.prepare_for_tx(&mdltn_params, 20, false).await { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await { - Ok(()) => { - info!("TX DONE"); - } - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - match lora.sleep(false).await { - Ok(()) => info!("Sleep successful"), - Err(err) => info!("Sleep unsuccessful = {}", err), - } - } -} 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 embassy-net = { version = "0.2.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "medium-ip", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6"] } embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" } embassy-net-ppp = { version = "0.1.0", path = "../../embassy-net-ppp", features = ["log"]} -embedded-io-async = { version = "0.6.0" } -embedded-io-adapters = { version = "0.6.0", features = ["futures-03"] } +embedded-io-async = { version = "0.6.1" } +embedded-io-adapters = { version = "0.6.1", features = ["futures-03"] } critical-section = { version = "1.1", features = ["std"] } 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 cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" embedded-io = { version = "0.6.0" } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 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 embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 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 embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6"] } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } defmt = "0.3" @@ -20,9 +20,9 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-nal-async = { version = "0.7" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-nal-async = { version = "0.7.1" } panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 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 embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6", "dns"] } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } defmt = "0.3" @@ -20,9 +20,9 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-nal-async = { version = "0.7" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-nal-async = { version = "0.7.1" } panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 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" [features] default = ["nightly"] -nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstable-traits", "embassy-executor/nightly", - "embassy-lora", "lora-phy", "lorawan-device", "lorawan", "dep:embedded-io-async"] +nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstable-traits", "embassy-executor/nightly", "dep:embedded-io-async"] [dependencies] # Change stm32l072cz to your chip name, if necessary. @@ -15,17 +14,13 @@ embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [" embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["defmt"] } embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } -embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true } -lora-phy = { version = "2", optional = true } -lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"], optional = true } -lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"], optional = true } defmt = "0.3" defmt-rtt = "0.4" embedded-storage = "0.3.0" embedded-io = { version = "0.6.0" } -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } 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 @@ -//! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio. -//! It demonstrates LORA P2P CAD functionality. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::Stm32l0InterfaceVariant; -use embassy_stm32::exti::{Channel, ExtiInput}; -use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; -use embassy_stm32::spi; -use embassy_stm32::time::khz; -use embassy_time::{Delay, Timer}; -use lora_phy::mod_params::*; -use lora_phy::sx1276_7_8_9::SX1276_7_8_9; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let mut config = embassy_stm32::Config::default(); - config.rcc.hsi = true; - config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI; - let p = embassy_stm32::init(config); - - let mut spi_config = spi::Config::default(); - spi_config.frequency = khz(200); - - // SPI for sx1276 - let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config); - - let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); - let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); - - let irq_pin = Input::new(p.PB4.degrade(), Pull::Up); - let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade()); - - let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap(); - - let mut lora = { - match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut debug_indicator = Output::new(p.PB5, Level::Low, Speed::Low); - let mut start_indicator = Output::new(p.PB6, Level::Low, Speed::Low); - - start_indicator.set_high(); - Timer::after_secs(5).await; - start_indicator.set_low(); - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - match lora.prepare_for_cad(&mdltn_params, true).await { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - match lora.cad().await { - Ok(cad_activity_detected) => { - if cad_activity_detected { - info!("cad successful with activity detected") - } else { - info!("cad successful without activity detected") - } - debug_indicator.set_high(); - Timer::after_secs(5).await; - debug_indicator.set_low(); - } - Err(err) => info!("cad unsuccessful = {}", err), - } -} 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 @@ -//! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio. -//! It demonstrates LoRaWAN join functionality. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::Stm32l0InterfaceVariant; -use embassy_lora::LoraTimer; -use embassy_stm32::exti::{Channel, ExtiInput}; -use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; -use embassy_stm32::rng::Rng; -use embassy_stm32::time::khz; -use embassy_stm32::{bind_interrupts, peripherals, rng, spi}; -use embassy_time::Delay; -use lora_phy::mod_params::*; -use lora_phy::sx1276_7_8_9::SX1276_7_8_9; -use lora_phy::LoRa; -use lorawan::default_crypto::DefaultFactory as Crypto; -use lorawan_device::async_device::lora_radio::LoRaRadio; -use lorawan_device::async_device::{region, Device, JoinMode}; -use lorawan_device::{AppEui, AppKey, DevEui}; -use {defmt_rtt as _, panic_probe as _}; - -bind_interrupts!(struct Irqs { - RNG_LPUART1 => rng::InterruptHandler; -}); - -const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let mut config = embassy_stm32::Config::default(); - config.rcc.hsi = true; - config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI; - let p = embassy_stm32::init(config); - - let mut spi_config = spi::Config::default(); - spi_config.frequency = khz(200); - - // SPI for sx1276 - let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config); - - let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); - let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); - - let irq_pin = Input::new(p.PB4.degrade(), Pull::Up); - let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade()); - - let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap(); - - let lora = { - match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, iv), true, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let radio = LoRaRadio::new(lora); - let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); - let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs)); - - defmt::info!("Joining LoRaWAN network"); - - // TODO: Adjust the EUI and Keys according to your network credentials - match device - .join(&JoinMode::OTAA { - deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]), - appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]), - appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), - }) - .await - { - Ok(()) => defmt::info!("LoRaWAN network joined"), - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; -} 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 @@ -//! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio. -//! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::Stm32l0InterfaceVariant; -use embassy_stm32::exti::{Channel, ExtiInput}; -use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; -use embassy_stm32::spi; -use embassy_stm32::time::khz; -use embassy_time::{Delay, Timer}; -use lora_phy::mod_params::*; -use lora_phy::sx1276_7_8_9::SX1276_7_8_9; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let mut config = embassy_stm32::Config::default(); - config.rcc.hsi = true; - config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI; - let p = embassy_stm32::init(config); - - let mut spi_config = spi::Config::default(); - spi_config.frequency = khz(200); - - // SPI for sx1276 - let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config); - - let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); - let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); - - let irq_pin = Input::new(p.PB4.degrade(), Pull::Up); - let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade()); - - let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap(); - - let mut lora = { - match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut debug_indicator = Output::new(p.PB5, Level::Low, Speed::Low); - let mut start_indicator = Output::new(p.PB6, Level::Low, Speed::Low); - - start_indicator.set_high(); - Timer::after_secs(5).await; - start_indicator.set_low(); - - let mut receiving_buffer = [00u8; 100]; - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let rx_pkt_params = { - match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) { - Ok(pp) => pp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - match lora - .prepare_for_rx(&mdltn_params, &rx_pkt_params, None, None, false) - .await - { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - loop { - receiving_buffer = [00u8; 100]; - match lora.rx(&rx_pkt_params, &mut receiving_buffer).await { - Ok((received_len, _rx_pkt_status)) => { - if (received_len == 3) - && (receiving_buffer[0] == 0x01u8) - && (receiving_buffer[1] == 0x02u8) - && (receiving_buffer[2] == 0x03u8) - { - info!("rx successful"); - debug_indicator.set_high(); - Timer::after_secs(5).await; - debug_indicator.set_low(); - } else { - info!("rx unknown packet"); - } - } - Err(err) => info!("rx unsuccessful = {}", err), - } - } -} 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 @@ -//! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio. -//! It demonstrates LORA P2P send functionality. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait)] - -use defmt::*; -use embassy_executor::Spawner; -use embassy_lora::iv::Stm32l0InterfaceVariant; -use embassy_stm32::exti::{Channel, ExtiInput}; -use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; -use embassy_stm32::spi; -use embassy_stm32::time::khz; -use embassy_time::Delay; -use lora_phy::mod_params::*; -use lora_phy::sx1276_7_8_9::SX1276_7_8_9; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let mut config = embassy_stm32::Config::default(); - config.rcc.hsi = true; - config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI; - let p = embassy_stm32::init(config); - - let mut spi_config = spi::Config::default(); - spi_config.frequency = khz(200); - - // SPI for sx1276 - let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config); - - let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); - let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); - - let irq_pin = Input::new(p.PB4.degrade(), Pull::Up); - let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade()); - - let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap(); - - let mut lora = { - match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut tx_pkt_params = { - match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) { - Ok(pp) => pp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - match lora.prepare_for_tx(&mdltn_params, 17, true).await { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - let buffer = [0x01u8, 0x02u8, 0x03u8]; - match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await { - Ok(()) => { - info!("TX DONE"); - } - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - match lora.sleep(false).await { - Ok(()) => info!("Sleep successful"), - Err(err) => info!("Sleep unsuccessful = {}", err), - } -} 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 embassy-net-adin1110 = { version = "0.2.0", path = "../../embassy-net-adin1110" } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "udp", "tcp", "dhcpv4", "medium-ethernet"] } embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } -embedded-io-async = { version = "0.6.0", features = ["defmt-03"] } +embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } embedded-io = { version = "0.6.0", features = ["defmt-03"] } defmt = "0.3" @@ -24,9 +24,9 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-hal-bus = { version = "=0.1.0-rc.1", features = ["async"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 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" futures = { version = "0.3.17", default-features = false, features = ["async-await"] } heapless = { version = "0.8", default-features = false } rand_core = { version = "0.6.3", default-features = false } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } static_cell = { version = "2", features = ["nightly"]} [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 embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } -embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } -lora-phy = { version = "2" } -lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"] } -lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"] } defmt = "0.3" 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 @@ -//! This example runs on a STM32WL board, which has a builtin Semtech Sx1262 radio. -//! It demonstrates LoRaWAN join functionality. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait, async_fn_in_trait)] -#![allow(stable_features, unknown_lints, async_fn_in_trait)] - -use defmt::info; -use embassy_executor::Spawner; -use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant}; -use embassy_lora::LoraTimer; -use embassy_stm32::gpio::{Level, Output, Pin, Speed}; -use embassy_stm32::rng::{self, Rng}; -use embassy_stm32::spi::Spi; -use embassy_stm32::time::Hertz; -use embassy_stm32::{bind_interrupts, peripherals}; -use embassy_time::Delay; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use lorawan::default_crypto::DefaultFactory as Crypto; -use lorawan_device::async_device::lora_radio::LoRaRadio; -use lorawan_device::async_device::{region, Device, JoinMode}; -use lorawan_device::{AppEui, AppKey, DevEui}; -use {defmt_rtt as _, panic_probe as _}; - -const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region - -bind_interrupts!(struct Irqs{ - SUBGHZ_RADIO => InterruptHandler; - RNG => rng::InterruptHandler; -}); - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let mut config = embassy_stm32::Config::default(); - { - use embassy_stm32::rcc::*; - config.rcc.hse = Some(Hse { - freq: Hertz(32_000_000), - mode: HseMode::Bypass, - prescaler: HsePrescaler::DIV1, - }); - config.rcc.mux = ClockSrc::PLL1_R; - config.rcc.pll = Some(Pll { - source: PllSource::HSE, - prediv: PllPreDiv::DIV2, - mul: PllMul::MUL6, - divp: None, - divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG - divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2) - }); - } - let p = embassy_stm32::init(config); - - let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); - - // Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx - let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High); - let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High); - let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High); - let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap(); - - let lora = { - match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), true, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - let radio = LoRaRadio::new(lora); - let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); - let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs)); - - defmt::info!("Joining LoRaWAN network"); - - // TODO: Adjust the EUI and Keys according to your network credentials - match device - .join(&JoinMode::OTAA { - deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]), - appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]), - appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), - }) - .await - { - Ok(()) => defmt::info!("LoRaWAN network joined"), - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; -} 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 @@ -//! This example runs on the STM32WL board, which has a builtin Semtech Sx1262 radio. -//! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait, async_fn_in_trait)] -#![allow(stable_features, unknown_lints, async_fn_in_trait)] - -use defmt::info; -use embassy_executor::Spawner; -use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant}; -use embassy_stm32::bind_interrupts; -use embassy_stm32::gpio::{Level, Output, Pin, Speed}; -use embassy_stm32::spi::Spi; -use embassy_stm32::time::Hertz; -use embassy_time::{Delay, Timer}; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -bind_interrupts!(struct Irqs{ - SUBGHZ_RADIO => InterruptHandler; -}); - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let mut config = embassy_stm32::Config::default(); - { - use embassy_stm32::rcc::*; - config.rcc.hse = Some(Hse { - freq: Hertz(32_000_000), - mode: HseMode::Bypass, - prescaler: HsePrescaler::DIV1, - }); - config.rcc.mux = ClockSrc::PLL1_R; - config.rcc.pll = Some(Pll { - source: PllSource::HSE, - prediv: PllPreDiv::DIV2, - mul: PllMul::MUL6, - divp: None, - divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG - divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2) - }); - } - let p = embassy_stm32::init(config); - - let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); - - // Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx - let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High); - let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High); - let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High); - let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap(); - - let mut lora = { - match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut debug_indicator = Output::new(p.PB9, Level::Low, Speed::Low); - let mut start_indicator = Output::new(p.PB15, Level::Low, Speed::Low); - - start_indicator.set_high(); - Timer::after_secs(5).await; - start_indicator.set_low(); - - let mut receiving_buffer = [00u8; 100]; - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let rx_pkt_params = { - match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) { - Ok(pp) => pp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - match lora - .prepare_for_rx(&mdltn_params, &rx_pkt_params, None, None, false) - .await - { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - loop { - receiving_buffer = [00u8; 100]; - match lora.rx(&rx_pkt_params, &mut receiving_buffer).await { - Ok((received_len, _rx_pkt_status)) => { - if (received_len == 3) - && (receiving_buffer[0] == 0x01u8) - && (receiving_buffer[1] == 0x02u8) - && (receiving_buffer[2] == 0x03u8) - { - info!("rx successful"); - debug_indicator.set_high(); - Timer::after_secs(5).await; - debug_indicator.set_low(); - } else { - info!("rx unknown packet"); - } - } - Err(err) => info!("rx unsuccessful = {}", err), - } - } -} 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 @@ -//! This example runs on a STM32WL board, which has a builtin Semtech Sx1262 radio. -//! It demonstrates LORA P2P send functionality. -#![no_std] -#![no_main] -#![macro_use] -#![feature(type_alias_impl_trait, async_fn_in_trait)] -#![allow(stable_features, unknown_lints, async_fn_in_trait)] - -use defmt::info; -use embassy_executor::Spawner; -use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant}; -use embassy_stm32::bind_interrupts; -use embassy_stm32::gpio::{Level, Output, Pin, Speed}; -use embassy_stm32::spi::Spi; -use embassy_stm32::time::Hertz; -use embassy_time::Delay; -use lora_phy::mod_params::*; -use lora_phy::sx1261_2::SX1261_2; -use lora_phy::LoRa; -use {defmt_rtt as _, panic_probe as _}; - -const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region - -bind_interrupts!(struct Irqs{ - SUBGHZ_RADIO => InterruptHandler; -}); - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let mut config = embassy_stm32::Config::default(); - { - use embassy_stm32::rcc::*; - config.rcc.hse = Some(Hse { - freq: Hertz(32_000_000), - mode: HseMode::Bypass, - prescaler: HsePrescaler::DIV1, - }); - config.rcc.mux = ClockSrc::PLL1_R; - config.rcc.pll = Some(Pll { - source: PllSource::HSE, - prediv: PllPreDiv::DIV2, - mul: PllMul::MUL6, - divp: None, - divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG - divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2) - }); - } - let p = embassy_stm32::init(config); - - let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); - - // Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx - let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High); - let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High); - let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High); - let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap(); - - let mut lora = { - match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), false, Delay).await { - Ok(l) => l, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mdltn_params = { - match lora.create_modulation_params( - SpreadingFactor::_10, - Bandwidth::_250KHz, - CodingRate::_4_8, - LORA_FREQUENCY_IN_HZ, - ) { - Ok(mp) => mp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - let mut tx_pkt_params = { - match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) { - Ok(pp) => pp, - Err(err) => { - info!("Radio error = {}", err); - return; - } - } - }; - - match lora.prepare_for_tx(&mdltn_params, 20, false).await { - Ok(()) => {} - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - let buffer = [0x01u8, 0x02u8, 0x03u8]; - match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await { - Ok(()) => { - info!("TX DONE"); - } - Err(err) => { - info!("Radio error = {}", err); - return; - } - }; - - match lora.sleep(false).await { - Ok(()) => info!("Sleep successful"), - Err(err) => info!("Sleep unsuccessful = {}", err), - } -} 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 embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-16384", "integrated-timers"] } embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] } embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } -embedded-io-async = { version = "0.6.0", features = ["defmt-03"] } +embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] } -embedded-hal-async = { version = "1.0.0-rc.1" } -embedded-hal-bus = { version = "0.1.0-rc.1", features = ["async"] } +embedded-hal-async = { version = "1.0.0-rc.2" } +embedded-hal-bus = { version = "0.1.0-rc.2", features = ["async"] } static_cell = { version = "2", features = [ "nightly" ] } perf-client = { path = "../perf-client" } 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" cortex-m = { version = "0.7.6" } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-hal-bus = { version = "=0.1.0-rc.1", features = ["async"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } embedded-storage = { version = "0.3" } static_cell = { version = "2", features = ["nightly"]} 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" cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } micromath = "2.0.0" panic-probe = { version = "0.3.0", features = ["print-defmt"] } rand_core = { version = "0.6", default-features = false }