Struct kernel::services::i2c::Transaction

source ·
pub struct Transaction {
    addr: Addr,
    tx: KProducer<Transfer>,
    rsp_rx: Reusable<Result<FixedVec<u8>, ErrorKind>>,
    ended: bool,
}
Expand description

A transaction on the I²C bus.

This type represents a transaction consisting of a series of read and write operations to a target device on an I²C bus with a given Addr. This type is part of a lower-level interface for I²C bus transactions, and is returned by the I2cClient::start_transaction method.

Once a Transaction has been created by I2cClient::start_transaction, data can be written to the target device using the Transaction::write method, and read from the target device using the Transaction::read method. Any number of read and write operations may be performed within a Transaction until an operation with end: true is performed. This completes the transaction.

While a Transaction is in progress, the I²C bus is “locked” by the client that is performing that transaction. Other clients calling I2cClient::start_transaction (or using the embedded_hal_async::i2c::I2c interface) will wait until the current transaction has completed before beginning their own transactions.

Fields§

§addr: Addr§tx: KProducer<Transfer>§rsp_rx: Reusable<Result<FixedVec<u8>, ErrorKind>>§ended: bool

Implementations§

source§

impl Transaction

source

pub async fn new(__arg0: StartTransaction) -> (Self, KConsumer<Transfer>)

Constructs a new Transaction from the provided StartTransaction message, returning the Transaction and a KConsumer for receiving Transfers within that Transaction.

This is intended to be used by server implementations of the I2cService when handling StartTransaction messages.

source

pub async fn read( &mut self, buf: FixedVec<u8>, len: usize, end: bool, ) -> Result<FixedVec<u8>, I2cError>

Read len bytes from the I²C bus into buf.

Note that, rather than always filling the entire buffer, this method takes a len argument which specifies the number of bytes to read. This is intended to allow callers to reuse the same FixedVec for multiple read and write operations.

§Arguments
  • buf: a FixedVec buffer into which bytes read from the I²C bus will be written
  • len: the number of bytes to read. This must be less than or equal to buf.len().
  • end: whether or not to end the transaction. If this is true, a STOP condition will be sent on the bus once len bytes have been read. If this is false, a repeated START condition will be sent on the bus once len bytes have been read.
§Errors
§Cancelation Safety

If this future is dropped, the underlying I²C bus read operation may still be performed.

source

pub async fn write( &mut self, buf: FixedVec<u8>, end: bool, ) -> Result<FixedVec<u8>, I2cError>

Write bytes from buf to the I²C.

§Arguments
  • buf: a FixedVec buffer containing the bytes to write to the I²C bus.
  • end: whether or not to end the transaction. If this is true, a STOP condition will be sent on the bus once the entire buffer has been sent. If this is false, a repeated START condition will be sent on the bus once the entire buffer has been written.
§Errors
  • If an error occurs performing the I²C bus transaction.
  • If there is no I2cService running.
§Cancelation Safety

If this future is dropped, the underlying I²C bus write operation may still be performed.

source

async fn xfer( &mut self, buf: FixedVec<u8>, len: usize, end: bool, dir: OpKind, ) -> Result<FixedVec<u8>, I2cError>

source§

impl Transaction

source

fn buf_too_small(&self, dir: OpKind, len: usize, buf: usize) -> I2cError

source

fn mk_err(&self, dir: OpKind) -> impl Fn(ErrorKind) -> I2cError

source

fn mk_no_driver_err<E>(&self, dir: OpKind) -> impl Fn(E) -> I2cError

Trait Implementations§

source§

impl Drop for Transaction

source§

fn drop(&mut self)

Executes the destructor for this type. 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.