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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define IRTHERMO4_REG_TP_OBJECT 0x01
70 #define IRTHERMO4_REG_TP_AMBIENT 0x03
71 #define IRTHERMO4_REG_TP_OBJ_LP1 0x05
72 #define IRTHERMO4_REG_TP_OBJ_LP2 0x07
73 #define IRTHERMO4_REG_TP_AMB_LP3 0x0A
74 #define IRTHERMO4_REG_TP_OBJ_LP2_FROZEN 0x0C
75 #define IRTHERMO4_REG_TP_PRESENCE 0x0F
76 #define IRTHERMO4_REG_TP_MOTION 0x10
77 #define IRTHERMO4_REG_TP_AMB_SHOCK 0x11
78 #define IRTHERMO4_REG_INTERRUPT_STATUS 0x12
79 #define IRTHERMO4_REG_CHIP_STATUS 0x13
80 #define IRTHERMO4_REG_S_LP1_LP2 0x14
81 #define IRTHERMO4_REG_S_LP3 0x15
82 #define IRTHERMO4_REG_TP_PRESENCE_THOLD 0x16
83 #define IRTHERMO4_REG_TP_MOTION_THOLD 0x17
84 #define IRTHERMO4_REG_TP_AMB_SHOCK_THOLD 0x18
85 #define IRTHERMO4_REG_INTERRUPT_MASK 0x19
86 #define IRTHERMO4_REG_MULTIPLE 0x1A
87 #define IRTHERMO4_REG_TIMER_INTERRUPT 0x1B
88 #define IRTHERMO4_REG_TP_OT_THOLD 0x1C
89 #define IRTHERMO4_REG_EEPROM_CONTROL 0x1F
90 #define IRTHERMO4_REG_EEPROM_CONTENT 0x20
91 #define IRTHERMO4_REG_SLAVE_ADDRESS 0x3F
92  // irthermo4_reg
94 
109 #define IRTHERMO4_ROOM_TEMPERATURE 25.0f
110 #define IRTHERMO4_FUNCTION_EXPONENT 4.2f
111 #define IRTHERMO4_DIGITS_K_TO_M 100.0f
112 #define IRTHERMO4_TP_OFFSET_TO_U0 32768
113 #define IRTHERMO4_TP_OUT_TO_UOUT 2
114 
119 #define IRTHERMO4_EEPROM_READ_ENABLE 0x80
120 #define IRTHERMO4_EEPROM_READ_DISABLE 0x00
121 
126 #define IRTHERMO4_CMD_RELOAD 0x04
127 
133 #define IRTHERMO4_DEVICE_ADDRESS_GEN_CALL 0x00
134 #define IRTHERMO4_DEVICE_ADDRESS_GND 0x0C
135 #define IRTHERMO4_DEVICE_ADDRESS_VCC 0x0E
136  // irthermo4_set
138 
153 #define IRTHERMO4_MAP_MIKROBUS( cfg, mikrobus ) \
154  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
155  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
156  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
157  // irthermo4_map // irthermo4
160 
165 typedef struct
166 {
167  uint8_t protocol;
168  uint8_t lookup;
169  uint16_t ptat25;
170  float m_val;
171  uint32_t u0_val;
172  uint32_t uout1;
173  uint8_t tobj1;
174  uint8_t slave_add;
175  float k_val;
178 
183 typedef struct
184 {
185  // Input pins
186  digital_in_t int_pin;
188  // Modules
189  i2c_master_t i2c;
191  // I2C slave address
192  uint8_t slave_address;
196 } irthermo4_t;
197 
202 typedef struct
203 {
204  pin_name_t scl;
205  pin_name_t sda;
207  pin_name_t int_pin;
209  uint32_t i2c_speed;
210  uint8_t i2c_address;
213 
218 typedef enum
219 {
221  IRTHERMO4_ERROR = -1
222 
224 
241 
256 
270 
285 err_t irthermo4_write_regs ( irthermo4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
286 
301 err_t irthermo4_read_regs ( irthermo4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
302 
315 err_t irthermo4_write_reg ( irthermo4_t *ctx, uint8_t reg, uint8_t data_in );
316 
329 err_t irthermo4_read_reg ( irthermo4_t *ctx, uint8_t reg, uint8_t *data_out );
330 
342 
354 
364 
376 err_t irthermo4_read_ambient_temp ( irthermo4_t *ctx, float *t_amb );
377 
390 err_t irthermo4_read_object_temp ( irthermo4_t *ctx, float *t_obj, float t_amb );
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 #endif // IRTHERMO4_H
396  // irthermo4
398 
399 // ------------------------------------------------------------------------ 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:172
irthermo4_cfg_t::int_pin
pin_name_t int_pin
Definition: irthermo4.h:207
irthermo4_cfg_t::sda
pin_name_t sda
Definition: irthermo4.h:205
irthermo4_t::int_pin
digital_in_t int_pin
Definition: irthermo4.h:186
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:175
irthermo4_cfg_t
IR Thermo 4 Click configuration object.
Definition: irthermo4.h:203
irthermo4_t::slave_address
uint8_t slave_address
Definition: irthermo4.h:192
irthermo4_eeprom_t::protocol
uint8_t protocol
Definition: irthermo4.h:167
irthermo4_eeprom_t
IR Thermo 4 Click EEPROM content object.
Definition: irthermo4.h:166
irthermo4_eeprom_t::slave_add
uint8_t slave_add
Definition: irthermo4.h:174
irthermo4_eeprom_t::m_val
float m_val
Definition: irthermo4.h:170
irthermo4_cfg_t::i2c_address
uint8_t i2c_address
Definition: irthermo4.h:210
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:184
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:194
irthermo4_cfg_t::scl
pin_name_t scl
Definition: irthermo4.h:204
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:209
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:171
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:221
irthermo4_eeprom_t::ptat25
uint16_t ptat25
Definition: irthermo4.h:169
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:168
irthermo4_return_value_t
irthermo4_return_value_t
IR Thermo 4 Click return value data.
Definition: irthermo4.h:219
IRTHERMO4_OK
@ IRTHERMO4_OK
Definition: irthermo4.h:220
irthermo4_eeprom_t::tobj1
uint8_t tobj1
Definition: irthermo4.h:173
irthermo4_t::i2c
i2c_master_t i2c
Definition: irthermo4.h:189