thermo15  2.0.0.0
thermo15.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 THERMO15_H
36 #define THERMO15_H
37 
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define THERMO15_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT );
55 
61 #define THERMO15_RETVAL uint8_t
62 
63 #define THERMO15_OK 0x00
64 #define THERMO15_INIT_ERROR 0xFF
65 
71 #define THERMO15_DEVICE_SLAVE_ADDR_000 0x48
72 #define THERMO15_DEVICE_SLAVE_ADDR_001 0x49
73 #define THERMO15_DEVICE_SLAVE_ADDR_010 0x4A
74 #define THERMO15_DEVICE_SLAVE_ADDR_011 0x4B
75 #define THERMO15_DEVICE_SLAVE_ADDR_100 0x4C
76 #define THERMO15_DEVICE_SLAVE_ADDR_101 0x4D
77 #define THERMO15_DEVICE_SLAVE_ADDR_110 0x4E
78 #define THERMO15_DEVICE_SLAVE_ADDR_111 0x4F
79 
85 #define THERMO15_REG_STORED_TEMPERATURE 0x00
86 #define THERMO15_REG_CONFIGURATION 0x01
87 #define THERMO15_REG_TEMPERATURE_HYSTERESIS 0x02
88 #define THERMO15_REG_TEMPERATURE_LIMIT 0x03
89 #define THERMO15_REG_ONE_SHOT 0x04
90 
96 #define THERMO15_DEF_TEMP_HYSTERESIS 75
97 #define THERMO15_DEF_TEMP_LIMIT 80
98 #define THERMO15_REG_ONE_SHOT 0x04
99 
105 #define THERMO15_CFG_WMODE_NORMAL 0x00
106 #define THERMO15_CFG_WMODE_ONE_SHOT 0x20
107 #define THERMO15_CFG_WMODE_SHUTDOWN 0x01
108 #define THERMO15_CFG_FAULT_QUEUE_1 0x00
109 #define THERMO15_CFG_FAULT_QUEUE_2 0x08
110 #define THERMO15_CFG_FAULT_QUEUE_4 0x10
111 #define THERMO15_CFG_FAULT_QUEUE_6 0x18
112 #define THERMO15_CFG_ALERT_ACTIVE_LOW 0x00
113 #define THERMO15_CFG_ALERT_ACTIVE_HIGH 0x04
114 #define THERMO15_CFG_TMODE_COMPARATOR 0x00
115 #define THERMO15_CFG_TMODE_INTERRUPT 0x02
116 
122 #define THERMO15_TEMP_IN_CELSIUS 0x00
123 #define THERMO15_TEMP_IN_KELVIN 0x01
124 #define THERMO15_TEMP_IN_FAHRENHEIT 0x02
125  // End group macro
128 // --------------------------------------------------------------- PUBLIC TYPES
137 typedef struct
138 {
139  digital_in_t alt;
140 
141  // Modules
142 
143  i2c_master_t i2c;
144 
145  // ctx variable
146 
147  hal_i2c_address_t slave_address;
148 
149 } thermo15_t;
150 
154 typedef struct
155 {
156  // Communication gpio pins
157 
158  pin_name_t scl;
159  pin_name_t sda;
160 
161  // Additional gpio pins
162 
163  pin_name_t alt;
164 
165  // static variable
166 
167  hal_i2c_speed_t i2c_speed;
168  hal_i2c_address_t i2c_address;
169 
171  // End types group
173 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
174 
180 #ifdef __cplusplus
181 extern "C"{
182 #endif
183 
192 void thermo15_cfg_setup ( thermo15_cfg_t *cfg );
193 
202 
210 void thermo15_default_cfg ( thermo15_t *ctx );
211 
222 void thermo15_generic_write ( thermo15_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len );
223 
234 void thermo15_generic_read ( thermo15_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len );
235 
243 float thermo15_get_temperature_data ( thermo15_t *ctx, uint8_t temp_format );
244 
257 void thermo15_set_temp_register ( thermo15_t *ctx, uint8_t temp_reg, float temp_data );
258 
271 float thermo15_get_temp_register ( thermo15_t *ctx, uint8_t temp_reg );
272 
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 #endif // _THERMO15_H_
284  // End public_function group
287 
288 // ------------------------------------------------------------------------- END
thermo15_cfg_t::sda
pin_name_t sda
Definition: thermo15.h:159
thermo15_t
Click ctx object definition.
Definition: thermo15.h:137
thermo15_cfg_t::i2c_address
hal_i2c_address_t i2c_address
Definition: thermo15.h:168
thermo15_t::slave_address
hal_i2c_address_t slave_address
Definition: thermo15.h:147
thermo15_cfg_t::scl
pin_name_t scl
Definition: thermo15.h:158
thermo15_cfg_t::alt
pin_name_t alt
Definition: thermo15.h:163
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_init
THERMO15_RETVAL thermo15_init(thermo15_t *ctx, thermo15_cfg_t *cfg)
Initialization function.
thermo15_cfg_t
Click configuration structure definition.
Definition: thermo15.h:154
thermo15_get_temp_register
float thermo15_get_temp_register(thermo15_t *ctx, uint8_t temp_reg)
Get temperature register.
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:61
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:139
thermo15_t::i2c
i2c_master_t i2c
Definition: thermo15.h:143
thermo15_cfg_t::i2c_speed
hal_i2c_speed_t i2c_speed
Definition: thermo15.h:167
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.