Low voltage digital temperature sensor

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3 X_NUCLEO_IKS01A3

Committer:
cparata
Date:
Tue May 05 13:50:14 2020 +0000
Revision:
2:2ea2e88ce467
Parent:
1:5859badee052
Fix bug get_temp_limit_status

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cparata 0:128dae13c732 1 /*
cparata 0:128dae13c732 2 ******************************************************************************
cparata 0:128dae13c732 3 * @file stts751_reg.h
cparata 0:128dae13c732 4 * @author Sensors Software Solution Team
cparata 0:128dae13c732 5 * @brief This file contains all the functions prototypes for the
cparata 0:128dae13c732 6 * stts751_reg.c driver.
cparata 0:128dae13c732 7 ******************************************************************************
cparata 0:128dae13c732 8 * @attention
cparata 0:128dae13c732 9 *
cparata 0:128dae13c732 10 * <h2><center>&copy; COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
cparata 0:128dae13c732 11 *
cparata 0:128dae13c732 12 * Redistribution and use in source and binary forms, with or without
cparata 0:128dae13c732 13 * modification, are permitted provided that the following conditions
cparata 0:128dae13c732 14 * are met:
cparata 0:128dae13c732 15 * 1. Redistributions of source code must retain the above copyright notice,
cparata 0:128dae13c732 16 * this list of conditions and the following disclaimer.
cparata 0:128dae13c732 17 * 2. Redistributions in binary form must reproduce the above copyright
cparata 0:128dae13c732 18 * notice, this list of conditions and the following disclaimer in the
cparata 0:128dae13c732 19 * documentation and/or other materials provided with the distribution.
cparata 0:128dae13c732 20 * 3. Neither the name of STMicroelectronics nor the names of its
cparata 0:128dae13c732 21 * contributors may be used to endorse or promote products derived from
cparata 0:128dae13c732 22 * this software without specific prior written permission.
cparata 0:128dae13c732 23 *
cparata 0:128dae13c732 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cparata 0:128dae13c732 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cparata 0:128dae13c732 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
cparata 0:128dae13c732 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
cparata 0:128dae13c732 28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
cparata 0:128dae13c732 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
cparata 0:128dae13c732 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
cparata 0:128dae13c732 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
cparata 0:128dae13c732 32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
cparata 0:128dae13c732 33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
cparata 0:128dae13c732 34 * POSSIBILITY OF SUCH DAMAGE.
cparata 0:128dae13c732 35 *
cparata 0:128dae13c732 36 */
cparata 0:128dae13c732 37
cparata 0:128dae13c732 38 /* Define to prevent recursive inclusion -------------------------------------*/
cparata 0:128dae13c732 39 #ifndef STTS751_REGS_H
cparata 0:128dae13c732 40 #define STTS751_REGS_H
cparata 0:128dae13c732 41
cparata 0:128dae13c732 42 #ifdef __cplusplus
cparata 1:5859badee052 43 extern "C" {
cparata 0:128dae13c732 44 #endif
cparata 0:128dae13c732 45
cparata 0:128dae13c732 46 /* Includes ------------------------------------------------------------------*/
cparata 0:128dae13c732 47 #include <stdint.h>
cparata 0:128dae13c732 48 #include <math.h>
cparata 0:128dae13c732 49
cparata 0:128dae13c732 50 /** @addtogroup STTS751
cparata 0:128dae13c732 51 * @{
cparata 0:128dae13c732 52 *
cparata 0:128dae13c732 53 */
cparata 0:128dae13c732 54
cparata 0:128dae13c732 55 /** @defgroup STTS751_sensors_common_types
cparata 0:128dae13c732 56 * @{
cparata 0:128dae13c732 57 *
cparata 0:128dae13c732 58 */
cparata 0:128dae13c732 59
cparata 0:128dae13c732 60 #ifndef MEMS_SHARED_TYPES
cparata 0:128dae13c732 61 #define MEMS_SHARED_TYPES
cparata 0:128dae13c732 62
cparata 0:128dae13c732 63 /**
cparata 0:128dae13c732 64 * @defgroup axisXbitXX_t
cparata 0:128dae13c732 65 * @brief These unions are useful to represent different sensors data type.
cparata 0:128dae13c732 66 * These unions are not need by the driver.
cparata 0:128dae13c732 67 *
cparata 0:128dae13c732 68 * REMOVING the unions you are compliant with:
cparata 0:128dae13c732 69 * MISRA-C 2012 [Rule 19.2] -> " Union are not allowed "
cparata 0:128dae13c732 70 *
cparata 0:128dae13c732 71 * @{
cparata 0:128dae13c732 72 *
cparata 0:128dae13c732 73 */
cparata 0:128dae13c732 74
cparata 1:5859badee052 75 typedef union {
cparata 1:5859badee052 76 int16_t i16bit[3];
cparata 1:5859badee052 77 uint8_t u8bit[6];
cparata 0:128dae13c732 78 } axis3bit16_t;
cparata 0:128dae13c732 79
cparata 1:5859badee052 80 typedef union {
cparata 1:5859badee052 81 int16_t i16bit;
cparata 1:5859badee052 82 uint8_t u8bit[2];
cparata 0:128dae13c732 83 } axis1bit16_t;
cparata 0:128dae13c732 84
cparata 1:5859badee052 85 typedef union {
cparata 1:5859badee052 86 int32_t i32bit[3];
cparata 1:5859badee052 87 uint8_t u8bit[12];
cparata 0:128dae13c732 88 } axis3bit32_t;
cparata 0:128dae13c732 89
cparata 1:5859badee052 90 typedef union {
cparata 1:5859badee052 91 int32_t i32bit;
cparata 1:5859badee052 92 uint8_t u8bit[4];
cparata 0:128dae13c732 93 } axis1bit32_t;
cparata 0:128dae13c732 94
cparata 0:128dae13c732 95 /**
cparata 0:128dae13c732 96 * @}
cparata 0:128dae13c732 97 *
cparata 0:128dae13c732 98 */
cparata 0:128dae13c732 99
cparata 1:5859badee052 100 typedef struct {
cparata 1:5859badee052 101 uint8_t bit0 : 1;
cparata 1:5859badee052 102 uint8_t bit1 : 1;
cparata 1:5859badee052 103 uint8_t bit2 : 1;
cparata 1:5859badee052 104 uint8_t bit3 : 1;
cparata 1:5859badee052 105 uint8_t bit4 : 1;
cparata 1:5859badee052 106 uint8_t bit5 : 1;
cparata 1:5859badee052 107 uint8_t bit6 : 1;
cparata 1:5859badee052 108 uint8_t bit7 : 1;
cparata 0:128dae13c732 109 } bitwise_t;
cparata 0:128dae13c732 110
cparata 0:128dae13c732 111 #define PROPERTY_DISABLE (0U)
cparata 0:128dae13c732 112 #define PROPERTY_ENABLE (1U)
cparata 0:128dae13c732 113
cparata 0:128dae13c732 114 #endif /* MEMS_SHARED_TYPES */
cparata 0:128dae13c732 115
cparata 0:128dae13c732 116 /**
cparata 0:128dae13c732 117 * @}
cparata 0:128dae13c732 118 *
cparata 0:128dae13c732 119 */
cparata 0:128dae13c732 120
cparata 0:128dae13c732 121 /** @addtogroup STTS751_Interfaces_Functions
cparata 0:128dae13c732 122 * @brief This section provide a set of functions used to read and
cparata 0:128dae13c732 123 * write a generic register of the device.
cparata 0:128dae13c732 124 * MANDATORY: return 0 -> no Error.
cparata 0:128dae13c732 125 * @{
cparata 0:128dae13c732 126 *
cparata 0:128dae13c732 127 */
cparata 0:128dae13c732 128
cparata 1:5859badee052 129 typedef int32_t (*stts751_write_ptr)(void *, uint8_t, uint8_t *, uint16_t);
cparata 1:5859badee052 130 typedef int32_t (*stts751_read_ptr)(void *, uint8_t, uint8_t *, uint16_t);
cparata 0:128dae13c732 131
cparata 0:128dae13c732 132 typedef struct {
cparata 1:5859badee052 133 /** Component mandatory fields **/
cparata 1:5859badee052 134 stts751_write_ptr write_reg;
cparata 1:5859badee052 135 stts751_read_ptr read_reg;
cparata 1:5859badee052 136 /** Customizable optional pointer **/
cparata 1:5859badee052 137 void *handle;
cparata 0:128dae13c732 138 } stts751_ctx_t;
cparata 0:128dae13c732 139
cparata 0:128dae13c732 140 /**
cparata 0:128dae13c732 141 * @}
cparata 0:128dae13c732 142 *
cparata 0:128dae13c732 143 */
cparata 0:128dae13c732 144
cparata 0:128dae13c732 145 /** @defgroup STTS751_Infos
cparata 0:128dae13c732 146 * @{
cparata 0:128dae13c732 147 *
cparata 0:128dae13c732 148 */
cparata 0:128dae13c732 149
cparata 0:128dae13c732 150 /** I2C Device Address 8 bit format **/
cparata 0:128dae13c732 151 #define STTS751_0xxxx_ADD_7K5 0x91U
cparata 0:128dae13c732 152 #define STTS751_0xxxx_ADD_12K 0x93U
cparata 0:128dae13c732 153 #define STTS751_0xxxx_ADD_20K 0x71U
cparata 0:128dae13c732 154 #define STTS751_0xxxx_ADD_33K 0x73U
cparata 0:128dae13c732 155
cparata 0:128dae13c732 156 #define STTS751_1xxxx_ADD_7K5 0x95U
cparata 0:128dae13c732 157 #define STTS751_1xxxx_ADD_12K 0x97U
cparata 0:128dae13c732 158 #define STTS751_1xxxx_ADD_20K 0x75U
cparata 0:128dae13c732 159 #define STTS751_1xxxx_ADD_33K 0x77U
cparata 0:128dae13c732 160
cparata 0:128dae13c732 161 /** Device Identification **/
cparata 0:128dae13c732 162 /* Product ID */
cparata 0:128dae13c732 163 #define STTS751_ID_0xxxx 0x00U
cparata 0:128dae13c732 164 #define STTS751_ID_1xxxx 0x01U
cparata 0:128dae13c732 165 /* Manufacturer ID */
cparata 0:128dae13c732 166 #define STTS751_ID_MAN 0x53U
cparata 0:128dae13c732 167 /* Revision number */
cparata 0:128dae13c732 168 #define STTS751_REV 0x01U
cparata 0:128dae13c732 169
cparata 0:128dae13c732 170 /**
cparata 0:128dae13c732 171 * @}
cparata 0:128dae13c732 172 *
cparata 0:128dae13c732 173 */
cparata 0:128dae13c732 174
cparata 0:128dae13c732 175 #define STTS751_TEMPERATURE_HIGH 0x00U
cparata 0:128dae13c732 176 #define STTS751_STATUS 0x01U
cparata 0:128dae13c732 177 typedef struct {
cparata 1:5859badee052 178 uint8_t thrm : 1;
cparata 1:5859badee052 179 uint8_t not_used_01 : 4;
cparata 1:5859badee052 180 uint8_t t_low : 1;
cparata 1:5859badee052 181 uint8_t t_high : 1;
cparata 1:5859badee052 182 uint8_t busy : 1;
cparata 0:128dae13c732 183 } stts751_status_t;
cparata 0:128dae13c732 184
cparata 0:128dae13c732 185 #define STTS751_TEMPERATURE_LOW 0x02U
cparata 0:128dae13c732 186 #define STTS751_CONFIGURATION 0x03U
cparata 0:128dae13c732 187 typedef struct {
cparata 1:5859badee052 188 uint8_t not_used_01 : 2;
cparata 1:5859badee052 189 uint8_t tres : 2;
cparata 1:5859badee052 190 uint8_t not_used_02 : 2;
cparata 1:5859badee052 191 uint8_t stop : 1;
cparata 1:5859badee052 192 uint8_t mask1 : 1;
cparata 0:128dae13c732 193 } stts751_configuration_t;
cparata 0:128dae13c732 194
cparata 0:128dae13c732 195 #define STTS751_CONVERSION_RATE 0x04U
cparata 0:128dae13c732 196 typedef struct {
cparata 1:5859badee052 197 uint8_t conv : 4;
cparata 1:5859badee052 198 uint8_t not_used_01 : 4;
cparata 0:128dae13c732 199 } stts751_conversion_rate_t;
cparata 0:128dae13c732 200
cparata 0:128dae13c732 201 #define STTS751_TEMPERATURE_HIGH_LIMIT_HIGH 0x05U
cparata 0:128dae13c732 202 #define STTS751_TEMPERATURE_HIGH_LIMIT_LOW 0x06U
cparata 0:128dae13c732 203 #define STTS751_TEMPERATURE_LOW_LIMIT_HIGH 0x07U
cparata 0:128dae13c732 204 #define STTS751_TEMPERATURE_LOW_LIMIT_LOW 0x08U
cparata 0:128dae13c732 205 #define STTS751_ONE_SHOT 0x0FU
cparata 0:128dae13c732 206 #define STTS751_THERM_LIMIT 0x20U
cparata 0:128dae13c732 207 #define STTS751_THERM_HYSTERESIS 0x21U
cparata 0:128dae13c732 208 #define STTS751_SMBUS_TIMEOUT 0x22U
cparata 0:128dae13c732 209 typedef struct {
cparata 1:5859badee052 210 uint8_t not_used_01 : 7;
cparata 1:5859badee052 211 uint8_t timeout : 1;
cparata 0:128dae13c732 212 } stts751_smbus_timeout_t;
cparata 0:128dae13c732 213
cparata 0:128dae13c732 214 #define STTS751_PRODUCT_ID 0xFDU
cparata 0:128dae13c732 215 #define STTS751_MANUFACTURER_ID 0xFEU
cparata 0:128dae13c732 216 #define STTS751_REVISION_ID 0xFFU
cparata 0:128dae13c732 217
cparata 0:128dae13c732 218 /**
cparata 0:128dae13c732 219 * @defgroup STTS751_Register_Union
cparata 0:128dae13c732 220 * @brief This union group all the registers that has a bitfield
cparata 0:128dae13c732 221 * description.
cparata 0:128dae13c732 222 * This union is useful but not need by the driver.
cparata 0:128dae13c732 223 *
cparata 0:128dae13c732 224 * REMOVING this union you are compliant with:
cparata 0:128dae13c732 225 * MISRA-C 2012 [Rule 19.2] -> " Union are not allowed "
cparata 0:128dae13c732 226 *
cparata 0:128dae13c732 227 * @{
cparata 0:128dae13c732 228 *
cparata 0:128dae13c732 229 */
cparata 1:5859badee052 230 typedef union {
cparata 1:5859badee052 231 stts751_status_t status;
cparata 1:5859badee052 232 stts751_configuration_t configuration;
cparata 1:5859badee052 233 stts751_conversion_rate_t conversion_rate;
cparata 1:5859badee052 234 stts751_smbus_timeout_t smbus_timeout;
cparata 1:5859badee052 235 bitwise_t bitwise;
cparata 1:5859badee052 236 uint8_t byte;
cparata 0:128dae13c732 237 } stts751_reg_t;
cparata 0:128dae13c732 238
cparata 0:128dae13c732 239 /**
cparata 0:128dae13c732 240 * @}
cparata 0:128dae13c732 241 *
cparata 0:128dae13c732 242 */
cparata 0:128dae13c732 243
cparata 1:5859badee052 244 int32_t stts751_read_reg(stts751_ctx_t *ctx, uint8_t reg, uint8_t *data,
cparata 1:5859badee052 245 uint16_t len);
cparata 1:5859badee052 246 int32_t stts751_write_reg(stts751_ctx_t *ctx, uint8_t reg, uint8_t *data,
cparata 0:128dae13c732 247 uint16_t len);
cparata 0:128dae13c732 248
cparata 0:128dae13c732 249 extern float stts751_from_lsb_to_celsius(int16_t lsb);
cparata 0:128dae13c732 250 extern int16_t stts751_from_celsius_to_lsb(float celsius);
cparata 0:128dae13c732 251
cparata 0:128dae13c732 252 typedef enum {
cparata 1:5859badee052 253 STTS751_TEMP_ODR_OFF = 0x80,
cparata 1:5859badee052 254 STTS751_TEMP_ODR_ONE_SHOT = 0x90,
cparata 1:5859badee052 255 STTS751_TEMP_ODR_62mHz5 = 0x00,
cparata 1:5859badee052 256 STTS751_TEMP_ODR_125mHz = 0x01,
cparata 1:5859badee052 257 STTS751_TEMP_ODR_250mHz = 0x02,
cparata 1:5859badee052 258 STTS751_TEMP_ODR_500mHz = 0x03,
cparata 1:5859badee052 259 STTS751_TEMP_ODR_1Hz = 0x04,
cparata 1:5859badee052 260 STTS751_TEMP_ODR_2Hz = 0x05,
cparata 1:5859badee052 261 STTS751_TEMP_ODR_4Hz = 0x06,
cparata 1:5859badee052 262 STTS751_TEMP_ODR_8Hz = 0x07,
cparata 1:5859badee052 263 STTS751_TEMP_ODR_16Hz = 0x08, /* 9, 10, or 11-bit resolutions only */
cparata 1:5859badee052 264 STTS751_TEMP_ODR_32Hz = 0x09, /* 9 or 10-bit resolutions only */
cparata 0:128dae13c732 265 } stts751_odr_t;
cparata 0:128dae13c732 266 int32_t stts751_temp_data_rate_set(stts751_ctx_t *ctx, stts751_odr_t val);
cparata 0:128dae13c732 267 int32_t stts751_temp_data_rate_get(stts751_ctx_t *ctx, stts751_odr_t *val);
cparata 0:128dae13c732 268
cparata 0:128dae13c732 269 typedef enum {
cparata 1:5859badee052 270 STTS751_9bit = 2,
cparata 1:5859badee052 271 STTS751_10bit = 0,
cparata 1:5859badee052 272 STTS751_11bit = 1,
cparata 1:5859badee052 273 STTS751_12bit = 3,
cparata 0:128dae13c732 274 } stts751_tres_t;
cparata 0:128dae13c732 275 int32_t stts751_resolution_set(stts751_ctx_t *ctx, stts751_tres_t val);
cparata 0:128dae13c732 276 int32_t stts751_resolution_get(stts751_ctx_t *ctx, stts751_tres_t *val);
cparata 0:128dae13c732 277
cparata 0:128dae13c732 278 int32_t stts751_status_reg_get(stts751_ctx_t *ctx, stts751_status_t *val);
cparata 0:128dae13c732 279
cparata 0:128dae13c732 280 int32_t stts751_flag_busy_get(stts751_ctx_t *ctx, uint8_t *val);
cparata 0:128dae13c732 281
cparata 0:128dae13c732 282 int32_t stts751_temperature_raw_get(stts751_ctx_t *ctx, int16_t *buff);
cparata 0:128dae13c732 283
cparata 0:128dae13c732 284 int32_t stts751_pin_event_route_set(stts751_ctx_t *ctx, uint8_t val);
cparata 0:128dae13c732 285 int32_t stts751_pin_event_route_get(stts751_ctx_t *ctx, uint8_t *val);
cparata 0:128dae13c732 286
cparata 0:128dae13c732 287
cparata 0:128dae13c732 288 int32_t stts751_high_temperature_threshold_set(stts751_ctx_t *ctx,
cparata 0:128dae13c732 289 int16_t buff);
cparata 0:128dae13c732 290 int32_t stts751_high_temperature_threshold_get(stts751_ctx_t *ctx,
cparata 0:128dae13c732 291 int16_t *buff);
cparata 0:128dae13c732 292
cparata 0:128dae13c732 293 int32_t stts751_low_temperature_threshold_set(stts751_ctx_t *ctx,
cparata 0:128dae13c732 294 int16_t buff);
cparata 0:128dae13c732 295 int32_t stts751_low_temperature_threshold_get(stts751_ctx_t *ctx,
cparata 0:128dae13c732 296 int16_t *buff);
cparata 0:128dae13c732 297
cparata 0:128dae13c732 298 int32_t stts751_ota_thermal_limit_set(stts751_ctx_t *ctx, int8_t val);
cparata 0:128dae13c732 299 int32_t stts751_ota_thermal_limit_get(stts751_ctx_t *ctx, int8_t *val);
cparata 0:128dae13c732 300
cparata 0:128dae13c732 301 int32_t stts751_ota_thermal_hyst_set(stts751_ctx_t *ctx, int8_t val);
cparata 0:128dae13c732 302 int32_t stts751_ota_thermal_hyst_get(stts751_ctx_t *ctx, int8_t *val);
cparata 0:128dae13c732 303
cparata 0:128dae13c732 304 int32_t stts751_smbus_timeout_set(stts751_ctx_t *ctx, uint8_t val);
cparata 0:128dae13c732 305 int32_t stts751_smbus_timeout_get(stts751_ctx_t *ctx, uint8_t *val);
cparata 0:128dae13c732 306
cparata 0:128dae13c732 307 typedef struct {
cparata 1:5859badee052 308 uint8_t product_id;
cparata 1:5859badee052 309 uint8_t manufacturer_id;
cparata 1:5859badee052 310 uint8_t revision_id;
cparata 0:128dae13c732 311 } stts751_id_t;
cparata 0:128dae13c732 312 int32_t stts751_device_id_get(stts751_ctx_t *ctx, stts751_id_t *buff);
cparata 0:128dae13c732 313
cparata 0:128dae13c732 314 /**
cparata 0:128dae13c732 315 * @}
cparata 0:128dae13c732 316 *
cparata 0:128dae13c732 317 */
cparata 0:128dae13c732 318
cparata 0:128dae13c732 319 #ifdef __cplusplus
cparata 0:128dae13c732 320 }
cparata 0:128dae13c732 321 #endif
cparata 0:128dae13c732 322
cparata 0:128dae13c732 323 #endif /*STTS751_REGS_H */
cparata 0:128dae13c732 324
cparata 0:128dae13c732 325 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/