2 * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
3 * Copyright (c) 2014 Intel Corporation.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * @brief General Purpose IO
31 * Gpio is the General Purpose IO interface to libmraa. Its features depend on
32 * the board type used, it can use gpiolibs (exported via a kernel module
33 * through sysfs), or memory mapped IO via a /dev/uio device or /dev/mem
34 * depending again on the board configuration.
36 * @snippet gpio_read6.c Interesting
53 * Opaque pointer definition to the internal struct _gpio
55 typedef struct _gpio* mraa_gpio_context;
61 MRAA_GPIO_STRONG = 0, /**< Default. Strong high and low */
62 MRAA_GPIO_PULLUP = 1, /**< Resistive High */
63 MRAA_GPIO_PULLDOWN = 2, /**< Resistive Low */
64 MRAA_GPIO_HIZ = 3 /**< High Z State */
68 * Gpio Direction options
71 MRAA_GPIO_OUT = 0, /**< Output. A Mode can also be set */
72 MRAA_GPIO_IN = 1, /**< Input */
73 MRAA_GPIO_OUT_HIGH = 2, /**< Output. Init High */
74 MRAA_GPIO_OUT_LOW = 3 /**< Output. Init Low */
78 * Gpio Edge types for interupts
81 MRAA_GPIO_EDGE_NONE = 0, /**< No interrupt on Gpio */
82 MRAA_GPIO_EDGE_BOTH = 1, /**< Interupt on rising & falling */
83 MRAA_GPIO_EDGE_RISING = 2, /**< Interupt on rising only */
84 MRAA_GPIO_EDGE_FALLING = 3 /**< Interupt on falling only */
88 * Initialise gpio_context, based on board number
90 * @param pin Pin number read from the board, i.e IO3 is 3
91 * @returns gpio context or NULL
93 mraa_gpio_context mraa_gpio_init(int pin);
96 * Initialise gpio context without any mapping to a pin
98 * @param gpiopin gpio pin as listed in SYSFS
99 * @return gpio context or NULL
101 mraa_gpio_context mraa_gpio_init_raw(int gpiopin);
104 * Set the edge mode on the gpio
106 * @param dev The Gpio context
107 * @param mode The edge mode to set the gpio into
108 * @return Result of operation
110 mraa_result_t mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode);
113 * Set an interupt on pin
115 * @param dev The Gpio context
116 * @param edge The edge mode to set the gpio into
117 * @param fptr Function pointer to function to be called when interupt is
119 * @param args Arguments passed to the interrupt handler (fptr)
120 * @return Result of operation
122 mraa_result_t mraa_gpio_isr(mraa_gpio_context dev, mraa_gpio_edge_t edge, void (*fptr)(void*), void* args);
125 * Stop the current interupt watcher on this Gpio, and set the Gpio edge mode
126 * to MRAA_GPIO_EDGE_NONE
128 * @param dev The Gpio context
129 * @return Result of operation
131 mraa_result_t mraa_gpio_isr_exit(mraa_gpio_context dev);
134 * Set Gpio Output Mode,
136 * @param dev The Gpio context
137 * @param mode The Gpio Output Mode
138 * @return Result of operation
140 mraa_result_t mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode);
145 * @param dev The Gpio context
146 * @param dir The direction of the Gpio
147 * @return Result of operation
149 mraa_result_t mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir);
152 * Close the Gpio context
153 * - Will free the memory for the context and unexport the Gpio
155 * @param dev The Gpio context
156 * @return Result of operation
158 mraa_result_t mraa_gpio_close(mraa_gpio_context dev);
161 * Read the Gpio value. This can be 0 or 1. A resonse of -1 means that there
164 * @param dev The Gpio context
165 * @return Result of operation
167 int mraa_gpio_read(mraa_gpio_context dev);
170 * Write to the Gpio Value.
172 * @param dev The Gpio context
173 * @param value Integer value to write
174 * @return Result of operation
176 mraa_result_t mraa_gpio_write(mraa_gpio_context dev, int value);
179 * Change ownership of the context.
181 * @param dev The Gpio context
182 * @param owner Does this context own the pin
183 * @return Result of operation
185 mraa_result_t mraa_gpio_owner(mraa_gpio_context dev, mraa_boolean_t owner);
188 * Enable using memory mapped io instead of sysfs
190 * @param dev The Gpio context
191 * @param mmap Use mmap instead of sysfs
192 * @return Result of operation
194 mraa_result_t mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap);
197 * Get a pin number of the gpio, invalid will return -1
199 * @param dev The Gpio context
202 int mraa_gpio_get_pin(mraa_gpio_context dev);
205 * Get a gpio number as used within sysfs, invalid will return -1
207 * @param dev The Gpio context
208 * @return gpio number
210 int mraa_gpio_get_pin_raw(mraa_gpio_context dev);