Skip to content

Commit

Permalink
New environment: t-display-s3
Browse files Browse the repository at this point in the history
Forced square blocks (will be configurable in the future)
Brightness control
Pin allocation
  • Loading branch information
Victoare committed May 3, 2024
1 parent 439aba5 commit 7380b36
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 48 deletions.
98 changes: 83 additions & 15 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -842,20 +842,21 @@ upload_speed = 921600
build_flags = ${common.build_flags_esp32} ${esp32.AR_build_flags}
# -D WLED_DISABLE_BROWNOUT_DET
# -D WLED_DISABLE_INFRARED
-D SERVERNAME="\"WLED-TTGO\""
-D SERVERNAME="\"T-DISPLAY\""
# -D WLED_RELEASE_NAME=lilygo_tdisplay_s3
# -D USERMOD_RTC
# -D DEFAULT_LED_COUNT=16*9
-D LEDPIN=12 #def 16 collides with TFT_DC
-D USERMOD_TTGO_TDISPLAY_OUTPUT
; digital LED strip types - uncomment only one ! - this will disable WS281x / SK681x support
; -D USE_APA102
; -D USE_WS2801
; -D USE_LPD8806
-D MAX_LEDS_PER_BUS=6400
-D UM_DisplayMatrix_Pins="TFT_MOSI,TFT_SCLK,TFT_CS,TFT_DC,TFT_RST,TFT_BL" #reserved pins

# Display config (TFT_sSPI)
-D USER_SETUP_LOADED
-D DISABLE_ALL_LIBRARY_WARNINGS # because of "TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available!" warning
-D DISABLE_ALL_LIBRARY_WARNINGS # because of "TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available!" warning
-D ST7789_DRIVER
-D TFT_SDA_READ # Display has a bidirectional SDA pin
-D CGRAM_OFFSET
-D TFT_WIDTH=135
-D TFT_HEIGHT=240
-D TFT_MOSI=19
Expand All @@ -864,19 +865,86 @@ build_flags = ${common.build_flags_esp32} ${esp32.AR_build_flags}
-D TFT_DC=16
-D TFT_RST=23
-D TFT_BL=4 # backlight pin
# -D TFT_BACKLIGHT_ON=HIGH
-D LOAD_GLCD
-D LOAD_FONT2
-D LOAD_FONT4
-D LOAD_FONT6
-D LOAD_FONT7
-D LOAD_FONT8
-D LOAD_GFXFF
# -D SMOOTH_FONT=1 // needs spiffs.h
-D SPI_FREQUENCY=27000000
# -D LOAD_FONT2
# -D LOAD_FONT4
# -D LOAD_FONT6
# -D LOAD_FONT7
# -D LOAD_FONT8
# -D LOAD_GFXFF
# -D SMOOTH_FONT # needs spiffs.h
-D SPI_FREQUENCY=40000000
-D SPI_READ_FREQUENCY=6000000 # 6 MHz is the maximum SPI read speed for the ST7789V

monitor_filters = esp32_exception_decoder
lib_deps =
${esp32.lib_deps}
TFT_eSPI @ 2.5.33 # newer version needs newer espressif32 platform ( https://github.com/Bodmer/TFT_eSPI/discussions/3048 )
${esp32.AR_lib_deps}
board_build.partitions = ${esp32.default_partitions}
board_build.partitions = ${esp32.default_partitions}

# ------------------------------------------------------------------------------
# LILYGO T-Display-S3 as led output (with audioreactive)
# ------------------------------------------------------------------------------
[env:lilygo_tdisplay_s3_output]
extends = env:esp32s3dev_16MB_PSRAM_opi
#board = lilygo-t-display-S3 # https://docs.platformio.org/en/latest/boards/espressif32/lilygo-t-display-s3.html

build_flags = ${env:esp32s3dev_16MB_PSRAM_opi.build_flags} ${esp32.AR_build_flags}
#build_flags = ${esp32s3dev_8MB_PSRAM_opi.build_flags} ${esp32.AR_build_flags}
# -D WLED_DISABLE_BROWNOUT_DET
# -D WLED_DISABLE_INFRARED
-D SERVERNAME="\"T-DISPLAY-S3\""
# -D WLED_RELEASE_NAME=lilygo_tdisplay_s3
# -D USERMOD_RTC
# -D DEFAULT_LED_COUNT=16*9
-D USERMOD_TTGO_TDISPLAY_OUTPUT
-D MAX_LEDS_PER_BUS=6400
-D UM_DisplayMatrix_Pins="TFT_CS,TFT_DC,TFT_RST,TFT_WR,TFT_RD,TFT_D0,TFT_D1,TFT_D2,TFT_D3,TFT_D4,TFT_D5,TFT_D6,TFT_D7,TFT_BL" #reserved pins

