Skip to content

ESP8266: Fix pin locking during busio.SPI.configure #938

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

Merged
merged 1 commit into from
Jun 16, 2018

Conversation

sommersoft
Copy link

Fixes Issue #642.

hspi.c->spi_init_gpio() is now bypassed for both construct and configure.

Tested pin locking for MOSI & MISO. Passes. Tested that SPI still works with a TFT display. Passes.

@sommersoft
Copy link
Author

I meant to note that I did not test one-way SPI (MOSI only, MISO only). I don't have a test case for that, so feel free to wait for someone who does/can. I could hook up the Saleae, but not sure that is a valid test...

@dhalbert
Copy link
Collaborator

I meant to note that I did not test one-way SPI (MOSI only, MISO only). I don't have a test case for that, so feel free to wait for someone who does/can. I could hook up the Saleae, but not sure that is a valid test...

I think a sufficient test for MISO is to jumper the MISO pin high and see if you read 1's and then hold it low and see if you read 0's. For MOSI you could use the Saleae and just send data, or even just send it to an LED: all 1's and all 0's.

It's equally important just to test that supplying None for either pin doesn't crash.

@sommersoft
Copy link
Author

sommersoft commented Jun 15, 2018

One last note that I missed... Queue Where is my mind?

I removed the passing of HSPI arguments, since it never passed anything but that. I didn't see anywhere else that it was needed for busio.SPI either.

@sommersoft
Copy link
Author

@dhalbert

It's equally important just to test that supplying None for either pin doesn't crash.

>>> import board, busio, digitalio
>>> spider = busio.SPI(board.SCK, board.MOSI, MISO=None)
>>> spider.try_lock()
True
>>> spider.configure(baudrate=100000)
>>> gp = digitalio.DigitalInOut(board.GPIO12)
>>>

That is what I ran for both to check construction and pin lockout.

I can run those with the Saleae. Just wasn't sure if that would pass muster for a real-world test.

@dhalbert
Copy link
Collaborator

I think those tests are fine. I tested bidirectional SIPI just by jumpering MOSI to MISO.

@dhalbert
Copy link
Collaborator

I mean I think testing with the Saleae woudl be fine for actually see that levels show up.

@tannewt tannewt requested a review from dhalbert June 15, 2018 23:55
@sommersoft
Copy link
Author

sommersoft commented Jun 16, 2018

MOSI Only:

>>> import busio, board
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=None)
>>> spi.try_lock()
True
>>> buffer = bytearray(b'0xff\0xff\0xff')
>>> spi.write(buffer)
>>>

mosi_only

I couldn't get MISO only to register anything. I tried using a gpio just set as high/low, as well as another board connected as a SPI Master. Reading SPI tea-leaves is not my forté.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks very much! Tested MISO-only with a jumper to 3.3V and ground, got expected data.

@dhalbert dhalbert merged commit be5eb91 into adafruit:master Jun 16, 2018
@sommersoft sommersoft deleted the esp_busio_fix branch September 26, 2019 02:35
@bogus105
Copy link

Hi Guys,
it looks like i can find the answer for my problem here:) on esp8266-12e i'm using TFT module via HSPI however i'm using unidirectional communication thus MISO (GPIO12 aka D6) is not connected to TFT. The problem is i need to use GPIO12 to control TFT LED pin responsible for backlight control - thus one is out of SPI protocol, just set H to turn the backlit on, L to turn it off).
Initially i thought i damaged PGIO12 as even if i set its mode to OUTPUT (yes, i'm using Arduino IDE) i can't see any change on the phisical pin when giving commands to go HIGH or LOW.
Could you explain me if and how can i 'unlock' GPIO12 to use is as general purpouse pin? I tried to understand what you guys have wrinnet here but no luck:)
Thanks!

@bogus105
Copy link

it looks like i found solution: first i've initiated SPI and after that i've set GPIO mode to OUPUT. Now i can control this pin as normal and TFT works as normal as well:)

@palsayantan
Copy link

It doesn't work if you set GPIO12 as input. Any solution to that?

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.

4 participants