| 1 | /* |
| 2 | Copyright (c) 2012-2021 Ben Croston |
| 3 | |
| 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 5 | this software and associated documentation files (the "Software"), to deal in |
| 6 | the Software without restriction, including without limitation the rights to |
| 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 8 | of the Software, and to permit persons to whom the Software is furnished to do |
| 9 | so, subject to the following conditions: |
| 10 | |
| 11 | The above copyright notice and this permission notice shall be included in all |
| 12 | copies or substantial portions of the Software. |
| 13 | |
| 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | int setup(void); |
| 24 | void setup_gpio(int gpio, int direction, int pud); |
| 25 | int gpio_function(int gpio); |
| 26 | void output_gpio(int gpio, int value); |
| 27 | int input_gpio(int gpio); |
| 28 | void set_rising_event(int gpio, int enable); |
| 29 | void set_falling_event(int gpio, int enable); |
| 30 | void set_high_event(int gpio, int enable); |
| 31 | void set_low_event(int gpio, int enable); |
| 32 | int eventdetected(int gpio); |
| 33 | void cleanup(void); |
| 34 | |
| 35 | #define SETUP_OK 0 |
| 36 | #define SETUP_DEVMEM_FAIL 1 |
| 37 | #define SETUP_MALLOC_FAIL 2 |
| 38 | #define SETUP_MMAP_FAIL 3 |
| 39 | #define SETUP_CPUINFO_FAIL 4 |
| 40 | #define SETUP_NO_PERI_ADDR 5 |
| 41 | |
| 42 | #define INPUT 1 // is really 0 for control register! |
| 43 | #define OUTPUT 0 // is really 1 for control register! |
| 44 | #define ALT0 4 |
| 45 | |
| 46 | #define HIGH 1 |
| 47 | #define LOW 0 |
| 48 | |
| 49 | #define PUD_OFF 0 |
| 50 | #define PUD_DOWN 1 |
| 51 | #define PUD_UP 2 |