mirror of
https://github.com/kidoman/embd
synced 2025-07-03 03:47:33 +02:00
- add analog pin details to bbb descriptor
- pinMap lookups now honor pin capabilities
This commit is contained in:
parent
53e6c55378
commit
833ab3a472
4 changed files with 91 additions and 72 deletions
28
pin_test.go
28
pin_test.go
|
@ -5,25 +5,37 @@ import "testing"
|
|||
func TestPinMapLookup(t *testing.T) {
|
||||
var tests = []struct {
|
||||
key interface{}
|
||||
cap int
|
||||
id string
|
||||
}{
|
||||
{"10", "P1_1"},
|
||||
{10, "P1_1"},
|
||||
{"P1_2", "P1_2"},
|
||||
{"GPIO10", "P1_2"},
|
||||
{"10", CapAnalog, "P1_1"},
|
||||
{10, CapAnalog, "P1_1"},
|
||||
{"10", CapNormal, "P1_2"},
|
||||
{"P1_2", CapNormal, "P1_2"},
|
||||
{"P1_2", CapAnalog, "P1_2"},
|
||||
{"GPIO10", CapNormal, "P1_2"},
|
||||
}
|
||||
var pinMap = PinMap{
|
||||
&PinDesc{ID: "P1_1", Aliases: []string{"AN1", "10"}},
|
||||
&PinDesc{ID: "P1_2", Aliases: []string{"GPIO10"}},
|
||||
&PinDesc{ID: "P1_1", Aliases: []string{"AN1", "10"}, Caps: CapAnalog},
|
||||
&PinDesc{ID: "P1_2", Aliases: []string{"10", "GPIO10"}, Caps: CapNormal},
|
||||
}
|
||||
for _, test := range tests {
|
||||
pd, found := pinMap.Lookup(test.key)
|
||||
pd, found := pinMap.Lookup(test.key, test.cap)
|
||||
if !found {
|
||||
t.Errorf("Could not find a descriptor for %q", test.key)
|
||||
continue
|
||||
}
|
||||
if pd.ID != test.id {
|
||||
t.Errorf("Looking up %q: got %v, want %v", test.key, pd.ID, test.id)
|
||||
var capStr string
|
||||
switch test.cap {
|
||||
case CapNormal:
|
||||
capStr = "CapNormal"
|
||||
case CapAnalog:
|
||||
capStr = "CapAnalog"
|
||||
default:
|
||||
t.Fatalf("Unknown cap %v", test.cap)
|
||||
}
|
||||
t.Errorf("Looking up %q with %v: got %v, want %v", test.key, capStr, pd.ID, test.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue