2 * Author: Brendan Le Foll <brendan.le.foll@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 C++ interface for libmaa
37 // These enums must match the enums in gpio.h
59 Gpio(int pin, bool owner=true, bool raw=false) {
61 m_gpio = maa_gpio_init_raw(pin);
63 m_gpio = maa_gpio_init(pin);
65 maa_gpio_owner(m_gpio, 0);
68 maa_result_t x = maa_gpio_close(m_gpio);
70 maa_result_t edge(Edge mode) {
71 return maa_gpio_edge_mode(m_gpio, (gpio_edge_t) mode);
73 #if defined(SWIGPYTHON)
74 maa_result_t isr(Edge mode, PyObject *pyfunc) {
75 return maa_gpio_isr(m_gpio, (gpio_edge_t) mode, (void (*) ()) pyfunc);
78 maa_result_t isr(Edge mode, void (*fptr)(void)) {
79 return maa_gpio_isr(m_gpio, (gpio_edge_t) mode, fptr);
82 maa_result_t isr_exit() {
83 return maa_gpio_isr_exit(m_gpio);
85 maa_result_t mode(Mode mode) {
86 return maa_gpio_mode(m_gpio, (gpio_mode_t) mode);
88 maa_result_t dir(Dir dir) {
89 return maa_gpio_dir(m_gpio, (gpio_dir_t) dir);
92 return maa_gpio_read(m_gpio);
94 int write(int value) {
95 return maa_gpio_write(m_gpio, value);
98 maa_gpio_context m_gpio;