Help to reduce large RAM when display is initialised/registered


I have a fully working display and touch screen and have used to test many widgets. However, in building my project I noticed that the RAM being used seems excessive.
I am really enjoying this amazing library but need to reduce the RAM

What MCU/Processor/Board and compiler are you using?

Teensy 4.0 , Arduino IDE

What LVGL version are you using?


What do you want to achieve?

Reduce the RAM on initialisation

What have you tried so far?

By trial and error in removing lines of code I found that when the display is registered … code line lv_disp_drv_register( &disp_drv ); the RAM moves a lot.
If there are no widgets in the sketch and I comment out this line the RAM goes down by 139,264 bytes. If there is a single example widget button_1 in the sketch and I comment out this line the RAM drops by 73,728 bytes.
So, is the problem with the initialisation/registration somehow? I am hoping this is some small oversight on my part as.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*  #include "Arduino.h"
#include <SPI.h>
#include "DFRobot_Touch.h" //GT911 touch
#include <Wire.h>
#include <ILI9488_t3.h>

#include <lvgl.h>

#define TFT_DC  20
#define TFT_CS  10
#define TFT_RST 14

ILI9488_t3 display = ILI9488_t3(&SPI, TFT_CS, TFT_DC, TFT_RST);//from TFT_ILI9488_t3_colortest.ino

DFRobot_Touch_GT911 touch; // Touch

//Change to your screen resolution
static const uint32_t screenWidth  = 320;//480 for rot 3,320 for rot 2(but need to translate touch points)
static const uint32_t screenHeight = 480;//320 for rot 3, 480 for rot 2(but need to translate touch points)

static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf1[ screenWidth * /*10*/ 40 ];//declare screen buffer size

#if LV_USE_LOG != 0
// Serial debugging 
void my_print( lv_log_level_t level, const char * file, uint32_t line, const char * fn_name, const char * dsc )
   Serial.printf( "%s(%s)@%d->%s\r\n", file, fn_name, line, dsc );

// Display flushing ----taken from SKPang using ILI9488 screen driver 

void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
  uint16_t width = (area->x2 - area->x1 +1);
  uint16_t height = (area->y2 - area->y1+1);
  display.writeRect(area->x1, area->y1, width, height, (uint16_t *)color_p);
  lv_disp_flush_ready(disp); /* tell lvgl that flushing is done */  

//Read the touchpad
uint16_t xpoint;//referenced to DFRobot_Touch.cpp
uint16_t ypoint;//referenced to DFRobot_Touch.cpp
int Touched;

int oldTouchX=0;
int oldTouchY=0;

void my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
  uint16_t touchX, touchY;
   if (Touched = 1)
     touchX = xpoint;//translate cap touch point to match TFT orientation...touchX=ypoint matches display.setRotation(3),touchX=xpoint matches display.setRotation(2) 
     touchY = ypoint;//translate cap touch point to match TFT orientation...touchY=xpoint matches display.setRotation(3),touchY=ypoint matches display.setRotation(2)
     touchY = 480-touchY;//touchX=480-touchX matches display.setRotation(3),touchY=480-touchY matches display.setRotation(2)
     touchX = 320-touchX; //touchX=320-touchX matches display.setRotation(2)
    Serial.print("X= ");
    Serial.print(" Y= ");

    if ((touchX != oldTouchX) || (touchY != oldTouchY))
            oldTouchY = touchY;
            oldTouchX = touchX;
               data->state = LV_INDEV_STATE_PR; 
             //  data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; //dont know what this does commented out by SKPang
                data->point.x = touchX;
                data->point.y = touchY;
  } else
        data->point.x = oldTouchX;
        data->point.y = oldTouchY;
        data->state =LV_INDEV_STATE_REL;
  return 0;

//================================ put static items for examples here ================================//

static void event_handler(lv_event_t * e)
    lv_event_code_t code = lv_event_get_code(e);

    if(code == LV_EVENT_CLICKED) {
    else if(code == LV_EVENT_VALUE_CHANGED) {

void setup()
   Serial.begin( 115200 ); // prepare for possible serial debug 
   Serial.println( "Hello Arduino! (V8.0.X)" );
   Serial.println( "I am LVGL_Arduino" );


//    causes display to freeze at blue screen in set up 
//#if LV_USE_LOG != 0
//   lv_log_register_print_cb( my_print ); // register print function for debugging 


  display.setRotation(2); // (3)180, (2)90
   lv_disp_draw_buf_init( &draw_buf, buf1, NULL, screenWidth * /*10*/ 40 );//initialise the display buffer
   //Initialize the display
   static lv_disp_drv_t disp_drv;
   lv_disp_drv_init( &disp_drv );
   //Change the following line to your display resolution
   disp_drv.hor_res = screenWidth;
   disp_drv.ver_res = screenHeight;
   disp_drv.flush_cb = my_disp_flush;
   disp_drv.draw_buf = &draw_buf;
   //lv_disp_drv_register( &disp_drv );

   //Initialize the (dummy) input device driver
   static lv_indev_drv_t indev_drv;
   lv_indev_drv_init( &indev_drv );
   indev_drv.type = LV_INDEV_TYPE_POINTER;
   indev_drv.read_cb = my_touchpad_read;
   lv_indev_drv_register( &indev_drv );
//======================= put void function from example here

 //================================  button_1 =================
    lv_obj_t * label;

    lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
    lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
    lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);

    label = lv_label_create(btn1);
    lv_label_set_text(label, "Button");

    lv_obj_t * btn2 = lv_btn_create(lv_scr_act());
    lv_obj_add_event_cb(btn2, event_handler, LV_EVENT_ALL, NULL);
    lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40);
    lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
    lv_obj_set_height(btn2, LV_SIZE_CONTENT);

    label = lv_label_create(btn2);
    lv_label_set_text(label, "Toggle");

   Serial.println( "Setup done" );

void loop()
    lv_timer_handler(); /* let the GUI do its work */
    delay( 5 );
}    */

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.