mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-31 11:01:19 +00:00
Design Goals: 1. Every time the AP boots, the same default sensor settings are configured. 2. If the AP goes to suspend (S3) and wakes back up (S0), then the AP sensor settings will be restored. 3. In S3 and in S5, only sample specific sensors that are needed. BUG=chrome-os-partner:32368 BRANCH=ToT TEST=Verified on Samus. Verified suspend and resume logic with EC console messages. - Test Case0: close lid & open lid - Test Case1: powerd_dbus_suspend Change-Id: I553c53e63ecfcb39d5e649a7189aa6ea02589471 Signed-off-by: Sheng-Liang Song <ssl@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/220371 Reviewed-by: Alec Berg <alecaberg@chromium.org>
135 lines
3.1 KiB
C
135 lines
3.1 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.
|
|
*/
|
|
|
|
/* Header for motion_sense.c */
|
|
|
|
#ifndef __CROS_EC_MOTION_SENSE_H
|
|
#define __CROS_EC_MOTION_SENSE_H
|
|
|
|
#include "gpio.h"
|
|
#include "math_util.h"
|
|
#include "chipset.h"
|
|
|
|
/* Anything outside of lid angle range [-180, 180] should work. */
|
|
#define LID_ANGLE_UNRELIABLE 500.0F
|
|
|
|
/**
|
|
* This structure defines all of the data needed to specify the orientation
|
|
* of the base and lid accelerometers in order to calculate the lid angle.
|
|
*/
|
|
struct accel_orientation {
|
|
/*
|
|
* Rotation matrix to rotate the lid sensor into the same reference
|
|
* frame as the base sensor.
|
|
*/
|
|
matrix_3x3_t rot_align;
|
|
|
|
/* Rotation matrix to rotate positive 90 degrees around the hinge. */
|
|
matrix_3x3_t rot_hinge_90;
|
|
|
|
/*
|
|
* Rotation matrix to rotate 180 degrees around the hinge. The value
|
|
* here should be rot_hinge_90 ^ 2.
|
|
*/
|
|
matrix_3x3_t rot_hinge_180;
|
|
|
|
/*
|
|
* Rotation matrix to rotate base sensor into the standard reference
|
|
* frame.
|
|
*/
|
|
matrix_3x3_t rot_standard_ref;
|
|
|
|
/* Vector pointing along hinge axis. */
|
|
vector_3_t hinge_axis;
|
|
};
|
|
|
|
/* Link global structure for orientation. This must be defined in board.c. */
|
|
extern const struct accel_orientation acc_orient;
|
|
|
|
|
|
/**
|
|
* Get last calculated lid angle. Note, the lid angle calculated by the EC
|
|
* is un-calibrated and is an approximate angle.
|
|
*
|
|
* @return lid angle in degrees in range [0, 360].
|
|
*/
|
|
int motion_get_lid_angle(void);
|
|
|
|
|
|
/**
|
|
* Interrupt function for lid accelerometer.
|
|
*
|
|
* @param signal GPIO signal that caused interrupt
|
|
*/
|
|
void accel_int_lid(enum gpio_signal signal);
|
|
|
|
/**
|
|
* Interrupt function for base accelerometer.
|
|
*
|
|
* @param signal GPIO signal that caused interrupt
|
|
*/
|
|
void accel_int_base(enum gpio_signal signal);
|
|
|
|
enum sensor_location_t {
|
|
LOCATION_BASE = 0,
|
|
LOCATION_LID = 1,
|
|
};
|
|
|
|
enum sensor_type_t {
|
|
SENSOR_ACCELEROMETER = 0x1,
|
|
SENSOR_GYRO = 0x2,
|
|
};
|
|
|
|
enum sensor_chip_t {
|
|
SENSOR_CHIP_KXCJ9 = 0,
|
|
SENSOR_CHIP_LSM6DS0 = 1,
|
|
};
|
|
|
|
enum sensor_state {
|
|
SENSOR_NOT_INITIALIZED = 0,
|
|
SENSOR_INITIALIZED = 1,
|
|
SENSOR_INIT_ERROR = 2
|
|
};
|
|
|
|
#define SENSOR_ACTIVE_S5 CHIPSET_STATE_SOFT_OFF
|
|
#define SENSOR_ACTIVE_S3 CHIPSET_STATE_SUSPEND
|
|
#define SENSOR_ACTIVE_S0 CHIPSET_STATE_ON
|
|
#define SENSOR_ACTIVE_S0_S3 (SENSOR_ACTIVE_S3 | SENSOR_ACTIVE_S0)
|
|
#define SENSOR_ACTIVE_S0_S3_S5 (SENSOR_ACTIVE_S0_S3 | SENSOR_ACTIVE_S5)
|
|
|
|
struct motion_sensor_t {
|
|
/* RO fields */
|
|
uint32_t active_mask;
|
|
char *name;
|
|
enum sensor_chip_t chip;
|
|
enum sensor_type_t type;
|
|
enum sensor_location_t location;
|
|
const struct accelgyro_drv *drv;
|
|
struct mutex *mutex;
|
|
void *drv_data;
|
|
uint8_t i2c_addr;
|
|
|
|
/* Default configuration parameters, RO only */
|
|
int default_odr;
|
|
int default_range;
|
|
|
|
/* Run-Time configuration parameters */
|
|
int odr;
|
|
int range;
|
|
|
|
/* state parameters */
|
|
enum sensor_state state;
|
|
enum chipset_state_mask active;
|
|
vector_3_t raw_xyz;
|
|
vector_3_t xyz;
|
|
|
|
};
|
|
|
|
/* Defined at board level. */
|
|
extern struct motion_sensor_t motion_sensors[];
|
|
extern const unsigned int motion_sensor_count;
|
|
|
|
#endif /* __CROS_EC_MOTION_SENSE_H */
|