summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2020-01-11 13:14:30 +0700
committerGitHub <[email protected]>2020-01-11 13:14:30 +0700
commit13016c5cbbf2ee058371670e4f7cc33703c36f75 (patch)
treec6178e13588d9b9101e4ec5ced5f5523eb0b8922
parent744674bb2803285703449f0dc3c9b9ac42c4b8e4 (diff)
parent516e6e6bea047d28e6a286aa0285b238859ecd61 (diff)
Merge pull request #266 from hathach/develop
follow up to PR #240
-rw-r--r--.github/workflows/build.yml3
-rw-r--r--CONTRIBUTORS.md1
-rw-r--r--examples/device/cdc_dual_ports/src/main.c12
-rw-r--r--examples/device/cdc_dual_ports/src/usb_descriptors.c9
-rw-r--r--examples/device/cdc_dual_ports/src/usb_descriptors.h28
5 files changed, 13 insertions, 40 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 4fc11f3dd..729222512 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -24,7 +24,8 @@ jobs:
strategy:
fail-fast: false
matrix:
- example: ['board_test', 'cdc_msc', 'dfu_rt', 'hid_composite', 'hid_generic_inout', 'midi_test', 'msc_dual_lun', 'usbtmc', 'webusb_serial']
+ example: ['board_test', 'cdc_dual_ports', 'cdc_msc', 'dfu_rt', 'hid_composite',
+ 'hid_generic_inout', 'midi_test', 'msc_dual_lun', 'usbtmc', 'webusb_serial']
steps:
- name: Setup Python
uses: actions/setup-python@v1
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 0b52c4c5b..e1d5db693 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -27,6 +27,7 @@
* **[Peter Lawrence](https://github.com/majbthrd)**
* Nuvoton NUC 121, 125, 126 device driver port
* Board support for NuTiny NUC121s, NUC125s, NUC126V
+ * Complete multiple class interfaces & add cdc_dual_ports example
* **[Scott Shawcroft](https://github.com/tannewt)**
* SAMD21 and SAMD51 device driver port
diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c
index e612dc83a..d6e38df85 100644
--- a/examples/device/cdc_dual_ports/src/main.c
+++ b/examples/device/cdc_dual_ports/src/main.c
@@ -30,7 +30,6 @@
#include "bsp/board.h"
#include "tusb.h"
-#include "usb_descriptors.h"
//------------- prototypes -------------//
static void cdc_task(void);
@@ -51,7 +50,9 @@ int main(void)
return 0;
}
-static void echo_all(uint8_t itf, uint8_t buf[], uint32_t count)
+// echo to either Serial0 or Serial1
+// with Serial0 as all lower case, Serial1 as all upper case
+static void echo_serial_port(uint8_t itf, uint8_t buf[], uint32_t count)
{
for(uint32_t i=0; i<count; i++)
{
@@ -65,7 +66,7 @@ static void echo_all(uint8_t itf, uint8_t buf[], uint32_t count)
// echo back additional ports as upper case
if (islower(buf[i])) buf[i] -= 'a' - 'A';
}
-
+
tud_cdc_n_write_char(itf, buf[i]);
if ( buf[i] == '\r' ) tud_cdc_n_write_char(itf, '\n');
@@ -90,8 +91,9 @@ static void cdc_task(void)
uint32_t count = tud_cdc_n_read(itf, buf, sizeof(buf));
- // echo back to cdc
- echo_all(itf, buf, count);
+ // echo back to both serial ports
+ echo_serial_port(0, buf, count);
+ echo_serial_port(1, buf, count);
}
}
}
diff --git a/examples/device/cdc_dual_ports/src/usb_descriptors.c b/examples/device/cdc_dual_ports/src/usb_descriptors.c
index 63885347d..1e24a0f15 100644
--- a/examples/device/cdc_dual_ports/src/usb_descriptors.c
+++ b/examples/device/cdc_dual_ports/src/usb_descriptors.c
@@ -24,7 +24,6 @@
*/
#include "tusb.h"
-#include "usb_descriptors.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
@@ -77,10 +76,8 @@ enum
{
ITF_NUM_CDC1 = 0,
ITF_NUM_CDC_DATA1,
-#if (CFG_TUD_CDC > 1)
ITF_NUM_CDC2,
ITF_NUM_CDC_DATA2,
-#endif
ITF_NUM_TOTAL
};
@@ -99,11 +96,11 @@ uint8_t const desc_configuration[] =
// Interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
- // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
+ // 1st CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC1, 4, 0x81, 8, EPNUM_CDC, 0x80 | EPNUM_CDC, 64),
-#if (CFG_TUD_CDC > 1)
+
+ // 2nd CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC2, 4, 0x83, 8, EPNUM_CDC + 2, 0x80 | (EPNUM_CDC + 2), 64),
-#endif
};
// Invoked when received GET CONFIGURATION DESCRIPTOR
diff --git a/examples/device/cdc_dual_ports/src/usb_descriptors.h b/examples/device/cdc_dual_ports/src/usb_descriptors.h
deleted file mode 100644
index 280570831..000000000
--- a/examples/device/cdc_dual_ports/src/usb_descriptors.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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 USB_DESCRIPTORS_H_
-#define USB_DESCRIPTORS_H_
-
-#endif /* USB_DESCRIPTORS_H_ */