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: u16I2C address of the bus participant
send_buf: [u8; 16]input sequence to be sent to the bus participant
send_len: usizeThe actual length of the command in the buffer.
sleep_time_millis: u64sleep time in milliseconds before retrieving an answer from the bus participant
expected_response_length: usizelength of the expected response in byte
Implementations§
Source§impl I2cRequest
impl I2cRequest
Sourcepub fn new(
i2c_address: u16,
send_slice: &[u8],
sleep_time_millis: u64,
expected_response_length: usize,
) -> Result<I2cRequest, I2cError>
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 ofsend_sliceexceeds theMAX_I2C_COMMAND_LENGTHconstant.
Auto Trait Implementations§
impl Freeze for I2cRequest
impl RefUnwindSafe for I2cRequest
impl Send for I2cRequest
impl Sync for I2cRequest
impl Unpin for I2cRequest
impl UnwindSafe for I2cRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more