1 /* 2 * Copyright (c) 2023 Wuerth Elektronik eiSos GmbH & Co. KG 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief Header file for the WSEN-HIDS-2525020210001 sensor driver. 10 */ 11 12 #ifndef _WSEN_HIDS_2525020210001_H 13 #define _WSEN_HIDS_2525020210001_H 14 15 /* Includes */ 16 17 #include <stdint.h> 18 19 #include "../WeSensorsSDK.h" 20 21 22 /* HIDS 2525020210001 DEVICE_ID */ 23 24 #define HIDS_DEVICE_ID_VALUE 0xBC /**< Device ID of HIDS Sensor */ 25 26 27 /* Available HIDS I2C slave addresses */ 28 29 #define HIDS_ADDRESS_I2C_0 0x5F /**< HIDS I2C address */ 30 31 32 /* Register address definitions */ 33 34 #define HIDS_DEVICE_ID_REG 0x0F /**< Device ID register */ 35 #define HIDS_AVERAGE_REG 0x10 /**< Average configuration register */ 36 #define HIDS_CTRL_REG_1 0x20 /**< Control register 1 */ 37 #define HIDS_CTRL_REG_2 0x21 /**< Control register 2 */ 38 #define HIDS_CTRL_REG_3 0x22 /**< Control register 3 */ 39 #define HIDS_STATUS_REG 0x27 /**< Status register */ 40 #define HIDS_H_OUT_L_REG 0x28 /**< Humidity output LSB value register */ 41 #define HIDS_H_OUT_H_REG 0x29 /**< Humidity output MSB value register */ 42 #define HIDS_T_OUT_L_REG 0x2A /**< Temperature output LSB value register */ 43 #define HIDS_T_OUT_H_REG 0x2B /**< Temperature output MSB value register */ 44 #define HIDS_H0_RH_X2 0x30 /**< H0_RH_X2 calibration register */ 45 #define HIDS_H1_RH_X2 0x31 /**< H1_RH_X2 calibration register */ 46 #define HIDS_T0_DEGC_X8 0x32 /**< T0_DEGC_X8 calibration register */ 47 #define HIDS_T1_DEGC_X8 0x33 /**< T1_DEGC_X8 calibration register */ 48 #define HIDS_T0_T1_DEGC_H2 0x35 /**< T0_T1_DEGC_H2 calibration register */ 49 #define HIDS_H0_T0_OUT_L 0x36 /**< H0_T0_OUT_L LSB calibration register */ 50 #define HIDS_H0_T0_OUT_H 0x37 /**< H0_T0_OUT_H MSB calibration register */ 51 #define HIDS_H1_T0_OUT_L 0x3A /**< H1_T0_OUT_L LSB calibration register */ 52 #define HIDS_H1_T0_OUT_H 0x3B /**< H1_T0_OUT_H MSB calibration register */ 53 #define HIDS_T0_OUT_L 0x3C /**< T0_OUT_L LSB calibration register */ 54 #define HIDS_T0_OUT_H 0x3D /**< T0_OUT_H MSB calibration register */ 55 #define HIDS_T1_OUT_L 0x3E /**< T1_OUT_L LSB calibration register */ 56 #define HIDS_T1_OUT_H 0x3F /**< T1_OUT_H MSB calibration register */ 57 58 59 /* Register type definitions */ 60 61 /** 62 * @brief Humidity and temperature average configuration 63 * 64 * Address 0x10 65 * Type R/W 66 * Default value: 0x1B 67 * 68 * AVG 2:0 | (AVGT) | (AVGH) | 69 * ---------------------------------- 70 * 000 | 2 | 4 | 71 * 001 | 4 | 8 | 72 * 010 | 8 | 16 | 73 * 011 | 16 | 32 | 74 * 100 | 32 | 64 | 75 * 101 | 64 | 128 | 76 * 110 | 128 | 256 | 77 * 111 | 256 | 512 | 78 * ---------------------------------- 79 */ 80 typedef struct 81 { 82 uint8_t avgHum : 3; /**< AVG_H: Select the number of averaged humidity samples (4 - 512) */ 83 uint8_t avgTemp : 3; /**< AVG_T: Select the number of averaged temperature samples (2 - 256) */ 84 uint8_t notUsed01 : 2; /**< This bit must be set to 0 for proper operation of the device */ 85 } HIDS_averageConfig_t; 86 87 /** 88 * @brief Control Register 1 89 * 90 * Address 0x20 91 * Type R/W 92 * Default value: 0x00 93 * 94 * ODR1 | ODR0 | Humidity/temperature output data rate (Hz) 95 * --------------------------------------------------------------------- 96 * 0 | 0 | One-shot mode 97 * 0 | 1 | 1 98 * 1 | 0 | 7 99 * 1 | 1 | 12.5 100 */ 101 typedef struct 102 { 103 uint8_t odr : 2; /**< ODR: Output data rate selection */ 104 uint8_t bdu : 1; /**< BDU: Block data update. 0 - continuous update; 1 - output registers are not updated until both MSB and LSB have been read */ 105 uint8_t notUsed01 : 4; /**< This bit must be set to 0 for proper operation of the device */ 106 uint8_t powerControlMode : 1; /**< PD: (0: power-down mode; 1: active mode) */ 107 } HIDS_ctrl1_t; 108 109 /** 110 * @brief Control Register 2 111 * 112 * Address 0x21 113 * Type R/W 114 * Default value: 0x00 115 */ 116 typedef struct 117 { 118 uint8_t oneShotBit : 1; /**< One-shot enable (0: conversion done; 1: start new conversion) */ 119 uint8_t heater : 1; /**< Heater (0: heater disabled; 1: heater enabled) */ 120 uint8_t notUsed01 : 5; /**< This bit must be set to 0 for proper operation of the device */ 121 uint8_t rebootMemory : 1; /**< BOOT (0: normal mode; 1: reboot) */ 122 } HIDS_ctrl2_t; 123 124 /** 125 * @brief Control Register 3 126 * 127 * Address 0x22 128 * Type R/W 129 * Default value: 0x00 130 */ 131 typedef struct 132 { 133 uint8_t notUsed01 : 2; /**< This bit must be set to 0 for proper operation of the device */ 134 uint8_t enDataReady : 1; /**< DRDY_EN Data ready interrupt control (0: Data ready interrupt disabled - default; 1: Data ready signal available on pin 3) */ 135 uint8_t notUsed02 : 3; /**< This bit must be set to 0 for proper operation of the device */ 136 uint8_t interruptPinConfig : 1; /**< PP_OD (0: push-pull - default; 1: open drain) */ 137 uint8_t drdyOutputLevel : 1; /**< DRDY_H_L: Data ready interrupt level (0: active high - default; 1: active low) */ 138 } HIDS_ctrl3_t; 139 140 /** 141 * @brief Status register 142 * 143 * Address 0x27 144 * Type R 145 * Default value: 0x00 146 */ 147 typedef struct 148 { 149 uint8_t humDataAvailable : 1; /**< H_DA: Pressure data available (0: new humidity sample not yet available; 1: new humidity sample is available) */ 150 uint8_t tempDataAvailable : 1; /**< T_DA: Temperature data available (0: new temperature sample not yet available; 1: new temperature sample is available) */ 151 uint8_t notUsed01 : 6; /**< This bit must be set to 0 for proper operation of the device */ 152 } HIDS_status_t; 153 154 155 /* Functional type definitions */ 156 157 /** 158 * @brief HIDS state type. 159 */ 160 typedef enum 161 { 162 HIDS_disable = 0, 163 HIDS_enable = 1 164 } HIDS_state_t; 165 166 167 /** 168 * @brief Power mode 169 */ 170 typedef enum 171 { 172 HIDS_powerDownMode = 0, 173 HIDS_activeMode = 1 174 } HIDS_powerMode_t; 175 176 /** 177 * @brief Output data rate 178 */ 179 typedef enum 180 { 181 HIDS_oneShot = 0, /**< One-shot */ 182 HIDS_odr1Hz = 1, /**< 1Hz */ 183 HIDS_odr7Hz = 2, /**< 7Hz */ 184 HIDS_odr12_5Hz = 3, /**< 12.5Hz */ 185 } HIDS_outputDataRate_t; 186 187 /** 188 * @brief Humidity averaging configuration 189 */ 190 typedef enum 191 { 192 HIDS_humidityAvg4 = 0, 193 HIDS_humidityAvg8 = 1, 194 HIDS_humidityAvg16 = 2, 195 HIDS_humidityAvg32 = 3, 196 HIDS_humidityAvg64 = 4, 197 HIDS_humidityAvg128 = 5, 198 HIDS_humidityAvg256 = 6, 199 HIDS_humidityAvg512 = 7 200 } HIDS_humidityAverageConfig_t; 201 202 /** 203 * @brief Temperature averaging configuration 204 */ 205 typedef enum 206 { 207 HIDS_temperatureAvg2 = 0, 208 HIDS_temperatureAvg4 = 1, 209 HIDS_temperatureAvg8 = 2, 210 HIDS_temperatureAvg16 = 3, 211 HIDS_temperatureAvg32 = 4, 212 HIDS_temperatureAvg64 = 5, 213 HIDS_temperatureAvg128 = 6, 214 HIDS_temperatureAvg256 = 7 215 } HIDS_temperatureAverageConfig_t; 216 217 /** 218 * @brief Interrupt active level 219 */ 220 typedef enum 221 { 222 HIDS_activeHigh = 0, 223 HIDS_activeLow = 1 224 } HIDS_interruptActiveLevel_t; 225 226 /** 227 * @brief Interrupt pin configuration 228 */ 229 typedef enum 230 { 231 HIDS_pushPull = 0, 232 HIDS_openDrain = 1 233 } HIDS_interruptPinConfig_t; 234 235 236 /* Function definitions */ 237 238 #ifdef __cplusplus 239 extern "C" 240 { 241 #endif 242 243 int8_t HIDS_getDefaultInterface(WE_sensorInterface_t* sensorInterface); 244 245 int8_t HIDS_getDeviceID(WE_sensorInterface_t* sensorInterface, uint8_t *deviceID); 246 247 uint8_t HIDS_setHumidityAverageConfig(WE_sensorInterface_t* sensorInterface, HIDS_humidityAverageConfig_t avgHum); 248 uint8_t HIDS_getHumidityAverageConfig(WE_sensorInterface_t* sensorInterface, HIDS_humidityAverageConfig_t *avgHum); 249 uint8_t HIDS_setTemperatureAverageConfig(WE_sensorInterface_t* sensorInterface, HIDS_temperatureAverageConfig_t avgTemp); 250 uint8_t HIDS_getTemperatureAverageConfig(WE_sensorInterface_t* sensorInterface, HIDS_temperatureAverageConfig_t *avgTemp); 251 252 int8_t HIDS_setOutputDataRate(WE_sensorInterface_t* sensorInterface, HIDS_outputDataRate_t odr); 253 int8_t HIDS_getOutputDataRate(WE_sensorInterface_t* sensorInterface, HIDS_outputDataRate_t *odr); 254 255 int8_t HIDS_enableBlockDataUpdate(WE_sensorInterface_t* sensorInterface, HIDS_state_t bdu); 256 int8_t HIDS_isBlockDataUpdateEnabled(WE_sensorInterface_t* sensorInterface, HIDS_state_t *bdu); 257 258 int8_t HIDS_setPowerMode(WE_sensorInterface_t* sensorInterface, HIDS_powerMode_t pd); 259 int8_t HIDS_getPowerMode(WE_sensorInterface_t* sensorInterface, HIDS_powerMode_t *pd); 260 261 int8_t HIDS_enableOneShot(WE_sensorInterface_t* sensorInterface, HIDS_state_t oneShot); 262 int8_t HIDS_isOneShotEnabled(WE_sensorInterface_t* sensorInterface, HIDS_state_t *oneShot); 263 264 int8_t HIDS_enableHeater(WE_sensorInterface_t* sensorInterface, HIDS_state_t heater); 265 int8_t HIDS_isHeaterEnabled(WE_sensorInterface_t* sensorInterface, HIDS_state_t *heater); 266 267 int8_t HIDS_reboot(WE_sensorInterface_t* sensorInterface, HIDS_state_t reboot); 268 int8_t HIDS_isRebooting(WE_sensorInterface_t* sensorInterface, HIDS_state_t *rebooting); 269 270 int8_t HIDS_enableDataReadyInterrupt(WE_sensorInterface_t* sensorInterface, HIDS_state_t drdy); 271 int8_t HIDS_isDataReadyInterruptEnabled(WE_sensorInterface_t* sensorInterface, HIDS_state_t *drdy); 272 273 int8_t HIDS_setInterruptPinType(WE_sensorInterface_t* sensorInterface, HIDS_interruptPinConfig_t pinType); 274 int8_t HIDS_getInterruptPinType(WE_sensorInterface_t* sensorInterface, HIDS_interruptPinConfig_t *pinType); 275 276 int8_t HIDS_setInterruptActiveLevel(WE_sensorInterface_t* sensorInterface, HIDS_interruptActiveLevel_t level); 277 int8_t HIDS_getInterruptActiveLevel(WE_sensorInterface_t* sensorInterface, HIDS_interruptActiveLevel_t *level); 278 279 int8_t HIDS_isTemperatureDataAvailable(WE_sensorInterface_t* sensorInterface, HIDS_state_t *state); 280 int8_t HIDS_isHumidityDataAvailable(WE_sensorInterface_t* sensorInterface, HIDS_state_t *state); 281 int8_t HIDS_isDataAvailable(WE_sensorInterface_t* sensorInterface, HIDS_state_t *temp_state, HIDS_state_t *hum_state); 282 283 284 int8_t HIDS_getRawHumidity(WE_sensorInterface_t* sensorInterface, int16_t *rawHumidity); 285 int8_t HIDS_getRawTemperature(WE_sensorInterface_t* sensorInterface, int16_t *rawTemp); 286 int8_t HIDS_getRawValues(WE_sensorInterface_t* sensorInterface, int16_t *rawHumidity, int16_t *rawTemp); 287 288 #ifdef WE_USE_FLOAT 289 int8_t HIDS_getHumidity_float(WE_sensorInterface_t* sensorInterface, float *humidity); 290 int8_t HIDS_getTemperature_float(WE_sensorInterface_t* sensorInterface, float *tempDegC); 291 292 int8_t HIDS_convertHumidity_float(WE_sensorInterface_t* sensorInterface, int16_t rawHumidity, float *humidity); 293 int8_t HIDS_convertTemperature_float(WE_sensorInterface_t* sensorInterface, int16_t rawTemp, float *tempDegC); 294 #endif /* WE_USE_FLOAT */ 295 296 int8_t HIDS_getHumidity_int8(WE_sensorInterface_t* sensorInterface, int8_t *humidity); 297 int8_t HIDS_getTemperature_int8(WE_sensorInterface_t* sensorInterface, int8_t *tempDegC); 298 299 int8_t HIDS_convertHumidity_int8(WE_sensorInterface_t* sensorInterface, int16_t rawHumidity, int8_t *humidity); 300 int8_t HIDS_convertTemperature_int8(WE_sensorInterface_t* sensorInterface, int16_t rawTemp, int8_t *tempDegC); 301 302 int8_t HIDS_getHumidity_uint16(WE_sensorInterface_t* sensorInterface, uint16_t *humidity); 303 int8_t HIDS_getTemperature_int16(WE_sensorInterface_t* sensorInterface, int16_t *temperature); 304 305 int8_t HIDS_convertHumidity_uint16(WE_sensorInterface_t* sensorInterface, int16_t rawHumidity, uint16_t *humidity); 306 int8_t HIDS_convertTemperature_int16(WE_sensorInterface_t* sensorInterface, int16_t rawTemp, int16_t *temperature); 307 308 int8_t HIDS_readCalibrationData(WE_sensorInterface_t* sensorInterface); 309 310 #ifdef __cplusplus 311 } 312 #endif 313 314 #endif /* _WSEN_HIDS_H */ 315