-
Notifications
You must be signed in to change notification settings - Fork 39
/
pin.go
83 lines (69 loc) · 1.87 KB
/
pin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package hwio
import (
"strings"
)
// Definitions relating to pins.
type PinIOMode int
// The modes for PinMode.
const (
INPUT PinIOMode = iota
OUTPUT
INPUT_PULLUP
INPUT_PULLDOWN
)
// String representation of pin IO mode
func (mode PinIOMode) String() string {
switch mode {
case INPUT:
return "INPUT"
case OUTPUT:
return "OUTPUT"
case INPUT_PULLUP:
return "INPUT_PULLUP"
case INPUT_PULLDOWN:
return "INPUT_PULLDOWN"
}
return ""
}
// Convenience constants for digital pin values.
const (
HIGH = 1
LOW = 0
)
type Pin int
type PinDef struct {
pin Pin // the pin, also in the map key of HardwarePinMap
names []string // a list of names for the pin as defined by Driver. There should be at least one. The first is the canonical name.
modules []string // a list of module names that can use this pin
}
type PinList []Pin
type HardwarePinMap map[Pin]*PinDef
// Add a pin to the map
func (m HardwarePinMap) Add(pin Pin, names []string, modules []string) {
m[pin] = &PinDef{pin, names, modules}
}
// Given a pin number, return it's PinDef, or nil if that pin is not defined in the map
func (m HardwarePinMap) GetPin(pin Pin) *PinDef {
return m[pin]
}
// Provide a string representation of a logic pin and the capabilties it
// supports.
func (pd *PinDef) String() string {
s := pd.Names() + " modules:" + strings.Join(pd.modules, ",")
return s
}
// From the hwPinRefs, construct a string by appending them together. Not brilliantly efficient,
// but its most for diagnostics anyway.
func (pd *PinDef) Names() string {
return strings.Join(pd.names, ",")
}
// // Determine if a pin has a particular capability.
// func (pd *PinDef) HasCapability(cap Capability) bool {
// // fmt.Printf("HasCap: checking (%s) has capability %s", pd.String(), cap.String())
// for _, v := range pd.capabilities {
// if v == cap {
// return true
// }
// }
// return false
// }