thermo13  2.0.0.0
thermo13.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 THERMO13_H
36 #define THERMO13_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 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define THERMO13_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
67 
73 #define THERMO13_RETVAL uint8_t
74 
75 #define THERMO13_OK 0x00
76 #define THERMO13_INIT_ERROR 0xFF
77 
83 #define THERMO13_DEVICE_SLAVE_ADDR_000 0x48
84 #define THERMO13_DEVICE_SLAVE_ADDR_001 0x49
85 #define THERMO13_DEVICE_SLAVE_ADDR_010 0x4A
86 #define THERMO13_DEVICE_SLAVE_ADDR_011 0x4B
87 #define THERMO13_DEVICE_SLAVE_ADDR_100 0x4C
88 #define THERMO13_DEVICE_SLAVE_ADDR_101 0x4D
89 #define THERMO13_DEVICE_SLAVE_ADDR_110 0x4E
90 #define THERMO13_DEVICE_SLAVE_ADDR_111 0x4F
91 
97 #define THERMO13_REG_TEMPERATURE 0x00
98 #define THERMO13_REG_CONFIGURATION 0x01
99 #define THERMO13_REG_TEMPERATURE_LIMIT_LOW 0x02
100 #define THERMO13_REG_TEMPERATURE_LIMIT_HIGH 0x03
101 #define THERMO13_REG_SOFTWARE_RESET 0x04
102 
108 #define THERMO13_TEMP_IN_CELSIUS 0x00
109 #define THERMO13_TEMP_IN_KELVIN 0x01
110 #define THERMO13_TEMP_IN_FAHRENHEIT 0x02
111 
117 #define THERMO13_DEF_TEMP_LIMIT_LOW 75
118 #define THERMO13_DEF_TEMP_LIMIT_HIGH 80
119 
125 #define THERMO13_CFG_CONTINUOUS_MEASUREMENT 0x0000
126 #define THERMO13_CFG_SINGLE_MEASUREMENT 0x8000
127 #define THERMO13_CFG_INTERRUPT_IS_NOT_ACTIVE 0x0000
128 #define THERMO13_CFG_INTERRUPT_IS_ACTIVE 0x4000
129 #define THERMO13_CFG_FAULT_QUEUE_1 0x0000
130 #define THERMO13_CFG_FAULT_QUEUE_2 0x0800
131 #define THERMO13_CFG_FAULT_QUEUE_4 0x1000
132 #define THERMO13_CFG_FAULT_QUEUE_6 0x1800
133 #define THERMO13_CFG_ALERT_ACTIVE_LOW 0x0000
134 #define THERMO13_CFG_ALERT_ACTIVE_HIGH 0x0400
135 #define THERMO13_CFG_NO_SHUTDOWN 0x0000
136 #define THERMO13_CFG_SHUTDOWN_ACTIVE 0x0100
137 #define THERMO13_CFG_WAIT_TIME_X16 0x0000
138 #define THERMO13_CFG_WAIT_TIME_X4 0x0001
139 #define THERMO13_CFG_WAIT_TIME_X1 0x0002
140 #define THERMO13_CFG_WAIT_TIME_X0p5 0x0003
141  // End group macro
144 // --------------------------------------------------------------- PUBLIC TYPES
153 typedef struct thermo13_s
154 {
155  // Output pins
156 
157  digital_out_t int_pin;
158 
159  // Modules
160 
161  i2c_master_t i2c;
162 
163  // ctx variable
164 
165  uint8_t slave_address;
166 
168 
172 typedef struct
173 {
174  // Communication gpio pins
175 
176  pin_name_t scl;
177  pin_name_t sda;
178 
179  // Additional gpio pins
180 
181  pin_name_t int_pin;
182 
183  // static variable
184 
185  uint32_t i2c_speed;
186  uint8_t i2c_address;
187 
188 
190  // End types group
192 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
193 
199 #ifdef __cplusplus
200 extern "C"{
201 #endif
202 
212 
221 
230 
241 void thermo13_generic_write ( thermo13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
242 
254 void thermo13_generic_read ( thermo13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
255 
263 uint16_t thermo13_read_data ( thermo13_t *ctx, uint8_t reg_addr );
264 
273 void thermo13_configuration ( thermo13_t *ctx,uint16_t cfg_data );
274 
282 float thermo13_get_ambient_temperature_data ( thermo13_t *ctx, uint8_t temp_in );
283 
296 void thermo13_set_temp_limit ( thermo13_t *ctx, uint8_t temp_reg, float temp );
297 
310 float thermo13_get_temp_limit ( thermo13_t *ctx, uint8_t temp_reg );
311 
319 
324 
325 
326 #ifdef __cplusplus
327 }
328 #endif
329 #endif // THERMO13_H_
330  // End public_function group
333 
334 // ------------------------------------------------------------------------- END
thermo13_cfg_t::scl
pin_name_t scl
Definition: thermo13.h:176
thermo13_t
struct thermo13_s thermo13_t
Click ctx object definition.
thermo13_get_interrupt_state
uint8_t thermo13_get_interrupt_state(thermo13_t *ctx)
Interrupt state.
thermo13_s::slave_address
uint8_t slave_address
Definition: thermo13.h:165
thermo13_cfg_setup
void thermo13_cfg_setup(thermo13_cfg_t *cfg)
Config Object Initialization function.
thermo13_get_temp_limit
float thermo13_get_temp_limit(thermo13_t *ctx, uint8_t temp_reg)
Get temperature register.
thermo13_configuration
void thermo13_configuration(thermo13_t *ctx, uint16_t cfg_data)
Configuration register.
thermo13_set_temp_limit
void thermo13_set_temp_limit(thermo13_t *ctx, uint8_t temp_reg, float temp)
Set temperature limit register.
thermo13_cfg_t::int_pin
pin_name_t int_pin
Definition: thermo13.h:181
thermo13_software_reset
void thermo13_software_reset(thermo13_t *ctx)
Software reset.
thermo13_s
Click ctx object definition.
Definition: thermo13.h:154
thermo13_default_cfg
void thermo13_default_cfg(thermo13_t *ctx)
Click Default Configuration function.
thermo13_cfg_t
Click configuration structure definition.
Definition: thermo13.h:173
thermo13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo13.h:185
thermo13_s::int_pin
digital_out_t int_pin
Definition: thermo13.h:157
THERMO13_RETVAL
#define THERMO13_RETVAL
Definition: thermo13.h:73
thermo13_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo13.h:186
thermo13_read_data
uint16_t thermo13_read_data(thermo13_t *ctx, uint8_t reg_addr)
Functions for read data from registers.
thermo13_init
THERMO13_RETVAL thermo13_init(thermo13_t *ctx, thermo13_cfg_t *cfg)
Initialization function.
thermo13_get_ambient_temperature_data
float thermo13_get_ambient_temperature_data(thermo13_t *ctx, uint8_t temp_in)
Ambient temperature data.
thermo13_cfg_t::sda
pin_name_t sda
Definition: thermo13.h:177
thermo13_generic_read
void thermo13_generic_read(thermo13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
thermo13_generic_write
void thermo13_generic_write(thermo13_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
thermo13_s::i2c
i2c_master_t i2c
Definition: thermo13.h:161