thermo22  2.0.0.0
thermo22.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 THERMO22_H
29 #define THERMO22_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 THERMO22_REG_TEMPERATURE 0x00
70 #define THERMO22_REG_CONFIGURATION 0x01
71 #define THERMO22_REG_TEMPERATURE_LOW 0x02
72 #define THERMO22_REG_TEMPERATURE_HIGH 0x03
73 #define THERMO22_REG_ONE_SHOT 0x04
74  // thermo22_reg
76 
91 #define THERMO22_CONFIG_ONESHOT_DIS 0x00
92 #define THERMO22_CONFIG_ONESHOT_EN 0x20
93 #define THERMO22_CONFIG_FAULT_QUEUE_1 0x00
94 #define THERMO22_CONFIG_FAULT_QUEUE_2 0x08
95 #define THERMO22_CONFIG_FAULT_QUEUE_4 0x10
96 #define THERMO22_CONFIG_FAULT_QUEUE_6 0x18
97 #define THERMO22_CONFIG_ALERT_ACTIVE_LOW 0x00
98 #define THERMO22_CONFIG_ALERT_ACTIVE_HIGH 0x04
99 #define THERMO22_CONFIG_ALERT_COMPARATOR 0x00
100 #define THERMO22_CONFIG_ALERT_INTERRUPT 0x02
101 #define THERMO22_CONFIG_SHUTDOWN_DIS 0x00
102 #define THERMO22_CONFIG_SHUTDOWN_EN 0x01
103 
108 #define THERMO22_TEMPERATURE_RESOLUTION 0.0625
109 #define THERMO22_TEMPERATURE_MAX 128.0
110 #define THERMO22_TEMPERATURE_MIN -128.0
111 #define THERMO22_TEMPERATURE_ALERT_LIMIT 35.0
112 
118 #define THERMO22_DEV_ADDR_A2A1A0_000 0x48
119 #define THERMO22_DEV_ADDR_A2A1A0_001 0x49
120 #define THERMO22_DEV_ADDR_A2A1A0_010 0x4A
121 #define THERMO22_DEV_ADDR_A2A1A0_011 0x4B
122 #define THERMO22_DEV_ADDR_A2A1A0_100 0x4C
123 #define THERMO22_DEV_ADDR_A2A1A0_101 0x4D
124 #define THERMO22_DEV_ADDR_A2A1A0_110 0x4E
125 #define THERMO22_DEV_ADDR_A2A1A0_111 0x4F
126  // thermo22_set
128 
143 #define THERMO22_MAP_MIKROBUS( cfg, mikrobus ) \
144  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
145  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
146  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
147  // thermo22_map // thermo22
150 
155 typedef struct
156 {
157  // Input pins
158  digital_in_t int_pin;
160  // Modules
161  i2c_master_t i2c;
163  // I2C slave address
164  uint8_t slave_address;
166 } thermo22_t;
167 
172 typedef struct
173 {
174  pin_name_t scl;
175  pin_name_t sda;
177  pin_name_t int_pin;
179  uint32_t i2c_speed;
180  uint8_t i2c_address;
183 
188 typedef enum
189 {
191  THERMO22_ERROR = -1
192 
194 
211 
227 
242 
255 err_t thermo22_write_config ( thermo22_t *ctx, uint8_t config );
256 
269 err_t thermo22_read_config ( thermo22_t *ctx, uint8_t *config );
270 
282 err_t thermo22_read_temperature ( thermo22_t *ctx, float *temperature );
283 
296 err_t thermo22_set_temperature_low_limit ( thermo22_t *ctx, float low_limit );
297 
310 err_t thermo22_set_temperature_high_limit ( thermo22_t *ctx, float high_limit );
311 
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 #endif // THERMO22_H
326  // thermo22
328 
329 // ------------------------------------------------------------------------ END
thermo22_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo22.h:180
thermo22_t
Thermo 22 Click context object.
Definition: thermo22.h:156
thermo22_t::int_pin
digital_in_t int_pin
Definition: thermo22.h:158
THERMO22_OK
@ THERMO22_OK
Definition: thermo22.h:190
thermo22_init
err_t thermo22_init(thermo22_t *ctx, thermo22_cfg_t *cfg)
Thermo 22 initialization function.
thermo22_t::slave_address
uint8_t slave_address
Definition: thermo22.h:164
thermo22_set_temperature_low_limit
err_t thermo22_set_temperature_low_limit(thermo22_t *ctx, float low_limit)
Thermo 22 set temperature low limit function.
thermo22_cfg_t::scl
pin_name_t scl
Definition: thermo22.h:174
THERMO22_ERROR
@ THERMO22_ERROR
Definition: thermo22.h:191
thermo22_cfg_t::int_pin
pin_name_t int_pin
Definition: thermo22.h:177
thermo22_read_temperature
err_t thermo22_read_temperature(thermo22_t *ctx, float *temperature)
Thermo 22 read temperature function.
thermo22_cfg_setup
void thermo22_cfg_setup(thermo22_cfg_t *cfg)
Thermo 22 configuration object setup function.
thermo22_t::i2c
i2c_master_t i2c
Definition: thermo22.h:161
thermo22_write_config
err_t thermo22_write_config(thermo22_t *ctx, uint8_t config)
Thermo 22 write config function.
thermo22_cfg_t
Thermo 22 Click configuration object.
Definition: thermo22.h:173
thermo22_default_cfg
err_t thermo22_default_cfg(thermo22_t *ctx)
Thermo 22 default configuration function.
thermo22_cfg_t::sda
pin_name_t sda
Definition: thermo22.h:175
thermo22_return_value_t
thermo22_return_value_t
Thermo 22 Click return value data.
Definition: thermo22.h:189
thermo22_read_config
err_t thermo22_read_config(thermo22_t *ctx, uint8_t *config)
Thermo 22 read config function.
thermo22_set_temperature_high_limit
err_t thermo22_set_temperature_high_limit(thermo22_t *ctx, float high_limit)
Thermo 22 set temperature high limit function.
thermo22_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo22.h:179
thermo22_get_int_pin
uint8_t thermo22_get_int_pin(thermo22_t *ctx)
Thermo 22 get int pin function.