-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdht22.h
81 lines (69 loc) · 3.09 KB
/
dht22.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* DHT22 Humidity And Temperature Sensor Driver
*
* Copyright (c) Edward Lin <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _DHT22_H
#define _DHT22_H
#define DEFAULT_GPIO 4
#define DEFAULT_AUTOUPDATE_SEC 10 /* re-trigger DHT22 after 10 sec */
#define AUTOUPDATE_SEC_MIN 3 /* 3 seconds */
#define AUTOUPDATE_SEC_MAX 60000 /* 10 min */
#define IO_BUF_MAX 64
/*
* proprietary to dht22.c, not seen by others
*/
#ifdef _INCLUDE_DHT22_DECL
static void process_results(struct work_struct* work);
static irqreturn_t dht22_irq_handler(int irq, void* data);
static enum hrtimer_restart autoupdate_func(struct hrtimer *hrtimer);
static enum hrtimer_restart timeout_func(struct hrtimer* hrtimer);
static void to_trigger_dht22(void);
static void trigger_dht22(void);
static void dht22_timer_init(struct hrtimer*,
enum hrtimer_restart (*)(struct hrtimer*),
bool,
int);
static int dht22_dev_init(void);
static void dht22_dev_exit(void);
static int dev_open(struct inode*, struct file*);
static int dev_close(struct inode*, struct file*);
/* humidity fops */
static int dev_open_h(struct inode*, struct file*);
static ssize_t dev_read_h(struct file*, char __user*, size_t, loff_t*);
/* temperature fops */
static int dev_open_t(struct inode*, struct file*);
static ssize_t dev_read_t(struct file*, char __user*, size_t, loff_t*);
static ssize_t read_data(struct file*, char __user*, size_t, loff_t*, int,
int factor);
#define ATTR_RW(v) struct kobj_attribute v ## _attr = __ATTR_RW(v)
#define ATTR_RO(v) struct kobj_attribute v ## _attr = __ATTR_RO(v)
#define ATTR_WO(v) struct kobj_attribute v ## _attr = __ATTR_WO(v)
#define DECL_ATTR_SHOW(f) ssize_t f ## _show (struct kobject* kobj,\
struct kobj_attribute* attr,\
char* buf)
#define DECL_ATTR_STORE(f) ssize_t f ## _store(struct kobject* kobj,\
struct kobj_attribute* attr,\
const char* buf,\
size_t count)
static DECL_ATTR_SHOW (gpio);
static DECL_ATTR_SHOW (autoupdate);
static DECL_ATTR_STORE(autoupdate);
static DECL_ATTR_SHOW (autoupdate_sec);
static DECL_ATTR_STORE(autoupdate_sec);
static DECL_ATTR_SHOW (humidity);
static DECL_ATTR_SHOW (temperature);
static DECL_ATTR_STORE(trigger);
static DECL_ATTR_STORE(debug);
#endif /* _INCLUDE_DHT22_DECL */
#endif /*_DHT22_H */