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

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

commit bcd721b6276ecdf3d25416248facf115054a7882
Author: raiden00pl <[email protected]>
AuthorDate: Tue Feb 7 14:14:56 2023 +0100

    examples/nxscope: add support for CDCACM dev
---
 examples/nxscope/Kconfig        |  5 ++++
 examples/nxscope/nxscope_main.c | 53 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/examples/nxscope/Kconfig b/examples/nxscope/Kconfig
index 94e39b3bd..17f3b5a92 100644
--- a/examples/nxscope/Kconfig
+++ b/examples/nxscope/Kconfig
@@ -34,6 +34,11 @@ config EXAMPLES_NXSCOPE_SERIAL_BAUD
        int "nxscope serial baud"
        default 115200
 
+config EXAMPLES_NXSCOPE_CDCACM
+       bool "nxscope CDCACM device support"
+       depends on CDCACM
+       default n
+
 endif # LOGGING_NXSCOPE_INTF_SERIAL
 
 config EXAMPLES_NXSCOPE_FORCE_ENABLE
diff --git a/examples/nxscope/nxscope_main.c b/examples/nxscope/nxscope_main.c
index 0d1ff0323..b7eab4a55 100644
--- a/examples/nxscope/nxscope_main.c
+++ b/examples/nxscope/nxscope_main.c
@@ -24,6 +24,8 @@
 
 #include <nuttx/config.h>
 
+#include <sys/boardctl.h>
+
 #include <assert.h>
 #include <pthread.h>
 #include <stdio.h>
@@ -237,6 +239,34 @@ static FAR void *nxscope_crichan_thr(FAR void *arg)
 }
 #endif
 
+#ifdef CONFIG_EXAMPLES_NXSCOPE_CDCACM
+/****************************************************************************
+ * Name: nxscope_cdcacm_init
+ ****************************************************************************/
+
+static int nxscope_cdcacm_init(void)
+{
+  struct boardioc_usbdev_ctrl_s  ctrl;
+  FAR void                      *handle;
+  int                            ret = OK;
+
+  ctrl.usbdev   = BOARDIOC_USBDEV_CDCACM;
+  ctrl.action   = BOARDIOC_USBDEV_CONNECT;
+  ctrl.instance = 0;
+  ctrl.handle   = &handle;
+
+  ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
+  if (ret < 0)
+    {
+      printf("ERROR: BOARDIOC_USBDEV_CONTROL failed %d\n", ret);
+      goto errout;
+    }
+
+errout:
+  return ret;
+}
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -263,6 +293,29 @@ int main(int argc, FAR char *argv[])
   struct nxscope_dummy_cfg_s  nxs_dummy_cfg;
 #endif
 
+#ifndef CONFIG_NSH_ARCHINIT
+  /* Perform architecture-specific initialization (if configured) */
+
+  boardctl(BOARDIOC_INIT, 0);
+
+#  ifdef CONFIG_BOARDCTL_FINALINIT
+  /* Perform architecture-specific final-initialization (if configured) */
+
+  boardctl(BOARDIOC_FINALINIT, 0);
+#  endif
+#endif
+
+#ifdef CONFIG_EXAMPLES_NXSCOPE_CDCACM
+  /* Initialize the USB CDCACM device */
+
+  ret = nxscope_cdcacm_init();
+  if (ret < 0)
+    {
+      printf("ERROR: nxscope_cdcacm_init failed %d\n", ret);
+      goto errout_noproto;
+    }
+#endif
+
   /* Default serial protocol */
 
   ret = nxscope_proto_ser_init(&proto, NULL);

Reply via email to