templog4  2.0.0.0
templog4.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 TEMPLOG4_H
36 #define TEMPLOG4_H
37 
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define TEMPLOG4_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
56 
62 #define TEMPLOG4_RETVAL uint8_t
63 
64 #define TEMPLOG4_OK 0x00
65 #define TEMPLOG4_INIT_ERROR 0xFF
66 
72 #define TEMPLOG4_SLAVE_ADDR_A0_H 0x19
73 #define TEMPLOG4_SLAVE_ADDR_A0_L 0x18
74 
80 #define TEMPLOG4_CAPABILITY_REG 0x00
81 #define TEMPLOG4_CONFIG_REG 0x01
82 #define TEMPLOG4_TEMP_UPPER_REG 0x02
83 #define TEMPLOG4_TEMP_LOWER_REG 0x03
84 #define TEMPLOG4_TEMP_CRITICAL_REG 0x04
85 #define TEMPLOG4_TEMP_AMBIENT_REG 0x05
86 #define TEMPLOG4_MANUFACT_ID_REG 0x06
87 #define TEMPLOG4_DEVICE_ID_REG 0x07
88 #define TEMPLOG4_SMBUS_REG 0x22
89 
95 #define TEMPLOG4_EVENT_SHDN_STATUS_MASK 0x80
96 #define TEMPLOG4_BUS_TIMEOUT_STATUS_MASK 0x40
97 #define TEMPLOG4_HIGH_VOLT_INPUT_STATUS_MASK 0x20
98 #define TEMPLOG4_RESOLUTION_STATUS_MASK 0x18
99 #define TEMPLOG4_MEAS_RANGE_STATUS_MASK 0x04
100 #define TEMPLOG4_ACCURACY_STATUS_MASK 0x02
101 #define TEMPLOG4_ALARM_STATUS_MASK 0x01
102 
108 #define TEMPLOG4_TLIMIT_HYST_0_DEG 0x0000
109 #define TEMPLOG4_TLIMIT_HYST_ONE_HALF_DEG 0x0200
110 #define TEMPLOG4_TLIMIT_HYST_3_DEG 0x0400
111 #define TEMPLOG4_TLIMIT_HYST_6_DEG 0x0600
112 #define TEMPLOG4_CONT_CONV_MODE 0x0000
113 #define TEMPLOG4_SHUTDOWN_MODE 0x0100
114 #define TEMPLOG4_TCRIT_LOCKED 0x0080
115 #define TEMPLOG4_TUPPER_TLOWER_LOCKED 0x0040
116 #define TEMPLOG4_INT_CLEAR 0x0020
117 #define TEMPLOG4_EVENT_OUTPUT_STATUS_MASK 0x0010
118 #define TEMPLOG4_EVENT_OUTPUT_EN 0x0008
119 #define TEMPLOG4_EVENT_ALL_TLIMIT 0x0000
120 #define TEMPLOG4_EVENT_TCRIT_ONLY 0x0004
121 #define TEMPLOG4_EVENT_POL_ACT_LOW 0x0000
122 #define TEMPLOG4_EVENT_POL_ACT_HIGH 0x0002
123 #define TEMPLOG4_EVENT_COMPARATOR_MODE 0x0000
124 #define TEMPLOG4_EVENT_INTERRUPT_MODE 0x0001
125 
131 #define TEMPLOG4_TCRIT_DETECT 0x80
132 #define TEMPLOG4_TUPPER_DETECT 0x40
133 #define TEMPLOG4_TLOWER_DETECT 0x20
134 #define TEMPLOG4_NBYTES_ERROR 0x04
135 #define TEMPLOG4_TEMP_RANGE_ERROR 0x03
136 #define TEMPLOG4_ADDR_ERROR 0x02
137 #define TEMPLOG4_ALARMING 0x01
138 #define TEMPLOG4_OK 0x00
139 
145 #define TEMPLOG4_SMBUS_TIMEOUT_DIS 0x80
146 #define TEMPLOG4_SMBUS_TIMEOUT_SHTDN_EN 0x20
147 #define TEMPLOG4_SMBUS_ARA_DIS 0x01
148 
154 #define TEMPLOG4_EEPROM_WRITE 0x00
155 #define TEMPLOG4_SW_WRITE_PROTECT 0x01
156 #define TEMPLOG4_CLEAR_WRITE_PROTECT 0x02
157 
163 #define _TEMPLOG4_EEPROM_SIZE 256
164 #define _TEMPLOG4_MANUFACT_ID 0x1131
165 #define _TEMPLOG4_DEVICE_ID 0xA203
166 #define TEMPLOG4_DUMMY_BYTE 0x00
167  // End group macro
170 // --------------------------------------------------------------- PUBLIC TYPES
179 typedef struct
180 {
181  // Input pins
182 
183  digital_in_t int_pin;
184 
185  // Modules
186 
187  i2c_master_t i2c;
188 
189  // ctx variable
190 
191  hal_i2c_address_t slave_address;
192  hal_i2c_address_t eeprom_address;
193 
194 } templog4_t;
195 
199 typedef struct
200 {
201  // Communication gpio pins
202 
203  pin_name_t scl;
204  pin_name_t sda;
205 
206  // Additional gpio pins
207 
208  pin_name_t int_pin;
209 
210  // static variable
211 
212  hal_i2c_speed_t i2c_speed;
213  hal_i2c_address_t i2c_address;
214  hal_i2c_address_t i2c_eeprom_address;
215 
217  // End types group
219 
220 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
221 
227 #ifdef __cplusplus
228 extern "C"{
229 #endif
230 
239 void templog4_cfg_setup ( templog4_cfg_t *cfg );
240 
249 
257 void templog4_default_cfg ( templog4_t *ctx );
258 
269 void templog4_generic_write ( templog4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
270 
282 void templog4_generic_read ( templog4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
283 
294 uint8_t templog4_write_reg ( templog4_t *ctx, uint8_t reg, uint16_t input_data );
295 
306 uint8_t templog4_read_reg ( templog4_t *ctx, uint8_t reg, uint16_t *out_var );
307 
317 void templog4_set_addr_ptr ( templog4_t *ctx, uint8_t addr );
318 
328 void templog4_repeated_read ( templog4_t *ctx, uint16_t *out_var );
329 
340 uint8_t templog4_get_temp ( templog4_t *ctx, uint8_t temp_sel, float *temp_out );
341 
352 void templog4_set_temp ( templog4_t *ctx, uint8_t temp_sel, float temp_in );
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 #endif // _TEMPLOG4_H_
358  // End public_function group
361 
362 // ------------------------------------------------------------------------- END
hal_i2c_address_t i2c_eeprom_address
Definition: templog4.h:214
uint8_t templog4_read_reg(templog4_t *ctx, uint8_t reg, uint16_t *out_var)
Generic Read function.
void templog4_set_addr_ptr(templog4_t *ctx, uint8_t addr)
Set Address Pointer function.
Click configuration structure definition.
Definition: templog4.h:199
void templog4_repeated_read(templog4_t *ctx, uint16_t *out_var)
Repeated Read function.
TEMPLOG4_RETVAL templog4_init(templog4_t *ctx, templog4_cfg_t *cfg)
Initialization function.
hal_i2c_address_t eeprom_address
Definition: templog4.h:192
hal_i2c_speed_t i2c_speed
Definition: templog4.h:212
void templog4_generic_write(templog4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
pin_name_t sda
Definition: templog4.h:204
pin_name_t scl
Definition: templog4.h:203
hal_i2c_address_t i2c_address
Definition: templog4.h:213
void templog4_default_cfg(templog4_t *ctx)
Click Default Configuration function.
void templog4_cfg_setup(templog4_cfg_t *cfg)
Config Object Initialization function.
void templog4_set_temp(templog4_t *ctx, uint8_t temp_sel, float temp_in)
Set Temperature function.
digital_in_t int_pin
Definition: templog4.h:183
uint8_t templog4_write_reg(templog4_t *ctx, uint8_t reg, uint16_t input_data)
Generic Write function.
uint8_t templog4_get_temp(templog4_t *ctx, uint8_t temp_sel, float *temp_out)
Get Temperature function.
hal_i2c_address_t slave_address
Definition: templog4.h:191
#define TEMPLOG4_RETVAL
Definition: templog4.h:62
pin_name_t int_pin
Definition: templog4.h:208
i2c_master_t i2c
Definition: templog4.h:187
void templog4_generic_read(templog4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
Click ctx object definition.
Definition: templog4.h:179