diff --git a/arch/sim/src/sim/sim_framebuffer.c b/arch/sim/src/sim/sim_framebuffer.c index 86eed48183..276c0a0e6b 100644 --- a/arch/sim/src/sim/sim_framebuffer.c +++ b/arch/sim/src/sim/sim_framebuffer.c @@ -127,8 +127,6 @@ static const struct fb_planeinfo_s g_planeinfo = .bpp = CONFIG_SIM_FBBPP, }; #else -static struct work_s g_updatework; - /* This structure describes the single, X11 color plane */ static struct fb_planeinfo_s g_planeinfo; @@ -150,7 +148,7 @@ static struct fb_cursorsize_s g_csize; * in this simple framebuffer simulation. */ -struct fb_vtable_s g_fbobject = +static struct fb_vtable_s g_fbobject = { .getvideoinfo = sim_getvideoinfo, .getplaneinfo = sim_getplaneinfo, @@ -334,23 +332,32 @@ static int sim_setcursor(struct fb_vtable_s *vtable, } #endif -/**************************************************************************** - * Name: sim_updatework - ****************************************************************************/ - -#ifdef CONFIG_SIM_X11FB -static void sim_updatework(void *arg) -{ - work_queue(LPWORK, &g_updatework, sim_updatework, NULL, MSEC2TICK(33)); - sim_x11update(); - fb_pollnotify(&g_fbobject); -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: sim_x11loop + ****************************************************************************/ + +void sim_x11loop(void) +{ +#ifdef CONFIG_SIM_X11FB + if (g_planeinfo.fbmem != NULL) + { + static clock_t last; + clock_t now = clock_systime_ticks(); + + if (now - last >= MSEC2TICK(16)) + { + sim_x11update(); + fb_pollnotify(&g_fbobject); + last = now; + } + } +#endif +} + /**************************************************************************** * Name: up_fbinitialize * @@ -373,12 +380,8 @@ int up_fbinitialize(int display) #ifdef CONFIG_SIM_X11FB ret = sim_x11initialize(CONFIG_SIM_FBWIDTH, CONFIG_SIM_FBHEIGHT, - &g_planeinfo.fbmem, &g_planeinfo.fblen, - &g_planeinfo.bpp, &g_planeinfo.stride); - if (ret == OK) - { - work_queue(LPWORK, &g_updatework, sim_updatework, NULL, MSEC2TICK(33)); - } + &g_planeinfo.fbmem, &g_planeinfo.fblen, + &g_planeinfo.bpp, &g_planeinfo.stride); #endif return ret; diff --git a/arch/sim/src/sim/sim_initialize.c b/arch/sim/src/sim/sim_initialize.c index 48af8bde77..1eb23e5879 100644 --- a/arch/sim/src/sim/sim_initialize.c +++ b/arch/sim/src/sim/sim_initialize.c @@ -173,6 +173,10 @@ static int sim_loop_task(int argc, char **argv) sim_x11events(); #endif +#if defined(CONFIG_SIM_LCDDRIVER) || defined(CONFIG_SIM_FRAMEBUFFER) + sim_x11loop(); +#endif + #ifdef CONFIG_SIM_NETDEV /* Run the network if enabled */ diff --git a/arch/sim/src/sim/sim_internal.h b/arch/sim/src/sim/sim_internal.h index 2dc5267f3b..037bc27300 100644 --- a/arch/sim/src/sim/sim_internal.h +++ b/arch/sim/src/sim/sim_internal.h @@ -241,6 +241,12 @@ void sim_x11events(void); void sim_buttonevent(int x, int y, int buttons); #endif +/* sim_framebuffer.c sim_lcd.c **********************************************/ + +#if defined(CONFIG_SIM_LCDDRIVER) || defined(CONFIG_SIM_FRAMEBUFFER) +void sim_x11loop(void); +#endif + /* sim_ajoystick.c **********************************************************/ #ifdef CONFIG_SIM_AJOYSTICK diff --git a/arch/sim/src/sim/sim_lcd.c b/arch/sim/src/sim/sim_lcd.c index c71c72820a..b20193f44f 100644 --- a/arch/sim/src/sim/sim_lcd.c +++ b/arch/sim/src/sim/sim_lcd.c @@ -157,8 +157,6 @@ static uint8_t g_runbuffer[FB_STRIDE]; #else static size_t g_fblen; static unsigned short g_stride; - -static struct work_s g_updatework; #endif /* This structure describes the overall LCD video controller */ @@ -432,13 +430,22 @@ static int sim_setcontrast(struct lcd_dev_s *dev, unsigned int contrast) * Name: sim_updatework ****************************************************************************/ -#ifdef CONFIG_SIM_X11FB -static void sim_updatework(void *arg) +void sim_x11loop(void) { - work_queue(LPWORK, &g_updatework, sim_updatework, NULL, MSEC2TICK(33)); - sim_x11update(); -} +#ifdef CONFIG_SIM_X11FB + if (g_planeinfo.buffer != NULL) + { + static clock_t last; + clock_t now = clock_systime_ticks(); + + if (now - last >= MSEC2TICK(16)) + { + sim_x11update(); + last = now; + } + } #endif +} /**************************************************************************** * Public Functions @@ -462,14 +469,8 @@ int board_lcd_initialize(void) #ifdef CONFIG_SIM_X11FB ret = sim_x11initialize(CONFIG_SIM_FBWIDTH, CONFIG_SIM_FBHEIGHT, - (void**)&g_planeinfo.buffer, &g_fblen, - &g_planeinfo.bpp, &g_stride); - - if (ret == OK) - { - work_queue(LPWORK, &g_updatework, sim_updatework, NULL, MSEC2TICK(33)); - } - + (void**)&g_planeinfo.buffer, &g_fblen, + &g_planeinfo.bpp, &g_stride); #endif return ret;