Skip to content

Commit 7f55145

Browse files
committed
BitAssign
1 parent ef010c6 commit 7f55145

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/generate/generic.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub trait RawReg:
66
+ Default
77
+ core::ops::BitOr<Output = Self>
88
+ core::ops::BitAnd<Output = Self>
9+
+ core::ops::BitOrAssign
10+
+ core::ops::BitAndAssign
911
+ core::ops::Not<Output = Self>
1012
+ core::ops::Shl<u8, Output = Self>
1113
{
@@ -30,7 +32,7 @@ macro_rules! raw_reg {
3032
const fn $mask<const WI: u8>() -> $U {
3133
<$U>::MAX >> ($size - WI)
3234
}
33-
}
35+
};
3436
}
3537

3638
raw_reg!(u8, 8, mask_u8);
@@ -507,8 +509,8 @@ macro_rules! impl_bit_proxy {
507509
/// Writes bit to the field
508510
#[inline(always)]
509511
pub fn bit(self, value: bool) -> &'a mut REG::Writer {
510-
self.w.bits = (self.w.bits & !(U::one() << { OF }))
511-
| ((U::from(value) & U::one()) << { OF });
512+
self.w.bits &= !(U::one() << { OF });
513+
self.w.bits |= (U::from(value) & U::one()) << { OF };
512514
self.w
513515
}
514516
/// Writes `variant` to the field
@@ -542,8 +544,8 @@ where
542544
/// Passing incorrect value can cause undefined behaviour. See reference manual
543545
#[inline(always)]
544546
pub unsafe fn bits(self, value: N) -> &'a mut REG::Writer {
545-
self.w.bits = (self.w.bits & !(U::mask::<WI>() << { OF }))
546-
| ((value.into() & U::mask::<WI>()) << { OF });
547+
self.w.bits &= !(U::mask::<WI>() << { OF });
548+
self.w.bits |= (value.into() & U::mask::<WI>()) << { OF };
547549
self.w
548550
}
549551
/// Writes `variant` to the field
@@ -552,7 +554,6 @@ where
552554
unsafe { self.bits(variant.into()) }
553555
}
554556
}
555-
556557
impl<'a, U, REG, N, FI, const WI: u8, const OF: u8> FieldWriterSafe<'a, U, REG, N, FI, WI, OF>
557558
where
558559
REG: Writable + RegisterSpec<Ux = U>,
@@ -563,8 +564,8 @@ where
563564
/// Writes raw bits to the field
564565
#[inline(always)]
565566
pub fn bits(self, value: N) -> &'a mut REG::Writer {
566-
self.w.bits = (self.w.bits & !(U::mask::<WI>() << { OF }))
567-
| ((value.into() & U::mask::<WI>()) << { OF });
567+
self.w.bits &= !(U::mask::<WI>() << { OF });
568+
self.w.bits |= (value.into() & U::mask::<WI>()) << { OF };
568569
self.w
569570
}
570571
/// Writes `variant` to the field

0 commit comments

Comments
 (0)