driver: input: sensor: convert gyro sensor data to match user level
Change-Id: If23a83abc26c46ed31da11f6c2e49fdb8625e7a5 Signed-off-by: Zorro Liu <lyx@rock-chips.com>
This commit is contained in:
parent
4b5687dec0
commit
b8e487f1f6
4 changed files with 86 additions and 105 deletions
54
drivers/input/sensors/gyro/ewtsa.c
Executable file → Normal file
54
drivers/input/sensors/gyro/ewtsa.c
Executable file → Normal file
|
|
@ -338,12 +338,13 @@ static int gyro_report_value(struct i2c_client *client, struct sensor_axis *axis
|
|||
struct sensor_private_data *sensor =
|
||||
(struct sensor_private_data *) i2c_get_clientdata(client);
|
||||
|
||||
/* Report GYRO information */
|
||||
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
|
||||
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
|
||||
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
|
||||
input_sync(sensor->input_dev);
|
||||
DBG("gyro x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
|
||||
if (sensor->status_cur == SENSOR_ON) {
|
||||
/* Report GYRO information */
|
||||
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
|
||||
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
|
||||
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
|
||||
input_sync(sensor->input_dev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -395,37 +396,32 @@ static int sensor_report_value(struct i2c_client *client)
|
|||
axis.z = z;
|
||||
}
|
||||
|
||||
//filter gyro data
|
||||
if((abs(axis.x) > pdata->x_min)||(abs(axis.y) > pdata->y_min)||(abs(axis.z) > pdata->z_min))
|
||||
{
|
||||
gyro_report_value(client, &axis);
|
||||
gyro_report_value(client, &axis);
|
||||
|
||||
/* »¥³âµØ»º´æÊý¾Ý. */
|
||||
mutex_lock(&(sensor->data_mutex) );
|
||||
sensor->axis = axis;
|
||||
mutex_unlock(&(sensor->data_mutex) );
|
||||
}
|
||||
mutex_lock(&sensor->data_mutex);
|
||||
sensor->axis = axis;
|
||||
mutex_unlock(&sensor->data_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
struct sensor_operate gyro_ewtsa_ops = {
|
||||
.name = "ewtsa",
|
||||
.type = SENSOR_TYPE_GYROSCOPE,//sensor type and it should be correct
|
||||
.id_i2c = GYRO_ID_EWTSA, //i2c id number
|
||||
.read_reg = GYRO_DATA_REG, //read data
|
||||
.read_len = 6, //data length
|
||||
.id_reg = -1, //read device id from this register
|
||||
.id_data = -1, //device id
|
||||
.precision = 8, //8 bits
|
||||
.ctrl_reg = REG_PWR_MGM, //enable or disable
|
||||
.int_status_reg = REG_INT_STATUS, //intterupt status register,if no exist then -1
|
||||
.range = {-32768,32768}, //range
|
||||
.trig = IRQF_TRIGGER_HIGH|IRQF_ONESHOT,
|
||||
.active = sensor_active,
|
||||
.name = "ewtsa",
|
||||
.type = SENSOR_TYPE_GYROSCOPE,
|
||||
.id_i2c = GYRO_ID_EWTSA,
|
||||
.read_reg = GYRO_DATA_REG,
|
||||
.read_len = 6,
|
||||
.id_reg = -1,
|
||||
.id_data = -1,
|
||||
.precision = 16,
|
||||
.ctrl_reg = REG_PWR_MGM,
|
||||
.int_status_reg = REG_INT_STATUS,
|
||||
.range = {-32768, 32768},
|
||||
.trig = IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
|
||||
.active = sensor_active,
|
||||
.init = sensor_init,
|
||||
.report = sensor_report_value,
|
||||
.report = sensor_report_value,
|
||||
};
|
||||
|
||||
/****************operate according to sensor chip:end************/
|
||||
|
|
|
|||
54
drivers/input/sensors/gyro/l3g20d.c
Executable file → Normal file
54
drivers/input/sensors/gyro/l3g20d.c
Executable file → Normal file
|
|
@ -121,12 +121,13 @@ static int gyro_report_value(struct i2c_client *client, struct sensor_axis *axis
|
|||
struct sensor_private_data *sensor =
|
||||
(struct sensor_private_data *) i2c_get_clientdata(client);
|
||||
|
||||
/* Report GYRO information */
|
||||
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
|
||||
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
|
||||
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
|
||||
input_sync(sensor->input_dev);
|
||||
DBG("gyro x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
|
||||
if (sensor->status_cur == SENSOR_ON) {
|
||||
/* Report GYRO information */
|
||||
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
|
||||
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
|
||||
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
|
||||
input_sync(sensor->input_dev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -184,16 +185,11 @@ static int sensor_report_value(struct i2c_client *client)
|
|||
axis.z = z;
|
||||
}
|
||||
|
||||
//filter gyro data
|
||||
if((abs(axis.x) > pdata->x_min)||(abs(axis.y) > pdata->y_min)||(abs(axis.z) > pdata->z_min))
|
||||
{
|
||||
gyro_report_value(client, &axis);
|
||||
gyro_report_value(client, &axis);
|
||||
|
||||
/* »¥³âµØ»º´æÊý¾Ý. */
|
||||
mutex_lock(&(sensor->data_mutex) );
|
||||
sensor->axis = axis;
|
||||
mutex_unlock(&(sensor->data_mutex) );
|
||||
}
|
||||
mutex_lock(&sensor->data_mutex);
|
||||
sensor->axis = axis;
|
||||
mutex_unlock(&sensor->data_mutex);
|
||||
|
||||
if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register
|
||||
{
|
||||
|
|
@ -207,21 +203,21 @@ static int sensor_report_value(struct i2c_client *client)
|
|||
|
||||
|
||||
static struct sensor_operate gyro_l3g20d_ops = {
|
||||
.name = "l3g20d",
|
||||
.type = SENSOR_TYPE_GYROSCOPE,//sensor type and it should be correct
|
||||
.id_i2c = GYRO_ID_L3G20D, //i2c id number
|
||||
.read_reg = GYRO_DATA_REG, //read data
|
||||
.read_len = 6, //data length
|
||||
.id_reg = GYRO_WHO_AM_I, //read device id from this register
|
||||
.id_data = GYRO_DEVID_L3G20D, //device id
|
||||
.precision = 8, //8 bits
|
||||
.ctrl_reg = GYRO_CTRL_REG1, //enable or disable
|
||||
.int_status_reg = GYRO_INT_SRC, //intterupt status register,if no exist then -1
|
||||
.range = {-32768,32768}, //range
|
||||
.trig = IRQF_TRIGGER_LOW|IRQF_ONESHOT,
|
||||
.active = sensor_active,
|
||||
.name = "l3g20d",
|
||||
.type = SENSOR_TYPE_GYROSCOPE,
|
||||
.id_i2c = GYRO_ID_L3G20D,
|
||||
.read_reg = GYRO_DATA_REG,
|
||||
.read_len = 6,
|
||||
.id_reg = GYRO_WHO_AM_I,
|
||||
.id_data = GYRO_DEVID_L3G20D,
|
||||
.precision = 16,
|
||||
.ctrl_reg = GYRO_CTRL_REG1,
|
||||
.int_status_reg = GYRO_INT_SRC,
|
||||
.range = {-32768, 32768},
|
||||
.trig = IRQF_TRIGGER_LOW | IRQF_ONESHOT,
|
||||
.active = sensor_active,
|
||||
.init = sensor_init,
|
||||
.report = sensor_report_value,
|
||||
.report = sensor_report_value,
|
||||
};
|
||||
|
||||
/****************operate according to sensor chip:end************/
|
||||
|
|
|
|||
54
drivers/input/sensors/gyro/l3g4200d.c
Executable file → Normal file
54
drivers/input/sensors/gyro/l3g4200d.c
Executable file → Normal file
|
|
@ -121,12 +121,13 @@ static int gyro_report_value(struct i2c_client *client, struct sensor_axis *axis
|
|||
struct sensor_private_data *sensor =
|
||||
(struct sensor_private_data *) i2c_get_clientdata(client);
|
||||
|
||||
/* Report GYRO information */
|
||||
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
|
||||
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
|
||||
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
|
||||
input_sync(sensor->input_dev);
|
||||
DBG("gyro x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
|
||||
if (sensor->status_cur == SENSOR_ON) {
|
||||
/* Report GYRO information */
|
||||
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
|
||||
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
|
||||
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
|
||||
input_sync(sensor->input_dev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -184,16 +185,11 @@ static int sensor_report_value(struct i2c_client *client)
|
|||
axis.z = z;
|
||||
}
|
||||
|
||||
//filter gyro data
|
||||
if((abs(axis.x) > pdata->x_min)||(abs(axis.y) > pdata->y_min)||(abs(axis.z) > pdata->z_min))
|
||||
{
|
||||
gyro_report_value(client, &axis);
|
||||
gyro_report_value(client, &axis);
|
||||
|
||||
/* »¥³âµØ»º´æÊý¾Ý. */
|
||||
mutex_lock(&(sensor->data_mutex) );
|
||||
sensor->axis = axis;
|
||||
mutex_unlock(&(sensor->data_mutex) );
|
||||
}
|
||||
mutex_lock(&sensor->data_mutex);
|
||||
sensor->axis = axis;
|
||||
mutex_unlock(&sensor->data_mutex);
|
||||
|
||||
if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register
|
||||
{
|
||||
|
|
@ -207,21 +203,21 @@ static int sensor_report_value(struct i2c_client *client)
|
|||
|
||||
|
||||
struct sensor_operate gyro_l3g4200d_ops = {
|
||||
.name = "l3g4200d",
|
||||
.type = SENSOR_TYPE_GYROSCOPE,//sensor type and it should be correct
|
||||
.id_i2c = GYRO_ID_L3G4200D, //i2c id number
|
||||
.read_reg = GYRO_DATA_REG, //read data
|
||||
.read_len = 6, //data length
|
||||
.id_reg = GYRO_WHO_AM_I, //read device id from this register
|
||||
.id_data = GYRO_DEVID_L3G4200D, //device id
|
||||
.precision = 8, //8 bits
|
||||
.ctrl_reg = GYRO_CTRL_REG1, //enable or disable
|
||||
.int_status_reg = GYRO_INT_SRC, //intterupt status register,if no exist then -1
|
||||
.range = {-32768,32768}, //range
|
||||
.trig = IRQF_TRIGGER_LOW|IRQF_ONESHOT,
|
||||
.active = sensor_active,
|
||||
.name = "l3g4200d",
|
||||
.type = SENSOR_TYPE_GYROSCOPE,
|
||||
.id_i2c = GYRO_ID_L3G4200D,
|
||||
.read_reg = GYRO_DATA_REG,
|
||||
.read_len = 6,
|
||||
.id_reg = GYRO_WHO_AM_I,
|
||||
.id_data = GYRO_DEVID_L3G4200D,
|
||||
.precision = 16,
|
||||
.ctrl_reg = GYRO_CTRL_REG1,
|
||||
.int_status_reg = GYRO_INT_SRC,
|
||||
.range = {-32768, 32768},
|
||||
.trig = IRQF_TRIGGER_LOW | IRQF_ONESHOT,
|
||||
.active = sensor_active,
|
||||
.init = sensor_init,
|
||||
.report = sensor_report_value,
|
||||
.report = sensor_report_value,
|
||||
};
|
||||
|
||||
/****************operate according to sensor chip:end************/
|
||||
|
|
|
|||
|
|
@ -144,11 +144,12 @@ static int gyro_report_value(struct i2c_client *client,
|
|||
struct sensor_private_data *sensor =
|
||||
(struct sensor_private_data *)i2c_get_clientdata(client);
|
||||
|
||||
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
|
||||
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
|
||||
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
|
||||
input_sync(sensor->input_dev);
|
||||
DBG("gyro x==%d y==%d z==%d\n", axis->x, axis->y, axis->z);
|
||||
if (sensor->status_cur == SENSOR_ON) {
|
||||
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
|
||||
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
|
||||
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
|
||||
input_sync(sensor->input_dev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -194,18 +195,10 @@ static int sensor_report_value(struct i2c_client *client)
|
|||
(pdata->orientation[7]) * y +
|
||||
(pdata->orientation[8]) * z;
|
||||
|
||||
axis.x = (axis.x * 872) / 1000;
|
||||
axis.y = (axis.y * 872) / 1000;
|
||||
axis.z = (axis.z * 872) / 1000;
|
||||
|
||||
if ((abs(axis.x) > pdata->x_min) ||
|
||||
(abs(axis.y) > pdata->y_min) ||
|
||||
(abs(axis.z) > pdata->z_min)) {
|
||||
gyro_report_value(client, &axis);
|
||||
mutex_lock(&sensor->data_mutex);
|
||||
sensor->axis = axis;
|
||||
mutex_unlock(&sensor->data_mutex);
|
||||
}
|
||||
gyro_report_value(client, &axis);
|
||||
mutex_lock(&sensor->data_mutex);
|
||||
sensor->axis = axis;
|
||||
mutex_unlock(&sensor->data_mutex);
|
||||
|
||||
if (sensor->pdata->irq_enable) {
|
||||
value = sensor_read_reg(client, sensor->ops->int_status_reg);
|
||||
|
|
@ -226,7 +219,7 @@ struct sensor_operate gyro_lsm330_ops = {
|
|||
.precision = 16,
|
||||
.ctrl_reg = CTRL_REG1_G,
|
||||
.int_status_reg = INT1_SRC_G,
|
||||
.range = {-0xffff, 0xffff},
|
||||
.range = {-32768, 32768},
|
||||
.trig = IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
|
||||
.active = sensor_active,
|
||||
.init = sensor_init,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue