mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Update MSA301 driver to fix orientation detection and cleanup
This commit is contained in:
@@ -18,23 +18,32 @@ static const FRToSI2C::I2C_REG i2c_registers[] = { //
|
||||
{ MSA301_REG_POWERMODE, 0b0001001, 1 }, // Normal mode
|
||||
{ MSA301_REG_RESRANGE, 0b00000001, 0 }, // 14bit resolution @ 4G range
|
||||
{ MSA301_REG_ORIENT_HY, 0b01000000, 0 }, // 4*62.5mg hyst, no blocking, symmetrical
|
||||
{ MSA301_REG_ORIENT_HY, 0b01000000, 0 }, // 4*62.5mg hyst, no blocking, symmetrical
|
||||
{ MSA301_REG_INTSET0, 1 << 6, 0 }, // Turn on orientation detection (by enabling its interrupt)
|
||||
|
||||
};
|
||||
|
||||
bool MSA301::initalize() {
|
||||
// Enable X/Y/Z
|
||||
// Normal mode
|
||||
// 250Hz filter
|
||||
// 4G range
|
||||
// 14 bit resolution
|
||||
|
||||
return FRToSI2C::writeRegistersBulk(MSA301_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
}
|
||||
|
||||
Orientation MSA301::getOrientation() {
|
||||
//read MSA301_REG_ORIENT_STATUS
|
||||
uint8_t temp = 0;
|
||||
FRToSI2C::Mem_Read(MSA301_I2C_ADDRESS, MSA301_REG_ORIENT_STATUS, &temp, 1);
|
||||
switch (temp) {
|
||||
case 112:
|
||||
return Orientation::ORIENTATION_LEFT_HAND;
|
||||
case 96:
|
||||
return Orientation::ORIENTATION_RIGHT_HAND;
|
||||
}
|
||||
return Orientation::ORIENTATION_FLAT;
|
||||
}
|
||||
|
||||
void MSA301::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
uint8_t temp[6];
|
||||
//Bulk read all 6 regs
|
||||
FRToSI2C::Mem_Read(MSA301_I2C_ADDRESS, MSA301_REG_OUT_X_L, temp, 6);
|
||||
x = int16_t(((int16_t) temp[1]) << 8 | temp[0]) >> 2;
|
||||
y = int16_t(((int16_t) temp[3]) << 8 | temp[2]) >> 2;
|
||||
z = int16_t(((int16_t) temp[5]) << 8 | temp[4]) >> 2;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user