forked from imxrt-rs/imxrt-iomuxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaisy.py
executable file
·49 lines (36 loc) · 1.54 KB
/
daisy.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
#!/usr/bin/env python3
"""
Generate Daisy constants from an i.MX RT SVD file
Example usage: to create SPI-related Daisy constants,
./daisy.py path/to/imxrt.svd | grep LPSPI
Copy and paste the constants into a Rust module.
"""
import xml.etree.ElementTree as ET
def daisy_constant(iomuxc):
base_address = int(iomuxc.find("./baseAddress").text, 16)
for register in iomuxc.findall("./registers/register"):
name = register.find("./name").text
if "_SELECT_INPUT" in name:
name = name.replace("_SELECT_INPUT", "")
offset = int(register.find("./addressOffset").text, 16)
address = base_address + offset
for field in register.findall("./fields/field"):
for values in field.findall("./enumeratedValues/enumeratedValue"):
pad = values.find("./name").text
if "_ALT" in pad:
pad = pad[:-5] # _ALTx
daisy = int(values.find("./value").text, 16)
constant = f"pub const DAISY_{name}_{pad}: Daisy = Daisy::new({address:#010x} as *mut u32, {daisy});"
print(constant)
def search_iomuxces(path):
tree = ET.parse(path)
root = tree.getroot()
iomuxc = root.find("./peripherals/peripheral[name='IOMUXC']")
iomuxc_lpsr = root.find("./peripherals/peripheral[name='IOMUXC_LPSR']")
if iomuxc:
daisy_constant(iomuxc)
if iomuxc_lpsr:
daisy_constant(iomuxc_lpsr)
if __name__ == "__main__":
import sys
search_iomuxces(sys.argv[1])