summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com>2021-01-19 09:24:34 -0800
committerCommit Bot <commit-bot@chromium.org>2021-10-12 15:10:54 +0000
commit9fd1f538da4f33dde6ec923b5bf52daac9148091 (patch)
treece01cf2ae858ce011d05dad90208e32e9347f34e
parent5538f961c1c9146c93ed7b3da0fe6447202090dc (diff)
downloadchrome-ec-9fd1f538da4f33dde6ec923b5bf52daac9148091.tar.gz
Zephyr: Create public headers for bmi260, bma2x2, and tcs3400
Separate out the public part of sensor headers so it can be included from Zephyr. BUG=b:175434113 BRANCH=none TEST=make buildall -j8 build volteer on zephyr Conflicts: board/volteer/sensors.c: sensors are not enabled in branch driver/accel_bma2x2.h: waddledoo add BMA253 sensor support driver/accelgyro_bmi_common.h: Makefile include path does not include include/driver Signed-off-by: Hyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com> Change-Id: I899e9aea99d6c7d56a1b6735538b280fe0735313 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2637251 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> (cherry picked from commit 6a87ebfedddef0a3d0438bcbb894e45dc16fe1e1) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3214012 Commit-Queue: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org> Auto-Submit: Rong Chang <rongchang@chromium.org>
-rw-r--r--driver/accel_bma2x2.c2
-rw-r--r--driver/accel_bma2x2.h35
-rw-r--r--driver/accelgyro_bmi260.c5
-rw-r--r--driver/accelgyro_bmi260.h23
-rw-r--r--driver/accelgyro_bmi_common.c6
-rw-r--r--driver/accelgyro_bmi_common.h21
-rw-r--r--driver/als_tcs3400.c2
-rw-r--r--driver/als_tcs3400.h59
-rw-r--r--include/driver/accel_bma2x2_public.h48
-rw-r--r--include/driver/accelgyro_bmi260_public.h31
-rw-r--r--include/driver/accelgyro_bmi_common_public.h32
-rw-r--r--include/driver/als_tcs3400_public.h73
12 files changed, 198 insertions, 139 deletions
diff --git a/driver/accel_bma2x2.c b/driver/accel_bma2x2.c
index 9a63bdc1ba..4c1a93879b 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 ef5eafe0f8..990de18c01 100644
--- a/driver/accel_bma2x2.h
+++ b/driver/accel_bma2x2.h
@@ -8,30 +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
-* 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 "driver/accel_bma2x2_public.h"
/*** Chip-specific registers ***/
/* REGISTER ADDRESS DEFINITIONS */
@@ -158,14 +135,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 d7264d4512..c721693e9e 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 4358e657fe..7864b786ce 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
@@ -330,12 +319,4 @@
#define BMI260_FF_DATA_LEN_MAG 8
-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 b031d1a1a7..e61fcfd16d 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 9f082e85f1..2282dfebd6 100644
--- a/driver/accelgyro_bmi_common.h
+++ b/driver/accelgyro_bmi_common.h
@@ -8,8 +8,9 @@
#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 "driver/accelgyro_bmi_common_public.h"
#include "mag_bmm150.h"
#define BMI_CONF_REG(_sensor) (0x40 + 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 6b7f063257..f1d9965d96 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 */