# Display config (TFT_sSPI) ST7789 using 8-bit Parallel
-D USER_SETUP_LOADED
-D DISABLE_ALL_LIBRARY_WARNINGS # because of "TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available!" warning
-D ST7789_DRIVER
-D TFT_PARALLEL_8_BIT
-D INIT_SEQUENCE_3 # Using this initialisation sequence improves the display image
-D CGRAM_OFFSET
-D TFT_RGB_ORDER=TFT_RGB # Colour order Red-Green-Blue
# -D TFT_RGB_ORDER TFT_BGR # Colour order Blue-Green-Red
-D TFT_INVERSION_ON
# -D TFT_INVERSION_OFF
-D TFT_WIDTH=170
-D TFT_HEIGHT=320
-D TFT_CS=6
-D TFT_DC=7
-D TFT_RST=5
-D TFT_WR=8
-D TFT_RD=9
-D TFT_D0=39
-D TFT_D1=40
-D TFT_D2=41
-D TFT_D3=42
-D TFT_D4=45
-D TFT_D5=46
-D TFT_D6=47
-D TFT_D7=48
-D TFT_BL=38
-D LOAD_GLCD
# -D LOAD_FONT2
# -D LOAD_FONT4
# -D LOAD_FONT6
# -D LOAD_FONT7
# -D LOAD_FONT8
# -D LOAD_GFXFF
# -D SMOOTH_FONT # needs spiffs.h
-D SPI_FREQUENCY=27000000

monitor_filters = esp32_exception_decoder
#monitor_rts = 0 #set to zero run monitor, then back to 1 to and restart monitor to see startup messages
#monitor_dtr = 0

lib_deps =
${env:esp32s3dev_16MB_PSRAM_opi.lib_deps}
TFT_eSPI @ 2.5.33 # newer version needs newer espressif32 platform ( https://github.com/Bodmer/TFT_eSPI/discussions/3048 )
${esp32.AR_lib_deps}
Binary file modified usermods/usermod_v2_TTGO-TDisplay_output/resolution_calc.xlsx
Binary file not shown.
125 changes: 92 additions & 33 deletions usermods/usermod_v2_TTGO-TDisplay_output/usermod.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
- add reserved pins (tft) to xml.cpp
- usermod configuration instead of led and 2D settings ?
- add "display" as led type
Measurement:
Time to draw = ~19200 microsec / fullscreen + ~15 microsec / "led"
60x34 = 2400 led = 52160 microsec
48x27 = 1296 led = 39050 microsec
40x22 = 880 led = 32580 microsec
16x9 = 144 led = 19430 microsec
(all with margins)
*/

#pragma once
Expand All @@ -25,27 +17,41 @@
#include <TFT_eSPI.h>

#define ADC_EN 14 // Used for enabling battery voltage measurements - not used in this program
// #define measureRenderTime

