andrewm@0: /* andrewm@0: * SimpleGPIO.h andrewm@0: * andrewm@0: * Copyright Derek Molloy, School of Electronic Engineering, Dublin City University andrewm@0: * www.derekmolloy.ie andrewm@0: * andrewm@0: * Based on Software by RidgeRun andrewm@0: * Copyright (c) 2011, RidgeRun andrewm@0: * All rights reserved. andrewm@0: * andrewm@0: * Redistribution and use in source and binary forms, with or without andrewm@0: * modification, are permitted provided that the following conditions are met: andrewm@0: * 1. Redistributions of source code must retain the above copyright andrewm@0: * notice, this list of conditions and the following disclaimer. andrewm@0: * 2. Redistributions in binary form must reproduce the above copyright andrewm@0: * notice, this list of conditions and the following disclaimer in the andrewm@0: * documentation and/or other materials provided with the distribution. andrewm@0: * 3. All advertising materials mentioning features or use of this software andrewm@0: * must display the following acknowledgement: andrewm@0: * This product includes software developed by the RidgeRun. andrewm@0: * 4. Neither the name of the RidgeRun nor the andrewm@0: * names of its contributors may be used to endorse or promote products andrewm@0: * derived from this software without specific prior written permission. andrewm@0: * andrewm@0: * THIS SOFTWARE IS PROVIDED BY RIDGERUN ''AS IS'' AND ANY andrewm@0: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED andrewm@0: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE andrewm@0: * DISCLAIMED. IN NO EVENT SHALL RIDGERUN BE LIABLE FOR ANY andrewm@0: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES andrewm@0: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; andrewm@0: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND andrewm@0: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT andrewm@0: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS andrewm@0: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. andrewm@0: */ andrewm@0: andrewm@0: #ifndef SIMPLEGPIO_H_ andrewm@0: #define SIMPLEGPIO_H_ andrewm@0: andrewm@0: /**************************************************************** andrewm@0: * Constants andrewm@0: ****************************************************************/ andrewm@0: andrewm@0: #define SYSFS_GPIO_DIR "/sys/class/gpio" andrewm@0: #define SYSFS_LED_DIR "/sys/class/leds" andrewm@0: #define POLL_TIMEOUT (3 * 1000) /* 3 seconds */ andrewm@0: #define MAX_BUF 128 andrewm@0: andrewm@0: enum PIN_DIRECTION{ andrewm@0: INPUT_PIN=0, andrewm@0: OUTPUT_PIN=1 andrewm@0: }; andrewm@0: andrewm@0: enum PIN_VALUE{ andrewm@0: LOW=0, andrewm@0: HIGH=1 andrewm@0: }; andrewm@0: andrewm@0: /**************************************************************** andrewm@0: * gpio_functions andrewm@0: ****************************************************************/ andrewm@0: int gpio_setup(unsigned int gpio, int out_flag); andrewm@0: int gpio_export(unsigned int gpio); andrewm@0: int gpio_unexport(unsigned int gpio); andrewm@0: int gpio_set_dir(unsigned int gpio, int out_flag); andrewm@0: int gpio_set_value(unsigned int gpio, int value); andrewm@0: int gpio_get_value(unsigned int gpio, unsigned int *value); andrewm@0: int gpio_set_edge(unsigned int gpio, char *edge); andrewm@0: int gpio_fd_open(unsigned int gpio, int writeFlag); andrewm@0: int gpio_fd_close(int fd); andrewm@0: int gpio_write(int fd, int value); andrewm@0: int gpio_read(int fd, unsigned int *value); andrewm@0: int gpio_dismiss(int fd, unsigned int gpio); andrewm@0: andrewm@0: int led_set_trigger(unsigned int lednum, const char *trigger); andrewm@0: andrewm@0: #endif /* SIMPLEGPIO_H_ */