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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define TEMPLOG3_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 TEMPLOG3_RETVAL uint8_t
63 
64 #define TEMPLOG3_OK 0x00
65 #define TEMPLOG3_INIT_ERROR 0xFF
66 
72 #define TEMPLOG3_SLAVE_ADDR_A0_H 0x19
73 #define TEMPLOG3_SLAVE_ADDR_A0_L 0x18
74 
80 #define TEMPLOG3_CAPABILITY_REG 0x00
81 #define TEMPLOG3_CONFIG_REG 0x01
82 #define TEMPLOG3_TEMP_UPPER_REG 0x02
83 #define TEMPLOG3_TEMP_LOWER_REG 0x03
84 #define TEMPLOG3_TEMP_CRITICAL_REG 0x04
85 #define TEMPLOG3_TEMP_AMBIENT_REG 0x05
86 #define TEMPLOG3_MANUFACT_ID_REG 0x06
87 #define TEMPLOG3_DEVICE_ID_REG 0x07
88 #define TEMPLOG3_RESOLUTION_REG 0x08
89 
95 #define TEMPLOG3_EVENT_SHDN_STATUS_MASK 0x80
96 #define TEMPLOG3_I2C_TIMEOUT_STATUS_MASK 0x40
97 #define TEMPLOG3_HIGH_VOLT_INPUT_STATUS_MASK 0x20
98 #define TEMPLOG3_RESOLUTION_STATUS_MASK 0x18
99 #define TEMPLOG3_MEAS_RANGE_STATUS_MASK 0x04
100 #define TEMPLOG3_ACCURACY_STATUS_MASK 0x02
101 #define TEMPLOG3_ALARM_STATUS_MASK 0x01
102 
108 #define TEMPLOG3_TLIMIT_HYST_0_DEG 0x0000
109 #define TEMPLOG3_TLIMIT_HYST_ONE_HALF_DEG 0x0200
110 #define TEMPLOG3_TLIMIT_HYST_3_DEG 0x0400
111 #define TEMPLOG3_TLIMIT_HYST_6_DEG 0x0600
112 #define TEMPLOG3_CONT_CONV_MODE 0x0000
113 #define TEMPLOG3_SHUTDOWN_MODE 0x0100
114 #define TEMPLOG3_TCRIT_LOCKED 0x0080
115 #define TEMPLOG3_TUPPER_TLOWER_LOCKED 0x0040
116 #define TEMPLOG3_INT_CLEAR 0x0020
117 #define TEMPLOG3_EVENT_OUTPUT_STATUS_MASK 0x0010
118 #define TEMPLOG3_EVENT_OUTPUT_EN 0x0008
119 #define TEMPLOG3_EVENT_ALL_TLIMIT 0x0000
120 #define TEMPLOG3_EVENT_TCRIT_ONLY 0x0004
121 #define TEMPLOG3_EVENT_POL_ACT_LOW 0x0000
122 #define TEMPLOG3_EVENT_POL_ACT_HIGH 0x0002
123 #define TEMPLOG3_EVENT_COMPARATOR_MODE 0x0000
124 #define TEMPLOG3_EVENT_INTERRUPT_MODE 0x0001
125 
131 #define TEMPLOG3_TCRIT_DETECT 0x80
132 #define TEMPLOG3_TUPPER_DETECT 0x40
133 #define TEMPLOG3_TLOWER_DETECT 0x20
134 #define TEMPLOG3_NBYTES_ERROR 0x04
135 #define TEMPLOG3_TEMP_RANGE_ERROR 0x03
136 #define TEMPLOG3_ADDR_ERROR 0x02
137 #define TEMPLOG3_ALARMING 0x01
138 #define TEMPLOG3_OK 0x00
139 
145 #define TEMPLOG3_12BIT_RESOLUTION 0x03
146 #define TEMPLOG3_11BIT_RESOLUTION 0x02
147 #define TEMPLOG3_10BIT_RESOLUTION 0x01
148 #define TEMPLOG3_9BIT_RESOLUTION 0x00
149 
155 #define TEMPLOG3_EEPROM_WRITE 0x00
156 #define TEMPLOG3_SW_WRITE_PROTECT 0x01
157 #define TEMPLOG3_CLEAR_WRITE_PROTECT 0x02
158 
164 #define TEMPLOG3_EEPROM_SIZE 256
165  // End group macro
168 // --------------------------------------------------------------- PUBLIC TYPES
177 typedef struct
178 {
179  // Input pins
180 
181  digital_in_t int_pin;
182 
183  // Modules
184 
185  i2c_master_t i2c;
186 
187  // ctx variable
188 
189  uint8_t slave_address;
190  uint8_t slave_eeprom;
191 
192  uint8_t resolution;
193  uint8_t n_bytes;
194 
195 } templog3_t;
196 
200 typedef struct
201 {
202  // Communication gpio pins
203 
204  pin_name_t scl;
205  pin_name_t sda;
206 
207  // Additional gpio pins
208 
209  pin_name_t int_pin;
210 
211  // static variable
212 
213  uint32_t i2c_speed;
214  uint8_t i2c_address;
215  uint8_t i2c_eeprom;
216 
217  uint8_t dev_resolution;
218  uint8_t dev_n_bytes;
219 
221  // End types group
223 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
224 
230 #ifdef __cplusplus
231 extern "C"{
232 #endif
233 
243 
253 
281 
293 uint8_t templog3_write_reg ( templog3_t *ctx, uint8_t reg_addr, uint16_t data_in );
294 
306 uint8_t templog3_read_reg ( templog3_t *ctx, uint8_t reg_addr, uint16_t *data_out );
307 
318 uint8_t templog3_set_addr_ptr ( templog3_t *ctx, uint8_t reg_addr );
319 
328 void templog3_repeated_read ( templog3_t *ctx, uint16_t *data_out );
329 
341 uint8_t templog3_get_temp ( templog3_t *ctx, uint8_t temp_sel, float *temp_out );
342 
354 uint8_t templog3_set_temp ( templog3_t *ctx, uint8_t temp_sel, float temp_in );
355 
366 
375 
386 void templog3_eeprom_byte_write ( templog3_t *ctx, uint8_t reg_addr, uint8_t data_in, uint8_t eeprom_mode );
387 
397 void templog3_eeprom_page_write ( templog3_t *ctx, uint8_t reg_addr, uint8_t *data_in );
398 
407 void templog3_eeprom_curr_addr_read ( templog3_t *ctx, uint8_t *current_address );
408 
418 void templog3_eeprom_byte_read ( templog3_t *ctx, uint8_t reg_addr, uint8_t *data_out );
419 
433 uint8_t templog3_eeprom_sequential_read ( templog3_t *ctx, uint8_t reg_addr, uint8_t *data_out, uint16_t num_bytes );
434 
435 
436 #ifdef __cplusplus
437 }
438 #endif
439 #endif // _TEMPLOG3_H_
440  // End public_function group
443 
444 // ------------------------------------------------------------------------- END
templog3_cfg_t
Click configuration structure definition.
Definition: templog3.h:201
templog3_read_reg
uint8_t templog3_read_reg(templog3_t *ctx, uint8_t reg_addr, uint16_t *data_out)
Generic Read function.
templog3_eeprom_sequential_read
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.
templog3_t::resolution
uint8_t resolution
Definition: templog3.h:192
templog3_eeprom_byte_read
void templog3_eeprom_byte_read(templog3_t *ctx, uint8_t reg_addr, uint8_t *data_out)
EEPROM Single Read function.
templog3_t::i2c
i2c_master_t i2c
Definition: templog3.h:185
templog3_cfg_t::int_pin
pin_name_t int_pin
Definition: templog3.h:209
templog3_t::slave_address
uint8_t slave_address
Definition: templog3.h:189
templog3_write_reg
uint8_t templog3_write_reg(templog3_t *ctx, uint8_t reg_addr, uint16_t data_in)
Generic Write function.
templog3_eeprom_byte_write
void templog3_eeprom_byte_write(templog3_t *ctx, uint8_t reg_addr, uint8_t data_in, uint8_t eeprom_mode)
EEPROM Single Write function.
templog3_default_cfg
void templog3_default_cfg(templog3_t *ctx)
Click Default Configuration function.
templog3_t::n_bytes
uint8_t n_bytes
Definition: templog3.h:193
templog3_t::slave_eeprom
uint8_t slave_eeprom
Definition: templog3.h:190
templog3_repeated_read
void templog3_repeated_read(templog3_t *ctx, uint16_t *data_out)
Repeated Read function.
TEMPLOG3_RETVAL
#define TEMPLOG3_RETVAL
Definition: templog3.h:62
templog3_cfg_t::i2c_eeprom
uint8_t i2c_eeprom
Definition: templog3.h:215
templog3_t::int_pin
digital_in_t int_pin
Definition: templog3.h:181
templog3_t
Click ctx object definition.
Definition: templog3.h:178
templog3_get_temp
uint8_t templog3_get_temp(templog3_t *ctx, uint8_t temp_sel, float *temp_out)
Get Temperature function.
templog3_set_temp
uint8_t templog3_set_temp(templog3_t *ctx, uint8_t temp_sel, float temp_in)
Set Temperature function.
templog3_set_addr_ptr
uint8_t templog3_set_addr_ptr(templog3_t *ctx, uint8_t reg_addr)
Set Address Pointer function.
templog3_eeprom_page_write
void templog3_eeprom_page_write(templog3_t *ctx, uint8_t reg_addr, uint8_t *data_in)
EEPROM Page Write function.
templog3_cfg_setup
void templog3_cfg_setup(templog3_cfg_t *cfg)
Config Object Initialization function.
templog3_cfg_t::sda
pin_name_t sda
Definition: templog3.h:205
templog3_wait_conv_done
void templog3_wait_conv_done(templog3_t *ctx)
Conversion Time function.
templog3_check_alarm
uint8_t templog3_check_alarm(templog3_t *ctx)
Alarm-Event Check function.
templog3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: templog3.h:213
templog3_cfg_t::dev_n_bytes
uint8_t dev_n_bytes
Definition: templog3.h:218
templog3_init
TEMPLOG3_RETVAL templog3_init(templog3_t *ctx, templog3_cfg_t *cfg)
Initialization function.
templog3_cfg_t::i2c_address
uint8_t i2c_address
Definition: templog3.h:214
templog3_cfg_t::scl
pin_name_t scl
Definition: templog3.h:204
templog3_eeprom_curr_addr_read
void templog3_eeprom_curr_addr_read(templog3_t *ctx, uint8_t *current_address)
EEPROM Current Address Read function.
templog3_cfg_t::dev_resolution
uint8_t dev_resolution
Definition: templog3.h:217