From 009afd11732ebd259577474646675873448fc8e5 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Tue, 13 Dec 2022 00:58:29 +0100 Subject: [PATCH] drivers/sht2x: extend Kconfig by sensor parameters --- drivers/sht2x/Kconfig | 62 ++++++++++++++++++++++++--- drivers/sht2x/include/sht2x_params.h | 63 ++++++++++++++++++++++++---- 2 files changed, 110 insertions(+), 15 deletions(-) diff --git a/drivers/sht2x/Kconfig b/drivers/sht2x/Kconfig index acb8f04f80..afc924019f 100644 --- a/drivers/sht2x/Kconfig +++ b/drivers/sht2x/Kconfig @@ -5,15 +5,65 @@ # directory for more details. # -config MODULE_SHT2X - bool "SHT2x temperature and humidity sensor" +config HAVE_SHT2X + bool + select MODULE_SHT2X if MODULE_SAUL_DEFAULT + help + Indicates that a SHT2x humidity and temperature sensor is present. + +menuconfig MODULE_SHT2X + bool "SHT2x humidity and temperature sensor" depends on HAS_PERIPH_I2C depends on TEST_KCONFIG select MODULE_PERIPH_I2C select MODULE_ZTIMER_MSEC -config HAVE_SHT2X - bool - select MODULE_SHT2X if MODULE_SAUL_DEFAULT +if MODULE_SHT2X + +choice + bool "Measurement Resolution" + default SHT2X_RES_12_14BIT + + config SHT2X_RES_12_14BIT + bool "Humidity with 12 bit, Temperature with 14 bit" + config SHT2X_RES_11_11BIT + bool "Humidity with 11 bit, Temperature with 11 bit" + config SHT2X_RES_10_13BIT + bool "Humidity with 10 bit, Temperature with 13 bit" + config SHT2X_RES_8_12BIT + bool "Humidity with 8 bit, Temperature with 12 bit" help - Indicates that a SHT2x temperature and humidity sensor is present. + Measurement resolution +endchoice + +choice + bool "Measurement Mode" + default SHT2X_MEASURE_MODE_NO_HOLD + + config SHT2X_MEASURE_MODE_NO_HOLD + bool "No Hold" + help + In Hold mode the measurement is started and the sensor blocks the + master by clock stretching until the measurement is finished. Thus, + in this mode, both the I2C bus and the processor are blocked for the + entire measurement duration, which can be up to 85 ms for temperature + measurement and up to 29 ms for humidity measurement, depending on the + resolution. Therefore, the no-hold mode should be used, where the + measurement is started and a timer is used to fetch the results. + This way neither the I2C bus nor the processor are blocked for the + duration of the measurement. Furthermore, the hold mode requires that + the MCU supports clock stretching. + config SHT2X_MEASURE_MODE_HOLD + bool "Hold" + help + In no-hold mode the measurement is started and a timer is used to + fetch the results. This way neither the I2C bus nor the processor + are blocked for the duration of the measurement. +endchoice + +config SHT2X_CRC_MODE + bool "CRC check" + help + Enable to check the CRC of measurement data. + +endif # MODULE_SHT2X diff --git a/drivers/sht2x/include/sht2x_params.h b/drivers/sht2x/include/sht2x_params.h index ced7de49ad..1508d6628e 100644 --- a/drivers/sht2x/include/sht2x_params.h +++ b/drivers/sht2x/include/sht2x_params.h @@ -13,7 +13,7 @@ * * @{ * @file - * @brief Default configuration for SHT2X + * @brief Default configuration for SHT2x humidity and temperature sensor * * @author Kees Bakker * @author George Psimenos @@ -30,26 +30,70 @@ extern "C" { #endif +#if !DOXYGEN +/* Mapping of Kconfig defines to the respective driver enumeration values */ + +#if CONFIG_SHT2X_RES_12_14BIT +#define CONFIG_SHT2X_RESOLUTION (SHT2X_RES_12_14BIT) +#elif CONFIG_SHT2X_RES_11_11BIT +#define CONFIG_SHT2X_RESOLUTION (SHT2X_RES_11_11BIT) +#elif CONFIG_SHT2X_RES_10_13BIT +#define CONFIG_SHT2X_RESOLUTION (SHT2X_RES_10_13BIT) +#elif CONFIG_SHT2X_RES_8_12BIT +#define CONFIG_SHT2X_RESOLUTION (SHT2X_RES_8_12BIT) +#else +#define CONFIG_SHT2X_RESOLUTION (SHT2X_RES_12_14BIT) +#endif + +#if CONFIG_SHT2X_MEASURE_MODE_HOLD +#define CONFIG_SHT2X_MEASURE_MODE (SHT2X_MEASURE_MODE_HOLD) +#elif CONFIG_SHT2X_MEASURE_MODE_NO_HOLD +#define CONFIG_SHT2X_MEASURE_MODE (SHT2X_MEASURE_MODE_NO_HOLD) +#else +#define CONFIG_SHT2X_MEASURE_MODE (SHT2X_MEASURE_MODE_NO_HOLD) +#endif + +#ifndef CONFIG_SHT2X_CRC_MODE +#define CONFIG_SHT2X_CRC_MODE (1) +#endif + +#endif /* !DOXYGEN */ + /** - * @brief Set default configuration parameters for the SHT2X + * @name Default SHT2x hardware configuration * @{ */ #ifndef SHT2X_PARAM_I2C_DEV +/** I2C device used */ #define SHT2X_PARAM_I2C_DEV (I2C_DEV(0)) #endif + #ifndef SHT2X_PARAM_I2C_ADDR +/** I2C slave slave of the SHT2x sensor */ #define SHT2X_PARAM_I2C_ADDR (0x40) #endif +/** @} */ + +/** + * @name Default sensor configuration for the SHT2x sensor + * @{ + */ #ifndef SHT2X_PARAM_RESOLUTION -#define SHT2X_PARAM_RESOLUTION (SHT2X_RES_12_14BIT) -#endif -#ifndef SHT2X_PARAM_MEASURE_MODE -#define SHT2X_PARAM_MEASURE_MODE (SHT2X_MEASURE_MODE_HOLD) -#endif -#ifndef SHT2X_PARAM_CRC_MODE -#define SHT2X_PARAM_CRC_MODE (1) +/** SHT2x resolution */ +#define SHT2X_PARAM_RESOLUTION (CONFIG_SHT2X_RESOLUTION) #endif +#ifndef SHT2X_PARAM_MEASURE_MODE +/** SHT2x measurement mode */ +#define SHT2X_PARAM_MEASURE_MODE (CONFIG_SHT2X_MEASURE_MODE) +#endif + +#ifndef SHT2X_PARAM_CRC_MODE +/** SHT2x CRC mode */ +#define SHT2X_PARAM_CRC_MODE (CONFIG_SHT2X_CRC_MODE) +#endif + +/** Default SHT2x parameter set */ #define SHT2X_PARAMS_DEFAULT {.i2c_dev = SHT2X_PARAM_I2C_DEV, \ .i2c_addr = SHT2X_PARAM_I2C_ADDR, \ .resolution = SHT2X_PARAM_RESOLUTION, \ @@ -58,6 +102,7 @@ extern "C" { } #ifndef SHT2X_SAUL_INFO +/** Default SAUL device info */ #define SHT2X_SAUL_INFO { .name = "sht2x" } #endif /**@}*/