Skip to content

Commit

Permalink
Add a new controller reset method to support devices that lack timers…
Browse files Browse the repository at this point in the history
… implementing the CountDown trait: reset_with_delay
  • Loading branch information
antoinevg committed Nov 25, 2021
1 parent 84cc954 commit c7117b9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extern crate embedded_hal as emhal;
extern crate nb;

use byteorder::{ByteOrder, LittleEndian};
use emhal::blocking;
use core::cmp::min;
use core::convert::TryFrom;
use core::marker::PhantomData;
Expand Down Expand Up @@ -493,6 +494,22 @@ where
Ok(())
}

/// Resets the BlueNRG Controller. Uses the given delay to wait
/// `time` milliseconds after toggling the reset pin.
pub fn reset_with_delay<D, UXX>(&mut self, delay: &mut D, time: UXX) -> nb::Result<(), OutputPin2::Error>
where
D: blocking::delay::DelayMs<UXX>,
UXX: Copy,
{
self.reset.set_low().map_err(nb::Error::Other)?;
delay.delay_ms(time);

self.reset.set_high().map_err(nb::Error::Other)?;
delay.delay_ms(time);

Ok(())
}

/// Returns true if the controller has data ready to transmit to the host.
fn data_ready(&self) -> Result<bool, InputPin::Error> {
self.data_ready.is_high()
Expand Down

0 comments on commit c7117b9

Please sign in to comment.