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
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
67#define DHT22_RESP_NOT_READY 0
68#define DHT22_RESP_READY 1
69
70 // 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
90 // dht22_map
91 // dht22
92
93
104
108typedef struct
109{
110 digital_out_t sda_out;
112 digital_in_t sda_in;
114 pin_name_t sd1;
115 pin_name_t sd2;
122} dht22_t;
123
127typedef struct
128{
129 // Data pin descriptors
130
131 pin_name_t sd1;
132 pin_name_t sd2;
137
138
143typedef enum
144{
146 DHT22_ERROR = -1
147
149
166
180err_t dht22_init ( dht22_t *ctx, dht22_cfg_t *cfg );
181
192
206
223err_t dht22_get_sensor_data ( dht22_t *ctx, uint16_t *hum_data, uint16_t *temp_data );
224
238err_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
271 // dht22
272
273// ------------------------------------------------------------------------ END
dht22_return_value_t
DHT22 Click return value data.
Definition dht22.h:144
@ DHT22_OK
Definition dht22.h:145
@ DHT22_ERROR
Definition dht22.h:146
dht22_sda_sel_t
DHT22 Click data pin selector.
Definition dht22.h:99
@ DHT22_SDA_SEL_SDA2
Definition dht22.h:101
@ DHT22_SDA_SEL_SDA1
Definition dht22.h:100
err_t dht22_start_signal(dht22_t *ctx)
DHT22 sends start signal to the sensor function.
err_t dht22_get_measurement_data(dht22_t *ctx, float *humidity, float *temperature)
DHT22 get measurement data from the sensor function.
err_t dht22_init_sda_input(dht22_t *ctx)
DHT22 init SDA data pin as input function.
err_t dht22_init(dht22_t *ctx, dht22_cfg_t *cfg)
DHT22 initialization function.
err_t dht22_init_sda_output(dht22_t *ctx)
DHT22 init SDA data pin as output function.
err_t dht22_check_sensor_response(dht22_t *ctx)
DHT22 release the bus to wait the sensor response signal function.
void dht22_cfg_setup(dht22_cfg_t *cfg)
DHT22 configuration object setup function.
err_t dht22_get_sensor_data(dht22_t *ctx, uint16_t *hum_data, uint16_t *temp_data)
DHT22 reading data from the sensor function.
Click configuration structure definition.
Definition dht22.h:128
pin_name_t sd2
Definition dht22.h:132
pin_name_t sd1
Definition dht22.h:131
dht22_sda_sel_t sda_sel
Definition dht22.h:134
Click ctx object definition.
Definition dht22.h:109
err_t sda_out_stat
Definition dht22.h:119
err_t sda_in_stat
Definition dht22.h:120
pin_name_t sd2
Definition dht22.h:115
digital_in_t sda_in
Definition dht22.h:112
pin_name_t sd1
Definition dht22.h:114
digital_out_t sda_out
Definition dht22.h:110
dht22_sda_sel_t sda_sel
Definition dht22.h:117