summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2014-07-31 13:44:30 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-19 06:59:28 +0000
commita048d76e0df9244e2deb104201e14afc80e0864c (patch)
tree236a1dbd34def4b73ced8957c27a450531d98af2 /include
parentbe060242e310090a421f70caa5917e2808f26433 (diff)
downloadchrome-ec-a048d76e0df9244e2deb104201e14afc80e0864c.tar.gz
Refactor accel / gyro driver to accomodate various configurations
Previously our accel / gyro drivers assumed that we had exactly two of each identical part in the system. Some systems may have different configurations, so allow this to be specified at the board-level. Note that our motion_sense algorithm currently assumes that we have one accelerometer in the lid and one in the base -- we'll need to fix that in another CL. BUG=chrome-os-partner:27320 TEST=Compile-only. Tested in future Samus commit. BRANCH=None. Change-Id: I1fae1f6c578fedebe78b473a5d66a5794ccaae00 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/212321 Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/accelerometer.h87
-rw-r--r--include/accelgyro.h111
-rw-r--r--include/ec_commands.h1
-rw-r--r--include/motion_sense.h16
4 files changed, 128 insertions, 87 deletions
diff --git a/include/accelerometer.h b/include/accelerometer.h
deleted file mode 100644
index 0c8703f3ae..0000000000
--- a/include/accelerometer.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/* Copyright (c) 2014 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.
- */
-
-#ifndef __CROS_EC_ACCELEROMETER_H
-#define __CROS_EC_ACCELEROMETER_H
-
-/* Header file for accelerometer drivers. */
-
-/* This array must be defined in board.c. */
-extern const int accel_addr[];
-
-/* This enum must be defined in board.h. */
-enum accel_id;
-
-/* Number of counts from accelerometer that represents 1G acceleration. */
-#define ACCEL_G 1024
-
-/**
- * Read all three accelerations of an accelerometer. Note that all three
- * accelerations come back in counts, where ACCEL_G can be used to convert
- * counts to engineering units.
- *
- * @param id Target accelerometer
- * @param x_acc Pointer to store X-axis acceleration (in counts).
- * @param y_acc Pointer to store Y-axis acceleration (in counts).
- * @param z_acc Pointer to store Z-axis acceleration (in counts).
- *
- * @return EC_SUCCESS if successful, non-zero if error.
- */
-int accel_read(const enum accel_id id, int * const x_acc, int * const y_acc,
- int * const z_acc);
-
-/**
- * Initialize accelerometers.
- *
- * @param id Target accelerometer
- *
- * @return EC_SUCCESS if successful, non-zero if error.
- */
-int accel_init(const enum accel_id id);
-
-/**
- * Setter and getter methods for the sensor range. The sensor range defines
- * the maximum value that can be returned from accel_read(). As the range
- * increases, the resolution gets worse.
- *
- * @param id Target accelerometer
- * @param range Range (Units are +/- G's for accel, +/- deg/s for gyro)
- * @param rnd Rounding flag. If true, it rounds up to nearest valid value.
- * Otherwise, it rounds down.
- *
- * @return EC_SUCCESS if successful, non-zero if error.
- */
-int accel_set_range(const enum accel_id id, const int range, const int rnd);
-int accel_get_range(const enum accel_id id, int * const range);
-
-
-/**
- * Setter and getter methods for the sensor resolution.
- *
- * @param id Target accelerometer
- * @param range Resolution (Units are number of bits)
- * param rnd Rounding flag. If true, it rounds up to nearest valid value.
- * Otherwise, it rounds down.
- *
- * @return EC_SUCCESS if successful, non-zero if error.
- */
-int accel_set_resolution(const enum accel_id id, const int res, const int rnd);
-int accel_get_resolution(const enum accel_id id, int * const res);
-
-/**
- * Setter and getter methods for the sensor output data range. As the ODR
- * increases, the LPF roll-off frequency also increases.
- *
- * @param id Target accelerometer
- * @param rate Output data rate (units are mHz)
- * @param rnd Rounding flag. If true, it rounds up to nearest valid value.
- * Otherwise, it rounds down.
- *
- * @return EC_SUCCESS if successful, non-zero if error.
- */
-int accel_set_datarate(const enum accel_id id, const int rate, const int rnd);
-int accel_get_datarate(const enum accel_id id, int * const rate);
-
-#endif /* __CROS_EC_ACCELEROMETER_H */
diff --git a/include/accelgyro.h b/include/accelgyro.h
new file mode 100644
index 0000000000..2a4a458cfa
--- /dev/null
+++ b/include/accelgyro.h
@@ -0,0 +1,111 @@
+/* Copyright (c) 2014 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.
+ */
+
+#ifndef __CROS_EC_ACCELGYRO_H
+#define __CROS_EC_ACCELGYRO_H
+
+/* Header file for accelerometer / gyro drivers. */
+
+/* Number of counts from accelerometer that represents 1G acceleration. */
+#define ACCEL_G 1024
+
+enum accelgyro_chip_t {
+ CHIP_TEST,
+ CHIP_KXCJ9,
+ CHIP_LSM6DS0,
+};
+
+enum accelgyro_sensor_t {
+ SENSOR_ACCELEROMETER,
+ SENSOR_GYRO,
+};
+
+struct accelgyro_info {
+ enum accelgyro_chip_t chip_type;
+ enum accelgyro_sensor_t sensor_type;
+
+ /**
+ * Initialize accelerometers.
+ * @param drv_data Pointer to sensor data.
+ * @i2c_addr i2c slave device address
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+ int (*init)(void *drv_data,
+ int i2c_addr);
+
+ /**
+ * Read all three accelerations of an accelerometer. Note that all
+ * three accelerations come back in counts, where ACCEL_G can be used
+ * to convert counts to engineering units.
+ * @param drv_data Pointer to sensor data.
+ * @param x_acc Pointer to store X-axis acceleration (in counts).
+ * @param y_acc Pointer to store Y-axis acceleration (in counts).
+ * @param z_acc Pointer to store Z-axis acceleration (in counts).
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+ int (*read)(void *drv_data,
+ int * const x_acc,
+ int * const y_acc,
+ int * const z_acc);
+
+ /**
+ * Setter and getter methods for the sensor range. The sensor range
+ * defines the maximum value that can be returned from read(). As the
+ * range increases, the resolution gets worse.
+ * @param drv_data Pointer to sensor data.
+ * @param range Range (Units are +/- G's for accel, +/- deg/s for gyro)
+ * @param rnd Rounding flag. If true, it rounds up to nearest valid
+ * value. Otherwise, it rounds down.
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+ int (*set_range)(void *drv_data,
+ const int range,
+ const int rnd);
+ int (*get_range)(void *drv_data,
+ int * const range);
+
+ /**
+ * Setter and getter methods for the sensor resolution.
+ * @param drv_data Pointer to sensor data.
+ * @param range Resolution (Units are number of bits)
+ * param rnd Rounding flag. If true, it rounds up to nearest valid
+ * value. Otherwise, it rounds down.
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+ int (*set_resolution)(void *drv_data,
+ const int res,
+ const int rnd);
+ int (*get_resolution)(void *drv_data,
+ int * const res);
+
+ /**
+ * Setter and getter methods for the sensor output data range. As the
+ * ODR increases, the LPF roll-off frequency also increases.
+ * @param drv_data Pointer to sensor data.
+ * @param rate Output data rate (units are mHz)
+ * @param rnd Rounding flag. If true, it rounds up to nearest valid
+ * value. Otherwise, it rounds down.
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+ int (*set_datarate)(void *drv_data,
+ const int rate,
+ const int rnd);
+ int (*get_datarate)(void *drv_data,
+ int * const rate);
+
+#ifdef CONFIG_ACCEL_INTERRUPTS
+ /**
+ * Setup a one-time accel interrupt. If the threshold is low enough, the
+ * interrupt may trigger due simply to noise and not any real motion.
+ * If the threshold is 0, the interrupt will fire immediately.
+ * @param drv_data Pointer to sensor data.
+ * @param threshold Threshold for interrupt in units of counts.
+ */
+ int (*set_interrupt)(void *drv_data,
+ unsigned int threshold);
+#endif
+};
+
+#endif /* __CROS_EC_ACCELGYRO_H */
diff --git a/include/ec_commands.h b/include/ec_commands.h
index d5d5590269..a8c9ab450b 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1300,6 +1300,7 @@ enum motionsensor_location {
/* List of motion sensor chips. */
enum motionsensor_chip {
MOTIONSENSE_CHIP_KXCJ9 = 0,
+ MOTIONSENSE_CHIP_LSM6DS0 = 1,
};
/* Module flag masks used for the dump sub-command. */
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 3a3b9b5121..0319514fd7 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -92,5 +92,21 @@ void accel_int_lid(enum gpio_signal signal);
*/
void accel_int_base(enum gpio_signal signal);
+enum sensor_location_t {
+ LOCATION_BASE,
+ LOCATION_LID,
+};
+
+struct motion_sensor_t {
+ char *name;
+ enum sensor_location_t location;
+ const struct accelgyro_info *drv;
+ void *drv_data;
+ uint8_t i2c_addr;
+};
+
+/* Defined at board level. */
+extern const struct motion_sensor_t motion_sensors[];
+extern const unsigned int motion_sensor_count;
#endif /* __CROS_EC_MOTION_SENSE_H */