1 /** 2 ****************************************************************************** 3 * @file stts751_reg.h 4 * @author Sensors Software Solution Team 5 * @brief This file contains all the functions prototypes for the 6 * stts751_reg.c driver. 7 ****************************************************************************** 8 * @attention 9 * 10 * <h2><center>© Copyright (c) 2021 STMicroelectronics. 11 * All rights reserved.</center></h2> 12 * 13 * This software component is licensed by ST under BSD 3-Clause license, 14 * the "License"; You may not use this file except in compliance with the 15 * License. You may obtain a copy of the License at: 16 * opensource.org/licenses/BSD-3-Clause 17 * 18 ****************************************************************************** 19 */ 20 21 /* Define to prevent recursive inclusion -------------------------------------*/ 22 #ifndef STTS751_REGS_H 23 #define STTS751_REGS_H 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /* Includes ------------------------------------------------------------------*/ 30 #include <stdint.h> 31 #include <stddef.h> 32 #include <math.h> 33 34 /** @addtogroup STTS751 35 * @{ 36 * 37 */ 38 39 /** @defgroup Endianness definitions 40 * @{ 41 * 42 */ 43 44 #ifndef DRV_BYTE_ORDER 45 #ifndef __BYTE_ORDER__ 46 47 #define DRV_LITTLE_ENDIAN 1234 48 #define DRV_BIG_ENDIAN 4321 49 50 /** if _BYTE_ORDER is not defined, choose the endianness of your architecture 51 * by uncommenting the define which fits your platform endianness 52 */ 53 //#define DRV_BYTE_ORDER DRV_BIG_ENDIAN 54 #define DRV_BYTE_ORDER DRV_LITTLE_ENDIAN 55 56 #else /* defined __BYTE_ORDER__ */ 57 58 #define DRV_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ 59 #define DRV_BIG_ENDIAN __ORDER_BIG_ENDIAN__ 60 #define DRV_BYTE_ORDER __BYTE_ORDER__ 61 62 #endif /* __BYTE_ORDER__*/ 63 #endif /* DRV_BYTE_ORDER */ 64 65 /** 66 * @} 67 * 68 */ 69 70 /** @defgroup STMicroelectronics sensors common types 71 * @{ 72 * 73 */ 74 75 #ifndef MEMS_SHARED_TYPES 76 #define MEMS_SHARED_TYPES 77 78 typedef struct 79 { 80 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN 81 uint8_t bit0 : 1; 82 uint8_t bit1 : 1; 83 uint8_t bit2 : 1; 84 uint8_t bit3 : 1; 85 uint8_t bit4 : 1; 86 uint8_t bit5 : 1; 87 uint8_t bit6 : 1; 88 uint8_t bit7 : 1; 89 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN 90 uint8_t bit7 : 1; 91 uint8_t bit6 : 1; 92 uint8_t bit5 : 1; 93 uint8_t bit4 : 1; 94 uint8_t bit3 : 1; 95 uint8_t bit2 : 1; 96 uint8_t bit1 : 1; 97 uint8_t bit0 : 1; 98 #endif /* DRV_BYTE_ORDER */ 99 } bitwise_t; 100 101 #define PROPERTY_DISABLE (0U) 102 #define PROPERTY_ENABLE (1U) 103 104 /** @addtogroup Interfaces_Functions 105 * @brief This section provide a set of functions used to read and 106 * write a generic register of the device. 107 * MANDATORY: return 0 -> no Error. 108 * @{ 109 * 110 */ 111 112 typedef int32_t (*stmdev_write_ptr)(void *, uint8_t, const uint8_t *, uint16_t); 113 typedef int32_t (*stmdev_read_ptr)(void *, uint8_t, uint8_t *, uint16_t); 114 typedef void (*stmdev_mdelay_ptr)(uint32_t millisec); 115 116 typedef struct 117 { 118 /** Component mandatory fields **/ 119 stmdev_write_ptr write_reg; 120 stmdev_read_ptr read_reg; 121 /** Component optional fields **/ 122 stmdev_mdelay_ptr mdelay; 123 /** Customizable optional pointer **/ 124 void *handle; 125 } stmdev_ctx_t; 126 127 /** 128 * @} 129 * 130 */ 131 132 #endif /* MEMS_SHARED_TYPES */ 133 134 #ifndef MEMS_UCF_SHARED_TYPES 135 #define MEMS_UCF_SHARED_TYPES 136 137 /** @defgroup Generic address-data structure definition 138 * @brief This structure is useful to load a predefined configuration 139 * of a sensor. 140 * You can create a sensor configuration by your own or using 141 * Unico / Unicleo tools available on STMicroelectronics 142 * web site. 143 * 144 * @{ 145 * 146 */ 147 148 typedef struct 149 { 150 uint8_t address; 151 uint8_t data; 152 } ucf_line_t; 153 154 /** 155 * @} 156 * 157 */ 158 159 #endif /* MEMS_UCF_SHARED_TYPES */ 160 161 /** 162 * @} 163 * 164 */ 165 166 /** @defgroup STTS751_Infos 167 * @{ 168 * 169 */ 170 171 /** I2C Device Address 8 bit format **/ 172 #define STTS751_0xxxx_ADD_7K5 0x91U 173 #define STTS751_0xxxx_ADD_12K 0x93U 174 #define STTS751_0xxxx_ADD_20K 0x71U 175 #define STTS751_0xxxx_ADD_33K 0x73U 176 177 #define STTS751_1xxxx_ADD_7K5 0x95U 178 #define STTS751_1xxxx_ADD_12K 0x97U 179 #define STTS751_1xxxx_ADD_20K 0x75U 180 #define STTS751_1xxxx_ADD_33K 0x77U 181 182 /** Device Identification **/ 183 /* Product ID */ 184 #define STTS751_ID_0xxxx 0x00U 185 #define STTS751_ID_1xxxx 0x01U 186 /* Manufacturer ID */ 187 #define STTS751_ID_MAN 0x53U 188 /* Revision number */ 189 #define STTS751_REV 0x01U 190 191 /** 192 * @} 193 * 194 */ 195 196 #define STTS751_TEMPERATURE_HIGH 0x00U 197 #define STTS751_STATUS 0x01U 198 typedef struct 199 { 200 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN 201 uint8_t thrm : 1; 202 uint8_t not_used_01 : 4; 203 uint8_t t_low : 1; 204 uint8_t t_high : 1; 205 uint8_t busy : 1; 206 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN 207 uint8_t busy : 1; 208 uint8_t t_high : 1; 209 uint8_t t_low : 1; 210 uint8_t not_used_01 : 4; 211 uint8_t thrm : 1; 212 #endif /* DRV_BYTE_ORDER */ 213 } stts751_status_t; 214 215 #define STTS751_TEMPERATURE_LOW 0x02U 216 #define STTS751_CONFIGURATION 0x03U 217 typedef struct 218 { 219 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN 220 uint8_t not_used_01 : 2; 221 uint8_t tres : 2; 222 uint8_t not_used_02 : 2; 223 uint8_t stop : 1; 224 uint8_t mask1 : 1; 225 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN 226 uint8_t mask1 : 1; 227 uint8_t stop : 1; 228 uint8_t not_used_02 : 2; 229 uint8_t tres : 2; 230 uint8_t not_used_01 : 2; 231 #endif /* DRV_BYTE_ORDER */ 232 } stts751_configuration_t; 233 234 #define STTS751_CONVERSION_RATE 0x04U 235 typedef struct 236 { 237 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN 238 uint8_t conv : 4; 239 uint8_t not_used_01 : 4; 240 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN 241 uint8_t not_used_01 : 4; 242 uint8_t conv : 4; 243 #endif /* DRV_BYTE_ORDER */ 244 } stts751_conversion_rate_t; 245 246 #define STTS751_TEMPERATURE_HIGH_LIMIT_HIGH 0x05U 247 #define STTS751_TEMPERATURE_HIGH_LIMIT_LOW 0x06U 248 #define STTS751_TEMPERATURE_LOW_LIMIT_HIGH 0x07U 249 #define STTS751_TEMPERATURE_LOW_LIMIT_LOW 0x08U 250 #define STTS751_ONE_SHOT 0x0FU 251 #define STTS751_THERM_LIMIT 0x20U 252 #define STTS751_THERM_HYSTERESIS 0x21U 253 #define STTS751_SMBUS_TIMEOUT 0x22U 254 typedef struct 255 { 256 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN 257 uint8_t not_used_01 : 7; 258 uint8_t timeout : 1; 259 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN 260 uint8_t timeout : 1; 261 uint8_t not_used_01 : 7; 262 #endif /* DRV_BYTE_ORDER */ 263 } stts751_smbus_timeout_t; 264 265 #define STTS751_PRODUCT_ID 0xFDU 266 #define STTS751_MANUFACTURER_ID 0xFEU 267 #define STTS751_REVISION_ID 0xFFU 268 269 /** 270 * @defgroup STTS751_Register_Union 271 * @brief This union group all the registers having a bit-field 272 * description. 273 * This union is useful but it's not needed by the driver. 274 * 275 * REMOVING this union you are compliant with: 276 * MISRA-C 2012 [Rule 19.2] -> " Union are not allowed " 277 * 278 * @{ 279 * 280 */ 281 typedef union 282 { 283 stts751_status_t status; 284 stts751_configuration_t configuration; 285 stts751_conversion_rate_t conversion_rate; 286 stts751_smbus_timeout_t smbus_timeout; 287 bitwise_t bitwise; 288 uint8_t byte; 289 } stts751_reg_t; 290 291 /** 292 * @} 293 * 294 */ 295 296 #ifndef __weak 297 #define __weak __attribute__((weak)) 298 #endif /* __weak */ 299 300 /* 301 * These are the basic platform dependent I/O routines to read 302 * and write device registers connected on a standard bus. 303 * The driver keeps offering a default implementation based on function 304 * pointers to read/write routines for backward compatibility. 305 * The __weak directive allows the final application to overwrite 306 * them with a custom implementation. 307 */ 308 309 int32_t stts751_read_reg(const stmdev_ctx_t *ctx, uint8_t reg, 310 uint8_t *data, 311 uint16_t len); 312 int32_t stts751_write_reg(const stmdev_ctx_t *ctx, uint8_t reg, 313 uint8_t *data, 314 uint16_t len); 315 316 float_t stts751_from_lsb_to_celsius(int16_t lsb); 317 int16_t stts751_from_celsius_to_lsb(float_t celsius); 318 319 typedef enum 320 { 321 STTS751_TEMP_ODR_OFF = 0x80, 322 STTS751_TEMP_ODR_ONE_SHOT = 0x90, 323 STTS751_TEMP_ODR_62mHz5 = 0x00, 324 STTS751_TEMP_ODR_125mHz = 0x01, 325 STTS751_TEMP_ODR_250mHz = 0x02, 326 STTS751_TEMP_ODR_500mHz = 0x03, 327 STTS751_TEMP_ODR_1Hz = 0x04, 328 STTS751_TEMP_ODR_2Hz = 0x05, 329 STTS751_TEMP_ODR_4Hz = 0x06, 330 STTS751_TEMP_ODR_8Hz = 0x07, 331 STTS751_TEMP_ODR_16Hz = 0x08, /* 9, 10, or 11-bit resolutions only */ 332 STTS751_TEMP_ODR_32Hz = 0x09, /* 9 or 10-bit resolutions only */ 333 } stts751_odr_t; 334 int32_t stts751_temp_data_rate_set(const stmdev_ctx_t *ctx, 335 stts751_odr_t val); 336 int32_t stts751_temp_data_rate_get(const stmdev_ctx_t *ctx, 337 stts751_odr_t *val); 338 339 typedef enum 340 { 341 STTS751_9bit = 2, 342 STTS751_10bit = 0, 343 STTS751_11bit = 1, 344 STTS751_12bit = 3, 345 } stts751_tres_t; 346 int32_t stts751_resolution_set(const stmdev_ctx_t *ctx, stts751_tres_t val); 347 int32_t stts751_resolution_get(const stmdev_ctx_t *ctx, 348 stts751_tres_t *val); 349 350 int32_t stts751_status_reg_get(const stmdev_ctx_t *ctx, 351 stts751_status_t *val); 352 353 int32_t stts751_flag_busy_get(const stmdev_ctx_t *ctx, uint8_t *val); 354 355 int32_t stts751_temperature_raw_get(const stmdev_ctx_t *ctx, int16_t *val); 356 357 int32_t stts751_pin_event_route_set(const stmdev_ctx_t *ctx, uint8_t val); 358 int32_t stts751_pin_event_route_get(const stmdev_ctx_t *ctx, uint8_t *val); 359 360 361 int32_t stts751_high_temperature_threshold_set(const stmdev_ctx_t *ctx, 362 int16_t val); 363 int32_t stts751_high_temperature_threshold_get(const stmdev_ctx_t *ctx, 364 int16_t *val); 365 366 int32_t stts751_low_temperature_threshold_set(const stmdev_ctx_t *ctx, 367 int16_t val); 368 int32_t stts751_low_temperature_threshold_get(const stmdev_ctx_t *ctx, 369 int16_t *val); 370 371 int32_t stts751_ota_thermal_limit_set(const stmdev_ctx_t *ctx, int8_t val); 372 int32_t stts751_ota_thermal_limit_get(const stmdev_ctx_t *ctx, int8_t *val); 373 374 int32_t stts751_ota_thermal_hyst_set(const stmdev_ctx_t *ctx, int8_t val); 375 int32_t stts751_ota_thermal_hyst_get(const stmdev_ctx_t *ctx, int8_t *val); 376 377 int32_t stts751_smbus_timeout_set(const stmdev_ctx_t *ctx, uint8_t val); 378 int32_t stts751_smbus_timeout_get(const stmdev_ctx_t *ctx, uint8_t *val); 379 380 typedef struct 381 { 382 uint8_t product_id; 383 uint8_t manufacturer_id; 384 uint8_t revision_id; 385 } stts751_id_t; 386 int32_t stts751_device_id_get(const stmdev_ctx_t *ctx, stts751_id_t *buff); 387 388 /** 389 * @} 390 * 391 */ 392 393 #ifdef __cplusplus 394 } 395 #endif 396 397 #endif /*STTS751_REGS_H */ 398 399 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 400