stm32-rs / stm32f0xx-hal

A Rust `embedded-hal` implementation for all MCUs in the STM32 F0 family
BSD Zero Clause License
134 stars 59 forks source link

Improve API to allow having an array of Analog pins #154

Open pum-purum-pum-pum opened 2 years ago

pum-purum-pum-pum commented 2 years ago

It would be great to be able to store analog pins in the array and process them sequentially. If one needs to have multiple analog pins in the array it's not possible -- types are different and Channel trait has type-associated function.

Currently, Adc implements OneShot trait which accepts pin. https://github.com/stm32-rs/stm32f0xx-hal/blob/9f21c49001ebc841bac21759b11aaa632858057f/src/adc.rs#L604 The pin argument itself is not used, but the associated function of its type channel (which is the channel id) is used instead.

Perhaps we can change the function to fn channel(&self) but it might break some assumptions. Would be great to hear some input

newAM commented 2 years ago

Perhaps we can change the function to fn channel(&self) but it might break some assumptions.

That is one of the changes coming in the 1.0.0 release of embedded-hal: https://docs.rs/embedded-hal/1.0.0-alpha.7/embedded_hal/adc/nb/trait.Channel.html

Would be great to hear some input

Do you know of other STM32 HALs that have this feature? Maybe there's an elegant way to support the trait from the current stable version and the alpha?