periph: Remove Type; gpio: improve pin registering (#48)

periph:
- Type was an approximation to enforce priority ordering. Remove the need for
  approximate ordering by improving gpio instead to support out-of-order pin
  registration. This has the side effect of increasing parallelism. This saved
  ~5ms on "gpio-list" runtime (out of 30ms) when run on a Raspberry Pi 3.

gpio:
- Redo RegisterAlias() to support out of order registration.
- Replace Functional() with Aliases(), which is much more generic.
- Unexport PinAlias, it is not necessary anymore.
- Improve error messages by wrapping the error, it helps legibility in case of
  errors.
- Remove Unregister(), it will be added back when there's an actual call site.
- Remove the (%d) number on sysfs-gpio and bcm283x since it wasn't useful.
- sysfs-gpio: Fix edge when switching output.
- consistently fix accumulated edged when calling sysfs.Pin.In().

lirc:
- Stop mapping IR_IN and IR_OUT when the pin is not mapped.

periph-smoketest:
- Fix to use host.Init(), otherwise drivers weren't correctly loaded.

Fixes #45
(I think)
pull/1/head
M-A 10 years ago committed by Thorsten von Eicken
parent 508e7b6b50
commit 495d261bae

@ -14,7 +14,6 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/google/periph"
"github.com/google/periph/conn/gpio" "github.com/google/periph/conn/gpio"
"github.com/google/periph/conn/ir" "github.com/google/periph/conn/ir"
) )
@ -215,33 +214,20 @@ func (d *driver) String() string {
return "lirc" return "lirc"
} }
func (d *driver) Type() periph.Type {
// Return the lowest priority, which is Functional.
return periph.Functional
}
func (d *driver) Init() (bool, error) { func (d *driver) Init() (bool, error) {
in, out := getPins() in, out := getPins()
if in == -1 && out == -1 { if in == -1 && out == -1 {
return false, nil return false, nil
} }
if in != -1 { if in != -1 {
if pin := gpio.ByNumber(in); pin != nil { if err := gpio.RegisterAlias("IR_IN", in); err != nil {
gpio.MapFunction("IR_IN", pin) return true, err
} else {
gpio.MapFunction("IR_IN", gpio.INVALID)
} }
} else {
gpio.MapFunction("IR_IN", gpio.INVALID)
} }
if out != -1 { if out != -1 {
if pin := gpio.ByNumber(out); pin != nil { if err := gpio.RegisterAlias("IR_OUT", out); err != nil {
gpio.MapFunction("IR_OUT", pin) return true, err
} else {
gpio.MapFunction("IR_OUT", gpio.INVALID)
} }
} else {
gpio.MapFunction("IR_OUT", gpio.INVALID)
} }
return true, nil return true, nil
} }

Loading…
Cancel
Save