zhugengyu 2 éve
szülő
commit
4b59a1330e

+ 47 - 37
demo/phytium-e2000/usbhost/inc/usb_config.h

@@ -14,30 +14,38 @@
  * FilePath: usb_config.h
  * Date: 2022-09-19 17:28:44
  * LastEditTime: 2022-09-19 17:28:45
- * Description:  This files is for usb hc xhci configuration
+ * Description:  This file is for usb hc xhci configuration.
  *
  * Modify History:
  *  Ver   Who        Date         Changes
  * ----- ------     --------    --------------------------------------
  * 1.0   zhugengyu  2022/9/19   init commit
+ * 1.1  liqiaozhong 2023/2/10   update to v0.7.0
  */
 
-#ifndef CHERRYUSB_CONFIG_H
-#define CHERRYUSB_CONFIG_H
+#ifndef USB_CONFIG_H
+#define USB_CONFIG_H
 
+#ifdef __cplusplus
+extern "C"
+{
+#endif
 
 /* ================ USB common Configuration ================ */
+void *usb_hc_malloc(size_t size);
+void usb_hc_free();
+void *usb_hc_malloc_align(size_t align, size_t size);
 
-#define CONFIG_USB_PRINTF(...) printf(__VA_ARGS__)
-
-extern void *usb_hc_malloc(size_t size);
-extern void *usb_hc_free(size_t size);
-
-#define usb_malloc(size) usb_hc_malloc(size)
-#define usb_free(ptr)    usb_hc_free(ptr)
+#define usb_malloc(size)                    usb_hc_malloc(size)
+#define usb_free(ptr)                       usb_hc_free(ptr)
+#define usb_align(align, size)              usb_hc_malloc_align(align, size)  
 
 #ifndef CONFIG_USB_DBG_LEVEL
-#define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
+    #define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
+#endif
+
+#ifndef CONFIG_USB_PRINTF
+    #define CONFIG_USB_PRINTF printf
 #endif
 
 /* Enable print with color */
@@ -45,7 +53,7 @@ extern void *usb_hc_free(size_t size);
 
 /* data align size when use dma */
 #ifndef CONFIG_USB_ALIGN_SIZE
-#define CONFIG_USB_ALIGN_SIZE 4
+    #define CONFIG_USB_ALIGN_SIZE 4
 #endif
 
 /* attribute data into no cache ram */
@@ -58,19 +66,19 @@ extern void *usb_hc_free(size_t size);
 
 
 #ifndef CONFIG_USBDEV_MSC_BLOCK_SIZE
-#define CONFIG_USBDEV_MSC_BLOCK_SIZE 512
+    #define CONFIG_USBDEV_MSC_BLOCK_SIZE 512
 #endif
 
 #ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
-#define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
+    #define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
 #endif
 
 #ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
-#define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
+    #define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
 #endif
 
 #ifndef CONFIG_USBDEV_MSC_VERSION_STRING
-#define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
+    #define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
 #endif
 
 // #define CONFIG_USBHOST_GET_STRING_DESC
@@ -80,26 +88,26 @@ extern void *usb_hc_free(size_t size);
 #define CONFIG_INPUT_MOUSE_WHEEL
 
 #ifdef CONFIG_USBDEV_MSC_THREAD
-#ifndef CONFIG_USBDEV_MSC_STACKSIZE
-#define CONFIG_USBDEV_MSC_STACKSIZE 2048
-#endif
+    #ifndef CONFIG_USBDEV_MSC_STACKSIZE
+        #define CONFIG_USBDEV_MSC_STACKSIZE 2048
+    #endif
 
-#ifndef CONFIG_USBDEV_MSC_PRIO
-#define CONFIG_USBDEV_MSC_PRIO 4
-#endif
+    #ifndef CONFIG_USBDEV_MSC_PRIO
+        #define CONFIG_USBDEV_MSC_PRIO 4
+    #endif
 #endif
 
 #ifndef CONFIG_USBDEV_AUDIO_VERSION
-#define CONFIG_USBDEV_AUDIO_VERSION 0x0100
+    #define CONFIG_USBDEV_AUDIO_VERSION 0x0100
 #endif
 
 #ifndef CONFIG_USBDEV_AUDIO_MAX_CHANNEL
-#define CONFIG_USBDEV_AUDIO_MAX_CHANNEL 8
+    #define CONFIG_USBDEV_AUDIO_MAX_CHANNEL 8
 #endif
 
 /* ================ USB HOST Stack Configuration ================== */
 
-#define CONFIG_USBHOST_MAX_RHPORTS          1
+#define CONFIG_USBHOST_MAX_RHPORTS          2
 #define CONFIG_USBHOST_MAX_EXTHUBS          2
 #define CONFIG_USBHOST_MAX_EHPORTS          4
 #define CONFIG_USBHOST_MAX_INTERFACES       6
@@ -109,32 +117,29 @@ extern void *usb_hc_free(size_t size);
 #define CONFIG_USBHOST_DEV_NAMELEN 16
 
 #ifndef CONFIG_USBHOST_PSC_PRIO
-#define CONFIG_USBHOST_PSC_PRIO 4
+    #define CONFIG_USBHOST_PSC_PRIO 4
 #endif
 #ifndef CONFIG_USBHOST_PSC_STACKSIZE
-#define CONFIG_USBHOST_PSC_STACKSIZE 2048
+    #define CONFIG_USBHOST_PSC_STACKSIZE 4096
 #endif
 
 /* Ep0 max transfer buffer */
 #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
 
 #ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
-#define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
+    #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
 #endif
 
 #ifndef CONFIG_USBHOST_MSC_TIMEOUT
-#define CONFIG_USBHOST_MSC_TIMEOUT 5000
+    #define CONFIG_USBHOST_MSC_TIMEOUT 5000
 #endif
 
-/* ================ USB Device Port Configuration ================*/
-
-/* Phytium-E2000 instance-0 */
-#define CONFIG_XHCI_BASE_ADDR   0x31A08000U
-#define CONFIG_XHCI_IRQ_NUM     48U
+/* do not try to enumrate one interface */
+#ifndef CONFIG_USBHOST_ENUM_FIRST_INTERFACE_ONLY
+    #define CONFIG_USBHOST_ENUM_FIRST_INTERFACE_ONLY
+#endif
 
-/* Phytium-E2000 instance-1 */
-// #define CONFIG_XHCI_BASE_ADDR   0x31A28000U
-// #define CONFIG_XHCI_IRQ_NUM     49U
+/* ================ USB Device Port Configuration ================*/
 
 #define CONFIG_XHCI_PAGE_SIZE   4096U
 #define CONFIG_XHCI_PAGE_SHIFT  12U
@@ -145,5 +150,10 @@ extern void *usb_hc_free(size_t size);
 
 /* ================ XHCI Configuration ================ */
 #define CONFIG_USBHOST_XHCI
+#define CONFIG_USBHOST_XHCI_ID  0
+
+#ifdef __cplusplus
+}
+#endif
 
 #endif

