show how one-wire driver could be rewritten to use function HAL

This commit is contained in:
soypat
2025-10-13 18:23:21 -03:00
parent 3183013cbb
commit 293de2b61a
2 changed files with 51 additions and 16 deletions
+27
View File
@@ -0,0 +1,27 @@
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)
}
p.Set(level)
},
get: func() (level bool) {
if isOut {
legacy.ConfigurePinInputPullup(p)
}
return p.Get()
},
}
}