Datasheet

Table Of Contents
each data bit. Autopull must be configured, with a threshold of 24. Software can then write 24-bit pixel values into the
FIFO, and these will be serialised to a chain of WS2812 LEDs.
Ê1 #include "tb.h"
Ê2 #include "gpio.h"
Ê3 #include "pio.h"
Ê4 #include "pio/stdio.pio.h"
Ê5
Ê6 #include <stdlib.h>
Ê7
Ê8 static inline void put_pixel(uint32_t pixel_grb)
Ê9 {
10 pio_put_blocking(pio0, 0, pixel_grb << 8);
11 }
12
13 static inline uint32_t urgb_u32(uint8_t r, uint8_t g, uint8_t b)
14 {
15 return
16 ((uint32_t)(r) << 8) |
17 ((uint32_t)(g) << 16) |
18 (uint32_t)(b);
19 }
20
21 void pattern_snakes(uint len, uint t)
22 {
23 for (uint i = 0; i < len; ++i)
24 {
25 uint x = (i + (t >> 1)) % 64;
26 if (x < 10)
27 put_pixel(urgb_u32(0xff, 0, 0));
28 else if (x >= 15 && x < 25)
29 put_pixel(urgb_u32(0, 0xff, 0));
30 else if (x >= 30 && x < 40)
31 put_pixel(urgb_u32(0, 0, 0xff));
32 else
33 put_pixel(0);
34 }
35 }
36
37 void pattern_random(uint len, uint t)
38 {
39 if (t % 8)
40 return;
41 for (int i = 0; i < len; ++i)
42 put_pixel(rand());
43 }
44
45 void pattern_sparkle(uint len, uint t)
46 {
47 if (t % 8)
48 return;
49 for (int i = 0; i < len; ++i)
50 put_pixel(rand() % 16 ? 0 : 0xffffffff);
51 }
52
53 typedef void (*pattern)(uint len, uint t);
54 const struct {pattern pat; const char *name;} pattern_table[] = {
55 {pattern_snakes, "Snakes!"},
56 {pattern_random, "Random data"},
57 {pattern_sparkle, "Sparkles"},
58 };
59
RP2040 Datasheet
3.6. Examples 348