+ 21 - 19
demo/phytium-e2000/usbhost/inc/usb_host.h

@@ -1,27 +1,28 @@
 /*
- * Copyright : (C) 2022 Phytium Information Technology, Inc. 
+ * Copyright : (C) 2022 Phytium Information Technology, Inc.
  * All Rights Reserved.
- *  
- * This program is OPEN SOURCE software: you can redistribute it and/or modify it  
- * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,  
- * either version 1.0 of the License, or (at your option) any later version. 
- *  
- * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;  
+ *
+ * This program is OPEN SOURCE software: you can redistribute it and/or modify it
+ * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
+ * either version 1.0 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the Phytium Public License for more details. 
- *  
- * 
+ * See the Phytium Public License for more details.
+ *
+ *
  * FilePath: usb_host.h
  * Date: 2022-07-19 09:26:25
  * LastEditTime: 2022-07-19 09:26:25
- * Description:  This files is for 
- * 
- * Modify History: 
+ * Description:  This file is for the usb host definition.
+ *
+ * Modify History:
  *  Ver   Who        Date         Changes
  * ----- ------     --------    --------------------------------------
+ * 1.0   zhugengyu  2022/9/20   init commit
  */
-#ifndef  EXAMPLE_USB_HOST_H
-#define  EXAMPLE_USB_HOST_H
+#ifndef  USB_HOST_H
+#define  USB_HOST_H
 
 #ifdef __cplusplus
 extern "C"
@@ -39,10 +40,11 @@ extern "C"
 /************************** Function Prototypes ******************************/
 
 /*****************************************************************************/
-BaseType_t FFreeRTOSInitUsb(void);
-BaseType_t FFreeRTOSWriteReadUsbDisk(void);
-BaseType_t FFreeRTOSRecvInput(void);
-BaseType_t FFreeRTOSListUsb(int argc, char *argv[]);
+BaseType_t FFreeRTOSInitUsb(u32 id);
+BaseType_t FFreeRTOSRunUsbDisk(const char *devname);
+BaseType_t FFreeRTOSRunUsbKeyboard(const char *devname);
+BaseType_t FFreeRTOSRunUsbMouse(const char *devname);
+BaseType_t FFreeRTOSListUsbDev(int argc, char *argv[]);
 
 #ifdef __cplusplus
 }

+ 22 - 20
demo/phytium-e2000/usbhost/main.c

@@ -1,25 +1,25 @@
 /*
- * Copyright : (C) 2022 Phytium Information Technology, Inc. 
+ * Copyright : (C) 2022 Phytium Information Technology, Inc.
  * All Rights Reserved.
- *  
- * This program is OPEN SOURCE software: you can redistribute it and/or modify it  
- * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,  
- * either version 1.0 of the License, or (at your option) any later version. 
- *  
- * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;  
+ *
+ * This program is OPEN SOURCE software: you can redistribute it and/or modify it
+ * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
+ * either version 1.0 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the Phytium Public License for more details. 
- *  
- * 
+ * See the Phytium Public License for more details.
+ *
+ *
  * FilePath: main.c
  * Date: 2022-06-17 08:17:59
  * LastEditTime: 2022-06-17 08:17:59
- * Description:  This file is for c main entry
- * 
- * Modify History: 
- *  Ver   Who  Date   Changes
- * ----- ------  -------- --------------------------------------
- * 1.0   zhugengyu  2022/9/20  init commit
+ * Description:   This file is for cherry-usb test main entry.
+ *
+ * Modify History:
+ *  Ver   Who         Date         Changes
+ * ----- ------     --------    --------------------------------------
+ * 1.0   zhugengyu  2022/10/19   init commit
  */
 
 #include "shell.h"
@@ -31,13 +31,15 @@ int main(void)
     BaseType_t ret;
 
     ret = LSUserShellTask();
-    if(ret != pdPASS)
+    if (ret != pdPASS)
+    {
         goto FAIL_EXIT;
+    }
 
-    vTaskStartScheduler(); /* 启动任务,开启调度 */   
+    vTaskStartScheduler(); /* 启动任务,开启调度 */
     while (1); /* 正常不会执行到这里 */
-    
+
 FAIL_EXIT:
-    printf("failed 0x%x \r\n", ret);  
+    printf("Failed,the ret value is 0x%x. \r\n", ret);
     return 0;
 }

+ 69 - 18
demo/phytium-e2000/usbhost/sdkconfig

@@ -19,6 +19,7 @@ CONFIG_USE_CACHE=y
 CONFIG_USE_MMU=y
 CONFIG_USE_SYS_TICK=y
 # CONFIG_MMU_DEBUG_PRINTS is not set
+# CONFIG_BOOT_WITH_FLUSH_CACHE is not set
 # end of Arch Configuration
 
 #
@@ -60,9 +61,7 @@ CONFIG_ENABLE_Pl011_UART=y
 # CONFIG_USE_SDMMC is not set
 # CONFIG_USE_PCIE is not set
 # CONFIG_USE_WDT is not set
-CONFIG_USE_DMA=y
-# CONFIG_ENABLE_FGDMA is not set
-CONFIG_ENABLE_FDDMA=y
+# CONFIG_USE_DMA is not set
 # CONFIG_USE_NAND is not set
 # CONFIG_USE_RTC is not set
 # CONFIG_USE_SATA is not set
@@ -70,6 +69,8 @@ CONFIG_ENABLE_FDDMA=y
 # CONFIG_USE_ADC is not set
 # CONFIG_USE_PWM is not set
 # CONFIG_USE_IPC is not set
+# CONFIG_USE_MEDIA is not set
+# CONFIG_USE_SCMI_MHU is not set
 # end of Components Configuration
 
 CONFIG_USE_NEW_LIBC=y
@@ -88,6 +89,7 @@ CONFIG_USE_DEFAULT_INTERRUPT_CONFIG=y
 CONFIG_INTERRUPT_ROLE_MASTER=y
 # CONFIG_INTERRUPT_ROLE_SLAVE is not set
 CONFIG_LOG_EXTRA_INFO=y
+# CONFIG_LOG_DISPALY_CORE_NUM is not set
 # CONFIG_BOOTUP_DEBUG_PRINTS is not set
 
 #
@@ -110,6 +112,15 @@ CONFIG_FPU_STACK_SIZE=0x1000
 #
 # Compiler Options
 #
+
+#
+# Cross-Compiler Setting
+#
+CONFIG_GCC_OPTIMIZE_LEVEL=0
+# CONFIG_USE_EXT_COMPILER is not set
+# CONFIG_USE_KLIN_SYS is not set
+# end of Cross-Compiler Setting
+
 CONFIG_OUTPUT_BINARY=y
 # end of Compiler Options
 # end of Building Option
@@ -146,6 +157,7 @@ CONFIG_FREERTOS_USE_UART=y
 # Freertos Eth Drivers
 #
 # CONFIG_FREERTOS_USE_XMAC is not set
+# CONFIG_FREERTOS_USE_GMAC is not set
 # end of Freertos Eth Drivers
 
 #
@@ -163,29 +175,47 @@ CONFIG_FREERTOS_USE_FSPIM=y
 #
 # Freertos DMA Drivers
 #
-CONFIG_FREERTOS_USE_FDDMA=y
+# CONFIG_FREERTOS_USE_FDDMA is not set
 # CONFIG_FREERTOS_USE_FGDMA is not set
 # end of Freertos DMA Drivers
 
-#
-# Freertos MMC Drivers
-#
-# CONFIG_FREERTOS_USE_FSDIO is not set
-# end of Freertos MMC Drivers
-
 #
 # Freertos Adc Drivers
 #
 # CONFIG_FREERTOS_USE_ADC is not set
 # end of Freertos Adc Drivers
+
+#
+# Freertos Can Drivers
+#
+# CONFIG_FREERTOS_USE_CAN is not set
+# end of Freertos Can Drivers
+
+#
+# Freertos I2c Drivers
+#
+# CONFIG_FREERTOS_USE_I2C is not set
+# end of Freertos I2c Drivers
+
+#
+# Freertos Mio Drivers
+#
+# CONFIG_FREERTOS_USE_MIO is not set
+# end of Freertos Mio Drivers
+
+#
+# Freertos Timer Drivers
+#
+# CONFIG_FREERTOS_USE_TIMER is not set
+# end of Freertos Timer Drivers
 # end of Component Configuration
 
 #
-# FreeRTOS Setting
+# Third-Party Configuration
 #
 # CONFIG_USE_LWIP is not set
 CONFIG_USE_BACKTRACE=y
-# CONFIG_USE_FATFS is not set
+# CONFIG_USE_FATFS_0_1_4 is not set
 # CONFIG_USE_SFUD is not set
 # CONFIG_USE_SPIFFS is not set
 # CONFIG_USE_AMP is not set
@@ -214,10 +244,31 @@ CONFIG_CHERRYUSB_HOST=y
 CONFIG_CHERRY_USB_HOST_HUB=y
 CONFIG_CHERRY_USB_HOST_MSC=y
 CONFIG_CHERRY_USB_HOST_HID=y
-# CONFIG_CHERRY_USB_HOST_MTP is not set
-# CONFIG_CHERRY_USB_HOST_CDC is not set
-# CONFIG_CHERRY_USB_HOST_PRINTER is not set
-# CONFIG_CHERRY_USB_HOST_AXU_NET is not set
-# CONFIG_CHERRY_USB_HOST_RNDIS_WIRELESS is not set
+CONFIG_CHERRY_USB_HOST_VEDIO=y
+CONFIG_CHERRY_USB_HOST_CDC=y
+CONFIG_CHERRY_USB_HOST_RNDIS_WIRELESS=y
 # end of CherryUSB Configuration
-# end of FreeRTOS Setting
+# end of Third-Party Configuration
+
+#
+# Kernel Configuration
+#
+CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y
+CONFIG_FREERTOS_HZ=1000
+CONFIG_FREERTOS_MAX_PRIORITIES=32
+CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES=13
+CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES=11
+CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1
+CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE=1024
+CONFIG_FREERTOS_MAX_TASK_NAME_LEN=32
+CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1
+CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048
+CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10
+CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0
+CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
+CONFIG_FREERTOS_USE_TRACE_FACILITY=y
+CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y
+# CONFIG_FREERTOS_USE_TICKLESS_IDLE is not set
+CONFIG_FREERTOS_TOTAL_HEAP_SIZE=10240
+CONFIG_FREERTOS_TASK_FPU_SUPPORT=1
+# end of Kernel Configuration

+ 61 - 17
demo/phytium-e2000/usbhost/sdkconfig.h

@@ -18,6 +18,7 @@
 #define CONFIG_USE_MMU
 #define CONFIG_USE_SYS_TICK
 /* CONFIG_MMU_DEBUG_PRINTS is not set */
+/* CONFIG_BOOT_WITH_FLUSH_CACHE is not set */
 /* end of Arch Configuration */
 
 /* Board Configuration */
@@ -55,9 +56,7 @@
 /* CONFIG_USE_SDMMC is not set */
 /* CONFIG_USE_PCIE is not set */
 /* CONFIG_USE_WDT is not set */
-#define CONFIG_USE_DMA
-/* CONFIG_ENABLE_FGDMA is not set */
-#define CONFIG_ENABLE_FDDMA
+/* CONFIG_USE_DMA is not set */
 /* CONFIG_USE_NAND is not set */
 /* CONFIG_USE_RTC is not set */
 /* CONFIG_USE_SATA is not set */
@@ -65,6 +64,8 @@
 /* CONFIG_USE_ADC is not set */
 /* CONFIG_USE_PWM is not set */
 /* CONFIG_USE_IPC is not set */
+/* CONFIG_USE_MEDIA is not set */
+/* CONFIG_USE_SCMI_MHU is not set */
 /* end of Components Configuration */
 #define CONFIG_USE_NEW_LIBC
 /* end of Standalone Setting */
@@ -81,6 +82,7 @@
 #define CONFIG_INTERRUPT_ROLE_MASTER
 /* CONFIG_INTERRUPT_ROLE_SLAVE is not set */
 #define CONFIG_LOG_EXTRA_INFO
+/* CONFIG_LOG_DISPALY_CORE_NUM is not set */
 /* CONFIG_BOOTUP_DEBUG_PRINTS is not set */
 
 /* Linker Options */
@@ -101,6 +103,12 @@
 
 /* Compiler Options */
 
+/* Cross-Compiler Setting */
+
+#define CONFIG_GCC_OPTIMIZE_LEVEL 0
+/* CONFIG_USE_EXT_COMPILER is not set */
+/* CONFIG_USE_KLIN_SYS is not set */
+/* end of Cross-Compiler Setting */
 #define CONFIG_OUTPUT_BINARY
 /* end of Compiler Options */
 /* end of Building Option */
@@ -130,6 +138,7 @@
 /* Freertos Eth Drivers */
 
 /* CONFIG_FREERTOS_USE_XMAC is not set */
+/* CONFIG_FREERTOS_USE_GMAC is not set */
 /* end of Freertos Eth Drivers */
 
 /* Freertos Gpio Drivers */
@@ -144,26 +153,41 @@
 
 /* Freertos DMA Drivers */
 
-#define CONFIG_FREERTOS_USE_FDDMA
+/* CONFIG_FREERTOS_USE_FDDMA is not set */
 /* CONFIG_FREERTOS_USE_FGDMA is not set */
 /* end of Freertos DMA Drivers */
 
-/* Freertos MMC Drivers */
-
-/* CONFIG_FREERTOS_USE_FSDIO is not set */
-/* end of Freertos MMC Drivers */
-
 /* Freertos Adc Drivers */
 
 /* CONFIG_FREERTOS_USE_ADC is not set */
 /* end of Freertos Adc Drivers */
+
+/* Freertos Can Drivers */
+
+/* CONFIG_FREERTOS_USE_CAN is not set */
+/* end of Freertos Can Drivers */
+
+/* Freertos I2c Drivers */
+
+/* CONFIG_FREERTOS_USE_I2C is not set */
+/* end of Freertos I2c Drivers */
+
+/* Freertos Mio Drivers */
+
+/* CONFIG_FREERTOS_USE_MIO is not set */
+/* end of Freertos Mio Drivers */
+
+/* Freertos Timer Drivers */
+
+/* CONFIG_FREERTOS_USE_TIMER is not set */
+/* end of Freertos Timer Drivers */
 /* end of Component Configuration */
 
-/* FreeRTOS Setting */
+/* Third-Party Configuration */
 
 /* CONFIG_USE_LWIP is not set */
 #define CONFIG_USE_BACKTRACE
-/* CONFIG_USE_FATFS is not set */
+/* CONFIG_USE_FATFS_0_1_4 is not set */
 /* CONFIG_USE_SFUD is not set */
 /* CONFIG_USE_SPIFFS is not set */
 /* CONFIG_USE_AMP is not set */
@@ -189,12 +213,32 @@
 #define CONFIG_CHERRY_USB_HOST_HUB
 #define CONFIG_CHERRY_USB_HOST_MSC
 #define CONFIG_CHERRY_USB_HOST_HID
-/* CONFIG_CHERRY_USB_HOST_MTP is not set */
-/* CONFIG_CHERRY_USB_HOST_CDC is not set */
-/* CONFIG_CHERRY_USB_HOST_PRINTER is not set */
-/* CONFIG_CHERRY_USB_HOST_AXU_NET is not set */
-/* CONFIG_CHERRY_USB_HOST_RNDIS_WIRELESS is not set */
+#define CONFIG_CHERRY_USB_HOST_VEDIO
+#define CONFIG_CHERRY_USB_HOST_CDC
+#define CONFIG_CHERRY_USB_HOST_RNDIS_WIRELESS
 /* end of CherryUSB Configuration */
-/* end of FreeRTOS Setting */
+/* end of Third-Party Configuration */
+
+/* Kernel Configuration */
+
+#define CONFIG_FREERTOS_OPTIMIZED_SCHEDULER
+#define CONFIG_FREERTOS_HZ 1000
+#define CONFIG_FREERTOS_MAX_PRIORITIES 32
+#define CONFIG_FREERTOS_KERNEL_INTERRUPT_PRIORITIES 13
+#define CONFIG_FREERTOS_MAX_API_CALL_INTERRUPT_PRIORITIES 11
+#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1
+#define CONFIG_FREERTOS_MINIMAL_TASK_STACKSIZE 1024
+#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 32
+#define CONFIG_FREERTOS_TIMER_TASK_PRIORITY 1
+#define CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH 2048
+#define CONFIG_FREERTOS_TIMER_QUEUE_LENGTH 10
+#define CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE 0
+#define CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
+#define CONFIG_FREERTOS_USE_TRACE_FACILITY
+#define CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS
+/* CONFIG_FREERTOS_USE_TICKLESS_IDLE is not set */
+#define CONFIG_FREERTOS_TOTAL_HEAP_SIZE 10240
+#define CONFIG_FREERTOS_TASK_FPU_SUPPORT 1
+/* end of Kernel Configuration */
 
 #endif

+ 45 - 21
demo/phytium-e2000/usbhost/src/cmd_usb.c

@@ -1,22 +1,22 @@
 /*
- * Copyright : (C) 2022 Phytium Information Technology, Inc. 
+ * Copyright : (C) 2022 Phytium Information Technology, Inc.
  * All Rights Reserved.
- *  
- * This program is OPEN SOURCE software: you can redistribute it and/or modify it  
- * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,  
- * either version 1.0 of the License, or (at your option) any later version. 
- *  
- * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;  
+ *
+ * This program is OPEN SOURCE software: you can redistribute it and/or modify it
+ * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
+ * either version 1.0 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the Phytium Public License for more details. 
- *  
- * 
+ * See the Phytium Public License for more details.
+ *
+ *
  * FilePath: cmd_usb.c
  * Date: 2022-09-19 14:34:44
  * LastEditTime: 2022-09-19 14:34:45
- * Description:  This files is for letter shell command implmentation
- * 
- * Modify History: 
+ * Description:  This file is for USB shell command.
+ *
+ * Modify History:
  *  Ver   Who        Date         Changes
  * ----- ------     --------    --------------------------------------
  * 1.0   zhugengyu  2022/9/20  init commit
@@ -34,24 +34,48 @@
 static int USBCmdEntry(int argc, char *argv[])
 {
     int ret = 0;
-    u32 bytes = 32;
-    u32 usb_id = 0U;
+    u32 usb_id = 0;
+    const char *devname;
 
     if (!strcmp(argv[1], "init"))
     {
-        ret = FFreeRTOSInitUsb();
+        if (argc < 3) {
+            return -2;
+        }
+
+        usb_id = (uint8_t)simple_strtoul(argv[2], NULL, 10);
+        ret = FFreeRTOSInitUsb(usb_id);
+    }
+    else if (!strcmp(argv[1], "lsusb"))
+    {
+        ret = FFreeRTOSListUsbDev(argc - 1, &argv[1]);
     }
     else if (!strcmp(argv[1], "disk"))
     {
-        ret = FFreeRTOSWriteReadUsbDisk();
+        if (argc < 3) {
+            return -2;
+        }
+
+        devname = argv[2];
+        ret = FFreeRTOSRunUsbDisk(devname);
     }
-    else if (!strcmp(argv[1], "hid"))
+    else if (!strcmp(argv[1], "kbd"))
     {
-        ret = FFreeRTOSRecvInput();
+        if (argc < 3) {
+            return -2;
+        }
+
+        devname = argv[2];
+        ret = FFreeRTOSRunUsbKeyboard(devname);
     }
-    else if (!strcmp(argv[1], "lsusb"))
+    else if (!strcmp(argv[1], "mouse"))
     {
-        ret = FFreeRTOSListUsb(argc - 1, &argv[1]);
+        if (argc < 3) {
+            return -2;
+        }
+
+        devname = argv[2];
+        ret = FFreeRTOSRunUsbMouse(devname);
     }
 
     return ret;

+ 62 - 53
demo/phytium-e2000/usbhost/src/usb_disk.c

@@ -1,24 +1,25 @@
 /*
- * Copyright : (C) 2022 Phytium Information Technology, Inc. 
+ * Copyright : (C) 2022 Phytium Information Technology, Inc.
  * All Rights Reserved.
- *  
- * This program is OPEN SOURCE software: you can redistribute it and/or modify it  
- * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,  
- * either version 1.0 of the License, or (at your option) any later version. 
- *  
- * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;  
+ *
+ * This program is OPEN SOURCE software: you can redistribute it and/or modify it
+ * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
+ * either version 1.0 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the Phytium Public License for more details. 
- *  
- * 
+ * See the Phytium Public License for more details.
+ *
+ *
  * FilePath: usb_disk.c
  * Date: 2022-09-23 08:24:09
  * LastEditTime: 2022-09-23 08:24:10
- * Description:  This files is for 
- * 
- * Modify History: 
- *  Ver   Who        Date         Changes
+ * Description:  This file is for the usb disk functions.
+ *
+ * Modify History:
+ *  Ver   Who         Date         Changes
  * ----- ------     --------    --------------------------------------
+ * 1.0   zhugengyu  2022/10/19   init commit
  */
 /***************************** Include Files *********************************/
 #include <stdio.h>
@@ -27,10 +28,10 @@
 #include "FreeRTOS.h"
 #include "task.h"
 
-#include "ft_assert.h"
-#include "interrupt.h"
-#include "cpu_info.h"
-#include "ft_debug.h"
+#include "fassert.h"
+#include "finterrupt.h"
+#include "fcpu_info.h"
+#include "fdebug.h"
 
 #include "usbh_core.h"
 #include "usbh_msc.h"
@@ -51,75 +52,83 @@
 
 
 /*****************************************************************************/
-
-static void UsbMscTask(void * args)
+static void UsbMscTask(void *args)
 {
     int ret;
     struct usbh_msc *msc_class;
-    static uint8_t partition_table[512] = {0};
+    static uint8_t rd_table[512] = {0};
+    static uint8_t wr_table[512] = {0};
+    u32 loop = 0;
+    const char *devname = (const char *)args;
+
+    msc_class = (struct usbh_msc *)usbh_find_class_instance(devname);
+    if (msc_class == NULL)
+    {
+        USB_LOG_RAW("Do not find %s. \r\n", devname);
+        goto err_exit;
+    }
 
     while (TRUE)
     {
-        msc_class = (struct usbh_msc *)usbh_find_class_instance("/dev/sda");
-        if (msc_class == NULL) 
+        /* write partition table */
+        memcpy(wr_table, rd_table, sizeof(rd_table));
+        for (uint32_t i = 0; i < 512; i++)
+        {
+            wr_table[i] ^= 0xfffff;
+        }
+
+        ret = usbh_msc_scsi_write10(msc_class, 0, wr_table, 1);
+        if (ret < 0)
         {
-            USB_LOG_RAW("do not find /dev/sda\r\n");
+            USB_LOG_ERR("Error in scsi_write10 error, ret:%d", ret);
             goto err_exit;
         }
 
         /* get the partition table */
-        ret = usbh_msc_scsi_read10(msc_class, 0, partition_table, 1);
-        if (ret < 0) 
+        ret = usbh_msc_scsi_read10(msc_class, 0, rd_table, 1);
+        if (ret < 0)
         {
-            USB_LOG_RAW("scsi_read10 error,ret:%d\r\n", ret);
+            USB_LOG_RAW("Error in scsi_read10, ret:%d", ret);
             goto err_exit;
         }
-        
-        for (uint32_t i = 0; i < 512; i++) 
+
+        /* check if read table == write table */
+        if (0 != memcmp(wr_table, rd_table, sizeof(rd_table)))
         {
-            if (i % 16 == 0) 
-            {
-                USB_LOG_RAW("\r\n");
-            }
-            USB_LOG_RAW("%02x ", partition_table[i]);
+            USB_LOG_ERR("Failed to check read and write.\r\n");
+            goto err_exit;
         }
-        USB_LOG_RAW("\r\n");
-
-        /* write partition table */
-        for (uint32_t i = 0; i < 512; i++) 
+        else
         {
-            partition_table[i] ^= 0xfffff;
+            printf("[%d] disk read and write successfully.\r\n", loop++);
         }
 
-        ret = usbh_msc_scsi_write10(msc_class, 0, partition_table, 1);
-        if (ret < 0) 
-        {
-            USB_LOG_RAW("scsi_write10 error,ret:%d\r\n", ret);
-            goto err_exit;
+        if (loop > 10) {
+            break;
         }
 
-        vTaskDelay(10);
+        vTaskDelay(100);
     }
 
 err_exit:
     vTaskDelete(NULL);
 }
 
-BaseType_t FFreeRTOSWriteReadUsbDisk(void)
+BaseType_t FFreeRTOSRunUsbDisk(const char *devname)
 {
     BaseType_t ret = pdPASS;
 
     taskENTER_CRITICAL(); /* no schedule when create task */
 
-    ret = xTaskCreate((TaskFunction_t )UsbMscTask,
-                            (const char* )"UsbMscTask",
-                            (uint16_t )2048,
-                            NULL,
-                            (UBaseType_t )configMAX_PRIORITIES - 1,
-                            NULL);
+    ret = xTaskCreate((TaskFunction_t)UsbMscTask,
+                      (const char *)"UsbMscTask",
+                      (uint16_t)2048,
+                      (void *)devname,
+                      (UBaseType_t)configMAX_PRIORITIES - 1,
+                      NULL);
     FASSERT_MSG(pdPASS == ret, "create task failed");
 
     taskEXIT_CRITICAL(); /* allow schedule since task created */
 
-    return ret;    
+    return ret;
 }

+ 63 - 43
demo/phytium-e2000/usbhost/src/usb_host.c

@@ -1,22 +1,22 @@
 /*
- * Copyright : (C) 2022 Phytium Information Technology, Inc. 
+ * Copyright : (C) 2022 Phytium Information Technology, Inc.
  * All Rights Reserved.
- *  
- * This program is OPEN SOURCE software: you can redistribute it and/or modify it  
- * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,  
- * either version 1.0 of the License, or (at your option) any later version. 
- *  
- * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;  
+ *
+ * This program is OPEN SOURCE software: you can redistribute it and/or modify it
+ * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
+ * either version 1.0 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the Phytium Public License for more details. 
- *  
- * 
+ * See the Phytium Public License for more details.
+ *
+ *
  * FilePath: usb_host.c
  * Date: 2022-07-22 13:57:42
  * LastEditTime: 2022-07-22 13:57:43
- * Description:  This files is for cherry usb host function implementation
- * 
- * Modify History: 
+ * Description:  This file is for the usb host functions.
+ *
+ * Modify History:
  *  Ver   Who        Date         Changes
  * ----- ------     --------    --------------------------------------
  * 1.0   zhugengyu  2022/9/20  init commit
@@ -28,15 +28,14 @@
 #include "FreeRTOS.h"
 #include "task.h"
 
-#include "ft_assert.h"
-#include "interrupt.h"
-#include "cpu_info.h"
-#include "ft_debug.h"
-#include "cache.h"
+#include "fassert.h"
+#include "finterrupt.h"
+#include "fcpu_info.h"
+#include "fdebug.h"
+#include "fcache.h"
+#include "fmemory_pool.h"
 
 #include "usbh_core.h"
-
-#include "fmemory_pool.h"
 /************************** Constant Definitions *****************************/
 #define FUSB_MEMP_TOTAL_SIZE     SZ_1M
 
@@ -54,18 +53,18 @@ static u8 memp_buf[FUSB_MEMP_TOTAL_SIZE];
 #define FUSB_DEBUG(format, ...) FT_DEBUG_PRINT_D(FUSB_DEBUG_TAG, format, ##__VA_ARGS__)
 
 /************************** Function Prototypes ******************************/
-extern void USBH_IRQHandler(void);
+extern void USBH_IRQHandler(void *);
 
 /*****************************************************************************/
 static void UsbHcInterrruptHandler(s32 vector, void *param)
 {
-    USBH_IRQHandler();
+    USBH_IRQHandler(param);
 }
 
-static void UsbHcSetupInterrupt(void)
+static void UsbHcSetupInterrupt(u32 id)
 {
     u32 cpu_id;
-    u32 irq_num = CONFIG_XHCI_IRQ_NUM;
+    u32 irq_num = (id == FUSB3_ID_0) ? FUSB3_0_IRQ_NUM : FUSB3_1_IRQ_NUM;
     u32 irq_priority = 13U;
 
     GetCpuId(&cpu_id);
@@ -74,9 +73,9 @@ static void UsbHcSetupInterrupt(void)
     InterruptSetPriority(irq_num, irq_priority);
 
     /* register intr callback */
-    InterruptInstall(irq_num, 
-                     UsbHcInterrruptHandler, 
-                     NULL, 
+    InterruptInstall(irq_num,
+                     UsbHcInterrruptHandler,
+                     NULL,
                      NULL);
 
     /* enable irq */
@@ -91,11 +90,19 @@ void UsbHcSetupMemp(void)
     }
 }
 
-/* implement cherryusb */
-void usb_hc_low_level_init(void)
+/* implement cherryusb weak functions */
+void usb_hc_low_level_init()
 {
     UsbHcSetupMemp();
-    UsbHcSetupInterrupt();
+    UsbHcSetupInterrupt(CONFIG_USBHOST_XHCI_ID);
+}
+
+unsigned long usb_hc_get_register_base()
+{
+    if (FUSB3_ID_0 == CONFIG_USBHOST_XHCI_ID)
+        return FUSB3_0_BASE_ADDR + FUSB3_XHCI_OFFSET;
+    else
+        return FUSB3_1_BASE_ADDR + FUSB3_XHCI_OFFSET;
 }
 
 void *usb_hc_malloc(size_t size)
@@ -106,17 +113,21 @@ void *usb_hc_malloc(size_t size)
 void *usb_hc_malloc_align(size_t align, size_t size)
 {
     void *result = FMempMallocAlign(&memp, size, align);
-    
+
     if (result)
+    {
         memset(result, 0U, size);
+    }
 
     return result;
 }
 
 void usb_hc_free(void *ptr)
 {
-	if (NULL != ptr)
-		FMempFree(&memp, ptr);    
+    if (NULL != ptr)
+    {
+        FMempFree(&memp, ptr);
+    }
 }
 
 void usb_assert(const char *filename, int linenum)
@@ -128,25 +139,34 @@ void usb_hc_dcache_invalidate(void *addr, unsigned long len)
 {
     FCacheDCacheInvalidateRange((uintptr)addr, len);
 }
+/*****************************************/
 
-static void UsbInitTask(void * args)
+static void UsbInitTask(void *args)
 {
-    usbh_initialize();
+    if (0 == usbh_initialize())
+    {
+        printf("Init cherryusb host successfully.put 'usb lsusb -t' to see devices.\r\n");
+    }
+    else
+    {
+        FUSB_ERROR("Init cherryusb host failed.");
+    }
+
     vTaskDelete(NULL);
 }
 
-BaseType_t FFreeRTOSInitUsb(void)
+BaseType_t FFreeRTOSInitUsb()
 {
     BaseType_t ret = pdPASS;
 
     taskENTER_CRITICAL(); /* no schedule when create task */
 
-    ret = xTaskCreate((TaskFunction_t )UsbInitTask,
-                            (const char* )"UsbInitTask",
-                            (uint16_t )2048,
-                            NULL,
-                            (UBaseType_t )configMAX_PRIORITIES - 1,
-                            NULL);
+    ret = xTaskCreate((TaskFunction_t)UsbInitTask,
+                      (const char *)"UsbInitTask",
+                      (uint16_t)2048,
+                      NULL,
+                      (UBaseType_t)configMAX_PRIORITIES - 1,
+                      NULL);
     FASSERT_MSG(pdPASS == ret, "create task failed");
 
     taskEXIT_CRITICAL(); /* allow schedule since task created */
@@ -154,7 +174,7 @@ BaseType_t FFreeRTOSInitUsb(void)
     return ret;
 }
 
-BaseType_t FFreeRTOSListUsb(int argc, char *argv[])
+BaseType_t FFreeRTOSListUsbDev(int argc, char *argv[])
 {
     return lsusb(argc, argv);
 }

+ 140 - 57
demo/phytium-e2000/usbhost/src/usb_input.c

@@ -1,22 +1,22 @@
 /*
- * Copyright : (C) 2022 Phytium Information Technology, Inc. 
+ * Copyright : (C) 2022 Phytium Information Technology, Inc.
  * All Rights Reserved.
- *  
- * This program is OPEN SOURCE software: you can redistribute it and/or modify it  
- * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,  
- * either version 1.0 of the License, or (at your option) any later version. 
- *  
- * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;  
+ *
+ * This program is OPEN SOURCE software: you can redistribute it and/or modify it
+ * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
+ * either version 1.0 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the Phytium Public License for more details. 
- *  
- * 
+ * See the Phytium Public License for more details.
+ *
+ *
  * FilePath: usb_input.c
  * Date: 2022-07-22 13:57:42
  * LastEditTime: 2022-07-22 13:57:43
- * Description:  This files is for 
- * 
- * Modify History: 
+ * Description:  This file is for the usb input functions.
+ *
+ * Modify History:
  *  Ver   Who        Date         Changes
  * ----- ------     --------    --------------------------------------
  * 1.0   zhugengyu  2022/9/20  init commit
@@ -28,10 +28,10 @@
 #include "FreeRTOS.h"
 #include "task.h"
 
-#include "ft_assert.h"
-#include "interrupt.h"
-#include "cpu_info.h"
-#include "ft_debug.h"
+#include "fassert.h"
+#include "finterrupt.h"
+#include "fcpu_info.h"
+#include "fdebug.h"
 
 #include "usbh_core.h"
 #include "usbh_hid.h"
@@ -145,6 +145,10 @@
 
 /************************** Variable Definitions *****************************/
 static u8 const keycode2ascii[128][2] =  { HID_KEYCODE_TO_ASCII };
+static struct usbh_urb kbd_intin_urb;
+static struct usbh_urb mouse_intin_urb;
+static uint8_t kbd_buffer[128] __attribute__((aligned(sizeof(unsigned long)))) = {0};
+static uint8_t mouse_buffer[128] __attribute__((aligned(sizeof(unsigned long)))) = {0};
 
 /***************** Macros (Inline Functions) Definitions *********************/
 #define FUSB_DEBUG_TAG "USB-INPUT"
@@ -159,17 +163,17 @@ static u8 const keycode2ascii[128][2] =  { HID_KEYCODE_TO_ASCII };
 /*****************************************************************************/
 static inline void UsbMouseLeftButtonCB(void)
 {
-    printf("    Button Left\r\n");
+    printf("<-\r\n");
 }
 
 static inline void UsbMouseRightButtonCB(void)
 {
-    printf("    Button Right\r\n");
+    printf("->\r\n");
 }
 
 static inline void UsbMouseMiddleButtonCB(void)
 {
-    printf("    Button Middle\r\n");
+    printf("C\r\n");
 }
 
 static void UsbMouseHandleInput(struct usb_hid_mouse_report *input)
@@ -191,16 +195,18 @@ static void UsbMouseHandleInput(struct usb_hid_mouse_report *input)
     }
 
     /*------------- cursor movement -------------*/
