mirror of
https://github.com/kidoman/embd
synced 2025-07-03 11:57:38 +02:00
gpio: rename
This commit is contained in:
parent
833ab3a472
commit
d193c200ea
1 changed files with 0 additions and 0 deletions
|
@ -1,68 +0,0 @@
|
|||
package embd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
type pin interface {
|
||||
Close() error
|
||||
}
|
||||
|
||||
type gpioDriver struct {
|
||||
pinMap PinMap
|
||||
initializedPins map[string]pin
|
||||
}
|
||||
|
||||
func newGPIODriver(pinMap PinMap) *gpioDriver {
|
||||
return &gpioDriver{
|
||||
pinMap: pinMap,
|
||||
initializedPins: map[string]pin{},
|
||||
}
|
||||
}
|
||||
|
||||
func (io *gpioDriver) lookupKey(key interface{}, cap int) (*PinDesc, bool) {
|
||||
return io.pinMap.Lookup(key, cap)
|
||||
}
|
||||
|
||||
func (io *gpioDriver) digitalPin(key interface{}) (*digitalPin, error) {
|
||||
pd, found := io.lookupKey(key, CapNormal)
|
||||
if !found {
|
||||
return nil, fmt.Errorf("gpio: could not find pin matching %q", key)
|
||||
}
|
||||
|
||||
id := pd.ID
|
||||
|
||||
p, ok := io.initializedPins[id]
|
||||
if ok {
|
||||
dp, ok := p.(*digitalPin)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("gpio: sorry, pin %q is already initialized for a different mode", key)
|
||||
}
|
||||
return dp, nil
|
||||
}
|
||||
|
||||
if pd.Caps != CapNormal {
|
||||
glog.Infof("gpio: pin %q is not a dedicated digital io pin. please refer to the system reference manual for more details", key)
|
||||
}
|
||||
|
||||
dp := newDigitalPin(pd.DigitalLogical)
|
||||
io.initializedPins[id] = dp
|
||||
|
||||
return dp, nil
|
||||
}
|
||||
|
||||
func (io *gpioDriver) DigitalPin(key interface{}) (DigitalPin, error) {
|
||||
return io.digitalPin(key)
|
||||
}
|
||||
|
||||
func (io *gpioDriver) Close() error {
|
||||
for _, p := range io.initializedPins {
|
||||
if err := p.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue