Skip to content

Commit e3e7c5d

Browse files
Add back sample generated PIO files (#759)
These should not have been deleted See #721
1 parent 9a2c91c commit e3e7c5d

6 files changed

Lines changed: 262 additions & 6 deletions

File tree

‎.gitignore‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,3 @@ build-*
77
build_*
88
.DS_Store
99
*.pdf
10-
pio/squarewave/generated/squarewave_wrap.pio.h
11-
pio/squarewave/generated/squarewave.hex
12-
pio/squarewave/generated/squarewave.pio.h
13-
pio/ws2812/generated/ws2812.pio.h
14-
pio/ws2812/generated/ws2812.py
15-
.gitignore
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
e081
2+
e101
3+
e000
4+
0001
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
// squarewave //
13+
// ---------- //
14+
15+
#define squarewave_wrap_target 0
16+
#define squarewave_wrap 3
17+
#define squarewave_pio_version 0
18+
19+
static const uint16_t squarewave_program_instructions[] = {
20+
// .wrap_target
21+
0xe081, // 0: set pindirs, 1
22+
0xe101, // 1: set pins, 1 [1]
23+
0xe000, // 2: set pins, 0
24+
0x0001, // 3: jmp 1
25+
// .wrap
26+
};
27+
28+
#if !PICO_NO_HARDWARE
29+
static const struct pio_program squarewave_program = {
30+
.instructions = squarewave_program_instructions,
31+
.length = 4,
32+
.origin = -1,
33+
.pio_version = squarewave_pio_version,
34+
#if PICO_PIO_VERSION > 0
35+
.used_gpio_ranges = 0x0
36+
#endif
37+
};
38+
39+
static inline pio_sm_config squarewave_program_get_default_config(uint offset) {
40+
pio_sm_config c = pio_get_default_sm_config();
41+
sm_config_set_wrap(&c, offset + squarewave_wrap_target, offset + squarewave_wrap);
42+
return c;
43+
}
44+
#endif
45+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
// squarewave_wrap //
13+
// --------------- //
14+
15+
#define squarewave_wrap_wrap_target 1
16+
#define squarewave_wrap_wrap 2
17+
#define squarewave_wrap_pio_version 0
18+
19+
static const uint16_t squarewave_wrap_program_instructions[] = {
20+
0xe081, // 0: set pindirs, 1
21+
// .wrap_target
22+
0xe101, // 1: set pins, 1 [1]
23+
0xe100, // 2: set pins, 0 [1]
24+
// .wrap
25+
};
26+
27+
#if !PICO_NO_HARDWARE
28+
static const struct pio_program squarewave_wrap_program = {
29+
.instructions = squarewave_wrap_program_instructions,
30+
.length = 3,
31+
.origin = -1,
32+
.pio_version = squarewave_wrap_pio_version,
33+
#if PICO_PIO_VERSION > 0
34+
.used_gpio_ranges = 0x0
35+
#endif
36+
};
37+
38+
static inline pio_sm_config squarewave_wrap_program_get_default_config(uint offset) {
39+
pio_sm_config c = pio_get_default_sm_config();
40+
sm_config_set_wrap(&c, offset + squarewave_wrap_wrap_target, offset + squarewave_wrap_wrap);
41+
return c;
42+
}
43+
#endif
44+

‎pio/ws2812/generated/ws2812.pio.h‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 = ws2812_pio_version,
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 = ws2812_parallel_pio_version,
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_fifo_join(&c, PIO_FIFO_JOIN_TX);
115+
int cycles_per_bit = ws2812_parallel_T1 + ws2812_parallel_T2 + ws2812_parallel_T3;
116+
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
117+
sm_config_set_clkdiv(&c, div);
118+
pio_sm_init(pio, sm, offset, &c);
119+
pio_sm_set_enabled(pio, sm, true);
120+
}
121+
122+
#endif
123+

‎pio/ws2812/generated/ws2812.py‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -------------------------------------------------- #
2+
# This file is autogenerated by pioasm; do not edit! #
3+
# -------------------------------------------------- #
4+
5+
import rp2
6+
from machine import Pin
7+
# ------ #
8+
# ws2812 #
9+
# ------ #
10+
11+
ws2812_T1 = 3
12+
ws2812_T2 = 3
13+
ws2812_T3 = 4
14+
15+
@rp2.asm_pio(sideset_init=pico.PIO.OUT_HIGH, out_init=pico.PIO.OUT_HIGH, out_shiftdir=1)
16+
def ws2812():
17+
wrap_target()
18+
label("0")
19+
out(x, 1) .side(0) [3] # 0
20+
jmp(not_x, "3") .side(1) [2] # 1
21+
jmp("0") .side(1) [2] # 2
22+
label("3")
23+
nop() .side(0) [2] # 3
24+
wrap()
25+
26+
27+
28+
# --------------- #
29+
# ws2812_parallel #
30+
# --------------- #
31+
32+
ws2812_parallel_T1 = 3
33+
ws2812_parallel_T2 = 3
34+
ws2812_parallel_T3 = 4
35+
36+
@rp2.asm_pio()
37+
def ws2812_parallel():
38+
wrap_target()
39+
out(x, 32) # 0
40+
mov(pins, invert(null)) [2] # 1
41+
mov(pins, x) [2] # 2
42+
mov(pins, null) [2] # 3
43+
wrap()
44+
45+
46+

0 commit comments

Comments
 (0)