Skip to main content

Module async_db

Module async_db 

Source
Available on crate feature async only.
Expand description

Async version of SensorDb for use with Embassy and embedded-storage-async.

This module provides SensorDbAsync, which mirrors the API of SensorDb but uses async fn for all flash-touching operations. This enables DMA-based flash access on targets like RP2350 when used with Embassy.

§Differences from SensorDb

  • No RefCell: All methods take &mut self. Async code cannot safely borrow through RefCell across .await points, so interior mutability is not used.
  • All flash operations are async: mount, format, append, sync, latest, query_range, oldest, count, compact are all async.

§What is shared with the sync implementation

SensorDbAsync holds the same SensorDbState value as SensorDb, so every field and every helper that does not touch flash — sector ordering, wear levelling (find_next_sector), page-buffer scanning, bloom filters — is defined exactly once in db.rs and used verbatim here.

What remains duplicated is only the code that actually calls flash. The sync and async NorFlash traits are unrelated types, so flush_page, seal_and_advance, the sector scanners and the five *_in_sector readers exist in both flavours. That duplication is deliberate: it buys zero-overhead sync and async types with no generic sync/async machinery.

§Example

ⓘ
use sensor_db::SensorDbAsync;

let mut db: SensorDbAsync<_, 256, 512> = SensorDbAsync::new(
    flash, 0x0020_0000, 512, 2,
)?;

db.mount().await?;
db.append(0x01, timestamp_us, &temperature_bytes).await?;

Structs§

SensorDbAsync
Async append-only sensor database for NOR flash.