diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b2d3295..88adc971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - Skip generating `.add(0)` and `1 *` in accessors - Bump MSRV of generated code to 1.76 - move `must_use` from methods to generic type -- Add `write_and`, `write_with_zero_and`, and `modify_and` register modifiers +- *breaking change* Return raw writtened value +- Add `from_write`, `from_write_with_zero`, and `from_modify` register modifiers + with generic return value ## [v0.33.5] - 2024-10-12 diff --git a/ci/script.sh b/ci/script.sh index b0da0e4b..9f634458 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -589,7 +589,7 @@ main() { test_patched_stm32 stm32f7x3 test_patched_stm32 stm32g070 test_patched_stm32 stm32g473 - test_patched_stm32 stm32h753 + test_patched_stm32 stm32h743 test_patched_stm32 stm32l0x3 test_patched_stm32 stm32l162 test_patched_stm32 stm32l4x6 diff --git a/src/generate/generic_reg_vcell.rs b/src/generate/generic_reg_vcell.rs index 585c6e0c..b0ca0d5e 100644 --- a/src/generate/generic_reg_vcell.rs +++ b/src/generate/generic_reg_vcell.rs @@ -74,18 +74,18 @@ impl Reg { /// ``` /// In the latter case, other fields will be set to their reset value. #[inline(always)] - pub fn write(&self, f: F) + pub fn write(&self, f: F) -> REG::Ux where F: FnOnce(&mut W) -> &mut W, { - self.register.set( - f(&mut W { - bits: REG::RESET_VALUE & !REG::ONE_TO_MODIFY_FIELDS_BITMAP - | REG::ZERO_TO_MODIFY_FIELDS_BITMAP, - _reg: marker::PhantomData, - }) - .bits, - ); + let value = f(&mut W { + bits: REG::RESET_VALUE & !REG::ONE_TO_MODIFY_FIELDS_BITMAP + | REG::ZERO_TO_MODIFY_FIELDS_BITMAP, + _reg: marker::PhantomData, + }) + .bits; + self.register.set(value); + value } /// Writes bits to a `Writable` register and produce a value. @@ -143,17 +143,17 @@ impl Reg { /// /// Unsafe to use with registers which don't allow to write 0. #[inline(always)] - pub unsafe fn write_with_zero(&self, f: F) + pub unsafe fn write_with_zero(&self, f: F) -> REG::Ux where F: FnOnce(&mut W) -> &mut W, { - self.register.set( - f(&mut W { - bits: REG::Ux::default(), - _reg: marker::PhantomData, - }) - .bits, - ); + let value = f(&mut W { + bits: REG::Ux::default(), + _reg: marker::PhantomData, + }) + .bits; + self.register.set(value); + value } /// Writes 0 to a `Writable` register and produces a value. @@ -208,25 +208,24 @@ impl Reg { /// ``` /// Other fields will have the value they had before the call to `modify`. #[inline(always)] - pub fn modify(&self, f: F) + pub fn modify(&self, f: F) -> REG::Ux where for<'w> F: FnOnce(&R, &'w mut W) -> &'w mut W, { let bits = self.register.get(); - self.register.set( - f( - &R { - bits, - _reg: marker::PhantomData, - }, - &mut W { - bits: bits & !REG::ONE_TO_MODIFY_FIELDS_BITMAP - | REG::ZERO_TO_MODIFY_FIELDS_BITMAP, - _reg: marker::PhantomData, - }, - ) - .bits, - ); + let value = f( + &R { + bits, + _reg: marker::PhantomData, + }, + &mut W { + bits: bits & !REG::ONE_TO_MODIFY_FIELDS_BITMAP | REG::ZERO_TO_MODIFY_FIELDS_BITMAP, + _reg: marker::PhantomData, + }, + ) + .bits; + self.register.set(value); + value } /// Modifies the contents of the register by reading and then writing it