While doing some initial programming on stm32 (blue pill etc.) I've used example for blinky. Suppose I have a different board which has LED on a different pin and GPIO port. Since everything in stm32 HAL crates return structs with different types, how I can declare which port and pon to use when compiling on different board ?
Comming from C++ I'd just include header responsible for given board in which I'd define pin and ports. I can use cfg macro in rust but that's only half way done.
As you start to do more complex things, this kind of duplication can get annoying but in my experience it's usually possible to factor out the bits that are board specific so you don't have to duplicate as much stuff.
There are also traits in embedded-hal and in HAL crates that make it easy to generalize over pins in a zero-cost fashion without having to manually get all the types to align like we do above. For example:
Solves one problem. Which pin to use. However I still need to pass which pin (struct field) I want to use
gpioc
.pc9
.into_push_pull_output(&mut gpioc.crh)
As far as I know, there is no way to do it based on LedPin.
Correct me if I am wrong because it seems to me that I have to copy and paste code for each implementation. I have to hardcode each pin pin9 in each function along with it's method to get output. pin. Or use macros to generate this code.