temphum5  2.0.0.0
temphum5.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 TEMPHUM5_H
36 #define TEMPHUM5_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 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define TEMPHUM5_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.all = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
67  cfg.alh = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define TEMPHUM5_RETVAL uint8_t
75 
76 #define TEMPHUM5_OK 0x00
77 #define TEMPHUM5_INIT_ERROR 0xFF
78 
84 #define TEMPHUM5_DEVICE_SLAVE_ADDRESS 0x27
85 
91 #define TEMPHUM5_TEMP_DATA_IN_CELSIUS 0x01
92 #define TEMPHUM5_TEMP_DATA_IN_KELVIN 0x02
93 #define TEMPHUM5_TEMP_DATA_IN_FAHRENHEIT 0x03
94 
101 #define TEMPHUM5_STATUS_NORMAL_OPERATION 0x00
102 #define TEMPHUM5_STATUS_STALE_DATA 0x01
103 #define TEMPHUM5_STATUS_COMMAND_MODE 0x02
104 
110 #define TEMPHUM5_ALARM_OUTPUT_HIGH 0x01
111 #define TEMPHUM5_ALARM_OUTPUT_LOW 0x02
112  // End group macro
115 // --------------------------------------------------------------- PUBLIC TYPES
124 typedef struct
125 {
126  // Input pins
127 
128  digital_in_t all;
129  digital_in_t alh;
130 
131  // Modules
132 
133  i2c_master_t i2c;
134 
135  // ctx variable
136 
137  uint8_t slave_address;
138 
139  uint16_t temperature;
140  uint16_t humidity;
141 
142 } temphum5_t;
143 
147 typedef struct
148 {
149  // Communication gpio pins
150 
151  pin_name_t scl;
152  pin_name_t sda;
153 
154  // Additional gpio pins
155 
156  pin_name_t all;
157  pin_name_t alh;
158 
159  // static variable
160 
161  uint32_t i2c_speed;
162  uint8_t i2c_address;
163 
164  uint16_t dev_temperature;
165  uint16_t dev_humidity;
166 
168  // End types group
170 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
171 
177 #ifdef __cplusplus
178 extern "C"{
179 #endif
180 
190 
199 
210 void temphum5_generic_write ( temphum5_t *ctx, uint8_t cmd );
211 
223 void temphum5_generic_read ( temphum5_t *ctx, uint8_t *data_out );
224 
241 
251 float temphum5_get_temperature ( temphum5_t *ctx, uint8_t temp_in );
252 
262 
271 uint8_t temphum5_get_alarm ( temphum5_t *ctx, uint8_t alarm );
272 
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 #endif // _TEMPHUM5_H_
278  // End public_function group
281 
282 // ------------------------------------------------------------------------- END
temphum5_t::humidity
uint16_t humidity
Definition: temphum5.h:140
temphum5_cfg_t::i2c_address
uint8_t i2c_address
Definition: temphum5.h:162
temphum5_cfg_t::all
pin_name_t all
Definition: temphum5.h:156
temphum5_cfg_t::alh
pin_name_t alh
Definition: temphum5.h:157
temphum5_t::slave_address
uint8_t slave_address
Definition: temphum5.h:137
TEMPHUM5_RETVAL
#define TEMPHUM5_RETVAL
Definition: temphum5.h:74
temphum5_start_measurement
uint8_t temphum5_start_measurement(temphum5_t *ctx)
Functions for start measurement.
temphum5_t::temperature
uint16_t temperature
Definition: temphum5.h:139
temphum5_get_humidity
float temphum5_get_humidity(temphum5_t *ctx)
Functions for read Relative Huminidy data.
temphum5_get_temperature
float temphum5_get_temperature(temphum5_t *ctx, uint8_t temp_in)
Functions for read Temperature data.
temphum5_cfg_t::sda
pin_name_t sda
Definition: temphum5.h:152
temphum5_cfg_setup
void temphum5_cfg_setup(temphum5_cfg_t *cfg)
Config Object Initialization function.
temphum5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: temphum5.h:161
temphum5_generic_write
void temphum5_generic_write(temphum5_t *ctx, uint8_t cmd)
Generic write function.
temphum5_t
Click ctx object definition.
Definition: temphum5.h:125
temphum5_generic_read
void temphum5_generic_read(temphum5_t *ctx, uint8_t *data_out)
Generic read function.
temphum5_cfg_t
Click configuration structure definition.
Definition: temphum5.h:148
temphum5_init
TEMPHUM5_RETVAL temphum5_init(temphum5_t *ctx, temphum5_cfg_t *cfg)
Initialization function.
temphum5_t::i2c
i2c_master_t i2c
Definition: temphum5.h:133
temphum5_cfg_t::dev_humidity
uint16_t dev_humidity
Definition: temphum5.h:165
temphum5_t::alh
digital_in_t alh
Definition: temphum5.h:129
temphum5_get_alarm
uint8_t temphum5_get_alarm(temphum5_t *ctx, uint8_t alarm)
Functions for get output Alarm.
temphum5_cfg_t::scl
pin_name_t scl
Definition: temphum5.h:151
temphum5_cfg_t::dev_temperature
uint16_t dev_temperature
Definition: temphum5.h:164
temphum5_t::all
digital_in_t all
Definition: temphum5.h:128