diff options
author | Josh-Tsai <josh_tsai@compal.corp-partner.google.com> | 2022-11-28 17:06:54 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-12-01 00:26:04 +0000 |
commit | 1f0e75baabd0ad6b3b2f99146f831cefefe4c374 (patch) | |
tree | 1356b68470fcea3ba66e4b5aa27a46391dc21375 /driver | |
parent | c50046ad633f1958107eead2b778422a2f33d7af (diff) | |
download | chrome-ec-1f0e75baabd0ad6b3b2f99146f831cefefe4c374.tar.gz |
driver: lis2dw12: 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.,
power mode
Add get_rms_noise() function to get the root mean square
of noise in lis2dw12.
LOW_COVERAGE_REASON=no unit test for body_detection yet: b/259754018
BRANCH=None
BUG=b:236668095
TEST=zmake build winterhold
Change-Id: Ic7e99902e010f6ec0441abff6bb3684a63cfd471
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4060290
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Tested-by: Josh Tsai <josh_tsai@compal.corp-partner.google.com>
Reviewed-by: Elthan Huang <elthan_huang@compal.corp-partner.google.com>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/accel_lis2dw12.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/driver/accel_lis2dw12.c b/driver/accel_lis2dw12.c index 42d9381bda..f3f3ae8537 100644 --- a/driver/accel_lis2dw12.c +++ b/driver/accel_lis2dw12.c @@ -380,6 +380,35 @@ unlock_rate: return ret; } +#ifdef CONFIG_BODY_DETECTION +static int get_rms_noise(const struct motion_sensor_t *s) +{ + fp_t rate, noise_density_ug; + + /* change unit of ODR to Hz to prevent INT_TO_FP() overflow */ + rate = INT_TO_FP(st_get_data_rate(s) / 1000); + + /* + * LIS2DW12: 90ug/sqrt(Hz) when ODR is over 200Hz + * When lower, we are in power mode 2, so the noise density does not + * depend on frequency and the RMS at +/-2g is 2.4mg. + * + * LIS12DWL: 110uq/sqr(Hz) for all frequencies, since low power mode + * is not used. + */ + + if (!IS_ENABLED(CONFIG_ACCEL_LIS2DWL)) { + if (rate < INT_TO_FP(200)) + return 2400; + noise_density_ug = INT_TO_FP(90); + } else { + noise_density_ug = INT_TO_FP(110); + } + + return FP_TO_INT(fp_mul(fp_sqrtf(rate), noise_density_ug)); +} +#endif + static int is_data_ready(const struct motion_sensor_t *s, int *ready) { int ret, tmp; @@ -527,4 +556,7 @@ const struct accelgyro_drv lis2dw12_drv = { #ifdef ACCEL_LIS2DW12_INT_ENABLE .irq_handler = lis2dw12_irq_handler, #endif /* ACCEL_LIS2DW12_INT_ENABLE */ +#ifdef CONFIG_BODY_DETECTION + .get_rms_noise = get_rms_noise, +#endif }; |