summaryrefslogtreecommitdiff
path: root/helper/convert-stm32.py
blob: 73c4a2eb7f8ef5cf730dd4524cf49848d0e30d80 (plain) (blame)
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
print('DEF STM32F429BIT6_1 IC 0 40 Y Y 4 F N')
print('F1 "" 0 0 60 H V C CNN')
print('F2 "" 0 0 60 H V C CNN')
print('F3 "" 0 0 60 H V C CNN')
print('DRAW')

def print_rec(r):
    for i in range(len(r)):
        ri = r[i]
        if i > 0: print(' ', end='')
        print(ri, end='')
        
    print("\n", end='')

SKIP_REC_TYPES = ['#', 'F0', 'F1', 'F2', 'F3', 'DRAW', 'ENDDRAW', 'ENDDEF']

with open('stm32.old', 'r') as f_rd:
    f_rd_lines = f_rd.readlines()
    
    for f_rd_line in f_rd_lines:
        rd_line = f_rd_line.strip()
        
        rec = rd_line.split(' ')
        rec_type = rec[0]
    
        #
        # DEF
        #
        if rec_type == "DEF":
            unit = rec[1].split('_')[1]
            continue

        #
        # T
        #
        if rec_type == "T":
            rec[6] = unit
            print_rec(rec)
            continue
        
        #
        # P
        #
        if rec_type == "P":
            rec[2] = unit
            print_rec(rec)
            continue
        
        #
        # X
        #
        if rec_type == "X":
            rec[-3] = unit
            print_rec(rec)
            continue

        if rec_type in SKIP_REC_TYPES: continue
        else: raise RuntimeError("rec_type == '%s'" % rec_type)    
    
        print(rd_line)
        

print('ENDDRAW')
print('ENDDEF')