You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gpio-raw.h 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef GPIO_RAW_H
  2. #define GPIO_RAW_H
  3. #define BCM2708_PERI_BASE 0x20000000
  4. #define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
  5. #include <dirent.h>
  6. #include <fcntl.h>
  7. #include <assert.h>
  8. #include <sys/mman.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <stdlib.h>
  12. #include <unistd.h>
  13. #define PAGE_SIZE (4*1024)
  14. #define BLOCK_SIZE (4*1024)
  15. extern int mem_fd;
  16. extern char *gpio_mem, *gpio_map;
  17. extern char *spi0_mem, *spi0_map;
  18. // I/O access
  19. extern volatile unsigned *gpio;
  20. // GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
  21. #define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  22. #define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))
  23. #define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  24. #define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0
  25. #define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0
  26. #define GPIO_LEV *(gpio+13)
  27. #define GPIO_VALUE_R(ALL, PIN) ((ALL & (1 << PIN)) != 0)
  28. #define GPIO_VALUE(PIN) GPIO_VALUE_R(GPIO_LEV, PIN)
  29. bool setup_io();
  30. #endif // GPIO_RAW_H