-
Notifications
You must be signed in to change notification settings - Fork 23
Feature/polling #12
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
base: master
Are you sure you want to change the base?
Feature/polling #12
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.
Interesting. Thank you for this proposal.
A couple of thoughts:
- It could be that in some applications this repeated polling is undesirable, since it blocks the I2C bus. I think a straight-forward solution would be to add a
disable_pollingmethod. Could you do that? - Looking at the
Storage::waitmethod, it seems we could simplify it by implementing the loop directly instead of using therepeat_timeout!andnb::block!with something like:
// I just wrote this down, please excuse small errors.
loop {
match self.count_down.wait() {
Err(nb::Error::Other(e)) => { break Err(e) }
Err(nb::Error::WouldBlock) => {
if self.eeprom.polling {
match self.eeprom.read_byte(0) {
Ok(_) => { break Ok(()) } // done
Err(Error::I2C(_)) => { } // not ready, repeat
Err(e) => { break Err(e) } // TODO this error probably needs some mapping to the outer error type
}
}
}
Ok(_) => break Ok(()),
}
}TODO:
- Remove embedded-timeout-macros if solution above is viable
- Changelog
- Tests
- Docs, README update
eldruin
left a comment
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.
Would you be able to add some tests? I would take care of the rest.
eldruin
left a comment
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.
Thank you for adding the tests! only a small thing left
| // Basically, we have to wait before any I2C access and ensure that the countdown is | ||
| // running again afterwards. | ||
| count_down.start(Duration::from_millis(0)); | ||
| count_down.start(Duration::from_millis(5)); |
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.
Any reason for this change?
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 guess @eldruin is right and the initial countdown should be zero. The rationale is already given in the comment above.
| embedded-hal = "0.2" | ||
| embedded-storage = "0.2.0" | ||
| nb = "1.0.0" | ||
| embedded-timeout-macros = "0.3" |
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.
| embedded-timeout-macros = "0.3" |
|
Hi, |
|
I will merge this and do the last fixes myself on it over the next few days. |
Added polling support to improve performance.