Skip to content

add variant to reader #354

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

Merged
merged 4 commits into from
Jul 30, 2019
Merged

add variant to reader #354

merged 4 commits into from
Jul 30, 2019

Conversation

burrbull
Copy link
Member

r? @therealprof

Restore access to enum's by variant method that return enum FIELD when possible or Variant.

Also replace _to_bits method in writer with trait.
So now enums for reader and writer are identical (when they don't use different values for read and write) and can be replaced by one.

See #353 .

@burrbull burrbull requested a review from a team as a code owner July 30, 2019 05:54
@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools labels Jul 30, 2019
@burrbull
Copy link
Member Author

изображение

@@ -277,7 +277,7 @@ pub fn fields(
let pc_r = Ident::from(&*format!("{}R", pc));
let _pc_r = Ident::from(&*format!("{}_R", pc));
let pc_w = Ident::from(&*format!("{}W", pc));
let _pc_w = Ident::from(&*format!("_{}W", pc));
let _pc_w = Ident::from(&*format!("{}_W", pc));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh... It's a pity we didn't notice this earlier. But would you please remove it from this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.
Then
_pc_r => "_{}R" ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just remove the change from this PR and put it in a separate one.

@therealprof
Copy link
Contributor

Which file did you test it on? Don't seem to have a SVD file in reach which actually uses the changed parts.

@burrbull
Copy link
Member Author

burrbull commented Jul 30, 2019

from stm32-rs
For example LATENCY field: https://docs.rs/stm32f1/0.8.0/stm32f1/stm32f103/flash/acr/index.html

#[doc = r"Reader of the field"]
pub type LATENCY_R = crate::FR<u8, LATENCYR>;
impl LATENCY_R {
    #[doc = r"Enumerated values"]
    #[inline(always)]
    pub fn variant(&self) -> crate::Variant<u8, LATENCYR> {
        use crate::Variant::*;
        match self.bits() {
            0 => Val(LATENCYR::WS0),
            1 => Val(LATENCYR::WS1),
            2 => Val(LATENCYR::WS2),
            i => Res(i),
        }
    }
    #[doc = "Checks if the value of the field is `WS0`"]
    #[inline(always)]
    pub fn is_ws0(&self) -> bool {
        *self == LATENCYR::WS0
    }

@burrbull
Copy link
Member Author

I've moved identical code to add_from_variants and derive_from_base functions.

@therealprof
Copy link
Contributor

Hm, it's a pity I can't see the changes using the unmodified SVD files from cmsis-svd. Anyway, please add a CHANGELOG entry and we can land this.

@burrbull
Copy link
Member Author

Done.

Copy link
Contributor

@therealprof therealprof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@therealprof
Copy link
Contributor

bors r+

bors bot added a commit that referenced this pull request Jul 30, 2019
354: add variant to reader r=therealprof a=burrbull

r? @therealprof 

Restore access to `enum`'s by `variant` method that return `enum FIELD` when possible or `Variant`.

Also replace `_to_bits` method in writer with trait.
So now enums for reader and writer are identical (when they don't use different values for read and write) and can be replaced by one.

See #353 .

Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jul 30, 2019

Build succeeded

@bors bors bot merged commit e7d448e into rust-embedded:master Jul 30, 2019
@burrbull burrbull mentioned this pull request Jul 31, 2019
@burrbull burrbull deleted the reserved branch August 1, 2019 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants