commit | author | age
|
e30a4c
|
1 |
/********************************************************************************* |
GW |
2 |
* Copyright: (C) 2019 LingYun IoT System Studio |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* Filename: gpio.h |
|
6 |
* Description: This file is GPIO input/output functions |
|
7 |
* |
|
8 |
* Version: 1.0.0(2019年06月24日) |
|
9 |
* Author: Guo Wenxue <guowenxue@gmail.com> |
|
10 |
* ChangeLog: 1, Release initial version on "2019年06月24日 23时46分47秒" |
|
11 |
* |
|
12 |
********************************************************************************/ |
|
13 |
|
|
14 |
#ifndef _GPIO_H_ |
|
15 |
#define _GPIO_H_ |
|
16 |
|
|
17 |
#include <gpiod.h> |
|
18 |
|
|
19 |
#define GPIO_MAXOUT 8 |
|
20 |
#define GPIO_MAXIN 4 |
|
21 |
|
|
22 |
typedef struct gpio_info_s |
|
23 |
{ |
|
24 |
char name[32]; /* GPIO connected module name */ |
|
25 |
int pin; /* GPIO BCM pin number */ |
|
26 |
int active_level; /* active power level */ |
|
27 |
struct gpiod_line *line; /* gpiod line */ |
|
28 |
} gpio_info_t; |
|
29 |
|
|
30 |
|
|
31 |
typedef struct gpio_s |
|
32 |
{ |
|
33 |
gpio_info_t output[GPIO_MAXOUT]; /* GPIO output pins */ |
|
34 |
int outcnt; /* GPIO output numbers */ |
|
35 |
int light_intval; /* light on interval time */ |
|
36 |
|
|
37 |
gpio_info_t input[GPIO_MAXIN]; /* GPIO input pins */ |
|
38 |
int incnt; /* GPIO input numbers */ |
|
39 |
int infrared_enable; /* infrared enable or not */ |
|
40 |
} gpio_t; |
|
41 |
|
|
42 |
extern int gpio_init(gpio_t *gpio); |
|
43 |
extern void gpio_term(void); |
|
44 |
|
|
45 |
/* turn which light on/off */ |
|
46 |
extern void gpio_out(char *name, char *cmd); |
|
47 |
|
|
48 |
|
|
49 |
/*thread work body to turn light $name on for some seconds */ |
|
50 |
void *light_on_worker(void *arg); |
|
51 |
|
|
52 |
/* Return value: 0(LOW): Nobody detected, !0: Which infrared detect incoming */ |
|
53 |
#define FLAG_INFRARED_INDOOR (1<<0) |
|
54 |
#define FLAG_INFRARED_HALLWAY (1<<1) |
|
55 |
extern int infrared_detect(void); |
|
56 |
|
|
57 |
#endif /* ----- #ifndef _GPIO_H_ ----- */ |
|
58 |
|