-
Notifications
You must be signed in to change notification settings - Fork 221
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
I2C: Prefer compile-time checks over runtime checks where possible, prefer a fallible API over panics. #2831
Conversation
esp-hal/src/i2c/master/mod.rs
Outdated
@@ -92,6 +92,9 @@ const MAX_ITERATIONS: u32 = 1_000_000; | |||
pub enum Error { | |||
/// The transmission exceeded the FIFO size. | |||
ExceedingFifo, | |||
#[cfg(any(esp32, esp32s2))] | |||
/// Read limit of 32 bytes or transfer limit of 31 bytes exceeded. | |||
ExceedingTransactionSize, |
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.
Why is this different from ExceedingFifo
?
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 was not sure if ExceedingFifo
is descriptive enough (?) for this error...
I'm still not sure though, so if you think we can re-use already existing ExceedingFifo
- I'll do the fix
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.
ExceedingTransactionSize
doesn't immediately make sense to me, as I'm not sure what exactly had been exceeded.
ExceedingTransactionSizeLimit
is probably what you want.
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 was not sure if ExceedingFifo is descriptive enough (?) for this error...
It shouldn't ever happen, otherwise we have a bug. The HAL is responsible for papering over length issues if possible. (This also means that a panic is actually not a bad tool here - it's a bug to hit it).
I'd rather not introduce a new error variant for something that we shouldn't let happen in the first place. But trying to read/write longer data than what fits into the FIFO is IMHO pretty much covered by ExceedingFifo
. If that isn't descriptive enough, then it should be made more descriptive. Note that we already return that error in setup_write
or setup_read
for a very similar problem.
0ba4cb0
to
0b23469
Compare
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.
Given we will move the validation phase to before we do any register operations (and improve validation in general, provide more helpful logs) this looks good to me (and also those improvements won't affect the public API)
2a4455d
to
54e9ca6
Compare
54e9ca6
to
f5278f7
Compare
pub enum ConfigError {} | ||
pub enum ConfigError { | ||
/// Provided bus frequency is invalid for the current configuration. | ||
InvalidFrequency, |
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.
Next fun issue, now we have a precedent of TimeoutInvalid
, should this be FrequencyInvalid
?
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, yes - that would be better
Description
closes #2767