Skip to content

Commit

Permalink
beaglebone: use universal io cape manager to initialize board setup
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Dec 19, 2017
1 parent 9323b6e commit 165a6f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
22 changes: 14 additions & 8 deletions platforms/beaglebone/beaglebone_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
},
}

Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions platforms/beaglebone/beaglebone_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 165a6f8

Please sign in to comment.