Subversion Repositories Projects

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

#ifndef _GPIO_H
 #define _GPIO_H

#define BCM2708_PERI_BASE       0x20000000
#define GPIO_BASE               (BCM2708_PERI_BASE + 0x200000)  // GPIO controller
#define BLOCK_SIZE                              (4*1024)

extern struct bcm2835_peripheral gpio;  

// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x)
#define INP_GPIO(g)               *(gpio.addr + ((g)/10)) &= ~(7<<(((g)%10)*3))
#define OUT_GPIO(g)               *(gpio.addr + ((g)/10)) |=  (1<<(((g)%10)*3))
#define SET_GPIO_ALT(g,a)       *(gpio.addr + (((g)/10))) |= (((a)<=3?(a) + 4:(a)==4?3:2)<<(((g)%10)*3))
#define GPIO_SET                            *(gpio.addr + 7)  // sets   bits which are 1 ignores bits which are 0
#define GPIO_CLR                            *(gpio.addr + 10) // clears bits which are 1 ignores bits which are 0
#define GPIO_READ(g)              *(gpio.addr + 13) &= (1<<(g))

// Exposes the physical address defined in the passed structure using mmap on /dev/mem
extern void gpio_init();
extern void buzzer_short(int seq);

#endif //_GPIO_H