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 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DHT22_H
36 #define DHT22_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define DHT22_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.sd11= MIKROBUS( mikrobus, MIKROBUS_CS ); \
53  cfg.sd12= MIKROBUS( mikrobus, MIKROBUS_CS ); \
54  cfg.sd2= MIKROBUS( mikrobus, MIKROBUS_INT );
55 
61 #define DHT22_RETVAL uint8_t
62 
63 #define DHT22_OK 0x00
64 #define DHT22_INIT_ERROR 0xFF
65  // End group macro
68 // --------------------------------------------------------------- PUBLIC TYPES
77 typedef struct
78 {
79  // Output pins
80 
81  digital_out_t sd12;
82 
83  // Input pins
84 
85  digital_in_t sd11;
86  digital_in_t sd2;
87 
88 } dht22_t;
89 
93 typedef struct
94 {
95  // Additional gpio pins
96 
97  pin_name_t sd11;
98  pin_name_t sd12;
99  pin_name_t sd2;
100 
101 } dht22_cfg_t;
102  // End types group
104 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
105 
111 #ifdef __cplusplus
112 extern "C"{
113 #endif
114 
123 void dht22_cfg_setup ( dht22_cfg_t *cfg );
124 
133 
145 void dht22_start_signal ( dht22_t *ctx );
146 
164 uint8_t dht22_check_sensor_response ( dht22_t *ctx );
165 
184 uint32_t dht22_get_sensor_data ( dht22_t *ctx );
185 
203 uint16_t dht22_calculate_temperature ( dht22_t *ctx, uint32_t sensor_data );
204 
218 float dht22_calc_temp_c ( dht22_t *ctx, uint32_t sensor_data );
219 
237 uint16_t dht22_calculate_humidity ( dht22_t *ctx, uint32_t sensor_data );
238 
252 float dht22_calc_humidity ( dht22_t *ctx, uint32_t sensor_data );
253 
262 void cs_input (dht22_t *ctx,dht22_cfg_t *cfg);
263 
272 void cs_output (dht22_t *ctx,dht22_cfg_t *cfg);
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 #endif // _DHT22_H_
278  // End public_function group
281 
282 // ------------------------------------------------------------------------- END
void dht22_cfg_setup(dht22_cfg_t *cfg)
Config Object Initialization function.
digital_in_t sd11
Definition: dht22.h:85
uint16_t dht22_calculate_humidity(dht22_t *ctx, uint32_t sensor_data)
Calculate the humidity data function.
uint32_t dht22_get_sensor_data(dht22_t *ctx)
Reading data from the sensor function.
void cs_output(dht22_t *ctx, dht22_cfg_t *cfg)
Cs output.
pin_name_t sd11
Definition: dht22.h:97
DHT22_RETVAL dht22_init(dht22_t *ctx, dht22_cfg_t *cfg)
Initialization function.
uint8_t dht22_check_sensor_response(dht22_t *ctx)
Release the bus to wait the sensor response signal function.
#define DHT22_RETVAL
Definition: dht22.h:61
digital_in_t sd2
Definition: dht22.h:86
digital_out_t sd12
Definition: dht22.h:81
float dht22_calc_humidity(dht22_t *ctx, uint32_t sensor_data)
Calculate the humidity in percentage function.
Click configuration structure definition.
Definition: dht22.h:93
float dht22_calc_temp_c(dht22_t *ctx, uint32_t sensor_data)
Calculate the temperature in degrees Celsius function.
pin_name_t sd12
Definition: dht22.h:98
void cs_input(dht22_t *ctx, dht22_cfg_t *cfg)
Cs input.
uint16_t dht22_calculate_temperature(dht22_t *ctx, uint32_t sensor_data)
Calculate the temperature data function.
Click ctx object definition.
Definition: dht22.h:77
pin_name_t sd2
Definition: dht22.h:99
void dht22_start_signal(dht22_t *ctx)
Sends start signal to the sensor function.