thermo5  2.0.0.0
thermo5.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 THERMO5_H
36 #define THERMO5_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define THERMO5_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
56 
62 #define THERMO5_RETVAL uint8_t
63 
64 #define THERMO5_OK 0x00
65 #define THERMO5_INIT_ERROR 0xFF
66 
72 #define THERMO5_I2C_ADDRESS 0x4C
73 
79 #define THERMO5_INTER_DIO_DATA_HI_BYTE 0x00
80 #define THERMO5_INTER_DIO_DATA_LO_BYTE 0x29
81 #define THERMO5_EXTER_DIO_1_DATA_HI_BYTE 0x01
82 #define THERMO5_EXTER_DIO_1_DATA_LO_BYTE 0x10
83 #define THERMO5_EXTER_DIO_2_DATA_HI_BYTE 0x23
84 #define THERMO5_EXTER_DIO_2_DATA_LO_BYTE 0x24
85 #define THERMO5_EXTER_DIO_3_HI_BYTE 0x2A
86 #define THERMO5_EXTER_DIO_3_LO_BYTE 0x2B
87 
88 #define THERMO5_INTER_DIODE 0x0029
89 #define THERMO5_EXTER_DIODE1 0x0110
90 #define THERMO5_EXTER_DIODE2 0x2324
91 #define THERMO5_EXTER_DIODE3 0x2A2B
92 
98 #define THERMO5_STAT 0x02
99 
105 #define THERMO5_CONFIG 0x03
106 
112 #define THERMO5_CONVERS_RATE 0x04
113 
119 #define THERMO5_INTER_DIO_HI_LIM 0x05
120 #define THERMO5_INTER_DIO_LO_LIM 0x06
121 #define THERMO5_EXTER_DIO_1_HI_LIM_HI_BYTE 0x07
122 #define THERMO5_EXTER_DIO_1_HI_LIM_LO_BYTE 0x13
123 #define THERMO5_EXTER_DIO_1_LO_LIM_HI_BYTE 0x08
124 #define THERMO5_EXTER_DIO_1_LO_LIM_LO_BYTE 0x14
125 #define THERMO5_EXTER_DIO_2_HI_LIM_HI_BYTE 0x15
126 #define THERMO5_EXTER_DIO_2_LO_LIM_HI_BYTE 0x16
127 #define THERMO5_EXTER_DIO_2_HI_LIM_LO_BYTE 0x17
128 #define THERMO5_EXTER_DIO_2_LO_LIM_LO_BYTE 0x18
129 #define THERMO5_EXTER_DIO_3_HI_LIM_HI_BYTE 0x2C
130 #define THERMO5_EXTER_DIO_3_LO_LIM_HI_BYTE 0x2D
131 #define THERMO5_EXTER_DIO_3_HI_LIM_LO_BYTE 0x2E
132 #define THERMO5_EXTER_DIO_3_LO_LIM_LO_BYTE 0x2F
133 
139 #define THERMO5_SCRATCHPAD_1 0x11
140 #define THERMO5_SCRATCHPAD_2 0x12
141 
147 #define THERMO5_ONE_SHOT 0x0F
148 
154 #define THERMO5_EXTER_DIO_1_THERM_LIM 0x19
155 #define THERMO5_EXTER_DIO_2_THERM_LIM 0x1A
156 #define THERMO5_INTER_DIO_THERM_LIM 0x20
157 #define THERMO5_THERM_HYSTERESIS 0x21
158 #define THERMO5_EXTER_DIO_3_THERM_LIM 0x30
159 
165 #define THERMO5_EXTER_DIO_FAULT 0x1B
166 
172 #define THERMO5_CHANNEL_MASK_REGISTER 0x1F
173 
179 #define THERMO5_CONSECUTIVE_ALERT 0x22
180 
186 #define THERMO5_EXTER_DIO_1_BETA_CONFIG 0x25
187 #define THERMO5_EXTER_DIO_2_BETA_CONFIG 0x26
188 
194 #define THERMO5_EXTER_DIO_1_IDE_FAC 0x27
195 #define THERMO5_EXTER_DIO_2_IDE_FAC 0x28
196 #define THERMO5_EXTER_DIO_3_IDE_FAC 0x31
197 
203 #define THERMO5_HI_LIM_STAT 0x35
204 
210 #define THERMO5_LO_LIM_STAT 0x36
211 
217 #define THERMO5_THERM_LIM_STAT 0x37
218 
224 #define THERMO5_FILTER_CONTROL 0x40
225 
231 #define THERMO5_PRODUCT_ID 0xFD
232 
238 #define THERMO5_MANUFACTURER_ID 0xFE
239 
245 #define THERMO5_REVISION 0xFF
246 
252 #define THERMO5_CONVER_RATE_0_0625 0x00
253 #define THERMO5_CONVER_RATE_0_125 0x01
254 #define THERMO5_CONVER_RATE_0_25 0x02
255 #define THERMO5_CONVER_RATE_0_5 0x03
256 #define THERMO5_CONVER_RATE_1 0x04
257 #define THERMO5_CONVER_RATE_2 0x05
258 #define THERMO5_CONVER_RATE_4 0x06
259 #define THERMO5_CONVER_RATE_8 0x07
260 #define THERMO5_CONVER_RATE_16 0x08
261 #define THERMO5_CONVER_RATE_32 0x09
262 #define THERMO5_CONVER_RATE_64 0x0A
263 
269 #define THERMO5_FILTER_DECODE_DISABLE 0x00
270 #define THERMO5_FILTER_DECODE_LEVEL_1 0x01
271 #define THERMO5_FILTER_DECODE_AVERAGE 0x02
272 #define THERMO5_FILTER_DECODE_LEVEL_2 0x03
273  // End group macro
276 // --------------------------------------------------------------- PUBLIC TYPES
285 typedef struct
286 {
287  // Input pins
288 
289  digital_in_t int_pin;
290 
291  // Modules
292 
293  i2c_master_t i2c;
294 
295  // ctx variable
296 
297  uint8_t slave_address;
298 
299 } thermo5_t;
300 
304 typedef struct
305 {
306  // Communication gpio pins
307 
308  pin_name_t scl;
309  pin_name_t sda;
310 
311  // Additional gpio pins
312 
313  pin_name_t int_pin;
314 
315  // static variable
316 
317  uint32_t i2c_speed;
318  uint8_t i2c_address;
319 
320 } thermo5_cfg_t;
321  // End types group
323 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
324 
330 #ifdef __cplusplus
331 extern "C"{
332 #endif
333 
342 void thermo5_cfg_setup ( thermo5_cfg_t *cfg );
343 
353 
364 void thermo5_generic_write ( thermo5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
365 
376 void thermo5_generic_read ( thermo5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
377 
387 void thermo5_write_byte ( thermo5_t *ctx, uint8_t wr_addr, uint8_t wr_data );
388 
397 uint8_t thermo5_read_byte ( thermo5_t *ctx, uint8_t rd_addr );
398 
407 uint16_t thermo5_read_data ( thermo5_t *ctx, uint16_t reg_addr );
408 
416 float thermo5_read_inter_temp ( thermo5_t *ctx );
417 
426 
435 
444 
452 uint8_t thermo5_read_product_id ( thermo5_t *ctx );
453 
461 uint8_t thermo5_read_manufacturer_id ( thermo5_t *ctx );
462 
471 
479 uint8_t thermo5_get_interrupt_state ( thermo5_t *ctx );
480 
488 uint8_t thermo5_read_stat_reg ( thermo5_t *ctx );
489 
499 
509 
518 uint8_t thermo5_read_low_limit_stat ( thermo5_t *ctx );
519 
528 uint8_t thermo5_read_high_limit_stat ( thermo5_t *ctx );
529 
538 void thermo5_write_config ( thermo5_t *ctx, uint8_t wr_data );
539 
547 uint8_t thermo5_read_config ( thermo5_t *ctx );
548 
557 void thermo5_set_convers_rate ( thermo5_t *ctx, uint8_t convers_rate );
558 
566 uint8_t thermo5_read_convers_rate ( thermo5_t *ctx );
567 
576 void thermo5_set_filter_rate ( thermo5_t *ctx, uint8_t filter_decode_rate );
577 
585 uint8_t thermo5_read_filter_rate ( thermo5_t *ctx );
586 
595 void thermo5_set_diode_1_beta_config ( thermo5_t *ctx, uint8_t enable );
596 
605 
614 void thermo5_set_diode_2_beta_config ( thermo5_t *ctx, uint8_t enable );
615 
624 
625 #ifdef __cplusplus
626 }
627 #endif
628 #endif // _THERMO5_H_
629  // End public_function group
632 
633 // ------------------------------------------------------------------------- END
thermo5_set_diode_2_beta_config
void thermo5_set_diode_2_beta_config(thermo5_t *ctx, uint8_t enable)
Set External Diode 2 Beta Configuration function.
thermo5_cfg_setup
void thermo5_cfg_setup(thermo5_cfg_t *cfg)
Config Object Initialization function.
thermo5_read_config
uint8_t thermo5_read_config(thermo5_t *ctx)
Read configuration function.
thermo5_read_therm_limit_stat
uint8_t thermo5_read_therm_limit_stat(thermo5_t *ctx)
Read therm limit status function.
thermo5_read_low_limit_stat
uint8_t thermo5_read_low_limit_stat(thermo5_t *ctx)
Read low limit status function.
thermo5_read_extern_1_temp
float thermo5_read_extern_1_temp(thermo5_t *ctx)
Read external diode 1 temperature function.
thermo5_set_convers_rate
void thermo5_set_convers_rate(thermo5_t *ctx, uint8_t convers_rate)
Set conversion rate function.
thermo5_read_data
uint16_t thermo5_read_data(thermo5_t *ctx, uint16_t reg_addr)
Read data function.
thermo5_read_filter_rate
uint8_t thermo5_read_filter_rate(thermo5_t *ctx)
Read filter configuration function.
thermo5_read_stat_reg
uint8_t thermo5_read_stat_reg(thermo5_t *ctx)
Read status register function.
thermo5_cfg_t::scl
pin_name_t scl
Definition: thermo5.h:308
thermo5_get_interrupt_state
uint8_t thermo5_get_interrupt_state(thermo5_t *ctx)
Get interrupt state function.
thermo5_read_extern_2_temp
float thermo5_read_extern_2_temp(thermo5_t *ctx)
Read external diode 2 temperature function.
thermo5_write_config
void thermo5_write_config(thermo5_t *ctx, uint8_t wr_data)
Write configuration function.
thermo5_read_byte
uint8_t thermo5_read_byte(thermo5_t *ctx, uint8_t rd_addr)
Read byte function.
thermo5_cfg_t::int_pin
pin_name_t int_pin
Definition: thermo5.h:313
thermo5_cfg_t::sda
pin_name_t sda
Definition: thermo5.h:309
thermo5_read_product_id
uint8_t thermo5_read_product_id(thermo5_t *ctx)
Read product ID function.
thermo5_t::slave_address
uint8_t slave_address
Definition: thermo5.h:297
thermo5_read_extern_3_temp
float thermo5_read_extern_3_temp(thermo5_t *ctx)
Read external diode 3 temperature function.
thermo5_cfg_t
Click configuration structure definition.
Definition: thermo5.h:304
thermo5_t
Click ctx object definition.
Definition: thermo5.h:285
thermo5_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo5.h:318
thermo5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo5.h:317
thermo5_read_diode_1_beta_config
uint8_t thermo5_read_diode_1_beta_config(thermo5_t *ctx)
Read External Diode 1 Beta Configuration function.
thermo5_read_revision_register
uint8_t thermo5_read_revision_register(thermo5_t *ctx)
Read revision register function.
thermo5_t::int_pin
digital_in_t int_pin
Definition: thermo5.h:289
thermo5_set_filter_rate
void thermo5_set_filter_rate(thermo5_t *ctx, uint8_t filter_decode_rate)
Filter configuration function.
thermo5_read_exter_diode_fault
uint8_t thermo5_read_exter_diode_fault(thermo5_t *ctx)
Read external diode fault function.
thermo5_read_high_limit_stat
uint8_t thermo5_read_high_limit_stat(thermo5_t *ctx)
Read high limit status function.
THERMO5_RETVAL
#define THERMO5_RETVAL
Definition: thermo5.h:62
thermo5_read_diode_2_beta_config
uint8_t thermo5_read_diode_2_beta_config(thermo5_t *ctx)
Read External Diode 2 Beta Configuration function.
thermo5_set_diode_1_beta_config
void thermo5_set_diode_1_beta_config(thermo5_t *ctx, uint8_t enable)
Set External Diode 1 Beta Configuration function.
thermo5_init
THERMO5_RETVAL thermo5_init(thermo5_t *ctx, thermo5_cfg_t *cfg)
Initialization function.
thermo5_read_inter_temp
float thermo5_read_inter_temp(thermo5_t *ctx)
Read internal diode temperature function.
thermo5_read_manufacturer_id
uint8_t thermo5_read_manufacturer_id(thermo5_t *ctx)
Read manufacturer ID function.
thermo5_generic_write
void thermo5_generic_write(thermo5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
thermo5_read_convers_rate
uint8_t thermo5_read_convers_rate(thermo5_t *ctx)
Read conversion rate function.
thermo5_t::i2c
i2c_master_t i2c
Definition: thermo5.h:293
thermo5_write_byte
void thermo5_write_byte(thermo5_t *ctx, uint8_t wr_addr, uint8_t wr_data)
Write byte function.
thermo5_generic_read
void thermo5_generic_read(thermo5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.