thermo11  2.0.0.0
thermo11.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 THERMO11_H
36 #define THERMO11_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define THERMO11_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
57 
63 #define THERMO11_RETVAL uint8_t
64 
65 #define THERMO11_OK 0x00
66 #define THERMO11_INIT_ERROR 0xFF
67 
73 #define THERMO11_DEV_ADDR 0x48
74 
80 #define THERMO11_TEMPERATURE_REG 0x00
81 #define THERMO11_CONFIG_REG 0x01
82 #define THERMO11_HIGH_LIMIT_REG 0x02
83 #define THERMO11_LOW_LIMIT_REG 0x03
84 #define THERMO11_EEPROM_UNLOCK_REG 0x04
85 #define THERMO11_EEPROM1_REG 0x05
86 #define THERMO11_EEPROM2_REG 0x06
87 #define THERMO11_TEMP_OFFSET_REG 0x07
88 #define THERMO11_EEPROM3_REG 0x08
89 #define THERMO11_DEV_ID_REG 0x0F
90 
96 #define THERMO11_CONTINUOUS_CONV_MODE 0x0000
97 #define THERMO11_SHUTDOWN_MODE 0x0400
98 #define THERMO11_ONESHOT_CONV_MODE 0x0C00
99 #define THERMO11_CONV_TIME_0 0x0000
100 #define THERMO11_CONV_TIME_1 0x0080
101 #define THERMO11_CONV_TIME_2 0x0100
102 #define THERMO11_CONV_TIME_3 0x0180
103 #define THERMO11_CONV_TIME_4 0x0200
104 #define THERMO11_CONV_TIME_5 0x0280
105 #define THERMO11_CONV_TIME_6 0x0300
106 #define THERMO11_CONV_TIME_7 0x0380
107 #define THERMO11_NO_AVRG 0x0000
108 #define THERMO11_8_AVRG_CONV 0x0020
109 #define THERMO11_32_AVRG_CONV 0x0040
110 #define THERMO11_64_AVRG_CONV 0x0060
111 #define THERMO11_THERM_MODE 0x0010
112 #define THERMO11_ALERT_MODE 0x0000
113 #define THERMO11_INT_PIN_ACT_HIGH 0x0008
114 #define THERMO11_INT_PIN_ACT_LOW 0x0000
115 #define THERMO11_INT_PIN_DRDY_FLAG 0x0004
116 #define THERMO11_INT_PIN_ALERT_FLAGS 0x0000
117 #define THERMO11_SW_RESET_CMD 0x0002
118 
124 #define THERMO11_EEPROM_LOCK 0x0000
125 #define THERMO11_EEPROM_UNLOCK 0x8000
126 #define THERMO11_EEPROM_BUSY_FLAG 0x4000
127 
133 #define THERMO11_DEV_ID_MASK 0x0FFF
134 #define THERMO11_REVISION_MASK 0xF000
135 
141 #define THERMO11_DRDY_FLAG 0x01
142 #define THERMO11_LOW_ALERT_FLAG 0x02
143 #define THERMO11_HIGH_ALERT_FLAG 0x04
144 #define THERMO11_FLAG_IS_CLEARED 0x00
145 
151 #define THERMO11_INVALID_TEMP_RANGE 0x02
152 #define THERMO11_INVALID_ADDR 0x01
153 #define THERMO11_OK 0x00
154  // End group macro
157 // --------------------------------------------------------------- PUBLIC TYPES
166 typedef struct
167 {
168 
169  // Input pins
170 
171  digital_in_t int_pin;
172 
173  // Modules
174 
175  i2c_master_t i2c;
176 
177  // ctx variable
178 
179  hal_i2c_address_t slave_address;
180 
181 } thermo11_t;
182 
186 typedef struct
187 {
188  // Communication gpio pins
189 
190  pin_name_t scl;
191  pin_name_t sda;
192 
193  // Additional gpio pins
194 
195  pin_name_t int_pin;
196 
197  // static variable
198 
199  hal_i2c_speed_t i2c_speed;
200  hal_i2c_address_t i2c_address;
201 
203  // End types group
205 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
206 
212 #ifdef __cplusplus
213 extern "C"{
214 #endif
215 
224 void thermo11_cfg_setup ( thermo11_cfg_t *cfg );
225 
235 
257 void thermo11_default_cfg ( thermo11_t *ctx );
258 
269 void thermo11_generic_write ( thermo11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
270 
282 void thermo11_generic_read ( thermo11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
283 
293 THERMO11_RETVAL thermo11_write_reg ( thermo11_t *ctx, uint8_t reg_addr, uint16_t data_in );
294 
304 THERMO11_RETVAL thermo11_read_reg ( thermo11_t *ctx, uint8_t reg_addr, uint16_t *data_out );
305 
316 float thermo11_get_temp ( thermo11_t *ctx, uint8_t temp_addr );
317 
327 
337 uint8_t thermo11_sm_bus_alert_cmd ( thermo11_t *ctx );
338 
347 
354 void thermo11_sw_reset ( thermo11_t *ctx );
355 
366 
381 THERMO11_RETVAL thermo11_program_eeprom ( thermo11_t *ctx, uint8_t eeprom_addr, uint16_t eeprom_data );
382 
394 THERMO11_RETVAL thermo11_set_temp ( thermo11_t *ctx, uint8_t temp_addr, float temp_value );
395 
396 #ifdef __cplusplus
397 }
398 #endif
399 #endif // _THERMO11_H_
400  // End public_function group
403 
404 // ------------------------------------------------------------------------- END
void thermo11_cfg_setup(thermo11_cfg_t *cfg)
Config Object Initialization function.
Click ctx object definition.
Definition: thermo11.h:166
pin_name_t int_pin
Definition: thermo11.h:195
float thermo11_get_temp(thermo11_t *ctx, uint8_t temp_addr)
Temperature Get function.
void thermo11_generic_read(thermo11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t thermo11_sm_bus_alert_cmd(thermo11_t *ctx)
SMBus Alert Command.
pin_name_t scl
Definition: thermo11.h:190
digital_in_t int_pin
Definition: thermo11.h:171
hal_i2c_address_t i2c_address
Definition: thermo11.h:200
pin_name_t sda
Definition: thermo11.h:191
#define THERMO11_RETVAL
Definition: thermo11.h:63
THERMO11_RETVAL thermo11_check_status(thermo11_t *ctx)
Status Check function.
void thermo11_generic_write(thermo11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
hal_i2c_address_t slave_address
Definition: thermo11.h:179
void thermo11_general_call_reset_cmd(thermo11_t *ctx)
General Call Reset Command.
hal_i2c_speed_t i2c_speed
Definition: thermo11.h:199
void thermo11_default_cfg(thermo11_t *ctx)
Click Default Configuration function.
THERMO11_RETVAL thermo11_set_temp(thermo11_t *ctx, uint8_t temp_addr, float temp_value)
Temperature Set function.
void thermo11_sw_reset(thermo11_t *ctx)
Software Reset Command.
THERMO11_RETVAL thermo11_write_reg(thermo11_t *ctx, uint8_t reg_addr, uint16_t data_in)
Repeated Write function.
i2c_master_t i2c
Definition: thermo11.h:175
THERMO11_RETVAL thermo11_get_int(thermo11_t *ctx)
INT Pin Check function.
THERMO11_RETVAL thermo11_program_eeprom(thermo11_t *ctx, uint8_t eeprom_addr, uint16_t eeprom_data)
EEPROM Program function.
THERMO11_RETVAL thermo11_init(thermo11_t *ctx, thermo11_cfg_t *cfg)
Initialization function.
THERMO11_RETVAL thermo11_read_reg(thermo11_t *ctx, uint8_t reg_addr, uint16_t *data_out)
Repeated Read function.
Click configuration structure definition.
Definition: thermo11.h:186