This repository has been archived on 2026-08-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
donglora/vendor/embedded-storage-async/src/nor_flash.rs
T
swaitsandClaude Opus 4.6 3102fc747a feat: add display UI with splash screen, dashboard, and RSSI sparkline
Implement full SSD1306 OLED display support:
- Splash screen on boot (1.5s) with project name, version, board
- Dashboard showing radio state, config, counters, RSSI/SNR
- RSSI history sparkline (64-sample ring buffer, 2px-wide bars)
- DisplayOn/DisplayOff host commands routed via dedicated channel
- Pure render functions against generic DrawTarget (no hardware coupling)
- Display on/off control bypasses radio task entirely

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:54 -06:00

88 lines
3.1 KiB
Rust

pub use embedded_storage::nor_flash::{ErrorType, NorFlashError, NorFlashErrorKind};
/// Read only NOR flash trait.
pub trait ReadNorFlash: ErrorType {
/// The minumum number of bytes the storage peripheral can read
const READ_SIZE: usize;
/// Read a slice of data from the storage peripheral, starting the read
/// operation at the given address offset, and reading `bytes.len()` bytes.
///
/// # Errors
///
/// Returns an error if the arguments are not aligned or out of bounds. The implementation
/// can use the [`check_read`] helper function.
async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error>;
/// The capacity of the peripheral in bytes.
fn capacity(&self) -> usize;
}
/// NOR flash trait.
pub trait NorFlash: ReadNorFlash {
/// The minumum number of bytes the storage peripheral can write
const WRITE_SIZE: usize;
/// The minumum number of bytes the storage peripheral can erase
const ERASE_SIZE: usize;
/// Erase the given storage range, clearing all data within `[from..to]`.
/// The given range will contain all 1s afterwards.
///
/// If power is lost during erase, contents of the page are undefined.
///
/// # Errors
///
/// Returns an error if the arguments are not aligned or out of bounds (the case where `to >
/// from` is considered out of bounds). The implementation can use the [`check_erase`]
/// helper function.
async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error>;
/// If power is lost during write, the contents of the written words are undefined,
/// but the rest of the page is guaranteed to be unchanged.
/// It is not allowed to write to the same word twice.
///
/// # Errors
///
/// Returns an error if the arguments are not aligned or out of bounds. The implementation
/// can use the [`check_write`] helper function.
async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error>;
}
impl<T: ReadNorFlash> ReadNorFlash for &mut T {
const READ_SIZE: usize = T::READ_SIZE;
async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
T::read(self, offset, bytes).await
}
fn capacity(&self) -> usize {
T::capacity(self)
}
}
impl<T: NorFlash> NorFlash for &mut T {
const WRITE_SIZE: usize = T::WRITE_SIZE;
const ERASE_SIZE: usize = T::ERASE_SIZE;
async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> {
T::erase(self, from, to).await
}
async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> {
T::write(self, offset, bytes).await
}
}
/// Marker trait for NorFlash relaxing the restrictions on `write`.
///
/// Writes to the same word twice are now allowed. The result is the logical AND of the
/// previous data and the written data. That is, it is only possible to change 1 bits to 0 bits.
///
/// If power is lost during write:
/// - Bits that were 1 on flash and are written to 1 are guaranteed to stay as 1
/// - Bits that were 1 on flash and are written to 0 are undefined
/// - Bits that were 0 on flash are guaranteed to stay as 0
/// - Rest of the bits in the page are guaranteed to be unchanged
pub trait MultiwriteNorFlash: NorFlash {}