comparison include/GPIOcontrol.h @ 0:8a575ba3ab52

Initial commit.
author andrewm
date Fri, 31 Oct 2014 19:10:17 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8a575ba3ab52
1 /*
2 * SimpleGPIO.h
3 *
4 * Copyright Derek Molloy, School of Electronic Engineering, Dublin City University
5 * www.derekmolloy.ie
6 *
7 * Based on Software by RidgeRun
8 * Copyright (c) 2011, RidgeRun
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the RidgeRun.
21 * 4. Neither the name of the RidgeRun nor the
22 * names of its contributors may be used to endorse or promote products
23 * derived from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY RIDGERUN ''AS IS'' AND ANY
26 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL RIDGERUN BE LIABLE FOR ANY
29 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #ifndef SIMPLEGPIO_H_
38 #define SIMPLEGPIO_H_
39
40 /****************************************************************
41 * Constants
42 ****************************************************************/
43
44 #define SYSFS_GPIO_DIR "/sys/class/gpio"
45 #define SYSFS_LED_DIR "/sys/class/leds"
46 #define POLL_TIMEOUT (3 * 1000) /* 3 seconds */
47 #define MAX_BUF 128
48
49 enum PIN_DIRECTION{
50 INPUT_PIN=0,
51 OUTPUT_PIN=1
52 };
53
54 enum PIN_VALUE{
55 LOW=0,
56 HIGH=1
57 };
58
59 /****************************************************************
60 * gpio_functions
61 ****************************************************************/
62 int gpio_setup(unsigned int gpio, int out_flag);
63 int gpio_export(unsigned int gpio);
64 int gpio_unexport(unsigned int gpio);
65 int gpio_set_dir(unsigned int gpio, int out_flag);
66 int gpio_set_value(unsigned int gpio, int value);
67 int gpio_get_value(unsigned int gpio, unsigned int *value);
68 int gpio_set_edge(unsigned int gpio, char *edge);
69 int gpio_fd_open(unsigned int gpio, int writeFlag);
70 int gpio_fd_close(int fd);
71 int gpio_write(int fd, int value);
72 int gpio_read(int fd, unsigned int *value);
73 int gpio_dismiss(int fd, unsigned int gpio);
74
75 int led_set_trigger(unsigned int lednum, const char *trigger);
76
77 #endif /* SIMPLEGPIO_H_ */