use core::ffi::CStr;
use alloc::ffi::CString;
use crate::sys::*;
extern crate alloc;
pub struct Spiffs {
partition: CString,
}
impl Spiffs {
pub unsafe fn new(partition_label: &str) -> Result<Self, EspError> {
Ok(Self {
partition: crate::private::cstr::to_cstring_arg(partition_label)?,
})
}
pub fn partition_label(&self) -> &CStr {
&self.partition
}
pub fn check(&mut self) -> Result<(), EspError> {
esp!(unsafe { esp_spiffs_check(self.partition.as_ptr()) })
}
pub fn format(&mut self) -> Result<(), EspError> {
esp!(unsafe { esp_spiffs_format(self.partition.as_ptr()) })
}
#[cfg(not(esp_idf_version_major = "4"))]
pub fn gc(&mut self, size_to_gc: usize) -> Result<(), EspError> {
esp!(unsafe { esp_spiffs_gc(self.partition.as_ptr(), size_to_gc) })
}
}