Skip to content

Commit

Permalink
add power up and power down
Browse files Browse the repository at this point in the history
  • Loading branch information
tarfu committed Oct 21, 2023
1 parent 9597a75 commit 912bae7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
7 changes: 7 additions & 0 deletions examples/embassy-stm32-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ ublox-cellular-rs = {version = "0.4.0", path = "../..", features = ["sara-r5", "
ublox-sockets = { path = "../../../ublox-sockets" }
no-std-net = { git = "https://github.com/rushmorem/no-std-net", branch = "issue-15" }
embassy-time = { package = "embassy-time", git = "https://github.com/embassy-rs/embassy", branch = "main" }


[profile.dev]
opt-level = "s"

[profile.release]
opt-level = "s"
5 changes: 4 additions & 1 deletion examples/embassy-stm32-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async fn main_task(spawner: Spawner) {
let mut uart_config = embassy_stm32::usart::Config::default();
{
uart_config.baudrate = 115200;
uart_config.baudrate = 9600;
// uart_config.baudrate = 9600;
uart_config.parity = embassy_stm32::usart::Parity::ParityNone;
uart_config.stop_bits = embassy_stm32::usart::StopBits::STOP1;
uart_config.data_bits = embassy_stm32::usart::DataBits::DataBits8;
Expand Down Expand Up @@ -147,6 +147,9 @@ async fn main_task(spawner: Spawner) {
loop {
// runner.init().await.unwrap();
defmt::info!("{:?}", runner.is_alive().await);
if runner.is_alive().await != Ok(true){
runner.init().await.unwrap();
}
Timer::after(Duration::from_millis(1000)).await;
}
defmt::unwrap!(spawner.spawn(cellular_task(runner)));
Expand Down
39 changes: 39 additions & 0 deletions src/asynch/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize>
// Initilize a new ublox device to a known state (set RS232 settings)
debug!("Initializing module");
// Hard reset module
if Ok(false) == self.has_power().await {
self.power_up().await?;
};
self.reset().await?;
self.is_alive().await?;

Expand Down Expand Up @@ -101,6 +104,42 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize>
}
}

pub async fn power_up(&mut self) -> Result<(), Error> {
if !self.has_power().await? {
if let Some(pin) = self.config.power_pin() {
pin.set_low().map_err(|_| Error::IoPin)?;
Timer::after(crate::module_timing::pwr_on_time()).await;
pin.set_high().map_err(|_| Error::IoPin)?;
self.ch.set_power_state(PowerState::PowerUp);
debug!("Powered up");
Ok(())
} else {
warn!("No power pin configured");
Ok(())
}
} else {
Ok(())
}
}

pub async fn power_down(&mut self) -> Result<(), Error> {
if self.has_power().await? {
if let Some(pin) = self.config.power_pin() {
pin.set_low().map_err(|_| Error::IoPin)?;
Timer::after(crate::module_timing::pwr_off_time()).await;
pin.set_high().map_err(|_| Error::IoPin)?;
self.ch.set_power_state(PowerState::PowerDown);
debug!("Powered down");
Ok(())
} else {
defmt::warn!("No power pin configured");
Ok(())
}
} else {
Ok(())
}
}

pub async fn init_at(&mut self) -> Result<(), Error> {
if !self.is_alive().await? {
return Err(Error::PoweredDown);
Expand Down

0 comments on commit 912bae7

Please sign in to comment.