Skip to content

Commit 4b884cf

Browse files
committed
scripts/mtl_ecspy_to_c.py: parse both gpcr and gcr regs
Signed-off-by: Filip Gołaś <filip.golas@3mdeb.com>
1 parent e27c224 commit 4b884cf

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

scripts/mtl_ecspy_to_c.py

+27-15
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,43 @@
1010
lines = open(ecspy_log).readlines()
1111
gpio_data = {}
1212

13-
# Regular expression to parse each line
14-
line_re = re.compile(r"([A-M]\d): data (\d) mirror (\d) pot (\d) control ([0-9A-Fa-f]{2})")
13+
# returns a list of positions of bits set to 1 in the integer
14+
def int_to_bits(n):
15+
return [i for i in range(n.bit_length()) if n & (1 << i)]
1516

17+
# Regular expression to parse each line
18+
gpr_line_re = re.compile(r"([A-M]\d): data (\d) mirror (\d) pot (\d) control ([0-9A-Fa-f]{2})")
19+
gcr_line_re = re.compile(r"GCR(\d): 0x([0-9A-Fa-f]{2})")
1620
gpr_grouped = {}
21+
gcr_grouped = {}
1722
for line in lines:
18-
match = line_re.match(line)
19-
if match:
23+
match_gpr = gpr_line_re.match(line)
24+
match_gcr = gcr_line_re.match(line)
25+
if match_gpr:
2026
gpr = {}
21-
gpr['pin'] = match.group(1)
22-
gpr['data'] = int(match.group(2))
23-
gpr['mirror'] = int(match.group(3))
24-
gpr['pot'] = int(match.group(4))
25-
gpr['control'] = int(match.group(5), 16)
27+
gpr['pin'] = match_gpr.group(1)
28+
gpr['data'] = int(match_gpr.group(2))
29+
gpr['mirror'] = int(match_gpr.group(3))
30+
gpr['pot'] = int(match_gpr.group(4))
31+
gpr['control'] = int(match_gpr.group(5), 16)
2632

2733
port = gpr['pin'][0]
2834
port_number = int(gpr['pin'][1])
2935

3036
if port not in gpr_grouped:
3137
gpr_grouped[port] = {}
3238
gpr_grouped[port][port_number] = gpr
33-
34-
39+
if match_gcr:
40+
gcr = {}
41+
gcr['number'] = int(match_gcr.group(1))
42+
gcr['value'] = int(match_gcr.group(2), 16)
43+
if gcr['number'] not in gcr_grouped:
44+
gcr_grouped[gcr['number']] = gcr
45+
46+
print("GPR:")
3547
for group in gpr_grouped:
36-
print(gpr_grouped[group])
37-
for reg in group:
38-
print(reg)
39-
48+
print(f"\n{group}: {gpr_grouped[group]}")
49+
print("\n\nGCR:")
50+
for group in gcr_grouped:
51+
print(f"\n{group}: {gcr_grouped[group]}")
4052

0 commit comments

Comments
 (0)