-    printf("    Cursor %d %d %d\r\n", input->xdisp, input->ydisp, input->wdisp);
+    printf("[x:%d y:%d w:%d]\r\n", input->xdisp, input->ydisp, input->wdisp);
 }
 
 /* look up new key in previous keys */
 static inline boolean FindKeyInPrevInput(const struct usb_hid_kbd_report *report, u8 keycode)
 {
-    for(u8 i=0; i < 6; i++)
+    for (u8 i = 0; i < 6; i++)
     {
-        if (report->key[i] == keycode)  
+        if (report->key[i] == keycode)
+        {
             return TRUE;
+        }
     }
 
     return FALSE;
@@ -247,67 +253,144 @@ static u8 UsbInputGetInterfaceProtocol(struct usbh_hid *hid_class)
     return intf_desc->bInterfaceProtocol;
 }
 
-static void UsbInputTask(void * args)
+static void UsbKeyboardCallback(void *arg, int nbytes)
 {
-    int ret;
-    struct usbh_hid *hid_class;
-    static uint8_t hid_buffer[128] = {0};
     u8 intf_protocol;
+    struct usbh_hid *kbd_class = (struct usbh_hid *)arg;
+    intf_protocol = UsbInputGetInterfaceProtocol(kbd_class);
 
-    FUSB_INFO("%s", __func__);
-
-    while (TRUE)
+    if (HID_PROTOCOL_KEYBOARD == intf_protocol) /* handle input from keyboard */
     {
-        hid_class = (struct usbh_hid *)usbh_find_class_instance("/dev/input0");
-        if (hid_class == NULL) 
+        if (nbytes < (int)sizeof(struct usb_hid_kbd_report))
         {
-            USB_LOG_RAW("do not find /dev/input0\r\n");
-            goto err_exit;
+            FUSB_ERROR("nbytes = %d", nbytes);
         }
-
-        ret = usbh_int_transfer(hid_class->intin, hid_buffer, 8, 1000);
-        if (ret < 0) 
+        else
         {
-            USB_LOG_RAW("intr in error,ret:%d\r\n", ret);
+            UsbKeyBoardHandleInput((struct usb_hid_kbd_report *)kbd_buffer);
         }
+    }
+    else
+    {
+        FUSB_ERROR("mismatch callback for protocol-%d", intf_protocol);
+        return;
+    }
 
-        intf_protocol = UsbInputGetInterfaceProtocol(hid_class);
-        if (HID_PROTOCOL_KEYBOARD == intf_protocol)
-        {
-            UsbKeyBoardHandleInput((struct usb_hid_kbd_report *)hid_buffer);
-        }
-        else if (HID_PROTOCOL_MOUSE == intf_protocol)
+    usbh_submit_urb(&kbd_intin_urb); /* ask for next inputs */
+}
+
+static void UsbMouseCallback(void *arg, int nbytes)
+{
+    u8 intf_protocol;
+    struct usbh_hid *mouse_class = (struct usbh_hid *)arg;
+    intf_protocol = UsbInputGetInterfaceProtocol(mouse_class);
+
+    if (HID_PROTOCOL_MOUSE == intf_protocol) /* handle input from mouse */
+    {
+        if (nbytes < (int)sizeof(struct usb_hid_mouse_report))
         {
-            UsbMouseHandleInput((struct usb_hid_mouse_report *)hid_buffer);            
+            FUSB_ERROR("nbytes = %d", nbytes);
         }
         else
         {
-            FUSB_ERROR("unsupported hid interface %d", intf_protocol);
-            goto err_exit;
-        }
+            UsbMouseHandleInput((struct usb_hid_mouse_report *)mouse_buffer);
+        }        
+    }
+    else
+    {
+        FUSB_ERROR("mismatch callback for protocol-%d", intf_protocol);
+        return;        
+    }
+
+    usbh_submit_urb(&mouse_intin_urb); /* ask for next inputs */
+}
+
+static void UsbKeyboardTask(void *args)
+{
+    int ret;
+    struct usbh_hid *kbd_class;
+    u8 intf_protocol;
+    const char *dev_name = (const char *)args;
+    
+    kbd_class = (struct usbh_hid *)usbh_find_class_instance(dev_name);
+    if (kbd_class == NULL)
+    {
+        FUSB_ERROR("Do not find %s.", dev_name);
+        goto err_exit;
+    }
+
+    while (TRUE)
+    {
+        usbh_int_urb_fill(&kbd_intin_urb, kbd_class->intin, kbd_buffer, 8, 0, UsbKeyboardCallback, kbd_class);
+        ret = usbh_submit_urb(&kbd_intin_urb);
+
+        vTaskDelay(1);
+    }
+
+err_exit:
+    vTaskDelete(NULL);
+}
+
+static void UsbMouseTask(void *args)
+{
+    int ret;
+    struct usbh_hid *mouse_class;
+    u8 intf_protocol;
+    const char *dev_name = (const char *)args;
+    
+    mouse_class = (struct usbh_hid *)usbh_find_class_instance(dev_name);
+    if (mouse_class == NULL)
+    {
+        FUSB_ERROR("Do not find %s.", dev_name);
+        goto err_exit;
+    }
+
+    while (TRUE)
+    {
+        usbh_int_urb_fill(&mouse_intin_urb, mouse_class->intin, mouse_buffer, 8, 0, UsbMouseCallback, mouse_class);
+        ret = usbh_submit_urb(&mouse_intin_urb);
 
-        vTaskDelay(10);
+        vTaskDelay(1);
     }
 
 err_exit:
     vTaskDelete(NULL);
 }
 
-BaseType_t FFreeRTOSRecvInput(void)
+BaseType_t FFreeRTOSRunUsbKeyboard(const char *devname)
+{
+    BaseType_t ret = pdPASS;
+
+    taskENTER_CRITICAL(); /* no schedule when create task */
+
+    ret = xTaskCreate((TaskFunction_t)UsbKeyboardTask,
+                      (const char *)"UsbKeyboardTask",
+                      (uint16_t)2048,
+                      (void *)devname,
+                      (UBaseType_t)configMAX_PRIORITIES - 1,
+                      NULL);
+    FASSERT_MSG(pdPASS == ret, "create task failed");
+
+    taskEXIT_CRITICAL(); /* allow schedule since task created */
+
+    return ret;
+}
+
+BaseType_t FFreeRTOSRunUsbMouse(const char *devname)
 {
     BaseType_t ret = pdPASS;
 
     taskENTER_CRITICAL(); /* no schedule when create task */
 
-    ret = xTaskCreate((TaskFunction_t )UsbInputTask,
-                        (const char* )"UsbInputTask",
-                        (uint16_t )2048,
-                        NULL,
-                        (UBaseType_t )configMAX_PRIORITIES - 1,
-                        NULL);
+    ret = xTaskCreate((TaskFunction_t)UsbMouseTask,
+                      (const char *)"UsbMouseTask",
+                      (uint16_t)2048,
+                      (void *)devname,
+                      (UBaseType_t)configMAX_PRIORITIES - 1,
+                      NULL);
     FASSERT_MSG(pdPASS == ret, "create task failed");
 
     taskEXIT_CRITICAL(); /* allow schedule since task created */
 
-    return ret;      
+    return ret;
 }