Struct I2cBus

Source
pub struct I2cBus(/* private fields */);

Implementations§

Source§

impl I2cBus

Source

pub fn from_unit(unit: u32) -> Result<I2cBus, I2cError>

Examples found in repository?
examples/mcp.rs (line 15)
12fn main() {
13    let adr = 0x20;
14    use embedded_hal::i2c::blocking::*;
15    let mut iic = freebsd_embedded_hal::I2cBus::from_unit(1).unwrap();
16    iic.write(adr, &[IODIRA, 0]).unwrap(); // A* are outputs
17    iic.write(adr, &[IODIRB, 0xff]).unwrap(); // B* are inputs
18    iic.write(adr, &[GPPUB, 0xff]).unwrap(); // B* are pulled up
19    loop {
20        let mut bank_b: [u8; 1] = [0x69];
21        iic.write_read(adr, &[GPIOB], &mut bank_b).unwrap();
22        eprintln!("GPIOB: {:x} ({:b})", bank_b[0], bank_b[0]);
23        std::thread::sleep(std::time::Duration::from_millis(10));
24        iic.write(adr, &[GPIOA, (bank_b[0] & 1) << 7]).unwrap();
25        std::thread::sleep(std::time::Duration::from_millis(10));
26    }
27}
Source

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<I2cBus, I2cError>

Trait Implementations§

Source§

impl AsRawFd for I2cBus

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Drop for I2cBus

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl FromRawFd for I2cBus

Source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more
Source§

impl IntoRawFd for I2cBus

Source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more
Source§

impl Read for I2cBus

Source§

type Error = I2cError

Error type
Source§

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

Reads enough bytes from slave with address to fill buffer Read more
Source§

impl Transactional for I2cBus

Source§

type Error = I2cError

Error type
Source§

fn exec<'a>( &mut self, address: u8, operations: &mut [Operation<'a>], ) -> Result<(), Self::Error>

Execute the provided operations on the I2C bus. Read more
Source§

impl TransactionalIter for I2cBus

Source§

type Error = I2cError

Error type
Source§

fn exec_iter<'a, O>( &mut self, address: u8, operations: O, ) -> Result<(), Self::Error>
where O: IntoIterator<Item = Operation<'a>>,

Execute the provided operations on the I2C bus (iterator version). Read more
Source§

impl Write for I2cBus

Source§

type Error = I2cError

Error type
Source§

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

Writes bytes to slave with address address Read more
Source§

impl WriteIter for I2cBus

Source§

type Error = I2cError

Error type
Source§

fn write_iter<B>(&mut self, address: u8, bytes: B) -> Result<(), Self::Error>
where B: IntoIterator<Item = u8>,

Writes bytes to slave with address address Read more
Source§

impl WriteIterRead for I2cBus

Source§

type Error = I2cError

Error type
Source§

fn write_iter_read<B>( &mut self, address: u8, bytes: B, buffer: &mut [u8], ) -> Result<(), Self::Error>
where B: IntoIterator<Item = u8>,

Writes bytes to slave with address address and then reads enough bytes to fill buffer in a single transaction Read more
Source§

impl WriteRead for I2cBus

Source§

type Error = I2cError

Error type
Source§

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

Writes bytes to slave with address address and then reads enough bytes to fill buffer in a single transaction Read more

Auto Trait Implementations§

§

impl Freeze for I2cBus

§

impl RefUnwindSafe for I2cBus

§

impl Send for I2cBus

§

impl Sync for I2cBus

§

impl Unpin for I2cBus

§

impl UnwindSafe for I2cBus

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.