add framebuffer

This commit is contained in:
Manuel
2025-10-04 12:36:31 +02:00
parent fb46938582
commit 19e62b8686
2 changed files with 39 additions and 14 deletions

View File

@@ -57,13 +57,13 @@ class LGFX : public lgfx::LGFX_Device
{ // Set the display panel control. { // Set the display panel control.
auto cfg = _panel_instance.config(); // Gets a structure for display panel settings. auto cfg = _panel_instance.config(); // Gets a structure for display panel settings.
cfg.pin_cs = CO5300_CS; // Pin number where CS is connected (-1 = disable) cfg.pin_cs = CO5300_CS; // Pin number where CS is connected (-1 = disable)
cfg.pin_rst = CO5300_RESET; // Pin number where RST is connected (-1 = disable) cfg.pin_rst = CO5300_RESET; // Pin number where RST is connected (-1 = disable)
cfg.panel_width = TFT_WIDTH; // actual displayable width cfg.panel_width = TFT_WIDTH; // actual displayable width
cfg.panel_height = TFT_HEIGHT; // actual displayable height cfg.panel_height = TFT_HEIGHT; // actual displayable height
cfg.offset_rotation = 0; // Rotation direction value offset 0~7 (4~7 is upside down) cfg.offset_rotation = TFT_OFFSET_ROTATION; // Rotation direction value offset 0~7 (4~7 is upside down)
cfg.offset_x = 22; cfg.offset_x = TFT_OFFSET_X;
cfg.offset_y = 0; cfg.offset_y = TFT_OFFSET_Y;
cfg.dummy_read_pixel = 8; // Number of bits for dummy read before pixel readout cfg.dummy_read_pixel = 8; // Number of bits for dummy read before pixel readout
cfg.dummy_read_bits = 1; // Number of bits for dummy read before non-pixel data read cfg.dummy_read_bits = 1; // Number of bits for dummy read before non-pixel data read
cfg.readable = true; // Set to true if data can be read cfg.readable = true; // Set to true if data can be read
@@ -81,6 +81,29 @@ class LGFX : public lgfx::LGFX_Device
setPanel(&_panel_instance); setPanel(&_panel_instance);
} }
bool enableFrameBuffer(bool auto_display = false)
{
if (_panel_instance.initPanelFb()) {
auto fbPanel = _panel_instance.getPanelFb();
if (fbPanel) {
fbPanel->setBus(&_bus_instance);
fbPanel->setAutoDisplay(auto_display);
setPanel(fbPanel);
return true;
}
}
return false;
}
void disableFrameBuffer()
{
auto fbPanel = _panel_instance.getPanelFb();
if (fbPanel) {
_panel_instance.deinitPanelFb();
setPanel(&_panel_instance);
}
}
bool init() bool init()
{ {
#ifdef CO5300_RESET #ifdef CO5300_RESET
@@ -93,7 +116,7 @@ class LGFX : public lgfx::LGFX_Device
lgfx::gpio_hi(CO5300_RESET); lgfx::gpio_hi(CO5300_RESET);
delay(200); delay(200);
#endif #endif
return lgfx::LGFX_Device::init(); return lgfx::LGFX_Device::init() && enableFrameBuffer(false);
} }
}; };
@@ -1303,8 +1326,8 @@ void TFTDisplay::display(bool fromBlank)
// Step 4: Send the changed pixels on this line to the screen as a single block transfer. // Step 4: Send the changed pixels on this line to the screen as a single block transfer.
// This function accepts pixel data MSB first so it can dump the memory straight out the SPI port. // This function accepts pixel data MSB first so it can dump the memory straight out the SPI port.
tft->pushRect(x_FirstPixelUpdate, y, (x_LastPixelUpdate - x_FirstPixelUpdate + 1), 1, tft->pushImage(x_FirstPixelUpdate, y, (x_LastPixelUpdate - x_FirstPixelUpdate + 1), 1,
&linePixelBuffer[x_FirstPixelUpdate]); &linePixelBuffer[x_FirstPixelUpdate]);
somethingChanged = true; somethingChanged = true;
} }
@@ -1364,7 +1387,7 @@ void TFTDisplay::sendCommand(uint8_t com)
// handle display on/off directly // handle display on/off directly
switch (com) { switch (com) {
case DISPLAYON: { case DISPLAYON: {
// LOG_DEBUG("Display on"); LOG_DEBUG("Display on");
backlightEnable->set(true); backlightEnable->set(true);
#if ARCH_PORTDUINO #if ARCH_PORTDUINO
display(true); display(true);
@@ -1383,12 +1406,13 @@ void TFTDisplay::sendCommand(uint8_t com)
#endif #endif
#ifdef RAK14014 #ifdef RAK14014
#elif !defined(M5STACK) && !defined(ST7789_CS) // T-Deck gets brightness set in Screen.cpp in the handleSetOn function #elif !defined(M5STACK) && !defined(ST7789_CS) // T-Deck gets brightness set in Screen.cpp in the handleSetOn function
LOG_DEBUG("tft->setBrightness(172)");
tft->setBrightness(172); tft->setBrightness(172);
#endif #endif
break; break;
} }
case DISPLAYOFF: { case DISPLAYOFF: {
// LOG_DEBUG("Display off"); LOG_DEBUG("Display off");
backlightEnable->set(false); backlightEnable->set(false);
#if ARCH_PORTDUINO #if ARCH_PORTDUINO
tft->clear(); tft->clear();
@@ -1407,6 +1431,7 @@ void TFTDisplay::sendCommand(uint8_t com)
#endif #endif
#ifdef RAK14014 #ifdef RAK14014
#elif !defined(M5STACK) #elif !defined(M5STACK)
LOG_DEBUG("tft->setBrightness(0)");
tft->setBrightness(0); tft->setBrightness(0);
#endif #endif
break; break;
@@ -1482,8 +1507,8 @@ bool TFTDisplay::connect()
tft = new LGFX; tft = new LGFX;
#endif #endif
backlightEnable->set(true);
LOG_INFO("Power to TFT Backlight"); LOG_INFO("Power to TFT Backlight");
backlightEnable->set(true);
#ifdef UNPHONE #ifdef UNPHONE
unphone.backlight(true); // using unPhone library unphone.backlight(true); // using unPhone library

View File

@@ -13,7 +13,7 @@
#define SPI_READ_FREQUENCY 16000000 // irrelevant #define SPI_READ_FREQUENCY 16000000 // irrelevant
#define TFT_HEIGHT 502 #define TFT_HEIGHT 502
#define TFT_WIDTH 410 #define TFT_WIDTH 410
#define TFT_OFFSET_X 0 #define TFT_OFFSET_X 22
#define TFT_OFFSET_Y 0 #define TFT_OFFSET_Y 0
#define TFT_OFFSET_ROTATION 0 #define TFT_OFFSET_ROTATION 0
#define SCREEN_TRANSITION_FRAMERATE 5 // fps #define SCREEN_TRANSITION_FRAMERATE 5 // fps