#include #include > #include #include "lv_drivers/display/fbdev.h" #include "lv_drivers/indev/evdev.h" #include "lv_drivers/indev/mouse.h" #include "font/lv_font.h" #include #include #include #include #include #include static char* frame_buf = NULL; static int32_t frame_len = 0; static bool frame_freshed = false; static int SCREEN_WIDTH = 294; //1920; static int SCREEN_HEIGHT = 70; //1080; static int BITS_P_PIXEL = 32; static bool runflag = false; static lv_color_t* draw_buf1 = NULL; static lv_color_t* draw_buf2 = NULL; // static lv_img_dsc_t IMG1; // static lv_img_dsc_t IMG2; uint32_t custom_tick_get(void) { static uint64_t start_ms = 0; if(start_ms == 0) { struct timeval tv_start; gettimeofday(&tv_start, NULL); start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000; } struct timeval tv_now; gettimeofday(&tv_now, NULL); uint64_t now_ms; now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000; uint32_t time_ms = now_ms - start_ms; return time_ms; } static void widgets_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p) { /*Truncate the area to the screen*/ int32_t act_x1 = area->x1 < 0 ? 0 : area->x1; int32_t act_y1 = area->y1 < 0 ? 0 : area->y1; int32_t act_x2 = area->x2 > (int32_t)SCREEN_WIDTH - 1 ? (int32_t)SCREEN_WIDTH - 1 : area->x2; int32_t act_y2 = area->y2 > (int32_t)SCREEN_HEIGHT - 1 ? (int32_t)SCREEN_HEIGHT - 1 : area->y2; lv_coord_t w = (act_x2 - act_x1 + 1); long int location = 0; long int byte_location = 0; unsigned char bit_location = 0; if(!frame_buf){ printf("frame buffer: %d\n", SCREEN_WIDTH*SCREEN_HEIGHT*BITS_P_PIXEL/8); frame_buf = (char*)malloc(SCREEN_WIDTH*SCREEN_HEIGHT*BITS_P_PIXEL/8); frame_len = SCREEN_WIDTH*SCREEN_HEIGHT*BITS_P_PIXEL/8; } int BytesPP = BITS_P_PIXEL/8; /*32 or 24 bit per pixel*/ if(BITS_P_PIXEL == 32 ||BITS_P_PIXEL == 24) { uint32_t * fbp32 = (uint32_t *)frame_buf; int32_t y; for(y = act_y1; y <= act_y2; y++) { location = (act_x1) + (y) * SCREEN_WIDTH; memcpy( &fbp32[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 4); color_p += w; } } else { /*Not supported bit per pixel*/ } //May be some direct update command is required //ret = ioctl(state->fd, FBIO_UPDATE, (unsigned long)((uintptr_t)rect)); frame_freshed = true; FILE* fp = fopen("./rgba_data_flush_from_lvgl.txt", "wb"); assert(fp); fwrite(frame_buf, 1, frame_len, fp); fclose(fp); lv_disp_flush_ready(drv); } static void driver_init(int w, int h, int bpp) { /*A small buffer for LittlevGL to draw the screen's content*/ //static lv_color_t buf[DISP_BUF_SIZE]; int DISP_BUF_SIZE = w*h*bpp/8; draw_buf1 = (lv_color_t*)malloc(DISP_BUF_SIZE); draw_buf2 = (lv_color_t*)malloc(DISP_BUF_SIZE); memset(draw_buf1, 0x0, DISP_BUF_SIZE); memset(draw_buf2, 0x0, DISP_BUF_SIZE); /*Initialize a descriptor for the buffer*/ static lv_disp_draw_buf_t disp_buf; lv_disp_draw_buf_init(&disp_buf, draw_buf1, draw_buf2, DISP_BUF_SIZE); /*Initialize and register a display driver*/ static lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); disp_drv.draw_buf = &disp_buf; #if FDEV disp_drv.flush_cb = fbdev_flush; // #else disp_drv.flush_cb = widgets_flush; #endif disp_drv.hor_res = w; //1920; //800; disp_drv.ver_res = h; //1080; //480; lv_disp_drv_register(&disp_drv); } void* lvgl_init_test(int w, int h, int bpp ) { runflag = true; SCREEN_WIDTH = w; SCREEN_HEIGHT = h; BITS_P_PIXEL = bpp; frame_buf = (char*)malloc(SCREEN_WIDTH*SCREEN_HEIGHT*BITS_P_PIXEL/8); frame_len = SCREEN_WIDTH*SCREEN_HEIGHT*BITS_P_PIXEL/8; memset(frame_buf, 0x0, frame_len); /*LittlevGL init*/ lv_init(); /*Linux frame buffer device init*/ #if FDEV fbdev_init(); #endif lv_png_init(); driver_init(w, h, bpp); lv_obj_set_style_bg_opa(lv_scr_act(), LV_OPA_TRANSP, LV_PART_MAIN); lv_disp_set_bg_opa(NULL, LV_OPA_TRANSP); lv_obj_t* top_vision = lv_img_create(lv_scr_act()); lv_obj_set_pos(top_vision, 0, 0); lv_obj_set_size(top_vision, w, h); lv_obj_t* disp_left = lv_img_create(top_vision); lv_img_set_src(disp_left, "../resources/passenger_alarm.png"); lv_obj_set_pos(disp_left, 0, 0); lv_obj_set_size(disp_left, 294, 70); lv_obj_set_style_bg_color(disp_left, lv_color_make(255, 0, 0), 0); lv_obj_set_style_bg_opa(disp_left, LV_OPA_TRANSP, LV_PART_ANY); return top_vision; } static void* GUI_handler(void* data) { /*Handle LitlevGL tasks (tickless mode)*/ while(runflag){ lv_timer_handler(); usleep(20000); } return NULL; } static void pic_timer(lv_timer_t* t) { return; } int main(void) { void* window_tv = lvgl_init_test(294, 70, 32); runflag = true; lv_timer_t* timer = lv_timer_create(pic_timer, 35, NULL); //SDL_CreateThread(GUI_handler, "GUI_handler", NULL); pthread_t pid; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); int ret = pthread_create(&pid, &attr, GUI_handler, NULL); pthread_attr_destroy(&attr); printf("GUI_handler = 0x%x\n", GUI_handler); while(runflag); return 1; }