-
Notifications
You must be signed in to change notification settings - Fork 11
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
read and write in send #2
Conversation
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.
Also, I haven't tested these changes on hardware
src/spi.rs
Outdated
@@ -22,6 +22,7 @@ where | |||
mosi: Mosi, | |||
sck: Sck, | |||
timer: Timer, | |||
read_val: u8, |
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.
Seems to me that read_val
should be Option<u8>
, so that read()
can return an error if it's called when no data is available. Then read()
can be
fn read(&mut self) -> nb::Result<u8, Error> {
if let Some(byte) = self.read_val.take() {
Ok(byte)
} else {
Err(Something)
}
}
But I also don't think this is strictly required by the embedded-hal
trait, it's just a way to help catch invalid uses of your interface.
src/spi.rs
Outdated
self.read_val = (self.read_val << 1) | 1 | ||
} else { | ||
self.read_val = self.read_val << 1 | ||
} |
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'm not sure this code is correct in the case where self.mode.phase == CaptureOnSecondTransition
. In that case in the original implementation, you have a clock transition before reading the first bit. Here, you immediately read the pin on entry, which may be in an indeterminate state depending on the peripheral to which you're interfacing.
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 think I may be wrong about something here -- I'll try to prove/disprove this problem, and get back to you
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.
Nope, my comment is correct. Sorry for the confusion
@austinglaser Try now. |
LGTM, at least as far as I can tell without actually testing on hardware |
Fixes #1
@austinglaser Please review. Is this a correct implementation now?