Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions default_4MB.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x140000,
app1, app, ota_1, 0x150000,0x140000,
spiffs, data, spiffs, 0x290000,0x160000,
coredump, data, coredump,0x3F0000,0x10000,
51 changes: 48 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ board_build.embed_txtfiles =
src/www/index.html
src/www/app.js
src/www/vcr.ttf
extra_scripts = pre:extra_script.py

[common_build_flags]
build_flags =
Expand All @@ -39,14 +40,13 @@ build_flags =
extends = common
board = esp32-s3-devkitc-1
board_build.arduino.memory_type = qio_opi
extra_scripts = pre:extra_script.py
board_build.flash_mode = qio
board_build.psram_type = opi
board_upload.flash_size = 16MB
board_build.partitions = default_16MB.csv
build_flags =
${common_build_flags.build_flags}
-DBOARD_HAS_PSRAM
-DBOARD_HAS_PSRAM
; -DUSE_DMA
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
Expand Down Expand Up @@ -81,4 +81,49 @@ build_flags =
-DSYS_EN=GPIO_NUM_41
-DSYS_OUT=GPIO_NUM_40
; Battery monitor
-DBATTERY_VOLTAGE_PIN=GPIO_NUM_1
-DBATTERY_VOLTAGE_PIN=GPIO_NUM_1

[env:cheap_yellow_display]
extends = common
board = esp32dev
board_build.flash_mode = qio
board_upload.flash_size = 4MB
board_build.partitions = default_4MB.csv
build_flags =
${common_build_flags.build_flags}
-DCHEAP_YELLOW_DISPLAY
; TFT_eSPI setup
; -DTFT_INVERSION_OFF
; -DUSE_HSPI_PORT
; -DTFT_RGB_ORDER=TFT_BGR
-DUSER_SETUP_LOADED=1
-DILI9341_DRIVER=1
-DTFT_WIDTH=240
-DTFT_HEIGHT=320
-DTFT_MISO=12
-DTFT_MOSI=13
-DTFT_SCLK=14
-DTFT_CS=15
-DTFT_DC=2
-DTFT_RST=-1
-DTFT_BL=27
-DTFT_BACKLIGHT_ON=HIGH
-DTFT_BACKLIGHT_OFF=LOW
-DTOUCH_CS=-1
-DLOAD_GLCD=1
-DLOAD_FONT2=1
-DLOAD_FONT4=1
-DSPI_FREQUENCY=40000000
-DSPI_READ_FREQUENCY=20000000
-DSPI_TOUCH_FREQUENCY=2500000
; SD card
-DUSE_SDCARD
-DSD_CARD_MISO=GPIO_NUM_19
-DSD_CARD_MOSI=GPIO_NUM_23
-DSD_CARD_CLK=GPIO_NUM_18
-DSD_CARD_CS=GPIO_NUM_5
; Button
-DSYS_EN=GPIO_NUM_1
-DSYS_OUT=GPIO_NUM_4
; Battery monitor
-DBATTERY_VOLTAGE_PIN=GPIO_NUM_34
62 changes: 62 additions & 0 deletions src/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ Display::Display(Prefs *prefs) : tft(new TFT_eSPI()), _prefs(prefs)

// First, initialize the TFT itself and set the rotation
tft->init();
#ifdef CHEAP_YELLOW_DISPLAY
tft->setRotation(2);
#else
tft->setRotation(3);
#endif

#ifdef BOARD_HAS_PSRAM
// Now create the sprite with the correct, rotated dimensions
frameSprite = new TFT_eSprite(tft);
frameSprite->createSprite(tft->width(), tft->height());
frameSprite->setTextFont(2);
frameSprite->setTextSize(2);
#endif

// setup the backlight
#ifdef TFT_BL
Expand Down Expand Up @@ -71,22 +77,34 @@ void Display::drawPixels(int x, int y, int width, int height, uint16_t *pixels)
// new function to draw to our framebuffer sprite
void Display::drawPixelsToSprite(int x, int y, int width, int height, uint16_t *pixels)
{
#ifdef BOARD_HAS_PSRAM
frameSprite->pushImage(x, y, width, height, pixels);
#else
drawPixels(x, y, width, height, pixels);
#endif
}

// new function to push the framebuffer to the screen
void Display::flushSprite()
{
#ifdef BOARD_HAS_PSRAM
xSemaphoreTakeRecursive(tft_mutex, portMAX_DELAY);
frameSprite->pushSprite(0, 0);
xSemaphoreGiveRecursive(tft_mutex);
#endif
}

void Display::fillSprite(uint16_t color)
{
#ifdef BOARD_HAS_PSRAM
xSemaphoreTakeRecursive(tft_mutex, portMAX_DELAY);
frameSprite->fillSprite(color);
xSemaphoreGiveRecursive(tft_mutex);
#else
xSemaphoreTakeRecursive(tft_mutex, portMAX_DELAY);
tft->fillScreen(color);
xSemaphoreGiveRecursive(tft_mutex);
#endif
}

int Display::width()
Expand All @@ -107,9 +125,15 @@ int Display::height()

void Display::fillScreen(uint16_t color)
{
#ifdef BOARD_HAS_PSRAM
xSemaphoreTakeRecursive(tft_mutex, portMAX_DELAY);
frameSprite->fillScreen(color);
xSemaphoreGiveRecursive(tft_mutex);
#else
xSemaphoreTakeRecursive(tft_mutex, portMAX_DELAY);
tft->fillScreen(color);
xSemaphoreGiveRecursive(tft_mutex);
#endif
}

void Display::drawOSD(const char *text, OSDPosition position, OSDLevel level)
Expand All @@ -118,6 +142,7 @@ void Display::drawOSD(const char *text, OSDPosition position, OSDLevel level)
{
return;
}
#ifdef BOARD_HAS_PSRAM
// draw OSD text into the sprite, with a black background for readability
frameSprite->setTextColor(TFT_ORANGE, TFT_BLACK);

Expand Down Expand Up @@ -151,6 +176,43 @@ void Display::drawOSD(const char *text, OSDPosition position, OSDLevel level)
}
frameSprite->setCursor(x, y);
frameSprite->println(text);
#else
// no sprite, draw directly to the screen
xSemaphoreTakeRecursive(tft_mutex, portMAX_DELAY);
tft->setTextColor(TFT_ORANGE, TFT_BLACK);

int textWidth = tft->textWidth(text);
int textHeight = tft->fontHeight();
int x = 0;
int y = 0;

switch (position)
{
case TOP_LEFT:
x = 20;
y = 20;
break;
case TOP_RIGHT:
x = width() - textWidth - 20;
y = 20;
break;
case BOTTOM_LEFT:
x = 20;
y = height() - textHeight - 20;
break;
case BOTTOM_RIGHT:
x = width() - textWidth - 20;
y = height() - textHeight - 20;
break;
case CENTER:
x = (width() - textWidth) / 2;
y = (height() - textHeight) / 2;
break;
}
tft->setCursor(x, y);
tft->println(text);
xSemaphoreGiveRecursive(tft_mutex);
#endif
}