dht22  2.0.0.0
dht22.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 DHT22_H
29 #define DHT22_H
30 
31 #ifdef __cplusplus
32 extern "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 
67 #define DHT22_RESP_NOT_READY 0
68 #define DHT22_RESP_READY 1
69  // dht22_set
71 
86 #define DHT22_MAP_MIKROBUS( cfg, mikrobus ) \
87  cfg.sd1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
88  cfg.sd2 = MIKROBUS( mikrobus, MIKROBUS_INT )
89  // dht22_map // dht22
92 
93 
98 typedef enum
99 {
102 
104 
108 typedef struct
109 {
110  digital_out_t sda_out;
112  digital_in_t sda_in;
114  pin_name_t sd1;
115  pin_name_t sd2;
119  err_t sda_out_stat;
120  err_t sda_in_stat;
122 } dht22_t;
123 
127 typedef struct
128 {
129  // Data pin descriptors
130 
131  pin_name_t sd1;
132  pin_name_t sd2;
136 } dht22_cfg_t;
137 
138 
143 typedef enum
144 {
145  DHT22_OK = 0,
146  DHT22_ERROR = -1
147 
149 
166 
180 err_t dht22_init ( dht22_t *ctx, dht22_cfg_t *cfg );
181 
192 
206 
223 err_t dht22_get_sensor_data ( dht22_t *ctx, uint16_t *hum_data, uint16_t *temp_data );
224 
238 err_t dht22_get_measurement_data ( dht22_t *ctx, float *humidity, float *temperature );
239 
252 
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 #endif // DHT22_H
270  // dht22
272 
273 // ------------------------------------------------------------------------ END
dht22_get_measurement_data
err_t dht22_get_measurement_data(dht22_t *ctx, float *humidity, float *temperature)
DHT22 get measurement data from the sensor function.
dht22_cfg_setup
void dht22_cfg_setup(dht22_cfg_t *cfg)
DHT22 configuration object setup function.
DHT22_SDA_SEL_SDA2
@ DHT22_SDA_SEL_SDA2
Definition: dht22.h:101
dht22_return_value_t
dht22_return_value_t
DHT22 Click return value data.
Definition: dht22.h:144
dht22_cfg_t::sd2
pin_name_t sd2
Definition: dht22.h:132
DHT22_ERROR
@ DHT22_ERROR
Definition: dht22.h:146
dht22_t::sda_sel
dht22_sda_sel_t sda_sel
Definition: dht22.h:117
dht22_t::sd1
pin_name_t sd1
Definition: dht22.h:114
dht22_init
err_t dht22_init(dht22_t *ctx, dht22_cfg_t *cfg)
DHT22 initialization function.
dht22_t::sda_in_stat
err_t sda_in_stat
Definition: dht22.h:120
dht22_t::sd2
pin_name_t sd2
Definition: dht22.h:115
dht22_get_sensor_data
err_t dht22_get_sensor_data(dht22_t *ctx, uint16_t *hum_data, uint16_t *temp_data)
DHT22 reading data from the sensor function.
dht22_cfg_t::sda_sel
dht22_sda_sel_t sda_sel
Definition: dht22.h:134
dht22_init_sda_input
err_t dht22_init_sda_input(dht22_t *ctx)
DHT22 init SDA data pin as input function.
dht22_init_sda_output
err_t dht22_init_sda_output(dht22_t *ctx)
DHT22 init SDA data pin as output function.
dht22_t::sda_out
digital_out_t sda_out
Definition: dht22.h:110
dht22_cfg_t
Click configuration structure definition.
Definition: dht22.h:128
dht22_cfg_t::sd1
pin_name_t sd1
Definition: dht22.h:131
DHT22_SDA_SEL_SDA1
@ DHT22_SDA_SEL_SDA1
Definition: dht22.h:100
dht22_t::sda_out_stat
err_t sda_out_stat
Definition: dht22.h:119
DHT22_OK
@ DHT22_OK
Definition: dht22.h:145
dht22_sda_sel_t
dht22_sda_sel_t
DHT22 Click data pin selector.
Definition: dht22.h:99
dht22_start_signal
err_t dht22_start_signal(dht22_t *ctx)
DHT22 sends start signal to the sensor function.
dht22_t
Click ctx object definition.
Definition: dht22.h:109
dht22_t::sda_in
digital_in_t sda_in
Definition: dht22.h:112
dht22_check_sensor_response
err_t dht22_check_sensor_response(dht22_t *ctx)
DHT22 release the bus to wait the sensor response signal function.