summaryrefslogtreecommitdiff
path: root/driver/accelgyro_bmi_common.c
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-09-21 14:10:01 -0700
committerTom Hughes <tomhughes@chromium.org>2022-09-22 12:49:33 -0700
commit2bcf863b492fe7ed8105c853814dba6ed32ba719 (patch)
treefcf6ce5810f9ff9e3c8cce434812dd75492269ed /driver/accelgyro_bmi_common.c
parente5fb0b9ba488614b5684e640530f00821ab7b943 (diff)
parent28712dae9d7ed1e694f7622cc083afa71090d4d5 (diff)
downloadchrome-ec-2bcf863b492fe7ed8105c853814dba6ed32ba719.tar.gz
Merge remote-tracking branch cros/main into firmware-fpmcu-bloonchipper-releasefirmware-fpmcu-bloonchipper-release
Generated by: ./util/update_release_branch.py --board bloonchipper --relevant_paths_file ./util/fingerprint-relevant-paths.txt firmware- fpmcu-bloonchipper-release Relevant changes: git log --oneline e5fb0b9ba4..28712dae9d -- board/hatch_fp board/bloonchipper common/fpsensor docs/fingerprint driver/fingerprint util/getversion.sh ded9307b79 util/getversion.sh: Fix version when not in a git repo 956055e692 board: change Google USB vendor info 71b2ef709d Update license boilerplate text in source code files 33e11afda0 Revert "fpsensor: Build fpsensor source file with C++" c8d0360723 fpsensor: Build fpsensor source file with C++ bc113abd53 fpsensor: Fix g++ compiler error 150a58a0dc fpsensor: Fix fp_set_sensor_mode return type b33b5ce85b fpsensor: Remove nested designators for C++ compatibility 2e864b2539 tree-wide: const-ify argv for console commands 56d8b360f9 test: Add test for get ikm failure when seed not set 3a3d6c3690 test: Add test for fpsensor trivial key failure 233e6bbd08 fpsensor_crypto: Abstract calls to hmac_SHA256 0a041b285b docs/fingerprint: Typo correction c03fab67e2 docs/fingerprint: Fix the path of fputils.py 0b5d4baf5a util/getversion.sh: Fix empty file list handling 6e128fe760 FPMCU dev board environment with Satlab 3eb29b6aa5 builtin: Move ssize_t to sys/types.h 345d62ebd1 docs/fingerprint: Update power numbers for latest dartmonkey release c25ffdb316 common: Conditionally support printf %l and %i modifiers 9a3c514b45 test: Add a test to check if the debugger is connected 54e603413f Move standard library tests to their own file 43fa6b4bf8 docs/fingerprint: Update power numbers for latest bloonchipper release 25536f9a84 driver/fingerprint/fpc/bep/fpc_sensor_spi.c: Format with clang-format 4face99efd driver/fingerprint/fpc/libfp/fpc_sensor_pal.h: Format with clang-format 738de2b575 trng: Rename rand to trng_rand 14b8270edd docs/fingerprint: Update dragonclaw power numbers 0b268f93d1 driver/fingerprint/fpc/libfp/fpc_private.c: Format with clang-format f80da163f2 driver/fingerprint/fpc/libfp/fpc_private.h: Format with clang-format 5e9c85c9b1 driver/fingerprint/fpc/libfp/fpc_sensor_pal.c: Format with clang-format c1f9dd3cf8 driver/fingerprint/fpc/libfp/fpc_bio_algorithm.h: Format with clang-format eb1e1bed8d driver/fingerprint/fpc/libfp/fpc1145_private.h: Format with clang-format 6e7b611821 driver/fingerprint/fpc/bep/fpc_bio_algorithm.h: Format with clang-format e0589cd5e2 driver/fingerprint/fpc/bep/fpc1035_private.h: Format with clang-format 7905e556a0 common/fpsensor/fpsensor_crypto.c: Format with clang-format 21289d170c driver/fingerprint/fpc/bep/fpc1025_private.h: Format with clang-format 98a20f937e common/fpsensor/fpsensor_state.c: Format with clang-format a2d255d8af common/fpsensor/fpsensor.c: Format with clang-format 73055eeb3f driver/fingerprint/fpc/bep/fpc_private.c: Format with clang-format 0f7b5cb509 common/fpsensor/fpsensor_private.h: Format with clang-format 1ceade6e65 driver/fingerprint/fpc/bep/fpc_private.h: Format with clang-format dc3e9008b8 board/hatch_fp/board.h: Format with clang-format dca9d74321 Revert "trng: Rename rand to trng_rand" a6b0b3554f trng: Rename rand to trng_rand 28d0b75b70 third_party/boringssl: Remove unused header BRANCH=None BUG=b:246424843 b:234181908 b:244781166 b:234181908 b:244387210 BUG=b:242720240 chromium:1098010 b:180945056 b:236025198 b:234181908 BUG=b:234181908 b:237344361 b:131913998 b:236386294 b:234143158 BUG=b:234781655 b:215613183 b:242720910 TEST=`make -j buildall` TEST=./test/run_device_tests.py --board bloonchipper Test "aes": PASSED Test "cec": PASSED Test "cortexm_fpu": PASSED Test "crc": PASSED Test "flash_physical": PASSED Test "flash_write_protect": PASSED Test "fpsensor_hw": PASSED Test "fpsensor_spi_ro": PASSED Test "fpsensor_spi_rw": PASSED Test "fpsensor_uart_ro": PASSED Test "fpsensor_uart_rw": PASSED Test "mpu_ro": PASSED Test "mpu_rw": PASSED Test "mutex": PASSED Test "pingpong": PASSED Test "printf": PASSED Test "queue": PASSED Test "rollback_region0": PASSED Test "rollback_region1": PASSED Test "rollback_entropy": PASSED Test "rtc": PASSED Test "sha256": PASSED Test "sha256_unrolled": PASSED Test "static_if": PASSED Test "stdlib": PASSED Test "system_is_locked_wp_on": PASSED Test "system_is_locked_wp_off": PASSED Test "timer_dos": PASSED Test "utils": PASSED Test "utils_str": PASSED Test "stm32f_rtc": PASSED Test "panic_data_bloonchipper_v2.0.4277": PASSED Test "panic_data_bloonchipper_v2.0.5938": PASSED Force-Relevant-Builds: all Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I264ad0ffe7afcd507a1e483c6e934a9c4fea47c3
Diffstat (limited to 'driver/accelgyro_bmi_common.c')
-rw-r--r--driver/accelgyro_bmi_common.c132
1 files changed, 60 insertions, 72 deletions
diff --git a/driver/accelgyro_bmi_common.c b/driver/accelgyro_bmi_common.c
index 210cfd37ce..73131b0aae 100644
--- a/driver/accelgyro_bmi_common.c
+++ b/driver/accelgyro_bmi_common.c
@@ -1,4 +1,4 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+/* Copyright 2020 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,7 +8,6 @@
* 3D digital accelerometer & 3D digital gyroscope
*/
-
#include "accelgyro.h"
#include "console.h"
#include "accelgyro_bmi_common.h"
@@ -20,29 +19,29 @@
#include "spi.h"
#define CPUTS(outstr) cputs(CC_ACCEL, outstr)
-#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ##args)
-#if !defined(CONFIG_ACCELGYRO_BMI160) && \
- !defined(CONFIG_ACCELGYRO_BMI220) && \
- !defined(CONFIG_ACCELGYRO_BMI260) && \
- !defined(CONFIG_ACCELGYRO_BMI3XX)
+#if !defined(CONFIG_ACCELGYRO_BMI160) && !defined(CONFIG_ACCELGYRO_BMI220) && \
+ !defined(CONFIG_ACCELGYRO_BMI260) && !defined(CONFIG_ACCELGYRO_BMI3XX)
#error "Must use following sensors BMI160 BMI220 BMI260 BMI3XX"
#endif
#if (defined(CONFIG_ACCELGYRO_BMI260) || defined(CONFIG_ACCELGYRO_BMI220)) && \
- !defined(CONFIG_ACCELGYRO_BMI160)
+ !defined(CONFIG_ACCELGYRO_BMI160)
#define V(s_) 1
-#elif defined(CONFIG_ACCELGYRO_BMI160) && \
- !(defined(CONFIG_ACCELGYRO_BMI260) || defined(CONFIG_ACCELGYRO_BMI220))
+#elif defined(CONFIG_ACCELGYRO_BMI160) && \
+ !(defined(CONFIG_ACCELGYRO_BMI260) || \
+ defined(CONFIG_ACCELGYRO_BMI220))
#define V(s_) 0
#else
-#define V(s_) ((s_)->chip == MOTIONSENSE_CHIP_BMI260 || \
- (s_)->chip == MOTIONSENSE_CHIP_BMI220)
+#define V(s_) \
+ ((s_)->chip == MOTIONSENSE_CHIP_BMI260 || \
+ (s_)->chip == MOTIONSENSE_CHIP_BMI220)
#endif
/* Index for which table to use. */
#if defined(CONFIG_ACCELGYRO_BMI160) && \
- (defined(CONFIG_ACCELGYRO_BMI220) || defined(CONFIG_ACCELGYRO_BMI260))
+ (defined(CONFIG_ACCELGYRO_BMI220) || defined(CONFIG_ACCELGYRO_BMI260))
#define T(s_) V(s_)
#else
#define T(s_) 0
@@ -51,16 +50,16 @@
/* List of range values in +/-G's and their associated register values. */
const struct bmi_accel_param_pair g_ranges[][4] = {
#ifdef CONFIG_ACCELGYRO_BMI160
- { {2, BMI160_GSEL_2G},
- {4, BMI160_GSEL_4G},
- {8, BMI160_GSEL_8G},
- {16, BMI160_GSEL_16G} },
+ { { 2, BMI160_GSEL_2G },
+ { 4, BMI160_GSEL_4G },
+ { 8, BMI160_GSEL_8G },
+ { 16, BMI160_GSEL_16G } },
#endif
#if defined(CONFIG_ACCELGYRO_BMI220) || defined(CONFIG_ACCELGYRO_BMI260)
- { {2, BMI260_GSEL_2G},
- {4, BMI260_GSEL_4G},
- {8, BMI260_GSEL_8G},
- {16, BMI260_GSEL_16G} },
+ { { 2, BMI260_GSEL_2G },
+ { 4, BMI260_GSEL_4G },
+ { 8, BMI260_GSEL_8G },
+ { 16, BMI260_GSEL_16G } },
#endif
};
@@ -70,18 +69,18 @@ const struct bmi_accel_param_pair g_ranges[][4] = {
*/
const struct bmi_accel_param_pair dps_ranges[][5] = {
#ifdef CONFIG_ACCELGYRO_BMI160
- { {125, BMI160_DPS_SEL_125},
- {250, BMI160_DPS_SEL_250},
- {500, BMI160_DPS_SEL_500},
- {1000, BMI160_DPS_SEL_1000},
- {2000, BMI160_DPS_SEL_2000} },
+ { { 125, BMI160_DPS_SEL_125 },
+ { 250, BMI160_DPS_SEL_250 },
+ { 500, BMI160_DPS_SEL_500 },
+ { 1000, BMI160_DPS_SEL_1000 },
+ { 2000, BMI160_DPS_SEL_2000 } },
#endif
#if defined(CONFIG_ACCELGYRO_BMI220) || defined(CONFIG_ACCELGYRO_BMI260)
- { {125, BMI260_DPS_SEL_125},
- {250, BMI260_DPS_SEL_250},
- {500, BMI260_DPS_SEL_500},
- {1000, BMI260_DPS_SEL_1000},
- {2000, BMI260_DPS_SEL_2000} },
+ { { 125, BMI260_DPS_SEL_125 },
+ { 250, BMI260_DPS_SEL_250 },
+ { 500, BMI260_DPS_SEL_500 },
+ { 1000, BMI260_DPS_SEL_1000 },
+ { 2000, BMI260_DPS_SEL_2000 } },
#endif
};
@@ -99,8 +98,8 @@ int bmi_get_xyz_reg(const struct motion_sensor_t *s)
}
}
-const struct bmi_accel_param_pair *bmi_get_range_table(
- const struct motion_sensor_t *s, int *psize)
+const struct bmi_accel_param_pair *
+bmi_get_range_table(const struct motion_sensor_t *s, int *psize)
{
if (s->type == MOTIONSENSE_TYPE_ACCEL) {
if (psize)
@@ -119,8 +118,7 @@ const struct bmi_accel_param_pair *bmi_get_range_table(
* outside the range of values, it returns the closest valid reg value.
*/
int bmi_get_reg_val(const int eng_val, const int round_up,
- const struct bmi_accel_param_pair *pairs,
- const int size)
+ const struct bmi_accel_param_pair *pairs, const int size)
{
int i;
@@ -128,7 +126,7 @@ int bmi_get_reg_val(const int eng_val, const int round_up,
if (eng_val <= pairs[i].val)
break;
- if (eng_val < pairs[i+1].val) {
+ if (eng_val < pairs[i + 1].val) {
if (round_up)
i += 1;
break;
@@ -154,8 +152,8 @@ int bmi_get_engineering_val(const int reg_val,
}
#ifdef CONFIG_ACCELGYRO_BMI_COMM_SPI
-static int bmi_spi_raw_read(const int addr, const uint8_t reg,
- uint8_t *data, const int len)
+static int bmi_spi_raw_read(const int addr, const uint8_t reg, uint8_t *data,
+ const int len)
{
uint8_t cmd = 0x80 | reg;
@@ -166,8 +164,8 @@ static int bmi_spi_raw_read(const int addr, const uint8_t reg,
/**
* Read 8bit register from accelerometer.
*/
-int bmi_read8(const int port, const uint16_t i2c_spi_addr_flags,
- const int reg, int *data_ptr)
+int bmi_read8(const int port, const uint16_t i2c_spi_addr_flags, const int reg,
+ int *data_ptr)
{
int rv;
@@ -189,8 +187,8 @@ int bmi_read8(const int port, const uint16_t i2c_spi_addr_flags,
/**
* Write 8bit register from accelerometer.
*/
-int bmi_write8(const int port, const uint16_t i2c_spi_addr_flags,
- const int reg, int data)
+int bmi_write8(const int port, const uint16_t i2c_spi_addr_flags, const int reg,
+ int data)
{
int rv;
@@ -381,16 +379,16 @@ int bmi_decode_header(struct motion_sensor_t *accel, enum fifo_header hdr,
s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE)
v = s->spoof_xyz;
if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
- struct ec_response_motion_sensor_data vector;
+ struct ec_response_motion_sensor_data
+ vector;
vector.flags = 0;
vector.data[X] = v[X];
vector.data[Y] = v[Y];
vector.data[Z] = v[Z];
vector.sensor_num = s - motion_sensors;
- motion_sense_fifo_stage_data(&vector, s,
- 3,
- last_ts);
+ motion_sense_fifo_stage_data(
+ &vector, s, 3, last_ts);
} else {
motion_sense_push_raw_xyz(s);
}
@@ -626,30 +624,21 @@ int bmi_get_offset(const struct motion_sensor_t *s, int16_t *offset,
}
#ifdef CONFIG_BODY_DETECTION
-int bmi_get_rms_noise(const struct motion_sensor_t *s)
+int bmi_get_rms_noise(const struct motion_sensor_t *accel,
+ int rms_noise_100hz_mg)
{
- int ret;
- fp_t noise_100hz, rate, sqrt_rate_ratio;
+ fp_t 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;
+ /* change unit of ODR to Hz to prevent INT_TO_FP() overflow */
+ rate = INT_TO_FP(bmi_get_data_rate(accel) / 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.
+ */
+ sqrt_rate_ratio = fp_sqrtf(fp_div(rate, INT_TO_FP(BMI_ACCEL_100HZ)));
+ return FP_TO_INT(
+ fp_mul(INT_TO_FP(rms_noise_100hz_mg), sqrt_rate_ratio));
}
#endif
@@ -859,7 +848,7 @@ int bmi_set_accel_offset(const struct motion_sensor_t *accel, intv3_t v)
}
int bmi_set_gyro_offset(const struct motion_sensor_t *gyro, intv3_t v,
- int *val98_ptr)
+ int *val98_ptr)
{
int i, val, ret;
@@ -903,8 +892,7 @@ void motion_orientation_update(const struct motion_sensor_t *s)
}
#endif
-int bmi_list_activities(const struct motion_sensor_t *s,
- uint32_t *enabled,
+int bmi_list_activities(const struct motion_sensor_t *s, uint32_t *enabled,
uint32_t *disabled)
{
struct bmi_drv_data_t *data = BMI_GET_DATA(s);