MCPcopy Create free account
hub / github.com/FrameworkComputer/framework-system / read_bytes

Method read_bytes

framework_lib/src/smart_battery.rs:835–846  ·  view source on GitHub ↗

Read a block of bytes with expected length

(&self, ec: &CrosEc, addr: u16, len: u16)

Source from the content-addressed store, hash-verified

833
834 /// Read a block of bytes with expected length
835 fn read_bytes(&self, ec: &CrosEc, addr: u16, len: u16) -> EcResult<Vec<u8>> {
836 let i2c_response = i2c_read(ec, self.i2c_port, self.i2c_addr >> 1, addr, len + 1)?;
837 i2c_response.is_successful()?;
838 let actual_len = i2c_response.data[0];
839 if actual_len != len as u8 {
840 return Err(EcError::DeviceError(format!(
841 "Expected {} bytes but got {} from register 0x{:02X}",
842 len, actual_len, addr
843 )));
844 }
845 Ok(i2c_response.data[1..].to_vec())
846 }
847
848 /// Read a block of bytes, returning whatever length the device provides
849 fn read_block(&self, ec: &CrosEc, addr: u16, max_len: u16) -> EcResult<Vec<u8>> {

Callers 1

collect_dataMethod · 0.80

Calls 2

i2c_readFunction · 0.85
is_successfulMethod · 0.80

Tested by

no test coverage detected