@@ -59,20 +59,14 @@ pub trait FieldSpec: Sized {
59
59
/// Trait implemented by readable registers to enable the `read` method.
60
60
///
61
61
/// Registers marked with `Writable` can be also be `modify`'ed.
62
- pub trait Readable : RegisterSpec {
63
- /// Result from a call to `read` and argument to `modify`.
64
- type Reader : From < R < Self > > + core:: ops:: Deref < Target = R < Self > > ;
65
- }
62
+ pub trait Readable : RegisterSpec { }
66
63
67
64
/// Trait implemented by writeable registers.
68
65
///
69
66
/// This enables the `write`, `write_with_zero` and `reset` methods.
70
67
///
71
68
/// Registers marked with `Readable` can be also be `modify`'ed.
72
69
pub trait Writable : RegisterSpec {
73
- /// Writer type argument to `write`, et al.
74
- type Writer : From < W < Self > > + core:: ops:: DerefMut < Target = W < Self > > ;
75
-
76
70
/// Specifies the register bits that are not changed if you pass `1` and are changed if you pass `0`
77
71
const ZERO_TO_MODIFY_FIELDS_BITMAP : Self :: Ux ;
78
72
@@ -130,11 +124,11 @@ impl<REG: Readable> Reg<REG> {
130
124
/// let flag = reader.field2().bit_is_set();
131
125
/// ```
132
126
#[ inline( always) ]
133
- pub fn read ( & self ) -> REG :: Reader {
134
- REG :: Reader :: from ( R {
127
+ pub fn read ( & self ) -> R < REG > {
128
+ R {
135
129
bits : self . register . get ( ) ,
136
130
_reg : marker:: PhantomData ,
137
- } )
131
+ }
138
132
}
139
133
}
140
134
@@ -173,14 +167,14 @@ impl<REG: Resettable + Writable> Reg<REG> {
173
167
#[ inline( always) ]
174
168
pub fn write < F > ( & self , f : F )
175
169
where
176
- F : FnOnce ( & mut REG :: Writer ) -> & mut W < REG > ,
170
+ F : FnOnce ( & mut W < REG > ) -> & mut W < REG > ,
177
171
{
178
172
self . register . set (
179
- f ( & mut REG :: Writer :: from ( W {
173
+ f ( & mut W {
180
174
bits : REG :: RESET_VALUE & !REG :: ONE_TO_MODIFY_FIELDS_BITMAP
181
175
| REG :: ZERO_TO_MODIFY_FIELDS_BITMAP ,
182
176
_reg : marker:: PhantomData ,
183
- } ) )
177
+ } )
184
178
. bits ,
185
179
) ;
186
180
}
@@ -197,13 +191,13 @@ impl<REG: Writable> Reg<REG> {
197
191
#[ inline( always) ]
198
192
pub unsafe fn write_with_zero < F > ( & self , f : F )
199
193
where
200
- F : FnOnce ( & mut REG :: Writer ) -> & mut W < REG > ,
194
+ F : FnOnce ( & mut W < REG > ) -> & mut W < REG > ,
201
195
{
202
196
self . register . set (
203
- f ( & mut REG :: Writer :: from ( W {
197
+ f ( & mut W {
204
198
bits : REG :: Ux :: default ( ) ,
205
199
_reg : marker:: PhantomData ,
206
- } ) )
200
+ } )
207
201
. bits ,
208
202
) ;
209
203
}
@@ -238,20 +232,20 @@ impl<REG: Readable + Writable> Reg<REG> {
238
232
#[ inline( always) ]
239
233
pub fn modify < F > ( & self , f : F )
240
234
where
241
- for < ' w > F : FnOnce ( & REG :: Reader , & ' w mut REG :: Writer ) -> & ' w mut W < REG > ,
235
+ for < ' w > F : FnOnce ( & R < REG > , & ' w mut W < REG > ) -> & ' w mut W < REG > ,
242
236
{
243
237
let bits = self . register . get ( ) ;
244
238
self . register . set (
245
239
f (
246
- & REG :: Reader :: from ( R {
240
+ & R {
247
241
bits,
248
242
_reg : marker:: PhantomData ,
249
- } ) ,
250
- & mut REG :: Writer :: from ( W {
243
+ } ,
244
+ & mut W {
251
245
bits : bits & !REG :: ONE_TO_MODIFY_FIELDS_BITMAP
252
246
| REG :: ZERO_TO_MODIFY_FIELDS_BITMAP ,
253
247
_reg : marker:: PhantomData ,
254
- } ) ,
248
+ } ,
255
249
)
256
250
. bits ,
257
251
) ;
@@ -262,7 +256,10 @@ impl<REG: Readable + Writable> Reg<REG> {
262
256
///
263
257
/// Result of the `read` methods of registers. Also used as a closure argument in the `modify`
264
258
/// method.
265
- pub struct R < REG : RegisterSpec + ?Sized > {
259
+ pub type R < REG > = RRaw < REG > ;
260
+
261
+ #[ doc( hidden) ]
262
+ pub struct RRaw < REG : RegisterSpec > {
266
263
pub ( crate ) bits : REG :: Ux ,
267
264
_reg : marker:: PhantomData < REG > ,
268
265
}
@@ -290,25 +287,15 @@ where
290
287
/// Register writer.
291
288
///
292
289
/// Used as an argument to the closures in the `write` and `modify` methods of the register.
293
- pub struct W < REG : RegisterSpec + ?Sized > {
290
+ pub type W < REG > = WRaw < REG > ;
291
+
292
+ #[ doc( hidden) ]
293
+ pub struct WRaw < REG : RegisterSpec > {
294
294
///Writable bits
295
295
pub ( crate ) bits : REG :: Ux ,
296
296
_reg : marker:: PhantomData < REG > ,
297
297
}
298
298
299
- impl < REG : RegisterSpec > W < REG > {
300
- /// Writes raw bits to the register.
301
- ///
302
- /// # Safety
303
- ///
304
- /// Read datasheet or reference manual to find what values are allowed to pass.
305
- #[ inline( always) ]
306
- pub unsafe fn bits ( & mut self , bits : REG :: Ux ) -> & mut Self {
307
- self . bits = bits;
308
- self
309
- }
310
- }
311
-
312
299
#[ doc( hidden) ]
313
300
pub struct FieldReaderRaw < FI = u8 >
314
301
where
@@ -414,7 +401,7 @@ where
414
401
REG : Writable + RegisterSpec ,
415
402
FI : FieldSpec ,
416
403
{
417
- pub ( crate ) w : & ' a mut REG :: Writer ,
404
+ pub ( crate ) w : & ' a mut W < REG > ,
418
405
_field : marker:: PhantomData < ( FI , Safety ) > ,
419
406
}
420
407
@@ -427,7 +414,7 @@ where
427
414
/// Creates a new instance of the writer
428
415
#[ allow( unused) ]
429
416
#[ inline( always) ]
430
- pub ( crate ) fn new ( w : & ' a mut REG :: Writer ) -> Self {
417
+ pub ( crate ) fn new ( w : & ' a mut W < REG > ) -> Self {
431
418
Self {
432
419
w,
433
420
_field : marker:: PhantomData ,
@@ -441,7 +428,7 @@ where
441
428
REG : Writable + RegisterSpec ,
442
429
bool : From < FI > ,
443
430
{
444
- pub ( crate ) w : & ' a mut REG :: Writer ,
431
+ pub ( crate ) w : & ' a mut W < REG > ,
445
432
_field : marker:: PhantomData < ( FI , M ) > ,
446
433
}
447
434
@@ -453,7 +440,7 @@ where
453
440
/// Creates a new instance of the writer
454
441
#[ allow( unused) ]
455
442
#[ inline( always) ]
456
- pub ( crate ) fn new ( w : & ' a mut REG :: Writer ) -> Self {
443
+ pub ( crate ) fn new ( w : & ' a mut W < REG > ) -> Self {
457
444
Self {
458
445
w,
459
446
_field : marker:: PhantomData ,
@@ -514,14 +501,14 @@ macro_rules! impl_bit_proxy {
514
501
{
515
502
/// Writes bit to the field
516
503
#[ inline( always) ]
517
- pub fn bit( self , value: bool ) -> & ' a mut REG :: Writer {
504
+ pub fn bit( self , value: bool ) -> & ' a mut W < REG > {
518
505
self . w. bits &= !( REG :: Ux :: one( ) << OF ) ;
519
506
self . w. bits |= ( REG :: Ux :: from( value) & REG :: Ux :: one( ) ) << OF ;
520
507
self . w
521
508
}
522
509
/// Writes `variant` to the field
523
510
#[ inline( always) ]
524
- pub fn variant( self , variant: FI ) -> & ' a mut REG :: Writer {
511
+ pub fn variant( self , variant: FI ) -> & ' a mut W < REG > {
525
512
self . bit( bool :: from( variant) )
526
513
}
527
514
}
@@ -548,14 +535,14 @@ where
548
535
///
549
536
/// Passing incorrect value can cause undefined behaviour. See reference manual
550
537
#[ inline( always) ]
551
- pub unsafe fn bits ( self , value : FI :: Ux ) -> & ' a mut REG :: Writer {
538
+ pub unsafe fn bits ( self , value : FI :: Ux ) -> & ' a mut W < REG > {
552
539
self . w . bits &= !( REG :: Ux :: mask :: < WI > ( ) << OF ) ;
553
540
self . w . bits |= ( REG :: Ux :: from ( value) & REG :: Ux :: mask :: < WI > ( ) ) << OF ;
554
541
self . w
555
542
}
556
543
/// Writes `variant` to the field
557
544
#[ inline( always) ]
558
- pub fn variant ( self , variant : FI ) -> & ' a mut REG :: Writer {
545
+ pub fn variant ( self , variant : FI ) -> & ' a mut W < REG > {
559
546
unsafe { self . bits ( FI :: Ux :: from ( variant) ) }
560
547
}
561
548
}
@@ -567,14 +554,14 @@ where
567
554
{
568
555
/// Writes raw bits to the field
569
556
#[ inline( always) ]
570
- pub fn bits ( self , value : FI :: Ux ) -> & ' a mut REG :: Writer {
557
+ pub fn bits ( self , value : FI :: Ux ) -> & ' a mut W < REG > {
571
558
self . w . bits &= !( REG :: Ux :: mask :: < WI > ( ) << OF ) ;
572
559
self . w . bits |= ( REG :: Ux :: from ( value) & REG :: Ux :: mask :: < WI > ( ) ) << OF ;
573
560
self . w
574
561
}
575
562
/// Writes `variant` to the field
576
563
#[ inline( always) ]
577
- pub fn variant ( self , variant : FI ) -> & ' a mut REG :: Writer {
564
+ pub fn variant ( self , variant : FI ) -> & ' a mut W < REG > {
578
565
self . bits ( FI :: Ux :: from ( variant) )
579
566
}
580
567
}
@@ -594,13 +581,13 @@ where
594
581
{
595
582
/// Sets the field bit
596
583
#[ inline( always) ]
597
- pub fn set_bit ( self ) -> & ' a mut REG :: Writer {
584
+ pub fn set_bit ( self ) -> & ' a mut W < REG > {
598
585
self . w . bits |= REG :: Ux :: one ( ) << OF ;
599
586
self . w
600
587
}
601
588
/// Clears the field bit
602
589
#[ inline( always) ]
603
- pub fn clear_bit ( self ) -> & ' a mut REG :: Writer {
590
+ pub fn clear_bit ( self ) -> & ' a mut W < REG > {
604
591
self . w . bits &= !( REG :: Ux :: one ( ) << OF ) ;
605
592
self . w
606
593
}
@@ -613,7 +600,7 @@ where
613
600
{
614
601
/// Sets the field bit
615
602
#[ inline( always) ]
616
- pub fn set_bit ( self ) -> & ' a mut REG :: Writer {
603
+ pub fn set_bit ( self ) -> & ' a mut W < REG > {
617
604
self . w . bits |= REG :: Ux :: one ( ) << OF ;
618
605
self . w
619
606
}
@@ -626,7 +613,7 @@ where
626
613
{
627
614
/// Clears the field bit
628
615
#[ inline( always) ]
629
- pub fn clear_bit ( self ) -> & ' a mut REG :: Writer {
616
+ pub fn clear_bit ( self ) -> & ' a mut W < REG > {
630
617
self . w . bits &= !( REG :: Ux :: one ( ) << OF ) ;
631
618
self . w
632
619
}
@@ -639,7 +626,7 @@ where
639
626
{
640
627
///Clears the field bit by passing one
641
628
#[ inline( always) ]
642
- pub fn clear_bit_by_one ( self ) -> & ' a mut REG :: Writer {
629
+ pub fn clear_bit_by_one ( self ) -> & ' a mut W < REG > {
643
630
self . w . bits |= REG :: Ux :: one ( ) << OF ;
644
631
self . w
645
632
}
@@ -652,7 +639,7 @@ where
652
639
{
653
640
///Sets the field bit by passing zero
654
641
#[ inline( always) ]
655
- pub fn set_bit_by_zero ( self ) -> & ' a mut REG :: Writer {
642
+ pub fn set_bit_by_zero ( self ) -> & ' a mut W < REG > {
656
643
self . w . bits &= !( REG :: Ux :: one ( ) << OF ) ;
657
644
self . w
658
645
}
@@ -665,7 +652,7 @@ where
665
652
{
666
653
///Toggle the field bit by passing one
667
654
#[ inline( always) ]
668
- pub fn toggle_bit ( self ) -> & ' a mut REG :: Writer {
655
+ pub fn toggle_bit ( self ) -> & ' a mut W < REG > {
669
656
self . w . bits |= REG :: Ux :: one ( ) << OF ;
670
657
self . w
671
658
}
@@ -678,7 +665,7 @@ where
678
665
{
679
666
///Toggle the field bit by passing zero
680
667
#[ inline( always) ]
681
- pub fn toggle_bit ( self ) -> & ' a mut REG :: Writer {
668
+ pub fn toggle_bit ( self ) -> & ' a mut W < REG > {
682
669
self . w . bits &= !( REG :: Ux :: one ( ) << OF ) ;
683
670
self . w
684
671
}
0 commit comments