templog4  2.0.0.0
templog4.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 TEMPLOG4_H
36 #define TEMPLOG4_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_in.h"
49 #include "drv_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define TEMPLOG4_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
65 
71 #define TEMPLOG4_RETVAL uint8_t
72 
73 #define TEMPLOG4_OK 0x00
74 #define TEMPLOG4_INIT_ERROR 0xFF
75 
81 #define TEMPLOG4_SLAVE_ADDR_A0_H 0x19
82 #define TEMPLOG4_SLAVE_ADDR_A0_L 0x18
83 
89 #define TEMPLOG4_CAPABILITY_REG 0x00
90 #define TEMPLOG4_CONFIG_REG 0x01
91 #define TEMPLOG4_TEMP_UPPER_REG 0x02
92 #define TEMPLOG4_TEMP_LOWER_REG 0x03
93 #define TEMPLOG4_TEMP_CRITICAL_REG 0x04
94 #define TEMPLOG4_TEMP_AMBIENT_REG 0x05
95 #define TEMPLOG4_MANUFACT_ID_REG 0x06
96 #define TEMPLOG4_DEVICE_ID_REG 0x07
97 #define TEMPLOG4_SMBUS_REG 0x22
98 
104 #define TEMPLOG4_EVENT_SHDN_STATUS_MASK 0x80
105 #define TEMPLOG4_BUS_TIMEOUT_STATUS_MASK 0x40
106 #define TEMPLOG4_HIGH_VOLT_INPUT_STATUS_MASK 0x20
107 #define TEMPLOG4_RESOLUTION_STATUS_MASK 0x18
108 #define TEMPLOG4_MEAS_RANGE_STATUS_MASK 0x04
109 #define TEMPLOG4_ACCURACY_STATUS_MASK 0x02
110 #define TEMPLOG4_ALARM_STATUS_MASK 0x01
111 
117 #define TEMPLOG4_TLIMIT_HYST_0_DEG 0x0000
118 #define TEMPLOG4_TLIMIT_HYST_ONE_HALF_DEG 0x0200
119 #define TEMPLOG4_TLIMIT_HYST_3_DEG 0x0400
120 #define TEMPLOG4_TLIMIT_HYST_6_DEG 0x0600
121 #define TEMPLOG4_CONT_CONV_MODE 0x0000
122 #define TEMPLOG4_SHUTDOWN_MODE 0x0100
123 #define TEMPLOG4_TCRIT_LOCKED 0x0080
124 #define TEMPLOG4_TUPPER_TLOWER_LOCKED 0x0040
125 #define TEMPLOG4_INT_CLEAR 0x0020
126 #define TEMPLOG4_EVENT_OUTPUT_STATUS_MASK 0x0010
127 #define TEMPLOG4_EVENT_OUTPUT_EN 0x0008
128 #define TEMPLOG4_EVENT_ALL_TLIMIT 0x0000
129 #define TEMPLOG4_EVENT_TCRIT_ONLY 0x0004
130 #define TEMPLOG4_EVENT_POL_ACT_LOW 0x0000
131 #define TEMPLOG4_EVENT_POL_ACT_HIGH 0x0002
132 #define TEMPLOG4_EVENT_COMPARATOR_MODE 0x0000
133 #define TEMPLOG4_EVENT_INTERRUPT_MODE 0x0001
134 
140 #define TEMPLOG4_TCRIT_DETECT 0x80
141 #define TEMPLOG4_TUPPER_DETECT 0x40
142 #define TEMPLOG4_TLOWER_DETECT 0x20
143 #define TEMPLOG4_NBYTES_ERROR 0x04
144 #define TEMPLOG4_TEMP_RANGE_ERROR 0x03
145 #define TEMPLOG4_ADDR_ERROR 0x02
146 #define TEMPLOG4_ALARMING 0x01
147 #define TEMPLOG4_OK 0x00
148 
154 #define TEMPLOG4_SMBUS_TIMEOUT_DIS 0x80
155 #define TEMPLOG4_SMBUS_TIMEOUT_SHTDN_EN 0x20
156 #define TEMPLOG4_SMBUS_ARA_DIS 0x01
157 
163 #define TEMPLOG4_EEPROM_WRITE 0x00
164 #define TEMPLOG4_SW_WRITE_PROTECT 0x01
165 #define TEMPLOG4_CLEAR_WRITE_PROTECT 0x02
166 
172 #define _TEMPLOG4_EEPROM_SIZE 256
173 #define _TEMPLOG4_MANUFACT_ID 0x1131
174 #define _TEMPLOG4_DEVICE_ID 0xA203
175 #define TEMPLOG4_DUMMY_BYTE 0x00
176  // End group macro
179 // --------------------------------------------------------------- PUBLIC TYPES
188 typedef struct
189 {
190  // Input pins
191 
192  digital_in_t int_pin;
193 
194  // Modules
195 
196  i2c_master_t i2c;
197 
198  // ctx variable
199 
200  uint8_t slave_address;
201 
202 } templog4_t;
203 
207 typedef struct
208 {
209  // Communication gpio pins
210 
211  pin_name_t scl;
212  pin_name_t sda;
213 
214  // Additional gpio pins
215 
216  pin_name_t int_pin;
217 
218  // static variable
219 
220  uint32_t i2c_speed;
221  uint8_t i2c_address;
223 
225  // End types group
227 
228 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
229 
235 #ifdef __cplusplus
236 extern "C"{
237 #endif
238 
248 
258 
267 
278 void templog4_generic_write ( templog4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
279 
290 void templog4_generic_read ( templog4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
291 
301 uint8_t templog4_write_reg ( templog4_t *ctx, uint8_t reg, uint16_t input_data );
302 
312 uint8_t templog4_read_reg ( templog4_t *ctx, uint8_t reg, uint16_t *out_var );
313 
322 void templog4_set_addr_ptr ( templog4_t *ctx, uint8_t addr );
323 
332 void templog4_repeated_read ( templog4_t *ctx, uint16_t *out_var );
333 
343 uint8_t templog4_get_temp ( templog4_t *ctx, uint8_t temp_sel, float *temp_out );
344 
354 void templog4_set_temp ( templog4_t *ctx, uint8_t temp_sel, float temp_in );
355 
356 #ifdef __cplusplus
357 }
358 #endif
359 #endif // _TEMPLOG4_H_
360  // End public_function group
363 
364 // ------------------------------------------------------------------------- END
templog4_cfg_t
Click configuration structure definition.
Definition: templog4.h:208
templog4_init
TEMPLOG4_RETVAL templog4_init(templog4_t *ctx, templog4_cfg_t *cfg)
Initialization function.
templog4_cfg_t::i2c_address
uint8_t i2c_address
Definition: templog4.h:221
templog4_set_temp
void templog4_set_temp(templog4_t *ctx, uint8_t temp_sel, float temp_in)
Set Temperature function.
templog4_default_cfg
void templog4_default_cfg(templog4_t *ctx)
Click Default Configuration function.
templog4_cfg_t::scl
pin_name_t scl
Definition: templog4.h:211
templog4_t::int_pin
digital_in_t int_pin
Definition: templog4.h:192
templog4_generic_write
void templog4_generic_write(templog4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
templog4_read_reg
uint8_t templog4_read_reg(templog4_t *ctx, uint8_t reg, uint16_t *out_var)
Generic Read function.
templog4_cfg_setup
void templog4_cfg_setup(templog4_cfg_t *cfg)
Config Object Initialization function.
templog4_cfg_t::sda
pin_name_t sda
Definition: templog4.h:212
templog4_repeated_read
void templog4_repeated_read(templog4_t *ctx, uint16_t *out_var)
Repeated Read function.
templog4_generic_read
void templog4_generic_read(templog4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
templog4_set_addr_ptr
void templog4_set_addr_ptr(templog4_t *ctx, uint8_t addr)
Set Address Pointer function.
TEMPLOG4_RETVAL
#define TEMPLOG4_RETVAL
Definition: templog4.h:71
templog4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: templog4.h:220
templog4_t::slave_address
uint8_t slave_address
Definition: templog4.h:200
templog4_get_temp
uint8_t templog4_get_temp(templog4_t *ctx, uint8_t temp_sel, float *temp_out)
Get Temperature function.
templog4_t
Click ctx object definition.
Definition: templog4.h:189
templog4_write_reg
uint8_t templog4_write_reg(templog4_t *ctx, uint8_t reg, uint16_t input_data)
Generic Write function.
templog4_t::i2c
i2c_master_t i2c
Definition: templog4.h:196
templog4_cfg_t::int_pin
pin_name_t int_pin
Definition: templog4.h:216
templog4_cfg_t::i2c_eeprom_address
uint8_t i2c_eeprom_address
Definition: templog4.h:222