mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-02 13:14:51 +00:00
Changed motion_sense task to assume sensors are unpowered in G3 and re-initialize sensors every time coming out of G3. Added EC command line test utils as well. Fixed some bug during unit tests. BUG=chrome-os-partner:27313,27320 BRANCH=ToT TEST=Verified on Samus. Tested with accel EC CLIs accelread, accelrange, accelrate, accelres Tested accelcalib, a ACCEL calibration util, and it succeeded. Tested sysfs interface: cd /sys/bus/iio/devices/iio:device1 cat in_accel_*_gyro_raw Signed-off-by: Sheng-Liang Song <ssl@chromium.org> Change-Id: I5752b00c03e1942c790ea4f28610fda83fa2dcbc Reviewed-on: https://chromium-review.googlesource.com/211484 Reviewed-by: Alec Berg <alecaberg@chromium.org>
99 lines
3.2 KiB
C
99 lines
3.2 KiB
C
/* 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
|
|
|
|
#include "motion_sense.h"
|
|
|
|
/* Header file for accelerometer / gyro drivers. */
|
|
|
|
/* Number of counts from accelerometer that represents 1G acceleration. */
|
|
#define ACCEL_G 1024
|
|
|
|
struct accelgyro_drv {
|
|
/**
|
|
* Initialize accelerometers.
|
|
* @s Pointer to sensor data pointer. Sensor data will be
|
|
* allocated on success.
|
|
* @return EC_SUCCESS if successful, non-zero if error.
|
|
*/
|
|
int (*init)(const struct motion_sensor_t *s);
|
|
|
|
/**
|
|
* 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.
|
|
* @s Pointer to sensor data.
|
|
* @x_acc Pointer to store X-axis acceleration (in counts).
|
|
* @y_acc Pointer to store Y-axis acceleration (in counts).
|
|
* @z_acc Pointer to store Z-axis acceleration (in counts).
|
|
* @return EC_SUCCESS if successful, non-zero if error.
|
|
*/
|
|
int (*read)(const struct motion_sensor_t *s,
|
|
int *x_acc,
|
|
int *y_acc,
|
|
int *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.
|
|
* @s Pointer to sensor data.
|
|
* @range Range (Units are +/- G's for accel, +/- deg/s for gyro)
|
|
* @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)(const struct motion_sensor_t *s,
|
|
int range,
|
|
int rnd);
|
|
int (*get_range)(const struct motion_sensor_t *s,
|
|
int *range);
|
|
|
|
/**
|
|
* Setter and getter methods for the sensor resolution.
|
|
* @s Pointer to sensor data.
|
|
* @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)(const struct motion_sensor_t *s,
|
|
int res,
|
|
int rnd);
|
|
int (*get_resolution)(const struct motion_sensor_t *s,
|
|
int *res);
|
|
|
|
/**
|
|
* Setter and getter methods for the sensor output data range. As the
|
|
* ODR increases, the LPF roll-off frequency also increases.
|
|
* @s Pointer to sensor data.
|
|
* @rate Output data rate (units are Hz)
|
|
* @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_data_rate)(const struct motion_sensor_t *s,
|
|
int rate,
|
|
int rnd);
|
|
int (*get_data_rate)(const struct motion_sensor_t *s,
|
|
int *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.
|
|
* @s Pointer to sensor data.
|
|
* @threshold Threshold for interrupt in units of counts.
|
|
*/
|
|
int (*set_interrupt)(const struct motion_sensor_t *s,
|
|
unsigned int threshold);
|
|
#endif
|
|
};
|
|
|
|
#endif /* __CROS_EC_ACCELGYRO_H */
|