-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathps_hub75_OLD.pio
108 lines (92 loc) · 4.16 KB
/
ps_hub75_OLD.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
/*****************************************************
*
* 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_hub75_data
.side_set 1
public entry_point:
.wrap_target
public shift0:
set x, 29 side 0 // init loop counter for 60 columns
push noblock side 0 // clear ISR
pull block side 0 // get cols 0 + 1 (block until DMA starts)
loop0:
out pins, 11 side 0 // ----------- appy data and addr ----------------------
out null, 5 [1] side 1
out pins, 11 [1] side 0 // ----------- appy data and addr ----------------------
pull block [1] side 1 // get cols 2 .. 61
jmp x--, loop0 side 0
out pins, 11 side 0 // ----------- appy data and addr ----------------------
in osr, 5 side 1 // save 5 MSB of line delay
out null, 5 side 1
set pins, 3 side 0 // apply LATCH and OE
out pins, 11 side 0 // ----------- appy data and addr ----------------------
in osr, 5 side 1 // save 5 LSB bits of line delay
mov y, isr side 1 // x now contains 10 bits line delay (bit position)
push noblock side 1 // clear ISR
pull block side 0 // get cols 62 + 63
out pins, 11 side 0 // ----------- appy data and addr ----------------------
in osr, 5 [1] side 1 // save 5 MSB bits of brightness
out null, 5 side 0
out pins, 11 side 0 // ----------- appy data and addr ----------------------
in osr, 5 [1] side 1 // save 5 LSB of brightness
set pins, 0 side 0 // enable OE
mov x, isr side 0 // y now contains the global brightness
loopA:
mov isr, y side 0 // save line delay to ISR for later re-use
set y,31 side 0 // init loop counter
loopB:
jmp x!=y, loopC [3] side 0 // if loop counter reaches brt value then activate OE
set pins, 2 side 0 // disable OE
loopC:
jmp y--, loopB side 0 // inner loop ends when loop counter gets zero
set pins, 0 side 0 // enable OE
mov y, isr side 0 // restore line delay
jmp y--, loopA side 0 // check and decrement line delay
.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_hub75_data_program_init(PIO pio, uint sm, uint offset, uint basepin, uint ctrlpin) {
pio_sm_config c = ps_hub75_data_program_get_default_config(offset);
pio_sm_set_consecutive_pindirs(pio, sm, 0, 14, true);
for (int i = 0; i<=13; i++) {
pio_gpio_init(pio, i);
}
sm_config_set_out_pins(&c, 0, 11);
sm_config_set_set_pins(&c, 11, 2); // LATCH and OE
sm_config_set_sideset_pins(&c, 13);
sm_config_set_sideset(&c, 1, false, false);
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
// Uncomment to slow down everything. Useful when using a logic analyzer
// 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_hub75_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();
}
%}