aboutsummaryrefslogtreecommitdiff
path: root/examples/efm32/tinygecko/efm32-tg-stk3300/lcd_demo/generate_lcd_mapping.py
blob: 1b6405f58bc5c6836b689d2163915704361c554f (plain)
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
#!/usr/bin/env python

import yaml

class Font(dict):
    def __init__(self, letterdict):
        for (k, v) in letterdict.items():
            self[k] = set(v.split())

class Display(object):
    def __init__(self, data):
        self.mapping = {}

        for c, segs in enumerate(data['coms']):
            for s, name in enumerate(segs):
                self.mapping[name] = (c, s)

    def render_text(self, text, symbols, font):
        cursor = 1
        segments = set()
        for letter in text:
            if letter == '.':
                segments.add("a%s_dp"%(cursor-1))
            elif letter == ':':
                segments.add("a%s_colon"%(cursor-1))
            elif letter in font:
                for segment in font[letter]:
                    segments.add("a%s_%s"%(cursor, segment))
                cursor += 1

        for s in symbols:
            segments.add(s)

        coms = {}
        for segment in segments:
            com, seg = self.mapping[segment]
            coms[com] = coms.get(com, 0) | (1<<seg)

        return coms

def main():
    data = yaml.load(open("lcd_mapping.yaml"))

    d = Display(data)

    text = "{FNORD}"
    symbols = ['gecko']
    f = Font({
        '-': 'g1 g2',
        'A': 'e f a b c g1 g2',
        'C': 'a f e d',
        'D': 'a b c d i l',
        'E': 'a f g1 g2 e d',
        'F': 'a f g1 g2 e',
        'H': "f b g1 g2 e c",
        'I': "i l a d",
        'L': 'f e d',
        'M': 'e f h j b c',
        'N': 'e f h m c b',
        'O': 'a f e d c b',
        'R': 'a e f g1 j m',
        'T': 'i l a',
        'U': 'f e d c b',
        '[': 'a d e f',
        ']': 'a b c d',
        '{': 'a d k h g1',
        '}': 'a j g2 m d',
        })

    for com, data in d.render_text(text, symbols, f).items():
        print "set_bank(%d, %#08.0x);"%(com, data)
#    with open('lcd_mapping.c', 'w') as outfile:
#        for symbol in data['symbols']:

if __name__ == "__main__":
    main()