12345678910111213141516171819202122232425262728293031323334353637383940 |
- #ifndef GPIO_RAW_H
- #define GPIO_RAW_H
- #define BCM2708_PERI_BASE 0x20000000
- #define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
-
- #include <dirent.h>
- #include <fcntl.h>
- #include <assert.h>
- #include <sys/mman.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <stdlib.h>
-
- #include <unistd.h>
-
- #define PAGE_SIZE (4*1024)
- #define BLOCK_SIZE (4*1024)
-
- extern int mem_fd;
- extern char *gpio_mem, *gpio_map;
- extern char *spi0_mem, *spi0_map;
-
-
- // I/O access
- extern volatile unsigned *gpio;
-
- // GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
- #define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
- #define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))
- #define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
-
- #define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0
- #define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0
- #define GPIO_LEV *(gpio+13)
- #define GPIO_VALUE_R(ALL, PIN) ((ALL & (1 << PIN)) != 0)
- #define GPIO_VALUE(PIN) GPIO_VALUE_R(GPIO_LEV, PIN)
-
- bool setup_io();
-
- #endif // GPIO_RAW_H
|