mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-11 18:35:28 +00:00
sensors: add bmi160 & kionix orientation driver
BRANCH=none BUG=chromium:718919 TEST=make buildall -j works, orientation works when enabled on gru and scarlet. Change-Id: I16dcfa5d9dea39c082d98190fa1bb6e496168b17 Signed-off-by: Nick Vaccaro <nvaccaro@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/540124 Tested-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
This commit is contained in:
@@ -26,12 +26,26 @@
|
||||
#include "timer.h"
|
||||
#include "task.h"
|
||||
#include "util.h"
|
||||
#include "accel_kionix.h"
|
||||
|
||||
/* Console output macros */
|
||||
#define CPUTS(outstr) cputs(CC_MOTION_SENSE, outstr)
|
||||
#define CPRINTS(format, args...) cprints(CC_MOTION_SENSE, format, ## args)
|
||||
#define CPRINTF(format, args...) cprintf(CC_MOTION_SENSE, format, ## args)
|
||||
|
||||
#ifdef CONFIG_ORIENTATION_SENSOR
|
||||
/*
|
||||
* Orientation mode vectors, must match sequential ordering of
|
||||
* known orientations from enum motionsensor_orientation
|
||||
*/
|
||||
const vector_3_t orientation_modes[] = {
|
||||
[MOTIONSENSE_ORIENTATION_LANDSCAPE] = { 0, -1, 0 },
|
||||
[MOTIONSENSE_ORIENTATION_PORTRAIT] = { 1, 0, 0 },
|
||||
[MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT] = { -1, 0, 0 },
|
||||
[MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE] = { 0, 1, 0 },
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Sampling interval for measuring acceleration and calculating lid angle.
|
||||
*/
|
||||
@@ -711,6 +725,115 @@ static int motion_sense_process(struct motion_sensor_t *sensor,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ORIENTATION_SENSOR
|
||||
enum motionsensor_orientation motion_sense_remap_orientation(
|
||||
const struct motion_sensor_t *s,
|
||||
enum motionsensor_orientation orientation)
|
||||
{
|
||||
enum motionsensor_orientation rotated_orientation;
|
||||
const vector_3_t *orientation_v;
|
||||
vector_3_t rotated_orientation_v;
|
||||
|
||||
if (orientation == MOTIONSENSE_ORIENTATION_UNKNOWN)
|
||||
return MOTIONSENSE_ORIENTATION_UNKNOWN;
|
||||
|
||||
orientation_v = &orientation_modes[orientation];
|
||||
rotate(*orientation_v, *s->rot_standard_ref, rotated_orientation_v);
|
||||
rotated_orientation = ((2 * rotated_orientation_v[1] +
|
||||
rotated_orientation_v[0] + 4) % 5);
|
||||
return rotated_orientation;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GESTURE_DETECTION
|
||||
static void check_and_queue_gestures(uint32_t *event)
|
||||
{
|
||||
#ifdef CONFIG_ORIENTATION_SENSOR
|
||||
const struct motion_sensor_t *sensor;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GESTURE_SW_DETECTION
|
||||
/* Run gesture recognition engine */
|
||||
gesture_calc(event);
|
||||
#endif
|
||||
#ifdef CONFIG_GESTURE_SENSOR_BATTERY_TAP
|
||||
if (*event & CONFIG_GESTURE_TAP_EVENT) {
|
||||
#ifdef CONFIG_GESTURE_HOST_DETECTION
|
||||
struct ec_response_motion_sensor_data vector;
|
||||
|
||||
/*
|
||||
* Send events to the FIFO
|
||||
* AP is ignoring double tap event, do no wake up and no
|
||||
* automatic disable.
|
||||
*/
|
||||
vector.flags = 0;
|
||||
vector.activity = MOTIONSENSE_ACTIVITY_DOUBLE_TAP;
|
||||
vector.state = 1; /* triggered */
|
||||
vector.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID;
|
||||
motion_sense_fifo_add_unit(&vector, NULL, 0);
|
||||
#endif
|
||||
CPRINTS("double tap!");
|
||||
/* Call board specific function to process tap */
|
||||
sensor_board_proc_double_tap();
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_GESTURE_SIGMO
|
||||
if (*event & CONFIG_GESTURE_SIGMO_EVENT) {
|
||||
struct motion_sensor_t *activity_sensor;
|
||||
#ifdef CONFIG_GESTURE_HOST_DETECTION
|
||||
struct ec_response_motion_sensor_data vector;
|
||||
|
||||
/* Send events to the FIFO */
|
||||
vector.flags = MOTIONSENSE_SENSOR_FLAG_WAKEUP;
|
||||
vector.activity = MOTIONSENSE_ACTIVITY_SIG_MOTION;
|
||||
vector.state = 1; /* triggered */
|
||||
vector.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID;
|
||||
motion_sense_fifo_add_unit(&vector, NULL, 0);
|
||||
#endif
|
||||
CPRINTS("significant motion");
|
||||
/* Disable further detection */
|
||||
activity_sensor = &motion_sensors[CONFIG_GESTURE_SIGMO];
|
||||
activity_sensor->drv->manage_activity(
|
||||
activity_sensor,
|
||||
MOTIONSENSE_ACTIVITY_SIG_MOTION,
|
||||
0, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ORIENTATION_SENSOR
|
||||
sensor = &motion_sensors[LID_ACCEL];
|
||||
if (SENSOR_ACTIVE(sensor) && (sensor->state == SENSOR_INITIALIZED)) {
|
||||
struct ec_response_motion_sensor_data vector = {
|
||||
.flags = 0,
|
||||
.activity = MOTIONSENSE_ACTIVITY_ORIENTATION,
|
||||
.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID,
|
||||
};
|
||||
|
||||
mutex_lock(sensor->mutex);
|
||||
if (ORIENTATION_CHANGED(sensor) && (GET_ORIENTATION(sensor) !=
|
||||
MOTIONSENSE_ORIENTATION_UNKNOWN)) {
|
||||
SET_ORIENTATION_UPDATED(sensor);
|
||||
vector.state = GET_ORIENTATION(sensor);
|
||||
motion_sense_fifo_add_unit(&vector, NULL, 0);
|
||||
#ifdef CONFIG_DEBUG_ORIENTATION
|
||||
{
|
||||
static const char * const mode_strs[] = {
|
||||
"Landscape",
|
||||
"Portrait",
|
||||
"Inv_Portrait",
|
||||
"Inv_Landscape",
|
||||
"Unknown"
|
||||
};
|
||||
CPRINTS(mode_strs[GET_ORIENTATION(sensor)]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
mutex_unlock(sensor->mutex);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Motion Sense Task
|
||||
* Requirement: motion_sensors[] are defined in board.c file.
|
||||
@@ -763,55 +886,8 @@ void motion_sense_task(void *u)
|
||||
ready_status |= (1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_GESTURE_DETECTION
|
||||
#ifdef CONFIG_GESTURE_SW_DETECTION
|
||||
/* Run gesture recognition engine */
|
||||
gesture_calc(&event);
|
||||
#endif
|
||||
#ifdef CONFIG_GESTURE_SENSOR_BATTERY_TAP
|
||||
if (event & CONFIG_GESTURE_TAP_EVENT) {
|
||||
#ifdef CONFIG_GESTURE_HOST_DETECTION
|
||||
struct ec_response_motion_sensor_data vector;
|
||||
|
||||
/*
|
||||
* Send events to the FIFO
|
||||
* AP is ignoring double tap event, do no wake up and no
|
||||
* automatic disable.
|
||||
*/
|
||||
vector.flags = 0;
|
||||
vector.activity = MOTIONSENSE_ACTIVITY_DOUBLE_TAP;
|
||||
vector.state = 1; /* triggered */
|
||||
vector.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID;
|
||||
motion_sense_fifo_add_unit(&vector, NULL, 0);
|
||||
#endif
|
||||
CPRINTS("double tap!");
|
||||
/* Call board specific function to process tap */
|
||||
sensor_board_proc_double_tap();
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_GESTURE_SIGMO
|
||||
if (event & CONFIG_GESTURE_SIGMO_EVENT) {
|
||||
struct motion_sensor_t *activity_sensor;
|
||||
#ifdef CONFIG_GESTURE_HOST_DETECTION
|
||||
struct ec_response_motion_sensor_data vector;
|
||||
|
||||
/* Send events to the FIFO */
|
||||
vector.flags = MOTIONSENSE_SENSOR_FLAG_WAKEUP;
|
||||
vector.activity = MOTIONSENSE_ACTIVITY_SIG_MOTION;
|
||||
vector.state = 1; /* triggered */
|
||||
vector.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID;
|
||||
motion_sense_fifo_add_unit(&vector, NULL, 0);
|
||||
#endif
|
||||
CPRINTS("significant motion");
|
||||
/* Disable further detection */
|
||||
activity_sensor = &motion_sensors[CONFIG_GESTURE_SIGMO];
|
||||
activity_sensor->drv->manage_activity(
|
||||
activity_sensor,
|
||||
MOTIONSENSE_ACTIVITY_SIG_MOTION,
|
||||
0, NULL);
|
||||
}
|
||||
#endif
|
||||
check_and_queue_gestures(&event);
|
||||
#endif
|
||||
#ifdef CONFIG_LID_ANGLE
|
||||
/*
|
||||
|
||||
@@ -253,6 +253,12 @@ static int enable_sensor(const struct motion_sensor_t *s, int reg_val)
|
||||
if (ret != EC_SUCCESS)
|
||||
continue;
|
||||
|
||||
#ifdef CONFIG_KX022_ORIENTATION_SENSOR
|
||||
/* Enable tilt orientation mode if lid sensor */
|
||||
if ((s->location == MOTIONSENSE_LOC_LID) && (V(s) == 0))
|
||||
reg_val |= KX022_CNTL1_TPE;
|
||||
#endif
|
||||
|
||||
/* Enable accelerometer based on reg_val value. */
|
||||
ret = raw_write8(s->port, s->addr, reg,
|
||||
reg_val | pc1_field);
|
||||
@@ -394,6 +400,55 @@ static int get_offset(const struct motion_sensor_t *s, int16_t *offset,
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_KX022_ORIENTATION_SENSOR
|
||||
static enum motionsensor_orientation kx022_convert_orientation(
|
||||
const struct motion_sensor_t *s,
|
||||
int orientation)
|
||||
{
|
||||
enum motionsensor_orientation res = MOTIONSENSE_ORIENTATION_UNKNOWN;
|
||||
|
||||
switch (orientation) {
|
||||
case KX022_ORIENT_PORTRAIT:
|
||||
res = MOTIONSENSE_ORIENTATION_PORTRAIT;
|
||||
break;
|
||||
case KX022_ORIENT_INVERT_PORTRAIT:
|
||||
res = MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT;
|
||||
break;
|
||||
case KX022_ORIENT_LANDSCAPE:
|
||||
res = MOTIONSENSE_ORIENTATION_LANDSCAPE;
|
||||
break;
|
||||
case KX022_ORIENT_INVERT_LANDSCAPE:
|
||||
res = MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
res = motion_sense_remap_orientation(s, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int check_orientation_locked(const struct motion_sensor_t *s)
|
||||
{
|
||||
struct kionix_accel_data *data = s->drv_data;
|
||||
int orientation, raw_orientation;
|
||||
int ret;
|
||||
|
||||
ret = raw_read8(s->port, s->addr,
|
||||
KX022_TSCP, &raw_orientation);
|
||||
if (ret != EC_SUCCESS)
|
||||
return ret;
|
||||
|
||||
/* mask off up and down events, we don't care about those */
|
||||
raw_orientation &= KX022_ORIENT_MASK;
|
||||
if (raw_orientation && (raw_orientation != data->raw_orientation)) {
|
||||
data->raw_orientation = raw_orientation;
|
||||
orientation = kx022_convert_orientation(s, raw_orientation);
|
||||
SET_ORIENTATION(s, orientation);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int read(const struct motion_sensor_t *s, vector_3_t v)
|
||||
{
|
||||
uint8_t acc[6];
|
||||
@@ -405,6 +460,11 @@ static int read(const struct motion_sensor_t *s, vector_3_t v)
|
||||
reg = KIONIX_XOUT_L(V(s));
|
||||
mutex_lock(s->mutex);
|
||||
ret = raw_read_multi(s->port, s->addr, reg, acc, 6);
|
||||
#ifdef CONFIG_KX022_ORIENTATION_SENSOR
|
||||
if ((s->location == MOTIONSENSE_LOC_LID) && (V(s) == 0) &&
|
||||
(ret == EC_SUCCESS))
|
||||
ret = check_orientation_locked(s);
|
||||
#endif
|
||||
mutex_unlock(s->mutex);
|
||||
|
||||
if (ret != EC_SUCCESS)
|
||||
|
||||
@@ -30,6 +30,11 @@ struct kionix_accel_data {
|
||||
/* Current resolution of accelerometer. */
|
||||
int sensor_resolution;
|
||||
int16_t offset[3];
|
||||
#ifdef CONFIG_KX022_ORIENTATION_SENSOR
|
||||
int8_t raw_orientation;
|
||||
enum motionsensor_orientation orientation;
|
||||
enum motionsensor_orientation last_orientation;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern const struct accelgyro_drv kionix_accel_drv;
|
||||
@@ -77,4 +82,20 @@ extern const struct accelgyro_drv kionix_accel_drv;
|
||||
extern struct i2c_stress_test_dev kionix_i2c_stress_test_dev;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_KX022_ORIENTATION_SENSOR
|
||||
#define ORIENTATION_CHANGED(_sensor) \
|
||||
(((struct kionix_accel_data *)(_sensor->drv_data))->orientation != \
|
||||
((struct kionix_accel_data *)(_sensor->drv_data))->last_orientation)
|
||||
|
||||
#define GET_ORIENTATION(_sensor) \
|
||||
(((struct kionix_accel_data *)(_sensor->drv_data))->orientation)
|
||||
|
||||
#define SET_ORIENTATION(_sensor, _val) \
|
||||
(((struct kionix_accel_data *)(_sensor->drv_data))->orientation = _val)
|
||||
|
||||
#define SET_ORIENTATION_UPDATED(_sensor) \
|
||||
(((struct kionix_accel_data *)(_sensor->drv_data))->last_orientation = \
|
||||
((struct kionix_accel_data *)(_sensor->drv_data))->orientation)
|
||||
#endif
|
||||
|
||||
#endif /* __CROS_EC_ACCEL_KIONIX_H */
|
||||
|
||||
@@ -74,6 +74,17 @@
|
||||
|
||||
#define KX022_CNTL1_PC1 (1 << 7)
|
||||
#define KX022_CNTL1_WUFE (1 << 1)
|
||||
#define KX022_CNTL1_TPE (1 << 0)
|
||||
|
||||
/* TSCP orientations */
|
||||
#define KX022_ORIENT_PORTRAIT (1 << 2)
|
||||
#define KX022_ORIENT_INVERT_PORTRAIT (1 << 3)
|
||||
#define KX022_ORIENT_LANDSCAPE (1 << 4)
|
||||
#define KX022_ORIENT_INVERT_LANDSCAPE (1 << 5)
|
||||
#define KX022_ORIENT_MASK (KX022_ORIENT_PORTRAIT | \
|
||||
KX022_ORIENT_INVERT_PORTRAIT | \
|
||||
KX022_ORIENT_LANDSCAPE | \
|
||||
KX022_ORIENT_INVERT_LANDSCAPE)
|
||||
|
||||
#define KX022_CNTL2_SRST (1 << 7)
|
||||
|
||||
|
||||
@@ -796,6 +796,16 @@ static int config_interrupt(const struct motion_sensor_t *s)
|
||||
ret = raw_write8(s->port, s->addr, BMI160_INT_TAP_1,
|
||||
BMI160_TAP_TH(s, CONFIG_GESTURE_TAP_THRES_MG));
|
||||
#endif
|
||||
#ifdef CONFIG_BMI160_ORIENTATION_SENSOR
|
||||
/* only use orientation sensor on the lid sensor */
|
||||
if (s->location == MOTIONSENSE_LOC_LID) {
|
||||
ret = raw_write8(s->port, s->addr, BMI160_INT_ORIENT_0,
|
||||
BMI160_INT_ORIENT_0_INIT_VAL);
|
||||
ret = raw_write8(s->port, s->addr, BMI160_INT_ORIENT_1,
|
||||
BMI160_INT_ORIENT_1_INIT_VAL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Set a 5ms latch to be sure the EC can read the interrupt register
|
||||
* properly, even when it is running more slowly.
|
||||
@@ -819,6 +829,11 @@ static int config_interrupt(const struct motion_sensor_t *s)
|
||||
#endif
|
||||
#ifdef CONFIG_GESTURE_SENSOR_BATTERY_TAP
|
||||
tmp |= BMI160_INT_D_TAP;
|
||||
#endif
|
||||
#ifdef CONFIG_BMI160_ORIENTATION_SENSOR
|
||||
/* enable orientation interrupt for lid sensor only */
|
||||
if (s->location == MOTIONSENSE_LOC_LID)
|
||||
tmp |= BMI160_INT_ORIENT;
|
||||
#endif
|
||||
ret = raw_write8(s->port, s->addr, BMI160_INT_MAP_REG(1), tmp);
|
||||
|
||||
@@ -859,6 +874,9 @@ static int config_interrupt(const struct motion_sensor_t *s)
|
||||
static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
|
||||
{
|
||||
int interrupt;
|
||||
#ifdef CONFIG_BMI160_ORIENTATION_SENSOR
|
||||
int shifted_masked_orientation;
|
||||
#endif
|
||||
|
||||
if ((s->type != MOTIONSENSE_TYPE_ACCEL) ||
|
||||
(!(*event & CONFIG_ACCELGYRO_BMI160_INT_EVENT)))
|
||||
@@ -873,6 +891,37 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
|
||||
#ifdef CONFIG_GESTURE_SIGMO
|
||||
if (interrupt & BMI160_SIGMOT_INT)
|
||||
*event |= CONFIG_GESTURE_SIGMO_EVENT;
|
||||
#endif
|
||||
#ifdef CONFIG_BMI160_ORIENTATION_SENSOR
|
||||
shifted_masked_orientation = (interrupt >> 24) & BMI160_ORIENT_XY_MASK;
|
||||
if (BMI160_GET_DATA(s)->raw_orientation != shifted_masked_orientation) {
|
||||
enum motionsensor_orientation orientation =
|
||||
MOTIONSENSE_ORIENTATION_UNKNOWN;
|
||||
|
||||
BMI160_GET_DATA(s)->raw_orientation =
|
||||
shifted_masked_orientation;
|
||||
|
||||
switch (shifted_masked_orientation) {
|
||||
case BMI160_ORIENT_PORTRAIT:
|
||||
orientation = MOTIONSENSE_ORIENTATION_PORTRAIT;
|
||||
break;
|
||||
case BMI160_ORIENT_PORTRAIT_INVERT:
|
||||
orientation =
|
||||
MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT;
|
||||
break;
|
||||
case BMI160_ORIENT_LANDSCAPE:
|
||||
orientation = MOTIONSENSE_ORIENTATION_LANDSCAPE;
|
||||
break;
|
||||
case BMI160_ORIENT_LANDSCAPE_INVERT:
|
||||
orientation =
|
||||
MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
orientation = motion_sense_remap_orientation(s, orientation);
|
||||
SET_ORIENTATION(s, orientation);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* No need to read the FIFO here, motion sense task is
|
||||
|
||||
@@ -99,6 +99,12 @@
|
||||
#define BMI160_S_TAP_INT (1 << 5)
|
||||
#define BMI160_ORIENT_INT (1 << 6)
|
||||
#define BMI160_FLAT_INT (1 << 7)
|
||||
#define BMI160_ORIENT_XY_MASK 0x30
|
||||
#define BMI160_ORIENT_PORTRAIT (0 << 4)
|
||||
#define BMI160_ORIENT_PORTRAIT_INVERT (1 << 4)
|
||||
#define BMI160_ORIENT_LANDSCAPE (2 << 4)
|
||||
#define BMI160_ORIENT_LANDSCAPE_INVERT (3 << 4)
|
||||
|
||||
|
||||
#define BMI160_INT_STATUS_1 0x1d
|
||||
#define BMI160_HIGHG_INT (1 << (2 + 8))
|
||||
@@ -333,8 +339,15 @@ enum fifo_header {
|
||||
#define BMI160_TAP_TH(_s, _mg) \
|
||||
(MIN(((_mg) * 1000) / ((_s)->drv->get_range(_s) * 31250), 0x1f))
|
||||
|
||||
#define BMI160_INT_ORIENT_0 0x65
|
||||
#define BMI160_INT_ORIENT_1 0x66
|
||||
#define BMI160_INT_ORIENT_0 0x65
|
||||
|
||||
/* No hysterisis, theta block, int on slope > 0.2 or axis > 1.5, symmetrical */
|
||||
#define BMI160_INT_ORIENT_0_INIT_VAL 0x48
|
||||
|
||||
#define BMI160_INT_ORIENT_1 0x66
|
||||
|
||||
/* no axes remap, no int on up/down, no blocking angle */
|
||||
#define BMI160_INT_ORIENT_1_INIT_VAL 0x00
|
||||
|
||||
#define BMI160_INT_FLAT_0 0x67
|
||||
#define BMI160_INT_FLAT_1 0x68
|
||||
@@ -449,6 +462,12 @@ struct bmi160_drv_data_t {
|
||||
#ifdef CONFIG_MAG_BMI160_BMM150
|
||||
struct bmm150_private_data compass;
|
||||
#endif
|
||||
#ifdef CONFIG_BMI160_ORIENTATION_SENSOR
|
||||
uint8_t raw_orientation;
|
||||
enum motionsensor_orientation orientation;
|
||||
enum motionsensor_orientation last_orientation;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#define BMI160_GET_DATA(_s) \
|
||||
@@ -456,6 +475,22 @@ struct bmi160_drv_data_t {
|
||||
#define BMI160_GET_SAVED_DATA(_s) \
|
||||
(&BMI160_GET_DATA(_s)->saved_data[(_s)->type])
|
||||
|
||||
#ifdef CONFIG_BMI160_ORIENTATION_SENSOR
|
||||
#define ORIENTATION_CHANGED(_sensor) \
|
||||
(BMI160_GET_DATA(_sensor)->orientation != \
|
||||
BMI160_GET_DATA(_sensor)->last_orientation)
|
||||
|
||||
#define GET_ORIENTATION(_sensor) \
|
||||
(BMI160_GET_DATA(_sensor)->orientation)
|
||||
|
||||
#define SET_ORIENTATION(_sensor, _val) \
|
||||
(BMI160_GET_DATA(_sensor)->orientation = _val)
|
||||
|
||||
#define SET_ORIENTATION_UPDATED(_sensor) \
|
||||
(BMI160_GET_DATA(_sensor)->last_orientation = \
|
||||
BMI160_GET_DATA(_sensor)->orientation)
|
||||
#endif
|
||||
|
||||
void bmi160_interrupt(enum gpio_signal signal);
|
||||
|
||||
#ifdef CONFIG_MAG_BMI160_BMM150
|
||||
|
||||
@@ -69,6 +69,21 @@
|
||||
#undef CONFIG_ACCELGYRO_BMI160
|
||||
#undef CONFIG_ACCELGYRO_LSM6DSM
|
||||
|
||||
/* Support for BMI160 hardware orientation sensor */
|
||||
#undef CONFIG_BMI160_ORIENTATION_SENSOR
|
||||
|
||||
/* Support for KIONIX KX022 hardware orientation sensor */
|
||||
#undef CONFIG_KX022_ORIENTATION_SENSOR
|
||||
|
||||
/*
|
||||
* Define if either CONFIG_BMI160_ORIENTATION_SUPPORT or
|
||||
* CONFIG_KX022_ORIENTATION_SUPPORT is set.
|
||||
*/
|
||||
#undef CONFIG_ORIENTATION_SENSOR
|
||||
|
||||
/* Support the orientation gesture */
|
||||
#undef CONFIG_GESTURE_ORIENTATION
|
||||
|
||||
/* Specify barometer attached */
|
||||
#undef CONFIG_BARO_BMP280
|
||||
|
||||
@@ -943,6 +958,12 @@
|
||||
*/
|
||||
#define CONFIG_DEBUG_EXCEPTIONS
|
||||
|
||||
/*
|
||||
* Print orientation when device orientation changes
|
||||
* (requires CONFIG_SENSOR_ORIENTATION)
|
||||
*/
|
||||
#undef CONFIG_DEBUG_ORIENTATION
|
||||
|
||||
/* Support Synchronous UART debug printf. */
|
||||
#undef CONFIG_DEBUG_PRINTF
|
||||
|
||||
@@ -2916,6 +2937,16 @@
|
||||
#define CONFIG_MKBP_EVENT
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/* Set generic orientation config if a specific orientation config is set. */
|
||||
#if defined(CONFIG_KX022_ORIENTATION_SENSOR) || \
|
||||
defined(CONFIG_BMI160_ORIENTATION_SENSOR)
|
||||
#ifndef CONFIG_ACCEL_FIFO
|
||||
#error CONFIG_ACCEL_FIFO must be defined to use hw orientation sensor support
|
||||
#endif
|
||||
#define CONFIG_ORIENTATION_SENSOR
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
* Handle task-dependent configs.
|
||||
|
||||
@@ -2080,6 +2080,15 @@ enum motionsensor_chip {
|
||||
MOTIONSENSE_CHIP_OPT3001 = 10,
|
||||
};
|
||||
|
||||
/* List of orientation positions */
|
||||
enum motionsensor_orientation {
|
||||
MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
|
||||
MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
|
||||
MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
|
||||
MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
|
||||
MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
|
||||
};
|
||||
|
||||
struct __ec_todo_packed ec_response_motion_sensor_data {
|
||||
/* Flags for each sensor. */
|
||||
uint8_t flags;
|
||||
@@ -2124,6 +2133,7 @@ enum motionsensor_activity {
|
||||
MOTIONSENSE_ACTIVITY_RESERVED = 0,
|
||||
MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
|
||||
MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
|
||||
MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
|
||||
};
|
||||
|
||||
struct __ec_todo_unpacked ec_motion_sense_activity {
|
||||
|
||||
@@ -203,7 +203,13 @@ void sensor_init_done(const struct motion_sensor_t *sensor, int range);
|
||||
*/
|
||||
void sensor_board_proc_double_tap(void);
|
||||
|
||||
#ifdef CONFIG_GESTURE_HOST_DETECTION
|
||||
#ifdef CONFIG_ORIENTATION_SENSOR
|
||||
enum motionsensor_orientation motion_sense_remap_orientation(
|
||||
const struct motion_sensor_t *s,
|
||||
enum motionsensor_orientation orientation);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_GESTURE_HOST_DETECTION) || defined(CONFIG_ORIENTATION_SENSOR)
|
||||
/* Add an extra sensor. We may need to add more */
|
||||
#define MOTION_SENSE_ACTIVITY_SENSOR_ID (motion_sensor_count)
|
||||
#define ALL_MOTION_SENSORS (MOTION_SENSE_ACTIVITY_SENSOR_ID + 1)
|
||||
|
||||
Reference in New Issue
Block a user