Skip to content

Rename struct gpio_t to struct gpio to distinguish from gpio_t#1668

Merged
mossmann merged 1 commit intogreatscottgadgets:mainfrom
martinling:struct-gpio
Mar 4, 2026
Merged

Rename struct gpio_t to struct gpio to distinguish from gpio_t#1668
mossmann merged 1 commit intogreatscottgadgets:mainfrom
martinling:struct-gpio

Conversation

@martinling
Copy link
Copy Markdown
Member

We've been using gpio_t as both the name of a struct, and a typedef for a pointer to that struct.

In C that's possible because struct gpio_t names a different type from gpio_t , but it's confusing, and causes problems when trying to include the types elsewhere.

@martinling
Copy link
Copy Markdown
Member Author

@antoinevg This will conflict badly with your work in #1657, so if you'd rather include this change in that PR somehow, I can drop this one.

@antoinevg
Copy link
Copy Markdown
Member

@antoinevg This will conflict badly with your work in #1657, so if you'd rather include this change in that PR somehow, I can drop this one.

Thank you @martinling, good call!

Commit with the change is here for perusal and/or any feedback: fd6ab3b

@martinling
Copy link
Copy Markdown
Member Author

martinling commented Feb 9, 2026

@antoinevg You have the same problem in that commit, just with both types being named gpio instead of both named gpio_t. This causes problems when the code is used elsewhere, like:

firmware/common/gpio.h:28:30: error: conflicting declaration 'typedef const struct gpio_t* gpio_t'
   28 | typedef const struct gpio_t* gpio_t;
      |                              ^~~~~~
firmware/common/gpio.h:28:22: note: previous declaration as 'struct gpio_t'
   28 | typedef const struct gpio_t* gpio_t;
      |                      ^~~~~~

@antoinevg
Copy link
Copy Markdown
Member

Oh doh, it's worse than I thought… Tx!

Updated commit: 10710f0

@martinling
Copy link
Copy Markdown
Member Author

@antoinevg Yup that looks good. I'll close this one.

@martinling martinling closed this Feb 9, 2026
@antoinevg antoinevg reopened this Mar 3, 2026
@antoinevg antoinevg force-pushed the struct-gpio branch 2 times, most recently from 9c479d2 to 31e27c8 Compare March 3, 2026 07:18
@antoinevg
Copy link
Copy Markdown
Member

Re-opened and rebased against main.

Copy link
Copy Markdown
Member

@mossmann mossmann left a comment

Choose a reason for hiding this comment

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

@antoinevg It looks like there are some stragglers in ui_portapack.c that I think should be included.

@antoinevg
Copy link
Copy Markdown
Member

antoinevg commented Mar 4, 2026

We originally had two types sharing the name gpio_t:

  1. A struct called gpio_t
struct gpio {
    const uint32_t mask;
    gpio_port_t* const port;
    volatile uint32_t* const gpio_w;
};
  1. …and a typedef which represented a pointer to a const struct gpio_t:
typedef const struct gpio_t* gpio_t;

The struct has been renamed to gpio so now gpio_t only means a const pointer to a struct gpio:

struct gpio {
    const uint32_t mask;
    gpio_port_t* const port;
    volatile uint32_t* const gpio_w;
};

typedef const struct gpio* gpio_t;

The gpio_t's in portapack.c are meant to be const pointers to a struct gpio :-)

(See exchange between me and @martinling above for my shared initial confuzzlement)

@antoinevg antoinevg requested a review from mossmann March 4, 2026 05:39
Copy link
Copy Markdown
Member

@mossmann mossmann left a comment

Choose a reason for hiding this comment

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

Thank you both!

@mossmann mossmann merged commit ff6ce14 into greatscottgadgets:main Mar 4, 2026
77 of 79 checks passed
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.

3 participants