From 165a6f8798de83d991ae0367db2889ff699e3f5c Mon Sep 17 00:00:00 2001 From: deadprogram Date: Tue, 19 Dec 2017 12:03:41 +0100 Subject: [PATCH] beaglebone: use universal io cape manager to initialize board setup Signed-off-by: deadprogram --- platforms/beaglebone/beaglebone_adaptor.go | 22 ++++++++++++------- .../beaglebone/beaglebone_adaptor_test.go | 12 +++++----- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/platforms/beaglebone/beaglebone_adaptor.go b/platforms/beaglebone/beaglebone_adaptor.go index 6d2081fc..17173608 100644 --- a/platforms/beaglebone/beaglebone_adaptor.go +++ b/platforms/beaglebone/beaglebone_adaptor.go @@ -36,7 +36,7 @@ type Adaptor struct { pwmPinMap map[string]pwmPinData analogPinMap map[string]string mutex *sync.Mutex - findPin func(pinPath string) string + findPin func(pinPath string) (string, error) } // NewAdaptor returns a new Beaglebone Adaptor @@ -50,9 +50,9 @@ func NewAdaptor() *Adaptor { pinMap: bbbPinMap, pwmPinMap: bbbPwmPinMap, analogPinMap: bbbAnalogPinMap, - findPin: func(pinPath string) string { - files, _ := filepath.Glob(pinPath) - return files[0] + findPin: func(pinPath string) (string, error) { + files, err := filepath.Glob(pinPath) + return files[0], err }, } @@ -77,11 +77,15 @@ func (b *Adaptor) Connect() error { b.mutex.Lock() defer b.mutex.Unlock() - if err := ensureSlot(b.slots, "BB-ADC"); err != nil { + // loads U-Boot Cape Universal + // https://github.com/cdsteinkuehler/beaglebone-universal-io + if err := ensureSlot(b.slots, "cape-universaln"); err != nil { return err } - return nil + // loads U-Boot ADC + err := ensureSlot(b.slots, "BB-ADC") + return err } // Finalize releases all i2c devices and exported analog, digital, pwm pins. @@ -207,11 +211,13 @@ func (b *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) { if b.pwmPins[pin] == nil { newPin := sysfs.NewPWMPin(pinInfo.channel) - newPin.Path = b.findPin(pinInfo.path) - if err = muxPin(pin, "pwm"); err != nil { return } + + if newPin.Path, err = b.findPin(pinInfo.path); err != nil { + return + } if err = newPin.Export(); err != nil { return } diff --git a/platforms/beaglebone/beaglebone_adaptor_test.go b/platforms/beaglebone/beaglebone_adaptor_test.go index 2e8521ac..ae99114a 100644 --- a/platforms/beaglebone/beaglebone_adaptor_test.go +++ b/platforms/beaglebone/beaglebone_adaptor_test.go @@ -26,18 +26,18 @@ var _ i2c.Connector = (*Adaptor)(nil) func initBBBTestAdaptor() (*Adaptor, error) { a := NewAdaptor() - a.findPin = func(pinPath string) string { + a.findPin = func(pinPath string) (string, error) { switch pinPath { case "/sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip*": - return "/sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip4" + return "/sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip4", nil case "/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip*": - return "/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip2" + return "/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip2", nil case "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip*": - return "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0" + return "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0", nil case "/sys/devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip*": - return "/sys/devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip0" + return "/sys/devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip0", nil default: - return pinPath + return pinPath, nil } }