Description
I started implementing PWM for this crate in two slightly different ways:
Approach one
https://github.com/stm32-rs/stm32f0xx-hal/tree/features/pwm
This uses the typical approach of initialising the PWM peripheral with the timer and pins to use for PWM. The code is loosely based on https://github.com/stm32-rs/stm32f1xx-hal/blob/master/src/pwm.rs and I can see a number of advantages and disadvantages with this.
Advantages:
- Prevents misconfigurations of timer, channel and GPIO combinations
Disadvantages:
- Does not allow using one channel for multiple GPIOs at once
- Earth shattering number of timer, channel and GPIO combinations need to be encoded
- Someone might want to use PWM without assigned GPIO which is not possible in the current design
Approach two
https://github.com/stm32-rs/stm32f0xx-hal/tree/features/pwm-alternate
This approach only binds the timer to provide 4 PWM channels without any association to a GPIO.
Advantages:
- Allows for much more flexible configuration of zero or more GPIOs per channel
Disadvantages:
- No sanity checking for correctly configured GPIO pins and channel relations
I'm a bit on the fence which variant we should go for. Approach one is rather limiting, especially if we want to support advanced uses of PWM (and maybe other nice timer features). It is also very complex to implement for all chips and all possible combinations at once. On the other hand it would be great to have a way of telling a user that some timer/channel/GPIO combination will not work or is incorrectly configured.
Ideas?
CC @zklapow