Skip to main content

EspPartition

Struct EspPartition 

Source
pub struct EspPartition(/* private fields */);
Expand description

Represents a partition in the ESP32 flash memory

Implementations§

Source§

impl EspPartition

Source

pub unsafe fn wrap(partition: *const esp_partition_t) -> Self

Wrap a raw pointer into an EspPartition instance

§Safety

The raw pointer should be a valid one It should not be shared in multiple EspPartition instances

Source

pub unsafe fn new(label: &str) -> Result<Option<Self>, EspError>

Create a new EspPartition instance for an existing partition identified by its label

§Arguments
  • label: The label of the partition

Return None if the partition with the label does not exist or Some with the partition if it exists.

§Safety

Only a single partition should be active at any point in time for that label.

Source

pub unsafe fn cnew(clabel: &CStr) -> Result<Option<Self>, EspError>

Create a new EspPartition instance for an existing partition identified by its C-string label

§Arguments
  • clabel: The label of the partition as a C string

Return None if the partition with the label does not exist or Some with the partition if it exists.

§Safety

Only a single partition should be active at any point in time for that label.

Source

pub unsafe fn find_first( partition_type: EspPartitionType, ) -> Result<Option<Self>, EspError>

Find and return the first partition of a specific type

§Arguments
  • partition_type: The type of the partition to find

Return None if a partition of the specified type does not exist or Some with the first partition of the specified type if it exists.

§Safety

User should not end up with two EspPartition instances representing the same ESP IDF partition.

Source

pub fn clabel(&self) -> &CStr

Return the label of the partition as a C string

Source

pub fn label(&self) -> &str

Return the label of the partition

Source

pub fn partition_type(&self) -> EspPartitionType

Return the type of the partition

Source

pub fn address(&self) -> usize

Return the address/offset of the partition in the flash storage

Source

pub fn size(&self) -> usize

Return the size of the partition in bytes in the flash storage

Source

pub fn erase_size(&self) -> usize

Return the erase size block of the partition in bytes

Source

pub fn encrypted(&self) -> bool

Return true if the partition is encrypted

Source

pub fn readonly(&self) -> bool

Return true if the partition is read-only

Source

pub fn read(&mut self, offset: usize, buf: &mut [u8]) -> Result<(), EspError>

Read data from the partition, performing decryption of the data if the partition is encrypted.

§Arguments
  • offset: The offset in the partition to read from, in bytes
  • buf: The buffer to read the data into

Return an error if the read operation failed. The read operation would fail if the offset and buffer length are beyond the partition bounds.

The read operation will also fail if the offset and the buffer length are not aligned with the partition read alignment.

Source

pub fn write(&mut self, offset: usize, data: &[u8]) -> Result<(), EspError>

Write data to the partition, performing encryption of the data if the partition is encrypted.

§Arguments
  • offset: The offset in the partition to write to, in bytes
  • data: The data to write to the partition

Return an error if the write operation failed. The write operation would fail if the offset and data length are beyond the partition bounds.

The write operation will also fail if the offset and the data length are not aligned with the partition write alignment.

Source

pub fn erase(&mut self, offset: usize, size: usize) -> Result<(), EspError>

Erase a region of the partition

§Arguments
  • offset: The offset in the partition to start erasing from, in bytes
  • size: The size of the region to erase

Return an error if the erase operation failed. The erase operation would fail if the offset and size are beyond the partition bounds.

The erase operation will also fail if the offset and the size are not aligned with the partition erase block returned by erase_size.

Source

pub fn read_raw( &mut self, offset: usize, buf: &mut [u8], ) -> Result<(), EspError>

Read data from the partition without performing decryption

Identical to read if the partition is not encrypted.

Source

pub fn write_raw(&mut self, offset: usize, data: &[u8]) -> Result<(), EspError>

Write data to the partition without performing encryption

Identical to write if the partition is not encrypted.

Source

pub unsafe fn mmap( &mut self, offset: usize, size: usize, mmap_type: EspMemMapType, ) -> Result<EspMemMappedPartition<'_>, EspError>

Map a region of the partition to memory

§Arguments
  • offset: The offset in the partition to map from, in bytes
  • size: The size of the region to map, in bytes
  • mmap_type: The type of memory mapping

Return an error if the memory mapping operation failed.

§Safety

TBD

Trait Implementations§

Source§

impl RawHandle for EspPartition

Source§

type Handle = *const esp_partition_t

Source§

fn handle(&self) -> Self::Handle

Care should be taken to use the returned ESP-IDF driver raw handle only while the driver is still alive, so as to avoid use-after-free errors.
Source§

impl Send for EspPartition

Auto Trait Implementations§

§

impl !Sync for EspPartition

§

impl Freeze for EspPartition

§

impl RefUnwindSafe for EspPartition

§

impl Unpin for EspPartition

§

impl UnsafeUnpin for EspPartition

§

impl UnwindSafe for EspPartition

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = !

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.