|
| 1 | +use msp430_atomic::AtomicOperations; |
| 2 | + |
| 3 | +impl<REG: Writable> Reg<REG> |
| 4 | +where |
| 5 | + Self: Readable + Writable, |
| 6 | + REG::Ux: AtomicOperations + Default + core::ops::Not<Output = REG::Ux>, |
| 7 | +{ |
| 8 | + /// Set high every bit in the register that was set in the write proxy. Leave other bits |
| 9 | + /// untouched. The write is done in a single atomic instruction. |
| 10 | + #[inline(always)] |
| 11 | + pub unsafe fn set_bits<F>(&self, f: F) |
| 12 | + where |
| 13 | + F: FnOnce(&mut W<REG>) -> &mut W<REG>, |
| 14 | + { |
| 15 | + let bits = f(&mut W { |
| 16 | + bits: Default::default(), |
| 17 | + _reg: marker::PhantomData, |
| 18 | + }) |
| 19 | + .bits; |
| 20 | + REG::Ux::atomic_or(self.register.as_ptr(), bits); |
| 21 | + } |
| 22 | + |
| 23 | + /// Clear every bit in the register that was cleared in the write proxy. Leave other bits |
| 24 | + /// untouched. The write is done in a single atomic instruction. |
| 25 | + #[inline(always)] |
| 26 | + pub unsafe fn clear_bits<F>(&self, f: F) |
| 27 | + where |
| 28 | + F: FnOnce(&mut W<REG>) -> &mut W<REG>, |
| 29 | + { |
| 30 | + let bits = f(&mut W { |
| 31 | + bits: !REG::Ux::default(), |
| 32 | + _reg: marker::PhantomData, |
| 33 | + }) |
| 34 | + .bits; |
| 35 | + REG::Ux::atomic_and(self.register.as_ptr(), bits); |
| 36 | + } |
| 37 | + |
| 38 | + /// Toggle every bit in the register that was set in the write proxy. Leave other bits |
| 39 | + /// untouched. The write is done in a single atomic instruction. |
| 40 | + #[inline(always)] |
| 41 | + pub unsafe fn toggle_bits<F>(&self, f: F) |
| 42 | + where |
| 43 | + F: FnOnce(&mut W<REG>) -> &mut W<REG>, |
| 44 | + { |
| 45 | + let bits = f(&mut W { |
| 46 | + bits: Default::default(), |
| 47 | + _reg: marker::PhantomData, |
| 48 | + }) |
| 49 | + .bits; |
| 50 | + REG::Ux::atomic_xor(self.register.as_ptr(), bits); |
| 51 | + } |
| 52 | +} |
0 commit comments