Skip to main content

OneWire

Struct OneWire 

Source
pub struct OneWire<'a> { /* private fields */ }
Expand description

Async 1-Wire bus master built on a pair of RMT TX/RX channels.

Implementations§

Source§

impl<'a> OneWire<'a>

Source

pub fn new<Txc: TxChannelCreator<'a, Async>, Rxc: RxChannelCreator<'a, Async>, P: Pin + 'a>( txcc: Txc, rxcc: Rxc, pin: P, ) -> Result<Self, Error>

Create a 1-Wire master driving pin (open-drain, pull-up) using the supplied RMT TX and RX channel creators.

Source§

impl<'a> OneWire<'a>

Source

pub async fn strong_pull_up(&mut self, duration: Duration) -> Result<(), Error>

Hold the bus HIGH for duration, then release it.

This is the parasite-power path. A device whose Vdd is tied to GND draws its conversion current – up to 1.5 mA – from the data line, and a 4.7 kOhm pull-up cannot supply that: it sources 0.7 mA at 3.3 V, so the line sags and the device’s internal cap cannot carry the conversion. The pad sources tens of mA instead, so no external strong pull-up is needed.

Mechanically: the RMT is told to drive its idle output (which the TX inverter turns into a HIGH pad), and the pad is switched to push-pull so that “high” is driven rather than released. Both are undone afterwards.

The bus MUST NOT be touched while this runs: a parasite device cannot answer a read slot during its conversion, and the datasheet forbids trying.

Source

pub async fn reset(&mut self) -> Result<bool, Error>

Issue a 1-Wire reset pulse and return true if at least one device responded with a presence pulse.

Source

pub async fn send_and_receive( &mut self, indata: &mut [PulseCode], data: &[PulseCode], ) -> Result<usize, Error>

Transmit data while simultaneously sampling the bus into indata, returning the number of received RMT symbols.

Source

pub fn encode_bit(bit: bool) -> PulseCode

Encode a single 1-Wire bit as an RMT pulse code (write/read time slot).

Source

pub fn decode_bit(code: PulseCode) -> bool

Decode a sampled RMT pulse code back into the 1-Wire bit value.

Source

pub async fn exchange_byte(&mut self, byte: u8) -> Result<u8, Error>

Write one byte (LSB first) and read the byte the bus returns in the same time slots.

Source

pub async fn send_byte(&mut self, byte: u8) -> Result<(), Error>

Write one byte (LSB first) without reading the response.

Source

pub async fn exchange_bits( &mut self, bits: &[bool], out: &mut [bool], ) -> Result<(), Error>

Write the bits in bits and read the bus response into out in the same time slots. bits and out must have equal length, and at most Self::MAX_EXCHANGE_BITS elements.

This replaces the original const-generic exchange_bits<const N> (which required generic_const_exprs) with a slice-based API backed by a small fixed-capacity buffer. The RMT framing is identical: each bit maps to one PulseCode followed by a trailing end_marker().

Source

pub async fn send_u64(&mut self, val: u64) -> Result<(), Error>

Write a 64-bit value (typically a ROM address) least-significant byte first.

Source

pub async fn send_address(&mut self, val: Address) -> Result<(), Error>

Write a 64-bit 1-Wire ROM Address.

Auto Trait Implementations§

§

impl<'a> !Send for OneWire<'a>

§

impl<'a> !UnwindSafe for OneWire<'a>

§

impl<'a> Freeze for OneWire<'a>

§

impl<'a> PsramSafe for OneWire<'a>

§

impl<'a> RefUnwindSafe for OneWire<'a>

§

impl<'a> Sync for OneWire<'a>

§

impl<'a> Unpin for OneWire<'a>

§

impl<'a> UnsafeUnpin for OneWire<'a>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

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

§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.