Skip to content
Snippets Groups Projects
Commit 9a16c9d5 authored by homunkulus's avatar homunkulus
Browse files

Auto merge of #3 - thejpster:master, r=japaric

Add modify method to RW.
parents 1ec3b12d b8fa1d19
No related branches found
No related tags found
No related merge requests found
[package] [package]
authors = ["Jorge Aparicio <japaricious@gmail.com>"] authors = [
"Jorge Aparicio <japaricious@gmail.com>",
"Jonathan 'theJPster' Pallant <github@thejpster.org.uk>"
]
description = "Volatile access to memory mapped hardware registers" description = "Volatile access to memory mapped hardware registers"
documentation = "https://docs.rs/volatile-register" documentation = "https://docs.rs/volatile-register"
keywords = ["volatile", "register"] keywords = ["volatile", "register"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
name = "volatile-register" name = "volatile-register"
repository = "https://github.com/japaric/volatile-register" repository = "https://github.com/japaric/volatile-register"
version = "0.1.1" version = "0.1.2"
...@@ -78,6 +78,13 @@ impl<T> RW<T> ...@@ -78,6 +78,13 @@ impl<T> RW<T>
ptr::write_volatile(&mut self.register, value); ptr::write_volatile(&mut self.register, value);
} }
} }
/// Perform a read-modify-write, using `func` to perform the modification.
pub fn modify<F>(&mut self, func: F) where F: FnOnce(T) -> T {
let mut t = self.read();
t = func(t);
self.write(t);
}
} }
/// Write-Only register /// Write-Only register
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment