Skip to content

Commit 1f2c1dd

Browse files
authored
pocketbeagle: introduce and use cdev by default (hybridgroup#1118)
1 parent ac0d59b commit 1f2c1dd

30 files changed

+431
-238
lines changed

MIGRATION.md

+26
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,32 @@ Also those findings needs to be replaced, which usually affects developers, but
4848
* `system.WithDigitalPinGpiodAccess()` --> `system.WithDigitalPinCdevAccess()`
4949
* `IsGpiodDigitalPinAccess()` --> `IsCdevDigitalPinAccess()`
5050

51+
### PocketBeagle adaptor goes cdev
52+
53+
The beagle board "PocketBeagle" supports with latest images the Linux Kernel character device API, so the adaptor was
54+
changed to use this as the default.
55+
56+
By "adaptors.WithSysfsAccess()" the old behavior can be forced. This is most likely needed if an old image with old
57+
Kernel is used which does not support this new API.
58+
59+
A small renaming is also done, please search and replace:
60+
61+
```go
62+
// old
63+
...
64+
"gobot.io/x/gobot/v2/platforms/beaglebone"
65+
...
66+
beaglebone.NewPocketBeagleAdaptor(...)
67+
...
68+
69+
// new
70+
...
71+
"gobot.io/x/gobot/v2/platforms/beagleboard/pocketbeagle"
72+
...
73+
pocketbeagle.NewAdaptor(...)
74+
...
75+
```
76+
5177
## Switch from version 2.3.0 (ble and sphero adaptors affected)
5278

5379
### BLE drivers and client adaptor

examples/beaglebone_basic_direct_pin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"fmt"
1111

1212
"gobot.io/x/gobot/v2/drivers/gpio"
13-
"gobot.io/x/gobot/v2/platforms/beaglebone"
13+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1414
)
1515

1616
func main() {

examples/beaglebone_blink.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"gobot.io/x/gobot/v2"
1414
"gobot.io/x/gobot/v2/drivers/gpio"
15-
"gobot.io/x/gobot/v2/platforms/beaglebone"
15+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1616
)
1717

1818
func main() {

examples/beaglebone_blink_usr_led.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"gobot.io/x/gobot/v2"
1414
"gobot.io/x/gobot/v2/drivers/gpio"
15-
"gobot.io/x/gobot/v2/platforms/beaglebone"
15+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1616
)
1717

1818
func main() {

examples/beaglebone_blinkm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"gobot.io/x/gobot/v2"
1414
"gobot.io/x/gobot/v2/drivers/i2c"
15-
"gobot.io/x/gobot/v2/platforms/beaglebone"
15+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1616
)
1717

1818
func main() {

examples/beaglebone_button.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"gobot.io/x/gobot/v2"
1313
"gobot.io/x/gobot/v2/drivers/gpio"
14-
"gobot.io/x/gobot/v2/platforms/beaglebone"
14+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1515
)
1616

1717
func main() {

examples/beaglebone_direct_pin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"gobot.io/x/gobot/v2"
1414
"gobot.io/x/gobot/v2/drivers/gpio"
15-
"gobot.io/x/gobot/v2/platforms/beaglebone"
15+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1616
)
1717

1818
func main() {

examples/beaglebone_grove_accelerometer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"gobot.io/x/gobot/v2"
1414
"gobot.io/x/gobot/v2/drivers/i2c"
15-
"gobot.io/x/gobot/v2/platforms/beaglebone"
15+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1616
)
1717

1818
func main() {

examples/beaglebone_led_brightness.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"gobot.io/x/gobot/v2"
1414
"gobot.io/x/gobot/v2/drivers/gpio"
15-
"gobot.io/x/gobot/v2/platforms/beaglebone"
15+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1616
)
1717

1818
func main() {

examples/beaglebone_led_brightness_with_analog_input.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"gobot.io/x/gobot/v2"
1414
"gobot.io/x/gobot/v2/drivers/aio"
1515
"gobot.io/x/gobot/v2/drivers/gpio"
16-
"gobot.io/x/gobot/v2/platforms/beaglebone"
16+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1717
)
1818

1919
func main() {

examples/beaglebone_servo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"gobot.io/x/gobot/v2"
1515
"gobot.io/x/gobot/v2/drivers/gpio"
16-
"gobot.io/x/gobot/v2/platforms/beaglebone"
16+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1717
)
1818

1919
func main() {

examples/beaglepocket_direct_pin.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"gobot.io/x/gobot/v2"
1414
"gobot.io/x/gobot/v2/drivers/gpio"
1515
"gobot.io/x/gobot/v2/platforms/adaptors"
16-
"gobot.io/x/gobot/v2/platforms/beaglebone"
16+
"gobot.io/x/gobot/v2/platforms/beagleboard/pocketbeagle"
1717
)
1818

1919
// Wiring
@@ -23,29 +23,37 @@ import (
2323
// LED's: the output pins are wired to the cathode of the LED, the anode is wired with a resistor (70-130Ohm for 20mA)
2424
// to VCC
2525
// Expected behavior: always one LED is on, the other in opposite state, if button is pressed the state changes
26+
// note: you can also use user LEDs, e.g. "usr0", "usr3"
2627
func main() {
2728
const (
2829
inPinNum = "P1_34"
2930
outPinNum = "P1_35"
3031
outPinInvertedNum = "P1_36"
3132
)
3233

33-
board := beaglebone.NewPocketBeagleAdaptor(adaptors.WithGpiosActiveLow(outPinInvertedNum))
34+
board := pocketbeagle.NewAdaptor(adaptors.WithGpiosActiveLow(outPinInvertedNum))
3435

3536
inPin := gpio.NewDirectPinDriver(board, inPinNum)
3637
outPin := gpio.NewDirectPinDriver(board, outPinNum)
3738
outPinInverted := gpio.NewDirectPinDriver(board, outPinInvertedNum)
3839

3940
work := func() {
41+
level := byte(1)
42+
4043
gobot.Every(500*time.Millisecond, func() {
4144
read, err := inPin.DigitalRead()
4245
fmt.Printf("pin %s state is %d\n", inPinNum, read)
4346
if err != nil {
4447
fmt.Println(err)
48+
if level == 1 {
49+
level = 0
50+
} else {
51+
level = 1
52+
}
53+
} else {
54+
level = byte(read)
4555
}
4656

47-
level := byte(read)
48-
4957
err = outPin.DigitalWrite(level)
5058
fmt.Printf("pin %s is now %d\n", outPinNum, level)
5159
if err != nil {

examples/nanopi_direct_pin.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func main() {
4949
fmt.Printf("pin %s state is %d\n", inPinNum, read)
5050
if err != nil {
5151
fmt.Println(err)
52+
if level == 1 {
53+
level = 0
54+
} else {
55+
level = 1
56+
}
5257
} else {
5358
level = byte(read)
5459
}
@@ -64,12 +69,6 @@ func main() {
6469
if err != nil {
6570
fmt.Println(err)
6671
}
67-
68-
if level == 1 {
69-
level = 0
70-
} else {
71-
level = 1
72-
}
7372
})
7473
}
7574

File renamed without changes.

platforms/beaglebone/README.md platforms/beagleboard/README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Beaglebone
1+
# BeagleBoard devices
22

33
The BeagleBone is an ARM based single board computer, with lots of GPIO, I2C, and analog interfaces built in.
44

@@ -35,12 +35,12 @@ import (
3535

3636
"gobot.io/x/gobot/v2"
3737
"gobot.io/x/gobot/v2/drivers/gpio"
38-
"gobot.io/x/gobot/v2/platforms/beaglebone"
38+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
3939
)
4040

4141
func main() {
42-
beagleboneAdaptor := beaglebone.NewAdaptor()
43-
led := gpio.NewLedDriver(beagleboneAdaptor, "P9_12")
42+
beagleBoneAdaptor := beaglebone.NewAdaptor()
43+
led := gpio.NewLedDriver(beagleBoneAdaptor, "P9_12")
4444

4545
work := func() {
4646
gobot.Every(1*time.Second, func() {
@@ -51,7 +51,7 @@ func main() {
5151
}
5252

5353
robot := gobot.NewRobot("blinkBot",
54-
[]gobot.Connection{beagleboneAdaptor},
54+
[]gobot.Connection{beagleBoneAdaptor},
5555
[]gobot.Device{led},
5656
work,
5757
)
@@ -62,7 +62,7 @@ func main() {
6262
}
6363
```
6464

65-
To use the PocketBeagle, use `beaglebone.NewPocketBeagleAdaptor()` like this:
65+
To use the PocketBeagle, use `pocketbeagle.NewAdaptor()` like this:
6666

6767
```go
6868
package main
@@ -72,12 +72,12 @@ import (
7272

7373
"gobot.io/x/gobot/v2"
7474
"gobot.io/x/gobot/v2/drivers/gpio"
75-
"gobot.io/x/gobot/v2/platforms/beaglebone"
75+
"gobot.io/x/gobot/v2/platforms/beagleboard/pocketbeagle"
7676
)
7777

7878
func main() {
79-
beagleboneAdaptor := beaglebone.NewPocketBeagleAdaptor()
80-
led := gpio.NewLedDriver(beagleboneAdaptor, "P1_02")
79+
pocketBeagleAdaptor := pocketbeagle.NewAdaptor()
80+
led := gpio.NewLedDriver(pocketBeagleAdaptor, "P1_02")
8181

8282
work := func() {
8383
gobot.Every(1*time.Second, func() {
@@ -88,7 +88,7 @@ func main() {
8888
}
8989

9090
robot := gobot.NewRobot("pocketBeagleBot",
91-
[]gobot.Connection{beagleboneAdaptor},
91+
[]gobot.Connection{pocketBeagleAdaptor},
9292
[]gobot.Device{led},
9393
work,
9494
)

platforms/beaglebone/beaglebone_adaptor.go platforms/beagleboard/beaglebone/beaglebone_adaptor.go

+23-20
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ type Adaptor struct {
3636
*adaptors.PWMPinsAdaptor
3737
*adaptors.I2cBusAdaptor
3838
*adaptors.SpiBusAdaptor
39-
usrLed string
40-
pinMap map[string]int
41-
pwmPinTranslate func(string) (string, int, error)
39+
usrLed string
4240
}
4341

4442
// NewAdaptor returns a new Beaglebone Black/Green Adaptor
@@ -53,12 +51,10 @@ func NewAdaptor(opts ...interface{}) *Adaptor {
5351
sys := system.NewAccesser(system.WithDigitalPinSysfsAccess())
5452
pwmPinTranslator := adaptors.NewPWMPinTranslator(sys, bbbPwmPinMap)
5553
a := &Adaptor{
56-
name: gobot.DefaultName("BeagleboneBlack"),
57-
sys: sys,
58-
mutex: &sync.Mutex{},
59-
pinMap: bbbPinMap,
60-
pwmPinTranslate: pwmPinTranslator.Translate,
61-
usrLed: "/sys/class/leds/beaglebone:green:",
54+
name: gobot.DefaultName("BeagleboneBlack"),
55+
sys: sys,
56+
mutex: &sync.Mutex{},
57+
usrLed: "/sys/class/leds/beaglebone:green:",
6258
}
6359

6460
var digitalPinsOpts []adaptors.DigitalPinsOptionApplier
@@ -69,6 +65,8 @@ func NewAdaptor(opts ...interface{}) *Adaptor {
6965
digitalPinsOpts = append(digitalPinsOpts, o)
7066
case adaptors.PwmPinsOptionApplier:
7167
pwmPinsOpts = append(pwmPinsOpts, o)
68+
case func(system.Optioner):
69+
o(sys)
7270
default:
7371
panic(fmt.Sprintf("'%s' can not be applied on adaptor '%s'", opt, a.name))
7472
}
@@ -83,7 +81,8 @@ func NewAdaptor(opts ...interface{}) *Adaptor {
8381

8482
a.AnalogPinsAdaptor = adaptors.NewAnalogPinsAdaptor(sys, analogPinTranslator.Translate)
8583
a.DigitalPinsAdaptor = adaptors.NewDigitalPinsAdaptor(sys, a.translateAndMuxDigitalPin, digitalPinsOpts...)
86-
a.PWMPinsAdaptor = adaptors.NewPWMPinsAdaptor(sys, a.translateAndMuxPWMPin, pwmPinsOpts...)
84+
a.PWMPinsAdaptor = adaptors.NewPWMPinsAdaptor(sys, a.getTranslateAndMuxPWMPinFunc(pwmPinTranslator.Translate),
85+
pwmPinsOpts...)
8786
a.I2cBusAdaptor = adaptors.NewI2cBusAdaptor(sys, i2cBusNumberValidator.Validate, defaultI2cBusNumber)
8887
a.SpiBusAdaptor = adaptors.NewSpiBusAdaptor(sys, spiBusNumberValidator.Validate, defaultSpiBusNumber,
8988
defaultSpiChipNumber, defaultSpiMode, defaultSpiBitsNumber, defaultSpiMaxSpeed)
@@ -165,7 +164,7 @@ func (a *Adaptor) DigitalWrite(id string, val byte) error {
165164

166165
// translatePin converts digital pin name to pin position
167166
func (a *Adaptor) translateAndMuxDigitalPin(id string) (string, int, error) {
168-
line, ok := a.pinMap[id]
167+
line, ok := bbbPinMap[id]
169168
if !ok {
170169
return "", -1, fmt.Errorf("'%s' is not a valid id for a digital pin", id)
171170
}
@@ -176,17 +175,21 @@ func (a *Adaptor) translateAndMuxDigitalPin(id string) (string, int, error) {
176175
return "", line, nil
177176
}
178177

179-
func (a *Adaptor) translateAndMuxPWMPin(id string) (string, int, error) {
180-
path, channel, err := a.pwmPinTranslate(id)
181-
if err != nil {
182-
return path, channel, err
183-
}
178+
func (a *Adaptor) getTranslateAndMuxPWMPinFunc(
179+
pwmPinTranslate func(id string) (string, int, error),
180+
) func(id string) (string, int, error) {
181+
return func(id string) (string, int, error) {
182+
path, channel, err := pwmPinTranslate(id)
183+
if err != nil {
184+
return path, channel, err
185+
}
184186

185-
if err := a.muxPin(id, "pwm"); err != nil {
186-
return "", -1, err
187-
}
187+
if err := a.muxPin(id, "pwm"); err != nil {
188+
return "", -1, err
189+
}
188190

189-
return path, channel, nil
191+
return path, channel, nil
192+
}
190193
}
191194

192195
func (a *Adaptor) muxPin(pin, cmd string) error {

platforms/beaglebone/beaglebone_adaptor_test.go platforms/beagleboard/beaglebone/beaglebone_adaptor_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ func TestNewAdaptor(t *testing.T) {
8989
assert.NotNil(t, a.PWMPinsAdaptor)
9090
assert.NotNil(t, a.I2cBusAdaptor)
9191
assert.NotNil(t, a.SpiBusAdaptor)
92-
assert.Equal(t, bbbPinMap, a.pinMap)
93-
assert.NotNil(t, a.pwmPinTranslate)
9492
assert.Equal(t, "/sys/class/leds/beaglebone:green:", a.usrLed)
9593
assert.True(t, a.sys.IsSysfsDigitalPinAccess())
9694
// act & assert
@@ -341,8 +339,10 @@ func Test_translateAndMuxPWMPin(t *testing.T) {
341339
// arrange
342340
muxPath := fmt.Sprintf("/sys/devices/platform/ocp/ocp:%s_pinmux/state", name)
343341
fs.Add(muxPath)
342+
pwmPinTranslator := adaptors.NewPWMPinTranslator(a.sys, bbbPwmPinMap)
343+
translateAndMuxPWMPin := a.getTranslateAndMuxPWMPinFunc(pwmPinTranslator.Translate)
344344
// act
345-
path, channel, err := a.translateAndMuxPWMPin(name)
345+
path, channel, err := translateAndMuxPWMPin(name)
346346
// assert
347347
assert.Equal(t, tc.wantErr, err)
348348
assert.Equal(t, tc.wantDir, path)

platforms/beaglebone/doc.go platforms/beagleboard/doc.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Package beaglebone provides the Gobot adaptor for the Beaglebone Black/Green, as well as a
2+
Package beagleboard provides the Gobot adaptor for the Beaglebone Black/Green, as well as a
33
separate Adaptor for the PocketBeagle.
44
55
Installing:
@@ -15,7 +15,7 @@ Example:
1515
1616
"gobot.io/x/gobot/v2"
1717
"gobot.io/x/gobot/v2/drivers/gpio"
18-
"gobot.io/x/gobot/v2/platforms/beaglebone"
18+
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
1919
)
2020
2121
func main() {
@@ -42,6 +42,6 @@ Example:
4242
}
4343
4444
For more information refer to the beaglebone README:
45-
https://github.com/hybridgroup/gobot/blob/release/platforms/beaglebone/README.md
45+
https://github.com/hybridgroup/gobot/blob/release/platforms/beagleboard/README.md
4646
*/
47-
package beaglebone // import "gobot.io/x/gobot/v2/platforms/beaglebone"
47+
package beagleboard // import "gobot.io/x/gobot/v2/platforms/beagleboard"

0 commit comments

Comments
 (0)