io.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 <time.h>
  11. #include <fcntl.h>
  12. #include <pthread.h>
  13. #define ARM 1
  14. #define BCM2708_PERI_BASE 0x20000000
  15. #define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <fcntl.h>
  19. #include <sys/mman.h>
  20. #include <unistd.h>
  21. #define PAGE_SIZE (4*1024)
  22. #define BLOCK_SIZE (4*1024)
  23. extern int mem_fd;
  24. extern void *gpio_map;
  25. /* I/O access */
  26. extern volatile unsigned *gpio;
  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)
  31. #define GPIO_CLR *(gpio+10)
  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)
  34. #define GPIO_PULL *(gpio+37)
  35. #define GPIO_PULLCLK0 *(gpio+38)
  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