humidity 2.0.0.0
humidity.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef HUMIDITY_H
29#define HUMIDITY_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_analog_in.h"
52#include "drv_i2c_master.h"
53
75#define HUMIDITY_SET_DEV_ADDR 0x4D
76
81#define HUMIDITY_ADC_RESOLUTION 0x0FFF
82#define HUMIDITY_VREF_3V3 3.3
83#define HUMIDITY_VREF_5V 5.0
84
89#define HUMIDITY_DIVISOR 0.00636
90#define HUMIDITY_SUBTRAHEND 0.1515
91
92 // humidity_set
93
108#define HUMIDITY_MAP_MIKROBUS( cfg, mikrobus ) \
109 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
110 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
111 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
112
113 // humidity_map
114 // humidity
115
126
131typedef struct
132{
133 analog_in_t adc;
134 i2c_master_t i2c;
138 float vref;
140} humidity_t;
141
146typedef struct
147{
148 pin_name_t an;
149 pin_name_t scl;
150 pin_name_t sda;
152 uint32_t i2c_speed;
153 uint8_t i2c_address;
156 analog_in_resolution_t resolution;
157 float vref;
160
165typedef enum
166{
168 HUMIDITY_ERROR = -1
169
171
188
204
220
233err_t humidity_read_raw_adc ( humidity_t *ctx, uint16_t *raw_adc );
234
247err_t humidity_read_voltage ( humidity_t *ctx, float *voltage );
248
261err_t humidity_set_vref ( humidity_t *ctx, float vref );
262
272float humidity_voltage_to_rh ( humidity_t *ctx, float voltage );
273
274#ifdef __cplusplus
275}
276#endif
277#endif // HUMIDITY_H
278
279 // humidity
280
281// ------------------------------------------------------------------------ END
void humidity_drv_interface_selection(humidity_cfg_t *cfg, humidity_drv_t drv_sel)
Humidity driver interface setup function.
err_t humidity_init(humidity_t *ctx, humidity_cfg_t *cfg)
Humidity initialization function.
void humidity_cfg_setup(humidity_cfg_t *cfg)
Humidity configuration object setup function.
float humidity_voltage_to_rh(humidity_t *ctx, float voltage)
Humidity voltage to relative humidity function.
err_t humidity_read_voltage(humidity_t *ctx, float *voltage)
Humidity read voltage level function.
err_t humidity_read_raw_adc(humidity_t *ctx, uint16_t *raw_adc)
Humidity read raw ADC value function.
err_t humidity_set_vref(humidity_t *ctx, float vref)
Humidity set vref function.
humidity_drv_t
Humidity Click driver selector.
Definition humidity.h:121
@ HUMIDITY_DRV_SEL_I2C
Definition humidity.h:123
@ HUMIDITY_DRV_SEL_ADC
Definition humidity.h:122
humidity_return_value_t
Humidity Click return value data.
Definition humidity.h:166
@ HUMIDITY_ERROR
Definition humidity.h:168
@ HUMIDITY_OK
Definition humidity.h:167
Humidity Click configuration object.
Definition humidity.h:147
humidity_drv_t drv_sel
Definition humidity.h:155
analog_in_resolution_t resolution
Definition humidity.h:156
float vref
Definition humidity.h:157
uint32_t i2c_speed
Definition humidity.h:152
pin_name_t scl
Definition humidity.h:149
pin_name_t sda
Definition humidity.h:150
pin_name_t an
Definition humidity.h:148
uint8_t i2c_address
Definition humidity.h:153
Humidity Click context object.
Definition humidity.h:132
humidity_drv_t drv_sel
Definition humidity.h:136
float vref
Definition humidity.h:138
i2c_master_t i2c
Definition humidity.h:134
uint8_t slave_address
Definition humidity.h:137
analog_in_t adc
Definition humidity.h:133