templog2  2.0.0.0
templog2.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 _TEMPLOG2_H_
36 #define _TEMPLOG2_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
70 #define TEMPLOG2_TEMP_REG 0x00
71 #define TEMPLOG2_CONFIG_REG 0x01
72 #define TEMPLOG2_HIGH_LIMIT_REG 0x02
73 #define TEMPLOG2_LOW_LIMIT_REG 0x03
74 #define TEMPLOG2_EEPROM_UNLOCK_REG 0x04
75 #define TEMPLOG2_EEPROM1_REG 0x05
76 #define TEMPLOG2_EEPROM2_REG 0x06
77 #define TEMPLOG2_EEPROM3_REG 0x07
78 #define TEMPLOG2_EEPROM4_REG 0x08
79 #define TEMPLOG2_ID_REG 0x0F
80 
86 #define TEMPLOG2_15_MILISEC_0_AVG 0x00
87 #define TEMPLOG2_125_MILISEC_0_AVG 0x0080
88 #define TEMPLOG2_250_MILISEC_0_AVG 0x0100
89 #define TEMPLOG2_500_MILISEC_0_AVG 0x0180
90 #define TEMPLOG2_1_SEC_0_AVG 0x0200
91 #define TEMPLOG2_4_SEC_0_AVG 0x0280
92 #define TEMPLOG2_8_SEC_0_AVG 0x0300
93 #define TEMPLOG2_16_SEC_0_AVG 0x0380
94 #define TEMPLOG2_125_MILISEC_8_AVG 0x0020
95 #define TEMPLOG2_250_MILISEC_8_AVG 0x0120
96 #define TEMPLOG2_500_MILISEC_8_AVG 0x01A0
97 #define TEMPLOG2_1_SEC_8_AVG 0x0220
98 #define TEMPLOG2_4_SEC_8_AVG 0x02A0
99 #define TEMPLOG2_8_SEC_8_AVG 0x0320
100 #define TEMPLOG2_16_SEC_8_AVG 0x03A0
101 #define TEMPLOG2_500_MILISEC_32_AVG 0x0040
102 #define TEMPLOG2_1_SEC_32_AVG 0x0240
103 #define TEMPLOG2_4_SEC_32_AVG 0x02C0
104 #define TEMPLOG2_8_SEC_32_AVG 0x0340
105 #define TEMPLOG2_16_SEC_32_AVG 0x03C0
106 #define TEMPLOG2_1_SEC_64_AVG 0x0060
107 #define TEMPLOG2_4_SEC_64_AVG 0x02E0
108 #define TEMPLOG2_8_SEC_64_AVG 0x0360
109 #define TEMPLOG2_16_SEC_64_AVG 0x03E0
110 #define TEMPLOG2_POL_ACTIVE_LOW 0x00
111 #define TEMPLOG2_POL_ACTIVE_HIGH 0x0008
112 #define TEMPLOG2_PIN_ALERT_FLAGS 0x00
113 #define TEMPLOG2_PIN_DATAREADY_FLAG 0x0004
114 
119 #define TEMPLOG2_LOCK_EEPROM 0x00
120 #define TEMPLOG2_UNLOCK_EEPROM 0x8000
121 
127 #define TEMPLOG2_0_CELSIUS 0x00
128 #define TEMPLOG2_1_CELSIUS_POS 0x0080
129 #define TEMPLOG2_25_CELSIUS_POS 0x0C80
130 #define TEMPLOG2_25_CELSIUS_NEG 0xF380
131 #define TEMPLOG2_100_CELSIUS_POS 0x3200
132 #define TEMPLOG2_256_CELSIUS_POS 0x7FFF
133 #define TEMPLOG2_256_CELSIUS_NEG 0x8000
134 
140 #define TEMPLOG2_CONT_CONV_OP_MODE 0x00
141 #define TEMPLOG2_SHUTDOWN_OP_MODE 0x01
142 #define TEMPLOG2_ONE_SHOT_OP_MODE 0x02
143 #define TEMPLOG2_ALERT_MODE 0x00
144 #define TEMPLOG2_THERM_MODE 0x01
145  // End settings group
148 
153 #define TEMPLOG2_DATA_READY_MASK 0x01
154 #define TEMPLOG2_LOW_LIMIT_MASK 0x02
155 #define TEMPLOG2_HIGH_LIMIT_MASK 0x04
156 #define TEMPLOG2_BUSY_MASK 0x4000
157  // End registers group
160 
170 #define TEMPLOG2_OK 0x00
171 #define TEMPLOG2_INVALID_ADDR 0xFF
172 #define TEMPLOG2_INVALID_PARAM 0xFE
173 #define TEMPLOG2_INIT_DRV_ERROR 0xFD
174 
180 #define TEMPLOG2_RETVAL uint8_t
181  // End error group
184 
189 #define TEMPLOG2_MAP_MIKROBUS( cfg, mikrobus ) \
190  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT ); \
191  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
192  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
193  // End macros group
196 // --------------------------------------------------------------- PUBLIC TYPES
205 typedef struct
206 {
207  // Click mikrobus DRV objects.
208  digital_in_t alt;
209  i2c_master_t i2c;
210 
211  // Used I2C slave address.
212  uint8_t slave_addr;
213 
214 } templog2_t;
215 
219 typedef struct
220 {
221  // Used mikrobus pins.
222  pin_name_t alt;
223  pin_name_t scl;
224  pin_name_t sda;
225 
230  bool addr_sel;
231  uint32_t i2c_speed;
232 
234  // End types group
236 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
242 #ifdef __cplusplus
243 extern "C"{
244 #endif
245 
257 void
259 
273 
282 void
284 
297 templog2_write_reg( templog2_t *ctx, uint8_t reg_addr, uint16_t transfer_data );
298 
311 templog2_read_reg( templog2_t *ctx, uint8_t reg_addr, uint16_t *data_out );
312 
322 uint8_t
324 
335 uint8_t
337 
347 float
349 
362 templog2_set_mode( templog2_t *ctx, uint8_t op_mode, uint8_t alert_mode );
363 
376 templog2_write_eeprom( templog2_t *ctx, uint8_t eeprom_addr, uint16_t data_in );
377 
386 void
388 
389 #ifdef __cplusplus
390 }
391 #endif
392 #endif // _TEMPLOG2_H_
393  // End public_function group
396 
397 // ------------------------------------------------------------------------ END
templog2_reset
void templog2_reset(templog2_t *ctx)
Reset function.
templog2_default_config
void templog2_default_config(templog2_t *ctx)
Click Default Configuration function.
templog2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: templog2.h:231
templog2_t::i2c
i2c_master_t i2c
Definition: templog2.h:209
templog2_t::alt
digital_in_t alt
Definition: templog2.h:208
templog2_read_temp
float templog2_read_temp(templog2_t *ctx)
Read Temperature function.
templog2_write_eeprom
TEMPLOG2_RETVAL templog2_write_eeprom(templog2_t *ctx, uint8_t eeprom_addr, uint16_t data_in)
EEPROM Writing function.
templog2_init
TEMPLOG2_RETVAL templog2_init(templog2_t *ctx, templog2_cfg_t *cfg)
Click Initialization function.
templog2_check_alert
uint8_t templog2_check_alert(templog2_t *ctx)
Alert Checking function.
TEMPLOG2_RETVAL
#define TEMPLOG2_RETVAL
Definition: templog2.h:180
templog2_cfg_t::alt
pin_name_t alt
Definition: templog2.h:222
templog2_cfg_setup
void templog2_cfg_setup(templog2_cfg_t *cfg)
Configuration Object Setup function.
templog2_write_reg
TEMPLOG2_RETVAL templog2_write_reg(templog2_t *ctx, uint8_t reg_addr, uint16_t transfer_data)
Write Register function.
templog2_t::slave_addr
uint8_t slave_addr
Definition: templog2.h:212
templog2_cfg_t::scl
pin_name_t scl
Definition: templog2.h:223
templog2_cfg_t::addr_sel
bool addr_sel
Definition: templog2.h:230
templog2_read_reg
TEMPLOG2_RETVAL templog2_read_reg(templog2_t *ctx, uint8_t reg_addr, uint16_t *data_out)
Read Register function.
templog2_cfg_t::sda
pin_name_t sda
Definition: templog2.h:224
templog2_set_mode
TEMPLOG2_RETVAL templog2_set_mode(templog2_t *ctx, uint8_t op_mode, uint8_t alert_mode)
Mode Setting function.
templog2_data_ready
uint8_t templog2_data_ready(templog2_t *ctx)
Data Ready function.
templog2_t
Click context object definition.
Definition: templog2.h:206
templog2_cfg_t
Click configuration structure definition.
Definition: templog2.h:220