mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 15:33:40 +00:00
machine: refactor PWM support
This commit refactors PWM support in the machine package to be more flexible. The new API can be used to produce tones at a specific frequency and control servos in a portable way, by abstracting over counter widths and prescalers.
This commit is contained in:
committed by
Ron Evans
parent
f880950c3e
commit
72acda22b0
@@ -0,0 +1,21 @@
|
||||
package machine
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrPWMPeriodTooLong = errors.New("pwm: period too long")
|
||||
)
|
||||
|
||||
// PWMConfig allows setting some configuration while configuring a PWM
|
||||
// peripheral. A zero PWMConfig is ready to use for simple applications such as
|
||||
// dimming LEDs.
|
||||
type PWMConfig struct {
|
||||
// PWM period in nanosecond. Leaving this zero will pick a reasonable period
|
||||
// value for use with LEDs.
|
||||
// If you want to configure a frequency instead of a period, you can use the
|
||||
// following formula to calculate a period from a frequency:
|
||||
//
|
||||
// period = 1e9 / frequency
|
||||
//
|
||||
Period uint64
|
||||
}
|
||||
Reference in New Issue
Block a user