dnx RTOS 2.2.0 "Eagle"
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
DHT11 Driver

Detailed Description

Description

Driver handles DHT11 sensor.

Supported architectures

Meaning of major and minor numbers

Module handles only major device number. The minor number is not used. A new instance of driver is next major number.

Numeration restrictions

Number of devices (major number) can be theoretically up to 256 or to limits of memory capacity. Minor number is ignored (should be set to 0).

Driver initialization

To initialize driver the following code can be used:

driver_init("DHT11", 0, 0, "/dev/DHT11-0"); // device path can be more descriptive
driver_init("DHT11", 1, 0, "/dev/DHT11-1");

Driver release

To release driver the following code can be used:

driver_release("DHT11", 0, 0);
driver_release("DHT11", 1, 0);

Driver configuration

Driver configuration should be done before usage and after initialization. The best place to do this is user application. To configure particular DHT11 sensor the ioctl() function shall be used as follow:

#include <stdio.h>
#include <stdbool.h>
#include <sys/ioctl.h>
static const DHT11_config_t cfg = {
.port_idx = IOCTL_GPIO_PORT_IDX__DHT11,
.pin_idx = IOCTL_GPIO_PIN_IDX__DHT11
};
FILE *dev = fopen("/dev/DHT11-0", "r+");
if (dev) {
if (ioctl(fileno(dev), IOCTL_DHT11__CONFIGURE, &cfg) != 0) {
}
fclose(dev);
} else {
}
...

Data write

There is no possibility to write any data to the device.

Data read

Data from the DHT11 sensor can be read as regular file.

#include <stdio.h>
#include <stdbool.h>
#include <dnx/misc.h>
#include <sys/ioctl.h>
GLOBAL_VARIABLES_SECTION {
};
static const DHT11_config_t cfg = {
.port_idx = IOCTL_GPIO_PORT_IDX__DHT11,
.pin_idx = IOCTL_GPIO_PIN_IDX__DHT11
};
int_main(dht11, STACK_DEPTH_LOW, int argc, char *argv[])
{
FILE *dev = fopen("/dev/DHT11-0", "r+");
if (dev) {
uint8_t buf[5];
rewind(dev);
fread(buf, 1, ARRAY_SIZE(buf), dev);
fclose(dev);
} else {
}
return 0;
}

Data Structures

struct  DHT11_config_t
 

Macros

#define IOCTL_DHT11__CONFIGURE   _IOW(DHT11, 0, const DHT11_config_t*)
 Join driver with pin where DHT11 sensor is connected to. More...
 

Data Structure Documentation

struct DHT11_config_t

Type represent DHT11 configuration.

Data Fields
u8_t pin_idx

Pin index (use IOCTL_GPIO_PIN_IDX__xxx macro).

u8_t port_idx

Port index (use IOCTL_GPIO_PORT_IDX__xxx macro).

Macro Definition Documentation

#define IOCTL_DHT11__CONFIGURE   _IOW(DHT11, 0, const DHT11_config_t*)
Parameters
[WR]DHT11_config_t* Driver configuration structure.
Returns
On success 0 is returned, otherwise -1 and errno code is set.