Skip to content

fix(GPIO): Alternative Function numbers were inverted#543

Merged
FoniksFox merged 3 commits into
developmentfrom
fix/AF
Jan 21, 2026
Merged

fix(GPIO): Alternative Function numbers were inverted#543
FoniksFox merged 3 commits into
developmentfrom
fix/AF

Conversation

@FoniksFox
Copy link
Copy Markdown
Contributor

@FoniksFox FoniksFox commented Dec 25, 2025

Just what the title says + Make inscribes return std::size_t (the result of the add operation) so that they are easier to use from higher domains

Copilot AI review requested due to automatic review settings December 25, 2025 15:42
@FoniksFox FoniksFox marked this pull request as ready for review December 25, 2025 15:42

This comment was marked as spam.

@victor-Lopez25 victor-Lopez25 self-requested a review December 27, 2025 23:05
victor-Lopez25
victor-Lopez25 previously approved these changes Dec 27, 2025
Copy link
Copy Markdown
Contributor

@victor-Lopez25 victor-Lopez25 left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Contributor

@jorgesg82 jorgesg82 left a comment

Choose a reason for hiding this comment

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

They are not inverted I think. The AF0 is the LSB. Check the function valid_af:

inline constexpr bool valid_af(const AlternateFunction af) const {
  if (af == AlternateFunction::NO_AF)
    return true;
  return ((1 << static_cast<uint8_t>(af)) & afs) != 0;
}

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@FoniksFox
Copy link
Copy Markdown
Contributor Author

They are not inverted I think. The AF0 is the LSB. Check the function valid_af:

inline constexpr bool valid_af(const AlternateFunction af) const {
  if (af == AlternateFunction::NO_AF)
    return true;
  return ((1 << static_cast<uint8_t>(af)) & afs) != 0;
}

@jorgesg82

What I meant with inverted is with respect to the casting made in the build method, alternate functions have a 1 to 1 correspondence (AF10 == 10) so currently the casting doesn't interpret correctly the alternate function.
I didn't take into account the valid_af method, we should either invert the bitmaps, the valid_af method or leave it as it was before and only invert the AF in the cast...
Inverting the bitmaps in Pin.hpp would certainly be the better approach.
As for the AF10 being equal to 10 and so on, you can check it out in stm32h7xx_hal_gpio_ex.h (I think the general AF10 and so on were defined somewhere else, but I can't find where; either way, the _ex.h file is example enough).
You can also check PinModel/Pin.hpp (legacy Pin): the alternative functions are defined the same way I am doing here.

@FoniksFox FoniksFox marked this pull request as draft January 13, 2026 21:17
@jorgesg82
Copy link
Copy Markdown
Contributor

jorgesg82 commented Jan 15, 2026

From my point of view, the instantiated pins in Inc/HALAL/Models/Pin.hpp, the AlternateFunction enum, and the valid_af function match one with each other. I think the only thing that does NOT match with the rest is the cast in the build function, so changing that to match with the others will be the less disturbing fix, don't you think?

Otherwise you will have to invert the enum, to modify the valid_af function, and to change all the bitmaps (that would be for sure the most painful thing of them)

@FoniksFox
Copy link
Copy Markdown
Contributor Author

From my point of view, the instantiated pins in Inc/HALAL/Models/Pin.hpp, the AlternateFunction enum, and the valid_af function match one with each other. I think the only thing that does NOT match with the rest is the cast in the build function, so changing that to match with the others will be the less disturbing fix, don't you think?

Otherwise you will have to invert the enum, to modify the valid_af function, and to change all the bitmaps (that would be for sure the most painful thing of them)

Yeah, that's true, will do that, I'll also add a comment to the enum clarifying that

@FoniksFox FoniksFox marked this pull request as ready for review January 15, 2026 22:02
Copy link
Copy Markdown
Contributor

@victor-Lopez25 victor-Lopez25 left a comment

Choose a reason for hiding this comment

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

I like returning std::size_t in inscribe since it allows doing more interesting things elsewhere but remember to change the wiki for it

@FoniksFox
Copy link
Copy Markdown
Contributor Author

I like returning std::size_t in inscribe since it allows doing more interesting things elsewhere but remember to change the wiki for it

Yeah, will do the moment this pr is approved

Copy link
Copy Markdown
Contributor

@oganigl oganigl left a comment

Choose a reason for hiding this comment

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

It seems fine to me.

Copy link
Copy Markdown
Contributor

@oganigl oganigl left a comment

Choose a reason for hiding this comment

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

It seems fine to me.

@FoniksFox FoniksFox dismissed jorgesg82’s stale review January 21, 2026 17:03

Already implemented what was asked in the review exactly as it was requested

@FoniksFox FoniksFox merged commit 64ace7d into development Jan 21, 2026
13 checks passed
@jdmarmen jdmarmen deleted the fix/AF branch January 27, 2026 17:28
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.

5 participants