[draft] Re-organizing cargo features to support more devices#716
Closed
TethysSvensson wants to merge 1 commit intoatsamd-rs:masterfrom
Closed
[draft] Re-organizing cargo features to support more devices#716TethysSvensson wants to merge 1 commit intoatsamd-rs:masterfrom
TethysSvensson wants to merge 1 commit intoatsamd-rs:masterfrom
Conversation
456fa93 to
edfdaa8
Compare
Contributor
|
@TethysSvensson, @bradleyharden, you can find a very minimal proof of concept of what a custom proc-macro would look like here: https://github.com/jbeaurivage/atsamd/tree/proc-macro. I'm still in the process of discovering what we would and wouldn't be capable of doing. |
3 tasks
Contributor
|
Superseded by #728 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This is a draft PR, to open a discussion about how different variants of the same peripheral are organized in the code.
Motivation
Currently a most peripherals with more than one variant decides which variant to use based on the
thumbv6orthumbv7features.However, this approach does not work for devices such as the
l22, which is athumbv6device has peripherals that behave both like the thumbv6 and the thumbv7 variants. A few peripherals are even completely different from either of the two.Implementation
This draft PR proposes solving this problem by introducing more cargo flags for variant-implementations. In this PR I have converted
adc.rsandserial_number.rsfrom thethumbv6/thumbv7style to this alternative style.If you like this style of organizing the code, I am up for converting the entire
thumbv6/thumbv7hierarchy to this format.Alternatives
This use of cargo features is not really the intended one. It is somewhat cumbersome to make sure that the feature lists are both correct and complete. Currently the features are mostly used to decide which peripherals are present, and not as much which variant -- and even so the feature list is already unusually long.
One alternative solution would be to implement a proc-macro, which kept a list of all peripherals supported by each device, including which variant.
This proc-macro could be invoked as
#[hal_feature(serial-numbers)],#[hal_feature(serial-numbers-variant1)]or#[hal_feature(serial-numbers-variant1a)].This proc-macro would then expand to
#[cfg(any(feature = "device1", feature = "device2", ..))].