thermo6  2.0.0.0
thermo6.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 THERMO6_H
36 #define THERMO6_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 THERMO6_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define THERMO6_RETVAL uint8_t
72 
73 #define THERMO6_OK 0x00
74 #define THERMO6_INIT_ERROR 0xFF
75 
81 #define THERMO6_SLAVE_ADDRESS 0x48
82 
88 #define THERMO6_REG_TEMPERATURE 0x00
89 #define THERMO6_REG_CONFIG 0x01
90 #define THERMO6_REG_TEMP_HYST 0x02
91 #define THERMO6_REG_TEMP_OS 0x03
92 
98 #define THERMO6_CFG_ONE_SHOT 0x0001
99 
100 #define THERMO6_CFG_CONVERSION_RATE_0_25 0x0000
101 #define THERMO6_CFG_CONVERSION_RATE_1 0x0002
102 #define THERMO6_CFG_CONVERSION_RATE_4 0x0004
103 #define THERMO6_CFG_CONVERSION_RATE_8 0x0006
104 
105 #define THERMO6_CFG_PEC_ENABLE 0x0008
106 #define THERMO6_CFG_PEC_DISABLE 0x0000
107 
108 #define THERMO6_CFG_TIMEOUT_ENABLE 0x0010
109 #define THERMO6_CFG_TIMEOUT_DISABLE 0x0000
110 
111 #define THERMO6_CFG_RESOLUTION_8 0x0000
112 #define THERMO6_CFG_RESOLUTION_9 0x0020
113 #define THERMO6_CFG_RESOLUTION_10 0x0040
114 #define THERMO6_CFG_RESOLUTION_12 0x0060
115 
116 #define THERMO6_CFG_NORMAL_FORMAT 0x0000
117 #define THERMO6_CFG_EXTENDED_FORMAT 0x0080
118 
119 #define THERMO6_CFG_SHUT_DOWN 0x0100
120 #define THERMO6_CFG_POWER_UP 0x0000
121 
122 #define THERMO6_CFG_COMPARATOR_MODE 0x0000
123 #define THERMO6_CFG_INTERRUPT_MODE 0x0200
124 
125 #define THERMO6_CFG_FAULT_QUEUE_1 0x0000
126 #define THERMO6_CFG_FAULT_QUEUE_2 0x0800
127 #define THERMO6_CFG_FAULT_QUEUE_4 0x1000
128 #define THERMO6_CFG_FAULT_QUEUE_6 0x1800
129 
135 #define THERMO6_TEMP_FORMAT_CELSIUS 0
136 #define THERMO6_TEMP_FORMAT_FAHRENHEIT 2
137 #define THERMO6_TEMP_FORMAT_KELVIN 1
138 
144 #define THERMO6_TEMP_RESOLUTION_12bit 3
145 #define THERMO6_TEMP_RESOLUTION_10bit 2
146 #define THERMO6_TEMP_RESOLUTION_9bit 1
147 #define THERMO6_TEMP_RESOLUTION_8bit 0
148  // End group macro
151 // --------------------------------------------------------------- PUBLIC TYPES
160 typedef struct
161 {
162  // Modules
163 
164  i2c_master_t i2c;
165 
166  // ctx variable
167 
168  uint8_t slave_address;
170 
171 } thermo6_t;
172 
176 typedef struct
177 {
178  // Communication gpio pins
179 
180  pin_name_t scl;
181  pin_name_t sda;
182 
183  // static variable
184 
185  uint32_t i2c_speed;
186  uint8_t i2c_address;
187 
188 } thermo6_cfg_t;
189  // End types group
191 
192 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
193 
199 #ifdef __cplusplus
200 extern "C"{
201 #endif
202 
212 
222 
244 
255 void thermo6_generic_write ( thermo6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
256 
268 void thermo6_generic_read ( thermo6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
269 
279 float thermo6_get_temperature_data ( thermo6_t *ctx, uint8_t temp_format );
280 
290 void thermo6_set_other_register ( thermo6_t *ctx, uint8_t reg, float tx_data );
291 
301 float thermo6_get_other_register( thermo6_t *ctx, uint8_t reg );
302 
315 
325 void thermo6_set_register_cfg ( thermo6_t *ctx, uint16_t cfg_data );
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 #endif // _THERMO6_H_
331  // End public_function group
334 
335 // ------------------------------------------------------------------------- END
THERMO6_RETVAL
#define THERMO6_RETVAL
Definition: thermo6.h:71
thermo6_get_temperature_data
float thermo6_get_temperature_data(thermo6_t *ctx, uint8_t temp_format)
Temperature function.
thermo6_init
THERMO6_RETVAL thermo6_init(thermo6_t *ctx, thermo6_cfg_t *cfg)
Initialization function.
thermo6_set_register_cfg
void thermo6_set_register_cfg(thermo6_t *ctx, uint16_t cfg_data)
Write configuration function.
thermo6_set_other_register
void thermo6_set_other_register(thermo6_t *ctx, uint8_t reg, float tx_data)
Set other register.
thermo6_cfg_t
Click configuration structure definition.
Definition: thermo6.h:177
thermo6_default_cfg
void thermo6_default_cfg(thermo6_t *ctx)
Click Default Configuration function.
thermo6_t
Click ctx object definition.
Definition: thermo6.h:161
thermo6_t::i2c
i2c_master_t i2c
Definition: thermo6.h:164
thermo6_t::slave_address
uint8_t slave_address
Definition: thermo6.h:168
thermo6_cfg_t::sda
pin_name_t sda
Definition: thermo6.h:181
thermo6_t::temp_resolution
uint8_t temp_resolution
Definition: thermo6.h:169
thermo6_generic_write
void thermo6_generic_write(thermo6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
thermo6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo6.h:185
thermo6_get_over_temp_status
uint8_t thermo6_get_over_temp_status(thermo6_t *ctx)
Read over-temperature status function.
thermo6_cfg_setup
void thermo6_cfg_setup(thermo6_cfg_t *cfg)
Config Object Initialization function.
thermo6_get_other_register
float thermo6_get_other_register(thermo6_t *ctx, uint8_t reg)
Set other register.
thermo6_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo6.h:186
thermo6_cfg_t::scl
pin_name_t scl
Definition: thermo6.h:180
thermo6_generic_read
void thermo6_generic_read(thermo6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.