thermo15  2.0.0.0
thermo15.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 THERMO15_H
36 #define THERMO15_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_in.h"
53 #include "drv_i2c_master.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define THERMO15_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT );
69 
75 #define THERMO15_RETVAL uint8_t
76 
77 #define THERMO15_OK 0x00
78 #define THERMO15_INIT_ERROR 0xFF
79 
85 #define THERMO15_DEVICE_SLAVE_ADDR_000 0x48
86 #define THERMO15_DEVICE_SLAVE_ADDR_001 0x49
87 #define THERMO15_DEVICE_SLAVE_ADDR_010 0x4A
88 #define THERMO15_DEVICE_SLAVE_ADDR_011 0x4B
89 #define THERMO15_DEVICE_SLAVE_ADDR_100 0x4C
90 #define THERMO15_DEVICE_SLAVE_ADDR_101 0x4D
91 #define THERMO15_DEVICE_SLAVE_ADDR_110 0x4E
92 #define THERMO15_DEVICE_SLAVE_ADDR_111 0x4F
93 
99 #define THERMO15_REG_STORED_TEMPERATURE 0x00
100 #define THERMO15_REG_CONFIGURATION 0x01
101 #define THERMO15_REG_TEMPERATURE_HYSTERESIS 0x02
102 #define THERMO15_REG_TEMPERATURE_LIMIT 0x03
103 #define THERMO15_REG_ONE_SHOT 0x04
104 
110 #define THERMO15_DEF_TEMP_HYSTERESIS 75
111 #define THERMO15_DEF_TEMP_LIMIT 80
112 #define THERMO15_REG_ONE_SHOT 0x04
113 
119 #define THERMO15_CFG_WMODE_NORMAL 0x00
120 #define THERMO15_CFG_WMODE_ONE_SHOT 0x20
121 #define THERMO15_CFG_WMODE_SHUTDOWN 0x01
122 #define THERMO15_CFG_FAULT_QUEUE_1 0x00
123 #define THERMO15_CFG_FAULT_QUEUE_2 0x08
124 #define THERMO15_CFG_FAULT_QUEUE_4 0x10
125 #define THERMO15_CFG_FAULT_QUEUE_6 0x18
126 #define THERMO15_CFG_ALERT_ACTIVE_LOW 0x00
127 #define THERMO15_CFG_ALERT_ACTIVE_HIGH 0x04
128 #define THERMO15_CFG_TMODE_COMPARATOR 0x00
129 #define THERMO15_CFG_TMODE_INTERRUPT 0x02
130 
136 #define THERMO15_TEMP_IN_CELSIUS 0x00
137 #define THERMO15_TEMP_IN_KELVIN 0x01
138 #define THERMO15_TEMP_IN_FAHRENHEIT 0x02
139  // End group macro
142 // --------------------------------------------------------------- PUBLIC TYPES
151 typedef struct
152 {
153  digital_in_t alt;
154 
155  // Modules
156 
157  i2c_master_t i2c;
158 
159  // ctx variable
160 
161  uint8_t slave_address;
162 
163 } thermo15_t;
164 
168 typedef struct
169 {
170  // Communication gpio pins
171 
172  pin_name_t scl;
173  pin_name_t sda;
174 
175  // Additional gpio pins
176 
177  pin_name_t alt;
178 
179  // static variable
180 
181  uint32_t i2c_speed;
182  uint8_t i2c_address;
183 
185  // End types group
187 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
188 
194 #ifdef __cplusplus
195 extern "C"{
196 #endif
197 
207 
216 
225 
236 void thermo15_generic_write ( thermo15_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len );
237 
248 void thermo15_generic_read ( thermo15_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len );
249 
257 float thermo15_get_temperature_data ( thermo15_t *ctx, uint8_t temp_format );
258 
271 void thermo15_set_temp_register ( thermo15_t *ctx, uint8_t temp_reg, float temp_data );
272 
285 float thermo15_get_temp_register ( thermo15_t *ctx, uint8_t temp_reg );
286 
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 #endif // _THERMO15_H_
298  // End public_function group
301 
302 // ------------------------------------------------------------------------- END
thermo15_cfg_t::sda
pin_name_t sda
Definition: thermo15.h:173
thermo15_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo15.h:181
thermo15_t
Click ctx object definition.
Definition: thermo15.h:152
thermo15_cfg_t::scl
pin_name_t scl
Definition: thermo15.h:172
thermo15_cfg_t::alt
pin_name_t alt
Definition: thermo15.h:177
thermo15_get_interrupt_state
uint8_t thermo15_get_interrupt_state(thermo15_t *ctx)
Interrupt state.
thermo15_get_temperature_data
float thermo15_get_temperature_data(thermo15_t *ctx, uint8_t temp_format)
Ambient temperature data.
thermo15_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo15.h:182
thermo15_init
THERMO15_RETVAL thermo15_init(thermo15_t *ctx, thermo15_cfg_t *cfg)
Initialization function.
thermo15_cfg_t
Click configuration structure definition.
Definition: thermo15.h:169
thermo15_get_temp_register
float thermo15_get_temp_register(thermo15_t *ctx, uint8_t temp_reg)
Get temperature register.
thermo15_t::slave_address
uint8_t slave_address
Definition: thermo15.h:161
thermo15_generic_read
void thermo15_generic_read(thermo15_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len)
Generic read function.
THERMO15_RETVAL
#define THERMO15_RETVAL
Definition: thermo15.h:75
thermo15_cfg_setup
void thermo15_cfg_setup(thermo15_cfg_t *cfg)
Config Object Initialization function.
thermo15_set_temp_register
void thermo15_set_temp_register(thermo15_t *ctx, uint8_t temp_reg, float temp_data)
Set temperature register.
thermo15_t::alt
digital_in_t alt
Definition: thermo15.h:153
thermo15_t::i2c
i2c_master_t i2c
Definition: thermo15.h:157
thermo15_generic_write
void thermo15_generic_write(thermo15_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len)
Generic write function.
thermo15_default_cfg
void thermo15_default_cfg(thermo15_t *ctx)
Click Default Configuration function.