rp-rs / pio-rs

Support crate for Raspberry Pi's PIO architecture.
MIT License
149 stars 22 forks source link

Define at compile time in pico_asm! #63

Open dthelegend opened 3 months ago

dthelegend commented 3 months ago

Is there any way of doing the following:

fn some_function<const N : u8> -> ! {
    let led_program = pio_proc::pio_asm!(
        ".define T1 42",
        ".wrap_target",
            "mov pins , 0 [T0]",
            "mov pins , 1 [T1]",
        ".wrap",
        define(T0 = N) // Add T0 defined to the value of compile constant N
    );
    ...
}

Essentially where you can add a define to a pio_asm at compile time? If not I would like to propose this addition.

jannic commented 3 months ago

It's not currently possible, but it sounds like a nice enhancement.

However, I'm not sure if it's possible to actually evaluate N inside the macro at compile time.

dthelegend commented 3 months ago

I checked and you cannot evaluate constants at macro time, so this is DOA :(

I also noticed that since you can't get the type out from the public defines, you can't declare a pio_asm! as a constant variable. It might be worth adding a way to forward declare the ExpandedDefines type with a new option(public_defines_type) or something.

I can see a world where if you can at least declare it constant at compile time one could modify the program at compile with a custom define they needed.