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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
43 
48 #define TEMPLOG_MAP_MIKROBUS( cfg, mikrobus ) \
49  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
50  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
51  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT )
52 
58 #define TEMPLOG_RETVAL uint8_t
59 
60 #define TEMPLOG_OK 0x00
61 #define TEMPLOG_INIT_ERROR 0xFF
62 
68 #define TEMP_LOG_TEMPERATURE 0x00
69 #define TEMP_LOG_CONFIGURATION 0x01
70 #define TEMP_LOG_TLOW_LIMIT 0x02
71 #define TEMP_LOG_THIGH_LIMIT 0x03
72 #define TEMP_LOG_CONFIGURATION_NONVOL 0x11
73 #define TEMP_LOG_TLOW_LIMIT_NONVOL 0x12
74 #define TEMP_LOG_THIGH_LIMIT_NONVOL 0x13
75 #define TEMP_LOG_SLAVE_ADDRESS 0x48
76 #define TEMP_LOG_8_BITS_DATA 0x01
77 #define TEMP_LOG_16_BITS_DATA 0x00
78 #define TEMP_LOG_RESOLUTION_9_BITS 0x0000
79 #define TEMP_LOG_RESOLUTION_10_BITS 0x2000
80 #define TEMP_LOG_RESOLUTION_11_BITS 0x4000
81 #define TEMP_LOG_RESOLUTION_12_BITS 0x6000
82 #define TEMP_LOG_0_CELSIUS 0x0000
83 #define TEMP_LOG_10_125_CELSIUS 0x0A20
84 #define TEMP_LOG_25_25_CELSIUS 0x1940
85 #define TEMP_LOG_50_5_CELSIUS 0x3200
86 #define TEMP_LOG_75_CELSIUS 0x4B00
87 #define TEMP_LOG_100_CELSIUS 0x6400
88 #define TEMP_LOG_125_CELSIUS 0x7D00
89 #define TEMP_LOG_NEGATIVE_10_125_CELSIUS 0xF5E0
90 #define TEMP_LOG_NEGATIVE_25_25_CELSIUS 0xE7C0
91 #define TEMP_LOG_NEGATIVE_50_5_CELSIUS 0xCE80
92 #define TEMP_LOG_NEGATIVE_55_CELSIUS 0xC900
93  // End group macro
96 // --------------------------------------------------------------- PUBLIC TYPES
105 typedef struct
106 {
107  // Input pins
108 
109  digital_in_t alt;
110 
111  // Modules
112 
113  i2c_master_t i2c;
114 
115  // ctx variable
116 
117  uint8_t slave_address;
118  pin_name_t chip_select;
119 
120 } templog_t;
121 
125 typedef struct
126 {
127  // Communication gpio pins
128 
129  pin_name_t scl;
130  pin_name_t sda;
131 
132  // Additional gpio pins
133 
134  pin_name_t alt;
135 
136  // static variable
137 
138  uint32_t i2c_speed;
139  uint8_t i2c_address;
140 
141 } templog_cfg_t;
142  // End types group
144 
145 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
146 
152 #ifdef __cplusplus
153 extern "C"{
154 #endif
155 
164 void templog_cfg_setup ( templog_cfg_t *cfg );
165 
177 
185 void templog_default_cfg ( templog_t *ctx );
186 
197 void templog_generic_write ( templog_t *ctx, uint8_t reg, uint16_t transfer_data, uint8_t len );
198 
209 uint16_t templog_generic_read ( templog_t *ctx, uint8_t reg );
210 
221 uint16_t temp_log_read_temp_dec ( templog_t *ctx, uint16_t resolution );
222 
232 float temp_log_convert_to_celsius ( uint16_t temperature_data );
233 
243 uint8_t temp_log_get_alert ( templog_t *ctx );
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 #endif // _TEMPLOG_H_
249  // End public_function group
252 
253 // ------------------------------------------------------------------------- END
templog_cfg_t::i2c_address
uint8_t i2c_address
Definition: templog.h:139
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:118
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:134
templog_cfg_t::scl
pin_name_t scl
Definition: templog.h:129
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:130
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:125
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:105
templog_t::alt
digital_in_t alt
Definition: templog.h:109
templog_t::i2c
i2c_master_t i2c
Definition: templog.h:113
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:138
TEMPLOG_RETVAL
#define TEMPLOG_RETVAL
Definition: templog.h:58
templog_t::slave_address
uint8_t slave_address
Definition: templog.h:117