templog  2.0.0.0
templog.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 TEMPLOG_H
36 #define TEMPLOG_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
57 
62 #define TEMPLOG_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define TEMPLOG_RETVAL uint8_t
73 
74 #define TEMPLOG_OK 0x00
75 #define TEMPLOG_INIT_ERROR 0xFF
76 
82 #define TEMP_LOG_TEMPERATURE 0x00
83 #define TEMP_LOG_CONFIGURATION 0x01
84 #define TEMP_LOG_TLOW_LIMIT 0x02
85 #define TEMP_LOG_THIGH_LIMIT 0x03
86 #define TEMP_LOG_CONFIGURATION_NONVOL 0x11
87 #define TEMP_LOG_TLOW_LIMIT_NONVOL 0x12
88 #define TEMP_LOG_THIGH_LIMIT_NONVOL 0x13
89 #define TEMP_LOG_SLAVE_ADDRESS 0x48
90 #define TEMP_LOG_8_BITS_DATA 0x01
91 #define TEMP_LOG_16_BITS_DATA 0x00
92 #define TEMP_LOG_RESOLUTION_9_BITS 0x0000
93 #define TEMP_LOG_RESOLUTION_10_BITS 0x2000
94 #define TEMP_LOG_RESOLUTION_11_BITS 0x4000
95 #define TEMP_LOG_RESOLUTION_12_BITS 0x6000
96 #define TEMP_LOG_0_CELSIUS 0x0000
97 #define TEMP_LOG_10_125_CELSIUS 0x0A20
98 #define TEMP_LOG_25_25_CELSIUS 0x1940
99 #define TEMP_LOG_50_5_CELSIUS 0x3200
100 #define TEMP_LOG_75_CELSIUS 0x4B00
101 #define TEMP_LOG_100_CELSIUS 0x6400
102 #define TEMP_LOG_125_CELSIUS 0x7D00
103 #define TEMP_LOG_NEGATIVE_10_125_CELSIUS 0xF5E0
104 #define TEMP_LOG_NEGATIVE_25_25_CELSIUS 0xE7C0
105 #define TEMP_LOG_NEGATIVE_50_5_CELSIUS 0xCE80
106 #define TEMP_LOG_NEGATIVE_55_CELSIUS 0xC900
107  // End group macro
110 // --------------------------------------------------------------- PUBLIC TYPES
119 typedef struct
120 {
121  // Input pins
122 
123  digital_in_t alt;
124 
125  // Modules
126 
127  i2c_master_t i2c;
128 
129  // ctx variable
130 
131  uint8_t slave_address;
132  pin_name_t chip_select;
133 
134 } templog_t;
135 
139 typedef struct
140 {
141  // Communication gpio pins
142 
143  pin_name_t scl;
144  pin_name_t sda;
145 
146  // Additional gpio pins
147 
148  pin_name_t alt;
149 
150  // static variable
151 
152  uint32_t i2c_speed;
153  uint8_t i2c_address;
154 
155 } templog_cfg_t;
156  // End types group
158 
159 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
160 
166 #ifdef __cplusplus
167 extern "C"{
168 #endif
169 
179 
191 
200 
211 void templog_generic_write ( templog_t *ctx, uint8_t reg, uint16_t transfer_data, uint8_t len );
212 
223 uint16_t templog_generic_read ( templog_t *ctx, uint8_t reg );
224 
235 uint16_t temp_log_read_temp_dec ( templog_t *ctx, uint16_t resolution );
236 
246 float temp_log_convert_to_celsius ( uint16_t temperature_data );
247 
257 uint8_t temp_log_get_alert ( templog_t *ctx );
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 #endif // _TEMPLOG_H_
263  // End public_function group
266 
267 // ------------------------------------------------------------------------- END
templog_cfg_t::i2c_address
uint8_t i2c_address
Definition: templog.h:153
temp_log_convert_to_celsius
float temp_log_convert_to_celsius(uint16_t temperature_data)
Convert function.
templog_t::chip_select
pin_name_t chip_select
Definition: templog.h:132
templog_init
TEMPLOG_RETVAL templog_init(templog_t *ctx, templog_cfg_t *cfg)
Initialization function.
templog_cfg_t::alt
pin_name_t alt
Definition: templog.h:148
templog_cfg_t::scl
pin_name_t scl
Definition: templog.h:143
templog_generic_read
uint16_t templog_generic_read(templog_t *ctx, uint8_t reg)
Generic read function.
templog_cfg_t::sda
pin_name_t sda
Definition: templog.h:144
templog_generic_write
void templog_generic_write(templog_t *ctx, uint8_t reg, uint16_t transfer_data, uint8_t len)
Generic write function.
templog_cfg_setup
void templog_cfg_setup(templog_cfg_t *cfg)
Config Object Initialization function.
templog_cfg_t
Click configuration structure definition.
Definition: templog.h:140
temp_log_read_temp_dec
uint16_t temp_log_read_temp_dec(templog_t *ctx, uint16_t resolution)
Temp read function.
templog_t
Click ctx object definition.
Definition: templog.h:120
templog_t::alt
digital_in_t alt
Definition: templog.h:123
templog_t::i2c
i2c_master_t i2c
Definition: templog.h:127
templog_default_cfg
void templog_default_cfg(templog_t *ctx)
Click Default Configuration function.
temp_log_get_alert
uint8_t temp_log_get_alert(templog_t *ctx)
Alert function.
templog_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: templog.h:152
TEMPLOG_RETVAL
#define TEMPLOG_RETVAL
Definition: templog.h:72
templog_t::slave_address
uint8_t slave_address
Definition: templog.h:131