dht22  2.0.0.0
dht22.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 
34 #ifndef DHT22_H
35 #define DHT22_H
36 
37 #include "drv_digital_out.h"
38 #include "drv_digital_in.h"
39 
49 #define DHT22_MAP_MIKROBUS( cfg, mikrobus ) \
50  cfg.sd1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
51  cfg.sd2 = MIKROBUS( mikrobus, MIKROBUS_INT )
52 
58 #define DHT22_OK 0
59 #define DHT22_ERROR (-1)
60 
66 #define DHT22_RESP_NOT_READY 0
67 #define DHT22_RESP_READY 1
68  // End group macro
71 
80 typedef enum
81 {
84 
86 
90 typedef struct
91 {
92  // Output data pin object
93 
94  digital_out_t sda_out;
95 
96  // Input data pin object
97 
98  digital_in_t sda_in;
99 
100  // Data pin descriptors
101 
102  pin_name_t sd1;
103  pin_name_t sd2;
104 
105  // Data pin selector
106 
108 
109  // Data pin object status
110 
112  err_t sda_in_stat;
113 
114 } dht22_t;
115 
119 typedef struct
120 {
121  // Data pin descriptors
122 
123  pin_name_t sd1;
124  pin_name_t sd2;
125 
126  // Data pin selector
127 
129 
130 } dht22_cfg_t;
131  // End types group
133 
139 #ifdef __cplusplus
140 extern "C"{
141 #endif
142 
151 void dht22_cfg_setup ( dht22_cfg_t *cfg );
152 
162 err_t dht22_init ( dht22_t *ctx, dht22_cfg_t *cfg );
163 
175 err_t dht22_start_signal ( dht22_t *ctx );
176 
195 err_t dht22_check_sensor_response ( dht22_t *ctx, uint8_t *check_out );
196 
214 err_t dht22_get_sensor_data ( dht22_t *ctx, uint32_t *data_out );
215 
230 uint16_t dht22_get_temperature ( dht22_t *ctx, uint32_t sensor_data );
231 
242 float dht22_calculate_temperature ( dht22_t *ctx, uint32_t sensor_data );
243 
258 uint16_t dht22_get_humidity ( dht22_t *ctx, uint32_t sensor_data );
259 
270 float dht22_calculate_humidity ( dht22_t *ctx, uint32_t sensor_data );
271 
281 err_t dht22_init_sda_input ( dht22_t *ctx );
282 
292 err_t dht22_init_sda_output ( dht22_t *ctx );
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 #endif // DHT22_H
298  // End public_function group // End click Driver group
301 
302 // ------------------------------------------------------------------------ END
dht22_init_sda_output
err_t dht22_init_sda_output(dht22_t *ctx)
Init SDA data pin as output.
dht22_cfg_t::sd2
pin_name_t sd2
Definition: dht22.h:124
dht22_get_humidity
uint16_t dht22_get_humidity(dht22_t *ctx, uint32_t sensor_data)
Get the humidity data function.
DHT22_SDA_SEL_SDA1
Definition: dht22.h:82
dht22_t::sda_sel
dht22_sda_sel_t sda_sel
Definition: dht22.h:107
dht22_start_signal
err_t dht22_start_signal(dht22_t *ctx)
Sends start signal to the sensor function.
dht22_init_sda_input
err_t dht22_init_sda_input(dht22_t *ctx)
Init SDA data pin as input.
dht22_t::sd1
pin_name_t sd1
Definition: dht22.h:102
dht22_get_temperature
uint16_t dht22_get_temperature(dht22_t *ctx, uint32_t sensor_data)
Get the temperature data function.
DHT22_SDA_SEL_SDA2
Definition: dht22.h:83
dht22_t::sda_in_stat
err_t sda_in_stat
Definition: dht22.h:112
dht22_t::sd2
pin_name_t sd2
Definition: dht22.h:103
dht22_cfg_setup
void dht22_cfg_setup(dht22_cfg_t *cfg)
Config Object Initialization function.
dht22_sda_sel_t
dht22_sda_sel_t
Click data pin selector.
Definition: dht22.h:80
dht22_cfg_t::sda_sel
dht22_sda_sel_t sda_sel
Definition: dht22.h:128
dht22_t::sda_out
digital_out_t sda_out
Definition: dht22.h:94
dht22_cfg_t
Click configuration structure definition.
Definition: dht22.h:119
dht22_cfg_t::sd1
pin_name_t sd1
Definition: dht22.h:123
dht22_calculate_temperature
float dht22_calculate_temperature(dht22_t *ctx, uint32_t sensor_data)
Calculate the temperature in degrees Celsius function.
dht22_t::sda_out_stat
err_t sda_out_stat
Definition: dht22.h:111
dht22_init
err_t dht22_init(dht22_t *ctx, dht22_cfg_t *cfg)
Initialization function.
dht22_get_sensor_data
err_t dht22_get_sensor_data(dht22_t *ctx, uint32_t *data_out)
Reading data from the sensor function.
dht22_check_sensor_response
err_t dht22_check_sensor_response(dht22_t *ctx, uint8_t *check_out)
Release the bus to wait the sensor response signal function.
dht22_t
Click ctx object definition.
Definition: dht22.h:90
dht22_calculate_humidity
float dht22_calculate_humidity(dht22_t *ctx, uint32_t sensor_data)
Calculate the humidity in percentage function.
dht22_t::sda_in
digital_in_t sda_in
Definition: dht22.h:98