Skip to content

Rethinking NorFlash and writing abilities #58

Open
@diondokter

Description

@diondokter

Hi all!

In #57 an extension was proposed to add a second write must be 0 ability.
However, the way this is done doesn't really help anyone who wants to abstract over the different write abilities.

Personally for sequential-storage I want to do these two things:

  • Put bounds on functions so people can only call them with a flash that has the correct write ability
  • Have general APIs that can still respond to the write abilities (to e.g. adapt the memory layout to thee abilities)

This last one isn't possible at the moment, but hasn't been a big issue for me thus far.

Currently there are two (cap?)abilities:

  • Write once
  • Write twice, second write is bitwise AND

It's worked ok so far, but when adding more abilities like Write twice, second write is 0, things get more complex.
To support this in s-s without making things worse for real multiwrite flashes, we need to be able to query the abilities in general APIs that can't use the trait bounds (because they need to be general).

So, I propose we discuss something along these lines: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4479663da7dd48eb5ad8402260d75d24

It's verbose sadly, but it does make everything work. If someone can come up with something better I'm all ears!

We need the chain of traits because const generics aren't stable yet and we can't put const bounds on our functions and structs.
We need the associated consts so we can query the abilities on APIs that only use the NorFlash trait as a bound. (This would be solved by reflection, but alas)

This is now all implemented as an associated type to make the implementation less bug-prone.

Could this be a good direction to go in?

There's also #56 which proposes block devices like SD cards.
Now I've been thinking about how to run s-s on SD cards and there's no good way since they would be separate traits.
However, that might not be necessary with the write abilities I propose here. Maybe we can unify these all and make one trait based on the current NorFlash trait and add a Block write ability? I don't know, maybe there are reasons why that can't work...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions