io.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef IO_H
  2. #define IO_H
  3. #ifdef __linux__
  4. #include <unistd.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <fcntl.h>
  11. #include <pthread.h>
  12. #define ARM 1
  13. #define BCM2708_PERI_BASE 0x20000000
  14. #define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <fcntl.h>
  18. #include <sys/mman.h>
  19. #include <unistd.h>
  20. #define PAGE_SIZE (4*1024)
  21. #define BLOCK_SIZE (4*1024)
  22. extern int mem_fd;
  23. extern void *gpio_map;
  24. // I/O access
  25. extern volatile unsigned *gpio;
  26. // GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
  27. #define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  28. #define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))
  29. #define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  30. #define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0
  31. #define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0
  32. #define GPIO_WRITE(gpio, value) ((value)?(GPIO_SET = 1 << gpio):(GPIO_CLR = 1 << gpio))
  33. #define GET_GPIO(g) ((*(gpio+13)&(1<<g))?1:0) // 0 if LOW, (1<<g) if HIGH
  34. #define GPIO_PULL *(gpio+37) // Pull up/pull down
  35. #define GPIO_PULLCLK0 *(gpio+38) // Pull up/pull down clock
  36. void setup_io();
  37. #else
  38. #include <Arduino.h>
  39. #include <avr/wdt.h>
  40. #include <avr/sleep.h>
  41. #include <avr/io.h>
  42. #include <avr/interrupt.h>
  43. #endif
  44. #endif