Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
tarfu committed Dec 4, 2023
1 parent d8f41a2 commit 59ae613
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 33 deletions.
5 changes: 1 addition & 4 deletions src/asynch/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ pub struct Control<'a, AT: AtatClient> {
}

impl<'a, AT: AtatClient> Control<'a, AT> {
pub(crate) fn new(
state_ch: state::StateRunner<'a>,
at: AtHandle<'a, AT>,
) -> Self {
pub(crate) fn new(state_ch: state::StateRunner<'a>, at: AtHandle<'a, AT>) -> Self {
Self { state_ch, at }
}

Expand Down
1 change: 0 additions & 1 deletion src/asynch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub async fn new<
SUB: AtatUrcChannel<Urc, URC_CAPACITY, 2>,
C: CellularConfig,
const URC_CAPACITY: usize,

>(
state: &'a mut State<AT>,
subscriber: &'a SUB,
Expand Down
17 changes: 3 additions & 14 deletions src/asynch/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,15 @@ use super::AtHandle;
/// Background runner for the Ublox Module.
///
/// You must call `.run()` in a background task for the Ublox Module to operate.
pub struct Runner<
'd,
AT: AtatClient,
C: CellularConfig,
const URC_CAPACITY: usize,

> {
pub struct Runner<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize> {
ch: state::Runner<'d>,
at: AtHandle<'d, AT>,
config: C,
urc_subscription: UrcSubscription<'d, Urc, URC_CAPACITY, 2>,
}

impl<
'd,
AT: AtatClient,
C: CellularConfig,
const URC_CAPACITY: usize,

> Runner<'d, AT, C, URC_CAPACITY>
impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize>
Runner<'d, AT, C, URC_CAPACITY>
{
pub(crate) fn new(
ch: state::Runner<'d>,
Expand Down
35 changes: 21 additions & 14 deletions src/asynch/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use embassy_sync::blocking_mutex::Mutex;
use embassy_sync::pubsub::PubSubChannel;
use embassy_sync::waitqueue::WakerRegistration;


const MAX_STATE_LISTENERS: usize = 5;

/// The link state of a network device.
Expand Down Expand Up @@ -68,13 +67,15 @@ pub struct Shared {

pub struct Runner<'d> {
shared: &'d Mutex<NoopRawMutex, RefCell<Shared>>,
desired_state_pub_sub: &'d PubSubChannel<NoopRawMutex, OperationState, 1, MAX_STATE_LISTENERS, 1>,
desired_state_pub_sub:
&'d PubSubChannel<NoopRawMutex, OperationState, 1, MAX_STATE_LISTENERS, 1>,
}

#[derive(Clone, Copy)]
pub struct StateRunner<'d> {
shared: &'d Mutex<NoopRawMutex, RefCell<Shared>>,
desired_state_pub_sub: &'d PubSubChannel<NoopRawMutex, OperationState, 1, MAX_STATE_LISTENERS, 1>,
desired_state_pub_sub:
&'d PubSubChannel<NoopRawMutex, OperationState, 1, MAX_STATE_LISTENERS, 1>,
}

impl<'d> Runner<'d> {
Expand Down Expand Up @@ -178,7 +179,10 @@ impl<'d> StateRunner<'d> {
.publish_immediate(ps);
}

pub async fn wait_for_desired_state(&mut self, ps: OperationState) -> Result<OperationState, Error> {
pub async fn wait_for_desired_state(
&mut self,
ps: OperationState,
) -> Result<OperationState, Error> {
if self.desired_state() == ps {
info!("Desired state already set to {:?}, returning", ps);
return Ok(ps);
Expand Down Expand Up @@ -208,10 +212,7 @@ pub fn new<'d, AT: AtatClient, const URC_CAPACITY: usize>(
state: &'d mut State,
at: AtHandle<'d, AT>,
urc_subscription: UrcSubscription<'d, Urc, URC_CAPACITY, 2>,
) -> (
Runner<'d>,
Device<'d, AT, URC_CAPACITY>,
) {
) -> (Runner<'d>, Device<'d, AT, URC_CAPACITY>) {
// safety: this is a self-referential struct, however:
// - it can't move while the `'d` borrow is active.
// - when the borrow ends, the dangling references inside the MaybeUninit will never be used again.
Expand All @@ -225,8 +226,13 @@ pub fn new<'d, AT: AtatClient, const URC_CAPACITY: usize>(
desired_state: OperationState::PowerDown,
waker: WakerRegistration::new(),
})),
desired_state_pub_sub:
PubSubChannel::<NoopRawMutex, OperationState, 1, MAX_STATE_LISTENERS, 1>::new(),
desired_state_pub_sub: PubSubChannel::<
NoopRawMutex,
OperationState,
1,
MAX_STATE_LISTENERS,
1,
>::new(),
});

(
Expand All @@ -251,9 +257,7 @@ pub struct Device<'d, AT: AtatClient, const URC_CAPACITY: usize> {
pub(crate) urc_subscription: UrcSubscription<'d, Urc, URC_CAPACITY, 2>,
}

impl<'d, AT: AtatClient, const URC_CAPACITY: usize>
Device<'d, AT, URC_CAPACITY>
{
impl<'d, AT: AtatClient, const URC_CAPACITY: usize> Device<'d, AT, URC_CAPACITY> {
pub fn link_state_poll_fn(&mut self, cx: &mut Context) -> LinkState {
self.shared.lock(|s| {
let s = &mut *s.borrow_mut();
Expand Down Expand Up @@ -302,7 +306,10 @@ impl<'d, AT: AtatClient, const URC_CAPACITY: usize>
.publish_immediate(ps);
}

pub async fn wait_for_desired_state(&mut self, ps: OperationState) -> Result<OperationState, Error> {
pub async fn wait_for_desired_state(
&mut self,
ps: OperationState,
) -> Result<OperationState, Error> {
if self.desired_state() == ps {
return Ok(ps);
}
Expand Down

0 comments on commit 59ae613

Please sign in to comment.