diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-07-03 17:08:59 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-07-03 17:08:59 -0600 |
commit | 4b59193e39baf25f2923ef64745c44a7f2d55027 (patch) | |
tree | 643f2f94d78b846cbaf3c76e95d77bf0e97837c9 | |
parent | 54ce35a1e1502a0d7455292ccdb7498fefdbe94e (diff) |
NSH Keyboard: Close stdin before trying to reopen. Otherwise, driver will persist
-rw-r--r-- | apps/nshlib/nsh_usbkeyboard.c | 43 | ||||
-rw-r--r-- | nuttx/configs/sama5d4-ek/README.txt | 4 |
2 files changed, 34 insertions, 13 deletions
diff --git a/apps/nshlib/nsh_usbkeyboard.c b/apps/nshlib/nsh_usbkeyboard.c index 845d56a889..9baf78955d 100644 --- a/apps/nshlib/nsh_usbkeyboard.c +++ b/apps/nshlib/nsh_usbkeyboard.c @@ -92,6 +92,16 @@ static int nsh_wait_usbready(FAR const char *msg) * not be available until the device is connected to the host and enumerated. */ + /* Close standard fd 0. Unbeknownst to stdin. We do this here in case we + * had the USB keyboard device open. In that case, the driver will exist + * we will get an ENODEV error when we try to open it (instead of ENOENT). + * + * NOTE: This might not be portable behavior! + */ + + (void)close(0); + sleep(1); + /* Open the USB keyboard device for read-only access */ do @@ -101,11 +111,18 @@ static int nsh_wait_usbready(FAR const char *msg) fd = open(NSH_USBKBD_DEVNAME, O_RDONLY); if (fd < 0) { +#ifdef CONFIG_DEBUG + int errcode = errno; + /* ENOENT means that the USB device is not yet connected and, - * hence, has no entry under /dev. Anything else would be bad. + * hence, has no entry under /dev. If the USB driver still + * exists under(because other threads still have the driver + * open), then we might also get ENODEV. Anything else would + * be really bad. */ - DEBUGASSERT(errno == ENOENT); + DEBUGASSERT(errcode == ENOENT || errcode == ENODEV); +#endif /* Let the user know that we are waiting */ @@ -127,21 +144,21 @@ static int nsh_wait_usbready(FAR const char *msg) } while (fd < 0); - /* Okay.. we have successfully opened a keyboard device - * - * Close standard fd 0. Unbeknownst to stdin. - * NOTE: This might not be portable behavior! + /* Okay.. we have successfully opened a keyboard device. Did + * we just re-open fd 0? */ - (void)close(0); + if (fd != 0) + { + /* No.. Dup the fd to create standard fd 0. stdin should not know. */ - /* Dup the fd to create standard fd 0. stdin should not know */ + (void)dup2(fd, 0); - (void)dup2(fd, 0); + /* Close the keyboard device that we just opened */ - /* Close the keyboard device that we just opened */ + close(fd); + } - close(fd); return OK; } @@ -195,7 +212,7 @@ int nsh_consolemain(int argc, char *argv[]) /* Now loop, executing creating a session for each USB connection */ - msg = "Waiting for keyboard to be connected...\n"; + msg = "Waiting for a keyboard...\n"; for (;;) { /* Wait for the USB to be connected to the host and switch @@ -204,8 +221,8 @@ int nsh_consolemain(int argc, char *argv[]) ret = nsh_wait_usbready(msg); - (void)ret; /* Eliminate warning if not used */ DEBUGASSERT(ret == OK); + UNUSED(ret); /* Execute the session */ diff --git a/nuttx/configs/sama5d4-ek/README.txt b/nuttx/configs/sama5d4-ek/README.txt index 1ff6b5a33b..463e38e4e1 100644 --- a/nuttx/configs/sama5d4-ek/README.txt +++ b/nuttx/configs/sama5d4-ek/README.txt @@ -3475,6 +3475,10 @@ Configurations CONFIG_NSH_USBKBD=y CONFIG_NSH_USBKBD_DEVNAME="/dev/kbda" + [Using the RAMLOG with the USB keyboard is, however, probably a bad + idea because you cannot type the 'dmesg' command to view the RAMLOG + without a keyboard attached.] + 14. Support the USB high-speed USB device driver (UDPHS) is not enabled by default but could be enabled by changing the NuttX configuration file as described above in the section entitled "USB High-Speed Device." |