-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add writeto_then_readfrom to I2C API. Deprecate stop kwarg. #2012
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
Conversation
This is going to break a lot of stuff. Would it be possible to have the |
I wonder if there are pathological I2C chips for which we still want fine control of |
the I2C FRAM needed repeated-start for reading the device id but not for data. https://github.com/adafruit/Adafruit_FRAM_I2C/blob/master/Adafruit_FRAM_I2C.cpp#L109 most chips specify they want a stop but will work fine with repeated start, so we default to repeated start in the register library and it works just fine. i prefer we keep |
Well, if a chip wants a stop, then that's fine — you can do that simply with a second transaction. The problem is when you want to do a repeated start, without the stop. But I think it would be nice to have a version in which both |
@ladyada It's not clear to me that we need fine grained control of stop. Looking at the FRAM, the device ID read looks like the standard write (address 0xf8 has data direction 0 for write), no stop, repeated start, read (0xf9 is the same address with direction bit high) that we'll now have with the composite call. I'm all for not limiting ourselves to what Linux can do. However, in this case I think Linux does everything that I2C devices need and by aligning our APIs through implicit control of stop we'll make maintenance of libraries easier. Going forwards if a stop bit isn't desired, the only way to do it will be writeto_then_readfrom. To have a stop bit, one simply calls writeto and then readfrom_into. @deshipu Is there a reason you are using busio directly rather than with BusDevice which already does the checking for writeto_then_readfrom? Couldn't it also work on rPi if it was switched over? 5.x stable is a couple months away still and breaking code is the most reliable way to get it updated. Leaving both options also leaves the option not to update it. I'm happy to help fixup code if it's open source and would prefer to break and fix now to have it finished. |
im ok with it for 5.0 :) |
Do we need to test this with an FRAM breakout or do we know it will work? |
it shoud be fine, if you need a stop, you'd implement as two commands instead of one... |
@tannewt BusDevice is huge in terms of memory and rather slow. I'm controlling displays on PewPew with I2C, so speed is rather important. I'm not concerned with me failing to update the library. The scenario I'm concerned with is me updating the library, which then fails to work with all the older versions of CircuitPython, because people didn't update their boards immediately (or can't do it, for instance because they use HUZZAH). That would mean I either would have to effectively support twice as much code (and have confusing releases for different versions), or have boilerplate code detecting what APIs are available and branches that do different things depending on that. I'm not particularly thrilled by either. Having a release with both |
@deshipu I'd suggest snagging I don't want to leave both because it means 1) new code could be added using the old way and 2) existing code with the old way may not be found and updated. @dhalbert Please weigh in on this PR. |
I have been trying to avoid this because I don't have much background in it. 😃 . @deshipu, if you can do the attribute check as suggested by @tannewt, then that might be good enough. If busdevice is too slow, we should consider how to speed it up (make it native?). In the code link above, we could at least check for the attribute just once and remember the result. |
I rest my case. If we ever come upon a chip that requires an interaction that we don't support, we can always add it. |
writeto_then_readfrom has been added to do a write -> no stop -> repeated start -> read sequence. This is done to match the capabilities of Blinka on Linux. Code that uses stop=False will not work correctly on Blinka. To fix, if stop=False then use writeto_then_readfrom otherwise use writeto then readfrom_into. First step in micropython#2082
7e59305
to
82d436d
Compare
Ok, I've done as @deshipu asked. writeto_then_readfrom is added and stop is documented as deprecated. Once 5.x is stable we can remove the stop= kwarg. Please take another look. |
Also, switch CIRCUITPY_BITBANG_APA102 to makefile setting so it can alter included files
@dhalbert please take another look. Had to turn off bitbangio for itsy bitsy. |
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.
Too bad about bitbangio. In the long run we need to find some more space somewhere, like LZW message compression, or ... Worth discussing, later, but let's get an alpha out.
writeto will now always output a stop bit and writeto_then_readfrom
has been added to do a write -> no stop -> repeated start -> read
sequence. This is done to match the capabilities of Blinka on Linux.
Code broken by this change will have been broken on Blinka anyway.
To fix, if stop=False then use writeto_then_readfrom otherwise use
writeto then readfrom_into.