diff --git a/Cargo.toml b/Cargo.toml index de5489f3a7f6da9c38c936cd5175b37c1d35bdbd..04019d8818f89e2ef753cc013c8430cd00e0b764 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,12 @@ [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" diff --git a/src/lib.rs b/src/lib.rs index d170994e3eb9148408d3fc3f42e040df44bc7abc..83274c302ccbf1a9f83bb9d40ebecde295f29837 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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