guowenxue
2021-04-21 e0e3a637e92dbe3c7700cc541410ff19b3b0c80c
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
/*********************************************************************************
 *      Copyright:  (C) 2019 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  gpio.h
 *    Description:  This file is GPIO input/output functions
 *                 
 *        Version:  1.0.0(2019年06月24日)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "2019年06月24日 23时46分47秒"
 *                 
 ********************************************************************************/
 
#ifndef  _GPIO_H_
#define  _GPIO_H_
 
#include <gpiod.h>
 
#define OFF   0
#define ON    1
 
#define GPIO_MAXOUT         8
#define GPIO_MAXIN          4
 
typedef struct gpio_info_s
{
    char                 name[32];      /*  GPIO connected module name */
    int                  pin;           /*  GPIO BCM pin number */
    int                  active_level;  /*  active power level */
    struct gpiod_line   *line;          /*  gpiod line */
} gpio_info_t;
 
 
typedef struct gpio_s 
{
    gpio_info_t          output[GPIO_MAXOUT]; /* GPIO output pins */
    int                  outcnt;              /* GPIO output numbers */
    int                  light_intval;        /* light on interval time */
 
    gpio_info_t          input[GPIO_MAXIN];   /* GPIO input pins */
    int                  incnt;               /* GPIO input numbers */
} gpio_t; 
 
extern int gpio_init(gpio_t *gpio);
extern void gpio_term(void);
 
 
/* turn which light on/off */
extern void turn_light(int which, int cmd);
 
/* turn which led on/off */
extern void turn_led(int which, int cmd);
 
/* Return value: 0(LOW): Nobody detected, !0: Which infrared detect incoming */
extern int infrared_detect(void);
 
#endif   /* ----- #ifndef _GPIO_H_  ----- */