@@ -304,51 +304,55 @@ pub mod raw {
304
304
}
305
305
}
306
306
307
- pub struct FieldWriter < ' a , REG , const WI : u8 , const O : u8 , FI = u8 , Safety = Unsafe >
307
+ pub struct FieldWriter < ' a , REG , const WI : u8 , FI = u8 , Safety = Unsafe >
308
308
where
309
309
REG : Writable + RegisterSpec ,
310
310
FI : FieldSpec ,
311
311
{
312
312
pub ( crate ) w : & ' a mut W < REG > ,
313
+ pub ( crate ) o : u8 ,
313
314
_field : marker:: PhantomData < ( FI , Safety ) > ,
314
315
}
315
316
316
- impl < ' a , REG , const WI : u8 , const O : u8 , FI , Safety > FieldWriter < ' a , REG , WI , O , FI , Safety >
317
+ impl < ' a , REG , const WI : u8 , FI , Safety > FieldWriter < ' a , REG , WI , FI , Safety >
317
318
where
318
319
REG : Writable + RegisterSpec ,
319
320
FI : FieldSpec ,
320
321
{
321
322
/// Creates a new instance of the writer
322
323
#[ allow( unused) ]
323
324
#[ inline( always) ]
324
- pub ( crate ) fn new ( w : & ' a mut W < REG > ) -> Self {
325
+ pub ( crate ) fn new ( w : & ' a mut W < REG > , o : u8 ) -> Self {
325
326
Self {
326
327
w,
328
+ o,
327
329
_field : marker:: PhantomData ,
328
330
}
329
331
}
330
332
}
331
333
332
- pub struct BitWriter < ' a , REG , const O : u8 , FI = bool , M = BitM >
334
+ pub struct BitWriter < ' a , REG , FI = bool , M = BitM >
333
335
where
334
336
REG : Writable + RegisterSpec ,
335
337
bool : From < FI > ,
336
338
{
337
339
pub ( crate ) w : & ' a mut W < REG > ,
340
+ pub ( crate ) o : u8 ,
338
341
_field : marker:: PhantomData < ( FI , M ) > ,
339
342
}
340
343
341
- impl < ' a , REG , const O : u8 , FI , M > BitWriter < ' a , REG , O , FI , M >
344
+ impl < ' a , REG , FI , M > BitWriter < ' a , REG , FI , M >
342
345
where
343
346
REG : Writable + RegisterSpec ,
344
347
bool : From < FI > ,
345
348
{
346
349
/// Creates a new instance of the writer
347
350
#[ allow( unused) ]
348
351
#[ inline( always) ]
349
- pub ( crate ) fn new ( w : & ' a mut W < REG > ) -> Self {
352
+ pub ( crate ) fn new ( w : & ' a mut W < REG > , o : u8 ) -> Self {
350
353
Self {
351
354
w,
355
+ o,
352
356
_field : marker:: PhantomData ,
353
357
}
354
358
}
@@ -447,13 +451,11 @@ pub struct Safe;
447
451
pub struct Unsafe ;
448
452
449
453
/// Write field Proxy with unsafe `bits`
450
- pub type FieldWriter < ' a , REG , const WI : u8 , const O : u8 , FI = u8 > =
451
- raw:: FieldWriter < ' a , REG , WI , O , FI , Unsafe > ;
454
+ pub type FieldWriter < ' a , REG , const WI : u8 , FI = u8 > = raw:: FieldWriter < ' a , REG , WI , FI , Unsafe > ;
452
455
/// Write field Proxy with safe `bits`
453
- pub type FieldWriterSafe < ' a , REG , const WI : u8 , const O : u8 , FI = u8 > =
454
- raw:: FieldWriter < ' a , REG , WI , O , FI , Safe > ;
456
+ pub type FieldWriterSafe < ' a , REG , const WI : u8 , FI = u8 > = raw:: FieldWriter < ' a , REG , WI , FI , Safe > ;
455
457
456
- impl < ' a , REG , const WI : u8 , const OF : u8 , FI > FieldWriter < ' a , REG , WI , OF , FI >
458
+ impl < ' a , REG , const WI : u8 , FI > FieldWriter < ' a , REG , WI , FI >
457
459
where
458
460
REG : Writable + RegisterSpec ,
459
461
FI : FieldSpec ,
@@ -462,15 +464,27 @@ where
462
464
/// Field width
463
465
pub const WIDTH : u8 = WI ;
464
466
467
+ /// Field width
468
+ #[ inline( always) ]
469
+ pub const fn width ( & self ) -> u8 {
470
+ WI
471
+ }
472
+
473
+ /// Field offset
474
+ #[ inline( always) ]
475
+ pub const fn offset ( & self ) -> u8 {
476
+ self . o
477
+ }
478
+
465
479
/// Writes raw bits to the field
466
480
///
467
481
/// # Safety
468
482
///
469
483
/// Passing incorrect value can cause undefined behaviour. See reference manual
470
484
#[ inline( always) ]
471
485
pub unsafe fn bits ( self , value : FI :: Ux ) -> & ' a mut W < REG > {
472
- self . w . bits &= !( REG :: Ux :: mask :: < WI > ( ) << OF ) ;
473
- self . w . bits |= ( REG :: Ux :: from ( value) & REG :: Ux :: mask :: < WI > ( ) ) << OF ;
486
+ self . w . bits &= !( REG :: Ux :: mask :: < WI > ( ) << self . o ) ;
487
+ self . w . bits |= ( REG :: Ux :: from ( value) & REG :: Ux :: mask :: < WI > ( ) ) << self . o ;
474
488
self . w
475
489
}
476
490
/// Writes `variant` to the field
@@ -480,7 +494,7 @@ where
480
494
}
481
495
}
482
496
483
- impl < ' a , REG , const WI : u8 , const OF : u8 , FI > FieldWriterSafe < ' a , REG , WI , OF , FI >
497
+ impl < ' a , REG , const WI : u8 , FI > FieldWriterSafe < ' a , REG , WI , FI >
484
498
where
485
499
REG : Writable + RegisterSpec ,
486
500
FI : FieldSpec ,
@@ -489,11 +503,23 @@ where
489
503
/// Field width
490
504
pub const WIDTH : u8 = WI ;
491
505
506
+ /// Field width
507
+ #[ inline( always) ]
508
+ pub const fn width ( & self ) -> u8 {
509
+ WI
510
+ }
511
+
512
+ /// Field offset
513
+ #[ inline( always) ]
514
+ pub const fn offset ( & self ) -> u8 {
515
+ self . o
516
+ }
517
+
492
518
/// Writes raw bits to the field
493
519
#[ inline( always) ]
494
520
pub fn bits ( self , value : FI :: Ux ) -> & ' a mut W < REG > {
495
- self . w . bits &= !( REG :: Ux :: mask :: < WI > ( ) << OF ) ;
496
- self . w . bits |= ( REG :: Ux :: from ( value) & REG :: Ux :: mask :: < WI > ( ) ) << OF ;
521
+ self . w . bits &= !( REG :: Ux :: mask :: < WI > ( ) << self . o ) ;
522
+ self . w . bits |= ( REG :: Ux :: from ( value) & REG :: Ux :: mask :: < WI > ( ) ) << self . o ;
497
523
self . w
498
524
}
499
525
/// Writes `variant` to the field
@@ -509,21 +535,33 @@ macro_rules! bit_proxy {
509
535
pub struct $mwv;
510
536
511
537
/// Bit-wise write field proxy
512
- pub type $writer<' a, REG , const O : u8 , FI = bool > = raw:: BitWriter <' a, REG , O , FI , $mwv>;
538
+ pub type $writer<' a, REG , FI = bool > = raw:: BitWriter <' a, REG , FI , $mwv>;
513
539
514
- impl <' a, REG , const OF : u8 , FI > $writer<' a, REG , OF , FI >
540
+ impl <' a, REG , FI > $writer<' a, REG , FI >
515
541
where
516
542
REG : Writable + RegisterSpec ,
517
543
bool : From <FI >,
518
544
{
519
545
/// Field width
520
546
pub const WIDTH : u8 = 1 ;
521
547
548
+ /// Field width
549
+ #[ inline( always) ]
550
+ pub const fn width( & self ) -> u8 {
551
+ Self :: WIDTH
552
+ }
553
+
554
+ /// Field offset
555
+ #[ inline( always) ]
556
+ pub const fn offset( & self ) -> u8 {
557
+ self . o
558
+ }
559
+
522
560
/// Writes bit to the field
523
561
#[ inline( always) ]
524
562
pub fn bit( self , value: bool ) -> & ' a mut W <REG > {
525
- self . w. bits &= !( REG :: Ux :: one( ) << OF ) ;
526
- self . w. bits |= ( REG :: Ux :: from( value) & REG :: Ux :: one( ) ) << OF ;
563
+ self . w. bits &= !( REG :: Ux :: one( ) << self . o ) ;
564
+ self . w. bits |= ( REG :: Ux :: from( value) & REG :: Ux :: one( ) ) << self . o ;
527
565
self . w
528
566
}
529
567
/// Writes `variant` to the field
@@ -543,99 +581,99 @@ bit_proxy!(BitWriter0S, Bit0S);
543
581
bit_proxy ! ( BitWriter1T , Bit1T ) ;
544
582
bit_proxy ! ( BitWriter0T , Bit0T ) ;
545
583
546
- impl < ' a , REG , const OF : u8 , FI > BitWriter < ' a , REG , OF , FI >
584
+ impl < ' a , REG , FI > BitWriter < ' a , REG , FI >
547
585
where
548
586
REG : Writable + RegisterSpec ,
549
587
bool : From < FI > ,
550
588
{
551
589
/// Sets the field bit
552
590
#[ inline( always) ]
553
591
pub fn set_bit ( self ) -> & ' a mut W < REG > {
554
- self . w . bits |= REG :: Ux :: one ( ) << OF ;
592
+ self . w . bits |= REG :: Ux :: one ( ) << self . o ;
555
593
self . w
556
594
}
557
595
/// Clears the field bit
558
596
#[ inline( always) ]
559
597
pub fn clear_bit ( self ) -> & ' a mut W < REG > {
560
- self . w . bits &= !( REG :: Ux :: one ( ) << OF ) ;
598
+ self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
561
599
self . w
562
600
}
563
601
}
564
602
565
- impl < ' a , REG , const OF : u8 , FI > BitWriter1S < ' a , REG , OF , FI >
603
+ impl < ' a , REG , FI > BitWriter1S < ' a , REG , FI >
566
604
where
567
605
REG : Writable + RegisterSpec ,
568
606
bool : From < FI > ,
569
607
{
570
608
/// Sets the field bit
571
609
#[ inline( always) ]
572
610
pub fn set_bit ( self ) -> & ' a mut W < REG > {
573
- self . w . bits |= REG :: Ux :: one ( ) << OF ;
611
+ self . w . bits |= REG :: Ux :: one ( ) << self . o ;
574
612
self . w
575
613
}
576
614
}
577
615
578
- impl < ' a , REG , const OF : u8 , FI > BitWriter0C < ' a , REG , OF , FI >
616
+ impl < ' a , REG , FI > BitWriter0C < ' a , REG , FI >
579
617
where
580
618
REG : Writable + RegisterSpec ,
581
619
bool : From < FI > ,
582
620
{
583
621
/// Clears the field bit
584
622
#[ inline( always) ]
585
623
pub fn clear_bit ( self ) -> & ' a mut W < REG > {
586
- self . w . bits &= !( REG :: Ux :: one ( ) << OF ) ;
624
+ self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
587
625
self . w
588
626
}
589
627
}
590
628
591
- impl < ' a , REG , const OF : u8 , FI > BitWriter1C < ' a , REG , OF , FI >
629
+ impl < ' a , REG , FI > BitWriter1C < ' a , REG , FI >
592
630
where
593
631
REG : Writable + RegisterSpec ,
594
632
bool : From < FI > ,
595
633
{
596
634
///Clears the field bit by passing one
597
635
#[ inline( always) ]
598
636
pub fn clear_bit_by_one ( self ) -> & ' a mut W < REG > {
599
- self . w . bits |= REG :: Ux :: one ( ) << OF ;
637
+ self . w . bits |= REG :: Ux :: one ( ) << self . o ;
600
638
self . w
601
639
}
602
640
}
603
641
604
- impl < ' a , REG , const OF : u8 , FI > BitWriter0S < ' a , REG , OF , FI >
642
+ impl < ' a , REG , FI > BitWriter0S < ' a , REG , FI >
605
643
where
606
644
REG : Writable + RegisterSpec ,
607
645
bool : From < FI > ,
608
646
{
609
647
///Sets the field bit by passing zero
610
648
#[ inline( always) ]
611
649
pub fn set_bit_by_zero ( self ) -> & ' a mut W < REG > {
612
- self . w . bits &= !( REG :: Ux :: one ( ) << OF ) ;
650
+ self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
613
651
self . w
614
652
}
615
653
}
616
654
617
- impl < ' a , REG , const OF : u8 , FI > BitWriter1T < ' a , REG , OF , FI >
655
+ impl < ' a , REG , FI > BitWriter1T < ' a , REG , FI >
618
656
where
619
657
REG : Writable + RegisterSpec ,
620
658
bool : From < FI > ,
621
659
{
622
660
///Toggle the field bit by passing one
623
661
#[ inline( always) ]
624
662
pub fn toggle_bit ( self ) -> & ' a mut W < REG > {
625
- self . w . bits |= REG :: Ux :: one ( ) << OF ;
663
+ self . w . bits |= REG :: Ux :: one ( ) << self . o ;
626
664
self . w
627
665
}
628
666
}
629
667
630
- impl < ' a , REG , const OF : u8 , FI > BitWriter0T < ' a , REG , OF , FI >
668
+ impl < ' a , REG , FI > BitWriter0T < ' a , REG , FI >
631
669
where
632
670
REG : Writable + RegisterSpec ,
633
671
bool : From < FI > ,
634
672
{
635
673
///Toggle the field bit by passing zero
636
674
#[ inline( always) ]
637
675
pub fn toggle_bit ( self ) -> & ' a mut W < REG > {
638
- self . w . bits &= !( REG :: Ux :: one ( ) << OF ) ;
676
+ self . w . bits &= !( REG :: Ux :: one ( ) << self . o ) ;
639
677
self . w
640
678
}
641
679
}
0 commit comments