-
Notifications
You must be signed in to change notification settings - Fork 0
/
port.s
75 lines (66 loc) · 1.36 KB
/
port.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
.macro _port_pcr port, base, i=0, m=31
def PORT\port\()_PCR\i, \base + (4 * \i), 32
.if \m - \i
.altmacro
_port_pcr \port, \base, %(\i + 1), \m
.noaltmacro
.endif
.endm
.macro _port port, base
_port_pcr \port, \base
def PORT\port\()_GPCLR, \base + 0x80, 32
def PORT\port\()_GPCHR, \base + 0x84, 32
def PORT\port\()_ISFR, \base + 0xA0, 32
.endm
_port A 0x40049000
_port B 0x4004A000
_port C 0x4004B000
_port D 0x4004C000
_port E 0x4004D000
.equiv ISF, 24
.equiv IRQC, 16
.equiv MUX, 8
.equiv DSE, 6
.equiv PFE, 4
.equiv SRE, 2
.equiv PE, 1
.equiv PS, 0
.equiv GPWE, 16
.equiv GPWD, 0
.macro port_cfg_map pin, keycode
.if PIN\pin\()_PORT == port
.if ((high == 1 && PIN\pin\()_NUM >= 16) || (high == 0 && PIN\pin\()_NUM < 16))
.set acc, acc | 1<<PIN\pin\()_NUM
.endif
.endif
.endm
/* IN r0 - desired Pin Control Register bits [15:0], will not be modified
* OUT r1 - scratch register, contents undefined
*/
.macro port_cfg port
.set port, \port
.set acc, 0
.set high, 0
.include "keymap.s"
.if acc > 0
val r1, acc << GPWE
orrs r1, r0
reg_write PORT\port\()_GPCLR, r1
.endif
.set acc, 0
.set high, 1
.include "keymap.s"
.if acc > 0
val r1, acc
orrs r1, r0
reg_write PORT\port\()_GPCHR, r1
.endif
.endm
.macro port_init
val r0, 1<<MUX | 1<<PE | 1<<PS
port_cfg A
port_cfg B
port_cfg C
port_cfg D
port_cfg E
.endm