Skip to content

Commit

Permalink
bcm283x: fix invalid aliasing; causing failure on RPi1 and RPi Zero
Browse files Browse the repository at this point in the history
The regression was introduced in
3d9b008, so version v3.2.0 up to v3.6.0
are affected.

Add smoketest to catch regressions. Manually tested on a RPi1 and RPiZW.

Fixes google#420
  • Loading branch information
maruel committed Aug 14, 2019
1 parent 77f8cb0 commit ebc08ac
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gohci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ workers:
- P1_15
- -pin2
- P1_16
- cmd:
- periph-smoketest
- bcm283x
- -quick
# Laptop on Windows 10.
- name: win10
checks:
Expand Down
65 changes: 64 additions & 1 deletion host/bcm283x/bcm283xsmoketest/bcm283xsmoketest.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"flag"
"fmt"
"reflect"
"regexp"
"time"

"periph.io/x/periph/conn/gpio"
"periph.io/x/periph/conn/gpio/gpioreg"
"periph.io/x/periph/conn/gpio/gpiostream"
"periph.io/x/periph/conn/physic"
"periph.io/x/periph/conn/pin"
Expand All @@ -35,11 +37,12 @@ func (s *SmokeTest) Name() string {

// Description implements the SmokeTest interface.
func (s *SmokeTest) Description() string {
return "Tests advanced bcm283x functionality"
return "Tests advanced bcm283x functionality with GPIO6 and GPIO13"
}

// Run implements the SmokeTest interface.
func (s *SmokeTest) Run(f *flag.FlagSet, args []string) error {
quick := f.Bool("quick", false, "Skip tests requiring DMA")
if err := f.Parse(args); err != nil {
return err
}
Expand All @@ -52,6 +55,13 @@ func (s *SmokeTest) Run(f *flag.FlagSet, args []string) error {
return errors.New("this smoke test can only be run on a bcm283x based host")
}

if err := testAliases(); err != nil {
return err
}
if *quick {
return nil
}

start := time.Now()
pClk := &loggingPin{bcm283x.GPIO6, start}
pPWM := &loggingPin{bcm283x.GPIO13, start}
Expand Down Expand Up @@ -231,6 +241,59 @@ func (s *SmokeTest) testStreamIn(p1, p2 *loggingPin) (err error) {

//

// testAliases catches unexpected GPIO aliases.
func testAliases() error {
expectedStr := []string{
`\d+`,
`GPIO\d+`,
`AUDIO_\d`,
`CLK\d`,
`GPCLK\d`,
`HDMI_\d`,
`I2C\d_SCL`,
`I2C\d_SDA`,
`I2S_DIN`,
`I2S_DOUT`,
`I2S_SCK`,
`I2S_WS`,
`P1_\d+`,
`P5_\d+`,
`PWM\d`,
`PWM\d_OUT`,
`SPI\d_CLK`,
`SPI\d_CS\d`,
`SPI\d_MISO`,
`SPI\d_MOSI`,
`UART\d_CTS`,
`UART\d_RTS`,
`UART\d_RX`,
`UART\d_TX`,
}
valid := make([]*regexp.Regexp, 0, len(expectedStr))
for i, v := range expectedStr {
r, err := regexp.Compile("^" + v + "$")
if err != nil {
return fmt.Errorf("Accepted #%d is invalid: %q", i, v)
}
valid = append(valid, r)
}

for _, p := range gpioreg.Aliases() {
n := p.Name()
ok := false
for _, r := range valid {
if r.MatchString(n) {
ok = true
break
}
}
if !ok {
return fmt.Errorf("Found unexpected alias %q", n)
}
}
return nil
}

func printPin(p gpio.PinIO) {
fmt.Printf("- %s: %s", p, p.Function())
if r, ok := p.(gpio.RealPin); ok {
Expand Down
2 changes: 1 addition & 1 deletion host/bcm283x/gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ func (d *driverGPIO) Init() (bool, error) {
return true, err
}
switch f := cpuPins[i].Func(); f {
case gpio.IN, gpio.OUT:
case gpio.IN, gpio.OUT, gpio.IN_LOW, gpio.IN_HIGH, gpio.OUT_LOW, gpio.OUT_HIGH, pin.FuncNone:
default:
// Registering the same alias twice fails. This can happen if two pins
// are configured with the same function. For example both pin #12, #18
Expand Down

0 comments on commit ebc08ac

Please sign in to comment.