apps/nshlib: Add support to use SLCD as NSH Console

This commit is contained in:
Alan Carvalho de Assis 2018-11-29 18:41:42 -06:00 committed by Gregory Nutt
parent 521052ae1f
commit c21d640eaf
5 changed files with 186 additions and 22 deletions

View File

@ -126,6 +126,10 @@ ifeq ($(CONFIG_USBHOST),y)
CSRCS += nsh_usbkeyboard.c
endif
ifeq ($(CONFIG_SLCD),y)
CSRCS += nsh_slcd.c
endif
ifeq ($(CONFIG_NSH_USBDEV_TRACE),y)
CSRCS += nsh_usbtrace.c
endif

View File

@ -291,6 +291,19 @@
# endif
#endif /* HAVE_USB_KEYBOARD */
#undef HAVE_SLCD_CONSOLE
/* Check if SLCD is configured as alternative console */
#if defined(CONFIG_SLCD) && defined(CONFIG_NSH_ALTCONDEV)
# define HAVE_SLCD_CONSOLE 1
# ifndef CONFIG_NSH_CONDEV
# define CONFIG_NSH_CONDEV "/dev/slcd0"
# endif
#endif /* HAVE_SLCD_CONSOLE */
/* USB trace settings */
#ifndef CONFIG_USBDEV_TRACE

View File

@ -47,7 +47,8 @@
#include "nsh.h"
#include "nsh_console.h"
#if !defined(HAVE_USB_CONSOLE) && !defined(HAVE_USB_KEYBOARD)
#if !defined(HAVE_USB_CONSOLE) && !defined(HAVE_USB_KEYBOARD) && \
!defined(HAVE_SLCD_CONSOLE)
/****************************************************************************
* Public Functions
@ -117,4 +118,4 @@ int nsh_consolemain(int argc, char *argv[])
return ret;
}
#endif /* !HAVE_USB_CONSOLE && !HAVE_USB_KEYBOARD */
#endif /* !HAVE_USB_CONSOLE && !HAVE_USB_KEYBOARD !HAVE_SLCD_CONSOLE */

166
nshlib/nsh_slcd.c Normal file
View File

@ -0,0 +1,166 @@
/****************************************************************************
* apps/nshlib/nsh_slcd.c
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Author: Alan Carvalho de Assis <acassis@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <debug.h>
#include "nsh.h"
#include "nsh_console.h"
#if defined(HAVE_SLCD_CONSOLE)
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_clone_console
*
* Description:
* Wait for the USB keyboard device to be ready
*
****************************************************************************/
static int nsh_clone_console(FAR struct console_stdio_s *pstate)
{
int fd;
/* Close stdin */
(void)close(0);
/* Open the console */
fd = open("/dev/console", O_RDONLY);
if (fd < 0)
{
return -ENODEV;
}
/* Associate /dev/console as stdin */
(void)dup2(fd, 0);
/* Close the console device that we just opened */
if (fd != 0)
{
close(fd);
}
/* Use /dev/console as console input */
pstate->cn_confd = fd;
/* Create a standard C stream on the console device */
pstate->cn_constream = fdopen(pstate->cn_confd, "r+");
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_consolemain (USB console version)
*
* Description:
* This interfaces maybe to called or started with task_start to start a
* single an NSH instance that operates on stdin and stdout. This
* function does not return.
*
* This function handles generic /dev/console character devices for output
* but uses a special USB keyboard device for input. The USB keyboard
* requires some special operations to handle the cases where the session
* input is lost when the USB keyboard is unplugged and restarted when the
* USB keyboard is plugged in again.
*
* Input Parameters:
* Standard task start-up arguments. These are not used. argc may be
* zero and argv may be NULL.
*
* Returned Values:
* This function does not return nor does it ever exit (unless the user
* executes the NSH exit command).
*
****************************************************************************/
int nsh_consolemain(int argc, char *argv[])
{
FAR struct console_stdio_s *pstate = nsh_newconsole();
int ret;
DEBUGASSERT(pstate);
/* Execute the one-time start-up script. Any output will go to /dev/console. */
#ifdef CONFIG_NSH_ROMFSETC
(void)nsh_initscript(&pstate->cn_vtbl);
#endif
#if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
/* Perform architecture-specific final-initialization (if configured) */
(void)boardctl(BOARDIOC_FINALINIT, 0);
#endif
/* Try to associate /dev/console as stdin because otherwise /dev/slcd0 will be it */
ret = nsh_clone_console(pstate);
if (ret < 0)
{
return ret;
}
/* Execute the session */
(void)nsh_session(pstate);
}
#endif /* HAVE_SLCD_CONSOLE */

View File

@ -51,26 +51,6 @@
#if defined(HAVE_USB_KEYBOARD) && !defined(HAVE_USB_CONSOLE)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/