sensor: th02: Convert to DTS

Convert th02 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:
Kumar Gala 2019-11-07 04:19:27 -06:00 committed by Maureen Helm
parent 2f965a1fb0
commit 0e9e67297e
6 changed files with 36 additions and 20 deletions

View file

@ -1,24 +1,8 @@
# Copyright (c) 2016 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
menuconfig TH02
config TH02
bool "TH02 Temperature Sensor"
depends on I2C
help
Enable driver for the TH02 temperature sensor.
if TH02
config TH02_NAME
string "Driver name"
default "TH02"
help
Device name with which the TH02 sensor is identified.
config TH02_I2C_MASTER_DEV_NAME
string "I2C Master"
default "I2C_0"
help
The device name of the I2C master device to which the TH02
chip is connected.
endif

View file

@ -126,10 +126,10 @@ static int th02_init(struct device *dev)
{
struct th02_data *drv_data = dev->driver_data;
drv_data->i2c = device_get_binding(CONFIG_TH02_I2C_MASTER_DEV_NAME);
drv_data->i2c = device_get_binding(DT_INST_0_HOPERF_TH02_BUS_NAME);
if (drv_data->i2c == NULL) {
LOG_ERR("Failed to get pointer to %s device!",
CONFIG_TH02_I2C_MASTER_DEV_NAME);
DT_INST_0_HOPERF_TH02_BUS_NAME);
return -EINVAL;
}
@ -138,6 +138,6 @@ static int th02_init(struct device *dev)
static struct th02_data th02_driver;
DEVICE_AND_API_INIT(th02, CONFIG_TH02_NAME, th02_init, &th02_driver,
DEVICE_AND_API_INIT(th02, DT_INST_0_HOPERF_TH02_LABEL, th02_init, &th02_driver,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&th02_driver_api);

View file

@ -0,0 +1,12 @@
# Copyright (c) 2019, Linaro Limited
# SPDX-License-Identifier: Apache-2.0
title: TH02 Temperature and Humidity sensor
description: |
TH02 Temperature and Humidity sensor. See datasheet at
http://www.datasheetspdf.com/mobile/748107/TH02.html
compatible: "hoperf,th02"
include: i2c-device.yaml

View file

@ -0,0 +1,13 @@
/*
* Copyright (c) 2019, Linaro Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
&i2c0 {
th02@40 {
compatible = "hoperf,th02";
reg = <0x40>;
label = "TH02";
};
};

View file

@ -5,3 +5,4 @@ tests:
harness: sensor
tags: sensors
depends_on: i2c
filter: dt_compat_enabled("hoperf,th02")

View file

@ -312,6 +312,12 @@
#define DT_INST_0_ATMEL_AT24_TIMEOUT 5
#endif
#ifndef DT_INST_0_HOPERF_TH02_LABEL
#define DT_INST_0_HOPERF_TH02_LABEL ""
#define DT_INST_0_HOPERF_TH02_BUS_NAME ""
#define DT_INST_0_HOPERF_TH02_BASE_ADDRESS 0
#endif
#endif /* CONFIG_HAS_DTS_I2C */
#ifndef DT_ADXL372_DEV_NAME