-
Notifications
You must be signed in to change notification settings - Fork 2k
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
drivers/periph: reworked I2C driver #4926
Conversation
Related: #3366 |
* | ||
* @param[in] dev I2C peripheral device | ||
* @param[in] address bus address of the target device | ||
* @param[in] addr 7-bit device address (right-aligned) |
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.
👍 good clarification
@@ -140,147 +145,110 @@ int i2c_init_master(i2c_t dev, i2c_speed_t speed); | |||
* @param[in] dev I2C device to access | |||
* |
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.
missing @param[in] speed
. What's the purpose of adding the speed to the i2c_acquire
?
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.
as the bus is shared, we have the situation that multiple devices use the bus with different clock speeds. By moving the clock selection into the acquire function, this is now possible.
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! good catch! 👍
So is everyone ok with these interface changes? Then I would to and adapt the existing implementations so we can test them and bring this into the release... @gebart, @PeterKietzmann, @kYc0o, @jfischer-phytec-iot, @lebrush, @LudwigKnuepfer: ping. |
I'm OK with the changes, it adds flexibility and the code it's really understandable. It will break all the drivers using i2c right? |
I would say that moving the speed to the acquire function is even more signs that it would make sense to introduce a state struct for keeping the hardware settings between calls. Are the periph drivers expected to precompute all possible speed settings inside the init function and then use a lookup to find the right set of register values depending on the speed setting when a driver acquires the bus? |
It may not be the best idea to mix speeds on the i2c bus since it does not provide a discrete Chip Select signal.. The slowest devices may undersample the bus and read the aliased signal as valid data and try to reply. Can we keep the bus speed selection in the init function? See: http://electronics.stackexchange.com/questions/62365/is-i2c-mixed-frequency-possible |
I agree with @gebart that mixed bus speeds could be dangerous for i2s slaves as there's no dedicated CS lines like in SPI. Though I never tested a setup like this... Other than that, your proposal looks good to me. |
I don't see the valid (!) I²C answer |
b981dae
to
b286cd8
Compare
@gebart: you are completely right, using different bus speeds for different devices is not an option - I don't really know what I was thinking there... So I have a new, even simpler proposal: why don't we just specify the speed valued in the |
@LudwigKnuepfer: not sure I understand your comment, why do you want to have NACK as return value? We can group errors in two major groups: errors during addressing and errors during the actual data transfer -> hence |
In case the slave does not reply with an ACK (replies with a NACK), this is not an error per se.
I still don't know what qualifies as a data/address error. For example: In my understanding of I2C a NACK is a valid communication pattern, not an error. |
this would be an |
IC, thank you for the clarification. As a NACK is a well-defined and named part of regular communication I would not call it error or an exception, but a NACK. |
The problem I see with NACK is, that it is very specific, but there could be, dependent on the hardware, also other error cases. Having a more generic return value would make the interface easier to implement. |
i2c_speed_t speed; /**< I2C bus speed */ | ||
uint8_t rcc_bit; /**< bit in the rcc register */ | ||
uint8_t irqn; /**< IRQ channel */ | ||
} |
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.
Incomplete code ;)
} i2c_conf_t;
/** @} */
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 know :-) Will fix as soon as we decide for the interface changes
That's what I thought - so define ACK, NACK and a generic other error case. |
Ok, again: just returning NACK makes no sense, was the NACK on address, on data byte. I say that one exception return value for the address byte and one for data bytes fully sufficient for device drivers that build on top of the interface. |
I agree that the two types of NACK should be differentiated. |
b286cd8
to
53adfc5
Compare
@LudwigKnuepfer: how does this look now? |
@haukepetersen , thanks for your feedback. I've published a PR with my code as #6205 - the code should merge cleanly, but needs to be reviewed. In the future, I would happily participate in remodeling the implementation - even if my contribution is indeed minimal. |
@ant9000 great! Can't promise anything but I will try to test your PR this week. And just keep a watch on this PR so you can jump in when we move on - your help is much appreciated! |
@haukepetersen, glad to be of help - count me in for the future. Hope that my PR can be useful, waiting for a tip from you when you get the time for it. Antonio |
postponed, due to high impact changes |
No significant progress for over a year and it seems @haukepetersen gave up on this task. Closing as memo for now. |
@miri64 I tend to reopen this one. Even though @haukepetersen might have "given up on this task" it is still on our TODO list. This PR acts as place to showcase and discuss the actual API proposal. Objections? |
Mh.. I'd rather prefer that you open an issue for that. Having an open (and stale) PR that serves as a show-case seems like a bad idea. |
I know this has been stale for too long, but IMHO the proposed interface changes are still valid and the base for the (at some time) coming remodeling. So in this case I disagree with closing this PR! |
sorry, I mixed up PR numbers. #6576 is the one that should remain open, so I agree with closing this PR. |
Analog to #4780: This PR brings the I2C driver up-to-date with our current discussions. But as in #4780, we need to agree on this concept until it makes sense to touch the existing implementations...
As analyzed in #4758: the
i2c
peripheral is a shared bus allowing atomic access, implying that it needs to be acquired/released before/after usage and should be powered off when not in use.Main changes:
TODO:
acquire/release
and more