Rahix / avr-hal

embedded-hal abstractions for AVR microcontrollers
Apache License 2.0
1.23k stars 216 forks source link

Enhance `avr_hal_generic::renamed_pins! {}` to also generate type aliases for each pin #558

Closed Rahix closed 3 weeks ago

Rahix commented 3 weeks ago

The renamed_pins! {} macro is used to generate a Pins struct where the pins can be identified by their names on a specific board. This is nice because users don't have to look up the pin mapping every time. The macro is used extensively in arduino-hal to name pins by their "board name" on each Arduino board.

However, when pins need to be referred to by their type, this abstraction breaks as there is no way to name a pin type by the board name right now. It would be great if the renamed_pins! {} macro could also create type aliases for each pin. Something like this:

// From this line:
//         pub a0: atmega_hal::port::PC0 = pc0,
pub type A0<MODE> = Pin<MODE, atmega_hal::port::PC0>;

//         pub d9: atmega_hal::port::PB1 = pb1,
pub type D9<MODE> = Pin<MODE, atmega_hal::port::PB1>;

CC: @LuigiPiucco, @djdisodo