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

Add SM as an associated type of ValidStateMachine in pio #729

Closed
wants to merge 1 commit into from

Conversation

Sympatron
Copy link
Contributor

Since some functions in the pio module expect a ValidStateMachine and some require (PIOExt, StateMachineIndex) it's difficult to write generic code without access to ValidStateMachine::SM. This PR fixes this.

@jannic
Copy link
Member

jannic commented Dec 23, 2023

Can you give a quick example where this is useful?
(Not a full example to be added to the repo, just a quick code snipped showing the use case.)

@Sympatron
Copy link
Contributor Author

Initially I tried to be generic over VSM: ValidStateMachine and use VSM::PIO and VSM::SM to get the the actual PIO and StateMachineIndex instance. But I ran into problems with PioBuilder::build() and changed my implementation to be generic over PIO: PioExt and SM: StateMachineIndex separately. So I don't need it anymore personally, but I still think it might be useful to have and it is not a breaking change, because all implementations of ValidStateMachine are defined in rp2040-hal anyway.

Btw I was working on a software serial implementation using PIO. You can find it here: https://github.com/Sympatron/pio-uart

@@ -453,6 +455,7 @@ pub type PIO1SM3 = (PIO1, SM3);

impl<P: PIOExt, SM: StateMachineIndex> ValidStateMachine for (P, SM) {
type PIO = P;
type SM = SM;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps call the type something like SMIdx? This type SM = SM looks a little bit strange, and SM isn't really referring to a specific state machine, only the full tuple (P, SM) does.

@Sympatron Sympatron closed this Oct 30, 2024
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 this pull request may close these issues.

2 participants