@@ -56,6 +56,9 @@ pub trait FieldSpec: Sized {
56
56
type Ux : Copy + PartialEq + From < Self > ;
57
57
}
58
58
59
+ /// Marker for fields with fixed values
60
+ pub trait IsEnum : FieldSpec { }
61
+
59
62
/// Trait implemented by readable registers to enable the `read` method.
60
63
///
61
64
/// Registers marked with `Writable` can be also be `modify`'ed.
@@ -474,16 +477,13 @@ pub struct Safe;
474
477
/// You should check that value is allowed to pass to register/field writer marked with this
475
478
pub struct Unsafe ;
476
479
477
- /// Write field Proxy with unsafe `bits`
478
- pub type FieldWriter < ' a , REG , const WI : u8 , FI = u8 > = raw:: FieldWriter < ' a , REG , WI , FI , Unsafe > ;
479
- /// Write field Proxy with safe `bits`
480
- pub type FieldWriterSafe < ' a , REG , const WI : u8 , FI = u8 > = raw:: FieldWriter < ' a , REG , WI , FI , Safe > ;
480
+ /// Write field Proxy
481
+ pub type FieldWriter < ' a , REG , const WI : u8 , FI = u8 , Safety = Unsafe > = raw:: FieldWriter < ' a , REG , WI , FI , Safety > ;
481
482
482
- impl < ' a , REG , const WI : u8 , FI > FieldWriter < ' a , REG , WI , FI >
483
+ impl < ' a , REG , const WI : u8 , FI , Safety > FieldWriter < ' a , REG , WI , FI , Safety >
483
484
where
484
485
REG : Writable + RegisterSpec ,
485
486
FI : FieldSpec ,
486
- REG :: Ux : From < FI :: Ux > ,
487
487
{
488
488
/// Field width
489
489
pub const WIDTH : u8 = WI ;
@@ -499,7 +499,14 @@ where
499
499
pub const fn offset ( & self ) -> u8 {
500
500
self . o
501
501
}
502
+ }
502
503
504
+ impl < ' a , REG , const WI : u8 , FI , Safety > FieldWriter < ' a , REG , WI , FI , Safety >
505
+ where
506
+ REG : Writable + RegisterSpec ,
507
+ FI : FieldSpec ,
508
+ REG :: Ux : From < FI :: Ux > ,
509
+ {
503
510
/// Writes raw bits to the field
504
511
///
505
512
/// # Safety
@@ -511,45 +518,31 @@ where
511
518
self . w . bits |= ( REG :: Ux :: from ( value) & REG :: Ux :: mask :: < WI > ( ) ) << self . o ;
512
519
self . w
513
520
}
514
- /// Writes `variant` to the field
515
- #[ inline( always) ]
516
- pub fn variant ( self , variant : FI ) -> & ' a mut W < REG > {
517
- unsafe { self . bits ( FI :: Ux :: from ( variant) ) }
518
- }
519
521
}
520
522
521
- impl < ' a , REG , const WI : u8 , FI > FieldWriterSafe < ' a , REG , WI , FI >
523
+ impl < ' a , REG , const WI : u8 , FI > FieldWriter < ' a , REG , WI , FI , Safe >
522
524
where
523
525
REG : Writable + RegisterSpec ,
524
526
FI : FieldSpec ,
525
527
REG :: Ux : From < FI :: Ux > ,
526
528
{
527
- /// Field width
528
- pub const WIDTH : u8 = WI ;
529
-
530
- /// Field width
531
- #[ inline( always) ]
532
- pub const fn width ( & self ) -> u8 {
533
- WI
534
- }
535
-
536
- /// Field offset
537
- #[ inline( always) ]
538
- pub const fn offset ( & self ) -> u8 {
539
- self . o
540
- }
541
-
542
529
/// Writes raw bits to the field
543
530
#[ inline( always) ]
544
- pub fn bits ( self , value : FI :: Ux ) -> & ' a mut W < REG > {
545
- self . w . bits &= !( REG :: Ux :: mask :: < WI > ( ) << self . o ) ;
546
- self . w . bits |= ( REG :: Ux :: from ( value) & REG :: Ux :: mask :: < WI > ( ) ) << self . o ;
547
- self . w
531
+ pub fn set ( self , value : FI :: Ux ) -> & ' a mut W < REG > {
532
+ unsafe { self . bits ( value) }
548
533
}
534
+ }
535
+
536
+ impl < ' a , REG , const WI : u8 , FI , Safety > FieldWriter < ' a , REG , WI , FI , Safety >
537
+ where
538
+ REG : Writable + RegisterSpec ,
539
+ FI : IsEnum ,
540
+ REG :: Ux : From < FI :: Ux > ,
541
+ {
549
542
/// Writes `variant` to the field
550
543
#[ inline( always) ]
551
544
pub fn variant ( self , variant : FI ) -> & ' a mut W < REG > {
552
- self . bits ( FI :: Ux :: from ( variant) )
545
+ unsafe { self . bits ( FI :: Ux :: from ( variant) ) }
553
546
}
554
547
}
555
548
0 commit comments