-
Notifications
You must be signed in to change notification settings - Fork 25
Adding support for the SPI stack chips #10
base: master
Are you sure you want to change the base?
Conversation
…ich exports the BlockDevice and Read trait and formatting the crate with cargo fmt
…ich exports the BlockDevice and Read trait and formatting the crate with cargo fmt
Co-Authored-By: Jonas Schievink <[email protected]>
Co-Authored-By: Jonas Schievink <[email protected]>
Co-Authored-By: Jonas Schievink <[email protected]>
Co-Authored-By: Jonas Schievink <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, this looks pretty good!
It would be nice to address the code duplication though. Also, please run cargo fmt
on the code.
#[allow(missing_debug_implementations)] | ||
pub struct Die0; | ||
#[allow(missing_debug_implementations)] | ||
pub struct Die1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can just #[derive(Debug)]
, there shouldn't be any harm in that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also make them enum
s instead of struct
s since they're just used as type markers
src/w25m.rs
Outdated
} | ||
|
||
#[derive(Debug)] | ||
pub struct Flash<DIE0, DIE1, DIE> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add documentation to this type that explains what the type parameters are for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DIE
could also be bounded by an ActiveDie
trait, which would be implemented by Die0
and Die1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, DIE
is actually supposed to be a type state, it doesn`t have to fulfill any trait bounds it is just there so rust knows which switch_die implementation it is supposed to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. If you bound it by a trait that is only implemented by the 2 types that are supposed to be used though, users wouldn't be able to name invalid Flash
types like Flash<Bla, Bla, ()>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean technically the user is just supposed to _ the type state as the constructor only produces Die0 types, so if a user starts to mess around with the state parameter he is most likely doing something wrong isn't he?
src/w25n.rs
Outdated
|
||
// write to config register 2, set BUF=0 (continious mode) and everything else on reset | ||
this.command(&mut [Opcode::WriteStatus as u8, 0xA0, 0b00000010])?; | ||
this.command(&mut [Opcode::WriteStatus as u8, 0xB0, 0b00010000])?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, could this perhaps be integrated into the w25m Flash
? Then we wouldn't have to duplicate the series25 module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we still have to duplicate it because of the method the w25n chips use to read and write based on their internal buffer which is a thing the series25 chips are not doing at the moment
Sadly I was only able to get the API for the user to this form
If rust would not explicitly require me to place the two type parameters for the W25N it obviously knows already there it would look a lot more beautiful but for some reason it does that