-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWS2812.pio
51 lines (38 loc) · 1.31 KB
/
WS2812.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
.program pio_matrix
.wrap_target
out x, 1
jmp !x do_zero
do_one:
set pins, 1 [4]
jmp cont
do_zero:
set pins, 1 [2]
set pins, 0 [2]
cont:
set pins, 0 [1]
.wrap
% c-sdk {
static inline void pio_matrix_program_init(PIO pio, uint sm, uint offset, uint pin)
{
pio_sm_config c = pio_matrix_program_get_default_config(offset);
// Set pin to be part of set output group, i.e. set by set instruction
sm_config_set_set_pins(&c, pin, 1);
// Attach pio to the GPIO
pio_gpio_init(pio, pin);
// Set pin direction to output at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
// Set pio clock to 8MHz, giving 10 cycles per LED binary digit
float div = clock_get_hz(clk_sys) / 8000000.0;
sm_config_set_clkdiv(&c, div);
// Give all the FIFO space to TX (not using RX)
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
// Shift to the left, use autopull, next pull threshold 24 bits
sm_config_set_out_shift(&c, false, true, 24);
// Set sticky-- continue to drive value from last set/out. Other stuff off.
sm_config_set_out_special(&c, true, false, false);
// Load configuration, and jump to the start of the program
pio_sm_init(pio, sm, offset, &c);
// enable this pio state machine
pio_sm_set_enabled(pio, sm, true);
}
%}