sim: support LCD emulation over X11; correctly decouple LCD/FB from X11/NX

This commit is contained in:
Matias N 2020-11-01 22:38:48 -03:00 committed by Xiang Xiao
parent d987dd2f5a
commit fea3ee28f7
15 changed files with 128 additions and 66 deletions

View File

@ -205,36 +205,24 @@ config SIM_RPTUN_MASTER
bool "Remote Processor Tunneling Role"
depends on RPTUN
config SIM_LCDDRIVER
bool "Build a simulated LCD driver"
default y
depends on NX && NX_LCDDRIVER
---help---
Build a simulated LCD driver"
config SIM_FRAMEBUFFER
bool "Build a simulated frame buffer driver"
default n
depends on !NX_LCDDRIVER
---help---
Build a simulated frame buffer driver"
if SIM_FRAMEBUFFER
menu "Simulated Graphics/Input"
config SIM_X11FB
bool "Use X11 window"
default n
select SCHED_LPWORK
bool "X11 graphics/input"
default n
select SCHED_LPWORK
depends on SIM_WALLTIME
---help---
Use an X11 graphics window to simulate the graphics device"
Use X11 to provide graphics and input emulation to interact with host.
config SIM_X11NOSHM
bool "Don't use shared memory with X11"
default n
depends on SIM_X11FB
---help---
Don't use shared memory with the X11 graphics device emulation."
Don't use shared memory with the X11 graphics device emulation.
menu "Window Configuration"
config SIM_FBHEIGHT
int "Display height"
@ -244,8 +232,7 @@ config SIM_FBHEIGHT
config SIM_FBWIDTH
int "Display width"
default 320 if SIM_LCDDRIVER
default 480 if SIM_FRAMEBUFFER
default 320
---help---
Simulated width of the display. Default: 320 or 480
@ -257,28 +244,52 @@ config SIM_FBBPP
If you use the X11 display emulation, the selected BPP must match the BPP
of your graphics hardware (probably 32 bits). Default: 8
endif # SIM_FRAMEBUFFER
endmenu
if SIM_X11FB && INPUT
choice
prompt "X11 Simulated Input Device"
prompt "Graphics Device"
default SIM_FRAMEBUFFER
---help---
Choose which kind of graphics device to emulate
config SIM_LCDDRIVER
bool "LCD device"
depends on LCD
---help---
Emulate an LCD driver
config SIM_FRAMEBUFFER
bool "Framebuffer"
depends on VIDEO_FB
---help---
Emulate a framebuffer
endchoice
if INPUT
choice
prompt "Input Device"
default SIM_NOINPUT
config SIM_TOUCHSCREEN
bool "X11 mouse-based touchscreen emulation"
depends on SIM_X11FB
---help---
Support an X11 mouse-based touchscreen emulation. Also needs INPUT=y
config SIM_AJOYSTICK
bool "X11 mouse-based analog joystick emulation"
depends on SIM_X11FB
---help---
Support an X11 mouse-based analog joystick emulation. Also needs INPUT=y
config SIM_NOINPUT
bool "No input device"
endchoice # X11 Simulated Input Device
endif # SIM_X11FB && INPUT
endchoice # Input Device
endif # if INPUT
endmenu
config SIM_TCNWAITERS
bool "Maximum number poll() waiters"

View File

@ -125,10 +125,14 @@ ifeq ($(CONFIG_RTC_DRIVER),y)
CSRCS += up_rtc.c
endif
ifeq ($(CONFIG_NX_LCDDRIVER),y)
ifeq ($(CONFIG_SIM_LCDDRIVER),y)
CSRCS += up_lcd.c
else
CSRCS += up_framebuffer.c
ifeq ($(CONFIG_SIM_FRAMEBUFFER),y)
CSRCS += up_framebuffer.c
endif
endif
ifeq ($(CONFIG_SIM_X11FB),y)
ifeq ($(CONFIG_SIM_X11NOSHM),y)
HOSTCFLAGS += -DCONFIG_SIM_X11NOSHM=1
@ -146,7 +150,6 @@ else ifeq ($(CONFIG_SIM_AJOYSTICK),y)
HOSTSRCS += up_x11eventloop.c
endif
endif
endif
ifeq ($(CONFIG_SIM_IOEXPANDER),y)
CSRCS += up_ioexpander.c

View File

@ -54,18 +54,6 @@
* Pre-processor Definitions
****************************************************************************/
#ifndef CONFIG_SIM_FBWIDTH
# define CONFIG_SIM_FBWIDTH 480 /* Framebuffer width in pixels */
#endif
#ifndef CONFIG_SIM_FBHEIGHT
# define CONFIG_SIM_FBHEIGHT 240 /* Framebuffer height in pixels */
#endif
#ifndef CONFIG_SIM_FBBPP
# define CONFIG_SIM_FBBPP 16 /* Framebuffer bytes per pixel (RGB) */
#endif
#undef FB_FMT
#if CONFIG_SIM_FBBPP == 1
# define FB_FMT FB_FMT_RGB1

View File

@ -49,6 +49,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <nuttx/lcd/lcd.h>
#include "up_internal.h"
/****************************************************************************
* Pre-processor Definitions
@ -70,18 +71,6 @@
/* Simulated LCD geometry and color format */
#ifndef CONFIG_SIM_FBWIDTH
# define CONFIG_SIM_FBWIDTH 320 /* Framebuffer width in pixels */
#endif
#ifndef CONFIG_SIM_FBHEIGHT
# define CONFIG_SIM_FBHEIGHT 240 /* Framebuffer height in pixels */
#endif
#ifndef CONFIG_SIM_FBBPP
# define CONFIG_SIM_FBBPP 16 /* Framebuffer bytes per pixel (RGB) */
#endif
#define FB_STRIDE ((CONFIG_SIM_FBBPP * CONFIG_SIM_FBWIDTH + 7) >> 3)
#undef FB_FMT
@ -159,6 +148,7 @@ static int sim_setcontrast(struct lcd_dev_s *dev, unsigned int contrast);
* Private Data
****************************************************************************/
#ifndef CONFIG_SIM_X11FB
/* This is working memory allocated by the LCD driver for each LCD device
* and for each color plane. This memory will hold one raster line of data.
* The size of the allocated run buffer must therefore be at least
@ -171,6 +161,12 @@ static int sim_setcontrast(struct lcd_dev_s *dev, unsigned int contrast);
*/
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 */
@ -184,12 +180,13 @@ static const struct fb_videoinfo_s g_videoinfo =
/* This is the standard, NuttX Plane information object */
static const struct lcd_planeinfo_s g_planeinfo =
static struct lcd_planeinfo_s g_planeinfo =
{
.putrun = sim_putrun, /* Put a run into LCD memory */
.getrun = sim_getrun, /* Get a run from LCD memory */
#ifndef CONFIG_SIM_X11FB
.buffer = (FAR uint8_t *)g_runbuffer, /* Run scratch buffer */
.display = 0, /* Display number */
#endif
.bpp = CONFIG_SIM_FBBPP, /* Bits-per-pixel */
};
@ -239,6 +236,12 @@ static int sim_putrun(fb_coord_t row, fb_coord_t col,
FAR const uint8_t *buffer, size_t npixels)
{
lcdinfo("row: %d col: %d npixels: %d\n", row, col, npixels);
#ifdef CONFIG_SIM_X11FB
memcpy(&g_planeinfo.buffer[row * g_stride + col * (g_planeinfo.bpp / 8)],
buffer, npixels * g_planeinfo.bpp / 8);
#endif
return OK;
}
@ -365,6 +368,18 @@ static int sim_setcontrast(struct lcd_dev_s *dev, unsigned int contrast)
return -ENOSYS;
}
/****************************************************************************
* Name: up_updatework
****************************************************************************/
#ifdef CONFIG_SIM_X11FB
static void up_updatework(FAR void *arg)
{
work_queue(LPWORK, &g_updatework, up_updatework, NULL, MSEC2TICK(33));
up_x11update();
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -381,8 +396,23 @@ static int sim_setcontrast(struct lcd_dev_s *dev, unsigned int contrast)
int board_lcd_initialize(void)
{
int ret = OK;
ginfo("Initializing\n");
return OK;
#ifdef CONFIG_SIM_X11FB
ret = up_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, up_updatework, NULL, MSEC2TICK(33));
}
#endif
return ret;
}
/****************************************************************************

View File

@ -20,7 +20,6 @@ CONFIG_EXAMPLES_FB=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_MAX_TASKS=16
CONFIG_SDCLONE_DISABLE=y
CONFIG_SIM_FRAMEBUFFER=y
CONFIG_START_DAY=28
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2008

View File

@ -46,7 +46,6 @@ CONFIG_SDCLONE_DISABLE=y
CONFIG_SIM_FBBPP=32
CONFIG_SIM_FBHEIGHT=480
CONFIG_SIM_FBWIDTH=640
CONFIG_SIM_FRAMEBUFFER=y
CONFIG_SIM_TOUCHSCREEN=y
CONFIG_SIM_X11FB=y
CONFIG_STACK_CANARIES=y

View File

@ -16,6 +16,7 @@ CONFIG_ARCH_SIM=y
CONFIG_BUILTIN=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVERS_VIDEO=y
CONFIG_EXAMPLES_NX=y
CONFIG_EXAMPLES_NXHELLO=y
CONFIG_EXAMPLES_NXHELLO_FONTID=6
@ -49,7 +50,6 @@ CONFIG_NX_XYINPUT_MOUSE=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SIM_FBBPP=32
CONFIG_SIM_FRAMEBUFFER=y
CONFIG_SIM_TOUCHSCREEN=y
CONFIG_SIM_X11FB=y
CONFIG_START_DAY=6
@ -58,3 +58,4 @@ CONFIG_START_YEAR=2011
CONFIG_SYSTEM_NSH=y
CONFIG_USERMAIN_STACKSIZE=4096
CONFIG_USER_ENTRYPOINT="nsh_main"
CONFIG_VIDEO_FB=y

View File

@ -15,6 +15,7 @@ CONFIG_ARCH_SIM=y
CONFIG_DISABLE_ENVIRON=y
CONFIG_DISABLE_MOUNTPOINT=y
CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVERS_VIDEO=y
CONFIG_EXAMPLES_NX=y
CONFIG_EXAMPLES_NX_BPP=8
CONFIG_IDLETHREAD_STACKSIZE=4096
@ -26,9 +27,9 @@ CONFIG_NX_BLOCKING=y
CONFIG_NX_KBD=y
CONFIG_NX_XYINPUT_MOUSE=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SIM_FRAMEBUFFER=y
CONFIG_START_DAY=28
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2008
CONFIG_USERMAIN_STACKSIZE=4096
CONFIG_USER_ENTRYPOINT="nx_main"
CONFIG_VIDEO_FB=y

View File

@ -15,6 +15,7 @@ CONFIG_ARCH_SIM=y
CONFIG_DISABLE_ENVIRON=y
CONFIG_DISABLE_MOUNTPOINT=y
CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVERS_VIDEO=y
CONFIG_EXAMPLES_NX=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_MAX_TASKS=16
@ -26,10 +27,10 @@ CONFIG_NX_KBD=y
CONFIG_NX_XYINPUT_MOUSE=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SIM_FBBPP=32
CONFIG_SIM_FRAMEBUFFER=y
CONFIG_SIM_X11FB=y
CONFIG_START_DAY=28
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2008
CONFIG_USERMAIN_STACKSIZE=16384
CONFIG_USER_ENTRYPOINT="nx_main"
CONFIG_VIDEO_FB=y

View File

@ -17,6 +17,7 @@ CONFIG_ARCH_SIM=y
CONFIG_BOARD_LOOPSPERMSEC=0
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVERS_VIDEO=y
CONFIG_EXAMPLES_NXLINES=y
CONFIG_EXAMPLES_NXLINES_BGCOLOR=0x00006400
CONFIG_EXAMPLES_NXLINES_BORDERCOLOR=0x00ffff00
@ -51,9 +52,9 @@ CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SIM_FBBPP=32
CONFIG_SIM_FRAMEBUFFER=y
CONFIG_SIM_X11FB=y
CONFIG_START_MONTH=5
CONFIG_START_YEAR=2012
CONFIG_USERMAIN_STACKSIZE=16384
CONFIG_USER_ENTRYPOINT="nxlines_main"
CONFIG_VIDEO_FB=y

View File

@ -15,6 +15,7 @@ CONFIG_ARCH_CHIP="sim"
CONFIG_ARCH_SIM=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVERS_VIDEO=y
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FS_FAT=y
@ -49,8 +50,8 @@ CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SIM_FBBPP=32
CONFIG_SIM_FRAMEBUFFER=y
CONFIG_SIM_X11FB=y
CONFIG_START_MONTH=5
CONFIG_START_YEAR=2012
CONFIG_USER_ENTRYPOINT="nxwm_main"
CONFIG_VIDEO_FB=y

View File

@ -29,7 +29,6 @@ CONFIG_SDCLONE_DISABLE=y
CONFIG_SIM_FBBPP=32
CONFIG_SIM_FBHEIGHT=320
CONFIG_SIM_FBWIDTH=240
CONFIG_SIM_FRAMEBUFFER=y
CONFIG_SIM_TOUCHSCREEN=y
CONFIG_SIM_X11FB=y
CONFIG_START_DAY=28

View File

@ -59,7 +59,7 @@ ifeq ($(CONFIG_LIB_ZONEINFO_ROMFS),y)
endif
endif
ifeq ($(CONFIG_NX),y)
ifeq ($(CONFIG_SIM_X11FB),y)
ifeq ($(CONFIG_SIM_TOUCHSCREEN),y)
CSRCS += sim_touchscreen.c
endif

View File

@ -41,6 +41,10 @@
#include <nuttx/wireless/bluetooth/bt_null.h>
#include <nuttx/wireless/ieee802154/ieee802154_loopback.h>
#ifdef CONFIG_LCD_DEV
#include <nuttx/lcd/lcd_dev.h>
#endif
#include "up_internal.h"
#include "sim.h"
@ -259,6 +263,26 @@ int sim_bringup(void)
}
# endif
# ifdef CONFIG_LCD
ret = board_lcd_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: board_lcd_initialize() failed: %d\n", ret);
}
# ifdef CONFIG_LCD_DEV
ret = lcddev_register(0);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: lcddev_register() failed: %d\n", ret);
}
# endif
# endif
# ifdef CONFIG_SIM_TOUCHSCREEN
/* Initialize the touchscreen */

View File

@ -228,6 +228,7 @@ int sim_tsc_setup(int minor)
return ERROR;
}
#ifdef CONFIG_NX
/* Set the background to the configured background color */
iinfo("Set background color=%d\n", CONFIG_EXAMPLES_TOUCHSCREEN_BGCOLOR);
@ -239,6 +240,9 @@ int sim_tsc_setup(int minor)
ierr("ERROR: nx_setbgcolor failed: %d\n", ret);
goto errout_with_nx;
}
#else
UNUSED(color);
#endif
/* Finally, initialize the touchscreen simulation on the X window */