thermo11  2.0.0.0
thermo11.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 THERMO11_H
36 #define THERMO11_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 THERMO11_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 THERMO11_RETVAL uint8_t
74 
75 #define THERMO11_OK 0x00
76 #define THERMO11_INIT_ERROR 0xFF
77 
83 #define THERMO11_DEV_ADDR 0x48
84 
90 #define THERMO11_TEMPERATURE_REG 0x00
91 #define THERMO11_CONFIG_REG 0x01
92 #define THERMO11_HIGH_LIMIT_REG 0x02
93 #define THERMO11_LOW_LIMIT_REG 0x03
94 #define THERMO11_EEPROM_UNLOCK_REG 0x04
95 #define THERMO11_EEPROM1_REG 0x05
96 #define THERMO11_EEPROM2_REG 0x06
97 #define THERMO11_TEMP_OFFSET_REG 0x07
98 #define THERMO11_EEPROM3_REG 0x08
99 #define THERMO11_DEV_ID_REG 0x0F
100 
106 #define THERMO11_CONTINUOUS_CONV_MODE 0x0000
107 #define THERMO11_SHUTDOWN_MODE 0x0400
108 #define THERMO11_ONESHOT_CONV_MODE 0x0C00
109 #define THERMO11_CONV_TIME_0 0x0000
110 #define THERMO11_CONV_TIME_1 0x0080
111 #define THERMO11_CONV_TIME_2 0x0100
112 #define THERMO11_CONV_TIME_3 0x0180
113 #define THERMO11_CONV_TIME_4 0x0200
114 #define THERMO11_CONV_TIME_5 0x0280
115 #define THERMO11_CONV_TIME_6 0x0300
116 #define THERMO11_CONV_TIME_7 0x0380
117 #define THERMO11_NO_AVRG 0x0000
118 #define THERMO11_8_AVRG_CONV 0x0020
119 #define THERMO11_32_AVRG_CONV 0x0040
120 #define THERMO11_64_AVRG_CONV 0x0060
121 #define THERMO11_THERM_MODE 0x0010
122 #define THERMO11_ALERT_MODE 0x0000
123 #define THERMO11_INT_PIN_ACT_HIGH 0x0008
124 #define THERMO11_INT_PIN_ACT_LOW 0x0000
125 #define THERMO11_INT_PIN_DRDY_FLAG 0x0004
126 #define THERMO11_INT_PIN_ALERT_FLAGS 0x0000
127 #define THERMO11_SW_RESET_CMD 0x0002
128 
134 #define THERMO11_EEPROM_LOCK 0x0000
135 #define THERMO11_EEPROM_UNLOCK 0x8000
136 #define THERMO11_EEPROM_BUSY_FLAG 0x4000
137 
143 #define THERMO11_DEV_ID_MASK 0x0FFF
144 #define THERMO11_REVISION_MASK 0xF000
145 
151 #define THERMO11_DRDY_FLAG 0x01
152 #define THERMO11_LOW_ALERT_FLAG 0x02
153 #define THERMO11_HIGH_ALERT_FLAG 0x04
154 #define THERMO11_FLAG_IS_CLEARED 0x00
155 
161 #define THERMO11_INVALID_TEMP_RANGE 0x02
162 #define THERMO11_INVALID_ADDR 0x01
163 #define THERMO11_OK 0x00
164  // End group macro
167 // --------------------------------------------------------------- PUBLIC TYPES
176 typedef struct
177 {
178 
179  // Input pins
180  digital_in_t int_pin;
181 
182  // Modules
183 
184  i2c_master_t i2c;
185 
186  // ctx variable
187 
188  uint8_t slave_address;
189 
190 } thermo11_t;
191 
195 typedef struct
196 {
197  // Communication gpio pins
198 
199  pin_name_t scl;
200  pin_name_t sda;
201 
202  // Additional gpio pins
203 
204  pin_name_t int_pin;
205 
206  // static variable
207 
208  uint32_t i2c_speed;
209  uint8_t i2c_address;
210 
212  // End types group
214 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
215 
221 #ifdef __cplusplus
222 extern "C"{
223 #endif
224 
234 
244 
267 
278 void thermo11_generic_write ( thermo11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
279 
291 void thermo11_generic_read ( thermo11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
292 
302 THERMO11_RETVAL thermo11_write_reg ( thermo11_t *ctx, uint8_t reg_addr, uint16_t data_in );
303 
313 THERMO11_RETVAL thermo11_read_reg ( thermo11_t *ctx, uint8_t reg_addr, uint16_t *data_out );
314 
325 float thermo11_get_temp ( thermo11_t *ctx, uint8_t temp_addr );
326 
336 
347 
356 
364 
375 
390 THERMO11_RETVAL thermo11_program_eeprom ( thermo11_t *ctx, uint8_t eeprom_addr, uint16_t eeprom_data );
391 
403 THERMO11_RETVAL thermo11_set_temp ( thermo11_t *ctx, uint8_t temp_addr, float temp_value );
404 
405 #ifdef __cplusplus
406 }
407 #endif
408 #endif // _THERMO11_H_
409  // End public_function group
412 
413 // ------------------------------------------------------------------------- END
thermo11_write_reg
THERMO11_RETVAL thermo11_write_reg(thermo11_t *ctx, uint8_t reg_addr, uint16_t data_in)
Repeated Write function.
thermo11_generic_write
void thermo11_generic_write(thermo11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
thermo11_generic_read
void thermo11_generic_read(thermo11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
thermo11_t::i2c
i2c_master_t i2c
Definition: thermo11.h:184
thermo11_default_cfg
void thermo11_default_cfg(thermo11_t *ctx)
Click Default Configuration function.
thermo11_program_eeprom
THERMO11_RETVAL thermo11_program_eeprom(thermo11_t *ctx, uint8_t eeprom_addr, uint16_t eeprom_data)
EEPROM Program function.
thermo11_sw_reset
void thermo11_sw_reset(thermo11_t *ctx)
Software Reset Command.
THERMO11_RETVAL
#define THERMO11_RETVAL
Definition: thermo11.h:73
thermo11_read_reg
THERMO11_RETVAL thermo11_read_reg(thermo11_t *ctx, uint8_t reg_addr, uint16_t *data_out)
Repeated Read function.
thermo11_get_temp
float thermo11_get_temp(thermo11_t *ctx, uint8_t temp_addr)
Temperature Get function.
thermo11_t::slave_address
uint8_t slave_address
Definition: thermo11.h:188
thermo11_general_call_reset_cmd
void thermo11_general_call_reset_cmd(thermo11_t *ctx)
General Call Reset Command.
thermo11_cfg_t
Click configuration structure definition.
Definition: thermo11.h:196
thermo11_t
Click ctx object definition.
Definition: thermo11.h:177
thermo11_cfg_t::sda
pin_name_t sda
Definition: thermo11.h:200
thermo11_cfg_setup
void thermo11_cfg_setup(thermo11_cfg_t *cfg)
Config Object Initialization function.
thermo11_cfg_t::int_pin
pin_name_t int_pin
Definition: thermo11.h:204
thermo11_t::int_pin
digital_in_t int_pin
Definition: thermo11.h:180
thermo11_check_status
THERMO11_RETVAL thermo11_check_status(thermo11_t *ctx)
Status Check function.
thermo11_cfg_t::scl
pin_name_t scl
Definition: thermo11.h:199
thermo11_set_temp
THERMO11_RETVAL thermo11_set_temp(thermo11_t *ctx, uint8_t temp_addr, float temp_value)
Temperature Set function.
thermo11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo11.h:208
thermo11_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo11.h:209
thermo11_init
THERMO11_RETVAL thermo11_init(thermo11_t *ctx, thermo11_cfg_t *cfg)
Initialization function.
thermo11_get_int
THERMO11_RETVAL thermo11_get_int(thermo11_t *ctx)
INT Pin Check function.
thermo11_sm_bus_alert_cmd
uint8_t thermo11_sm_bus_alert_cmd(thermo11_t *ctx)
SMBus Alert Command.