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-TIDS sensor driver. 10 * 11 * #### INFORMATIVE #### 12 * This sensor only has a I2C communication interface. 13 */ 14 15 #ifndef _WSEN_TIDS_H 16 #define _WSEN_TIDS_H 17 18 /* Includes */ 19 20 #include <stdint.h> 21 22 #include <WeSensorsSDK.h> 23 24 25 /* TIDS 2521020222501 DEVICE_ID */ 26 27 #define TIDS_DEVICE_ID_VALUE 0xA0 /**< Device ID of TIDS 2521020222501 Sensor */ 28 29 30 /* Available TIDS I2C slave addresses */ 31 32 #define TIDS_ADDRESS_I2C_0 0x3F /**< When SAO of TIDS is connected to ground */ 33 #define TIDS_ADDRESS_I2C_1 0x38 /**< When SAO of TIDS is connected to positive supply voltage */ 34 35 36 /* Register address definitions */ 37 38 #define TIDS_DEVICE_ID_REG 0x01 /**< Device ID register */ 39 #define TIDS_LIMIT_T_H_REG 0x02 /**< Temperature high limit register */ 40 #define TIDS_LIMIT_T_L_REG 0x03 /**< Temperature low limit register */ 41 #define TIDS_CTRL_REG 0x04 /**< Control register */ 42 #define TIDS_STATUS_REG 0x05 /**< Status register */ 43 #define TIDS_DATA_T_L_REG 0x06 /**< Temperature output LSB value register */ 44 #define TIDS_DATA_T_H_REG 0x07 /**< Temperature output MSB value register */ 45 #define TIDS_SOFT_RESET_REG 0x0C /**< Software reset register */ 46 47 48 /* Register type definitions */ 49 50 /** 51 * @brief Control register 52 * Address 0x04 53 * Type R/W 54 * Default value: 0x00 55 * 56 * AVG1 | AVG0 | Temperature output data-rate (Hz) 57 * ---------------- ---------------------------------------------------- 58 * 0 | 0 | 25 59 * 0 | 1 | 50 60 * 1 | 0 | 100 61 * 1 | 1 | 200 62 */ 63 typedef struct 64 { 65 uint8_t oneShotBit : 1; /**< Trigger a single measurement by setting this bit to 1; Bit is automatically reset to 0 */ 66 uint8_t reserved01 : 1; /**< Must be set to 0 */ 67 uint8_t freeRunBit : 1; /**< FREERUN: 1: Enable continuous mode, 0: Disable continuous mode */ 68 uint8_t autoAddIncr : 1; /**< IF_ADD_INC: Register address automatically incremented during a multiple byte access with I2C interface. Default value 1 (0: disable; 1: enable) */ 69 uint8_t outputDataRate : 2; /**< AVG[1:0]: Output data rate in continuous mode. Default '00' */ 70 uint8_t blockDataUpdate : 1; /**< BDU: Block data update. 0: continuous update; 1: output registers are not updated until both MSB and LSB have been read */ 71 uint8_t reserved02 : 1; /**< Must be set to 0 */ 72 } TIDS_ctrl_t; 73 74 /** 75 * @brief Status register 76 * Address 0x05 77 * Type R 78 * Default value: Output; 0x00 79 */ 80 typedef struct 81 { 82 uint8_t busy : 1; /**< BUSY: Temperature conversion status (0: data conversion complete; 1: data conversion in progress) */ 83 uint8_t upperLimitExceeded : 1; /**< OVER_THL: Temperature upper limit status (0: temperature is below upper limit or disabled; 1: temperature exceeded high limit */ 84 uint8_t lowerLimitExceeded : 2; /**< UNDER_TLL: Temperature lower limit status (0: temperature is above lower limit or disabled; 1: temperature exceeded low limit */ 85 uint8_t reserved01 : 5; /**< Must be set to 0 */ 86 } TIDS_status_t; 87 88 /** 89 * @brief Software reset register 90 * Address 0x0C 91 * Type R/W 92 * Default value: 0x00 93 */ 94 typedef struct 95 { 96 uint8_t reserved01 : 1; /**< Must be set to 0 */ 97 uint8_t reset : 1; /**< SOFT_RESET: Perform software reset by setting this bit to 1 */ 98 uint8_t reserved02 : 6; /**< Must be set to 0 */ 99 } TIDS_softReset_t; 100 101 102 /* Functional type definition */ 103 104 typedef enum 105 { 106 TIDS_disable = 0, 107 TIDS_enable = 1 108 } TIDS_state_t; 109 110 111 typedef enum 112 { 113 TIDS_outputDataRate25Hz = 0, /**< 25 Hz */ 114 TIDS_outputDataRate50Hz = 1, /**< 50 Hz */ 115 TIDS_outputDataRate100Hz = 2, /**< 100 Hz */ 116 TIDS_outputDataRate200Hz = 3, /**< 200 Hz */ 117 } TIDS_outputDataRate_t; 118 119 120 #ifdef __cplusplus 121 extern "C" 122 { 123 #endif 124 125 /* Function definitions */ 126 127 /* Sensor/interface initialization */ 128 int8_t TIDS_getDefaultInterface(WE_sensorInterface_t* sensorInterface); 129 130 /* Device ID */ 131 int8_t TIDS_getDeviceID(WE_sensorInterface_t* sensorInterface, uint8_t *deviceID); 132 133 /* Software reset */ 134 int8_t TIDS_softReset(WE_sensorInterface_t* sensorInterface, TIDS_state_t swReset); 135 int8_t TIDS_getSoftResetState(WE_sensorInterface_t* sensorInterface, TIDS_state_t *swReset); 136 137 /* Free run mode */ 138 int8_t TIDS_enableContinuousMode(WE_sensorInterface_t* sensorInterface, TIDS_state_t mode); 139 int8_t TIDS_isContinuousModeEnabled(WE_sensorInterface_t* sensorInterface, TIDS_state_t *mode); 140 141 /* Block data update */ 142 int8_t TIDS_enableBlockDataUpdate(WE_sensorInterface_t* sensorInterface, TIDS_state_t bdu); 143 int8_t TIDS_isBlockDataUpdateEnabled(WE_sensorInterface_t* sensorInterface, TIDS_state_t *bdu); 144 145 /* Output data rate */ 146 int8_t TIDS_setOutputDataRate(WE_sensorInterface_t* sensorInterface, TIDS_outputDataRate_t odr); 147 int8_t TIDS_getOutputDataRate(WE_sensorInterface_t* sensorInterface, TIDS_outputDataRate_t* odr); 148 149 /* One shot mode */ 150 int8_t TIDS_enableOneShot(WE_sensorInterface_t* sensorInterface, TIDS_state_t oneShot); 151 int8_t TIDS_isOneShotEnabled(WE_sensorInterface_t* sensorInterface, TIDS_state_t *oneShot); 152 153 /* Address auto increment */ 154 int8_t TIDS_enableAutoIncrement(WE_sensorInterface_t* sensorInterface, TIDS_state_t autoIncr); 155 int8_t TIDS_isAutoIncrementEnabled(WE_sensorInterface_t* sensorInterface, TIDS_state_t *autoIncr); 156 157 /* Temperature limits */ 158 int8_t TIDS_setTempHighLimit(WE_sensorInterface_t* sensorInterface, uint8_t hLimit); 159 int8_t TIDS_getTempHighLimit(WE_sensorInterface_t* sensorInterface, uint8_t *hLimit); 160 161 int8_t TIDS_setTempLowLimit(WE_sensorInterface_t* sensorInterface, uint8_t lLimit); 162 int8_t TIDS_getTempLowLimit(WE_sensorInterface_t* sensorInterface, uint8_t *lLimit); 163 164 /* Status */ 165 int8_t TIDS_getStatusRegister(WE_sensorInterface_t* sensorInterface, TIDS_status_t *status); 166 int8_t TIDS_isBusy(WE_sensorInterface_t* sensorInterface, TIDS_state_t *busy); 167 int8_t TIDS_isUpperLimitExceeded(WE_sensorInterface_t* sensorInterface, TIDS_state_t *state); 168 int8_t TIDS_isLowerLimitExceeded(WE_sensorInterface_t* sensorInterface, TIDS_state_t *state); 169 170 /* Standard data out */ 171 int8_t TIDS_getRawTemperature(WE_sensorInterface_t* sensorInterface, int16_t *rawTemp); 172 int8_t TIDS_getTemperature(WE_sensorInterface_t* sensorInterface, float *tempDegC); 173 174 #ifdef __cplusplus 175 } 176 #endif 177 178 #endif /* _WSEN_TIDS_H */ 179