diff options
-rw-r--r-- | board/volteer/sensors.c | 9 | ||||
-rw-r--r-- | driver/accel_bma2x2.c | 2 | ||||
-rw-r--r-- | driver/accel_bma2x2.h | 36 | ||||
-rw-r--r-- | driver/accelgyro_bmi260.c | 5 | ||||
-rw-r--r-- | driver/accelgyro_bmi260.h | 23 | ||||
-rw-r--r-- | driver/accelgyro_bmi_common.c | 6 | ||||
-rw-r--r-- | driver/accelgyro_bmi_common.h | 21 | ||||
-rw-r--r-- | driver/als_tcs3400.c | 2 | ||||
-rw-r--r-- | driver/als_tcs3400.h | 59 | ||||
-rw-r--r-- | include/driver/accel_bma2x2_public.h | 48 | ||||
-rw-r--r-- | include/driver/accelgyro_bmi260_public.h | 31 | ||||
-rw-r--r-- | include/driver/accelgyro_bmi_common_public.h | 32 | ||||
-rw-r--r-- | include/driver/als_tcs3400_public.h | 73 |
13 files changed, 202 insertions, 145 deletions
diff --git a/board/volteer/sensors.c b/board/volteer/sensors.c index 9e34812131..1bf5df3a06 100644 --- a/board/volteer/sensors.c +++ b/board/volteer/sensors.c @@ -6,11 +6,10 @@ /* Volteer family-specific sensor configuration */ #include "common.h" #include "accelgyro.h" -#include "driver/accel_bma2x2.h" -#include "driver/accelgyro_bmi_common.h" -#include "driver/accelgyro_bmi260.h" -#include "driver/als_tcs3400.h" -#include "driver/sync.h" +#include "driver/accel_bma2x2_public.h" +#include "driver/accelgyro_bmi_common_public.h" +#include "driver/accelgyro_bmi260_public.h" +#include "driver/als_tcs3400_public.h" #include "keyboard_scan.h" #include "hooks.h" #include "i2c.h" diff --git a/driver/accel_bma2x2.c b/driver/accel_bma2x2.c index 3b1cf72a8c..68f3251b06 100644 --- a/driver/accel_bma2x2.c +++ b/driver/accel_bma2x2.c @@ -12,7 +12,7 @@ #include "accelgyro.h" #include "common.h" #include "console.h" -#include "driver/accel_bma2x2.h" +#include "accel_bma2x2.h" #include "i2c.h" #include "math_util.h" #include "spi.h" diff --git a/driver/accel_bma2x2.h b/driver/accel_bma2x2.h index 67228ab35d..37f7bd2062 100644 --- a/driver/accel_bma2x2.h +++ b/driver/accel_bma2x2.h @@ -8,31 +8,7 @@ #ifndef __CROS_EC_ACCEL_BMA2x2_H #define __CROS_EC_ACCEL_BMA2x2_H -extern const struct accelgyro_drv bma2x2_accel_drv; - -/* I2C ADDRESS DEFINITIONS */ -/* The following definition of I2C address is used for the following sensors -* BMA253 -* BMA255 -* BMA355 -* BMA280 -* BMA282 -* BMA223 -* BMA254 -* BMA284 -* BMA250E -* BMA222E -*/ -#define BMA2x2_I2C_ADDR1_FLAGS 0x18 -#define BMA2x2_I2C_ADDR2_FLAGS 0x19 - -/* The following definition of I2C address is used for the following sensors -* BMC150 -* BMC056 -* BMC156 -*/ -#define BMA2x2_I2C_ADDR3_FLAGS 0x10 -#define BMA2x2_I2C_ADDR4_FLAGS 0x11 +#include "accel_bma2x2_public.h" /*** Chip-specific registers ***/ /* REGISTER ADDRESS DEFINITIONS */ @@ -161,14 +137,4 @@ extern const struct accelgyro_drv bma2x2_accel_drv; /* Sensor resolution in number of bits. This sensor has fixed resolution. */ #define BMA2x2_RESOLUTION 12 -/* - * Min and Max sampling frequency in mHz. - * Given BMA255 is polled, we limit max frequency to 125Hz. - * If set to 250Hz, given we can read up to 3ms before the due time - * (see CONFIG_MOTION_MIN_SENSE_WAIT_TIME), we may read too early when - * other sensors are active. - */ -#define BMA255_ACCEL_MIN_FREQ 7810 -#define BMA255_ACCEL_MAX_FREQ \ - MOTION_MAX_SENSOR_FREQUENCY(125000, 15625) #endif /* __CROS_EC_ACCEL_BMA2x2_H */ diff --git a/driver/accelgyro_bmi260.c b/driver/accelgyro_bmi260.c index f0c9f3e9db..faac2f75a5 100644 --- a/driver/accelgyro_bmi260.c +++ b/driver/accelgyro_bmi260.c @@ -10,9 +10,8 @@ #include "accelgyro.h" #include "console.h" -#include "driver/accelgyro_bmi_common.h" -#include "driver/accelgyro_bmi260.h" -#include "endian.h" +#include "accelgyro_bmi_common.h" +#include "accelgyro_bmi260.h" #include "hwtimer.h" #include "i2c.h" #include "init_rom.h" diff --git a/driver/accelgyro_bmi260.h b/driver/accelgyro_bmi260.h index 9c7edc0766..9f39dd568a 100644 --- a/driver/accelgyro_bmi260.h +++ b/driver/accelgyro_bmi260.h @@ -10,19 +10,8 @@ #include "accelgyro.h" #include "common.h" -#include "driver/mag_bmm150.h" - -/* - * The addr field of motion_sensor support both SPI and I2C: - * This is defined in include/i2c.h and is no longer an 8bit - * address. The 7/10 bit address starts at bit 0 and leaves - * room for a 10 bit address, although we don't currently - * have any 10 bit slaves. I2C or SPI is indicated by a - * more significant bit - */ - -/* I2C addresses */ -#define BMI260_ADDR0_FLAGS 0x68 +#include "mag_bmm150.h" +#include "driver/accelgyro_bmi260_public.h" #define BMI260_CHIP_ID 0x00 #define BMI260_CHIP_ID_MAJOR 0x27 @@ -332,12 +321,4 @@ /* Root mean square noise of 100Hz accelerometer, units: ug */ #define BMI260_ACCEL_RMS_NOISE_100HZ 1060 -extern const struct accelgyro_drv bmi260_drv; - -void bmi260_interrupt(enum gpio_signal signal); - -#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL -extern struct i2c_stress_test_dev bmi260_i2c_stress_test_dev; -#endif - #endif /* __CROS_EC_ACCELGYRO_BMI260_H */ diff --git a/driver/accelgyro_bmi_common.c b/driver/accelgyro_bmi_common.c index 9be2fe2bad..b23e4521f5 100644 --- a/driver/accelgyro_bmi_common.c +++ b/driver/accelgyro_bmi_common.c @@ -11,9 +11,9 @@ #include "accelgyro.h" #include "console.h" -#include "driver/accelgyro_bmi_common.h" -#include "driver/mag_bmm150.h" -#include "driver/mag_lis2mdl.h" +#include "accelgyro_bmi_common.h" +#include "mag_bmm150.h" +#include "mag_lis2mdl.h" #include "i2c.h" #include "math_util.h" #include "motion_sense_fifo.h" diff --git a/driver/accelgyro_bmi_common.h b/driver/accelgyro_bmi_common.h index d7906b68ee..95294f8539 100644 --- a/driver/accelgyro_bmi_common.h +++ b/driver/accelgyro_bmi_common.h @@ -8,9 +8,10 @@ #define __CROS_EC_ACCELGYRO_BMI_COMMON_H #include "accelgyro.h" -#include "driver/accelgyro_bmi160.h" -#include "driver/accelgyro_bmi260.h" +#include "accelgyro_bmi160.h" +#include "accelgyro_bmi260.h" #include "mag_bmm150.h" +#include "accelgyro_bmi_common_public.h" #define BMI_CONF_REG(_sensor) (0x40 + 2 * (_sensor)) #define BMI_RANGE_REG(_sensor) (0x41 + 2 * (_sensor)) @@ -63,22 +64,6 @@ enum bmi_running_mode { #define BMI_FIFO_FLAG_OFFSET 4 #define BMI_FIFO_ALL_MASK 7 -struct bmi_drv_data_t { - struct accelgyro_saved_data_t saved_data[3]; - uint8_t flags; - uint8_t enabled_activities; - uint8_t disabled_activities; -#ifdef CONFIG_MAG_BMI_BMM150 - struct bmm150_private_data compass; -#endif -#ifdef CONFIG_BMI_ORIENTATION_SENSOR - uint8_t raw_orientation; - enum motionsensor_orientation orientation; - enum motionsensor_orientation last_orientation; -#endif - -}; - #define BMI_GET_DATA(_s) \ ((struct bmi_drv_data_t *)(_s)->drv_data) #define BMI_GET_SAVED_DATA(_s) \ diff --git a/driver/als_tcs3400.c b/driver/als_tcs3400.c index 2639e9c7bd..fa4a665df9 100644 --- a/driver/als_tcs3400.c +++ b/driver/als_tcs3400.c @@ -7,7 +7,7 @@ #include "accelgyro.h" #include "common.h" #include "console.h" -#include "driver/als_tcs3400.h" +#include "als_tcs3400.h" #include "hooks.h" #include "hwtimer.h" #include "i2c.h" diff --git a/driver/als_tcs3400.h b/driver/als_tcs3400.h index 892b4881fd..0078b90442 100644 --- a/driver/als_tcs3400.h +++ b/driver/als_tcs3400.h @@ -8,8 +8,7 @@ #ifndef __CROS_EC_ALS_TCS3400_H #define __CROS_EC_ALS_TCS3400_H -/* I2C Interface */ -#define TCS3400_I2C_ADDR_FLAGS 0x39 +#include "driver/als_tcs3400_public.h" /* ID for TCS34001 and TCS34005 */ #define TCS340015_DEVICE_ID 0x90 @@ -77,39 +76,10 @@ enum tcs3400_mode { #define TCS_CLEAR_DATA_SIZE 2 #define TCS_RGBC_DATA_SIZE 8 -/* Min and Max sampling frequency in mHz */ -#define TCS3400_LIGHT_MIN_FREQ 149 -#define TCS3400_LIGHT_MAX_FREQ 1000 -#if (CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ <= TCS3400_LIGHT_MAX_FREQ) -#error "EC too slow for light sensor" -#endif - #define TCS3400_DRV_DATA(_s) ((struct als_drv_data_t *)(_s)->drv_data) #define TCS3400_RGB_DRV_DATA(_s) \ ((struct tcs3400_rgb_drv_data_t *)(_s)->drv_data) -/* NOTE: The higher the ATIME value in reg, the shorter the accumulation time */ -#define TCS_MIN_ATIME 0x00 /* 712 ms */ -#define TCS_MAX_ATIME 0x70 /* 400 ms */ -#define TCS_ATIME_GRANULARITY 256 /* 256 atime settings */ -#define TCS_SATURATION_LEVEL 0xffff /* for 0 < atime < 0x70 */ -#define TCS_DEFAULT_ATIME TCS_MIN_ATIME /* 712 ms */ -#define TCS_CALIBRATION_ATIME TCS_MIN_ATIME -#define TCS_GAIN_UPSHIFT_ATIME TCS_MAX_ATIME - -/* Number of different ranges supported for atime adjustment support */ -#define TCS_MAX_ATIME_RANGES 13 -#define TCS_GAIN_TABLE_MAX_LUX 12999 -#define TCS_ATIME_GAIN_FACTOR 100 /* table values are 100x actual value */ - -#define TCS_MIN_AGAIN 0x00 /* 1x gain */ -#define TCS_MAX_AGAIN 0x03 /* 64x gain */ -#define TCS_CALIBRATION_AGAIN 0x02 /* 16x gain */ -#define TCS_DEFAULT_AGAIN TCS_CALIBRATION_AGAIN - -#define TCS_ATIME_DEC_STEP 5 -#define TCS_ATIME_INC_STEP TCS_GAIN_UPSHIFT_ATIME - /* * Factor to multiply light value by to determine if an increase in gain * would cause the next value to saturate. @@ -149,31 +119,4 @@ enum crbg_index { CRGB_COUNT, }; -/* saturation auto-adjustment */ -struct tcs_saturation_t { - /* - * Gain Scaling; must be value between 0 and 3 - * 0 - 1x scaling - * 1 - 4x scaling - * 2 - 16x scaling - * 3 - 64x scaling - */ - uint8_t again; - - /* Acquisition Time, controlled by the ATIME register */ - uint8_t atime; /* ATIME register setting */ -}; - -/* tcs3400 rgb als driver data */ -struct tcs3400_rgb_drv_data_t { - uint8_t calibration_mode;/* 0 = normal run mode, 1 = calibration mode */ - - struct rgb_calibration_t calibration; - struct tcs_saturation_t saturation; /* saturation adjustment */ -}; - -extern const struct accelgyro_drv tcs3400_drv; -extern const struct accelgyro_drv tcs3400_rgb_drv; - -void tcs3400_interrupt(enum gpio_signal signal); #endif /* __CROS_EC_ALS_TCS3400_H */ diff --git a/include/driver/accel_bma2x2_public.h b/include/driver/accel_bma2x2_public.h new file mode 100644 index 0000000000..6b3d366270 --- /dev/null +++ b/include/driver/accel_bma2x2_public.h @@ -0,0 +1,48 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* BMA2x2 gsensor module for Chrome EC */ + +#ifndef __CROS_EC_DRIVER_ACCEL_BMA2x2_PUBLIC_H +#define __CROS_EC_DRIVER_ACCEL_BMA2x2_PUBLIC_H + +extern const struct accelgyro_drv bma2x2_accel_drv; + +/* I2C ADDRESS DEFINITIONS */ +/* The following definition of I2C address is used for the following sensors +* BMA253 +* BMA255 +* BMA355 +* BMA280 +* BMA282 +* BMA223 +* BMA254 +* BMA284 +* BMA250E +* BMA222E +*/ +#define BMA2x2_I2C_ADDR1_FLAGS 0x18 +#define BMA2x2_I2C_ADDR2_FLAGS 0x19 + +/* The following definition of I2C address is used for the following sensors +* BMC150 +* BMC056 +* BMC156 +*/ +#define BMA2x2_I2C_ADDR3_FLAGS 0x10 +#define BMA2x2_I2C_ADDR4_FLAGS 0x11 + +/* + * Min and Max sampling frequency in mHz. + * Given BMA255 is polled, we limit max frequency to 125Hz. + * If set to 250Hz, given we can read up to 3ms before the due time + * (see CONFIG_MOTION_MIN_SENSE_WAIT_TIME), we may read too early when + * other sensors are active. + */ +#define BMA255_ACCEL_MIN_FREQ 7810 +#define BMA255_ACCEL_MAX_FREQ \ + MOTION_MAX_SENSOR_FREQUENCY(125000, 15625) + +#endif /* CROS_EC_DRIVER_ACCEL_BMA2x2_PUBLIC_H */ diff --git a/include/driver/accelgyro_bmi260_public.h b/include/driver/accelgyro_bmi260_public.h new file mode 100644 index 0000000000..fa616d4a41 --- /dev/null +++ b/include/driver/accelgyro_bmi260_public.h @@ -0,0 +1,31 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* BMI260 accelerometer and gyro for Chrome EC */ + +#ifndef __CROS_EC_DRIVER_ACCELGYRO_BMI260_PUBLIC_H +#define __CROS_EC_DRIVER_ACCELGYRO_BMI260_PUBLIC_H + +/* + * The addr field of motion_sensor support both SPI and I2C: + * This is defined in include/i2c.h and is no longer an 8bit + * address. The 7/10 bit address starts at bit 0 and leaves + * room for a 10 bit address, although we don't currently + * have any 10 bit slaves. I2C or SPI is indicated by a + * more significant bit + */ + +/* I2C addresses */ +#define BMI260_ADDR0_FLAGS 0x68 + +extern const struct accelgyro_drv bmi260_drv; + +void bmi260_interrupt(enum gpio_signal signal); + +#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL +extern struct i2c_stress_test_dev bmi260_i2c_stress_test_dev; +#endif + +#endif /* __CROS_EC_DRIVER_ACCELGYRO_BMI260_PUBLIC_H */ diff --git a/include/driver/accelgyro_bmi_common_public.h b/include/driver/accelgyro_bmi_common_public.h new file mode 100644 index 0000000000..52814c71bf --- /dev/null +++ b/include/driver/accelgyro_bmi_common_public.h @@ -0,0 +1,32 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +/* BMI accelerometer and gyro common definitions for Chrome EC */ + +#ifndef __CROS_EC_DRIVER_ACCELGYRO_BMI_COMMON_PUBLIC_H +#define __CROS_EC_DRIVER_ACCELGYRO_BMI_COMMON_PUBLIC_H + +/* Min and Max sampling frequency in mHz */ +#define BMI_ACCEL_MIN_FREQ 12500 +#define BMI_ACCEL_MAX_FREQ MOTION_MAX_SENSOR_FREQUENCY(1600000, 100000) +#define BMI_GYRO_MIN_FREQ 25000 +#define BMI_GYRO_MAX_FREQ MOTION_MAX_SENSOR_FREQUENCY(3200000, 100000) + +struct bmi_drv_data_t { + struct accelgyro_saved_data_t saved_data[3]; + uint8_t flags; + uint8_t enabled_activities; + uint8_t disabled_activities; +#ifdef CONFIG_MAG_BMI_BMM150 + struct bmm150_private_data compass; +#endif +#ifdef CONFIG_BMI_ORIENTATION_SENSOR + uint8_t raw_orientation; + enum motionsensor_orientation orientation; + enum motionsensor_orientation last_orientation; +#endif + +}; + +#endif /* __CROS_EC_DRIVER_ACCELGYRO_BMI_COMMON_PUBLIC_H */ diff --git a/include/driver/als_tcs3400_public.h b/include/driver/als_tcs3400_public.h new file mode 100644 index 0000000000..9a9225bfc6 --- /dev/null +++ b/include/driver/als_tcs3400_public.h @@ -0,0 +1,73 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * AMS TCS3400 light sensor driver + */ + +#ifndef __CROS_EC_DRIVER_ALS_TCS3400_PUBLIC_H +#define __CROS_EC_DRIVER_ALS_TCS3400_PUBLIC_H + +#include "accelgyro.h" + +/* I2C Interface */ +#define TCS3400_I2C_ADDR_FLAGS 0x39 + +/* NOTE: The higher the ATIME value in reg, the shorter the accumulation time */ +#define TCS_MIN_ATIME 0x00 /* 712 ms */ +#define TCS_MAX_ATIME 0x70 /* 400 ms */ +#define TCS_ATIME_GRANULARITY 256 /* 256 atime settings */ +#define TCS_SATURATION_LEVEL 0xffff /* for 0 < atime < 0x70 */ +#define TCS_DEFAULT_ATIME TCS_MIN_ATIME /* 712 ms */ +#define TCS_CALIBRATION_ATIME TCS_MIN_ATIME +#define TCS_GAIN_UPSHIFT_ATIME TCS_MAX_ATIME + +/* Number of different ranges supported for atime adjustment support */ +#define TCS_MAX_ATIME_RANGES 13 +#define TCS_GAIN_TABLE_MAX_LUX 12999 +#define TCS_ATIME_GAIN_FACTOR 100 /* table values are 100x actual value */ + +#define TCS_MIN_AGAIN 0x00 /* 1x gain */ +#define TCS_MAX_AGAIN 0x03 /* 64x gain */ +#define TCS_CALIBRATION_AGAIN 0x02 /* 16x gain */ +#define TCS_DEFAULT_AGAIN TCS_CALIBRATION_AGAIN + +#define TCS_ATIME_DEC_STEP 5 +#define TCS_ATIME_INC_STEP TCS_GAIN_UPSHIFT_ATIME + +/* Min and Max sampling frequency in mHz */ +#define TCS3400_LIGHT_MIN_FREQ 149 +#define TCS3400_LIGHT_MAX_FREQ 1000 +#if (CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ <= TCS3400_LIGHT_MAX_FREQ) +#error "EC too slow for light sensor" +#endif + +/* saturation auto-adjustment */ +struct tcs_saturation_t { + /* + * Gain Scaling; must be value between 0 and 3 + * 0 - 1x scaling + * 1 - 4x scaling + * 2 - 16x scaling + * 3 - 64x scaling + */ + uint8_t again; + + /* Acquisition Time, controlled by the ATIME register */ + uint8_t atime; /* ATIME register setting */ +}; + +/* tcs3400 rgb als driver data */ +struct tcs3400_rgb_drv_data_t { + uint8_t calibration_mode;/* 0 = normal run mode, 1 = calibration mode */ + + struct rgb_calibration_t calibration; + struct tcs_saturation_t saturation; /* saturation adjustment */ +}; + +extern const struct accelgyro_drv tcs3400_drv; +extern const struct accelgyro_drv tcs3400_rgb_drv; + +void tcs3400_interrupt(enum gpio_signal signal); + +#endif /* __CROS_EC_DRIVER_ALS_TCS3400_PUBLIC_H */ |