From 96f2df4c0901c54dd3826b975735d61c54cc6a46 Mon Sep 17 00:00:00 2001 From: Yu Xifeng <2860280851@qq.com> Date: Sun, 15 Dec 2024 08:23:39 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8F=8C=E5=B1=8F=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8=E5=92=8C=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/lv_drivers/display/fbdev.c | 227 +++++++++++++++++++++++--- components/lv_drivers/display/fbdev.h | 3 +- components/lv_port/lv_drv_conf.h | 7 +- main_app/lvgl_app.c | 151 ++++++++++++++++- main_app/lvgl_app.h | 4 +- main_app/lvgl_task.c | 42 ++++- 6 files changed, 396 insertions(+), 38 deletions(-) diff --git a/components/lv_drivers/display/fbdev.c b/components/lv_drivers/display/fbdev.c index 71c6b2d..97d38f0 100755 --- a/components/lv_drivers/display/fbdev.c +++ b/components/lv_drivers/display/fbdev.c @@ -69,8 +69,8 @@ struct bsd_fb_fix_info{ static struct bsd_fb_var_info vinfo; static struct bsd_fb_fix_info finfo; #else -static struct fb_var_screeninfo vinfo; -static struct fb_fix_screeninfo finfo; +// static struct fb_var_screeninfo vinfo; +// static struct fb_fix_screeninfo finfo; #endif /* USE_BSD_FBDEV */ static char *fbp = 0; static long int screensize = 0; @@ -84,19 +84,50 @@ static int fbfd = 0; #define FBIOBLANK FBIO_BLANK #endif /* USE_BSD_FBDEV */ +#ifdef LV_DISP_MAX_NUM + +typedef struct fbdev_lvgl_t_ +{ + const char* fbdev_path; + int fbfd; + char *fbp; + struct fb_var_screeninfo vinfo; + struct fb_fix_screeninfo finfo; +}fbdev_lvgl_t; + +fbdev_lvgl_t fbdev_1 ={ + .fbdev_path = FBDEV_PATH, + .fbfd = 0, + .fbp = 0, +}; +fbdev_lvgl_t fbdev_2={ + .fbdev_path = FBDEV_2_PATH, + .fbfd = 0, + .fbp = 0, +}; +#endif + + /********************** * GLOBAL FUNCTIONS **********************/ -void fbdev_init(void) +void fbdev_init(const char* fbdev_path) { // Open the file for reading and writing - fbfd = open(FBDEV_PATH, O_RDWR); + fbfd = open(fbdev_path, O_RDWR); if(fbfd == -1) { perror("Error: cannot open framebuffer device"); return; } LV_LOG_INFO("The framebuffer device was opened successfully"); + if (strcmp(fbdev_2.fbdev_path, fbdev_path) == 0) { + fbdev_2.fbfd = fbfd; + printf("fbdev_2.fbfd:%d\r\n",fbdev_2.fbfd); + }else{ + fbdev_1.fbfd = fbfd; + printf("fbdev_1.fbfd:%d\r\n",fbdev_1.fbfd); + } // Make sure that the display is on. // if (ioctl(fbfd, FBIOBLANK, FB_BLANK_UNBLANK) != 0) { @@ -129,32 +160,71 @@ void fbdev_init(void) finfo.smem_len = finfo.line_length * vinfo.yres; #else /* USE_BSD_FBDEV */ - // Get fixed screen information - if(ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) { - perror("Error reading fixed information"); - return; - } + // // Get fixed screen information + // if(ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) { + // perror("Error reading fixed information"); + // return; + // } - // Get variable screen information - if(ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) { - perror("Error reading variable information"); - return; - } - screensize = finfo.line_length * vinfo.yres; + // // Get variable screen information + // if(ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) { + // perror("Error reading variable information"); + // return; + // } + // screensize = finfo.line_length * vinfo.yres; #endif /* USE_BSD_FBDEV */ - LV_LOG_INFO("%dx%d, %dbpp", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel); + // LV_LOG_INFO("%dx%d, %dbpp", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel); - // Figure out the size of the screen in bytes - // screensize = finfo.smem_len; //finfo.line_length * vinfo.yres; - fbp = mmap(NULL, screensize, PROT_WRITE, MAP_SHARED, fbfd, 0); - // Map the device to memory - //fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); - if((intptr_t)fbp == -1) { - perror("Error: failed to map framebuffer device to memory"); - return; + // // Figure out the size of the screen in bytes + // // screensize = finfo.smem_len; //finfo.line_length * vinfo.yres; + // fbp = mmap(NULL, screensize, PROT_WRITE, MAP_SHARED, fbfd, 0); + // // Map the device to memory + // //fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); + // if((intptr_t)fbp == -1) { + // perror("Error: failed to map framebuffer device to memory"); + // return; + // } + if(fbdev_2.fbfd == fbfd) + { + // Get fixed screen information + if(ioctl(fbfd, FBIOGET_FSCREENINFO, &fbdev_2.finfo) == -1) { + perror("Error reading fixed information"); + return; + } + + // Get variable screen information + if(ioctl(fbfd, FBIOGET_VSCREENINFO, &fbdev_2.vinfo) == -1) { + perror("Error reading variable information"); + return; + } + screensize = fbdev_2.finfo.line_length * fbdev_2.vinfo.yres; + fbdev_2.fbp = mmap(NULL, screensize, PROT_WRITE, MAP_SHARED, fbfd, 0); + if((intptr_t)fbdev_2.fbp == -1) { + perror("Error: failed to map framebuffer device to memory"); + return; + } + fbp = fbdev_2.fbp; + }else{ + // Get fixed screen information + if(ioctl(fbfd, FBIOGET_FSCREENINFO, &fbdev_1.finfo) == -1) { + perror("Error reading fixed information"); + return; + } + + // Get variable screen information + if(ioctl(fbfd, FBIOGET_VSCREENINFO, &fbdev_1.vinfo) == -1) { + perror("Error reading variable information"); + return; + } + screensize = fbdev_1.finfo.line_length * fbdev_1.vinfo.yres; + fbdev_1.fbp = mmap(NULL, screensize, PROT_WRITE, MAP_SHARED, fbfd, 0); + if((intptr_t)fbdev_1.fbp == -1) { + perror("Error: failed to map framebuffer device to memory"); + return; + } + fbp = fbdev_1.fbp; } - // Don't initialise the memory to retain what's currently displayed / avoid clearing the screen. // This is important for applications that only draw to a subsection of the full framebuffer. @@ -175,6 +245,11 @@ void fbdev_exit(void) */ void fbdev_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p) { + static struct fb_var_screeninfo vinfo; + static struct fb_fix_screeninfo finfo; + fbp = fbdev_1.fbp; + vinfo = fbdev_1.vinfo; + finfo = fbdev_1.finfo; if(fbp == NULL || area->x2 < 0 || area->y2 < 0 || @@ -253,7 +328,103 @@ void fbdev_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color lv_disp_flush_ready(drv); } +/** + * Flush a buffer to the marked area + * @param drv pointer to driver where this function belongs + * @param area an area where to copy `color_p` + * @param color_p an array of pixels to copy to the `area` part of the screen + */ +void fbdev_flush_2(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p) +{ + static struct fb_var_screeninfo vinfo; + static struct fb_fix_screeninfo finfo; + fbp = fbdev_2.fbp; + vinfo = fbdev_2.vinfo; + finfo = fbdev_2.finfo; + if(fbp == NULL || + area->x2 < 0 || + area->y2 < 0 || + area->x1 > (int32_t)vinfo.xres - 1 || + area->y1 > (int32_t)vinfo.yres - 1) { + lv_disp_flush_ready(drv); + return; + } + + /*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)vinfo.xres - 1 ? (int32_t)vinfo.xres - 1 : area->x2; + int32_t act_y2 = area->y2 > (int32_t)vinfo.yres - 1 ? (int32_t)vinfo.yres - 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; + + /*32 or 24 bit per pixel*/ + if(vinfo.bits_per_pixel == 32 || vinfo.bits_per_pixel == 24) { + uint32_t * fbp32 = (uint32_t *)fbp; + int32_t y; + for(y = act_y1; y <= act_y2; y++) { + location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length / 4; + memcpy(&fbp32[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 4); + color_p += w; + } + } + /*16 bit per pixel*/ + else if(vinfo.bits_per_pixel == 16) { + uint16_t * fbp16 = (uint16_t *)fbp; + int32_t y; + for(y = act_y1; y <= act_y2; y++) { + location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length / 2; + memcpy(&fbp16[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 2); + color_p += w; + } + } + /*8 bit per pixel*/ + else if(vinfo.bits_per_pixel == 8) { + uint8_t * fbp8 = (uint8_t *)fbp; + int32_t y; + for(y = act_y1; y <= act_y2; y++) { + location = (act_x1 + vinfo.xoffset) + (y + vinfo.yoffset) * finfo.line_length; + memcpy(&fbp8[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1)); + color_p += w; + } + } + /*1 bit per pixel*/ + else if(vinfo.bits_per_pixel == 1) { + uint8_t * fbp8 = (uint8_t *)fbp; + int32_t x; + int32_t y; + for(y = act_y1; y <= act_y2; y++) { + for(x = act_x1; x <= act_x2; x++) { + location = (x + vinfo.xoffset) + (y + vinfo.yoffset) * vinfo.xres; + byte_location = location / 8; /* find the byte we need to change */ + bit_location = location % 8; /* inside the byte found, find the bit we need to change */ + fbp8[byte_location] &= ~(((uint8_t)(1)) << bit_location); + fbp8[byte_location] |= ((uint8_t)(color_p->full)) << bit_location; + color_p++; + } + + color_p += area->x2 - act_x2; + } + } 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)); + + lv_disp_flush_ready(drv); +} + + void fbdev_get_sizes(uint32_t *width, uint32_t *height, uint32_t *dpi) { + static struct fb_var_screeninfo vinfo; + static struct fb_fix_screeninfo finfo; + vinfo = fbdev_1.vinfo; + finfo = fbdev_1.finfo; if (width) *width = vinfo.xres; @@ -265,6 +436,12 @@ void fbdev_get_sizes(uint32_t *width, uint32_t *height, uint32_t *dpi) { } void fbdev_set_offset(uint32_t xoffset, uint32_t yoffset) { + + static struct fb_var_screeninfo vinfo; + static struct fb_fix_screeninfo finfo; + vinfo = fbdev_1.vinfo; + finfo = fbdev_1.finfo; + vinfo.xoffset = xoffset; vinfo.yoffset = yoffset; } diff --git a/components/lv_drivers/display/fbdev.h b/components/lv_drivers/display/fbdev.h index e73dba1..d2acede 100755 --- a/components/lv_drivers/display/fbdev.h +++ b/components/lv_drivers/display/fbdev.h @@ -40,9 +40,10 @@ extern "C" { /********************** * GLOBAL PROTOTYPES **********************/ -void fbdev_init(void); +void fbdev_init(const char* fbdev_path); void fbdev_exit(void); void fbdev_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p); +void fbdev_flush_2(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p); void fbdev_get_sizes(uint32_t *width, uint32_t *height, uint32_t *dpi); /** * Set the X and Y offset in the variable framebuffer info. diff --git a/components/lv_port/lv_drv_conf.h b/components/lv_port/lv_drv_conf.h index 92b1002..4463379 100755 --- a/components/lv_port/lv_drv_conf.h +++ b/components/lv_port/lv_drv_conf.h @@ -273,10 +273,15 @@ *-----------------------------------------*/ #ifndef USE_FBDEV # define USE_FBDEV 1 +#define LV_DISP_MAX_NUM 2 #endif #if USE_FBDEV -# define FBDEV_PATH "/dev/fb0" +# define FBDEV_PATH "/dev/fb1" + +#if LV_DISP_MAX_NUM == 2 +# define FBDEV_2_PATH "/dev/fb0" +#endif #endif /*----------------------------------------- diff --git a/main_app/lvgl_app.c b/main_app/lvgl_app.c index 1d00d9b..9a75d70 100755 --- a/main_app/lvgl_app.c +++ b/main_app/lvgl_app.c @@ -254,11 +254,160 @@ void screen_Navigation_bar(lv_obj_t * parent) } +void Load_Physical_screen(lv_disp_t * disp) +{ + lv_disp_set_default(disp); +} + +static void btn_event_cb(lv_event_t * e) +{ + lv_obj_t * btn = lv_event_get_target(e); // 获取触发事件的按钮 + uint32_t i = (uint32_t)lv_obj_get_user_data(btn); // 获取按钮的索引 + lv_obj_t * label = lv_obj_get_child(btn, NULL); + + // printf("第%d按钮被按下!\n",i); // 打印信息 + // // lv_disp_set_default(disp_480x320); + // lv_font_open_Init(32); + // /*Create style with the new font*/ + // static lv_style_t style; + // lv_style_init(&style); + // lv_style_set_text_font(&style, MHEIGB_Info[32].font); + // lv_style_set_text_align(&style, LV_TEXT_ALIGN_AUTO); + // lv_obj_t * Hello_lable = lv_obj_get_child(Lock_screen.screen,NULL); + + // lv_obj_add_style(Hello_lable, &style, 0); + // lv_label_set_text_fmt(Hello_lable, "%d:画板",i); + + // lv_disp_set_default(disp_300x240); + // lv_label_set_text_fmt(label, "%d:按下",i); + +} + +// 定义面板的事件回调函数 +static void panel_event_cb(lv_event_t * e) +{ + int i=0; + lv_obj_t * panel = lv_event_get_target(e); + lv_coord_t scroll_x = lv_obj_get_scroll_x(panel); + lv_coord_t panel_width = lv_obj_get_width(panel); + lv_coord_t btn_width = 150; // 按钮宽度 + + +} + +void lv_example_scroll_2(void) +{ + lv_obj_t * panel = lv_obj_create(lv_scr_act()); + lv_obj_set_size(panel, 300, 220); + lv_obj_set_scroll_snap_x(panel, LV_SCROLL_SNAP_CENTER); + lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW); + lv_obj_align(panel, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_scroll_dir(panel, LV_DIR_HOR); + uint32_t i; + uint32_t btn_width = 150; // 按钮宽度 + lv_font_open_Init(36); + static lv_style_t style; + lv_style_init(&style); + lv_style_set_text_font(&style, MHEIGB_Info[36].font); + for(i = 0; i < 9; i++) { + lv_obj_t * btn = lv_btn_create(panel); + lv_obj_set_size(btn, btn_width, lv_pct(108)); + + lv_obj_t * label = lv_label_create(btn); + lv_obj_add_style(label, &style, 0); + switch (i) + { + // case 0: + // lv_label_set_text(label, "0"); + // break; + // case 1: + // lv_label_set_text(label, "1"); + // break; + default: + lv_label_set_text_fmt(label, "Panel %"LV_PRIu32, i); + break; + } + + lv_obj_center(label); + + // 设置按钮的索引作为用户数据 + lv_obj_set_user_data(btn, i); + + // 为按钮添加事件回调,监听点击事件 + lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_CLICKED, NULL); + } + + // 滚动到第二个按钮 + lv_obj_scroll_to_x(panel, btn_width * 1, LV_ANIM_OFF); // 第二个按钮的位置 + lv_obj_update_snap(panel, LV_ANIM_ON); + lv_obj_add_flag(panel, LV_OBJ_FLAG_SCROLL_ONE); + + // 添加事件回调,监听滚动事件 + // lv_obj_add_event_cb(panel, panel_event_cb, LV_EVENT_SCROLL, NULL); + // 使得滚动面板实现循环 + lv_obj_add_event_cb(panel, panel_event_cb, LV_EVENT_SCROLL, NULL); + lv_obj_add_event_cb(panel, panel_event_cb, LV_EVENT_SCROLL_END, NULL); +} + + + + +void Center_menu() +{ + lv_example_scroll_2(); +} + +void Physical_Screen_480x320() +{ + lv_disp_t * disp = disp_480x320; + // disp = lv_disp_get_next(disp); + lv_disp_set_default(disp); + + lv_style_init(&Lock_screen.style); + lv_style_set_outline_color(&Lock_screen.style,lv_palette_main(LV_PALETTE_BLUE)); + lv_style_set_border_opa(&Lock_screen.style,LV_OPA_0); //设置边框透明度 + // lv_style_set_outline_opa(&Lock_screen.style,LV_OPA_0); //设置外轮廓透明度 + Lock_screen.screen = lv_obj_create(lv_scr_act()); + lv_obj_set_style_bg_color(Lock_screen.screen, lv_color_hex(0x696969), 0); // 设置背景颜色 + lv_obj_set_size(Lock_screen.screen,480,320); + lv_obj_set_align(Lock_screen.screen,LV_ALIGN_CENTER); + lv_obj_set_style_pad_all(Lock_screen.screen, 0, 0); + lv_obj_set_scrollbar_mode(Lock_screen.screen, LV_SCROLLBAR_MODE_OFF);//关闭滚动条 + lv_obj_set_style_radius(Lock_screen.screen,0,0);//设置容器圆角为直角 + lv_obj_add_style(Lock_screen.screen, &Lock_screen.style, 0); + lv_font_open_Init(72); + /*Create style with the new font*/ + static lv_style_t style; + lv_style_init(&style); + lv_style_set_text_font(&style, MHEIGB_Info[72].font); + lv_style_set_text_align(&style, LV_TEXT_ALIGN_AUTO); + /*Create a label with the new style*/ + lv_obj_t * Hello_lable = lv_label_create(Lock_screen.screen); + + lv_obj_add_style(Hello_lable, &style, 0); + lv_label_set_text(Hello_lable, "LinkEase-NAS"); + lv_obj_align(Hello_lable, LV_ALIGN_CENTER, 0, 0); + + lv_group_add_obj(Key_Matrix_Group ,Lock_screen.screen); + lv_obj_add_event_cb(Lock_screen.screen, Lock_screen.event_cb, LV_EVENT_ALL, NULL); +} + +void Physical_Screen_300x240() +{ + lv_disp_t * disp = disp_300x240; + // disp = lv_disp_get_next(disp); + lv_disp_set_default(disp); + + lv_example_scroll_2(); +} void lvgl_app_start() { uint16_t i=0; - lv_example_btn_1(); + Physical_Screen_480x320(); + Physical_Screen_300x240(); return; + // lv_example_btn_1(); + // return; lv_style_init(&Lock_screen.style); lv_style_set_outline_color(&Lock_screen.style,lv_palette_main(LV_PALETTE_BLUE)); lv_style_set_border_opa(&Lock_screen.style,LV_OPA_0); //设置边框透明度 diff --git a/main_app/lvgl_app.h b/main_app/lvgl_app.h index 94cc250..ad40fca 100755 --- a/main_app/lvgl_app.h +++ b/main_app/lvgl_app.h @@ -55,9 +55,11 @@ typedef struct extern lv_indev_t* Touch_indev; extern config_lv_page_t Lock_screen; extern config_lv_page_t Bar_screen; - +extern lv_disp_t * disp_480x320; +extern lv_disp_t * disp_300x240; extern void lv_example_freetype_1(lv_obj_t * parent); extern void Main_Picture_background(lv_obj_t * parent); extern void Main_interface_page_btn(lv_obj_t * parent); + #endif \ No newline at end of file diff --git a/main_app/lvgl_task.c b/main_app/lvgl_task.c index b49aa4a..6de6926 100755 --- a/main_app/lvgl_task.c +++ b/main_app/lvgl_task.c @@ -6,6 +6,9 @@ pthread_t Thread_Lv_Main; +lv_disp_t * disp_480x320; +lv_disp_t * disp_300x240; + #define DISP_BUF_SIZE (1280 * 720 * 4) extern void mouse_init(void); @@ -61,7 +64,8 @@ void *Lv_main_task(void *arg) lv_init(); #if USE_FBDEV /*Linux frame buffer device init*/ - fbdev_init(); + fbdev_init("/dev/fb0"); + fbdev_init("/dev/fb1"); #elif USE_DRM /*Linux DRM device init*/ drm_init(); @@ -82,15 +86,32 @@ void *Lv_main_task(void *arg) #if USE_FBDEV disp_drv.flush_cb = fbdev_flush; - disp_drv.hor_res = 320; - disp_drv.ver_res = 480; - // disp_drv.hor_res = 240; - // disp_drv.ver_res = 300; + // disp_drv.hor_res = 320; + // disp_drv.ver_res = 480; + disp_drv.hor_res = 240; + disp_drv.ver_res = 300; // disp_drv.hor_res = 800; // disp_drv.ver_res = 480; disp_drv.sw_rotate = 1; // add for rotation disp_drv.rotated = LV_DISP_ROT_90; // add for rotation - lv_disp_drv_register(&disp_drv); + disp_300x240 = lv_disp_drv_register(&disp_drv); + +#if LV_DISP_MAX_NUM == 2 + static lv_disp_draw_buf_t disp_buf2; + lv_disp_draw_buf_init(&disp_buf2, buf2, NULL, DISP_BUF_SIZE); + static lv_disp_drv_t disp_drv2; + lv_disp_drv_init(&disp_drv2); + disp_drv2.draw_buf = &disp_buf2; + disp_drv2.flush_cb = fbdev_flush_2; + disp_drv2.hor_res = 320; + disp_drv2.ver_res = 480; + disp_drv2.sw_rotate = 1; // add for rotation + disp_drv2.rotated = LV_DISP_ROT_90; // add for rotation + disp_480x320 = lv_disp_drv_register(&disp_drv2); + + lv_disp_set_default(disp_300x240); +#endif + #endif /* Linux input device init */ @@ -104,13 +125,16 @@ void *Lv_main_task(void *arg) indev_drv.type = LV_INDEV_TYPE_POINTER; indev_drv.read_cb = evdev_read; //lv_gesture_dir_t lv_indev_get_gesture_dir(const lv_indev_t * indev) - lv_indev_drv_register(&indev_drv); + indev_drv.disp = disp_300x240; + lv_indev_t* indev_touch = lv_indev_drv_register(&indev_drv); + // indev_drv.disp = disp1; + // lv_indev_drv_update(indev_touch,&indev_drv); #endif /*Create a Demo*/ //lv_demo_widgets(); - lv_demo_benchmark(); + // lv_demo_benchmark(); // lv_example_btn_1(); - // lvgl_app_start(); + lvgl_app_start(); while(1) { lv_timer_handler(); usleep(5000);