i2C GPIO fix and SPI GPIO fix for _gpio_mask#277
Open
TedKus wants to merge 4 commits into
Open
Conversation
- moved self._gpio_mask into init _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. - add immediate option to set_gpio_diection this forces the outputs to move to new mode NOW without altering data on the pins. The default is False to prevent interference with legacy uses, however new users might naturally expect this to be True. in the original implementation without immediate, the gpio pins would not take a new state until a write_gpio occured. - add immediate to gpio().set_direction - in write() allow "writing" gpio "outputs" to gpio's set as "inputs". This may cause 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. - add _gpio_last for user output state of GPIO If immediate and with_input, the user can have pins set to low as outputs and use them as open_drain pins.
Untested with SPI, but functionally identical to I2C useage.
Owner
|
Hi, I know this is a very old PR and that I've not been working on PyFTDI for nearly two years... I did not dig into the code, but if you are still working with PyFtdi it would be nice to merge this PR. Do you have some test that demonstrates the issue and shows your PR fix it? Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes issues in #233 which were followed up in #270 and #260 (260 closed for being a sloppy commit)
The _gpio_mask was being reduced every time a pin was set to tri-state. Once put into tri-state the pin could not be written, or removed from tri-state back to active because the mask test forbid it as 'non existent'
with the changes in this branch the gpio_mask becomes something setup for the ftdi device connected to and it remains static.
Some enhancements were made to allow use of pins as open-drain by setting driving state low and using tri-state as the state switch.
Perhaps a future branch should add the ability to read the i2c/spi pin states to check for common hardware issues (floating, stuck high, stuck low etc).
In this branch I worked on the I2C and SPI 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 added the freeze options for closing the device in depreciated terminate()
Tested with C232HM-EDHSL-0