1
1
#!/usr/bin/env python3
2
+ # Script to generate the mapping of LEDs to the CS and SW registers of the
3
+ # IS31FL3741A controller.
4
+ #
5
+ # The output looks like:
6
+ # (0x00, 0), // x:1, y:1, sw:1, cs:1, id:1
7
+ # (0x1e, 0), // x:2, y:1, sw:2, cs:1, id:2
8
+ # [...]
2
9
3
10
from dataclasses import dataclass
4
11
12
+ WIDTH = 9
13
+ HEIGHT = 34
14
+
5
15
6
16
@dataclass
7
17
class Led :
@@ -14,6 +24,7 @@ class Led:
14
24
cs : int
15
25
16
26
def led_register (self ):
27
+ # See the IS31FL3741A for how the data pages are separated
17
28
if self .cs <= 30 and self .sw >= 7 :
18
29
page = 1
19
30
register = self .cs - 1 + (self .sw - 7 ) * 30
@@ -22,63 +33,64 @@ def led_register(self):
22
33
register = self .cs - 1 + (self .sw - 1 ) * 30
23
34
if self .cs >= 31 :
24
35
page = 1
25
- register = 0x5a + self .cs - 31 + (self .sw - 1 ) * 9
36
+ register = 0x5A + self .cs - 31 + (self .sw - 1 ) * 9
26
37
return (register , page )
27
38
28
39
29
40
def get_leds ():
30
41
leds = []
31
42
43
+ # Generate LED mapping as how they are mapped in the Lotus LED Matrix Module
44
+
32
45
# First down and then right
33
46
# CS1 through CS4
34
47
for cs in range (1 , 5 ):
35
- for sw in range (1 , 10 ):
36
- leds .append (Led (id = 9 * (cs - 1 ) + sw , x = sw , y = cs , sw = sw , cs = cs ))
48
+ for sw in range (1 , WIDTH + 1 ):
49
+ leds .append (Led (id = WIDTH * (cs - 1 ) + sw , x = sw , y = cs , sw = sw , cs = cs ))
37
50
38
51
# First right and then down
39
52
# CS5 through CS7
40
53
base_cs = 4
41
- base_id = 9 * base_cs
54
+ base_id = WIDTH * base_cs
42
55
for cs in range (1 , 5 ):
43
- for sw in range (1 , 10 ):
56
+ for sw in range (1 , WIDTH + 1 ):
44
57
leds .append (Led (id = base_id + 4 * (sw - 1 ) + cs , x = sw ,
45
58
y = cs + base_cs , sw = sw , cs = cs + base_cs ))
46
59
47
60
# First right and then down
48
61
# CS9 through CS16
49
62
base_cs = 8
50
- base_id = 9 * base_cs
63
+ base_id = WIDTH * base_cs
51
64
for cs in range (1 , 9 ):
52
- for sw in range (1 , 10 ):
65
+ for sw in range (1 , WIDTH + 1 ):
53
66
leds .append (Led (id = base_id + 8 * (sw - 1 ) + cs , x = sw ,
54
67
y = cs + base_cs , sw = sw , cs = cs + base_cs ))
55
68
56
69
# First right and then down
57
70
# CS17 through CS32
58
71
base_cs = 16
59
- base_id = 9 * base_cs
72
+ base_id = WIDTH * base_cs
60
73
for cs in range (1 , 17 ):
61
- for sw in range (1 , 10 ):
74
+ for sw in range (1 , WIDTH + 1 ):
62
75
leds .append (Led (id = base_id + 16 * (sw - 1 ) + cs , x = sw ,
63
76
y = cs + base_cs , sw = sw , cs = cs + base_cs ))
64
77
65
78
# First down and then right
66
79
# CS33 through CS34
67
80
base_cs = 32
68
- base_id = 9 * base_cs
81
+ base_id = WIDTH * base_cs
69
82
for cs in range (1 , 3 ):
70
- for sw in range (1 , 10 ):
83
+ for sw in range (1 , WIDTH + 1 ):
71
84
leds .append (Led (id = base_id + 9 * (cs - 1 ) + sw , x = sw ,
72
85
y = cs + base_cs , sw = sw , cs = cs + base_cs ))
73
86
74
87
return leds
75
88
76
89
77
90
def main ():
91
+ # Assumes that the index in the LEDs list is: index = x + y * 9
78
92
leds = get_leds ()
79
93
80
- # Assume that the index in the leds list is: index = x + y * 9
81
-
82
94
debug = False
83
95
84
96
for led in leds :
@@ -88,19 +100,18 @@ def main():
88
100
else :
89
101
print ("(0x{:02x}, {}), // x:{}, y:{}, sw:{}, cs:{}, id:{}" .format (
90
102
register , page , led .x , led .y , led .sw , led .cs , led .id ))
91
-
92
103
# print_led(leds, 0, 30)
93
104
94
105
# For debugging
95
106
96
107
97
108
def get_led (leds , x , y ):
98
- return leds [x + y * 9 ]
109
+ return leds [x + y * WIDTH ]
99
110
100
111
101
112
# For debugging
102
113
def print_led (leds , x , y ):
103
- led = get_led (leds , 0 , 30 )
114
+ led = get_led (leds , x , y )
104
115
(register , page ) = led .led_register ()
105
116
print (led , "(0x{:02x}, {})" .format (register , page ))
106
117
0 commit comments