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:52 UTC

[mynewt-core] branch master updated (71bc0c3 -> 88d9df7)

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

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


    from 71bc0c3  Merge pull request #2144 from nkaje/HWID_BLE
     new 63a182f  Add package to handle USB stack from tinyusb project
     new 532734c  tinyusb: Add hardware initialization for NRF5x
     new 4012a75  tinyusb: Add hardware initialization for STM32F1xx
     new fb9576c  tinyusb: Add hardware initialization for STM32F4xx STM32L4xx
     new 371c3d0  tinyusb: Add package for standard descriptors CDC,HID
     new d2b4b3c  console: Add console over USB CDC
     new 88d9df7  Update LICENSE file with TinyUSB content

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 LICENSE                                            |   4 +
 {sys/console => hw/usb/tinyusb}/README.md          |  42 +++-
 .../usb/tinyusb/cdc_console}/pkg.yml               |  11 +-
 hw/usb/tinyusb/cdc_console/src/cdc_console.c       | 147 ++++++++++++
 .../usb/tinyusb/cdc_console}/syscfg.yml            |  10 +-
 .../usb/tinyusb/include/tinyusb/tinyusb.h          |  26 +-
 hw/usb/tinyusb/nrf5x/include/tusb_hw.h             |  75 ++++++
 hw/{drivers/lora => usb/tinyusb/nrf5x}/pkg.yml     |  11 +-
 hw/usb/tinyusb/nrf5x/src/nrf5x.c                   |  98 ++++++++
 {sys/shell => hw/usb/tinyusb}/pkg.yml              |  36 +--
 hw/usb/tinyusb/src/tinyusb.c                       |  65 +++++
 .../tinyusb/std_descriptors/include/tusb_config.h  |  91 +++++++
 .../usb/tinyusb/std_descriptors}/pkg.yml           |  10 +-
 .../tinyusb/std_descriptors/src/std_descriptors.c  | 261 +++++++++++++++++++++
 hw/usb/tinyusb/std_descriptors/syscfg.yml          | 121 ++++++++++
 hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h       |  75 ++++++
 .../lora => usb/tinyusb/stm32_fsdev}/pkg.yml       |  11 +-
 hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c       |  66 ++++++
 .../usb/tinyusb/stm32_fsdev}/syscfg.yml            |  11 +-
 hw/usb/tinyusb/synopsys/include/tusb_hw.h          |  79 +++++++
 hw/{drivers/lora => usb/tinyusb/synopsys}/pkg.yml  |  11 +-
 hw/usb/tinyusb/synopsys/src/synopsys.c             |  71 ++++++
 .../tinyusb/synopsys}/syscfg.yml                   |  23 +-
 {mgmt/oicmgr => hw/usb/tinyusb}/syscfg.yml         |  32 +--
 sys/console/full/pkg.yml                           |   2 +
 sys/console/full/syscfg.yml                        |   3 +
 26 files changed, 1301 insertions(+), 91 deletions(-)
 copy {sys/console => hw/usb/tinyusb}/README.md (53%)
 copy {sys/console/full/history_log => hw/usb/tinyusb/cdc_console}/pkg.yml (80%)
 mode change 100644 => 100755
 create mode 100755 hw/usb/tinyusb/cdc_console/src/cdc_console.c
 copy {apps/hash_test => hw/usb/tinyusb/cdc_console}/syscfg.yml (84%)
 mode change 100644 => 100755
 copy apps/ocf_sample/src/ocf_sample.h => hw/usb/tinyusb/include/tinyusb/tinyusb.h (81%)
 mode change 100644 => 100755
 create mode 100755 hw/usb/tinyusb/nrf5x/include/tusb_hw.h
 copy hw/{drivers/lora => usb/tinyusb/nrf5x}/pkg.yml (85%)
 create mode 100755 hw/usb/tinyusb/nrf5x/src/nrf5x.c
 copy {sys/shell => hw/usb/tinyusb}/pkg.yml (57%)
 create mode 100755 hw/usb/tinyusb/src/tinyusb.c
 create mode 100755 hw/usb/tinyusb/std_descriptors/include/tusb_config.h
 copy {sys/sysdown => hw/usb/tinyusb/std_descriptors}/pkg.yml (83%)
 create mode 100755 hw/usb/tinyusb/std_descriptors/src/std_descriptors.c
 create mode 100644 hw/usb/tinyusb/std_descriptors/syscfg.yml
 create mode 100755 hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
 copy hw/{drivers/lora => usb/tinyusb/stm32_fsdev}/pkg.yml (84%)
 create mode 100755 hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c
 copy {apps/loraping => hw/usb/tinyusb/stm32_fsdev}/syscfg.yml (79%)
 create mode 100755 hw/usb/tinyusb/synopsys/include/tusb_hw.h
 copy hw/{drivers/lora => usb/tinyusb/synopsys}/pkg.yml (84%)
 create mode 100755 hw/usb/tinyusb/synopsys/src/synopsys.c
 copy hw/{charge-control => usb/tinyusb/synopsys}/syscfg.yml (61%)
 copy {mgmt/oicmgr => hw/usb/tinyusb}/syscfg.yml (64%)


[mynewt-core] 03/07: tinyusb: Add hardware initialization for STM32F1xx

Posted by je...@apache.org.
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 4012a75cc1bc349519b50ae924de971bd7df7cdc
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Apr 30 14:15:34 2020 +0200

    tinyusb: Add hardware initialization for STM32F1xx
    
    This provides code for hardware initialization.
    Part of this initialization is present in tinyusb bsps which
    are not used by mynewt since it has own bsps.
---
 hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h | 25 +++++++++++
 hw/usb/tinyusb/stm32_fsdev/pkg.yml           | 33 ++++++++++++++
 hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c | 66 ++++++++++++++++++++++++++++
 hw/usb/tinyusb/stm32_fsdev/syscfg.yml        | 27 ++++++++++++
 4 files changed, 151 insertions(+)

