1 /*
2  * Copyright (c) 2020 Innoseis BV
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_SENSOR_TMP112_TMP112_H_
8 #define ZEPHYR_DRIVERS_SENSOR_TMP112_TMP112_H_
9 
10 #include <zephyr/device.h>
11 #include <zephyr/sys/util.h>
12 
13 #define TMP112_REG_TEMPERATURE          0x00
14 #define TMP112_DATA_INVALID_BIT         (BIT(1) | BIT(2))
15 #define TMP112_DATA_EXTENDED            (BIT(0))
16 #define TMP112_DATA_EXTENDED_SHIFT      3
17 #define TMP112_DATA_NORMAL_SHIFT        4
18 
19 
20 #define TMP112_REG_CONFIG   0x01
21 #define TMP112_CONFIG_EM    BIT(4)
22 
23 #define TMP112_ALERT_EN_BIT     BIT(5)
24 #define TMP112_CONV_RATE_SHIFT  6
25 #define TMP112_CONV_RATE_MASK   (BIT_MASK(2) <<  TMP112_CONV_RATE_SHIFT)
26 #define TMP112_CONV_RATE_025    0
27 #define TMP112_CONV_RATE_1000   1
28 #define TMP112_CONV_RATE_4      2
29 #define TMP112_CONV_RATE_8      3
30 
31 #define TMP112_CONV_RATE(cr)    ((cr) << TMP112_CONV_RATE_SHIFT)
32 
33 #define TMP112_CONV_RES_SHIFT   13
34 #define TMP112_CONV_RES_MASK    (BIT_MASK(2) << TMP112_CONV_RES_SHIFT)
35 
36 #define TMP112_ONE_SHOT         BIT(15)
37 
38 #define TMP112_REG_TLOW         0x02
39 #define TMP112_REG_THIGH        0x03
40 
41 /* scale in micro degrees Celsius */
42 #define TMP112_TEMP_SCALE       62500
43 
44 struct tmp112_data {
45 	int16_t sample;
46 	uint16_t config_reg;
47 };
48 
49 struct tmp112_config {
50 	const struct i2c_dt_spec bus;
51 	uint8_t cr;
52 	bool extended_mode : 1;
53 };
54 
55 #endif
56