-
Notifications
You must be signed in to change notification settings - Fork 0
/
ws2812.pio
53 lines (42 loc) · 1.32 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
52
53
; write neopixel
; Auto pull : false
; OSR threshould : 24bit
.program write_neopixel
.origin 0
set pins, 0;
pull; blocks
bit_loop:
set pins, 1 [1]; HIGH 2clks
out pins, 1 [3]; HIGH if 1, LOW if 0, 4clks
set pins, 0 [2]; LOW 3clks
jmp !OSRE bit_loop; LOW 1clk
% c-sdk {
#include "hardware/clocks.h"
#include "hardware/gpio.h"
static inline void write_neopixel_program_init(
PIO pio,
uint sm,
uint pin
)
{
const uint offset = 0;
// GPIOの設定
pio_gpio_init(pio, pin);
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
// ステートマシンの設定
pio_sm_config c = write_neopixel_program_get_default_config(offset);
// OSR shift_right, auto_pull, threshould
sm_config_set_out_shift(&c, false, false, 24);
sm_config_set_out_pins(&c, pin, 1);
sm_config_set_set_pins(&c, pin, 1);
// all the FIFOs is TX
//sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
int cycles_per_bit =10;
float div = clock_get_hz(clk_sys) / (800000 * cycles_per_bit);
sm_config_set_clkdiv(&c, div);
//sm_config_set_clkdiv(&c, (float)clock_get_hz(clk_sys) / (7200000UL));
// start state machine
pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
%}