@@ -352,16 +352,16 @@ where
352
352
}
353
353
354
354
#[ doc( hidden) ]
355
- pub struct BitWriterRaw < ' a , U , REG , FI , const O : u8 >
355
+ pub struct BitWriterRaw < ' a , U , REG , FI , M , const O : u8 >
356
356
where
357
357
REG : Writable + RegisterSpec < Ux = U > ,
358
358
FI : Into < bool > ,
359
359
{
360
360
pub ( crate ) w : & ' a mut REG :: Writer ,
361
- _field : marker:: PhantomData < FI > ,
361
+ _field : marker:: PhantomData < ( FI , M ) > ,
362
362
}
363
363
364
- impl < ' a , U , REG , FI , const O : u8 > BitWriterRaw < ' a , U , REG , FI , O >
364
+ impl < ' a , U , REG , FI , M , const O : u8 > BitWriterRaw < ' a , U , REG , FI , M , O >
365
365
where
366
366
REG : Writable + RegisterSpec < Ux = U > ,
367
367
FI : Into < bool > ,
@@ -382,9 +382,6 @@ pub type FieldWriter<'a, U, REG, N, FI, const WI: u8, const O: u8> = FieldWriter
382
382
/// Write field Proxy with safe `bits`
383
383
pub type FieldWriterSafe < ' a , U , REG , N , FI , const WI : u8 , const O : u8 > = FieldWriterRaw < ' a , U , REG , N , FI , Safe , WI , O > ;
384
384
385
- /// Bit-wise write field proxy
386
- pub type BitWriter < ' a , U , REG , FI , const O : u8 > = BitWriterRaw < ' a , U , REG , FI , O > ;
387
-
388
385
389
386
impl < ' a , U , REG , N , FI , const WI : u8 , const OF : u8 > FieldWriter < ' a , U , REG , N , FI , WI , OF >
390
387
where
@@ -408,17 +405,57 @@ where
408
405
pub const OFFSET : u8 = OF ;
409
406
}
410
407
411
- impl < ' a , U , REG , FI , const OF : u8 > BitWriter < ' a , U , REG , FI , OF >
412
- where
413
- REG : Writable + RegisterSpec < Ux = U > ,
414
- FI : Into < bool > ,
415
- {
416
- /// Field width
417
- pub const WIDTH : u8 = 1 ;
418
- /// Field offset
419
- pub const OFFSET : u8 = OF ;
408
+ macro_rules! bit_proxy {
409
+ ( $writer: ident, $mwv: ident) => {
410
+ #[ doc( hidden) ]
411
+ pub struct $mwv;
412
+
413
+ /// Bit-wise write field proxy
414
+ pub type $writer<' a, U , REG , FI , const O : u8 > = BitWriterRaw <' a, U , REG , FI , $mwv, O >;
415
+
416
+ impl <' a, U , REG , FI , const OF : u8 > $writer<' a, U , REG , FI , OF >
417
+ where
418
+ REG : Writable + RegisterSpec <Ux = U >,
419
+ FI : Into <bool >,
420
+ {
421
+ /// Field width
422
+ pub const WIDTH : u8 = 1 ;
423
+ /// Field offset
424
+ pub const OFFSET : u8 = OF ;
425
+ }
426
+ }
420
427
}
421
428
429
+ macro_rules! impl_bit_proxy {
430
+ ( $writer: ident, $U: ty) => {
431
+ impl <' a, REG , FI , const OF : u8 > $writer<' a, $U, REG , FI , OF >
432
+ where
433
+ REG : Writable + RegisterSpec <Ux = $U>,
434
+ FI : Into <bool >,
435
+ {
436
+ /// Writes bit to the field
437
+ #[ inline( always) ]
438
+ pub fn bit( self , value: bool ) -> & ' a mut REG :: Writer {
439
+ self . w. bits = ( self . w. bits & !( 1 << { OF } ) ) | ( ( <$U>:: from( value) & 1 ) << { OF } ) ;
440
+ self . w
441
+ }
442
+ /// Writes `variant` to the field
443
+ #[ inline( always) ]
444
+ pub fn variant( self , variant: FI ) -> & ' a mut REG :: Writer {
445
+ self . bit( variant. into( ) )
446
+ }
447
+ }
448
+ }
449
+ }
450
+
451
+ bit_proxy ! ( BitWriter , BitM ) ;
452
+ bit_proxy ! ( BitWriter1S , Bit1S ) ;
453
+ bit_proxy ! ( BitWriter0C , Bit0C ) ;
454
+ bit_proxy ! ( BitWriter1C , Bit1C ) ;
455
+ bit_proxy ! ( BitWriter0S , Bit0S ) ;
456
+ bit_proxy ! ( BitWriter1T , Bit1T ) ;
457
+ bit_proxy ! ( BitWriter0T , Bit0T ) ;
458
+
422
459
macro_rules! impl_proxy {
423
460
( $U: ty) => {
424
461
impl <' a, REG , N , FI , const WI : u8 , const OF : u8 > FieldWriter <' a, $U, REG , N , FI , WI , OF >
@@ -465,32 +502,94 @@ macro_rules! impl_proxy {
465
502
self . bits( variant. into( ) )
466
503
}
467
504
}
505
+ impl_bit_proxy!( BitWriter , $U) ;
506
+ impl_bit_proxy!( BitWriter1S , $U) ;
507
+ impl_bit_proxy!( BitWriter0C , $U) ;
508
+ impl_bit_proxy!( BitWriter1C , $U) ;
509
+ impl_bit_proxy!( BitWriter0S , $U) ;
510
+ impl_bit_proxy!( BitWriter1T , $U) ;
511
+ impl_bit_proxy!( BitWriter0T , $U) ;
468
512
impl <' a, REG , FI , const OF : u8 > BitWriter <' a, $U, REG , FI , OF >
469
513
where
470
514
REG : Writable + RegisterSpec <Ux = $U>,
471
515
FI : Into <bool >,
472
516
{
473
- /// Writes bit to the field
517
+ /// Sets the field bit
474
518
#[ inline( always) ]
475
- pub fn bit( self , value: bool ) -> & ' a mut REG :: Writer {
476
- self . w. bits = ( self . w. bits & !( 1 << { OF } ) ) | ( ( <$U>:: from( value) & 1 ) << { OF } ) ;
477
- self . w
519
+ pub fn set_bit( self ) -> & ' a mut REG :: Writer {
520
+ self . bit( true )
478
521
}
479
- /// Writes `variant` to the field
522
+ /// Clears the field bit
480
523
#[ inline( always) ]
481
- pub fn variant ( self , variant : FI ) -> & ' a mut REG :: Writer {
482
- self . bit( variant . into ( ) )
524
+ pub fn clear_bit ( self ) -> & ' a mut REG :: Writer {
525
+ self . bit( false )
483
526
}
527
+ }
528
+ impl <' a, REG , FI , const OF : u8 > BitWriter1S <' a, $U, REG , FI , OF >
529
+ where
530
+ REG : Writable + RegisterSpec <Ux = $U>,
531
+ FI : Into <bool >,
532
+ {
484
533
/// Sets the field bit
485
534
#[ inline( always) ]
486
535
pub fn set_bit( self ) -> & ' a mut REG :: Writer {
487
536
self . bit( true )
488
537
}
538
+ }
539
+ impl <' a, REG , FI , const OF : u8 > BitWriter0C <' a, $U, REG , FI , OF >
540
+ where
541
+ REG : Writable + RegisterSpec <Ux = $U>,
542
+ FI : Into <bool >,
543
+ {
489
544
/// Clears the field bit
490
545
#[ inline( always) ]
491
546
pub fn clear_bit( self ) -> & ' a mut REG :: Writer {
492
547
self . bit( false )
493
548
}
494
549
}
550
+ impl <' a, REG , FI , const OF : u8 > BitWriter1C <' a, $U, REG , FI , OF >
551
+ where
552
+ REG : Writable + RegisterSpec <Ux = $U>,
553
+ FI : Into <bool >,
554
+ {
555
+ ///Clears the field bit by passing one
556
+ #[ inline( always) ]
557
+ pub fn clear_bit_by_one( self ) -> & ' a mut REG :: Writer {
558
+ self . bit( true )
559
+ }
560
+ }
561
+ impl <' a, REG , FI , const OF : u8 > BitWriter0S <' a, $U, REG , FI , OF >
562
+ where
563
+ REG : Writable + RegisterSpec <Ux = $U>,
564
+ FI : Into <bool >,
565
+ {
566
+ ///Sets the field bit by passing zero
567
+ #[ inline( always) ]
568
+ pub fn set_bit_by_zero( self ) -> & ' a mut REG :: Writer {
569
+ self . bit( false )
570
+ }
571
+ }
572
+ impl <' a, REG , FI , const OF : u8 > BitWriter1T <' a, $U, REG , FI , OF >
573
+ where
574
+ REG : Writable + RegisterSpec <Ux = $U>,
575
+ FI : Into <bool >,
576
+ {
577
+ ///Toggle the field bit by passing one
578
+ #[ inline( always) ]
579
+ pub fn toggle_bit( self ) -> & ' a mut REG :: Writer {
580
+ self . bit( true )
581
+ }
582
+ }
583
+ impl <' a, REG , FI , const OF : u8 > BitWriter0T <' a, $U, REG , FI , OF >
584
+ where
585
+ REG : Writable + RegisterSpec <Ux = $U>,
586
+ FI : Into <bool >,
587
+ {
588
+ ///Toggle the field bit by passing zero
589
+ #[ inline( always) ]
590
+ pub fn toggle_bit( self ) -> & ' a mut REG :: Writer {
591
+ self . bit( false )
592
+ }
593
+ }
495
594
}
496
595
}
0 commit comments