repo: add support for sharing global values between host and device code #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a rough proof-of-concept for defining a set of
.toml
configuration files for values that need to be shared between host & device interfaces.Currently there are three files:
usb.toml
-- USB identifiers such asbVendorId
,bProductId
etc.libgreat.toml
-- endpoint addresses and vendor request numbers for thelibgreat
transport.registers.toml
-- TODO @martinling !While these files could be parsed using arbitrary mechanisms I've added a little bit of sugar for common use:
Python
The
cynthion.shared
sub-module provides a wrapper around the files which is provisioned at runtime using the built-intomllib
library:shared.py
Rust
The rust implementation uses the
static-toml
crate to provide a hand-rolled wrapper which is provisioned at compile-time:lib.rs
Limitations and Considerations
shared
rather thaninterfaces
to avoid confusion with the pre-existing usage of the word forpygreat
board definitions. (host/cynthion/board.py
/host/cynthion/interfaces/*
).toml
files would live in a top-level directory such ascynthion.git/shared/
instead of inside the cynthion host module but that'd make the module build process a pain.static
items, rather thanconst
. Which is somewhat of a pain if you want to define things like Enum values with it.static-toml
crate does horrible things to both numeric types and snake-cased section names. It's not that much effort to maintain a small sanity wrapper though so maybe it doesn't matter too much.Other approaches
I also futzed around a bit with the
uneval
crate which had some promise:https://gist.github.com/antoinevg/28bb9ddae8d6c8580b7e84a708113c8b
The main issues I ran into:
static-toml
and requires a fair amount of massaging to get it running onstd
andno_std
code.serde
which, until now, I'm rather proud of us NOT pulling in.