From aa684363f01d8446b76f0b8aaa648274edcd250d Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Fri, 18 Jan 2019 12:54:36 -0600 Subject: [PATCH] drivers: sht3xd: update to new I2C API Use the new i2c_write_read() wrapper to simplify the code. Also add several overlays used to test the sensor on a variety of boards, and conf file support for trigger testing. Signed-off-by: Peter A. Bigot --- drivers/sensor/sht3xd/sht3xd.c | 16 ++-------------- samples/sensor/sht3xd/efr32mg_sltb004a.overlay | 14 ++++++++++++++ samples/sensor/sht3xd/frdm_k64f.overlay | 14 ++++++++++++++ samples/sensor/sht3xd/nrf51_ble400.overlay | 4 ++-- samples/sensor/sht3xd/nrf52840_pca10056.overlay | 14 ++++++++++++++ samples/sensor/sht3xd/nucleo_l476rg.overlay | 15 +++++++++++++++ samples/sensor/sht3xd/sample.yaml | 9 ++++++++- samples/sensor/sht3xd/trigger.conf | 12 ++++++++++++ 8 files changed, 81 insertions(+), 17 deletions(-) create mode 100644 samples/sensor/sht3xd/efr32mg_sltb004a.overlay create mode 100644 samples/sensor/sht3xd/frdm_k64f.overlay create mode 100644 samples/sensor/sht3xd/nrf52840_pca10056.overlay create mode 100644 samples/sensor/sht3xd/nucleo_l476rg.overlay create mode 100644 samples/sensor/sht3xd/trigger.conf diff --git a/drivers/sensor/sht3xd/sht3xd.c b/drivers/sensor/sht3xd/sht3xd.c index 5eb5ff46a4..2c917cdcc9 100644 --- a/drivers/sensor/sht3xd/sht3xd.c +++ b/drivers/sensor/sht3xd/sht3xd.c @@ -90,20 +90,8 @@ static int sht3xd_sample_fetch(struct device *dev, enum sensor_channel chan) SHT3XD_CMD_FETCH & 0xFF }; - struct i2c_msg msgs[2] = { - { - .buf = tx_buf, - .len = sizeof(tx_buf), - .flags = I2C_MSG_WRITE | I2C_MSG_RESTART, - }, - { - .buf = rx_buf, - .len = sizeof(rx_buf), - .flags = I2C_MSG_READ | I2C_MSG_STOP, - }, - }; - - if (i2c_transfer(i2c, msgs, 2, address) < 0) { + if (i2c_write_read(i2c, address, tx_buf, sizeof(tx_buf), + rx_buf, sizeof(rx_buf)) < 0) { LOG_DBG("Failed to read data sample!"); return -EIO; } diff --git a/samples/sensor/sht3xd/efr32mg_sltb004a.overlay b/samples/sensor/sht3xd/efr32mg_sltb004a.overlay new file mode 100644 index 0000000000..529c5673c2 --- /dev/null +++ b/samples/sensor/sht3xd/efr32mg_sltb004a.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2018-2019 Peter Bigot Consulting, LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c0 { /* SDA H16=PC10, SCL H15=PC11, ALERT H13=PF6 */ + sht3xd@44 { + compatible = "sensirion,sht3xd"; + reg = <0x44>; + label = "SHT3XD"; + alert-gpios = <&gpiof 6 GPIO_INT_ACTIVE_HIGH>; + }; +}; diff --git a/samples/sensor/sht3xd/frdm_k64f.overlay b/samples/sensor/sht3xd/frdm_k64f.overlay new file mode 100644 index 0000000000..ffd32e4031 --- /dev/null +++ b/samples/sensor/sht3xd/frdm_k64f.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 Peter Bigot Consulting, LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c0 { /* SDA PTE25, SCL PTE24, ALERT PTE26 */ + sht3xd@44 { + compatible = "sensirion,sht3xd"; + reg = <0x44>; + label = "SHT3XD"; + alert-gpios = <&gpioe 26 GPIO_INT_ACTIVE_HIGH>; + }; +}; diff --git a/samples/sensor/sht3xd/nrf51_ble400.overlay b/samples/sensor/sht3xd/nrf51_ble400.overlay index c8f23b8f5c..1b7aca973e 100644 --- a/samples/sensor/sht3xd/nrf51_ble400.overlay +++ b/samples/sensor/sht3xd/nrf51_ble400.overlay @@ -1,10 +1,10 @@ /* - * Copyright (c) 2018 Peter Bigot Consulting, LLC + * Copyright (c) 2018-2019 Peter Bigot Consulting, LLC * * SPDX-License-Identifier: Apache-2.0 */ -&i2c0 { +&i2c0 { /* SDA 0, SCL 1 */ sht3xd@44 { compatible = "sensirion,sht3xd"; reg = <0x44>; diff --git a/samples/sensor/sht3xd/nrf52840_pca10056.overlay b/samples/sensor/sht3xd/nrf52840_pca10056.overlay new file mode 100644 index 0000000000..736dba5054 --- /dev/null +++ b/samples/sensor/sht3xd/nrf52840_pca10056.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2018-2019 Peter Bigot Consulting, LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c0 { /* SDA P0.26, SCL P0.27, ALERT P1.10 */ + sht3xd@44 { + compatible = "sensirion,sht3xd"; + reg = <0x44>; + label = "SHT3XD"; + alert-gpios = <&gpio1 10 GPIO_INT_ACTIVE_HIGH>; + }; +}; diff --git a/samples/sensor/sht3xd/nucleo_l476rg.overlay b/samples/sensor/sht3xd/nucleo_l476rg.overlay new file mode 100644 index 0000000000..5e972fcc9e --- /dev/null +++ b/samples/sensor/sht3xd/nucleo_l476rg.overlay @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2019 Peter Bigot Consulting, LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c1 { /* SDA CN5.9=PB9, SCL CN5.10=PB8, ALERT CN5.1=D8=PA9 */ +/* &i2c3 { * SDA CN7.36=PC1, SCL CN7.38=PC0, ALERT CN7.34=PB0 */ + sht3xd@44 { + compatible = "sensirion,sht3xd"; + reg = <0x44>; + label = "SHT3XD"; + alert-gpios = <&gpioa 9 GPIO_INT_ACTIVE_HIGH>; + }; +}; diff --git a/samples/sensor/sht3xd/sample.yaml b/samples/sensor/sht3xd/sample.yaml index 2a417b264d..4d253fc02f 100644 --- a/samples/sensor/sht3xd/sample.yaml +++ b/samples/sensor/sht3xd/sample.yaml @@ -9,5 +9,12 @@ sample: tests: test: build_only: true - platform_whitelist: nrf51_ble400 + platform_whitelist: efr32mg_sltb004a frdm_k64f nrf51_ble400 + nrf52840_pca10056 nucleo_l476rg + tags: sensors + test_trigger: + build_only: true + extra_args: CONF_FILE="trigger.conf" + platform_whitelist: efr32mg_sltb004a frdm_k64f nrf51_ble400 + nrf52840_pca10056 nucleo_l476rg tags: sensors diff --git a/samples/sensor/sht3xd/trigger.conf b/samples/sensor/sht3xd/trigger.conf new file mode 100644 index 0000000000..f0f06d981c --- /dev/null +++ b/samples/sensor/sht3xd/trigger.conf @@ -0,0 +1,12 @@ +# +# Copyright (c) 2019 Peter Bigot Consulting, LLC +# +# SPDX-License-Identifier: Apache-2.0 +# + +CONFIG_STDOUT_CONSOLE=y +CONFIG_I2C=y +CONFIG_SENSOR=y +CONFIG_SHT3XD=y +CONFIG_SHT3XD_TRIGGER=y +CONFIG_SHT3XD_TRIGGER_GLOBAL_THREAD=y