Skip to content

Commit

Permalink
beagleboard: now works on kernel 4.4+ of Debian
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Dec 3, 2016
1 parent 4c724bf commit fc2d98f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/beaglebone_blink_usr_led.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func main() {
beagleboneAdaptor := beaglebone.NewAdaptor()
led := gpio.NewLedDriver(beagleboneAdaptor, "usr0")
led := gpio.NewLedDriver(beagleboneAdaptor, "usr1")

work := func() {
gobot.Every(1*time.Second, func() {
Expand Down
4 changes: 2 additions & 2 deletions platforms/beaglebone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func main() {
Simply compile your Gobot program like this:

```bash
$ GOARM=7 GOARCH=arm GOOS=linux go build examples/beaglebone_blink.go
$ GOARCH=arm GOOS=linux go build examples/beaglebone_blink.go
```

If you are running the official Debian Linux through the usb->ethernet connection, or are connected to the board using WiFi, you can simply upload your program and execute it with the `scp` command like this:
Expand All @@ -72,7 +72,7 @@ Once you have created the SD card, boot your BeagleBone using the new image as f

- Insert SD card into your (powered-down) board, hold down the USER/BOOT button (if using Black) and apply power, either by the USB cable or 5V adapter.

- If using an original BeagleBone, you are done.
- If all you want to do it boot once from the SD card, it should now be booting.

- If using BeagleBone Black and desire to write the image to your on-board eMMC, you'll need to follow the instructions at http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#Flashing_eMMC. When the flashing is complete, all 4 USRx LEDs will be steady on or off. The latest Debian flasher images automatically power down the board upon completion. This can take up to 45 minutes. Power-down your board, remove the SD card and apply power again to be complete.

Expand Down
51 changes: 32 additions & 19 deletions platforms/beaglebone/beaglebone_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ var glob = func(pattern string) (matches []string, err error) {

// Adaptor is the gobot.Adaptor representation for the Beaglebone
type Adaptor struct {
name string
kernel string
digitalPins []sysfs.DigitalPin
pwmPins map[string]*pwmPin
i2cDevice sysfs.I2cDevice
usrLed string
ocp string
helper string
slots string
name string
kernel string
digitalPins []sysfs.DigitalPin
pwmPins map[string]*pwmPin
i2cDevice sysfs.I2cDevice
usrLed string
ocp string
analogPath string
analogPinMap map[string]string
slots string
}

// NewAdaptor returns a new Beaglebone Adaptor
Expand Down Expand Up @@ -74,19 +75,31 @@ func (b *Adaptor) Kernel() string { return b.kernel }

// Connect initializes the pwm and analog dts.
func (b *Adaptor) Connect() error {
if err := ensureSlot(b.slots, "cape-bone-iio"); err != nil {
return err
}
// enable analog
if b.kernel[:1] == "4" {
if err := ensureSlot(b.slots, "BB-ADC"); err != nil {
return err
}

if err := ensureSlot(b.slots, "am33xx_pwm"); err != nil {
return err
b.analogPath = "/sys/bus/iio/devices/iio:device0"
b.analogPinMap = analogPins44
} else {
if err := ensureSlot(b.slots, "cape-bone-iio"); err != nil {
return err
}

g, err := glob(fmt.Sprintf("%v/helper.*", b.ocp))
if err != nil {
return err
}
b.analogPath = g[0]
b.analogPinMap = analogPins3
}

g, err := glob(fmt.Sprintf("%v/helper.*", b.ocp))
if err != nil {
// enable pwm
if err := ensureSlot(b.slots, "am33xx_pwm"); err != nil {
return err
}
b.helper = g[0]

return nil
}
Expand Down Expand Up @@ -165,7 +178,7 @@ func (b *Adaptor) AnalogRead(pin string) (val int, err error) {
if err != nil {
return
}
fi, err := sysfs.OpenFile(fmt.Sprintf("%v/%v", b.helper, analogPin), os.O_RDONLY, 0644)
fi, err := sysfs.OpenFile(fmt.Sprintf("%v/%v", b.analogPath, analogPin), os.O_RDONLY, 0644)
defer fi.Close()

if err != nil {
Expand Down Expand Up @@ -233,7 +246,7 @@ func (b *Adaptor) translatePwmPin(pin string) (value string, err error) {

// translateAnalogPin converts analog pin name to pin position
func (b *Adaptor) translateAnalogPin(pin string) (value string, err error) {
for key, value := range analogPins {
for key, value := range b.analogPinMap {
if key == pin {
return value, nil
}
Expand Down
10 changes: 5 additions & 5 deletions platforms/beaglebone/beaglebone_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func TestBeagleboneAdaptor(t *testing.T) {
"/sys/devices/platform/bone_capemgr",
"/sys/devices/platform/ocp/ocp4",
"/sys/class/leds/beaglebone:green:usr1/brightness",
"/sys/devices/platform/ocp/ocp4/helper.5",
"/sys/devices/platform/ocp/ocp4/helper.5/AIN1",
"/sys/bus/iio/devices/iio:device0",
"/sys/bus/iio/devices/iio:device0/in_voltage1_raw",
"/sys/devices/platform/ocp/ocp4/pwm_test_P9_14.5",
"/sys/devices/platform/ocp/ocp4/pwm_test_P9_14.5/run",
"/sys/devices/platform/ocp/ocp4/pwm_test_P9_14.5/period",
Expand All @@ -79,7 +79,7 @@ func TestBeagleboneAdaptor(t *testing.T) {

a.Connect()

a.helper = "/sys/devices/platform/ocp/ocp4/helper.5"
a.analogPath = "/sys/bus/iio/devices/iio:device0"

// PWM
glob = func(pattern string) (matches []string, err error) {
Expand Down Expand Up @@ -113,11 +113,11 @@ func TestBeagleboneAdaptor(t *testing.T) {
)

// Analog
fs.Files["/sys/devices/platform/ocp/ocp4/helper.5/AIN1"].Contents = "567\n"
fs.Files["/sys/bus/iio/devices/iio:device0/in_voltage1_raw"].Contents = "567\n"
i, _ := a.AnalogRead("P9_40")
gobottest.Assert(t, i, 567)

i, err := a.AnalogRead("P9_99")
_, err := a.AnalogRead("P9_99")
gobottest.Assert(t, err, errors.New("Not a valid pin"))

// DigitalIO
Expand Down
12 changes: 11 additions & 1 deletion platforms/beaglebone/beaglebone_pins.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var pwmPins = map[string]string{
"P8_46": "P8_46",
}

var analogPins = map[string]string{
var analogPins3 = map[string]string{
"P9_39": "AIN0",
"P9_40": "AIN1",
"P9_37": "AIN2",
Expand All @@ -89,3 +89,13 @@ var analogPins = map[string]string{
"P9_36": "AIN5",
"P9_35": "AIN6",
}

var analogPins44 = map[string]string{
"P9_39": "in_voltage0_raw",
"P9_40": "in_voltage1_raw",
"P9_37": "in_voltage2_raw",
"P9_38": "in_voltage3_raw",
"P9_33": "in_voltage4_raw",
"P9_36": "in_voltage5_raw",
"P9_35": "in_voltage6_raw",
}

0 comments on commit fc2d98f

Please sign in to comment.