beaglebone: use glob to find variations of pwm for mappings
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
9bef0a45dd
commit
5952b7aab4
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -35,6 +36,7 @@ type Adaptor struct {
|
|||
pwmPinMap map[string]pwmPinData
|
||||
analogPinMap map[string]string
|
||||
mutex *sync.Mutex
|
||||
findPin func(pinPath string) string
|
||||
}
|
||||
|
||||
// NewAdaptor returns a new Beaglebone Adaptor
|
||||
|
@ -48,6 +50,10 @@ func NewAdaptor() *Adaptor {
|
|||
pinMap: bbbPinMap,
|
||||
pwmPinMap: bbbPwmPinMap,
|
||||
analogPinMap: bbbAnalogPinMap,
|
||||
findPin: func(pinPath string) string {
|
||||
files, _ := filepath.Glob(pinPath)
|
||||
return files[0]
|
||||
},
|
||||
}
|
||||
|
||||
b.setSlots()
|
||||
|
@ -201,7 +207,7 @@ func (b *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) {
|
|||
|
||||
if b.pwmPins[pin] == nil {
|
||||
newPin := sysfs.NewPWMPin(pinInfo.channel)
|
||||
newPin.Path = pinInfo.path
|
||||
newPin.Path = b.findPin(pinInfo.path)
|
||||
|
||||
if err = muxPin(pin, "pwm"); err != nil {
|
||||
return
|
||||
|
@ -212,9 +218,6 @@ func (b *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) {
|
|||
if err = newPin.SetPeriod(pwmDefaultPeriod); err != nil {
|
||||
return
|
||||
}
|
||||
// if err = newPin.InvertPolarity(false); err != nil {
|
||||
// return
|
||||
// }
|
||||
if err = newPin.Enable(true); err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -24,6 +24,28 @@ var _ sysfs.DigitalPinnerProvider = (*Adaptor)(nil)
|
|||
var _ sysfs.PWMPinnerProvider = (*Adaptor)(nil)
|
||||
var _ i2c.Connector = (*Adaptor)(nil)
|
||||
|
||||
func initBBBTestAdaptor() (*Adaptor, error) {
|
||||
a := NewAdaptor()
|
||||
a.findPin = func(pinPath string) string {
|
||||
switch pinPath {
|
||||
case "/sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip*":
|
||||
return "/sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip4"
|
||||
case "/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip*":
|
||||
return "/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip2"
|
||||
case "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip*":
|
||||
return "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0"
|
||||
case "/sys/devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip*":
|
||||
return "/sys/devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip0"
|
||||
default:
|
||||
return pinPath
|
||||
}
|
||||
}
|
||||
|
||||
err := a.Connect()
|
||||
|
||||
return a, err
|
||||
}
|
||||
|
||||
func TestBeagleboneAdaptor(t *testing.T) {
|
||||
fs := sysfs.NewMockFilesystem([]string{
|
||||
"/dev/i2c-2",
|
||||
|
@ -59,9 +81,8 @@ func TestBeagleboneAdaptor(t *testing.T) {
|
|||
})
|
||||
|
||||
sysfs.SetFilesystem(fs)
|
||||
a := NewAdaptor()
|
||||
|
||||
a.Connect()
|
||||
a, _ := initBBBTestAdaptor()
|
||||
|
||||
// PWM
|
||||
gobottest.Assert(t, a.PwmWrite("P9_99", 175), errors.New("Not a valid PWM pin"))
|
||||
|
@ -184,8 +205,7 @@ func TestBeagleboneConnectNoSlot(t *testing.T) {
|
|||
})
|
||||
sysfs.SetFilesystem(fs)
|
||||
|
||||
a := NewAdaptor()
|
||||
err := a.Connect()
|
||||
_, err := initBBBTestAdaptor()
|
||||
gobottest.Assert(t, strings.Contains(err.Error(), "/sys/devices/platform/bone_capemgr/slots: No such file."), true)
|
||||
}
|
||||
|
||||
|
@ -195,8 +215,7 @@ func TestBeagleboneAnalogReadFileError(t *testing.T) {
|
|||
})
|
||||
sysfs.SetFilesystem(fs)
|
||||
|
||||
a := NewAdaptor()
|
||||
a.Connect()
|
||||
a, _ := initBBBTestAdaptor()
|
||||
|
||||
_, err := a.AnalogRead("P9_40")
|
||||
gobottest.Assert(t, strings.Contains(err.Error(), "/sys/bus/iio/devices/iio:device0/in_voltage1_raw: No such file."), true)
|
||||
|
@ -211,8 +230,7 @@ func TestBeagleboneDigitalPinDirectionFileError(t *testing.T) {
|
|||
})
|
||||
sysfs.SetFilesystem(fs)
|
||||
|
||||
a := NewAdaptor()
|
||||
a.Connect()
|
||||
a, _ := initBBBTestAdaptor()
|
||||
|
||||
err := a.DigitalWrite("P9_12", 1)
|
||||
gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/gpio60/direction: No such file."), true)
|
||||
|
@ -231,8 +249,7 @@ func TestBeagleboneDigitalPinFinalizeFileError(t *testing.T) {
|
|||
})
|
||||
sysfs.SetFilesystem(fs)
|
||||
|
||||
a := NewAdaptor()
|
||||
a.Connect()
|
||||
a, _ := initBBBTestAdaptor()
|
||||
|
||||
err := a.DigitalWrite("P9_12", 1)
|
||||
gobottest.Assert(t, err, nil)
|
||||
|
|
|
@ -50,14 +50,14 @@ var bbbPinMap = map[string]int{
|
|||
}
|
||||
|
||||
var bbbPwmPinMap = map[string]pwmPinData{
|
||||
"P8_13": {path: "/sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip4", channel: 1},
|
||||
"P8_19": {path: "/sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip4", channel: 0},
|
||||
"P8_13": {path: "/sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip*", channel: 1},
|
||||
"P8_19": {path: "/sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip*", channel: 0},
|
||||
|
||||
"P9_14": {path: "/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip2", channel: 0},
|
||||
"P9_16": {path: "/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip2", channel: 1},
|
||||
"P9_21": {path: "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0", channel: 1},
|
||||
"P9_22": {path: "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0", channel: 0},
|
||||
"P9_42": {path: "/sys/devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip0", channel: 0},
|
||||
"P9_14": {path: "/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip*", channel: 0},
|
||||
"P9_16": {path: "/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip*", channel: 1},
|
||||
"P9_21": {path: "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip*", channel: 1},
|
||||
"P9_22": {path: "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip*", channel: 0},
|
||||
"P9_42": {path: "/sys/devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip*", channel: 0},
|
||||
}
|
||||
|
||||
var bbbAnalogPinMap = map[string]string{
|
||||
|
|
Loading…
Reference in New Issue