lm75_params.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 ML!PA Consulting GmbH
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
21 #include "board.h"
22 #include "lm75.h"
23 #include "lm75_regs.h"
24 #include "kernel_defines.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #ifndef LM75_PARAM_I2C
31 #define LM75_PARAM_I2C I2C_DEV(0)
32 #endif
33 
37 #ifndef CONFIG_LM75_I2C_ADDR
38 #define CONFIG_LM75_I2C_ADDR (0x48)
39 #endif
40 
41 /* Device operation mode configuration - normal or shutdown */
42 #if IS_ACTIVE(CONFIG_NORMAL_MODE)
43 #define CONFIG_OPERATION_MODE NORMAL_MODE
44 #elif IS_ACTIVE(CONFIG_SHUTDOWN_MODE)
45 #define CONFIG_OPERATION_MODE SHUTDOWN_MODE
46 #endif
47 
48 #ifndef CONFIG_OPERATION_MODE
49 #define CONFIG_OPERATION_MODE NORMAL_MODE
51 #endif
52 
53 /* Device Overtemperature Shutdown operation mode configuration - comparator or interrupt */
54 #if IS_ACTIVE(CONFIG_COMPARATOR_MODE)
55 #define CONFIG_THERMOSTAT_MODE COMPARATOR_MODE
56 #elif IS_ACTIVE(CONFIG_INTERRUPT_MODE)
57 #define CONFIG_THERMOSTAT_MODE INTERRUPT_MODE
58 #endif
59 
60 #ifndef CONFIG_THERMOSTAT_MODE
61 #define CONFIG_THERMOSTAT_MODE COMPARATOR_MODE
63 #endif
64 
65 /* Device Overtemperature Shutdown polarity configuration - OS active low or high */
66 #if IS_ACTIVE(CONFIG_OS_ACTIVE_LOW)
67 #define CONFIG_OS_POLARITY OS_ACTIVE_LOW
68 #elif IS_ACTIVE(CONFIG_OS_ACTIVE_HIGH)
69 #define CONFIG_OS_POLARITY OS_ACTIVE_HIGH
70 #endif
71 
72 #ifndef CONFIG_OS_POLARITY
73 #define CONFIG_OS_POLARITY OS_ACTIVE_LOW
75 #endif
76 
77 /* Device Overtemperatue Shutdown fault queue configuration -
78  * number of faults that must occur consecutively until OS goes active */
79 #if IS_ACTIVE(CONFIG_FAULT_1)
80 #define CONFIG_FAULT_QUEUE FAULT_1
81 #elif IS_ACTIVE(CONFIG_FAULT_2)
82 #define CONFIG_FAULT_QUEUE FAULT_2
83 #elif (IS_ACTIVE(CONFIG_FAULT_3) && IS_USED(MODULE_TMP1075))
84 #define CONFIG_FAULT_QUEUE FAULT_3
85 #elif (IS_ACTIVE(CONFIG_FAULT_4) && IS_USED(MODULE_LM75A))
86 #define CONFIG_FAULT_QUEUE FAULT_4
87 #elif (IS_ACTIVE(CONFIG_FAULT_4) && IS_USED(MODULE_TMP1075))
88 #define CONFIG_FAULT_QUEUE FAULT_4_TMP1075
89 #elif (IS_ACTIVE(CONFIG_FAULT_6) && IS_USED(MODULE_LM75A))
90 #define CONFIG_FAULT_QUEUE FAULT_6
91 #endif
92 
93 #ifndef CONFIG_FAULT_QUEUE
94 #define CONFIG_FAULT_QUEUE FAULT_1
96 #endif
97 
98 #ifndef LM75_PARAM_INT
99 #define LM75_PARAM_INT GPIO_UNDEF
100 #endif
101 
102 #define LM75A_CONV_RATE (100)
104 #define LM75A_OS_RES (5)
105 #define LM75A_OS_MULT (10)
106 #define LM75A_OS_SHIFT (7)
107 #define LM75A_TEMP_RES (125)
108 #define LM75A_TEMP_MULT (1000)
109 #define LM75A_TEMP_SHIFT (5)
111 #define TMP1075_OS_RES (625)
112 #define TMP1075_OS_MULT (10000)
113 #define TMP1075_OS_SHIFT (4)
114 #define TMP1075_TEMP_RES (625)
115 #define TMP1075_TEMP_MULT (10000)
116 #define TMP1075_TEMP_SHIFT (4)
118 /* Device conversion rate configuration - only available in the TMP1075 sensor */
119 #if IS_ACTIVE(CONFIG_TMP1075_CONV_RATE_REG_27H)
120 #define CONFIG_TMP1075_CONV_RATE_REG TMP1075_CONV_RATE_REG_27H
121 #define TMP1075_CONV_RATE (28)
122 #elif IS_ACTIVE(CONFIG_TMP1075_CONV_RATE_REG_55)
123 #define CONFIG_TMP1075_CONV_RATE_REG TMP1075_CONV_RATE_REG_55
124 #define TMP1075_CONV_RATE (55)
125 #elif IS_ACTIVE(CONFIG_TMP1075_CONV_RATE_REG_110)
126 #define CONFIG_TMP1075_CONV_RATE_REG TMP1075_CONV_RATE_REG_110
127 #define TMP1075_CONV_RATE (110)
128 #elif IS_ACTIVE(CONFIG_TMP1075_CONV_RATE_REG_220)
129 #define CONFIG_TMP1075_CONV_RATE_REG TMP1075_CONV_RATE_REG_220
130 #define TMP1075_CONV_RATE (220)
131 #endif
132 
133 #ifndef CONFIG_TMP1075_CONV_RATE_REG
134 #define CONFIG_TMP1075_CONV_RATE_REG TMP1075_CONV_RATE_REG_27H
135 #define TMP1075_CONV_RATE (28)
136 /* this was rounded up to 28ms to retain usage of integers and to keep all times in ms */
137 #endif
138 
139 #ifndef LM75_PARAMS
140 #if IS_USED(MODULE_LM75A)
141 #define LM75_PARAMS { .res = &lm75a_properties, \
142  .gpio_alarm = LM75_PARAM_INT, \
143  .conv_rate = LM75A_CONV_RATE, \
144  .i2c_bus = LM75_PARAM_I2C, \
145  .i2c_addr = CONFIG_LM75_I2C_ADDR, \
146  .shutdown_mode = CONFIG_OPERATION_MODE, \
147  .tm_mode = CONFIG_THERMOSTAT_MODE, \
148  .polarity = CONFIG_OS_POLARITY, \
149  .fault_q = CONFIG_FAULT_QUEUE }
150 
151 #endif
152 
153 #if IS_USED(MODULE_TMP1075)
154 #define LM75_PARAMS { .res = &tmp1075_properties, \
155  .gpio_alarm = LM75_PARAM_INT, \
156  .conv_rate = TMP1075_CONV_RATE, \
157  .i2c_bus = LM75_PARAM_I2C, \
158  .i2c_addr = CONFIG_LM75_I2C_ADDR, \
159  .shutdown_mode = CONFIG_OPERATION_MODE, \
160  .tm_mode = CONFIG_THERMOSTAT_MODE, \
161  .polarity = CONFIG_OS_POLARITY, \
162  .fault_q = CONFIG_FAULT_QUEUE, \
163  .conv_rate_reg = CONFIG_TMP1075_CONV_RATE_REG }
164 #endif
165 #endif /* LM75_PARAMS */
166 
170 static const lm75_params_t lm75_params[] =
171 {
172  LM75_PARAMS
173 };
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
Common macros and compiler attributes/pragmas configuration.
Driver for the LM75 temperature sensor.
Registers for the lm75 and derived (lm75a and tmp1075) temperature sensors.
params required for initialization
Definition: lm75.h:63