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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
53 
58 #define TEMPLOG_MAP_MIKROBUS( cfg, mikrobus ) \
59  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
60  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
61  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT )
62 
68 #define TEMPLOG_RETVAL uint8_t
69 
70 #define TEMPLOG_OK 0x00
71 #define TEMPLOG_INIT_ERROR 0xFF
72 
78 #define TEMP_LOG_TEMPERATURE 0x00
79 #define TEMP_LOG_CONFIGURATION 0x01
80 #define TEMP_LOG_TLOW_LIMIT 0x02
81 #define TEMP_LOG_THIGH_LIMIT 0x03
82 #define TEMP_LOG_CONFIGURATION_NONVOL 0x11
83 #define TEMP_LOG_TLOW_LIMIT_NONVOL 0x12
84 #define TEMP_LOG_THIGH_LIMIT_NONVOL 0x13
85 #define TEMP_LOG_SLAVE_ADDRESS 0x48
86 #define TEMP_LOG_8_BITS_DATA 0x01
87 #define TEMP_LOG_16_BITS_DATA 0x00
88 #define TEMP_LOG_RESOLUTION_9_BITS 0x0000
89 #define TEMP_LOG_RESOLUTION_10_BITS 0x2000
90 #define TEMP_LOG_RESOLUTION_11_BITS 0x4000
91 #define TEMP_LOG_RESOLUTION_12_BITS 0x6000
92 #define TEMP_LOG_0_CELSIUS 0x0000
93 #define TEMP_LOG_10_125_CELSIUS 0x0A20
94 #define TEMP_LOG_25_25_CELSIUS 0x1940
95 #define TEMP_LOG_50_5_CELSIUS 0x3200
96 #define TEMP_LOG_75_CELSIUS 0x4B00
97 #define TEMP_LOG_100_CELSIUS 0x6400
98 #define TEMP_LOG_125_CELSIUS 0x7D00
99 #define TEMP_LOG_NEGATIVE_10_125_CELSIUS 0xF5E0
100 #define TEMP_LOG_NEGATIVE_25_25_CELSIUS 0xE7C0
101 #define TEMP_LOG_NEGATIVE_50_5_CELSIUS 0xCE80
102 #define TEMP_LOG_NEGATIVE_55_CELSIUS 0xC900
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  // Input pins
118 
119  digital_in_t alt;
120 
121  // Modules
122 
123  i2c_master_t i2c;
124 
125  // ctx variable
126 
127  uint8_t slave_address;
128  pin_name_t chip_select;
129 
130 } templog_t;
131 
135 typedef struct
136 {
137  // Communication gpio pins
138 
139  pin_name_t scl;
140  pin_name_t sda;
141 
142  // Additional gpio pins
143 
144  pin_name_t alt;
145 
146  // static variable
147 
148  uint32_t i2c_speed;
149  uint8_t i2c_address;
150 
151 } templog_cfg_t;
152  // End types group
154 
155 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
156 
162 #ifdef __cplusplus
163 extern "C"{
164 #endif
165 
175 
187 
196 
207 void templog_generic_write ( templog_t *ctx, uint8_t reg, uint16_t transfer_data, uint8_t len );
208 
219 uint16_t templog_generic_read ( templog_t *ctx, uint8_t reg );
220 
231 uint16_t temp_log_read_temp_dec ( templog_t *ctx, uint16_t resolution );
232 
242 float temp_log_convert_to_celsius ( uint16_t temperature_data );
243 
253 uint8_t temp_log_get_alert ( templog_t *ctx );
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 #endif // _TEMPLOG_H_
259  // End public_function group
262 
263 // ------------------------------------------------------------------------- END
templog_cfg_t::i2c_address
uint8_t i2c_address
Definition: templog.h:149
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:128
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:144
templog_cfg_t::scl
pin_name_t scl
Definition: templog.h:139
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:140
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:136
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:116
templog_t::alt
digital_in_t alt
Definition: templog.h:119
templog_t::i2c
i2c_master_t i2c
Definition: templog.h:123
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:148
TEMPLOG_RETVAL
#define TEMPLOG_RETVAL
Definition: templog.h:68
templog_t::slave_address
uint8_t slave_address
Definition: templog.h:127