apply suggestions from team

This commit is contained in:
soypat
2025-04-30 15:18:21 -03:00
committed by deadprogram
parent cf81c5ab02
commit 7d3404f060
9 changed files with 573 additions and 43 deletions
+29
View File
@@ -0,0 +1,29 @@
package legacy
// 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)
}
// 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)
}
+12
View File
@@ -0,0 +1,12 @@
//go:build baremetal
package legacy
import "machine"
func configurePinOut(p PinOutput) {
machinePin, ok := p.(machine.Pin)
if ok {
machinePin.Configure(machine.PinConfig{Mode: machine.PinOutput})
}
}
+5
View File
@@ -0,0 +1,5 @@
//go:build !baremetal
package legacy
func configurePinOut(p PinOutput) {}