#memory #data #flash #medium #write #no-alloc #sectorized

no-std sectorize

A small library for writing arbitrarily-aligned data to sectored mediums

1 unstable release

0.1.0 Jun 30, 2024

#1677 in Encoding

Download history 182/week @ 2024-06-29 24/week @ 2024-07-06 9/week @ 2024-08-10 9/week @ 2024-08-17 3/week @ 2024-08-24 13/week @ 2024-08-31 35/week @ 2024-09-07 42/week @ 2024-09-14 32/week @ 2024-09-21 34/week @ 2024-09-28 11/week @ 2024-10-05

121 downloads per month

MIT license

7KB
175 lines

sectorize

A basic library for writing data at an arbitrary address/length to a sectorized medium, like flash memory.

Usage

Here's how I'm using it. This is a snippet from a project I'm working on (and the motivation for writing this crate).

fn write_data(&mut self, start_addr: usize, buf: &[u8]) {
    for s in SectorizeIter::new(SECTOR_SIZE, start_addr, buf.len()) {
        let mut existing = self.read_slice(s.sector_index * SECTOR_SIZE);

        // only write if there's a difference
        if existing[s.sector_start..s.sector_end] != buf[s.input_start..s.input_end] {
            existing[s.sector_start..s.sector_end]
                .copy_from_slice(&buf[s.input_start..s.input_end]);
            self.write_sector(s.sector_index * SECTOR_SIZE, &existing);
        }
    }
}

No runtime deps