diff options
Diffstat (limited to 'examples')
57 files changed, 180 insertions, 138 deletions
diff --git a/examples/nrf52840-rtic/src/bin/blinky.rs b/examples/nrf52840-rtic/src/bin/blinky.rs index 5a074ea17..719e22729 100644 --- a/examples/nrf52840-rtic/src/bin/blinky.rs +++ b/examples/nrf52840-rtic/src/bin/blinky.rs | |||
| @@ -8,7 +8,7 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 8 | mod app { | 8 | mod app { |
| 9 | use defmt::info; | 9 | use defmt::info; |
| 10 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 10 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
| 11 | use embassy_nrf::peripherals; | 11 | use embassy_nrf::{peripherals, Peri}; |
| 12 | use embassy_time::Timer; | 12 | use embassy_time::Timer; |
| 13 | 13 | ||
| 14 | #[shared] | 14 | #[shared] |
| @@ -28,7 +28,7 @@ mod app { | |||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | #[task(priority = 1)] | 30 | #[task(priority = 1)] |
| 31 | async fn blink(_cx: blink::Context, pin: peripherals::P0_13) { | 31 | async fn blink(_cx: blink::Context, pin: Peri<'static, peripherals::P0_13>) { |
| 32 | let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); | 32 | let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); |
| 33 | 33 | ||
| 34 | loop { | 34 | loop { |
diff --git a/examples/nrf52840/src/bin/channel_sender_receiver.rs b/examples/nrf52840/src/bin/channel_sender_receiver.rs index 29f70f91c..74c62ca20 100644 --- a/examples/nrf52840/src/bin/channel_sender_receiver.rs +++ b/examples/nrf52840/src/bin/channel_sender_receiver.rs | |||
| @@ -3,7 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::unwrap; | 4 | use defmt::unwrap; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; | 6 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive}; |
| 7 | use embassy_nrf::Peri; | ||
| 7 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | 8 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; |
| 8 | use embassy_sync::channel::{Channel, Receiver, Sender}; | 9 | use embassy_sync::channel::{Channel, Receiver, Sender}; |
| 9 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
| @@ -28,7 +29,7 @@ async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) { | |||
| 28 | } | 29 | } |
| 29 | 30 | ||
| 30 | #[embassy_executor::task] | 31 | #[embassy_executor::task] |
| 31 | async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedState, 1>) { | 32 | async fn recv_task(led: Peri<'static, AnyPin>, receiver: Receiver<'static, NoopRawMutex, LedState, 1>) { |
| 32 | let mut led = Output::new(led, Level::Low, OutputDrive::Standard); | 33 | let mut led = Output::new(led, Level::Low, OutputDrive::Standard); |
| 33 | 34 | ||
| 34 | loop { | 35 | loop { |
| @@ -45,5 +46,5 @@ async fn main(spawner: Spawner) { | |||
| 45 | let channel = CHANNEL.init(Channel::new()); | 46 | let channel = CHANNEL.init(Channel::new()); |
| 46 | 47 | ||
| 47 | unwrap!(spawner.spawn(send_task(channel.sender()))); | 48 | unwrap!(spawner.spawn(send_task(channel.sender()))); |
| 48 | unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver()))); | 49 | unwrap!(spawner.spawn(recv_task(p.P0_13.into(), channel.receiver()))); |
| 49 | } | 50 | } |
diff --git a/examples/nrf52840/src/bin/pdm_continuous.rs b/examples/nrf52840/src/bin/pdm_continuous.rs index e948203a5..0d76636b0 100644 --- a/examples/nrf52840/src/bin/pdm_continuous.rs +++ b/examples/nrf52840/src/bin/pdm_continuous.rs | |||
| @@ -20,14 +20,14 @@ bind_interrupts!(struct Irqs { | |||
| 20 | 20 | ||
| 21 | #[embassy_executor::main] | 21 | #[embassy_executor::main] |
| 22 | async fn main(_p: Spawner) { | 22 | async fn main(_p: Spawner) { |
| 23 | let mut p = embassy_nrf::init(Default::default()); | 23 | let p = embassy_nrf::init(Default::default()); |
| 24 | let mut config = Config::default(); | 24 | let mut config = Config::default(); |
| 25 | // Pins are correct for the onboard microphone on the Feather nRF52840 Sense. | 25 | // Pins are correct for the onboard microphone on the Feather nRF52840 Sense. |
| 26 | config.frequency = Frequency::_1280K; // 16 kHz sample rate | 26 | config.frequency = Frequency::_1280K; // 16 kHz sample rate |
| 27 | config.ratio = Ratio::RATIO80; | 27 | config.ratio = Ratio::RATIO80; |
| 28 | config.operation_mode = OperationMode::Mono; | 28 | config.operation_mode = OperationMode::Mono; |
| 29 | config.gain_left = I7F1::from_bits(5); // 2.5 dB | 29 | config.gain_left = I7F1::from_bits(5); // 2.5 dB |
| 30 | let mut pdm = Pdm::new(p.PDM, Irqs, &mut p.P0_00, &mut p.P0_01, config); | 30 | let mut pdm = Pdm::new(p.PDM, Irqs, p.P0_00, p.P0_01, config); |
| 31 | 31 | ||
| 32 | let mut bufs = [[0; 1024]; 2]; | 32 | let mut bufs = [[0; 1024]; 2]; |
| 33 | 33 | ||
diff --git a/examples/nrf52840/src/bin/qspi_lowpower.rs b/examples/nrf52840/src/bin/qspi_lowpower.rs index 516c9b481..238a0d941 100644 --- a/examples/nrf52840/src/bin/qspi_lowpower.rs +++ b/examples/nrf52840/src/bin/qspi_lowpower.rs | |||
| @@ -37,14 +37,14 @@ async fn main(_p: Spawner) { | |||
| 37 | }); | 37 | }); |
| 38 | 38 | ||
| 39 | let mut q = qspi::Qspi::new( | 39 | let mut q = qspi::Qspi::new( |
| 40 | &mut p.QSPI, | 40 | p.QSPI.reborrow(), |
| 41 | Irqs, | 41 | Irqs, |
| 42 | &mut p.P0_19, | 42 | p.P0_19.reborrow(), |
| 43 | &mut p.P0_17, | 43 | p.P0_17.reborrow(), |
| 44 | &mut p.P0_20, | 44 | p.P0_20.reborrow(), |
| 45 | &mut p.P0_21, | 45 | p.P0_21.reborrow(), |
| 46 | &mut p.P0_22, | 46 | p.P0_22.reborrow(), |
| 47 | &mut p.P0_23, | 47 | p.P0_23.reborrow(), |
| 48 | config, | 48 | config, |
| 49 | ); | 49 | ); |
| 50 | 50 | ||
diff --git a/examples/nrf52840/src/bin/saadc.rs b/examples/nrf52840/src/bin/saadc.rs index 653b7d606..cf2d860ab 100644 --- a/examples/nrf52840/src/bin/saadc.rs +++ b/examples/nrf52840/src/bin/saadc.rs | |||
| @@ -16,7 +16,7 @@ bind_interrupts!(struct Irqs { | |||
| 16 | async fn main(_p: Spawner) { | 16 | async fn main(_p: Spawner) { |
| 17 | let mut p = embassy_nrf::init(Default::default()); | 17 | let mut p = embassy_nrf::init(Default::default()); |
| 18 | let config = Config::default(); | 18 | let config = Config::default(); |
| 19 | let channel_config = ChannelConfig::single_ended(&mut p.P0_02); | 19 | let channel_config = ChannelConfig::single_ended(p.P0_02.reborrow()); |
| 20 | let mut saadc = Saadc::new(p.SAADC, Irqs, config, [channel_config]); | 20 | let mut saadc = Saadc::new(p.SAADC, Irqs, config, [channel_config]); |
| 21 | 21 | ||
| 22 | loop { | 22 | loop { |
diff --git a/examples/nrf52840/src/bin/saadc_continuous.rs b/examples/nrf52840/src/bin/saadc_continuous.rs index f76fa3570..e8f169c8c 100644 --- a/examples/nrf52840/src/bin/saadc_continuous.rs +++ b/examples/nrf52840/src/bin/saadc_continuous.rs | |||
| @@ -18,9 +18,9 @@ bind_interrupts!(struct Irqs { | |||
| 18 | async fn main(_p: Spawner) { | 18 | async fn main(_p: Spawner) { |
| 19 | let mut p = embassy_nrf::init(Default::default()); | 19 | let mut p = embassy_nrf::init(Default::default()); |
| 20 | let config = Config::default(); | 20 | let config = Config::default(); |
| 21 | let channel_1_config = ChannelConfig::single_ended(&mut p.P0_02); | 21 | let channel_1_config = ChannelConfig::single_ended(p.P0_02.reborrow()); |
| 22 | let channel_2_config = ChannelConfig::single_ended(&mut p.P0_03); | 22 | let channel_2_config = ChannelConfig::single_ended(p.P0_03.reborrow()); |
| 23 | let channel_3_config = ChannelConfig::single_ended(&mut p.P0_04); | 23 | let channel_3_config = ChannelConfig::single_ended(p.P0_04.reborrow()); |
| 24 | let mut saadc = Saadc::new( | 24 | let mut saadc = Saadc::new( |
| 25 | p.SAADC, | 25 | p.SAADC, |
| 26 | Irqs, | 26 | Irqs, |
| @@ -40,9 +40,9 @@ async fn main(_p: Spawner) { | |||
| 40 | 40 | ||
| 41 | saadc | 41 | saadc |
| 42 | .run_task_sampler( | 42 | .run_task_sampler( |
| 43 | &mut p.TIMER0, | 43 | p.TIMER0.reborrow(), |
| 44 | &mut p.PPI_CH0, | 44 | p.PPI_CH0.reborrow(), |
| 45 | &mut p.PPI_CH1, | 45 | p.PPI_CH1.reborrow(), |
| 46 | Frequency::F1MHz, | 46 | Frequency::F1MHz, |
| 47 | 1000, // We want to sample at 1KHz | 47 | 1000, // We want to sample at 1KHz |
| 48 | &mut bufs, | 48 | &mut bufs, |
diff --git a/examples/nrf52840/src/bin/twim_lowpower.rs b/examples/nrf52840/src/bin/twim_lowpower.rs index e2efbdd8d..8a6f958eb 100644 --- a/examples/nrf52840/src/bin/twim_lowpower.rs +++ b/examples/nrf52840/src/bin/twim_lowpower.rs | |||
| @@ -32,7 +32,13 @@ async fn main(_p: Spawner) { | |||
| 32 | let config = twim::Config::default(); | 32 | let config = twim::Config::default(); |
| 33 | 33 | ||
| 34 | // Create the TWIM instance with borrowed singletons, so they're not consumed. | 34 | // Create the TWIM instance with borrowed singletons, so they're not consumed. |
| 35 | let mut twi = Twim::new(&mut p.TWISPI0, Irqs, &mut p.P0_03, &mut p.P0_04, config); | 35 | let mut twi = Twim::new( |
| 36 | p.TWISPI0.reborrow(), | ||
| 37 | Irqs, | ||
| 38 | p.P0_03.reborrow(), | ||
| 39 | p.P0_04.reborrow(), | ||
| 40 | config, | ||
| 41 | ); | ||
| 36 | 42 | ||
| 37 | info!("Reading..."); | 43 | info!("Reading..."); |
| 38 | 44 | ||
diff --git a/examples/nrf9160/src/bin/modem_tcp_client.rs b/examples/nrf9160/src/bin/modem_tcp_client.rs index 35900cdd8..2ba964b1f 100644 --- a/examples/nrf9160/src/bin/modem_tcp_client.rs +++ b/examples/nrf9160/src/bin/modem_tcp_client.rs | |||
| @@ -13,9 +13,9 @@ use embassy_net::{Ipv4Cidr, Stack, StackResources}; | |||
| 13 | use embassy_net_nrf91::context::Status; | 13 | use embassy_net_nrf91::context::Status; |
| 14 | use embassy_net_nrf91::{context, Runner, State, TraceBuffer, TraceReader}; | 14 | use embassy_net_nrf91::{context, Runner, State, TraceBuffer, TraceReader}; |
| 15 | use embassy_nrf::buffered_uarte::{self, BufferedUarteTx}; | 15 | use embassy_nrf::buffered_uarte::{self, BufferedUarteTx}; |
| 16 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; | 16 | use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive}; |
| 17 | use embassy_nrf::uarte::Baudrate; | 17 | use embassy_nrf::uarte::Baudrate; |
| 18 | use embassy_nrf::{bind_interrupts, interrupt, peripherals, uarte}; | 18 | use embassy_nrf::{bind_interrupts, interrupt, peripherals, uarte, Peri}; |
| 19 | use embassy_time::{Duration, Timer}; | 19 | use embassy_time::{Duration, Timer}; |
| 20 | use embedded_io_async::Write; | 20 | use embedded_io_async::Write; |
| 21 | use heapless::Vec; | 21 | use heapless::Vec; |
| @@ -91,7 +91,7 @@ fn status_to_config(status: &Status) -> embassy_net::ConfigV4 { | |||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | #[embassy_executor::task] | 93 | #[embassy_executor::task] |
| 94 | async fn blink_task(pin: AnyPin) { | 94 | async fn blink_task(pin: Peri<'static, AnyPin>) { |
| 95 | let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); | 95 | let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); |
| 96 | loop { | 96 | loop { |
| 97 | led.set_high(); | 97 | led.set_high(); |
| @@ -112,7 +112,7 @@ async fn main(spawner: Spawner) { | |||
| 112 | 112 | ||
| 113 | info!("Hello World!"); | 113 | info!("Hello World!"); |
| 114 | 114 | ||
| 115 | unwrap!(spawner.spawn(blink_task(p.P0_02.degrade()))); | 115 | unwrap!(spawner.spawn(blink_task(p.P0_02.into()))); |
| 116 | 116 | ||
| 117 | let ipc_mem = unsafe { | 117 | let ipc_mem = unsafe { |
| 118 | let ipc_start = &__start_ipc as *const u8 as *mut MaybeUninit<u8>; | 118 | let ipc_start = &__start_ipc as *const u8 as *mut MaybeUninit<u8>; |
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index cde804a15..4fc1d35d6 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml | |||
| @@ -30,7 +30,7 @@ serde = { version = "1.0.203", default-features = false, features = ["derive"] } | |||
| 30 | serde-json-core = "0.5.1" | 30 | serde-json-core = "0.5.1" |
| 31 | 31 | ||
| 32 | # for assign resources example | 32 | # for assign resources example |
| 33 | assign-resources = { git = "https://github.com/adamgreig/assign-resources", rev = "94ad10e2729afdf0fd5a77cd12e68409a982f58a" } | 33 | assign-resources = { git = "https://github.com/adamgreig/assign-resources", rev = "bd22cb7a92031fb16f74a5da42469d466c33383e" } |
| 34 | 34 | ||
| 35 | #cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 35 | #cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 36 | cortex-m = { version = "0.7.6", features = ["inline-asm"] } | 36 | cortex-m = { version = "0.7.6", features = ["inline-asm"] } |
diff --git a/examples/rp/src/bin/adc_dma.rs b/examples/rp/src/bin/adc_dma.rs index f755cf5bf..b42c13fde 100644 --- a/examples/rp/src/bin/adc_dma.rs +++ b/examples/rp/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/rp/src/bin/assign_resources.rs b/examples/rp/src/bin/assign_resources.rs index ff6eff4a2..341f54d22 100644 --- a/examples/rp/src/bin/assign_resources.rs +++ b/examples/rp/src/bin/assign_resources.rs | |||
| @@ -16,6 +16,7 @@ use defmt::*; | |||
| 16 | use embassy_executor::Spawner; | 16 | use embassy_executor::Spawner; |
| 17 | use embassy_rp::gpio::{Level, Output}; | 17 | use embassy_rp::gpio::{Level, Output}; |
| 18 | use embassy_rp::peripherals::{self, PIN_20, PIN_21}; | 18 | use embassy_rp::peripherals::{self, PIN_20, PIN_21}; |
| 19 | use embassy_rp::Peri; | ||
| 19 | use embassy_time::Timer; | 20 | use embassy_time::Timer; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 21 | use {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] |
| 41 | async fn double_blinky_manually_assigned(_spawner: Spawner, pin_20: PIN_20, pin_21: PIN_21) { | 42 | async 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/rp/src/bin/blinky_two_channels.rs b/examples/rp/src/bin/blinky_two_channels.rs index b2eec2a21..51e139e94 100644 --- a/examples/rp/src/bin/blinky_two_channels.rs +++ b/examples/rp/src/bin/blinky_two_channels.rs | |||
| @@ -11,7 +11,7 @@ use embassy_rp::gpio; | |||
| 11 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | 11 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 12 | use embassy_sync::channel::{Channel, Sender}; | 12 | use embassy_sync::channel::{Channel, Sender}; |
| 13 | use embassy_time::{Duration, Ticker}; | 13 | use embassy_time::{Duration, Ticker}; |
| 14 | use gpio::{AnyPin, Level, Output}; | 14 | use gpio::{Level, Output}; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | 16 | ||
| 17 | enum LedState { | 17 | enum LedState { |
| @@ -22,7 +22,7 @@ static CHANNEL: Channel<ThreadModeRawMutex, LedState, 64> = Channel::new(); | |||
| 22 | #[embassy_executor::main] | 22 | #[embassy_executor::main] |
| 23 | async fn main(spawner: Spawner) { | 23 | async 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/rp/src/bin/blinky_two_tasks.rs b/examples/rp/src/bin/blinky_two_tasks.rs index a57b513d6..67a9108c0 100644 --- a/examples/rp/src/bin/blinky_two_tasks.rs +++ b/examples/rp/src/bin/blinky_two_tasks.rs | |||
| @@ -11,7 +11,7 @@ use embassy_rp::gpio; | |||
| 11 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | 11 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 12 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 13 | use embassy_time::{Duration, Ticker}; | 13 | use embassy_time::{Duration, Ticker}; |
| 14 | use gpio::{AnyPin, Level, Output}; | 14 | use gpio::{Level, Output}; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | 16 | ||
| 17 | type LedType = Mutex<ThreadModeRawMutex, Option<Output<'static>>>; | 17 | type LedType = Mutex<ThreadModeRawMutex, Option<Output<'static>>>; |
| @@ -21,7 +21,7 @@ static LED: LedType = Mutex::new(None); | |||
| 21 | async fn main(spawner: Spawner) { | 21 | async 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/rp/src/bin/orchestrate_tasks.rs b/examples/rp/src/bin/orchestrate_tasks.rs index 7ff004860..5e2775793 100644 --- a/examples/rp/src/bin/orchestrate_tasks.rs +++ b/examples/rp/src/bin/orchestrate_tasks.rs | |||
| @@ -24,7 +24,7 @@ use embassy_futures::select::{select, Either}; | |||
| 24 | use embassy_rp::adc::{Adc, Channel, Config, InterruptHandler}; | 24 | use embassy_rp::adc::{Adc, Channel, Config, InterruptHandler}; |
| 25 | use embassy_rp::clocks::RoscRng; | 25 | use embassy_rp::clocks::RoscRng; |
| 26 | use embassy_rp::gpio::{Input, Pull}; | 26 | use embassy_rp::gpio::{Input, Pull}; |
| 27 | use embassy_rp::{bind_interrupts, peripherals}; | 27 | use embassy_rp::{bind_interrupts, peripherals, Peri}; |
| 28 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 28 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 29 | use embassy_sync::mutex::Mutex; | 29 | use embassy_sync::mutex::Mutex; |
| 30 | use embassy_sync::{channel, signal}; | 30 | use embassy_sync::{channel, signal}; |
diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs index 08c702347..bf6dbee69 100644 --- a/examples/rp/src/bin/pio_async.rs +++ b/examples/rp/src/bin/pio_async.rs | |||
| @@ -4,10 +4,10 @@ | |||
| 4 | #![no_main] | 4 | #![no_main] |
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_rp::bind_interrupts; | ||
| 8 | use embassy_rp::peripherals::PIO0; | 7 | use embassy_rp::peripherals::PIO0; |
| 9 | use embassy_rp::pio::program::pio_asm; | 8 | use embassy_rp::pio::program::pio_asm; |
| 10 | use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine}; | 9 | use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine}; |
| 10 | use embassy_rp::{bind_interrupts, Peri}; | ||
| 11 | use fixed::traits::ToFixed; | 11 | use fixed::traits::ToFixed; |
| 12 | use fixed_macro::types::U56F8; | 12 | use fixed_macro::types::U56F8; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {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 | ||
| 19 | fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 0>, pin: impl PioPin) { | 19 | fn setup_pio_task_sm0<'d>(pio: &mut Common<'d, PIO0>, sm: &mut StateMachine<'d, PIO0, 0>, pin: Peri<'d, impl PioPin>) { |
| 20 | // Setup sm0 | 20 | // Setup sm0 |
| 21 | 21 | ||
| 22 | // Send data serially to pin | 22 | // Send data serially to pin |
| @@ -50,7 +50,7 @@ async fn pio_task_sm0(mut sm: StateMachine<'static, PIO0, 0>) { | |||
| 50 | } | 50 | } |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | fn setup_pio_task_sm1<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 1>) { | 53 | fn setup_pio_task_sm1<'d>(pio: &mut Common<'d, PIO0>, sm: &mut StateMachine<'d, PIO0, 1>) { |
| 54 | // Setupm sm1 | 54 | // Setupm sm1 |
| 55 | 55 | ||
| 56 | // Read 0b10101 repeatedly until ISR is full | 56 | // Read 0b10101 repeatedly until ISR is full |
| @@ -80,7 +80,7 @@ async fn pio_task_sm1(mut sm: StateMachine<'static, PIO0, 1>) { | |||
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | fn setup_pio_task_sm2<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 2>) { | 83 | fn setup_pio_task_sm2<'d>(pio: &mut Common<'d, PIO0>, sm: &mut StateMachine<'d, PIO0, 2>) { |
| 84 | // Setup sm2 | 84 | // Setup sm2 |
| 85 | 85 | ||
| 86 | // Repeatedly trigger IRQ 3 | 86 | // Repeatedly trigger IRQ 3 |
diff --git a/examples/rp/src/bin/pio_dma.rs b/examples/rp/src/bin/pio_dma.rs index da6e47a1b..64d603ba4 100644 --- a/examples/rp/src/bin/pio_dma.rs +++ b/examples/rp/src/bin/pio_dma.rs | |||
| @@ -5,10 +5,10 @@ | |||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_futures::join::join; | 7 | use embassy_futures::join::join; |
| 8 | use embassy_rp::bind_interrupts; | ||
| 8 | use embassy_rp::peripherals::PIO0; | 9 | use embassy_rp::peripherals::PIO0; |
| 9 | use embassy_rp::pio::program::pio_asm; | 10 | use embassy_rp::pio::program::pio_asm; |
| 10 | use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection}; | 11 | use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection}; |
| 11 | use embassy_rp::{bind_interrupts, Peripheral}; | ||
| 12 | use fixed::traits::ToFixed; | 12 | use fixed::traits::ToFixed; |
| 13 | use fixed_macro::types::U56F8; | 13 | use fixed_macro::types::U56F8; |
| 14 | use {defmt_rtt as _, panic_probe as _}; | 14 | use {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/rp/src/bin/pio_i2s.rs b/examples/rp/src/bin/pio_i2s.rs index 447100ddf..192c8f854 100644 --- a/examples/rp/src/bin/pio_i2s.rs +++ b/examples/rp/src/bin/pio_i2s.rs | |||
| @@ -14,6 +14,7 @@ use core::mem; | |||
| 14 | 14 | ||
| 15 | use embassy_executor::Spawner; | 15 | use embassy_executor::Spawner; |
| 16 | use embassy_rp::bind_interrupts; | 16 | use embassy_rp::bind_interrupts; |
| 17 | use embassy_rp::bootsel::is_bootsel_pressed; | ||
| 17 | use embassy_rp::peripherals::PIO0; | 18 | use embassy_rp::peripherals::PIO0; |
| 18 | use embassy_rp::pio::{InterruptHandler, Pio}; | 19 | use embassy_rp::pio::{InterruptHandler, Pio}; |
| 19 | use embassy_rp::pio_programs::i2s::{PioI2sOut, PioI2sOutProgram}; | 20 | use embassy_rp::pio_programs::i2s::{PioI2sOut, PioI2sOutProgram}; |
| @@ -70,7 +71,11 @@ async fn main(_spawner: Spawner) { | |||
| 70 | let dma_future = i2s.write(front_buffer); | 71 | let dma_future = i2s.write(front_buffer); |
| 71 | 72 | ||
| 72 | // fade in audio when bootsel is pressed | 73 | // fade in audio when bootsel is pressed |
| 73 | let fade_target = if p.BOOTSEL.is_pressed() { i32::MAX } else { 0 }; | 74 | let fade_target = if is_bootsel_pressed(p.BOOTSEL.reborrow()) { |
| 75 | i32::MAX | ||
| 76 | } else { | ||
| 77 | 0 | ||
| 78 | }; | ||
| 74 | 79 | ||
| 75 | // fill back buffer with fresh audio samples before awaiting the dma future | 80 | // fill back buffer with fresh audio samples before awaiting the dma future |
| 76 | for s in back_buffer.iter_mut() { | 81 | for s in back_buffer.iter_mut() { |
diff --git a/examples/rp/src/bin/pwm.rs b/examples/rp/src/bin/pwm.rs index 2f5f94870..04374323d 100644 --- a/examples/rp/src/bin/pwm.rs +++ b/examples/rp/src/bin/pwm.rs | |||
| @@ -11,6 +11,7 @@ use defmt::*; | |||
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_rp::peripherals::{PIN_25, PIN_4, PWM_SLICE2, PWM_SLICE4}; | 12 | use embassy_rp::peripherals::{PIN_25, PIN_4, PWM_SLICE2, PWM_SLICE4}; |
| 13 | use embassy_rp::pwm::{Config, Pwm, SetDutyCycle}; | 13 | use embassy_rp::pwm::{Config, Pwm, SetDutyCycle}; |
| 14 | use embassy_rp::Peri; | ||
| 14 | use embassy_time::Timer; | 15 | use embassy_time::Timer; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {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] |
| 29 | async fn pwm_set_config(slice4: PWM_SLICE4, pin25: PIN_25) { | 30 | async 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] |
| 47 | async fn pwm_set_dutycycle(slice2: PWM_SLICE2, pin4: PIN_4) { | 48 | async 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/rp/src/bin/shared_bus.rs b/examples/rp/src/bin/shared_bus.rs index c6cb5d64c..9267dfccb 100644 --- a/examples/rp/src/bin/shared_bus.rs +++ b/examples/rp/src/bin/shared_bus.rs | |||
| @@ -8,7 +8,7 @@ use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice; | |||
| 8 | use embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice; | 8 | use embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice; |
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_rp::bind_interrupts; | 10 | use embassy_rp::bind_interrupts; |
| 11 | use embassy_rp::gpio::{AnyPin, Level, Output}; | 11 | use embassy_rp::gpio::{Level, Output}; |
| 12 | use embassy_rp::i2c::{self, I2c, InterruptHandler}; | 12 | use embassy_rp::i2c::{self, I2c, InterruptHandler}; |
| 13 | use embassy_rp::peripherals::{I2C1, SPI1}; | 13 | use embassy_rp::peripherals::{I2C1, SPI1}; |
| 14 | use embassy_rp::spi::{self, Spi}; | 14 | use 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/rp/src/bin/zerocopy.rs b/examples/rp/src/bin/zerocopy.rs index 39f03c8e4..d1fb0eb00 100644 --- a/examples/rp/src/bin/zerocopy.rs +++ b/examples/rp/src/bin/zerocopy.rs | |||
| @@ -9,9 +9,9 @@ use core::sync::atomic::{AtomicU16, Ordering}; | |||
| 9 | use defmt::*; | 9 | use defmt::*; |
| 10 | use embassy_executor::Spawner; | 10 | use embassy_executor::Spawner; |
| 11 | use embassy_rp::adc::{self, Adc, Async, Config, InterruptHandler}; | 11 | use embassy_rp::adc::{self, Adc, Async, Config, InterruptHandler}; |
| 12 | use embassy_rp::bind_interrupts; | ||
| 13 | use embassy_rp::gpio::Pull; | 12 | use embassy_rp::gpio::Pull; |
| 14 | use embassy_rp::peripherals::DMA_CH0; | 13 | use embassy_rp::peripherals::DMA_CH0; |
| 14 | use embassy_rp::{bind_interrupts, Peri}; | ||
| 15 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | 15 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; |
| 16 | use embassy_sync::zerocopy_channel::{Channel, Receiver, Sender}; | 16 | use embassy_sync::zerocopy_channel::{Channel, Receiver, Sender}; |
| 17 | use embassy_time::{Duration, Ticker, Timer}; | 17 | use embassy_time::{Duration, Ticker, Timer}; |
| @@ -31,7 +31,7 @@ static MAX: AtomicU16 = AtomicU16::new(0); | |||
| 31 | struct AdcParts { | 31 | struct 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(); |
diff --git a/examples/rp235x/Cargo.toml b/examples/rp235x/Cargo.toml index 4e9c93e7c..c9e0ee120 100644 --- a/examples/rp235x/Cargo.toml +++ b/examples/rp235x/Cargo.toml | |||
| @@ -28,7 +28,7 @@ serde = { version = "1.0.203", default-features = false, features = ["derive"] } | |||
| 28 | serde-json-core = "0.5.1" | 28 | serde-json-core = "0.5.1" |
| 29 | 29 | ||
| 30 | # for assign resources example | 30 | # for assign resources example |
| 31 | assign-resources = { git = "https://github.com/adamgreig/assign-resources", rev = "94ad10e2729afdf0fd5a77cd12e68409a982f58a" } | 31 | assign-resources = { git = "https://github.com/adamgreig/assign-resources", rev = "bd22cb7a92031fb16f74a5da42469d466c33383e" } |
| 32 | 32 | ||
| 33 | # for TB6612FNG example | 33 | # for TB6612FNG example |
| 34 | tb6612fng = "1.0.0" | 34 | tb6612fng = "1.0.0" |
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::*; | |||
| 16 | use embassy_executor::Spawner; | 16 | use embassy_executor::Spawner; |
| 17 | use embassy_rp::gpio::{Level, Output}; | 17 | use embassy_rp::gpio::{Level, Output}; |
| 18 | use embassy_rp::peripherals::{self, PIN_20, PIN_21}; | 18 | use embassy_rp::peripherals::{self, PIN_20, PIN_21}; |
| 19 | use embassy_rp::Peri; | ||
| 19 | use embassy_time::Timer; | 20 | use embassy_time::Timer; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 21 | use {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] |
| 41 | async fn double_blinky_manually_assigned(_spawner: Spawner, pin_20: PIN_20, pin_21: PIN_21) { | 42 | async 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; | |||
| 11 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | 11 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 12 | use embassy_sync::channel::{Channel, Sender}; | 12 | use embassy_sync::channel::{Channel, Sender}; |
| 13 | use embassy_time::{Duration, Ticker}; | 13 | use embassy_time::{Duration, Ticker}; |
| 14 | use gpio::{AnyPin, Level, Output}; | 14 | use gpio::{Level, Output}; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | 16 | ||
| 17 | enum LedState { | 17 | enum LedState { |
| @@ -22,7 +22,7 @@ static CHANNEL: Channel<ThreadModeRawMutex, LedState, 64> = Channel::new(); | |||
| 22 | #[embassy_executor::main] | 22 | #[embassy_executor::main] |
| 23 | async fn main(spawner: Spawner) { | 23 | async 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; | |||
| 11 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; | 11 | use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; |
| 12 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 13 | use embassy_time::{Duration, Ticker}; | 13 | use embassy_time::{Duration, Ticker}; |
| 14 | use gpio::{AnyPin, Level, Output}; | 14 | use gpio::{Level, Output}; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 16 | 16 | ||
| 17 | type LedType = Mutex<ThreadModeRawMutex, Option<Output<'static>>>; | 17 | type LedType = Mutex<ThreadModeRawMutex, Option<Output<'static>>>; |
| @@ -21,7 +21,7 @@ static LED: LedType = Mutex::new(None); | |||
| 21 | async fn main(spawner: Spawner) { | 21 | async 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] |
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_rp::bind_interrupts; | ||
| 8 | use embassy_rp::peripherals::PIO0; | 7 | use embassy_rp::peripherals::PIO0; |
| 9 | use embassy_rp::pio::program::pio_asm; | 8 | use embassy_rp::pio::program::pio_asm; |
| 10 | use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine}; | 9 | use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine}; |
| 10 | use embassy_rp::{bind_interrupts, Peri}; | ||
| 11 | use fixed::traits::ToFixed; | 11 | use fixed::traits::ToFixed; |
| 12 | use fixed_macro::types::U56F8; | 12 | use fixed_macro::types::U56F8; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {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 | ||
| 19 | fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 0>, pin: impl PioPin) { | 19 | fn 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 @@ | |||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_futures::join::join; | 7 | use embassy_futures::join::join; |
| 8 | use embassy_rp::bind_interrupts; | ||
| 8 | use embassy_rp::peripherals::PIO0; | 9 | use embassy_rp::peripherals::PIO0; |
| 9 | use embassy_rp::pio::program::pio_asm; | 10 | use embassy_rp::pio::program::pio_asm; |
| 10 | use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection}; | 11 | use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection}; |
| 11 | use embassy_rp::{bind_interrupts, Peripheral}; | ||
| 12 | use fixed::traits::ToFixed; | 12 | use fixed::traits::ToFixed; |
| 13 | use fixed_macro::types::U56F8; | 13 | use fixed_macro::types::U56F8; |
| 14 | use {defmt_rtt as _, panic_probe as _}; | 14 | use {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; | |||
| 9 | use embassy_rp::gpio::Pull; | 9 | use embassy_rp::gpio::Pull; |
| 10 | use embassy_rp::peripherals::PIO0; | 10 | use embassy_rp::peripherals::PIO0; |
| 11 | use embassy_rp::pio::program::pio_asm; | 11 | use embassy_rp::pio::program::pio_asm; |
| 12 | use embassy_rp::{bind_interrupts, pio}; | 12 | use embassy_rp::{bind_interrupts, pio, Peri}; |
| 13 | use embassy_time::Timer; | 13 | use embassy_time::Timer; |
| 14 | use fixed::traits::ToFixed; | 14 | use fixed::traits::ToFixed; |
| 15 | use pio::{Common, Config, FifoJoin, Instance, InterruptHandler, Pio, PioPin, ShiftDirection, StateMachine}; | 15 | use 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::*; | |||
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_rp::peripherals::{PIN_25, PIN_4, PWM_SLICE2, PWM_SLICE4}; | 12 | use embassy_rp::peripherals::{PIN_25, PIN_4, PWM_SLICE2, PWM_SLICE4}; |
| 13 | use embassy_rp::pwm::{Config, Pwm, SetDutyCycle}; | 13 | use embassy_rp::pwm::{Config, Pwm, SetDutyCycle}; |
| 14 | use embassy_rp::Peri; | ||
| 14 | use embassy_time::Timer; | 15 | use embassy_time::Timer; |
| 15 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {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] |
| 29 | async fn pwm_set_config(slice4: PWM_SLICE4, pin25: PIN_25) { | 30 | async 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] |
| 47 | async fn pwm_set_dutycycle(slice2: PWM_SLICE2, pin4: PIN_4) { | 48 | async 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::*; | |||
| 10 | use embassy_executor::Spawner; | 10 | use embassy_executor::Spawner; |
| 11 | use embassy_rp::config::Config; | 11 | use embassy_rp::config::Config; |
| 12 | use embassy_rp::gpio::Output; | 12 | use embassy_rp::gpio::Output; |
| 13 | use embassy_rp::{gpio, peripherals, pwm}; | 13 | use embassy_rp::{gpio, peripherals, pwm, Peri}; |
| 14 | use embassy_time::{Duration, Timer}; | 14 | use embassy_time::{Duration, Timer}; |
| 15 | use tb6612fng::{DriveCommand, Motor, Tb6612fng}; | 15 | use tb6612fng::{DriveCommand, Motor, Tb6612fng}; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {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; | |||
| 8 | use embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice; | 8 | use embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice; |
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_rp::bind_interrupts; | 10 | use embassy_rp::bind_interrupts; |
| 11 | use embassy_rp::gpio::{AnyPin, Level, Output}; | 11 | use embassy_rp::gpio::{Level, Output}; |
| 12 | use embassy_rp::i2c::{self, I2c, InterruptHandler}; | 12 | use embassy_rp::i2c::{self, I2c, InterruptHandler}; |
| 13 | use embassy_rp::peripherals::{I2C1, SPI1}; | 13 | use embassy_rp::peripherals::{I2C1, SPI1}; |
| 14 | use embassy_rp::spi::{self, Spi}; | 14 | use 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}; | |||
| 9 | use defmt::*; | 9 | use defmt::*; |
| 10 | use embassy_executor::Spawner; | 10 | use embassy_executor::Spawner; |
| 11 | use embassy_rp::adc::{self, Adc, Async, Config, InterruptHandler}; | 11 | use embassy_rp::adc::{self, Adc, Async, Config, InterruptHandler}; |
| 12 | use embassy_rp::bind_interrupts; | ||
| 13 | use embassy_rp::gpio::Pull; | 12 | use embassy_rp::gpio::Pull; |
| 14 | use embassy_rp::peripherals::DMA_CH0; | 13 | use embassy_rp::peripherals::DMA_CH0; |
| 14 | use embassy_rp::{bind_interrupts, Peri}; | ||
| 15 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | 15 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; |
| 16 | use embassy_sync::zerocopy_channel::{Channel, Receiver, Sender}; | 16 | use embassy_sync::zerocopy_channel::{Channel, Receiver, Sender}; |
| 17 | use embassy_time::{Duration, Ticker, Timer}; | 17 | use embassy_time::{Duration, Ticker, Timer}; |
| @@ -31,7 +31,7 @@ static MAX: AtomicU16 = AtomicU16::new(0); | |||
| 31 | struct AdcParts { | 31 | struct 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(); |
diff --git a/examples/stm32c0/src/bin/adc.rs b/examples/stm32c0/src/bin/adc.rs index 10481f4d2..1f54b0b18 100644 --- a/examples/stm32c0/src/bin/adc.rs +++ b/examples/stm32c0/src/bin/adc.rs | |||
| @@ -36,7 +36,8 @@ async fn main(_spawner: Spawner) { | |||
| 36 | ); | 36 | ); |
| 37 | 37 | ||
| 38 | let channels_seqence: [&mut AnyAdcChannel<ADC1>; 3] = [&mut vref, &mut temp, &mut pin0]; | 38 | let channels_seqence: [&mut AnyAdcChannel<ADC1>; 3] = [&mut vref, &mut temp, &mut pin0]; |
| 39 | adc.read(&mut dma, channels_seqence.into_iter(), &mut read_buffer).await; | 39 | adc.read(dma.reborrow(), channels_seqence.into_iter(), &mut read_buffer) |
| 40 | .await; | ||
| 40 | // Values are ordered according to hardware ADC channel number! | 41 | // Values are ordered according to hardware ADC channel number! |
| 41 | info!( | 42 | info!( |
| 42 | "DMA ADC read in set: vref = {}, temp = {}, pin0 = {}.", | 43 | "DMA ADC read in set: vref = {}, temp = {}, pin0 = {}.", |
| @@ -45,7 +46,7 @@ async fn main(_spawner: Spawner) { | |||
| 45 | 46 | ||
| 46 | let hw_channel_selection: u32 = | 47 | let hw_channel_selection: u32 = |
| 47 | (1 << temp.get_hw_channel()) + (1 << vref.get_hw_channel()) + (1 << pin0.get_hw_channel()); | 48 | (1 << temp.get_hw_channel()) + (1 << vref.get_hw_channel()) + (1 << pin0.get_hw_channel()); |
| 48 | adc.read_in_hw_order(&mut dma, hw_channel_selection, Scandir::UP, &mut read_buffer) | 49 | adc.read_in_hw_order(dma.reborrow(), hw_channel_selection, Scandir::UP, &mut read_buffer) |
| 49 | .await; | 50 | .await; |
| 50 | info!( | 51 | info!( |
| 51 | "DMA ADC read in hardware order: vref = {}, temp = {}, pin0 = {}.", | 52 | "DMA ADC read in hardware order: vref = {}, temp = {}, pin0 = {}.", |
diff --git a/examples/stm32f0/src/bin/button_controlled_blink.rs b/examples/stm32f0/src/bin/button_controlled_blink.rs index 4465483d9..744df3e3b 100644 --- a/examples/stm32f0/src/bin/button_controlled_blink.rs +++ b/examples/stm32f0/src/bin/button_controlled_blink.rs | |||
| @@ -8,14 +8,15 @@ use core::sync::atomic::{AtomicU32, Ordering}; | |||
| 8 | use defmt::info; | 8 | use defmt::info; |
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 10 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Pull, Speed}; | 11 | use embassy_stm32::gpio::{AnyPin, Level, Output, Pull, Speed}; |
| 12 | use embassy_stm32::Peri; | ||
| 12 | use embassy_time::Timer; | 13 | use embassy_time::Timer; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 14 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 15 | ||
| 15 | static BLINK_MS: AtomicU32 = AtomicU32::new(0); | 16 | static BLINK_MS: AtomicU32 = AtomicU32::new(0); |
| 16 | 17 | ||
| 17 | #[embassy_executor::task] | 18 | #[embassy_executor::task] |
| 18 | async fn led_task(led: AnyPin) { | 19 | async fn led_task(led: Peri<'static, AnyPin>) { |
| 19 | // Configure the LED pin as a push pull output and obtain handler. | 20 | // Configure the LED pin as a push pull output and obtain handler. |
| 20 | // On the Nucleo F091RC there's an on-board LED connected to pin PA5. | 21 | // On the Nucleo F091RC there's an on-board LED connected to pin PA5. |
| 21 | let mut led = Output::new(led, Level::Low, Speed::Low); | 22 | let mut led = Output::new(led, Level::Low, Speed::Low); |
| @@ -45,7 +46,7 @@ async fn main(spawner: Spawner) { | |||
| 45 | BLINK_MS.store(del_var, Ordering::Relaxed); | 46 | BLINK_MS.store(del_var, Ordering::Relaxed); |
| 46 | 47 | ||
| 47 | // Spawn LED blinking task | 48 | // Spawn LED blinking task |
| 48 | spawner.spawn(led_task(p.PA5.degrade())).unwrap(); | 49 | spawner.spawn(led_task(p.PA5.into())).unwrap(); |
| 49 | 50 | ||
| 50 | loop { | 51 | loop { |
| 51 | // Check if button got pressed | 52 | // Check if button got pressed |
diff --git a/examples/stm32f1/src/bin/input_capture.rs b/examples/stm32f1/src/bin/input_capture.rs index 5e2dab9e6..6fe8e0b50 100644 --- a/examples/stm32f1/src/bin/input_capture.rs +++ b/examples/stm32f1/src/bin/input_capture.rs | |||
| @@ -7,14 +7,14 @@ use embassy_stm32::gpio::{Level, Output, Pull, Speed}; | |||
| 7 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 8 | use embassy_stm32::timer::input_capture::{CapturePin, InputCapture}; | 8 | use embassy_stm32::timer::input_capture::{CapturePin, InputCapture}; |
| 9 | use embassy_stm32::timer::{self, Channel}; | 9 | use embassy_stm32::timer::{self, Channel}; |
| 10 | use embassy_stm32::{bind_interrupts, peripherals}; | 10 | use embassy_stm32::{bind_interrupts, peripherals, Peri}; |
| 11 | use embassy_time::Timer; | 11 | use embassy_time::Timer; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | /// Connect PA2 and PC13 with a 1k Ohm resistor | 14 | /// Connect PA2 and PC13 with a 1k Ohm resistor |
| 15 | 15 | ||
| 16 | #[embassy_executor::task] | 16 | #[embassy_executor::task] |
| 17 | async fn blinky(led: peripherals::PC13) { | 17 | async fn blinky(led: Peri<'static, peripherals::PC13>) { |
| 18 | let mut led = Output::new(led, Level::High, Speed::Low); | 18 | let mut led = Output::new(led, Level::High, Speed::Low); |
| 19 | 19 | ||
| 20 | loop { | 20 | loop { |
diff --git a/examples/stm32f1/src/bin/pwm_input.rs b/examples/stm32f1/src/bin/pwm_input.rs index f74853d4e..afbef3edb 100644 --- a/examples/stm32f1/src/bin/pwm_input.rs +++ b/examples/stm32f1/src/bin/pwm_input.rs | |||
| @@ -6,14 +6,14 @@ use embassy_executor::Spawner; | |||
| 6 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; | 6 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 7 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 8 | use embassy_stm32::timer::pwm_input::PwmInput; | 8 | use embassy_stm32::timer::pwm_input::PwmInput; |
| 9 | use embassy_stm32::{bind_interrupts, peripherals, timer}; | 9 | use embassy_stm32::{bind_interrupts, peripherals, timer, Peri}; |
| 10 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | /// Connect PA0 and PC13 with a 1k Ohm resistor | 13 | /// Connect PA0 and PC13 with a 1k Ohm resistor |
| 14 | 14 | ||
| 15 | #[embassy_executor::task] | 15 | #[embassy_executor::task] |
| 16 | async fn blinky(led: peripherals::PC13) { | 16 | async fn blinky(led: Peri<'static, peripherals::PC13>) { |
| 17 | let mut led = Output::new(led, Level::High, Speed::Low); | 17 | let mut led = Output::new(led, Level::High, Speed::Low); |
| 18 | 18 | ||
| 19 | loop { | 19 | loop { |
diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs index ee99acf41..77ec307b9 100644 --- a/examples/stm32f1/src/bin/usb_serial.rs +++ b/examples/stm32f1/src/bin/usb_serial.rs | |||
| @@ -47,7 +47,7 @@ async fn main(_spawner: Spawner) { | |||
| 47 | // Pull the D+ pin down to send a RESET condition to the USB bus. | 47 | // Pull the D+ pin down to send a RESET condition to the USB bus. |
| 48 | // This forced reset is needed only for development, without it host | 48 | // This forced reset is needed only for development, without it host |
| 49 | // will not reset your device when you upload new firmware. | 49 | // will not reset your device when you upload new firmware. |
| 50 | let _dp = Output::new(&mut p.PA12, Level::Low, Speed::Low); | 50 | let _dp = Output::new(p.PA12.reborrow(), Level::Low, Speed::Low); |
| 51 | Timer::after_millis(10).await; | 51 | Timer::after_millis(10).await; |
| 52 | } | 52 | } |
| 53 | 53 | ||
diff --git a/examples/stm32f334/src/bin/opamp.rs b/examples/stm32f334/src/bin/opamp.rs index 2dbf1bdab..b30445ead 100644 --- a/examples/stm32f334/src/bin/opamp.rs +++ b/examples/stm32f334/src/bin/opamp.rs | |||
| @@ -48,7 +48,7 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 48 | 48 | ||
| 49 | let mut vrefint = adc.enable_vref(); | 49 | let mut vrefint = adc.enable_vref(); |
| 50 | let mut temperature = adc.enable_temperature(); | 50 | let mut temperature = adc.enable_temperature(); |
| 51 | let mut buffer = opamp.buffer_ext(&mut p.PA7, &mut p.PA6, OpAmpGain::Mul1); | 51 | let mut buffer = opamp.buffer_ext(p.PA7.reborrow(), p.PA6.reborrow(), OpAmpGain::Mul1); |
| 52 | 52 | ||
| 53 | loop { | 53 | loop { |
| 54 | let vref = adc.read(&mut vrefint).await; | 54 | let vref = adc.read(&mut vrefint).await; |
diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs index 8e3beee24..fd90e0d6d 100644 --- a/examples/stm32f4/src/bin/can.rs +++ b/examples/stm32f4/src/bin/can.rs | |||
| @@ -30,7 +30,7 @@ async fn main(_spawner: Spawner) { | |||
| 30 | // To synchronise to the bus the RX input needs to see a high level. | 30 | // To synchronise to the bus the RX input needs to see a high level. |
| 31 | // Use `mem::forget()` to release the borrow on the pin but keep the | 31 | // Use `mem::forget()` to release the borrow on the pin but keep the |
| 32 | // pull-up resistor enabled. | 32 | // pull-up resistor enabled. |
| 33 | let rx_pin = Input::new(&mut p.PA11, Pull::Up); | 33 | let rx_pin = Input::new(p.PA11.reborrow(), Pull::Up); |
| 34 | core::mem::forget(rx_pin); | 34 | core::mem::forget(rx_pin); |
| 35 | 35 | ||
| 36 | let mut can = Can::new(p.CAN1, p.PA11, p.PA12, Irqs); | 36 | let mut can = Can::new(p.CAN1, p.PA11, p.PA12, Irqs); |
diff --git a/examples/stm32f4/src/bin/flash_async.rs b/examples/stm32f4/src/bin/flash_async.rs index 493a536f3..755713542 100644 --- a/examples/stm32f4/src/bin/flash_async.rs +++ b/examples/stm32f4/src/bin/flash_async.rs | |||
| @@ -3,9 +3,9 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::{info, unwrap}; | 4 | use defmt::{info, unwrap}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::bind_interrupts; | ||
| 7 | use embassy_stm32::flash::{Flash, InterruptHandler}; | 6 | use embassy_stm32::flash::{Flash, InterruptHandler}; |
| 8 | use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Speed}; | 7 | use embassy_stm32::gpio::{AnyPin, Level, Output, Speed}; |
| 8 | use embassy_stm32::{bind_interrupts, Peri}; | ||
| 9 | use embassy_time::Timer; | 9 | use embassy_time::Timer; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| @@ -21,14 +21,14 @@ async fn main(spawner: Spawner) { | |||
| 21 | let mut f = Flash::new(p.FLASH, Irqs); | 21 | let mut f = Flash::new(p.FLASH, Irqs); |
| 22 | 22 | ||
| 23 | // Led should blink uninterrupted during ~2sec erase operation | 23 | // Led should blink uninterrupted during ~2sec erase operation |
| 24 | spawner.spawn(blinky(p.PB7.degrade())).unwrap(); | 24 | spawner.spawn(blinky(p.PB7.into())).unwrap(); |
| 25 | 25 | ||
| 26 | // Test on bank 2 in order not to stall CPU. | 26 | // Test on bank 2 in order not to stall CPU. |
| 27 | test_flash(&mut f, 1024 * 1024, 128 * 1024).await; | 27 | test_flash(&mut f, 1024 * 1024, 128 * 1024).await; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | #[embassy_executor::task] | 30 | #[embassy_executor::task] |
| 31 | async fn blinky(p: AnyPin) { | 31 | async fn blinky(p: Peri<'static, AnyPin>) { |
| 32 | let mut led = Output::new(p, Level::High, Speed::Low); | 32 | let mut led = Output::new(p, Level::High, Speed::Low); |
| 33 | 33 | ||
| 34 | loop { | 34 | loop { |
diff --git a/examples/stm32f4/src/bin/input_capture.rs b/examples/stm32f4/src/bin/input_capture.rs index 49de33d2b..fe5e2bdfc 100644 --- a/examples/stm32f4/src/bin/input_capture.rs +++ b/examples/stm32f4/src/bin/input_capture.rs | |||
| @@ -7,14 +7,14 @@ use embassy_stm32::gpio::{Level, Output, Pull, Speed}; | |||
| 7 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 8 | use embassy_stm32::timer::input_capture::{CapturePin, InputCapture}; | 8 | use embassy_stm32::timer::input_capture::{CapturePin, InputCapture}; |
| 9 | use embassy_stm32::timer::{self, Channel}; | 9 | use embassy_stm32::timer::{self, Channel}; |
| 10 | use embassy_stm32::{bind_interrupts, peripherals}; | 10 | use embassy_stm32::{bind_interrupts, peripherals, Peri}; |
| 11 | use embassy_time::Timer; | 11 | use embassy_time::Timer; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | /// Connect PB2 and PB10 with a 1k Ohm resistor | 14 | /// Connect PB2 and PB10 with a 1k Ohm resistor |
| 15 | 15 | ||
| 16 | #[embassy_executor::task] | 16 | #[embassy_executor::task] |
| 17 | async fn blinky(led: peripherals::PB2) { | 17 | async fn blinky(led: Peri<'static, peripherals::PB2>) { |
| 18 | let mut led = Output::new(led, Level::High, Speed::Low); | 18 | let mut led = Output::new(led, Level::High, Speed::Low); |
| 19 | 19 | ||
| 20 | loop { | 20 | loop { |
diff --git a/examples/stm32f4/src/bin/pwm_input.rs b/examples/stm32f4/src/bin/pwm_input.rs index ce200549d..465cbe4f5 100644 --- a/examples/stm32f4/src/bin/pwm_input.rs +++ b/examples/stm32f4/src/bin/pwm_input.rs | |||
| @@ -6,14 +6,14 @@ use embassy_executor::Spawner; | |||
| 6 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; | 6 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 7 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 8 | use embassy_stm32::timer::pwm_input::PwmInput; | 8 | use embassy_stm32::timer::pwm_input::PwmInput; |
| 9 | use embassy_stm32::{bind_interrupts, peripherals, timer}; | 9 | use embassy_stm32::{bind_interrupts, peripherals, timer, Peri}; |
| 10 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | /// Connect PB2 and PA6 with a 1k Ohm resistor | 13 | /// Connect PB2 and PA6 with a 1k Ohm resistor |
| 14 | 14 | ||
| 15 | #[embassy_executor::task] | 15 | #[embassy_executor::task] |
| 16 | async fn blinky(led: peripherals::PB2) { | 16 | async fn blinky(led: Peri<'static, peripherals::PB2>) { |
| 17 | let mut led = Output::new(led, Level::High, Speed::Low); | 17 | let mut led = Output::new(led, Level::High, Speed::Low); |
| 18 | 18 | ||
| 19 | loop { | 19 | loop { |
diff --git a/examples/stm32f4/src/bin/ws2812_pwm.rs b/examples/stm32f4/src/bin/ws2812_pwm.rs index 3ab93d6e0..ca924e181 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm.rs | |||
| @@ -92,7 +92,7 @@ async fn main(_spawner: Spawner) { | |||
| 92 | loop { | 92 | loop { |
| 93 | for &color in color_list { | 93 | for &color in color_list { |
| 94 | // with &mut, we can easily reuse same DMA channel multiple times | 94 | // with &mut, we can easily reuse same DMA channel multiple times |
| 95 | ws2812_pwm.waveform_up(&mut dp.DMA1_CH2, pwm_channel, color).await; | 95 | ws2812_pwm.waveform_up(dp.DMA1_CH2.reborrow(), pwm_channel, color).await; |
| 96 | // ws2812 need at least 50 us low level input to confirm the input data and change it's state | 96 | // ws2812 need at least 50 us low level input to confirm the input data and change it's state |
| 97 | Timer::after_micros(50).await; | 97 | Timer::after_micros(50).await; |
| 98 | // wait until ticker tick | 98 | // wait until ticker tick |
diff --git a/examples/stm32f7/src/bin/can.rs b/examples/stm32f7/src/bin/can.rs index a82e335a9..58ba940a8 100644 --- a/examples/stm32f7/src/bin/can.rs +++ b/examples/stm32f7/src/bin/can.rs | |||
| @@ -42,7 +42,7 @@ async fn main(spawner: Spawner) { | |||
| 42 | // To synchronise to the bus the RX input needs to see a high level. | 42 | // To synchronise to the bus the RX input needs to see a high level. |
| 43 | // Use `mem::forget()` to release the borrow on the pin but keep the | 43 | // Use `mem::forget()` to release the borrow on the pin but keep the |
| 44 | // pull-up resistor enabled. | 44 | // pull-up resistor enabled. |
| 45 | let rx_pin = Input::new(&mut p.PA15, Pull::Up); | 45 | let rx_pin = Input::new(p.PA15.reborrow(), Pull::Up); |
| 46 | core::mem::forget(rx_pin); | 46 | core::mem::forget(rx_pin); |
| 47 | 47 | ||
| 48 | static CAN: StaticCell<Can<'static>> = StaticCell::new(); | 48 | static CAN: StaticCell<Can<'static>> = StaticCell::new(); |
diff --git a/examples/stm32g0/src/bin/adc_dma.rs b/examples/stm32g0/src/bin/adc_dma.rs index 3713e5a21..d7515933c 100644 --- a/examples/stm32g0/src/bin/adc_dma.rs +++ b/examples/stm32g0/src/bin/adc_dma.rs | |||
| @@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) { | |||
| 25 | 25 | ||
| 26 | loop { | 26 | loop { |
| 27 | adc.read( | 27 | adc.read( |
| 28 | &mut dma, | 28 | dma.reborrow(), |
| 29 | [ | 29 | [ |
| 30 | (&mut vrefint_channel, SampleTime::CYCLES160_5), | 30 | (&mut vrefint_channel, SampleTime::CYCLES160_5), |
| 31 | (&mut pa0, SampleTime::CYCLES160_5), | 31 | (&mut pa0, SampleTime::CYCLES160_5), |
diff --git a/examples/stm32g0/src/bin/input_capture.rs b/examples/stm32g0/src/bin/input_capture.rs index bc814cb13..08df4e043 100644 --- a/examples/stm32g0/src/bin/input_capture.rs +++ b/examples/stm32g0/src/bin/input_capture.rs | |||
| @@ -16,14 +16,14 @@ use embassy_stm32::time::khz; | |||
| 16 | use embassy_stm32::timer::input_capture::{CapturePin, InputCapture}; | 16 | use embassy_stm32::timer::input_capture::{CapturePin, InputCapture}; |
| 17 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | 17 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; |
| 18 | use embassy_stm32::timer::Channel; | 18 | use embassy_stm32::timer::Channel; |
| 19 | use embassy_stm32::{bind_interrupts, peripherals, timer}; | 19 | use embassy_stm32::{bind_interrupts, peripherals, timer, Peri}; |
| 20 | use embassy_time::Timer; | 20 | use embassy_time::Timer; |
| 21 | use {defmt_rtt as _, panic_probe as _}; | 21 | use {defmt_rtt as _, panic_probe as _}; |
| 22 | 22 | ||
| 23 | // Connect PB1 and PA6 with a 1k Ohm resistor | 23 | // Connect PB1 and PA6 with a 1k Ohm resistor |
| 24 | 24 | ||
| 25 | #[embassy_executor::task] | 25 | #[embassy_executor::task] |
| 26 | async fn blinky(led: peripherals::PB1) { | 26 | async fn blinky(led: Peri<'static, peripherals::PB1>) { |
| 27 | let mut led = Output::new(led, Level::High, Speed::Low); | 27 | let mut led = Output::new(led, Level::High, Speed::Low); |
| 28 | 28 | ||
| 29 | loop { | 29 | loop { |
diff --git a/examples/stm32g0/src/bin/pwm_input.rs b/examples/stm32g0/src/bin/pwm_input.rs index db9cf4f8a..9d6b5fe97 100644 --- a/examples/stm32g0/src/bin/pwm_input.rs +++ b/examples/stm32g0/src/bin/pwm_input.rs | |||
| @@ -14,13 +14,13 @@ use embassy_stm32::gpio::{Level, Output, OutputType, Pull, Speed}; | |||
| 14 | use embassy_stm32::time::khz; | 14 | use embassy_stm32::time::khz; |
| 15 | use embassy_stm32::timer::pwm_input::PwmInput; | 15 | use embassy_stm32::timer::pwm_input::PwmInput; |
| 16 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | 16 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; |
| 17 | use embassy_stm32::{bind_interrupts, peripherals, timer}; | 17 | use embassy_stm32::{bind_interrupts, peripherals, timer, Peri}; |
| 18 | use embassy_time::Timer; | 18 | use embassy_time::Timer; |
| 19 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 20 | ||
| 21 | // Connect PB1 and PA6 with a 1k Ohm resistor | 21 | // Connect PB1 and PA6 with a 1k Ohm resistor |
| 22 | #[embassy_executor::task] | 22 | #[embassy_executor::task] |
| 23 | async fn blinky(led: peripherals::PB1) { | 23 | async fn blinky(led: Peri<'static, peripherals::PB1>) { |
| 24 | let mut led = Output::new(led, Level::High, Speed::Low); | 24 | let mut led = Output::new(led, Level::High, Speed::Low); |
| 25 | 25 | ||
| 26 | loop { | 26 | loop { |
diff --git a/examples/stm32g4/src/bin/adc_dma.rs b/examples/stm32g4/src/bin/adc_dma.rs index 970623b32..202704085 100644 --- a/examples/stm32g4/src/bin/adc_dma.rs +++ b/examples/stm32g4/src/bin/adc_dma.rs | |||
| @@ -41,7 +41,7 @@ async fn main(_spawner: Spawner) { | |||
| 41 | 41 | ||
| 42 | loop { | 42 | loop { |
| 43 | adc.read( | 43 | adc.read( |
| 44 | &mut dma, | 44 | dma.reborrow(), |
| 45 | [ | 45 | [ |
| 46 | (&mut vrefint_channel, SampleTime::CYCLES247_5), | 46 | (&mut vrefint_channel, SampleTime::CYCLES247_5), |
| 47 | (&mut pa0, SampleTime::CYCLES247_5), | 47 | (&mut pa0, SampleTime::CYCLES247_5), |
diff --git a/examples/stm32h5/src/bin/cordic.rs b/examples/stm32h5/src/bin/cordic.rs index 73e873574..cbf854704 100644 --- a/examples/stm32h5/src/bin/cordic.rs +++ b/examples/stm32h5/src/bin/cordic.rs | |||
| @@ -11,7 +11,7 @@ async fn main(_spawner: Spawner) { | |||
| 11 | let mut dp = embassy_stm32::init(Default::default()); | 11 | let mut dp = embassy_stm32::init(Default::default()); |
| 12 | 12 | ||
| 13 | let mut cordic = cordic::Cordic::new( | 13 | let mut cordic = cordic::Cordic::new( |
| 14 | &mut dp.CORDIC, | 14 | dp.CORDIC.reborrow(), |
| 15 | unwrap!(cordic::Config::new( | 15 | unwrap!(cordic::Config::new( |
| 16 | cordic::Function::Sin, | 16 | cordic::Function::Sin, |
| 17 | Default::default(), | 17 | Default::default(), |
| @@ -59,8 +59,8 @@ async fn main(_spawner: Spawner) { | |||
| 59 | let cnt1 = unwrap!( | 59 | let cnt1 = unwrap!( |
| 60 | cordic | 60 | cordic |
| 61 | .async_calc_32bit( | 61 | .async_calc_32bit( |
| 62 | &mut dp.GPDMA1_CH0, | 62 | dp.GPDMA1_CH0.reborrow(), |
| 63 | &mut dp.GPDMA1_CH1, | 63 | dp.GPDMA1_CH1.reborrow(), |
| 64 | &input_buf[..arg1.len() - 1], // limit input buf to its actual length | 64 | &input_buf[..arg1.len() - 1], // limit input buf to its actual length |
| 65 | &mut output_u32, | 65 | &mut output_u32, |
| 66 | true, | 66 | true, |
diff --git a/examples/stm32h5/src/bin/stop.rs b/examples/stm32h5/src/bin/stop.rs index 0d14c0668..e650791c5 100644 --- a/examples/stm32h5/src/bin/stop.rs +++ b/examples/stm32h5/src/bin/stop.rs | |||
| @@ -10,7 +10,7 @@ use embassy_stm32::gpio::{AnyPin, Level, Output, Speed}; | |||
| 10 | use embassy_stm32::low_power::Executor; | 10 | use embassy_stm32::low_power::Executor; |
| 11 | use embassy_stm32::rcc::{HSIPrescaler, LsConfig}; | 11 | use embassy_stm32::rcc::{HSIPrescaler, LsConfig}; |
| 12 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | 12 | use embassy_stm32::rtc::{Rtc, RtcConfig}; |
| 13 | use embassy_stm32::Config; | 13 | use embassy_stm32::{Config, Peri}; |
| 14 | use embassy_time::Timer; | 14 | use embassy_time::Timer; |
| 15 | use static_cell::StaticCell; | 15 | use static_cell::StaticCell; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -48,7 +48,7 @@ async fn async_main(spawner: Spawner) { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | #[embassy_executor::task] | 50 | #[embassy_executor::task] |
| 51 | async fn blinky(led: AnyPin) { | 51 | async fn blinky(led: Peri<'static, AnyPin>) { |
| 52 | let mut led = Output::new(led, Level::Low, Speed::Low); | 52 | let mut led = Output::new(led, Level::Low, Speed::Low); |
| 53 | loop { | 53 | loop { |
| 54 | info!("high"); | 54 | info!("high"); |
diff --git a/examples/stm32h7/src/bin/adc_dma.rs b/examples/stm32h7/src/bin/adc_dma.rs index 0b905d227..dc775f18a 100644 --- a/examples/stm32h7/src/bin/adc_dma.rs +++ b/examples/stm32h7/src/bin/adc_dma.rs | |||
| @@ -57,7 +57,7 @@ async fn main(_spawner: Spawner) { | |||
| 57 | 57 | ||
| 58 | loop { | 58 | loop { |
| 59 | adc.read( | 59 | adc.read( |
| 60 | &mut dma, | 60 | dma.reborrow(), |
| 61 | [ | 61 | [ |
| 62 | (&mut vrefint_channel, SampleTime::CYCLES387_5), | 62 | (&mut vrefint_channel, SampleTime::CYCLES387_5), |
| 63 | (&mut pc0, SampleTime::CYCLES810_5), | 63 | (&mut pc0, SampleTime::CYCLES810_5), |
diff --git a/examples/stm32h7/src/bin/dac_dma.rs b/examples/stm32h7/src/bin/dac_dma.rs index 98c9f1e90..8314754bc 100644 --- a/examples/stm32h7/src/bin/dac_dma.rs +++ b/examples/stm32h7/src/bin/dac_dma.rs | |||
| @@ -10,6 +10,7 @@ use embassy_stm32::peripherals::{DAC1, TIM6, TIM7}; | |||
| 10 | use embassy_stm32::rcc::frequency; | 10 | use embassy_stm32::rcc::frequency; |
| 11 | use embassy_stm32::time::Hertz; | 11 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::timer::low_level::Timer; | 12 | use embassy_stm32::timer::low_level::Timer; |
| 13 | use embassy_stm32::Peri; | ||
| 13 | use micromath::F32Ext; | 14 | use micromath::F32Ext; |
| 14 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 16 | ||
| @@ -57,7 +58,7 @@ async fn main(spawner: Spawner) { | |||
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | #[embassy_executor::task] | 60 | #[embassy_executor::task] |
| 60 | async fn dac_task1(tim: TIM6, mut dac: DacCh1<'static, DAC1, Async>) { | 61 | async fn dac_task1(tim: Peri<'static, TIM6>, mut dac: DacCh1<'static, DAC1, Async>) { |
| 61 | let data: &[u8; 256] = &calculate_array::<256>(); | 62 | let data: &[u8; 256] = &calculate_array::<256>(); |
| 62 | 63 | ||
| 63 | info!("TIM6 frequency is {}", frequency::<TIM6>()); | 64 | info!("TIM6 frequency is {}", frequency::<TIM6>()); |
| @@ -100,7 +101,7 @@ async fn dac_task1(tim: TIM6, mut dac: DacCh1<'static, DAC1, Async>) { | |||
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | #[embassy_executor::task] | 103 | #[embassy_executor::task] |
| 103 | async fn dac_task2(tim: TIM7, mut dac: DacCh2<'static, DAC1, Async>) { | 104 | async fn dac_task2(tim: Peri<'static, TIM7>, mut dac: DacCh2<'static, DAC1, Async>) { |
| 104 | let data: &[u8; 256] = &calculate_array::<256>(); | 105 | let data: &[u8; 256] = &calculate_array::<256>(); |
| 105 | 106 | ||
| 106 | info!("TIM7 frequency is {}", frequency::<TIM6>()); | 107 | info!("TIM7 frequency is {}", frequency::<TIM6>()); |
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index b796996ea..8de31ea5b 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -7,7 +7,7 @@ use embassy_stm32::gpio::{AfType, Flex, OutputType, Speed}; | |||
| 7 | use embassy_stm32::time::{khz, Hertz}; | 7 | use embassy_stm32::time::{khz, Hertz}; |
| 8 | use embassy_stm32::timer::low_level::{OutputCompareMode, Timer as LLTimer}; | 8 | use embassy_stm32::timer::low_level::{OutputCompareMode, Timer as LLTimer}; |
| 9 | use embassy_stm32::timer::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance32bit4Channel}; | 9 | use embassy_stm32::timer::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance32bit4Channel}; |
| 10 | use embassy_stm32::{into_ref, Config, Peripheral}; | 10 | use embassy_stm32::{Config, Peri}; |
| 11 | use embassy_time::Timer; | 11 | use embassy_time::Timer; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| @@ -66,15 +66,13 @@ pub struct SimplePwm32<'d, T: GeneralInstance32bit4Channel> { | |||
| 66 | 66 | ||
| 67 | impl<'d, T: GeneralInstance32bit4Channel> SimplePwm32<'d, T> { | 67 | impl<'d, T: GeneralInstance32bit4Channel> SimplePwm32<'d, T> { |
| 68 | pub fn new( | 68 | pub fn new( |
| 69 | tim: impl Peripheral<P = T> + 'd, | 69 | tim: Peri<'d, T>, |
| 70 | ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd, | 70 | ch1: Peri<'d, impl Channel1Pin<T>>, |
| 71 | ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd, | 71 | ch2: Peri<'d, impl Channel2Pin<T>>, |
| 72 | ch3: impl Peripheral<P = impl Channel3Pin<T>> + 'd, | 72 | ch3: Peri<'d, impl Channel3Pin<T>>, |
| 73 | ch4: impl Peripheral<P = impl Channel4Pin<T>> + 'd, | 73 | ch4: Peri<'d, impl Channel4Pin<T>>, |
| 74 | freq: Hertz, | 74 | freq: Hertz, |
| 75 | ) -> Self { | 75 | ) -> Self { |
| 76 | into_ref!(ch1, ch2, ch3, ch4); | ||
| 77 | |||
| 78 | let af1 = ch1.af_num(); | 76 | let af1 = ch1.af_num(); |
| 79 | let af2 = ch2.af_num(); | 77 | let af2 = ch2.af_num(); |
| 80 | let af3 = ch3.af_num(); | 78 | let af3 = ch3.af_num(); |
diff --git a/examples/stm32h723/src/bin/spdifrx.rs b/examples/stm32h723/src/bin/spdifrx.rs index 69ef5cd07..bc8249ced 100644 --- a/examples/stm32h723/src/bin/spdifrx.rs +++ b/examples/stm32h723/src/bin/spdifrx.rs | |||
| @@ -77,14 +77,19 @@ async fn main(_spawner: Spawner) { | |||
| 77 | }; | 77 | }; |
| 78 | 78 | ||
| 79 | let mut sai_transmitter = new_sai_transmitter( | 79 | let mut sai_transmitter = new_sai_transmitter( |
| 80 | &mut p.SAI4, | 80 | p.SAI4.reborrow(), |
| 81 | &mut p.PD13, | 81 | p.PD13.reborrow(), |
| 82 | &mut p.PC1, | 82 | p.PC1.reborrow(), |
| 83 | &mut p.PD12, | 83 | p.PD12.reborrow(), |
| 84 | &mut p.BDMA_CH0, | 84 | p.BDMA_CH0.reborrow(), |
| 85 | sai_buffer, | 85 | sai_buffer, |
| 86 | ); | 86 | ); |
| 87 | let mut spdif_receiver = new_spdif_receiver(&mut p.SPDIFRX1, &mut p.PD7, &mut p.DMA2_CH7, spdifrx_buffer); | 87 | let mut spdif_receiver = new_spdif_receiver( |
| 88 | p.SPDIFRX1.reborrow(), | ||
| 89 | p.PD7.reborrow(), | ||
| 90 | p.DMA2_CH7.reborrow(), | ||
| 91 | spdifrx_buffer, | ||
| 92 | ); | ||
| 88 | spdif_receiver.start(); | 93 | spdif_receiver.start(); |
| 89 | 94 | ||
| 90 | let mut renew_sai = false; | 95 | let mut renew_sai = false; |
| @@ -96,11 +101,11 @@ async fn main(_spawner: Spawner) { | |||
| 96 | trace!("Renew SAI."); | 101 | trace!("Renew SAI."); |
| 97 | drop(sai_transmitter); | 102 | drop(sai_transmitter); |
| 98 | sai_transmitter = new_sai_transmitter( | 103 | sai_transmitter = new_sai_transmitter( |
| 99 | &mut p.SAI4, | 104 | p.SAI4.reborrow(), |
| 100 | &mut p.PD13, | 105 | p.PD13.reborrow(), |
| 101 | &mut p.PC1, | 106 | p.PC1.reborrow(), |
| 102 | &mut p.PD12, | 107 | p.PD12.reborrow(), |
| 103 | &mut p.BDMA_CH0, | 108 | p.BDMA_CH0.reborrow(), |
| 104 | sai_buffer, | 109 | sai_buffer, |
| 105 | ); | 110 | ); |
| 106 | } | 111 | } |
| @@ -111,7 +116,12 @@ async fn main(_spawner: Spawner) { | |||
| 111 | Err(spdifrx::Error::RingbufferError(_)) => { | 116 | Err(spdifrx::Error::RingbufferError(_)) => { |
| 112 | trace!("SPDIFRX ringbuffer error. Renew."); | 117 | trace!("SPDIFRX ringbuffer error. Renew."); |
| 113 | drop(spdif_receiver); | 118 | drop(spdif_receiver); |
| 114 | spdif_receiver = new_spdif_receiver(&mut p.SPDIFRX1, &mut p.PD7, &mut p.DMA2_CH7, spdifrx_buffer); | 119 | spdif_receiver = new_spdif_receiver( |
| 120 | p.SPDIFRX1.reborrow(), | ||
| 121 | p.PD7.reborrow(), | ||
| 122 | p.DMA2_CH7.reborrow(), | ||
| 123 | spdifrx_buffer, | ||
| 124 | ); | ||
| 115 | spdif_receiver.start(); | 125 | spdif_receiver.start(); |
| 116 | continue; | 126 | continue; |
| 117 | } | 127 | } |
diff --git a/examples/stm32l4/src/bin/dac_dma.rs b/examples/stm32l4/src/bin/dac_dma.rs index 6c9219080..cde24f411 100644 --- a/examples/stm32l4/src/bin/dac_dma.rs +++ b/examples/stm32l4/src/bin/dac_dma.rs | |||
| @@ -10,6 +10,7 @@ use embassy_stm32::peripherals::{DAC1, TIM6, TIM7}; | |||
| 10 | use embassy_stm32::rcc::frequency; | 10 | use embassy_stm32::rcc::frequency; |
| 11 | use embassy_stm32::time::Hertz; | 11 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::timer::low_level::Timer; | 12 | use embassy_stm32::timer::low_level::Timer; |
| 13 | use embassy_stm32::Peri; | ||
| 13 | use micromath::F32Ext; | 14 | use micromath::F32Ext; |
| 14 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 16 | ||
| @@ -28,7 +29,7 @@ async fn main(spawner: Spawner) { | |||
| 28 | } | 29 | } |
| 29 | 30 | ||
| 30 | #[embassy_executor::task] | 31 | #[embassy_executor::task] |
| 31 | async fn dac_task1(tim: TIM6, mut dac: DacCh1<'static, DAC1, Async>) { | 32 | async fn dac_task1(tim: Peri<'static, TIM6>, mut dac: DacCh1<'static, DAC1, Async>) { |
| 32 | let data: &[u8; 256] = &calculate_array::<256>(); | 33 | let data: &[u8; 256] = &calculate_array::<256>(); |
| 33 | 34 | ||
| 34 | info!("TIM6 frequency is {}", frequency::<TIM6>()); | 35 | info!("TIM6 frequency is {}", frequency::<TIM6>()); |
| @@ -71,7 +72,7 @@ async fn dac_task1(tim: TIM6, mut dac: DacCh1<'static, DAC1, Async>) { | |||
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | #[embassy_executor::task] | 74 | #[embassy_executor::task] |
| 74 | async fn dac_task2(tim: TIM7, mut dac: DacCh2<'static, DAC1, Async>) { | 75 | async fn dac_task2(tim: Peri<'static, TIM7>, mut dac: DacCh2<'static, DAC1, Async>) { |
| 75 | let data: &[u8; 256] = &calculate_array::<256>(); | 76 | let data: &[u8; 256] = &calculate_array::<256>(); |
| 76 | 77 | ||
| 77 | info!("TIM7 frequency is {}", frequency::<TIM7>()); | 78 | info!("TIM7 frequency is {}", frequency::<TIM7>()); |
diff --git a/examples/stm32l5/src/bin/stop.rs b/examples/stm32l5/src/bin/stop.rs index 32a736de8..d7a1efea9 100644 --- a/examples/stm32l5/src/bin/stop.rs +++ b/examples/stm32l5/src/bin/stop.rs | |||
| @@ -7,7 +7,7 @@ use embassy_stm32::gpio::{AnyPin, Level, Output, Speed}; | |||
| 7 | use embassy_stm32::low_power::Executor; | 7 | use embassy_stm32::low_power::Executor; |
| 8 | use embassy_stm32::rcc::LsConfig; | 8 | use embassy_stm32::rcc::LsConfig; |
| 9 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | 9 | use embassy_stm32::rtc::{Rtc, RtcConfig}; |
| 10 | use embassy_stm32::Config; | 10 | use embassy_stm32::{Config, Peri}; |
| 11 | use embassy_time::Timer; | 11 | use embassy_time::Timer; |
| 12 | use static_cell::StaticCell; | 12 | use static_cell::StaticCell; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -39,7 +39,7 @@ async fn async_main(spawner: Spawner) { | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | #[embassy_executor::task] | 41 | #[embassy_executor::task] |
| 42 | async fn blinky(led: AnyPin) -> ! { | 42 | async fn blinky(led: Peri<'static, AnyPin>) -> ! { |
| 43 | let mut led = Output::new(led, Level::Low, Speed::Low); | 43 | let mut led = Output::new(led, Level::Low, Speed::Low); |
| 44 | loop { | 44 | loop { |
| 45 | info!("high"); | 45 | info!("high"); |
diff --git a/examples/stm32u5/src/bin/adc.rs b/examples/stm32u5/src/bin/adc.rs index 6ba21cc63..d2aa28087 100644 --- a/examples/stm32u5/src/bin/adc.rs +++ b/examples/stm32u5/src/bin/adc.rs | |||
| @@ -72,7 +72,7 @@ async fn main(_spawner: embassy_executor::Spawner) { | |||
| 72 | let mut measurements = [0u16; 2]; | 72 | let mut measurements = [0u16; 2]; |
| 73 | 73 | ||
| 74 | adc1.read( | 74 | adc1.read( |
| 75 | &mut p.GPDMA1_CH0, | 75 | p.GPDMA1_CH0.reborrow(), |
| 76 | [ | 76 | [ |
| 77 | (&mut degraded11, adc::SampleTime::CYCLES160_5), | 77 | (&mut degraded11, adc::SampleTime::CYCLES160_5), |
| 78 | (&mut degraded12, adc::SampleTime::CYCLES160_5), | 78 | (&mut degraded12, adc::SampleTime::CYCLES160_5), |
| @@ -96,7 +96,7 @@ async fn main(_spawner: embassy_executor::Spawner) { | |||
| 96 | 96 | ||
| 97 | // The channels must be in ascending order and can't repeat for ADC4 | 97 | // The channels must be in ascending order and can't repeat for ADC4 |
| 98 | adc4.read( | 98 | adc4.read( |
| 99 | &mut p.GPDMA1_CH1, | 99 | p.GPDMA1_CH1.reborrow(), |
| 100 | [&mut degraded42, &mut degraded41].into_iter(), | 100 | [&mut degraded42, &mut degraded41].into_iter(), |
| 101 | &mut measurements, | 101 | &mut measurements, |
| 102 | ) | 102 | ) |
