aboutsummaryrefslogtreecommitdiff
path: root/examples/rp235x/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-03-26 16:01:37 +0100
committerDario Nieuwenhuis <[email protected]>2025-03-27 15:18:06 +0100
commitd41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch)
tree678b6fc732216e529dc38e6f65b72a309917ac32 /examples/rp235x/src
parent9edf5b7f049f95742b60b041e4443967d8a6b708 (diff)
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'examples/rp235x/src')
-rw-r--r--examples/rp235x/src/bin/adc_dma.rs4
-rw-r--r--examples/rp235x/src/bin/assign_resources.rs7
-rw-r--r--examples/rp235x/src/bin/blinky_two_channels.rs4
-rw-r--r--examples/rp235x/src/bin/blinky_two_tasks.rs4
-rw-r--r--examples/rp235x/src/bin/pio_async.rs4
-rw-r--r--examples/rp235x/src/bin/pio_dma.rs6
-rw-r--r--examples/rp235x/src/bin/pio_rotary_encoder_rxf.rs6
-rw-r--r--examples/rp235x/src/bin/pwm.rs5
-rw-r--r--examples/rp235x/src/bin/pwm_tb6612fng_motor_driver.rs2
-rw-r--r--examples/rp235x/src/bin/shared_bus.rs6
-rw-r--r--examples/rp235x/src/bin/zerocopy.rs9
11 files changed, 33 insertions, 24 deletions
diff --git a/examples/rp235x/src/bin/adc_dma.rs b/examples/rp235x/src/bin/adc_dma.rs
index f755cf5bf..b42c13fde 100644
--- a/examples/rp235x/src/bin/adc_dma.rs
+++ b/examples/rp235x/src/bin/adc_dma.rs
@@ -38,13 +38,13 @@ async fn main(_spawner: Spawner) {
38 // Read 100 samples from a single channel 38 // Read 100 samples from a single channel
39 let mut buf = [0_u16; BLOCK_SIZE]; 39 let mut buf = [0_u16; BLOCK_SIZE];
40 let div = 479; // 100kHz sample rate (48Mhz / 100kHz - 1) 40 let div = 479; // 100kHz sample rate (48Mhz / 100kHz - 1)
41 adc.read_many(&mut pin, &mut buf, div, &mut dma).await.unwrap(); 41 adc.read_many(&mut pin, &mut buf, div, dma.reborrow()).await.unwrap();
42 info!("single: {:?} ...etc", buf[..8]); 42 info!("single: {:?} ...etc", buf[..8]);
43 43
44 // Read 100 samples from 4 channels interleaved 44 // Read 100 samples from 4 channels interleaved
45 let mut buf = [0_u16; { BLOCK_SIZE * NUM_CHANNELS }]; 45 let mut buf = [0_u16; { BLOCK_SIZE * NUM_CHANNELS }];
46 let div = 119; // 100kHz sample rate (48Mhz / 100kHz * 4ch - 1) 46 let div = 119; // 100kHz sample rate (48Mhz / 100kHz * 4ch - 1)
47 adc.read_many_multichannel(&mut pins, &mut buf, div, &mut dma) 47 adc.read_many_multichannel(&mut pins, &mut buf, div, dma.reborrow())
48 .await 48 .await
49 .unwrap(); 49 .unwrap();
50 info!("multi: {:?} ...etc", buf[..NUM_CHANNELS * 2]); 50 info!("multi: {:?} ...etc", buf[..NUM_CHANNELS * 2]);
diff --git a/examples/rp235x/src/bin/assign_resources.rs b/examples/rp235x/src/bin/assign_resources.rs
index ff6eff4a2..341f54d22 100644
--- a/examples/rp235x/src/bin/assign_resources.rs
+++ b/examples/rp235x/src/bin/assign_resources.rs
@@ -16,6 +16,7 @@ use defmt::*;
16use embassy_executor::Spawner; 16use embassy_executor::Spawner;
17use embassy_rp::gpio::{Level, Output}; 17use embassy_rp::gpio::{Level, Output};
18use embassy_rp::peripherals::{self, PIN_20, PIN_21}; 18use embassy_rp::peripherals::{self, PIN_20, PIN_21};
19use embassy_rp::Peri;
19use embassy_time::Timer; 20use embassy_time::Timer;
20use {defmt_rtt as _, panic_probe as _}; 21use {defmt_rtt as _, panic_probe as _};
21 22
@@ -38,7 +39,11 @@ async fn main(spawner: Spawner) {
38 39
39// 1) Assigning a resource to a task by passing parts of the peripherals. 40// 1) Assigning a resource to a task by passing parts of the peripherals.
40#[embassy_executor::task] 41#[embassy_executor::task]
41async fn double_blinky_manually_assigned(_spawner: Spawner, pin_20: PIN_20, pin_21: PIN_21) { 42async fn double_blinky_manually_assigned(
43 _spawner: Spawner,
44 pin_20: Peri<'static, PIN_20>,
45 pin_21: Peri<'static, PIN_21>,
46) {
42 let mut led_20 = Output::new(pin_20, Level::Low); 47 let mut led_20 = Output::new(pin_20, Level::Low);
43 let mut led_21 = Output::new(pin_21, Level::High); 48 let mut led_21 = Output::new(pin_21, Level::High);
44 49
diff --git a/examples/rp235x/src/bin/blinky_two_channels.rs b/examples/rp235x/src/bin/blinky_two_channels.rs
index b2eec2a21..51e139e94 100644
--- a/examples/rp235x/src/bin/blinky_two_channels.rs
+++ b/examples/rp235x/src/bin/blinky_two_channels.rs
@@ -11,7 +11,7 @@ use embassy_rp::gpio;
11use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; 11use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
12use embassy_sync::channel::{Channel, Sender}; 12use embassy_sync::channel::{Channel, Sender};
13use embassy_time::{Duration, Ticker}; 13use embassy_time::{Duration, Ticker};
14use gpio::{AnyPin, Level, Output}; 14use gpio::{Level, Output};
15use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, panic_probe as _};
16 16
17enum LedState { 17enum LedState {
@@ -22,7 +22,7 @@ static CHANNEL: Channel<ThreadModeRawMutex, LedState, 64> = Channel::new();
22#[embassy_executor::main] 22#[embassy_executor::main]
23async fn main(spawner: Spawner) { 23async fn main(spawner: Spawner) {
24 let p = embassy_rp::init(Default::default()); 24 let p = embassy_rp::init(Default::default());
25 let mut led = Output::new(AnyPin::from(p.PIN_25), Level::High); 25 let mut led = Output::new(p.PIN_25, Level::High);
26 26
27 let dt = 100 * 1_000_000; 27 let dt = 100 * 1_000_000;
28 let k = 1.003; 28 let k = 1.003;
diff --git a/examples/rp235x/src/bin/blinky_two_tasks.rs b/examples/rp235x/src/bin/blinky_two_tasks.rs
index a57b513d6..67a9108c0 100644
--- a/examples/rp235x/src/bin/blinky_two_tasks.rs
+++ b/examples/rp235x/src/bin/blinky_two_tasks.rs
@@ -11,7 +11,7 @@ use embassy_rp::gpio;
11use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; 11use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
12use embassy_sync::mutex::Mutex; 12use embassy_sync::mutex::Mutex;
13use embassy_time::{Duration, Ticker}; 13use embassy_time::{Duration, Ticker};
14use gpio::{AnyPin, Level, Output}; 14use gpio::{Level, Output};
15use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, panic_probe as _};
16 16
17type LedType = Mutex<ThreadModeRawMutex, Option<Output<'static>>>; 17type LedType = Mutex<ThreadModeRawMutex, Option<Output<'static>>>;
@@ -21,7 +21,7 @@ static LED: LedType = Mutex::new(None);
21async fn main(spawner: Spawner) { 21async fn main(spawner: Spawner) {
22 let p = embassy_rp::init(Default::default()); 22 let p = embassy_rp::init(Default::default());
23 // set the content of the global LED reference to the real LED pin 23 // set the content of the global LED reference to the real LED pin
24 let led = Output::new(AnyPin::from(p.PIN_25), Level::High); 24 let led = Output::new(p.PIN_25, Level::High);
25 // inner scope is so that once the mutex is written to, the MutexGuard is dropped, thus the 25 // inner scope is so that once the mutex is written to, the MutexGuard is dropped, thus the
26 // Mutex is released 26 // Mutex is released
27 { 27 {
diff --git a/examples/rp235x/src/bin/pio_async.rs b/examples/rp235x/src/bin/pio_async.rs
index 08c702347..baf567b58 100644
--- a/examples/rp235x/src/bin/pio_async.rs
+++ b/examples/rp235x/src/bin/pio_async.rs
@@ -4,10 +4,10 @@
4#![no_main] 4#![no_main]
5use defmt::info; 5use defmt::info;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_rp::bind_interrupts;
8use embassy_rp::peripherals::PIO0; 7use embassy_rp::peripherals::PIO0;
9use embassy_rp::pio::program::pio_asm; 8use embassy_rp::pio::program::pio_asm;
10use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine}; 9use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine};
10use embassy_rp::{bind_interrupts, Peri};
11use fixed::traits::ToFixed; 11use fixed::traits::ToFixed;
12use fixed_macro::types::U56F8; 12use fixed_macro::types::U56F8;
13use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
@@ -16,7 +16,7 @@ bind_interrupts!(struct Irqs {
16 PIO0_IRQ_0 => InterruptHandler<PIO0>; 16 PIO0_IRQ_0 => InterruptHandler<PIO0>;
17}); 17});
18 18
19fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 0>, pin: impl PioPin) { 19fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 0>, pin: Peri<'a, impl PioPin>) {
20 // Setup sm0 20 // Setup sm0
21 21
22 // Send data serially to pin 22 // Send data serially to pin
diff --git a/examples/rp235x/src/bin/pio_dma.rs b/examples/rp235x/src/bin/pio_dma.rs
index da6e47a1b..64d603ba4 100644
--- a/examples/rp235x/src/bin/pio_dma.rs
+++ b/examples/rp235x/src/bin/pio_dma.rs
@@ -5,10 +5,10 @@
5use defmt::info; 5use defmt::info;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_futures::join::join; 7use embassy_futures::join::join;
8use embassy_rp::bind_interrupts;
8use embassy_rp::peripherals::PIO0; 9use embassy_rp::peripherals::PIO0;
9use embassy_rp::pio::program::pio_asm; 10use embassy_rp::pio::program::pio_asm;
10use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection}; 11use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection};
11use embassy_rp::{bind_interrupts, Peripheral};
12use fixed::traits::ToFixed; 12use fixed::traits::ToFixed;
13use fixed_macro::types::U56F8; 13use fixed_macro::types::U56F8;
14use {defmt_rtt as _, panic_probe as _}; 14use {defmt_rtt as _, panic_probe as _};
@@ -62,8 +62,8 @@ async fn main(_spawner: Spawner) {
62 sm.set_config(&cfg); 62 sm.set_config(&cfg);
63 sm.set_enable(true); 63 sm.set_enable(true);
64 64
65 let mut dma_out_ref = p.DMA_CH0.into_ref(); 65 let mut dma_out_ref = p.DMA_CH0;
66 let mut dma_in_ref = p.DMA_CH1.into_ref(); 66 let mut dma_in_ref = p.DMA_CH1;
67 let mut dout = [0x12345678u32; 29]; 67 let mut dout = [0x12345678u32; 29];
68 for i in 1..dout.len() { 68 for i in 1..dout.len() {
69 dout[i] = (dout[i - 1] & 0x0fff_ffff) * 13 + 7; 69 dout[i] = (dout[i - 1] & 0x0fff_ffff) * 13 + 7;
diff --git a/examples/rp235x/src/bin/pio_rotary_encoder_rxf.rs b/examples/rp235x/src/bin/pio_rotary_encoder_rxf.rs
index 0216c131b..ccc601661 100644
--- a/examples/rp235x/src/bin/pio_rotary_encoder_rxf.rs
+++ b/examples/rp235x/src/bin/pio_rotary_encoder_rxf.rs
@@ -9,7 +9,7 @@ use embassy_executor::Spawner;
9use embassy_rp::gpio::Pull; 9use embassy_rp::gpio::Pull;
10use embassy_rp::peripherals::PIO0; 10use embassy_rp::peripherals::PIO0;
11use embassy_rp::pio::program::pio_asm; 11use embassy_rp::pio::program::pio_asm;
12use embassy_rp::{bind_interrupts, pio}; 12use embassy_rp::{bind_interrupts, pio, Peri};
13use embassy_time::Timer; 13use embassy_time::Timer;
14use fixed::traits::ToFixed; 14use fixed::traits::ToFixed;
15use pio::{Common, Config, FifoJoin, Instance, InterruptHandler, Pio, PioPin, ShiftDirection, StateMachine}; 15use pio::{Common, Config, FifoJoin, Instance, InterruptHandler, Pio, PioPin, ShiftDirection, StateMachine};
@@ -37,8 +37,8 @@ impl<'d, T: Instance, const SM: usize> PioEncoder<'d, T, SM> {
37 pub fn new( 37 pub fn new(
38 pio: &mut Common<'d, T>, 38 pio: &mut Common<'d, T>,
39 mut sm: StateMachine<'d, T, SM>, 39 mut sm: StateMachine<'d, T, SM>,
40 pin_a: impl PioPin, 40 pin_a: Peri<'d, impl PioPin>,
41 pin_b: impl PioPin, 41 pin_b: Peri<'d, impl PioPin>,
42 ) -> Self { 42 ) -> Self {
43 let mut pin_a = pio.make_pio_pin(pin_a); 43 let mut pin_a = pio.make_pio_pin(pin_a);
44 let mut pin_b = pio.make_pio_pin(pin_b); 44 let mut pin_b = pio.make_pio_pin(pin_b);
diff --git a/examples/rp235x/src/bin/pwm.rs b/examples/rp235x/src/bin/pwm.rs
index a3c0f7e49..da1acc18a 100644
--- a/examples/rp235x/src/bin/pwm.rs
+++ b/examples/rp235x/src/bin/pwm.rs
@@ -11,6 +11,7 @@ use defmt::*;
11use embassy_executor::Spawner; 11use embassy_executor::Spawner;
12use embassy_rp::peripherals::{PIN_25, PIN_4, PWM_SLICE2, PWM_SLICE4}; 12use embassy_rp::peripherals::{PIN_25, PIN_4, PWM_SLICE2, PWM_SLICE4};
13use embassy_rp::pwm::{Config, Pwm, SetDutyCycle}; 13use embassy_rp::pwm::{Config, Pwm, SetDutyCycle};
14use embassy_rp::Peri;
14use embassy_time::Timer; 15use embassy_time::Timer;
15use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
16 17
@@ -26,7 +27,7 @@ async fn main(spawner: Spawner) {
26/// Using the onboard led, if You are using a different Board than plain Pico2 (i.e. W variant) 27/// Using the onboard led, if You are using a different Board than plain Pico2 (i.e. W variant)
27/// you must use another slice & pin and an appropriate resistor. 28/// you must use another slice & pin and an appropriate resistor.
28#[embassy_executor::task] 29#[embassy_executor::task]
29async fn pwm_set_config(slice4: PWM_SLICE4, pin25: PIN_25) { 30async fn pwm_set_config(slice4: Peri<'static, PWM_SLICE4>, pin25: Peri<'static, PIN_25>) {
30 let mut c = Config::default(); 31 let mut c = Config::default();
31 c.top = 32_768; 32 c.top = 32_768;
32 c.compare_b = 8; 33 c.compare_b = 8;
@@ -44,7 +45,7 @@ async fn pwm_set_config(slice4: PWM_SLICE4, pin25: PIN_25) {
44/// 45///
45/// Using GP4 in Slice2, make sure to use an appropriate resistor. 46/// Using GP4 in Slice2, make sure to use an appropriate resistor.
46#[embassy_executor::task] 47#[embassy_executor::task]
47async fn pwm_set_dutycycle(slice2: PWM_SLICE2, pin4: PIN_4) { 48async fn pwm_set_dutycycle(slice2: Peri<'static, PWM_SLICE2>, pin4: Peri<'static, PIN_4>) {
48 // If we aim for a specific frequency, here is how we can calculate the top value. 49 // If we aim for a specific frequency, here is how we can calculate the top value.
49 // The top value sets the period of the PWM cycle, so a counter goes from 0 to top and then wraps around to 0. 50 // The top value sets the period of the PWM cycle, so a counter goes from 0 to top and then wraps around to 0.
50 // Every such wraparound is one PWM cycle. So here is how we get 25KHz: 51 // Every such wraparound is one PWM cycle. So here is how we get 25KHz:
diff --git a/examples/rp235x/src/bin/pwm_tb6612fng_motor_driver.rs b/examples/rp235x/src/bin/pwm_tb6612fng_motor_driver.rs
index 3b700884c..2cfb2038d 100644
--- a/examples/rp235x/src/bin/pwm_tb6612fng_motor_driver.rs
+++ b/examples/rp235x/src/bin/pwm_tb6612fng_motor_driver.rs
@@ -10,7 +10,7 @@ use defmt::*;
10use embassy_executor::Spawner; 10use embassy_executor::Spawner;
11use embassy_rp::config::Config; 11use embassy_rp::config::Config;
12use embassy_rp::gpio::Output; 12use embassy_rp::gpio::Output;
13use embassy_rp::{gpio, peripherals, pwm}; 13use embassy_rp::{gpio, peripherals, pwm, Peri};
14use embassy_time::{Duration, Timer}; 14use embassy_time::{Duration, Timer};
15use tb6612fng::{DriveCommand, Motor, Tb6612fng}; 15use tb6612fng::{DriveCommand, Motor, Tb6612fng};
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
diff --git a/examples/rp235x/src/bin/shared_bus.rs b/examples/rp235x/src/bin/shared_bus.rs
index c6cb5d64c..9267dfccb 100644
--- a/examples/rp235x/src/bin/shared_bus.rs
+++ b/examples/rp235x/src/bin/shared_bus.rs
@@ -8,7 +8,7 @@ use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice;
8use embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice; 8use embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_rp::bind_interrupts; 10use embassy_rp::bind_interrupts;
11use embassy_rp::gpio::{AnyPin, Level, Output}; 11use embassy_rp::gpio::{Level, Output};
12use embassy_rp::i2c::{self, I2c, InterruptHandler}; 12use embassy_rp::i2c::{self, I2c, InterruptHandler};
13use embassy_rp::peripherals::{I2C1, SPI1}; 13use embassy_rp::peripherals::{I2C1, SPI1};
14use embassy_rp::spi::{self, Spi}; 14use embassy_rp::spi::{self, Spi};
@@ -45,8 +45,8 @@ async fn main(spawner: Spawner) {
45 let spi_bus = SPI_BUS.init(Mutex::new(spi)); 45 let spi_bus = SPI_BUS.init(Mutex::new(spi));
46 46
47 // Chip select pins for the SPI devices 47 // Chip select pins for the SPI devices
48 let cs_a = Output::new(AnyPin::from(p.PIN_0), Level::High); 48 let cs_a = Output::new(p.PIN_0, Level::High);
49 let cs_b = Output::new(AnyPin::from(p.PIN_1), Level::High); 49 let cs_b = Output::new(p.PIN_1, Level::High);
50 50
51 spawner.must_spawn(spi_task_a(spi_bus, cs_a)); 51 spawner.must_spawn(spi_task_a(spi_bus, cs_a));
52 spawner.must_spawn(spi_task_b(spi_bus, cs_b)); 52 spawner.must_spawn(spi_task_b(spi_bus, cs_b));
diff --git a/examples/rp235x/src/bin/zerocopy.rs b/examples/rp235x/src/bin/zerocopy.rs
index 39f03c8e4..d1fb0eb00 100644
--- a/examples/rp235x/src/bin/zerocopy.rs
+++ b/examples/rp235x/src/bin/zerocopy.rs
@@ -9,9 +9,9 @@ use core::sync::atomic::{AtomicU16, Ordering};
9use defmt::*; 9use defmt::*;
10use embassy_executor::Spawner; 10use embassy_executor::Spawner;
11use embassy_rp::adc::{self, Adc, Async, Config, InterruptHandler}; 11use embassy_rp::adc::{self, Adc, Async, Config, InterruptHandler};
12use embassy_rp::bind_interrupts;
13use embassy_rp::gpio::Pull; 12use embassy_rp::gpio::Pull;
14use embassy_rp::peripherals::DMA_CH0; 13use embassy_rp::peripherals::DMA_CH0;
14use embassy_rp::{bind_interrupts, Peri};
15use embassy_sync::blocking_mutex::raw::NoopRawMutex; 15use embassy_sync::blocking_mutex::raw::NoopRawMutex;
16use embassy_sync::zerocopy_channel::{Channel, Receiver, Sender}; 16use embassy_sync::zerocopy_channel::{Channel, Receiver, Sender};
17use embassy_time::{Duration, Ticker, Timer}; 17use embassy_time::{Duration, Ticker, Timer};
@@ -31,7 +31,7 @@ static MAX: AtomicU16 = AtomicU16::new(0);
31struct AdcParts { 31struct AdcParts {
32 adc: Adc<'static, Async>, 32 adc: Adc<'static, Async>,
33 pin: adc::Channel<'static>, 33 pin: adc::Channel<'static>,
34 dma: DMA_CH0, 34 dma: Peri<'static, DMA_CH0>,
35} 35}
36 36
37#[embassy_executor::main] 37#[embassy_executor::main]
@@ -70,7 +70,10 @@ async fn producer(mut sender: Sender<'static, NoopRawMutex, SampleBuffer>, mut a
70 let buf = sender.send().await; 70 let buf = sender.send().await;
71 71
72 // Fill it with data 72 // Fill it with data
73 adc.adc.read_many(&mut adc.pin, buf, 1, &mut adc.dma).await.unwrap(); 73 adc.adc
74 .read_many(&mut adc.pin, buf, 1, adc.dma.reborrow())
75 .await
76 .unwrap();
74 77
75 // Notify the channel that the buffer is now ready to be received 78 // Notify the channel that the buffer is now ready to be received
76 sender.send_done(); 79 sender.send_done();