diff --git a/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h b/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
new file mode 100755
index 0000000..e8cbe2a
--- /dev/null
+++ b/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
@@ -0,0 +1,25 @@
+/*
+ * 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 __TUSB_HW_H__
+#define __TUSB_HW_H__
+
+#define CFG_TUSB_MCU OPT_MCU_STM32F1
+
+#endif
diff --git a/hw/usb/tinyusb/stm32_fsdev/pkg.yml b/hw/usb/tinyusb/stm32_fsdev/pkg.yml
new file mode 100644
index 0000000..25372e5
--- /dev/null
+++ b/hw/usb/tinyusb/stm32_fsdev/pkg.yml
@@ -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.
+#
+
+pkg.name: hw/usb/tinyusb/stm32_fsdev
+pkg.description: Hardware initialization for TinyUSB
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - usb
+    - tinyusb
+
+pkg.apis:
+    - TINYUSB_HW_INIT
+
+pkg.deps:
+    - "@apache-mynewt-core/kernel/os"
+    - "@tinyusb/tinyusb"
diff --git a/hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c b/hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c
new file mode 100755
index 0000000..a0f82af
--- /dev/null
+++ b/hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c
@@ -0,0 +1,66 @@
+/*
+ * 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 <mcu/mcu.h>
+
+#include <tusb.h>
+
+#include <mcu/stm32f1_bsp.h>
+#include <mcu/stm32f1xx_mynewt_hal.h>
+#include <bsp/stm32f1xx_hal_conf.h>
+
+static void
+USB_IRQHandler(void)
+{
+    tud_int_handler(0);
+}
+
+void
+tinyusb_hardware_init(void)
+{
+    /* TinyUSB provides interrupt handler, here it is setup the mynewt way */
+    NVIC_SetVector(USB_HP_CAN1_TX_IRQn, (uint32_t)USB_IRQHandler);
+    NVIC_SetPriority(USB_HP_CAN1_TX_IRQn, 2);
+    NVIC_SetVector(USB_LP_CAN1_RX0_IRQn, (uint32_t)USB_IRQHandler);
+    NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 2);
+    NVIC_SetVector(USBWakeUp_IRQn, (uint32_t)USB_IRQHandler);
+    NVIC_SetPriority(USBWakeUp_IRQn, 2);
+
+    /*
+     * USB Pin Init
+     * PA11- DM, PA12- DP
+     */
+    hal_gpio_init_af(MCU_GPIO_PORTA(11), 0, GPIO_NOPULL, GPIO_MODE_AF_PP);
+
+    /*
+     * Device needs external PULLUP, following two lines change DP to 0 for a while
+     * to indicated device connection.
+     */
+#if MYNEWT_VAL(USB_DP_HAS_EXTERNAL_PULL_UP)
+    hal_gpio_init_out(MCU_GPIO_PORTA(12), 0);
+    os_time_delay(1);
+#endif
+    hal_gpio_init_af(MCU_GPIO_PORTA(12), 0, GPIO_NOPULL, GPIO_MODE_AF_PP);
+
+    /*
+     * Enable USB clock
+     */
+    __HAL_RCC_USB_CLK_ENABLE();
+}
diff --git a/hw/usb/tinyusb/stm32_fsdev/syscfg.yml b/hw/usb/tinyusb/stm32_fsdev/syscfg.yml
new file mode 100644
index 0000000..37f2fbe
--- /dev/null
+++ b/hw/usb/tinyusb/stm32_fsdev/syscfg.yml
@@ -0,0 +1,27 @@
+#
+# 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:
+    USB_DP_HAS_EXTERNAL_PULL_UP:
+        description: >
+            Set this to 1 if hardware has external pull up resistor.
+            Setting this changes DP pin to 0 at startup for a fraction
+            then device is discovered by host.
+        value: 1
+


[mynewt-core] 04/07: tinyusb: Add hardware initialization for STM32F4xx STM32L4xx

Posted by je...@apache.org.
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 fb9576ca090399a50a5b3794cc97e428b2f10674
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Apr 30 14:22:49 2020 +0200

    tinyusb: Add hardware initialization for STM32F4xx STM32L4xx
    
    This provides code for hardware initialization.
    Part of this initialization is present in tinyusb bsps which
    are not used by mynewt since it has own bsps.
---
 hw/usb/tinyusb/synopsys/include/tusb_hw.h | 31 ++++++++++++++
 hw/usb/tinyusb/synopsys/pkg.yml           | 33 ++++++++++++++
 hw/usb/tinyusb/synopsys/src/synopsys.c    | 71 +++++++++++++++++++++++++++++++
 hw/usb/tinyusb/synopsys/syscfg.yml        | 33 ++++++++++++++
 4 files changed, 168 insertions(+)

diff --git a/hw/usb/tinyusb/synopsys/include/tusb_hw.h b/hw/usb/tinyusb/synopsys/include/tusb_hw.h
new file mode 100755
index 0000000..fe1dd71
--- /dev/null
+++ b/hw/usb/tinyusb/synopsys/include/tusb_hw.h
@@ -0,0 +1,31 @@
+/*
+ * 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 __TUSB_HW_H__
+#define __TUSB_HW_H__
+
+#include <syscfg/syscfg.h>
+
+#if MYNEWT_VAL(MCU_STM32F4)
+#define CFG_TUSB_MCU OPT_MCU_STM32F4
+#elif MYNEWT_VAL(MCU_STM32L4)
+#define CFG_TUSB_MCU OPT_MCU_STM32L4
+#endif
+
+#endif
diff --git a/hw/usb/tinyusb/synopsys/pkg.yml b/hw/usb/tinyusb/synopsys/pkg.yml
new file mode 100644
index 0000000..0ef48f9
--- /dev/null
+++ b/hw/usb/tinyusb/synopsys/pkg.yml
@@ -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.
+#
+
+pkg.name: hw/usb/tinyusb/synopsys
+pkg.description: Hardware initialization for TinyUSB
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - usb
+    - tinyusb
+
+pkg.apis:
+    - TINYUSB_HW_INIT
+
+pkg.deps:
+    - "@apache-mynewt-core/kernel/os"
+    - "@tinyusb/tinyusb"
diff --git a/hw/usb/tinyusb/synopsys/src/synopsys.c b/hw/usb/tinyusb/synopsys/src/synopsys.c
new file mode 100755
index 0000000..2300c10
--- /dev/null
+++ b/hw/usb/tinyusb/synopsys/src/synopsys.c
@@ -0,0 +1,71 @@
+/*
+ * 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 <mcu/mcu.h>
+
+#include <tusb.h>
+
+#include <mcu/stm32_hal.h>
+
+static void
+OTG_FS_IRQHandler(void)
+{
+    /* TinyUSB provides interrupt handler code */
+    tud_int_handler(0);
+}
+
+void
+tinyusb_hardware_init(void)
+{
+    NVIC_SetVector(OTG_FS_IRQn, (uint32_t)OTG_FS_IRQHandler);
+    NVIC_SetPriority(OTG_FS_IRQn, 2);
+
+    /*
+     * USB Pin Init
+     * PA11- DM, PA12- DP
+     */
+    hal_gpio_init_af(MCU_GPIO_PORTA(11), GPIO_AF10_OTG_FS, GPIO_NOPULL, GPIO_MODE_AF_PP);
+#if MYNEWT_VAL(USB_DP_HAS_EXTERNAL_PULL_UP)
+    hal_gpio_init_out(MCU_GPIO_PORTA(12), 0);
+    os_time_delay(1);
+#endif
+    hal_gpio_init_af(MCU_GPIO_PORTA(12), GPIO_AF10_OTG_FS, GPIO_NOPULL, GPIO_MODE_AF_PP);
+
+    /*
+     * Enable USB OTG clock, force device mode
+     */
+    __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
+    USB_OTG_FS->GUSBCFG &= ~USB_OTG_GUSBCFG_FHMOD;
+    USB_OTG_FS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD;
+
+#ifdef USB_OTG_GCCFG_NOVBUSSENS
+#if !MYNEWT_VAL(USB_VBUS_DETECTION_ENABLE)
+    /* PA9- VUSB not used for USB */
+    USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
+    USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
+    USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
+#else
+    USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
+    USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
+    USB_OTG_FS->GCCFG |= ~USB_OTG_GCCFG_VBUSASEN;
+    hal_gpio_init_af(MCU_GPIO_PORTA(9), GPIO_AF10_OTG_FS, GPIO_NOPULL, GPIO_MODE_AF_PP);
+#endif
+#endif
+}
diff --git a/hw/usb/tinyusb/synopsys/syscfg.yml b/hw/usb/tinyusb/synopsys/syscfg.yml
new file mode 100644
index 0000000..5718df3
--- /dev/null
+++ b/hw/usb/tinyusb/synopsys/syscfg.yml
@@ -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.
+#
+
+syscfg.defs:
+    USB_DP_HAS_EXTERNAL_PULL_UP:
+        description: >
+            Set this to 1 if hardware has external pull up resistor.
+            Synopsys does have internal pull up that allows to re-enumarate
+            without physical disconnection, but it will not work when
+            external pull up is present (like on on black_vet6 board).
+            Setting this changes pin to GPIO 0 at startup for a fraction
+            then device is discovered by host.
+        value: 0
+    USB_VBUS_DETECTION_ENABLE:
+        description:
+            Set to 1 when PA9 is connected to detect VBus.
+        value: 0


