Struct kernel::services::i2c::I2cClient

source ·
pub struct I2cClient {
    handle: KernelHandle<I2cService>,
    reply: Reusable<Envelope<Result<Transaction, Infallible>>>,
    cached_buf: Option<FixedVec<u8>>,
}
Expand description

A client for the I2cService.

This type is used to perform I²C bus operations. It is obtained using I2cClient::from_registry (or I2cClient::from_registry_no_retry).

Once an I2cClient has been acquired, it may be used to perform I²C operations, either using its implementation of the embedded_hal_async I2c trait, or using the lower-level Transaction interface returned by I2cClient::start_transaction. See the documentation for embedded_hal_async::i2c::I2c for details on that interface, or the Transaction type for details on using the lower-level transaction interface.

An I2cClient does not represent a “lock” on the I²C bus. Multiple I2cClients can coexist without preventing each other from performing bus operations. Instead, the bus is locked only while performing a Transaction, or while using the I2c::transaction method on the embedded_hal_async::i2c::I2c implementation.

Fields§

§handle: KernelHandle<I2cService>§reply: Reusable<Envelope<Result<Transaction, Infallible>>>§cached_buf: Option<FixedVec<u8>>

Implementations§

source§

impl I2cClient

source

pub async fn from_registry( kernel: &'static Kernel, ) -> Result<Self, ConnectError<I2cService>>

Obtain an I2cClient

If the I2cService hasn’t been registered yet, we will retry until it has been registered.

source

pub async fn from_registry_no_retry( kernel: &'static Kernel, ) -> Result<Self, ConnectError<I2cService>>

Obtain an I2cClient

Does NOT attempt to get an I2cService handle more than once.

Prefer I2cClient::from_registry unless you will not be spawning one around the same time as obtaining a client.

source

pub fn with_cached_buf(self, buf: impl Into<Option<FixedVec<u8>>>) -> Self

Sets a cached buffer to use for embedded_hal_async::i2c::I2c transactions.

If a cached buffer is present, and it is small enough to perform a read/write operation in a transaction, it will be used, rather than allocating a new buffer for that transaction.

source

pub async fn start_transaction(&mut self, addr: Addr) -> Transaction

Starts an I²C Transaction with the device at the provided addr.

This method begins a bus transaction with the target device. While the returned Transaction type is held, other I2cClients cannot perform bus operations; the bus is released when the Transaction is dropped.

After starting a Transaction, the Transaction::read and Transaction::write methods are used to write to and read from the target I²C device. See the Transaction type’s documentation for more information on how to use it.

Trait Implementations§

source§

impl ErrorType for I2cClient

§

type Error = I2cError

Error type
source§

impl<A> I2c<A> for I2cClient
where A: AddressMode, Addr: From<A>,

source§

async fn transaction( &mut self, address: A, operations: &mut [Operation<'_>], ) -> Result<(), Self::Error>

Execute the provided operations on the I2C bus as a single transaction. Read more
source§

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

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

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

Writes bytes to slave with address address Read more
source§

async fn write_read( &mut self, address: A, write: &[u8], read: &mut [u8], ) -> Result<(), Self::Error>

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

Auto Trait Implementations§

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> Az for T

source§

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

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
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.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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.
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.
source§

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

§

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>,

§

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.
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> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
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.