forked from pitschu/RP2040matrix-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps_hub75_64.pio
158 lines (129 loc) · 5.16 KB
/
ps_hub75_64.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
/*****************************************************
*
* 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
*/
; 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 pin is LATCH(11)
; 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
set y, 0 side 0 ; used as 'last loop indicator' for LATCH pulse
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 null, 2 side 1
jmp x!=y, loop1 side 1
set pins 1 side 0 ; apply LATCH
loop1:
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 ----------------------
jmp x--, loop0 [1] 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_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);
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_64_data_offset_entry_data);
pio_sm_set_enabled(pio, sm, true);
}
%}
.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
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 (triggers ctrl DMA channel)
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 {
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);
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_64_ctrl_offset_entry_ctrl);
pio_sm_set_enabled(pio, sm, true);
}
%}