@@ -3,7 +3,8 @@ use core::marker;
3
3
/// Raw register type (`u8`, `u16`, `u32`, ...)
4
4
pub trait RawReg :
5
5
Copy
6
- + Default
6
+ + ConstOne
7
+ + ConstZero
7
8
+ From < bool >
8
9
+ core:: ops:: BitOr < Output = Self >
9
10
+ core:: ops:: BitAnd < Output = Self >
@@ -14,8 +15,10 @@ pub trait RawReg:
14
15
{
15
16
/// Mask for bits of width `WI`
16
17
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 ;
19
22
}
20
23
21
24
macro_rules! raw_reg {
@@ -25,10 +28,8 @@ macro_rules! raw_reg {
25
28
fn mask<const WI : u8 >( ) -> Self {
26
29
$mask:: <WI >( )
27
30
}
28
- #[ inline( always) ]
29
- fn one( ) -> Self {
30
- 1
31
- }
31
+ const ZERO : Self = 0 ;
32
+ const ONE : Self = 1 ;
32
33
}
33
34
const fn $mask<const WI : u8 >( ) -> $U {
34
35
<$U>:: MAX >> ( $size - WI )
@@ -74,10 +75,10 @@ pub trait Writable: RegisterSpec {
74
75
type Safety ;
75
76
76
77
/// 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 ;
78
79
79
80
/// 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 ;
81
82
}
82
83
83
84
/// Reset value of the register.
@@ -86,7 +87,7 @@ pub trait Writable: RegisterSpec {
86
87
/// register by using the `reset` method.
87
88
pub trait Resettable : RegisterSpec {
88
89
/// Reset value of the register.
89
- const RESET_VALUE : Self :: Ux ;
90
+ const RESET_VALUE : Self :: Ux = Self :: Ux :: ZERO ;
90
91
91
92
/// Reset value of the register.
92
93
#[ inline( always) ]
@@ -247,7 +248,10 @@ impl<REG: Writable> W<REG> {
247
248
self
248
249
}
249
250
}
250
- impl < REG > W < REG > where REG : Writable < Safety = Safe > {
251
+ impl < REG > W < REG >
252
+ where
253
+ REG : Writable < Safety = Safe > ,
254
+ {
251
255
/// Writes raw bits to the register.
252
256
#[ inline( always) ]
253
257
pub fn set ( & mut self , bits : REG :: Ux ) -> & mut Self {
@@ -335,7 +339,8 @@ pub struct RangeFrom<const MIN: u64>;
335
339
pub struct RangeTo < const MAX : u64 > ;
336
340
337
341
/// 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 > ;
339
344
340
345
impl < REG , const WI : u8 , FI , Safety > FieldWriter < ' _ , REG , WI , FI , Safety >
341
346
where
@@ -390,7 +395,8 @@ where
390
395
}
391
396
}
392
397
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 > >
394
400
where
395
401
REG : Writable + RegisterSpec ,
396
402
FI : FieldSpec ,
@@ -478,7 +484,7 @@ macro_rules! bit_proxy {
478
484
pub const fn width( & self ) -> u8 {
479
485
Self :: WIDTH
480
486
}
481
-
487
+
482
488
/// Field offset
483
489
#[ inline( always) ]
484
490
pub const fn offset( & self ) -> u8 {
@@ -488,8 +494,8 @@ macro_rules! bit_proxy {
488
494
/// Writes bit to the field
489
495
#[ inline( always) ]
490
496
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;
493
499
self . w
494
500
}
495
501
/// Writes `variant` to the field
@@ -517,13 +523,13 @@ where
517
523
/// Sets the field bit
518
524
#[ inline( always) ]
519
525
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 ;
521
527
self . w
522
528
}
523
529
/// Clears the field bit
524
530
#[ inline( always) ]
525
531
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 ) ;
527
533
self . w
528
534
}
529
535
}
@@ -536,7 +542,7 @@ where
536
542
/// Sets the field bit
537
543
#[ inline( always) ]
538
544
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 ;
540
546
self . w
541
547
}
542
548
}
@@ -549,7 +555,7 @@ where
549
555
/// Clears the field bit
550
556
#[ inline( always) ]
551
557
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 ) ;
553
559
self . w
554
560
}
555
561
}
@@ -562,7 +568,7 @@ where
562
568
///Clears the field bit by passing one
563
569
#[ inline( always) ]
564
570
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 ;
566
572
self . w
567
573
}
568
574
}
@@ -575,7 +581,7 @@ where
575
581
///Sets the field bit by passing zero
576
582
#[ inline( always) ]
577
583
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 ) ;
579
585
self . w
580
586
}
581
587
}
@@ -588,7 +594,7 @@ where
588
594
///Toggle the field bit by passing one
589
595
#[ inline( always) ]
590
596
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 ;
592
598
self . w
593
599
}
594
600
}
@@ -601,7 +607,7 @@ where
601
607
///Toggle the field bit by passing zero
602
608
#[ inline( always) ]
603
609
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 ) ;
605
611
self . w
606
612
}
607
613
}
0 commit comments