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

@@ -25,14 +25,14 @@ async fn main(_spawner: Spawner) {
// test teardown + recreate of the buffereduarte works fine.
for _ in 0..2 {
let u = BufferedUarte::new(
&mut peri!(p, UART0),
&mut p.TIMER0,
&mut p.PPI_CH0,
&mut p.PPI_CH1,
&mut p.PPI_GROUP0,
peri!(p, UART0).reborrow(),
p.TIMER0.reborrow(),
p.PPI_CH0.reborrow(),
p.PPI_CH1.reborrow(),
p.PPI_GROUP0.reborrow(),
irqs!(UART0_BUFFERED),
&mut peri!(p, PIN_A),
&mut peri!(p, PIN_B),
peri!(p, PIN_A).reborrow(),
peri!(p, PIN_B).reborrow(),
config.clone(),
&mut rx_buffer,
&mut tx_buffer,

View File

@@ -27,21 +27,21 @@ async fn main(_spawner: Spawner) {
const COUNT: usize = 40_000;
let mut tx = BufferedUarteTx::new(
&mut peri!(p, UART1),
peri!(p, UART1).reborrow(),
irqs!(UART1_BUFFERED),
&mut peri!(p, PIN_A),
peri!(p, PIN_A).reborrow(),
config.clone(),
&mut tx_buffer,
);
let mut rx = BufferedUarteRx::new(
&mut peri!(p, UART0),
&mut p.TIMER0,
&mut p.PPI_CH0,
&mut p.PPI_CH1,
&mut p.PPI_GROUP0,
peri!(p, UART0).reborrow(),
p.TIMER0.reborrow(),
p.PPI_CH0.reborrow(),
p.PPI_CH1.reborrow(),
p.PPI_GROUP0.reborrow(),
irqs!(UART0_BUFFERED),
&mut peri!(p, PIN_B),
peri!(p, PIN_B).reborrow(),
config.clone(),
&mut rx_buffer,
);

View File

@@ -27,7 +27,11 @@ async fn main(_spawner: Spawner) {
let mut rx_buffer = [0u8; 1024];
mem::forget(Output::new(&mut peri!(p, PIN_A), Level::High, OutputDrive::Standard));
mem::forget(Output::new(
peri!(p, PIN_A).reborrow(),
Level::High,
OutputDrive::Standard,
));
let mut u = BufferedUarteRx::new(
peri!(p, UART0),

View File

@@ -17,11 +17,11 @@ async fn main(_spawner: Spawner) {
let mut config = spim::Config::default();
config.frequency = spim::Frequency::M1;
let mut spim = Spim::new(
&mut peri!(p, SPIM0),
peri!(p, SPIM0).reborrow(),
irqs!(SPIM0),
&mut peri!(p, PIN_X),
&mut peri!(p, PIN_A), // MISO
&mut peri!(p, PIN_B), // MOSI
peri!(p, PIN_X).reborrow(),
peri!(p, PIN_A).reborrow(), // MISO
peri!(p, PIN_B).reborrow(), // MOSI
config.clone(),
);
let data = [

View File

@@ -19,8 +19,18 @@ async fn main(_spawner: Spawner) {
config.parity = uarte::Parity::EXCLUDED;
config.baudrate = uarte::Baudrate::BAUD1M;
let mut tx = UarteTx::new(&mut peri!(p, UART0), irqs!(UART0), &mut peri!(p, PIN_A), config.clone());
let mut rx = UarteRx::new(&mut peri!(p, UART1), irqs!(UART1), &mut peri!(p, PIN_B), config.clone());
let mut tx = UarteTx::new(
peri!(p, UART0).reborrow(),
irqs!(UART0),
peri!(p, PIN_A).reborrow(),
config.clone(),
);
let mut rx = UarteRx::new(
peri!(p, UART1).reborrow(),
irqs!(UART1),
peri!(p, PIN_B).reborrow(),
config.clone(),
);
let data = [
0x42, 0x43, 0x44, 0x45, 0x66, 0x12, 0x23, 0x34, 0x45, 0x19, 0x91, 0xaa, 0xff, 0xa5, 0x5a, 0x77,

View File

@@ -21,10 +21,10 @@ async fn main(_spawner: Spawner) {
config.baudrate = uarte::Baudrate::BAUD9600;
let uarte = Uarte::new(
&mut peri!(p, UART0),
peri!(p, UART0).reborrow(),
irqs!(UART0),
&mut peri!(p, PIN_A),
&mut peri!(p, PIN_B),
peri!(p, PIN_A).reborrow(),
peri!(p, PIN_B).reborrow(),
config.clone(),
);
let (mut tx, mut rx) = uarte.split();

View File

@@ -30,12 +30,12 @@ async fn main(_spawner: Spawner) {
{
{
let mut p = Channel::new_pin(&mut a, Pull::Down);
let mut p = Channel::new_pin(a.reborrow(), Pull::Down);
defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000);
defmt::assert!(adc.read(&mut p).await.unwrap() < 0b01_0000_0000);
}
{
let mut p = Channel::new_pin(&mut a, Pull::Up);
let mut p = Channel::new_pin(a.reborrow(), Pull::Up);
defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000);
defmt::assert!(adc.read(&mut p).await.unwrap() > 0b11_0000_0000);
}
@@ -43,21 +43,21 @@ async fn main(_spawner: Spawner) {
// not bothering with async reads from now on
{
{
let mut p = Channel::new_pin(&mut b, Pull::Down);
let mut p = Channel::new_pin(b.reborrow(), Pull::Down);
defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000);
}
{
let mut p = Channel::new_pin(&mut b, Pull::Up);
let mut p = Channel::new_pin(b.reborrow(), Pull::Up);
defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000);
}
}
{
{
let mut p = Channel::new_pin(&mut c, Pull::Down);
let mut p = Channel::new_pin(c.reborrow(), Pull::Down);
defmt::assert!(adc.blocking_read(&mut p).unwrap() < 0b01_0000_0000);
}
{
let mut p = Channel::new_pin(&mut c, Pull::Up);
let mut p = Channel::new_pin(c.reborrow(), Pull::Up);
defmt::assert!(adc.blocking_read(&mut p).unwrap() > 0b11_0000_0000);
}
}
@@ -65,15 +65,15 @@ async fn main(_spawner: Spawner) {
// gp29 is connected to vsys through a 200k/100k divider,
// adding pulls should change the value
let low = {
let mut p = Channel::new_pin(&mut d, Pull::Down);
let mut p = Channel::new_pin(d.reborrow(), Pull::Down);
adc.blocking_read(&mut p).unwrap()
};
let none = {
let mut p = Channel::new_pin(&mut d, Pull::None);
let mut p = Channel::new_pin(d.reborrow(), Pull::None);
adc.blocking_read(&mut p).unwrap()
};
let up = {
let mut p = Channel::new_pin(&mut d, Pull::Up);
let mut p = Channel::new_pin(d.reborrow(), Pull::Up);
adc.blocking_read(&mut p).unwrap()
};
defmt::assert!(low < none);
@@ -81,7 +81,7 @@ async fn main(_spawner: Spawner) {
}
{
let temp = convert_to_celsius(
adc.read(&mut Channel::new_temp_sensor(&mut p.ADC_TEMP_SENSOR))
adc.read(&mut Channel::new_temp_sensor(p.ADC_TEMP_SENSOR.reborrow()))
.await
.unwrap(),
);
@@ -97,14 +97,29 @@ async fn main(_spawner: Spawner) {
let mut low = [0u16; 16];
let mut none = [0u8; 16];
let mut up = [Sample::default(); 16];
adc.read_many(&mut Channel::new_pin(&mut d, Pull::Down), &mut low, 1, &mut p.DMA_CH0)
.await
.unwrap();
adc.read_many(&mut Channel::new_pin(&mut d, Pull::None), &mut none, 1, &mut p.DMA_CH0)
.await
.unwrap();
adc.read_many_raw(&mut Channel::new_pin(&mut d, Pull::Up), &mut up, 1, &mut p.DMA_CH0)
.await;
adc.read_many(
&mut Channel::new_pin(d.reborrow(), Pull::Down),
&mut low,
1,
p.DMA_CH0.reborrow(),
)
.await
.unwrap();
adc.read_many(
&mut Channel::new_pin(d.reborrow(), Pull::None),
&mut none,
1,
p.DMA_CH0.reborrow(),
)
.await
.unwrap();
adc.read_many_raw(
&mut Channel::new_pin(d.reborrow(), Pull::Up),
&mut up,
1,
p.DMA_CH0.reborrow(),
)
.await;
defmt::assert!(low.iter().zip(none.iter()).all(|(l, n)| *l >> 4 < *n as u16));
defmt::assert!(up.iter().all(|s| s.good()));
defmt::assert!(none.iter().zip(up.iter()).all(|(n, u)| (*n as u16) < u.value()));
@@ -112,10 +127,10 @@ async fn main(_spawner: Spawner) {
{
let mut temp = [0u16; 16];
adc.read_many(
&mut Channel::new_temp_sensor(&mut p.ADC_TEMP_SENSOR),
&mut Channel::new_temp_sensor(p.ADC_TEMP_SENSOR.reborrow()),
&mut temp,
1,
&mut p.DMA_CH0,
p.DMA_CH0.reborrow(),
)
.await
.unwrap();
@@ -126,10 +141,10 @@ async fn main(_spawner: Spawner) {
{
let mut multi = [0u16; 2];
let mut channels = [
Channel::new_pin(&mut a, Pull::Up),
Channel::new_temp_sensor(&mut p.ADC_TEMP_SENSOR),
Channel::new_pin(a.reborrow(), Pull::Up),
Channel::new_temp_sensor(p.ADC_TEMP_SENSOR.reborrow()),
];
adc.read_many_multichannel(&mut channels, &mut multi, 1, &mut p.DMA_CH0)
adc.read_many_multichannel(&mut channels, &mut multi, 1, p.DMA_CH0.reborrow())
.await
.unwrap();
defmt::assert!(multi[0] > 3_000);

View File

@@ -4,12 +4,13 @@ teleprobe_meta::target!(b"rpi-pico");
use defmt::{assert_eq, *};
use embassy_executor::Spawner;
use embassy_rp::bootsel::is_bootsel_pressed;
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let mut p = embassy_rp::init(Default::default());
let p = embassy_rp::init(Default::default());
info!("Hello World!");
// add some delay to give an attached debug probe time to parse the
@@ -18,7 +19,7 @@ async fn main(_spawner: Spawner) {
// https://github.com/knurling-rs/defmt/pull/683
Timer::after_millis(10).await;
assert_eq!(p.BOOTSEL.is_pressed(), false);
assert_eq!(is_bootsel_pressed(p.BOOTSEL), false);
info!("Test OK");
cortex_m::asm::bkpt();

View File

@@ -21,10 +21,10 @@ async fn main(_spawner: Spawner) {
// Test initial output
{
let b = Input::new(&mut b, Pull::None);
let b = Input::new(b.reborrow(), Pull::None);
{
let a = Output::new(&mut a, Level::Low);
let a = Output::new(a.reborrow(), Level::Low);
delay();
assert!(b.is_low());
assert!(!b.is_high());
@@ -32,7 +32,7 @@ async fn main(_spawner: Spawner) {
assert!(!a.is_set_high());
}
{
let mut a = Output::new(&mut a, Level::High);
let mut a = Output::new(a.reborrow(), Level::High);
delay();
assert!(!b.is_low());
assert!(b.is_high());
@@ -69,10 +69,10 @@ async fn main(_spawner: Spawner) {
// Test input no pull
{
let b = Input::new(&mut b, Pull::None);
let b = Input::new(b.reborrow(), Pull::None);
// no pull, the status is undefined
let mut a = Output::new(&mut a, Level::Low);
let mut a = Output::new(a.reborrow(), Level::Low);
delay();
assert!(b.is_low());
a.set_high();
@@ -83,11 +83,11 @@ async fn main(_spawner: Spawner) {
// Test input pulldown
#[cfg(feature = "rp2040")]
{
let b = Input::new(&mut b, Pull::Down);
let b = Input::new(b.reborrow(), Pull::Down);
delay();
assert!(b.is_low());
let mut a = Output::new(&mut a, Level::Low);
let mut a = Output::new(a.reborrow(), Level::Low);
delay();
assert!(b.is_low());
a.set_high();
@@ -97,11 +97,11 @@ async fn main(_spawner: Spawner) {
// Test input pullup
{
let b = Input::new(&mut b, Pull::Up);
let b = Input::new(b.reborrow(), Pull::Up);
delay();
assert!(b.is_high());
let mut a = Output::new(&mut a, Level::Low);
let mut a = Output::new(a.reborrow(), Level::Low);
delay();
assert!(b.is_low());
a.set_high();
@@ -112,8 +112,8 @@ async fn main(_spawner: Spawner) {
// OUTPUT OPEN DRAIN
#[cfg(feature = "rp2040")]
{
let mut b = OutputOpenDrain::new(&mut b, Level::High);
let mut a = Flex::new(&mut a);
let mut b = OutputOpenDrain::new(b.reborrow(), Level::High);
let mut a = Flex::new(a.reborrow());
a.set_as_input();
// When an OutputOpenDrain is high, it doesn't drive the pin.
@@ -170,12 +170,12 @@ async fn main(_spawner: Spawner) {
// Test initial output
{
//Flex pin configured as input
let mut b = Flex::new(&mut b);
let mut b = Flex::new(b.reborrow());
b.set_as_input();
{
//Flex pin configured as output
let mut a = Flex::new(&mut a); //Flex pin configured as output
let mut a = Flex::new(a.reborrow()); //Flex pin configured as output
a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state
a.set_as_output();
delay();
@@ -183,7 +183,7 @@ async fn main(_spawner: Spawner) {
}
{
//Flex pin configured as output
let mut a = Flex::new(&mut a);
let mut a = Flex::new(a.reborrow());
a.set_high();
a.set_as_output();
@@ -194,10 +194,10 @@ async fn main(_spawner: Spawner) {
// Test input no pull
{
let mut b = Flex::new(&mut b);
let mut b = Flex::new(b.reborrow());
b.set_as_input(); // no pull by default.
let mut a = Flex::new(&mut a);
let mut a = Flex::new(a.reborrow());
a.set_low();
a.set_as_output();
@@ -211,13 +211,13 @@ async fn main(_spawner: Spawner) {
// Test input pulldown
#[cfg(feature = "rp2040")]
{
let mut b = Flex::new(&mut b);
let mut b = Flex::new(b.reborrow());
b.set_as_input();
b.set_pull(Pull::Down);
delay();
assert!(b.is_low());
let mut a = Flex::new(&mut a);
let mut a = Flex::new(a.reborrow());
a.set_low();
a.set_as_output();
delay();
@@ -229,13 +229,13 @@ async fn main(_spawner: Spawner) {
// Test input pullup
{
let mut b = Flex::new(&mut b);
let mut b = Flex::new(b.reborrow());
b.set_as_input();
b.set_pull(Pull::Up);
delay();
assert!(b.is_high());
let mut a = Flex::new(&mut a);
let mut a = Flex::new(a.reborrow());
a.set_high();
a.set_as_output();
delay();

View File

@@ -22,8 +22,8 @@ async fn main(_spawner: Spawner) {
{
info!("test wait_for_high");
let mut output = Output::new(&mut output_pin, Level::Low);
let mut input = Input::new(&mut input_pin, Pull::None);
let mut output = Output::new(output_pin.reborrow(), Level::Low);
let mut input = Input::new(input_pin.reborrow(), Pull::None);
assert!(input.is_low(), "input was expected to be low");
@@ -43,8 +43,8 @@ async fn main(_spawner: Spawner) {
{
info!("test wait_for_low");
let mut output = Output::new(&mut output_pin, Level::High);
let mut input = Input::new(&mut input_pin, Pull::None);
let mut output = Output::new(output_pin.reborrow(), Level::High);
let mut input = Input::new(input_pin.reborrow(), Pull::None);
assert!(input.is_high(), "input was expected to be high");
@@ -63,8 +63,8 @@ async fn main(_spawner: Spawner) {
{
info!("test wait_for_rising_edge");
let mut output = Output::new(&mut output_pin, Level::Low);
let mut input = Input::new(&mut input_pin, Pull::None);
let mut output = Output::new(output_pin.reborrow(), Level::Low);
let mut input = Input::new(input_pin.reborrow(), Pull::None);
assert!(input.is_low(), "input was expected to be low");
@@ -83,8 +83,8 @@ async fn main(_spawner: Spawner) {
{
info!("test wait_for_falling_edge");
let mut output = Output::new(&mut output_pin, Level::High);
let mut input = Input::new(&mut input_pin, Pull::None);
let mut output = Output::new(output_pin.reborrow(), Level::High);
let mut input = Input::new(input_pin.reborrow(), Pull::None);
assert!(input.is_high(), "input was expected to be high");
@@ -103,8 +103,8 @@ async fn main(_spawner: Spawner) {
{
info!("test wait_for_any_edge (falling)");
let mut output = Output::new(&mut output_pin, Level::High);
let mut input = Input::new(&mut input_pin, Pull::None);
let mut output = Output::new(output_pin.reborrow(), Level::High);
let mut input = Input::new(input_pin.reborrow(), Pull::None);
assert!(input.is_high(), "input was expected to be high");
@@ -123,8 +123,8 @@ async fn main(_spawner: Spawner) {
{
info!("test wait_for_any_edge (rising)");
let mut output = Output::new(&mut output_pin, Level::Low);
let mut input = Input::new(&mut input_pin, Pull::None);
let mut output = Output::new(output_pin.reborrow(), Level::Low);
let mut input = Input::new(input_pin.reborrow(), Pull::None);
assert!(input.is_low(), "input was expected to be low");

View File

@@ -10,6 +10,7 @@ use embassy_executor::Executor;
use embassy_rp::gpio::{Input, Level, Output, Pull};
use embassy_rp::multicore::{spawn_core1, Stack};
use embassy_rp::peripherals::{PIN_0, PIN_1};
use embassy_rp::Peri;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::channel::Channel;
use static_cell::StaticCell;
@@ -37,7 +38,7 @@ fn main() -> ! {
}
#[embassy_executor::task]
async fn core0_task(p: PIN_0) {
async fn core0_task(p: Peri<'static, PIN_0>) {
info!("CORE0 is running");
let mut pin = Output::new(p, Level::Low);
@@ -54,7 +55,7 @@ async fn core0_task(p: PIN_0) {
}
#[embassy_executor::task]
async fn core1_task(p: PIN_1) {
async fn core1_task(p: Peri<'static, PIN_1>) {
info!("CORE1 is running");
CHANNEL0.receive().await;

View File

@@ -33,7 +33,7 @@ async fn main(_spawner: Spawner) {
// Test free-running clock
{
let pwm = Pwm::new_free(&mut p.PWM_SLICE3, cfg.clone());
let pwm = Pwm::new_free(p.PWM_SLICE3.reborrow(), cfg.clone());
cortex_m::asm::delay(125);
let ctr = pwm.counter();
assert!(ctr > 0);
@@ -50,8 +50,8 @@ async fn main(_spawner: Spawner) {
// Test output from A
{
let pin1 = Input::new(&mut p9, Pull::None);
let _pwm = Pwm::new_output_a(&mut p.PWM_SLICE3, &mut p6, cfg.clone());
let pin1 = Input::new(p9.reborrow(), Pull::None);
let _pwm = Pwm::new_output_a(p.PWM_SLICE3.reborrow(), p6.reborrow(), cfg.clone());
Timer::after_millis(1).await;
assert_eq!(pin1.is_low(), invert_a);
Timer::after_millis(5).await;
@@ -64,8 +64,8 @@ async fn main(_spawner: Spawner) {
// Test output from B
{
let pin2 = Input::new(&mut p11, Pull::None);
let _pwm = Pwm::new_output_b(&mut p.PWM_SLICE3, &mut p7, cfg.clone());
let pin2 = Input::new(p11.reborrow(), Pull::None);
let _pwm = Pwm::new_output_b(p.PWM_SLICE3.reborrow(), p7.reborrow(), cfg.clone());
Timer::after_millis(1).await;
assert_ne!(pin2.is_low(), invert_a);
Timer::after_millis(5).await;
@@ -78,9 +78,9 @@ async fn main(_spawner: Spawner) {
// Test output from A+B
{
let pin1 = Input::new(&mut p9, Pull::None);
let pin2 = Input::new(&mut p11, Pull::None);
let _pwm = Pwm::new_output_ab(&mut p.PWM_SLICE3, &mut p6, &mut p7, cfg.clone());
let pin1 = Input::new(p9.reborrow(), Pull::None);
let pin2 = Input::new(p11.reborrow(), Pull::None);
let _pwm = Pwm::new_output_ab(p.PWM_SLICE3.reborrow(), p6.reborrow(), p7.reborrow(), cfg.clone());
Timer::after_millis(1).await;
assert_eq!(pin1.is_low(), invert_a);
assert_ne!(pin2.is_low(), invert_a);
@@ -99,8 +99,14 @@ async fn main(_spawner: Spawner) {
// Test level-gated
#[cfg(feature = "rp2040")]
{
let mut pin2 = Output::new(&mut p11, Level::Low);
let pwm = Pwm::new_input(&mut p.PWM_SLICE3, &mut p7, Pull::None, InputMode::Level, cfg.clone());
let mut pin2 = Output::new(p11.reborrow(), Level::Low);
let pwm = Pwm::new_input(
p.PWM_SLICE3.reborrow(),
p7.reborrow(),
Pull::None,
InputMode::Level,
cfg.clone(),
);
assert_eq!(pwm.counter(), 0);
Timer::after_millis(5).await;
assert_eq!(pwm.counter(), 0);
@@ -117,10 +123,10 @@ async fn main(_spawner: Spawner) {
// Test rising-gated
#[cfg(feature = "rp2040")]
{
let mut pin2 = Output::new(&mut p11, Level::Low);
let mut pin2 = Output::new(p11.reborrow(), Level::Low);
let pwm = Pwm::new_input(
&mut p.PWM_SLICE3,
&mut p7,
p.PWM_SLICE3.reborrow(),
p7.reborrow(),
Pull::None,
InputMode::RisingEdge,
cfg.clone(),
@@ -139,10 +145,10 @@ async fn main(_spawner: Spawner) {
// Test falling-gated
#[cfg(feature = "rp2040")]
{
let mut pin2 = Output::new(&mut p11, Level::High);
let mut pin2 = Output::new(p11.reborrow(), Level::High);
let pwm = Pwm::new_input(
&mut p.PWM_SLICE3,
&mut p7,
p.PWM_SLICE3.reborrow(),
p7.reborrow(),
Pull::None,
InputMode::FallingEdge,
cfg.clone(),
@@ -160,10 +166,10 @@ async fn main(_spawner: Spawner) {
// pull-down
{
let pin2 = Input::new(&mut p11, Pull::None);
let pin2 = Input::new(p11.reborrow(), Pull::None);
Pwm::new_input(
&mut p.PWM_SLICE3,
&mut p7,
p.PWM_SLICE3.reborrow(),
p7.reborrow(),
Pull::Down,
InputMode::FallingEdge,
cfg.clone(),
@@ -174,10 +180,10 @@ async fn main(_spawner: Spawner) {
// pull-up
{
let pin2 = Input::new(&mut p11, Pull::None);
let pin2 = Input::new(p11.reborrow(), Pull::None);
Pwm::new_input(
&mut p.PWM_SLICE3,
&mut p7,
p.PWM_SLICE3.reborrow(),
p7.reborrow(),
Pull::Up,
InputMode::FallingEdge,
cfg.clone(),

View File

@@ -56,7 +56,7 @@ async fn main(_spawner: Spawner) {
{
let config = Config::default();
let mut uart = Uart::new_blocking(&mut uart, &mut tx, &mut rx, config);
let mut uart = Uart::new_blocking(uart.reborrow(), tx.reborrow(), rx.reborrow(), config);
// We can't send too many bytes, they have to fit in the FIFO.
// This is because we aren't sending+receiving at the same time.
@@ -69,7 +69,7 @@ async fn main(_spawner: Spawner) {
info!("test overflow detection");
{
let config = Config::default();
let mut uart = Uart::new_blocking(&mut uart, &mut tx, &mut rx, config);
let mut uart = Uart::new_blocking(uart.reborrow(), tx.reborrow(), rx.reborrow(), config);
let data = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
@@ -93,7 +93,7 @@ async fn main(_spawner: Spawner) {
info!("test break detection");
{
let config = Config::default();
let mut uart = Uart::new_blocking(&mut uart, &mut tx, &mut rx, config);
let mut uart = Uart::new_blocking(uart.reborrow(), tx.reborrow(), rx.reborrow(), config);
// break on empty fifo
uart.send_break(20).await;
@@ -113,11 +113,11 @@ async fn main(_spawner: Spawner) {
// parity detection. here we bitbang to not require two uarts.
info!("test parity error detection");
{
let mut pin = Output::new(&mut tx, Level::High);
let mut pin = Output::new(tx.reborrow(), Level::High);
let mut config = Config::default();
config.baudrate = 1000;
config.parity = Parity::ParityEven;
let mut uart = UartRx::new_blocking(&mut uart, &mut rx, config);
let mut uart = UartRx::new_blocking(uart.reborrow(), rx.reborrow(), config);
async fn chr(pin: &mut Output<'_>, v: u8, parity: u8) {
send(pin, v, Some(parity != 0)).await;
@@ -140,10 +140,10 @@ async fn main(_spawner: Spawner) {
// framing error detection. here we bitbang because there's no other way.
info!("test framing error detection");
{
let mut pin = Output::new(&mut tx, Level::High);
let mut pin = Output::new(tx.reborrow(), Level::High);
let mut config = Config::default();
config.baudrate = 1000;
let mut uart = UartRx::new_blocking(&mut uart, &mut rx, config);
let mut uart = UartRx::new_blocking(uart.reborrow(), rx.reborrow(), config);
async fn chr(pin: &mut Output<'_>, v: u8, good: bool) {
if good {

View File

@@ -73,7 +73,15 @@ async fn main(_spawner: Spawner) {
let config = Config::default();
let tx_buf = &mut [0u8; 16];
let rx_buf = &mut [0u8; 16];
let mut uart = BufferedUart::new(&mut uart, Irqs, &mut tx, &mut rx, tx_buf, rx_buf, config);
let mut uart = BufferedUart::new(
uart.reborrow(),
Irqs,
tx.reborrow(),
rx.reborrow(),
tx_buf,
rx_buf,
config,
);
// Make sure we send more bytes than fits in the FIFO, to test the actual
// bufferedUart.
@@ -93,7 +101,15 @@ async fn main(_spawner: Spawner) {
let config = Config::default();
let tx_buf = &mut [0u8; 16];
let rx_buf = &mut [0u8; 16];
let mut uart = BufferedUart::new(&mut uart, Irqs, &mut tx, &mut rx, tx_buf, rx_buf, config);
let mut uart = BufferedUart::new(
uart.reborrow(),
Irqs,
tx.reborrow(),
rx.reborrow(),
tx_buf,
rx_buf,
config,
);
// Make sure we send more bytes than fits in the FIFO, to test the actual
// bufferedUart.
@@ -128,7 +144,15 @@ async fn main(_spawner: Spawner) {
config.baudrate = 1000;
let tx_buf = &mut [0u8; 16];
let rx_buf = &mut [0u8; 16];
let mut uart = BufferedUart::new(&mut uart, Irqs, &mut tx, &mut rx, tx_buf, rx_buf, config);
let mut uart = BufferedUart::new(
uart.reborrow(),
Irqs,
tx.reborrow(),
rx.reborrow(),
tx_buf,
rx_buf,
config,
);
// break on empty buffer
uart.send_break(20).await;
@@ -156,13 +180,13 @@ async fn main(_spawner: Spawner) {
// parity detection. here we bitbang to not require two uarts.
info!("test parity error detection");
{
let mut pin = Output::new(&mut tx, Level::High);
let mut pin = Output::new(tx.reborrow(), Level::High);
// choose a very slow baud rate to make tests reliable even with O0
let mut config = Config::default();
config.baudrate = 1000;
config.parity = Parity::ParityEven;
let rx_buf = &mut [0u8; 16];
let mut uart = BufferedUartRx::new(&mut uart, Irqs, &mut rx, rx_buf, config);
let mut uart = BufferedUartRx::new(uart.reborrow(), Irqs, rx.reborrow(), rx_buf, config);
async fn chr(pin: &mut Output<'_>, v: u8, parity: u32) {
send(pin, v, Some(parity != 0)).await;
@@ -204,12 +228,12 @@ async fn main(_spawner: Spawner) {
// framing error detection. here we bitbang because there's no other way.
info!("test framing error detection");
{
let mut pin = Output::new(&mut tx, Level::High);
let mut pin = Output::new(tx.reborrow(), Level::High);
// choose a very slow baud rate to make tests reliable even with O0
let mut config = Config::default();
config.baudrate = 1000;
let rx_buf = &mut [0u8; 16];
let mut uart = BufferedUartRx::new(&mut uart, Irqs, &mut rx, rx_buf, config);
let mut uart = BufferedUartRx::new(uart.reborrow(), Irqs, rx.reborrow(), rx_buf, config);
async fn chr(pin: &mut Output<'_>, v: u8, good: bool) {
if good {

View File

@@ -65,12 +65,12 @@ async fn main(_spawner: Spawner) {
{
let config = Config::default();
let mut uart = Uart::new(
&mut uart,
&mut tx,
&mut rx,
uart.reborrow(),
tx.reborrow(),
rx.reborrow(),
Irqs,
&mut p.DMA_CH0,
&mut p.DMA_CH1,
p.DMA_CH0.reborrow(),
p.DMA_CH1.reborrow(),
config,
);
@@ -86,12 +86,12 @@ async fn main(_spawner: Spawner) {
{
let config = Config::default();
let mut uart = Uart::new(
&mut uart,
&mut tx,
&mut rx,
uart.reborrow(),
tx.reborrow(),
rx.reborrow(),
Irqs,
&mut p.DMA_CH0,
&mut p.DMA_CH1,
p.DMA_CH0.reborrow(),
p.DMA_CH1.reborrow(),
config,
);
@@ -115,12 +115,12 @@ async fn main(_spawner: Spawner) {
{
let config = Config::default();
let (mut tx, mut rx) = Uart::new(
&mut uart,
&mut tx,
&mut rx,
uart.reborrow(),
tx.reborrow(),
rx.reborrow(),
Irqs,
&mut p.DMA_CH0,
&mut p.DMA_CH1,
p.DMA_CH0.reborrow(),
p.DMA_CH1.reborrow(),
config,
)
.split();
@@ -156,12 +156,12 @@ async fn main(_spawner: Spawner) {
// parity detection. here we bitbang to not require two uarts.
info!("test parity error detection");
{
let mut pin = Output::new(&mut tx, Level::High);
let mut pin = Output::new(tx.reborrow(), Level::High);
// choose a very slow baud rate to make tests reliable even with O0
let mut config = Config::default();
config.baudrate = 1000;
config.parity = Parity::ParityEven;
let mut uart = UartRx::new(&mut uart, &mut rx, Irqs, &mut p.DMA_CH0, config);
let mut uart = UartRx::new(uart.reborrow(), rx.reborrow(), Irqs, p.DMA_CH0.reborrow(), config);
async fn chr(pin: &mut Output<'_>, v: u8, parity: u32) {
send(pin, v, Some(parity != 0)).await;
@@ -202,11 +202,11 @@ async fn main(_spawner: Spawner) {
// framing error detection. here we bitbang because there's no other way.
info!("test framing error detection");
{
let mut pin = Output::new(&mut tx, Level::High);
let mut pin = Output::new(tx.reborrow(), Level::High);
// choose a very slow baud rate to make tests reliable even with O0
let mut config = Config::default();
config.baudrate = 1000;
let mut uart = UartRx::new(&mut uart, &mut rx, Irqs, &mut p.DMA_CH0, config);
let mut uart = UartRx::new(uart.reborrow(), rx.reborrow(), Irqs, p.DMA_CH0.reborrow(), config);
async fn chr(pin: &mut Output<'_>, v: u8, good: bool) {
if good {

View File

@@ -43,7 +43,7 @@ async fn main(_spawner: Spawner) {
// To synchronise to the bus the RX input needs to see a high level.
// Use `mem::forget()` to release the borrow on the pin but keep the
// pull-up resistor enabled.
let rx_pin = Input::new(&mut rx, Pull::Up);
let rx_pin = Input::new(rx.reborrow(), Pull::Up);
core::mem::forget(rx_pin);
let mut can = embassy_stm32::can::Can::new(can, rx, tx, Irqs);

View File

@@ -82,8 +82,8 @@ async fn main(_spawner: Spawner) {
let cnt1 = defmt::unwrap!(
cordic
.async_calc_32bit(
&mut write_dma,
&mut read_dma,
write_dma.reborrow(),
read_dma.reborrow(),
&input_q1_31[2..],
&mut output_q1_31[cnt0..],
true,

View File

@@ -20,10 +20,10 @@ async fn main(_spawner: Spawner) {
// Test initial output
{
let b = Input::new(&mut b, Pull::None);
let b = Input::new(b.reborrow(), Pull::None);
{
let a = Output::new(&mut a, Level::Low, Speed::Low);
let a = Output::new(a.reborrow(), Level::Low, Speed::Low);
delay();
assert!(b.is_low());
assert!(!b.is_high());
@@ -31,7 +31,7 @@ async fn main(_spawner: Spawner) {
assert!(!a.is_set_high());
}
{
let mut a = Output::new(&mut a, Level::High, Speed::Low);
let mut a = Output::new(a.reborrow(), Level::High, Speed::Low);
delay();
assert!(!b.is_low());
assert!(b.is_high());
@@ -68,10 +68,10 @@ async fn main(_spawner: Spawner) {
// Test input no pull
{
let b = Input::new(&mut b, Pull::None);
let b = Input::new(b.reborrow(), Pull::None);
// no pull, the status is undefined
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
let mut a = Output::new(a.reborrow(), Level::Low, Speed::Low);
delay();
assert!(b.is_low());
a.set_high();
@@ -81,11 +81,11 @@ async fn main(_spawner: Spawner) {
// Test input pulldown
{
let b = Input::new(&mut b, Pull::Down);
let b = Input::new(b.reborrow(), Pull::Down);
delay();
assert!(b.is_low());
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
let mut a = Output::new(a.reborrow(), Level::Low, Speed::Low);
delay();
assert!(b.is_low());
a.set_high();
@@ -95,11 +95,11 @@ async fn main(_spawner: Spawner) {
// Test input pullup
{
let b = Input::new(&mut b, Pull::Up);
let b = Input::new(b.reborrow(), Pull::Up);
delay();
assert!(b.is_high());
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
let mut a = Output::new(a.reborrow(), Level::Low, Speed::Low);
delay();
assert!(b.is_low());
a.set_high();
@@ -109,10 +109,10 @@ async fn main(_spawner: Spawner) {
// Test output open drain
{
let b = Input::new(&mut b, Pull::Down);
let b = Input::new(b.reborrow(), Pull::Down);
// no pull, the status is undefined
let mut a = OutputOpenDrain::new(&mut a, Level::Low, Speed::Low);
let mut a = OutputOpenDrain::new(a.reborrow(), Level::Low, Speed::Low);
delay();
assert!(b.is_low());
a.set_high(); // High-Z output
@@ -124,12 +124,12 @@ async fn main(_spawner: Spawner) {
// Test initial output
{
//Flex pin configured as input
let mut b = Flex::new(&mut b);
let mut b = Flex::new(b.reborrow());
b.set_as_input(Pull::None);
{
//Flex pin configured as output
let mut a = Flex::new(&mut a); //Flex pin configured as output
let mut a = Flex::new(a.reborrow()); //Flex pin configured as output
a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state
a.set_as_output(Speed::Low);
delay();
@@ -137,7 +137,7 @@ async fn main(_spawner: Spawner) {
}
{
//Flex pin configured as output
let mut a = Flex::new(&mut a);
let mut a = Flex::new(a.reborrow());
a.set_high();
a.set_as_output(Speed::Low);
@@ -148,10 +148,10 @@ async fn main(_spawner: Spawner) {
// Test input no pull
{
let mut b = Flex::new(&mut b);
let mut b = Flex::new(b.reborrow());
b.set_as_input(Pull::None); // no pull, the status is undefined
let mut a = Flex::new(&mut a);
let mut a = Flex::new(a.reborrow());
a.set_low();
a.set_as_output(Speed::Low);
@@ -164,12 +164,12 @@ async fn main(_spawner: Spawner) {
// Test input pulldown
{
let mut b = Flex::new(&mut b);
let mut b = Flex::new(b.reborrow());
b.set_as_input(Pull::Down);
delay();
assert!(b.is_low());
let mut a = Flex::new(&mut a);
let mut a = Flex::new(a.reborrow());
a.set_low();
a.set_as_output(Speed::Low);
delay();
@@ -181,12 +181,12 @@ async fn main(_spawner: Spawner) {
// Test input pullup
{
let mut b = Flex::new(&mut b);
let mut b = Flex::new(b.reborrow());
b.set_as_input(Pull::Up);
delay();
assert!(b.is_high());
let mut a = Flex::new(&mut a);
let mut a = Flex::new(a.reborrow());
a.set_high();
a.set_as_output(Speed::Low);
delay();
@@ -198,10 +198,10 @@ async fn main(_spawner: Spawner) {
// Test output open drain
{
let mut b = Flex::new(&mut b);
let mut b = Flex::new(b.reborrow());
b.set_as_input(Pull::Down);
let mut a = Flex::new(&mut a);
let mut a = Flex::new(a.reborrow());
a.set_low();
a.set_as_input_output(Speed::Low);
delay();

View File

@@ -40,15 +40,15 @@ async fn main(_spawner: Spawner) {
// ======== Try 4bit. ==============
info!("initializing in 4-bit mode...");
let mut s = Sdmmc::new_4bit(
&mut sdmmc,
sdmmc.reborrow(),
Irqs,
&mut dma,
&mut clk,
&mut cmd,
&mut d0,
&mut d1,
&mut d2,
&mut d3,
dma.reborrow(),
clk.reborrow(),
cmd.reborrow(),
d0.reborrow(),
d1.reborrow(),
d2.reborrow(),
d3.reborrow(),
Default::default(),
);
@@ -89,12 +89,12 @@ async fn main(_spawner: Spawner) {
// ======== Try 1bit. ==============
info!("initializing in 1-bit mode...");
let mut s = Sdmmc::new_1bit(
&mut sdmmc,
sdmmc.reborrow(),
Irqs,
&mut dma,
&mut clk,
&mut cmd,
&mut d0,
dma.reborrow(),
clk.reborrow(),
cmd.reborrow(),
d0.reborrow(),
Default::default(),
);

View File

@@ -25,10 +25,10 @@ async fn main(_spawner: Spawner) {
spi_config.frequency = Hertz(1_000_000);
let mut spi = Spi::new_blocking(
&mut spi_peri,
&mut sck, // Arduino D13
&mut mosi, // Arduino D11
&mut miso, // Arduino D12
spi_peri.reborrow(),
sck.reborrow(), // Arduino D13
mosi.reborrow(), // Arduino D11
miso.reborrow(), // Arduino D12
spi_config,
);
@@ -43,20 +43,20 @@ async fn main(_spawner: Spawner) {
defmt::assert!(!embassy_stm32::pac::RCC.apb2enr().read().spi1en());
// test rx-only configuration
let mut spi = Spi::new_blocking_rxonly(&mut spi_peri, &mut sck, &mut miso, spi_config);
let mut mosi_out = Output::new(&mut mosi, Level::Low, Speed::VeryHigh);
let mut spi = Spi::new_blocking_rxonly(spi_peri.reborrow(), sck.reborrow(), miso.reborrow(), spi_config);
let mut mosi_out = Output::new(mosi.reborrow(), Level::Low, Speed::VeryHigh);
test_rx::<u8>(&mut spi, &mut mosi_out);
test_rx::<u16>(&mut spi, &mut mosi_out);
drop(spi);
drop(mosi_out);
let mut spi = Spi::new_blocking_txonly(&mut spi_peri, &mut sck, &mut mosi, spi_config);
let mut spi = Spi::new_blocking_txonly(spi_peri.reborrow(), sck.reborrow(), mosi.reborrow(), spi_config);
test_tx::<u8>(&mut spi);
test_tx::<u16>(&mut spi);
drop(spi);
let mut spi = Spi::new_blocking_txonly_nosck(&mut spi_peri, &mut mosi, spi_config);
let mut spi = Spi::new_blocking_txonly_nosck(spi_peri.reborrow(), mosi.reborrow(), spi_config);
test_tx::<u8>(&mut spi);
test_tx::<u16>(&mut spi);
drop(spi);

View File

@@ -27,12 +27,12 @@ async fn main(_spawner: Spawner) {
spi_config.frequency = Hertz(1_000_000);
let mut spi = Spi::new(
&mut spi_peri,
&mut sck, // Arduino D13
&mut mosi, // Arduino D11
&mut miso, // Arduino D12
&mut tx_dma,
&mut rx_dma,
spi_peri.reborrow(),
sck.reborrow(), // Arduino D13
mosi.reborrow(), // Arduino D11
miso.reborrow(), // Arduino D12
tx_dma.reborrow(),
rx_dma.reborrow(),
spi_config,
);
@@ -42,28 +42,34 @@ async fn main(_spawner: Spawner) {
// test rx-only configuration
let mut spi = Spi::new_rxonly(
&mut spi_peri,
&mut sck,
&mut miso,
spi_peri.reborrow(),
sck.reborrow(),
miso.reborrow(),
// SPIv1/f1 requires txdma even if rxonly.
#[cfg(not(feature = "spi-v345"))]
&mut tx_dma,
&mut rx_dma,
tx_dma.reborrow(),
rx_dma.reborrow(),
spi_config,
);
let mut mosi_out = Output::new(&mut mosi, Level::Low, Speed::VeryHigh);
let mut mosi_out = Output::new(mosi.reborrow(), Level::Low, Speed::VeryHigh);
test_rx::<u8>(&mut spi, &mut mosi_out).await;
test_rx::<u16>(&mut spi, &mut mosi_out).await;
drop(spi);
drop(mosi_out);
let mut spi = Spi::new_txonly(&mut spi_peri, &mut sck, &mut mosi, &mut tx_dma, spi_config);
let mut spi = Spi::new_txonly(
spi_peri.reborrow(),
sck.reborrow(),
mosi.reborrow(),
tx_dma.reborrow(),
spi_config,
);
test_tx::<u8>(&mut spi).await;
test_tx::<u16>(&mut spi).await;
drop(spi);
let mut spi = Spi::new_txonly_nosck(&mut spi_peri, &mut mosi, &mut tx_dma, spi_config);
let mut spi = Spi::new_txonly_nosck(spi_peri.reborrow(), mosi.reborrow(), tx_dma.reborrow(), spi_config);
test_tx::<u8>(&mut spi).await;
test_tx::<u16>(&mut spi).await;
drop(spi);

View File

@@ -9,7 +9,7 @@ use defmt::{assert, assert_eq};
use embassy_executor::Spawner;
use embassy_futures::join::join;
use embassy_stm32::ucpd::{self, CcPhy, CcPull, CcSel, CcVState, RxError, Ucpd};
use embassy_stm32::{bind_interrupts, peripherals};
use embassy_stm32::{bind_interrupts, peripherals, Peri};
use embassy_time::Timer;
bind_interrupts!(struct Irqs {
@@ -28,8 +28,8 @@ async fn wait_for_vstate<T: ucpd::Instance>(cc_phy: &mut CcPhy<'_, T>, vstate: C
async fn source(
mut ucpd: Ucpd<'static, peripherals::UCPD1>,
rx_dma: peripherals::DMA1_CH1,
tx_dma: peripherals::DMA1_CH2,
rx_dma: Peri<'static, peripherals::DMA1_CH1>,
tx_dma: Peri<'static, peripherals::DMA1_CH2>,
) {
debug!("source: setting default current pull-up");
ucpd.cc_phy().set_pull(CcPull::SourceDefaultUsb);
@@ -65,8 +65,8 @@ async fn source(
async fn sink(
mut ucpd: Ucpd<'static, peripherals::UCPD2>,
rx_dma: peripherals::DMA1_CH3,
tx_dma: peripherals::DMA1_CH4,
rx_dma: Peri<'static, peripherals::DMA1_CH3>,
tx_dma: Peri<'static, peripherals::DMA1_CH4>,
) {
debug!("sink: setting pull down");
ucpd.cc_phy().set_pull(CcPull::Sink);

View File

@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
{
let config = Config::default();
let mut usart = Uart::new_blocking(&mut usart, &mut rx, &mut tx, config).unwrap();
let mut usart = Uart::new_blocking(usart.reborrow(), rx.reborrow(), tx.reborrow(), config).unwrap();
// We can't send too many bytes, they have to fit in the FIFO.
// This is because we aren't sending+receiving at the same time.
@@ -45,7 +45,7 @@ async fn main(_spawner: Spawner) {
// Test error handling with with an overflow error
{
let config = Config::default();
let mut usart = Uart::new_blocking(&mut usart, &mut rx, &mut tx, config).unwrap();
let mut usart = Uart::new_blocking(usart.reborrow(), rx.reborrow(), tx.reborrow(), config).unwrap();
// Send enough bytes to fill the RX FIFOs off all USART versions.
let data = [0; 64];
@@ -75,7 +75,7 @@ async fn main(_spawner: Spawner) {
let mut config = Config::default();
config.baudrate = baudrate;
let mut usart = match Uart::new_blocking(&mut usart, &mut rx, &mut tx, config) {
let mut usart = match Uart::new_blocking(usart.reborrow(), rx.reborrow(), tx.reborrow(), config) {
Ok(x) => x,
Err(ConfigError::BaudrateTooHigh) => {
info!("baudrate too high");