mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-10 17:41:54 +00:00
motion_sense: Add more complex EC/AP sensor rate support.
Add config settings for ODR and EC rate per requestor and per power state (1 for the AP, 3 for the EC). This way we can finely set ec rate and ODR depending on usage. On chromeos, AP is not setting frequency, so EC sets for different power state. On some platform, sensors can now be suspended in S3/S5. Allow EC oversampling when AP is only looking for a few samples. It is useful for double tap detection where high accelerator ODR is required. BRANCH=ryu TEST=Tested on Ryu BUG=chromium:513458 Change-Id: Ic3888a749699f07b10c5da3bc07204afd4de70da Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/295637
This commit is contained in:
committed by
chrome-bot
parent
398bd9a017
commit
4e7e1bb796
@@ -511,7 +511,7 @@ static int init(const struct motion_sensor_t *s)
|
||||
}
|
||||
} while (1);
|
||||
|
||||
ret = set_range(s, s->runtime_config.range, 1);
|
||||
ret = set_range(s, s->default_range, 1);
|
||||
if (ret != EC_SUCCESS)
|
||||
return ret;
|
||||
|
||||
@@ -519,15 +519,11 @@ static int init(const struct motion_sensor_t *s)
|
||||
if (ret != EC_SUCCESS)
|
||||
return ret;
|
||||
|
||||
ret = set_data_rate(s, s->runtime_config.odr, 1);
|
||||
if (ret != EC_SUCCESS)
|
||||
return ret;
|
||||
|
||||
#ifdef CONFIG_ACCEL_INTERRUPTS
|
||||
config_interrupt(s);
|
||||
#endif
|
||||
CPRINTF("[%T %s: Done Init type:0x%X range:%d rate:%d]\n",
|
||||
s->name, s->type, get_range(s), get_data_rate(s));
|
||||
CPRINTF("[%T %s: Done Init type:0x%X range:%d]\n",
|
||||
s->name, s->type, get_range(s));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ static int set_range(const struct motion_sensor_t *s,
|
||||
int ret, range_tbl_size;
|
||||
uint8_t reg_val, ctrl_reg;
|
||||
const struct accel_param_pair *ranges;
|
||||
struct motion_data_t *data = BMI160_GET_SAVED_DATA(s);
|
||||
struct accelgyro_saved_data_t *data = BMI160_GET_SAVED_DATA(s);
|
||||
|
||||
if (s->type == MOTIONSENSE_TYPE_MAG) {
|
||||
data->range = range;
|
||||
@@ -325,7 +325,7 @@ static int set_range(const struct motion_sensor_t *s,
|
||||
|
||||
static int get_range(const struct motion_sensor_t *s)
|
||||
{
|
||||
struct motion_data_t *data = BMI160_GET_SAVED_DATA(s);
|
||||
struct accelgyro_saved_data_t *data = BMI160_GET_SAVED_DATA(s);
|
||||
|
||||
return data->range;
|
||||
}
|
||||
@@ -349,7 +349,7 @@ static int set_data_rate(const struct motion_sensor_t *s,
|
||||
{
|
||||
int ret, val, normalized_rate;
|
||||
uint8_t ctrl_reg, reg_val;
|
||||
struct motion_data_t *data = BMI160_GET_SAVED_DATA(s);
|
||||
struct accelgyro_saved_data_t *data = BMI160_GET_SAVED_DATA(s);
|
||||
|
||||
if (rate == 0) {
|
||||
#ifdef CONFIG_ACCEL_FIFO
|
||||
@@ -429,8 +429,9 @@ static int set_data_rate(const struct motion_sensor_t *s,
|
||||
data->odr = normalized_rate;
|
||||
|
||||
#ifdef CONFIG_ACCEL_FIFO
|
||||
/* FIFO start collecting events */
|
||||
enable_fifo(s, 1);
|
||||
/* FIFO start collecting events if AP wants them */
|
||||
if (s->config[SENSOR_CONFIG_AP].odr != 0)
|
||||
enable_fifo(s, 1);
|
||||
#endif
|
||||
|
||||
accel_cleanup:
|
||||
@@ -440,7 +441,7 @@ accel_cleanup:
|
||||
|
||||
static int get_data_rate(const struct motion_sensor_t *s)
|
||||
{
|
||||
struct motion_data_t *data = BMI160_GET_SAVED_DATA(s);
|
||||
struct accelgyro_saved_data_t *data = BMI160_GET_SAVED_DATA(s);
|
||||
|
||||
return data->odr;
|
||||
}
|
||||
@@ -1015,11 +1016,10 @@ static int init(const struct motion_sensor_t *s)
|
||||
if (s->type == MOTIONSENSE_TYPE_ACCEL)
|
||||
ret = config_interrupt(s);
|
||||
#endif
|
||||
set_data_rate(s, s->runtime_config.odr, 0);
|
||||
set_range(s, s->runtime_config.range, 0);
|
||||
set_range(s, s->default_range, 0);
|
||||
|
||||
CPRINTF("[%T %s: MS Done Init type:0x%X range:%d odr:%d]\n",
|
||||
s->name, s->type, get_range(s), get_data_rate(s));
|
||||
CPRINTF("[%T %s: MS Done Init type:0x%X range:%d]\n",
|
||||
s->name, s->type, get_range(s));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -405,7 +405,7 @@ enum bmi160_running_mode {
|
||||
#define BMI160_FIFO_ALL_MASK 7
|
||||
|
||||
struct bmi160_drv_data_t {
|
||||
struct motion_data_t saved_data[3];
|
||||
struct accelgyro_saved_data_t saved_data[3];
|
||||
uint8_t flags;
|
||||
#ifdef CONFIG_MAG_BMI160_BMM150
|
||||
struct bmm150_comp_registers comp_regs;
|
||||
|
||||
@@ -426,29 +426,20 @@ static int init(const struct motion_sensor_t *s)
|
||||
if (ret)
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
ret = set_range(s, s->runtime_config.range, 1);
|
||||
if (ret)
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
ret = set_data_rate(s, s->runtime_config.odr, 1);
|
||||
ret = set_range(s, s->default_range, 1);
|
||||
if (ret)
|
||||
return EC_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
if (MOTIONSENSE_TYPE_GYRO == s->type) {
|
||||
/* Config GYRO Range */
|
||||
ret = set_range(s, s->runtime_config.range, 1);
|
||||
if (ret)
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
/* Config ACCEL & GYRO ODR */
|
||||
ret = set_data_rate(s, s->runtime_config.odr, 1);
|
||||
ret = set_range(s, s->default_range, 1);
|
||||
if (ret)
|
||||
return EC_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
CPRINTF("[%T %s: MS Done Init type:0x%X range:%d odr:%d]\n",
|
||||
s->name, s->type, get_range(s), get_data_rate(s));
|
||||
CPRINTF("[%T %s: MS Done Init type:0x%X range:%d]\n",
|
||||
s->name, s->type, get_range(s));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef __CROS_EC_ACCELGYRO_LSM6DS0_H
|
||||
#define __CROS_EC_ACCELGYRO_LSM6DS0_H
|
||||
|
||||
#include "motion_sense.h"
|
||||
#include "accelgyro.h"
|
||||
#include "task.h"
|
||||
|
||||
/*
|
||||
@@ -119,7 +119,7 @@ enum lsm6ds0_bdu {
|
||||
|
||||
extern const struct accelgyro_drv lsm6ds0_drv;
|
||||
struct lsm6ds0_data {
|
||||
struct motion_data_t base;
|
||||
struct accelgyro_saved_data_t base;
|
||||
int16_t offset[3];
|
||||
};
|
||||
|
||||
|
||||
@@ -487,7 +487,7 @@ static int init(const struct motion_sensor_t *s)
|
||||
resol = 5;
|
||||
}
|
||||
|
||||
set_range(s, s->runtime_config.range, 0);
|
||||
set_range(s, s->default_range, 0);
|
||||
/*
|
||||
* Sensor is most likely behind a glass.
|
||||
* Max out the gain to get correct measurement
|
||||
|
||||
Reference in New Issue
Block a user