templog6  2.0.0.0
templog6.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 TEMPLOG6_H
36 #define TEMPLOG6_H
37 
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define TEMPLOG6_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
55 
61 #define TEMPLOG6_RETVAL uint8_t
62 
63 #define TEMPLOG6_OK 0x00
64 #define TEMPLOG6_INIT_ERROR 0xFF
65 
71 #define TEMPLOG6_REG_LOCAL_TEMPERATURE 0x00
72 #define TEMPLOG6_REG_REMOTE_TEMPERATURE 0x01
73 #define TEMPLOG6_REG_STATUS 0x02
74 #define TEMPLOG6_REG_RD_CONFIGURATION 0x03
75 #define TEMPLOG6_REG_RD_LOCAL_HIGH_LIMIT 0x05
76 #define TEMPLOG6_REG_RD_REMOTE_HIGH_LIMIT 0x07
77 #define TEMPLOG6_REG_WR_CONFIGURATION 0x09
78 #define TEMPLOG6_REG_WR_LOCAL_HIGH_LIMIT 0x0B
79 #define TEMPLOG6_REG_WR_REMOTE_HIGH_LIMIT 0x0D
80 #define TEMPLOG6_REG_SINGLE_SHOT 0x0F
81 #define TEMPLOG6_REG_REMOTE_EXTENDED_TEMP 0x10
82 #define TEMPLOG6_REG_INTERNAL_EXTENDED_TEMP 0x11
83 #define TEMPLOG6_REG_MANUFACTURER_ID 0xFE
84 
90 #define TEMPLOG6_CFG_ALERT_OFF 0x80
91 #define TEMPLOG6_CFG_ALERT_ON 0x00
92 #define TEMPLOG6_CFG_STANDBY_MODE 0x40
93 #define TEMPLOG6_CFG_NORMAL_MODE 0x00
94 #define TEMPLOG6_CFG_LOCAL_MEASUREMENT_OFF 0x20
95 #define TEMPLOG6_CFG_LOCAL_MEASUREMENT_ON 0x00
96 #define TEMPLOG6_CFG_ALERT_1_FAULT 0x00
97 #define TEMPLOG6_CFG_ALERT_2_FAULT 0x10
98 
99 #define TEMPLOG6_DEVICE_SLAVE_ADDRESS 0x4A
100 #define TEMPLOG6_MANUFACTURER_ID 0x4D
101  // End group macro
104 // --------------------------------------------------------------- PUBLIC TYPES
113 typedef struct
114 {
115  // Input pins
116 
117  digital_in_t int_pin;
118 
119  // Modules
120 
121  i2c_master_t i2c;
122 
123  // ctx variable
124 
125  hal_i2c_address_t slave_address;
126 
127 } templog6_t;
128 
132 typedef struct
133 {
134  // Communication gpio pins
135 
136  pin_name_t scl;
137  pin_name_t sda;
138 
139  // Additional gpio pins
140 
141  pin_name_t int_pin;
142 
143  // static variable
144 
145  hal_i2c_speed_t i2c_speed;
146  hal_i2c_address_t i2c_address;
147 
149  // End variable group
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
170 void templog6_cfg_setup ( templog6_cfg_t *cfg );
171 
180 
188 void templog6_default_cfg ( templog6_t *ctx );
189 
200 void templog6_generic_write ( templog6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
201 
212 void templog6_generic_read ( templog6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
213 
223 void templog6_write_byte ( templog6_t *ctx, uint8_t reg, uint8_t data_buf );
224 
233 uint8_t templog6_read_byte ( templog6_t *ctx, uint8_t reg );
234 
242 uint8_t templog6_get_interrupt ( templog6_t *ctx );
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 #endif // _TEMPLOG6_H_
248  // End public_function group
251 
252 // ------------------------------------------------------------------------- END
pin_name_t scl
Definition: templog6.h:136
pin_name_t int_pin
Definition: templog6.h:141
void templog6_generic_write(templog6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
pin_name_t sda
Definition: templog6.h:137
void templog6_write_byte(templog6_t *ctx, uint8_t reg, uint8_t data_buf)
Write one byte function.
hal_i2c_speed_t i2c_speed
Definition: templog6.h:145
TEMPLOG6_RETVAL templog6_init(templog6_t *ctx, templog6_cfg_t *cfg)
Initialization function.
digital_in_t int_pin
Definition: templog6.h:117
hal_i2c_address_t i2c_address
Definition: templog6.h:146
void templog6_default_cfg(templog6_t *ctx)
Click Default Configuration function.
i2c_master_t i2c
Definition: templog6.h:121
hal_i2c_address_t slave_address
Definition: templog6.h:125
uint8_t templog6_get_interrupt(templog6_t *ctx)
Gets interrupt.
uint8_t templog6_read_byte(templog6_t *ctx, uint8_t reg)
Read one byte function.
void templog6_cfg_setup(templog6_cfg_t *cfg)
Config Object Initialization function.
void templog6_generic_read(templog6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
Click configuration structure definition.
Definition: templog6.h:132
Click ctx object definition.
Definition: templog6.h:113
#define TEMPLOG6_RETVAL
Definition: templog6.h:61