You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/11/03 03:22:13 UTC
[incubator-nuttx] branch master updated: sim: support LCD emulation
over X11; correctly decouple LCD/FB from X11/NX
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new fea3ee2 sim: support LCD emulation over X11; correctly decouple LCD/FB from X11/NX
fea3ee2 is described below
commit fea3ee28f744da6a07a658518255b5899fd0b775
Author: Matias N <ma...@protobits.dev>
AuthorDate: Sun Nov 1 22:38:48 2020 -0300
sim: support LCD emulation over X11; correctly decouple LCD/FB from X11/NX
---
arch/sim/Kconfig | 65 ++++++++++++++----------
arch/sim/src/Makefile | 9 ++--
arch/sim/src/sim/up_framebuffer.c | 12 -----
arch/sim/src/sim/up_lcd.c | 60 ++++++++++++++++------
boards/sim/sim/sim/configs/fb/defconfig | 1 -
boards/sim/sim/sim/configs/lvgl/defconfig | 1 -
boards/sim/sim/sim/configs/nsh2/defconfig | 3 +-
boards/sim/sim/sim/configs/nx/defconfig | 3 +-
boards/sim/sim/sim/configs/nx11/defconfig | 3 +-
boards/sim/sim/sim/configs/nxlines/defconfig | 3 +-
boards/sim/sim/sim/configs/nxwm/defconfig | 3 +-
boards/sim/sim/sim/configs/touchscreen/defconfig | 1 -
boards/sim/sim/sim/src/Makefile | 2 +-
boards/sim/sim/sim/src/sim_bringup.c | 24 +++++++++
boards/sim/sim/sim/src/sim_touchscreen.c | 4 ++
15 files changed, 128 insertions(+), 66 deletions(-)
diff --git a/arch/sim/Kconfig b/arch/sim/Kconfig
index 1c09cac..13fc7ad 100644
--- a/arch/sim/Kconfig
+++ b/arch/sim/Kconfig
@@ -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"
diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile
index a7e13df..6b726ce 100644
--- a/arch/sim/src/Makefile
+++ b/arch/sim/src/Makefile
@@ -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
diff --git a/arch/sim/src/sim/up_framebuffer.c b/arch/sim/src/sim/up_framebuffer.c
index cdfaf19..9c3c0a6 100644
--- a/arch/sim/src/sim/up_framebuffer.c
+++ b/arch/sim/src/sim/up_framebuffer.c
@@ -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
diff --git a/arch/sim/src/sim/up_lcd.c b/arch/sim/src/sim/up_lcd.c
index eb184cd..605770b 100644
--- a/arch/sim/src/sim/up_lcd.c
+++ b/arch/sim/src/sim/up_lcd.c
@@ -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;
}
@@ -366,6 +369,18 @@ static int sim_setcontrast(struct lcd_dev_s *dev, unsigned int contrast)
}
/****************************************************************************
+ * 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;
}
/****************************************************************************
diff --git a/boards/sim/sim/sim/configs/fb/defconfig b/boards/sim/sim/sim/configs/fb/defconfig
index da138f7..1c708cc 100644
--- a/boards/sim/sim/sim/configs/fb/defconfig
+++ b/boards/sim/sim/sim/configs/fb/defconfig
@@ -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
diff --git a/boards/sim/sim/sim/configs/lvgl/defconfig b/boards/sim/sim/sim/configs/lvgl/defconfig
index d9ea14d..ea9c906 100644
--- a/boards/sim/sim/sim/configs/lvgl/defconfig
+++ b/boards/sim/sim/sim/configs/lvgl/defconfig
@@ -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
diff --git a/boards/sim/sim/sim/configs/nsh2/defconfig b/boards/sim/sim/sim/configs/nsh2/defconfig
index ce40932..4cfa2e9 100644
--- a/boards/sim/sim/sim/configs/nsh2/defconfig
+++ b/boards/sim/sim/sim/configs/nsh2/defconfig
@@ -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
diff --git a/boards/sim/sim/sim/configs/nx/defconfig b/boards/sim/sim/sim/configs/nx/defconfig
index 6bc94f0..a8994a8 100644
--- a/boards/sim/sim/sim/configs/nx/defconfig
+++ b/boards/sim/sim/sim/configs/nx/defconfig
@@ -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
diff --git a/boards/sim/sim/sim/configs/nx11/defconfig b/boards/sim/sim/sim/configs/nx11/defconfig
index ed5055d..6199703 100644
--- a/boards/sim/sim/sim/configs/nx11/defconfig
+++ b/boards/sim/sim/sim/configs/nx11/defconfig
@@ -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
diff --git a/boards/sim/sim/sim/configs/nxlines/defconfig b/boards/sim/sim/sim/configs/nxlines/defconfig
index 283a6df..7dac105 100644
--- a/boards/sim/sim/sim/configs/nxlines/defconfig
+++ b/boards/sim/sim/sim/configs/nxlines/defconfig
@@ -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
diff --git a/boards/sim/sim/sim/configs/nxwm/defconfig b/boards/sim/sim/sim/configs/nxwm/defconfig
index 4967e28..9663a12 100644
--- a/boards/sim/sim/sim/configs/nxwm/defconfig
+++ b/boards/sim/sim/sim/configs/nxwm/defconfig
@@ -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
diff --git a/boards/sim/sim/sim/configs/touchscreen/defconfig b/boards/sim/sim/sim/configs/touchscreen/defconfig
index fbb60c0..52f35f9 100644
--- a/boards/sim/sim/sim/configs/touchscreen/defconfig
+++ b/boards/sim/sim/sim/configs/touchscreen/defconfig
@@ -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
diff --git a/boards/sim/sim/sim/src/Makefile b/boards/sim/sim/sim/src/Makefile
index ef66e5b..f609733 100644
--- a/boards/sim/sim/sim/src/Makefile
+++ b/boards/sim/sim/sim/src/Makefile
@@ -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
diff --git a/boards/sim/sim/sim/src/sim_bringup.c b/boards/sim/sim/sim/src/sim_bringup.c
index d6e0271..cf7fce2 100644
--- a/boards/sim/sim/sim/src/sim_bringup.c
+++ b/boards/sim/sim/sim/src/sim_bringup.c
@@ -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 */
diff --git a/boards/sim/sim/sim/src/sim_touchscreen.c b/boards/sim/sim/sim/src/sim_touchscreen.c
index 97dea33..070e767 100644
--- a/boards/sim/sim/sim/src/sim_touchscreen.c
+++ b/boards/sim/sim/sim/src/sim_touchscreen.c
@@ -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 */