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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define TEMPHUM5_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.all = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
57  cfg.alh = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define TEMPHUM5_RETVAL uint8_t
65 
66 #define TEMPHUM5_OK 0x00
67 #define TEMPHUM5_INIT_ERROR 0xFF
68 
74 #define TEMPHUM5_DEVICE_SLAVE_ADDRESS 0x27
75 
81 #define TEMPHUM5_TEMP_DATA_IN_CELSIUS 0x01
82 #define TEMPHUM5_TEMP_DATA_IN_KELVIN 0x02
83 #define TEMPHUM5_TEMP_DATA_IN_FAHRENHEIT 0x03
84 
91 #define TEMPHUM5_STATUS_NORMAL_OPERATION 0x00
92 #define TEMPHUM5_STATUS_STALE_DATA 0x01
93 #define TEMPHUM5_STATUS_COMMAND_MODE 0x02
94 
100 #define TEMPHUM5_ALARM_OUTPUT_HIGH 0x01
101 #define TEMPHUM5_ALARM_OUTPUT_LOW 0x02
102  // End group macro
105 // --------------------------------------------------------------- PUBLIC TYPES
114 typedef struct
115 {
116  // Input pins
117 
118  digital_in_t all;
119  digital_in_t alh;
120 
121  // Modules
122 
123  i2c_master_t i2c;
124 
125  // ctx variable
126 
127  uint8_t slave_address;
128 
129  uint16_t temperature;
130  uint16_t humidity;
131 
132 } temphum5_t;
133 
137 typedef struct
138 {
139  // Communication gpio pins
140 
141  pin_name_t scl;
142  pin_name_t sda;
143 
144  // Additional gpio pins
145 
146  pin_name_t all;
147  pin_name_t alh;
148 
149  // static variable
150 
151  uint32_t i2c_speed;
152  uint8_t i2c_address;
153 
154  uint16_t dev_temperature;
155  uint16_t dev_humidity;
156 
158  // End types group
160 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
161 
167 #ifdef __cplusplus
168 extern "C"{
169 #endif
170 
179 void temphum5_cfg_setup ( temphum5_cfg_t *cfg );
180 
189 
200 void temphum5_generic_write ( temphum5_t *ctx, uint8_t cmd );
201 
213 void temphum5_generic_read ( temphum5_t *ctx, uint8_t *data_out );
214 
230 uint8_t temphum5_start_measurement ( temphum5_t *ctx );
231 
241 float temphum5_get_temperature ( temphum5_t *ctx, uint8_t temp_in );
242 
251 float temphum5_get_humidity ( temphum5_t *ctx );
252 
261 uint8_t temphum5_get_alarm ( temphum5_t *ctx, uint8_t alarm );
262 
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 #endif // _TEMPHUM5_H_
268  // End public_function group
271 
272 // ------------------------------------------------------------------------- END
pin_name_t all
Definition: temphum5.h:146
float temphum5_get_humidity(temphum5_t *ctx)
Functions for read Relative Huminidy data.
void temphum5_generic_read(temphum5_t *ctx, uint8_t *data_out)
Generic read function.
i2c_master_t i2c
Definition: temphum5.h:123
pin_name_t sda
Definition: temphum5.h:142
void temphum5_generic_write(temphum5_t *ctx, uint8_t cmd)
Generic write function.
#define TEMPHUM5_RETVAL
Definition: temphum5.h:64
void temphum5_cfg_setup(temphum5_cfg_t *cfg)
Config Object Initialization function.
uint8_t temphum5_get_alarm(temphum5_t *ctx, uint8_t alarm)
Functions for get output Alarm.
uint8_t i2c_address
Definition: temphum5.h:152
pin_name_t alh
Definition: temphum5.h:147
uint16_t humidity
Definition: temphum5.h:130
uint8_t slave_address
Definition: temphum5.h:127
digital_in_t all
Definition: temphum5.h:118
uint16_t temperature
Definition: temphum5.h:129
uint32_t i2c_speed
Definition: temphum5.h:151
digital_in_t alh
Definition: temphum5.h:119
Click ctx object definition.
Definition: temphum5.h:114
uint16_t dev_humidity
Definition: temphum5.h:155
uint16_t dev_temperature
Definition: temphum5.h:154
pin_name_t scl
Definition: temphum5.h:141
Click configuration structure definition.
Definition: temphum5.h:137
uint8_t temphum5_start_measurement(temphum5_t *ctx)
Functions for start measurement.
float temphum5_get_temperature(temphum5_t *ctx, uint8_t temp_in)
Functions for read Temperature data.
TEMPHUM5_RETVAL temphum5_init(temphum5_t *ctx, temphum5_cfg_t *cfg)
Initialization function.