@@ -57,7 +57,22 @@ pub fn render(
57
57
let desc = format ! ( "Reader of register {}" , register. name) ;
58
58
mod_items. extend ( quote ! {
59
59
#[ doc = #desc]
60
- pub type R = crate :: R <#name_uc_spec>;
60
+ pub struct R ( crate :: R <#name_uc_spec>) ;
61
+
62
+ impl core:: ops:: Deref for R {
63
+ type Target = crate :: R <#name_uc_spec>;
64
+
65
+ #[ inline( always) ]
66
+ fn deref( & self ) -> & Self :: Target {
67
+ & self . 0
68
+ }
69
+ }
70
+
71
+ impl core:: convert:: From <crate :: R <#name_uc_spec>> for R {
72
+ fn from( reader: crate :: R <#name_uc_spec>) -> Self {
73
+ R ( reader)
74
+ }
75
+ }
61
76
} ) ;
62
77
methods. push ( "read" ) ;
63
78
}
@@ -66,7 +81,29 @@ pub fn render(
66
81
let desc = format ! ( "Writer for register {}" , register. name) ;
67
82
mod_items. extend ( quote ! {
68
83
#[ doc = #desc]
69
- pub type W = crate :: W <#name_uc_spec>;
84
+ pub struct W ( crate :: W <#name_uc_spec>) ;
85
+
86
+ impl core:: ops:: Deref for W {
87
+ type Target = crate :: W <#name_uc_spec>;
88
+
89
+ #[ inline( always) ]
90
+ fn deref( & self ) -> & Self :: Target {
91
+ & self . 0
92
+ }
93
+ }
94
+
95
+ impl core:: ops:: DerefMut for W {
96
+ #[ inline( always) ]
97
+ fn deref_mut( & mut self ) -> & mut Self :: Target {
98
+ & mut self . 0
99
+ }
100
+ }
101
+
102
+ impl core:: convert:: From <crate :: W <#name_uc_spec>> for W {
103
+ fn from( writer: crate :: W <#name_uc_spec>) -> Self {
104
+ W ( writer)
105
+ }
106
+ }
70
107
} ) ;
71
108
methods. push ( "write_with_zero" ) ;
72
109
if can_reset {
@@ -125,6 +162,14 @@ pub fn render(
125
162
126
163
mod_items. extend ( w_impl_items) ;
127
164
165
+ mod_items. extend ( quote ! {
166
+ #[ doc = "Writes raw bits to the register." ]
167
+ pub unsafe fn bits( & mut self , bits: #rty) -> & mut Self {
168
+ self . 0 . bits( bits) ;
169
+ self
170
+ }
171
+ } ) ;
172
+
128
173
close. to_tokens ( & mut mod_items) ;
129
174
}
130
175
@@ -167,7 +212,9 @@ pub fn render(
167
212
) ;
168
213
mod_items. extend ( quote ! {
169
214
#[ doc = #doc]
170
- impl crate :: Readable for #name_uc_spec { }
215
+ impl crate :: Readable for #name_uc_spec {
216
+ type Reader = R ;
217
+ }
171
218
} ) ;
172
219
}
173
220
if can_write {
@@ -177,7 +224,9 @@ pub fn render(
177
224
) ;
178
225
mod_items. extend ( quote ! {
179
226
#[ doc = #doc]
180
- impl crate :: Writable for #name_uc_spec { }
227
+ impl crate :: Writable for #name_uc_spec {
228
+ type Writer = W ;
229
+ }
181
230
} ) ;
182
231
}
183
232
if let Some ( rv) = res_val. map ( util:: hex) {
@@ -388,7 +437,22 @@ pub fn fields(
388
437
389
438
mod_items. extend ( quote ! {
390
439
#[ doc = #readerdoc]
391
- pub type #name_pc_r = crate :: FieldReader <#fty, #name_pc_a>;
440
+ pub struct #name_pc_r( crate :: FieldReader <#fty, #name_pc_a>) ;
441
+
442
+ impl #name_pc_r {
443
+ pub ( crate ) fn new( bits: #fty) -> Self {
444
+ #name_pc_r( crate :: FieldReader :: new( bits) )
445
+ }
446
+ }
447
+
448
+ impl core:: ops:: Deref for #name_pc_r {
449
+ type Target = crate :: FieldReader <#fty, #name_pc_a>;
450
+
451
+ #[ inline( always) ]
452
+ fn deref( & self ) -> & Self :: Target {
453
+ & self . 0
454
+ }
455
+ }
392
456
} ) ;
393
457
} else {
394
458
let has_reserved_variant = evs. values . len ( ) != ( 1 << width) ;
@@ -463,23 +527,51 @@ pub fn fields(
463
527
#[ doc = #doc]
464
528
#inline
465
529
pub fn #is_variant( & self ) -> bool {
466
- * self == #name_pc_a:: #pc
530
+ * * self == #name_pc_a:: #pc
467
531
}
468
532
} ) ;
469
533
}
470
534
471
535
mod_items. extend ( quote ! {
472
536
#[ doc = #readerdoc]
473
- pub type #name_pc_r = crate :: FieldReader <#fty, #name_pc_a>;
537
+ pub struct #name_pc_r( crate :: FieldReader <#fty, #name_pc_a>) ;
538
+
474
539
impl #name_pc_r {
540
+ pub ( crate ) fn new( bits: #fty) -> Self {
541
+ #name_pc_r( crate :: FieldReader :: new( bits) )
542
+ }
475
543
#enum_items
476
544
}
545
+
546
+ impl core:: ops:: Deref for #name_pc_r {
547
+ type Target = crate :: FieldReader <#fty, #name_pc_a>;
548
+
549
+ #[ inline( always) ]
550
+ fn deref( & self ) -> & Self :: Target {
551
+ & self . 0
552
+ }
553
+ }
477
554
} ) ;
478
555
}
479
556
} else {
480
557
mod_items. extend ( quote ! {
481
558
#[ doc = #readerdoc]
482
- pub type #name_pc_r = crate :: FieldReader <#fty, #fty>;
559
+ pub struct #name_pc_r( crate :: FieldReader <#fty, #fty>) ;
560
+
561
+ impl #name_pc_r {
562
+ pub ( crate ) fn new( bits: #fty) -> Self {
563
+ #name_pc_r( crate :: FieldReader :: new( bits) )
564
+ }
565
+ }
566
+
567
+ impl core:: ops:: Deref for #name_pc_r {
568
+ type Target = crate :: FieldReader <#fty, #fty>;
569
+
570
+ #[ inline( always) ]
571
+ fn deref( & self ) -> & Self :: Target {
572
+ & self . 0
573
+ }
574
+ }
483
575
} )
484
576
}
485
577
}
0 commit comments