Skip to content

Commit

Permalink
Native API for EspFirmwareInfoLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Sep 23, 2023
1 parent bdc2311 commit 479b4d2
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/ota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,11 @@ impl From<Newtype<&esp_app_desc_t>> for FirmwareInfo {
pub struct EspFirmwareInfoLoader(heapless::Vec<u8, 512>);

impl EspFirmwareInfoLoader {
pub fn new() -> Self {
pub const fn new() -> Self {
Self(heapless::Vec::new())
}
}

impl Default for EspFirmwareInfoLoader {
fn default() -> Self {
Self::new()
}
}

impl io::ErrorType for EspFirmwareInfoLoader {
type Error = EspIOError;
}

impl FirmwareInfoLoader for EspFirmwareInfoLoader {
fn load(&mut self, buf: &[u8]) -> Result<LoadResult, Self::Error> {
pub fn load(&mut self, buf: &[u8]) -> Result<LoadResult, EspError> {
if !self.is_loaded() {
let remaining = self.0.capacity() - self.0.len();
if remaining > 0 {
Expand All @@ -85,14 +73,14 @@ impl FirmwareInfoLoader for EspFirmwareInfoLoader {
})
}

fn is_loaded(&self) -> bool {
pub fn is_loaded(&self) -> bool {
self.0.len()
>= mem::size_of::<esp_image_header_t>()
+ mem::size_of::<esp_image_segment_header_t>()
+ mem::size_of::<esp_app_desc_t>()
}

fn get_info(&self) -> Result<FirmwareInfo, Self::Error> {
pub fn get_info(&self) -> Result<FirmwareInfo, EspError> {
if self.is_loaded() {
let app_desc_slice = &self.0[mem::size_of::<esp_image_header_t>()
+ mem::size_of::<esp_image_segment_header_t>()
Expand All @@ -112,6 +100,30 @@ impl FirmwareInfoLoader for EspFirmwareInfoLoader {
}
}

impl Default for EspFirmwareInfoLoader {
fn default() -> Self {
Self::new()
}
}

impl io::ErrorType for EspFirmwareInfoLoader {
type Error = EspIOError;
}

impl FirmwareInfoLoader for EspFirmwareInfoLoader {
fn load(&mut self, buf: &[u8]) -> Result<LoadResult, Self::Error> {
Ok(EspFirmwareInfoLoader::load(self, buf)?)
}

fn is_loaded(&self) -> bool {
EspFirmwareInfoLoader::is_loaded(self)
}

fn get_info(&self) -> Result<FirmwareInfo, Self::Error> {
Ok(EspFirmwareInfoLoader::get_info(self)?)
}
}

#[derive(Debug)]
pub struct EspOtaUpdate<'a> {
update_partition: *const esp_partition_t,
Expand Down

0 comments on commit 479b4d2

Please sign in to comment.