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>&copy; 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 
115 typedef struct
116 {
117   /** Component mandatory fields **/
118   stmdev_write_ptr  write_reg;
119   stmdev_read_ptr   read_reg;
120   /** Customizable optional pointer **/
121   void *handle;
122 } stmdev_ctx_t;
123 
124 /**
125   * @}
126   *
127   */
128 
129 #endif /* MEMS_SHARED_TYPES */
130 
131 #ifndef MEMS_UCF_SHARED_TYPES
132 #define MEMS_UCF_SHARED_TYPES
133 
134 /** @defgroup    Generic address-data structure definition
135   * @brief       This structure is useful to load a predefined configuration
136   *              of a sensor.
137   *              You can create a sensor configuration by your own or using
138   *              Unico / Unicleo tools available on STMicroelectronics
139   *              web site.
140   *
141   * @{
142   *
143   */
144 
145 typedef struct
146 {
147   uint8_t address;
148   uint8_t data;
149 } ucf_line_t;
150 
151 /**
152   * @}
153   *
154   */
155 
156 #endif /* MEMS_UCF_SHARED_TYPES */
157 
158 /**
159   * @}
160   *
161   */
162 
163 /** @defgroup STTS751_Infos
164   * @{
165   *
166   */
167 
168 /** I2C Device Address 8 bit format **/
169 #define STTS751_0xxxx_ADD_7K5  0x91U
170 #define STTS751_0xxxx_ADD_12K  0x93U
171 #define STTS751_0xxxx_ADD_20K  0x71U
172 #define STTS751_0xxxx_ADD_33K  0x73U
173 
174 #define STTS751_1xxxx_ADD_7K5  0x95U
175 #define STTS751_1xxxx_ADD_12K  0x97U
176 #define STTS751_1xxxx_ADD_20K  0x75U
177 #define STTS751_1xxxx_ADD_33K  0x77U
178 
179 /** Device Identification **/
180 /* Product ID */
181 #define STTS751_ID_0xxxx       0x00U
182 #define STTS751_ID_1xxxx       0x01U
183 /* Manufacturer ID */
184 #define STTS751_ID_MAN         0x53U
185 /* Revision number */
186 #define STTS751_REV            0x01U
187 
188 /**
189   * @}
190   *
191   */
192 
193 #define STTS751_TEMPERATURE_HIGH            0x00U
194 #define STTS751_STATUS                      0x01U
195 typedef struct
196 {
197 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
198   uint8_t thrm                       : 1;
199   uint8_t not_used_01                : 4;
200   uint8_t t_low                      : 1;
201   uint8_t t_high                     : 1;
202   uint8_t busy                       : 1;
203 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
204   uint8_t busy                       : 1;
205   uint8_t t_high                     : 1;
206   uint8_t t_low                      : 1;
207   uint8_t not_used_01                : 4;
208   uint8_t thrm                       : 1;
209 #endif /* DRV_BYTE_ORDER */
210 } stts751_status_t;
211 
212 #define STTS751_TEMPERATURE_LOW             0x02U
213 #define STTS751_CONFIGURATION               0x03U
214 typedef struct
215 {
216 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
217   uint8_t not_used_01                : 2;
218   uint8_t tres                       : 2;
219   uint8_t not_used_02                : 2;
220   uint8_t stop                       : 1;
221   uint8_t mask1                      : 1;
222 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
223   uint8_t mask1                      : 1;
224   uint8_t stop                       : 1;
225   uint8_t not_used_02                : 2;
226   uint8_t tres                       : 2;
227   uint8_t not_used_01                : 2;
228 #endif /* DRV_BYTE_ORDER */
229 } stts751_configuration_t;
230 
231 #define STTS751_CONVERSION_RATE             0x04U
232 typedef struct
233 {
234 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
235   uint8_t conv                       : 4;
236   uint8_t not_used_01                : 4;
237 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
238   uint8_t not_used_01                : 4;
239   uint8_t conv                       : 4;
240 #endif /* DRV_BYTE_ORDER */
241 } stts751_conversion_rate_t;
242 
243 #define STTS751_TEMPERATURE_HIGH_LIMIT_HIGH 0x05U
244 #define STTS751_TEMPERATURE_HIGH_LIMIT_LOW  0x06U
245 #define STTS751_TEMPERATURE_LOW_LIMIT_HIGH  0x07U
246 #define STTS751_TEMPERATURE_LOW_LIMIT_LOW   0x08U
247 #define STTS751_ONE_SHOT                    0x0FU
248 #define STTS751_THERM_LIMIT                 0x20U
249 #define STTS751_THERM_HYSTERESIS            0x21U
250 #define STTS751_SMBUS_TIMEOUT               0x22U
251 typedef struct
252 {
253 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
254   uint8_t not_used_01                : 7;
255   uint8_t timeout                    : 1;
256 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
257   uint8_t timeout                    : 1;
258   uint8_t not_used_01                : 7;
259 #endif /* DRV_BYTE_ORDER */
260 } stts751_smbus_timeout_t;
261 
262 #define STTS751_PRODUCT_ID                  0xFDU
263 #define STTS751_MANUFACTURER_ID             0xFEU
264 #define STTS751_REVISION_ID                 0xFFU
265 
266 /**
267   * @defgroup STTS751_Register_Union
268   * @brief    This union group all the registers having a bit-field
269   *           description.
270   *           This union is useful but it's not needed by the driver.
271   *
272   *           REMOVING this union you are compliant with:
273   *           MISRA-C 2012 [Rule 19.2] -> " Union are not allowed "
274   *
275   * @{
276   *
277   */
278 typedef union
279 {
280   stts751_status_t                       status;
281   stts751_configuration_t                configuration;
282   stts751_conversion_rate_t              conversion_rate;
283   stts751_smbus_timeout_t                smbus_timeout;
284   bitwise_t                              bitwise;
285   uint8_t                                byte;
286 } stts751_reg_t;
287 
288 /**
289   * @}
290   *
291   */
292 
293 int32_t stts751_read_reg(stmdev_ctx_t *ctx, uint8_t reg,
294                          uint8_t *data,
295                          uint16_t len);
296 int32_t stts751_write_reg(stmdev_ctx_t *ctx, uint8_t reg,
297                           uint8_t *data,
298                           uint16_t len);
299 
300 float_t stts751_from_lsb_to_celsius(int16_t lsb);
301 int16_t stts751_from_celsius_to_lsb(float_t celsius);
302 
303 typedef enum
304 {
305   STTS751_TEMP_ODR_OFF        = 0x80,
306   STTS751_TEMP_ODR_ONE_SHOT   = 0x90,
307   STTS751_TEMP_ODR_62mHz5     = 0x00,
308   STTS751_TEMP_ODR_125mHz     = 0x01,
309   STTS751_TEMP_ODR_250mHz     = 0x02,
310   STTS751_TEMP_ODR_500mHz     = 0x03,
311   STTS751_TEMP_ODR_1Hz        = 0x04,
312   STTS751_TEMP_ODR_2Hz        = 0x05,
313   STTS751_TEMP_ODR_4Hz        = 0x06,
314   STTS751_TEMP_ODR_8Hz        = 0x07,
315   STTS751_TEMP_ODR_16Hz       = 0x08, /* 9, 10, or 11-bit resolutions only */
316   STTS751_TEMP_ODR_32Hz       = 0x09, /* 9 or 10-bit resolutions only */
317 } stts751_odr_t;
318 int32_t stts751_temp_data_rate_set(stmdev_ctx_t *ctx,
319                                    stts751_odr_t val);
320 int32_t stts751_temp_data_rate_get(stmdev_ctx_t *ctx,
321                                    stts751_odr_t *val);
322 
323 typedef enum
324 {
325   STTS751_9bit      = 2,
326   STTS751_10bit     = 0,
327   STTS751_11bit     = 1,
328   STTS751_12bit     = 3,
329 } stts751_tres_t;
330 int32_t stts751_resolution_set(stmdev_ctx_t *ctx, stts751_tres_t val);
331 int32_t stts751_resolution_get(stmdev_ctx_t *ctx,
332                                stts751_tres_t *val);
333 
334 int32_t stts751_status_reg_get(stmdev_ctx_t *ctx,
335                                stts751_status_t *val);
336 
337 int32_t stts751_flag_busy_get(stmdev_ctx_t *ctx, uint8_t *val);
338 
339 int32_t stts751_temperature_raw_get(stmdev_ctx_t *ctx, int16_t *val);
340 
341 int32_t stts751_pin_event_route_set(stmdev_ctx_t *ctx, uint8_t val);
342 int32_t stts751_pin_event_route_get(stmdev_ctx_t *ctx, uint8_t *val);
343 
344 
345 int32_t stts751_high_temperature_threshold_set(stmdev_ctx_t *ctx,
346                                                int16_t val);
347 int32_t stts751_high_temperature_threshold_get(stmdev_ctx_t *ctx,
348                                                int16_t *val);
349 
350 int32_t stts751_low_temperature_threshold_set(stmdev_ctx_t *ctx,
351                                               int16_t val);
352 int32_t stts751_low_temperature_threshold_get(stmdev_ctx_t *ctx,
353                                               int16_t *val);
354 
355 int32_t stts751_ota_thermal_limit_set(stmdev_ctx_t *ctx, int8_t val);
356 int32_t stts751_ota_thermal_limit_get(stmdev_ctx_t *ctx, int8_t *val);
357 
358 int32_t stts751_ota_thermal_hyst_set(stmdev_ctx_t *ctx, int8_t val);
359 int32_t stts751_ota_thermal_hyst_get(stmdev_ctx_t *ctx, int8_t *val);
360 
361 int32_t stts751_smbus_timeout_set(stmdev_ctx_t *ctx, uint8_t val);
362 int32_t stts751_smbus_timeout_get(stmdev_ctx_t *ctx, uint8_t *val);
363 
364 typedef struct
365 {
366   uint8_t product_id;
367   uint8_t manufacturer_id;
368   uint8_t revision_id;
369 } stts751_id_t;
370 int32_t stts751_device_id_get(stmdev_ctx_t *ctx, stts751_id_t *buff);
371 
372 /**
373   * @}
374   *
375   */
376 
377 #ifdef __cplusplus
378 }
379 #endif
380 
381 #endif /*STTS751_REGS_H */
382 
383 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
384