Skip to content

Commit

Permalink
Allow changing the power mode of BNO055
Browse files Browse the repository at this point in the history
  • Loading branch information
corruptbear committed Nov 18, 2023
1 parent 9c3ca75 commit ad280e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions software/firmware/src/peripherals/include/imu.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ typedef struct
void imu_init(void);
void imu_deinit(void);
void imu_register_motion_change_callback(motion_change_callback_t callback, bno055_opmode_t mode);
void imu_set_power_mode(bno055_powermode_t power_mode);
void imu_read_accel_data(bno055_acc_t *acc);
void imu_read_linear_accel_data(bno055_acc_t *acc);
void imu_read_gravity_accel_data(bno055_acc_t *acc);
Expand Down
8 changes: 8 additions & 0 deletions software/firmware/src/peripherals/src/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ void imu_register_motion_change_callback(motion_change_callback_t callback, bno0
set_mode(mode);
}

void imu_set_power_mode(bno055_powermode_t power_mode)
{
bno055_opmode_t saved_mode = get_mode();
set_mode(OPERATION_MODE_CONFIG);
i2c_write8(BNO055_PWR_MODE_ADDR, power_mode);
set_mode(saved_mode);
}

void imu_read_accel_data(bno055_acc_t *acc)
{
static int16_t accel_data[3];
Expand Down
1 change: 1 addition & 0 deletions software/firmware/tests/peripherals/test_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ int main(void)
bno055_acc_t acc = {0};

imu_register_motion_change_callback(motion_interrupt, OPERATION_MODE_NDOF);
imu_set_power_mode(POWER_MODE_NORMAL);

imu_read_fw_version(&rev_msb, &rev_lsb);
print("BNO055 firmware version:%u.%u\n",rev_msb, rev_lsb);
Expand Down

0 comments on commit ad280e4

Please sign in to comment.