rewrite wifi crate
This commit is contained in:
@@ -1,33 +1,5 @@
|
||||
use esp_storage::FlashStorage;
|
||||
|
||||
pub struct MemoryRegion {
|
||||
pub offset: u32,
|
||||
pub size: usize,
|
||||
}
|
||||
|
||||
impl MemoryRegion {
|
||||
pub const fn new(offset: u32, size: usize) -> Self {
|
||||
assert!(offset.is_multiple_of(4), "Flash requires 4 bytes alignment");
|
||||
assert!(size.is_multiple_of(4), "Flash requires 4 bytes alignment");
|
||||
Self { offset, size }
|
||||
}
|
||||
|
||||
pub const fn end(&self) -> usize {
|
||||
self.offset as usize + self.size
|
||||
}
|
||||
}
|
||||
|
||||
pub const MAX_FLASH: usize = 16 * 1024 * 1024;
|
||||
|
||||
pub const MAGIC_REGION: MemoryRegion = MemoryRegion::new(0, 4);
|
||||
|
||||
pub const SETTINGS_REGION: MemoryRegion = MemoryRegion::new(MAGIC_REGION.end() as u32, 1024);
|
||||
|
||||
pub const CARDSTORE_REGION: MemoryRegion = MemoryRegion::new(
|
||||
SETTINGS_REGION.end() as u32,
|
||||
MAX_FLASH - SETTINGS_REGION.end(),
|
||||
);
|
||||
|
||||
pub type Nvs = esp_nvs::Nvs<FlashStorage<'static>>;
|
||||
|
||||
pub mod cardstore;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::card::model::RawCard;
|
||||
use crate::peripherals::Mutex;
|
||||
use crate::peripherals::storage::Nvs;
|
||||
use alloc::sync::Arc;
|
||||
use alloc::vec::Vec;
|
||||
use binary_serde::{BinarySerde, DeserializeError, Endianness};
|
||||
use core::error::Error;
|
||||
@@ -67,11 +68,11 @@ impl CardStoreMetaData {
|
||||
}
|
||||
|
||||
pub struct CardStore {
|
||||
nvs: Mutex<Nvs>,
|
||||
nvs: Arc<Mutex<Nvs>>,
|
||||
}
|
||||
|
||||
impl CardStore {
|
||||
pub async fn new(nvs: Mutex<Nvs>) -> Result<Self, CardStoreError> {
|
||||
pub async fn new(nvs: Arc<Mutex<Nvs>>) -> Result<Self, CardStoreError> {
|
||||
if !Self::is_initialized(&nvs).await? {
|
||||
log::info!("CardStore has not been initialized");
|
||||
Self::initialize(&nvs).await?;
|
||||
|
||||
Reference in New Issue
Block a user