-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[draft] Re-organizing using a proc-macro to support more devices #719
Conversation
f89c518
to
2ab11b3
Compare
@TethysSvensson, I took the time to review more in depth, I really like the approach you took here. Some more detailed comments, most of which are more or less suggestions:
atsamd_hal_macros::hal_module_mapping!(
pub adc,
["adc-d11", "adc-d21"] => "adc/d11.rs",
["adc-d5x"] => "adc/d5x.rs",
); and #[hal_cfgs("serial-numbers-d11", "serial-numbers-d21")]
My rationale is that we'll usually write these macro declarations only once, but many people will likely read them often. So it makes sense to make the code more readable at the expense of a few extra keystrokes. Thoughts? |
I agree. After porting most of the crate to use the proc-macros, I found it that even this macro was not enough. I also had to create a
Sounds good, I will do this next time I work on this. 👍
I think there are a few cases where this would make the code nicer, such as for
I agree completely. I originally did it like that, because I wanted to keep the proc-macro as small and simple as possible. However, after porting most of the crate, I realized that I needed more functionality in the proc-macro anyways, but I never re-examined the decision to keep it in a single string. I will definitely change this, the next time I work on this. |
After attempting to diff the before/after of introducing the macros, I found the following potential bug: #[hal_cfgs("pin-group-b")]
B, expands to #[cfg(any(
feature = "samd21el",
feature = "samd21g",
feature = "samd21gl",
feature = "samd21j",
feature = "samd51g",
feature = "samd51j",
feature = "samd51n",
feature = "samd51p",
feature = "same51g",
feature = "same51j",
feature = "same51n",
feature = "same53j",
feature = "same53n",
feature = "same54n",
feature = "same54p"
))]
B, Unless I misunderstand how pin groups work, shouldn't all chips have a pin group B? As it is now, pin group B starts at SAMD21EL. |
Hi and sorry for the lack of communication. I am still planning to clean this up a bit and turn it into a series of PRs (or alternatively one big PR if you prefer that). I've been quite busy the last few weeks with a new job, and I expect it to be at least another week or two until things calm down enough for me to take another look. If you're itching to get this merged to the main branch, feel free to take a look at my reorganization branch. If I remember correct, I have ported all of the code except for conditional docstrings to use macros instead of feature flags. |
And to answer your question: The samd11c, samd11d and samd21e only have |
Duh, I should've double checked the datasheet before talking too fast! Nothing to see here, carry on 😁 I've been thinking about how you added a |
I could also combine them, so you would have to do This would also allow you to do nested expressions if that ever turns out to be useful. |
Superseded by #728. |
Summary
This is a different variant of #716 with the same goals. Instead of introducing more cargo features, this one uses a proc-macro. I have ported the same two modules as in #716. If this way of organization is accepted, more modules could be ported in follow-up PRs.
This was partially inspired by the
proc-macro
branch made by @jbeaurivage, but works slightly differently.A few implementation details of note:
hal
.build.rs
file inside proc-macro to prevent having to read config files for each invocation of the macro.hal_module_mapping!()
macro to get around the problem of proc-macro-attributes not usable in as many locations as the#[cfg()]
macro.hal_code_mapping!()
macro that works in the same way as thehal_module_mapping!()
, but it was not needed for this example.