diff --git a/Cargo.toml b/Cargo.toml index b459e8e..723b734 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,22 +16,19 @@ doctest = false [dependencies] atat = { version = "0.20.0", features = ["derive", "bytes"] } -embedded-hal = "=1.0.0-rc.1" -embedded-nal = "0.7" hash32 = "^0.3" heapless = { version = "^0.8", features = ["serde"] } nb = "^1" serde = { version = "^1", default-features = false, features = ["derive"] } ublox-sockets = { version = "0.5", optional = true } -embassy-time = "0.1.5" -embassy-sync = "0.4" +embassy-time = "0.2" +embassy-sync = "0.5" no-std-net = { version = "^0.6", features = ["serde"] } log = { version = "^0.4", default-features = false, optional = true } defmt = { version = "^0.3", optional = true } -embedded-nal-async = { version = "0.6", optional = true } futures-util = { version = "0.3.29", default-features = false } #futures = { version = "0.3.17", default-features = false, features = [ # "async-await", @@ -39,6 +36,11 @@ futures-util = { version = "0.3.29", default-features = false } embassy-futures = { version = "0.1", optional = true } +embedded-hal = "=1.0.0-rc.3" +embedded-nal = "0.8" +embedded-nal-async = { version = "0.7", optional = true } + + embedded-io = "0.6" embedded-io-async = "0.6" @@ -84,7 +86,10 @@ default-members = ["."] exclude = ["examples"] [patch.crates-io] -ublox-sockets = { git = "https://github.com/BlackbirdHQ/ublox-sockets", branch = "feature/async-borrowed-sockets" } +#ublox-sockets = { git = "https://github.com/BlackbirdHQ/ublox-sockets", branch = "feature/async-borrowed-sockets" } no-std-net = { git = "https://github.com/rushmorem/no-std-net", branch = "issue-15" } -#ublox-sockets = { path = "../ublox-sockets" } -atat = { path = "../atat/atat" } +ublox-sockets = { path = "../ublox-sockets" } +atat = { git = "https://github.com/BlackbirdHQ/atat", branch = "master" } +embassy-time = { package = "embassy-time", git = "https://github.com/embassy-rs/embassy", branch = "main" } +embassy-sync = { package = "embassy-sync", git = "https://github.com/embassy-rs/embassy", branch = "main" } +embassy-futures = { package = "embassy-futures", git = "https://github.com/embassy-rs/embassy", branch = "main" } diff --git a/examples/embassy-stm32-example/Cargo.toml b/examples/embassy-stm32-example/Cargo.toml index 4f052db..61d5585 100644 --- a/examples/embassy-stm32-example/Cargo.toml +++ b/examples/embassy-stm32-example/Cargo.toml @@ -5,10 +5,10 @@ edition = "2021" # Example for the STM32H747I-DISCO board with SARA-R5 modem attached to UART8 [dependencies] -embassy-stm32 = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["nightly", "defmt", "stm32h747xi-cm7", "time-driver-any", "exti", "memory-x", "unstable-pac", "unstable-traits"] } -embassy-executor = { version = "0.3.0", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } -embassy-time = { version = "0.1", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "nightly"] } -embassy-sync = { version = "0.4", features = ["defmt"] } +embassy-stm32 = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["defmt", "stm32h747xi-cm7", "time-driver-any", "exti", "memory-x", "unstable-pac"] } +embassy-executor = { version = "0.4.0", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } +embassy-time = { version = "0.2", features = ["defmt", "defmt-timestamp-uptime"] } +embassy-sync = { version = "0.5", features = ["defmt"] } cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] } @@ -30,6 +30,8 @@ no-std-net = { git = "https://github.com/rushmorem/no-std-net", branch = "issue- embassy-time = { package = "embassy-time", git = "https://github.com/embassy-rs/embassy", branch = "main" } embassy-sync = { package = "embassy-sync", git = "https://github.com/embassy-rs/embassy", branch = "main" } embassy-futures = { package = "embassy-futures", git = "https://github.com/embassy-rs/embassy", branch = "main" } +embassy-executor = { package = "embassy-executor", git = "https://github.com/embassy-rs/embassy", branch = "main" } + #ublox-sockets = { path = "../../../ublox-sockets" } #atat = { path = "../../../atat/atat" } diff --git a/examples/embassy-stm32-example/rust-toolchain.toml b/examples/embassy-stm32-example/rust-toolchain.toml index 419c310..3c44968 100644 --- a/examples/embassy-stm32-example/rust-toolchain.toml +++ b/examples/embassy-stm32-example/rust-toolchain.toml @@ -1,7 +1,8 @@ # Before upgrading check that everything is available on all tier1 targets here: # https://rust-lang.github.io/rustup-components-history [toolchain] -channel = "nightly-2023-11-01" +#channel = "beta-2023-12-17" +channel = "nightly-2023-12-17" components = [ "rust-src", "rustfmt", "llvm-tools" ] targets = [ "thumbv7em-none-eabi", diff --git a/examples/embassy-stm32-example/src/main.rs b/examples/embassy-stm32-example/src/main.rs index 7e04f41..593666d 100644 --- a/examples/embassy-stm32-example/src/main.rs +++ b/examples/embassy-stm32-example/src/main.rs @@ -3,6 +3,9 @@ #![allow(stable_features)] #![feature(type_alias_impl_trait)] +use atat::asynch::Client; +use atat::UrcChannel; +use atat::ResponseSlot; use core::cell::RefCell; use cortex_m_rt::entry; use defmt::*; @@ -24,10 +27,11 @@ use ublox_cellular; use ublox_cellular::config::{CellularConfig, ReverseOutputPin}; use atat::asynch::AtatClient; -use atat::{AtDigester, AtatIngress, Buffers, DefaultDigester, Ingress, Parser}; +use atat::{AtDigester, AtatIngress, DefaultDigester, Ingress, Parser}; use ublox_cellular::asynch::runner::Runner; use ublox_cellular::asynch::state::{LinkState, OperationState}; use ublox_cellular::asynch::State; +use ublox_cellular::command; use ublox_cellular::command::{Urc, AT}; bind_interrupts!(struct Irqs { @@ -127,14 +131,21 @@ async fn main_task(spawner: Spawner) { vint_pin: Some(Input::new(p.PJ3, Pull::Down).degrade()), }; - let buffers = &*make_static!(atat::Buffers::new()); - let (ingress, client) = buffers.split(writer, AtDigester::default(), atat::Config::new()); + static RES_SLOT: ResponseSlot = ResponseSlot::new(); + static URC_CHANNEL: UrcChannel = UrcChannel::new(); + let ingress = Ingress::new( + DefaultDigester::::default(), + &RES_SLOT, + &URC_CHANNEL, + ); + let buf = static_cell::make_static!([0; 1024]); + let mut client = Client::new(writer, &RES_SLOT, buf, atat::Config::default()); spawner.spawn(ingress_task(ingress, reader)).unwrap(); let state = make_static!(State::new(client)); let (device, mut control, mut runner) = - ublox_cellular::asynch::new(state, &buffers.urc_channel, celullar_config).await; + ublox_cellular::asynch::new(state, &URC_CHANNEL, celullar_config).await; // defmt::info!("{:?}", runner.init().await); // control.set_desired_state(PowerState::Connected).await; diff --git a/src/asynch/mod.rs b/src/asynch/mod.rs index bd3c56c..3f8edda 100644 --- a/src/asynch/mod.rs +++ b/src/asynch/mod.rs @@ -6,7 +6,7 @@ pub mod ublox_stack; pub mod state; use crate::{command::Urc, config::CellularConfig}; -use atat::{asynch::AtatClient, AtatUrcChannel}; +use atat::{asynch::AtatClient, UrcChannel}; use embassy_sync::{blocking_mutex::raw::NoopRawMutex, mutex::Mutex}; use runner::Runner; use state::Device; @@ -16,11 +16,11 @@ use self::control::Control; pub struct AtHandle<'d, AT: AtatClient>(&'d Mutex); impl<'d, AT: AtatClient> AtHandle<'d, AT> { - async fn send, const LEN: usize>( + async fn send( &mut self, - cmd: Cmd, + cmd: &Cmd, ) -> Result { - self.0.lock().await.send_retry::(&cmd).await + self.0.lock().await.send_retry::(cmd).await } } @@ -41,12 +41,11 @@ impl State { pub async fn new< 'a, AT: AtatClient, - SUB: AtatUrcChannel, C: CellularConfig, const URC_CAPACITY: usize, >( state: &'a mut State, - subscriber: &'a SUB, + subscriber: &'a UrcChannel, config: C, ) -> ( Device<'a, AT, URC_CAPACITY>, diff --git a/src/asynch/runner.rs b/src/asynch/runner.rs index 5af5728..b5e76da 100644 --- a/src/asynch/runner.rs +++ b/src/asynch/runner.rs @@ -82,7 +82,7 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize> return Err(Error::PoweredDown); } - let alive = match self.at.send(AT).await { + let alive = match self.at.send(&AT).await { Ok(_) => { return Ok(true); } @@ -149,14 +149,14 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize> // Extended errors on self.at - .send(SetReportMobileTerminationError { + .send(&SetReportMobileTerminationError { n: TerminationErrorMode::Enabled, }) .await?; // Select SIM self.at - .send(SetGpioConfiguration { + .send(&SetGpioConfiguration { gpio_id: 25, gpio_mode: GpioMode::Output(GpioOutValue::High), }) @@ -164,13 +164,13 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize> #[cfg(any(feature = "lara-r6"))] self.at - .send(SetGpioConfiguration { + .send(&SetGpioConfiguration { gpio_id: 42, gpio_mode: GpioMode::Input(GpioInPull::NoPull), }) .await?; - let model_id = self.at.send(GetModelId).await?; + let model_id = self.at.send(&GetModelId).await?; // self.at.send( // &IdentificationInformation { @@ -178,29 +178,29 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize> // }, // ).await?; - self.at.send(GetFirmwareVersion).await?; + self.at.send(&GetFirmwareVersion).await?; self.select_sim_card().await?; - let ccid = self.at.send(GetCCID).await?; + let ccid = self.at.send(&GetCCID).await?; info!("CCID: {}", ccid.ccid); // DCD circuit (109) changes in accordance with the carrier self.at - .send(SetCircuit109Behaviour { + .send(&SetCircuit109Behaviour { value: Circuit109Behaviour::ChangesWithCarrier, }) .await?; // Ignore changes to DTR self.at - .send(SetCircuit108Behaviour { + .send(&SetCircuit108Behaviour { value: Circuit108Behaviour::Ignore, }) .await?; // Switch off UART power saving until it is integrated into this API self.at - .send(SetPowerSavingControl { + .send(&SetPowerSavingControl { mode: PowerSavingMode::Disabled, timeout: None, }) @@ -208,13 +208,13 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize> if C::HEX_MODE { self.at - .send(SetHexMode { + .send(&SetHexMode { hex_mode_disable: HexMode::Enabled, }) .await?; } else { self.at - .send(SetHexMode { + .send(&SetHexMode { hex_mode_disable: HexMode::Disabled, }) .await?; @@ -224,13 +224,13 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize> // FIXME: Use AT+IFC=2,2 instead of AT&K here if C::FLOW_CONTROL { self.at - .send(SetFlowControl { + .send(&SetFlowControl { value: FlowControl::RtsCts, }) .await?; } else { self.at - .send(SetFlowControl { + .send(&SetFlowControl { value: FlowControl::Disabled, }) .await?; @@ -240,7 +240,7 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize> pub async fn select_sim_card(&mut self) -> Result<(), Error> { for _ in 0..2 { - match self.at.send(GetPinStatus).await { + match self.at.send(&GetPinStatus).await { Ok(PinStatus { code }) if code == PinStatusCode::Ready => { return Ok(()); } @@ -254,7 +254,7 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize> // We've seen issues on uBlox-based devices, as a precation, we'll cycle // the modem here through minimal/full functional state. self.at - .send(SetModuleFunctionality { + .send(&SetModuleFunctionality { fun: Functionality::Minimum, // SARA-R5 This parameter can be used only when is 1, 4 or 19 #[cfg(feature = "sara-r5")] @@ -264,7 +264,7 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize> }) .await?; self.at - .send(SetModuleFunctionality { + .send(&SetModuleFunctionality { fun: Functionality::Full, rst: Some(ResetMode::DontReset), }) diff --git a/src/config.rs b/src/config.rs index 1021df2..32a84bd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,11 +8,11 @@ impl ErrorType for NoPin { } impl InputPin for NoPin { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(true) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(false) } } @@ -57,11 +57,11 @@ impl> ErrorType for ReverseInputPin

{ } impl> InputPin for ReverseInputPin

{ - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { self.0.is_low() } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { self.0.is_high() } }