You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2020/05/18 09:35:53 UTC

[mynewt-core] 01/07: Add package to handle USB stack from tinyusb project

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

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 63a182fcce03731fea4562a454d991c6cf698d7c
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Apr 30 13:38:41 2020 +0200

    Add package to handle USB stack from tinyusb project
    
    This package adds task that will handle USB stack.
    USB task code is provided by tinyusb project
    that must be present in project.yml.
---
 hw/usb/tinyusb/README.md                 | 36 ++++++++++++++++++
 hw/usb/tinyusb/include/tinyusb/tinyusb.h | 33 ++++++++++++++++
 hw/usb/tinyusb/pkg.yml                   | 40 ++++++++++++++++++++
 hw/usb/tinyusb/src/tinyusb.c             | 65 ++++++++++++++++++++++++++++++++
 hw/usb/tinyusb/syscfg.yml                | 36 ++++++++++++++++++
 5 files changed, 210 insertions(+)

diff --git a/hw/usb/tinyusb/README.md b/hw/usb/tinyusb/README.md
new file mode 100644
index 0000000..9c4d160
--- /dev/null
+++ b/hw/usb/tinyusb/README.md
@@ -0,0 +1,36 @@
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+-->
+
+To use tinyusb add following lines to **project.yml**.
+
+```yaml
+repository.tinyusb:
+    type: github
+    vers: 0.0.0
+    user: hathach
+    repo: tinyusb
+```
+
+This dependency will start USB stack task.
+```yaml
+pkg.deps:
+    - "@apache-mynewt-core/hw/usb/tinyusb"
+```
diff --git a/hw/usb/tinyusb/include/tinyusb/tinyusb.h b/hw/usb/tinyusb/include/tinyusb/tinyusb.h
new file mode 100755
index 0000000..2a900ff
--- /dev/null
+++ b/hw/usb/tinyusb/include/tinyusb/tinyusb.h
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __TINYUSB_H__
+#define __TINYUSB_H__
+
+/**
+ * Init USB hardware.
+ */
+void tinyusb_hardware_init(void);
+
+/**
+ * Start USB stack
+ */
+void tinyusb_start(void);
+
+#endif /* __TINYUSB_H__ */
diff --git a/hw/usb/tinyusb/pkg.yml b/hw/usb/tinyusb/pkg.yml
new file mode 100644
index 0000000..2ff9a3f
--- /dev/null
+++ b/hw/usb/tinyusb/pkg.yml
@@ -0,0 +1,40 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: hw/usb/tinyusb
+pkg.description: >
+    Package provides task for TinyUSB.
+    This package requires API TINYUSB_HW_INIT that will
+    provide function tinyusb_hardware_init().
+
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - usb
+    - tinyusb
+
+pkg.deps:
+    - "@apache-mynewt-core/kernel/os"
+    - "@tinyusb/tinyusb"
+
+pkg.init:
+    tinyusb_start: 'MYNEWT_VAL(USBD_SYSINIT_STAGE)'
+
+pkg.req_apis:
+    - TINYUSB_HW_INIT
diff --git a/hw/usb/tinyusb/src/tinyusb.c b/hw/usb/tinyusb/src/tinyusb.c
new file mode 100755
index 0000000..a05a135
--- /dev/null
+++ b/hw/usb/tinyusb/src/tinyusb.c
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include <os/mynewt.h>
+#include <device/usbd.h>
+
+#include <tusb.h>
+
+#include <tinyusb/tinyusb.h>
+
+#define USBD_STACK_SIZE     MYNEWT_VAL(USBD_STACK_SIZE)
+#define USBD_TASK_PRIORITY  MYNEWT_VAL(USBD_TASK_PRIORITY)
+
+static struct os_task usbd_task;
+static os_stack_t usbd_stack[OS_STACK_ALIGN(USBD_STACK_SIZE)];
+
+/**
+ * USB Device Driver task
+ * This top level thread process all usb events and invoke callbacks
+ */
+static void
+tinyusb_device_task(void *param)
+{
+    (void)param;
+
+    while (1) {
+        tud_task();
+    }
+}
+
+void
+tinyusb_start(void)
+{
+    /**
+     * Note:
+     * Interrupt initialization.
+     * It would be nice to have this present in tinyusb repository since this duplicates code
+     * present in bsp initialization there.
+     */
+    tinyusb_hardware_init();
+
+    /* USB stack initialization */
+    tusb_init();
+
+    /* Create a task for tinyusb device stack */
+    os_task_init(&usbd_task, "usbd", tinyusb_device_task, NULL, USBD_TASK_PRIORITY,
+                 OS_WAIT_FOREVER, usbd_stack, USBD_STACK_SIZE);
+}
diff --git a/hw/usb/tinyusb/syscfg.yml b/hw/usb/tinyusb/syscfg.yml
new file mode 100644
index 0000000..726f90c
--- /dev/null
+++ b/hw/usb/tinyusb/syscfg.yml
@@ -0,0 +1,36 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.defs:
+    TINYUSB:
+        description: Constant value
+        value: 1
+
+    USBD_TASK_PRIORITY:
+        description: >
+            USBD task priority
+        value: 'OS_TASK_PRI_HIGHEST + 2'
+    USBD_STACK_SIZE:
+        description: >
+            Stack size for usbd task
+        value: 150
+    USBD_SYSINIT_STAGE:
+        description: >
+            Sysinit stage for USB device functionality.
+        value: 500