Skip to content

Add support for putget to PIO #935

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

Open
horazont opened this issue Jun 4, 2025 · 6 comments · May be fixed by #936
Open

Add support for putget to PIO #935

horazont opened this issue Jun 4, 2025 · 6 comments · May be fixed by #936

Comments

@horazont
Copy link
Contributor

horazont commented Jun 4, 2025

PIOs support changing the FIFO configuration to support random access instead of acting as a FIFO (see for example Section 11.4.8 and 11.4.9. of the reference manual, as well as FJOIN_RX_PUT / FJOIN_RX_GET in the SMx_SHIFTCTRL registers).

As far as I can tell, this is currently not supported by the RP235x HAL.

I was thinking to add support for that (as I am currently bypassing the HAL for one of my PIO uses because of that) and I'd like to get a quick gauge whether I'm heading the right way. Here's what I was planning to do:

  1. Add typestate to PIOBuilder which tracks the configuration.
  2. Add separate RxGet / RxPut / RxPutGet types which provide access to the "fifo" contents.
  3. Depending on the typestate, change the output types of build() to use the correct Rx* form as mentioned in point 2.

This will increase the complexity of the builder somewhat, but I think this is the only typesafe way of doing it.

While we're at it, we could also move the effect of the buffers() call into typestate, so that the return type of build() wouldn't contain a tx if the tx has been merged into the rx fifo, and vice versa.

Opinions / thoughts?

@horazont
Copy link
Contributor Author

horazont commented Jun 4, 2025

As far as I can tell, we can avoid adding extra typestate to the StateMachine, if we add typestate to Rx instead of making different types. Then the StateMachine::uninit call can just take any variant of Rx instead of having to keep track which kind of Rx the StateMachine has to consume on uninit.

@thejpster
Copy link
Member

Sounds reasonable on first glance.

What's the use case for random access?

@horazont
Copy link
Contributor Author

horazont commented Jun 5, 2025 via email

@thejpster
Copy link
Member

oh, nice.

@horazont
Copy link
Contributor Author

horazont commented Jun 5, 2025

Oha, looks like initial support for the feature was added in 8328792.

I would still consider the typestate method a valuable improvement. 8328792 does not introduce the necessary changes to the Rx struct and I don't think there's a safe way to do this without typestate.

(Also, we need to ensure that autopush is turned off, because that's UB with RxGet or RxPut enabled, according to 11.5.4 of the reference)

horazont added a commit to horazont/rp-hal that referenced this issue Jun 5, 2025
@horazont horazont linked a pull request Jun 5, 2025 that will close this issue
1 task
@horazont
Copy link
Contributor Author

horazont commented Jun 5, 2025

I opened #936, but there's an open question which we should discuss, preferably over there. It already works for my use case, but there's a few bits which need to be fixed.

I'd like to get some guidance on the open question before that, though :).

horazont added a commit to horazont/rp-hal that referenced this issue Jun 5, 2025
horazont added a commit to horazont/rp-hal that referenced this issue Jun 5, 2025
horazont added a commit to horazont/rp-hal that referenced this issue Jun 5, 2025
horazont added a commit to horazont/rp-hal that referenced this issue Jun 5, 2025
horazont added a commit to horazont/rp-hal that referenced this issue Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants