From c01db536e914584ece57695fa97f3d989dd7d3ca Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 9 Mar 2017 15:17:28 -0600 Subject: [PATCH] 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. --- examples/hidkbd/Kconfig | 13 --- examples/hidkbd/Makefile | 13 ++- examples/hidkbd/hidkbd_main.c | 160 +++++++--------------------------- 3 files changed, 42 insertions(+), 144 deletions(-) diff --git a/examples/hidkbd/Kconfig b/examples/hidkbd/Kconfig index 7d6e6eb53..3f2bc7a5d 100644 --- a/examples/hidkbd/Kconfig +++ b/examples/hidkbd/Kconfig @@ -6,24 +6,11 @@ config EXAMPLES_HIDKBD bool "USB HID keyboard example" default n - depends on !BUILD_PROTECTED && !BUILD_KERNEL ---help--- Enable the USB HID keyboard example 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 string "Keyboard Device Name" default "/dev/kbda" diff --git a/examples/hidkbd/Makefile b/examples/hidkbd/Makefile index 8b0298ea9..deed9c074 100644 --- a/examples/hidkbd/Makefile +++ b/examples/hidkbd/Makefile @@ -1,7 +1,7 @@ ############################################################################ # 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 # # Redistribution and use in source and binary forms, with or without @@ -37,13 +37,20 @@ # USB Host HID keyboard Example +CONFIG_EXAMPLES_HIDKBD_PRIORITY ?= SCHED_PRIORITY_DEFAULT +CONFIG_EXAMPLES_HIDKBD_STACKSIZE ?= 2048 + APPNAME = hidkbd +PRIORITY = $(CONFIG_EXAMPLES_HIDKBD_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_HIDKBD_STACKSIZE) + +# Hello, World! Example ASRCS = CSRCS = MAINSRC = hidkbd_main.c -CONFIG_XYZ_PROGNAME ?= hidkbd$(EXEEXT) -PROGNAME = $(CONFIG_XYZ_PROGNAME) +CONFIG_EXAMPLES_HIDKBD_PROGNAME ?= hidkbd$(EXEEXT) +PROGNAME = $(CONFIG_EXAMPLES_HIDKBD_PROGNAME) include $(APPDIR)/Application.mk diff --git a/examples/hidkbd/hidkbd_main.c b/examples/hidkbd/hidkbd_main.c index c0a3c49bd..c93889069 100644 --- a/examples/hidkbd/hidkbd_main.c +++ b/examples/hidkbd/hidkbd_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * 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 * * Redistribution and use in source and binary forms, with or without @@ -39,16 +39,9 @@ #include -#include -#include - #include #include #include -#include -#include -#include -#include #include #include @@ -79,14 +72,6 @@ /* 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 # define CONFIG_EXAMPLES_HIDKBD_DEVNAME "/dev/kbda" #endif @@ -108,22 +93,6 @@ struct hidbkd_instream_s }; #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 ****************************************************************************/ @@ -223,41 +192,6 @@ static void hidkbd_decode(FAR char *buffer, ssize_t nbytes) } #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 ****************************************************************************/ @@ -273,88 +207,58 @@ int hidkbd_main(int argc, char *argv[]) #endif { char buffer[256]; - pid_t pid; ssize_t nbytes; int fd; - int ret; - /* First, register all of the USB host HID keyboard class driver */ - - 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. + /* Eventually logic here will open the kbd device and perform the HID + * keyboard test. */ - printf("hidkbd_main: Initialize USB host keyboard driver\n"); - g_usbconn = arch_usbhost_initialize(); - if (g_usbconn) + for (;;) { - /* Start a thread to handle device connection. */ - - 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. + /* Open the keyboard device. Loop until the device is successfully + * opened. */ - for (;;) + do { - /* Open the keyboard device. Loop until the device is successfully - * opened. - */ - - do + printf("Opening device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME); + fd = open(CONFIG_EXAMPLES_HIDKBD_DEVNAME, O_RDONLY); + if (fd < 0) { - printf("Opening device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME); - fd = open(CONFIG_EXAMPLES_HIDKBD_DEVNAME, O_RDONLY); - if (fd < 0) - { - printf("Failed: %d\n", errno); - fflush(stdout); - 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); - fflush(stdout); + printf("Device %s opened\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME); + 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 */ - - nbytes = read(fd, buffer, 256); - if (nbytes > 0) - { - /* On success, echo the buffer to stdout */ + /* On success, echo the buffer to stdout */ #ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED - hidkbd_decode(buffer, nbytes); + hidkbd_decode(buffer, nbytes); #else - (void)write(1, buffer, nbytes); + (void)write(1, buffer, nbytes); #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;