Skip to main content

BitBang

Struct BitBang 

Source
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§

Source§

impl<P, D> BitBang<P, D>

Source

pub fn new(pin: P, delay: D) -> BitBang<P, D>

Creates a controller over pin, timed by delay.

§Arguments
  • pin - the open-drain line, driven low to signal and released to listen.
  • delay - the microsecond timer that paces the slots.
§Returns

The controller, with the line released.

Source

pub fn into_parts(self) -> (P, D)

Gives back the pin and the delay.

§Returns

The pin and delay the controller was built from.

Trait Implementations§

Source§

impl<P: Debug, D: Debug> Debug for BitBang<P, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: OutputPin + InputPin, D: DelayNs> OneWireBus for BitBang<P, D>

Source§

type Error = <P as ErrorType>::Error

The error the controller underneath reports.
Source§

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>

Sends one bit in a write slot. Read more
Source§

fn read_bit(&mut self) -> Result<bool, Self::Error>

Samples one bit in a read slot. Read more
Source§

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>

Reads one byte, least significant bit first. Read more
Source§

fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), Self::Error>

Sends every byte of bytes in order. Read more
Source§

fn read_bytes(&mut self, buffer: &mut [u8]) -> Result<(), Self::Error>

Fills buffer with bytes read in order. Read more
Source§

fn skip_rom(&mut self) -> Result<(), OneWireError<Self::Error>>

Resets the bus and addresses every device at once with SKIP_ROM. Read more
Source§

fn match_rom(&mut self, rom: &RomCode) -> Result<(), OneWireError<Self::Error>>

Resets the bus and addresses one device by its ROM code with MATCH_ROM. Read more
Source§

fn read_rom(&mut self) -> Result<RomCode, OneWireError<Self::Error>>

Resets the bus and reads the ROM code of the only device on it. Read more

Auto Trait Implementations§

§

impl<P, D> Freeze for BitBang<P, D>
where P: Freeze, D: Freeze,

§

impl<P, D> RefUnwindSafe for BitBang<P, D>

§

impl<P, D> Send for BitBang<P, D>
where P: Send, D: Send,

§

impl<P, D> Sync for BitBang<P, D>
where P: Sync, D: Sync,

§

impl<P, D> Unpin for BitBang<P, D>
where P: Unpin, D: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.