Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of slice for Program code #55

Open
ibuki2003 opened this issue Feb 8, 2024 · 2 comments
Open

Support of slice for Program code #55

ibuki2003 opened this issue Feb 8, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@ibuki2003
Copy link

Now Program::code is ArrayVec type, which contains its own data.
I think almost all of use cases are to program "static" one, and it is not necessary to allocate memory every time.

So I suggest to add slice support for Program::code.

Furthermore, I want pio_proc assembler macros to support slice as well.
The macros returns ProgramWithDefines<> type, which has dynamic type parameter, so it is not possible to use it as static variable.

I am able to work with this change, but I am not sure if it is good idea or not.

@jannic jannic added the enhancement New feature or request label Aug 27, 2024
@jannic
Copy link
Member

jannic commented Aug 27, 2024

As pio programs are only a few bytes long, I wonder if it's worth to spend effort on optimizing memory usage.
Do you have an example where such a change would help?

@ibuki2003
Copy link
Author

Hello, @jannic.

Your indication is correct; the performance problem is not so significant.
I don't like that the process is not minimal.

However, I think that is more convenient since slice is available as a primitive type.

  • In almost all use cases, the program is a static value, so we can use a static slice.
    • The difference is little, but a simple and fast way is preferable.
  • When dynamically generating programs, we don't need to convert the array to ArrayVec.

The code I first confront this issue is like this:

fn main() {
  //
  pio0.install(&PROGRAM).unwrap();
  //
}

// Here the program is compile-time-static value
// but this approach is not available.
static PROGRAM: Program<32> = pio_proc::pio_asm![
  ".wrap_target",
  "  set pins, 1",
  "  set pins, 0",
  ".wrap",
].program;

I get some errors because ArrayVec does not work in statics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants