templog3 2.0.0.0
templog3.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 TEMPLOG3_H
36#define TEMPLOG3_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define TEMPLOG3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define TEMPLOG3_RETVAL uint8_t
77
78#define TEMPLOG3_OK 0x00
79#define TEMPLOG3_INIT_ERROR 0xFF
86#define TEMPLOG3_SLAVE_ADDR_A0_H 0x19
87#define TEMPLOG3_SLAVE_ADDR_A0_L 0x18
94#define TEMPLOG3_CAPABILITY_REG 0x00
95#define TEMPLOG3_CONFIG_REG 0x01
96#define TEMPLOG3_TEMP_UPPER_REG 0x02
97#define TEMPLOG3_TEMP_LOWER_REG 0x03
98#define TEMPLOG3_TEMP_CRITICAL_REG 0x04
99#define TEMPLOG3_TEMP_AMBIENT_REG 0x05
100#define TEMPLOG3_MANUFACT_ID_REG 0x06
101#define TEMPLOG3_DEVICE_ID_REG 0x07
102#define TEMPLOG3_RESOLUTION_REG 0x08
109#define TEMPLOG3_EVENT_SHDN_STATUS_MASK 0x80
110#define TEMPLOG3_I2C_TIMEOUT_STATUS_MASK 0x40
111#define TEMPLOG3_HIGH_VOLT_INPUT_STATUS_MASK 0x20
112#define TEMPLOG3_RESOLUTION_STATUS_MASK 0x18
113#define TEMPLOG3_MEAS_RANGE_STATUS_MASK 0x04
114#define TEMPLOG3_ACCURACY_STATUS_MASK 0x02
115#define TEMPLOG3_ALARM_STATUS_MASK 0x01
122#define TEMPLOG3_TLIMIT_HYST_0_DEG 0x0000
123#define TEMPLOG3_TLIMIT_HYST_ONE_HALF_DEG 0x0200
124#define TEMPLOG3_TLIMIT_HYST_3_DEG 0x0400
125#define TEMPLOG3_TLIMIT_HYST_6_DEG 0x0600
126#define TEMPLOG3_CONT_CONV_MODE 0x0000
127#define TEMPLOG3_SHUTDOWN_MODE 0x0100
128#define TEMPLOG3_TCRIT_LOCKED 0x0080
129#define TEMPLOG3_TUPPER_TLOWER_LOCKED 0x0040
130#define TEMPLOG3_INT_CLEAR 0x0020
131#define TEMPLOG3_EVENT_OUTPUT_STATUS_MASK 0x0010
132#define TEMPLOG3_EVENT_OUTPUT_EN 0x0008
133#define TEMPLOG3_EVENT_ALL_TLIMIT 0x0000
134#define TEMPLOG3_EVENT_TCRIT_ONLY 0x0004
135#define TEMPLOG3_EVENT_POL_ACT_LOW 0x0000
136#define TEMPLOG3_EVENT_POL_ACT_HIGH 0x0002
137#define TEMPLOG3_EVENT_COMPARATOR_MODE 0x0000
138#define TEMPLOG3_EVENT_INTERRUPT_MODE 0x0001
145#define TEMPLOG3_TCRIT_DETECT 0x80
146#define TEMPLOG3_TUPPER_DETECT 0x40
147#define TEMPLOG3_TLOWER_DETECT 0x20
148#define TEMPLOG3_NBYTES_ERROR 0x04
149#define TEMPLOG3_TEMP_RANGE_ERROR 0x03
150#define TEMPLOG3_ADDR_ERROR 0x02
151#define TEMPLOG3_ALARMING 0x01
152#define TEMPLOG3_OK 0x00
159#define TEMPLOG3_12BIT_RESOLUTION 0x03
160#define TEMPLOG3_11BIT_RESOLUTION 0x02
161#define TEMPLOG3_10BIT_RESOLUTION 0x01
162#define TEMPLOG3_9BIT_RESOLUTION 0x00
169#define TEMPLOG3_EEPROM_WRITE 0x00
170#define TEMPLOG3_SW_WRITE_PROTECT 0x01
171#define TEMPLOG3_CLEAR_WRITE_PROTECT 0x02
178#define TEMPLOG3_EEPROM_SIZE 256
181 // End group macro
182// --------------------------------------------------------------- PUBLIC TYPES
191typedef struct
192{
193 // Input pins
194
195 digital_in_t int_pin;
196
197 // Modules
198
199 i2c_master_t i2c;
200
201 // ctx variable
202
205
206 uint8_t resolution;
207 uint8_t n_bytes;
208
209} templog3_t;
210
214typedef struct
215{
216 // Communication gpio pins
217
218 pin_name_t scl;
219 pin_name_t sda;
220
221 // Additional gpio pins
222
223 pin_name_t int_pin;
224
225 // static variable
226
227 uint32_t i2c_speed;
228 uint8_t i2c_address;
229 uint8_t i2c_eeprom;
230
232 uint8_t dev_n_bytes;
233
235
236 // End types group
237// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
238
244#ifdef __cplusplus
245extern "C"{
246#endif
247
257
267
295
307uint8_t templog3_write_reg ( templog3_t *ctx, uint8_t reg_addr, uint16_t data_in );
308
320uint8_t templog3_read_reg ( templog3_t *ctx, uint8_t reg_addr, uint16_t *data_out );
321
332uint8_t templog3_set_addr_ptr ( templog3_t *ctx, uint8_t reg_addr );
333
342void templog3_repeated_read ( templog3_t *ctx, uint16_t *data_out );
343
355uint8_t templog3_get_temp ( templog3_t *ctx, uint8_t temp_sel, float *temp_out );
356
368uint8_t templog3_set_temp ( templog3_t *ctx, uint8_t temp_sel, float temp_in );
369
380
389
400void templog3_eeprom_byte_write ( templog3_t *ctx, uint8_t reg_addr, uint8_t data_in, uint8_t eeprom_mode );
401
411void templog3_eeprom_page_write ( templog3_t *ctx, uint8_t reg_addr, uint8_t *data_in );
412
421void templog3_eeprom_curr_addr_read ( templog3_t *ctx, uint8_t *current_address );
422
432void templog3_eeprom_byte_read ( templog3_t *ctx, uint8_t reg_addr, uint8_t *data_out );
433
447uint8_t templog3_eeprom_sequential_read ( templog3_t *ctx, uint8_t reg_addr, uint8_t *data_out, uint16_t num_bytes );
448
449
450#ifdef __cplusplus
451}
452#endif
453#endif // _TEMPLOG3_H_
454
455 // End public_function group
457
458// ------------------------------------------------------------------------- END
#define TEMPLOG3_RETVAL
Definition templog3.h:76
void templog3_eeprom_byte_write(templog3_t *ctx, uint8_t reg_addr, uint8_t data_in, uint8_t eeprom_mode)
EEPROM Single Write function.
uint8_t templog3_get_temp(templog3_t *ctx, uint8_t temp_sel, float *temp_out)
Get Temperature function.
void templog3_default_cfg(templog3_t *ctx)
Click Default Configuration function.
uint8_t templog3_write_reg(templog3_t *ctx, uint8_t reg_addr, uint16_t data_in)
Generic Write function.
uint8_t templog3_check_alarm(templog3_t *ctx)
Alarm-Event Check function.
uint8_t templog3_read_reg(templog3_t *ctx, uint8_t reg_addr, uint16_t *data_out)
Generic Read function.
void templog3_repeated_read(templog3_t *ctx, uint16_t *data_out)
Repeated Read function.
TEMPLOG3_RETVAL templog3_init(templog3_t *ctx, templog3_cfg_t *cfg)
Initialization function.
uint8_t templog3_set_temp(templog3_t *ctx, uint8_t temp_sel, float temp_in)
Set Temperature function.
uint8_t templog3_eeprom_sequential_read(templog3_t *ctx, uint8_t reg_addr, uint8_t *data_out, uint16_t num_bytes)
EEPROM Sequential Read function.
void templog3_eeprom_page_write(templog3_t *ctx, uint8_t reg_addr, uint8_t *data_in)
EEPROM Page Write function.
void templog3_eeprom_curr_addr_read(templog3_t *ctx, uint8_t *current_address)
EEPROM Current Address Read function.
void templog3_cfg_setup(templog3_cfg_t *cfg)
Config Object Initialization function.
void templog3_eeprom_byte_read(templog3_t *ctx, uint8_t reg_addr, uint8_t *data_out)
EEPROM Single Read function.
uint8_t templog3_set_addr_ptr(templog3_t *ctx, uint8_t reg_addr)
Set Address Pointer function.
void templog3_wait_conv_done(templog3_t *ctx)
Conversion Time function.
Click configuration structure definition.
Definition templog3.h:215
uint8_t dev_resolution
Definition templog3.h:231
uint32_t i2c_speed
Definition templog3.h:227
pin_name_t scl
Definition templog3.h:218
pin_name_t int_pin
Definition templog3.h:223
pin_name_t sda
Definition templog3.h:219
uint8_t dev_n_bytes
Definition templog3.h:232
uint8_t i2c_eeprom
Definition templog3.h:229
uint8_t i2c_address
Definition templog3.h:228
Click ctx object definition.
Definition templog3.h:192
uint8_t resolution
Definition templog3.h:206
uint8_t slave_eeprom
Definition templog3.h:204
uint8_t n_bytes
Definition templog3.h:207
digital_in_t int_pin
Definition templog3.h:195
i2c_master_t i2c
Definition templog3.h:199
uint8_t slave_address
Definition templog3.h:203