templog2  2.0.0.0
templog2.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 _TEMPLOG2_H_
36 #define _TEMPLOG2_H_
37 
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
57 #define _TEMPLOG2_TEMP_REG 0x00
58 #define _TEMPLOG2_CONFIG_REG 0x01
59 #define _TEMPLOG2_HIGH_LIMIT_REG 0x02
60 #define _TEMPLOG2_LOW_LIMIT_REG 0x03
61 #define _TEMPLOG2_EEPROM_UNLOCK_REG 0x04
62 #define _TEMPLOG2_EEPROM1_REG 0x05
63 #define _TEMPLOG2_EEPROM2_REG 0x06
64 #define _TEMPLOG2_EEPROM3_REG 0x07
65 #define _TEMPLOG2_EEPROM4_REG 0x08
66 #define _TEMPLOG2_ID_REG 0x0F
67 
73 #define _TEMPLOG2_15_MILISEC_0_AVG 0x00
74 #define _TEMPLOG2_125_MILISEC_0_AVG 0x0080
75 #define _TEMPLOG2_250_MILISEC_0_AVG 0x0100
76 #define _TEMPLOG2_500_MILISEC_0_AVG 0x0180
77 #define _TEMPLOG2_1_SEC_0_AVG 0x0200
78 #define _TEMPLOG2_4_SEC_0_AVG 0x0280
79 #define _TEMPLOG2_8_SEC_0_AVG 0x0300
80 #define _TEMPLOG2_16_SEC_0_AVG 0x0380
81 #define _TEMPLOG2_125_MILISEC_8_AVG 0x0020
82 #define _TEMPLOG2_250_MILISEC_8_AVG 0x0120
83 #define _TEMPLOG2_500_MILISEC_8_AVG 0x01A0
84 #define _TEMPLOG2_1_SEC_8_AVG 0x0220
85 #define _TEMPLOG2_4_SEC_8_AVG 0x02A0
86 #define _TEMPLOG2_8_SEC_8_AVG 0x0320
87 #define _TEMPLOG2_16_SEC_8_AVG 0x03A0
88 #define _TEMPLOG2_500_MILISEC_32_AVG 0x0040
89 #define _TEMPLOG2_1_SEC_32_AVG 0x0240
90 #define _TEMPLOG2_4_SEC_32_AVG 0x02C0
91 #define _TEMPLOG2_8_SEC_32_AVG 0x0340
92 #define _TEMPLOG2_16_SEC_32_AVG 0x03C0
93 #define _TEMPLOG2_1_SEC_64_AVG 0x0060
94 #define _TEMPLOG2_4_SEC_64_AVG 0x02E0
95 #define _TEMPLOG2_8_SEC_64_AVG 0x0360
96 #define _TEMPLOG2_16_SEC_64_AVG 0x03E0
97 #define _TEMPLOG2_POL_ACTIVE_LOW 0x00
98 #define _TEMPLOG2_POL_ACTIVE_HIGH 0x0008
99 #define _TEMPLOG2_PIN_ALERT_FLAGS 0x00
100 #define _TEMPLOG2_PIN_DATAREADY_FLAG 0x0004
101 
106 #define _TEMPLOG2_LOCK_EEPROM 0x00
107 #define _TEMPLOG2_UNLOCK_EEPROM 0x8000
108 
114 #define _TEMPLOG2_0_CELSIUS 0x00
115 #define _TEMPLOG2_1_CELSIUS_POS 0x0080
116 #define _TEMPLOG2_25_CELSIUS_POS 0x0C80
117 #define _TEMPLOG2_25_CELSIUS_NEG 0xF380
118 #define _TEMPLOG2_100_CELSIUS_POS 0x3200
119 #define _TEMPLOG2_256_CELSIUS_POS 0x7FFF
120 #define _TEMPLOG2_256_CELSIUS_NEG 0x8000
121 
127 #define _TEMPLOG2_CONT_CONV_OP_MODE 0x00
128 #define _TEMPLOG2_SHUTDOWN_OP_MODE 0x01
129 #define _TEMPLOG2_ONE_SHOT_OP_MODE 0x02
130 #define _TEMPLOG2_ALERT_MODE 0x00
131 #define _TEMPLOG2_THERM_MODE 0x01
132  // End settings group
135 
140 #define _TEMPLOG2_DATA_READY_MASK 0x01
141 #define _TEMPLOG2_LOW_LIMIT_MASK 0x02
142 #define _TEMPLOG2_HIGH_LIMIT_MASK 0x04
143 #define _TEMPLOG2_BUSY_MASK 0x4000
144  // End registers group
147 
157 #define _TEMPLOG2_OK 0x00
158 #define _TEMPLOG2_INVALID_ADDR 0xFF
159 #define _TEMPLOG2_INVALID_PARAM 0xFE
160 #define _TEMPLOG2_INIT_DRV_ERROR 0xFD
161 
167 #define TEMPLOG2_RETVAL uint8_t
168  // End error group
171 
176 #define TEMPLOG2_MAP_MIKROBUS( cfg, mikrobus ) \
177  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT ); \
178  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
179  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
180  // End macros group
183 // --------------------------------------------------------------- PUBLIC TYPES
192 typedef struct
193 {
194  // Click mikrobus DRV objects.
195  digital_in_t alt;
196  i2c_master_t i2c;
197 
198  // Used I2C slave address.
199  i2c_master_data_t slave_addr;
200 
201 } templog2_t;
202 
206 typedef struct
207 {
208  // Used mikrobus pins.
209  pin_name_t alt;
210  pin_name_t scl;
211  pin_name_t sda;
212 
217  bool addr_sel;
218 
220  // End types group
222 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
228 #ifdef __cplusplus
229 extern "C"{
230 #endif
231 
243 void
245 
259 
268 void
270 
283 templog2_write_reg( templog2_t *ctx, uint8_t reg_addr, uint16_t transfer_data );
284 
297 templog2_read_reg( templog2_t *ctx, uint8_t reg_addr, uint16_t *data_out );
298 
308 uint8_t
310 
321 digital_in_data_t
323 
333 float
335 
348 templog2_set_mode( templog2_t *ctx, uint8_t op_mode, uint8_t alert_mode );
349 
362 templog2_write_eeprom( templog2_t *ctx, uint8_t eeprom_addr, uint16_t data_in );
363 
372 void
373 templog2_reset( templog2_t *ctx );
374 
375 #ifdef __cplusplus
376 }
377 #endif
378 #endif // _TEMPLOG2_H_
379  // End public_function group
382 
383 // ------------------------------------------------------------------------ END
TEMPLOG2_RETVAL templog2_set_mode(templog2_t *ctx, uint8_t op_mode, uint8_t alert_mode)
Mode Setting function.
digital_in_t alt
Definition: templog2.h:195
Click configuration structure definition.
Definition: templog2.h:206
void templog2_cfg_setup(templog2_cfg_t *cfg)
Configuration Object Setup function.
TEMPLOG2_RETVAL templog2_write_eeprom(templog2_t *ctx, uint8_t eeprom_addr, uint16_t data_in)
EEPROM Writing function.
Click context object definition.
Definition: templog2.h:192
i2c_master_t i2c
Definition: templog2.h:196
TEMPLOG2_RETVAL templog2_read_reg(templog2_t *ctx, uint8_t reg_addr, uint16_t *data_out)
Read Register function.
void templog2_reset(templog2_t *ctx)
Reset function.
i2c_master_data_t slave_addr
Definition: templog2.h:199
TEMPLOG2_RETVAL templog2_write_reg(templog2_t *ctx, uint8_t reg_addr, uint16_t transfer_data)
Write Register function.
void templog2_default_config(templog2_t *ctx)
Click Default Configuration function.
bool addr_sel
Definition: templog2.h:217
pin_name_t alt
Definition: templog2.h:209
#define TEMPLOG2_RETVAL
Definition: templog2.h:167
uint8_t templog2_data_ready(templog2_t *ctx)
Data Ready function.
float templog2_read_temp(templog2_t *ctx)
Read Temperature function.
TEMPLOG2_RETVAL templog2_init(templog2_t *ctx, templog2_cfg_t *cfg)
Click Initialization function.
pin_name_t scl
Definition: templog2.h:210
digital_in_data_t templog2_check_alert(templog2_t *ctx)
Alert Checking function.
pin_name_t sda
Definition: templog2.h:211