Trait opentitanlib::io::i2c::Bus

source ·
pub trait Bus {
    // Required methods
    fn get_max_speed(&self) -> Result<u32>;
    fn set_max_speed(&self, max_speed: u32) -> Result<()>;
    fn set_default_address(&self, addr: u8) -> Result<()>;
    fn run_transaction(
        &self,
        addr: Option<u8>,
        transaction: &mut [Transfer<'_, '_>]
    ) -> Result<()>;

    // Provided methods
    fn set_mode(&self, mode: Mode) -> Result<()> { ... }
    fn set_pins(
        &self,
        _serial_clock: Option<&Rc<dyn GpioPin>>,
        _serial_data: Option<&Rc<dyn GpioPin>>,
        _gsc_ready: Option<&Rc<dyn GpioPin>>
    ) -> Result<()> { ... }
    fn get_device_status(&self, _timeout: Duration) -> Result<DeviceStatus> { ... }
    fn prepare_read_data(&self, _data: &[u8], _sticky: bool) -> Result<()> { ... }
}
Expand description

A trait which represents a I2C Bus.

Required Methods§

source

fn get_max_speed(&self) -> Result<u32>

Gets the maximum allowed speed of the I2C bus.

source

fn set_max_speed(&self, max_speed: u32) -> Result<()>

Sets the maximum allowed speed of the I2C bus, typical values are 100_000, 400_000 or 1_000_000.

source

fn set_default_address(&self, addr: u8) -> Result<()>

Sets the “default” device address, used in cases when not overriden by parameter to run_transaction().

source

fn run_transaction( &self, addr: Option<u8>, transaction: &mut [Transfer<'_, '_>] ) -> Result<()>

Runs a I2C transaction composed from the slice of Transfer objects. If addr is None, then the last value given to set_default_adress() is used instead.

Provided Methods§

source

fn set_mode(&self, mode: Mode) -> Result<()>

source

fn set_pins( &self, _serial_clock: Option<&Rc<dyn GpioPin>>, _serial_data: Option<&Rc<dyn GpioPin>>, _gsc_ready: Option<&Rc<dyn GpioPin>> ) -> Result<()>

Sets which pins should be used for I2C communication. None value means use the same pin as previously, or the implementation default if never before specified. This call is not supported by most backend transports, and ones that do support it may still have restrictions on which set of pins can be used in which roles.

source

fn get_device_status(&self, _timeout: Duration) -> Result<DeviceStatus>

Retrieve a log of I2C operations performed by the I2C host since last time, as well as whether the I2C host is currently waiting to read data.

source

fn prepare_read_data(&self, _data: &[u8], _sticky: bool) -> Result<()>

Prepare data to be tranmitted to I2C host on future or currently waiting I2C read transfer. By default, the prepared data will be discarded if the I2C issues a write transfer on the bus (giving the caller a chance to react to the additional data before preparing another response). If the sticky parameter is true, the prepared data will be kept across any number of intervening write transfers, and used for a future read transfer.

Implementors§