configs/sim: Update touchscreen driver initialization to use only multiple-user NX server logic.
This commit is contained in:
parent
61293cfc4c
commit
692d4b3dc6
@ -1963,5 +1963,5 @@ struct adc_dev_s *stm32_adcinitialize(int intf, FAR const uint8_t *r_chanlist,
|
||||
}
|
||||
|
||||
#endif /* CONFIG_STM32_STM32F33XX */
|
||||
#endif /* CONFIG_STM32_ADC1 || CONFIG_STM32_ADC2*/
|
||||
#endif /* CONFIG_STM32_ADC1 || CONFIG_STM32_ADC2 */
|
||||
#endif /* CONFIG_STM32_ADC */
|
||||
|
@ -10,4 +10,39 @@ config EXAMPLES_TOUCHSCREEN_BGCOLOR
|
||||
default 0x007b68ee
|
||||
depends on EXAMPLES_TOUCHSCREEN
|
||||
|
||||
if SIM_TOUCHSCREEN
|
||||
|
||||
comment "NX Server Options"
|
||||
|
||||
config SIM_LISTENER_STACKSIZE
|
||||
int "NX Server/Listener Stack Size"
|
||||
default 2048
|
||||
---help---
|
||||
The stacksize to use when creating the NX server. Default 2048
|
||||
|
||||
config SIM_CLIENTPRIO
|
||||
int "Client Priority"
|
||||
default 100
|
||||
---help---
|
||||
The client priority. Default: 100
|
||||
|
||||
config SIM_SERVERPRIO
|
||||
int "Server Priority"
|
||||
default 120
|
||||
---help---
|
||||
The server priority. Default: 120
|
||||
|
||||
config SIM_LISTENERPRIO
|
||||
int "Listener Priority"
|
||||
default 80
|
||||
---help---
|
||||
The priority of the event listener thread. Default 80.
|
||||
|
||||
config SIM_NOTIFYSIGNO
|
||||
int "Notify Signal Number"
|
||||
default 4
|
||||
---help---
|
||||
The signal number to use with nx_eventnotify(). Default: 4
|
||||
|
||||
endif
|
||||
endif
|
||||
|
@ -40,7 +40,11 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/boardctl.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sched.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
@ -73,13 +77,68 @@
|
||||
struct sim_touchscreen_s
|
||||
{
|
||||
NXHANDLE hnx;
|
||||
bool connected;
|
||||
sem_t eventsem;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct sim_touchscreen_s g_simtc;
|
||||
static struct sim_touchscreen_s g_simtc =
|
||||
{
|
||||
NULL, /* hnx */
|
||||
false, /* connected */
|
||||
SEM_INITIALIZER(0), /* eventsem */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sim_listener
|
||||
****************************************************************************/
|
||||
|
||||
static FAR void *sim_listener(FAR void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Process events forever */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Handle the next event. If we were configured blocking, then
|
||||
* we will stay right here until the next event is received. Since
|
||||
* we have dedicated a while thread to servicing events, it would
|
||||
* be most natural to also select CONFIG_NX_BLOCKING -- if not, the
|
||||
* following would be a tight infinite loop (unless we added addition
|
||||
* logic with nx_eventnotify and sigwait to pace it).
|
||||
*/
|
||||
|
||||
ret = nx_eventhandler(g_simtc.hnx);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* An error occurred... assume that we have lost connection with
|
||||
* the server.
|
||||
*/
|
||||
|
||||
fwarn("WARNING: Lost server connection: %d\n", errno);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
/* If we received a message, we must be connected */
|
||||
|
||||
if (!g_simtc.connected)
|
||||
{
|
||||
g_simtc.connected = true;
|
||||
sem_post(&g_simtc.eventsem);
|
||||
ginfo("Connected\n");
|
||||
}
|
||||
}
|
||||
|
||||
return NULL; /* Not-reachable */
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@ -97,51 +156,81 @@ static struct sim_touchscreen_s g_simtc;
|
||||
|
||||
int board_tsc_setup(int minor)
|
||||
{
|
||||
FAR NX_DRIVERTYPE *dev;
|
||||
struct sched_param param;
|
||||
nxgl_mxpixel_t color;
|
||||
pthread_t thread;
|
||||
int ret;
|
||||
|
||||
/* Initialize the simulated frame buffer device. We need to create an
|
||||
* X11 window to support the mouse-driven touchscreen simulation.
|
||||
*/
|
||||
/* Set the client task priority */
|
||||
|
||||
iinfo("Initializing framebuffer\n");
|
||||
ret = up_fbinitialize(0);
|
||||
param.sched_priority = CONFIG_SIM_CLIENTPRIO;
|
||||
ret = sched_setparam(0, ¶m);
|
||||
if (ret < 0)
|
||||
{
|
||||
ierr("ERROR: up_fbinitialize failed: %d\n", -ret);
|
||||
goto errout;
|
||||
gerr("ERROR: sched_setparam failed: %d\n" , ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
dev = up_fbgetvplane(0, 0);
|
||||
if (!dev)
|
||||
/* Start the NX server kernel thread */
|
||||
|
||||
ret = boardctl(BOARDIOC_NX_START, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
ierr("ERROR: up_fbgetvplane 0 failed\n");
|
||||
ret = -ENODEV;
|
||||
goto errout_with_fb;
|
||||
gerr("ERROR: Failed to start the NX server: %d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Then open NX */
|
||||
/* Connect to the server */
|
||||
|
||||
iinfo("Open NX\n");
|
||||
g_simtc.hnx = nx_open(dev);
|
||||
if (!g_simtc.hnx)
|
||||
g_simtc.hnx = nx_connect();
|
||||
if (g_simtc.hnx)
|
||||
{
|
||||
ret = -errno;
|
||||
ierr("ERROR: nx_open failed: %d\n", ret);
|
||||
goto errout_with_fb;
|
||||
}
|
||||
pthread_attr_t attr;
|
||||
|
||||
#ifdef CONFIG_VNCSERVER
|
||||
/* Setup the VNC server to support keyboard/mouse inputs */
|
||||
/* Setup the VNC server to support keyboard/mouse inputs */
|
||||
|
||||
ret = vnc_default_fbinitialize(0, g_simtc.hnx);
|
||||
if (ret < 0)
|
||||
{
|
||||
ierr("ERROR: vnc_default_fbinitialize failed: %d\n", ret);
|
||||
goto errout_with_fb;
|
||||
}
|
||||
ret = vnc_default_fbinitialize(0, g_simtc.hnx);
|
||||
if (ret < 0)
|
||||
{
|
||||
ginfo("ERROR: vnc_default_fbinitialize failed: %d\n", ret);
|
||||
nx_disconnect(g_simtc.hnx);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
/* Start a separate thread to listen for server events. This is probably
|
||||
* the least efficient way to do this, but it makes this example flow more
|
||||
* smoothly.
|
||||
*/
|
||||
|
||||
(void)pthread_attr_init(&attr);
|
||||
param.sched_priority = CONFIG_SIM_LISTENERPRIO;
|
||||
(void)pthread_attr_setschedparam(&attr, ¶m);
|
||||
(void)pthread_attr_setstacksize(&attr, CONFIG_SIM_LISTENER_STACKSIZE);
|
||||
|
||||
ret = pthread_create(&thread, &attr, sim_listener, NULL);
|
||||
if (ret != 0)
|
||||
{
|
||||
gerr("ERROR: pthread_create failed: %d\n", ret);
|
||||
return -ret;
|
||||
}
|
||||
|
||||
/* Don't return until we are connected to the server */
|
||||
|
||||
while (!g_simtc.connected)
|
||||
{
|
||||
/* Wait for the listener thread to wake us up when we really
|
||||
* are connected.
|
||||
*/
|
||||
|
||||
(void)sem_wait(&g_simtc.eventsem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gerr("ERROR: nx_connect failed: %d\n", errno);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Set the background to the configured background color */
|
||||
|
||||
@ -167,11 +256,9 @@ int board_tsc_setup(int minor)
|
||||
return OK;
|
||||
|
||||
errout_with_nx:
|
||||
nx_close(g_simtc.hnx);
|
||||
nx_disconnect(g_simtc.hnx);
|
||||
goto errout;
|
||||
|
||||
errout_with_fb:
|
||||
up_fbuninitialize(0);
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
@ -194,5 +281,5 @@ void board_tsc_teardown(void)
|
||||
|
||||
/* Close NX */
|
||||
|
||||
nx_close(g_simtc.hnx);
|
||||
nx_disconnect(g_simtc.hnx);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user