1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #ifndef IO_H
- #define IO_H
- #ifdef __linux__
-
- #include <unistd.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <time.h>
- #include <fcntl.h>
- #include <pthread.h>
- //#define ARM 1
- #define BCM2708_PERI_BASE 0x20000000
- #define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <sys/mman.h>
- #include <unistd.h>
-
- #define PAGE_SIZE (4*1024)
- #define BLOCK_SIZE (4*1024)
-
- extern int mem_fd;
- extern void *gpio_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_WRITE(gpio, value) ((value)?(GPIO_SET = 1 << gpio):(GPIO_CLR = 1 << gpio))
-
- #define GET_GPIO(g) ((*(gpio+13)&(1<<g))?1:0) // 0 if LOW, (1<<g) if HIGH
-
- #define GPIO_PULL *(gpio+37) // Pull up/pull down
- #define GPIO_PULLCLK0 *(gpio+38) // Pull up/pull down clock
- void setup_io();
- #else
- #include <Arduino.h>
- #include <avr/wdt.h>
- #include <avr/sleep.h>
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #endif
- #endif
|