Bugfix ESP32: I2C pin defs used instead of the SPI pin defs (fixes pin remapping for HW SPI on ESP32 platform) #2123
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.
Follow-up from:
#377 (comment)
Platform
Arduino / ESP32-S3
Display
OLED SSD1309 (SPI)
Summary
A custom PCB requires non-standard SPI pin assignments for an SSD1309 OLED display driven by an ESP32-S3.
Everything has been tested functional with bit-banged SW_SPI (U8G2_SSD1309_128X64_NONAME2_F_4W_SW_SPI constructor) on the required "custom" SPI pin assignments. However, the display manages a very poor 18-19fps frame rate:
It appears in the U8G2 code that there is some proviso for manual pin assignments on the HW_SPI functionality. However, after creating a custom constructor to utilize this functionality, some notable bugs were discovered in the U8G2 HW_SPI setup functions: namely, that the "manual pin assigments" query the I2C pin assignment registers, instead of the SPI pin assignment registers (which only the latter are set by the custom HW_SPI constructor).
This error results in the manual SPI pin assignments being effectively inaccessible from the U8G2 constructors.
After correcting the "I2C pin assignments" to "SPI pin assignments", the U8G2 library can utilize the desired manual pin assignments with the SSD1309 OLED screen, showing a huge marked improvement in framerate to approximately 230fps (more than 10 times faster than SW_SPI), as seen here:
One further improvement that can be made to HW_SPI is to utilize a relatively unknown SPI function for bulk SPI writes on the ESP32, namely "SPI.writeBytes". (It has been mainstream in Arduino-ESP32 code since at least 2017.) Comments in the U8G2 code indicate that the "SPI.transfer" function has been found to overwrite the input buffer; "SPI.writeBytes" does not overwrite the input buffer (this has been tested).
Switching to "SPI.writeBytes" results in a further improvement in frame rate to 374fps, an easy 35% improvement from the "byte transfer" frame rate, as seen here: