From 2faccc550df93aa3023f072ccf35f73770684aaa Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Tue, 17 May 2022 00:32:36 +0800 Subject: [PATCH] sensors::L3G4200D: read byte by byte the chip i have seems to response to smbus read word in wrong order --- sensors/L3G4200D/L3G4200D.ha | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sensors/L3G4200D/L3G4200D.ha b/sensors/L3G4200D/L3G4200D.ha index e9c8f8c..4267223 100644 --- a/sensors/L3G4200D/L3G4200D.ha +++ b/sensors/L3G4200D/L3G4200D.ha @@ -19,11 +19,13 @@ export fn new(bus: int) (L3G4200D | fs::error | rt::errno) = { export fn init(sensor: L3G4200D) (void | rt::errno) = { i2c::smbus::write_byte_data(sensor.file, REG_CTRL_REG1, CTRL_REG1_PD | CTRL_REG1_Zen | CTRL_REG1_Yen | CTRL_REG1_Xen)?; + i2c::smbus::write_byte_data(sensor.file, REG_CTRL_REG4, CTRL_REG4_BDU)?; }; fn read_data(sensor: L3G4200D, reg: u8) (f64 | rt::errno) = { - const raw = i2c::smbus::read_word_data(sensor.file, reg)?; - const raw = raw: i16; + const raw = i2c::smbus::read_byte_data(sensor.file, reg)?; + const raw2 = i2c::smbus::read_byte_data(sensor.file, reg + 1)?; + const raw = (raw: u16 + (raw2: u16 << 8)): i16; return raw: f64 * FS_250DPS_So; }; -- 2.45.2