diff options
Diffstat (limited to 'examples/rp/src/bin/pio_async.rs')
| -rw-r--r-- | examples/rp/src/bin/pio_async.rs | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs index 9f47c2316..12484e882 100644 --- a/examples/rp/src/bin/pio_async.rs +++ b/examples/rp/src/bin/pio_async.rs | |||
| @@ -2,10 +2,13 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | use defmt::info; | 4 | use defmt::info; |
| 5 | use embassy_embedded_hal::SetConfig; | ||
| 5 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 6 | use embassy_rp::peripherals::PIO0; | 7 | use embassy_rp::peripherals::PIO0; |
| 7 | use embassy_rp::pio::{Common, Irq, Pio, PioPin, ShiftDirection, StateMachine}; | 8 | use embassy_rp::pio::{Common, Config, Irq, Pio, PioPin, ShiftDirection, StateMachine}; |
| 8 | use embassy_rp::relocate::RelocatedProgram; | 9 | use embassy_rp::relocate::RelocatedProgram; |
| 10 | use fixed::traits::ToFixed; | ||
| 11 | use fixed_macro::types::U56F8; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 13 | ||
| 11 | fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 0>, pin: impl PioPin) { | 14 | fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 0>, pin: impl PioPin) { |
| @@ -21,15 +24,14 @@ fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, | |||
| 21 | ); | 24 | ); |
| 22 | 25 | ||
| 23 | let relocated = RelocatedProgram::new(&prg.program); | 26 | let relocated = RelocatedProgram::new(&prg.program); |
| 24 | sm.use_program(&pio.load_program(&relocated), &[]); | 27 | let mut cfg = Config::default(); |
| 28 | cfg.use_program(&pio.load_program(&relocated), &[]); | ||
| 25 | let out_pin = pio.make_pio_pin(pin); | 29 | let out_pin = pio.make_pio_pin(pin); |
| 26 | let pio_pins = [&out_pin]; | 30 | cfg.set_out_pins(&[&out_pin]); |
| 27 | sm.set_out_pins(&pio_pins); | 31 | cfg.set_set_pins(&[&out_pin]); |
| 28 | sm.set_clkdiv((125e6 / 20.0 / 2e2 * 256.0) as u32); | 32 | cfg.clock_divider = (U56F8!(125_000_000) / 20 / 200).to_fixed(); |
| 29 | sm.set_set_range(0, 1); | 33 | cfg.shift_out.auto_fill = true; |
| 30 | 34 | sm.set_config(&cfg); | |
| 31 | sm.set_autopull(true); | ||
| 32 | sm.set_out_shift_dir(ShiftDirection::Left); | ||
| 33 | } | 35 | } |
| 34 | 36 | ||
| 35 | #[embassy_executor::task] | 37 | #[embassy_executor::task] |
| @@ -51,11 +53,12 @@ fn setup_pio_task_sm1<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, | |||
| 51 | let prg = pio_proc::pio_asm!(".origin 8", "set x, 0x15", ".wrap_target", "in x, 5 [31]", ".wrap",); | 53 | let prg = pio_proc::pio_asm!(".origin 8", "set x, 0x15", ".wrap_target", "in x, 5 [31]", ".wrap",); |
| 52 | 54 | ||
| 53 | let relocated = RelocatedProgram::new(&prg.program); | 55 | let relocated = RelocatedProgram::new(&prg.program); |
| 54 | sm.use_program(&pio.load_program(&relocated), &[]); | 56 | let mut cfg = Config::default(); |
| 55 | sm.set_clkdiv((125e6 / 2e3 * 256.0) as u32); | 57 | cfg.use_program(&pio.load_program(&relocated), &[]); |
| 56 | sm.set_set_range(0, 0); | 58 | cfg.clock_divider = (U56F8!(125_000_000) / 2000).to_fixed(); |
| 57 | sm.set_autopush(true); | 59 | cfg.shift_in.auto_fill = true; |
| 58 | sm.set_in_shift_dir(ShiftDirection::Right); | 60 | cfg.shift_in.direction = ShiftDirection::Right; |
| 61 | sm.set_config(&cfg); | ||
| 59 | } | 62 | } |
| 60 | 63 | ||
| 61 | #[embassy_executor::task] | 64 | #[embassy_executor::task] |
| @@ -81,8 +84,10 @@ fn setup_pio_task_sm2<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, | |||
| 81 | ".wrap", | 84 | ".wrap", |
| 82 | ); | 85 | ); |
| 83 | let relocated = RelocatedProgram::new(&prg.program); | 86 | let relocated = RelocatedProgram::new(&prg.program); |
| 84 | sm.use_program(&pio.load_program(&relocated), &[]); | 87 | let mut cfg = Config::default(); |
| 85 | sm.set_clkdiv((125e6 / 2e3 * 256.0) as u32); | 88 | cfg.use_program(&pio.load_program(&relocated), &[]); |
| 89 | cfg.clock_divider = (U56F8!(125_000_000) / 2000).to_fixed(); | ||
| 90 | sm.set_config(&cfg); | ||
| 86 | } | 91 | } |
| 87 | 92 | ||
| 88 | #[embassy_executor::task] | 93 | #[embassy_executor::task] |
