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

[Bug] Some TFT configurations (and possibly other GPIO action) has problems with large GPIO #'s #139

Closed
robertlipe opened this issue Jul 26, 2023 · 6 comments
Labels
SW Enhancement New feature or request for software.

Comments

@robertlipe
Copy link

This doesn't actually affect me. It's my civic duty to report it and help analyze it because the next person to be affected by it may not be as mellow about it. I'm just killing time waiting for stupid python in stupid platformio to burn two minutes to analyze my stupid dependencies the 11 billionth's time before it performs a two second stupid action. (Hmm. mybe I should work on that mellow... On with the show!)

Describe the bug
The LilyGo configuration, like many that are possible on the ESP32S3 which has something like 45 GPIO registers has register numbers above 31 and thus, incapable of fitting into a processor word.

To Reproduce
Steps to reproduce the behavior:
~/.platformio/penv/bin/pio run --upload-port $PORT --target upload -e lilygo-t-display-s3

Hold your eyes open and don't blink when the yellow text scrolls by.

Expected behavior
Glorious, warning-free compilation.

Screenshots
If applicable, add screenshots to help explain your problem.

Please complete the following information:
~/.platformio/penv/bin/pio --version
PlatformIO Core, version 6.1.9

Additional context

Catch one warning in isolation and it's "obvious" what's going on.

.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c: In member function 'uint8_t TFT_eSPI::readByte()':
: warning: right shift count >= width of type [-Wshift-count-overflow]
.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c:115:16: note: in expansion of macro 'TFT_D0'
b = (((reg>>TFT_D0)&1) << 0);

Shifting anything 39 bits in a 32-bit processor isn't going to fly. This is a really common problem in embedded-land that we're starting to see even on the big-boys. The JH-7110 has some internally remapped GPIO numbers that are larger than 64-bits (!) so even that code needs reworked when ported to these newfangled SoCs with their crazy-axe register configuration blocks.

I think that's technically undefined behaviour; some systems will shift all the bits through and give a zero. Some will do a rotate (exactly what this case DOESN'T need) and some systems will toss an execution exception and stall. If these shifts are used in address calculations (common) it can result in memory in the wrong place being scribbled on. That's clearly bad.

I think this is an upstream library. If it's Bodmer TFT, there's surely an update that addresses this because it seems unlikely we're the first to run into this. That style of code (The PIO abstraction over the Arduino abstraction over the IDF abstraction for a #define for a number from 1-256) for something that compiles into one opcode can be depressingly hard to pencil-whip and that SPI - style of code where cmd might be an extra bit or an extra store completely can just be a mess to work through.

If you're lucky, someone else already has done this. :-)

Log
If applicable, add serial log output to support the analysis.

.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c: In member function 'uint8_t TFT_eSPI::readByte()':
: warning: right shift count >= width of type [-Wshift-count-overflow]
.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c:115:16: note: in expansion of macro 'TFT_D0'
b = (((reg>>TFT_D0)&1) << 0);
^~~~~~
: warning: right shift count >= width of type [-Wshift-count-overflow]
.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c:116:16: note: in expansion of macro 'TFT_D1'
b |= (((reg>>TFT_D1)&1) << 1);
^~~~~~
: warning: right shift count >= width of type [-Wshift-count-overflow]
.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c:117:16: note: in expansion of macro 'TFT_D2'
b |= (((reg>>TFT_D2)&1) << 2);
^~~~~~
: warning: right shift count >= width of type [-Wshift-count-overflow]
.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c:118:16: note: in expansion of macro 'TFT_D3'
b |= (((reg>>TFT_D3)&1) << 3);
^~~~~~
: warning: right shift count >= width of type [-Wshift-count-overflow]
.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c:119:16: note: in expansion of macro 'TFT_D4'
b |= (((reg>>TFT_D4)&1) << 4);
^~~~~~
: warning: right shift count >= width of type [-Wshift-count-overflow]
.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c:120:16: note: in expansion of macro 'TFT_D5'
b |= (((reg>>TFT_D5)&1) << 5);
^~~~~~
: warning: right shift count >= width of type [-Wshift-count-overflow]
.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c:121:16: note: in expansion of macro 'TFT_D6'
b |= (((reg>>TFT_D6)&1) << 6);
^~~~~~
: warning: right shift count >= width of type [-Wshift-count-overflow]
.pio/libdeps/lilygo-t-display-s3/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c:122:16: note: in expansion of macro 'TFT_D7'
b |= (((reg>>TFT_D7)&1) << 7);
^~~~~~

@BlueAndi
Copy link
Owner

I saw this as well and the issue itself should be fixed in the TFT_eSPI repository. Pixelix at the moment just uses the fork of this lib, provided by HajuSchulz.
@HajuSchulz Can you take care?

@nhjschulz
Copy link

I'll check the current state of TFT_eSPI regarding this over the weekend. In early S3 days only this somewhat hasty fork existed that I pinned.

@robertlipe
Copy link
Author

robertlipe commented Jul 27, 2023 via email

@nhjschulz
Copy link

The GPIO access problem got fixed meanwhile in the official TFT_eSPI repository. I'll prepare a push request to replace the early pinned S3 support patched one with it.

BlueAndi added a commit that referenced this issue Jul 30, 2023
Fix issue #139: S3: Switch to official eSPI_TFT library
@robertlipe
Copy link
Author

robertlipe commented Jul 31, 2023 via email

@BlueAndi BlueAndi added the SW Enhancement New feature or request for software. label Jul 31, 2023
@BlueAndi
Copy link
Owner

BlueAndi commented Jul 31, 2023

Thanks Robert and Norbert! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SW Enhancement New feature or request for software.
Projects
None yet
Development

No branches or pull requests

3 participants