1
1
use core:: marker;
2
+ use num_traits:: { ConstOne , ConstZero } ;
2
3
3
4
/// Raw register type (`u8`, `u16`, `u32`, ...)
4
5
pub trait RawReg :
5
6
Copy
6
- + Default
7
+ + ConstOne
8
+ + ConstZero
7
9
+ From < bool >
8
10
+ core:: ops:: BitOr < Output = Self >
9
11
+ core:: ops:: BitAnd < Output = Self >
@@ -14,8 +16,6 @@ pub trait RawReg:
14
16
{
15
17
/// Mask for bits of width `WI`
16
18
fn mask < const WI : u8 > ( ) -> Self ;
17
- /// Mask for bits of width 1
18
- fn one ( ) -> Self ;
19
19
}
20
20
21
21
macro_rules! raw_reg {
@@ -25,10 +25,6 @@ macro_rules! raw_reg {
25
25
fn mask<const WI : u8 >( ) -> Self {
26
26
$mask:: <WI >( )
27
27
}
28
- #[ inline( always) ]
29
- fn one( ) -> Self {
30
- 1
31
- }
32
28
}
33
29
const fn $mask<const WI : u8 >( ) -> $U {
34
30
<$U>:: MAX >> ( $size - WI )
@@ -74,10 +70,10 @@ pub trait Writable: RegisterSpec {
74
70
type Safety ;
75
71
76
72
/// 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 ;
73
+ const ZERO_TO_MODIFY_FIELDS_BITMAP : Self :: Ux = Self :: Ux :: ZERO ;
78
74
79
75
/// 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 ;
76
+ const ONE_TO_MODIFY_FIELDS_BITMAP : Self :: Ux = Self :: Ux :: ZERO ;
81
77
}
82
78
83
79
/// Reset value of the register.
@@ -86,7 +82,7 @@ pub trait Writable: RegisterSpec {
86
82
/// register by using the `reset` method.
87
83
pub trait Resettable : RegisterSpec {
88
84
/// Reset value of the register.
89
- const RESET_VALUE : Self :: Ux ;
85
+ const RESET_VALUE : Self :: Ux = Self :: Ux :: ZERO ;
90
86
91
87
/// Reset value of the register.
92
88
#[ inline( always) ]
@@ -247,7 +243,10 @@ impl<REG: Writable> W<REG> {
247
243
self
248
244
}
249
245
}
250
- impl < REG > W < REG > where REG : Writable < Safety = Safe > {
246
+ impl < REG > W < REG >
247
+ where
248
+ REG : Writable < Safety = Safe > ,
249
+ {
251
250
/// Writes raw bits to the register.
252
251
#[ inline( always) ]
253
252
pub fn set ( & mut self , bits : REG :: Ux ) -> & mut Self {
@@ -335,7 +334,8 @@ pub struct RangeFrom<const MIN: u64>;
335
334
pub struct RangeTo < const MAX : u64 > ;
336
335
337
336
/// Write field Proxy
338
- pub type FieldWriter < ' a , REG , const WI : u8 , FI = u8 , Safety = Unsafe > = raw:: FieldWriter < ' a , REG , WI , FI , Safety > ;
337
+ pub type FieldWriter < ' a , REG , const WI : u8 , FI = u8 , Safety = Unsafe > =
338
+ raw:: FieldWriter < ' a , REG , WI , FI , Safety > ;
339
339
340
340
impl < REG , const WI : u8 , FI , Safety > FieldWriter < ' _ , REG , WI , FI , Safety >
341
341
where
@@ -390,7 +390,8 @@ where
390
390
}
391
391
}
392
392
393
- impl < ' a , REG , const WI : u8 , FI , const MIN : u64 , const MAX : u64 > FieldWriter < ' a , REG , WI , FI , Range < MIN , MAX > >
393
+ impl < ' a , REG , const WI : u8 , FI , const MIN : u64 , const MAX : u64 >
394
+ FieldWriter < ' a , REG , WI , FI , Range < MIN , MAX > >
394
395
where
395
396
REG : Writable + RegisterSpec ,
396
397
FI : FieldSpec ,
@@ -478,7 +479,7 @@ macro_rules! bit_proxy {
478
479
pub const fn width( & self ) -> u8 {
479
480
Self :: WIDTH
480
481
}
481
-
482
+
482
483
/// Field offset
483
484
#[ inline( always) ]
484
485
pub const fn offset( & self ) -> u8 {
@@ -488,8 +489,8 @@ macro_rules! bit_proxy {
488
489
/// Writes bit to the field
489
490
#[ inline( always) ]
490
491
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;
492
+ self . w. bits &= !( REG :: Ux :: ONE << self . o) ;
493
+ self . w. bits |= ( REG :: Ux :: from( value) & REG :: Ux :: ONE ) << self . o;
493
494
self . w
494
495
}
495
496
/// Writes `variant` to the field
@@ -517,13 +518,13 @@ where
517
518
/// Sets the field bit
518
519
#[ inline( always) ]
519
520
pub fn set_bit ( self ) -> & ' a mut W < REG > {
520
- self . w . bits |= REG :: Ux :: one ( ) << self . o ;
521
+ self . w . bits |= REG :: Ux :: ONE << self . o ;
521
522
self . w
522
523
}
523
524
/// Clears the field bit
524
525
#[ inline( always) ]
525
526
pub fn clear_bit ( self ) -> & ' a mut W < REG > {
526
- self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
527
+ self . w . bits &= !( REG :: Ux :: ONE << self . o ) ;
527
528
self . w
528
529
}
529
530
}
@@ -536,7 +537,7 @@ where
536
537
/// Sets the field bit
537
538
#[ inline( always) ]
538
539
pub fn set_bit ( self ) -> & ' a mut W < REG > {
539
- self . w . bits |= REG :: Ux :: one ( ) << self . o ;
540
+ self . w . bits |= REG :: Ux :: ONE << self . o ;
540
541
self . w
541
542
}
542
543
}
@@ -549,7 +550,7 @@ where
549
550
/// Clears the field bit
550
551
#[ inline( always) ]
551
552
pub fn clear_bit ( self ) -> & ' a mut W < REG > {
552
- self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
553
+ self . w . bits &= !( REG :: Ux :: ONE << self . o ) ;
553
554
self . w
554
555
}
555
556
}
@@ -562,7 +563,7 @@ where
562
563
///Clears the field bit by passing one
563
564
#[ inline( always) ]
564
565
pub fn clear_bit_by_one ( self ) -> & ' a mut W < REG > {
565
- self . w . bits |= REG :: Ux :: one ( ) << self . o ;
566
+ self . w . bits |= REG :: Ux :: ONE << self . o ;
566
567
self . w
567
568
}
568
569
}
@@ -575,7 +576,7 @@ where
575
576
///Sets the field bit by passing zero
576
577
#[ inline( always) ]
577
578
pub fn set_bit_by_zero ( self ) -> & ' a mut W < REG > {
578
- self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
579
+ self . w . bits &= !( REG :: Ux :: ONE << self . o ) ;
579
580
self . w
580
581
}
581
582
}
@@ -588,7 +589,7 @@ where
588
589
///Toggle the field bit by passing one
589
590
#[ inline( always) ]
590
591
pub fn toggle_bit ( self ) -> & ' a mut W < REG > {
591
- self . w . bits |= REG :: Ux :: one ( ) << self . o ;
592
+ self . w . bits |= REG :: Ux :: ONE << self . o ;
592
593
self . w
593
594
}
594
595
}
@@ -601,7 +602,7 @@ where
601
602
///Toggle the field bit by passing zero
602
603
#[ inline( always) ]
603
604
pub fn toggle_bit ( self ) -> & ' a mut W < REG > {
604
- self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
605
+ self . w . bits &= !( REG :: Ux :: ONE << self . o ) ;
605
606
self . w
606
607
}
607
608
}
0 commit comments