[mynewt-core] 02/07: tinyusb: Add hardware initialization for NRF5x

Posted by je...@apache.org.
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 532734cc8181ff036f8938ff8d8e94998288bc02
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Apr 30 14:01:56 2020 +0200

    tinyusb: Add hardware initialization for NRF5x
    
    This provides code for hardware initialization.
    Part of this initialization is present in tinyusb bsps which
    are not used by mynewt since it has own bsps.
---
 hw/usb/tinyusb/nrf5x/include/tusb_hw.h | 25 +++++++++
 hw/usb/tinyusb/nrf5x/pkg.yml           | 33 ++++++++++++
 hw/usb/tinyusb/nrf5x/src/nrf5x.c       | 98 ++++++++++++++++++++++++++++++++++
 3 files changed, 156 insertions(+)

diff --git a/hw/usb/tinyusb/nrf5x/include/tusb_hw.h b/hw/usb/tinyusb/nrf5x/include/tusb_hw.h
new file mode 100755
index 0000000..c3a280f
--- /dev/null
+++ b/hw/usb/tinyusb/nrf5x/include/tusb_hw.h
@@ -0,0 +1,25 @@
+/*
+ * 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 __TUSB_HW_H__
+#define __TUSB_HW_H__
+
+#define CFG_TUSB_MCU OPT_MCU_NRF5X
+
+#endif
diff --git a/hw/usb/tinyusb/nrf5x/pkg.yml b/hw/usb/tinyusb/nrf5x/pkg.yml
new file mode 100644
index 0000000..a8c08af
--- /dev/null
+++ b/hw/usb/tinyusb/nrf5x/pkg.yml
@@ -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.
+#
+
+pkg.name: hw/usb/tinyusb/nrf5x
+pkg.description: Hardware initialization for Tinyusb
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - usb
+    - tinyusb
+
+pkg.apis:
+    - TINYUSB_HW_INIT
+
+pkg.deps:
+    - "@apache-mynewt-core/kernel/os"
+    - "@tinyusb/tinyusb"
diff --git a/hw/usb/tinyusb/nrf5x/src/nrf5x.c b/hw/usb/tinyusb/nrf5x/src/nrf5x.c
new file mode 100755
index 0000000..03d0545
--- /dev/null
+++ b/hw/usb/tinyusb/nrf5x/src/nrf5x.c
@@ -0,0 +1,98 @@
+/*
+ * 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 <mcu/mcu.h>
+
+#include <device/usbd.h>
+#include <tusb.h>
+#include <nrfx/hal/nrf_power.h>
+
+/* same value as NRFX_POWER_USB_EVT_* in nrfx_power */
+enum {
+    USB_EVT_DETECTED = 0,
+    USB_EVT_REMOVED = 1,
+    USB_EVT_READY = 2
+};
+
+/**
+ * tinyusb function that handles power event (0: detected, 1: remove, 2: ready)
+ * We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.
+ */
+extern void tusb_hal_nrf_power_event(uint32_t event);
+
+static void
+USBD_IRQHandler(void)
+{
+    tud_int_handler(0);
+}
+
+/* Power ISR to detect USB VBUS state */
+static void
+POWER_CLOCK_IRQHandler(void)
+{
+    uint32_t enabled = nrf_power_int_enable_get(NRF_POWER);
+
+    if ((0 != (enabled & NRF_POWER_INT_USBDETECTED_MASK)) &&
+        nrf_power_event_get_and_clear(NRF_POWER,NRF_POWER_EVENT_USBDETECTED)) {
+        tusb_hal_nrf_power_event(USB_EVT_DETECTED);
+    }
+
+    if ((0 != (enabled & NRF_POWER_INT_USBREMOVED_MASK)) &&
+        nrf_power_event_get_and_clear(NRF_POWER,NRF_POWER_EVENT_USBREMOVED)) {
+        tusb_hal_nrf_power_event(USB_EVT_REMOVED);
+    }
+
+    if ((0 != (enabled & NRF_POWER_INT_USBPWRRDY_MASK)) &&
+        nrf_power_event_get_and_clear(NRF_POWER, NRF_POWER_EVENT_USBPWRRDY)) {
+        tusb_hal_nrf_power_event(USB_EVT_READY);
+    }
+}
+
+void
+tinyusb_hardware_init(void)
+{
+    /* Setup USB IRQ */
+    NVIC_SetVector(USBD_IRQn, (uint32_t)USBD_IRQHandler);
+    NVIC_SetPriority(USBD_IRQn, 2);
+
+    /* Setup Power IRQ to detect USB VBUS state ( detected, ready, removed) */
+    NVIC_SetVector(POWER_CLOCK_IRQn, (uint32_t)POWER_CLOCK_IRQHandler);
+    NVIC_SetPriority(POWER_CLOCK_IRQn, 7);
+    nrf_power_int_enable(NRF_POWER,
+                         NRF_POWER_INT_USBDETECTED_MASK |
+                         NRF_POWER_INT_USBREMOVED_MASK  |
+                         NRF_POWER_INT_USBPWRRDY_MASK);
+
+    NVIC_EnableIRQ(POWER_CLOCK_IRQn);
+
+    /*
+     * USB power may already be ready at this time -> no event generated
+     * We need to invoke the handler based on the status initially
+     */
+    uint32_t usb_reg = NRF_POWER->USBREGSTATUS;
+
+    if (usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk) {
+        tusb_hal_nrf_power_event(USB_EVT_DETECTED);
+    }
+
+    if (usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk) {
+        tusb_hal_nrf_power_event(USB_EVT_READY);
+    }
+}


[mynewt-core] 07/07: Update LICENSE file with TinyUSB content

Posted by je...@apache.org.
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 88d9df7090973ed0be6638a73932c3545b8d3ba9
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Mon May 11 15:50:23 2020 +0200

    Update LICENSE file with TinyUSB content
    
    Some file content was taken from TinyUSB examples which
    have MIT license.
---
 LICENSE | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/LICENSE b/LICENSE
index 9320abb..22fdb84 100644
--- a/LICENSE
+++ b/LICENSE
@@ -683,3 +683,7 @@ under the "3-clause BSD" license. For details, see:
 This product bundles part of DA1469 SDK by Dialog Semiconductor which is
 available under the "3-clause BSD" license. Bundled files are:
     * hw/mcu/dialog/include/DA1469xAB.h
+
+This product bundles part of tinyusb which is available under the MIT license. Bundled files are:
+    * hw/usb/tinyusb/std_descriptors/include/tusb_config.h
+    * hw/usb/tinyusb/std_descriptors/src/std_descriptors.c


[mynewt-core] 05/07: tinyusb: Add package for standard descriptors CDC, HID

Posted by je...@apache.org.
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 371c3d0556c7e7b1a38a6c6a1e7f7fb2ee04680d
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Apr 30 14:57:53 2020 +0200

    tinyusb: Add package for standard descriptors CDC,HID
