templog6  2.0.0.0
templog6.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 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  uint8_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  uint32_t i2c_speed;
146  uint8_t i2c_address;
147 
149  // End variable group
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
171 
181 
190 
201 void templog6_generic_write ( templog6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
202 
213 void templog6_generic_read ( templog6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
214 
224 void templog6_write_byte ( templog6_t *ctx, uint8_t reg, uint8_t data_buf );
225 
234 uint8_t templog6_read_byte ( templog6_t *ctx, uint8_t reg );
235 
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 #endif // _TEMPLOG6_H_
249  // End public_function group
252 
253 // ------------------------------------------------------------------------- END
templog6_cfg_t::sda
pin_name_t sda
Definition: templog6.h:137
templog6_read_byte
uint8_t templog6_read_byte(templog6_t *ctx, uint8_t reg)
Read one byte function.
templog6_init
TEMPLOG6_RETVAL templog6_init(templog6_t *ctx, templog6_cfg_t *cfg)
Initialization function.
templog6_t::int_pin
digital_in_t int_pin
Definition: templog6.h:117
templog6_cfg_t::int_pin
pin_name_t int_pin
Definition: templog6.h:141
templog6_cfg_t::i2c_address
uint8_t i2c_address
Definition: templog6.h:146
templog6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: templog6.h:145
templog6_generic_read
void templog6_generic_read(templog6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
templog6_default_cfg
void templog6_default_cfg(templog6_t *ctx)
Click Default Configuration function.
templog6_write_byte
void templog6_write_byte(templog6_t *ctx, uint8_t reg, uint8_t data_buf)
Write one byte function.
templog6_generic_write
void templog6_generic_write(templog6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
templog6_t::i2c
i2c_master_t i2c
Definition: templog6.h:121
templog6_t
Click ctx object definition.
Definition: templog6.h:114
templog6_cfg_t
Click configuration structure definition.
Definition: templog6.h:133
templog6_t::slave_address
uint8_t slave_address
Definition: templog6.h:125
templog6_cfg_setup
void templog6_cfg_setup(templog6_cfg_t *cfg)
Config Object Initialization function.
TEMPLOG6_RETVAL
#define TEMPLOG6_RETVAL
Definition: templog6.h:61
templog6_cfg_t::scl
pin_name_t scl
Definition: templog6.h:136
templog6_get_interrupt
uint8_t templog6_get_interrupt(templog6_t *ctx)
Gets interrupt.