summaryrefslogtreecommitdiff
path: root/test/motion_common.c
diff options
context:
space:
mode:
authorChing-Kang Yen <chingkang@chromium.org>2020-07-31 02:12:02 +0800
committerCommit Bot <commit-bot@chromium.org>2020-09-03 07:15:48 +0000
commit8e7bbf94749ed9751e7ccb4963cd4a696186f765 (patch)
tree4b27512313d48c490724379d60e8ef3ca0b24a53 /test/motion_common.c
parent53a2ee971270fcf759766a83496da05685ec8151 (diff)
downloadchrome-ec-8e7bbf94749ed9751e7ccb4963cd4a696186f765.tar.gz
test: body_detection: add unittest for algorithm
Add test to check if the algorithm of body detection is correct. There are three testcases: OnBody: always in on-body state, should not change to off-body Off to On: change state from off-body to on-body On to Off: change state from on-body to off-body BRANCH=None BUG=b:123434029 TEST=make buildall Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> Change-Id: Ib027fa3ed659f0d2efd7416888a9ee4ad519edd6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2329113 Reviewed-by: Heng-ruey Hsu <henryhsu@chromium.org>
Diffstat (limited to 'test/motion_common.c')
-rw-r--r--test/motion_common.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/motion_common.c b/test/motion_common.c
index 36f9d003a0..2cacae0eb1 100644
--- a/test/motion_common.c
+++ b/test/motion_common.c
@@ -6,6 +6,7 @@
*/
#include "accelgyro.h"
+#include "driver/accelgyro_bmi_common.h"
#include "host_command.h"
#include "motion_common.h"
#include "motion_sense.h"
@@ -32,6 +33,10 @@ static int accel_get_range(const struct motion_sensor_t *s)
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;
}
@@ -50,6 +55,18 @@ static int accel_get_data_rate(const struct motion_sensor_t *s)
return test_data_rate[s - motion_sensors];
}
+#ifdef TEST_BODY_DETECTION
+static int accel_get_rms_noise(const struct motion_sensor_t *s)
+{
+ /* Assume we are using BMI160 */
+ fp_t rate = INT_TO_FP(accel_get_data_rate(s) / 1000);
+ fp_t noise_100hz = INT_TO_FP(BMI160_ACCEL_RMS_NOISE_100HZ);
+ fp_t sqrt_rate_ratio = fp_sqrtf(fp_div(rate,
+ INT_TO_FP(BMI_ACCEL_100HZ)));
+ return FP_TO_INT(fp_mul(noise_100hz, sqrt_rate_ratio));
+}
+#endif
+
const struct accelgyro_drv test_motion_sense = {
.init = accel_init,
.read = accel_read,
@@ -57,6 +74,9 @@ const struct accelgyro_drv test_motion_sense = {
.get_resolution = accel_get_resolution,
.set_data_rate = accel_set_data_rate,
.get_data_rate = accel_get_data_rate,
+#ifdef CONFIG_BODY_DETECTION
+ .get_rms_noise = accel_get_rms_noise,
+#endif
};
struct motion_sensor_t motion_sensors[] = {