// // How to access GPIO registers from C-code on the Raspberry-Pi // Example program // 15-January-2012 // Dom and Gert // Revised: 15-Feb-2013 #ifndef __arm__ #define SKIP_GPIO #endif // Access from ARM Running Linux #define BCM2708_PERI_BASE 0x20000000 #define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */ #define PAGE_SIZE (4*1024) #define BLOCK_SIZE (4*1024) #define SER_DAT_PIN 26 #define SER_CLK_PIN 19 #define GATE_PIN 13 #define PAR_CLK_PIN 6 #define SENSE_PIN 5 #define SCROLL_BUF_LEN 4096 int mem_fd; void *gpio_map; typedef struct { char buf[3][40]; int should_buf, is_buf, keep_running; pthread_t thread_id; } t_display_data; typedef struct { char buf[SCROLL_BUF_LEN]; int start, len; } t_scroll_buffer; typedef struct { int update; char input[(SCROLL_BUF_LEN - 39) / 2]; int input_len, keep_running; pthread_t thread_id; } t_scroll_data; // I/O access 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_ALTER(a) *(gpio+((a)==0?10:7)) // alters (a==0: clear, else: set) bits which are 1 ignores bits which are 0 #define GET_GPIO(g) (*(gpio+13)&(1<