[del] Make LocalRegisterCopy modifiable
This commit is contained in:
		
							parent
							
								
									b14cc2ac22
								
							
						
					
					
						commit
						ba8e8ae5ae
					
				| 
						 | 
					@ -329,15 +329,16 @@ impl<T: IntLike, R: RegisterLongName, W: RegisterLongName> Aliased<T, R, W> {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// A read-only copy register contents
 | 
					/// A read-write copy of register contents.
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
/// This behaves very similarly to a read-only register, but instead of doing a
 | 
					/// This behaves very similarly to a read-write register, but instead of doing a
 | 
				
			||||||
/// volatile read to MMIO to get the value for each function call, a copy of the
 | 
					/// volatile read to MMIO to get the value for each function call, a copy of the
 | 
				
			||||||
/// register contents are stored locally in memory. This allows a peripheral
 | 
					/// register contents are stored locally in memory. This allows a peripheral
 | 
				
			||||||
/// to do a single read on a register, and then check which bits are set without
 | 
					/// to do a single read on a register, and then check which bits are set without
 | 
				
			||||||
/// having to do a full MMIO read each time. It also allows the value of the
 | 
					/// having to do a full MMIO read each time. It also allows the value of the
 | 
				
			||||||
/// register to be "cached" in case the peripheral driver needs to clear the
 | 
					/// register to be "cached" in case the peripheral driver needs to clear the
 | 
				
			||||||
/// register in hardware yet still be able to check the bits.
 | 
					/// register in hardware yet still be able to check the bits.
 | 
				
			||||||
 | 
					/// You can write to a local register, which will modify the stored value.
 | 
				
			||||||
#[derive(Copy, Clone)]
 | 
					#[derive(Copy, Clone)]
 | 
				
			||||||
pub struct LocalRegisterCopy<T: IntLike, R: RegisterLongName = ()> {
 | 
					pub struct LocalRegisterCopy<T: IntLike, R: RegisterLongName = ()> {
 | 
				
			||||||
    value: T,
 | 
					    value: T,
 | 
				
			||||||
| 
						 | 
					@ -352,31 +353,55 @@ impl<T: IntLike, R: RegisterLongName> LocalRegisterCopy<T, R> {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Get the raw register value
 | 
				
			||||||
    #[inline]
 | 
					    #[inline]
 | 
				
			||||||
    pub fn get(&self) -> T {
 | 
					    pub fn get(&self) -> T {
 | 
				
			||||||
        self.value
 | 
					        self.value
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Set the raw register value
 | 
				
			||||||
 | 
					    #[inline]
 | 
				
			||||||
 | 
					    pub fn set(&mut self, value: T) {
 | 
				
			||||||
 | 
					        self.value = value;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Read the value of the given field
 | 
				
			||||||
    #[inline]
 | 
					    #[inline]
 | 
				
			||||||
    pub fn read(&self, field: Field<T, R>) -> T {
 | 
					    pub fn read(&self, field: Field<T, R>) -> T {
 | 
				
			||||||
        field.read(self.get())
 | 
					        field.read(self.get())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Read value of the given field as an enum member
 | 
				
			||||||
    #[inline]
 | 
					    #[inline]
 | 
				
			||||||
    pub fn read_as_enum<E: TryFromValue<T, EnumType = E>>(&self, field: Field<T, R>) -> Option<E> {
 | 
					    pub fn read_as_enum<E: TryFromValue<T, EnumType = E>>(&self, field: Field<T, R>) -> Option<E> {
 | 
				
			||||||
        field.read_as_enum(self.get())
 | 
					        field.read_as_enum(self.get())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Write the value of one or more fields, overwriting the other fields with zero
 | 
				
			||||||
 | 
					    #[inline]
 | 
				
			||||||
 | 
					    pub fn write(&mut self, field: FieldValue<T, R>) {
 | 
				
			||||||
 | 
					        self.set(field.value);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Write the value of one or more fields, leaving the other fields unchanged
 | 
				
			||||||
 | 
					    #[inline]
 | 
				
			||||||
 | 
					    pub fn modify(&mut self, field: FieldValue<T, R>) {
 | 
				
			||||||
 | 
					        self.set(field.modify(self.get()));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Check if one or more bits in a field are set
 | 
				
			||||||
    #[inline]
 | 
					    #[inline]
 | 
				
			||||||
    pub fn is_set(&self, field: Field<T, R>) -> bool {
 | 
					    pub fn is_set(&self, field: Field<T, R>) -> bool {
 | 
				
			||||||
        field.is_set(self.get())
 | 
					        field.is_set(self.get())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Check if any specified parts of a field match
 | 
				
			||||||
    #[inline]
 | 
					    #[inline]
 | 
				
			||||||
    pub fn matches_any(&self, field: FieldValue<T, R>) -> bool {
 | 
					    pub fn matches_any(&self, field: FieldValue<T, R>) -> bool {
 | 
				
			||||||
        field.matches_any(self.get())
 | 
					        field.matches_any(self.get())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Check if all specified parts of a field match
 | 
				
			||||||
    #[inline]
 | 
					    #[inline]
 | 
				
			||||||
    pub fn matches_all(&self, field: FieldValue<T, R>) -> bool {
 | 
					    pub fn matches_all(&self, field: FieldValue<T, R>) -> bool {
 | 
				
			||||||
        field.matches_all(self.get())
 | 
					        field.matches_all(self.get())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue