@@ -331,15 +331,17 @@ impl<T: IntLike, R: RegisterLongName, W: RegisterLongName> Aliased<T, R, W> {
331
331
}
332
332
}
333
333
334
- /// A read-only copy register contents
334
+ /// A read-write copy of register contents.
335
335
///
336
- /// This behaves very similarly to a read-only register, but instead of doing a
336
+ /// This behaves very similarly to a read-write register, but instead of doing a
337
337
/// volatile read to MMIO to get the value for each function call, a copy of the
338
338
/// register contents are stored locally in memory. This allows a peripheral
339
339
/// to do a single read on a register, and then check which bits are set without
340
340
/// having to do a full MMIO read each time. It also allows the value of the
341
341
/// register to be "cached" in case the peripheral driver needs to clear the
342
342
/// register in hardware yet still be able to check the bits.
343
+ /// You can write to a local register, which will modify the stored value, but
344
+ /// will not modify any hardware because it operates only on local copy.
343
345
#[ derive( Copy , Clone ) ]
344
346
pub struct LocalRegisterCopy < T : IntLike , R : RegisterLongName = ( ) > {
345
347
value : T ,
@@ -354,31 +356,55 @@ impl<T: IntLike, R: RegisterLongName> LocalRegisterCopy<T, R> {
354
356
}
355
357
}
356
358
359
+ /// Get the raw register value
357
360
#[ inline]
358
361
pub fn get ( & self ) -> T {
359
362
self . value
360
363
}
361
364
365
+ /// Set the raw register value
366
+ #[ inline]
367
+ pub fn set ( & mut self , value : T ) {
368
+ self . value = value;
369
+ }
370
+
371
+ /// Read the value of the given field
362
372
#[ inline]
363
373
pub fn read ( & self , field : Field < T , R > ) -> T {
364
374
field. read ( self . get ( ) )
365
375
}
366
376
377
+ /// Read value of the given field as an enum member
367
378
#[ inline]
368
379
pub fn read_as_enum < E : TryFromValue < T , EnumType = E > > ( & self , field : Field < T , R > ) -> Option < E > {
369
380
field. read_as_enum ( self . get ( ) )
370
381
}
371
382
383
+ /// Write the value of one or more fields, overwriting the other fields with zero
384
+ #[ inline]
385
+ pub fn write ( & mut self , field : FieldValue < T , R > ) {
386
+ self . set ( field. value ) ;
387
+ }
388
+
389
+ /// Write the value of one or more fields, leaving the other fields unchanged
390
+ #[ inline]
391
+ pub fn modify ( & mut self , field : FieldValue < T , R > ) {
392
+ self . set ( field. modify ( self . get ( ) ) ) ;
393
+ }
394
+
395
+ /// Check if one or more bits in a field are set
372
396
#[ inline]
373
397
pub fn is_set ( & self , field : Field < T , R > ) -> bool {
374
398
field. is_set ( self . get ( ) )
375
399
}
376
400
401
+ /// Check if any specified parts of a field match
377
402
#[ inline]
378
403
pub fn matches_any ( & self , field : FieldValue < T , R > ) -> bool {
379
404
field. matches_any ( self . get ( ) )
380
405
}
381
406
407
+ /// Check if all specified parts of a field match
382
408
#[ inline]
383
409
pub fn matches_all ( & self , field : FieldValue < T , R > ) -> bool {
384
410
field. matches_all ( self . get ( ) )
0 commit comments