thermo6  2.0.0.0
thermo6.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 THERMO6_H
36 #define THERMO6_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 THERMO6_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
56 
62 #define THERMO6_RETVAL uint8_t
63 
64 #define THERMO6_OK 0x00
65 #define THERMO6_INIT_ERROR 0xFF
66 
72 #define THERMO6_SLAVE_ADDRESS 0x48
73 
79 #define THERMO6_REG_TEMPERATURE 0x00
80 #define THERMO6_REG_CONFIG 0x01
81 #define THERMO6_REG_TEMP_HYST 0x02
82 #define THERMO6_REG_TEMP_OS 0x03
83 
89 #define THERMO6_CFG_ONE_SHOT 0x0001
90 
91 #define THERMO6_CFG_CONVERSION_RATE_0_25 0x0000
92 #define THERMO6_CFG_CONVERSION_RATE_1 0x0002
93 #define THERMO6_CFG_CONVERSION_RATE_4 0x0004
94 #define THERMO6_CFG_CONVERSION_RATE_8 0x0006
95 
96 #define THERMO6_CFG_PEC_ENABLE 0x0008
97 #define THERMO6_CFG_PEC_DISABLE 0x0000
98 
99 #define THERMO6_CFG_TIMEOUT_ENABLE 0x0010
100 #define THERMO6_CFG_TIMEOUT_DISABLE 0x0000
101 
102 #define THERMO6_CFG_RESOLUTION_8 0x0000
103 #define THERMO6_CFG_RESOLUTION_9 0x0020
104 #define THERMO6_CFG_RESOLUTION_10 0x0040
105 #define THERMO6_CFG_RESOLUTION_12 0x0060
106 
107 #define THERMO6_CFG_NORMAL_FORMAT 0x0000
108 #define THERMO6_CFG_EXTENDED_FORMAT 0x0080
109 
110 #define THERMO6_CFG_SHUT_DOWN 0x0100
111 #define THERMO6_CFG_POWER_UP 0x0000
112 
113 #define THERMO6_CFG_COMPARATOR_MODE 0x0000
114 #define THERMO6_CFG_INTERRUPT_MODE 0x0200
115 
116 #define THERMO6_CFG_FAULT_QUEUE_1 0x0000
117 #define THERMO6_CFG_FAULT_QUEUE_2 0x0800
118 #define THERMO6_CFG_FAULT_QUEUE_4 0x1000
119 #define THERMO6_CFG_FAULT_QUEUE_6 0x1800
120 
126 #define THERMO6_TEMP_FORMAT_CELSIUS 0
127 #define THERMO6_TEMP_FORMAT_FAHRENHEIT 2
128 #define THERMO6_TEMP_FORMAT_KELVIN 1
129 
135 #define THERMO6_TEMP_RESOLUTION_12bit 3
136 #define THERMO6_TEMP_RESOLUTION_10bit 2
137 #define THERMO6_TEMP_RESOLUTION_9bit 1
138 #define THERMO6_TEMP_RESOLUTION_8bit 0
139  // End group macro
142 // --------------------------------------------------------------- PUBLIC TYPES
151 typedef struct
152 {
153  // Modules
154 
155  i2c_master_t i2c;
156 
157  // ctx variable
158 
159  hal_i2c_address_t slave_address;
161 
162 } thermo6_t;
163 
167 typedef struct
168 {
169  // Communication gpio pins
170 
171  pin_name_t scl;
172  pin_name_t sda;
173 
174  // static variable
175 
176  hal_i2c_speed_t i2c_speed;
177  hal_i2c_address_t i2c_address;
178 
179 } thermo6_cfg_t;
180  // End types group
182 
183 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
184 
190 #ifdef __cplusplus
191 extern "C"{
192 #endif
193 
202 void thermo6_cfg_setup ( thermo6_cfg_t *cfg );
203 
212 
233 void thermo6_default_cfg ( thermo6_t *ctx );
234 
245 void thermo6_generic_write ( thermo6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
246 
258 void thermo6_generic_read ( thermo6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
259 
269 float thermo6_get_temperature_data ( thermo6_t *ctx, uint8_t temp_format );
270 
280 void thermo6_set_other_register ( thermo6_t *ctx, uint8_t reg, float tx_data );
281 
291 float thermo6_get_other_register( thermo6_t *ctx, uint8_t reg );
292 
305 
315 void thermo6_set_register_cfg ( thermo6_t *ctx, uint16_t cfg_data );
316 
317 #ifdef __cplusplus
318 }
319 #endif
320 #endif // _THERMO6_H_
321  // End public_function group
324 
325 // ------------------------------------------------------------------------- END
void thermo6_generic_write(thermo6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
hal_i2c_speed_t i2c_speed
Definition: thermo6.h:176
void thermo6_generic_read(thermo6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
hal_i2c_address_t i2c_address
Definition: thermo6.h:177
i2c_master_t i2c
Definition: thermo6.h:155
#define THERMO6_RETVAL
Definition: thermo6.h:62
uint8_t temp_resolution
Definition: thermo6.h:160
void thermo6_set_other_register(thermo6_t *ctx, uint8_t reg, float tx_data)
Set other register.
pin_name_t sda
Definition: thermo6.h:172
Click configuration structure definition.
Definition: thermo6.h:167
Click ctx object definition.
Definition: thermo6.h:151
hal_i2c_address_t slave_address
Definition: thermo6.h:159
void thermo6_default_cfg(thermo6_t *ctx)
Click Default Configuration function.
void thermo6_set_register_cfg(thermo6_t *ctx, uint16_t cfg_data)
Write configuration function.
void thermo6_cfg_setup(thermo6_cfg_t *cfg)
Config Object Initialization function.
uint8_t thermo6_get_over_temp_status(thermo6_t *ctx)
Read over-temperature status function.
pin_name_t scl
Definition: thermo6.h:171
THERMO6_RETVAL thermo6_init(thermo6_t *ctx, thermo6_cfg_t *cfg)
Initialization function.
float thermo6_get_other_register(thermo6_t *ctx, uint8_t reg)
Set other register.
float thermo6_get_temperature_data(thermo6_t *ctx, uint8_t temp_format)
Temperature function.