Struct I2cRequest

Source
pub struct I2cRequest {
    pub i2c_address: u16,
    pub(crate) send_buf: [u8; 16],
    pub(crate) send_len: usize,
    pub(crate) sleep_time_millis: u64,
    pub(crate) expected_response_length: usize,
}

Fields§

§i2c_address: u16

I2C address of the bus participant

§send_buf: [u8; 16]

input sequence to be sent to the bus participant

§send_len: usize

The actual length of the command in the buffer.

§sleep_time_millis: u64

sleep time in milliseconds before retrieving an answer from the bus participant

§expected_response_length: usize

length of the expected response in byte

Implementations§

Source§

impl I2cRequest

Source

pub fn new( i2c_address: u16, send_slice: &[u8], sleep_time_millis: u64, expected_response_length: usize, ) -> Result<I2cRequest, I2cError>

Creates a new I2cRequest after validating the command length.

This constructor prepares a command for sending over the I2C bus. It takes a command as a slice, copies it into a fixed-size buffer, and packages it with the necessary metadata for the I2C interface to execute the request.

§Arguments
  • i2c_address - The 7-bit I2C address of the target device.
  • send_slice - A byte slice (&[u8]) containing the command to be sent.
  • sleep_time_millis - The duration in milliseconds to wait after sending the command before attempting to read a response.
  • expected_response_length - The number of bytes expected in the response from the device.
§Returns

A Result containing a new I2cRequest struct on success.

§Errors

Returns an I2cError if the provided command is too large for the buffer:

  • I2cError::CommandTooLong: If the length of send_slice exceeds the MAX_I2C_COMMAND_LENGTH constant.

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

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T