-
Notifications
You must be signed in to change notification settings - Fork 5
/
ps_hub75_128.pio
167 lines (138 loc) · 5.45 KB
/
ps_hub75_128.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
/*****************************************************
*
* 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
*/
; 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
set y, 0 side 0 ; used as 'last loop indicator' for LATCH pulse
irq wait 0 side 0 ; set
loop0:
pull block side 0 ; get cols 0 + 1 (block until DMA starts)
out pins, 12 side 0 ; ----------- apply data ----------------------
out null, 4 side 1
jmp x!=y, loop1 side 1
set pins 1 side 0 ; apply LATCH
loop1:
out pins, 12 [1] side 0 ; ----------- apply data ----------------------
pull block [1] side 1
out pins, 12 [1] side 0 ; ----------- apply data ----------------------
out null, 4 [1] side 1
out pins, 12 [1] side 0 ; ----------- apply data ----------------------
jmp x--, loop0 side 1
irq clear 1 side 0 ; 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_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);
pio_gpio_init(pio, setBase);
pio_sm_set_consecutive_pindirs(pio, sm, setBase, 1, true); // LATCH pin
sm_config_set_set_pins(&c, setBase, 1);
pio_gpio_init(pio, sideBase);
pio_sm_set_consecutive_pindirs(pio, sm, sideBase, 1, true); // CLK pin
sm_config_set_sideset_pins(&c, sideBase);
sm_config_set_sideset(&c, 1, 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_point);
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
push noblock ; clear ISR
set pins, 0 ; disable LATCH, enable OE
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
in osr, 13 ; save 13 bits line delay
out null, 13
mov y, isr
push noblock ; flush ISR
in osr, 13 ; save 13 bits brightness
mov x, isr ; y now contains the global brightness
set pins, 0 ; disable LATCH, enable OE
loop1:
jmp x!=y, loop2 [1] // if loop counter reaches brt value then activate OE
set pins, 2
loop2:
jmp y--, loop1 // inner loop ends when loop counter gets zero
.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_point);
pio_sm_set_enabled(pio, sm, true);
}
%}