Skip to content

Commit

Permalink
update dependencies and make compatible with atat master
Browse files Browse the repository at this point in the history
  • Loading branch information
tarfu committed Dec 26, 2023
1 parent d238659 commit a1d6560
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 44 deletions.
21 changes: 13 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@ 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",
#] }

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"

Expand Down Expand Up @@ -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" }
10 changes: 6 additions & 4 deletions examples/embassy-stm32-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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" }

Expand Down
3 changes: 2 additions & 1 deletion examples/embassy-stm32-example/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 15 additions & 4 deletions examples/embassy-stm32-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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 {
Expand Down Expand Up @@ -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<INGRESS_BUF_SIZE> = ResponseSlot::new();
static URC_CHANNEL: UrcChannel<command::Urc, URC_CAPACITY, URC_SUBSCRIBERS> = UrcChannel::new();
let ingress = Ingress::new(
DefaultDigester::<command::Urc>::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;

Expand Down
11 changes: 5 additions & 6 deletions src/asynch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,11 +16,11 @@ use self::control::Control;
pub struct AtHandle<'d, AT: AtatClient>(&'d Mutex<NoopRawMutex, AT>);

impl<'d, AT: AtatClient> AtHandle<'d, AT> {
async fn send<Cmd: atat::AtatCmd<LEN>, const LEN: usize>(
async fn send<Cmd: atat::AtatCmd>(
&mut self,
cmd: Cmd,
cmd: &Cmd,
) -> Result<Cmd::Response, atat::Error> {
self.0.lock().await.send_retry::<Cmd, LEN>(&cmd).await
self.0.lock().await.send_retry::<Cmd>(cmd).await
}
}

Expand All @@ -41,12 +41,11 @@ impl<AT: AtatClient> State<AT> {
pub async fn new<
'a,
AT: AtatClient,
SUB: AtatUrcChannel<Urc, URC_CAPACITY, 2>,
C: CellularConfig,
const URC_CAPACITY: usize,
>(
state: &'a mut State<AT>,
subscriber: &'a SUB,
subscriber: &'a UrcChannel<Urc, URC_CAPACITY, 2>,
config: C,
) -> (
Device<'a, AT, URC_CAPACITY>,
Expand Down
34 changes: 17 additions & 17 deletions src/asynch/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -149,72 +149,72 @@ 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),
})
.await?;

#[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 {
// n: 9
// },
// ).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,
})
.await?;

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?;
Expand All @@ -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?;
Expand All @@ -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(());
}
Expand All @@ -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 <fun> is 1, 4 or 19
#[cfg(feature = "sara-r5")]
Expand All @@ -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),
})
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ impl ErrorType for NoPin {
}

impl InputPin for NoPin {
fn is_high(&self) -> Result<bool, Self::Error> {
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok(true)
}

fn is_low(&self) -> Result<bool, Self::Error> {
fn is_low(&mut self) -> Result<bool, Self::Error> {
Ok(false)
}
}
Expand Down Expand Up @@ -57,11 +57,11 @@ impl<P: InputPin<Error = Infallible>> ErrorType for ReverseInputPin<P> {
}

impl<P: InputPin<Error = Infallible>> InputPin for ReverseInputPin<P> {
fn is_high(&self) -> Result<bool, Self::Error> {
fn is_high(&mut self) -> Result<bool, Self::Error> {
self.0.is_low()
}

fn is_low(&self) -> Result<bool, Self::Error> {
fn is_low(&mut self) -> Result<bool, Self::Error> {
self.0.is_high()
}
}
Expand Down

0 comments on commit a1d6560

Please sign in to comment.