@@ -3,7 +3,8 @@ use core::marker;
33/// Raw register type (`u8`, `u16`, `u32`, ...)
44pub trait RawReg :
55 Copy
6- + Default
6+ + ConstOne
7+ + ConstZero
78 + From < bool >
89 + core:: ops:: BitOr < Output = Self >
910 + core:: ops:: BitAnd < Output = Self >
@@ -14,8 +15,10 @@ pub trait RawReg:
1415{
1516 /// Mask for bits of width `WI`
1617 fn mask < const WI : u8 > ( ) -> Self ;
17- /// Mask for bits of width 1
18- fn one ( ) -> Self ;
18+ /// `0`
19+ const ZERO : Self ;
20+ /// `1`
21+ const ONE : Self ;
1922}
2023
2124macro_rules! raw_reg {
@@ -25,10 +28,8 @@ macro_rules! raw_reg {
2528 fn mask<const WI : u8 >( ) -> Self {
2629 $mask:: <WI >( )
2730 }
28- #[ inline( always) ]
29- fn one( ) -> Self {
30- 1
31- }
31+ const ZERO : Self = 0 ;
32+ const ONE : Self = 1 ;
3233 }
3334 const fn $mask<const WI : u8 >( ) -> $U {
3435 <$U>:: MAX >> ( $size - WI )
@@ -74,10 +75,10 @@ pub trait Writable: RegisterSpec {
7475 type Safety ;
7576
7677 /// Specifies the register bits that are not changed if you pass `1` and are changed if you pass `0`
77- const ZERO_TO_MODIFY_FIELDS_BITMAP : Self :: Ux ;
78+ const ZERO_TO_MODIFY_FIELDS_BITMAP : Self :: Ux = Self :: Ux :: ZERO ;
7879
7980 /// Specifies the register bits that are not changed if you pass `0` and are changed if you pass `1`
80- const ONE_TO_MODIFY_FIELDS_BITMAP : Self :: Ux ;
81+ const ONE_TO_MODIFY_FIELDS_BITMAP : Self :: Ux = Self :: Ux :: ZERO ;
8182}
8283
8384/// Reset value of the register.
@@ -86,7 +87,7 @@ pub trait Writable: RegisterSpec {
8687/// register by using the `reset` method.
8788pub trait Resettable : RegisterSpec {
8889 /// Reset value of the register.
89- const RESET_VALUE : Self :: Ux ;
90+ const RESET_VALUE : Self :: Ux = Self :: Ux :: ZERO ;
9091
9192 /// Reset value of the register.
9293 #[ inline( always) ]
@@ -247,7 +248,10 @@ impl<REG: Writable> W<REG> {
247248 self
248249 }
249250}
250- impl < REG > W < REG > where REG : Writable < Safety = Safe > {
251+ impl < REG > W < REG >
252+ where
253+ REG : Writable < Safety = Safe > ,
254+ {
251255 /// Writes raw bits to the register.
252256 #[ inline( always) ]
253257 pub fn set ( & mut self , bits : REG :: Ux ) -> & mut Self {
@@ -335,7 +339,8 @@ pub struct RangeFrom<const MIN: u64>;
335339pub struct RangeTo < const MAX : u64 > ;
336340
337341/// Write field Proxy
338- pub type FieldWriter < ' a , REG , const WI : u8 , FI = u8 , Safety = Unsafe > = raw:: FieldWriter < ' a , REG , WI , FI , Safety > ;
342+ pub type FieldWriter < ' a , REG , const WI : u8 , FI = u8 , Safety = Unsafe > =
343+ raw:: FieldWriter < ' a , REG , WI , FI , Safety > ;
339344
340345impl < REG , const WI : u8 , FI , Safety > FieldWriter < ' _ , REG , WI , FI , Safety >
341346where
@@ -390,7 +395,8 @@ where
390395 }
391396}
392397
393- impl < ' a , REG , const WI : u8 , FI , const MIN : u64 , const MAX : u64 > FieldWriter < ' a , REG , WI , FI , Range < MIN , MAX > >
398+ impl < ' a , REG , const WI : u8 , FI , const MIN : u64 , const MAX : u64 >
399+ FieldWriter < ' a , REG , WI , FI , Range < MIN , MAX > >
394400where
395401 REG : Writable + RegisterSpec ,
396402 FI : FieldSpec ,
@@ -478,7 +484,7 @@ macro_rules! bit_proxy {
478484 pub const fn width( & self ) -> u8 {
479485 Self :: WIDTH
480486 }
481-
487+
482488 /// Field offset
483489 #[ inline( always) ]
484490 pub const fn offset( & self ) -> u8 {
@@ -488,8 +494,8 @@ macro_rules! bit_proxy {
488494 /// Writes bit to the field
489495 #[ inline( always) ]
490496 pub fn bit( self , value: bool ) -> & ' a mut W <REG > {
491- self . w. bits &= !( REG :: Ux :: one ( ) << self . o) ;
492- self . w. bits |= ( REG :: Ux :: from( value) & REG :: Ux :: one ( ) ) << self . o;
497+ self . w. bits &= !( REG :: Ux :: ONE << self . o) ;
498+ self . w. bits |= ( REG :: Ux :: from( value) & REG :: Ux :: ONE ) << self . o;
493499 self . w
494500 }
495501 /// Writes `variant` to the field
@@ -517,13 +523,13 @@ where
517523 /// Sets the field bit
518524 #[ inline( always) ]
519525 pub fn set_bit ( self ) -> & ' a mut W < REG > {
520- self . w . bits |= REG :: Ux :: one ( ) << self . o ;
526+ self . w . bits |= REG :: Ux :: ONE << self . o ;
521527 self . w
522528 }
523529 /// Clears the field bit
524530 #[ inline( always) ]
525531 pub fn clear_bit ( self ) -> & ' a mut W < REG > {
526- self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
532+ self . w . bits &= !( REG :: Ux :: ONE << self . o ) ;
527533 self . w
528534 }
529535}
@@ -536,7 +542,7 @@ where
536542 /// Sets the field bit
537543 #[ inline( always) ]
538544 pub fn set_bit ( self ) -> & ' a mut W < REG > {
539- self . w . bits |= REG :: Ux :: one ( ) << self . o ;
545+ self . w . bits |= REG :: Ux :: ONE << self . o ;
540546 self . w
541547 }
542548}
@@ -549,7 +555,7 @@ where
549555 /// Clears the field bit
550556 #[ inline( always) ]
551557 pub fn clear_bit ( self ) -> & ' a mut W < REG > {
552- self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
558+ self . w . bits &= !( REG :: Ux :: ONE << self . o ) ;
553559 self . w
554560 }
555561}
@@ -562,7 +568,7 @@ where
562568 ///Clears the field bit by passing one
563569 #[ inline( always) ]
564570 pub fn clear_bit_by_one ( self ) -> & ' a mut W < REG > {
565- self . w . bits |= REG :: Ux :: one ( ) << self . o ;
571+ self . w . bits |= REG :: Ux :: ONE << self . o ;
566572 self . w
567573 }
568574}
@@ -575,7 +581,7 @@ where
575581 ///Sets the field bit by passing zero
576582 #[ inline( always) ]
577583 pub fn set_bit_by_zero ( self ) -> & ' a mut W < REG > {
578- self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
584+ self . w . bits &= !( REG :: Ux :: ONE << self . o ) ;
579585 self . w
580586 }
581587}
@@ -588,7 +594,7 @@ where
588594 ///Toggle the field bit by passing one
589595 #[ inline( always) ]
590596 pub fn toggle_bit ( self ) -> & ' a mut W < REG > {
591- self . w . bits |= REG :: Ux :: one ( ) << self . o ;
597+ self . w . bits |= REG :: Ux :: ONE << self . o ;
592598 self . w
593599 }
594600}
@@ -601,7 +607,7 @@ where
601607 ///Toggle the field bit by passing zero
602608 #[ inline( always) ]
603609 pub fn toggle_bit ( self ) -> & ' a mut W < REG > {
604- self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
610+ self . w . bits &= !( REG :: Ux :: ONE << self . o ) ;
605611 self . w
606612 }
607613}
0 commit comments