From 495d261bae1da70ff695c6ef2cc4314b2050af6a Mon Sep 17 00:00:00 2001 From: M-A Date: Fri, 18 Nov 2016 00:03:52 -0500 Subject: [PATCH] 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) --- devices/lirc/lirc.go | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/devices/lirc/lirc.go b/devices/lirc/lirc.go index 24e753c..134bf45 100644 --- a/devices/lirc/lirc.go +++ b/devices/lirc/lirc.go @@ -14,7 +14,6 @@ import ( "strings" "sync" - "github.com/google/periph" "github.com/google/periph/conn/gpio" "github.com/google/periph/conn/ir" ) @@ -215,33 +214,20 @@ func (d *driver) String() string { return "lirc" } -func (d *driver) Type() periph.Type { - // Return the lowest priority, which is Functional. - return periph.Functional -} - func (d *driver) Init() (bool, error) { in, out := getPins() if in == -1 && out == -1 { return false, nil } if in != -1 { - if pin := gpio.ByNumber(in); pin != nil { - gpio.MapFunction("IR_IN", pin) - } else { - gpio.MapFunction("IR_IN", gpio.INVALID) + if err := gpio.RegisterAlias("IR_IN", in); err != nil { + return true, err } - } else { - gpio.MapFunction("IR_IN", gpio.INVALID) } if out != -1 { - if pin := gpio.ByNumber(out); pin != nil { - gpio.MapFunction("IR_OUT", pin) - } else { - gpio.MapFunction("IR_OUT", gpio.INVALID) + if err := gpio.RegisterAlias("IR_OUT", out); err != nil { + return true, err } - } else { - gpio.MapFunction("IR_OUT", gpio.INVALID) } return true, nil }