---
 hw/usb/tinyusb/README.md                           |  12 +
 hw/usb/tinyusb/nrf5x/include/tusb_hw.h             |  50 ++++
 hw/usb/tinyusb/pkg.yml                             |  11 +
 .../tinyusb/std_descriptors/include/tusb_config.h  |  91 +++++++
 hw/usb/tinyusb/{ => std_descriptors}/pkg.yml       |  21 +-
 .../tinyusb/std_descriptors/src/std_descriptors.c  | 261 +++++++++++++++++++++
 hw/usb/tinyusb/std_descriptors/syscfg.yml          | 121 ++++++++++
 hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h       |  50 ++++
 hw/usb/tinyusb/synopsys/include/tusb_hw.h          |  48 ++++
 hw/usb/tinyusb/syscfg.yml                          |   5 +
 10 files changed, 656 insertions(+), 14 deletions(-)

diff --git a/hw/usb/tinyusb/README.md b/hw/usb/tinyusb/README.md
index 9c4d160..5142326 100644
--- a/hw/usb/tinyusb/README.md
+++ b/hw/usb/tinyusb/README.md
@@ -34,3 +34,15 @@ This dependency will start USB stack task.
 pkg.deps:
     - "@apache-mynewt-core/hw/usb/tinyusb"
 ```
+
+To easy add support for CDC or HID class device simply add
+**hw/usb/tinyusb/std_descriptors** package to project
+```yaml
+pkg.deps:
+    - "@apache-mynewt-core/hw/usb/tinyusb/std_descriptors"
+```
+Vendor and product ID must be specified in **syscfg.vals:** section
+```yaml
+    USBD_VID: 0xABCD
+    USBD_PID: 0x1234
+```
diff --git a/hw/usb/tinyusb/nrf5x/include/tusb_hw.h b/hw/usb/tinyusb/nrf5x/include/tusb_hw.h
index c3a280f..682e08b 100755
--- a/hw/usb/tinyusb/nrf5x/include/tusb_hw.h
+++ b/hw/usb/tinyusb/nrf5x/include/tusb_hw.h
@@ -22,4 +22,54 @@
 
 #define CFG_TUSB_MCU OPT_MCU_NRF5X
 
+#include <syscfg/syscfg.h>
+
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP)
+#define USBD_CDC_NOTIFY_EP      MYNEWT_VAL(USBD_CDC_NOTIFY_EP)
+#else
+#define USBD_CDC_NOTIFY_EP      0x81
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP_SIZE)
+#define USBD_CDC_NOTIFY_EP_SIZE MYNEWT_VAL(USBD_CDC_NOTIFY_EP_SIZE)
+#else
+#define USBD_CDC_NOTIFY_EP_SIZE 0x08
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_OUT_EP)
+#define USBD_CDC_DATA_OUT_EP    MYNEWT_VAL(USBD_CDC_DATA_OUT_EP)
+#else
+#define USBD_CDC_DATA_OUT_EP    0x02
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_IN_EP)
+#define USBD_CDC_DATA_IN_EP     MYNEWT_VAL(USBD_CDC_DATA_IN_EP)
+#else
+#define USBD_CDC_DATA_IN_EP     0x82
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_EP_SIZE)
+#define USBD_CDC_DATA_EP_SIZE   MYNEWT_VAL(USBD_CDC_DATA_EP_SIZE)
+#else
+#define USBD_CDC_DATA_EP_SIZE   0x40
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP)
+#define USBD_HID_REPORT_EP      MYNEWT_VAL(USBD_HID_REPORT_EP)
+#else
+#define USBD_HID_REPORT_EP      0x83
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_SIZE)
+#define USBD_HID_REPORT_EP_SIZE MYNEWT_VAL(USBD_HID_REPORT_EP_SIZE)
+#else
+#define USBD_HID_REPORT_EP_SIZE 0x10
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_INTERVAL)
+#define USBD_HID_REPORT_EP_INTERVAL MYNEWT_VAL(USBD_HID_REPORT_EP_INTERVAL)
+#else
+#define USBD_HID_REPORT_EP_INTERVAL 10
+#endif
+
 #endif
diff --git a/hw/usb/tinyusb/pkg.yml b/hw/usb/tinyusb/pkg.yml
index 2ff9a3f..aeeaa94 100644
--- a/hw/usb/tinyusb/pkg.yml
+++ b/hw/usb/tinyusb/pkg.yml
@@ -36,5 +36,16 @@ pkg.deps:
 pkg.init:
     tinyusb_start: 'MYNEWT_VAL(USBD_SYSINIT_STAGE)'
 
+pkg.deps.USBD_STD_DESCRIPTORS:
+    - "@apache-mynewt-core/hw/usb/tinyusb/std_descriptors"
+pkg.deps.'MCU_TARGET == "nRF52840"':
+    - "@apache-mynewt-core/hw/usb/tinyusb/nrf5x"
+pkg.deps.MCU_STM32F4:
+    - "@apache-mynewt-core/hw/usb/tinyusb/synopsys"
+pkg.deps.MCU_STM32L4:
+    - "@apache-mynewt-core/hw/usb/tinyusb/synopsys"
+pkg.deps.MCU_STM32F1:
+    - "@apache-mynewt-core/hw/usb/tinyusb/stm32_fsdev"
+
 pkg.req_apis:
     - TINYUSB_HW_INIT
diff --git a/hw/usb/tinyusb/std_descriptors/include/tusb_config.h b/hw/usb/tinyusb/std_descriptors/include/tusb_config.h
new file mode 100755
index 0000000..3a8310d
--- /dev/null
+++ b/hw/usb/tinyusb/std_descriptors/include/tusb_config.h
@@ -0,0 +1,91 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef _TUSB_CONFIG_H_
+#define _TUSB_CONFIG_H_
+
+#include "syscfg/syscfg.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/**
+ * COMMON CONFIGURATION
+ */
+
+#include <tusb_hw.h>
+
+/* defined by compiler flags for flexibility */
+#ifndef CFG_TUSB_MCU
+#error CFG_TUSB_MCU must be defined
+#endif
+
+#define CFG_TUSB_RHPORT0_MODE       OPT_MODE_DEVICE
+
+#define CFG_TUSB_OS                 OPT_OS_MYNEWT
+#define CFG_TUSB_DEBUG              0
+
+/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
+ * Tinyusb use follows macros to declare transferring memory so that they can be put
+ * into those specific section.
+ * e.g
+ * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") ))
+ * - CFG_TUSB_MEM_ALIGN   : __attribute__ ((aligned(4)))
+ */
+#ifndef CFG_TUSB_MEM_SECTION
+#define CFG_TUSB_MEM_SECTION
+#endif
+
+#ifndef CFG_TUSB_MEM_ALIGN
+#define CFG_TUSB_MEM_ALIGN          __attribute__ ((aligned(4)))
+#endif
+
+/**
+ * DEVICE CONFIGURATION
+ */
+#define CFG_TUD_ENDPOINT0_SIZE   MYNEWT_VAL(USBD_EP0_SIZE)
+
+/* ------------- CLASS ------------- */
+#define CFG_TUD_CDC              MYNEWT_VAL(USBD_CDC)
+#define CFG_TUD_HID              MYNEWT_VAL(USBD_HID)
+#define CFG_TUD_MSC              0
+#define CFG_TUD_MIDI             0
+#define CFG_TUD_VENDOR           0
+#define CFG_TUD_USBTMC           0
+#define CFG_TUD_DFU_RT           0
+#define CFG_TUD_NET              0
+
+/*  CDC FIFO size of TX and RX */
+#define CFG_TUD_CDC_RX_BUFSIZE   64
+#define CFG_TUD_CDC_TX_BUFSIZE   64
+
+/* HID buffer size Should be sufficient to hold ID (if any) + Data */
+#define CFG_TUD_HID_BUFSIZE      16
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _TUSB_CONFIG_H_ */
diff --git a/hw/usb/tinyusb/pkg.yml b/hw/usb/tinyusb/std_descriptors/pkg.yml
similarity index 75%
copy from hw/usb/tinyusb/pkg.yml
copy to hw/usb/tinyusb/std_descriptors/pkg.yml
index 2ff9a3f..5a68cda 100644
--- a/hw/usb/tinyusb/pkg.yml
+++ b/hw/usb/tinyusb/std_descriptors/pkg.yml
@@ -6,7 +6,7 @@
 # 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,
@@ -17,24 +17,17 @@
 # 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.name: hw/usb/tinyusb/std_descriptors
+pkg.description: TinyUSB standard descriptor package
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
     - usb
     - tinyusb
+    - CDC
+    - HID
+    - MSC
 
 pkg.deps:
     - "@apache-mynewt-core/kernel/os"
-    - "@tinyusb/tinyusb"
-
-pkg.init:
-    tinyusb_start: 'MYNEWT_VAL(USBD_SYSINIT_STAGE)'
-
-pkg.req_apis:
-    - TINYUSB_HW_INIT
+    - "@apache-mynewt-core/hw/usb/tinyusb"
diff --git a/hw/usb/tinyusb/std_descriptors/src/std_descriptors.c b/hw/usb/tinyusb/std_descriptors/src/std_descriptors.c
new file mode 100755
index 0000000..6825a33
--- /dev/null
+++ b/hw/usb/tinyusb/std_descriptors/src/std_descriptors.c
@@ -0,0 +1,261 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018, hathach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include <syscfg/syscfg.h>
+#include <bsp/bsp.h>
+#include <string.h>
+#include <tusb.h>
+#include <device/usbd.h>
+#include <os/util.h>
+#include <console/console.h>
+#include <hal/hal_gpio.h>
+
+#define USBD_PRODUCT_RELEASE_NUMBER MYNEWT_VAL(USBD_PRODUCT_RELEASE_NUMBER)
+
+#ifndef CONFIG_NUM
+#define CONFIG_NUM 1
+#endif
+
+#define CDC_IF_STR_IX (MYNEWT_VAL(USBD_CDC_DESCRIPTOR_STRING) == NULL ? 0 : 4)
+#define MSC_IF_STR_IX (MYNEWT_VAL(USBD_MSC_DESCRIPTOR_STRING) == NULL ? 0 : 5)
+#define HID_IF_STR_IX (MYNEWT_VAL(USBD_HID_DESCRIPTOR_STRING) == NULL ? 0 : 6)
+
+
+#if CFG_TUD_HID
+
+#if MYNEWT_VAL(USBD_HID_REPORT_ID_KEYBOARD) || MYNEWT_VAL(USBD_HID_REPORT_ID_MOUSE)
+const uint8_t desc_hid_report[] = {
+#if MYNEWT_VAL(USBD_HID_REPORT_ID_KEYBOARD)
+    TUD_HID_REPORT_DESC_KEYBOARD(MYNEWT_VAL(USBD_HID_REPORT_ID_KEYBOARD),),
+#endif
+#if MYNEWT_VAL(USBD_HID_REPORT_ID_MOUSE)
+    TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(REPORT_ID_MOUSE),)
+#endif
+};
+#else
+#error Please specify keybaord and/or mouse report id
+#endif
+
+/*
+ * Invoked when received GET HID REPORT DESCRIPTOR
+ * Application return pointer to descriptor
+ * Descriptor contents must exist long enough for transfer to complete
+ */
+const uint8_t *
+tud_hid_descriptor_report_cb(void)
+{
+    return desc_hid_report;
+}
+
+/*
+ * Invoked when received GET_REPORT control request
+ * Application must fill buffer report's content and return its length.
+ * Return zero will cause the stack to STALL request
+ */
+uint16_t
+tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen)
+{
+    /* TODO: not implemented yet */
+    (void)report_id;
+    (void)report_type;
+    (void)buffer;
+    (void)reqlen;
+
+    return 0;
+}
+
+/*
+ * Invoked when received SET_REPORT control request or
+ * received data on OUT endpoint ( Report ID = 0, Type = 0 )
+ */
+void
+tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, const uint8_t *report, uint16_t report_size)
+{
+    (void)report_id;
+    (void)report_type;
+    (void)report_size;
+    if (MYNEWT_VAL(USBD_HID_CAPS_LOCK_LED_PIN) >= 0) {
+        hal_gpio_write(MYNEWT_VAL(USBD_HID_CAPS_LOCK_LED_PIN),
+                       1 & ((report[0] >> 1) ^ 1u ^ MYNEWT_VAL(USBD_HID_CAPS_LOCK_LED_ON_VALUE)));
+    }
+    if (MYNEWT_VAL(USBD_HID_NUM_LOCK_LED_PIN) >= 0) {
+        hal_gpio_write(MYNEWT_VAL(USBD_HID_NUM_LOCK_LED_PIN),
+                       1 & (report[0] ^ 1u ^ MYNEWT_VAL(USBD_HID_CAPS_LOCK_LED_ON_VALUE)));
+    }
+}
+#endif /* CFG_TUD_HID */
+
+const tusb_desc_device_t desc_device = {
+    .bLength            = sizeof(tusb_desc_device_t),
+    .bDescriptorType    = TUSB_DESC_DEVICE,
+    .bcdUSB             = 0x0200,
+
+#if CFG_TUD_CDC
+    /*
+     * Use Interface Association Descriptor (IAD) for CDC
+     * As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
+     */
+    .bDeviceClass       = TUSB_CLASS_MISC,
+    .bDeviceSubClass    = MISC_SUBCLASS_COMMON,
+    .bDeviceProtocol    = MISC_PROTOCOL_IAD,
+#else
+    .bDeviceClass       = 0x00,
+    .bDeviceSubClass    = 0x00,
+    .bDeviceProtocol    = 0x00,
+#endif
+
+    .bMaxPacketSize0    = CFG_TUD_ENDPOINT0_SIZE,
+
+    .idVendor           = MYNEWT_VAL(USBD_VID),
+    .idProduct          = MYNEWT_VAL(USBD_PID),
+    .bcdDevice          = USBD_PRODUCT_RELEASE_NUMBER,
+
+    .iManufacturer      = 0x02,
+    .iProduct           = 0x03,
+    .iSerialNumber      = 0x01,
+
+    .bNumConfigurations = 0x01
+};
+
+/*
+ * Invoked when received GET DEVICE DESCRIPTOR
+ * Application return pointer to descriptor
+ */
+const uint8_t *
+tud_descriptor_device_cb(void)
+{
+    return (const uint8_t *)&desc_device;
+}
+
+/*
+ * Configuration Descriptor
+ */
+
+enum {
+#if CFG_TUD_CDC
+    ITF_NUM_CDC,
+    ITF_NUM_CDC_DATA,
+#endif
+
+#if CFG_TUD_MSC
+    ITF_NUM_MSC,
+#endif
+
+#if CFG_TUD_HID
+    ITF_NUM_HID,
+#endif
+
+    ITF_NUM_TOTAL
+};
+
+#define CONFIG_TOTAL_LEN    (TUD_CONFIG_DESC_LEN + \
+                             CFG_TUD_CDC * TUD_CDC_DESC_LEN + \
+                             CFG_TUD_MSC * TUD_MSC_DESC_LEN + \
+                             CFG_TUD_HID * TUD_HID_DESC_LEN + \
+                             0)
+
+const uint8_t desc_configuration[] = {
+    TUD_CONFIG_DESCRIPTOR(CONFIG_NUM, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP,
+                          MYNEWT_VAL(USBD_CONFIGURATION_MAX_POWER)),
+
+#if CFG_TUD_CDC
+    TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, CDC_IF_STR_IX, USBD_CDC_NOTIFY_EP, USBD_CDC_NOTIFY_EP_SIZE,
+                       USBD_CDC_DATA_OUT_EP, USBD_CDC_DATA_IN_EP, USBD_CDC_DATA_EP_SIZE),
+#endif
+
+#if CFG_TUD_MSC
+    /* TODO: MSC not handled yet */
+    TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, MSC_IF_STR_IX, EPNUM_MSC_OUT, EPNUM_MSC_IN,
+                       (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED) ? 512 : 64),
+#endif
+
+#if CFG_TUD_HID
+    TUD_HID_DESCRIPTOR(ITF_NUM_HID, HID_IF_STR_IX, HID_PROTOCOL_NONE, sizeof(desc_hid_report),
+                       USBD_HID_REPORT_EP, USBD_HID_REPORT_EP_SIZE, USBD_HID_REPORT_EP_INTERVAL),
+#endif
+};
+
+/**
+ * Invoked when received GET CONFIGURATION DESCRIPTOR
+ * Application return pointer to descriptor
+ * Descriptor contents must exist long enough for transfer to complete
+ */
+const uint8_t *
+tud_descriptor_configuration_cb(uint8_t index)
+{
+    (void)index;
+
+    return desc_configuration;
+}
+
+const char *string_desc_arr[] = {
+    MYNEWT_VAL(USBD_VENDOR_STRING),
+    MYNEWT_VAL(USBD_PRODUCT_STRING),
+    MYNEWT_VAL(USBD_CDC_DESCRIPTOR_STRING),
+    MYNEWT_VAL(USBD_MSC_DESCRIPTOR_STRING),
+    MYNEWT_VAL(USBD_HID_DESCRIPTOR_STRING),
+};
+
+static uint16_t desc_string[MYNEWT_VAL(USBD_STRING_DESCRIPTOR_MAX_LENGTH) + 1];
+
+/*
+ * Invoked when received GET STRING DESCRIPTOR request
+ * Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
+ */
+const uint16_t *
+tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
+    int char_num = 0;
+    int i;
+    const char *str;
+
+    if (index == 0) {
+        desc_string[1] = MYNEWT_VAL(USBD_LANGID);
+        char_num = 1;
+    } else if (index == 1) {
+        /* TODO: Add function call to get serial number */
+        desc_string[1] = '1';
+        char_num = 1;
+    } else if (index - 2 < ARRAY_SIZE(string_desc_arr)) {
+        str = string_desc_arr[index - 2];
+
+        char_num = strlen(str);
+        if (char_num >= ARRAY_SIZE(desc_string)) {
+            char_num = ARRAY_SIZE(desc_string);
+        }
+
+        for (i = 0; i < char_num; ++i) {
+            desc_string[1 + i] = str[i];
+        }
+    }
+
+    if (char_num) {
+        /* Encode length in first byte */
+        desc_string[0] = (TUSB_DESC_STRING << 8) | (2 * char_num + 2);
+        return desc_string;
+    } else {
+        return NULL;
+    }
+}
diff --git a/hw/usb/tinyusb/std_descriptors/syscfg.yml b/hw/usb/tinyusb/std_descriptors/syscfg.yml
new file mode 100644
index 0000000..f313028
--- /dev/null
+++ b/hw/usb/tinyusb/std_descriptors/syscfg.yml
@@ -0,0 +1,121 @@
+#
+# 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:
+    USBD_STRING_DESCRIPTOR_MAX_LENGTH:
+        description: Maximum length of string descriptor in characters
+        value: 31
+    USBD_EP0_SIZE:
+        description: >
+            Endpoint 0 size
+        value: 64
+    USBD_VID:
+        description: Vendor ID
+        value:
+        restrictions:
+            - $notnull
+    USBD_PID:
+        description: Product ID
+        value:
+        restrictions:
+            - $notnull
+    USBD_PRODUCT_RELEASE_NUMBER:
+        description: Product release number needed for USB descriptor
+        value: 0x100
+    USBD_CONFIGURATION_MAX_POWER:
+        description: >
+            Maximum power consumption of the USB device from the bus in this specific
+            configuration when the device is fully operational. Expressed in 2 mA units
+            (i.e., 50 = 100 mA).
+        value: 100
+    USBD_LANGID:
+        description: Language ID as specified by usb.org
+        value: 0x0409
+    USBD_VENDOR_STRING:
+        description: Manufacturer identification string
+        value: '"Vendor string"'
+    USBD_PRODUCT_STRING:
+        description: Device friendly name
+        value: '"Dev device"'
+    USBD_CDC:
+        description: Enable CDC device
+        value: 0
+    USBD_HID:
+        description: Enable HID device
+        value: 0
+    USBD_MSC:
+        description: Enable MSC device
+        value: 0
+
+    USBD_CDC_DATA_OUT_EP:
+        description: CDC data out endpoint number
+        value:
+    USBD_CDC_DATA_IN_EP:
+        description: CDC data out endpoint number
+        value:
+    USBD_CDC_DATA_EP_SIZE:
+        description: CDC data endpoint size
+        value:
+    USBD_CDC_NOTIFY_EP:
+        description: CDC notify endpoint number
+        value:
+    USBD_CDC_NOTIFY_EP_SIZE:
+        description: CDC notify endpoint size
+        value:
+
+    USBD_CDC_DESCRIPTOR_STRING:
+        description: String for CDC interface
+        value: NULL
+
+    USBD_MSC_DESCRIPTOR_STRING:
+        description: String for MSC interface
+        value: NULL
+
+    USBD_HID_DESCRIPTOR_STRING:
+        description: String for HID interface
+        value: NULL
+
+    USBD_HID_REPORT_EP:
+        description: HID report endpoint number
+        value:
+    USBD_HID_REPORT_EP_SIZE:
+        description: HID report endpoint size
+        value:
+    USBD_HID_REPORT_EP_INTERVAL:
+        description: HID report endpoint interval
+        value:
+
+    USBD_HID_REPORT_ID_KEYBOARD:
+        description: HID keyboard report ID
+        value:
+    USBD_HID_CAPS_LOCK_LED_PIN:
+        description: Caps Lock LED
+        value: -1
+    USBD_HID_CAPS_LOCK_LED_ON_VALUE:
+        description: Value to set to pin to turn led on
+        value: 0
+    USBD_HID_NUM_LOCK_LED_PIN:
+        description: Num Lock LED
+        value: -1
+    USBD_HID_NUM_LOCK_LED_ON_VALUE:
+        description: Value to set to pin to turn led on
+        value: 0
+    USBD_HID_REPORT_ID_MOUSE:
+        description: HID keyboard report ID
+        value:
diff --git a/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h b/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
index e8cbe2a..9a4752e 100755
--- a/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
+++ b/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
@@ -22,4 +22,54 @@
 
 #define CFG_TUSB_MCU OPT_MCU_STM32F1
 
+#include <syscfg/syscfg.h>
+
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP)
+#define USBD_CDC_NOTIFY_EP      MYNEWT_VAL(USBD_CDC_NOTIFY_EP)
+#else
+#define USBD_CDC_NOTIFY_EP      0x81
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP_SIZE)
+#define USBD_CDC_NOTIFY_EP_SIZE MYNEWT_VAL(USBD_CDC_NOTIFY_EP_SIZE)
+#else
+#define USBD_CDC_NOTIFY_EP_SIZE 0x08
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_OUT_EP)
+#define USBD_CDC_DATA_OUT_EP    MYNEWT_VAL(USBD_CDC_DATA_OUT_EP)
+#else
+#define USBD_CDC_DATA_OUT_EP    0x01
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_IN_EP)
+#define USBD_CDC_DATA_IN_EP     MYNEWT_VAL(USBD_CDC_DATA_IN_EP)
+#else
+#define USBD_CDC_DATA_IN_EP     0x82
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_EP_SIZE)
+#define USBD_CDC_DATA_EP_SIZE   MYNEWT_VAL(USBD_CDC_DATA_EP_SIZE)
+#else
+#define USBD_CDC_DATA_EP_SIZE   0x40
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP)
+#define USBD_HID_REPORT_EP      MYNEWT_VAL(USBD_HID_REPORT_EP)
+#else
+#define USBD_HID_REPORT_EP      0x83
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_SIZE)
+#define USBD_HID_REPORT_EP_SIZE MYNEWT_VAL(USBD_HID_REPORT_EP_SIZE)
+#else
+#define USBD_HID_REPORT_EP_SIZE 0x10
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_INTERVAL)
+#define USBD_HID_REPORT_EP_INTERVAL MYNEWT_VAL(USBD_HID_REPORT_EP_INTERVAL)
+#else
+#define USBD_HID_REPORT_EP_INTERVAL 10
+#endif
+
 #endif
diff --git a/hw/usb/tinyusb/synopsys/include/tusb_hw.h b/hw/usb/tinyusb/synopsys/include/tusb_hw.h
index fe1dd71..34471fd 100755
--- a/hw/usb/tinyusb/synopsys/include/tusb_hw.h
+++ b/hw/usb/tinyusb/synopsys/include/tusb_hw.h
@@ -28,4 +28,52 @@
 #define CFG_TUSB_MCU OPT_MCU_STM32L4
 #endif
 
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP)
+#define USBD_CDC_NOTIFY_EP      MYNEWT_VAL(USBD_CDC_NOTIFY_EP)
+#else
+#define USBD_CDC_NOTIFY_EP      0x81
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP_SIZE)
+#define USBD_CDC_NOTIFY_EP_SIZE MYNEWT_VAL(USBD_CDC_NOTIFY_EP_SIZE)
+#else
+#define USBD_CDC_NOTIFY_EP_SIZE 0x08
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_OUT_EP)
+#define USBD_CDC_DATA_OUT_EP    MYNEWT_VAL(USBD_CDC_DATA_OUT_EP)
+#else
+#define USBD_CDC_DATA_OUT_EP    0x01
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_IN_EP)
+#define USBD_CDC_DATA_IN_EP     MYNEWT_VAL(USBD_CDC_DATA_IN_EP)
+#else
+#define USBD_CDC_DATA_IN_EP     0x82
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_EP_SIZE)
+#define USBD_CDC_DATA_EP_SIZE   MYNEWT_VAL(USBD_CDC_DATA_EP_SIZE)
+#else
+#define USBD_CDC_DATA_EP_SIZE   0x40
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP)
+#define USBD_HID_REPORT_EP      MYNEWT_VAL(USBD_HID_REPORT_EP)
+#else
+#define USBD_HID_REPORT_EP      0x83
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_SIZE)
+#define USBD_HID_REPORT_EP_SIZE MYNEWT_VAL(USBD_HID_REPORT_EP_SIZE)
+#else
+#define USBD_HID_REPORT_EP_SIZE 0x10
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_INTERVAL)
+#define USBD_HID_REPORT_EP_INTERVAL MYNEWT_VAL(USBD_HID_REPORT_EP_INTERVAL)
+#else
+#define USBD_HID_REPORT_EP_INTERVAL 10
+#endif
+
 #endif
diff --git a/hw/usb/tinyusb/syscfg.yml b/hw/usb/tinyusb/syscfg.yml
index 726f90c..c76307b 100644
--- a/hw/usb/tinyusb/syscfg.yml
+++ b/hw/usb/tinyusb/syscfg.yml
@@ -34,3 +34,8 @@ syscfg.defs:
         description: >
             Sysinit stage for USB device functionality.
         value: 500
+    USBD_STD_DESCRIPTORS:
+        description: >
+            Include descriptor support. This allows to easily use CDC, MSC, HID device
+            functionality.
+        value: 1


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

Posted by je...@apache.org.
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


[mynewt-core] 06/07: console: Add console over USB CDC

Posted by je...@apache.org.
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 d2b4b3cf546670a85928e7ccd55439fb9defe1bd
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Apr 30 15:06:21 2020 +0200

    console: Add console over USB CDC
    
    This adds package that handles console over TinyUSB
    provided USB stack.
---
 hw/usb/tinyusb/README.md                           |   6 +
 .../full => hw/usb/tinyusb/cdc_console}/pkg.yml    |  23 ++--
 hw/usb/tinyusb/cdc_console/src/cdc_console.c       | 147 +++++++++++++++++++++
 .../usb/tinyusb/cdc_console/syscfg.yml             |  30 ++---
 sys/console/full/pkg.yml                           |   2 +
 sys/console/full/syscfg.yml                        |   3 +
 6 files changed, 174 insertions(+), 37 deletions(-)

diff --git a/hw/usb/tinyusb/README.md b/hw/usb/tinyusb/README.md
index 5142326..5b1aa51 100644
--- a/hw/usb/tinyusb/README.md
+++ b/hw/usb/tinyusb/README.md
@@ -45,4 +45,10 @@ Vendor and product ID must be specified in **syscfg.vals:** section
 ```yaml
     USBD_VID: 0xABCD
     USBD_PID: 0x1234
