thermok  2.0.0.0
thermok.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef THERMOK_H
36 #define THERMOK_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define THERMOK_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.al4 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.al3 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.al2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
59  cfg.al1 = MIKROBUS( mikrobus, MIKROBUS_INT );
60 
66 #define THERMOK_RETVAL uint8_t
67 
68 #define THERMOK_OK 0x00
69 #define THERMOK_INIT_ERROR 0xFF
70 
76 #define THERMOK_DEVICE_SLAVE_ADDR_0 0x60
77 #define THERMOK_DEVICE_SLAVE_ADDR_1 0x61
78 #define THERMOK_DEVICE_SLAVE_ADDR_2 0x62
79 #define THERMOK_DEVICE_SLAVE_ADDR_3 0x63
80 #define THERMOK_DEVICE_SLAVE_ADDR_4 0x64
81 #define THERMOK_DEVICE_SLAVE_ADDR_5 0x65
82 #define THERMOK_DEVICE_SLAVE_ADDR_6 0x66
83 #define THERMOK_DEVICE_SLAVE_ADDR_7 0x67
84 
90 #define THERMOK_REG_HOT_JUNCTION_TEMP_THR 0x00
91 #define THERMOK_REG_JUNCTIONS_TEMP_DELTA_THR 0x01
92 #define THERMOK_REG_COLD_JUNCTION_TEMP_THR 0x02
93 #define THERMOK_REG_RAW_ADC_DATA 0x03
94 #define THERMOK_REG_STATUS 0x04
95 #define THERMOK_REG_SENSOR_CONFIG 0x05
96 #define THERMOK_REG_DEVICE_CONFIG 0x06
97 #define THERMOK_REG_ALERT1_CONFIG 0x08
98 #define THERMOK_REG_ALERT2_CONFIG 0x09
99 #define THERMOK_REG_ALERT3_CONFIG 0x0A
100 #define THERMOK_REG_ALERT4_CONFIG 0x0B
101 #define THERMOK_REG_ALERT1_HYSTERESIS 0x0C
102 #define THERMOK_REG_ALERT2_HYSTERESIS 0x0D
103 #define THERMOK_REG_ALERT3_HYSTERESIS 0x0E
104 #define THERMOK_REG_ALERT4_HYSTERESIS 0x0F
105 #define THERMOK_REG_ALERT1_LIMIT 0x10
106 #define THERMOK_REG_ALERT2_LIMIT 0x11
107 #define THERMOK_REG_ALERT3_LIMIT 0x12
108 #define THERMOK_REG_ALERT4_LIMIT 0x13
109 #define THERMOK_REG_DEVICE_ID 0x20
110 
116 #define THERMOK_SCFG_TYPE_K 0x00
117 #define THERMOK_SCFG_TYPE_J 0x10
118 #define THERMOK_SCFG_TYPE_T 0x20
119 #define THERMOK_SCFG_TYPE_N 0x30
120 #define THERMOK_SCFG_TYPE_S 0x40
121 #define THERMOK_SCFG_TYPE_E 0x50
122 #define THERMOK_SCFG_TYPE_B 0x60
123 #define THERMOK_SCFG_TYPE_R 0x70
124 #define THERMOK_SCFG_FILTER_COEFFICIENT_0 0x00
125 #define THERMOK_SCFG_FILTER_COEFFICIENT_1 0x01
126 #define THERMOK_SCFG_FILTER_COEFFICIENT_2 0x02
127 #define THERMOK_SCFG_FILTER_COEFFICIENT_3 0x03
128 #define THERMOK_SCFG_FILTER_COEFFICIENT_4 0x04
129 #define THERMOK_SCFG_FILTER_COEFFICIENT_5 0x05
130 #define THERMOK_SCFG_FILTER_COEFFICIENT_6 0x06
131 #define THERMOK_SCFG_FILTER_COEFFICIENT_7 0x07
132 
138 #define THERMOK_DCFG_COLD_JUNCTION_RES_0p0625 0x00
139 #define THERMOK_DCFG_COLD_JUNCTION_RES_0p25 0x80
140 #define THERMOK_DCFG_ADC_RES_18bit 0x00
141 #define THERMOK_DCFG_ADC_RES_16bit 0x20
142 #define THERMOK_DCFG_ADC_RES_14bit 0x40
143 #define THERMOK_DCFG_ADC_RES_12bit 0x60
144 #define THERMOK_DCFG_NUM_TEMP_SAMPLES_1 0x00
145 #define THERMOK_DCFG_NUM_TEMP_SAMPLES_2 0x04
146 #define THERMOK_DCFG_NUM_TEMP_SAMPLES_4 0x08
147 #define THERMOK_DCFG_NUM_TEMP_SAMPLES_8 0x0C
148 #define THERMOK_DCFG_NUM_TEMP_SAMPLES_16 0x10
149 #define THERMOK_DCFG_NUM_TEMP_SAMPLES_32 0x14
150 #define THERMOK_DCFG_NUM_TEMP_SAMPLES_64 0x18
151 #define THERMOK_DCFG_NUM_TEMP_SAMPLES_128 0x1C
152 #define THERMOK_DCFG_MODE_NORMAL_OPERATION 0x00
153 #define THERMOK_DCFG_MODE_SHUTDOWN 0x01
154 #define THERMOK_DCFG_MODE_BURST 0x02
155 
161 #define THERMOK_ACFG_INTERRUPT_CLEAR_1 0x80
162 #define THERMOK_ACFG_INTERRUPT_CLEAR_0 0x00
163 #define THERMOK_ACFG_ALERT_MONITOR_TC 0x10
164 #define THERMOK_ACFG_ALERT_MONITOR_TH 0x00
165 #define THERMOK_ACFG_ALERT_LIMIT_RISING 0x08
166 #define THERMOK_ACFG_ALERT_LIMIT_FALLING 0x00
167 #define THERMOK_ACFG_ALERT_ACTIVE_HIGH 0x04
168 #define THERMOK_ACFG_ALERT_ACTIVE_LOW 0x00
169 #define THERMOK_ACFG_ALERT_MODE_INTERRUPT 0x02
170 #define THERMOK_ACFG_ALERT_MODE_COMPARATOR 0x00
171 #define THERMOK_ACFG_ALERT_OUT_ENABLED 0x01
172 #define THERMOK_ACFG_ALERT_OUT_DISABLED 0x00
173 
179 #define THERMOK_AHYS_HYSTERESIS_128C 0x80
180 #define THERMOK_AHYS_HYSTERESIS_64C 0x40
181 #define THERMOK_AHYS_HYSTERESIS_32C 0x20
182 #define THERMOK_AHYS_HYSTERESIS_16C 0x10
183 #define THERMOK_AHYS_HYSTERESIS_8C 0x08
184 #define THERMOK_AHYS_HYSTERESIS_4C 0x04
185 #define THERMOK_AHYS_HYSTERESIS_2C 0x02
186 #define THERMOK_AHYS_HYSTERESIS_1C 0x01
187 
193 #define THERMOK_ALIMIT_1024C 0x4000
194 #define THERMOK_ALIMIT_512C 0x2000
195 #define THERMOK_ALIMIT_255C 0x1000
196 #define THERMOK_ALIMIT_128C 0x0800
197 #define THERMOK_ALIMIT_64C 0x0400
198 #define THERMOK_ALIMIT_32C 0x0200
199 #define THERMOK_ALIMIT_16C 0x0100
200 #define THERMOK_ALIMIT_8C 0x0080
201 #define THERMOK_ALIMIT_4C 0x0040
202 #define THERMOK_ALIMIT_2C 0x0020
203 #define THERMOK_ALIMIT_1C 0x0010
204 #define THERMOK_ALIMIT_0p5C 0x0008
205 #define THERMOK_ALIMIT_0p25C 0x0004
206 #define THERMOK_ALIMIT_SIGN_1 0x8000
207 #define THERMOK_ALIMIT_SIGN_0 0x0000
208 
214 #define THERMOK_DEVICE_ID 0x40
215 #define THERMOK_DEVICE_REV 0x10
216 #define THERMOK_DEVICE_INFO 0x4010
217 
223 #define THERMOK_TEMP_IN_FAHRENHEIT 0x02
224 #define THERMOK_TEMP_IN_KELVIN 0x01
225 #define THERMOK_TEMP_IN_CELSIUS 0x00
226  // End group macro
229 // --------------------------------------------------------------- PUBLIC TYPES
238 typedef struct
239 {
240  // Input pins
241 
242  digital_in_t al4;
243  digital_in_t al3;
244  digital_in_t al2;
245  digital_in_t al1;
246 
247  // Modules
248 
249  i2c_master_t i2c;
250 
251  // ctx variable
252 
253  uint8_t slave_address;
254 
255 } thermok_t;
256 
260 typedef struct
261 {
262  // Communication gpio pins
263 
264  pin_name_t scl;
265  pin_name_t sda;
266 
267  // Additional gpio pins
268 
269  pin_name_t al4;
270  pin_name_t al3;
271  pin_name_t al2;
272  pin_name_t al1;
273 
274  // static variable
275 
276  uint32_t i2c_speed;
277  uint8_t i2c_address;
278 
279 } thermok_cfg_t;
280 
284 typedef struct
285 {
286  uint8_t burst_cmp;
287  uint8_t temp_h_update;
288  uint8_t over_volt;
289  uint8_t alert_4;
290  uint8_t alert_3;
291  uint8_t alert_2;
292  uint8_t alert_1;
293 
295  // End types group
297 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
298 
304 #ifdef __cplusplus
305 extern "C"{
306 #endif
307 
316 void thermok_cfg_setup ( thermok_cfg_t *cfg );
317 
327 
338 void thermok_generic_write ( thermok_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
339 
350 void thermok_generic_read ( thermok_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
351 
358 uint16_t thermok_get_device_info ( thermok_t *ctx );
359 
366 void thermok_get_status ( thermok_t *ctx, thermok_alert_t *status );
367 
377 float thermok_get_temperature ( thermok_t *ctx, uint8_t reg, uint8_t temp_format );
378 
386 void thermok_set_register_cfg ( thermok_t *ctx, uint8_t reg_cfg, uint8_t cfg_data );
387 
394 uint8_t thermok_get_alert_state_1 ( thermok_t *ctx );
395 
402 uint8_t thermok_get_alert_state_2 ( thermok_t *ctx );
403 
410 uint8_t thermok_get_alert_state_3 ( thermok_t *ctx );
411 
418 uint8_t thermok_get_alert_state_4 ( thermok_t *ctx );
419 
420 #ifdef __cplusplus
421 }
422 #endif
423 #endif // _THERMOK_H_
424  // End public_function group
427 
428 // ------------------------------------------------------------------------- END
thermok_t::al3
digital_in_t al3
Definition: thermok.h:243
thermok_alert_t::over_volt
uint8_t over_volt
Definition: thermok.h:288
thermok_cfg_t::al4
pin_name_t al4
Definition: thermok.h:269
thermok_alert_t::alert_3
uint8_t alert_3
Definition: thermok.h:290
thermok_init
THERMOK_RETVAL thermok_init(thermok_t *ctx, thermok_cfg_t *cfg)
Initialization function.
thermok_alert_t::alert_2
uint8_t alert_2
Definition: thermok.h:291
thermok_set_register_cfg
void thermok_set_register_cfg(thermok_t *ctx, uint8_t reg_cfg, uint8_t cfg_data)
Set register config.
THERMOK_RETVAL
#define THERMOK_RETVAL
Definition: thermok.h:66
thermok_alert_t::temp_h_update
uint8_t temp_h_update
Definition: thermok.h:287
thermok_t
Click ctx object definition.
Definition: thermok.h:238
thermok_cfg_t::sda
pin_name_t sda
Definition: thermok.h:265
thermok_cfg_t::scl
pin_name_t scl
Definition: thermok.h:264
thermok_generic_write
void thermok_generic_write(thermok_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
thermok_alert_t::alert_1
uint8_t alert_1
Definition: thermok.h:292
thermok_alert_t::alert_4
uint8_t alert_4
Definition: thermok.h:289
thermok_t::al1
digital_in_t al1
Definition: thermok.h:245
thermok_cfg_t
Click configuration structure definition.
Definition: thermok.h:260
thermok_get_alert_state_4
uint8_t thermok_get_alert_state_4(thermok_t *ctx)
Alert 4 pin state.
thermok_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermok.h:277
thermok_t::al2
digital_in_t al2
Definition: thermok.h:244
thermok_cfg_setup
void thermok_cfg_setup(thermok_cfg_t *cfg)
Config Object Initialization function.
thermok_get_alert_state_3
uint8_t thermok_get_alert_state_3(thermok_t *ctx)
Alert 3 pin state.
thermok_generic_read
void thermok_generic_read(thermok_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
thermok_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermok.h:276
thermok_cfg_t::al1
pin_name_t al1
Definition: thermok.h:272
thermok_t::al4
digital_in_t al4
Definition: thermok.h:242
thermok_t::i2c
i2c_master_t i2c
Definition: thermok.h:249
thermok_get_temperature
float thermok_get_temperature(thermok_t *ctx, uint8_t reg, uint8_t temp_format)
Temperature data.
thermok_cfg_t::al2
pin_name_t al2
Definition: thermok.h:271
thermok_get_status
void thermok_get_status(thermok_t *ctx, thermok_alert_t *status)
Get status.
thermok_get_alert_state_2
uint8_t thermok_get_alert_state_2(thermok_t *ctx)
Alert 2 pin state.
thermok_cfg_t::al3
pin_name_t al3
Definition: thermok.h:270
thermok_get_alert_state_1
uint8_t thermok_get_alert_state_1(thermok_t *ctx)
Alert 1 pin state.
thermok_get_device_info
uint16_t thermok_get_device_info(thermok_t *ctx)
Functions for read device info.
thermok_t::slave_address
uint8_t slave_address
Definition: thermok.h:253
thermok_alert_t
Alert structure definition.
Definition: thermok.h:284
thermok_alert_t::burst_cmp
uint8_t burst_cmp
Definition: thermok.h:286