rewrote the gyro and accel update functions to make them faster
This commit is contained in:
parent
56e568643b
commit
68e1048a7b
|
@ -139,38 +139,22 @@ _Bool gy521_init(gy521_module *m, uint8_t slave_address) {
|
||||||
|
|
||||||
void gy521_update_accel(gy521_module *m)
|
void gy521_update_accel(gy521_module *m)
|
||||||
{
|
{
|
||||||
uint8_t read_regs[NUM_ACCEL_REGS] = {accel_xouth, accel_xoutl,
|
m->accel.x = read_register(m, accel_xouth) <<8;
|
||||||
accel_youth, accel_youth,
|
m->accel.x |= read_register(m, accel_xoutl);
|
||||||
accel_zouth, accel_zoutl};
|
m->accel.y = read_register(m, accel_youth) <<8;
|
||||||
|
m->accel.y |= read_register(m, accel_youtl);
|
||||||
/*update individually the structure by communicating with the device.*/
|
m->accel.z = read_register(m, accel_zouth) <<8;
|
||||||
for(uint8_t i = 0; i < NUM_ACCEL_REGS; i++) {
|
m->accel.z |= read_register(m, accel_zoutl);
|
||||||
read_regs[i] = read_register(m, read_regs[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*bitshift to reassembly the high/low regs into a single 16bit*/
|
|
||||||
m->accel.x = (read_regs[0] << 8) | read_regs[1];
|
|
||||||
m->accel.y = (read_regs[2] << 8) | read_regs[3];
|
|
||||||
m->accel.z = (read_regs[4] << 8) | read_regs[5];
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gy521_update_gyro(gy521_module *m)
|
void gy521_update_gyro(gy521_module *m)
|
||||||
{
|
{
|
||||||
uint8_t read_regs[NUM_GYRO_REGS] = {gyro_xouth, gyro_xoutl,
|
m->gyro.x = read_register(m, gyro_xouth) <<8;
|
||||||
gyro_youth, gyro_youth,
|
m->gyro.x |= read_register(m, gyro_xoutl);
|
||||||
gyro_zouth, gyro_zoutl};
|
m->gyro.y = read_register(m, gyro_youth) <<8;
|
||||||
|
m->gyro.y |= read_register(m, gyro_youtl);
|
||||||
/*update individually the structure by communicating with the device.*/
|
m->gyro.z = read_register(m, gyro_zouth) <<8;
|
||||||
for(uint8_t i = 0; i < NUM_GYRO_REGS; i++) {
|
m->gyro.z |= read_register(m, gyro_zoutl);
|
||||||
read_regs[i] = read_register(m, read_regs[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*bitshift to reassembly the high/low regs into a single 16bit*/
|
|
||||||
m->gyro.x = (read_regs[0] << 8) | read_regs[1];
|
|
||||||
m->gyro.y = (read_regs[2] << 8) | read_regs[3];
|
|
||||||
m->gyro.z = (read_regs[4] << 8) | read_regs[5];
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue