diff options
author | David Huang <david.huang@quanta.corp-partner.google.com> | 2021-01-08 11:47:41 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-08 17:17:00 +0000 |
commit | e7a9c9152444bc8dc62055ad6baafddbd97a8017 (patch) | |
tree | ac38381d587b564560da4d8a413c8c27f11a30f3 | |
parent | f1247196214779049b6bdcc849023fa102114ed2 (diff) | |
download | chrome-ec-e7a9c9152444bc8dc62055ad6baafddbd97a8017.tar.gz |
driver: Add/modify function and variable to fix build error
Add function and variable to fix icm426xx build error.
BUG=none
BRANCH=nami
TEST=make buildall -j success.
Signed-off-by: David Huang <david.huang@quanta.corp-partner.google.com>
Change-Id: I9e8f3f581d917dc79cdf8e4c7b9794e398096253
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2617321
Reviewed-by: YH Lin <yueherngl@chromium.org>
Commit-Queue: YH Lin <yueherngl@chromium.org>
-rw-r--r-- | common/math_util.c | 8 | ||||
-rw-r--r-- | driver/accelgyro_icm426xx.c | 14 | ||||
-rw-r--r-- | driver/accelgyro_icm426xx.h | 4 | ||||
-rw-r--r-- | include/accelgyro.h | 15 | ||||
-rw-r--r-- | include/common.h | 11 | ||||
-rw-r--r-- | include/ec_commands.h | 3 | ||||
-rw-r--r-- | include/math_util.h | 5 |
7 files changed, 51 insertions, 9 deletions
diff --git a/common/math_util.c b/common/math_util.c index 6a49dc31c3..93207d7ecf 100644 --- a/common/math_util.c +++ b/common/math_util.c @@ -253,3 +253,11 @@ void rotate_inv(const vector_3_t v, const matrix_3x3_t R, vector_3_t res) res[1] = FP_TO_INT(fp_div(t[1], deter)); res[2] = FP_TO_INT(fp_div(t[2], deter)); } + +/* division that round to the nearest integer */ +int round_divide(int64_t dividend, int divisor) +{ + return (dividend > 0) ^ (divisor > 0) ? + (dividend - divisor / 2) / divisor : + (dividend + divisor / 2) / divisor; +} diff --git a/driver/accelgyro_icm426xx.c b/driver/accelgyro_icm426xx.c index ef4859d548..efca0c009e 100644 --- a/driver/accelgyro_icm426xx.c +++ b/driver/accelgyro_icm426xx.c @@ -29,7 +29,7 @@ volatile uint32_t last_interrupt_timestamp; #endif -static int icm426xx_normalize(const struct motion_sensor_t *s, intv3_t v, +static int icm426xx_normalize(const struct motion_sensor_t *s, vector_3_t v, const uint8_t *raw) { struct accelgyro_saved_data_t *data = ICM_GET_SAVED_DATA(s); @@ -166,7 +166,7 @@ out_unlock: static void __maybe_unused icm426xx_push_fifo_data(struct motion_sensor_t *s, const uint8_t *raw, uint32_t ts) { - intv3_t v; + vector_3_t v; struct ec_response_motion_sensor_data vect; int ret; @@ -510,7 +510,7 @@ static int icm426xx_set_range(const struct motion_sensor_t *s, int range, } static int icm426xx_get_hw_offset(const struct motion_sensor_t *s, - intv3_t offset) + vector_3_t offset) { uint8_t raw[5]; int i, ret; @@ -564,7 +564,7 @@ static int icm426xx_get_hw_offset(const struct motion_sensor_t *s, } static int icm426xx_set_hw_offset(const struct motion_sensor_t *s, - intv3_t offset) + vector_3_t offset) { int i, val, ret; @@ -661,7 +661,7 @@ static int icm426xx_set_offset(const struct motion_sensor_t *s, const int16_t *offset, int16_t temp) { struct accelgyro_saved_data_t *data = ICM_GET_SAVED_DATA(s); - intv3_t v = { offset[X], offset[Y], offset[Z] }; + vector_3_t v = { offset[X], offset[Y], offset[Z] }; int range, div1, div2; int i; @@ -696,7 +696,7 @@ static int icm426xx_get_offset(const struct motion_sensor_t *s, int16_t *offset, int16_t *temp) { struct accelgyro_saved_data_t *data = ICM_GET_SAVED_DATA(s); - intv3_t v; + vector_3_t v; int range, div1, div2; int i, ret; @@ -734,7 +734,7 @@ static int icm426xx_get_offset(const struct motion_sensor_t *s, int16_t *offset, return EC_SUCCESS; } -static int icm426xx_read(const struct motion_sensor_t *s, intv3_t v) +static int icm426xx_read(const struct motion_sensor_t *s, vector_3_t v) { uint8_t raw[6]; int reg, ret; diff --git a/driver/accelgyro_icm426xx.h b/driver/accelgyro_icm426xx.h index f3a42414a6..22dff9bceb 100644 --- a/driver/accelgyro_icm426xx.h +++ b/driver/accelgyro_icm426xx.h @@ -20,9 +20,9 @@ /* Min and Max sampling frequency in mHz */ #define ICM426XX_ACCEL_MIN_FREQ 3125 -#define ICM426XX_ACCEL_MAX_FREQ MOTION_MAX_SENSOR_FREQUENCY(500000, 100000) +#define ICM426XX_ACCEL_MAX_FREQ 500000 #define ICM426XX_GYRO_MIN_FREQ 12500 -#define ICM426XX_GYRO_MAX_FREQ MOTION_MAX_SENSOR_FREQUENCY(4000000, 100000) +#define ICM426XX_GYRO_MAX_FREQ 4000000 /* Min and Max Accel FS in G */ #define ICM426XX_ACCEL_FS_MIN_VAL 2 diff --git a/include/accelgyro.h b/include/accelgyro.h index 4b11e0ea2b..5ab8fde664 100644 --- a/include/accelgyro.h +++ b/include/accelgyro.h @@ -88,6 +88,20 @@ struct accelgyro_drv { int (*get_offset)(const struct motion_sensor_t *s, int16_t *offset, int16_t *temp); + /** + * Setter and getter methods for the sensor scale. + * @s Pointer to sensor data. + * @scale: scale to apply to raw data. + * @temp: temperature when calibration was done. + * @return EC_SUCCESS if successful, non-zero if error. + */ + int (*set_scale)(const struct motion_sensor_t *s, + const uint16_t *scale, + int16_t temp); + int (*get_scale)(const struct motion_sensor_t *s, + uint16_t *scale, + int16_t *temp); + int (*perform_calib)(const struct motion_sensor_t *s); #ifdef CONFIG_ACCEL_INTERRUPTS /** @@ -131,6 +145,7 @@ struct accelgyro_drv { struct accelgyro_saved_data_t { int odr; int range; + uint16_t scale[3]; }; #define SENSOR_APPLY_DIV_SCALE(_input, _scale) \ diff --git a/include/common.h b/include/common.h index 657a86e26e..ca0ac79128 100644 --- a/include/common.h +++ b/include/common.h @@ -66,6 +66,17 @@ #endif /* + * __maybe_unused is equivalent to the Linux kernel definition, so we + * can follow the Kernel style guide more closely. + * + * An example use case is a function which is only used under certain + * CONFIG options. + */ +#ifndef __maybe_unused +#define __maybe_unused __attribute__((unused)) +#endif + +/* * externally_visible is required by GCC to avoid kicking out memset. */ #ifndef __visible diff --git a/include/ec_commands.h b/include/ec_commands.h index 0ac13fe7ca..9e09fd77f9 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -2406,6 +2406,9 @@ struct __ec_todo_unpacked ec_motion_sense_activity { /* Set Calibration information */ #define MOTION_SENSE_SET_OFFSET 1 +/* Default Scale value, factor 1. */ +#define MOTION_SENSE_DEFAULT_SCALE (1<<15) + #define LID_ANGLE_UNRELIABLE 500 enum motionsense_spoof_mode { diff --git a/include/math_util.h b/include/math_util.h index 385c044c6f..46981af05f 100644 --- a/include/math_util.h +++ b/include/math_util.h @@ -150,4 +150,9 @@ void rotate(const vector_3_t v, const matrix_3x3_t R, vector_3_t res); */ void rotate_inv(const vector_3_t v, const matrix_3x3_t R, vector_3_t res); +/** + * Divide dividend by divisor and round it to the nearest integer. + */ +int round_divide(int64_t dividend, int divisor); + #endif /* __CROS_EC_MATH_UTIL_H */ |