88
99.program dmd_reader_sam
1010
11- ; Send using an external clock on the SPI interface
12- ; - IN pin 0 is the DATA pin
1311
14- ; initialize y with 16348 = number of pixels (128x32x4)
15- set x, 1
16- in x, 1
17- in null, 15
18- mov y, isr
12+ ; initialize y with 16383, number of pixels (128x32x4) - 1 because counting starts at 0.
13+ set x, 31 ; x = 31 (max 5-bit value)
14+ in x, 5 ; shift in 5 bits, isr = 31
15+ set x, 31 ; x = 31
16+ in x, 5 ; shift in 5 bits, isr = 1023
17+ set x, 15 ; x = 15
18+ in x, 4 ; shift in 4 bits, isr = 16383
19+ in null, 2 ; pad with 2 zeros
20+ mov y, isr ; y = 16383
1921
2022.wrap_target
2123
2527 irq clear 4
2628 wait irq 4
2729
30+ wait 1 gpio RDATA ; raising edge indicates a new frame
31+
2832dotloop:
2933 wait 0 gpio DOTCLK ; falling edge
30- in null, 3 ; pad with 3 zeros
34+ in null, 3 ; left padding with 3 zeros
3135 wait 1 gpio DOTCLK ; raising edge
3236 in pins 1 ; read pin data
33-
34-
3537 jmp x-- dotloop
3638
3739.wrap
@@ -40,7 +42,7 @@ dotloop:
4042
4143.wrap_target
4244
43- ; synchronize on the least significant plane
45+ ; synchronize on a new frame
4446 wait 0 gpio RDATA
4547 wait 1 gpio RDATA
4648 irq 4
@@ -55,13 +57,15 @@ static inline void dmd_reader_sam_program_init(PIO pio, uint sm, uint offset) {
5557 // Set the IN pin, we don't use any other
5658 sm_config_set_in_pins(&c, 2); // SDATA
5759
60+ // Set the pin direction at the PIO
61+ pio_sm_set_consecutive_pindirs(pio, sm, 6, 1, false); // RDATA
62+ pio_sm_set_consecutive_pindirs(pio, sm, 2, 2, false); // SDATA, DOTCLK
63+
5864 // Connect these GPIOs to this PIO block
65+ pio_gpio_init(pio, 6); // RDATA
5966 pio_gpio_init(pio, 3); // DOTCLK
6067 pio_gpio_init(pio, 2); // SDATA
6168
62- // Set the pin direction at the PIO
63- pio_sm_set_consecutive_pindirs(pio, sm, 2, 2, false); // SDATA, DOTCLK
64-
6569 // Shifting to left matches the customary MSB-first ordering of SPI.
6670 sm_config_set_in_shift(
6771 &c,
0 commit comments