mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-08 08:53:40 +00:00
legacy.PinOutput->pin.Output and add High+Low methods on drivers.PinOutput and use them in drivers
This commit is contained in:
committed by
deadprogram
parent
2e007a6de7
commit
8ac285e821
@@ -1,38 +1,17 @@
|
||||
package legacy
|
||||
|
||||
import "errors"
|
||||
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
|
||||
// to expose an initialization function of a driver that receives pins of this type. Ideally
|
||||
// driver developers should also expose the initialization with drivers.Pin type:
|
||||
//
|
||||
// func New(p1, p2, p3 legacy.PinOutput) *Device {
|
||||
// return NewWithPinfuncs(p1.Set, p2.Set, p3.Set)
|
||||
// }
|
||||
//
|
||||
// func NewWithPinfuncs(p1, p2, p3 drivers.PinOutput) *Device {
|
||||
// return &Device{p1:p1, p2:p2, p3:p3}
|
||||
// }
|
||||
//
|
||||
// [relevant issue]: https://github.com/tinygo-org/drivers/pull/749/files
|
||||
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)
|
||||
}
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
// 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(po PinOutput) {
|
||||
func ConfigurePinOut(po pin.Output) {
|
||||
configurePinOut(po)
|
||||
}
|
||||
|
||||
@@ -41,7 +20,7 @@ func ConfigurePinOut(po PinOutput) {
|
||||
// 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) {
|
||||
func ConfigurePinInputPulldown(pi pin.Input) {
|
||||
configurePinInputPulldown(pi)
|
||||
}
|
||||
|
||||
@@ -50,7 +29,7 @@ func ConfigurePinInputPulldown(pi PinInput) {
|
||||
// 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) {
|
||||
func ConfigurePinInput(pi pin.Input) {
|
||||
configurePinInput(pi)
|
||||
}
|
||||
|
||||
@@ -59,7 +38,7 @@ func ConfigurePinInput(pi PinInput) {
|
||||
// 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) {
|
||||
func ConfigurePinInputPullup(pi pin.Input) {
|
||||
configurePinInputPullup(pi)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
package legacy
|
||||
|
||||
func configurePinOut(p PinOutput) {}
|
||||
func configurePinInput(p PinInput) {}
|
||||
func configurePinInputPulldown(p PinInput) {}
|
||||
func configurePinInputPullup(p PinInput) {}
|
||||
func pinIsNoPin(a any) bool { return false }
|
||||
import "tinygo.org/x/drivers/internal/pin"
|
||||
|
||||
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 }
|
||||
|
||||
@@ -2,22 +2,26 @@
|
||||
|
||||
package legacy
|
||||
|
||||
import "machine"
|
||||
import (
|
||||
"machine"
|
||||
|
||||
func configurePinOut(p PinOutput) {
|
||||
configurePin(p, machine.PinOutput)
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
func configurePinOut(po pin.Output) {
|
||||
configurePin(po, machine.PinOutput)
|
||||
}
|
||||
|
||||
func configurePinInputPulldown(p PinInput) {
|
||||
configurePin(p, pulldown) // some chips do not have pull down, in which case pulldown==machine.PinInput.
|
||||
func configurePinInputPulldown(pi pin.Input) {
|
||||
configurePin(pi, pulldown) // some chips do not have pull down, in which case pulldown==machine.PinInput.
|
||||
}
|
||||
|
||||
func configurePinInput(p PinInput) {
|
||||
configurePin(p, machine.PinInput)
|
||||
func configurePinInput(pi pin.Input) {
|
||||
configurePin(pi, machine.PinInput)
|
||||
}
|
||||
|
||||
func configurePinInputPullup(p PinInput) {
|
||||
configurePin(p, pullup) // some chips do not have pull up, in which case pullup==machine.PinInput.
|
||||
func configurePinInputPullup(pi pin.Input) {
|
||||
configurePin(pi, pullup) // some chips do not have pull up, in which case pullup==machine.PinInput.
|
||||
}
|
||||
|
||||
func pinIsNoPin(a any) bool {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user