]> git.sesse.net Git - pistorm/blob - gpio/gpio.h
IDE updates, fix mouse hook hotkey
[pistorm] / gpio / gpio.h
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
12
13 #define SA0 5
14 #define SA1 3
15 #define SA2 2
16
17 #define STATUSREGADDR  \
18   GPIO_CLR = 1 << SA0; \
19   GPIO_CLR = 1 << SA1; \
20   GPIO_SET = 1 << SA2;
21 #define W16            \
22   GPIO_CLR = 1 << SA0; \
23   GPIO_CLR = 1 << SA1; \
24   GPIO_CLR = 1 << SA2;
25 #define R16            \
26   GPIO_SET = 1 << SA0; \
27   GPIO_CLR = 1 << SA1; \
28   GPIO_CLR = 1 << SA2;
29 #define W8             \
30   GPIO_CLR = 1 << SA0; \
31   GPIO_SET = 1 << SA1; \
32   GPIO_CLR = 1 << SA2;
33 #define R8             \
34   GPIO_SET = 1 << SA0; \
35   GPIO_SET = 1 << SA1; \
36   GPIO_CLR = 1 << SA2;
37
38 #define PAGE_SIZE (4 * 1024)
39 #define BLOCK_SIZE (4 * 1024)
40
41 #define GPIOSET(no, ishigh) \
42   do {                      \
43     if (ishigh)             \
44       set |= (1 << (no));   \
45     else                    \
46       reset |= (1 << (no)); \
47   } while (0)
48
49 #define JOY0DAT 0xDFF00A
50 #define JOY1DAT 0xDFF00C
51 #define CIAAPRA 0xBFE001
52 #define CIAADAT 0xBFEC01
53 #define CIAAICR 0xBFED01
54 #define POTGOR  0xDFF016
55
56 // GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or
57 // SET_GPIO_ALT(x,y)
58 #define INP_GPIO(g) *(gpio + ((g) / 10)) &= ~(7 << (((g) % 10) * 3))
59 #define OUT_GPIO(g) *(gpio + ((g) / 10)) |= (1 << (((g) % 10) * 3))
60 #define SET_GPIO_ALT(g, a)  \
61   *(gpio + (((g) / 10))) |= \
62       (((a) <= 3 ? (a) + 4 : (a) == 4 ? 3 : 2) << (((g) % 10) * 3))
63
64 #define GPIO_SET \
65   *(gpio + 7)  // sets   bits which are 1 ignores bits which are 0
66 #define GPIO_CLR \
67   *(gpio + 10)  // clears bits which are 1 ignores bits which are 0
68
69 #define GET_GPIO(g) (*(gpio + 13) & (1 << g))  // 0 if LOW, (1<<g) if HIGH
70
71 #define GPIO_PULL *(gpio + 37)      // Pull up/pull down
72 #define GPIO_PULLCLK0 *(gpio + 38)  // Pull up/pull down clock
73
74 #define GPIO_HANDLE_IRQ \
75   if (GET_GPIO(1) == 0) { \
76     srdata = read_reg(); \
77     m68k_set_irq((srdata >> 13) & 0xff); \
78   } else { \
79     if ((gayle_int & 0x80) && (get_ide(0)->drive[0].intrq || get_ide(0)->drive[1].intrq)) { \
80       write16(0xdff09c, 0x8008); \
81       m68k_set_irq(2); \
82     } \
83     else \
84         m68k_set_irq(0); \
85   }; \
86
87 extern uint8_t gayle_int;
88 extern uint8_t gayle_a4k_int;
89
90 void setup_io();
91 void gpio_enable_200mhz();
92 void gpio_handle_irq();
93
94 int gpio_get_irq();
95
96 uint32_t read8(uint32_t address);
97 void write8(uint32_t address, uint32_t data);
98
99 uint32_t read16(uint32_t address);
100 void write16(uint32_t address, uint32_t data);
101
102 void write32(uint32_t address, uint32_t data);
103 uint32_t read32(uint32_t address);
104
105 uint16_t read_reg(void);
106 void write_reg(unsigned int value);