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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 
53 #define DHT22_RESP_NOT_READY 0
54 #define DHT22_RESP_READY 1
55  // dht22_set
57 
72 #define DHT22_MAP_MIKROBUS( cfg, mikrobus ) \
73  cfg.sd1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
74  cfg.sd2 = MIKROBUS( mikrobus, MIKROBUS_INT )
75  // dht22_map // dht22
78 
79 
84 typedef enum
85 {
88 
90 
94 typedef struct
95 {
96  digital_out_t sda_out;
98  digital_in_t sda_in;
100  pin_name_t sd1;
101  pin_name_t sd2;
105  err_t sda_out_stat;
106  err_t sda_in_stat;
108 } dht22_t;
109 
113 typedef struct
114 {
115  // Data pin descriptors
116 
117  pin_name_t sd1;
118  pin_name_t sd2;
122 } dht22_cfg_t;
123 
124 
129 typedef enum
130 {
131  DHT22_OK = 0,
132  DHT22_ERROR = -1
133 
135 
152 
166 err_t dht22_init ( dht22_t *ctx, dht22_cfg_t *cfg );
167 
178 
192 
209 err_t dht22_get_sensor_data ( dht22_t *ctx, uint16_t *hum_data, uint16_t *temp_data );
210 
224 err_t dht22_get_measurement_data ( dht22_t *ctx, float *humidity, float *temperature );
225 
238 
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif // DHT22_H
256  // dht22
258 
259 // ------------------------------------------------------------------------ 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:87
dht22_return_value_t
dht22_return_value_t
DHT22 Click return value data.
Definition: dht22.h:130
dht22_cfg_t::sd2
pin_name_t sd2
Definition: dht22.h:118
DHT22_ERROR
@ DHT22_ERROR
Definition: dht22.h:132
dht22_t::sda_sel
dht22_sda_sel_t sda_sel
Definition: dht22.h:103
dht22_t::sd1
pin_name_t sd1
Definition: dht22.h:100
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:106
dht22_t::sd2
pin_name_t sd2
Definition: dht22.h:101
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:120
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:96
dht22_cfg_t
Click configuration structure definition.
Definition: dht22.h:114
dht22_cfg_t::sd1
pin_name_t sd1
Definition: dht22.h:117
DHT22_SDA_SEL_SDA1
@ DHT22_SDA_SEL_SDA1
Definition: dht22.h:86
dht22_t::sda_out_stat
err_t sda_out_stat
Definition: dht22.h:105
DHT22_OK
@ DHT22_OK
Definition: dht22.h:131
dht22_sda_sel_t
dht22_sda_sel_t
DHT22 Click data pin selector.
Definition: dht22.h:85
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:95
dht22_t::sda_in
digital_in_t sda_in
Definition: dht22.h:98
dht22_check_sensor_response
err_t dht22_check_sensor_response(dht22_t *ctx)
DHT22 release the bus to wait the sensor response signal function.