1 //#define BCM2708_PERI_BASE 0x20000000 //pi0-1
2 //#define BCM2708_PERI_BASE 0xFE000000 //pi4
3 #define BCM2708_PERI_BASE 0x3F000000 // pi3
4 #define BCM2708_PERI_SIZE 0x01000000
5 #define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
6 #define GPCLK_BASE (BCM2708_PERI_BASE + 0x101000)
7 #define GPIO_ADDR 0x200000 /* GPIO controller */
8 #define GPCLK_ADDR 0x101000
9 #define CLK_PASSWD 0x5a000000
10 #define CLK_GP0_CTL 0x070
11 #define CLK_GP0_DIV 0x074
17 #define STATUSREGADDR \
18 GPIO_CLR = 1 << SA0; \
19 GPIO_CLR = 1 << SA1; \
22 GPIO_CLR = 1 << SA0; \
23 GPIO_CLR = 1 << SA1; \
26 GPIO_SET = 1 << SA0; \
27 GPIO_CLR = 1 << SA1; \
30 GPIO_CLR = 1 << SA0; \
31 GPIO_SET = 1 << SA1; \
34 GPIO_SET = 1 << SA0; \
35 GPIO_SET = 1 << SA1; \
38 #define PAGE_SIZE (4 * 1024)
39 #define BLOCK_SIZE (4 * 1024)
41 #define GPIOSET(no, ishigh) \
46 reset |= (1 << (no)); \
49 #define JOY0DAT 0xDFF00A
50 #define JOY1DAT 0xDFF00C
51 #define CIAAPRA 0xBFE001
52 #define POTGOR 0xDFF016
54 // GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or
56 #define INP_GPIO(g) *(gpio + ((g) / 10)) &= ~(7 << (((g) % 10) * 3))
57 #define OUT_GPIO(g) *(gpio + ((g) / 10)) |= (1 << (((g) % 10) * 3))
58 #define SET_GPIO_ALT(g, a) \
59 *(gpio + (((g) / 10))) |= \
60 (((a) <= 3 ? (a) + 4 : (a) == 4 ? 3 : 2) << (((g) % 10) * 3))
63 *(gpio + 7) // sets bits which are 1 ignores bits which are 0
65 *(gpio + 10) // clears bits which are 1 ignores bits which are 0
67 #define GET_GPIO(g) (*(gpio + 13) & (1 << g)) // 0 if LOW, (1<<g) if HIGH
69 #define GPIO_PULL *(gpio + 37) // Pull up/pull down
70 #define GPIO_PULLCLK0 *(gpio + 38) // Pull up/pull down clock
73 void gpio_enable_200mhz();
74 void gpio_handle_irq();
76 uint32_t read8(uint32_t address);
77 void write8(uint32_t address, uint32_t data);
79 uint32_t read16(uint32_t address);
80 void write16(uint32_t address, uint32_t data);
82 void write32(uint32_t address, uint32_t data);
83 uint32_t read32(uint32_t address);
85 uint16_t read_reg(void);
86 void write_reg(unsigned int value);