irthermo3  2.0.0.0
irthermo3.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 IRTHERMO3_H
36 #define IRTHERMO3_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define IRTHERMO3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define IRTHERMO3_OK 0x00
72 #define IRTHERMO3_ERROR 0xFF
73 
79 #define IRTHERMO3_DEV_ADR_GND 0x3A
80 #define IRTHERMO3_DEV_ADR_VCC 0x3B
81 
87 #define IRTHERMO3_EEPROM_VERSION 0x240B
88 
94 #define IRTHERMO3_EEPROM_CAL_CONST_P_R_LSW 0x240C
95 #define IRTHERMO3_EEPROM_CAL_CONST_P_R_MSW 0x240D
96 #define IRTHERMO3_EEPROM_CAL_CONST_P_G_LSW 0x240E
97 #define IRTHERMO3_EEPROM_CAL_CONST_P_G_MSW 0x240F
98 #define IRTHERMO3_EEPROM_CAL_CONST_P_T_LSW 0x2410
99 #define IRTHERMO3_EEPROM_CAL_CONST_P_T_MSW 0x2411
100 #define IRTHERMO3_EEPROM_CAL_CONST_P_O_LSW 0x2412
101 #define IRTHERMO3_EEPROM_CAL_CONST_P_O_MSW 0x2413
102 #define IRTHERMO3_EEPROM_CAL_CONST_AA_LSW 0x2414
103 #define IRTHERMO3_EEPROM_CAL_CONST_AA_MSW 0x2415
104 #define IRTHERMO3_EEPROM_CAL_CONST_AB_LSW 0x2416
105 #define IRTHERMO3_EEPROM_CAL_CONST_AB_MSW 0x2417
106 #define IRTHERMO3_EEPROM_CAL_CONST_BA_LSW 0x2418
107 #define IRTHERMO3_EEPROM_CAL_CONST_BA_MSW 0x2419
108 #define IRTHERMO3_EEPROM_CAL_CONST_BB_LSW 0x241A
109 #define IRTHERMO3_EEPROM_CAL_CONST_BB_MSW 0x241B
110 #define IRTHERMO3_EEPROM_CAL_CONST_CA_LSW 0x241C
111 #define IRTHERMO3_EEPROM_CAL_CONST_CA_MSW 0x241D
112 #define IRTHERMO3_EEPROM_CAL_CONST_CB_LSW 0x241E
113 #define IRTHERMO3_EEPROM_CAL_CONST_CB_MSW 0x241F
114 #define IRTHERMO3_EEPROM_CAL_CONST_DA_LSW 0x2420
115 #define IRTHERMO3_EEPROM_CAL_CONST_DA_MSW 0x2421
116 #define IRTHERMO3_EEPROM_CAL_CONST_DB_LSW 0x2422
117 #define IRTHERMO3_EEPROM_CAL_CONST_DB_MSW 0x2423
118 #define IRTHERMO3_EEPROM_CAL_CONST_EA_LSW 0x2424
119 #define IRTHERMO3_EEPROM_CAL_CONST_EA_MSW 0x2425
120 #define IRTHERMO3_EEPROM_CAL_CONST_EB_LSW 0x2426
121 #define IRTHERMO3_EEPROM_CAL_CONST_EB_MSW 0x2427
122 #define IRTHERMO3_EEPROM_CAL_CONST_FA_LSW 0x2428
123 #define IRTHERMO3_EEPROM_CAL_CONST_FA_MSW 0x2429
124 #define IRTHERMO3_EEPROM_CAL_CONST_FB_LSW 0x242A
125 #define IRTHERMO3_EEPROM_CAL_CONST_FB_MSW 0x242B
126 #define IRTHERMO3_EEPROM_CAL_CONST_GA_LSW 0x242C
127 #define IRTHERMO3_EEPROM_CAL_CONST_GA_MSW 0x242D
128 #define IRTHERMO3_EEPROM_CAL_CONST_GB 0x242E
129 #define IRTHERMO3_EEPROM_CAL_CONST_KA 0x242E
130 #define IRTHERMO3_EEPROM_CAL_CONST_KB 0x242E
131 #define IRTHERMO3_EEPROM_CAL_CONST_HA_COSTUMER 0x2481
132 #define IRTHERMO3_EEPROM_CAL_CONST_HB_COSTUMER 0x2482
133 
139 #define IRTHERMO3_EEPROM_CTRL_REG 0x24D4
140 #define IRTHERMO3_EEPROM_I2C_ADDRESS 0x24D5
141 #define IRTHERMO3_REG_I2C_ADDRESS 0x3000
142 #define IRTHERMO3_REG_CONTROL 0x3001
143 #define IRTHERMO3_REG_RESET 0x3005
144 #define IRTHERMO3_REG_STATUS 0x3FFF
145 
151 #define IRTHERMO3_RAW_DATA_1 0x4000
152 #define IRTHERMO3_RAW_DATA_2 0x4001
153 #define IRTHERMO3_RAW_DATA_3 0x4002
154 #define IRTHERMO3_RAW_DATA_4 0x4003
155 #define IRTHERMO3_RAW_DATA_5 0x4004
156 #define IRTHERMO3_RAW_DATA_6 0x4005
157 #define IRTHERMO3_RAW_DATA_7 0x4006
158 #define IRTHERMO3_RAW_DATA_8 0x4007
159 #define IRTHERMO3_RAW_DATA_9 0x4008
160 
166 #define IRTHERMO3_MODE_SLEEP 0x02
167 #define IRTHERMO3_MODE_STEPIN 0x04
168 #define IRTHERMO3_MODE_CONTINOUS 0x06
169  // End group macro
172 // --------------------------------------------------------------- PUBLIC TYPES
181 typedef struct
182 {
183  float p_r;
184  float p_g;
185  float p_t;
186  float p_o;
187  float ea;
188  float eb;
189  float fa;
190  float fb;
191  float ga;
192  float gb;
193  float ka;
194  float ha;
195  float hb;
196 
198 
202 typedef struct
203 {
204  // Modules
205  i2c_master_t i2c;
206 
207  // ctx variable
208  uint8_t slave_address;
209 
210  // Calculation coefficients
212 
213 } irthermo3_t;
214 
218 typedef struct
219 {
220  // Communication gpio pins
221  pin_name_t scl;
222  pin_name_t sda;
223 
224  // static variable
225  uint32_t i2c_speed;
226  uint8_t i2c_address;
227 
229  // End types group
231 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
232 
238 #ifdef __cplusplus
239 extern "C"{
240 #endif
241 
251 
261 
272 void irthermo3_generic_write ( irthermo3_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len );
273 
284 void irthermo3_generic_read ( irthermo3_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len );
285 
295 void irthermo3_write_u16 ( irthermo3_t *ctx, uint16_t reg, uint16_t wr_data );
296 
307 int16_t irthermo3_read_i16( irthermo3_t *ctx, uint16_t reg );
308 
319 int32_t irthermo3_read_i32 ( irthermo3_t *ctx, uint16_t reg );
320 
329 void irthermo3_set_mode( irthermo3_t *ctx, uint8_t mode );
330 
340 
349 
358 
359 #ifdef __cplusplus
360 }
361 #endif
362 #endif // _IRTHERMO3_H_
363  // End public_function group
366 
367 // ------------------------------------------------------------------------- END
irthermo3_get_ambient_temp
float irthermo3_get_ambient_temp(irthermo3_t *ctx)
Read Ambient Temperature function.
irthermo3_cal_coef_t::p_r
float p_r
Definition: irthermo3.h:183
irthermo3_cal_coef_t::fa
float fa
Definition: irthermo3.h:189
irthermo3_cal_coef_t::ka
float ka
Definition: irthermo3.h:193
irthermo3_generic_write
void irthermo3_generic_write(irthermo3_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
irthermo3_init
err_t irthermo3_init(irthermo3_t *ctx, irthermo3_cfg_t *cfg)
Initialization function.
irthermo3_cfg_t
Click configuration structure definition.
Definition: irthermo3.h:219
irthermo3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: irthermo3.h:225
irthermo3_cal_coef_t::eb
float eb
Definition: irthermo3.h:188
irthermo3_cal_coef_t
Calculation coefficients.
Definition: irthermo3.h:182
irthermo3_cal_coef_t::ha
float ha
Definition: irthermo3.h:194
irthermo3_read_i16
int16_t irthermo3_read_i16(irthermo3_t *ctx, uint16_t reg)
Read i16 dat function.
irthermo3_t::slave_address
uint8_t slave_address
Definition: irthermo3.h:208
irthermo3_t
Click ctx object definition.
Definition: irthermo3.h:203
irthermo3_cal_coef_t::ea
float ea
Definition: irthermo3.h:187
irthermo3_t::i2c
i2c_master_t i2c
Definition: irthermo3.h:205
irthermo3_cal_coef_t::p_g
float p_g
Definition: irthermo3.h:184
irthermo3_cfg_t::sda
pin_name_t sda
Definition: irthermo3.h:222
irthermo3_cal_coef_t::gb
float gb
Definition: irthermo3.h:192
irthermo3_cfg_t::scl
pin_name_t scl
Definition: irthermo3.h:221
irthermo3_cal_coef_t::ga
float ga
Definition: irthermo3.h:191
irthermo3_cfg_setup
void irthermo3_cfg_setup(irthermo3_cfg_t *cfg)
Config Object Initialization function.
irthermo3_get_object_temp
float irthermo3_get_object_temp(irthermo3_t *ctx)
Read Object Temperature function.
irthermo3_t::cal_coef
irthermo3_cal_coef_t cal_coef
Definition: irthermo3.h:211
irthermo3_generic_read
void irthermo3_generic_read(irthermo3_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
irthermo3_write_u16
void irthermo3_write_u16(irthermo3_t *ctx, uint16_t reg, uint16_t wr_data)
Write u16 data function.
irthermo3_set_mode
void irthermo3_set_mode(irthermo3_t *ctx, uint8_t mode)
Set device mode function.
irthermo3_cal_coef_t::hb
float hb
Definition: irthermo3.h:195
irthermo3_cal_coef_t::p_o
float p_o
Definition: irthermo3.h:186
irthermo3_cfg_t::i2c_address
uint8_t i2c_address
Definition: irthermo3.h:226
irthermo3_cal_coef_t::fb
float fb
Definition: irthermo3.h:190
irthermo3_cal
void irthermo3_cal(irthermo3_t *ctx)
Calibration function.
irthermo3_read_i32
int32_t irthermo3_read_i32(irthermo3_t *ctx, uint16_t reg)
Read i32 dat function.
irthermo3_cal_coef_t::p_t
float p_t
Definition: irthermo3.h:185