summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2020-05-17 16:43:02 -0700
committerCommit Bot <commit-bot@chromium.org>2020-11-12 03:23:26 +0000
commitd28c10498cdbf007b97b5c0a9a951373574d4eea (patch)
tree3d66ca06837aae98ff747fff85b439976e563045 /test
parent9676f9291f60efdfb31373aeb77385ebb6e9f6e5 (diff)
downloadchrome-ec-d28c10498cdbf007b97b5c0a9a951373574d4eea.tar.gz
motion_sense: Make change in range permanent
When AP changes range, unlike offset or ODR, it was not surviving init() call. If the sensor is powered off in S3, at resume the range would be back to the default. To make it consistent with other attributes, remember range change until EC powers down. - remove get_range - add current_range to store the range currently used. This is modifiable by the AP - when the AP shutdown, revert current_range to default_range - Remove const attribute for sensor structure when init and set_range is called. BUG=chromium:1083791 BRANCH=none TEST=One eve branch, check range is preserved even after 'shutdown -h 0' Change-Id: Ia7126ac0cc9c3fef60b4464d95d6dd15e64b0fc4 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2215751 Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/body_detection.c3
-rw-r--r--test/motion_angle.c2
-rw-r--r--test/motion_angle_tablet.c2
-rw-r--r--test/motion_common.c11
-rw-r--r--test/motion_lid.c11
-rw-r--r--test/online_calibration.c24
6 files changed, 14 insertions, 39 deletions
diff --git a/test/body_detection.c b/test/body_detection.c
index 48fefce249..fe86b457c5 100644
--- a/test/body_detection.c
+++ b/test/body_detection.c
@@ -20,8 +20,7 @@ static const int window_size = 50; /* sensor data rate (Hz) */
static int filler(const struct motion_sensor_t *s, const float v)
{
int resolution = s->drv->get_resolution(s);
- int range = s->drv->get_range(s);
- int data_1g = BIT(resolution - 1) / range;
+ int data_1g = BIT(resolution - 1) / s->current_range;
return (int)(v * data_1g / 9.8);
}
diff --git a/test/motion_angle.c b/test/motion_angle.c
index 06872a7a41..30f663de14 100644
--- a/test/motion_angle.c
+++ b/test/motion_angle.c
@@ -26,7 +26,7 @@
/* Array units is in m/s^2 - old matrix format. */
int filler(const struct motion_sensor_t *s, const float v)
{
- return (v * MOTION_SCALING_FACTOR) / s->drv->get_range(s);
+ return (v * MOTION_SCALING_FACTOR) / s->current_range;
}
static int test_lid_angle_less180(void)
diff --git a/test/motion_angle_tablet.c b/test/motion_angle_tablet.c
index 0829d9bb31..3cf496ac5b 100644
--- a/test/motion_angle_tablet.c
+++ b/test/motion_angle_tablet.c
@@ -28,7 +28,7 @@ int filler(const struct motion_sensor_t *s, const float v)
{
return FP_TO_INT( fp_div(
FLOAT_TO_FP(v) * MOTION_SCALING_FACTOR,
- fp_mul(INT_TO_FP(s->drv->get_range(s)), MOTION_ONE_G)));
+ fp_mul(INT_TO_FP(s->current_range), MOTION_ONE_G)));
}
static int test_lid_angle_less180(void)
diff --git a/test/motion_common.c b/test/motion_common.c
index 2cacae0eb1..4efa407b9f 100644
--- a/test/motion_common.c
+++ b/test/motion_common.c
@@ -15,9 +15,9 @@
/*****************************************************************************/
/* Mock functions */
-static int accel_init(const struct motion_sensor_t *s)
+static int accel_init(struct motion_sensor_t *s)
{
- return EC_SUCCESS;
+ return sensor_init_done(s);
}
static int accel_read(const struct motion_sensor_t *s, intv3_t v)
@@ -26,9 +26,10 @@ static int accel_read(const struct motion_sensor_t *s, intv3_t v)
return EC_SUCCESS;
}
-static int accel_get_range(const struct motion_sensor_t *s)
+static int accel_set_range(struct motion_sensor_t *s, int range, int rnd)
{
- return s->default_range;
+ s->current_range = range;
+ return EC_SUCCESS;
}
static int accel_get_resolution(const struct motion_sensor_t *s)
@@ -70,7 +71,7 @@ static int accel_get_rms_noise(const struct motion_sensor_t *s)
const struct accelgyro_drv test_motion_sense = {
.init = accel_init,
.read = accel_read,
- .get_range = accel_get_range,
+ .set_range = accel_set_range,
.get_resolution = accel_get_resolution,
.set_data_rate = accel_set_data_rate,
.get_data_rate = accel_get_data_rate,
diff --git a/test/motion_lid.c b/test/motion_lid.c
index a9ede3a651..2c6c216430 100644
--- a/test/motion_lid.c
+++ b/test/motion_lid.c
@@ -36,7 +36,7 @@ extern enum chipset_state_mask sensor_active;
/*****************************************************************************/
/* Mock functions */
-static int accel_init(const struct motion_sensor_t *s)
+static int accel_init(struct motion_sensor_t *s)
{
return EC_SUCCESS;
}
@@ -47,18 +47,14 @@ static int accel_read(const struct motion_sensor_t *s, intv3_t v)
return EC_SUCCESS;
}
-static int accel_set_range(const struct motion_sensor_t *s,
+static int accel_set_range(struct motion_sensor_t *s,
const int range,
const int rnd)
{
+ s->current_range = range;
return EC_SUCCESS;
}
-static int accel_get_range(const struct motion_sensor_t *s)
-{
- return s->default_range;
-}
-
static int accel_get_resolution(const struct motion_sensor_t *s)
{
return 0;
@@ -83,7 +79,6 @@ const struct accelgyro_drv test_motion_sense = {
.init = accel_init,
.read = accel_read,
.set_range = accel_set_range,
- .get_range = accel_get_range,
.get_resolution = accel_get_resolution,
.set_data_rate = accel_set_data_rate,
.get_data_rate = accel_get_data_rate,
diff --git a/test/online_calibration.c b/test/online_calibration.c
index f0432d5893..1b3abf51bc 100644
--- a/test/online_calibration.c
+++ b/test/online_calibration.c
@@ -44,30 +44,8 @@ static int mock_read_temp(const struct motion_sensor_t *s, int *temp)
return EC_ERROR_UNKNOWN;
}
-struct mock_get_range_result {
- struct motion_sensor_t *s;
- int ret;
- struct mock_get_range_result *next;
-};
-
-static struct mock_get_range_result *mock_get_range_results;
-
-static int mock_get_range(const struct motion_sensor_t *s)
-{
- struct mock_get_range_result *ptr = mock_get_range_results;
-
- while (ptr) {
- if (ptr->s == s)
- return ptr->ret;
- ptr = ptr->next;
- }
-
- return 4;
-}
-
static struct accelgyro_drv mock_sensor_driver = {
.read_temp = mock_read_temp,
- .get_range = mock_get_range,
};
static struct accel_cal_algo base_accel_cal_algos[] = {
@@ -105,6 +83,7 @@ bool accel_cal_accumulate(
struct motion_sensor_t motion_sensors[] = {
[BASE] = {
.type = MOTIONSENSE_TYPE_ACCEL,
+ .default_range = 4,
.drv = &mock_sensor_driver,
.online_calib_data[0] = {
.type_specific_data = &base_accel_cal_data,
@@ -112,6 +91,7 @@ struct motion_sensor_t motion_sensors[] = {
},
[LID] = {
.type = MOTIONSENSE_TYPE_MAG,
+ .default_range = 4,
.drv = &mock_sensor_driver,
.online_calib_data[0] = {
.type_specific_data = &lid_mag_cal_data,