Questions about embassy

Hey,

I am playing around with embassy and a microbit v2 (nrf52833 controller), trying to build some kind of robot around the board. Handling IO Pins and driving motors with PWMs already works. But now i stumbled over some problems. Probably because of the type and trait system.

First question is about updating from the crate embassy-nrf (version = "0.3.1") to embassy-nrf (version = "0.7.0"). In the old version something like this worked:

pub async fn ultrasonic_task(trigger_pin: AnyPin, echo_pin: AnyPin) { 
 // Initialize GPIO pins for the HCSR04 sensor let 
 let trigger = Output::new(trigger_pin, Level::Low, OutputDrive::Standard); 
 let echo = Input::new(echo_pin, Pull::None);
}

Use the defined task for example in main.

spawner
    .spawn(ultrasonic_task(
        peripherals.P0_12.degrade(),
        peripherals.P0_17.degrade(),
    ))
    .unwrap();

In 0.7.0 this code doesent work anymore. The degrade function seems to not exist anmymore.I dont find any examples how to pass a pin into a function?

The second problem appears when i try to move my pwm code into a seperate function/task. I have something like this in main:

let peripherals = embassy_nrf::init(Default::default());

let mut pwm = SimplePwm::new_1ch(peripherals.PWM0, peripherals.P0_04);

Would i pass a reference to peripherals into the function or would i move peripherals.PWM0 into the function? If so, how?

Many thanks in advance :slightly_smiling_face:.

firstly a disclaimer: the embassy design is slightly different from the bare metal hal crate, e.g. nrf52833-ahl which is more familiar to me, and I don't have the hardware to test it out, so I can't guarantee my answer is correct, you'll need to test it yourself.

looking at the documentation, e.g. of P0_12, there's impl From<P0_12> for AnyPin, so I think you can just call .into():

the latter.

the embedded rust ecosystem utilize rust types to represent hardware resources, the driver type, SimplePwm, should own the specific peripherals according to the hardware.

the example code you posted should be correct. if you countered compile error, it's probably for other reasons. please post the full error message and relevant code snippet for context.

Same issue with the change of the API for passing pins. I have submitted a Github Issue.