- Added support for TMP117 in existing driver for TMP116
The Texas Instruments TMP117 is a higher precision upgrade
from TMP116. It shares most functionality, but has a
differing device ID.
This patch will run with the hardware IDs of both devices.
- Fixed an int promote issue in tmp116_channel_get
Negative temperature values in drv_data->sample were not
processed correctly.
The error occured during integer promotion from u16_t to s32_t
in this code line:
tmp = (s32_t)drv_data->sample * TMP116_RESOLUTION;
By first promoting to s16_t, the correct result is obtained:
tmp = (s16_t)drv_data->sample * (s32_t)TMP116_RESOLUTION;
- Made temperature resolution compatible to sensor API
The fractional part of the temperature was returned as a
multiple of 10^-7 deg.Celsius.
This differs from the resolution sugegsted by the sensor API,
which is 10^-6.
The driver is now returning temperature readings with
a resolution of 10^-6 deg. Celsius.
- The changed driver was tested using following hardware:
TMP117 attached to disco_l475_iot1 via i2c1
Signed-off-by: Hans Wilmers <hans@wilmers.no>
37 lines
844 B
C
37 lines
844 B
C
/*
|
|
* Copyright (c) 2019 Centaur Analytics, Inc
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#ifndef ZEPHYR_DRIVERS_SENSOR_TMP116_TMP116_H_
|
|
#define ZEPHYR_DRIVERS_SENSOR_TMP116_TMP116_H_
|
|
|
|
#define TMP116_REG_TEMP 0x0
|
|
#define TMP116_REG_CFGR 0x1
|
|
#define TMP116_REG_HIGH_LIM 0x2
|
|
#define TMP116_REG_LOW_LIM 0x3
|
|
#define TMP116_REG_EEPROM_UL 0x4
|
|
#define TMP116_REG_EEPROM1 0x5
|
|
#define TMP116_REG_EEPROM2 0x6
|
|
#define TMP116_REG_EEPROM3 0x7
|
|
#define TMP116_REG_EEPROM4 0x8
|
|
#define TMP116_REG_DEVICE_ID 0xF
|
|
|
|
#define TMP116_RESOLUTION 78125 /* in tens of uCelsius*/
|
|
#define TMP116_RESOLUTION_DIV 10000000
|
|
|
|
#define TMP116_DEVICE_ID 0x1116
|
|
#define TMP117_DEVICE_ID 0x0117
|
|
|
|
struct tmp116_data {
|
|
struct device *i2c;
|
|
u16_t sample;
|
|
};
|
|
|
|
struct tmp116_dev_config {
|
|
u16_t i2c_addr;
|
|
};
|
|
|
|
#endif /* ZEPHYR_DRIVERS_SENSOR_TMP116_TMP116_H_ */
|