summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2023-01-09 14:24:46 -0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-01-11 18:43:03 +0000
commit32c498f7240595860fdce5bd1f4ad0693a7d503e (patch)
treef3753304a3f724fa75e95a3932ab8f9f7d29a013
parentcc3a1940419436150d363f3b74a4be9ff3037bcc (diff)
downloadchrome-ec-32c498f7240595860fdce5bd1f4ad0693a7d503e.tar.gz
body_detection: Remove get_resolution
EC accelerometer drivers already pad data from sensors when resolution is less than 16 bits. No more resolution processing is needed when measuring body activity. BUG=b:262680246 BRANCH=none TEST=Unit test. Change-Id: Iff7df3915e855e25abc287a3c2caa477fd678f27 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4148783 Reviewed-by: Diana Z <dzigterman@chromium.org> Tested-by: Elthan Huang <elthan_huang@compal.corp-partner.google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--common/body_detection.c11
-rw-r--r--test/body_detection.c5
-rw-r--r--test/motion_common.c10
3 files changed, 6 insertions, 20 deletions
diff --git a/common/body_detection.c b/common/body_detection.c
index 819ced4679..50b9b93d1c 100644
--- a/common/body_detection.c
+++ b/common/body_detection.c
@@ -143,12 +143,11 @@ static void determine_window_size(int odr)
}
}
-/* Determine variance threshold scale by range and resolution. */
-static void determine_threshold_scale(int range, int resolution, int rms_noise)
+/* Determine variance threshold scale by range. */
+static void determine_threshold_scale(int range, int rms_noise)
{
/*
* range: g
- * resolution: bits
* data_1g: LSB/g
* data_1g / 9800: LSB/(mm/s^2)
* (data_1g / 9800)^2: (LSB^2)/(mm^2/s^4), which number of
@@ -156,7 +155,7 @@ static void determine_threshold_scale(int range, int resolution, int rms_noise)
* rms_noise: ug
* var_noise: mm^2/s^4
*/
- const int data_1g = BIT(resolution - 1) / range;
+ const int data_1g = MOTION_SCALING_FACTOR / range;
const int multiplier = POW2(data_1g);
const int divisor = POW2(9800);
/*
@@ -181,7 +180,6 @@ static void determine_threshold_scale(int range, int resolution, int rms_noise)
void body_detect_reset(void)
{
int odr = body_sensor->drv->get_data_rate(body_sensor);
- int resolution = body_sensor->drv->get_resolution(body_sensor);
int rms_noise = body_sensor->drv->get_rms_noise(body_sensor);
body_detect_change_state(BODY_DETECTION_ON_BODY, false);
@@ -192,8 +190,7 @@ void body_detect_reset(void)
if (odr == 0)
return;
determine_window_size(odr);
- determine_threshold_scale(body_sensor->current_range, resolution,
- rms_noise);
+ determine_threshold_scale(body_sensor->current_range, rms_noise);
/* initialize motion data and state */
memset(data, 0, sizeof(data));
history_idx = 0;
diff --git a/test/body_detection.c b/test/body_detection.c
index dac2202eac..e1015f5a72 100644
--- a/test/body_detection.c
+++ b/test/body_detection.c
@@ -19,10 +19,9 @@ 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 data_1g = BIT(resolution - 1) / s->current_range;
+ int data_1g = MOTION_SCALING_FACTOR / s->current_range;
- return (int)(v * data_1g / 9.8);
+ return (int)(v * data_1g / MOTION_ONE_G);
}
static void feed_body_detect_data(const struct body_detect_test_data *array,
diff --git a/test/motion_common.c b/test/motion_common.c
index e274b206a9..b1e0a8cd7d 100644
--- a/test/motion_common.c
+++ b/test/motion_common.c
@@ -32,15 +32,6 @@ static int accel_set_range(struct motion_sensor_t *s, int range, int rnd)
return EC_SUCCESS;
}
-static int accel_get_resolution(const struct motion_sensor_t *s)
-{
-#ifdef TEST_BODY_DETECTION
- /* Assume we are using BMI160 */
- return BMI_RESOLUTION;
-#endif
- return 0;
-}
-
int test_data_rate[2] = { 0 };
static int accel_set_data_rate(const struct motion_sensor_t *s, const int rate,
@@ -71,7 +62,6 @@ const struct accelgyro_drv test_motion_sense = {
.init = accel_init,
.read = accel_read,
.set_range = accel_set_range,
- .get_resolution = accel_get_resolution,
.set_data_rate = accel_set_data_rate,
.get_data_rate = accel_get_data_rate,
#ifdef CONFIG_BODY_DETECTION