Remove Peripheral trait, rename PeripheralRef->Peri.

This commit is contained in:
Dario Nieuwenhuis
2025-03-26 16:01:37 +01:00
parent 9edf5b7f04
commit d41eeeae79
225 changed files with 2645 additions and 3215 deletions

View File

@@ -28,7 +28,7 @@ serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde-json-core = "0.5.1"
# for assign resources example
assign-resources = { git = "https://github.com/adamgreig/assign-resources", rev = "94ad10e2729afdf0fd5a77cd12e68409a982f58a" }
assign-resources = { git = "https://github.com/adamgreig/assign-resources", rev = "bd22cb7a92031fb16f74a5da42469d466c33383e" }
# for TB6612FNG example
tb6612fng = "1.0.0"

View File

@@ -38,13 +38,13 @@ async fn main(_spawner: Spawner) {
// Read 100 samples from a single channel
let mut buf = [0_u16; BLOCK_SIZE];
let div = 479; // 100kHz sample rate (48Mhz / 100kHz - 1)
adc.read_many(&mut pin, &mut buf, div, &mut dma).await.unwrap();
adc.read_many(&mut pin, &mut buf, div, dma.reborrow()).await.unwrap();
info!("single: {:?} ...etc", buf[..8]);
// Read 100 samples from 4 channels interleaved
let mut buf = [0_u16; { BLOCK_SIZE * NUM_CHANNELS }];
let div = 119; // 100kHz sample rate (48Mhz / 100kHz * 4ch - 1)
adc.read_many_multichannel(&mut pins, &mut buf, div, &mut dma)
adc.read_many_multichannel(&mut pins, &mut buf, div, dma.reborrow())
.await
.unwrap();
info!("multi: {:?} ...etc", buf[..NUM_CHANNELS * 2]);

View File

@@ -16,6 +16,7 @@ use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::gpio::{Level, Output};
use embassy_rp::peripherals::{self, PIN_20, PIN_21};
use embassy_rp::Peri;
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
@@ -38,7 +39,11 @@ async fn main(spawner: Spawner) {
// 1) Assigning a resource to a task by passing parts of the peripherals.
#[embassy_executor::task]
async fn double_blinky_manually_assigned(_spawner: Spawner, pin_20: PIN_20, pin_21: PIN_21) {
async fn double_blinky_manually_assigned(
_spawner: Spawner,
pin_20: Peri<'static, PIN_20>,
pin_21: Peri<'static, PIN_21>,
) {
let mut led_20 = Output::new(pin_20, Level::Low);
let mut led_21 = Output::new(pin_21, Level::High);

View File

@@ -11,7 +11,7 @@ use embassy_rp::gpio;
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
use embassy_sync::channel::{Channel, Sender};
use embassy_time::{Duration, Ticker};
use gpio::{AnyPin, Level, Output};
use gpio::{Level, Output};
use {defmt_rtt as _, panic_probe as _};
enum LedState {
@@ -22,7 +22,7 @@ static CHANNEL: Channel<ThreadModeRawMutex, LedState, 64> = Channel::new();
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let mut led = Output::new(AnyPin::from(p.PIN_25), Level::High);
let mut led = Output::new(p.PIN_25, Level::High);
let dt = 100 * 1_000_000;
let k = 1.003;

View File

@@ -11,7 +11,7 @@ use embassy_rp::gpio;
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
use embassy_sync::mutex::Mutex;
use embassy_time::{Duration, Ticker};
use gpio::{AnyPin, Level, Output};
use gpio::{Level, Output};
use {defmt_rtt as _, panic_probe as _};
type LedType = Mutex<ThreadModeRawMutex, Option<Output<'static>>>;
@@ -21,7 +21,7 @@ static LED: LedType = Mutex::new(None);
async fn main(spawner: Spawner) {
let p = embassy_rp::init(Default::default());
// set the content of the global LED reference to the real LED pin
let led = Output::new(AnyPin::from(p.PIN_25), Level::High);
let led = Output::new(p.PIN_25, Level::High);
// inner scope is so that once the mutex is written to, the MutexGuard is dropped, thus the
// Mutex is released
{

View File

@@ -4,10 +4,10 @@
#![no_main]
use defmt::info;
use embassy_executor::Spawner;
use embassy_rp::bind_interrupts;
use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::program::pio_asm;
use embassy_rp::pio::{Common, Config, InterruptHandler, Irq, Pio, PioPin, ShiftDirection, StateMachine};
use embassy_rp::{bind_interrupts, Peri};
use fixed::traits::ToFixed;
use fixed_macro::types::U56F8;
use {defmt_rtt as _, panic_probe as _};
@@ -16,7 +16,7 @@ bind_interrupts!(struct Irqs {
PIO0_IRQ_0 => InterruptHandler<PIO0>;
});
fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 0>, pin: impl PioPin) {
fn setup_pio_task_sm0<'a>(pio: &mut Common<'a, PIO0>, sm: &mut StateMachine<'a, PIO0, 0>, pin: Peri<'a, impl PioPin>) {
// Setup sm0
// Send data serially to pin

View File

@@ -5,10 +5,10 @@
use defmt::info;
use embassy_executor::Spawner;
use embassy_futures::join::join;
use embassy_rp::bind_interrupts;
use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::program::pio_asm;
use embassy_rp::pio::{Config, InterruptHandler, Pio, ShiftConfig, ShiftDirection};
use embassy_rp::{bind_interrupts, Peripheral};
use fixed::traits::ToFixed;
use fixed_macro::types::U56F8;
use {defmt_rtt as _, panic_probe as _};
@@ -62,8 +62,8 @@ async fn main(_spawner: Spawner) {
sm.set_config(&cfg);
sm.set_enable(true);
let mut dma_out_ref = p.DMA_CH0.into_ref();
let mut dma_in_ref = p.DMA_CH1.into_ref();
let mut dma_out_ref = p.DMA_CH0;
let mut dma_in_ref = p.DMA_CH1;
let mut dout = [0x12345678u32; 29];
for i in 1..dout.len() {
dout[i] = (dout[i - 1] & 0x0fff_ffff) * 13 + 7;

View File

@@ -9,7 +9,7 @@ use embassy_executor::Spawner;
use embassy_rp::gpio::Pull;
use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::program::pio_asm;
use embassy_rp::{bind_interrupts, pio};
use embassy_rp::{bind_interrupts, pio, Peri};
use embassy_time::Timer;
use fixed::traits::ToFixed;
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> {
pub fn new(
pio: &mut Common<'d, T>,
mut sm: StateMachine<'d, T, SM>,
pin_a: impl PioPin,
pin_b: impl PioPin,
pin_a: Peri<'d, impl PioPin>,
pin_b: Peri<'d, impl PioPin>,
) -> Self {
let mut pin_a = pio.make_pio_pin(pin_a);
let mut pin_b = pio.make_pio_pin(pin_b);

View File

@@ -11,6 +11,7 @@ use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::peripherals::{PIN_25, PIN_4, PWM_SLICE2, PWM_SLICE4};
use embassy_rp::pwm::{Config, Pwm, SetDutyCycle};
use embassy_rp::Peri;
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
@@ -26,7 +27,7 @@ async fn main(spawner: Spawner) {
/// Using the onboard led, if You are using a different Board than plain Pico2 (i.e. W variant)
/// you must use another slice & pin and an appropriate resistor.
#[embassy_executor::task]
async fn pwm_set_config(slice4: PWM_SLICE4, pin25: PIN_25) {
async fn pwm_set_config(slice4: Peri<'static, PWM_SLICE4>, pin25: Peri<'static, PIN_25>) {
let mut c = Config::default();
c.top = 32_768;
c.compare_b = 8;
@@ -44,7 +45,7 @@ async fn pwm_set_config(slice4: PWM_SLICE4, pin25: PIN_25) {
///
/// Using GP4 in Slice2, make sure to use an appropriate resistor.
#[embassy_executor::task]
async fn pwm_set_dutycycle(slice2: PWM_SLICE2, pin4: PIN_4) {
async fn pwm_set_dutycycle(slice2: Peri<'static, PWM_SLICE2>, pin4: Peri<'static, PIN_4>) {
// If we aim for a specific frequency, here is how we can calculate the top value.
// The top value sets the period of the PWM cycle, so a counter goes from 0 to top and then wraps around to 0.
// Every such wraparound is one PWM cycle. So here is how we get 25KHz:

View File

@@ -10,7 +10,7 @@ use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::config::Config;
use embassy_rp::gpio::Output;
use embassy_rp::{gpio, peripherals, pwm};
use embassy_rp::{gpio, peripherals, pwm, Peri};
use embassy_time::{Duration, Timer};
use tb6612fng::{DriveCommand, Motor, Tb6612fng};
use {defmt_rtt as _, panic_probe as _};

View File

@@ -8,7 +8,7 @@ use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice;
use embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice;
use embassy_executor::Spawner;
use embassy_rp::bind_interrupts;
use embassy_rp::gpio::{AnyPin, Level, Output};
use embassy_rp::gpio::{Level, Output};
use embassy_rp::i2c::{self, I2c, InterruptHandler};
use embassy_rp::peripherals::{I2C1, SPI1};
use embassy_rp::spi::{self, Spi};
@@ -45,8 +45,8 @@ async fn main(spawner: Spawner) {
let spi_bus = SPI_BUS.init(Mutex::new(spi));
// Chip select pins for the SPI devices
let cs_a = Output::new(AnyPin::from(p.PIN_0), Level::High);
let cs_b = Output::new(AnyPin::from(p.PIN_1), Level::High);
let cs_a = Output::new(p.PIN_0, Level::High);
let cs_b = Output::new(p.PIN_1, Level::High);
spawner.must_spawn(spi_task_a(spi_bus, cs_a));
spawner.must_spawn(spi_task_b(spi_bus, cs_b));

View File

@@ -9,9 +9,9 @@ use core::sync::atomic::{AtomicU16, Ordering};
use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::adc::{self, Adc, Async, Config, InterruptHandler};
use embassy_rp::bind_interrupts;
use embassy_rp::gpio::Pull;
use embassy_rp::peripherals::DMA_CH0;
use embassy_rp::{bind_interrupts, Peri};
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
use embassy_sync::zerocopy_channel::{Channel, Receiver, Sender};
use embassy_time::{Duration, Ticker, Timer};
@@ -31,7 +31,7 @@ static MAX: AtomicU16 = AtomicU16::new(0);
struct AdcParts {
adc: Adc<'static, Async>,
pin: adc::Channel<'static>,
dma: DMA_CH0,
dma: Peri<'static, DMA_CH0>,
}
#[embassy_executor::main]
@@ -70,7 +70,10 @@ async fn producer(mut sender: Sender<'static, NoopRawMutex, SampleBuffer>, mut a
let buf = sender.send().await;
// Fill it with data
adc.adc.read_many(&mut adc.pin, buf, 1, &mut adc.dma).await.unwrap();
adc.adc
.read_many(&mut adc.pin, buf, 1, adc.dma.reborrow())
.await
.unwrap();
// Notify the channel that the buffer is now ready to be received
sender.send_done();