thermo8  2.0.0.0
thermo8.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 THERMO8_H
36 #define THERMO8_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 THERMO8_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.ale = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define THERMO8_RETVAL uint8_t
73 
74 #define THERMO8_OK 0x00
75 #define THERMO8_INIT_ERROR 0xFF
76 
82 #define THERMO8_ADDR0 0x18
83 #define THERMO8_ADDR1 (0x18 | 0x01)
84 #define THERMO8_ADDR2 (0x18 | 0x02)
85 #define THERMO8_ADDR3 (0x18 | 0x03)
86 #define THERMO8_ADDR4 (0x18 | 0x04)
87 #define THERMO8_ADDR5 (0x18 | 0x05)
88 #define THERMO8_ADDR6 (0x18 | 0x06)
89 #define THERMO8_ADDR7 (0x18 | 0x07)
90 
96 #define THERMO8_CONFIG 0x01
97 #define THERMO8_TUPPER 0x02
98 #define THERMO8_TLOWER 0x03
99 #define THERMO8_TCRIT 0x04
100 #define THERMO8_TUPPER_REACHED 0x03
101 #define THERMO8_TLOWER_REACHED 0x0C
102 #define THERMO8_TCRIT_REACHED 0x30
103 #define THERMO8_TCRIT_ONLY_ALERT 1
104 #define THERMO8_ALERT_ON_ALL 0
105 #define THERMO8_THYS_0C 0x00
106 #define THERMO8_THYS_1C5 0x01
107 #define THERMO8_THYS_3C 0x02
108 #define THERMO8_THYS_6C 0x03
109 
115 #define THERMO8_TA 0x05
116 #define THERMO8_MANID 0x06
117 #define THERMO8_DEVID 0x07
118 
124 #define THERMO8_RESOLUTION_REG 0x08
125 #define THERMO8_R05C_30MS 0x00
126 #define THERMO8_R025C_65MS 0x01
127 #define THERMO8_R0125C_130MS 0x02
128 #define THERMO8_R00625C_250MS 0x03
129  // End group macro
132 // --------------------------------------------------------------- PUBLIC TYPES
141 typedef struct
142 {
143  // Input pins
144 
145  digital_in_t ale;
146 
147  // Modules
148 
149  i2c_master_t i2c;
150 
151  // ctx variable
152 
153  uint8_t slave_address;
154  uint16_t limit_status;
155 
156 } thermo8_t;
157 
161 typedef struct
162 {
163  // Communication gpio pins
164 
165  pin_name_t scl;
166  pin_name_t sda;
167 
168  // Additional gpio pins
169 
170  pin_name_t ale;
171 
172  // static variable
173 
174  uint32_t i2c_speed;
175  uint8_t i2c_address;
176 
177 } thermo8_cfg_t;
178  // End types group
180 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
181 
187 #ifdef __cplusplus
188 extern "C"{
189 #endif
190 
200 
210 
219 
230 void thermo8_generic_write ( thermo8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
231 
242 void thermo8_generic_read ( thermo8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
243 
251 uint8_t thermo8_ale_get ( thermo8_t *ctx );
252 
262 void thermo8_write_reg ( thermo8_t *ctx, uint8_t r_addr, uint16_t r_data );
263 
272 uint16_t thermo8_read_reg ( thermo8_t *ctx, uint8_t r_addr );
273 
283 void thermo8_write_reg_8 ( thermo8_t *ctx, uint8_t r_addr, uint8_t r_data);
284 
293 uint8_t thermo8_read_reg_8 ( thermo8_t *ctx, uint8_t r_addr );
294 
303 
312 void thermo8_set_resolution ( thermo8_t *ctx, uint8_t r_cfg );
313 
321 uint16_t thermo8_get_dev_id ( thermo8_t *ctx );
322 
330 uint16_t thermo8_get_man_id ( thermo8_t *ctx );
331 
340 void thermo8_sleep ( thermo8_t *ctx );
341 
350 
360 void thermo8_limit_set ( thermo8_t *ctx, uint8_t limit_reg_addr, float limit );
361 
370 
380 void thermo8_alert_enable ( thermo8_t *ctx, uint8_t thys, uint8_t alert_cfg );
381 
391 
400 
410 
419 
420 #ifdef __cplusplus
421 }
422 #endif
423 #endif // _THERMO8_H_
424  // End public_function group
427 
428 // ------------------------------------------------------------------------- END
thermo8_tcrit_unlock
void thermo8_tcrit_unlock(thermo8_t *ctx)
Function for unlocking the critical temperature setting register.
thermo8_get_temperature
float thermo8_get_temperature(thermo8_t *ctx)
Function will return the temperature value in �C.
thermo8_t::ale
digital_in_t ale
Definition: thermo8.h:145
thermo8_generic_write
void thermo8_generic_write(thermo8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
thermo8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo8.h:174
THERMO8_RETVAL
#define THERMO8_RETVAL
Definition: thermo8.h:72
thermo8_cfg_t::sda
pin_name_t sda
Definition: thermo8.h:166
thermo8_read_reg
uint16_t thermo8_read_reg(thermo8_t *ctx, uint8_t r_addr)
Function for reading from 16 bit registers.
thermo8_write_reg
void thermo8_write_reg(thermo8_t *ctx, uint8_t r_addr, uint16_t r_data)
Function for writing to 16 bit registers.
thermo8_limit_set
void thermo8_limit_set(thermo8_t *ctx, uint8_t limit_reg_addr, float limit)
Function for setting the temperature alarm levels for the lower, upper and critical alert levels.
thermo8_cfg_t::scl
pin_name_t scl
Definition: thermo8.h:165
thermo8_cfg_t
Click configuration structure definition.
Definition: thermo8.h:162
thermo8_generic_read
void thermo8_generic_read(thermo8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
thermo8_get_man_id
uint16_t thermo8_get_man_id(thermo8_t *ctx)
Function will return the manufacturer ID.
thermo8_cfg_setup
void thermo8_cfg_setup(thermo8_cfg_t *cfg)
Config Object Initialization function.
thermo8_get_alert_stat
uint8_t thermo8_get_alert_stat(thermo8_t *ctx)
Function will return all alert states.
thermo8_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo8.h:175
thermo8_tcrit_lock
void thermo8_tcrit_lock(thermo8_t *ctx)
Function for locking the critical temperature setting register.
thermo8_set_resolution
void thermo8_set_resolution(thermo8_t *ctx, uint8_t r_cfg)
Function will set the conversion resoult temperature step depending on the passed constant.
thermo8_t
Click ctx object definition.
Definition: thermo8.h:142
thermo8_get_dev_id
uint16_t thermo8_get_dev_id(thermo8_t *ctx)
Function will return the device ID.
thermo8_win_lock
void thermo8_win_lock(thermo8_t *ctx)
Function for locking the Tupper and Tlower registers.
thermo8_read_reg_8
uint8_t thermo8_read_reg_8(thermo8_t *ctx, uint8_t r_addr)
Function for single byte read's.
thermo8_ale_get
uint8_t thermo8_ale_get(thermo8_t *ctx)
Function for returning the state of the alert pin.
thermo8_t::i2c
i2c_master_t i2c
Definition: thermo8.h:149
thermo8_default_cfg
void thermo8_default_cfg(thermo8_t *ctx)
Click Default Configuration function.
thermo8_win_unlock
void thermo8_win_unlock(thermo8_t *ctx)
Function for unlocking the Tupper and Tlower registers.
thermo8_t::slave_address
uint8_t slave_address
Definition: thermo8.h:153
thermo8_init
THERMO8_RETVAL thermo8_init(thermo8_t *ctx, thermo8_cfg_t *cfg)
Initialization function.
thermo8_alert_enable
void thermo8_alert_enable(thermo8_t *ctx, uint8_t thys, uint8_t alert_cfg)
Function for setting the Tupper and Tlower hysterezis level as well as the alert mode.
thermo8_write_reg_8
void thermo8_write_reg_8(thermo8_t *ctx, uint8_t r_addr, uint8_t r_data)
Function for single byte writes.
thermo8_sleep
void thermo8_sleep(thermo8_t *ctx)
Function will place Thermo 8 to the low power mode.
thermo8_wake_up
void thermo8_wake_up(thermo8_t *ctx)
Function for waking up the click board from the sleep mode.
thermo8_cfg_t::ale
pin_name_t ale
Definition: thermo8.h:170
thermo8_t::limit_status
uint16_t limit_status
Definition: thermo8.h:154