Created
January 9, 2017 22:31
-
-
Save adrienthebo/1a9fcdc86a9042e107b35f5c5bb4f00b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* The peripheral base offset varies between the RPi 2 and 3. | |
* * RPi 2: 0x20000000 | |
* * RPi 3: 0x3F000000 | |
*/ | |
#define BCM2708_PERI_BASE 0x3F000000 | |
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */ | |
#define PAGE_SIZE (4*1024) | |
#define BLOCK_SIZE (4*1024) | |
// I/O access | |
static 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 GET_GPIO(g) (*(gpio+13)&(1<<g)) // 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment