acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_port_disp_template.c (6276B)

      1 /**
      2  * @file lv_port_disp_templ.c
      3  *
      4  */
      5 
      6 /*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
      7 #if 0
      8 
      9 /*********************
     10  *      INCLUDES
     11  *********************/
     12 #include "lv_port_disp_template.h"
     13 #include "../../lvgl.h"
     14 
     15 /*********************
     16  *      DEFINES
     17  *********************/
     18 
     19 /**********************
     20  *      TYPEDEFS
     21  **********************/
     22 
     23 /**********************
     24  *  STATIC PROTOTYPES
     25  **********************/
     26 static void disp_init(void);
     27 
     28 static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
     29 //static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
     30 //        const lv_area_t * fill_area, lv_color_t color);
     31 
     32 /**********************
     33  *  STATIC VARIABLES
     34  **********************/
     35 
     36 /**********************
     37  *      MACROS
     38  **********************/
     39 
     40 /**********************
     41  *   GLOBAL FUNCTIONS
     42  **********************/
     43 
     44 void lv_port_disp_init(void)
     45 {
     46     /*-------------------------
     47      * Initialize your display
     48      * -----------------------*/
     49     disp_init();
     50 
     51     /*-----------------------------
     52      * Create a buffer for drawing
     53      *----------------------------*/
     54 
     55     /**
     56      * LVGL requires a buffer where it internally draws the widgets.
     57      * Later this buffer will passed to your display driver's `flush_cb` to copy its content to your display.
     58      * The buffer has to be greater than 1 display row
     59      *
     60      * There are 3 buffering configurations:
     61      * 1. Create ONE buffer:
     62      *      LVGL will draw the display's content here and writes it to your display
     63      *
     64      * 2. Create TWO buffer:
     65      *      LVGL will draw the display's content to a buffer and writes it your display.
     66      *      You should use DMA to write the buffer's content to the display.
     67      *      It will enable LVGL to draw the next part of the screen to the other buffer while
     68      *      the data is being sent form the first buffer. It makes rendering and flushing parallel.
     69      *
     70      * 3. Double buffering
     71      *      Set 2 screens sized buffers and set disp_drv.full_refresh = 1.
     72      *      This way LVGL will always provide the whole rendered screen in `flush_cb`
     73      *      and you only need to change the frame buffer's address.
     74      */
     75 
     76     /* Example for 1) */
     77     static lv_disp_draw_buf_t draw_buf_dsc_1;
     78     static lv_color_t buf_1[MY_DISP_HOR_RES * 10];                          /*A buffer for 10 rows*/
     79     lv_disp_draw_buf_init(&draw_buf_dsc_1, buf_1, NULL, MY_DISP_HOR_RES * 10);   /*Initialize the display buffer*/
     80 
     81     /* Example for 2) */
     82     static lv_disp_draw_buf_t draw_buf_dsc_2;
     83     static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10];                        /*A buffer for 10 rows*/
     84     static lv_color_t buf_2_2[MY_DISP_HOR_RES * 10];                        /*An other buffer for 10 rows*/
     85     lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES * 10);   /*Initialize the display buffer*/
     86 
     87     /* Example for 3) also set disp_drv.full_refresh = 1 below*/
     88     static lv_disp_draw_buf_t draw_buf_dsc_3;
     89     static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES];            /*A screen sized buffer*/
     90     static lv_color_t buf_3_2[MY_DISP_HOR_RES * MY_DISP_VER_RES];            /*Another screen sized buffer*/
     91     lv_disp_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2,
     92                           MY_DISP_VER_RES * LV_VER_RES_MAX);   /*Initialize the display buffer*/
     93 
     94     /*-----------------------------------
     95      * Register the display in LVGL
     96      *----------------------------------*/
     97 
     98     static lv_disp_drv_t disp_drv;                         /*Descriptor of a display driver*/
     99     lv_disp_drv_init(&disp_drv);                    /*Basic initialization*/
    100 
    101     /*Set up the functions to access to your display*/
    102 
    103     /*Set the resolution of the display*/
    104     disp_drv.hor_res = 480;
    105     disp_drv.ver_res = 320;
    106 
    107     /*Used to copy the buffer's content to the display*/
    108     disp_drv.flush_cb = disp_flush;
    109 
    110     /*Set a display buffer*/
    111     disp_drv.draw_buf = &draw_buf_dsc_1;
    112 
    113     /*Required for Example 3)*/
    114     //disp_drv.full_refresh = 1
    115 
    116     /* Fill a memory array with a color if you have GPU.
    117      * Note that, in lv_conf.h you can enable GPUs that has built-in support in LVGL.
    118      * But if you have a different GPU you can use with this callback.*/
    119     //disp_drv.gpu_fill_cb = gpu_fill;
    120 
    121     /*Finally register the driver*/
    122     lv_disp_drv_register(&disp_drv);
    123 }
    124 
    125 /**********************
    126  *   STATIC FUNCTIONS
    127  **********************/
    128 
    129 /*Initialize your display and the required peripherals.*/
    130 static void disp_init(void)
    131 {
    132     /*You code here*/
    133 }
    134 
    135 /*Flush the content of the internal buffer the specific area on the display
    136  *You can use DMA or any hardware acceleration to do this operation in the background but
    137  *'lv_disp_flush_ready()' has to be called when finished.*/
    138 static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
    139 {
    140     /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
    141 
    142     int32_t x;
    143     int32_t y;
    144     for(y = area->y1; y <= area->y2; y++) {
    145         for(x = area->x1; x <= area->x2; x++) {
    146             /*Put a pixel to the display. For example:*/
    147             /*put_px(x, y, *color_p)*/
    148             color_p++;
    149         }
    150     }
    151 
    152     /*IMPORTANT!!!
    153      *Inform the graphics library that you are ready with the flushing*/
    154     lv_disp_flush_ready(disp_drv);
    155 }
    156 
    157 /*OPTIONAL: GPU INTERFACE*/
    158 
    159 /*If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color*/
    160 //static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
    161 //                    const lv_area_t * fill_area, lv_color_t color)
    162 //{
    163 //    /*It's an example code which should be done by your GPU*/
    164 //    int32_t x, y;
    165 //    dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
    166 //
    167 //    for(y = fill_area->y1; y <= fill_area->y2; y++) {
    168 //        for(x = fill_area->x1; x <= fill_area->x2; x++) {
    169 //            dest_buf[x] = color;
    170 //        }
    171 //        dest_buf+=dest_width;    /*Go to the next line*/
    172 //    }
    173 //}
    174 
    175 
    176 #else /*Enable this file at the top*/
    177 
    178 /*This dummy typedef exists purely to silence -Wpedantic.*/
    179 typedef int keep_pedantic_happy;
    180 #endif