Skip to content

Commit f3b98a8

Browse files
authored
Merge pull request embassy-rs#3865 from embassy-rs/pio2
rp/pio: update pio-rs, reexport, move instr methods to SM.
2 parents 1780f84 + 52dfefb commit f3b98a8

File tree

22 files changed

+137
-133
lines changed

22 files changed

+137
-133
lines changed

cyw43-pio/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ documentation = "https://docs.embassy.dev/cyw43-pio"
1212
[dependencies]
1313
cyw43 = { version = "0.3.0", path = "../cyw43" }
1414
embassy-rp = { version = "0.3.0", path = "../embassy-rp" }
15-
pio-proc = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
16-
pio = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
1715
fixed = "1.23.1"
1816
defmt = { version = "0.3", optional = true }
1917

cyw43-pio/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use core::slice;
88
use cyw43::SpiBusCyw43;
99
use embassy_rp::dma::Channel;
1010
use embassy_rp::gpio::{Drive, Level, Output, Pull, SlewRate};
11-
use embassy_rp::pio::{instr, Common, Config, Direction, Instance, Irq, PioPin, ShiftDirection, StateMachine};
11+
use embassy_rp::pio::program::pio_asm;
12+
use embassy_rp::pio::{Common, Config, Direction, Instance, Irq, PioPin, ShiftDirection, StateMachine};
1213
use embassy_rp::{Peripheral, PeripheralRef};
1314
use fixed::types::extra::U8;
1415
use fixed::FixedU32;
15-
use pio_proc::pio_asm;
1616

1717
/// SPI comms driven by PIO.
1818
pub struct PioSpi<'d, PIO: Instance, const SM: usize, DMA> {
@@ -161,10 +161,10 @@ where
161161
defmt::trace!("write={} read={}", write_bits, read_bits);
162162

163163
unsafe {
164-
instr::set_x(&mut self.sm, write_bits as u32);
165-
instr::set_y(&mut self.sm, read_bits as u32);
166-
instr::set_pindir(&mut self.sm, 0b1);
167-
instr::exec_jmp(&mut self.sm, self.wrap_target);
164+
self.sm.set_x(write_bits as u32);
165+
self.sm.set_y(read_bits as u32);
166+
self.sm.set_pindir(0b1);
167+
self.sm.exec_jmp(self.wrap_target);
168168
}
169169

170170
self.sm.set_enable(true);
@@ -192,10 +192,10 @@ where
192192
defmt::trace!("cmd_read cmd = {:02x} len = {}", cmd, read.len());
193193

194194
unsafe {
195-
instr::set_y(&mut self.sm, read_bits as u32);
196-
instr::set_x(&mut self.sm, write_bits as u32);
197-
instr::set_pindir(&mut self.sm, 0b1);
198-
instr::exec_jmp(&mut self.sm, self.wrap_target);
195+
self.sm.set_y(read_bits as u32);
196+
self.sm.set_x(write_bits as u32);
197+
self.sm.set_pindir(0b1);
198+
self.sm.exec_jmp(self.wrap_target);
199199
}
200200

201201
// self.cs.set_low();

embassy-rp/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,14 @@ embedded-storage-async = { version = "0.4.1" }
157157
rand_core = "0.6.4"
158158
fixed = "1.28.0"
159159

160-
rp-pac = { version = "7.0.0", feature = ["rt"] }
160+
rp-pac = { version = "7.0.0" }
161161

162162
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
163163
embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
164164
embedded-hal-async = { version = "1.0" }
165165
embedded-hal-nb = { version = "1.0" }
166166

167-
pio-proc = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
168-
pio = { git = "https://github.com/rp-rs/pio-rs", rev = "fa586448b0b223217eec8c92c19fe6823dd04cc4" }
167+
pio = { git = "https://github.com/rp-rs/pio-rs", rev = "506a51b9bc135845e8544a0debd75847b73754dc" }
169168
rp2040-boot2 = "0.3"
170169
document-features = "0.2.10"
171170
sha2-const-stable = "0.1"

embassy-rp/src/pio/instr.rs

Lines changed: 80 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,99 +3,101 @@ use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestin
33

44
use crate::pio::{Instance, StateMachine};
55

6-
/// Set value of scratch register X.
7-
pub unsafe fn set_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, value: u32) {
8-
const OUT: u16 = InstructionOperands::OUT {
9-
destination: OutDestination::X,
10-
bit_count: 32,
6+
impl<'d, PIO: Instance, const SM: usize> StateMachine<'d, PIO, SM> {
7+
/// Set value of scratch register X.
8+
pub unsafe fn set_x(&mut self, value: u32) {
9+
const OUT: u16 = InstructionOperands::OUT {
10+
destination: OutDestination::X,
11+
bit_count: 32,
12+
}
13+
.encode();
14+
self.tx().push(value);
15+
self.exec_instr(OUT);
1116
}
12-
.encode();
13-
sm.tx().push(value);
14-
sm.exec_instr(OUT);
15-
}
1617

17-
/// Get value of scratch register X.
18-
pub unsafe fn get_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) -> u32 {
19-
const IN: u16 = InstructionOperands::IN {
20-
source: InSource::X,
21-
bit_count: 32,
18+
/// Get value of scratch register X.
19+
pub unsafe fn get_x(&mut self) -> u32 {
20+
const IN: u16 = InstructionOperands::IN {
21+
source: InSource::X,
22+
bit_count: 32,
23+
}
24+
.encode();
25+
self.exec_instr(IN);
26+
self.rx().pull()
2227
}
23-
.encode();
24-
sm.exec_instr(IN);
25-
sm.rx().pull()
26-
}
2728

28-
/// Set value of scratch register Y.
29-
pub unsafe fn set_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, value: u32) {
30-
const OUT: u16 = InstructionOperands::OUT {
31-
destination: OutDestination::Y,
32-
bit_count: 32,
29+
/// Set value of scratch register Y.
30+
pub unsafe fn set_y(&mut self, value: u32) {
31+
const OUT: u16 = InstructionOperands::OUT {
32+
destination: OutDestination::Y,
33+
bit_count: 32,
34+
}
35+
.encode();
36+
self.tx().push(value);
37+
self.exec_instr(OUT);
3338
}
34-
.encode();
35-
sm.tx().push(value);
36-
sm.exec_instr(OUT);
37-
}
3839

39-
/// Get value of scratch register Y.
40-
pub unsafe fn get_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) -> u32 {
41-
const IN: u16 = InstructionOperands::IN {
42-
source: InSource::Y,
43-
bit_count: 32,
44-
}
45-
.encode();
46-
sm.exec_instr(IN);
40+
/// Get value of scratch register Y.
41+
pub unsafe fn get_y(&mut self) -> u32 {
42+
const IN: u16 = InstructionOperands::IN {
43+
source: InSource::Y,
44+
bit_count: 32,
45+
}
46+
.encode();
47+
self.exec_instr(IN);
4748

48-
sm.rx().pull()
49-
}
49+
self.rx().pull()
50+
}
5051

51-
/// Set instruction for pindir destination.
52-
pub unsafe fn set_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u8) {
53-
let set: u16 = InstructionOperands::SET {
54-
destination: SetDestination::PINDIRS,
55-
data,
52+
/// Set instruction for pindir destination.
53+
pub unsafe fn set_pindir(&mut self, data: u8) {
54+
let set: u16 = InstructionOperands::SET {
55+
destination: SetDestination::PINDIRS,
56+
data,
57+
}
58+
.encode();
59+
self.exec_instr(set);
5660
}
57-
.encode();
58-
sm.exec_instr(set);
59-
}
6061

61-
/// Set instruction for pin destination.
62-
pub unsafe fn set_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u8) {
63-
let set: u16 = InstructionOperands::SET {
64-
destination: SetDestination::PINS,
65-
data,
62+
/// Set instruction for pin destination.
63+
pub unsafe fn set_pin(&mut self, data: u8) {
64+
let set: u16 = InstructionOperands::SET {
65+
destination: SetDestination::PINS,
66+
data,
67+
}
68+
.encode();
69+
self.exec_instr(set);
6670
}
67-
.encode();
68-
sm.exec_instr(set);
69-
}
7071

71-
/// Out instruction for pin destination.
72-
pub unsafe fn set_out_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u32) {
73-
const OUT: u16 = InstructionOperands::OUT {
74-
destination: OutDestination::PINS,
75-
bit_count: 32,
72+
/// Out instruction for pin destination.
73+
pub unsafe fn set_out_pin(&mut self, data: u32) {
74+
const OUT: u16 = InstructionOperands::OUT {
75+
destination: OutDestination::PINS,
76+
bit_count: 32,
77+
}
78+
.encode();
79+
self.tx().push(data);
80+
self.exec_instr(OUT);
7681
}
77-
.encode();
78-
sm.tx().push(data);
79-
sm.exec_instr(OUT);
80-
}
8182

82-
/// Out instruction for pindir destination.
83-
pub unsafe fn set_out_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u32) {
84-
const OUT: u16 = InstructionOperands::OUT {
85-
destination: OutDestination::PINDIRS,
86-
bit_count: 32,
83+
/// Out instruction for pindir destination.
84+
pub unsafe fn set_out_pindir(&mut self, data: u32) {
85+
const OUT: u16 = InstructionOperands::OUT {
86+
destination: OutDestination::PINDIRS,
87+
bit_count: 32,
88+
}
89+
.encode();
90+
self.tx().push(data);
91+
self.exec_instr(OUT);
8792
}
88-
.encode();
89-
sm.tx().push(data);
90-
sm.exec_instr(OUT);
91-
}
9293

93-
/// Jump instruction to address.
94-
pub unsafe fn exec_jmp<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, to_addr: u8) {
95-
let jmp: u16 = InstructionOperands::JMP {
96-
address: to_addr,
97-
condition: JmpCondition::Always,
94+
/// Jump instruction to address.
95+
pub unsafe fn exec_jmp(&mut self, to_addr: u8) {
96+
let jmp: u16 = InstructionOperands::JMP {
97+
address: to_addr,
98+
condition: JmpCondition::Always,
99+
}
100+
.encode();
101+
self.exec_instr(jmp);
98102
}
99-
.encode();
100-
sm.exec_instr(jmp);
101103
}

embassy-rp/src/pio/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ use crate::interrupt::typelevel::{Binding, Handler, Interrupt};
1818
use crate::relocate::RelocatedProgram;
1919
use crate::{pac, peripherals, RegExt};
2020

21-
pub mod instr;
21+
mod instr;
22+
23+
#[doc(inline)]
24+
pub use pio as program;
2225

2326
/// Wakers for interrupts and FIFOs.
2427
pub struct Wakers([AtomicWaker; 12]);
@@ -812,7 +815,7 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> {
812815
}
813816

814817
if let Some(origin) = config.origin {
815-
unsafe { instr::exec_jmp(self, origin) }
818+
unsafe { self.exec_jmp(origin) }
816819
}
817820
}
818821

embassy-rp/src/pio_programs/hd44780.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct PioHD44780CommandWordProgram<'a, PIO: Instance> {
1515
impl<'a, PIO: Instance> PioHD44780CommandWordProgram<'a, PIO> {
1616
/// Load the program into the given pio
1717
pub fn new(common: &mut Common<'a, PIO>) -> Self {
18-
let prg = pio_proc::pio_asm!(
18+
let prg = pio::pio_asm!(
1919
r#"
2020
.side_set 1 opt
2121
.origin 20
@@ -46,7 +46,7 @@ impl<'a, PIO: Instance> PioHD44780CommandSequenceProgram<'a, PIO> {
4646
/// Load the program into the given pio
4747
pub fn new(common: &mut Common<'a, PIO>) -> Self {
4848
// many side sets are only there to free up a delay bit!
49-
let prg = pio_proc::pio_asm!(
49+
let prg = pio::pio_asm!(
5050
r#"
5151
.origin 27
5252
.side_set 1

embassy-rp/src/pio_programs/i2s.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct PioI2sOutProgram<'a, PIO: Instance> {
1616
impl<'a, PIO: Instance> PioI2sOutProgram<'a, PIO> {
1717
/// Load the program into the given pio
1818
pub fn new(common: &mut Common<'a, PIO>) -> Self {
19-
let prg = pio_proc::pio_asm!(
19+
let prg = pio::pio_asm!(
2020
".side_set 2",
2121
" set x, 14 side 0b01", // side 0bWB - W = Word Clock, B = Bit Clock
2222
"left_data:",

embassy-rp/src/pio_programs/onewire.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! OneWire pio driver
22
3-
use crate::pio::{self, Common, Config, Instance, LoadedProgram, PioPin, ShiftConfig, ShiftDirection, StateMachine};
3+
use crate::pio::{Common, Config, Instance, LoadedProgram, PioPin, ShiftConfig, ShiftDirection, StateMachine};
44

55
/// This struct represents an onewire driver program
66
pub struct PioOneWireProgram<'a, PIO: Instance> {
@@ -10,7 +10,7 @@ pub struct PioOneWireProgram<'a, PIO: Instance> {
1010
impl<'a, PIO: Instance> PioOneWireProgram<'a, PIO> {
1111
/// Load the program into the given pio
1212
pub fn new(common: &mut Common<'a, PIO>) -> Self {
13-
let prg = pio_proc::pio_asm!(
13+
let prg = pio::pio_asm!(
1414
r#"
1515
.wrap_target
1616
again:
@@ -60,11 +60,11 @@ impl<'a, PIO: Instance> PioOneWireProgram<'a, PIO> {
6060
}
6161

6262
/// Pio backed OneWire driver
63-
pub struct PioOneWire<'d, PIO: pio::Instance, const SM: usize> {
63+
pub struct PioOneWire<'d, PIO: Instance, const SM: usize> {
6464
sm: StateMachine<'d, PIO, SM>,
6565
}
6666

67-
impl<'d, PIO: pio::Instance, const SM: usize> PioOneWire<'d, PIO, SM> {
67+
impl<'d, PIO: Instance, const SM: usize> PioOneWire<'d, PIO, SM> {
6868
/// Create a new instance the driver
6969
pub fn new(
7070
common: &mut Common<'d, PIO>,

embassy-rp/src/pio_programs/pwm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct PioPwmProgram<'a, PIO: Instance> {
2121
impl<'a, PIO: Instance> PioPwmProgram<'a, PIO> {
2222
/// Load the program into the given pio
2323
pub fn new(common: &mut Common<'a, PIO>) -> Self {
24-
let prg = pio_proc::pio_asm!(
24+
let prg = pio::pio_asm!(
2525
".side_set 1 opt"
2626
"pull noblock side 0"
2727
"mov x, osr"

embassy-rp/src/pio_programs/rotary_encoder.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
use fixed::traits::ToFixed;
44

55
use crate::gpio::Pull;
6-
use crate::pio::{self, Common, Config, FifoJoin, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine};
6+
use crate::pio::{
7+
Common, Config, Direction as PioDirection, FifoJoin, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine,
8+
};
79

810
/// This struct represents an Encoder program loaded into pio instruction memory.
911
pub struct PioEncoderProgram<'a, PIO: Instance> {
@@ -13,7 +15,7 @@ pub struct PioEncoderProgram<'a, PIO: Instance> {
1315
impl<'a, PIO: Instance> PioEncoderProgram<'a, PIO> {
1416
/// Load the program into the given pio
1517
pub fn new(common: &mut Common<'a, PIO>) -> Self {
16-
let prg = pio_proc::pio_asm!("wait 1 pin 1", "wait 0 pin 1", "in pins, 2", "push",);
18+
let prg = pio::pio_asm!("wait 1 pin 1", "wait 0 pin 1", "in pins, 2", "push",);
1719

1820
let prg = common.load_program(&prg.program);
1921

@@ -39,7 +41,7 @@ impl<'d, T: Instance, const SM: usize> PioEncoder<'d, T, SM> {
3941
let mut pin_b = pio.make_pio_pin(pin_b);
4042
pin_a.set_pull(Pull::Up);
4143
pin_b.set_pull(Pull::Up);
42-
sm.set_pin_dirs(pio::Direction::In, &[&pin_a, &pin_b]);
44+
sm.set_pin_dirs(PioDirection::In, &[&pin_a, &pin_b]);
4345

4446
let mut cfg = Config::default();
4547
cfg.set_in_pins(&[&pin_a, &pin_b]);

0 commit comments

Comments
 (0)