-
Notifications
You must be signed in to change notification settings - Fork 222
GPIO in I2C fixes #260
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
GPIO in I2C fixes #260
Conversation
cmd = bytearray(self._idle * self._ck_delay) to add self._ck_delay because the timing wasn't allowing the bus to go idle with correct timing before a start or repeated start. Data was changing low at the same time as clock going high if the bus was in the relax=False state.
…reset if reset=False. Remember to use Freeze=True on close when testing.
_gpio_mask was being updated based on the direction, but that wasn't correct. Now the mask of available gpio is set at startup, and only direction changes.
this forces the outputs to move to new mode NOW without altering data on the pins. The default is False to prevent interferance with legacy uses, however new users might naturally expect this to be True.
… _i2c_mask can be 6-bit in some cases
I think there is more finesse that could be done here, for example, wide port reads and 8 bit data requires being careful with gpio mask outside the class. I think that _gpio_dir should be & with self._gpio_mask in _set_gpio_direction. that's for another day.
…use some programs which are poorly written to give unexpected results. however there are many cases in which programs may wish to write data to pins prior to removing them from tri-state. I will examine this next and make sure that values sent are the 'next used' when flipping the pin mode
add with_input to write_gpio add immediate to set_gpio_direction If immediate and with_input, the user can have pins set to low as outputs and use them as open_drain pins. in the original implementation without immediate, the gpio pins would not take a new state until a write_gpio occured. in the original implementation without _gpio_last it was hard or maybe impossible to get the pins seemlessly back to a prior state if tri-state was used. This version also has prior changes to make the gpio_mask a permanent fixture of the instance, only direction and state should be changing. Note that with_input = True will not be backwards compatible with programs that "want" an error when "writing" to inputs. I don't think this is a big deal because those were errors so nobody was likely to be using it that way.
meant passing kwargs or adding both as explicits even when only one or the other is used.
Also it appears i didn't make this as a new branch and some older commits are still in there. I can retract this and make a new one properly if needed. |
if the reset code gets figured out, this should be modified to pull the state of the pins somehow, but in the present implementation this covers all use cases.
allows full setup of gpio states, tri-state and drive state when opening the device.
don't use pyusb 1.2.0
I found a shortcoming with my original fix, and added a commit to init _gpio_last from the kwargs. |
I'm no longer able to understand the proposed PR. Could you close this PR and open a new one with logical change sets in each commit, so I can review it? Thanks a lot. |
i.e. https://github.com/eblot/pyftdi/pull/260/files seems to contains changes that already live in master... |
Absolutely. I'll close this and make only the targeted changes. my bad for not catching the lack of a branch. |
In this branch I worked on the I2C module and use of GPIO.
_gpio_mask was made a permanent fixture (after all they don't change)
_gpio_last was added to keep track of users last state for the pins
immediate was added to set_direction so that a change of in to out or out to in would take effect immediately (new default behavior)
with_input added to write to allow "writes" to gpio's set as inputs, which is useful for open-drain behavior when combined with gpio_last (new default behavior). This suppresses an error message that used to occur, but since no reasonably functional code would be looking for an error it should work for everyone.
This version should be backwards compatible with any existing code.
Also tried to more completely add the reset/freeze options for opening/closing the device but my testing with this was inconclusive and I have to move on. I2C works fine, but gpios' would not work if reset=False. There might be more to come on this as it's an interesting idea.
Tested with C232HM-EDHSL-0