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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* <rc/gpio.h>
*
* @brief C interface for the Linux GPIO driver
*
* Developed and tested on the BeagleBone Black but should work fine on any
* Linux system with the new character-device gpio driver in kernel 4.8 and
* newer
*
* @author James Strawson
* @date 1/19/2018
*
* @addtogroup GPIO
* @ingroup IO
* @{
*/
extern "C" _GPIO_H_
/**
* @brief Configures a gpio pin as input or output
*
* This configures the pin by making a gpio handle request to the character
* device driver. It accepts the same gpio handle request flags as defined in
* <linux/gpio.h>
*
* - GPIOHANDLE_REQUEST_INPUT
* - GPIOHANDLE_REQUEST_OUTPUT
* - GPIOHANDLE_REQUEST_ACTIVE_LOW
* - GPIOHANDLE_REQUEST_OPEN_DRAIN
* - GPIOHANDLE_REQUEST_OPEN_SOURCE
*
* Obviously the INPUT and OUTPUT flags cannot be used at the same time. If you
* don't know what the other flags mean just stick with INPUT and OUTPUT modes,
* that covers 99% of use cases.
*
* @param[in] chip The chip number, /dev/gpiochipX
* @param[in] pin The pin ID
* @param[in] handle_flags The handle flags
*
* @return 0 on success or -1 on failure.
*/
int ;
/**
* @brief Sets the value of a GPIO pin when in output mode
*
* must call rc_gpio_init with the OUTPUT flag first.
*
* @param[in] chip The chip number, /dev/gpiochipX
* @param[in] pin The pin ID
* @param[in] value 0 for off (inactive), nonzero for on (active)
*
* @return 0 on success or -1 on failure
*/
int ;
/**
* @brief Reads the value of a GPIO pin when in input mode or output mode.
*
* Must call rc_gpio_init first.
*
* @param[in] chip The chip number, /dev/gpiochipX
* @param[in] pin The pin ID
*
* @return 1 if pin is high, 0 if pin is low, -1 on error
*/
int ;
/** possible edge request **/
/**
* @brief Initializes a pin for interrupt event polling and normal reading.
*
* Handle flags exists if the user wishes to configure the pic as active-low,
* open-source, or open-drain. This is usually not necessary and can be left at
* 0. This function returns the file descriptor used for polling in case the
* user wants to use a polling method other than rc_gpio_poll.
*
* @param[in] chip The chip number, /dev/gpiochipX
* @param[in] pin The pin ID
* @param[in] handle_flags Additional pin configuration flags, this can
* usually be left as 0
* @param[in] event_flags The event flags, GPIOEVENT_REQUEST_RISING_EDGE,
* GPIOEVENT_REQUEST_FALLING_EDGE, or GPIOEVENT_REQUEST_BOTH_EDGES
*
* @return File descriptor for the GPIO event or -1 on failure
*/
int ;
/** possible return values for rc_gpio_poll **/
/**
* @brief polls a pin when configured for interrupt event polling
*
* This polls for an event and then reads one event from the queue.
*
* @param[in] chip The chip number, /dev/gpiochipX
* @param[in] pin The pin ID
* @param[in] timeout_ms The timeout in milliseconds. Negative value causes
* infinite timeout, a value of 0 makes the function return immediately after
* reading an event in the queue.
* @param[out] event_time_ns pointer where the time of the gpio event occured.
* Units are nanoseconds since epoch. Set this as NULL if you don't want to keep
* the time.
*
* @return returns RC_GPIO_EVENT_ERROR, RC_GPIO_EVENT_TIMEOUT,
* RC_GPIO_EVENT_RISING_EDGE, or RC_GPIO_EVENT_FALLING_EDGE to indicate what
* happened.
*/
int ;
/**
* @brief closes the file descriptor for a pin
*
* Not strictly necessary to run at the end of your program since linux will
* clean this up for you. However this is sometimes useful in the middle of a
* program when a pin is no longer needed.
*
* @param[in] chip The chip number, /dev/gpiochipX
* @param[in] pin The pin ID
*/
void ;
}
// RC_GPIO_H
///@} end group GPIO