~xdavidwu/motion-control

2faccc550df93aa3023f072ccf35f73770684aaa — xdavidwu 2 years ago 72dbf50
sensors::L3G4200D: read byte by byte

the chip i have seems to response to smbus read word in wrong order
1 files changed, 4 insertions(+), 2 deletions(-)

M sensors/L3G4200D/L3G4200D.ha
M sensors/L3G4200D/L3G4200D.ha => sensors/L3G4200D/L3G4200D.ha +4 -2
@@ 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;
};