Skip to content
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 GPIO fix and SPI GPIO fix for _gpio_mask #277

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

TedKus
Copy link
Contributor

@TedKus TedKus commented Dec 12, 2021

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

TedKus and others added 4 commits December 11, 2021 20:25
- 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.
@eblot
Copy link
Owner

eblot commented Apr 6, 2024

Hi,

I know this is a very old PR and that I've not been working on PyFTDI for nearly two years...
I did give a quick try to this new branch, but it seems that the I2cReadGpio still fails.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants