Skip to content

Conversation

burrbull
Copy link
Member

No description provided.

@usbalbin usbalbin changed the base branch from staged-pac to main April 28, 2025 21:05
@burrbull burrbull force-pushed the f4-gpio branch 3 times, most recently from e122258 to cd18012 Compare May 27, 2025 12:15
@burrbull burrbull mentioned this pull request May 27, 2025
@burrbull burrbull mentioned this pull request May 28, 2025
@burrbull burrbull force-pushed the f4-gpio branch 4 times, most recently from 5b40c21 to 83e5b28 Compare May 31, 2025 20:17
@burrbull burrbull marked this pull request as ready for review June 10, 2025 08:09
@burrbull
Copy link
Member Author

cc @usbalbin

Comment on lines -34 to +29
_tx: TX,
_rx: RX,
pins: (impl Into<Self::Tx>, impl Into<Self::Rx>),
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? Why a pair instead of two arguments?

pub struct Tx<USART: Instance, Dma, Otype = PushPull> {
pin: USART::Tx<Otype>,
pub struct Tx<USART: Instance, Dma = NoDMA, Otype = PushPull> {
pin: Option<USART::Tx<Otype>>,
Copy link
Member

Choose a reason for hiding this comment

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

This effectively makes this no longer a ZST? What is the advantage of the Option here as opposed to something like struct NoPin? Correct me if I am wrong but one disadvantage with Option is that you still have to specify the type even when passing None. That in my opinion defeats any ergonomics advantages vs just passing NoPin. Also there is not really any reduction in the amount of generic type parameters.

However I am still open to be convinced otherwise :)

Copy link
Member Author

Choose a reason for hiding this comment

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

This effectively makes this no longer a ZST?

This PR makes all alternate pins non-ZST as they are enums. If it is important to you to keep these structs a ZST than this PR is not for you.

Correct me if I am wrong but one disadvantage with Option is that you still have to specify the type even when passing None

Yes, this is issue. That is why I've added SPI1::NoMiso and friends in SpiExt trait. And alternative is to add None variant in each enum.

The reason of this PR is:

  1. You can keep pins inside structs and release with much less of generics (using associated types instead).
  2. Through Into you can pass gpioa.pa0 (Default on another Mode except another Alternate) instead of gpioa.pa0.into_alternate() (still allowed). In first case conversion will be done in .into() during peripheral initialization. In second case it will be done before peripheral initialization.

Saying about firmware size I don't see significant change in release mode. Although you should test it yourself if you interested in this PR.

@burrbull burrbull marked this pull request as draft June 10, 2025 19:22
use super::*;

pin! {
<Out> default:PushPull for [
Copy link
Member

Choose a reason for hiding this comment

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

Just to see if I am following here.

Here we create an enum Out which contains all the possible pins that can be used as output for this comparator. Then in the comparator we take a pin that implements Into<Out> which I assume all pins that have a corresponding enum variant do? Thanks to the enum we no longer need a type parameter for the pin type of peripherals that store the pin, which the comparator happens to not do. So in this case this should not incur any additional cost.

Just out curiosity how often do people actually need to be able to disable a peripheral and get back all pins etc? I have never felt the need. But that may very well be me missing some use case. If this functionality is indeed not needed then we do not need to store the pin and the peripheral should stay ZST(assuming nothing else needs to be stored), right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just out curiosity how often do people actually need to be able to disable a peripheral and get back all pins etc?

Not often. But sometimes people ask this functionality. I think it depends on peripheral.

should stay ZST

When you say "ZST" what features you mean except size of firmware?

Copy link
Member

Choose a reason for hiding this comment

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

I guess speed and size. Sorry, I have nothing more concrete in mind other than the feeling that there would be less for the optimizer to mess up(fail to optimize well) if there were simply nothing there to begin with. However I suppose the cost of a perhipheral having a size would probably only show when passing it around by value which I imagine is quite rare?

Sorry, my concern is likely completely moot. However on the of chance that it is not...

Not often. But sometimes people ask this functionality. I think it depends on peripheral.

Interesting

Copy link
Member Author

Choose a reason for hiding this comment

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

Usually it optimizes approximately the same. Sometimes even better. But tests are needed anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good

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