Skip to content
Snippets Groups Projects
Commit b8fa1d19 authored by Jonathan 'theJPster' Pallant's avatar Jonathan 'theJPster' Pallant
Browse files

Add modify method to RW.

parent afb07d59
Branches
Tags
No related merge requests found
[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"
documentation = "https://docs.rs/volatile-register"
keywords = ["volatile", "register"]
license = "MIT OR Apache-2.0"
name = "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>
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment