Replies: 1 comment 4 replies
|
I guess you're trying to enforce the same API on all platforms, so the I suggest we do something based on interfaces rather than wrappers to avoid creating one more level of indirection. A interface GPIOPin {
func Set(high bool)
func Get() bool
func Low()
func High()
}
interface GPIOPinInterrupt {
func SetInterrupt(change PinChange, callback func(Pin)) error
}A var _ GPIOPin = (*Pin)(nil) |
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I'd like to discuss a design I really enjoy for creating HALs that are well documented and searchable with
go doc. This pattern where thepins_exported.go("header" file) can be applied throughout all embedded Go projects, example(s) below. The design consists of two categories of files, the "Header" files and the implementation files."Header" or HAL
The "Header" files contain ALL exported API. Ideally these do not have build tags. See Grove example for an example of a no-build-tag HAL that can compile on any target, including native Go.
Implementation
The implementation files contain unexported functions, including those wrapped by Header/HAL.
Example(s):
Why concrete type and not an
interface? (edited)We need concrete types for HAL definitions for the following reasons:
type PinOutput func(level bool)Why I want this
This would serve to better standardize APIs. If we have a "header" file then we don't have competing documentation and function signatures for the same method. Standardization is what the world's infrastructure is built on. This is extremely valuable.
It would allow trivial PR reviewing- if someone adds support for a new MCU it is trivial to know whether they implemented the functionality correctly at the API level (functionality may or may not be complete, but at least we guarantee that if it compiles it follows the TinyGo API.
Furthermore, this is an issue today! We have several broken APIs in TinyGo TODAY!! Several Configure methods on certain SPI implementations DO NOT CONFORM to the expected TinyGo API and will break for other targets. We wish to keep TinyGo compatible with all supported architectures since it completely feasible to do so. This proposal simplifies the path to API compliance between targets.
All reactions