Skip to content

Commit 0ddd583

Browse files
committed
inline set/clear_bit
1 parent 90e97c1 commit 0ddd583

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Manually inline set/clear_bit
1011
- Don't cast fields with width 17-31
1112
- Make `generic.rs` generic
1213
- Change initial write value for registers with modifiedWriteValues

src/generate/generic.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<REG: RegisterSpec, FI> PartialEq<FI> for R<REG>
270270
where
271271
REG::Ux: PartialEq,
272272
FI: Copy,
273-
REG::Ux: From<FI>
273+
REG::Ux: From<FI>,
274274
{
275275
#[inline(always)]
276276
fn eq(&self, other: &FI) -> bool {
@@ -512,8 +512,8 @@ macro_rules! impl_bit_proxy {
512512
/// Writes bit to the field
513513
#[inline(always)]
514514
pub fn bit(self, value: bool) -> &'a mut REG::Writer {
515-
self.w.bits &= !(U::one() << { OF });
516-
self.w.bits |= (U::from(value) & U::one()) << { OF };
515+
self.w.bits &= !(U::one() << OF);
516+
self.w.bits |= (U::from(value) & U::one()) << OF;
517517
self.w
518518
}
519519
/// Writes `variant` to the field
@@ -546,8 +546,8 @@ where
546546
/// Passing incorrect value can cause undefined behaviour. See reference manual
547547
#[inline(always)]
548548
pub unsafe fn bits(self, value: N) -> &'a mut REG::Writer {
549-
self.w.bits &= !(U::mask::<WI>() << { OF });
550-
self.w.bits |= (U::from(value) & U::mask::<WI>()) << { OF };
549+
self.w.bits &= !(U::mask::<WI>() << OF);
550+
self.w.bits |= (U::from(value) & U::mask::<WI>()) << OF;
551551
self.w
552552
}
553553
/// Writes `variant` to the field
@@ -565,8 +565,8 @@ where
565565
/// Writes raw bits to the field
566566
#[inline(always)]
567567
pub fn bits(self, value: N) -> &'a mut REG::Writer {
568-
self.w.bits &= !(U::mask::<WI>() << { OF });
569-
self.w.bits |= (U::from(value) & U::mask::<WI>()) << { OF };
568+
self.w.bits &= !(U::mask::<WI>() << OF);
569+
self.w.bits |= (U::from(value) & U::mask::<WI>()) << OF;
570570
self.w
571571
}
572572
/// Writes `variant` to the field
@@ -593,12 +593,14 @@ where
593593
/// Sets the field bit
594594
#[inline(always)]
595595
pub fn set_bit(self) -> &'a mut REG::Writer {
596-
self.bit(true)
596+
self.w.bits |= U::one() << OF;
597+
self.w
597598
}
598599
/// Clears the field bit
599600
#[inline(always)]
600601
pub fn clear_bit(self) -> &'a mut REG::Writer {
601-
self.bit(false)
602+
self.w.bits &= !(U::one() << OF);
603+
self.w
602604
}
603605
}
604606

@@ -611,7 +613,8 @@ where
611613
/// Sets the field bit
612614
#[inline(always)]
613615
pub fn set_bit(self) -> &'a mut REG::Writer {
614-
self.bit(true)
616+
self.w.bits |= U::one() << OF;
617+
self.w
615618
}
616619
}
617620

@@ -624,7 +627,8 @@ where
624627
/// Clears the field bit
625628
#[inline(always)]
626629
pub fn clear_bit(self) -> &'a mut REG::Writer {
627-
self.bit(false)
630+
self.w.bits &= !(U::one() << OF);
631+
self.w
628632
}
629633
}
630634

@@ -637,7 +641,8 @@ where
637641
///Clears the field bit by passing one
638642
#[inline(always)]
639643
pub fn clear_bit_by_one(self) -> &'a mut REG::Writer {
640-
self.bit(true)
644+
self.w.bits |= U::one() << OF;
645+
self.w
641646
}
642647
}
643648

@@ -650,7 +655,8 @@ where
650655
///Sets the field bit by passing zero
651656
#[inline(always)]
652657
pub fn set_bit_by_zero(self) -> &'a mut REG::Writer {
653-
self.bit(false)
658+
self.w.bits &= !(U::one() << OF);
659+
self.w
654660
}
655661
}
656662

@@ -663,7 +669,8 @@ where
663669
///Toggle the field bit by passing one
664670
#[inline(always)]
665671
pub fn toggle_bit(self) -> &'a mut REG::Writer {
666-
self.bit(true)
672+
self.w.bits |= U::one() << OF;
673+
self.w
667674
}
668675
}
669676

@@ -676,6 +683,7 @@ where
676683
///Toggle the field bit by passing zero
677684
#[inline(always)]
678685
pub fn toggle_bit(self) -> &'a mut REG::Writer {
679-
self.bit(false)
686+
self.w.bits &= !(U::one() << OF);
687+
self.w
680688
}
681689
}

0 commit comments

Comments
 (0)