Skip to main content

OneWireBus

Trait OneWireBus 

Source
pub trait OneWireBus {
    type Error;

    // Required methods
    fn reset(&mut self) -> Result<bool, Self::Error>;
    fn write_bit(&mut self, bit: bool) -> Result<(), Self::Error>;
    fn read_bit(&mut self) -> Result<bool, Self::Error>;

    // Provided methods
    fn write_byte(&mut self, byte: u8) -> Result<(), Self::Error> { ... }
    fn read_byte(&mut self) -> Result<u8, Self::Error> { ... }
    fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), Self::Error> { ... }
    fn read_bytes(&mut self, buffer: &mut [u8]) -> Result<(), Self::Error> { ... }
    fn skip_rom(&mut self) -> Result<(), OneWireError<Self::Error>> { ... }
    fn match_rom(
        &mut self,
        rom: &RomCode,
    ) -> Result<(), OneWireError<Self::Error>> { ... }
    fn read_rom(&mut self) -> Result<RomCode, OneWireError<Self::Error>> { ... }
}
Expand description

A 1-Wire bus: the three signaling primitives, and the byte and ROM operations built on them.

Implement reset, write_bit, and read_bit for a controller; everything else has a default built on those. BitBang is the implementation over a bare pin.

Required Associated Types§

Source

type Error

The error the controller underneath reports.

Required Methods§

Source

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

Sends a reset pulse and reports whether any device answered with presence.

§Returns

true if at least one device is on the bus.

§Errors

Returns the controller’s error if the line cannot be driven or read.

Source

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

Sends one bit in a write slot.

§Arguments
  • bit - the bit to send.
§Errors

Returns the controller’s error if the line cannot be driven.

Source

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

Samples one bit in a read slot.

§Returns

The bit the addressed device drove.

§Errors

Returns the controller’s error if the line cannot be driven or read.

Provided Methods§

Source

fn write_byte(&mut self, byte: u8) -> Result<(), Self::Error>

Sends one byte, least significant bit first, as the bus requires.

§Arguments
  • byte - the byte to send.
§Errors

Returns the controller’s error if the line cannot be driven.

Source

fn read_byte(&mut self) -> Result<u8, Self::Error>

Reads one byte, least significant bit first.

§Returns

The byte the device sent.

§Errors

Returns the controller’s error if the line cannot be driven or read.

Source

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

Sends every byte of bytes in order.

§Arguments
  • bytes - the bytes to send.
§Errors

Returns the controller’s error if the line cannot be driven.

Source

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

Fills buffer with bytes read in order.

§Arguments
  • buffer - where the bytes go; its length is how many are read.
§Errors

Returns the controller’s error if the line cannot be driven or read.

Source

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

Resets the bus and addresses every device at once with SKIP_ROM.

The next function command reaches every device, which is what a bus with a single device, or a broadcast such as a temperature conversion, wants.

§Errors

Returns OneWireError::NoDevice if nothing answered the reset, or the controller’s error.

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.

§Arguments
  • rom - the device to address; the next function command goes to it alone.
§Errors

Returns OneWireError::NoDevice if nothing answered the reset, or the controller’s error.

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.

With more than one device the answers collide and the CRC fails; use Search instead.

§Returns

The device’s ROM code.

§Errors

Returns OneWireError::NoDevice if nothing answered the reset, OneWireError::Crc if the code read does not check, or the controller’s error.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: OneWireBus + ?Sized> OneWireBus for &mut T

Source§

type Error = <T as OneWireBus>::Error

Source§

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

Source§

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

Source§

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

Implementors§