more drivers are now cross platform

This commit is contained in:
soypat
2025-07-02 22:03:58 -03:00
committed by deadprogram
parent 7d3404f060
commit cd37668592
20 changed files with 481 additions and 325 deletions
+41 -2
View File
@@ -1,5 +1,7 @@
package legacy
import "errors"
// PinOutput 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. Pros and cons
// of both approaches have been discussed in the [relevant issue]. PinOutput should only be used
@@ -19,11 +21,48 @@ type PinOutput interface {
Set(level bool)
}
// PinInput represents a pin hardware abstraction layer. See [PinOutput] for
// more information on why this is "legacy".
type PinInput interface {
Get() (level bool)
}
// ConfigurePinOut is a legacy function used to configure pins as outputs.
//
// 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(p PinOutput) {
configurePinOut(p)
func ConfigurePinOut(po PinOutput) {
configurePinOut(po)
}
// ConfigurePinInput is a legacy function used to configure pins as inputs.
//
// 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 PinInput) {
configurePinInputPulldown(pi)
}
// ConfigurePinInput is a legacy function used to configure pins as inputs.
//
// 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 PinInput) {
configurePinInput(pi)
}
// ConfigurePinInput is a legacy function used to configure pins as inputs.
//
// 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 PinInput) {
configurePinInputPullup(pi)
}
var (
ErrConfigBeforeInstantiated = errors.New("device must be instantiated with New before calling Configure method")
)
+17 -1
View File
@@ -5,8 +5,24 @@ package legacy
import "machine"
func configurePinOut(p PinOutput) {
configurePin(p, machine.PinInputPulldown)
}
func configurePinInputPulldown(p PinInput) {
configurePin(p, machine.PinInputPulldown)
}
func configurePinInput(p PinInput) {
configurePin(p, machine.PinInput)
}
func configurePinInputPullup(p PinInput) {
configurePin(p, machine.PinInputPullup)
}
func configurePin(p any, mode machine.PinMode) {
machinePin, ok := p.(machine.Pin)
if ok {
machinePin.Configure(machine.PinConfig{Mode: machine.PinOutput})
machinePin.Configure(machine.PinConfig{Mode: mode})
}
}
+4 -1
View File
@@ -2,4 +2,7 @@
package legacy
func configurePinOut(p PinOutput) {}
func configurePinOut(p PinOutput) {}
func configurePinInput(p PinInput) {}
func configurePinInputPulldown(p PinInput) {}
func configurePinInputPullup(p PinInput) {}