+
+```
+To use console over USB, set those values in **syscfg.vals:** section
+```yaml
+    CONSOLE_USB: 1
+    USBD_CDC: 1
 ```
diff --git a/sys/console/full/pkg.yml b/hw/usb/tinyusb/cdc_console/pkg.yml
old mode 100644
new mode 100755
similarity index 64%
copy from sys/console/full/pkg.yml
copy to hw/usb/tinyusb/cdc_console/pkg.yml
index 150b5b0..45800d7
--- a/sys/console/full/pkg.yml
+++ b/hw/usb/tinyusb/cdc_console/pkg.yml
@@ -6,7 +6,7 @@
 # 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,
@@ -17,26 +17,19 @@
 # under the License.
 #
 
-pkg.name: sys/console/full
-pkg.description: Text-based IO interface.
+pkg.name: hw/usb/tinyusb/cdc_console
+pkg.description: Console over USB CDC.
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
+    - console
+    - usb
 
 pkg.deps:
     - "@apache-mynewt-core/hw/hal"
     - "@apache-mynewt-core/kernel/os"
-pkg.deps.CONSOLE_UART:
-    - "@apache-mynewt-core/hw/drivers/uart"
-pkg.deps.CONSOLE_RTT:
-    - "@apache-mynewt-core/hw/drivers/rtt"
-pkg.deps.CONSOLE_SEMIHOSTING:
-    - "@apache-mynewt-core/hw/drivers/semihosting"
-pkg.deps.'CONSOLE_HISTORY == "ram"':
-    - "@apache-mynewt-core/sys/console/full/history_ram"
-pkg.deps.'CONSOLE_HISTORY == "log"':
-    - "@apache-mynewt-core/sys/console/full/history_log"
-pkg.apis: console
+    - "@apache-mynewt-core/hw/usb/tinyusb"
+    - "@tinyusb/tinyusb"
 
 pkg.init:
-    console_pkg_init: 'MYNEWT_VAL(CONSOLE_SYSINIT_STAGE)'
+    usb_cdc_console_pkg_init: 'MYNEWT_VAL(CONSOLE_SYSINIT_STAGE)'
diff --git a/hw/usb/tinyusb/cdc_console/src/cdc_console.c b/hw/usb/tinyusb/cdc_console/src/cdc_console.c
new file mode 100755
index 0000000..1eaa828
--- /dev/null
+++ b/hw/usb/tinyusb/cdc_console/src/cdc_console.c
@@ -0,0 +1,147 @@
+/*
+ * 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 <class/cdc/cdc_device.h>
+
+#include <console/console.h>
+#include <bsp/bsp.h>
+
+static struct os_event rx_receive_event;
+static struct os_event tx_flush_event;
+static bool connected;
+
+static void
+cdc_schedule_tx_flush(void)
+{
+    os_eventq_put(os_eventq_dflt_get(), &tx_flush_event);
+}
+
+static void
+cdc_write(int c)
+{
+    uint32_t written;
+
+    written = tud_cdc_write_char(c);
+    if (tud_cdc_write_available() == 0) {
+        tud_cdc_write_flush();
+        if (written == 0) {
+            tud_cdc_write_char(c);
+        }
+    }
+}
+
+int
+console_out_nolock(int c)
+{
+    cdc_write(c);
+
+    if ('\n' == c) {
+        cdc_write('\r');
+    }
+
+    cdc_schedule_tx_flush();
+
+    return c;
+}
+
+void
+console_rx_restart(void)
+{
+    os_eventq_put(os_eventq_dflt_get(), &rx_receive_event);
+}
+
+static void
+tx_flush_ev_cb(struct os_event *ev)
+{
+    if (connected && tud_cdc_write_available() < USBD_CDC_DATA_EP_SIZE) {
+        if (tud_cdc_write_flush() == 0) {
+            /*
+             * Previous data not sent yet.
+             * There is no data sent notification in tinyusb/cdc, retry flush later.
+             */
+            cdc_schedule_tx_flush();
+        }
+    }
+}
+
+static void
+rx_ev_cb(struct os_event *ev)
+{
+    static int console_rejected_char = -1;
+    int ret;
+
+    /* We may have unhandled character - try it first */
+    if (console_rejected_char >= 0) {
+        ret = console_handle_char(console_rejected_char);
+        if (ret < 0) {
+            return;
+        }
+    }
+
+    while (tud_cdc_available()) {
+        console_rejected_char = tud_cdc_read_char();
+        if (console_rejected_char >= 0) {
+            ret = console_handle_char(console_rejected_char);
+            if (ret < 0) {
+                return;
+            }
+        } else {
+            break;
+        }
+    }
+
+    console_rejected_char = -1;
+}
+
+void
+tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
+{
+    if (dtr != connected) {
+        connected = dtr;
+        cdc_schedule_tx_flush();
+    }
+}
+
+/* Invoked when CDC interface received data from host */
+void
+tud_cdc_rx_cb(uint8_t itf)
+{
+    os_eventq_put(os_eventq_dflt_get(), &rx_receive_event);
+}
+
+void
+tud_cdc_line_coding_cb(uint8_t itf, const cdc_line_coding_t *p_line_coding)
+{
+}
+
+void
+tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char)
+{
+}
+
+int
+usb_cdc_console_pkg_init(void)
+{
+    rx_receive_event.ev_cb = rx_ev_cb;
+    tx_flush_event.ev_cb = tx_flush_ev_cb;
+
+    return 0;
+}
diff --git a/sys/console/full/pkg.yml b/hw/usb/tinyusb/cdc_console/syscfg.yml
old mode 100644
new mode 100755
similarity index 51%
copy from sys/console/full/pkg.yml
copy to hw/usb/tinyusb/cdc_console/syscfg.yml
index 150b5b0..ed5a3bb
--- a/sys/console/full/pkg.yml
+++ b/hw/usb/tinyusb/cdc_console/syscfg.yml
@@ -6,7 +6,7 @@
 # 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,
@@ -17,26 +17,12 @@
 # under the License.
 #
 
-pkg.name: sys/console/full
-pkg.description: Text-based IO interface.
-pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
+syscfg.defs:
+    USBD_CDC_DECRIPTOR_STRING:
+        description: String for CDC interface
+        value: '"Mynewt console"'
 
-pkg.deps:
-    - "@apache-mynewt-core/hw/hal"
-    - "@apache-mynewt-core/kernel/os"
-pkg.deps.CONSOLE_UART:
-    - "@apache-mynewt-core/hw/drivers/uart"
-pkg.deps.CONSOLE_RTT:
-    - "@apache-mynewt-core/hw/drivers/rtt"
-pkg.deps.CONSOLE_SEMIHOSTING:
-    - "@apache-mynewt-core/hw/drivers/semihosting"
-pkg.deps.'CONSOLE_HISTORY == "ram"':
-    - "@apache-mynewt-core/sys/console/full/history_ram"
-pkg.deps.'CONSOLE_HISTORY == "log"':
-    - "@apache-mynewt-core/sys/console/full/history_log"
-pkg.apis: console
+syscfg.vals:
 
-pkg.init:
-    console_pkg_init: 'MYNEWT_VAL(CONSOLE_SYSINIT_STAGE)'
+syscfg.restrictions:
+    - "USBD_CDC"
diff --git a/sys/console/full/pkg.yml b/sys/console/full/pkg.yml
index 150b5b0..cda20d9 100644
--- a/sys/console/full/pkg.yml
+++ b/sys/console/full/pkg.yml
@@ -32,6 +32,8 @@ pkg.deps.CONSOLE_RTT:
     - "@apache-mynewt-core/hw/drivers/rtt"
 pkg.deps.CONSOLE_SEMIHOSTING:
     - "@apache-mynewt-core/hw/drivers/semihosting"
+pkg.deps.CONSOLE_USB:
+    - "@apache-mynewt-core/hw/usb/tinyusb/cdc_console"
 pkg.deps.'CONSOLE_HISTORY == "ram"':
     - "@apache-mynewt-core/sys/console/full/history_ram"
 pkg.deps.'CONSOLE_HISTORY == "log"':
diff --git a/sys/console/full/syscfg.yml b/sys/console/full/syscfg.yml
index 2289163..f8fcb84 100644
--- a/sys/console/full/syscfg.yml
+++ b/sys/console/full/syscfg.yml
@@ -26,6 +26,9 @@ syscfg.defs:
     CONSOLE_SEMIHOSTING:
         description: 'Set console output to ARM semihosting'
         value: 0
+    CONSOLE_USB:
+        description: 'Set console to USB'
+        value: 0
     CONSOLE_BLE_MONITOR:
         description: 'Set console output to BLE Monitor'
         value: 0