MCPcopy Index your code
hub / github.com/FrameworkComputer/framework-system / read_i32

Method read_i32

framework_lib/src/smart_battery.rs:805–823  ·  view source on GitHub ↗

Read a 32-bit value from a ManufacturerAccess block command (SMBus block format with length prefix)

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

Source from the content-addressed store, hash-verified

803
804 /// Read a 32-bit value from a ManufacturerAccess block command (SMBus block format with length prefix)
805 fn read_i32(&self, ec: &CrosEc, addr: u16) -> EcResult<u32> {
806 // ManufacturerAccess block commands return data in SMBus block format:
807 // Byte 0: Length, Bytes 1-4: Data
808 let i2c_response = i2c_read(ec, self.i2c_port, self.i2c_addr >> 1, addr, 0x05)?;
809 i2c_response.is_successful()?;
810 let len = i2c_response.data[0];
811 if len != 4 {
812 return Err(EcError::DeviceError(format!(
813 "Expected 4 bytes but got {} from register 0x{:02X}",
814 len, addr
815 )));
816 }
817 Ok(u32::from_le_bytes([
818 i2c_response.data[1],
819 i2c_response.data[2],
820 i2c_response.data[3],
821 i2c_response.data[4],
822 ]))
823 }
824
825 fn read_string(&self, ec: &CrosEc, addr: u16) -> EcResult<String> {
826 // SMBus strings are length-prefixed

Callers 1

collect_dataMethod · 0.80

Calls 2

i2c_readFunction · 0.85
is_successfulMethod · 0.80

Tested by

no test coverage detected