apps/examples/hidkbd: Remove call to arch_usbhost_initialize(). That is violation of the OS interfacing rules and will no longer be supported. USB host should be initialized as part of the normal board bring-up logic as with any other devices and should not involve illegal calls from applications into the OS.
This commit is contained in:
parent
6f3b0615e1
commit
c01db536e9
@ -6,24 +6,11 @@
|
|||||||
config EXAMPLES_HIDKBD
|
config EXAMPLES_HIDKBD
|
||||||
bool "USB HID keyboard example"
|
bool "USB HID keyboard example"
|
||||||
default n
|
default n
|
||||||
depends on !BUILD_PROTECTED && !BUILD_KERNEL
|
|
||||||
---help---
|
---help---
|
||||||
Enable the USB HID keyboard example
|
Enable the USB HID keyboard example
|
||||||
|
|
||||||
if EXAMPLES_HIDKBD
|
if EXAMPLES_HIDKBD
|
||||||
|
|
||||||
config EXAMPLES_HIDKBD_DEFPRIO
|
|
||||||
int "Waiter Thread Priority"
|
|
||||||
default 50
|
|
||||||
---help---
|
|
||||||
Priority of "waiter" thread. Default: 50
|
|
||||||
|
|
||||||
config EXAMPLES_HIDKBD_STACKSIZE
|
|
||||||
int "Waiter Thread Stack Size"
|
|
||||||
default 1024
|
|
||||||
---help---
|
|
||||||
Stacksize of "waiter" thread. Default 1024
|
|
||||||
|
|
||||||
config EXAMPLES_HIDKBD_DEVNAME
|
config EXAMPLES_HIDKBD_DEVNAME
|
||||||
string "Keyboard Device Name"
|
string "Keyboard Device Name"
|
||||||
default "/dev/kbda"
|
default "/dev/kbda"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
############################################################################
|
############################################################################
|
||||||
# apps/examples/hidkbd/Makefile
|
# apps/examples/hidkbd/Makefile
|
||||||
#
|
#
|
||||||
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
# Copyright (C) 2011-2012, 2017 Gregory Nutt. All rights reserved.
|
||||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -37,13 +37,20 @@
|
|||||||
|
|
||||||
# USB Host HID keyboard Example
|
# USB Host HID keyboard Example
|
||||||
|
|
||||||
|
CONFIG_EXAMPLES_HIDKBD_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||||
|
CONFIG_EXAMPLES_HIDKBD_STACKSIZE ?= 2048
|
||||||
|
|
||||||
APPNAME = hidkbd
|
APPNAME = hidkbd
|
||||||
|
PRIORITY = $(CONFIG_EXAMPLES_HIDKBD_PRIORITY)
|
||||||
|
STACKSIZE = $(CONFIG_EXAMPLES_HIDKBD_STACKSIZE)
|
||||||
|
|
||||||
|
# Hello, World! Example
|
||||||
|
|
||||||
ASRCS =
|
ASRCS =
|
||||||
CSRCS =
|
CSRCS =
|
||||||
MAINSRC = hidkbd_main.c
|
MAINSRC = hidkbd_main.c
|
||||||
|
|
||||||
CONFIG_XYZ_PROGNAME ?= hidkbd$(EXEEXT)
|
CONFIG_EXAMPLES_HIDKBD_PROGNAME ?= hidkbd$(EXEEXT)
|
||||||
PROGNAME = $(CONFIG_XYZ_PROGNAME)
|
PROGNAME = $(CONFIG_EXAMPLES_HIDKBD_PROGNAME)
|
||||||
|
|
||||||
include $(APPDIR)/Application.mk
|
include $(APPDIR)/Application.mk
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/hidkbd/hidkbd_main.c
|
* examples/hidkbd/hidkbd_main.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011, 2013-2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2011, 2013-2015, 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -39,16 +39,9 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sched.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <nuttx/usb/usbhost.h>
|
#include <nuttx/usb/usbhost.h>
|
||||||
@ -79,14 +72,6 @@
|
|||||||
|
|
||||||
/* Provide some default values for other configuration settings */
|
/* Provide some default values for other configuration settings */
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_HIDKBD_DEFPRIO
|
|
||||||
# define CONFIG_EXAMPLES_HIDKBD_DEFPRIO 50
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_HIDKBD_STACKSIZE
|
|
||||||
# define CONFIG_EXAMPLES_HIDKBD_STACKSIZE 1024
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_HIDKBD_DEVNAME
|
#ifndef CONFIG_EXAMPLES_HIDKBD_DEVNAME
|
||||||
# define CONFIG_EXAMPLES_HIDKBD_DEVNAME "/dev/kbda"
|
# define CONFIG_EXAMPLES_HIDKBD_DEVNAME "/dev/kbda"
|
||||||
#endif
|
#endif
|
||||||
@ -108,22 +93,6 @@ struct hidbkd_instream_s
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static FAR struct usbhost_connection_s *g_usbconn;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
/* The platform-specific code must provide a wrapper called
|
|
||||||
* arch_usbhost_initialize() that will perform the actual USB host
|
|
||||||
* initialization.
|
|
||||||
*/
|
|
||||||
|
|
||||||
FAR struct usbhost_connection_s *arch_usbhost_initialize(void);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -223,41 +192,6 @@ static void hidkbd_decode(FAR char *buffer, ssize_t nbytes)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: hidkbd_waiter
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Wait for USB devices to be connected.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int hidkbd_waiter(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
FAR struct usbhost_hubport_s *hport;
|
|
||||||
|
|
||||||
printf("hidkbd_waiter: Running\n");
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
/* Wait for the device to change state */
|
|
||||||
|
|
||||||
DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport));
|
|
||||||
printf("hidkbd_waiter: %s\n", hport->connected ? "connected" : "disconnected");
|
|
||||||
|
|
||||||
/* Did we just become connected? */
|
|
||||||
|
|
||||||
if (hport->connected)
|
|
||||||
{
|
|
||||||
/* Yes.. enumerate the newly connected device */
|
|
||||||
|
|
||||||
(void)CONN_ENUMERATE(g_usbconn, hport);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Keep the compiler from complaining */
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -273,88 +207,58 @@ int hidkbd_main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
pid_t pid;
|
|
||||||
ssize_t nbytes;
|
ssize_t nbytes;
|
||||||
int fd;
|
int fd;
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* First, register all of the USB host HID keyboard class driver */
|
/* Eventually logic here will open the kbd device and perform the HID
|
||||||
|
* keyboard test.
|
||||||
printf("hidkbd_main: Register class drivers\n");
|
|
||||||
ret = usbhost_kbdinit();
|
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
printf("hidkbd_main: Failed to register the KBD class\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then get an instance of the USB host interface. The platform-specific
|
|
||||||
* code must provide a wrapper called arch_usbhost_initialize() that will
|
|
||||||
* perform the actual USB host initialization.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
printf("hidkbd_main: Initialize USB host keyboard driver\n");
|
for (;;)
|
||||||
g_usbconn = arch_usbhost_initialize();
|
|
||||||
if (g_usbconn)
|
|
||||||
{
|
{
|
||||||
/* Start a thread to handle device connection. */
|
/* Open the keyboard device. Loop until the device is successfully
|
||||||
|
* opened.
|
||||||
printf("hidkbd_main: Start hidkbd_waiter\n");
|
|
||||||
|
|
||||||
pid = task_create("usbhost", CONFIG_EXAMPLES_HIDKBD_DEFPRIO,
|
|
||||||
CONFIG_EXAMPLES_HIDKBD_STACKSIZE,
|
|
||||||
(main_t)hidkbd_waiter, (FAR char * const *)NULL);
|
|
||||||
UNUSED(pid);
|
|
||||||
|
|
||||||
/* Now just sleep. Eventually logic here will open the kbd device and
|
|
||||||
* perform the HID keyboard test.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (;;)
|
do
|
||||||
{
|
{
|
||||||
/* Open the keyboard device. Loop until the device is successfully
|
printf("Opening device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
|
||||||
* opened.
|
fd = open(CONFIG_EXAMPLES_HIDKBD_DEVNAME, O_RDONLY);
|
||||||
*/
|
if (fd < 0)
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
printf("Opening device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
|
printf("Failed: %d\n", errno);
|
||||||
fd = open(CONFIG_EXAMPLES_HIDKBD_DEVNAME, O_RDONLY);
|
fflush(stdout);
|
||||||
if (fd < 0)
|
sleep(3);
|
||||||
{
|
|
||||||
printf("Failed: %d\n", errno);
|
|
||||||
fflush(stdout);
|
|
||||||
sleep(3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (fd < 0);
|
}
|
||||||
|
while (fd < 0);
|
||||||
|
|
||||||
printf("Device %s opened\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
|
printf("Device %s opened\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
/* Loop until there is a read failure (or EOF?) */
|
/* Loop until there is a read failure (or EOF?) */
|
||||||
|
|
||||||
do
|
do
|
||||||
|
{
|
||||||
|
/* Read a buffer of data */
|
||||||
|
|
||||||
|
nbytes = read(fd, buffer, 256);
|
||||||
|
if (nbytes > 0)
|
||||||
{
|
{
|
||||||
/* Read a buffer of data */
|
/* On success, echo the buffer to stdout */
|
||||||
|
|
||||||
nbytes = read(fd, buffer, 256);
|
|
||||||
if (nbytes > 0)
|
|
||||||
{
|
|
||||||
/* On success, echo the buffer to stdout */
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED
|
#ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED
|
||||||
hidkbd_decode(buffer, nbytes);
|
hidkbd_decode(buffer, nbytes);
|
||||||
#else
|
#else
|
||||||
(void)write(1, buffer, nbytes);
|
(void)write(1, buffer, nbytes);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (nbytes > 0);
|
|
||||||
|
|
||||||
printf("Closing device %s: %d\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME, (int)nbytes);
|
|
||||||
fflush(stdout);
|
|
||||||
close(fd);
|
|
||||||
}
|
}
|
||||||
|
while (nbytes > 0);
|
||||||
|
|
||||||
|
printf("Closing device %s: %d\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME, (int)nbytes);
|
||||||
|
fflush(stdout);
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user