From 90c79d90699268d31a3a2d8f48af5955e493005b Mon Sep 17 00:00:00 2001 From: Ching-Kang Yen Date: Thu, 30 Jul 2020 17:37:08 +0800 Subject: driver: bmi: add get_rms_noise() for body detection We will need the amount of noise for body detection. The amount of noise in accelometer will depends on several thing, e.g., output data rate. Add get_rms_noise() function to get the root mean square of noise in BMI. BRANCH=None BUG=b:123434029 TEST=buildall Signed-off-by: Ching-Kang Yen Change-Id: Ia56bbd2cdb36bee771beb9df32451d3e56f4f028 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2329112 Reviewed-by: Gwendal Grignou Reviewed-by: Heng-ruey Hsu --- driver/accelgyro_bmi_common.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'driver/accelgyro_bmi_common.c') diff --git a/driver/accelgyro_bmi_common.c b/driver/accelgyro_bmi_common.c index f348edb1c5..2d8cfa2c45 100644 --- a/driver/accelgyro_bmi_common.c +++ b/driver/accelgyro_bmi_common.c @@ -661,6 +661,34 @@ int bmi_get_offset(const struct motion_sensor_t *s, return EC_SUCCESS; } +#ifdef CONFIG_BODY_DETECTION +int bmi_get_rms_noise(const struct motion_sensor_t *s) +{ + int ret; + fp_t noise_100hz, rate, sqrt_rate_ratio; + + switch (s->type) { + case MOTIONSENSE_TYPE_ACCEL: + /* change unit of ODR to Hz to prevent INT_TO_FP() overflow */ + rate = INT_TO_FP(bmi_get_data_rate(s) / 1000); + /* + * Since the noise is proportional to sqrt(ODR) in BMI, and we + * have rms noise in 100 Hz, we multiply it with the sqrt(ratio + * of ODR to 100Hz) to get current noise. + */ + noise_100hz = INT_TO_FP(BMI_ACCEL_RMS_NOISE_100HZ(V(s))); + sqrt_rate_ratio = fp_sqrtf(fp_div(rate, + INT_TO_FP(BMI_ACCEL_100HZ))); + ret = FP_TO_INT(fp_mul(noise_100hz, sqrt_rate_ratio)); + break; + default: + CPRINTS("%s with gyro/mag is not implemented", __func__); + return 0; + } + return ret; +} +#endif + int bmi_get_resolution(const struct motion_sensor_t *s) { return BMI_RESOLUTION; -- cgit v1.2.1