mirror of
https://github.com/kidoman/embd
synced 2025-07-03 03:47:33 +02:00
gpio: pwm support for bbb
This commit is contained in:
parent
8d9f991fb0
commit
14b078a43e
7 changed files with 329 additions and 28 deletions
|
@ -16,15 +16,17 @@ type gpioDriver struct {
|
|||
|
||||
dpf func(n int) DigitalPin
|
||||
apf func(n int) AnalogPin
|
||||
ppf func(n string) PWMPin
|
||||
|
||||
initializedPins map[string]pin
|
||||
}
|
||||
|
||||
func newGPIODriver(pinMap PinMap, dpf func(n int) DigitalPin, apf func(n int) AnalogPin) GPIODriver {
|
||||
func newGPIODriver(pinMap PinMap, dpf func(n int) DigitalPin, apf func(n int) AnalogPin, ppf func(n string) PWMPin) GPIODriver {
|
||||
return &gpioDriver{
|
||||
pinMap: pinMap,
|
||||
dpf: dpf,
|
||||
apf: apf,
|
||||
ppf: ppf,
|
||||
|
||||
initializedPins: map[string]pin{},
|
||||
}
|
||||
|
@ -62,6 +64,22 @@ func (io *gpioDriver) AnalogPin(key interface{}) (AnalogPin, error) {
|
|||
return p, nil
|
||||
}
|
||||
|
||||
func (io *gpioDriver) PWMPin(key interface{}) (PWMPin, error) {
|
||||
if io.ppf == nil {
|
||||
return nil, errors.New("gpio: pwm not supported on this host")
|
||||
}
|
||||
|
||||
pd, found := io.pinMap.Lookup(key, CapPWM)
|
||||
if !found {
|
||||
return nil, fmt.Errorf("gpio: could not find pin matching %v", key)
|
||||
}
|
||||
|
||||
p := io.ppf(pd.ID)
|
||||
io.initializedPins[pd.ID] = p
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (io *gpioDriver) Close() error {
|
||||
for _, p := range io.initializedPins {
|
||||
if err := p.Close(); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue