Skip to content

Giga Display going white with LVGL v9.2.2—what is causing this? #1004

Closed as not planned
@littlejohn657

Description

@littlejohn657

I am having trouble with the screen turning white immediately on startup and not showing anything. I'm using an Arduino Giga with an Arduino Giga Display Shield, LVGL v9.2.2, and Arduino_H7_Video.

To test the display buffer, I replaced the code in the display buffer to colour the screen red (i.e., replaced the code in the second for loop with Display.set(x, y, 255, 0, 0);). I saw the red streak through the display in blocks, and then the blocks be trailed almost immediately by black as the red continued down the screen (whether or not I had the code for lv_obj_t * screen_black = lv_obj_create(NULL); there or not), then the screen turned white. I also put a serial print in the flush callback that was outputting to the monitor. So I know that the flush callback is being called and is working.

If I replace lv_obj_t * screen_black = lv_obj_create(NULL); with lv_obj_t * screen_black = lv_obj_create(lv_screen_active());, leave the rest of the code for the screen obj, and remove the code for creating the display and buffers, the screen does appropriately turn black (with a small white border).

Any ideas of what might be going on here?

#include <Arduino_H7_Video.h>
#include <Arduino_GigaDisplay.h> // v1.0.2
#include <Arduino_GigaDisplayTouch.h> // v1.0.1
#include <lvgl.h> // LVGL v9.2.2
#include <ArduinoGraphics.h>

Arduino_H7_Video Display(800, 480, GigaDisplayShield);
Arduino_GigaDisplayTouch TouchDetector;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  
  Display.begin();

  lv_init();

  lv_display_t * display = lv_display_create(800, 480); 

  static uint8_t buf1[800 * 480 / 10];
  lv_display_set_buffers(display, buf1, NULL, sizeof(buf1), LV_DISPLAY_RENDER_MODE_PARTIAL);
  lv_display_set_flush_cb(display, my_disp_flush); 
  lv_disp_set_default(display);

  lv_obj_t * screen_black = lv_obj_create(NULL);
  lv_obj_set_size(screen_black, 800, 480);
  lv_obj_set_style_bg_color(screen_black, lv_color_black(), LV_PART_MAIN);
  lv_obj_set_style_bg_opa(screen_black, LV_OPA_COVER, LV_PART_MAIN);

  lv_screen_load(screen_black);

}

void loop() {
  // put your main code here, to run repeatedly:
  lv_timer_handler();
}

void my_disp_flush(lv_display_t *disp, const lv_area_t *area, uint8_t *color_p) {
  
  // Cast the buffer to lv_color_t for proper interpretation
  lv_color_t *color_map = (lv_color_t *)color_p;

  // Start drawing to the framebuffer
  Display.beginDraw();

  // Loop through the area and set pixels
  for (int32_t y = area->y1; y <= area->y2; y++) {
    for (int32_t x = area->x1; x <= area->x2; x++) {
      // Extract RGB565 from lv_color_t
      uint16_t color = *((uint16_t *)color_map);

      // Convert RGB565 to R, G, B components
      uint8_t r = (color >> 11) & 0x1F;  // Extract 5 bits for red
      uint8_t g = (color >> 5) & 0x3F;   // Extract 6 bits for green
      uint8_t b = color & 0x1F;          // Extract 5 bits for blue

      // Scale to 8-bit values (0-255)
      r = (r * 255) / 31;
      g = (g * 255) / 63;
      b = (b * 255) / 31;

      // Set the pixel color
      Display.set(x, y, r, g, b);

      // Advance to the next color in the buffer
      color_map++;
    }
  }

  // End drawing operation
  Display.endDraw();

  lv_display_flush_ready(disp);
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions