From af06b4421c935040b1ad53a79586c95f0567ef68 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Sat, 18 Apr 2026 12:38:18 +0300 Subject: [PATCH] Reg::prepare --- CHANGELOG.md | 1 + src/generate/generic_reg_vcell.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d1e2974..c28580d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - Use marker struct instead of address in `Periph` with `PeripheralSpec` trait - Add `--skip-peripherals-struct` flag to skip generating the `Peripherals` struct, its `take`/`steal` impl and the `DEVICE_PERIPHERALS` static +- Add `Reg::prepare`. ## [v0.37.1] - 2025-10-17 diff --git a/src/generate/generic_reg_vcell.rs b/src/generate/generic_reg_vcell.rs index 9e436334..2dd3aeeb 100644 --- a/src/generate/generic_reg_vcell.rs +++ b/src/generate/generic_reg_vcell.rs @@ -88,6 +88,20 @@ impl Reg { value } + /// Prepare bits for delayed write to register. + #[inline(always)] + pub fn prepare(&self, f: F) -> REG::Ux + where + F: FnOnce(&mut W) -> &mut W, + { + f(&mut W { + bits: REG::RESET_VALUE & !REG::ONE_TO_MODIFY_FIELDS_BITMAP + | REG::ZERO_TO_MODIFY_FIELDS_BITMAP, + _reg: marker::PhantomData, + }) + .bits + } + /// Writes bits to a `Writable` register and produce a value. /// /// You can write raw bits into a register: