feature: some additional changes to drivers.Pin HAL for clarity and readability.

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2025-09-20 08:29:32 +02:00
parent 97ed81556b
commit d224b5d648
33 changed files with 139 additions and 171 deletions
+5 -5
View File
@@ -3,7 +3,7 @@ package legacy
import (
"errors"
"tinygo.org/x/drivers/internal/pin"
"tinygo.org/x/drivers"
)
// ConfigurePinOut is a legacy function used to configure pins as outputs.
@@ -11,7 +11,7 @@ import (
// Deprecated: Do not configure pins in drivers.
// This is a legacy feature and should only be used by drivers that
// previously configured pins in initialization to avoid breaking users.
func ConfigurePinOut(po pin.Output) {
func ConfigurePinOut(po drivers.PinOutput) {
configurePinOut(po)
}
@@ -20,7 +20,7 @@ func ConfigurePinOut(po pin.Output) {
// Deprecated: Do not configure pins in drivers.
// This is a legacy feature and should only be used by drivers that
// previously configured pins in initialization to avoid breaking users.
func ConfigurePinInputPulldown(pi pin.Input) {
func ConfigurePinInputPulldown(pi drivers.PinInput) {
configurePinInputPulldown(pi)
}
@@ -29,7 +29,7 @@ func ConfigurePinInputPulldown(pi pin.Input) {
// Deprecated: Do not configure pins in drivers.
// This is a legacy feature and should only be used by drivers that
// previously configured pins in initialization to avoid breaking users.
func ConfigurePinInput(pi pin.Input) {
func ConfigurePinInput(pi drivers.PinInput) {
configurePinInput(pi)
}
@@ -38,7 +38,7 @@ func ConfigurePinInput(pi pin.Input) {
// Deprecated: Do not configure pins in drivers.
// This is a legacy feature and should only be used by drivers that
// previously configured pins in initialization to avoid breaking users.
func ConfigurePinInputPullup(pi pin.Input) {
func ConfigurePinInputPullup(pi drivers.PinInput) {
configurePinInputPullup(pi)
}
+8 -6
View File
@@ -2,10 +2,12 @@
package legacy
import "tinygo.org/x/drivers/internal/pin"
import (
"tinygo.org/x/drivers"
)
func configurePinOut(p pin.Output) {}
func configurePinInput(p pin.Input) {}
func configurePinInputPulldown(p pin.Input) {}
func configurePinInputPullup(p pin.Input) {}
func pinIsNoPin(a any) bool { return false }
func configurePinOut(p drivers.PinOutput) {}
func configurePinInput(p drivers.PinInput) {}
func configurePinInputPulldown(p drivers.PinInput) {}
func configurePinInputPullup(p drivers.PinInput) {}
func pinIsNoPin(a any) bool { return false }
+5 -5
View File
@@ -5,22 +5,22 @@ package legacy
import (
"machine"
"tinygo.org/x/drivers/internal/pin"
"tinygo.org/x/drivers"
)
func configurePinOut(po pin.Output) {
func configurePinOut(po drivers.PinOutput) {
configurePin(po, machine.PinOutput)
}
func configurePinInputPulldown(pi pin.Input) {
func configurePinInputPulldown(pi drivers.PinInput) {
configurePin(pi, pulldown) // some chips do not have pull down, in which case pulldown==machine.PinInput.
}
func configurePinInput(pi pin.Input) {
func configurePinInput(pi drivers.PinInput) {
configurePin(pi, machine.PinInput)
}
func configurePinInputPullup(pi pin.Input) {
func configurePinInputPullup(pi drivers.PinInput) {
configurePin(pi, pullup) // some chips do not have pull up, in which case pullup==machine.PinInput.
}
-23
View File
@@ -1,23 +0,0 @@
package pin
import "tinygo.org/x/drivers"
// Here to aid relevant documentation links of [drivers.PinOutput] and [drivers.PinInput].
var _ drivers.PinOutput
// Output represents a pin hardware abstraction layer for a pin that can output a digital signal.
//
// This is an alternative to [drivers.PinOutput] abstraction which is a function type and has
// not been standardized as of yet as a standard HAL in the drivers package,
// [discussion ongoing here].
//
// [discussion ongoing here]: https://github.com/orgs/tinygo-org/discussions/5043
type Output interface {
Set(level bool)
}
// Input represents a pin hardware abstraction layer.
// See [Output] for more information on why this type exists separate to drivers.
type Input interface {
Get() (level bool)
}