templog5  2.0.0.0
templog5.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 TEMPLOG5_H
36 #define TEMPLOG5_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 // -------------------------------------------------------------- PUBLIC MACROS
62 #define TEMPLOG5_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define TEMPLOG5_RETVAL uint8_t
73 
74 #define TEMPLOG5_OK 0x00
75 #define TEMPLOG5_INIT_ERROR 0xFF
76 
82 #define TEMPLOG5_REG_CAPABILITY 0x00
83 #define TEMPLOG5_REG_CONFIGURATION 0x01
84 #define TEMPLOG5_REG_HIGH_LIMIT 0x02
85 #define TEMPLOG5_REG_LOW_LIMIT 0x03
86 #define TEMPLOG5_REG_CRITICAL_LIMIT 0x04
87 #define TEMPLOG5_REG_TEMPERATURE 0x05
88 #define TEMPLOG5_REG_MANUFACTURER_ID 0x06
89 #define TEMPLOG5_REG_DEVICE_ID 0x07
90 
96 #define TEMPLOG5_CFG_DISABLE_HYSTERESIS 0x0000
97 #define TEMPLOG5_CFG_HYSTERESIS_TO_1p5C 0x0200
98 #define TEMPLOG5_CFG_HYSTERESIS_TO_3C 0x0400
99 #define TEMPLOG5_CFG_HYSTERESIS_TO_6C 0x0600
100 #define TEMPLOG5_CFG_TEMP_SENSOR_ENABLE 0x0000
101 #define TEMPLOG5_CFG_TEMP_SENSOR_DISABLE 0x0100
102 #define TEMPLOG5_CFG_CRITICAL_TRIP_ENABLE 0x0000
103 #define TEMPLOG5_CFG_CRITICAL_TRIP_DISABLE 0x0080
104 #define TEMPLOG5_CFG_ALARM_TRIP_ENABLE 0x0000
105 #define TEMPLOG5_CFG_ALARM_TRIP_DISABLE 0x0040
106 #define TEMPLOG5_CFG_EVENT_INT_PIN_ENABLE 0x0010
107 #define TEMPLOG5_CFG_EVENT_INT_PIN_DISABLE 0x0000
108 #define TEMPLOG5_CFG_EVENT_OUT_ENABLE 0x0008
109 #define TEMPLOG5_CFG_EVENT_OUT_DISABLE 0x0000
110 #define TEMPLOG5_CFG_EVENT_OUT_ACTIVE_LOW 0x0000
111 #define TEMPLOG5_CFG_EVENT_OUT_ACTIVE_HIGH 0x0002
112 #define TEMPLOG5_CFG_EVENT_MODE_COMPARATOR 0x0000
113 #define TEMPLOG5_CFG_EVENT_MODE_INTERRUPT 0x0001
114 
120 #define TEMPLOG5_CAP_EVSD_FROZEN 0x0000
121 #define TEMPLOG5_CAP_EVSD_CLEARD 0x0080
122 #define TEMPLOG5_CAP_TMOUT_10ms_60ms 0x0000
123 #define TEMPLOG5_CAP_TMOUT_25ms_35ms 0x0040
124 #define TEMPLOG5_CAP_RSWP_NOT_EXPLICITLY_STATED 0x0000
125 #define TEMPLOG5_CAP_RSWP_EXPLICITLY_STATED 0x0020
126 #define TEMPLOG5_CAP_TEMP_RES_9bit 0x0000
127 #define TEMPLOG5_CAP_TEMP_RES_10bit 0x0008
128 #define TEMPLOG5_CAP_TEMP_RES_11bit 0x0010
129 #define TEMPLOG5_CAP_TEMP_RES_12bit 0x0018
130 #define TEMPLOG5_CAP_POS_TEMP_ONLY 0x0000
131 #define TEMPLOG5_CAP_POS_AND_NEG_TEMP 0x0004
132 #define TEMPLOG5_CAP_ACC_CLASS_C 0x0000
133 #define TEMPLOG5_CAP_ACC_CLASS_B 0x0002
134 #define TEMPLOG5_CAP_EV_CRITICAL_TEMP_ONLY 0x0000
135 #define TEMPLOG5_CAP_EV_ALARM_AND_CRITICAL_TEMP 0x0001
136 
142 #define TEMPLOG5_TS_SLAVE_ADDR_000 0x18
143 #define TEMPLOG5_TS_SLAVE_ADDR_001 0x19
144 #define TEMPLOG5_TS_SLAVE_ADDR_010 0x1A
145 #define TEMPLOG5_TS_SLAVE_ADDR_011 0x1B
146 #define TEMPLOG5_TS_SLAVE_ADDR_100 0x1C
147 #define TEMPLOG5_TS_SLAVE_ADDR_101 0x1D
148 #define TEMPLOG5_TS_SLAVE_ADDR_110 0x1E
149 #define TEMPLOG5_TS_SLAVE_ADDR_111 0x1F
150 
156 #define TEMPLOG5_EEPROM_SLAVE_ADDR_000 0x50
157 #define TEMPLOG5_EEPROM_SLAVE_ADDR_001 0x51
158 #define TEMPLOG5_EEPROM_SLAVE_ADDR_010 0x52
159 #define TEMPLOG5_EEPROM_SLAVE_ADDR_011 0x53
160 #define TEMPLOG5_EEPROM_SLAVE_ADDR_100 0x54
161 #define TEMPLOG5_EEPROM_SLAVE_ADDR_101 0x55
162 #define TEMPLOG5_EEPROM_SLAVE_ADDR_110 0x56
163 #define TEMPLOG5_EEPROM_SLAVE_ADDR_111 0x57
164 
170 #define TEMPLOG5_MANUFACTURER_ID 0x1B09
171 #define TEMPLOG5_DEVICE_ID_REV_B 0x0813
172 #define TEMPLOG5_DEVICE_ID_REV_C 0x0A00
173  // End group macro
176 // --------------------------------------------------------------- PUBLIC TYPES
185 typedef struct
186 {
187  // Input pins
188 
189  digital_in_t int_pin;
190 
191  // Modules
192 
193  i2c_master_t i2c;
194 
195  // ctx variable
196 
197  uint8_t ts_slave;
198  uint8_t eeprom_slave;
199  uint8_t temp_status;
200 
201 } templog5_t;
202 
206 typedef struct
207 {
208  // Communication gpio pins
209 
210  pin_name_t scl;
211  pin_name_t sda;
212 
213  // Additional gpio pins
214 
215  pin_name_t int_pin;
216 
217  // static variable
218 
219  uint32_t i2c_speed;
220  uint8_t ts_slave;
221  uint8_t eeprom_slave;
222 
223 
225  // End types group
227 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
228 
234 #ifdef __cplusplus
235 extern "C"{
236 #endif
237 
247 
257 
280 
290 void templog5_write_data ( templog5_t *ctx, uint8_t reg, uint16_t data_in );
291 
304 void templog5_write_eeprom ( templog5_t *ctx, uint8_t start_addr, uint8_t *data_in, uint8_t n_byte );
305 
316 uint16_t templog5_read_data ( templog5_t *ctx, uint8_t reg );
317 
328 void templog5_read_eeprom ( templog5_t *ctx, uint8_t start_addr, uint8_t *data_out, uint8_t n_byte );
329 
340 
351 
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 #endif // _TEMPLOG5_H_
367  // End public_function group
370 
371 // ------------------------------------------------------------------------- END
templog5_get_interrupt_status
uint8_t templog5_get_interrupt_status(templog5_t *ctx)
EVENT Interrupt status.
templog5_cfg_t::sda
pin_name_t sda
Definition: templog5.h:211
templog5_init
TEMPLOG5_RETVAL templog5_init(templog5_t *ctx, templog5_cfg_t *cfg)
Initialization function.
templog5_cfg_t::ts_slave
uint8_t ts_slave
Definition: templog5.h:220
templog5_t::eeprom_slave
uint8_t eeprom_slave
Definition: templog5.h:198
templog5_t::i2c
i2c_master_t i2c
Definition: templog5.h:193
templog5_read_eeprom
void templog5_read_eeprom(templog5_t *ctx, uint8_t start_addr, uint8_t *data_out, uint8_t n_byte)
Reads data from EEPROM.
templog5_write_eeprom
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 ).
templog5_cfg_t::scl
pin_name_t scl
Definition: templog5.h:210
templog5_cfg_t::eeprom_slave
uint8_t eeprom_slave
Definition: templog5.h:221
templog5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: templog5.h:219
templog5_t::ts_slave
uint8_t ts_slave
Definition: templog5.h:197
templog5_default_cfg
void templog5_default_cfg(templog5_t *ctx)
Click Default Configuration function.
templog5_t::temp_status
uint8_t temp_status
Definition: templog5.h:199
TEMPLOG5_RETVAL
#define TEMPLOG5_RETVAL
Definition: templog5.h:72
templog5_t
Click ctx object definition.
Definition: templog5.h:186
templog5_write_data
void templog5_write_data(templog5_t *ctx, uint8_t reg, uint16_t data_in)
Functions for write data to the TS register.
templog5_get_temperature
float templog5_get_temperature(templog5_t *ctx)
Temperature Data.
templog5_cfg_t::int_pin
pin_name_t int_pin
Definition: templog5.h:215
templog5_cfg_setup
void templog5_cfg_setup(templog5_cfg_t *cfg)
Config Object Initialization function.
templog5_t::int_pin
digital_in_t int_pin
Definition: templog5.h:189
templog5_get_temperature_status
uint8_t templog5_get_temperature_status(templog5_t *ctx)
Teperature Status.
templog5_read_data
uint16_t templog5_read_data(templog5_t *ctx, uint8_t reg)
Functions for read data from registers.
templog5_cfg_t
Click configuration structure definition.
Definition: templog5.h:207