The resolution of your display (width, height, color depth):
1280 X 1024; color depth 8
The display type (‘dump’ or ‘smart’ display) and how it is connected to your hardware
Not sure if its a dump or smart display. It is connected to an FPGA.
How did you setup lvgl (e.g. working buffer size, color depth)
Here are my changes to the config file:
/* Maximal horizontal and vertical resolution to support by the library.*/
#define LV_HOR_RES_MAX (1280)
#define LV_VER_RES_MAX (1024)
/* Color depth:
* - 1: 1 byte per pixel
* - 8: RGB332
* - 16: RGB565
* - 32: ARGB8888
*/
#define LV_COLOR_DEPTH 8
/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
#define LV_MEM_CUSTOM 1
#if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (32U * 1024U)
/* Compiler prefix for a big array declaration */
# define LV_MEM_ATTR
/* Set an address for the memory pool instead of allocating it as an array.
* Can be in external SRAM too. */
# define LV_MEM_ADR 0xC0080000
/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */
# define LV_MEM_AUTO_DEFRAG 1
#else /*LV_MEM_CUSTOM*/
# define LV_MEM_CUSTOM_INCLUDE "FreeRTOS.h" /*Header for the dynamic memory function*/
# define LV_MEM_CUSTOM_ALLOC pvPortMalloc /*Wrapper to malloc*/
# define LV_MEM_CUSTOM_FREE vPortFree /*Wrapper to free*/
#endif /*LV_MEM_CUSTOM*/
Here is my code for LVGL:
#define LV_TICK_PERIOD_MS 1
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)
#define LAYER0_ADDRESS (0xc0000000)
static uint32_t * my_fb = (uint32_t *)LAYER0_ADDRESS;
void my_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t * area)
{
area->y1 = area->y1 & 0x10;
area->y2 = (area->y2 & 0x10) + 8;
}
void my_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa)
{
buf += buf_w * (y >> 3) + x;
if(lv_color_brightness(color) > 128) (*buf) |= (1 << (y % 8));
else (*buf) &= ~(1 << (y % 8));
}
void CopyBuffer(const uint32_t *pSrc, uint32_t *pDst, uint16_t x, uint16_t y, uint16_t xsize, uint16_t ysize)
{
uint32_t row;
for(row = y; row < y + ysize; row++ ) {
memcpy(&pDst[row * 480 + x], pSrc, xsize * 2);
pSrc += xsize;
}
}
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
CopyBuffer((const uint32_t *)color_p, my_fb, area->x1, area->y1, lv_area_get_width(area), lv_area_get_height(area));
lv_disp_flush_ready(disp_drv);
}
void vApplicationTickHook(void)
{
lv_tick_inc(1);
}
void LV_Task(void) {
lv_task_handler();
}
static void lvgl_timer_callback(xTimerHandle pxTimer)
{
lv_task_handler();
}
SemaphoreHandle_t xGuiSemaphore;
static lv_color_t buf[LV_HOR_RES_MAX * LV_VER_RES_MAX]; /*Declare a buffer*/
static lv_disp_buf_t disp_buf;
lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
static void Lv_init()
{
/* Initialize LVGL library */
lv_init();
printf("LVGL");
lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * LV_VER_RES_MAX); /*Initialize the display buffer*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.flush_cb = disp_flush; /*Set your driver function*/
disp_drv.buffer = &disp_buf; /*Assign the buffer to the display*/
lv_disp_drv_register(&disp_drv); /*Finally register the driver*/
lv_obj_t * scr1 = lv_scr_act();
lv_obj_t *label1 = lv_label_create(scr1, NULL);
lv_label_set_text(label1, "Hello world!");
lv_obj_set_style_local_bg_color(scr1, LV_OBJ_PART_MAIN, 0, LV_COLOR_BLUE);
vApplicationTickHook();
lv_task_handler();
xTimerHandle timerlvgl;
timerlvgl = xTimerCreate("LVGL", pdMS_TO_TICKS(1000), pdTRUE, NULL, lvgl_timer_callback);
xGuiSemaphore = xSemaphoreCreateMutex();
xTimerStart(timerlvgl, 50);
if (xTimerStart(timerlvgl, 0)!=pdPASS) {
for(;;);
}
}