use msp430_atomic::AtomicOperations;
impl<REG: Writable> Reg<REG>
where
Self: Readable + Writable,
REG::Ux: AtomicOperations + Default + core::ops::Not<Output = REG::Ux>,
{
#[inline(always)]
pub unsafe fn set_bits<F>(&self, f: F)
where
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
{
let bits = f(&mut W {
bits: Default::default(),
_reg: marker::PhantomData,
})
.bits;
REG::Ux::atomic_or(self.register.as_ptr(), bits);
}
#[inline(always)]
pub unsafe fn clear_bits<F>(&self, f: F)
where
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
{
let bits = f(&mut W {
bits: !REG::Ux::default(),
_reg: marker::PhantomData,
})
.bits;
REG::Ux::atomic_and(self.register.as_ptr(), bits);
}
#[inline(always)]
pub unsafe fn toggle_bits<F>(&self, f: F)
where
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
{
let bits = f(&mut W {
bits: Default::default(),
_reg: marker::PhantomData,
})
.bits;
REG::Ux::atomic_xor(self.register.as_ptr(), bits);
}
}