implement error view which displays all error on the display

This commit was merged in pull request #48.
This commit is contained in:
2026-08-29 20:19:14 +00:00
parent a31c818b37
commit ef10eec216
17 changed files with 316 additions and 92 deletions
+6 -6
View File
@@ -1,6 +1,6 @@
pub struct MemoryRegion {
offset: u32,
size: usize,
pub offset: u32,
pub size: usize,
}
impl MemoryRegion {
@@ -15,13 +15,13 @@ impl MemoryRegion {
}
}
const MAX_FLASH: usize = 16 * 1024 * 1024;
pub const MAX_FLASH: usize = 16 * 1024 * 1024;
const MAGIC_REGION: MemoryRegion = MemoryRegion::new(0, 4);
pub const MAGIC_REGION: MemoryRegion = MemoryRegion::new(0, 4);
const SETTINGS_REGION: MemoryRegion = MemoryRegion::new(MAGIC_REGION.end() as u32, 1024);
pub const SETTINGS_REGION: MemoryRegion = MemoryRegion::new(MAGIC_REGION.end() as u32, 1024);
const CARDSTORE_REGION: MemoryRegion = MemoryRegion::new(
pub const CARDSTORE_REGION: MemoryRegion = MemoryRegion::new(
SETTINGS_REGION.end() as u32,
MAX_FLASH - SETTINGS_REGION.end(),
);
+16 -2
View File
@@ -1,5 +1,7 @@
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
use core::error::Error;
use core::fmt::Display;
use binary_serde::{BinarySerde, DeserializeError, Endianness};
@@ -67,7 +69,19 @@ impl AllocationTableEntry {
pub enum CardStoreError {
Store(FlashStoreError),
CorruptedEntry(DeserializeError),
NoEntry,
NoEntry(u32),
}
impl Error for CardStoreError {}
impl Display for CardStoreError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
CardStoreError::Store(e) => e.fmt(f),
CardStoreError::CorruptedEntry(e) => e.fmt(f),
CardStoreError::NoEntry(uuid) => write!(f, "No Card Entry\nuuid: 0x{uuid:x}"),
}
}
}
impl From<FlashStoreError> for CardStoreError {
@@ -129,7 +143,7 @@ impl CardStore {
let entry = self
.allocation_table
.get(&uuid)
.ok_or(CardStoreError::NoEntry)?;
.ok_or(CardStoreError::NoEntry(uuid))?;
let mut raw_card: [u8; size_of::<RawCard>()] = [0; size_of::<RawCard>()];
self.store.read(entry.offset, &mut raw_card).await?;
+32 -5
View File
@@ -1,3 +1,6 @@
use core::error::Error;
use core::fmt::Display;
use crate::navigation::navigation::Mutex;
use embedded_storage::nor_flash::NorFlash;
use embedded_storage::nor_flash::ReadNorFlash;
@@ -5,7 +8,23 @@ use esp_storage::{FlashStorage, FlashStorageError};
use crate::peripherals::storage::MAGIC_REGION;
pub type FlashStoreError = FlashStorageError;
#[derive(Debug)]
pub struct FlashStoreError(FlashStorageError);
impl From<FlashStorageError> for FlashStoreError {
fn from(value: FlashStorageError) -> Self {
Self(value)
}
}
impl Error for FlashStoreError {}
impl Display for FlashStoreError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
use core::fmt::Debug;
self.0.fmt(f)
}
}
const FLASH_ADDR: u32 = 0x9000;
@@ -37,12 +56,17 @@ impl FlashStore {
}
pub async fn read(&self, offset: u32, bytes: &mut [u8]) -> Result<(), FlashStoreError> {
self.storage.lock().await.read(FLASH_ADDR + offset, bytes)
self.storage.lock().await.read(FLASH_ADDR + offset, bytes)?;
Ok(())
}
pub async fn write(&self, offset: u32, bytes: &mut [u8]) -> Result<(), FlashStoreError> {
log::debug!("Writing {} bytes at offset 0x{offset:08x}", bytes.len());
self.storage.lock().await.write(FLASH_ADDR + offset, bytes)
self.storage
.lock()
.await
.write(FLASH_ADDR + offset, bytes)?;
Ok(())
}
pub async fn write_erase(&self, offset: u32, bytes: &mut [u8]) -> Result<(), FlashStoreError> {
@@ -52,7 +76,8 @@ impl FlashStore {
);
let mut lock = self.storage.lock().await;
lock.erase(FLASH_ADDR + offset, FLASH_ADDR + bytes.len() as u32)?;
lock.write(FLASH_ADDR + offset, bytes)
lock.write(FLASH_ADDR + offset, bytes)?;
Ok(())
}
pub fn has_magic_bytes(storage: &mut FlashStorage) -> Result<bool, FlashStoreError> {
@@ -75,7 +100,9 @@ impl FlashStore {
if Self::has_magic_bytes(storage)? {
Ok(())
} else {
Err(FlashStoreError::Other(FLASH_INITIALIZE_MAGIC as i32))
Err(FlashStoreError(FlashStorageError::Other(
FLASH_INITIALIZE_MAGIC as i32,
)))
}
}
}