Skip to content

Commit

Permalink
imu: Remove defines to control features as dynamic feature enable/dis…
Browse files Browse the repository at this point in the history
…able is now supported.
  • Loading branch information
jakkra committed Aug 15, 2023
1 parent d7e4b1b commit c36b52e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
2 changes: 2 additions & 0 deletions app/src/zsw_gatt_sensor_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,15 @@ static void on_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
// TODO handle notifications per connection per service.
if (!notif_enabled && (value == BT_GATT_CCC_NOTIFY)) {
notif_enabled = true;
zsw_imu_feature_enable(ZSW_IMU_FEATURE_GYRO, false);
ble_comm_short_connection_interval();
zsw_periodic_chan_add_obs(&periodic_event_fast_chan, &azsw_gatt_sensor_server_lis);
} else if (notif_enabled && (value != BT_GATT_CCC_NOTIFY)) {
// If any char get notify off, then stop sending at all.
// TODO Keep track of which ones have notify on.
ble_comm_long_connection_interval();
zsw_periodic_chan_rm_obs(&periodic_event_fast_chan, &azsw_gatt_sensor_server_lis);
zsw_imu_feature_disable(ZSW_IMU_FEATURE_GYRO);
notif_enabled = false;
}
}
Expand Down
19 changes: 2 additions & 17 deletions app/src/zsw_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

LOG_MODULE_REGISTER(accel, LOG_LEVEL_INF);

#define USE_ANYMOTION 1
#define USE_GYRO 1

/*! Earth's gravity in m/s^2 */
#define GRAVITY_EARTH (9.80665f)

Expand All @@ -30,12 +27,8 @@ static int8_t configure_axis_remapping(struct bmi2_dev *bmi2_dev);
static int8_t configure_enable_all_bmi270(struct bmi2_dev *bmi2_dev);
static void configue_accel(struct bmi2_sens_config *config);
static void configure_step_counter(struct bmi2_sens_config *config);
#if USE_GYRO
static void configue_gyro(struct bmi2_sens_config *config);
#endif
#if USE_ANYMOTION
static void configure_anymotion(struct bmi2_sens_config *config);
#endif
static void configure_gesture_detect(struct bmi2_sens_config *config);
static void configure_wrist_wakeup(struct bmi2_sens_config *config);
static void configure_no_motion(struct bmi2_sens_config *config);
Expand All @@ -47,15 +40,11 @@ static void bmi270_int2_work_cb(struct k_work *work);
// List of the features used on the BMI270.
static bmi270_feature_config_set_t bmi270_enabled_features[] = {
{ .sensor_id = BMI2_ACCEL, .cfg_func = configue_accel},
#if USE_GYRO
// Gyro not used for now, disable to keep power consumption down
{ .sensor_id = BMI2_GYRO, .cfg_func = configue_gyro},
#endif
{ .sensor_id = BMI2_GYRO, .cfg_func = configue_gyro, .skip_enable = true},
{ .sensor_id = BMI2_STEP_COUNTER, .cfg_func = configure_step_counter},
{ .sensor_id = BMI2_SIG_MOTION, .cfg_func = NULL, .isr_disable = true},
#if USE_ANYMOTION
{ .sensor_id = BMI2_ANY_MOTION, .cfg_func = configure_anymotion, .isr_disable = true},
#endif
{ .sensor_id = BMI2_ANY_MOTION, .cfg_func = configure_anymotion, .isr_disable = true, .skip_enable = true},
{ .sensor_id = BMI2_STEP_ACTIVITY, .cfg_func = NULL, .skip_enable = true},
{ .sensor_id = BMI2_WRIST_GESTURE, .cfg_func = configure_gesture_detect},
{ .sensor_id = BMI2_WRIST_WEAR_WAKE_UP, .cfg_func = configure_wrist_wakeup},
Expand Down Expand Up @@ -417,7 +406,6 @@ static void configue_accel(struct bmi2_sens_config *config)
config->cfg.acc.filter_perf = BMI2_POWER_OPT_MODE;
}

#if USE_GYRO
static void configue_gyro(struct bmi2_sens_config *config)
{
/* The user can change the following configuration parameters according to their requirement. */
Expand Down Expand Up @@ -445,14 +433,12 @@ static void configue_gyro(struct bmi2_sens_config *config)
*/
config->cfg.gyr.filter_perf = BMI2_POWER_OPT_MODE;
}
#endif

static void configure_step_counter(struct bmi2_sens_config *config)
{
config->cfg.step_counter.watermark_level = 1;
}

#if USE_ANYMOTION
static void configure_anymotion(struct bmi2_sens_config *config)
{
/* 1LSB equals 20ms. Default is 100ms, setting to 80ms. */
Expand All @@ -461,7 +447,6 @@ static void configure_anymotion(struct bmi2_sens_config *config)
/* 1LSB equals to 0.48mg. Default is 83mg, setting to 50mg. */
config->cfg.any_motion.threshold = 0x68;
}
#endif

static void configure_gesture_detect(struct bmi2_sens_config *config)
{
Expand Down

0 comments on commit c36b52e

Please sign in to comment.