This is an automated email from the ASF dual-hosted git repository.

archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 98fba7199836e617516ee076ca75997212a87a7e
Author: zhangyuan21 <zhangyua...@xiaomi.com>
AuthorDate: Sat Jul 29 16:05:16 2023 +0800

    usbadb: add usbadb boardctl
    
    Signed-off-by: zhangyuan21 <zhangyua...@xiaomi.com>
---
 boards/boardctl.c                    | 34 ++++++++++++++++++++++++++++++++++
 boards/sim/sim/sim/src/sim_bringup.c |  4 +++-
 drivers/usbdev/adb.c                 | 21 ++++++++++++++++-----
 include/nuttx/usb/adb.h              | 14 ++++++++++++--
 include/sys/boardctl.h               |  3 +++
 5 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/boards/boardctl.c b/boards/boardctl.c
index ce6db3f745..2707bb161c 100644
--- a/boards/boardctl.c
+++ b/boards/boardctl.c
@@ -45,6 +45,7 @@
 #endif
 
 #ifdef CONFIG_BOARDCTL_USBDEVCTRL
+#  include <nuttx/usb/adb.h>
 #  include <nuttx/usb/cdcacm.h>
 #  include <nuttx/usb/pl2303.h>
 #  include <nuttx/usb/usbmsc.h>
@@ -88,6 +89,39 @@ static inline int
 
   switch (ctrl->usbdev)
     {
+#if defined(CONFIG_USBADB) && !defined(CONFIG_USBADB_COMPOSITE)
+      case BOARDIOC_USBDEV_ADB:              /* ADB class */
+        switch (ctrl->action)
+          {
+            case BOARDIOC_USBDEV_INITIALIZE: /* Initialize ADB device */
+              break;
+
+            case BOARDIOC_USBDEV_CONNECT:    /* Connect the ADB device */
+              {
+                DEBUGASSERT(ctrl->handle != NULL);
+
+                *ctrl->handle = usbdev_adb_initialize();
+                if (*ctrl->handle == NULL)
+                  {
+                    ret = -EIO;
+                  }
+              }
+              break;
+
+            case BOARDIOC_USBDEV_DISCONNECT: /* Disconnect the ADB device */
+              {
+                DEBUGASSERT(ctrl->handle != NULL && *ctrl->handle != NULL);
+                usbdev_adb_uninitialize(*ctrl->handle);
+              }
+              break;
+
+            default:
+              ret = -EINVAL;
+              break;
+          }
+        break;
+#endif
+
 #ifdef CONFIG_CDCACM
       case BOARDIOC_USBDEV_CDCACM:           /* CDC/ACM, not in a composite */
         switch (ctrl->action)
diff --git a/boards/sim/sim/sim/src/sim_bringup.c 
b/boards/sim/sim/sim/src/sim_bringup.c
index da5cc9d083..4f3f31a308 100644
--- a/boards/sim/sim/sim/src/sim_bringup.c
+++ b/boards/sim/sim/sim/src/sim_bringup.c
@@ -499,7 +499,9 @@ int sim_bringup(void)
   rc_dummy_initialize(0);
 #endif
 
-#if defined(CONFIG_USBADB) && !defined(CONFIG_USBADB_COMPOSITE)
+#if defined(CONFIG_USBADB) && \
+    !defined(CONFIG_USBADB_COMPOSITE) && \
+    !defined(CONFIG_BOARDCTL_USBDEVCTRL)
   usbdev_adb_initialize();
 #endif
 
diff --git a/drivers/usbdev/adb.c b/drivers/usbdev/adb.c
index b10bba5203..d0fa562daf 100644
--- a/drivers/usbdev/adb.c
+++ b/drivers/usbdev/adb.c
@@ -1929,18 +1929,29 @@ static void adb_char_on_connect(FAR struct usbdev_adb_s 
*priv, int connect)
  *   Initialize the Android Debug Bridge USB device driver.
  *
  * Returned Value:
- *   0 on success, -errno on failure
+ *   A non-NULL "handle" is returned on success.
  *
  ****************************************************************************/
 
-int usbdev_adb_initialize(void)
+FAR void *usbdev_adb_initialize(void)
 {
   struct composite_devdesc_s devdesc;
-  FAR void *cdev;
 
   usbdev_adb_get_composite_devdesc(&devdesc);
-  cdev = composite_initialize(1, &devdesc);
-  return cdev != NULL ? OK : -EINVAL;
+  return composite_initialize(1, &devdesc);
+}
+
+/****************************************************************************
+ * Name: usbdev_adb_uninitialize
+ *
+ * Description:
+ *   Uninitialize the Android Debug Bridge USB device driver.
+ *
+ ****************************************************************************/
+
+void usbdev_adb_uninitialize(FAR void *handle)
+{
+  composite_uninitialize(handle);
 }
 
 /****************************************************************************
diff --git a/include/nuttx/usb/adb.h b/include/nuttx/usb/adb.h
index a38f812e18..73294d6868 100644
--- a/include/nuttx/usb/adb.h
+++ b/include/nuttx/usb/adb.h
@@ -61,11 +61,21 @@ extern "C"
  *   Initialize the Android Debug Bridge USB device driver.
  *
  * Returned Value:
- *   0 on success, -errno on failure
+ *   A non-NULL "handle" is returned on success.
  *
  ****************************************************************************/
 
-int usbdev_adb_initialize(void);
+FAR void *usbdev_adb_initialize(void);
+
+/****************************************************************************
+ * Name: usbdev_adb_uninitialize
+ *
+ * Description:
+ *   Uninitialize the Android Debug Bridge USB device driver.
+ *
+ ****************************************************************************/
+
+void usbdev_adb_uninitialize(FAR void *handle);
 
 /****************************************************************************
  * Name: usbdev_adb_get_composite_devdesc
diff --git a/include/sys/boardctl.h b/include/sys/boardctl.h
index 6fd41b209f..9e70770091 100644
--- a/include/sys/boardctl.h
+++ b/include/sys/boardctl.h
@@ -331,6 +331,9 @@ struct boardioc_builtin_s
 enum boardioc_usbdev_identifier_e
 {
   BOARDIOC_USBDEV_NONE = 0        /* Not valid */
+#ifdef CONFIG_USBADB
+  , BOARDIOC_USBDEV_ADB           /* ADB */
+#endif
 #ifdef CONFIG_CDCACM
   , BOARDIOC_USBDEV_CDCACM        /* CDC/ACM */
 #endif

Reply via email to