summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-08-25 18:22:24 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-08-29 00:04:15 -0700
commit7a2299163b7769b546db53c0dd225eee9e0a0df1 (patch)
tree6fed3596ec94354b08d85ce2b65621aedd2794e2
parent252dce9bd3d70b09e33aba17580ad11d1203ee73 (diff)
downloadchrome-ec-7a2299163b7769b546db53c0dd225eee9e0a0df1.tar.gz
driver: change get_ interface.
Simplify sensor get_data_rate, get_range and get_resolution. Error code was not checked and these functions as currently implemented have no reason to fail. BRANCH=ryu,samus,cyan,strago BUG=chromium:513458 TEST=Check on ryu, compile Change-Id: I40dca41cee29a19f65b2f84d434b4c19eb6cbf3c Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/295635 Reviewed-by: Sheng-liang Song <ssl@chromium.org>
-rw-r--r--common/gesture.c5
-rw-r--r--common/motion_sense.c19
-rw-r--r--driver/accel_kxcj9.c28
-rw-r--r--driver/accelgyro_bmi160.c23
-rw-r--r--driver/accelgyro_lsm6ds0.c23
-rw-r--r--driver/als_si114x.c22
-rw-r--r--include/accelgyro.h9
7 files changed, 48 insertions, 81 deletions
diff --git a/common/gesture.c b/common/gesture.c
index 6c37d34e0e..51a77ce0ab 100644
--- a/common/gesture.c
+++ b/common/gesture.c
@@ -324,7 +324,7 @@ void gesture_calc(void)
/* Console commands */
static int command_tap_info(int argc, char **argv)
{
- int odr, val;
+ int val;
ccprintf("tap: %s\n", (tap_detection && !lid_is_open()) ?
"on" : "off");
@@ -336,8 +336,7 @@ static int command_tap_info(int argc, char **argv)
}
ccprintf("debug: %s\n", tap_debug ? "on" : "off");
- sensor->drv->get_data_rate(sensor, &odr);
- ccprintf("odr: %d\n", odr);
+ ccprintf("odr: %d\n", sensor->drv->get_data_rate(sensor));
return EC_SUCCESS;
}
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 40d922d1f7..64179750f3 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -119,8 +119,7 @@ static void motion_sense_get_fifo_info(
static inline int motion_sensor_time_to_read(const timestamp_t *ts,
const struct motion_sensor_t *sensor)
{
- int rate;
- sensor->drv->get_data_rate(sensor, &rate);
+ int rate = sensor->drv->get_data_rate(sensor);
if (rate == 0)
return 0;
/*
@@ -703,7 +702,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
}
- sensor->drv->get_data_rate(sensor, &data);
+ data = sensor->drv->get_data_rate(sensor);
/* Save configuration parameter: ODR */
sensor->runtime_config.odr = data;
@@ -732,7 +731,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
}
}
- sensor->drv->get_range(sensor, &data);
+ data = sensor->drv->get_range(sensor);
/* Save configuration parameter: range */
sensor->runtime_config.range = data;
@@ -885,8 +884,8 @@ static int command_accelrange(int argc, char **argv)
round) == EC_ERROR_INVAL)
return EC_ERROR_PARAM2;
} else {
- sensor->drv->get_range(sensor, &data);
- ccprintf("Range for sensor %d: %d\n", id, data);
+ ccprintf("Range for sensor %d: %d\n", id,
+ sensor->drv->get_range(sensor));
}
return EC_SUCCESS;
@@ -932,8 +931,8 @@ static int command_accelresolution(int argc, char **argv)
== EC_ERROR_INVAL)
return EC_ERROR_PARAM2;
} else {
- sensor->drv->get_resolution(sensor, &data);
- ccprintf("Resolution for sensor %d: %d\n", id, data);
+ ccprintf("Resolution for sensor %d: %d\n", id,
+ sensor->drv->get_resolution(sensor));
}
return EC_SUCCESS;
@@ -982,8 +981,8 @@ static int command_accel_data_rate(int argc, char **argv)
motion_sense_set_accel_interval(
NULL, MAX_MOTION_SENSE_WAIT_TIME);
} else {
- sensor->drv->get_data_rate(sensor, &data);
- ccprintf("Data rate for sensor %d: %d\n", id, data);
+ ccprintf("Data rate for sensor %d: %d\n", id,
+ sensor->drv->get_data_rate(sensor));
ccprintf("EC rate for sensor %d: %d\n", id,
SENSOR_EC_RATE(sensor));
ccprintf("Current EC rate: %d\n", accel_interval);
diff --git a/driver/accel_kxcj9.c b/driver/accel_kxcj9.c
index 9df954c3f7..90822854ef 100644
--- a/driver/accel_kxcj9.c
+++ b/driver/accel_kxcj9.c
@@ -207,12 +207,10 @@ static int set_range(const struct motion_sensor_t *s,
return ret;
}
-static int get_range(const struct motion_sensor_t *s,
- int * const range)
+static int get_range(const struct motion_sensor_t *s)
{
struct kxcj9_data *data = s->drv_data;
- *range = ranges[data->sensor_range].val;
- return EC_SUCCESS;
+ return ranges[data->sensor_range].val;
}
static int set_resolution(const struct motion_sensor_t *s,
@@ -252,12 +250,10 @@ static int set_resolution(const struct motion_sensor_t *s,
return ret;
}
-static int get_resolution(const struct motion_sensor_t *s,
- int *res)
+static int get_resolution(const struct motion_sensor_t *s)
{
struct kxcj9_data *data = s->drv_data;
- *res = resolutions[data->sensor_resolution].val;
- return EC_SUCCESS;
+ return resolutions[data->sensor_resolution].val;
}
static int set_data_rate(const struct motion_sensor_t *s,
@@ -294,12 +290,10 @@ static int set_data_rate(const struct motion_sensor_t *s,
return ret;
}
-static int get_data_rate(const struct motion_sensor_t *s,
- int *rate)
+static int get_data_rate(const struct motion_sensor_t *s)
{
struct kxcj9_data *data = s->drv_data;
- *rate = datarates[data->sensor_datarate].val;
- return EC_SUCCESS;
+ return datarates[data->sensor_datarate].val;
}
static int set_offset(const struct motion_sensor_t *s,
@@ -417,7 +411,7 @@ static int read(const struct motion_sensor_t *s, vector_3_t v)
*
* Add calibration offset before returning the data.
*/
- get_resolution(s, &resolution);
+ resolution = get_resolution(s);
for (i = X; i <= Z; i++) {
v[i] = (((int8_t)acc[i * 2 + 1]) << 4) |
(acc[i * 2] >> 4);
@@ -426,7 +420,7 @@ static int read(const struct motion_sensor_t *s, vector_3_t v)
rotate(v, *s->rot_standard_ref, v);
/* apply offset in the device coordinates */
- get_range(s, &range);
+ range = get_range(s);
for (i = X; i <= Z; i++)
v[i] += (data->offset[i] << 5) / range;
@@ -488,7 +482,7 @@ cleanup_exit:
static int init(const struct motion_sensor_t *s)
{
int ret = EC_SUCCESS;
- int cnt = 0, tmp, range, rate;
+ int cnt = 0, tmp;
/*
* This sensor can be powered through an EC reboot, so the state of
@@ -537,10 +531,8 @@ static int init(const struct motion_sensor_t *s)
#ifdef CONFIG_ACCEL_INTERRUPTS
config_interrupt(s);
#endif
- get_range(s, &range);
- get_data_rate(s, &rate);
CPRINTF("[%T %s: Done Init type:0x%X range:%d rate:%d]\n",
- s->name, s->type, range, rate);
+ s->name, s->type, get_range(s), get_data_rate(s));
return ret;
}
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
index 6bddcdfb1d..0960131926 100644
--- a/driver/accelgyro_bmi160.c
+++ b/driver/accelgyro_bmi160.c
@@ -323,13 +323,11 @@ static int set_range(const struct motion_sensor_t *s,
return ret;
}
-static int get_range(const struct motion_sensor_t *s,
- int *range)
+static int get_range(const struct motion_sensor_t *s)
{
struct motion_data_t *data = BMI160_GET_SAVED_DATA(s);
- *range = data->range;
- return EC_SUCCESS;
+ return data->range;
}
static int set_resolution(const struct motion_sensor_t *s,
@@ -340,11 +338,9 @@ static int set_resolution(const struct motion_sensor_t *s,
return EC_SUCCESS;
}
-static int get_resolution(const struct motion_sensor_t *s,
- int *res)
+static int get_resolution(const struct motion_sensor_t *s)
{
- *res = BMI160_RESOLUTION;
- return EC_SUCCESS;
+ return BMI160_RESOLUTION;
}
static int set_data_rate(const struct motion_sensor_t *s,
@@ -442,13 +438,11 @@ accel_cleanup:
return ret;
}
-static int get_data_rate(const struct motion_sensor_t *s,
- int *rate)
+static int get_data_rate(const struct motion_sensor_t *s)
{
struct motion_data_t *data = BMI160_GET_SAVED_DATA(s);
- *rate = data->odr;
- return EC_SUCCESS;
+ return data->odr;
}
static int get_offset(const struct motion_sensor_t *s,
int16_t *offset,
@@ -566,7 +560,7 @@ int perform_calib(const struct motion_sensor_t *s)
{
int ret, val, en_flag, status, timeout = 0, rate;
- get_data_rate(s, &rate);
+ rate = get_data_rate(s);
/*
* Temperary set frequency to 100Hz to get enough data in a short
* period of fime.
@@ -1025,8 +1019,7 @@ static int init(const struct motion_sensor_t *s)
set_range(s, s->runtime_config.range, 0);
CPRINTF("[%T %s: MS Done Init type:0x%X range:%d odr:%d]\n",
- s->name, s->type, s->runtime_config.range,
- s->runtime_config.odr);
+ s->name, s->type, get_range(s), get_data_rate(s));
return ret;
}
diff --git a/driver/accelgyro_lsm6ds0.c b/driver/accelgyro_lsm6ds0.c
index 9aa6644670..dee3e7d622 100644
--- a/driver/accelgyro_lsm6ds0.c
+++ b/driver/accelgyro_lsm6ds0.c
@@ -200,13 +200,11 @@ accel_cleanup:
return ret;
}
-static int get_range(const struct motion_sensor_t *s,
- int *range)
+static int get_range(const struct motion_sensor_t *s)
{
struct lsm6ds0_data *data = s->drv_data;
- *range = data->base.range;
- return EC_SUCCESS;
+ return data->base.range;
}
static int set_resolution(const struct motion_sensor_t *s,
@@ -217,11 +215,9 @@ static int set_resolution(const struct motion_sensor_t *s,
return EC_SUCCESS;
}
-static int get_resolution(const struct motion_sensor_t *s,
- int *res)
+static int get_resolution(const struct motion_sensor_t *s)
{
- *res = LSM6DS0_RESOLUTION;
- return EC_SUCCESS;
+ return LSM6DS0_RESOLUTION;
}
static int set_data_rate(const struct motion_sensor_t *s,
@@ -278,13 +274,11 @@ accel_cleanup:
return ret;
}
-static int get_data_rate(const struct motion_sensor_t *s,
- int *rate)
+static int get_data_rate(const struct motion_sensor_t *s)
{
struct lsm6ds0_data *data = s->drv_data;
- *rate = data->base.odr;
- return EC_SUCCESS;
+ return data->base.odr;
}
static int set_offset(const struct motion_sensor_t *s,
@@ -381,7 +375,7 @@ static int read(const struct motion_sensor_t *s, vector_3_t v)
rotate(v, *s->rot_standard_ref, v);
/* apply offset in the device coordinates */
- get_range(s, &range);
+ range = get_range(s);
for (i = X; i <= Z; i++)
v[i] += (data->offset[i] << 5) / range;
@@ -454,8 +448,7 @@ static int init(const struct motion_sensor_t *s)
}
CPRINTF("[%T %s: MS Done Init type:0x%X range:%d odr:%d]\n",
- s->name, s->type, s->runtime_config.range,
- s->runtime_config.odr);
+ s->name, s->type, get_range(s), get_data_rate(s));
return ret;
}
diff --git a/driver/als_si114x.c b/driver/als_si114x.c
index 6441873ed7..c7a3d0374a 100644
--- a/driver/als_si114x.c
+++ b/driver/als_si114x.c
@@ -391,8 +391,7 @@ static int set_resolution(const struct motion_sensor_t *s,
return ret;
}
-static int get_resolution(const struct motion_sensor_t *s,
- int *res)
+static int get_resolution(const struct motion_sensor_t *s)
{
int ret, reg, val;
if (s->type == MOTIONSENSE_TYPE_PROX)
@@ -404,10 +403,9 @@ static int get_resolution(const struct motion_sensor_t *s,
val = 0;
ret = si114x_param_op(s, SI114X_CMD_PARAM_QUERY, reg, &val);
if (ret != EC_SUCCESS)
- return ret;
+ return -1;
- *res = val & 0x07;
- return EC_SUCCESS;
+ return val & 0x07;
}
static int set_range(const struct motion_sensor_t *s,
@@ -420,21 +418,17 @@ static int set_range(const struct motion_sensor_t *s,
return EC_SUCCESS;
}
-static int get_range(const struct motion_sensor_t *s,
- int *range)
+static int get_range(const struct motion_sensor_t *s)
{
struct si114x_typed_data_t *data = SI114X_GET_TYPED_DATA(s);
- *range = (data->scale << 16) | (data->uscale);
- return EC_SUCCESS;
+ return (data->scale << 16) | (data->uscale);
}
-static int get_data_rate(const struct motion_sensor_t *s,
- int *rate)
+static int get_data_rate(const struct motion_sensor_t *s)
{
/* Sensor in forced mode, rate is used by motion_sense */
struct si114x_typed_data_t *data = SI114X_GET_TYPED_DATA(s);
- *rate = data->rate;
- return EC_SUCCESS;
+ return data->rate;
}
static int set_data_rate(const struct motion_sensor_t *s,
@@ -501,7 +495,7 @@ static int init(const struct motion_sensor_t *s)
set_resolution(s, resol, 0);
CPRINTF("[%T %s: MS Done Init type:0x%X range:%d]\n",
- s->name, s->type, s->runtime_config.range);
+ s->name, s->type, get_range(s));
return EC_SUCCESS;
}
diff --git a/include/accelgyro.h b/include/accelgyro.h
index f4cb542dc6..c65e624bf4 100644
--- a/include/accelgyro.h
+++ b/include/accelgyro.h
@@ -45,8 +45,7 @@ struct accelgyro_drv {
int (*set_range)(const struct motion_sensor_t *s,
int range,
int rnd);
- int (*get_range)(const struct motion_sensor_t *s,
- int *range);
+ int (*get_range)(const struct motion_sensor_t *s);
/**
* Setter and getter methods for the sensor resolution.
@@ -59,8 +58,7 @@ struct accelgyro_drv {
int (*set_resolution)(const struct motion_sensor_t *s,
int res,
int rnd);
- int (*get_resolution)(const struct motion_sensor_t *s,
- int *res);
+ int (*get_resolution)(const struct motion_sensor_t *s);
/**
* Setter and getter methods for the sensor output data range. As the
@@ -74,8 +72,7 @@ struct accelgyro_drv {
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);
+ int (*get_data_rate)(const struct motion_sensor_t *s);
/**