-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathps_hub75_128_BCM.pio
187 lines (156 loc) · 5.99 KB
/
ps_hub75_128_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
/*****************************************************
*
* 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 V2 pins:
; 26 = LATCH, 27 = OE, side set 28 = CLK
; Data pins are 12..17: R0, G0, B0, R1, G1, B1
; Data pins are 6..11: R2, G2, B2, R3, G3, B3
; Row sel pins are: 18..22: A .. E
.program ps_128_data
; OUT pins are 12..17: R0, G0, B0, R1, G1, B1
; OUT pins are 6..11: R2, G2, B2, R3, G3, B3
; SET pin is LATCH(26)
; SIDE pin is CLK(28)
.side_set 1
public entry_data:
.wrap_target
public shift0:
set x, 31 side 0 ; init loop counter for 128 columns
irq wait 0 side 0 ; set and wait for IRQ-0 to be reset
set pins 2 side 0 ; disable OE
loop0:
pull block side 0 ; get cols N..N+3 (triggers data DMA channel))
out pins, 16 side 0 ; ----------- appy data ----------------------
jmp !x, loop1 [1] side 1 ; last 4 pixels are handled below
out pins, 12 side 0 ; ----------- appy data ----------------------
out y, 4 side 0
pull block side 1
jmp !y, noOE1 side 1 ; enable OE when brightness limit reached
set pins 0 side 0
noOE1:
out pins, 12 side 0 ; ----------- appy data ----------------------
out y, 4 side 0
jmp !y, noOE2 [1] side 1
set pins 0 side 0
noOE2:
out pins, 12 side 0 ; ----------- appy data ----------------------
out y, 4 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, 12 [1] side 0 ; ----------- appy data ----------------------
pull block [1] side 1
out pins, 12 [1] side 0 ; ----------- appy data ----------------------
out null, 4 [1] side 1
out pins, 12 [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_128_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_128_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, 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_128_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_128_ctrl
; OUT pins are Row sel pins: 18..22: A .. E
; SET pins are LATCH(26) and OE(27)
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 {
// ; OUT pins are Row sel pins: 18..22: A .. E
// ; SET pins are LATCH(26) and OE(27)
static inline void ps_128_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_128_ctrl_program_get_default_config(offset);
pio_sm_set_consecutive_pindirs(pio, sm, outBase, outCnt, true);
for (int i = outBase; i < outBase+outCnt; i++) {
pio_gpio_init(pio, i);
}
sm_config_set_out_pins(&c, outBase, outCnt);
for (int i = setBase; i < setBase+setCnt; i++) {
pio_gpio_init(pio, i);
}
pio_sm_set_consecutive_pindirs(pio, sm, setBase, setCnt, true);
sm_config_set_set_pins(&c, setBase, setCnt); // LATCH and OE
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_128_ctrl_offset_entry_ctrl);
pio_sm_set_enabled(pio, sm, true);
}
%}