Browse Source

[usbhost] List keyboard option. (#6456)

* [bsp/nuvoton] Support NuMaker-M467HJ BSP and update drivers.

* Format files.

* [usbhost] List keyboard and update driver.

* Enlarge to reasonable thread stack size.

* Do indent..

* Keep private.

Co-authored-by: Wayne Lin <wclin@nuvoton.com>
Wayne 2 years ago
parent
commit
dc9887913b

+ 7 - 4
components/drivers/Kconfig

@@ -682,16 +682,19 @@ menu "Using USB"
                 default n
                 if RT_USBH_MSTORAGE
                     config UDISK_MOUNTPOINT
-                    string "Udisk mount dir"
-                    default "/"
+                        string "Udisk mount dir"
+                        default "/"
                 endif
             config RT_USBH_HID
                 bool "Enable HID Drivers"
                 default n
                 if RT_USBH_HID
                     config RT_USBH_HID_MOUSE
-                    bool "Enable HID mouse protocol"
-                    default n
+                        bool "Enable HID mouse protocol"
+                        default n
+                    config RT_USBH_HID_KEYBOARD
+                        bool "Enable HID keyboard protocol"
+                        default n
                 endif
         endif
     config RT_USING_USB_DEVICE

+ 23 - 2
components/drivers/usb/usbhost/class/ukbd.c

@@ -34,9 +34,27 @@ static rt_err_t rt_usbh_hid_kbd_callback(void* arg)
     return RT_EOK;
 }
 
+static rt_thread_t kbd_thread;
+static void kbd_task(void* param)
+{
+    struct uhintf* intf = (struct uhintf*)param;
+    while (1)
+    {
+        if (rt_usb_hcd_pipe_xfer(intf->device->hcd, ((struct uhid*)intf->user_data)->pipe_in,
+            ((struct uhid*)intf->user_data)->buffer, ((struct uhid*)intf->user_data)->pipe_in->ep.wMaxPacketSize,
+            USB_TIMEOUT_BASIC) == 0)
+        {
+            break;
+        }
+
+        rt_usbh_hid_kbd_callback(intf->user_data);
+    }
+}
+
+
 static rt_err_t rt_usbh_hid_kbd_init(void* arg)
 {
-    struct uintf* intf = (struct uintf*)arg;
+    struct uhintf* intf = (struct uhintf*)arg;
 
     RT_ASSERT(intf != RT_NULL);
 
@@ -44,7 +62,10 @@ static rt_err_t rt_usbh_hid_kbd_init(void* arg)
 
     rt_usbh_hid_set_idle(intf, 10, 0);
 
-    //RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb keyboard\n"));
+    RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb keyboard\n"));
+
+    kbd_thread = rt_thread_create("kbd0", kbd_task, intf, 1024, 8, 100);
+    rt_thread_startup(kbd_thread);
 
     return RT_EOK;
 }

+ 3 - 3
components/drivers/usb/usbhost/class/umouse.c

@@ -126,8 +126,8 @@ static rt_err_t rt_usbh_hid_mouse_callback(void* arg)
     return RT_EOK;
 }
 
-rt_thread_t mouse_thread;
-void mouse_task(void* param)
+static rt_thread_t mouse_thread;
+static void mouse_task(void* param)
 {
     struct uhintf* intf = (struct uhintf*)param;
     while (1)
@@ -154,7 +154,7 @@ static rt_err_t rt_usbh_hid_mouse_init(void* arg)
 
     rt_usbh_hid_set_idle(intf, 0, 0);
 
-    mouse_thread = rt_thread_create("mouse0", mouse_task, intf, 500, 8, 100);
+    mouse_thread = rt_thread_create("mouse0", mouse_task, intf, 1024, 8, 100);
     rt_thread_startup(mouse_thread);
 
     RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb mouse\n"));

+ 11 - 3
components/drivers/usb/usbhost/core/usbhost.c

@@ -47,13 +47,21 @@ rt_err_t rt_usb_host_init(const char *name)
     rt_usbh_class_driver_register(drv);
 #endif
 #ifdef RT_USBH_HID
+    extern ucd_t rt_usbh_class_driver_hid(void);
     /* register mass storage class driver */
     drv = rt_usbh_class_driver_hid();
     rt_usbh_class_driver_register(drv);
 #ifdef RT_USBH_HID_MOUSE
-    uprotocal_t protocal;
-    protocal = rt_usbh_hid_protocal_mouse();
-    rt_usbh_hid_protocal_register(protocal);
+    {
+        extern uprotocal_t rt_usbh_hid_protocal_mouse(void);
+        rt_usbh_hid_protocal_register(rt_usbh_hid_protocal_mouse());
+    }
+#endif
+#ifdef RT_USBH_HID_KEYBOARD
+    {
+        extern uprotocal_t rt_usbh_hid_protocal_kbd(void);
+        rt_usbh_hid_protocal_register(rt_usbh_hid_protocal_kbd());
+    }
 #endif
 #endif