mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
a0c5da601f
Signed-off-by: deadprogram <ron@hybridgroup.com>
37 lines
839 B
Go
37 lines
839 B
Go
//go:build baremetal
|
|
|
|
package unoqmatrix
|
|
|
|
import (
|
|
"machine"
|
|
|
|
pin "tinygo.org/x/drivers/internal/pin"
|
|
)
|
|
|
|
// NewFromBasePin creates a Device from a base machine.Pin.
|
|
// It constructs 11 CharlieplexPin values from consecutive pins starting at basePin.
|
|
// Each pin lazily switches between output and input mode as needed.
|
|
func NewFromBasePin(basePin machine.Pin) Device {
|
|
var pins [numPins]CharlieplexPin
|
|
for i := range pins {
|
|
p := basePin + machine.Pin(i)
|
|
var isOutput bool
|
|
pins[i] = CharlieplexPin{
|
|
Set: pin.OutputFunc(func(level bool) {
|
|
if !isOutput {
|
|
p.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
isOutput = true
|
|
}
|
|
p.Set(level)
|
|
}),
|
|
Float: func() {
|
|
if isOutput {
|
|
p.Configure(machine.PinConfig{Mode: machine.PinInput})
|
|
isOutput = false
|
|
}
|
|
},
|
|
}
|
|
}
|
|
return New(pins)
|
|
}
|