Skip to content

Adds in my alternate storage traits #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

tl8roy
Copy link

@tl8roy tl8roy commented Dec 11, 2020

Closes #28
These are a set of traits that can be used for on and off board storage.

Each function is split into its own trait to deal with the different types of memory (Particularly Read Only vs Read/Write)

MCU Flash impl:
https://github.com/tl8roy/alt-stm32f30x-hal/blob/master/src/storage.rs

I2C EEPROM impl:
https://github.com/tl8roy/eeprom24x-rs/blob/master/src/eeprom24x.rs

SPI PSRAM implementation:
https://github.com/tl8roy/esp_psram
This is a completely new implementation using SPI.

@eldruin
Copy link
Member

eldruin commented Dec 11, 2020

There was relevant discussion about this at: rust-embedded/embedded-hal#241

@MathiasKoch MathiasKoch changed the title Adds in my alerntate storage traits Adds in my alternate storage traits Dec 11, 2020
type Error;

/// Returns the start address of the device
fn try_start_address(&mut self) -> nb::Result<Address<U>, Self::Error>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it is a good idea to make these fallible. This will complicate the usage a lot. The same goes for try_total_size and try_page_size.

///
/// For Flash storage, the write functions can't set a bit to 1.
///
/// For non flash devices, this trait is not required, but it can be used to erase data as recommended by the device (EG set all fields to 0).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the behavior of these functions is device dependent, this trait is not really useful for generic drivers, because the driver has no way of knowing what the ErasePage trait will do. By driver I mean a file system implementation for example. That's why I proposed distinct traits for different kinds of storage with well defined behavior.

/// intended to be used for when there is a optimized method of reading multiple bytes.
///
/// Iterating over the slice is a valid method to ```impl``` this trait.
pub trait MultiWrite<Word, U> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the expected behavior of write? ANDed like flash, always as is or device specific?

}

/// Page represents an unsigned integer that is a Page ID in the device memory space.
pub struct Page<U>(pub U);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "Page"? For NOR flashes this is typically the maximum number of bytes you can write in one go. Since you used it further down in try_erase_page I suspect you mean the minimum erase size of the device. For NOR flashes this is typically a block. I thought about having something like that too, but erase sizes in flashes can be quite complicated, so I didn't know how to model that.

@Sympatron
Copy link
Contributor

Your approach is a little bit more granular. That might be useful for read only storage for example.
Also your Address and AddressOffset structs are more clever than what we have at the moment IMO.

My biggest concern is that this crate should clearly separate device or technology dependent behavior from a transparent/abstract storage that Just Works™. Otherwise it is not possible to write generic efficient file systems optimized for specific technologies like flash.

@MathiasKoch
Copy link
Collaborator

Will close this, as I think we have reached a concensus around traits in #12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants