-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
impl<REG: Writable> Reg<REG> { | ||
/// Writes bit with "bit-banding". | ||
#[inline(always)] | ||
pub fn bb_write<F, FI>(&self, f: F, set: bool) | ||
where | ||
F: FnOnce(&mut W<REG>) -> BitWriter<REG, FI>, | ||
bool: From<FI>, | ||
{ | ||
self.bbwrite(f, set) | ||
} | ||
#[inline(always)] | ||
fn bbwrite<F, FI, B>(&self, f: F, set: bool) | ||
where | ||
F: FnOnce(&mut W<REG>) -> raw::BitWriter<REG, FI, B>, | ||
bool: From<FI>, | ||
{ | ||
// Start address of the peripheral memory region capable of being addressed by bit-banding | ||
const PERI_ADDRESS_START: usize = 0x4000_0000; | ||
const PERI_BIT_BAND_BASE: usize = 0x4200_0000; | ||
|
||
let addr = self.as_ptr() as usize; | ||
let bit = f(&mut W { | ||
bits: REG::Ux::default(), | ||
_reg: marker::PhantomData, | ||
}) | ||
.o as usize; | ||
let bit = bit as usize; | ||
let bb_addr = (PERI_BIT_BAND_BASE + (addr - PERI_ADDRESS_START) * 32) + 4 * bit; | ||
unsafe { core::ptr::write_volatile(bb_addr as *mut u32, u32::from(set)) }; | ||
} | ||
|
||
/// Sets bit with "bit-banding". | ||
#[inline(always)] | ||
pub fn bb_set<F, FI, B>(&self, f: F) | ||
where | ||
F: FnOnce(&mut W<REG>) -> raw::BitWriter<REG, FI, B>, | ||
bool: From<FI>, | ||
B: BBSet, | ||
{ | ||
self.bbwrite(f, true); | ||
} | ||
|
||
/// Clears bit with "bit-banding". | ||
#[inline(always)] | ||
pub fn bb_clear<F, FI, B>(&self, f: F) | ||
where | ||
F: FnOnce(&mut W<REG>) -> raw::BitWriter<REG, FI, B>, | ||
bool: From<FI>, | ||
B: BBClear, | ||
{ | ||
self.bbwrite(f, false); | ||
} | ||
} | ||
|
||
pub trait BBSet {} | ||
pub trait BBClear {} | ||
impl BBSet for BitM {} | ||
impl BBSet for Bit1S {} | ||
impl BBSet for Bit1C {} | ||
impl BBSet for Bit1T {} | ||
impl BBClear for BitM {} | ||
impl BBClear for Bit0S {} | ||
impl BBClear for Bit0C {} | ||
impl BBClear for Bit0T {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters