mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-28 02:35:28 +00:00
driver: bmi160: Add temperature sensor
Allow BMI160 to report temperature like other device with a temperature sensor. Temparature is returned in K. Although BMI160 resolution is 9bits per degree, we round to the nearest degree. BUG=chrome-os-partner:58894 BRANCH=reef TEST=After enabling sensor on Reef, check we can measure the temperature with EC console commands temp or from user space with 'ectool temps 3' Check 'ectool tempsinfo 3' returns valid data: Sensor name: Gyro Sensor type: 1 Change-Id: Ib48f988e078cdee1dfbc05b23df806bd4eb09931 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/416297 Reviewed-by: Scott Collyer <scollyer@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
f50b1cec17
commit
e2e875c566
@@ -1261,3 +1261,19 @@ struct i2c_stress_test_dev bmi160_i2c_stress_test_dev = {
|
||||
.i2c_write = &raw_write8,
|
||||
};
|
||||
#endif /* CONFIG_CMD_I2C_STRESS_TEST_ACCEL */
|
||||
|
||||
int bmi160_get_sensor_temp(int idx, int *temp_ptr)
|
||||
{
|
||||
struct motion_sensor_t *s = &motion_sensors[idx];
|
||||
int16_t temp;
|
||||
int ret;
|
||||
|
||||
ret = raw_read_n(s->port, s->addr, BMI160_TEMPERATURE_0,
|
||||
(uint8_t *)&temp, sizeof(temp));
|
||||
|
||||
if (ret || temp == BMI160_INVALID_TEMP)
|
||||
return EC_ERROR_NOT_POWERED;
|
||||
|
||||
*temp_ptr = C_TO_K(23 + ((temp + 256) >> 9));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -127,6 +127,8 @@
|
||||
|
||||
#define BMI160_TEMPERATURE_0 0x20
|
||||
#define BMI160_TEMPERATURE_1 0x21
|
||||
#define BMI160_INVALID_TEMP 0x8000
|
||||
|
||||
|
||||
#define BMI160_FIFO_LENGTH_0 0x22
|
||||
#define BMI160_FIFO_LENGTH_1 0x23
|
||||
@@ -463,4 +465,5 @@ int raw_mag_write8(const int port, const int addr, const uint8_t reg, int data);
|
||||
extern struct i2c_stress_test_dev bmi160_i2c_stress_test_dev;
|
||||
#endif
|
||||
|
||||
int bmi160_get_sensor_temp(int idx, int *temp_ptr);
|
||||
#endif /* __CROS_EC_ACCELGYRO_BMI160_H */
|
||||
|
||||
Reference in New Issue
Block a user