-
Notifications
You must be signed in to change notification settings - Fork 994
Description
Currently, the machine package implements the methods Configure() and Set(). We need additional functionality in order to control the frequency and possibly other PWM settings per device. But because most devices have multiple channels per PWM, we really need a slightly different abstraction that would allow changing PWM settings separately from setting PWM channel outputs. See #855
Functionality we probably need:
- any initialization needed, depending on chip / board
- set frequency (possibly prescaler / bit rate settings?)
- configure an individual channel's output Pin
- set an individual channel's value
- ability to stop the PWM
Option A:
PWM could have the following functions:
Configure()SetFrequency(f int) errorConfigureChannel(num int, pin machine.Pin)SetChannel(num int, value uint16)Stop()
One variation would be to have configure look like this: Configure(pins []machine.Pin) error and not have a ConfigureChannel().
Option B:
Have separate PWM and PWMChannel structs. PWM could have:
Configure()SetFrequency(f int) errorChannel(num int) (PWMChannel, error)Stop()
and PWMChannel could have:
Configure(pin machine.Pin)Set(value uint16)
It would be somewhat painful to rewrite this for all the currently supported machines, but I think we need to do something in order to support servos and other hardware that uses PWMs. I would be happy to work on this if we can reach consensus. Thoughts?