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 * This file defines the gpio interface for libmaa
46 * A strucutre representing a gpio pin.
51 int pin; /**< the pin number, as known to the os. */
52 int value_fp; /**< the file pointer to the value of the gpio */
54 PyObject *isr; /**< the interupt service request */
56 void (* isr)(); /**< the interupt service request */
58 pthread_t thread_id; /**< the isr handler thread id */
59 int isr_value_fp; /**< the isr file pointer on the value */
67 MAA_GPIO_STRONG = 0, /**< Default. Strong high and low */
68 MAA_GPIO_PULLUP = 1, /**< Resistive High */
69 MAA_GPIO_PULLDOWN = 2, /**< Resistive Low */
70 MAA_GPIO_HIZ = 3 /**< High Z State */
74 * GPIO Direction options.
77 MAA_GPIO_OUT = 0, /**< Output. A Mode can also be set */
78 MAA_GPIO_IN = 1 /**< Input. */
82 MAA_GPIO_EDGE_NONE = 0, /**< No interrupt on GPIO */
83 MAA_GPIO_EDGE_BOTH = 1, /**< Interupt on rising & falling */
84 MAA_GPIO_EDGE_RISING = 2, /**< Interupt on rising only */
85 MAA_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.
92 * @returns maa_gpio_context based on the IO pin
94 maa_gpio_context* maa_gpio_init(int pin);
96 /** Initialise gpio context without any mapping to a pin.
97 * - For more expert users
99 * @param gpiopin gpio pin as listed in SYSFS
101 * @return gpio context
103 maa_gpio_context* maa_gpio_init_raw(int gpiopin);
105 /** Set the edge mode on the gpio
107 * @param dev The GPIO context
108 * @param mode The edge mode to set the gpio into
110 * @return maa result type.
112 maa_result_t maa_gpio_edge_mode(maa_gpio_context *dev, gpio_edge_t mode);
114 /** Set an interupt on pin
116 * @param dev The GPIO context
117 * @param mode The edge mode to set the gpio into
118 * @param fptr Function pointer to function to be called when interupt is
121 * @return maa result type.
124 maa_gpio_isr(maa_gpio_context *dev, gpio_edge_t edge, void (*fptr)(void));
126 /** Stop the current interupt watcher on this GPIO, and set the GPIO edge mode
127 * to MAA_GPIO_EDGE_NONE.
129 * @param dev The GPIO context.
131 * @return maa result type.
134 maa_gpio_isr_exit(maa_gpio_context *dev);
136 /** Set GPIO Output Mode,
138 * @param dev The GPIO context
139 * @param mode The GPIO Output Mode.
141 * @return maa result type.
143 maa_result_t maa_gpio_mode(maa_gpio_context *dev, gpio_mode_t mode);
145 /** Set GPIO direction
147 * @param dev The GPIO context.
148 * @param dir The direction of the GPIO.
150 * @return maa result type.
152 maa_result_t maa_gpio_dir(maa_gpio_context *dev, gpio_dir_t dir);
154 /** Close the GPIO context
155 * - Will free the memory for the context and unexport the GPIO
157 * @param dev the GPIO context
159 * @return maa result type.
161 maa_result_t maa_gpio_close(maa_gpio_context *dev);
163 /** Unexport the GPIO context (maa_gpio_close() will call this function)
165 * @param dev The GPIO context.
167 * @return maa result type.
169 maa_result_t maa_gpio_unexport(maa_gpio_context *dev);
171 /** Read the GPIO value.
173 * @param dev The GPIO context.
175 * @return the integer value of the GPIO
177 int maa_gpio_read(maa_gpio_context *dev);
179 /** Write to the GPIO Value.
181 * @param dev The GPIO context.
182 * @param value Integer value to write.
184 * @return maa result type
186 maa_result_t maa_gpio_write(maa_gpio_context *dev, int value);