diff --git a/dist/tools/doccheck/exclude_patterns b/dist/tools/doccheck/exclude_patterns index 0ff5d9fbf3..ddd8f7e258 100644 --- a/dist/tools/doccheck/exclude_patterns +++ b/dist/tools/doccheck/exclude_patterns @@ -10031,7 +10031,6 @@ drivers/include/sht2x\.h:[0-9]+: warning: Member SHT2X_USER_EOB_MASK \(macro def drivers/include/sht2x\.h:[0-9]+: warning: Member SHT2X_USER_HEATER_MASK \(macro definition\) of group drivers_sht2x is not documented\. drivers/include/sht2x\.h:[0-9]+: warning: Member SHT2X_USER_OTP_MASK \(macro definition\) of group drivers_sht2x is not documented\. drivers/include/sht2x\.h:[0-9]+: warning: Member SHT2X_USER_RESERVED_MASK \(macro definition\) of group drivers_sht2x is not documented\. -drivers/include/shtc1\.h:[0-9]+: warning: unbalanced grouping commands drivers/include/sx127x\.h:[0-9]+: warning: Member SX127X_CHANNEL_HOPPING_FLAG \(macro definition\) of group drivers_sx127x is not documented\. drivers/include/sx127x\.h:[0-9]+: warning: Member SX127X_ENABLE_CRC_FLAG \(macro definition\) of group drivers_sx127x is not documented\. drivers/include/sx127x\.h:[0-9]+: warning: Member SX127X_ENABLE_FIXED_HEADER_LENGTH_FLAG \(macro definition\) of group drivers_sx127x is not documented\. @@ -11966,10 +11965,10 @@ drivers/sht3x/include/sht3x_params\.h:[0-9]+: warning: Member SHT3X_PARAM_I2C_DE drivers/sht3x/include/sht3x_params\.h:[0-9]+: warning: Member SHT3X_PARAM_MODE \(macro definition\) of file sht3x_params\.h is not documented\. drivers/sht3x/include/sht3x_params\.h:[0-9]+: warning: Member SHT3X_PARAM_REPEAT \(macro definition\) of file sht3x_params\.h is not documented\. drivers/sht3x/include/sht3x_params\.h:[0-9]+: warning: Member SHT3X_SAUL_INFO \(macro definition\) of file sht3x_params\.h is not documented\. -drivers/shtc1/include/shtc1_params\.h:[0-9]+: warning: Member SHTC1_PARAMS \(macro definition\) of file shtc1_params\.h is not documented\. -drivers/shtc1/include/shtc1_params\.h:[0-9]+: warning: Member SHTC1_PARAM_I2C_ADDR \(macro definition\) of file shtc1_params\.h is not documented\. -drivers/shtc1/include/shtc1_params\.h:[0-9]+: warning: Member SHTC1_PARAM_I2C_DEV \(macro definition\) of file shtc1_params\.h is not documented\. -drivers/shtc1/include/shtc1_params\.h:[0-9]+: warning: Member SHTC1_SAUL_INFO \(macro definition\) of file shtc1_params\.h is not documented\. +drivers/shtcx/include/shtcx_params\.h:[0-9]+: warning: Member SHTCX_PARAMS \(macro definition\) of file shtcx_params\.h is not documented\. +drivers/shtcx/include/shtcx_params\.h:[0-9]+: warning: Member SHTCX_PARAM_I2C_ADDR \(macro definition\) of file shtcx_params\.h is not documented\. +drivers/shtcx/include/shtcx_params\.h:[0-9]+: warning: Member SHTCX_PARAM_I2C_DEV \(macro definition\) of file shtcx_params\.h is not documented\. +drivers/shtcx/include/shtcx_params\.h:[0-9]+: warning: Member SHTCX_SAUL_INFO \(macro definition\) of file shtcx_params\.h is not documented\. drivers/si1133/include/si1133_internals\.h:[0-9]+: warning: Member SI1133_ADCCONFIG_ADCMUX_MASK \(macro definition\) of file si1133_internals\.h is not documented\. drivers/si1133/include/si1133_internals\.h:[0-9]+: warning: Member SI1133_ADCCONFIG_ADCMUX_SHIFT \(macro definition\) of file si1133_internals\.h is not documented\. drivers/si1133/include/si1133_internals\.h:[0-9]+: warning: Member SI1133_ADCCONFIG_DECIM_RATE_MASK \(macro definition\) of file si1133_internals\.h is not documented\. diff --git a/drivers/Kconfig b/drivers/Kconfig index 2ba182e309..aec35ab748 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -129,7 +129,7 @@ rsource "seesaw_soil/Kconfig" rsource "sht1x/Kconfig" rsource "sht2x/Kconfig" rsource "sht3x/Kconfig" -rsource "shtc1/Kconfig" +rsource "shtcx/Kconfig" rsource "si70xx/Kconfig" rsource "si114x/Kconfig" rsource "si1133/Kconfig" diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index a8bf37de77..84dc17307d 100644 --- a/drivers/Makefile.dep +++ b/drivers/Makefile.dep @@ -163,6 +163,10 @@ ifneq (,$(filter sht1%,$(USEMODULE))) USEMODULE += sht1x endif +ifneq (,$(filter shtc%,$(USEMODULE))) + USEMODULE += shtcx +endif + ifneq (,$(filter si114%,$(USEMODULE))) USEMODULE += si114x endif diff --git a/drivers/include/shtc1.h b/drivers/include/shtcx.h similarity index 51% rename from drivers/include/shtc1.h rename to drivers/include/shtcx.h index 6d9da30bda..1c6c88637b 100644 --- a/drivers/include/shtc1.h +++ b/drivers/include/shtcx.h @@ -7,20 +7,22 @@ */ /** - * @defgroup drivers_shtc1 SHTC1 Temperature and humidity sensor + * @defgroup drivers_shtcx SHTCX Temperature and humidity sensor * @ingroup drivers_sensors * @ingroup drivers_saul - * @brief Driver for the Sensirion SHTC1 sensor. + * @brief Driver for the Sensirion SHTCX sensor. + * + * @{ * * @file - * @brief Device driver interface for the SHTC1 Temperature and humidity sensor + * @brief Device driver interface for the SHTCX Temperature and humidity sensor * * @author Steffen Robertz * @author Josua Arndt */ -#ifndef SHTC1_H -#define SHTC1_H +#ifndef SHTCX_H +#define SHTCX_H #include #include "saul.h" @@ -32,11 +34,11 @@ extern "C" { #endif /** - * @brief SHTC1 Default Address + * @brief SHTCX Default Address * */ -#ifndef SHTC1_I2C_ADDRESS -#define SHTC1_I2C_ADDRESS (0x70) +#ifndef SHTCX_I2C_ADDRESS +#define SHTCX_I2C_ADDRESS (0x70) #endif /** @@ -46,36 +48,36 @@ extern "C" { typedef struct { i2c_t i2c_dev; /**< I2C bus descriptor. */ uint8_t i2c_addr; /**< I2C address of the sensor. */ -} shtc1_params_t; +} shtcx_params_t; /** @} */ /** - * @brief device descriptor for the SHTC1 + * @brief device descriptor for the SHTCX * @{ */ typedef struct { - shtc1_params_t params; /**< Parameters struct with all settings set. */ -} shtc1_t; + shtcx_params_t params; /**< Parameters struct with all settings set. */ +} shtcx_t; /** @} */ enum { - SHTC1_OK, /**< Success, no error */ - SHTC1_ERROR_BUS, /**< I2C bus error */ - SHTC1_ERROR_CRC, /**< CRC error */ - SHTC1_ERROR /**< General error */ + SHTCX_OK, /**< Success, no error */ + SHTCX_ERROR_BUS, /**< I2C bus error */ + SHTCX_ERROR_CRC, /**< CRC error */ + SHTCX_ERROR /**< General error */ }; /** * @brief Initializes the sensor and I2C. * * @param[in] dev I2C device descriptor. - * @param[in] params SHTC1 parameters to be used. + * @param[in] params SHTCX parameters to be used. * - * @return SHTC1_OK on a working initialization. - * @return SHTC1_ERROR_BUS Reading I2C failed. - * @return SHTC1_ERROR_CRC Wrong ID. + * @return SHTCX_OK on a working initialization. + * @return SHTCX_ERROR_BUS Reading I2C failed. + * @return SHTCX_ERROR_CRC Wrong ID. */ -int8_t shtc1_init(shtc1_t* const dev, const shtc1_params_t* params); +int8_t shtcx_init(shtcx_t* const dev, const shtcx_params_t* params); /** * @brief Reads all register values from the device. @@ -85,24 +87,25 @@ int8_t shtc1_init(shtc1_t* const dev, const shtc1_params_t* params); * @param[in] rel_humidity Humidity in centi %. * @param[in] temperature Temperature in centi °C. * - * @return SHTC1_OK if a measurement completed. - * @return SHTC1_ERROR_BUS reading I2C failed. - * @return SHTC1_ERROR_CRC on checksum error. + * @return SHTCX_OK if a measurement completed. + * @return SHTCX_ERROR_BUS reading I2C failed. + * @return SHTCX_ERROR_CRC on checksum error. */ -int8_t shtc1_read(const shtc1_t *dev, uint16_t *rel_humidity, int16_t *temperature); +int8_t shtcx_read(const shtcx_t *dev, uint16_t *rel_humidity, int16_t *temperature); /** * @brief Reads the ID and saves it in the device descriptor * - * @details When working correctly ID should equal xxxx'xxxx'xx00'0111 where x is unspecified. + * @details When working correctly ID should equal + * xxxx'xxxx'xx00'0111 where x is unspecified. * * @param[in] dev The I2C device descriptor. * @param[in] id ID of the device. * - * @return SHTC1_OK on everything done. - * @return SHTC1_ERROR_BUS on error. + * @return SHTCX_OK on everything done. + * @return SHTCX_ERROR_BUS on error. */ -int8_t shtc1_id(const shtc1_t *dev, uint16_t *id); +int8_t shtcx_id(const shtcx_t *dev, uint16_t *id); /** * @brief Resets sensor @@ -111,14 +114,14 @@ int8_t shtc1_id(const shtc1_t *dev, uint16_t *id); * * @param[in] dev The I2C device descriptor. * - * @return SHTC1_OK on everything done. - * @return SHTC1_ERROR_BUS on error. + * @return SHTCX_OK on everything done. + * @return SHTCX_ERROR_BUS on error. */ -int8_t shtc1_reset(const shtc1_t *dev); +int8_t shtcx_reset(const shtcx_t *dev); #ifdef __cplusplus } #endif -#endif /* SHTC1_H */ +#endif /* SHTCX_H */ /** @} */ diff --git a/drivers/saul/init_devs/auto_init_shtc1.c b/drivers/saul/init_devs/auto_init_shtc1.c deleted file mode 100644 index 85fc765aaf..0000000000 --- a/drivers/saul/init_devs/auto_init_shtc1.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2019 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - * - */ - -/** - * @ingroup sys_auto_init_saul - * @{ - * - * @file - * @brief Auto initialization of shtc1 Digital Humidity Sensor - * - * @author Michel Gerlach - * - * @} - */ - - #include "assert.h" - #include "log.h" - #include "saul_reg.h" - - #include "shtc1.h" - #include "shtc1_params.h" - - /** - * @brief Define the number of configured sensors - */ - #define SHTC1_NUM ARRAY_SIZE(shtc1_params) - - /** - * @brief Allocate memory for the device descriptors - */ - static shtc1_t shtc1_devs[SHTC1_NUM]; - - /** - * @brief Memory for the SAUL registry entries - */ - static saul_reg_t saul_entries[SHTC1_NUM * 2]; - - /** - * @brief Define the number of saul info - */ - #define SHTC1_INFO_NUM ARRAY_SIZE(shtc1_saul_info) - - /** - * @brief Reference the driver struct - */ - extern const saul_driver_t shtc1_temperature_saul_driver; - extern const saul_driver_t shtc1_relative_humidity_saul_driver; - - void auto_init_shtc1(void) - { - assert(SHTC1_NUM == SHTC1_INFO_NUM); - - for (unsigned i = 0; i < SHTC1_NUM; i++) { - LOG_DEBUG("[auto_init_saul] initializing shtc1 #%u\n", i); - - if (shtc1_init(&shtc1_devs[i], &shtc1_params[i]) != SHTC1_OK) { - LOG_ERROR("[auto_init_saul] error initializing shtc1 #%u\n", i); - continue; - } - /* temperature */ - saul_entries[(i * 2)].dev = &(shtc1_devs[i]); - saul_entries[(i * 2)].name = shtc1_saul_info[i].name; - saul_entries[(i * 2)].driver = &shtc1_temperature_saul_driver; - - /* Humidity */ - saul_entries[(i * 2)+1].dev = &(shtc1_devs[i]); - saul_entries[(i * 2)+1].name = shtc1_saul_info[i].name; - saul_entries[(i * 2)+1].driver = &shtc1_relative_humidity_saul_driver; - - saul_reg_add(&(saul_entries[(i * 2)])); - saul_reg_add(&(saul_entries[(i * 2)+1])); - } - } diff --git a/drivers/saul/init_devs/auto_init_shtcx.c b/drivers/saul/init_devs/auto_init_shtcx.c new file mode 100644 index 0000000000..b96e720a90 --- /dev/null +++ b/drivers/saul/init_devs/auto_init_shtcx.c @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2019 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + * + */ + +/** + * @ingroup sys_auto_init_saul + * @{ + * + * @file + * @brief Auto initialization of shtcx Digital Humidity Sensor + * + * @author Michel Gerlach + * + * @} + */ + + #include "assert.h" + #include "log.h" + #include "saul_reg.h" + + #include "shtcx.h" + #include "shtcx_params.h" + + /** + * @brief Define the number of configured sensors + */ + #define SHTCX_NUM ARRAY_SIZE(shtcx_params) + + /** + * @brief Allocate memory for the device descriptors + */ + static shtcx_t shtcx_devs[SHTCX_NUM]; + + /** + * @brief Memory for the SAUL registry entries + */ + static saul_reg_t saul_entries[SHTCX_NUM * 2]; + + /** + * @brief Define the number of saul info + */ + #define SHTCX_INFO_NUM ARRAY_SIZE(shtcx_saul_info) + + /** + * @brief Reference the driver struct + */ + extern const saul_driver_t shtcx_temperature_saul_driver; + extern const saul_driver_t shtcx_relative_humidity_saul_driver; + + void auto_init_shtcx(void) + { + assert(SHTCX_NUM == SHTCX_INFO_NUM); + + for (unsigned i = 0; i < SHTCX_NUM; i++) { + LOG_DEBUG("[auto_init_saul] initializing shtcx #%u\n", i); + + if (shtcx_init(&shtcx_devs[i], &shtcx_params[i]) != SHTCX_OK) { + LOG_ERROR("[auto_init_saul] error initializing shtcx #%u\n", i); + continue; + } + /* temperature */ + saul_entries[(i * 2)].dev = &(shtcx_devs[i]); + saul_entries[(i * 2)].name = shtcx_saul_info[i].name; + saul_entries[(i * 2)].driver = &shtcx_temperature_saul_driver; + + /* Humidity */ + saul_entries[(i * 2)+1].dev = &(shtcx_devs[i]); + saul_entries[(i * 2)+1].name = shtcx_saul_info[i].name; + saul_entries[(i * 2)+1].driver = &shtcx_relative_humidity_saul_driver; + + saul_reg_add(&(saul_entries[(i * 2)])); + saul_reg_add(&(saul_entries[(i * 2)+1])); + } + } diff --git a/drivers/saul/init_devs/init.c b/drivers/saul/init_devs/init.c index 5360d52a86..572b830052 100644 --- a/drivers/saul/init_devs/init.c +++ b/drivers/saul/init_devs/init.c @@ -139,7 +139,7 @@ void saul_init_devs(void) extern void auto_init_ina2xx(void); auto_init_ina2xx(); } - if (IS_USED(MODULE_INA3221)) { + if (IS_USED(MODUE_INA3221)) { extern void auto_init_ina3221(void); auto_init_ina3221(); } @@ -283,9 +283,9 @@ void saul_init_devs(void) extern void auto_init_sht3x(void); auto_init_sht3x(); } - if (IS_USED(MODULE_SHTC1)) { - extern void auto_init_shtc1(void); - auto_init_shtc1(); + if (IS_USED(MODULE_SHTCX)) { + extern void auto_init_shtcx(void); + auto_init_shtcx(); } if (IS_USED(MODULE_SI1133)) { extern void auto_init_si1133(void); diff --git a/drivers/shtc1/Kconfig b/drivers/shtc1/Kconfig deleted file mode 100644 index 8d5c69fa93..0000000000 --- a/drivers/shtc1/Kconfig +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2021 HAW Hamburg -# -# This file is subject to the terms and conditions of the GNU Lesser -# General Public License v2.1. See the file LICENSE in the top level -# directory for more details. -# - -config MODULE_SHTC1 - bool "Sensirion SHTC1 Temperature and humidity sensor" - depends on HAS_PERIPH_I2C - depends on TEST_KCONFIG - select MODULE_PERIPH_I2C - select MODULE_CHECKSUM - -config HAVE_SHTC1 - bool - select MODULE_SHTC1 if MODULE_SAUL_DEFAULT - help - Indicates that a SHTC1 temperature and humidity sensor is present. diff --git a/drivers/shtc1/Makefile.include b/drivers/shtc1/Makefile.include deleted file mode 100644 index 16fe245a09..0000000000 --- a/drivers/shtc1/Makefile.include +++ /dev/null @@ -1,2 +0,0 @@ -USEMODULE_INCLUDES_shtc1 := $(LAST_MAKEFILEDIR)/include -USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_shtc1) diff --git a/drivers/shtc1/include/shtc1_params.h b/drivers/shtc1/include/shtc1_params.h deleted file mode 100644 index e21aa1c89d..0000000000 --- a/drivers/shtc1/include/shtc1_params.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2017, RWTH Aachen. All rights reserved. - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup drivers_shtc1 - * - * @{ - * - * @file - * @brief Default parameters for the SHTC1 Temperature and humidity sensor - * - * @author Steffen Robertz - * @author Josua Arndt - */ - -#ifndef SHTC1_PARAMS_H -#define SHTC1_PARAMS_H - -#include "board.h" -#include "shtc1.h" -#include "shtc1_regs.h" -#include "saul_reg.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @name Default configuration parameters for SHTC1 sensors - * @{ - */ -#ifndef SHTC1_PARAM_I2C_DEV -#define SHTC1_PARAM_I2C_DEV (I2C_DEV(0)) -#endif -#ifndef SHTC1_PARAM_I2C_ADDR -#define SHTC1_PARAM_I2C_ADDR SHTC1_I2C_ADDRESS -#endif - -#ifndef SHTC1_PARAMS -#define SHTC1_PARAMS { .i2c_dev = SHTC1_PARAM_I2C_DEV, \ - .i2c_addr = SHTC1_PARAM_I2C_ADDR } -#endif -#ifndef SHTC1_SAUL_INFO -#define SHTC1_SAUL_INFO { .name = "shtc1 temperature" }, \ - { .name = "shtc1 humidity" } -#endif -/** @} */ - -/** - * @brief Allocation of SHTC1 configuration - */ -static const shtc1_params_t shtc1_params[] = -{ - SHTC1_PARAMS -}; - -/** - * @brief Configure SAUL registry entries - */ -static const saul_reg_info_t shtc1_saul_info[] = -{ - SHTC1_SAUL_INFO -}; -#ifdef __cplusplus -} -#endif - -#endif /* SHTC1_PARAMS_H */ -/** @} */ diff --git a/drivers/shtc1/include/shtc1_regs.h b/drivers/shtc1/include/shtc1_regs.h deleted file mode 100644 index 4c8d750ce4..0000000000 --- a/drivers/shtc1/include/shtc1_regs.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2017, RWTH Aachen. All rights reserved. - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup drivers_shtc1 - * - * @{ - * @file - * @brief Register definitions for SHTC1 devices - * - * @author Steffen Robertz - * @author Josua Arndt - */ - -#ifndef SHTC1_REGS_H -#define SHTC1_REGS_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** -* @name SHTC1 registers -* @{ -*/ -#define SHTC1_CRC (0x31) /**< crc polynomial */ -#define SHTC1_MEASURE_CLOCK_STRETCHING_TEMP_HIGH (0x7C) /**< Clock stretching enable high*/ -#define SHTC1_MEASURE_CLOCK_STRETCHING_TEMP_LOW (0xA2) /**< Clock stretching disable high*/ -#define SHTC1_COMMAND_RESET_HIGH (0x80) /**< Reset command high*/ -#define SHTC1_COMMAND_RESET_LOW (0x5D) /**< Reset command low*/ -#define SHTC1_COMMAND_ID_HIGH (0xEF) /**< Get ID command low*/ -#define SHTC1_COMMAND_ID_LOW (0xC8) /**< Get ID command low*/ -/** @} */ - -/** -* @brief SHTC1 default ID -*/ -#define SHTC1_ID (0x07) /* ID Mask */ - -#ifdef __cplusplus -} -#endif -#endif /* SHTC1_REGS_H */ -/** @} */ diff --git a/drivers/shtcx/Kconfig b/drivers/shtcx/Kconfig new file mode 100644 index 0000000000..a25fd84e8b --- /dev/null +++ b/drivers/shtcx/Kconfig @@ -0,0 +1,59 @@ +# Copyright (c) 2021 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +menuconfig MODULE_SHTCX + bool + prompt "SHTCX Temperature and humidity sensors" if !(MODULE_SAUL_DEFAULT && HAVE_SHTCX) + default y if (MODULE_SAUL_DEFAULT && HAVE_SHTCX) + depends on HAS_PERIPH_I2C + depends on TEST_KCONFIG + select MODULE_PERIPH_I2C + select MODULE_CHECKSUM + help + Device driver for the Sensirion SHTCX Temperature and Humidity sensor family + (SHTC1/SHTC3). Select a model. + +if MODULE_SHTCX + +choice + bool "sensor variant" + default MODULE_SHTC1 if HAVE_SHTC1 + default MODULE_SHTC3 if HAVE_SHTC3 + help + Device driver for the SHTCX pressure sensor family + (SHTC1/SHTC3). Select a model. + +config MODULE_SHTC1 + bool "SHTC1" + +config MODULE_SHTC3 + bool "SHTC3" + +endchoice + +endif # MODULE_SHTCX + +menuconfig KCONFIG_USEMODULE_SHTCX + bool "Configure SHTCX driver" + depends on USEMODULE_SHTCX + help + Configure the SHTCX driver using Kconfig. + +config HAVE_SHTCX + bool + +config HAVE_SHTC1 + bool + select HAVE_SHTCX + help + Indicates that an SHTC1 sensor is present. + +config HAVE_SHTC3 + bool + select HAVE_SHTCX + help + Indicates that an SHTC3 sensor is present. diff --git a/drivers/shtc1/Makefile b/drivers/shtcx/Makefile similarity index 100% rename from drivers/shtc1/Makefile rename to drivers/shtcx/Makefile diff --git a/drivers/shtc1/Makefile.dep b/drivers/shtcx/Makefile.dep similarity index 100% rename from drivers/shtc1/Makefile.dep rename to drivers/shtcx/Makefile.dep diff --git a/drivers/shtcx/Makefile.include b/drivers/shtcx/Makefile.include new file mode 100644 index 0000000000..c0ef2d1830 --- /dev/null +++ b/drivers/shtcx/Makefile.include @@ -0,0 +1,6 @@ +# include variants of shtcx drivers as pseudo modules +PSEUDOMODULES += shtc1 +PSEUDOMODULES += shtc3 + +USEMODULE_INCLUDES_shtcx := $(LAST_MAKEFILEDIR)/include +USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_shtcx) diff --git a/drivers/shtcx/include/shtcx_params.h b/drivers/shtcx/include/shtcx_params.h new file mode 100644 index 0000000000..6d17434a17 --- /dev/null +++ b/drivers/shtcx/include/shtcx_params.h @@ -0,0 +1,75 @@ +/* + * Copyright 2017, RWTH Aachen. All rights reserved. + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_shtcx + * + * @{ + * + * @file + * @brief Default parameters for the SHTCX Temperature and humidity sensor + * + * @author Steffen Robertz + * @author Josua Arndt + */ + +#ifndef SHTCX_PARAMS_H +#define SHTCX_PARAMS_H + +#include "board.h" +#include "shtcx.h" +#include "shtcx_regs.h" +#include "saul_reg.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name Default configuration parameters for SHTCX sensors + * @{ + */ +#ifndef SHTCX_PARAM_I2C_DEV +#define SHTCX_PARAM_I2C_DEV (I2C_DEV(0)) /**< Default I2C BUS used */ +#endif +#ifndef SHTCX_PARAM_I2C_ADDR +#define SHTCX_PARAM_I2C_ADDR SHTCX_I2C_ADDRESS /**< I2C Address */ +#endif + +#ifndef SHTCX_PARAMS +#define SHTCX_PARAMS { .i2c_dev = SHTCX_PARAM_I2C_DEV, \ + .i2c_addr = SHTCX_PARAM_I2C_ADDR } +#endif +#ifndef SHTCX_SAUL_INFO +#define SHTCX_SAUL_INFO { .name = "shtcx temperature" }, \ + { .name = "shtcx humidity" } +#endif +/** @} */ + +/** + * @brief Allocation of SHTCX configuration + */ +static const shtcx_params_t shtcx_params[] = +{ + SHTCX_PARAMS +}; + +/** + * @brief Configure SAUL registry entries + */ +static const saul_reg_info_t shtcx_saul_info[] = +{ + SHTCX_SAUL_INFO +}; + +#ifdef __cplusplus +} +#endif + +#endif /* SHTCX_PARAMS_H */ +/** @} */ diff --git a/drivers/shtcx/include/shtcx_regs.h b/drivers/shtcx/include/shtcx_regs.h new file mode 100644 index 0000000000..4403d5472c --- /dev/null +++ b/drivers/shtcx/include/shtcx_regs.h @@ -0,0 +1,49 @@ +/* + * Copyright 2017, RWTH Aachen. All rights reserved. + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_shtcx + * + * @{ + * @file + * @brief Register definitions for SHTCX devices + * + * @author Steffen Robertz + * @author Josua Arndt + */ + +#ifndef SHTCX_REGS_H +#define SHTCX_REGS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @name SHTCX registers +* @{ +*/ +#define SHTCX_CRC (0x31) /**< crc polynomial */ +#define SHTCX_MEASURE_CLOCK_STRETCHING_TEMP_HIGH (0x7C) /**< Clock stretching enable high*/ +#define SHTCX_MEASURE_CLOCK_STRETCHING_TEMP_LOW (0xA2) /**< Clock stretching disable high*/ +#define SHTCX_COMMAND_RESET_HIGH (0x80) /**< Reset command high*/ +#define SHTCX_COMMAND_RESET_LOW (0x5D) /**< Reset command low*/ +#define SHTCX_COMMAND_ID_HIGH (0xEF) /**< Get ID command low*/ +#define SHTCX_COMMAND_ID_LOW (0xC8) /**< Get ID command low*/ +/** @} */ + +/** +* @brief SHTCX default ID +*/ +#define SHTCX_ID (0x07) /* ID Mask */ + +#ifdef __cplusplus +} +#endif +#endif /* SHTCX_REGS_H */ +/** @} */ diff --git a/drivers/shtc1/shtc1.c b/drivers/shtcx/shtcx.c similarity index 70% rename from drivers/shtc1/shtc1.c rename to drivers/shtcx/shtcx.c index 9e93031fd0..1166805c8d 100644 --- a/drivers/shtc1/shtc1.c +++ b/drivers/shtcx/shtcx.c @@ -7,11 +7,11 @@ */ /** - * @ingroup drivers_shtc1 + * @ingroup drivers_shtcx * @{ * * @file - * @brief Device driver implementation for the Sensirion SHTC1 temperature + * @brief Device driver implementation for the Sensirion SHTCX temperature * and humidity sensor. * * @author Steffen Robertz @@ -24,13 +24,13 @@ #include "log.h" #include "assert.h" #include "checksum/crc8.h" -#include "shtc1.h" -#include "shtc1_regs.h" +#include "shtcx.h" +#include "shtcx_regs.h" #define ENABLE_DEBUG 0 #include "debug.h" -int8_t shtc1_init(shtc1_t *const dev, const shtc1_params_t *params) +int8_t shtcx_init(shtcx_t *const dev, const shtcx_params_t *params) { uint16_t id; @@ -38,31 +38,31 @@ int8_t shtc1_init(shtc1_t *const dev, const shtc1_params_t *params) assert(dev && params); /* copy settings into the device descriptor */ dev->params = *params; - /* Verify the connection by reading the SHTC1's ID and checking its value */ - if (shtc1_id(dev, &id) != SHTC1_OK) { - return SHTC1_ERROR_BUS; + /* Verify the connection by reading the SHTCX's ID and checking its value */ + if (shtcx_id(dev, &id) != SHTCX_OK) { + return SHTCX_ERROR_BUS; } - else if ((id & 0x3F) != SHTC1_ID) { - return SHTC1_ERROR_CRC; + else if ((id & 0x3F) != SHTCX_ID) { + return SHTCX_ERROR_CRC; } else { - return SHTC1_OK; + return SHTCX_OK; } } -int8_t shtc1_read(const shtc1_t *dev, uint16_t *rel_humidity, +int8_t shtcx_read(const shtcx_t *dev, uint16_t *rel_humidity, int16_t *temperature) { uint8_t received[6]; /* Build and issue the measurement command */ uint8_t cmd[] = - { SHTC1_MEASURE_CLOCK_STRETCHING_TEMP_HIGH, - SHTC1_MEASURE_CLOCK_STRETCHING_TEMP_LOW }; + { SHTCX_MEASURE_CLOCK_STRETCHING_TEMP_HIGH, + SHTCX_MEASURE_CLOCK_STRETCHING_TEMP_LOW }; i2c_acquire(dev->params.i2c_dev); if (i2c_write_bytes(dev->params.i2c_dev, dev->params.i2c_addr, cmd, 2, 0)) { - return SHTC1_ERROR_BUS; + return SHTCX_ERROR_BUS; } /* Receive the measurement */ /* 16 bit Temperature @@ -72,7 +72,7 @@ int8_t shtc1_read(const shtc1_t *dev, uint16_t *rel_humidity, */ if (i2c_read_bytes(dev->params.i2c_dev, dev->params.i2c_addr, received, 6, 0)) { - return SHTC1_ERROR_BUS; + return SHTCX_ERROR_BUS; } i2c_release(dev->params.i2c_dev); @@ -89,47 +89,47 @@ int8_t shtc1_read(const shtc1_t *dev, uint16_t *rel_humidity, *temperature = ((17500 * (uint32_t)temp_f) >> 16) - 4500; } - if (!((crc8(&received[0], 2, SHTC1_CRC, 0xFF) == received[2]) && - (crc8(&received[3], 2, SHTC1_CRC, 0xFF) == received[5]))) { + if (!((crc8(&received[0], 2, SHTCX_CRC, 0xFF) == received[2]) && + (crc8(&received[3], 2, SHTCX_CRC, 0xFF) == received[5]))) { /* crc check failed */ DEBUG("CRC Error\n"); - return SHTC1_ERROR_CRC; + return SHTCX_ERROR_CRC; } DEBUG("CRC Passed! \n"); - return SHTC1_OK; + return SHTCX_OK; } -int8_t shtc1_id(const shtc1_t *dev, uint16_t *id) +int8_t shtcx_id(const shtcx_t *dev, uint16_t *id) { /* Build and send measurement command */ - uint8_t data[] = { SHTC1_COMMAND_ID_HIGH, SHTC1_COMMAND_ID_LOW }; + uint8_t data[] = { SHTCX_COMMAND_ID_HIGH, SHTCX_COMMAND_ID_LOW }; i2c_acquire(dev->params.i2c_dev); if (i2c_write_bytes(dev->params.i2c_dev, dev->params.i2c_addr, data, 2, 0)) { - return SHTC1_ERROR_BUS; + return SHTCX_ERROR_BUS; } /* receive ID and check if the send and receive commands were successful */ if (i2c_read_bytes(dev->params.i2c_dev, dev->params.i2c_addr, data, 2, 0)) { - return SHTC1_ERROR_BUS; + return SHTCX_ERROR_BUS; } i2c_release(dev->params.i2c_dev); /* Save ID in device descriptor */ *id = (data[0] << 8) | data[1]; - return SHTC1_OK; + return SHTCX_OK; } -int8_t shtc1_reset(const shtc1_t *const dev) +int8_t shtcx_reset(const shtcx_t *const dev) { /* Build and issue the reset command */ - uint8_t data[] = { SHTC1_COMMAND_RESET_HIGH, SHTC1_COMMAND_RESET_LOW }; + uint8_t data[] = { SHTCX_COMMAND_RESET_HIGH, SHTCX_COMMAND_RESET_LOW }; i2c_acquire(dev->params.i2c_dev); if (i2c_write_bytes(dev->params.i2c_dev, dev->params.i2c_addr, data, 2, 0)) { - return SHTC1_ERROR_BUS; + return SHTCX_ERROR_BUS; } i2c_release(dev->params.i2c_dev); - return SHTC1_OK; + return SHTCX_OK; } diff --git a/drivers/shtc1/shtc1_saul.c b/drivers/shtcx/shtcx_saul.c similarity index 69% rename from drivers/shtc1/shtc1_saul.c rename to drivers/shtcx/shtcx_saul.c index ad12396ba3..f366a8154b 100644 --- a/drivers/shtc1/shtc1_saul.c +++ b/drivers/shtcx/shtcx_saul.c @@ -7,11 +7,11 @@ */ /** - * @ingroup drivers_shtc1 + * @ingroup drivers_shtcx * @{ * * @file - * @brief SHTC1 adaption to the RIOT actuator/sensor interface + * @brief SHTCX adaption to the RIOT actuator/sensor interface * * @author Michel Gerlach * @@ -19,11 +19,11 @@ */ #include "saul.h" -#include "shtc1.h" +#include "shtcx.h" static int read_temperature(const void *dev, phydat_t *res) { - if (shtc1_read((shtc1_t *)dev, NULL, &res->val[0]) != SHTC1_OK) { + if (shtcx_read((shtcx_t *)dev, NULL, &res->val[0]) != SHTCX_OK) { return -ECANCELED; } res->unit = UNIT_TEMP_C; @@ -34,7 +34,7 @@ static int read_temperature(const void *dev, phydat_t *res) static int read_relative_humidity(const void *dev, phydat_t *res) { - if (shtc1_read((shtc1_t *)dev, (uint16_t *)&res->val[0], NULL) != SHTC1_OK) { + if (shtcx_read((shtcx_t *)dev, (uint16_t *)&res->val[0], NULL) != SHTCX_OK) { return -ECANCELED; } res->unit = UNIT_PERCENT; @@ -43,13 +43,13 @@ static int read_relative_humidity(const void *dev, phydat_t *res) return 1; } -const saul_driver_t shtc1_temperature_saul_driver = { +const saul_driver_t shtcx_temperature_saul_driver = { .read = read_temperature, .write = saul_notsup, .type = SAUL_SENSE_TEMP, }; -const saul_driver_t shtc1_relative_humidity_saul_driver = { +const saul_driver_t shtcx_relative_humidity_saul_driver = { .read = read_relative_humidity, .write = saul_notsup, .type = SAUL_SENSE_HUM, diff --git a/tests/driver_shtc1/README.md b/tests/driver_shtc1/README.md deleted file mode 100644 index 6bc4ab1698..0000000000 --- a/tests/driver_shtc1/README.md +++ /dev/null @@ -1,4 +0,0 @@ -#About -Testing application for the SHTC1 temperature and humidity sensor -#Usage -Just build it using the `make BOARD=??? flash` command in the `tests/driver_shtc1` folder. Temperature and humidity values should be printed in the terminal every 2s diff --git a/tests/driver_shtc1/Makefile b/tests/driver_shtcx/Makefile similarity index 100% rename from tests/driver_shtc1/Makefile rename to tests/driver_shtcx/Makefile diff --git a/tests/driver_shtcx/README.md b/tests/driver_shtcx/README.md new file mode 100644 index 0000000000..2e8d2a3072 --- /dev/null +++ b/tests/driver_shtcx/README.md @@ -0,0 +1,10 @@ +#About +Testing application for the SHTCX faimly of temperature and humidity sensors. +This driver can be used with the SHTC1 and SHTC3 sensors. + +Default driver is "shtc1". To use the SHTC3 driver, set the "DRIVER" when building the application: + + DRIVER=shtc3 make BOARD= + +#Usage +Just build it using the `make BOARD=??? flash` command in the `tests/driver_shtcx` folder. Temperature and humidity values should be printed in the terminal every 2s diff --git a/tests/driver_shtc1/app.config.test b/tests/driver_shtcx/app.config.test similarity index 91% rename from tests/driver_shtc1/app.config.test rename to tests/driver_shtcx/app.config.test index 96c6f5cab8..bb9a331944 100644 --- a/tests/driver_shtc1/app.config.test +++ b/tests/driver_shtcx/app.config.test @@ -1,6 +1,7 @@ # this file enables modules defined in Kconfig. Do not use this file for # application configuration. This is only needed during migration. CONFIG_MODULE_FMT=y +CONFIG_MODULE_SHTCX=y CONFIG_MODULE_SHTC1=y CONFIG_MODULE_ZTIMER=y CONFIG_MODULE_ZTIMER_MSEC=y diff --git a/tests/driver_shtc1/main.c b/tests/driver_shtcx/main.c similarity index 79% rename from tests/driver_shtc1/main.c rename to tests/driver_shtcx/main.c index 865eaa2724..5caddee803 100644 --- a/tests/driver_shtc1/main.c +++ b/tests/driver_shtcx/main.c @@ -10,7 +10,7 @@ * @{ * * @file - * @brief Test application for the SHTC1 temperature and humidity sensor + * @brief Test application for the SHTCX temperature and humidity sensor * * @author Steffen Robertz * @author Josua Arndt @@ -24,12 +24,12 @@ #include "timex.h" #include "ztimer.h" #include "fmt.h" -#include "shtc1.h" -#include "shtc1_params.h" +#include "shtcx.h" +#include "shtcx_params.h" int main(void) { - shtc1_t dev; + shtcx_t dev; int16_t temp; uint16_t hum; @@ -37,15 +37,15 @@ int main(void) char str_hum[8]; size_t len; - puts("SHTC1 test application\n"); + puts("SHTCX test application\n"); - if ((shtc1_init(&dev, &shtc1_params[0])) != SHTC1_OK) { + if ((shtcx_init(&dev, &shtcx_params[0])) != SHTCX_OK) { puts("can't initialize the sensor"); return -1; } - puts("SHTC1 initialized\n"); + puts("SHTCX initialized\n"); while (1) { - if (shtc1_read(&dev, &hum, &temp) == SHTC1_OK) { + if (shtcx_read(&dev, &hum, &temp) == SHTCX_OK) { len = fmt_s16_dfp(str_temp, temp, -2); str_temp[len] = '\0';