Skip to content

Instantly share code, notes, and snippets.

@hpwit
Created September 10, 2025 15:51
Show Gist options
  • Select an option

  • Save hpwit/0ba311bccae236dfd8e18822c36b4dcb to your computer and use it in GitHub Desktop.

Select an option

Save hpwit/0ba311bccae236dfd8e18822c36b4dcb to your computer and use it in GitHub Desktop.
#include "esp_lcd_panel_rgb.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_panel_vendor.h"
#include "esp32s3/rom/cache.h"
#define LCD_H_RES 800
#define LCD_V_RES 480
esp_lcd_panel_handle_t panel_handle = NULL;
static uint16_t image[50*50];
void display()
{
esp_lcd_rgb_panel_config_t panel_config = {
.clk_src = LCD_CLK_SRC_PLL160M,
.timings = {
.pclk_hz = 16 * 1000 * 1000, // Pixel clock
.h_res = LCD_H_RES,
.v_res = LCD_V_RES,
.hsync_pulse_width = 4,
.hsync_back_porch = 16,
.hsync_front_porch = 80,
.vsync_pulse_width = 4,
.vsync_back_porch = 4,
.vsync_front_porch = 22,
.flags = {
.hsync_idle_low = 1,//(uint32_t)((_hsync_polarity == 0) ? 1 : 0),
.vsync_idle_low = 1,//(uint32_t)((_vsync_polarity == 0) ? 1 : 0),
.de_idle_high = 0,
.pclk_active_neg = 1,
.pclk_idle_high = 0,
},
},
.data_width = 16, // RGB565
.bits_per_pixel = 16,
.bounce_buffer_size_px = 0,
.sram_trans_align = 8,
.psram_trans_align = 64,
.hsync_gpio_num = 39,
.vsync_gpio_num = 41,
.de_gpio_num = 40,
.pclk_gpio_num = 42,
.disp_gpio_num = -1,
.data_gpio_nums = {
8,3,46,9,1,5,6,7,15,16,4,45,48,47,21,14
},
.flags = {
.disp_active_low = true,
// #if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
.refresh_on_demand = true,
// #endif
.fb_in_psram = true, // allocate frame buffer from PSRAM
// #if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR >= 3
.double_fb = false,
.no_fb = false,
.bb_invalidate_cache = false,
// #endif
}
};
// Create panel
ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(&panel_config, &panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
// Example image (red)
for (int i = 0; i < 50 * 50; i++) {
image[i] = 0xFFFF; // RGB565 Red
}
// Push once
// ESP_ERROR_CHECK(esp_lcd_panel_draw_bitmap(panel_handle, 50, 50, 100, 100, image));
void *frame_buffer = nullptr;
ESP_ERROR_CHECK(esp_lcd_rgb_panel_get_frame_buffer(panel_handle, 1, &frame_buffer));
uint16_t *f=(uint16_t *)frame_buffer;
for(int i=0;i<500;i++)
{
f[i]=0xFFFF;
}
Cache_WriteBack_Addr((uint32_t)frame_buffer, 800*480);
ESP_ERROR_CHECK( esp_lcd_rgb_panel_refresh(panel_handle)); // 👈 triggers refresh
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
display();
}
void loop() {
// put your main code here, to run repeatedly:
}
@mockthebear
Copy link

I got the same problem you're having there, I'm even using the same display the ST7626.
I'm not sure, but i dont think the problem is in the code itself. I tried tweaking EVERY setting.

It seems a problem with the display itself :(

    esp_lcd_rgb_panel_config_t panel_config = {
      .clk_src = LCD_CLK_SRC_PLL160M,
      .timings = {
          .pclk_hz = 16000000,
          .h_res = 800,
          .v_res = 480,
          .hsync_pulse_width = 4,
          .hsync_back_porch = 8,
          .hsync_front_porch = 8,
          .vsync_pulse_width = 4,
          .vsync_back_porch = 8,
          .vsync_front_porch = 8,
          .flags = {
              .hsync_idle_low = 1,
              .vsync_idle_low = 1,
              .de_idle_high = 0,
              .pclk_active_neg = 1,
              .pclk_idle_high = 1,
          },
      },
      .data_width = 16, 
      .bits_per_pixel = 16,
      .num_fbs = 2,
      .sram_trans_align = 8,
      .psram_trans_align = 64,
      .hsync_gpio_num = 39,
      .vsync_gpio_num = 41,
      .de_gpio_num = 40,
      .pclk_gpio_num = 42,
      .disp_gpio_num = GPIO_NUM_NC, // -1
      .data_gpio_nums = {8,3,46,9,1,5,6,7,15,16,4,45,48,47,21,14},
      .flags = {
        .disp_active_low =false,
          .refresh_on_demand= false,
          .fb_in_psram = true, // allocate frame buffer from PSRAM
          .double_fb = true,
      }
    };


    ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(&panel_config, &panel_handle));

    ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
    ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
    ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, true));
    ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, true, false));

    void *kek;
    void *kek2;

    ESP_ERROR_CHECK(esp_lcd_rgb_panel_get_frame_buffer(panel_handle, 2, &kek, &kek2));

    _framebuffer = (uint16_t*)kek;
    _framebuffer2 = (uint16_t*)kek2;

```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment