sensor: tmp112: Convert to DTS
Convert tmp112 sensor driver and sample app to utilize device tree. Introduce a dts board overlay on the frdm_k64f board to ensure we at least have a single platform in which the sample gets built. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
0e9e67297e
commit
b388b178a0
6 changed files with 37 additions and 34 deletions
|
@ -3,7 +3,7 @@
|
|||
# Copyright (c) 2016 Firmwave
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menuconfig TMP112
|
||||
config TMP112
|
||||
bool "TMP112 Temperature Sensor"
|
||||
depends on I2C
|
||||
help
|
||||
|
@ -12,32 +12,3 @@ menuconfig TMP112
|
|||
|
||||
The TMP102 is compatible with the TMP112 but is less accurate and has
|
||||
been successfully tested with this driver.
|
||||
|
||||
if TMP112
|
||||
|
||||
config TMP112_NAME
|
||||
string "Driver name"
|
||||
default "TMP112"
|
||||
help
|
||||
Device name with which the TMP112 sensor is identified.
|
||||
|
||||
config TMP112_I2C_ADDR
|
||||
hex "I2C address for TMP112"
|
||||
default 0x48
|
||||
help
|
||||
I2C address of the TMP112 sensor.
|
||||
|
||||
0x48: A0 connected GND and A1 connected to GND.
|
||||
0x49: A0 connected VDD and A1 connected to GND.
|
||||
0x4A: A0 connected SDA and A1 connected to GND.
|
||||
0x4B: A0 connected SCL and A1 connected to GND.
|
||||
|
||||
|
||||
config TMP112_I2C_MASTER_DEV_NAME
|
||||
string "I2C master where TMP112 is connected"
|
||||
default "I2C_0"
|
||||
help
|
||||
Specify the device name of the I2C master device to which the
|
||||
TMP112 chip is connected.
|
||||
|
||||
endif # TMP112
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
LOG_MODULE_REGISTER(TMP112, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
#define TMP112_I2C_ADDRESS CONFIG_TMP112_I2C_ADDR
|
||||
#define TMP112_I2C_ADDRESS DT_INST_0_TI_TMP112_BASE_ADDRESS
|
||||
|
||||
#define TMP112_REG_TEMPERATURE 0x00
|
||||
#define TMP112_D0_BIT BIT(0)
|
||||
|
@ -195,10 +195,10 @@ int tmp112_init(struct device *dev)
|
|||
{
|
||||
struct tmp112_data *drv_data = dev->driver_data;
|
||||
|
||||
drv_data->i2c = device_get_binding(CONFIG_TMP112_I2C_MASTER_DEV_NAME);
|
||||
drv_data->i2c = device_get_binding(DT_INST_0_TI_TMP112_BUS_NAME);
|
||||
if (drv_data->i2c == NULL) {
|
||||
LOG_DBG("Failed to get pointer to %s device!",
|
||||
CONFIG_TMP112_I2C_MASTER_DEV_NAME);
|
||||
DT_INST_0_TI_TMP112_BUS_NAME);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -207,5 +207,5 @@ int tmp112_init(struct device *dev)
|
|||
|
||||
static struct tmp112_data tmp112_driver;
|
||||
|
||||
DEVICE_AND_API_INIT(tmp112, CONFIG_TMP112_NAME, tmp112_init, &tmp112_driver,
|
||||
DEVICE_AND_API_INIT(tmp112, DT_INST_0_TI_TMP112_LABEL, tmp112_init, &tmp112_driver,
|
||||
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &tmp112_driver_api);
|
||||
|
|
12
dts/bindings/sensor/ti,tmp112.yaml
Normal file
12
dts/bindings/sensor/ti,tmp112.yaml
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Copyright (c) 2019, Linaro Limited
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
title: TI TMP112 Digital Temperature Sensor
|
||||
|
||||
description: |
|
||||
TMP112 Digital Temperature Sensor. See more info at
|
||||
https://www.ti.com/product/TMP112
|
||||
|
||||
compatible: "ti,tmp112"
|
||||
|
||||
include: i2c-device.yaml
|
13
samples/sensor/tmp112/boards/frdm_k64f.overlay
Normal file
13
samples/sensor/tmp112/boards/frdm_k64f.overlay
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Copyright (c) 2019, Linaro Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&i2c0 {
|
||||
tmp112@4a {
|
||||
compatible = "ti,tmp112";
|
||||
reg = <0x4a>;
|
||||
label = "TMP112";
|
||||
};
|
||||
};
|
|
@ -5,6 +5,7 @@ tests:
|
|||
harness: console
|
||||
tags: sensors
|
||||
depends_on: i2c
|
||||
filter: dt_compat_enabled("ti,tmp112")
|
||||
harness_config:
|
||||
type: one_line
|
||||
regex:
|
||||
|
|
|
@ -318,6 +318,12 @@
|
|||
#define DT_INST_0_HOPERF_TH02_BASE_ADDRESS 0
|
||||
#endif
|
||||
|
||||
#ifndef DT_INST_0_TI_TMP112_LABEL
|
||||
#define DT_INST_0_TI_TMP112_LABEL ""
|
||||
#define DT_INST_0_TI_TMP112_BASE_ADDRESS 0
|
||||
#define DT_INST_0_TI_TMP112_BUS_NAME ""
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_HAS_DTS_I2C */
|
||||
|
||||
#ifndef DT_ADXL372_DEV_NAME
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue