Skip to content

Commit 5872a42

Browse files
committed
Add updated ws2812 generated pio file
1 parent 16da9c8 commit 5872a42

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

pio/ws2812/generated/ws2812.pio.h

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// -------------------------------------------------- //
2+
// This file is autogenerated by pioasm; do not edit! //
3+
// -------------------------------------------------- //
4+
5+
#pragma once
6+
7+
#if !PICO_NO_HARDWARE
8+
#include "hardware/pio.h"
9+
#endif
10+
11+
// ------ //
12+
// ws2812 //
13+
// ------ //
14+
15+
#define ws2812_wrap_target 0
16+
#define ws2812_wrap 3
17+
#define ws2812_pio_version 0
18+
19+
#define ws2812_T1 3
20+
#define ws2812_T2 3
21+
#define ws2812_T3 4
22+
23+
static const uint16_t ws2812_program_instructions[] = {
24+
// .wrap_target
25+
0x6321, // 0: out x, 1 side 0 [3]
26+
0x1223, // 1: jmp !x, 3 side 1 [2]
27+
0x1200, // 2: jmp 0 side 1 [2]
28+
0xa242, // 3: nop side 0 [2]
29+
// .wrap
30+
};
31+
32+
#if !PICO_NO_HARDWARE
33+
static const struct pio_program ws2812_program = {
34+
.instructions = ws2812_program_instructions,
35+
.length = 4,
36+
.origin = -1,
37+
.pio_version = 0,
38+
#if PICO_PIO_VERSION > 0
39+
.used_gpio_ranges = 0x0
40+
#endif
41+
};
42+
43+
static inline pio_sm_config ws2812_program_get_default_config(uint offset) {
44+
pio_sm_config c = pio_get_default_sm_config();
45+
sm_config_set_wrap(&c, offset + ws2812_wrap_target, offset + ws2812_wrap);
46+
sm_config_set_sideset(&c, 1, false, false);
47+
return c;
48+
}
49+
50+
#include "hardware/clocks.h"
51+
static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin, float freq, bool rgbw) {
52+
pio_gpio_init(pio, pin);
53+
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
54+
pio_sm_config c = ws2812_program_get_default_config(offset);
55+
sm_config_set_sideset_pins(&c, pin);
56+
sm_config_set_out_shift(&c, false, true, rgbw ? 32 : 24);
57+
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
58+
int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3;
59+
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
60+
sm_config_set_clkdiv(&c, div);
61+
pio_sm_init(pio, sm, offset, &c);
62+
pio_sm_set_enabled(pio, sm, true);
63+
}
64+
65+
#endif
66+
67+
// --------------- //
68+
// ws2812_parallel //
69+
// --------------- //
70+
71+
#define ws2812_parallel_wrap_target 0
72+
#define ws2812_parallel_wrap 3
73+
#define ws2812_parallel_pio_version 0
74+
75+
#define ws2812_parallel_T1 3
76+
#define ws2812_parallel_T2 3
77+
#define ws2812_parallel_T3 4
78+
79+
static const uint16_t ws2812_parallel_program_instructions[] = {
80+
// .wrap_target
81+
0x6020, // 0: out x, 32
82+
0xa20b, // 1: mov pins, !null [2]
83+
0xa201, // 2: mov pins, x [2]
84+
0xa203, // 3: mov pins, null [2]
85+
// .wrap
86+
};
87+
88+
#if !PICO_NO_HARDWARE
89+
static const struct pio_program ws2812_parallel_program = {
90+
.instructions = ws2812_parallel_program_instructions,
91+
.length = 4,
92+
.origin = -1,
93+
.pio_version = 0,
94+
#if PICO_PIO_VERSION > 0
95+
.used_gpio_ranges = 0x0
96+
#endif
97+
};
98+
99+
static inline pio_sm_config ws2812_parallel_program_get_default_config(uint offset) {
100+
pio_sm_config c = pio_get_default_sm_config();
101+
sm_config_set_wrap(&c, offset + ws2812_parallel_wrap_target, offset + ws2812_parallel_wrap);
102+
return c;
103+
}
104+
105+
#include "hardware/clocks.h"
106+
static inline void ws2812_parallel_program_init(PIO pio, uint sm, uint offset, uint pin_base, uint pin_count, float freq) {
107+
for(uint i=pin_base; i<pin_base+pin_count; i++) {
108+
pio_gpio_init(pio, i);
109+
}
110+
pio_sm_set_consecutive_pindirs(pio, sm, pin_base, pin_count, true);
111+
pio_sm_config c = ws2812_parallel_program_get_default_config(offset);
112+
sm_config_set_out_shift(&c, true, true, 32);
113+
sm_config_set_out_pins(&c, pin_base, pin_count);
114+
sm_config_set_set_pins(&c, pin_base, pin_count);
115+
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
116+
int cycles_per_bit = ws2812_parallel_T1 + ws2812_parallel_T2 + ws2812_parallel_T3;
117+
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
118+
sm_config_set_clkdiv(&c, div);
119+
pio_sm_init(pio, sm, offset, &c);
120+
pio_sm_set_enabled(pio, sm, true);
121+
}
122+
123+
#endif
124+

0 commit comments

Comments
 (0)