Implement first version of storage #45
Generated
+1
@@ -375,6 +375,7 @@ dependencies = [
|
||||
"log",
|
||||
"num_enum",
|
||||
"pn532",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -53,6 +53,7 @@ ch1115 = { version = "0.1.2", features = ["graphics"] }
|
||||
esp-storage = "0.9.0"
|
||||
embedded-storage = "0.3.1"
|
||||
binary_serde = "1.0.25"
|
||||
static_assertions = { version = "1.1.0", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
log = "0.4.27"
|
||||
|
||||
@@ -17,6 +17,7 @@ pub fn split_nfc_hex(payload: &[u8]) -> Option<RawCard> {
|
||||
packed_card_text: payload[0x2DB..0x311].try_into().ok()?,
|
||||
secret: payload[0x311..0x329].try_into().ok()?,
|
||||
_opaque_trailer: payload[0x329..0x35A].try_into().ok()?,
|
||||
_padding: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,11 @@ pub struct RawCard {
|
||||
pub packed_card_text: [u8; 54],
|
||||
pub secret: [u8; 24],
|
||||
pub _opaque_trailer: [u8; 49],
|
||||
pub _padding: [u8; 2],
|
||||
}
|
||||
|
||||
static_assertions::const_assert!(RawCard::SERIALIZED_SIZE.is_multiple_of(4));
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, FromPrimitive)]
|
||||
#[repr(u8)]
|
||||
pub enum CardType {
|
||||
|
||||
+11
-10
@@ -17,6 +17,17 @@ const COUNT_REGION: MemoryRegion = MemoryRegion {
|
||||
size: size_of::<u32>(),
|
||||
};
|
||||
|
||||
const ALLOCATION_TABLE_REGION: MemoryRegion = MemoryRegion {
|
||||
offset: COUNT_REGION.end() as u32,
|
||||
size: MAX_CARDS * AllocationTableEntry::SERIALIZED_SIZE,
|
||||
};
|
||||
|
||||
const CARDS_REGION: MemoryRegion = MemoryRegion {
|
||||
offset: ALLOCATION_TABLE_REGION.end() as u32,
|
||||
size: CARDSTORE_REGION.size - ALLOCATION_TABLE_REGION.end(),
|
||||
};
|
||||
|
||||
|
||||
#[derive(Debug, BinarySerde, PartialEq, Eq, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct AllocationTableEntry {
|
||||
@@ -52,16 +63,6 @@ impl AllocationTableEntry {
|
||||
}
|
||||
}
|
||||
|
||||
const ALLOCATION_TABLE_REGION: MemoryRegion = MemoryRegion {
|
||||
offset: COUNT_REGION.end() as u32,
|
||||
size: MAX_CARDS * AllocationTableEntry::SERIALIZED_SIZE,
|
||||
};
|
||||
|
||||
const CARDS_REGION: MemoryRegion = MemoryRegion {
|
||||
offset: ALLOCATION_TABLE_REGION.end() as u32,
|
||||
size: CARDSTORE_REGION.size - ALLOCATION_TABLE_REGION.end(),
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CardStoreError {
|
||||
Store(StoreError),
|
||||
|
||||
@@ -39,6 +39,7 @@ impl Store {
|
||||
}
|
||||
|
||||
pub fn write(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), StoreError> {
|
||||
log::debug!("Writing {} bytes at offset 0x{offset:08x}", bytes.len());
|
||||
self.storage.write(FLASH_ADDR + offset, bytes)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user