Skip to content

Commit 2b58ecf

Browse files
examples/vncviewer: add VNC viewer for LCD display
Add a minimal VNC viewer application that connects to a VNC server and renders the remote desktop on a local LCD. Features: - RFB 3.8 protocol with VNC Authentication (DES, pure software) - Raw encoding with pixel format auto-detected from LCD driver - Row-by-row rendering via LCDDEVIO_PUTAREA (minimal RAM usage) - LCD resolution and format queried at runtime via LCDDEVIO_GETVIDEOINFO - Auto-reconnect on connection loss with 2-second retry Usage: vncviewer <host> [port] vncviewer -p <password> <host> [port] vncviewer -p <password> -d <lcd_devno> <host> [port] Assisted-by: GitHubCopilot:claude-4.6-opus Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
1 parent 7dc8cec commit 2b58ecf

9 files changed

Lines changed: 1989 additions & 0 deletions

File tree

system/vncviewer/CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ##############################################################################
2+
# apps/system/vncviewer/CMakeLists.txt
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
if(CONFIG_SYSTEM_VNCVIEWER)
24+
nuttx_add_application(
25+
NAME
26+
${CONFIG_SYSTEM_VNCVIEWER_PROGNAME}
27+
SRCS
28+
vncviewer_main.c
29+
rfb_protocol.c
30+
lcd_render.c
31+
STACKSIZE
32+
${CONFIG_SYSTEM_VNCVIEWER_STACKSIZE}
33+
PRIORITY
34+
${CONFIG_SYSTEM_VNCVIEWER_PRIORITY})
35+
endif()

system/vncviewer/Kconfig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config SYSTEM_VNCVIEWER
7+
tristate "VNC Viewer"
8+
default n
9+
depends on NET_TCP && LCD
10+
---help---
11+
Enable the VNC Viewer example application.
12+
Connects to a VNC server and displays the remote
13+
framebuffer on a local LCD.
14+
15+
if SYSTEM_VNCVIEWER
16+
17+
config SYSTEM_VNCVIEWER_PROGNAME
18+
string "Program name"
19+
default "vncviewer"
20+
---help---
21+
This is the name of the program that will be used when the
22+
NSH ELF program is installed.
23+
24+
config SYSTEM_VNCVIEWER_PRIORITY
25+
int "VNC Viewer task priority"
26+
default 100
27+
28+
config SYSTEM_VNCVIEWER_STACKSIZE
29+
int "VNC Viewer stack size"
30+
default 4096
31+
32+
endif

system/vncviewer/Make.defs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
############################################################################
2+
# apps/system/vncviewer/Make.defs
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
ifneq ($(CONFIG_SYSTEM_VNCVIEWER),)
24+
CONFIGURED_APPS += $(APPDIR)/system/vncviewer
25+
endif

system/vncviewer/Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
############################################################################
2+
# apps/system/vncviewer/Makefile
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
include $(APPDIR)/Make.defs
24+
25+
# VNC Viewer built-in application info
26+
27+
PROGNAME = $(CONFIG_SYSTEM_VNCVIEWER_PROGNAME)
28+
PRIORITY = $(CONFIG_SYSTEM_VNCVIEWER_PRIORITY)
29+
STACKSIZE = $(CONFIG_SYSTEM_VNCVIEWER_STACKSIZE)
30+
MODULE = $(CONFIG_SYSTEM_VNCVIEWER)
31+
32+
# VNC Viewer sources
33+
34+
MAINSRC = vncviewer_main.c
35+
CSRCS = rfb_protocol.c lcd_render.c
36+
37+
include $(APPDIR)/Application.mk

