mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-07 16:33:39 +00:00
30 lines
530 B
Go
30 lines
530 B
Go
package onewire
|
|
|
|
import (
|
|
"machine"
|
|
|
|
"tinygo.org/x/drivers/internal/legacy"
|
|
)
|
|
|
|
// New creates a new GPIO 1-Wire connection.
|
|
// The pin must be pulled up to the VCC via a resistor greater than 500 ohms (default 4.7k).
|
|
func New(p machine.Pin) Device {
|
|
isOut := false
|
|
return Device{
|
|
set: func(level bool) {
|
|
if !isOut {
|
|
legacy.ConfigurePinOut(p)
|
|
isOut = true
|
|
}
|
|
p.Set(level)
|
|
},
|
|
get: func() (level bool) {
|
|
if isOut {
|
|
legacy.ConfigurePinInputPullup(p)
|
|
isOut = false
|
|
}
|
|
return p.Get()
|
|
},
|
|
}
|
|
}
|