Datasheet

Table Of Contents
Ê acknowledgement
9 .wrap_top
Note the use of relative IRQ addressing. Up to 4 of these interfaces could be instantiated on different pins, using the same
instructions, and the processor would receive a separate interrupt from each.
3.7.6. APA102 LEDs
APA102s have a 32-bit command syntax containing some constant bits, a global brightness config, and 24 bits of colour
data.
This program takes RGB555 pixels packed 2 per FIFO word, and serialises them to the LEDs, with colour padded to
RGB888. The global brightness is configured by initialising the Y register.
Start of frame and end of frame commands are transmitted by initialising the OSR correctly.
Ê1 .program apa102
Ê2
Ê3 ; OSR: shift to right
Ê4 ; ISR: shift to right
Ê5
Ê6 ; To set brightness, set ISR to bit-reverse of 5-bit brightness,
Ê7 ; followed by 111. (00...00_b0b1b2b3b4_111)
Ê8
Ê9 ; DMA pixel format is 0RRRRRGGGGGBBBBB x2 (15 bpp, 2px per FIFO word)
10
11 ; APA102 command structure:
12 ; increasing time ---->>
13 ; | byte 3 | byte 2 | byte 1 | byte 0 |
14 ; |7 0|7 0|7 0|7 0|
15 ; -------------------------------------
16 ; Pixel |111bbbbb|BBBBBBBB|GGGGGGGG|RRRRRRRR|
17 ; Start Frame |00000000|00000000|00000000|00000000|
18 ; Stop Frame |11111111|11111111|11111111|11111111|
19
20 .wrap_target
21 .extern pixel_out
22 ; pixel_out formats an APA102 colour command in the ISR.
23 ; bit_run shifts 32 bits out of the ISR, with clock.
24 pull ifempty
25 set x, 2
26 colour_loop:
27 in osr, 5
28 out null, 5
29 in null, 3
30 jmp x-- colour_loop
31 in y, 8
32 mov isr, ::isr ; reverse for msb-first wire order
33 out null, 1
34 .extern bit_run
35 ; in isr, n rotates ISR by n bits (right rotation only)
36 ; Use this to perform out shifts from ISR, via mov pins
37 set x, 31
38 bit_out:
39 set pins, 0
40 mov pins, isr [6]
41 set pins, 1
42 in isr, 1 [6]
43 jmp x-- bit_out
44 .wrap
RP2040 Datasheet
3.7. Outdated Examples 367