pub struct BitBang<P, D> { /* private fields */ }Expand description
A 1-Wire controller bit-banged over one open-drain pin and a delay.
The pin must drive the line low when set low and release it when set high, with a pull-up resistor (4.7 kΩ is the datasheet value) raising the released line, and it must read back the line’s level. On a microcontroller that is an open-drain output that can be read, or a pin switched between output and input.
§Examples
use pamoja_hal::digital::PinState::{High, Low};
use pamoja_hal::onewire::{BitBang, OneWireBus};
use pamoja_hal::script::{DelayLog, PinScript};
// The scripted pin answers the presence sample low: a device is there.
let pin = PinScript::new([Low]);
let mut bus = BitBang::new(pin, DelayLog::new());
assert!(bus.reset()?);
let (pin, delay) = bus.into_parts();
assert_eq!(pin.driven(), [Low, High]);
assert_eq!(delay.total_micros(), 980);Implementations§
Trait Implementations§
Source§impl<P: OutputPin + InputPin, D: DelayNs> OneWireBus for BitBang<P, D>
impl<P: OutputPin + InputPin, D: DelayNs> OneWireBus for BitBang<P, D>
Source§fn reset(&mut self) -> Result<bool, Self::Error>
fn reset(&mut self) -> Result<bool, Self::Error>
Sends a reset pulse and reports whether any device answered with presence. Read more
Source§fn write_bit(&mut self, bit: bool) -> Result<(), Self::Error>
fn write_bit(&mut self, bit: bool) -> Result<(), Self::Error>
Sends one bit in a write slot. Read more
Source§fn write_byte(&mut self, byte: u8) -> Result<(), Self::Error>
fn write_byte(&mut self, byte: u8) -> Result<(), Self::Error>
Sends one byte, least significant bit first, as the bus requires. Read more
Source§fn read_byte(&mut self) -> Result<u8, Self::Error>
fn read_byte(&mut self) -> Result<u8, Self::Error>
Reads one byte, least significant bit first. Read more
Source§fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), Self::Error>
fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), Self::Error>
Sends every byte of
bytes in order. Read moreSource§fn read_bytes(&mut self, buffer: &mut [u8]) -> Result<(), Self::Error>
fn read_bytes(&mut self, buffer: &mut [u8]) -> Result<(), Self::Error>
Fills
buffer with bytes read in order. Read moreSource§fn skip_rom(&mut self) -> Result<(), OneWireError<Self::Error>>
fn skip_rom(&mut self) -> Result<(), OneWireError<Self::Error>>
Resets the bus and addresses every device at once with
SKIP_ROM. Read moreAuto Trait Implementations§
impl<P, D> Freeze for BitBang<P, D>
impl<P, D> RefUnwindSafe for BitBang<P, D>where
P: RefUnwindSafe,
D: RefUnwindSafe,
impl<P, D> Send for BitBang<P, D>
impl<P, D> Sync for BitBang<P, D>
impl<P, D> Unpin for BitBang<P, D>
impl<P, D> UnsafeUnpin for BitBang<P, D>where
P: UnsafeUnpin,
D: UnsafeUnpin,
impl<P, D> UnwindSafe for BitBang<P, D>where
P: UnwindSafe,
D: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more