irthermo4  2.1.0.0
irthermo4.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef IRTHERMO4_H
29 #define IRTHERMO4_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define IRTHERMO4_REG_TP_OBJECT 0x01
74 #define IRTHERMO4_REG_TP_AMBIENT 0x03
75 #define IRTHERMO4_REG_TP_OBJ_LP1 0x05
76 #define IRTHERMO4_REG_TP_OBJ_LP2 0x07
77 #define IRTHERMO4_REG_TP_AMB_LP3 0x0A
78 #define IRTHERMO4_REG_TP_OBJ_LP2_FROZEN 0x0C
79 #define IRTHERMO4_REG_TP_PRESENCE 0x0F
80 #define IRTHERMO4_REG_TP_MOTION 0x10
81 #define IRTHERMO4_REG_TP_AMB_SHOCK 0x11
82 #define IRTHERMO4_REG_INTERRUPT_STATUS 0x12
83 #define IRTHERMO4_REG_CHIP_STATUS 0x13
84 #define IRTHERMO4_REG_S_LP1_LP2 0x14
85 #define IRTHERMO4_REG_S_LP3 0x15
86 #define IRTHERMO4_REG_TP_PRESENCE_THOLD 0x16
87 #define IRTHERMO4_REG_TP_MOTION_THOLD 0x17
88 #define IRTHERMO4_REG_TP_AMB_SHOCK_THOLD 0x18
89 #define IRTHERMO4_REG_INTERRUPT_MASK 0x19
90 #define IRTHERMO4_REG_MULTIPLE 0x1A
91 #define IRTHERMO4_REG_TIMER_INTERRUPT 0x1B
92 #define IRTHERMO4_REG_TP_OT_THOLD 0x1C
93 #define IRTHERMO4_REG_EEPROM_CONTROL 0x1F
94 #define IRTHERMO4_REG_EEPROM_CONTENT 0x20
95 #define IRTHERMO4_REG_SLAVE_ADDRESS 0x3F
96  // irthermo4_reg
98 
113 #define IRTHERMO4_ROOM_TEMPERATURE 25.0f
114 #define IRTHERMO4_FUNCTION_EXPONENT 4.2f
115 #define IRTHERMO4_DIGITS_K_TO_M 100.0f
116 #define IRTHERMO4_TP_OFFSET_TO_U0 32768
117 #define IRTHERMO4_TP_OUT_TO_UOUT 2
118 
123 #define IRTHERMO4_EEPROM_READ_ENABLE 0x80
124 #define IRTHERMO4_EEPROM_READ_DISABLE 0x00
125 
130 #define IRTHERMO4_CMD_RELOAD 0x04
131 
137 #define IRTHERMO4_DEVICE_ADDRESS_GEN_CALL 0x00
138 #define IRTHERMO4_DEVICE_ADDRESS_GND 0x0C
139 #define IRTHERMO4_DEVICE_ADDRESS_VCC 0x0E
140  // irthermo4_set
142 
157 #define IRTHERMO4_MAP_MIKROBUS( cfg, mikrobus ) \
158  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
159  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
160  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
161  // irthermo4_map // irthermo4
164 
169 typedef struct
170 {
171  uint8_t protocol;
172  uint8_t lookup;
173  uint16_t ptat25;
174  float m_val;
175  uint32_t u0_val;
176  uint32_t uout1;
177  uint8_t tobj1;
178  uint8_t slave_add;
179  float k_val;
182 
187 typedef struct
188 {
189  // Input pins
190  digital_in_t int_pin;
192  // Modules
193  i2c_master_t i2c;
195  // I2C slave address
196  uint8_t slave_address;
200 } irthermo4_t;
201 
206 typedef struct
207 {
208  pin_name_t scl;
209  pin_name_t sda;
211  pin_name_t int_pin;
213  uint32_t i2c_speed;
214  uint8_t i2c_address;
217 
222 typedef enum
223 {
225  IRTHERMO4_ERROR = -1
226 
228 
245 
260 
274 
289 err_t irthermo4_write_regs ( irthermo4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
290 
305 err_t irthermo4_read_regs ( irthermo4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
306 
319 err_t irthermo4_write_reg ( irthermo4_t *ctx, uint8_t reg, uint8_t data_in );
320 
333 err_t irthermo4_read_reg ( irthermo4_t *ctx, uint8_t reg, uint8_t *data_out );
334 
346 
358 
368 
380 err_t irthermo4_read_ambient_temp ( irthermo4_t *ctx, float *t_amb );
381 
394 err_t irthermo4_read_object_temp ( irthermo4_t *ctx, float *t_obj, float t_amb );
395 
396 #ifdef __cplusplus
397 }
398 #endif
399 #endif // IRTHERMO4_H
400  // irthermo4
402 
403 // ------------------------------------------------------------------------ END
irthermo4_read_object_temp
err_t irthermo4_read_object_temp(irthermo4_t *ctx, float *t_obj, float t_amb)
IR Thermo 4 read object temp function.
irthermo4_eeprom_t::uout1
uint32_t uout1
Definition: irthermo4.h:176
irthermo4_cfg_t::int_pin
pin_name_t int_pin
Definition: irthermo4.h:211
irthermo4_cfg_t::sda
pin_name_t sda
Definition: irthermo4.h:209
irthermo4_t::int_pin
digital_in_t int_pin
Definition: irthermo4.h:190
irthermo4_read_eeprom
err_t irthermo4_read_eeprom(irthermo4_t *ctx)
IR Thermo 4 read EEPROM function.
irthermo4_read_regs
err_t irthermo4_read_regs(irthermo4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
IR Thermo 4 read regs function.
irthermo4_init
err_t irthermo4_init(irthermo4_t *ctx, irthermo4_cfg_t *cfg)
IR Thermo 4 initialization function.
irthermo4_eeprom_t::k_val
float k_val
Definition: irthermo4.h:179
irthermo4_cfg_t
IR Thermo 4 Click configuration object.
Definition: irthermo4.h:207
irthermo4_t::slave_address
uint8_t slave_address
Definition: irthermo4.h:196
irthermo4_eeprom_t::protocol
uint8_t protocol
Definition: irthermo4.h:171
irthermo4_eeprom_t
IR Thermo 4 Click EEPROM content object.
Definition: irthermo4.h:170
irthermo4_eeprom_t::slave_add
uint8_t slave_add
Definition: irthermo4.h:178
irthermo4_eeprom_t::m_val
float m_val
Definition: irthermo4.h:174
irthermo4_cfg_t::i2c_address
uint8_t i2c_address
Definition: irthermo4.h:214
irthermo4_get_int_pin
uint8_t irthermo4_get_int_pin(irthermo4_t *ctx)
IR Thermo 4 get int pin function.
irthermo4_t
IR Thermo 4 Click context object.
Definition: irthermo4.h:188
irthermo4_write_regs
err_t irthermo4_write_regs(irthermo4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
IR Thermo 4 write regs function.
irthermo4_t::eeprom
irthermo4_eeprom_t eeprom
Definition: irthermo4.h:198
irthermo4_cfg_t::scl
pin_name_t scl
Definition: irthermo4.h:208
irthermo4_refresh_address
err_t irthermo4_refresh_address(irthermo4_t *ctx)
IR Thermo 4 refresh address function.
irthermo4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: irthermo4.h:213
irthermo4_read_ambient_temp
err_t irthermo4_read_ambient_temp(irthermo4_t *ctx, float *t_amb)
IR Thermo 4 read ambient temp function.
irthermo4_eeprom_t::u0_val
uint32_t u0_val
Definition: irthermo4.h:175
irthermo4_write_reg
err_t irthermo4_write_reg(irthermo4_t *ctx, uint8_t reg, uint8_t data_in)
IR Thermo 4 write reg function.
irthermo4_cfg_setup
void irthermo4_cfg_setup(irthermo4_cfg_t *cfg)
IR Thermo 4 configuration object setup function.
irthermo4_read_reg
err_t irthermo4_read_reg(irthermo4_t *ctx, uint8_t reg, uint8_t *data_out)
IR Thermo 4 read reg function.
IRTHERMO4_ERROR
@ IRTHERMO4_ERROR
Definition: irthermo4.h:225
irthermo4_eeprom_t::ptat25
uint16_t ptat25
Definition: irthermo4.h:173
irthermo4_default_cfg
err_t irthermo4_default_cfg(irthermo4_t *ctx)
IR Thermo 4 default configuration function.
irthermo4_eeprom_t::lookup
uint8_t lookup
Definition: irthermo4.h:172
irthermo4_return_value_t
irthermo4_return_value_t
IR Thermo 4 Click return value data.
Definition: irthermo4.h:223
IRTHERMO4_OK
@ IRTHERMO4_OK
Definition: irthermo4.h:224
irthermo4_eeprom_t::tobj1
uint8_t tobj1
Definition: irthermo4.h:177
irthermo4_t::i2c
i2c_master_t i2c
Definition: irthermo4.h:193