-
Notifications
You must be signed in to change notification settings - Fork 1
/
bank.go
64 lines (52 loc) · 1.75 KB
/
bank.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
// SPDX-FileCopyrightText: 2023 Kent Gibson <warthog618@gmail.com>
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
package gpiosim
// Bank contains the information required to configure a chip in a gpio-sim.
type Bank struct {
// The number of lines simulated by this bank/chip.
NumLines int
// The label of the chip.
Label string
// Lines assigned an identifying name.
//
// Line names do not need to be unique.
Names map[int]string
// Lines that appear to be already in use by some other entity.
Hogs map[int]Hog
}
// NewBank constructs a Bank with the label, numLines and options provided.
//
// The numLines is the number of lines to be simulated.
//
// The label is informational. It is returned in the uAPI ChipInfo and is
// intended to assist in identifying chips in the system.
// In a testing context the label can be used to identify the role of the chip
// in the test.
//
// The available options are [WithNamedLine] and [WithHoggedLine].
func NewBank(label string, numLines int, options ...NewBankOption) *Bank {
b := &Bank{Label: label, NumLines: numLines}
for _, o := range options {
o.applyBankOption(b)
}
return b
}
// Hog contains the details of a line hog, i.e. some other user of a line.
type Hog struct {
// The name of the consumer that appears to be using the line.
Consumer string
// The requested direction for the hogged line, and if an
// output then the direction of pull.
Direction HogDirection
}
// HogDirection indicates the direction of a hogged line.
type HogDirection int
const (
// Hogged line is requested as an input.
HogDirectionInput HogDirection = iota
// Hogged line is requested as an output pulled low.
HogDirectionOutputLow
// Hogged line is requested as an output pulled high.
HogDirectionOutputHigh
)