class TTGOTDisplayOutputUsermod : public Usermod {
private:
TFT_eSPI tft = TFT_eSPI(TFT_WIDTH, TFT_HEIGHT); // Setup display

uint8_t backlightChannel = 255;
uint16_t blocksW = 0;
uint16_t blocksH = 0;
bool forceSquareBlocks = true;
uint16_t top = 0;
uint16_t left = 0;
uint16_t oneWidth = 0;
uint16_t oneHeight = 0;
uint16_t margin = 1;
#ifdef measureRenderTime
uint32_t rtSum = 0;
uint32_t rtSamples = 0;
#endif
bool isSettingsValid(){
if(!strip.isMatrix) return false;
if(strip.panels!=1) return false;
return true;
}

// uint32_t milliSum = 0;
// uint32_t sampleCount = 0;
bool isSettingsChanged(){
if((strip.panel[0].serpentine?0:1) != margin) return true;
if(blocksW!=strip.panel[0].width) return true;
if(blocksH!=strip.panel[0].height) return true;
return false;
}

bool checkSettings(){
if(!strip.isMatrix) return false;
if(strip.panels!=1) return false;
bool marginSame = (strip.panel[0].serpentine?0:1) == margin;
if(blocksW==strip.panel[0].width && blocksH==strip.panel[0].height && marginSame) return true;
if(!isSettingsValid()) return false;
if(!isSettingsChanged()) return true;

tft.fillScreen(TFT_BLACK); // clear screen on change

Expand All @@ -55,38 +61,89 @@ class TTGOTDisplayOutputUsermod : public Usermod {

oneWidth = floor((tft.width() - (blocksW-1)*margin) / blocksW);
oneHeight = floor((tft.height() - (blocksH-1)*margin) / blocksH);
if(forceSquareBlocks){
oneHeight = oneWidth = min(oneWidth, oneHeight);
}
top = (tft.height() - (blocksH-1)*margin - oneHeight * blocksH) / 2;
left = (tft.width() - (blocksW-1)*margin - oneWidth * blocksW) / 2;

// Serial.printf("blocksW: %d, blocksH: %d, oneWidth: %d, oneHeight: %d, top: %d, left: %d\n",blocksW,blocksH,oneWidth,oneHeight,top,left);
// Serial.printf("blocksW: %d, blocksH: %d, oneWidth: %d, oneHeight: %d, top: %d, left: %d\n", blocksW, blocksH, oneWidth, oneHeight, top, left);

return true;
}

void setupBrightnessControl(){
backlightChannel = pinManager.allocateLedc(1);
if(backlightChannel==255){
pinMode(TFT_BL, OUTPUT);
}else{
ledcSetup(backlightChannel, 10000, 8); // t-display-s3 led driver: AW9364DNR, T-display direct led control with pwm
ledcAttachPin(TFT_BL, backlightChannel);
}
}

void setBrightness(){
if(backlightChannel==255){
digitalWrite(TFT_BL, bri==0?LOW:HIGH );
}else{
ledcWrite(backlightChannel, bri);
}
}

public:

void setup() {
//Serial.println("TTGO usermod - Setup");

pinMode(TFT_BL, OUTPUT); // Set backlight pin to output mode
digitalWrite(TFT_BL, HIGH); // Turn backlight on.
// Serial.println("T-Display usermod - Setup");

#ifdef UM_DisplayMatrix_Pins
uint8_t pinsToAllocate[] = {UM_DisplayMatrix_Pins};
uint8_t pinCount = sizeof(pinsToAllocate) / sizeof(uint8_t);
String notAllocated = "";
String allPins = "";
for(uint8_t i=0;i<pinCount;i++){
allPins += ", ";
allPins += pinsToAllocate[i];
if(!pinManager.allocatePin(pinsToAllocate[i], true, PinOwner::UM_Unspecified)){ // UM_DisplayMatrix
notAllocated += ", " + pinsToAllocate[i];
}
}
if(notAllocated.length()>0){
Serial.printf( "Usermod DisplayMatrix - Cannot allocate all the pins (%s) from (%s)\n", notAllocated.substring(2), allPins.substring(2)) ;
}else{
Serial.printf( "Usermod DisplayMatrix - All %d pins alocated (%s)\n", pinCount, allPins.substring(2)) ;
}
//pinManager.allocatePin(TFT_BL, true, PinOwner::UM_Unspecified); // UM_DisplayMatrix
#endif

tft.init();
tft.setRotation(3); //Rotation here is set up for the text to be readable with the port on the left.
tft.fillScreen(TFT_BLACK);
tft.setTextSize(2);
tft.setTextColor(TFT_WHITE);
tft.setCursor(1, 10);
tft.setTextDatum(MC_DATUM);
tft.println("WLED - TTGO");

setupBrightnessControl();
setBrightness();

uint8_t textSize = 4;
while (true)
{
tft.setTextSize(textSize);
if(textSize==1) break;
if(tft.textWidth(F("WLED - DisplayMatrix"))<=tft.width()) break;
textSize--;
}
tft.drawString(F("WLED - DisplayMatrix"), tft.width()/2, tft.height()/2);
}

void onStateChange(uint8_t mode) {
digitalWrite(TFT_BL, bri==0?LOW:HIGH );
setBrightness();
}

void loop() {
// unsigned long msStart = micros();
#ifdef measureRenderTime
unsigned long rtStart = micros();
#endif

if(bri==0) return;
if(!checkSettings()) return;

Expand All @@ -96,15 +153,17 @@ class TTGOTDisplayOutputUsermod : public Usermod {
}
}

// if(micros() > msStart){
// milliSum += micros() - msStart;
// sampleCount++;
// if(sampleCount==100){
// Serial.printf("Display time: %d microsecond => %d fps\n", milliSum / sampleCount, sampleCount * 1000000 / milliSum);
// milliSum = 0;
// sampleCount = 0;
// }
// }
#ifdef measureRenderTime
if(micros() > rtStart){
rtSum += micros() - rtStart;
rtSamples++;
if(rtSamples==100){
Serial.printf("2D Matrix: %dx%d with %d gap, display: %d microsecond => %d fps\n", blocksW, blocksH, margin, rtSum / rtSamples, sampleCount * 1000000 / rtSum);
rtSamples = 0;
sampleCount = 0;
}
}
#endif
}

};

0 comments on commit 7380b36

Please sign in to comment.