system/vncviewer/lcd_render.c

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/****************************************************************************
2+
* apps/system/vncviewer/lcd_render.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <stdio.h>
30+
#include <string.h>
31+
#include <errno.h>
32+
#include <fcntl.h>
33+
#include <stdlib.h>
34+
#include <unistd.h>
35+
#include <sys/ioctl.h>
36+
37+
#include <nuttx/video/fb.h>
38+
#include <nuttx/lcd/lcd_dev.h>
39+
40+
#include "lcd_render.h"
41+
42+
/****************************************************************************
43+
* Public Functions
44+
****************************************************************************/
45+
46+
/****************************************************************************
47+
* Name: lcd_init
48+
****************************************************************************/
49+
50+
int lcd_init(struct lcd_ctx_s *ctx, int devno)
51+
{
52+
char devpath[16];
53+
int ret;
54+
55+
snprintf(devpath, sizeof(devpath), "/dev/lcd%d", devno);
56+
57+
ctx->fd = open(devpath, O_RDWR);
58+
if (ctx->fd < 0)
59+
{
60+
printf("vncviewer: failed to open %s: %d\n", devpath, errno);
61+
return -errno;
62+
}
63+
64+
/* Query LCD resolution */
65+
66+
struct fb_videoinfo_s vinfo;
67+
ret = ioctl(ctx->fd, LCDDEVIO_GETVIDEOINFO,
68+
(unsigned long)(uintptr_t)&vinfo);
69+
if (ret < 0)
70+
{
71+
printf("vncviewer: GETVIDEOINFO failed: %d\n", errno);
72+
close(ctx->fd);
73+
ctx->fd = -1;
74+
return -errno;
75+
}
76+
else
77+
{
78+
ctx->xres = vinfo.xres;
79+
ctx->yres = vinfo.yres;
80+
ctx->fmt = vinfo.fmt;
81+
}
82+
83+
printf("vncviewer: LCD %s opened (%ux%u)\n",
84+
devpath, ctx->xres, ctx->yres);
85+
86+
/* Set power on */
87+
88+
ret = ioctl(ctx->fd, LCDDEVIO_SETPOWER, 1);
89+
if (ret < 0)
90+
{
91+
printf("vncviewer: WARNING: SETPOWER failed: %d\n", errno);
92+
}
93+
94+
return OK;
95+
}
96+
97+
/****************************************************************************
98+
* Name: lcd_put_row
99+
****************************************************************************/
100+
101+
int lcd_put_row(struct lcd_ctx_s *ctx, uint16_t x, uint16_t y,
102+
uint16_t w, const uint16_t *pixels)
103+
{
104+
struct lcddev_area_s area;
105+
int ret;
106+
107+
/* Clip to LCD bounds */
108+
109+
if (x >= ctx->xres || y >= ctx->yres)
110+
{
111+
return OK;
112+
}
113+
114+
if (x + w > ctx->xres)
115+
{
116+
w = ctx->xres - x;
117+
}
118+
119+
area.row_start = y;
120+
area.row_end = y;
121+
area.col_start = x;
122+
area.col_end = x + w - 1;
123+
area.data = (uint8_t *)pixels;
124+
125+
ret = ioctl(ctx->fd, LCDDEVIO_PUTAREA, (unsigned long)(uintptr_t)&area);
126+
if (ret < 0)
127+
{
128+
return -errno;
129+
}
130+
131+
return OK;
132+
}
133+
134+
/****************************************************************************
135+
* Name: lcd_fill
136+
****************************************************************************/
137+
138+
int lcd_fill(struct lcd_ctx_s *ctx, uint16_t color)
139+
{
140+
uint16_t y;
141+
uint16_t i;
142+
uint16_t w = ctx->xres;
143+
FAR uint16_t *rowbuf;
144+
145+
rowbuf = (FAR uint16_t *)malloc(w * sizeof(uint16_t));
146+
if (rowbuf == NULL)
147+
{
148+
return -ENOMEM;
149+
}
150+
151+
for (i = 0; i < w; i++)
152+
{
153+
rowbuf[i] = color;
154+
}
155+
156+
for (y = 0; y < ctx->yres; y++)
157+
{
158+
lcd_put_row(ctx, 0, y, w, rowbuf);
159+
}
160+
161+
free(rowbuf);
162+
163+
return OK;
164+
}
165+
166+
/****************************************************************************
167+
* Name: lcd_uninit
168+
****************************************************************************/
169+
170+
void lcd_uninit(struct lcd_ctx_s *ctx)
171+
{
172+
if (ctx->fd >= 0)
173+
{
174+
close(ctx->fd);
175+
ctx->fd = -1;
176+
}
177+
}

0 commit comments

Comments
 (0)