templog5  2.0.0.0
templog5.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 TEMPLOG5_H
36 #define TEMPLOG5_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 TEMPLOG5_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 TEMPLOG5_RETVAL uint8_t
64 
65 #define TEMPLOG5_OK 0x00
66 #define TEMPLOG5_INIT_ERROR 0xFF
67 
73 #define TEMPLOG5_REG_CAPABILITY 0x00
74 #define TEMPLOG5_REG_CONFIGURATION 0x01
75 #define TEMPLOG5_REG_HIGH_LIMIT 0x02
76 #define TEMPLOG5_REG_LOW_LIMIT 0x03
77 #define TEMPLOG5_REG_CRITICAL_LIMIT 0x04
78 #define TEMPLOG5_REG_TEMPERATURE 0x05
79 #define TEMPLOG5_REG_MANUFACTURER_ID 0x06
80 #define TEMPLOG5_REG_DEVICE_ID 0x07
81 
87 #define TEMPLOG5_CFG_DISABLE_HYSTERESIS 0x0000
88 #define TEMPLOG5_CFG_HYSTERESIS_TO_1p5C 0x0200
89 #define TEMPLOG5_CFG_HYSTERESIS_TO_3C 0x0400
90 #define TEMPLOG5_CFG_HYSTERESIS_TO_6C 0x0600
91 #define TEMPLOG5_CFG_TEMP_SENSOR_ENABLE 0x0000
92 #define TEMPLOG5_CFG_TEMP_SENSOR_DISABLE 0x0100
93 #define TEMPLOG5_CFG_CRITICAL_TRIP_ENABLE 0x0000
94 #define TEMPLOG5_CFG_CRITICAL_TRIP_DISABLE 0x0080
95 #define TEMPLOG5_CFG_ALARM_TRIP_ENABLE 0x0000
96 #define TEMPLOG5_CFG_ALARM_TRIP_DISABLE 0x0040
97 #define TEMPLOG5_CFG_EVENT_INT_PIN_ENABLE 0x0010
98 #define TEMPLOG5_CFG_EVENT_INT_PIN_DISABLE 0x0000
99 #define TEMPLOG5_CFG_EVENT_OUT_ENABLE 0x0008
100 #define TEMPLOG5_CFG_EVENT_OUT_DISABLE 0x0000
101 #define TEMPLOG5_CFG_EVENT_OUT_ACTIVE_LOW 0x0000
102 #define TEMPLOG5_CFG_EVENT_OUT_ACTIVE_HIGH 0x0002
103 #define TEMPLOG5_CFG_EVENT_MODE_COMPARATOR 0x0000
104 #define TEMPLOG5_CFG_EVENT_MODE_INTERRUPT 0x0001
105 
111 #define TEMPLOG5_CAP_EVSD_FROZEN 0x0000
112 #define TEMPLOG5_CAP_EVSD_CLEARD 0x0080
113 #define TEMPLOG5_CAP_TMOUT_10ms_60ms 0x0000
114 #define TEMPLOG5_CAP_TMOUT_25ms_35ms 0x0040
115 #define TEMPLOG5_CAP_RSWP_NOT_EXPLICITLY_STATED 0x0000
116 #define TEMPLOG5_CAP_RSWP_EXPLICITLY_STATED 0x0020
117 #define TEMPLOG5_CAP_TEMP_RES_9bit 0x0000
118 #define TEMPLOG5_CAP_TEMP_RES_10bit 0x0008
119 #define TEMPLOG5_CAP_TEMP_RES_11bit 0x0010
120 #define TEMPLOG5_CAP_TEMP_RES_12bit 0x0018
121 #define TEMPLOG5_CAP_POS_TEMP_ONLY 0x0000
122 #define TEMPLOG5_CAP_POS_AND_NEG_TEMP 0x0004
123 #define TEMPLOG5_CAP_ACC_CLASS_C 0x0000
124 #define TEMPLOG5_CAP_ACC_CLASS_B 0x0002
125 #define TEMPLOG5_CAP_EV_CRITICAL_TEMP_ONLY 0x0000
126 #define TEMPLOG5_CAP_EV_ALARM_AND_CRITICAL_TEMP 0x0001
127 
133 #define TEMPLOG5_TS_SLAVE_ADDR_000 0x18
134 #define TEMPLOG5_TS_SLAVE_ADDR_001 0x19
135 #define TEMPLOG5_TS_SLAVE_ADDR_010 0x1A
136 #define TEMPLOG5_TS_SLAVE_ADDR_011 0x1B
137 #define TEMPLOG5_TS_SLAVE_ADDR_100 0x1C
138 #define TEMPLOG5_TS_SLAVE_ADDR_101 0x1D
139 #define TEMPLOG5_TS_SLAVE_ADDR_110 0x1E
140 #define TEMPLOG5_TS_SLAVE_ADDR_111 0x1F
141 
147 #define TEMPLOG5_EEPROM_SLAVE_ADDR_000 0x50
148 #define TEMPLOG5_EEPROM_SLAVE_ADDR_001 0x51
149 #define TEMPLOG5_EEPROM_SLAVE_ADDR_010 0x52
150 #define TEMPLOG5_EEPROM_SLAVE_ADDR_011 0x53
151 #define TEMPLOG5_EEPROM_SLAVE_ADDR_100 0x54
152 #define TEMPLOG5_EEPROM_SLAVE_ADDR_101 0x55
153 #define TEMPLOG5_EEPROM_SLAVE_ADDR_110 0x56
154 #define TEMPLOG5_EEPROM_SLAVE_ADDR_111 0x57
155 
161 #define TEMPLOG5_MANUFACTURER_ID 0x1B09
162 #define TEMPLOG5_DEVICE_ID_REV_B 0x0813
163 #define TEMPLOG5_DEVICE_ID_REV_C 0x0A00
164  // End group macro
167 // --------------------------------------------------------------- PUBLIC TYPES
176 typedef struct
177 {
178  // Input pins
179 
180  digital_in_t int_pin;
181 
182  // Modules
183 
184  i2c_master_t i2c;
185 
186  // ctx variable
187 
188  uint8_t ts_slave;
189  uint8_t eeprom_slave;
190  uint8_t temp_status;
191 
192 } templog5_t;
193 
197 typedef struct
198 {
199  // Communication gpio pins
200 
201  pin_name_t scl;
202  pin_name_t sda;
203 
204  // Additional gpio pins
205 
206  pin_name_t int_pin;
207 
208  // static variable
209 
210  hal_i2c_speed_t i2c_speed;
211  uint8_t ts_slave;
212  uint8_t eeprom_slave;
213 
214 
216  // End types group
218 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
219 
225 #ifdef __cplusplus
226 extern "C"{
227 #endif
228 
237 void templog5_cfg_setup ( templog5_cfg_t *cfg );
238 
247 
269 void templog5_default_cfg ( templog5_t *ctx );
270 
280 void templog5_write_data ( templog5_t *ctx, uint8_t reg, uint16_t data_in );
281 
294 void templog5_write_eeprom ( templog5_t *ctx, uint8_t start_addr, uint8_t *data_in, uint8_t n_byte );
295 
306 uint16_t templog5_read_data ( templog5_t *ctx, uint8_t reg );
307 
318 void templog5_read_eeprom ( templog5_t *ctx, uint8_t start_addr, uint8_t *data_out, uint8_t n_byte );
319 
329 float templog5_get_temperature ( templog5_t *ctx );
330 
341 
352 
353 #ifdef __cplusplus
354 }
355 #endif
356 #endif // _TEMPLOG5_H_
357  // End public_function group
360 
361 // ------------------------------------------------------------------------- END
void templog5_write_eeprom(templog5_t *ctx, uint8_t start_addr, uint8_t *data_in, uint8_t n_byte)
Writes data to the EEPROM address ( maximum 16 bytes per 1 page ).
uint8_t eeprom_slave
Definition: templog5.h:189
pin_name_t sda
Definition: templog5.h:202
uint8_t ts_slave
Definition: templog5.h:211
digital_in_t int_pin
Definition: templog5.h:180
Click configuration structure definition.
Definition: templog5.h:197
uint8_t templog5_get_interrupt_status(templog5_t *ctx)
EVENT Interrupt status.
uint8_t temp_status
Definition: templog5.h:190
void templog5_default_cfg(templog5_t *ctx)
Click Default Configuration function.
void templog5_write_data(templog5_t *ctx, uint8_t reg, uint16_t data_in)
Functions for write data to the TS register.
i2c_master_t i2c
Definition: templog5.h:184
uint16_t templog5_read_data(templog5_t *ctx, uint8_t reg)
Functions for read data from registers.
uint8_t eeprom_slave
Definition: templog5.h:212
hal_i2c_speed_t i2c_speed
Definition: templog5.h:210
void templog5_read_eeprom(templog5_t *ctx, uint8_t start_addr, uint8_t *data_out, uint8_t n_byte)
Reads data from EEPROM.
#define TEMPLOG5_RETVAL
Definition: templog5.h:63
uint8_t templog5_get_temperature_status(templog5_t *ctx)
Teperature Status.
pin_name_t scl
Definition: templog5.h:201
pin_name_t int_pin
Definition: templog5.h:206
uint8_t ts_slave
Definition: templog5.h:188
float templog5_get_temperature(templog5_t *ctx)
Temperature Data.
TEMPLOG5_RETVAL templog5_init(templog5_t *ctx, templog5_cfg_t *cfg)
Initialization function.
void templog5_cfg_setup(templog5_cfg_t *cfg)
Config Object Initialization function.
Click ctx object definition.
Definition: templog5.h:176