aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/rp/src/bin/pio_async.rs25
-rw-r--r--examples/rp/src/bin/pio_dma.rs7
-rw-r--r--examples/rp/src/bin/pio_hd44780.rs16
-rw-r--r--examples/rp/src/bin/ws2812-pio.rs13
4 files changed, 13 insertions, 48 deletions
diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs
index 461ea3ff9..9f47c2316 100644
--- a/examples/rp/src/bin/pio_async.rs
+++ b/examples/rp/src/bin/pio_async.rs
@@ -5,11 +5,10 @@ use defmt::info;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_rp::peripherals::PIO0; 6use embassy_rp::peripherals::PIO0;
7use embassy_rp::pio::{Common, Irq, Pio, PioPin, ShiftDirection, StateMachine}; 7use embassy_rp::pio::{Common, Irq, Pio, PioPin, ShiftDirection, StateMachine};
8use embassy_rp::pio_instr_util;
9use embassy_rp::relocate::RelocatedProgram; 8use embassy_rp::relocate::RelocatedProgram;
10use {defmt_rtt as _, panic_probe as _}; 9use {defmt_rtt as _, panic_probe as _};
11 10
12fn setup_pio_task_sm0(pio: &mut Common<PIO0>, sm: &mut StateMachine<PIO0, 0>, pin: impl PioPin) { 11fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 0>, pin: impl PioPin) {
13 // Setup sm0 12 // Setup sm0
14 13
15 // Send data serially to pin 14 // Send data serially to pin
@@ -22,15 +21,12 @@ fn setup_pio_task_sm0(pio: &mut Common<PIO0>, sm: &mut StateMachine<PIO0, 0>, pi
22 ); 21 );
23 22
24 let relocated = RelocatedProgram::new(&prg.program); 23 let relocated = RelocatedProgram::new(&prg.program);
24 sm.use_program(&pio.load_program(&relocated), &[]);
25 let out_pin = pio.make_pio_pin(pin); 25 let out_pin = pio.make_pio_pin(pin);
26 let pio_pins = [&out_pin]; 26 let pio_pins = [&out_pin];
27 sm.set_out_pins(&pio_pins); 27 sm.set_out_pins(&pio_pins);
28 pio.write_instr(relocated.origin() as usize, relocated.code());
29 pio_instr_util::exec_jmp(sm, relocated.origin());
30 sm.set_clkdiv((125e6 / 20.0 / 2e2 * 256.0) as u32); 28 sm.set_clkdiv((125e6 / 20.0 / 2e2 * 256.0) as u32);
31 sm.set_set_range(0, 1); 29 sm.set_set_range(0, 1);
32 let pio::Wrap { source, target } = relocated.wrap();
33 sm.set_wrap(source, target);
34 30
35 sm.set_autopull(true); 31 sm.set_autopull(true);
36 sm.set_out_shift_dir(ShiftDirection::Left); 32 sm.set_out_shift_dir(ShiftDirection::Left);
@@ -48,20 +44,16 @@ async fn pio_task_sm0(mut sm: StateMachine<'static, PIO0, 0>) {
48 } 44 }
49} 45}
50 46
51fn setup_pio_task_sm1(pio: &mut Common<PIO0>, sm: &mut StateMachine<PIO0, 1>) { 47fn setup_pio_task_sm1<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 1>) {
52 // Setupm sm1 48 // Setupm sm1
53 49
54 // Read 0b10101 repeatedly until ISR is full 50 // Read 0b10101 repeatedly until ISR is full
55 let prg = pio_proc::pio_asm!(".origin 8", "set x, 0x15", ".wrap_target", "in x, 5 [31]", ".wrap",); 51 let prg = pio_proc::pio_asm!(".origin 8", "set x, 0x15", ".wrap_target", "in x, 5 [31]", ".wrap",);
56 52
57 let relocated = RelocatedProgram::new(&prg.program); 53 let relocated = RelocatedProgram::new(&prg.program);
58 pio.write_instr(relocated.origin() as usize, relocated.code()); 54 sm.use_program(&pio.load_program(&relocated), &[]);
59 pio_instr_util::exec_jmp(sm, relocated.origin());
60 sm.set_clkdiv((125e6 / 2e3 * 256.0) as u32); 55 sm.set_clkdiv((125e6 / 2e3 * 256.0) as u32);
61 sm.set_set_range(0, 0); 56 sm.set_set_range(0, 0);
62 let pio::Wrap { source, target } = relocated.wrap();
63 sm.set_wrap(source, target);
64
65 sm.set_autopush(true); 57 sm.set_autopush(true);
66 sm.set_in_shift_dir(ShiftDirection::Right); 58 sm.set_in_shift_dir(ShiftDirection::Right);
67} 59}
@@ -75,7 +67,7 @@ async fn pio_task_sm1(mut sm: StateMachine<'static, PIO0, 1>) {
75 } 67 }
76} 68}
77 69
78fn setup_pio_task_sm2(pio: &mut Common<PIO0>, sm: &mut StateMachine<PIO0, 2>) { 70fn setup_pio_task_sm2<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 2>) {
79 // Setup sm2 71 // Setup sm2
80 72
81 // Repeatedly trigger IRQ 3 73 // Repeatedly trigger IRQ 3
@@ -89,12 +81,7 @@ fn setup_pio_task_sm2(pio: &mut Common<PIO0>, sm: &mut StateMachine<PIO0, 2>) {
89 ".wrap", 81 ".wrap",
90 ); 82 );
91 let relocated = RelocatedProgram::new(&prg.program); 83 let relocated = RelocatedProgram::new(&prg.program);
92 pio.write_instr(relocated.origin() as usize, relocated.code()); 84 sm.use_program(&pio.load_program(&relocated), &[]);
93
94 let pio::Wrap { source, target } = relocated.wrap();
95 sm.set_wrap(source, target);
96
97 pio_instr_util::exec_jmp(sm, relocated.origin());
98 sm.set_clkdiv((125e6 / 2e3 * 256.0) as u32); 85 sm.set_clkdiv((125e6 / 2e3 * 256.0) as u32);
99} 86}
100 87
diff --git a/examples/rp/src/bin/pio_dma.rs b/examples/rp/src/bin/pio_dma.rs
index c664482e5..1c4e127c7 100644
--- a/examples/rp/src/bin/pio_dma.rs
+++ b/examples/rp/src/bin/pio_dma.rs
@@ -6,7 +6,7 @@ use embassy_executor::Spawner;
6use embassy_futures::join::join; 6use embassy_futures::join::join;
7use embassy_rp::pio::{Pio, ShiftDirection}; 7use embassy_rp::pio::{Pio, ShiftDirection};
8use embassy_rp::relocate::RelocatedProgram; 8use embassy_rp::relocate::RelocatedProgram;
9use embassy_rp::{pio_instr_util, Peripheral}; 9use embassy_rp::Peripheral;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12fn swap_nibbles(v: u32) -> u32 { 12fn swap_nibbles(v: u32) -> u32 {
@@ -38,11 +38,8 @@ async fn main(_spawner: Spawner) {
38 ); 38 );
39 39
40 let relocated = RelocatedProgram::new(&prg.program); 40 let relocated = RelocatedProgram::new(&prg.program);
41 common.write_instr(relocated.origin() as usize, relocated.code()); 41 sm.use_program(&common.load_program(&relocated), &[]);
42 pio_instr_util::exec_jmp(&mut sm, relocated.origin());
43 sm.set_clkdiv((125e6 / 10e3 * 256.0) as u32); 42 sm.set_clkdiv((125e6 / 10e3 * 256.0) as u32);
44 let pio::Wrap { source, target } = relocated.wrap();
45 sm.set_wrap(source, target);
46 sm.set_autopull(true); 43 sm.set_autopull(true);
47 sm.set_autopush(true); 44 sm.set_autopush(true);
48 sm.set_pull_threshold(32); 45 sm.set_pull_threshold(32);
diff --git a/examples/rp/src/bin/pio_hd44780.rs b/examples/rp/src/bin/pio_hd44780.rs
index 17b2440cf..c3466b554 100644
--- a/examples/rp/src/bin/pio_hd44780.rs
+++ b/examples/rp/src/bin/pio_hd44780.rs
@@ -123,15 +123,9 @@ impl<'l> HD44780<'l> {
123 embassy_rp::pio_instr_util::set_pindir(&mut sm0, 0b11111); 123 embassy_rp::pio_instr_util::set_pindir(&mut sm0, 0b11111);
124 124
125 let relocated = RelocatedProgram::new(&prg.program); 125 let relocated = RelocatedProgram::new(&prg.program);
126 common.write_instr(relocated.origin() as usize, relocated.code()); 126 sm0.use_program(&common.load_program(&relocated), &[&e]);
127 embassy_rp::pio_instr_util::exec_jmp(&mut sm0, relocated.origin());
128 sm0.set_clkdiv(125 * 256); 127 sm0.set_clkdiv(125 * 256);
129 let pio::Wrap { source, target } = relocated.wrap();
130 sm0.set_wrap(source, target);
131 sm0.set_side_enable(true);
132 sm0.set_out_pins(&[&db4, &db5, &db6, &db7]); 128 sm0.set_out_pins(&[&db4, &db5, &db6, &db7]);
133 sm0.set_sideset_base_pin(&e);
134 sm0.set_sideset_count(2);
135 sm0.set_out_shift_dir(ShiftDirection::Left); 129 sm0.set_out_shift_dir(ShiftDirection::Left);
136 sm0.set_fifo_join(FifoJoin::TxOnly); 130 sm0.set_fifo_join(FifoJoin::TxOnly);
137 sm0.set_autopull(true); 131 sm0.set_autopull(true);
@@ -199,17 +193,11 @@ impl<'l> HD44780<'l> {
199 ); 193 );
200 194
201 let relocated = RelocatedProgram::new(&prg.program); 195 let relocated = RelocatedProgram::new(&prg.program);
202 common.write_instr(relocated.origin() as usize, relocated.code()); 196 sm0.use_program(&common.load_program(&relocated), &[&e]);
203 embassy_rp::pio_instr_util::exec_jmp(&mut sm0, relocated.origin());
204 let pio::Wrap { source, target } = relocated.wrap();
205 sm0.set_clkdiv(8 * 256); // ~64ns/insn 197 sm0.set_clkdiv(8 * 256); // ~64ns/insn
206 sm0.set_side_enable(false);
207 sm0.set_jmp_pin(db7pin); 198 sm0.set_jmp_pin(db7pin);
208 sm0.set_wrap(source, target);
209 sm0.set_set_pins(&[&rs, &rw]); 199 sm0.set_set_pins(&[&rs, &rw]);
210 sm0.set_out_pins(&[&db4, &db5, &db6, &db7]); 200 sm0.set_out_pins(&[&db4, &db5, &db6, &db7]);
211 sm0.set_sideset_base_pin(&e);
212 sm0.set_sideset_count(1);
213 sm0.set_out_shift_dir(ShiftDirection::Left); 201 sm0.set_out_shift_dir(ShiftDirection::Left);
214 sm0.set_fifo_join(FifoJoin::TxOnly); 202 sm0.set_fifo_join(FifoJoin::TxOnly);
215 203
diff --git a/examples/rp/src/bin/ws2812-pio.rs b/examples/rp/src/bin/ws2812-pio.rs
index 2e6860d8b..889970541 100644
--- a/examples/rp/src/bin/ws2812-pio.rs
+++ b/examples/rp/src/bin/ws2812-pio.rs
@@ -5,7 +5,6 @@
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_rp::pio::{Common, FifoJoin, Instance, Pio, PioPin, ShiftDirection, StateMachine}; 7use embassy_rp::pio::{Common, FifoJoin, Instance, Pio, PioPin, ShiftDirection, StateMachine};
8use embassy_rp::pio_instr_util;
9use embassy_rp::relocate::RelocatedProgram; 8use embassy_rp::relocate::RelocatedProgram;
10use embassy_time::{Duration, Timer}; 9use embassy_time::{Duration, Timer};
11use smart_leds::RGB8; 10use smart_leds::RGB8;
@@ -45,15 +44,11 @@ impl<'d, P: Instance, const S: usize> Ws2812<'d, P, S> {
45 44
46 let prg = a.assemble_with_wrap(wrap_source, wrap_target); 45 let prg = a.assemble_with_wrap(wrap_source, wrap_target);
47 46
48 let relocated = RelocatedProgram::new(&prg);
49 pio.write_instr(relocated.origin() as usize, relocated.code());
50 pio_instr_util::exec_jmp(&mut sm, relocated.origin());
51
52 // Pin config 47 // Pin config
53 let out_pin = pio.make_pio_pin(pin); 48 let out_pin = pio.make_pio_pin(pin);
54 sm.set_set_pins(&[&out_pin]); 49
55 sm.set_sideset_base_pin(&out_pin); 50 let relocated = RelocatedProgram::new(&prg);
56 sm.set_sideset_count(1); 51 sm.use_program(&pio.load_program(&relocated), &[&out_pin]);
57 52
58 // Clock config 53 // Clock config
59 // TODO CLOCK_FREQ should come from embassy_rp 54 // TODO CLOCK_FREQ should come from embassy_rp
@@ -70,8 +65,6 @@ impl<'d, P: Instance, const S: usize> Ws2812<'d, P, S> {
70 } 65 }
71 66
72 sm.set_clkdiv((int << 8) | frac); 67 sm.set_clkdiv((int << 8) | frac);
73 let pio::Wrap { source, target } = relocated.wrap();
74 sm.set_wrap(source, target);
75 68
76 // FIFO config 69 // FIFO config
77 sm.set_autopull(true); 70 sm.set_autopull(true);