thermo13  2.0.0.0
thermo13.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef THERMO13_H
36 #define THERMO13_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define THERMO13_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
57 
63 #define THERMO13_RETVAL uint8_t
64 
65 #define THERMO13_OK 0x00
66 #define THERMO13_INIT_ERROR 0xFF
67 
73 #define THERMO13_DEVICE_SLAVE_ADDR_000 0x48
74 #define THERMO13_DEVICE_SLAVE_ADDR_001 0x49
75 #define THERMO13_DEVICE_SLAVE_ADDR_010 0x4A
76 #define THERMO13_DEVICE_SLAVE_ADDR_011 0x4B
77 #define THERMO13_DEVICE_SLAVE_ADDR_100 0x4C
78 #define THERMO13_DEVICE_SLAVE_ADDR_101 0x4D
79 #define THERMO13_DEVICE_SLAVE_ADDR_110 0x4E
80 #define THERMO13_DEVICE_SLAVE_ADDR_111 0x4F
81 
87 #define THERMO13_REG_TEMPERATURE 0x00
88 #define THERMO13_REG_CONFIGURATION 0x01
89 #define THERMO13_REG_TEMPERATURE_LIMIT_LOW 0x02
90 #define THERMO13_REG_TEMPERATURE_LIMIT_HIGH 0x03
91 #define THERMO13_REG_SOFTWARE_RESET 0x04
92 
98 #define THERMO13_TEMP_IN_CELSIUS 0x00
99 #define THERMO13_TEMP_IN_KELVIN 0x01
100 #define THERMO13_TEMP_IN_FAHRENHEIT 0x02
101 
107 #define THERMO13_DEF_TEMP_LIMIT_LOW 75
108 #define THERMO13_DEF_TEMP_LIMIT_HIGH 80
109 
115 #define THERMO13_CFG_CONTINUOUS_MEASUREMENT 0x0000
116 #define THERMO13_CFG_SINGLE_MEASUREMENT 0x8000
117 #define THERMO13_CFG_INTERRUPT_IS_NOT_ACTIVE 0x0000
118 #define THERMO13_CFG_INTERRUPT_IS_ACTIVE 0x4000
119 #define THERMO13_CFG_FAULT_QUEUE_1 0x0000
120 #define THERMO13_CFG_FAULT_QUEUE_2 0x0800
121 #define THERMO13_CFG_FAULT_QUEUE_4 0x1000
122 #define THERMO13_CFG_FAULT_QUEUE_6 0x1800
123 #define THERMO13_CFG_ALERT_ACTIVE_LOW 0x0000
124 #define THERMO13_CFG_ALERT_ACTIVE_HIGH 0x0400
125 #define THERMO13_CFG_NO_SHUTDOWN 0x0000
126 #define THERMO13_CFG_SHUTDOWN_ACTIVE 0x0100
127 #define THERMO13_CFG_WAIT_TIME_X16 0x0000
128 #define THERMO13_CFG_WAIT_TIME_X4 0x0001
129 #define THERMO13_CFG_WAIT_TIME_X1 0x0002
130 #define THERMO13_CFG_WAIT_TIME_X0p5 0x0003
131  // End group macro
134 // --------------------------------------------------------------- PUBLIC TYPES
143 typedef struct
144 {
145  // Output pins
146 
147  digital_out_t int_pin;
148 
149  // Modules
150 
151  i2c_master_t i2c;
152 
153  // ctx variable
154 
155  hal_i2c_address_t slave_address;
156 
157 } thermo13_t;
158 
162 typedef struct
163 {
164  // Communication gpio pins
165 
166  pin_name_t scl;
167  pin_name_t sda;
168 
169  // Additional gpio pins
170 
171  pin_name_t int_pin;
172 
173  // static variable
174 
175  hal_i2c_speed_t i2c_speed;
176  hal_i2c_address_t i2c_address;
177 
179  // End types group
181 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
182 
188 #ifdef __cplusplus
189 extern "C"{
190 #endif
191 
200 void thermo13_cfg_setup ( thermo13_cfg_t *cfg );
201 
210 
218 void thermo13_default_cfg ( thermo13_t *ctx );
219 
230 void thermo13_generic_write ( thermo13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
231 
243 void thermo13_generic_read ( thermo13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
244 
252 uint16_t thermo13_read_data ( thermo13_t *ctx, uint8_t reg_addr );
253 
262 void thermo13_configuration ( thermo13_t *ctx,uint16_t cfg_data );
263 
271 float thermo13_get_ambient_temperature_data ( thermo13_t *ctx, uint8_t temp_in );
272 
285 void thermo13_set_temp_limit ( thermo13_t *ctx, uint8_t temp_reg, float temp );
286 
299 float thermo13_get_temp_limit ( thermo13_t *ctx, uint8_t temp_reg );
300 
308 
312 void thermo13_software_reset ( thermo13_t *ctx );
313 
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 #endif // THERMO13_H_
319  // End public_function group
322 
323 // ------------------------------------------------------------------------- END
float thermo13_get_ambient_temperature_data(thermo13_t *ctx, uint8_t temp_in)
Ambient temperature data.
pin_name_t int_pin
Definition: thermo13.h:171
float thermo13_get_temp_limit(thermo13_t *ctx, uint8_t temp_reg)
Get temperature register.
void thermo13_cfg_setup(thermo13_cfg_t *cfg)
Config Object Initialization function.
void thermo13_default_cfg(thermo13_t *ctx)
Click Default Configuration function.
digital_out_t int_pin
Definition: thermo13.h:147
hal_i2c_address_t slave_address
Definition: thermo13.h:155
hal_i2c_address_t i2c_address
Definition: thermo13.h:176
hal_i2c_speed_t i2c_speed
Definition: thermo13.h:175
THERMO13_RETVAL thermo13_init(thermo13_t *ctx, thermo13_cfg_t *cfg)
Initialization function.
void thermo13_software_reset(thermo13_t *ctx)
Software reset.
void thermo13_generic_read(thermo13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
pin_name_t scl
Definition: thermo13.h:166
i2c_master_t i2c
Definition: thermo13.h:151
#define THERMO13_RETVAL
Definition: thermo13.h:63
pin_name_t sda
Definition: thermo13.h:167
void thermo13_configuration(thermo13_t *ctx, uint16_t cfg_data)
Configuration register.
void thermo13_set_temp_limit(thermo13_t *ctx, uint8_t temp_reg, float temp)
Set temperature limit register.
uint16_t thermo13_read_data(thermo13_t *ctx, uint8_t reg_addr)
Functions for read data from registers.
Click ctx object definition.
Definition: thermo13.h:143
void thermo13_generic_write(thermo13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t thermo13_get_interrupt_state(thermo13_t *ctx)
Interrupt state.
Click configuration structure definition.
Definition: thermo13.h:162