-
Notifications
You must be signed in to change notification settings - Fork 5
/
ps_hub75_64_BCM.pio
199 lines (169 loc) · 6.35 KB
/
ps_hub75_64_BCM.pio
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*****************************************************
*
* LED matrix driver for Raspberry RP2040
* (c) Peter Schulten, Mülheim, Germany
* peter_(at)_pitschu.de
*
* Unmodified reproduction and distribution of this entire
* source code in any form is permitted provided the above
* notice is preserved.
* I make this source code available free of charge and therefore
* offer neither support nor guarantee for its functionality.
* Furthermore, I assume no liability for the consequences of
* its use.
* The source code may only be used and modified for private,
* non-commercial purposes. Any further use requires my consent.
*
* History
* 25.01.2022 pitschu Start of work
*/
; PCB layout V1 pind:
; 11 = LATCH, 12 = OE, side set 13 = CLK
; Data pins are 0..5: R0, G0, B0, R1, G1, B1
; Row sel pins are: 6..10: A .. E
.program ps_64_data
; OUT pins are 0..5: R0, G0, B0, R1, G1, B1
; SET pins are LATCH(11) and OE(12)
; SIDE pin is CLK(13)
.side_set 1
public entry_data:
.wrap_target
public shift0:
set x, 15 side 0 ; init loop counter for 64 columns
irq wait 0 side 0 ; set and wait for IRQ-0 to be reset
loop0:
pull block side 0 ; get cols N..N+3 (triggers data DMA channel))
out pins, 6 side 0 ; ----------- appy data ----------------------
out y, 2 side 1
; jmp !y, noOE0 side 1 ; skip 2 steps because we have no enough program memory (only 32 words for all 4 machines)
; set pins 2 side 0
noOE0:
jmp !x, loop1 side 1 ; last 4 pixels are handled below
out pins, 6 side 0 ; ----------- appy data ----------------------
out y, 2 side 0
jmp !y, noOE1 [1] side 1 ; enable OE when brightness limit reached
set pins 0 side 0
noOE1:
out pins, 6 side 0 ; ----------- appy data ----------------------
out y, 2 side 0
jmp !y, noOE2 [1] side 1
set pins 0 side 0
noOE2:
out pins, 6 side 0 ; ----------- appy data ----------------------
out y, 2 side 0
jmp !y, noOE3 [1] side 1
set pins 0 side 0
noOE3:
jmp x--, loop0 side 0
; never reached because x==0 is handled above
loop1:
set pins 3 side 0 ; last data block in this row: apply LATCH; disable OE
out pins, 6 [1] side 0 ; ----------- appy data ----------------------
out null, 2 [1] side 1
out pins, 6 [1] side 0 ; ----------- appy data ----------------------
out null, 2 [1] side 1
out pins, 6 [1] side 0 ; ----------- appy data ----------------------
loop2:
irq clear 1 [1] side 1 ; LATCH will be released by ctrl state machine
.wrap
% c-sdk {
// this is a raw helper function for use by the user which sets up the GPIO output, and configures the SM to output on a particular pin
static inline void ps_64_data_program_init(PIO pio, uint sm, uint offset,
int outBase, int outCnt,
int setBase, int setCnt,
int sideBase, int sideCnt)
{
pio_sm_config c = ps_64_data_program_get_default_config(offset);
if (outCnt > 0)
{
pio_sm_set_consecutive_pindirs(pio, sm, outBase, outCnt, true); // 2*6 RGB pins
for (int i = outBase; i < outBase + outCnt; i++) {
pio_gpio_init(pio, i);
}
sm_config_set_out_pins(&c, outBase, outCnt);
}
if (setCnt > 0)
{
pio_sm_set_consecutive_pindirs(pio, sm, setBase, setCnt, true); // LATCH pin
for (int i = setBase; i < setBase + setCnt; i++) {
pio_gpio_init(pio, i);
}
sm_config_set_set_pins(&c, setBase, setCnt);
}
if (sideCnt > 0)
{
pio_sm_set_consecutive_pindirs(pio, sm, sideBase, sideCnt, true); // CLK pin
for (int i = sideBase; i < sideBase + sideCnt; i++) {
pio_gpio_init(pio, i);
}
sm_config_set_sideset_pins(&c, sideBase);
sm_config_set_sideset(&c, sideCnt, false, false);
}
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
// sm_config_set_clkdiv(&c, 2);
sm_config_set_out_shift(&c, true, true, 32);
sm_config_set_in_shift(&c, false, false, 32);
pio_sm_init(pio, sm, offset, &c);
pio_sm_exec(pio, sm, offset + ps_64_data_offset_entry_data);
pio_sm_set_enabled(pio, sm, true);
}
static inline void ps_hub75_wait_tx_stall(PIO pio, uint sm) {
uint32_t txstall_mask = 1u << (PIO_FDEBUG_TXSTALL_LSB + sm);
pio->fdebug = txstall_mask;
while (!(pio->fdebug & txstall_mask))
tight_loop_contents();
}
%}
.program ps_64_ctrl
; OUT pins are Row sel pins: 6..10: A .. E
; SET pins 11 = LATCH, 12 = OE
public entry_ctrl:
.wrap_target
irq clear 0 ; starts data state machine
;------------ state machine is running
irq wait 1 ; wait until data state machine is ready
set pins, 2 ; disable LATCH, disable OE
pull block ; get line address
out pins, 5 ; set addr lines
.wrap
% c-sdk {
static inline void ps_64_ctrl_program_init(PIO pio, uint sm, uint offset,
int outBase, int outCnt,
int setBase, int setCnt,
int sideBase, int sideCnt)
{
pio_sm_config c = ps_64_ctrl_program_get_default_config(offset);
if (outCnt > 0)
{
pio_sm_set_consecutive_pindirs(pio, sm, outBase, outCnt, true); // 2*6 RGB pins
for (int i = outBase; i < outBase + outCnt; i++) {
pio_gpio_init(pio, i);
}
sm_config_set_out_pins(&c, outBase, outCnt);
}
if (setCnt > 0)
{
pio_sm_set_consecutive_pindirs(pio, sm, setBase, setCnt, true); // LATCH pin
for (int i = setBase; i < setBase + setCnt; i++) {
pio_gpio_init(pio, i);
}
sm_config_set_set_pins(&c, setBase, setCnt);
}
if (sideCnt > 0)
{
pio_sm_set_consecutive_pindirs(pio, sm, sideBase, sideCnt, true); // CLK pin
for (int i = sideBase; i < sideBase + sideCnt; i++) {
pio_gpio_init(pio, i);
}
sm_config_set_sideset_pins(&c, sideBase);
sm_config_set_sideset(&c, sideCnt, false, false);
}
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
// sm_config_set_clkdiv(&c, 2);
sm_config_set_out_shift(&c, true, false, 32);
sm_config_set_in_shift(&c, false, false, 32);
pio_sm_init(pio, sm, offset, &c);
pio_sm_exec(pio, sm, offset + ps_64_ctrl_offset_entry_ctrl);
pio_sm_set_enabled(pio, sm, true);
}
%}