-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_gen_io.py
executable file
·189 lines (165 loc) · 2.1 KB
/
code_gen_io.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python3
io_regs = """
PINB 0x23
DDRB 0x24
PORTB 0x25
PINC 0x26
DDRC 0x27
PORTC 0x28
PIND 0x29
DDRD 0x2a
PORTD 0x2b
PINE 0x2c
DDRE 0x2d
PORTE 0x2e
PINF 0x2f
DDRF 0x30
PORTF 0x31
TIFR1 0x35
TIFR0 0x36
TIFR3 0x38
TIFR4 0x39
PCIFR 0x3b
EIFR 0x3c
EIMSK 0x3d
GPIOR0 0x3e
EECR 0x3f
EEDR 0x40
EEARL 0x41
EEARH 0x42
GTCCR 0x43
TCCR0A 0x44
TCCR0B 0x45
TCNT0 0x46
OCR0A 0x47
OCR0B 0x48
PLLCSR 0x49
GPIOR1 0x4a
GPIOR2 0x4b
SPCR 0x4c
SPSR 0x4d
SPDR 0x4e
ACSR 0x50
OCDR_MONDR 0x51
PLLFRQ 0x52
SMCR 0x53
MCUSR 0x54
MCUCR 0x55
SPMCSR 0x57
RAMPZ 0x5b
SPL 0x5d
SPH 0x5e
SREG 0x5f
WDTCSR 0x60
CLKPR 0x61
PRR0 0x64
PRR1 0x65
OSCCAL 0x66
RCCTRL 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s.split('\n'):
if len(io_reg) == 0 or io_reg[0] == '#':
continue
[reg, addr] = io_reg.split()
print(f'pub const {reg}: u16 = {addr};')
print()
print('match addr {')
for io_reg in io_regs.split('\n'):
if len(io_reg) == 0 or io_reg[0] == '#':
continue
[reg, addr] = io_reg.split()
print(f' {addr} => Some("{reg}"),')
print(' _ => None,')
print('}')