irthermo2  2.0.0.0
irthermo2.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 
25 #ifndef IRTHERMO2_H
26 #define IRTHERMO2_H
27 
28 #ifdef __cplusplus
29 extern "C"{
30 #endif
31 
32 #include "mikrosdk_version.h"
33 
34 #ifdef __GNUC__
35 #if mikroSDK_GET_VERSION < 20800ul
36 #include "rcu_delays.h"
37 #else
38 #include "delays.h"
39 #endif
40 #endif
41 
42 #include "drv_digital_out.h"
43 #include "drv_digital_in.h"
44 #include "drv_i2c_master.h"
45 
46 
67 #define IRTHERMO2_SENSOR_VOLTAGE 0x00
68 #define IRTHERMO2_LOCAL_TEMPERATURE 0x01
69 #define IRTHERMO2_CONFIGURATION 0x02
70 #define IRTHERMO2_OBJECT_TEMPERATURE 0x03
71 #define IRTHERMO2_STATUS 0x04
72 #define IRTHERMO2_STATUS_MASK_AND_ENABLE 0x05
73 #define IRTHERMO2_OBJECT_HIGH_LIMIT_TEMP 0x06
74 #define IRTHERMO2_OBJECT_LOW_LIMIT_TEMP 0x07
75 #define IRTHERMO2_LOCAL_HIGH_LIMIT_TEMP 0x08
76 #define IRTHERMO2_LOCAL_LOW_LIMIT_TEMP 0x09
77 #define IRTHERMO2_S0_COEFFICIENT 0x0A
78 #define IRTHERMO2_A0_COEFFICIENT 0x0B
79 #define IRTHERMO2_A1_COEFFICIENT 0x0C
80 #define IRTHERMO2_B0_COEFFICIENT 0x0D
81 #define IRTHERMO2_B1_COEFFICIENT 0x0E
82 #define IRTHERMO2_B2_COEFFICIENT 0x0F
83 #define IRTHERMO2_C_COEFFICIENT 0x10
84 #define IRTHERMO2_TC0_COEFFICIENT 0X11
85 #define IRTHERMO2_TC1_COEFFICIENT 0x12
86 #define IRTHERMO2_DEVICE_ID 0x1F
87 #define IRTHERMO2_MEMORY_ACCESS 0x2A
88  // irthermo2_reg
90 
105 #define IRTHERMO2_RESULT_OK 1
106 #define IRTHERMO2_RESULT_ERROR 0
107 #define IRTHERMO2_CFG_MODEON 0x1000
108 #define IRTHERMO2_CFG_RESET 0x8000
109 #define IRTHERMO2_CFG_1SAMPLE 0x0000
110 #define IRTHERMO2_CFG_2SAMPLE 0x0200
111 #define IRTHERMO2_CFG_4SAMPLE 0x0400
112 #define IRTHERMO2_CFG_8SAMPLE 0x0600
113 #define IRTHERMO2_CFG_16SAMPLE 0x0800
114 #define IRTHERMO2_CFG_ALERTEN 0x0100
115 #define IRTHERMO2_CFG_ALERTF 0x0080
116 #define IRTHERMO2_CFG_TRANSC 0x0040
117 #define IRTHERMO2_STAT_ALERTEN 0x8000
118 #define IRTHERMO2_STAT_CRTEN 0x4000
119 #define IRTHERMO2_DEVICE_ID_VALUE 0x0078
120 
126 #define IRTHERMO2_I2C_ADDRESS_0 0x40
127 #define IRTHERMO2_I2C_ADDRESS_1 0x41
128 #define IRTHERMO2_I2C_ADDRESS_2 0x44
129 #define IRTHERMO2_I2C_ADDRESS_3 0x45
130  // irthermo2_set
132 
147 #define IRTHERMO2_MAP_MIKROBUS( cfg, mikrobus ) \
148  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
149  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
150  cfg.al = MIKROBUS( mikrobus, MIKROBUS_INT )
151  // irthermo2_map // irthermo2
154 
155 
156 
157 
161 typedef struct
162 {
163  // Input pins
164  digital_in_t al;
166  // Modules
167  i2c_master_t i2c;
169  // ctx variable
170 
171  uint8_t slave_address;
173 } irthermo2_t;
174 
178 typedef struct
179 {
180  // Communication gpio pins
181 
182  pin_name_t scl;
183  pin_name_t sda;
185  // Additional gpio pins
186 
187  pin_name_t al;
189  // static variable
190 
191  uint32_t i2c_speed;
192  uint8_t i2c_address;
195 
200 typedef enum
201 {
203  IRTHERMO2_ERROR = -1
204 
206 
223 
237 
246 
257 void irthermo2_generic_write ( irthermo2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
258 
269 void irthermo2_generic_read ( irthermo2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
270 
280 void irthermo2_write_data ( irthermo2_t *ctx, uint8_t address, uint16_t write_data );
281 
290 uint16_t irthermo2_read_data ( irthermo2_t *ctx, uint8_t address );
291 
303 
315 
325 
337 
346 
347 #ifdef __cplusplus
348 }
349 #endif
350 #endif // _IRTHERMO2_H_
351 
353 // ------------------------------------------------------------------------- END
irthermo2_t::slave_address
uint8_t slave_address
Definition: irthermo2.h:171
IRTHERMO2_ERROR
@ IRTHERMO2_ERROR
Definition: irthermo2.h:203
irthermo2_cfg_t::sda
pin_name_t sda
Definition: irthermo2.h:183
irthermo2_generic_write
void irthermo2_generic_write(irthermo2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Generic write function.
irthermo2_cfg_setup
void irthermo2_cfg_setup(irthermo2_cfg_t *cfg)
Config Object Initialization function.
irthermo2_t::al
digital_in_t al
Definition: irthermo2.h:164
irthermo2_read_data
uint16_t irthermo2_read_data(irthermo2_t *ctx, uint8_t address)
Generic read 16-bit data from 8-bit address function.
irthermo2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: irthermo2.h:191
irthermo2_init
err_t irthermo2_init(irthermo2_t *ctx, irthermo2_cfg_t *cfg)
Initialization function.
irthermo2_cfg_t
Click configuration structure definition.
Definition: irthermo2.h:179
irthermo2_cfg_t::i2c_address
uint8_t i2c_address
Definition: irthermo2.h:192
irthermo2_get_object_temperature_c
float irthermo2_get_object_temperature_c(irthermo2_t *ctx)
Get object temperature in degrees Celsius function.
irthermo2_check_id
err_t irthermo2_check_id(irthermo2_t *ctx)
Check device ID function.
irthermo2_default_cfg
void irthermo2_default_cfg(irthermo2_t *ctx)
Click Default Configuration function.
irthermo2_get_raw_temperature
float irthermo2_get_raw_temperature(irthermo2_t *ctx)
Get raw temperature in degrees Celsius function.
irthermo2_t::i2c
i2c_master_t i2c
Definition: irthermo2.h:167
IRTHERMO2_OK
@ IRTHERMO2_OK
Definition: irthermo2.h:202
irhhermo2_get_alert
uint8_t irhhermo2_get_alert(irthermo2_t *ctx)
Get state of alert function.
irthermo2_generic_read
void irthermo2_generic_read(irthermo2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Generic read function.
irthermo2_cfg_t::al
pin_name_t al
Definition: irthermo2.h:187
irthermo2_cfg_t::scl
pin_name_t scl
Definition: irthermo2.h:182
irthermo2_t
Click ctx object definition.
Definition: irthermo2.h:162
irthermo2_write_data
void irthermo2_write_data(irthermo2_t *ctx, uint8_t address, uint16_t write_data)
Generic write 16-bit data function.
irthermo2_return_value_t
irthermo2_return_value_t
IrThermo 2 Click return value data.
Definition: irthermo2.h:201
irthermo2_get_object_temperature_f
float irthermo2_get_object_temperature_f(irthermo2_t *ctx)
Get object temperature in degrees Fahrenheit function.