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 <pab@pabigot.com>
This commit is contained in:
parent
46072632bd
commit
aa684363f0
|
@ -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;
|
||||
}
|
||||
|
|
14
samples/sensor/sht3xd/efr32mg_sltb004a.overlay
Normal file
14
samples/sensor/sht3xd/efr32mg_sltb004a.overlay
Normal file
|
@ -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>;
|
||||
};
|
||||
};
|
14
samples/sensor/sht3xd/frdm_k64f.overlay
Normal file
14
samples/sensor/sht3xd/frdm_k64f.overlay
Normal file
|
@ -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>;
|
||||
};
|
||||
};
|
|
@ -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>;
|
||||
|
|
14
samples/sensor/sht3xd/nrf52840_pca10056.overlay
Normal file
14
samples/sensor/sht3xd/nrf52840_pca10056.overlay
Normal file
|
@ -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>;
|
||||
};
|
||||
};
|
15
samples/sensor/sht3xd/nucleo_l476rg.overlay
Normal file
15
samples/sensor/sht3xd/nucleo_l476rg.overlay
Normal file
|
@ -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>;
|
||||
};
|
||||
};
|
|
@ -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
|
||||
|
|
12
samples/sensor/sht3xd/trigger.conf
Normal file
12
samples/sensor/sht3xd/trigger.conf
Normal file
|
@ -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
|
Loading…
Reference in a new issue