Struct stm32wlxx_hal::flash::Page
source · pub struct Page { /* private fields */ }
Expand description
Page address.
Implementations§
source§impl Page
impl Page
sourcepub const unsafe fn from_index_unchecked(idx: u8) -> Self
pub const unsafe fn from_index_unchecked(idx: u8) -> Self
sourcepub fn from_index(idx: u8) -> Option<Self>
pub fn from_index(idx: u8) -> Option<Self>
Create a page address from an index.
Returns None
if the value index is greater than the index of the last
page, for example 0x7F
(page 127) on the STM32WLE5.
Example
use stm32wlxx_hal::flash::Page;
assert!(Page::from_index(8).is_some());
assert!(Page::from_index(128).is_none());
sourcepub fn from_byte_offset(offset: usize) -> Option<Self>
pub fn from_byte_offset(offset: usize) -> Option<Self>
Create a page address from an offset from the base of the flash memory.
Returns None
if the address is out of bounds, or not page aligned.
Example
use stm32wlxx_hal::flash::Page;
assert_eq!(Page::from_byte_offset(0), Page::from_index(0));
assert_eq!(Page::from_byte_offset(2048), Page::from_index(1));
assert!(Page::from_byte_offset(2047).is_none());
assert!(Page::from_byte_offset(usize::MAX).is_none());
sourcepub fn from_addr(addr: usize) -> Option<Self>
pub fn from_addr(addr: usize) -> Option<Self>
Create a page address from an absolute address.
Returns None
if the address is out of bounds, or not page aligned.
Example
use stm32wlxx_hal::flash::Page;
assert_eq!(Page::from_addr(0x0800_0000), Page::from_index(0));
assert_eq!(Page::from_addr(0x0800_0800), Page::from_index(1));
assert!(Page::from_addr(0).is_none());
assert!(Page::from_addr(usize::MAX).is_none());
assert!(Page::from_addr(0x0800_0001).is_none());
sourcepub const fn to_index(self) -> u8
pub const fn to_index(self) -> u8
Get the page index.
Example
use stm32wlxx_hal::flash::Page;
let page7 = unsafe { Page::from_index_unchecked(7) };
assert_eq!(page7.to_index(), 7);
sourcepub const fn addr(&self) -> usize
pub const fn addr(&self) -> usize
Get the page address.
Example
use stm32wlxx_hal::flash::Page;
let page127 = unsafe { Page::from_index_unchecked(127) };
let page0 = unsafe { Page::from_index_unchecked(0) };
assert_eq!(page0.addr(), 0x0800_0000);
assert_eq!(page127.addr(), 0x0803_F800);
sourcepub const fn addr_range(&self) -> Range<usize>
pub const fn addr_range(&self) -> Range<usize>
Get the address range of the page.
Example
use core::ops::Range;
use stm32wlxx_hal::flash::Page;
let page0 = unsafe { Page::from_index_unchecked(0) };
assert_eq!(
page0.addr_range(),
Range {
start: 0x0800_0000,
end: 0x0800_0800
}
);
Trait Implementations§
source§impl From<Page> for AlignedAddr
impl From<Page> for AlignedAddr
source§impl Ord for Page
impl Ord for Page
source§impl PartialEq for Page
impl PartialEq for Page
source§impl PartialOrd for Page
impl PartialOrd for Page
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Page
impl Eq for Page
impl StructuralEq for Page
impl StructuralPartialEq for Page
Auto Trait Implementations§
impl RefUnwindSafe for Page
impl Send for Page
impl Sync for Page
impl Unpin for Page
impl UnwindSafe for Page
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more