Skip to content

feat: double-buffer write pattern for local storage #100

@dougborg

Description

@dougborg

Summary

Implement a ping-pong double-buffer to decouple scan processing from flash/SD writes. This prevents storage write latency from blocking the scan pipeline.

Inspired by the ESP32DualBandWardriver's Buffer class, which alternates two buffers for this exact purpose.

Design

  • Two fixed-size buffers alternate: one accumulates new data, one flushes to storage
  • When the active buffer is full (or a time threshold is hit), swap and signal the flush task
  • Flush task writes the completed buffer to flash/SD while new data goes to the other buffer
  • Generic PingPongBuffer<const N: usize> in the library crate — reusable across storage backends

Implementation

  • Fits naturally into Embassy async — flush task awaits on a swap signal (Signal or Channel)
  • Buffer size tunable per platform:
    • ESP32 (M5StickC): ~2KB per buffer (tight DRAM)
    • ESP32-S3 (XIAO): larger, especially with PSRAM
  • no_std + alloc compatible (or purely static with const generics)

Use Cases

Relates To

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureMulti-platform architecture and designenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions