diff --git a/.codespellrc b/.codespellrc
deleted file mode 100644
index 1f06e0c5c..000000000
--- a/.codespellrc
+++ /dev/null
@@ -1,10 +0,0 @@
-# See: https://github.com/codespell-project/codespell#using-a-config-file
-[codespell]
-# In the event of a false positive, add the problematic word, in all lowercase, to 'ignore-words.txt' (one word per line).
-# Or copy & paste the whole problematic line to 'exclude-file.txt'
-ignore-words = tools/codespell/ignore-words.txt
-exclude-file = tools/codespell/exclude-file.txt
-check-filenames =
-check-hidden =
-count =
-skip = *.rb,.cproject,.git,./lib,./examples/*/*/_build,./examples/*/*/ses,./examples/*/*/ozone,./hw/mcu,./tests_obsolete
diff --git a/.gitattributes b/.gitattributes
index 140ae8929..2342decc3 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,10 +1,10 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
-*.c text
-*.cpp text
+*.c text
+*.cpp text
*.h text
-*.icf text
+*.icf text
*.js text
*.json text
*.ld text
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index d00ee78bd..291b22079 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -33,10 +33,8 @@ body:
attributes:
label: Firmware
placeholder: |
- e.g examples/device/cdc_msc. If it is custom firmware, it is preferably compiled like one in example folder and reviewable for people to comment on. The easiest way is
- - Fork this repo, checkout a new branch
- - Add your-own-example based on stock one
- - Push and post it here.
+ e.g examples/device/cdc_msc.
+ If it is custom firmware, please provide links to your minimal sources or as attached files.
validations:
required: true
@@ -51,24 +49,22 @@ body:
attributes:
label: How to reproduce ?
placeholder: |
- Exact steps in chronological order, details should be specific e.g if you use a command/script to test with, please post it as well.
1. Go to '...'
2. Click on '....'
- 3. See error
+ 3. See error
validations:
required: true
- type: textarea
attributes:
- label: Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)
+ label: Debug Log
placeholder: |
- Attach your debug log txt file here, where the issue occurred, best with comments to explain the actual events.
+ TinyUSB debug log where the issue occurred as attached txt file, best with comments to explain the actual events.
- Note1: Please DO NOT paste your lengthy log contents here since it hurts the readability.
- Note2: To enable logging, add `LOG=2` to to the make command if building with stock examples or set `CFG_TUSB_DEBUG=2` in your tusb_config.h.
+ Note: To enable logging, add `LOG=3` to to the make command if building with stock examples or set `CFG_TUSB_DEBUG=3` in your tusb_config.h.
More information can be found at [example's readme](https://github.com/hathach/tinyusb/blob/master/docs/getting_started.md)
validations:
- required: true
+ required: false
- type: textarea
attributes:
@@ -76,11 +72,3 @@ body:
description: If applicable, add screenshots to help explain your problem.
validations:
required: false
-
- - type: checkboxes
- attributes:
- label: I have checked existing issues, dicussion and documentation
- description: You agree to check all the resources above before opening a new issue.
- options:
- - label: I confirm I have checked existing issues, dicussion and documentation.
- required: true
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
index 28fd27467..735a5ef22 100644
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -1,8 +1,4 @@
-blank_issues_enabled: false
contact_links:
- name: TinyUSB Discussion
url: https://github.com/hathach/tinyusb/discussions
about: If you have other questions or need help, post it here.
- - name: TinyUSB Docs
- url: https://docs.tinyusb.org/
- about: Online documentation
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
new file mode 100644
index 000000000..562d3113b
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,14 @@
+---
+name: Feature Request
+about: Suggest an idea for this project
+title: ''
+labels: Feature 💡
+assignees: ''
+
+---
+
+**Is your feature request related to a problem? Please describe.**
+A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+
+**Describe the solution you'd like**
+A clear and concise description of what you want to happen.
diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml
deleted file mode 100644
index 19f403246..000000000
--- a/.github/ISSUE_TEMPLATE/feature_request.yml
+++ /dev/null
@@ -1,49 +0,0 @@
-name: Feature Request
-description: Suggest an idea for this project
-labels: 'Feature 💡'
-body:
- - type: markdown
- attributes:
- value: |
- Thanks for taking the time to fill out this request!
- It's okay to leave some blank if it doesn't apply to your request.
-
- - type: input
- attributes:
- label: Related area
- description: Please briefly explain the area of your Feature Request.
- placeholder: eg. new port support, device stack, class driver ...
- validations:
- required: true
-
- - type: input
- attributes:
- label: Hardware specification
- description: Please provide if your proposal depends on specific Hardware.
- placeholder: eg. rp2040, samd51 ...
- validations:
- required: true
-
- - type: textarea
- attributes:
- label: Is your feature request related to a problem?
- description: Please provide a clear and concise description of what the problem is. Add relevant issue link.
- placeholder: ex. I'm facing the issue/missing function...
- validations:
- required: true
-
- - type: textarea
- attributes:
- label: Describe the solution you'd like
- description: Please provide a clear and concise description of what you want to happen.
- placeholder: ex. When using this function...
- validations:
- required: true
-
- - type: checkboxes
- attributes:
- label: I have checked existing issues, dicussion and documentation
- description: You agree to check all the resources above before opening a new issue.
- options:
- - label: I confirm I have checked existing issues, dicussion and documentation.
- required: true
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 000000000..b16cf3f87
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,159 @@
+name: Build ARM
+
+on:
+ pull_request:
+ push:
+ release:
+ types:
+ - created
+
+jobs:
+ # ---------------------------------------
+ # Unit testing with Ceedling
+ # ---------------------------------------
+ unit-test:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Setup Ruby
+ uses: actions/setup-ruby@v1
+ with:
+ ruby-version: '2.7'
+
+ - name: Checkout TinyUSB
+ uses: actions/checkout@v2
+
+ - name: Unit Tests
+ run: |
+ # Install Ceedling
+ gem install ceedling
+ cd test
+ ceedling test:all
+
+ # ---------------------------------------
+ # Build ARM family
+ # ---------------------------------------
+ build-arm:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ family:
+ # Alphabetical order
+ - 'imxrt'
+ - 'lpc15'
+ - 'lpc18'
+ - 'lpc54'
+ - 'lpc55'
+ - 'mm32'
+ - 'nrf'
+ - 'rp2040'
+ - 'samd11'
+ - 'samd21'
+ - 'samd51'
+ - 'saml2x'
+ - 'stm32f0'
+ - 'stm32f1'
+ - 'stm32f4'
+ - 'stm32f7'
+ - 'stm32h7'
+ steps:
+ - name: Setup Python
+ uses: actions/setup-python@v2
+
+ - name: Checkout TinyUSB
+ uses: actions/checkout@v2
+
+ - name: Checkout common submodules in lib
+ run: git submodule update --init lib/FreeRTOS-Kernel lib/lwip lib/sct_neopixel
+
+ - name: Checkout hathach/linkermap
+ uses: actions/checkout@v2
+ with:
+ repository: hathach/linkermap
+ path: linkermap
+
+ - name: Checkout pico-sdk
+ if: matrix.family == 'rp2040'
+ run: |
+ git clone --depth 1 -b develop https://github.com/raspberrypi/pico-sdk ~/pico-sdk
+ echo >> $GITHUB_ENV PICO_SDK_PATH=~/pico-sdk
+
+ - name: Set Toolchain URL
+ run: echo >> $GITHUB_ENV TOOLCHAIN_URL=https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v10.2.1-1.1/xpack-arm-none-eabi-gcc-10.2.1-1.1-linux-x64.tar.gz
+
+ - name: Cache Toolchain
+ uses: actions/cache@v2
+ id: cache-toolchain
+ with:
+ path: ~/cache/
+ key: ${{ runner.os }}-21-03-04-${{ env.TOOLCHAIN_URL }}
+
+ - name: Install Toolchain
+ if: steps.cache-toolchain.outputs.cache-hit != 'true'
+ run: |
+ mkdir -p ~/cache/toolchain
+ wget --progress=dot:mega $TOOLCHAIN_URL -O toolchain.tar.gz
+ tar -C ~/cache/toolchain -xaf toolchain.tar.gz
+
+ - name: Set Toolchain Path
+ run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
+
+ - name: Build
+ run: python3 tools/build_family.py ${{ matrix.family }}
+
+ - name: Linker Map
+ run: |
+ pip install linkermap/
+ for ex in `ls -d examples/device/*/`; do \
+ find ${ex} -name *.map -print -quit | \
+ xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'; \
+ done
+
+ # ---------------------------------------
+ # Build all no-family (opharned) boards
+ # ---------------------------------------
+ build-board:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ example:
+ # Alphabetical order, a group of 4
+ - 'device/audio_test device/board_test device/cdc_dual_ports device/cdc_msc'
+ - 'device/cdc_msc_freertos device/dfu_runtime device/hid_composite device/hid_composite_freertos'
+ - 'device/hid_generic_inout device/hid_multiple_interface device/midi_test device/msc_dual_lun'
+ - 'device/net_lwip_webserver'
+ - 'device/uac2_headset device/usbtmc device/webusb_serial host/cdc_msc_hid'
+
+ steps:
+ - name: Setup Python
+ uses: actions/setup-python@v2
+
+ - name: Checkout TinyUSB
+ uses: actions/checkout@v2
+
+ - name: Checkout common submodules in lib
+ run: git submodule update --init lib/FreeRTOS-Kernel lib/lwip
+
+ - name: Set Toolchain URL
+ run: echo >> $GITHUB_ENV TOOLCHAIN_URL=https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v10.2.1-1.1/xpack-arm-none-eabi-gcc-10.2.1-1.1-linux-x64.tar.gz
+
+ - name: Cache Toolchain
+ uses: actions/cache@v2
+ id: cache-toolchain
+ with:
+ path: ~/cache/
+ key: ${{ runner.os }}-21-03-04-${{ env.TOOLCHAIN_URL }}
+
+ - name: Install Toolchain
+ if: steps.cache-toolchain.outputs.cache-hit != 'true'
+ run: |
+ mkdir -p ~/cache/toolchain
+ wget --progress=dot:mega $TOOLCHAIN_URL -O toolchain.tar.gz
+ tar -C ~/cache/toolchain -xaf toolchain.tar.gz
+
+ - name: Set Toolchain Path
+ run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
+
+ - name: Build
+ run: python3 tools/build_board.py ${{ matrix.example }}
diff --git a/.github/workflows/build_aarch64.yml b/.github/workflows/build_aarch64.yml
deleted file mode 100644
index 6ac7ad015..000000000
--- a/.github/workflows/build_aarch64.yml
+++ /dev/null
@@ -1,84 +0,0 @@
-name: Build AArch64
-
-on:
- workflow_dispatch:
- push:
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_aarch64.yml'
- pull_request:
- branches: [ master ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_aarch64.yml'
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
- cancel-in-progress: true
-
-jobs:
- # ---------------------------------------
- # Build AARCH64 family
- # ---------------------------------------
- build-arm:
- runs-on: ubuntu-latest
- strategy:
- fail-fast: false
- matrix:
- family:
- # Alphabetical order
- - 'broadcom_64bit'
- steps:
- - name: Setup Python
- uses: actions/setup-python@v4
- with:
- python-version: '3.x'
-
- - name: Checkout TinyUSB
- uses: actions/checkout@v3
-
- - name: Checkout hathach/linkermap
- uses: actions/checkout@v3
- with:
- repository: hathach/linkermap
- path: linkermap
-
- - name: Set Toolchain URL
- run: echo >> $GITHUB_ENV TOOLCHAIN_URL=https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz
-
- - name: Cache Toolchain
- uses: actions/cache@v3
- id: cache-toolchain
- with:
- path: ~/cache/
- key: ${{ runner.os }}-21-11-02-${{ env.TOOLCHAIN_URL }}
-
- - name: Install Toolchain
- if: steps.cache-toolchain.outputs.cache-hit != 'true'
- run: |
- mkdir -p ~/cache/toolchain
- wget --progress=dot:mega $TOOLCHAIN_URL -O toolchain.tar.gz
- tar -C ~/cache/toolchain -xaf toolchain.tar.gz
-
- - name: Set Toolchain Path
- run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
-
- - name: Get Dependencies
- run: python3 tools/get_deps.py ${{ matrix.family }}
-
- - name: Build
- run: python3 tools/build_family.py ${{ matrix.family }}
-
- - name: Linker Map
- run: |
- pip install linkermap/
- for ex in `ls -d examples/device/*/`; do \
- find ${ex} -name *.map -print -quit | \
- xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'; \
- done
diff --git a/.github/workflows/build_arm.yml b/.github/workflows/build_arm.yml
deleted file mode 100644
index 171c1fec3..000000000
--- a/.github/workflows/build_arm.yml
+++ /dev/null
@@ -1,78 +0,0 @@
-name: Build ARM
-
-on:
- workflow_dispatch:
- push:
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_arm.yml'
- pull_request:
- branches: [ master ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_arm.yml'
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
- cancel-in-progress: true
-
-jobs:
- # ---------------------------------------
- # Build ARM family
- # ---------------------------------------
- build-arm:
- runs-on: ubuntu-latest
- strategy:
- fail-fast: false
- matrix:
- family:
- # Alphabetical order
- - 'broadcom_32bit'
- - 'kinetis_k32l2'
- - 'lpc11 lpc13 lpc15 lpc17'
- - 'lpc51'
- - 'mm32 msp432e4'
- - 'samd11 same5x saml2x'
- - 'stm32f2 stm32f3'
- - 'stm32l0 stm32wb'
- - 'tm4c123 xmc4000'
- steps:
- - name: Setup Python
- uses: actions/setup-python@v4
- with:
- python-version: '3.x'
-
- - name: Install ARM GCC
- uses: carlosperate/arm-none-eabi-gcc-action@v1
- with:
- release: '11.2-2022.02'
-
- - name: Checkout TinyUSB
- uses: actions/checkout@v3
-
- - name: Checkout hathach/linkermap
- uses: actions/checkout@v3
- with:
- repository: hathach/linkermap
- path: linkermap
-
- - name: Get Dependencies
- run: python3 tools/get_deps.py ${{ matrix.family }}
-
- - name: Build
- run: python3 tools/build_family.py ${{ matrix.family }}
-
- - name: Linker Map
- run: |
- pip install linkermap/
- # find -quit to only print linkermap of 1 board per example
- for ex in `ls -d examples/*/*/`
- do
- find ${ex} -name *.map -print -quit | xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'
- done
diff --git a/.github/workflows/build_esp.yml b/.github/workflows/build_esp.yml
index 897616f09..15071b178 100644
--- a/.github/workflows/build_esp.yml
+++ b/.github/workflows/build_esp.yml
@@ -1,26 +1,11 @@
name: Build ESP
on:
- workflow_dispatch:
- push:
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_esp.yml'
pull_request:
- branches: [ master ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_esp.yml'
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
- cancel-in-progress: true
+ push:
+ release:
+ types:
+ - created
jobs:
build-esp:
@@ -29,22 +14,35 @@ jobs:
fail-fast: false
matrix:
board:
+ # Alphabetical order
# ESP32-S2
- - 'espressif_kaluga_1'
+ - 'espressif_saola_1'
# ESP32-S3
- - 'espressif_s3_devkitm'
+ - 'espressif_addax_1'
steps:
- name: Setup Python
- uses: actions/setup-python@v4
- with:
- python-version: '3.x'
+ uses: actions/setup-python@v2
- name: Pull ESP-IDF docker
run: docker pull espressif/idf:latest
- name: Checkout TinyUSB
- uses: actions/checkout@v3
+ uses: actions/checkout@v2
+
+ - name: Checkout hathach/linkermap
+ uses: actions/checkout@v2
+ with:
+ repository: hathach/linkermap
+ path: linkermap
- name: Build
- run: docker run --rm -v $PWD:/project -w /project espressif/idf:latest python3 tools/build_esp32.py ${{ matrix.board }}
+ run: docker run --rm -v $PWD:/project -w /project espressif/idf:latest python3 tools/build_esp32sx.py ${{ matrix.board }}
+
+ - name: Linker Map
+ run: |
+ pip install linkermap/
+ for ex in `ls -d examples/device/*/`; do \
+ find ${ex} -maxdepth 3 -name *.map -print -quit | \
+ xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'; \
+ done
diff --git a/.github/workflows/build_iar.yml b/.github/workflows/build_iar.yml
deleted file mode 100644
index 1eacf90c9..000000000
--- a/.github/workflows/build_iar.yml
+++ /dev/null
@@ -1,54 +0,0 @@
-name: Build IAR
-
-on:
- workflow_dispatch:
- push:
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_iar.yml'
- pull_request:
- branches: [ master ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_iar.yml'
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
- cancel-in-progress: true
-
-jobs:
- cmake:
- runs-on: [self-hosted, Linux, X64, hifiphile]
- strategy:
- fail-fast: false
- matrix:
- family:
- # Alphabetical order
- # Note: bundle multiple families into a matrix since there is only one self-hosted instance can
- # run IAR build. Too many matrix can hurt due to setup/teardown overhead.
- - 'lpc43 stm32f0 stm32f1 stm32f4 stm32f7 stm32g0 stm32g4 stm32h7 stm32l4'
- steps:
- - name: Clean workspace
- run: |
- echo "Cleaning up previous run"
- rm -rf "${{ github.workspace }}"
- mkdir -p "${{ github.workspace }}"
-
- - name: Checkout TinyUSB
- uses: actions/checkout@v3
-
- - name: Get Dependencies
- run: python3 tools/get_deps.py ${{ matrix.family }}
-
- - name: Build
- run: python3 tools/build_cmake.py ${{ matrix.family }} -DTOOLCHAIN=iar -DCMAKE_BUILD_TYPE=MinSizeRel
-
- - name: Test on actual hardware (hardware in the loop)
- run: |
- python3 test/hil/hil_test.py hil_hfp.json
diff --git a/.github/workflows/build_msp430.yml b/.github/workflows/build_msp430.yml
index c62056940..98dc36cd9 100644
--- a/.github/workflows/build_msp430.yml
+++ b/.github/workflows/build_msp430.yml
@@ -1,28 +1,13 @@
name: Build MSP430
on:
- workflow_dispatch:
- push:
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_msp430.yml'
pull_request:
- branches: [ master ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_msp430.yml'
+ push:
+ release:
+ types:
+ - created
-concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
- cancel-in-progress: true
-
-jobs:
+jobs:
build-msp430:
runs-on: ubuntu-latest
strategy:
@@ -31,18 +16,18 @@ jobs:
family:
# Alphabetical order
- 'msp430'
-
steps:
- name: Setup Python
- uses: actions/setup-python@v4
- with:
- python-version: '3.x'
+ uses: actions/setup-python@v2
- name: Checkout TinyUSB
- uses: actions/checkout@v3
+ uses: actions/checkout@v2
+
+ - name: Checkout common submodules in lib
+ run: git submodule update --init lib/FreeRTOS-Kernel lib/lwip
- name: Checkout hathach/linkermap
- uses: actions/checkout@v3
+ uses: actions/checkout@v2
with:
repository: hathach/linkermap
path: linkermap
@@ -51,7 +36,7 @@ jobs:
run: echo >> $GITHUB_ENV TOOLCHAIN_URL=http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2
- name: Cache Toolchain
- uses: actions/cache@v3
+ uses: actions/cache@v2
id: cache-toolchain
with:
path: ~/cache/
@@ -67,17 +52,13 @@ jobs:
- name: Set Toolchain Path
run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
- - name: Get Dependencies
- run: python3 tools/get_deps.py ${{ matrix.family }}
-
- name: Build
run: python3 tools/build_family.py ${{ matrix.family }}
- name: Linker Map
run: |
pip install linkermap/
- # find -quit to only print linkermap of 1 board per example
- for ex in `ls -d examples/device/*/`
- do
- find ${ex} -name *.map -print -quit | xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'
+ for ex in `ls -d examples/device/*/`; do \
+ find ${ex} -name *.map -print -quit | \
+ xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'; \
done
diff --git a/.github/workflows/build_renesas.yml b/.github/workflows/build_renesas.yml
index 66b98a71b..6eb042d72 100644
--- a/.github/workflows/build_renesas.yml
+++ b/.github/workflows/build_renesas.yml
@@ -1,26 +1,11 @@
name: Build Renesas
on:
- workflow_dispatch:
- push:
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_renesas.yml'
pull_request:
- branches: [ master ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_renesas.yml'
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
- cancel-in-progress: true
+ push:
+ release:
+ types:
+ - created
jobs:
build-rx:
@@ -33,15 +18,16 @@ jobs:
- 'rx'
steps:
- name: Setup Python
- uses: actions/setup-python@v4
- with:
- python-version: '3.x'
+ uses: actions/setup-python@v2
- name: Checkout TinyUSB
- uses: actions/checkout@v3
+ uses: actions/checkout@v2
+
+ - name: Checkout common submodules in lib
+ run: git submodule update --init lib/FreeRTOS-Kernel lib/lwip
- name: Checkout hathach/linkermap
- uses: actions/checkout@v3
+ uses: actions/checkout@v2
with:
repository: hathach/linkermap
path: linkermap
@@ -50,7 +36,7 @@ jobs:
run: echo >> $GITHUB_ENV TOOLCHAIN_URL=http://gcc-renesas.com/downloads/get.php?f=rx/8.3.0.202004-gnurx/gcc-8.3.0.202004-GNURX-ELF.run
- name: Cache Toolchain
- uses: actions/cache@v3
+ uses: actions/cache@v2
id: cache-toolchain
with:
path: ~/cache/
@@ -67,17 +53,13 @@ jobs:
- name: Set Toolchain Path
run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
- - name: Get Dependencies
- run: python3 tools/get_deps.py ${{ matrix.family }}
-
- name: Build
run: python3 tools/build_family.py ${{ matrix.family }}
- name: Linker Map
run: |
pip install linkermap/
- # find -quit to only print linkermap of 1 board per example
- for ex in `ls -d examples/device/*/`
- do
- find ${ex} -name *.map -print -quit | xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'
+ for ex in `ls -d examples/device/*/`; do \
+ find ${ex} -name *.map -print -quit | \
+ xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'; \
done
diff --git a/.github/workflows/build_riscv.yml b/.github/workflows/build_riscv.yml
index 8ec549072..0c7b2d154 100644
--- a/.github/workflows/build_riscv.yml
+++ b/.github/workflows/build_riscv.yml
@@ -1,26 +1,11 @@
name: Build RISC-V
on:
- workflow_dispatch:
- push:
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_riscv.yml'
pull_request:
- branches: [ master ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_riscv.yml'
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
- cancel-in-progress: true
+ push:
+ release:
+ types:
+ - created
jobs:
build-riscv:
@@ -30,20 +15,20 @@ jobs:
matrix:
family:
# Alphabetical order
- - 'ch32v307'
- 'fomu'
- 'gd32vf103'
steps:
- name: Setup Python
- uses: actions/setup-python@v4
- with:
- python-version: '3.x'
+ uses: actions/setup-python@v2
- name: Checkout TinyUSB
- uses: actions/checkout@v3
+ uses: actions/checkout@v2
+
+ - name: Checkout common submodules in lib
+ run: git submodule update --init lib/FreeRTOS-Kernel lib/lwip
- name: Checkout hathach/linkermap
- uses: actions/checkout@v3
+ uses: actions/checkout@v2
with:
repository: hathach/linkermap
path: linkermap
@@ -52,7 +37,7 @@ jobs:
run: echo >> $GITHUB_ENV TOOLCHAIN_URL=https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack/releases/download/v10.1.0-1.1/xpack-riscv-none-embed-gcc-10.1.0-1.1-linux-x64.tar.gz
- name: Cache Toolchain
- uses: actions/cache@v3
+ uses: actions/cache@v2
id: cache-toolchain
with:
path: ~/cache/
@@ -68,17 +53,13 @@ jobs:
- name: Set Toolchain Path
run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
- - name: Get Dependencies
- run: python3 tools/get_deps.py ${{ matrix.family }}
-
- name: Build
run: python3 tools/build_family.py ${{ matrix.family }}
- name: Linker Map
run: |
pip install linkermap/
- # find -quit to only print linkermap of 1 board per example
- for ex in `ls -d examples/device/*/`
- do
- find ${ex} -name *.map -print -quit | xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'
+ for ex in `ls -d examples/device/*/`; do \
+ find ${ex} -name *.map -print -quit | \
+ xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'; \
done
diff --git a/.github/workflows/build_win_mac.yml b/.github/workflows/build_win_mac.yml
deleted file mode 100644
index cb879a705..000000000
--- a/.github/workflows/build_win_mac.yml
+++ /dev/null
@@ -1,54 +0,0 @@
-name: Build Windows/MacOS
-
-on:
- workflow_dispatch:
- push:
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_win_mac.yml'
- pull_request:
- branches: [ master ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/build_win_mac.yml'
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
- cancel-in-progress: true
-
-jobs:
- # ---------------------------------------
- # Build ARM family
- # ---------------------------------------
- build-arm:
- strategy:
- fail-fast: false
- matrix:
- os: [windows-latest, macos-latest]
- runs-on: ${{ matrix.os }}
-
- steps:
- - name: Setup Python
- uses: actions/setup-python@v4
- with:
- python-version: '3.x'
-
- - name: Install ARM GCC
- uses: carlosperate/arm-none-eabi-gcc-action@v1
- with:
- release: '10.3-2021.10'
-
- - name: Checkout TinyUSB
- uses: actions/checkout@v3
-
- - name: Get Dependencies
- run: python3 tools/get_deps.py stm32f4
-
- - name: Build
- run: python3 tools/build_family.py stm32f4 stm32f411disco
diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml
deleted file mode 100644
index 4c4b12a6b..000000000
--- a/.github/workflows/cifuzz.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-name: CIFuzz
-on:
- workflow_dispatch:
- pull_request:
- branches:
- - master
- paths:
- - '**.c'
- - '**.cc'
- - '**.cpp'
- - '**.cxx'
- - '**.h'
-jobs:
- Fuzzing:
- runs-on: ubuntu-latest
- steps:
- - name: Build Fuzzers
- id: build
- uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
- with:
- oss-fuzz-project-name: 'tinyusb'
- language: c++
- - name: Run Fuzzers
- uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
- with:
- oss-fuzz-project-name: 'tinyusb'
- language: c++
- fuzz-seconds: 600
- - name: Upload Crash
- uses: actions/upload-artifact@v3
- if: failure() && steps.build.outcome == 'success'
- with:
- name: artifacts
- path: ./out/artifacts
diff --git a/.github/workflows/cmake_arm.yml b/.github/workflows/cmake_arm.yml
deleted file mode 100644
index e57c297d7..000000000
--- a/.github/workflows/cmake_arm.yml
+++ /dev/null
@@ -1,164 +0,0 @@
-name: CMake ARM
-
-on:
- workflow_dispatch:
- push:
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/cmake_arm.yml'
- pull_request:
- branches: [ master ]
- paths:
- - 'src/**'
- - 'examples/**'
- - 'lib/**'
- - 'hw/**'
- - '.github/workflows/cmake_arm.yml'
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
- cancel-in-progress: true
-
-jobs:
- # ---------------------------------------
- # Build ARM family
- # ---------------------------------------
- build-arm:
- runs-on: ubuntu-latest
- strategy:
- fail-fast: false
- matrix:
- family:
- # Alphabetical order
- - 'imxrt'
- - 'kinetis_kl'
- - 'lpc18 lpc40 lpc43'
- - 'lpc54 lpc55'
- - 'mcx'
- - 'nrf'
- - 'ra'
- - 'rp2040'
- - 'samd21'
- - 'samd51'
- - 'stm32f0'
- - 'stm32f1'
- - 'stm32f4'
- - 'stm32f7'
- - 'stm32g0'
- - 'stm32g4'
- - 'stm32h7'
- - 'stm32l4'
- - 'stm32u5'
- steps:
- - name: Setup Python
- uses: actions/setup-python@v4
- with:
- python-version: '3.x'
-
- - name: Install ARM GCC
- uses: carlosperate/arm-none-eabi-gcc-action@v1
- with:
- release: '11.2-2022.02'
-
- - name: Install Ninja
- run: sudo apt install -y ninja-build
-
- - name: Checkout TinyUSB
- uses: actions/checkout@v3
-
- - name: Checkout pico-sdk for rp2040
- if: matrix.family == 'rp2040'
- uses: actions/checkout@v3
- with:
- repository: raspberrypi/pico-sdk
- ref: develop
- path: pico-sdk
-
- - name: Get Dependencies
- run: python3 tools/get_deps.py ${{ matrix.family }}
-
- - name: Build
- run: python tools/build_cmake.py ${{ matrix.family }} -DCMAKE_BUILD_TYPE=MinSizeRel
- env:
- # for rp2040, there is no harm if defined for other families
- PICO_SDK_PATH: ${{ github.workspace }}/pico-sdk
-
- # Upload binaries for hardware test with self-hosted
- - name: Prepare rp2040 Artifacts
- if: contains(matrix.family, 'rp2040') && github.repository_owner == 'hathach'
- working-directory: ${{github.workspace}}/cmake-build/cmake-build-raspberry_pi_pico
- run: |
- find device/ -name "*.elf" -exec mv {} ../../ \;
- # find host/ -name "*.elf" -exec mv {} ../../ \;
- # find dual/ -name "*.elf" -exec mv {} ../../ \;
-
- - name: Upload Artifacts for rp2040
- if: contains(matrix.family,'rp2040') && github.repository_owner == 'hathach'
- uses: actions/upload-artifact@v3
- with:
- name: rp2040
- path: |
- *.elf
-
- # ---------------------------------------
- # Hardware in the loop (HIL)
- # Current self-hosted instance is running on an RPI4 with
- # - pico + pico-probe connected via USB
- # - pico-probe is /dev/ttyACM0
- # ---------------------------------------
- hw-rp2040-test:
- # run only with hathach's commit due to limited resource on RPI4
- if: github.repository_owner == 'hathach'
- needs: build-arm
- runs-on: [self-hosted, Linux, ARM64, rp2040]
-
- steps:
- - name: Clean workspace
- run: |
- echo "Cleaning up previous run"
- rm -rf "${{ github.workspace }}"
- mkdir -p "${{ github.workspace }}"
-
- - name: Download rp2040 Artifacts
- uses: actions/download-artifact@v3
- with:
- name: rp2040
-
- - name: Create flash.sh
- run: |
- echo > flash.sh 'cmdout=$(openocd -f "interface/cmsis-dap.cfg" -f "target/rp2040.cfg" -c "adapter speed 5000" -c "program $1 reset exit")'
- echo >> flash.sh 'if (( $? )) ; then echo $cmdout ; fi'
- chmod +x flash.sh
-
- - name: Test cdc_dual_ports
- run: |
- ./flash.sh cdc_dual_ports.elf
- while (! ([ -e /dev/ttyACM1 ] && [ -e /dev/ttyACM2 ])) && [ $SECONDS -le 10 ]; do :; done
- test -e /dev/ttyACM1 && echo "ttyACM1 exists"
- test -e /dev/ttyACM2 && echo "ttyACM2 exists"
-
- - name: Test cdc_msc
- run: |
- ./flash.sh cdc_msc.elf
- readme='/media/pi/TinyUSB MSC/README.TXT'
- while (! ([ -e /dev/ttyACM1 ] && [ -f "$readme" ])) && [ $SECONDS -le 10 ]; do :; done
- test -e /dev/ttyACM1 && echo "ttyACM1 exists"
- test -f "$readme" && echo "$readme exists"
- cat "$readme"
-
- - name: Test dfu
- run: |
- ./flash.sh dfu.elf
- while (! (dfu-util -l | grep "Found DFU")) && [ $SECONDS -le 10 ]; do :; done
- dfu-util -d cafe -a 0 -U dfu0
- dfu-util -d cafe -a 1 -U dfu1
- grep "TinyUSB DFU! - Partition 0" dfu0
- grep "TinyUSB DFU! - Partition 1" dfu1
-
- - name: Test dfu_runtime
- run: |
- ./flash.sh dfu_runtime.elf
- while (! (dfu-util -l | grep "Found Runtime")) && [ $SECONDS -le 10 ]; do :; done
diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml
deleted file mode 100644
index f984954d9..000000000
--- a/.github/workflows/pre-commit.yml
+++ /dev/null
@@ -1,48 +0,0 @@
-name: pre-commit
-
-on:
- workflow_dispatch:
- push:
- pull_request:
- branches: [ master ]
-
-concurrency:
- group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
- cancel-in-progress: true
-
-jobs:
- pre-commit:
- runs-on: ubuntu-latest
- steps:
- - name: Setup Python
- uses: actions/setup-python@v4
- with:
- python-version: '3.x'
-
- - name: Setup Ruby
- uses: ruby/setup-ruby@v1
- with:
- ruby-version: '3.0'
-
- - name: Checkout TinyUSB
- uses: actions/checkout@v3
-
- - name: Get Dependencies
- run: |
- gem install ceedling
- #cd test/unit-test
- #ceedling test:all
-
- - name: Run pre-commit
- uses: pre-commit/action@v3.0.0
-
- - name: Build Fuzzer
- run: |
- export CC=clang
- export CXX=clang++
- fuzz_harness=$(ls -d test/fuzz/device/*/)
- for h in $fuzz_harness
- do
- make -C $h get-deps
- make -C $h all
- done
diff --git a/.github/workflows/trigger.yml b/.github/workflows/trigger.yml
index 33e3db859..40750a2f9 100644
--- a/.github/workflows/trigger.yml
+++ b/.github/workflows/trigger.yml
@@ -1,7 +1,6 @@
name: Trigger Repos
on:
- workflow_dispatch:
push:
branches: master
release:
@@ -23,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
- uses: actions/checkout@v3
+ uses: actions/checkout@v2
- name: Push to tinyusb_src
run: |
@@ -44,7 +43,7 @@ jobs:
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
- git push
+ git push
fi
- name: Create tinyusb_src Release
@@ -54,7 +53,6 @@ jobs:
cd tinyusb_src
git tag ${{ github.event.release.tag_name }}
git push origin ${{ github.event.release.tag_name }}
-
+
# Send POST reqwuest to release https://docs.github.com/en/rest/reference/repos#create-a-release
- bb="For release note, please checkout https://github.com/hathach/tinyusb/releases/tag/${{ github.event.release.tag_name }}"
- curl -X POST -H "Authorization: token ${{ secrets.API_TOKEN_GITHUB }}" -H "Accept: application/vnd.github.v3+json" --data '{"tag_name": "${{ github.event.release.tag_name }}", "name": "${{ github.event.release.name }}", "body": "$bb", "draft": ${{ github.event.release.draft }}, "prerelease": ${{ github.event.release.prerelease }}}' https://api.github.com/repos/hathach/tinyusb_src/releases
+ curl -X POST -H "Authorization: token ${{ secrets.API_TOKEN_GITHUB }}" -H "Accept: application/vnd.github.v3+json" --data '{"tag_name": "${{ github.event.release.tag_name }}", "name": "${{ github.event.release.name }}", "body": "${{ github.event.release.body }}", "draft": ${{ github.event.release.draft }}, "prerelease": ${{ github.event.release.prerelease }}}' https://api.github.com/repos/hathach/tinyusb_src/releases
diff --git a/.gitignore b/.gitignore
index c665d6c73..f7adff4c9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,7 @@ latex
*.ind
.env
.settings/
-.vscode/
+.idea/
.gdb_history
/examples/*/*/build*
test_old/
@@ -21,68 +21,8 @@ _build
/examples/*/*/ses
/examples/*/*/ozone
/examples/obsolete
-hw/bsp/**/cubemx/*/
-.mxproject
# coverity intermediate files
cov-int
# cppcheck build directories
*-build-dir
/_bin/
-__pycache__
-cmake-build-*
-sdkconfig
-
-# submodules
-hw/mcu/allwinner
-hw/mcu/bridgetek/ft9xx/ft90x-sdk
-hw/mcu/broadcom
-hw/mcu/gd/nuclei-sdk
-hw/mcu/infineon/mtb-xmclib-cat3
-hw/mcu/microchip
-hw/mcu/mindmotion/mm32sdk
-hw/mcu/nordic/nrfx
-hw/mcu/nuvoton
-hw/mcu/nxp/lpcopen
-hw/mcu/nxp/mcux-sdk
-hw/mcu/nxp/nxp_sdk
-hw/mcu/raspberry_pi/Pico-PIO-USB
-hw/mcu/renesas/rx
-hw/mcu/silabs/cmsis-dfp-efm32gg12b
-hw/mcu/sony/cxd56/spresense-exported-sdk
-hw/mcu/st/cmsis_device_f0
-hw/mcu/st/cmsis_device_f1
-hw/mcu/st/cmsis_device_f2
-hw/mcu/st/cmsis_device_f3
-hw/mcu/st/cmsis_device_f4
-hw/mcu/st/cmsis_device_f7
-hw/mcu/st/cmsis_device_g0
-hw/mcu/st/cmsis_device_g4
-hw/mcu/st/cmsis_device_h7
-hw/mcu/st/cmsis_device_l0
-hw/mcu/st/cmsis_device_l1
-hw/mcu/st/cmsis_device_l4
-hw/mcu/st/cmsis_device_l5
-hw/mcu/st/cmsis_device_u5
-hw/mcu/st/cmsis_device_wb
-hw/mcu/st/stm32f0xx_hal_driver
-hw/mcu/st/stm32f1xx_hal_driver
-hw/mcu/st/stm32f2xx_hal_driver
-hw/mcu/st/stm32f3xx_hal_driver
-hw/mcu/st/stm32f4xx_hal_driver
-hw/mcu/st/stm32f7xx_hal_driver
-hw/mcu/st/stm32g0xx_hal_driver
-hw/mcu/st/stm32g4xx_hal_driver
-hw/mcu/st/stm32h7xx_hal_driver
-hw/mcu/st/stm32l0xx_hal_driver
-hw/mcu/st/stm32l1xx_hal_driver
-hw/mcu/st/stm32l4xx_hal_driver
-hw/mcu/st/stm32l5xx_hal_driver
-hw/mcu/st/stm32u5xx_hal_driver
-hw/mcu/st/stm32wbxx_hal_driver
-hw/mcu/ti
-hw/mcu/wch/ch32v307
-lib/CMSIS_5
-lib/FreeRTOS-Kernel
-lib/lwip
-lib/sct_neopixel
-tools/uf2
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 000000000..5f5bee56c
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,129 @@
+[submodule "hw/mcu/nordic/nrfx"]
+ path = hw/mcu/nordic/nrfx
+ url = https://github.com/NordicSemiconductor/nrfx.git
+[submodule "tools/uf2"]
+ path = tools/uf2
+ url = https://github.com/microsoft/uf2.git
+[submodule "hw/mcu/sony/cxd56/spresense-exported-sdk"]
+ path = hw/mcu/sony/cxd56/spresense-exported-sdk
+ url = https://github.com/sonydevworld/spresense-exported-sdk.git
+[submodule "hw/mcu/ti"]
+ path = hw/mcu/ti
+ url = https://github.com/hathach/ti_driver.git
+[submodule "hw/mcu/microchip"]
+ path = hw/mcu/microchip
+ url = https://github.com/hathach/microchip_driver.git
+[submodule "hw/mcu/nuvoton"]
+ path = hw/mcu/nuvoton
+ url = https://github.com/majbthrd/nuc_driver.git
+[submodule "lib/lwip"]
+ path = lib/lwip
+ url = https://github.com/lwip-tcpip/lwip.git
+[submodule "hw/mcu/st/cmsis_device_f4"]
+ path = hw/mcu/st/cmsis_device_f4
+ url = https://github.com/STMicroelectronics/cmsis_device_f4.git
+[submodule "hw/mcu/st/stm32f4xx_hal_driver"]
+ path = hw/mcu/st/stm32f4xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32f4xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_f0"]
+ path = hw/mcu/st/cmsis_device_f0
+ url = https://github.com/STMicroelectronics/cmsis_device_f0.git
+[submodule "hw/mcu/st/stm32f0xx_hal_driver"]
+ path = hw/mcu/st/stm32f0xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32f0xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_f1"]
+ path = hw/mcu/st/cmsis_device_f1
+ url = https://github.com/STMicroelectronics/cmsis_device_f1.git
+[submodule "hw/mcu/st/stm32f1xx_hal_driver"]
+ path = hw/mcu/st/stm32f1xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32f1xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_f2"]
+ path = hw/mcu/st/cmsis_device_f2
+ url = https://github.com/STMicroelectronics/cmsis_device_f2.git
+[submodule "hw/mcu/st/stm32f2xx_hal_driver"]
+ path = hw/mcu/st/stm32f2xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32f2xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_f3"]
+ path = hw/mcu/st/cmsis_device_f3
+ url = https://github.com/STMicroelectronics/cmsis_device_f3.git
+[submodule "hw/mcu/st/stm32f3xx_hal_driver"]
+ path = hw/mcu/st/stm32f3xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32f3xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_f7"]
+ path = hw/mcu/st/cmsis_device_f7
+ url = https://github.com/STMicroelectronics/cmsis_device_f7.git
+[submodule "hw/mcu/st/stm32f7xx_hal_driver"]
+ path = hw/mcu/st/stm32f7xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32f7xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_h7"]
+ path = hw/mcu/st/cmsis_device_h7
+ url = https://github.com/STMicroelectronics/cmsis_device_h7.git
+[submodule "hw/mcu/st/stm32h7xx_hal_driver"]
+ path = hw/mcu/st/stm32h7xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32h7xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_l0"]
+ path = hw/mcu/st/cmsis_device_l0
+ url = https://github.com/STMicroelectronics/cmsis_device_l0.git
+[submodule "hw/mcu/st/stm32l0xx_hal_driver"]
+ path = hw/mcu/st/stm32l0xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32l0xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_l1"]
+ path = hw/mcu/st/cmsis_device_l1
+ url = https://github.com/STMicroelectronics/cmsis_device_l1.git
+[submodule "hw/mcu/st/stm32l1xx_hal_driver"]
+ path = hw/mcu/st/stm32l1xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32l1xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_l4"]
+ path = hw/mcu/st/cmsis_device_l4
+ url = https://github.com/STMicroelectronics/cmsis_device_l4.git
+[submodule "hw/mcu/st/stm32l4xx_hal_driver"]
+ path = hw/mcu/st/stm32l4xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32l4xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_g0"]
+ path = hw/mcu/st/cmsis_device_g0
+ url = https://github.com/STMicroelectronics/cmsis_device_g0.git
+[submodule "hw/mcu/st/stm32g0xx_hal_driver"]
+ path = hw/mcu/st/stm32g0xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32g0xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_g4"]
+ path = hw/mcu/st/cmsis_device_g4
+ url = https://github.com/STMicroelectronics/cmsis_device_g4.git
+[submodule "hw/mcu/st/stm32g4xx_hal_driver"]
+ path = hw/mcu/st/stm32g4xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32g4xx_hal_driver.git
+[submodule "hw/mcu/st/cmsis_device_l5"]
+ path = hw/mcu/st/cmsis_device_l5
+ url = https://github.com/STMicroelectronics/cmsis_device_l5.git
+[submodule "hw/mcu/st/stm32l5xx_hal_driver"]
+ path = hw/mcu/st/stm32l5xx_hal_driver
+ url = https://github.com/STMicroelectronics/stm32l5xx_hal_driver.git
+[submodule "lib/sct_neopixel"]
+ path = lib/sct_neopixel
+ url = https://github.com/gsteiert/sct_neopixel
+[submodule "lib/FreeRTOS-Kernel"]
+ path = lib/FreeRTOS-Kernel
+ url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git
+[submodule "lib/CMSIS_5"]
+ path = lib/CMSIS_5
+ url = https://github.com/ARM-software/CMSIS_5.git
+[submodule "hw/mcu/silabs/cmsis-dfp-efm32gg12b"]
+ path = hw/mcu/silabs/cmsis-dfp-efm32gg12b
+ url = https://github.com/cmsis-packs/cmsis-dfp-efm32gg12b
+[submodule "hw/mcu/renesas/rx"]
+ path = hw/mcu/renesas/rx
+ url = https://github.com/kkitayam/rx_device.git
+[submodule "hw/mcu/nxp/lpcopen"]
+ path = hw/mcu/nxp/lpcopen
+ url = https://github.com/hathach/nxp_lpcopen.git
+[submodule "hw/mcu/nxp/mcux-sdk"]
+ path = hw/mcu/nxp/mcux-sdk
+ url = https://github.com/NXPmicro/mcux-sdk.git
+[submodule "hw/mcu/nxp/nxp_sdk"]
+ path = hw/mcu/nxp/nxp_sdk
+ url = https://github.com/hathach/nxp_sdk.git
+[submodule "hw/mcu/gd/nuclei-sdk"]
+ path = hw/mcu/gd/nuclei-sdk
+ url = https://github.com/Nuclei-Software/nuclei-sdk.git
+[submodule "hw/mcu/mindmotion/mm32sdk"]
+ path = hw/mcu/mindmotion/mm32sdk
+ url = https://github.com/hathach/mm32sdk.git
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 73f69e095..000000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
-# Editor-based HTTP Client requests
-/httpRequests/
diff --git a/.idea/cmake.xml b/.idea/cmake.xml
deleted file mode 100644
index 88e0e27ad..000000000
--- a/.idea/cmake.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/kl25.xml b/.idea/runConfigurations/kl25.xml
deleted file mode 100644
index 66f8ea684..000000000
--- a/.idea/runConfigurations/kl25.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/lpc1857.xml b/.idea/runConfigurations/lpc1857.xml
deleted file mode 100644
index f7d4ba402..000000000
--- a/.idea/runConfigurations/lpc1857.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/lpc4088.xml b/.idea/runConfigurations/lpc4088.xml
deleted file mode 100644
index 911876903..000000000
--- a/.idea/runConfigurations/lpc4088.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/lpc54628.xml b/.idea/runConfigurations/lpc54628.xml
deleted file mode 100644
index e0047f187..000000000
--- a/.idea/runConfigurations/lpc54628.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/lpc55s69.xml b/.idea/runConfigurations/lpc55s69.xml
deleted file mode 100644
index d5e9b117a..000000000
--- a/.idea/runConfigurations/lpc55s69.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/mcx947.xml b/.idea/runConfigurations/mcx947.xml
deleted file mode 100644
index 31e5c27dd..000000000
--- a/.idea/runConfigurations/mcx947.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/nrf52840.xml b/.idea/runConfigurations/nrf52840.xml
deleted file mode 100644
index 3ffa16385..000000000
--- a/.idea/runConfigurations/nrf52840.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/nrf5340.xml b/.idea/runConfigurations/nrf5340.xml
deleted file mode 100644
index 2f8009444..000000000
--- a/.idea/runConfigurations/nrf5340.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/ra4m1.xml b/.idea/runConfigurations/ra4m1.xml
deleted file mode 100644
index 6135e5cf3..000000000
--- a/.idea/runConfigurations/ra4m1.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/ra6m1.xml b/.idea/runConfigurations/ra6m1.xml
deleted file mode 100644
index 0833d43b3..000000000
--- a/.idea/runConfigurations/ra6m1.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/ra6m5.xml b/.idea/runConfigurations/ra6m5.xml
deleted file mode 100644
index 606e04e52..000000000
--- a/.idea/runConfigurations/ra6m5.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/rp2040.xml b/.idea/runConfigurations/rp2040.xml
deleted file mode 100644
index 51ae689be..000000000
--- a/.idea/runConfigurations/rp2040.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/rt1010.xml b/.idea/runConfigurations/rt1010.xml
deleted file mode 100644
index f4f48181c..000000000
--- a/.idea/runConfigurations/rt1010.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/rt1060.xml b/.idea/runConfigurations/rt1060.xml
deleted file mode 100644
index 3d740edeb..000000000
--- a/.idea/runConfigurations/rt1060.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/samd21g18.xml b/.idea/runConfigurations/samd21g18.xml
deleted file mode 100644
index 9a1e65563..000000000
--- a/.idea/runConfigurations/samd21g18.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/samd51j19.xml b/.idea/runConfigurations/samd51j19.xml
deleted file mode 100644
index 74d0e3649..000000000
--- a/.idea/runConfigurations/samd51j19.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/stlink.xml b/.idea/runConfigurations/stlink.xml
deleted file mode 100644
index b29b63f1a..000000000
--- a/.idea/runConfigurations/stlink.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/stm32g474.xml b/.idea/runConfigurations/stm32g474.xml
deleted file mode 100644
index a7267fe90..000000000
--- a/.idea/runConfigurations/stm32g474.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/stm32h743.xml b/.idea/runConfigurations/stm32h743.xml
deleted file mode 100644
index 9cd142de0..000000000
--- a/.idea/runConfigurations/stm32h743.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/uno_r4.xml b/.idea/runConfigurations/uno_r4.xml
deleted file mode 100644
index 75eb3df4d..000000000
--- a/.idea/runConfigurations/uno_r4.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7f4..000000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
deleted file mode 100644
index 4071ec326..000000000
--- a/.pre-commit-config.yaml
+++ /dev/null
@@ -1,42 +0,0 @@
-# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
-#
-# SPDX-License-Identifier: Unlicense
-
-repos:
-- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v4.4.0
- hooks:
- - id: check-yaml
- - id: trailing-whitespace
- exclude: |
- (?x)^(
- hw/bsp/mcx/sdk/
- )
- - id: end-of-file-fixer
- exclude: |
- (?x)^(
- .idea/|
- hw/bsp/mcx/sdk/
- )
- - id: forbid-submodules
-
-- repo: https://github.com/codespell-project/codespell
- rev: v2.2.4
- hooks:
- - id: codespell
- args: [-w]
- exclude: |
- (?x)^(
- lib/|
- hw/bsp/mcx/sdk/
- )
-
-- repo: local
- hooks:
- - id: unit-test
- name: unit-test
- files: ^(src/|test/unit-test/)
- entry: sh -c "cd test/unit-test && ceedling test:all"
- pass_filenames: false
- types_or: [c, header]
- language: system
diff --git a/.readthedocs.yaml b/.readthedocs.yaml
index e26b1f475..e83cd90fd 100644
--- a/.readthedocs.yaml
+++ b/.readthedocs.yaml
@@ -4,21 +4,15 @@
version: 2
-# Set the version of Python and other tools you might need
-build:
- os: ubuntu-22.04
- tools:
- python: "3.11"
-
-# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
-# Optionally declare the Python requirements required to build your docs
python:
+ version: 3.8
install:
- requirements: docs/requirements.txt
submodules:
include: []
recursive: false
+
\ No newline at end of file
diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst
index 085f8082a..55a291222 100644
--- a/CONTRIBUTORS.rst
+++ b/CONTRIBUTORS.rst
@@ -18,12 +18,6 @@ Notable contributors
- Design the project logo
-`Gordon McNab `__
----------------------------------------------
-
-- Add new DCD port for Bridgetek FT90x and FT93x
-
-
`Ha Thach `__
-----------------------------------------
@@ -59,7 +53,6 @@ Notable contributors
-----------------------------------------------
- Add new DCD port for Dialog DA1469x
-- Add new DCD port for PIC32MZ
- Add new class driver for Bluetooth HCI
- Add ISO transfer for STM32 Synopsys, Nordic nRF, Dialog DA1469x
- Improve Audio driver and add uac2\_headset example
@@ -88,11 +81,11 @@ Notable contributors
`Koji KITAYAMA `__
-----------------------------------------------
-- Add new DCD and HCD port for NXP Kinetis KL25
-- Add new DCD and HCD port for Renesas RX family (RX600, RX700 ..) with GR-CITRUS, RX65n target board
-- Add new DCD and HCD port for Mentor musb with MSP432E4
+- Add new DCD port for NXP Kinetis KL25
+- Add new DCD port for Renesas RX family (RX600, RX700 ..) with GR-CITRUS, RX65n target board
- Add new class driver for USB Video Class (UVC 1.5)
+
`Nathan Conrad `__
---------------------------------------------
@@ -117,9 +110,8 @@ Notable contributors
`Rafael Silva `__
----------------------------------------------
-- Port DCD Synopsys to support Silabs EFM32GG12 with SLTB009A board
+- Add new DCD port for Silabs EFM32GG12 with SLTB009A board
- Rewrite documentation in rst and setup for readthedocs
-- Generalize Renesas driver and support RA family with EK-RA4M3 board
`Raspberry Pi Team `__
@@ -161,12 +153,6 @@ Notable contributors
- Add new class driver for DFU Runtime
-`Tian Yunhao `__
--------------------------------------------
-
-- Add new DCD port for Allwinner F1C100S/F1C200S
-- Add support for osal_rtx4
-
`Timon Skerutsch `__
----------------------------------------------
@@ -200,8 +186,6 @@ Notable contributors
- Add new DCD port for Microchip SAMx7x
- Add IAR compiler support
- Improve UAC2, CDC, DFU class driver
-- Improve stm32_fsdev, chipidea_ci_hs, lpc_ip3511 DCD
-- Host IAR Build CI & hardware in the loop (HITL) test
`Full contributors list `__
diff --git a/README.rst b/README.rst
index aef310b98..11804ccd1 100644
--- a/README.rst
+++ b/README.rst
@@ -1,7 +1,7 @@
.. figure:: docs/assets/logo.svg
:alt: TinyUSB
-|Build Status| |Documentation Status| |Fuzzing Status| |License|
+|Build Status| |Documentation Status| |License|
TinyUSB is an open-source cross-platform USB Host/Device stack for
embedded system, designed to be memory-safe with no dynamic allocation
@@ -20,8 +20,8 @@ Please take a look at the online `documentation `__.
├── docs # Documentation
├── examples # Sample with Makefile build support
├── hw
- │ ├── bsp # Supported boards source files
- │ └── mcu # Low level mcu core & peripheral drivers
+ │ ├── bsp # Supported boards source files
+ │ └── mcu # Low level mcu core & peripheral drivers
├── lib # Sources from 3rd party such as freeRTOS, fatfs ...
├── src # All sources files for TinyUSB stack itself.
├── test # Unit tests for the stack
@@ -32,35 +32,24 @@ Supported MCUs
The stack supports the following MCUs:
-- **Allwinner:** F1C100s/F1C200s
-- **Analog:** MAX3421e (aka Arduino usb host shield)
-- **Broadcom:** BCM2837, BCM2711
- **Dialog:** DA1469x
- **Espressif:** ESP32-S2, ESP32-S3
-- **GigaDevice:** GD32VF103
-- **Infineon:** XMC4500
- **MicroChip:** SAMD11, SAMD21, SAMD51, SAME5x, SAMG55, SAML21, SAML22, SAME7x
-- **NordicSemi:** nRF52833, nRF52840, nRF5340
+- **NordicSemi:** nRF52833, nRF52840
- **Nuvoton:** NUC120, NUC121/NUC125, NUC126, NUC505
- **NXP:**
- - iMX RT Series: RT10xx, RT11xx
- - Kinetis: KL25, K32L2
+ - iMX RT Series: RT1011, RT1015, RT1021, RT1052, RT1062, RT1064
+ - Kinetis: KL25, K32L2Bxx
- LPC Series: 11u, 13, 15, 17, 18, 40, 43, 51u, 54, 55
- - MCX: N9x
- **Raspberry Pi:** RP2040
-- **Renesas:**
-
- - RX Series: 63n, 65n, 72n
- - RA Series: 4m1, 4m3, 6m1, 6m5
-
-- **Silabs:** EFM32GG
+- **Renesas:** RX63N, RX65N
+- **Silabs:** EFM32GG12
- **Sony:** CXD56
-- **ST:** STM32 series: F0, F1, F2, F3, F4, F7, H7, G0, G4, L0, L1, L4, L4+, WB
-- **TI:** MSP430, MSP432E4, TM4C123
+- **ST:** STM32 series: L0, L1, F0, F1, F2, F3, F4, F7, H7 both FullSpeed and HighSpeed
+- **TI:** MSP430
- **ValentyUSB:** eptri
-- **WCH:** CH32V307
Here is the list of `Supported Devices`_ that can be used with provided examples.
@@ -72,7 +61,7 @@ Supports multiple device configurations by dynamically changing USB descriptors,
- Audio Class 2.0 (UAC2)
- Bluetooth Host Controller Interface (BTH HCI)
- Communication Device Class (CDC)
-- Device Firmware Update (DFU): DFU mode (WIP) and Runtime
+- Device Firmware Update (DFU): DFU mode (WIP) and Runtinme
- Human Interface Device (HID): Generic (In & Out), Keyboard, Mouse, Gamepad etc ...
- Mass Storage Class (MSC): with multiple LUNs
- Musical Instrument Digital Interface (MIDI)
@@ -82,25 +71,14 @@ Supports multiple device configurations by dynamically changing USB descriptors,
- Vendor-specific class support with generic In & Out endpoints. Can be used with MS OS 2.0 compatible descriptor to load winUSB driver without INF file.
- `WebUSB `__ with vendor-specific class
-If you have a special requirement, `usbd_app_driver_get_cb()` can be used to write your own class driver without modifying the stack. Here is how the RPi team added their reset interface `raspberrypi/pico-sdk#197 `_
+If you have a special requirement, `usbd_app_driver_get_cb()` can be used to write your own class driver without modifying the stack. Here is how the RPi team added their reset interface [raspberrypi/pico-sdk#197](https://github.com/raspberrypi/pico-sdk/pull/197)
Host Stack
==========
- Human Interface Device (HID): Keyboard, Mouse, Generic
- Mass Storage Class (MSC)
-- Communication Device Class: CDC-ACM
-- Vendor serial over USB: FTDI, CP210x
-- Hub with multiple-level support
-
-Similar to the Device Stack, if you have a special requirement, `usbh_app_driver_get_cb()` can be used to write your own class driver without modifying the stack.
-
-TypeC PD Stack
-==============
-
-- Power Delivery 3.0 (PD3.0) with USB Type-C support (WIP)
-- Super early stage, only for testing purpose
-- Only support STM32 G4
+- Hub currently only supports 1 level of hub (due to my laziness)
OS Abstraction layer
====================
@@ -109,11 +87,10 @@ TinyUSB is completely thread-safe by pushing all Interrupt Service Request (ISR)
- **No OS**
- **FreeRTOS**
-- `RT-Thread `_: `repo `_
-- **Mynewt** Due to the newt package build system, Mynewt examples are better to be on its `own repo `_
+- **Mynewt** Due to the newt package build system, Mynewt examples are better to be on its [own repo](https://github.com/hathach/mynewt-tinyusb-example)
-Docs
-====
+Local Docs
+==========
- Info
@@ -125,7 +102,6 @@ Docs
- `Supported Devices`_
- `Getting Started`_
- - `Dependencies`_
- `Concurrency`_
- `Contributing`_
@@ -144,12 +120,10 @@ Please make sure you understand all the license term for files you use
in your project.
-.. |Build Status| image:: https://github.com/hathach/tinyusb/actions/workflows/cmake_arm.yml/badge.svg
+.. |Build Status| image:: https://github.com/hathach/tinyusb/workflows/Build/badge.svg
:target: https://github.com/hathach/tinyusb/actions
.. |Documentation Status| image:: https://readthedocs.org/projects/tinyusb/badge/?version=latest
:target: https://docs.tinyusb.org/en/latest/?badge=latest
-.. |Fuzzing Status| image:: https://oss-fuzz-build-logs.storage.googleapis.com/badges/tinyusb.svg
- :target: https://oss-fuzz-build-logs.storage.googleapis.com/index.html#tinyusb
.. |License| image:: https://img.shields.io/badge/license-MIT-brightgreen.svg
:target: https://opensource.org/licenses/MIT
@@ -160,7 +134,6 @@ in your project.
.. _Reference: docs/reference/index.rst
.. _Supported Devices: docs/reference/supported.rst
.. _Getting Started: docs/reference/getting_started.rst
-.. _Dependencies: docs/reference/dependencies.rst
.. _Concurrency: docs/reference/concurrency.rst
.. _Contributing: docs/contributing/index.rst
.. _Code of Conduct: CODE_OF_CONDUCT.rst
diff --git a/docs/assets/stack.svg b/docs/assets/stack.svg
index ed46c8649..85fe35e96 100644
--- a/docs/assets/stack.svg
+++ b/docs/assets/stack.svg
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/docs/conf.py b/docs/conf.py
index 878b29645..c7a17478f 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -21,6 +21,7 @@ extensions = [
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx_autodoc_typehints',
+ 'sphinxemoji.sphinxemoji',
]
templates_path = ['_templates']
diff --git a/docs/contributing/index.rst b/docs/contributing/index.rst
index 7ff79cb32..c572894ad 100644
--- a/docs/contributing/index.rst
+++ b/docs/contributing/index.rst
@@ -6,7 +6,7 @@ Contributing can be highly rewarding, but it can also be frustrating at times.
It takes time to review patches, and as this is an open source project, that
sometimes can take a while. The reviewing process depends on the availability
of the maintainers, who may not be always available. Please try to be
-understanding through the process.
+understanding throught the process.
There a few guidelines you need to keep in mind when contributing. Please have
a look at them as that will make the contribution process easier for all
diff --git a/docs/contributing/porting.rst b/docs/contributing/porting.rst
index f81d98782..7e9e462f0 100644
--- a/docs/contributing/porting.rst
+++ b/docs/contributing/porting.rst
@@ -62,9 +62,9 @@ Feel free to skip this until you want to verify your demo code is running. To im
OS Abstraction Layer (OSAL)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
-The OS Abstraction Layer is responsible for providing basic data structures for TinyUSB that may allow for concurrency when used with an RTOS. Without an RTOS it simply handles concurrency issues between the main code and interrupts. The code is almost entirely agnostic of MCU and lives in ``src/osal``.
+The OS Abstraction Layer is responsible for providing basic data structures for TinyUSB that may allow for concurrency when used with an RTOS. Without an RTOS it simply handles concurrency issues between the main code and interrupts.
-In RTOS configurations, tud_task()/tuh_task() blocks behind a synchronization structure when the event queue is empty, so that the scheduler may give the CPU to a different task. To take advantage of the library's capability to yield the CPU when there are no actionable USB device events, ensure that the `CFG_TUSB_OS` symbol is defined, e.g `OPT_OS_FREERTOS` enables the FreeRTOS scheduler to schedule other threads than that which calls `tud_task()/tuh_task()`.
+The code is almost entirely agnostic of MCU and lives in ``src/osal``.
Device API
^^^^^^^^^^
@@ -195,7 +195,7 @@ Others (like the nRF52) may need each USB packet queued individually. To make th
some state for yourself and queue up an intermediate USB packet from the interrupt handler.
Once the transaction is going, the interrupt handler will notify TinyUSB of transfer completion.
-During transmission, the IN data buffer is guaranteed to remain unchanged in memory until the ``dcd_xfer_complete`` function is called.
+During transmission, the IN data buffer is guarenteed to remain unchanged in memory until the ``dcd_xfer_complete`` function is called.
The dcd_edpt_xfer function must never add zero-length-packets (ZLP) on its own to a transfer. If a ZLP is required,
then it must be explicitly sent by the stack calling dcd_edpt_xfer(), by calling dcd_edpt_xfer() a second time with len=0.
@@ -238,4 +238,4 @@ Use `WireShark `_ or `a Beagle 10.14 format)
-- [MSC] Add tud_msc_request_sense_cb() callback, change most default sense error to medium not present (0x02, 0x3A, 0x00)
-- [Video] Fix video_capture example fails enumeration when 8FPS
-
-Host Stack
-----------
-
-No notable changes
-
0.12.0
======
@@ -246,7 +69,7 @@ RP2040
^^^^^^
- Add RP2040 suspend & resume support
-- Implement double buffer for both host and device (#891). However device EPOUT is still single buffered due to techinical issue with short packet
+- Implement double buffer for both host and device (#891). Howver device EPOUT is still single bufferred due to techinical issue with short packet
Device Stack
------------
@@ -255,7 +78,7 @@ USBD
^^^^
- Better support big endian mcu
-- Add tuh_inited() and tud_inited(), will separate tusb_init/inited() to tud/tuh init/inited
+- Add tuh_inited() and tud_inited(), will separte tusb_init/inited() to tud/tuh init/inited
- Add dcd_attr.h for defining common controller attribute such as max endpoints
Bluetooth
@@ -267,7 +90,7 @@ DFU
^^^
- Enhance DFU implementation to support multiple alternate interface and better support bwPollTimeout
-- Rename CFG_TUD_DFU_MODE to simply CFG_TUD_DFU
+- Rename CFG_TUD_DFU_MODE to simply CFG_TUD_DFU
HID
^^^
@@ -287,7 +110,7 @@ UAC2
^^^^
- Fix bug and enhance of UAC2
-
+
Vendor
^^^^^^
@@ -300,8 +123,8 @@ Host Controller Driver (HCD)
RP2040
^^^^^^
-- Implement double buffered to fix E4 errata and boost performance
-- Lots of rp2040 update and enhancement
+- Implement double bufferred to fix E4 errata and boost performance
+- Lots of rp2040 update and enhancment
Host Stack
----------
@@ -309,7 +132,7 @@ Host Stack
- Major update and rework most of host stack, still needs more improvement
- Lots of improvement and update in parsing configuration and control
- Rework and major update to HID driver. Will default to enable boot interface if available
-- Separate CFG_TUH_DEVICE_MAX and CFG_TUH_HUB for better management and reduce SRAM usage
+- Sepearate CFG_TUH_DEVICE_MAX and CFG_TUH_HUB for better management and reduce SRAM usage
0.10.1 (2021-06-03)
===================
@@ -386,12 +209,12 @@ MIDI
Host Controller Driver (HCD)
----------------------------
-- No noticeable changes
+- No noticable changes
USB Host Driver (USBH)
----------------------
-- No noticeable changes
+- No noticable changes
Host Class Driver
-----------------
@@ -464,7 +287,7 @@ HID
MIDI
- Fix dropping MIDI sysex message when fifo is full
-- Fix typo in tud_midi_write24(), make example less ambiguous for cable and channel
+- Fix typo in tud_midi_write24(), make example less ambigous for cable and channel
- Fix incorrect endpoint descriptor length, MIDI v1 use Audio v1 which has 9-byte endpoint descriptor (instead of 7)
Host Stack
@@ -479,7 +302,7 @@ Host Controller Driver (HCD)
- Move echi/ohci files to portable/
- Rename hcd_lpc18_43 to hcd_transdimension
- Sub hcd API with hcd_ehci_init(), hcd_ehci_register_addr()
-
+
- Update NXP transdimention hcd_init() to reset controller to host mode
- Ported hcd to rt10xx
@@ -529,13 +352,13 @@ Device Controller Driver
- ESP32-S2:
- Add bus suspend and wakeup support
-
+
- SAMD21:
- Fix (walkaround) samd21 setup_packet overflow by USB DMA
-
+
- STM32 Synopsys:
- Rework USB FIFO allocation scheme and allow RX FIFO size reduction
-
+
- Sony CXD56
- Update Update Spresense SDK to 2.0.2
- Fix dcd issues with setup packets
@@ -554,17 +377,17 @@ USB Device
- CDC
- Allow to transmit data, even if the host does not support control line states i.e set DTR
-
+
- HID
- change default CFG_TUD_HID_EP_BUFSIZE from 16 to 64
-
+
- MIDI
- Fix midi sysex sending bug
-
+
- MSC
- Invoke only scsi complete callback after status transaction is complete.
- Fix scsi_mode_sense6_t padding, which cause IAR compiler internal error.
-
+
- USBTMC
- Change interrupt endpoint example size to 8 instead of 2 for better compatibility with mcu
@@ -614,20 +437,20 @@ Device Controller Driver
- Fix FIFO flush during stall
- Implement dcd_edpt_close() API
- Support F105, F107
-
+
- Enhance STM32 fsdev
- Improve dcd fifo allocation
- Fix ISTR race condition
- Support remap USB IRQ on supported MCUs
- Implement dcd_edpt_close() API
-
+
- Enhance NUC 505: enhance set configure behavior
- Enhance SAMD
- Fix race condition with setup packet
- Add SAMD11 option `OPT_MCU_SAMD11`
- Add SAME5x option `OPT_MCU_SAME5X`
-
+
- Fix SAMG control data toggle and stall race condition
- Enhance nRF
@@ -659,7 +482,7 @@ USB Device
- `usbd_driver_open()` add max length argument, and return length of interface (0 for not supported). Return value is used for finding appropriate driver
- Add application implemented class driver via `usbd_app_driver_get_cb()`
- IAD is handled to assign driver id
-
+
- Added `tud_descriptor_device_qualifier_cb()` callback
- Optimize `tu_fifo` bulk write/read transfer
- Forward non-std control request to class driver
@@ -675,12 +498,12 @@ USB Device
- Send zero length packet for end of data when needed
- Add `tud_cdc_tx_complete_cb()` callback
- Change tud_cdc_n_write_flush() return number of bytes forced to transfer, and flush when writing enough data to fifo
-
+
- MIDI:
- Add packet interface
- Add multiple jack descriptors
- Fix MIDI driver for sysex
-
+
- DFU Runtime: fix response to SET_INTERFACE and DFU_GETSTATUS request
- Rename some configure macro to make it clear that those are used directly for endpoint transfer
@@ -688,7 +511,7 @@ USB Device
- CFG_TUD_CDC_EPSIZE to CFG_TUD_CDC_EP_BUFSIZE
- CFG_TUD_MSC_BUFSIZE to CFG_TUD_MSC_EP_BUFSIZE
- CFG_TUD_MIDI_EPSIZE to CFG_TUD_MIDI_EP_BUFSIZE
-
+
- HID:
- Fix gamepad template descriptor
- Add multiple HID interface API
@@ -700,7 +523,7 @@ USB Host
- Rework USB host stack (still work in progress)
- Fix compile error with pipehandle
- Rework usbh control and enumeration as non-blocking
-
+
- Improve Hub, MSC, HID host driver
Examples
@@ -713,7 +536,7 @@ Examples
- Enhance `net_lwip_webserver` example
- Add multiple configuration: RNDIS for Windows, CDC-ECM for macOS (Linux will work with both)
- Update lwip to STABLE-2_1_2_RELEASE for net_lwip_webserver
-
+
- Added new Audio example: audio_test uac2_headsest
New Boards
@@ -779,7 +602,7 @@ Changed
- Generalized dcd_stm32f4.c to dcd_synopsys.c
- Changed cdc_msc_hid to cdc_msc (drop hid) due to limited endpoints number of some MCUs
- Improved DCD SAMD stability, fix missing setup packet occasionally
-- Improved usbd/usbd_control with proper handling of zero-length packet (ZLP)
+- Improved usbd/usbd_control with proper hanlding of zero-length packet (ZLP)
- Improved STM32 DCD FSDev
- Improved STM32 DCD Synopsys
- Migrated CI from Travis to Github Action
diff --git a/docs/reference/dependencies.rst b/docs/reference/dependencies.rst
deleted file mode 100644
index 130527e2c..000000000
--- a/docs/reference/dependencies.rst
+++ /dev/null
@@ -1,64 +0,0 @@
-************
-Dependencies
-************
-
-MCU low-level peripheral driver and external libraries for building TinyUSB examples
-
-======================================== ============================================================== ========================================
-Path Project Commit
-======================================== ============================================================== ========================================
-hw/mcu/allwinner https://github.com/hathach/allwinner_driver.git 8e5e89e8e132c0fd90e72d5422e5d3d68232b756
-hw/mcu/bridgetek/ft9xx/ft90x-sdk https://github.com/BRTSG-FOSS/ft90x-sdk.git 91060164afe239fcb394122e8bf9eb24d3194eb1
-hw/mcu/broadcom https://github.com/adafruit/broadcom-peripherals.git 08370086080759ed54ac1136d62d2ad24c6fa267
-hw/mcu/gd/nuclei-sdk https://github.com/Nuclei-Software/nuclei-sdk.git 7eb7bfa9ea4fbeacfafe1d5f77d5a0e6ed3922e7
-hw/mcu/infineon/mtb-xmclib-cat3 https://github.com/Infineon/mtb-xmclib-cat3.git daf5500d03cba23e68c2f241c30af79cd9d63880
-hw/mcu/microchip https://github.com/hathach/microchip_driver.git 9e8b37e307d8404033bb881623a113931e1edf27
-hw/mcu/mindmotion/mm32sdk https://github.com/hathach/mm32sdk.git 0b79559eb411149d36e073c1635c620e576308d4
-hw/mcu/nordic/nrfx https://github.com/NordicSemiconductor/nrfx.git 281cc2e178fd9a470d844b3afdea9eb322a0b0e8
-hw/mcu/nuvoton https://github.com/majbthrd/nuc_driver.git 2204191ec76283371419fbcec207da02e1bc22fa
-hw/mcu/nxp/lpcopen https://github.com/hathach/nxp_lpcopen.git 43c45c85405a5dd114fff0ea95cca62837740c13
-hw/mcu/nxp/mcux-sdk https://github.com/NXPmicro/mcux-sdk.git ae2ab01d9d70ad00cd0e935c2552bd5f0e5c0294
-hw/mcu/nxp/nxp_sdk https://github.com/hathach/nxp_sdk.git 845c8fc49b6fb660f06a5c45225494eacb06f00c
-hw/mcu/raspberry_pi/Pico-PIO-USB https://github.com/sekigon-gonnoc/Pico-PIO-USB.git c3715ce94b6f6391856de56081d4d9b3e98fa93d
-hw/mcu/renesas/fsp https://github.com/renesas/fsp.git 8dc14709f2a6518b43f71efad70d900b7718d9f1
-hw/mcu/renesas/rx https://github.com/kkitayam/rx_device.git 706b4e0cf485605c32351e2f90f5698267996023
-hw/mcu/silabs/cmsis-dfp-efm32gg12b https://github.com/cmsis-packs/cmsis-dfp-efm32gg12b.git f1c31b7887669cb230b3ea63f9b56769078960bc
-hw/mcu/sony/cxd56/spresense-exported-sdk https://github.com/sonydevworld/spresense-exported-sdk.git 2ec2a1538362696118dc3fdf56f33dacaf8f4067
-hw/mcu/st/cmsis_device_f0 https://github.com/STMicroelectronics/cmsis_device_f0.git 2fc25ee22264bc27034358be0bd400b893ef837e
-hw/mcu/st/cmsis_device_f1 https://github.com/STMicroelectronics/cmsis_device_f1.git 6601104a6397299b7304fd5bcd9a491f56cb23a6
-hw/mcu/st/cmsis_device_f2 https://github.com/STMicroelectronics/cmsis_device_f2.git 182fcb3681ce116816feb41b7764f1b019ce796f
-hw/mcu/st/cmsis_device_f3 https://github.com/STMicroelectronics/cmsis_device_f3.git 5e4ee5ed7a7b6c85176bb70a9fd3c72d6eb99f1b
-hw/mcu/st/cmsis_device_f4 https://github.com/STMicroelectronics/cmsis_device_f4.git 2615e866fa48fe1ff1af9e31c348813f2b19e7ec
-hw/mcu/st/cmsis_device_f7 https://github.com/STMicroelectronics/cmsis_device_f7.git fc676ef1ad177eb874eaa06444d3d75395fc51f4
-hw/mcu/st/cmsis_device_g0 https://github.com/STMicroelectronics/cmsis_device_g0.git 08258b28ee95f50cb9624d152a1cbf084be1f9a5
-hw/mcu/st/cmsis_device_g4 https://github.com/STMicroelectronics/cmsis_device_g4.git ce822adb1dc552b3aedd13621edbc7fdae124878
-hw/mcu/st/cmsis_device_h7 https://github.com/STMicroelectronics/cmsis_device_h7.git 60dc2c913203dc8629dc233d4384dcc41c91e77f
-hw/mcu/st/cmsis_device_l0 https://github.com/STMicroelectronics/cmsis_device_l0.git 06748ca1f93827befdb8b794402320d94d02004f
-hw/mcu/st/cmsis_device_l1 https://github.com/STMicroelectronics/cmsis_device_l1.git 7f16ec0a1c4c063f84160b4cc6bf88ad554a823e
-hw/mcu/st/cmsis_device_l4 https://github.com/STMicroelectronics/cmsis_device_l4.git 6ca7312fa6a5a460b5a5a63d66da527fdd8359a6
-hw/mcu/st/cmsis_device_l5 https://github.com/STMicroelectronics/cmsis_device_l5.git d922865fc0326a102c26211c44b8e42f52c1e53d
-hw/mcu/st/cmsis_device_u5 https://github.com/STMicroelectronics/cmsis_device_u5.git bc00f3c9d8a4e25220f84c26d414902cc6bdf566
-hw/mcu/st/cmsis_device_wb https://github.com/STMicroelectronics/cmsis_device_wb.git 9c5d1920dd9fabbe2548e10561d63db829bb744f
-hw/mcu/st/stm32f0xx_hal_driver https://github.com/STMicroelectronics/stm32f0xx_hal_driver.git 0e95cd88657030f640a11e690a8a5186c7712ea5
-hw/mcu/st/stm32f1xx_hal_driver https://github.com/STMicroelectronics/stm32f1xx_hal_driver.git 1dd9d3662fb7eb2a7f7d3bc0a4c1dc7537915a29
-hw/mcu/st/stm32f2xx_hal_driver https://github.com/STMicroelectronics/stm32f2xx_hal_driver.git c75ace9b908a9aca631193ebf2466963b8ea33d0
-hw/mcu/st/stm32f3xx_hal_driver https://github.com/STMicroelectronics/stm32f3xx_hal_driver.git 1761b6207318ede021706e75aae78f452d72b6fa
-hw/mcu/st/stm32f4xx_hal_driver https://github.com/STMicroelectronics/stm32f4xx_hal_driver.git 04e99fbdabd00ab8f370f377c66b0a4570365b58
-hw/mcu/st/stm32f7xx_hal_driver https://github.com/STMicroelectronics/stm32f7xx_hal_driver.git f7ffdf6bf72110e58b42c632b0a051df5997e4ee
-hw/mcu/st/stm32g0xx_hal_driver https://github.com/STMicroelectronics/stm32g0xx_hal_driver.git 5b53e6cee664a82b16c86491aa0060e2110c00cb
-hw/mcu/st/stm32g4xx_hal_driver https://github.com/STMicroelectronics/stm32g4xx_hal_driver.git 8b4518417706d42eef5c14e56a650005abf478a8
-hw/mcu/st/stm32h7xx_hal_driver https://github.com/STMicroelectronics/stm32h7xx_hal_driver.git d8461b980b59b1625207d8c4f2ce0a9c2a7a3b04
-hw/mcu/st/stm32l0xx_hal_driver https://github.com/STMicroelectronics/stm32l0xx_hal_driver.git fbdacaf6f8c82a4e1eb9bd74ba650b491e97e17b
-hw/mcu/st/stm32l1xx_hal_driver https://github.com/STMicroelectronics/stm32l1xx_hal_driver.git 44efc446fa69ed8344e7fd966e68ed11043b35d9
-hw/mcu/st/stm32l4xx_hal_driver https://github.com/STMicroelectronics/stm32l4xx_hal_driver.git aee3d5bf283ae5df87532b781bdd01b7caf256fc
-hw/mcu/st/stm32l5xx_hal_driver https://github.com/STMicroelectronics/stm32l5xx_hal_driver.git 675c32a75df37f39d50d61f51cb0dcf53f07e1cb
-hw/mcu/st/stm32u5xx_hal_driver https://github.com/STMicroelectronics/stm32u5xx_hal_driver.git 2e1d4cdb386e33391cb261dfff4fefa92e4aa35a
-hw/mcu/st/stm32wbxx_hal_driver https://github.com/STMicroelectronics/stm32wbxx_hal_driver.git 2c5f06638be516c1b772f768456ba637f077bac8
-hw/mcu/ti https://github.com/hathach/ti_driver.git 143ed6cc20a7615d042b03b21e070197d473e6e5
-hw/mcu/wch/ch32v307 https://github.com/openwch/ch32v307.git 17761f5cf9dbbf2dcf665b7c04934188add20082
-lib/CMSIS_5 https://github.com/ARM-software/CMSIS_5.git 20285262657d1b482d132d20d755c8c330d55c1f
-lib/FreeRTOS-Kernel https://github.com/FreeRTOS/FreeRTOS-Kernel.git def7d2df2b0506d3d249334974f51e427c17a41c
-lib/lwip https://github.com/lwip-tcpip/lwip.git 159e31b689577dbf69cf0683bbaffbd71fa5ee10
-lib/sct_neopixel https://github.com/gsteiert/sct_neopixel.git e73e04ca63495672d955f9268e003cffe168fcd8
-tools/uf2 https://github.com/microsoft/uf2.git 19615407727073e36d81bf239c52108ba92e7660
-======================================== ============================================================== ========================================
diff --git a/docs/reference/getting_started.rst b/docs/reference/getting_started.rst
index 1f41cb888..875372c81 100644
--- a/docs/reference/getting_started.rst
+++ b/docs/reference/getting_started.rst
@@ -37,43 +37,39 @@ It is relatively simple to incorporate tinyusb to your (existing) project
Examples
--------
-For your convenience, TinyUSB contains a handful of examples for both host and device with/without RTOS to quickly test the functionality as well as demonstrate how API() should be used. Most examples will work on most of `the supported boards `_. Firstly we need to ``git clone`` if not already
+For your convenience, TinyUSB contains a handful of examples for both host and device with/without RTOS to quickly test the functionality as well as demonstrate how API() should be used. Most examples will work on most of `the supported Boards `_. Firstly we need to ``git clone`` if not already
.. code-block::
$ git clone https://github.com/hathach/tinyusb tinyusb
$ cd tinyusb
-Some ports will also require a port-specific SDK (e.g. RP2040) or binary (e.g. Sony Spresense) to build examples. They are out of scope for tinyusb, you should download/install it first according to its manufacturer guide.
+Some TinyUSB examples also requires external submodule libraries in ``/lib`` such as FreeRTOS, Lightweight IP to build. Run following command to fetch them
+
+.. code-block::
+
+ $ git submodule update --init lib
+
+In addition, MCU driver submodule is also needed to provide low-level MCU peripheral's driver. Luckily, it will be fetched if needed when you run the ``make`` to build your board.
+
+Note: some examples especially those that uses Vendor class (e.g webUSB) may requires udev permission on Linux (and/or macOS) to access usb device. It depends on your OS distro, typically copy ``/examples/device/99-tinyusb.rules`` file to /etc/udev/rules.d/ then run ``sudo udevadm control --reload-rules && sudo udevadm trigger`` is good enough.
Build
^^^^^
-To build example, first change directory to an example folder.
+To build example, first change directory to an example folder.
.. code-block::
$ cd examples/device/cdc_msc
-Before building, we firstly need to download dependencies such as: MCU low-level peripheral driver and external libraries e.g FreeRTOS (required by some examples). Run the ``get-deps`` target in one of the example folder as follow. You only need to do this once per mcu. Check out `complete list of dependencies and their designated path here `_
-
-.. code-block::
-
- $ make BOARD=raspberry_pi_pico get-deps
-
Then compile with ``make BOARD=[board_name] all``\ , for example
.. code-block::
- $ make BOARD=raspberry_pi_pico all
+ $ make BOARD=feather_nrf52840_express all
Note: ``BOARD`` can be found as directory name in ``hw/bsp``\ , either in its family/boards or directly under bsp (no family).
-Note: some examples especially those that uses Vendor class (e.g webUSB) may requires udev permission on Linux (and/or macOS) to access usb device. It depends on your OS distro, typically copy ``99-tinyusb.rules`` and reload your udev is good to go
-
-.. code-block::
-
- $ cp examples/device/99-tinyusb.rules /etc/udev/rules.d/
- $ sudo udevadm control --reload-rules && sudo udevadm trigger
Port Selection
~~~~~~~~~~~~~~
@@ -114,7 +110,7 @@ To compile for debugging add ``DEBUG=1``\ , for example
Log
~~~
-Should you have an issue running example and/or submitting an bug report. You could enable TinyUSB built-in debug logging with optional ``LOG=``. LOG=1 will only print out error message, LOG=2 print more information with on-going events. LOG=3 or higher is not used yet.
+Should you have an issue running example and/or submitting an bug report. You could enable TinyUSB built-in debug logging with optional ``LOG=``. LOG=1 will only print out error message, LOG=2 print more information with on-going events. LOG=3 or higher is not used yet.
.. code-block::
@@ -123,7 +119,7 @@ Should you have an issue running example and/or submitting an bug report. You co
Logger
~~~~~~
-By default log message is printed via on-board UART which is slow and take lots of CPU time comparing to USB speed. If your board support on-board/external debugger, it would be more efficient to use it for logging. There are 2 protocols:
+By default log message is printed via on-board UART which is slow and take lots of CPU time comparing to USB speed. If your board support on-board/external debugger, it would be more efficient to use it for logging. There are 2 protocols:
* `LOGGER=rtt`: use `Segger RTT protocol `_
@@ -174,12 +170,12 @@ IAR Project Connection files are provided to import TinyUSB stack into your proj
* Take example of STM32F0:
-
+
- You need `stm32l0xx.h`, `startup_stm32f0xx.s`, `system_stm32f0xx.c`.
- `STM32L0xx_HAL_Driver` is only needed to run examples, TinyUSB stack itself doesn't rely on MCU's SDKs.
-* Open `Tools -> Configure Custom Argument Variables` (Switch to `Global` tab if you want to do it for all your projects)
+* Open `Tools -> Configure Custom Argument Variables` (Switch to `Global` tab if you want to do it for all your projects)
Click `New Group ...`, name it to `TUSB`, Click `Add Variable ...`, name it to `TUSB_DIR`, change it's value to the path of your TinyUSB stack,
for example `C:\\tinyusb`
diff --git a/docs/reference/index.rst b/docs/reference/index.rst
index a9663ee7d..fcff03590 100644
--- a/docs/reference/index.rst
+++ b/docs/reference/index.rst
@@ -25,7 +25,7 @@ Supports multiple device configurations by dynamically changing usb descriptors.
- Vendor-specific class support with generic In & Out endpoints. Can be used with MS OS 2.0 compatible descriptor to load winUSB driver without INF file.
- `WebUSB `__ with vendor-specific class
-If you have special need, `usbd_app_driver_get_cb()` can be used to write your own class driver without modifying the stack. Here is how RPi team add their reset interface `raspberrypi/pico-sdk#197 `__
+If you have special need, `usbd_app_driver_get_cb()` can be used to write your own class driver without modifying the stack. Here is how RPi team add their reset interface [raspberrypi/pico-sdk#197](https://github.com/raspberrypi/pico-sdk/pull/197)
Host Stack
==========
@@ -41,7 +41,7 @@ TinyUSB is completely thread-safe by pushing all ISR events into a central queue
- **No OS**
- **FreeRTOS**
-- **Mynewt** Due to the newt package build system, Mynewt examples are better to be on its `own repo `__
+- **Mynewt** Due to the newt package build system, Mynewt examples are better to be on its [own repo](https://github.com/hathach/mynewt-tinyusb-example)
License
=======
@@ -56,5 +56,4 @@ Index
supported
getting_started
- dependencies
concurrency
diff --git a/docs/reference/supported.rst b/docs/reference/supported.rst
index aed64782c..c8a441f18 100644
--- a/docs/reference/supported.rst
+++ b/docs/reference/supported.rst
@@ -2,124 +2,126 @@
Supported Devices
*****************
+
Supported MCUs
==============
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| Manufacturer | Family | Device | Host | Highspeed | Driver | Note |
-+==============+=======================+========+======+===========+===================+==============+
-| Broadcom | BCM2711, BCM2837 | ✔ | | ✔ | dwc2 | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| Dialog | DA1469x | ✔ | ✖ | ✖ | da146xx | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| Espressif | ESP32 S2, S3 | ✔ | | ✖ | dwc2 or esp32sx | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| GigaDevice | GD32VF103 | ✔ | | ✖ | dwc2 | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| Infineon | XMC4500 | ✔ | | ✖ | dwc2 | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| MicroChip | SAM D11, D21 | ✔ | | ✖ | samd | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | SAM D51, E5x | ✔ | | ✖ | samd | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | SAM G55 | ✔ | | ✖ | samg | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | SAM L21, L22 | ✔ | | ✖ | samd | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | SAM E70,S70,V70,V71 | ✔ | | ✔ | samx7x | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| NordicSemi | nRF52833, nRF52840 | ✔ | ✖ | ✖ | nrf5x | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | nRF5340 | ✔ | ✖ | ✖ | nrf5x | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| Nuvoton | NUC120 | ✔ | ✖ | ✖ | | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | NUC121/NUC125 | ✔ | ✖ | ✖ | | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | NUC126 | ✔ | ✖ | ✖ | | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | NUC505 | ✔ | | ✔ | | |
-+--------------+---------+-------------+--------+------+-----------+-------------------+--------------+
-| NXP | iMXRT | RT10xx | ✔ | ✔ | ✔ | ci_hs | |
-| | +-------------+--------+------+-----------+-------------------+--------------+
-| | | RT11xx | ✔ | ✔ | ✔ | ci_hs | |
-| +---------+-------------+--------+------+-----------+-------------------+--------------+
-| | Kinetis | KL25 | ✔ | ⚠ | ✖ | | |
-| | +-------------+--------+------+-----------+-------------------+--------------+
-| | | K32L2 | ✔ | | ✖ | | |
-| +---------+-------------+--------+------+-----------+-------------------+--------------+
-| | LPC | 11u, 13, 15 | ✔ | ✖ | ✖ | lpc_ip3511 | |
-| | +-------------+--------+------+-----------+-------------------+--------------+
-| | | 17, 40 | ✔ | ⚠ | ✖ | lpc17_40 | |
-| | +-------------+--------+------+-----------+-------------------+--------------+
-| | | 18, 43 | ✔ | ✔ | ✔ | ci_hs | |
-| | +-------------+--------+------+-----------+-------------------+--------------+
-| | | 51u | ✔ | ✖ | ✖ | lpc_ip3511 | |
-| | +-------------+--------+------+-----------+-------------------+--------------+
-| | | 54 | ✔ | | ✔ | lpc_ip3511 | |
-| | +-------------+--------+------+-----------+-------------------+--------------+
-| | | 55 | ✔ | | ✔ | lpc_ip3511 | |
-+--------------+---------+-------------+--------+------+-----------+-------------------+--------------+
-| Raspberry Pi | RP2040 | ✔ | ✔ | ✖ | rp2040, pio_usb | |
-+--------------+-----+-----------------+--------+------+-----------+-------------------+--------------+
-| Renesas | RX | 63N, 65N, 72N | ✔ | ✔ | ✖ | rusb2 | |
-| +-----+-----------------+--------+------+-----------+-------------------+--------------+
-| | RA | XXX | ✔ | ✔ | | rusb2 | |
-+--------------+-----+-----------------+--------+------+-----------+-------------------+--------------+
-| Silabs | EFM32GG12 | ✔ | | ✖ | dwc2 | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| Sony | CXD56 | ✔ | ✖ | ✔ | cxd56 | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| ST STM32 | F0 | ✔ | ✖ | ✖ | stm32_fsdev | |
-| +----+------------------+--------+------+-----------+-------------------+--------------+
-| | F1 | 102, 103 | ✔ | ✖ | ✖ | stm32_fsdev | |
-| | +------------------+--------+------+-----------+-------------------+--------------+
-| | | 105, 107 | ✔ | | ✖ | dwc2 | |
-| +----+------------------+--------+------+-----------+-------------------+--------------+
-| | F2 | ✔ | | ✔ | dwc2 | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | F3 | ✔ | ✖ | ✖ | stm32_fsdev | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | F4 | ✔ | | ✔ | dwc2 | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | F7 | ✔ | | ✔ | dwc2 | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | H7 | ✔ | | ✔ | dwc2 | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | G4 | ✔ | ✖ | ✖ | stm32_fsdev | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | L0, L1 | ✔ | ✖ | ✖ | stm32_fsdev | |
-| +----+------------------+--------+------+-----------+-------------------+--------------+
-| | L4 | 4x2, 4x3 | ✔ | ✖ | ✖ | stm32_fsdev | |
-| | +------------------+--------+------+-----------+-------------------+--------------+
-| | | 4x5, 4x6 | ✔ | | | dwc2 | |
-| +----+------------------+--------+------+-----------+-------------------+--------------+
-| | L4+ | ✔ | | | dwc2 | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | U5 | ⚠ | | | dwc2 | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | WBx5 | ✔ | | | stm32_fsdev | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| TI | MSP430 | ✔ | ✖ | ✖ | msp430x5xx | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | MSP432E4 | ✔ | | ✖ | musb | |
-| +-----------------------+--------+------+-----------+-------------------+--------------+
-| | TM4C123 | ✔ | | ✖ | musb | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| ValentyUSB | eptri | ✔ | ✖ | ✖ | eptri | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
-| WCH | CH32V307 | ✔ | | ✔ | ch32v307 | |
-+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
+.. admonition:: Warning
+ :class: warning
+ This table is a WIP! the data is not correct, tho if a device is listed, it likely works as a usb full speed device at the least.
+
++--------------+--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| Manufacturer | Family | Device | Host | FS | HS | Known Issues |
++==============+====================+===================+====================+===================+===================+==============+
+| Dialog | DA1469x | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
++--------------+--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| Espressif | ESP32-S2 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | ESP32-S3 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
++--------------+--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| MicroChip | SAMD11 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | SAMD21 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | SAMD51 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | SAME5x | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | SAMG55 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | SAML21 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | SAML22 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | SAME70,S70,V70,V71 | |:green_square:| | |:red_square:| | |:green_square:| | |:green_square:| | |
++--------------+--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| NordicSemi | nRF52833 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | nRF52840 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
++--------------+--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| Nuvoton | NUC120 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | NUC121/NUC125 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | NUC126 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | NUC505 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
++--------------+-------+------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| NXP | iMX | RT1011 | |:green_square:| | |:yellow_square:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | RT1015 | |:green_square:| | |:yellow_square:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | RT1021 | |:green_square:| | |:yellow_square:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | RT1052 | |:green_square:| | |:yellow_square:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | RT1062 | |:green_square:| | |:yellow_square:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | RT1064 | |:green_square:| | |:yellow_square:| | |:green_square:| | |:x:| | |
+| +-------+------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | Kinetis KL25 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| +-------+------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | LPC | 11u | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | 13 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | 15 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | 17 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | 18 | | |:yellow_square:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | 40 | | |:x:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | 43 | |:green_square:| | |:yellow_square:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | 51u | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | 54 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | 55 | |:green_square:| | |:x:| | |:green_square:| | | |
++--------------+-------+------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| Raspberry Pi | RP2040 | |:green_square:| | |:x:| | |:green_square:| | | |
++--------------+--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| Renesas | RX63N | |:green_square:| | | |:green_square:| | |:x:| | |
+| +--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | RX65N | |:green_square:| | | |:green_square:| | |:x:| | |
++--------------+--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| Silabs | EFM32GG12 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | #750 |
++--------------+--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| Sony | CXD56 | |:green_square:| | |:x:| | |:green_square:| | |:x:| | |
++--------------+-------+------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| ST | STM32 | L0 | |:green_square:| | | |:green_square:| | | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | F0 | |:green_square:| | | |:green_square:| | | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | F1 | |:green_square:| | | |:green_square:| | | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | F2 | |:green_square:| | | |:green_square:| | | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | F3 | |:green_square:| | | |:green_square:| | | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | F4 | |:green_square:| | | |:green_square:| | | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | F7 | |:green_square:| | | |:green_square:| | | |
+| | +------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| | | H7 | |:green_square:| | | |:green_square:| | |:green_square:| | |
++--------------+-------+------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| TI | MSP430 | |:green_square:| | | |:green_square:| | | |
++--------------+--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
+| ValentyUSB | eptri | |:green_square:| | | |:green_square:| | | |
++--------------+--------------------+-------------------+--------------------+-------------------+-------------------+--------------+
Table Legend
------------
-= ===================
-✔ Supported
-⚠ WIP/partial support
-✖ Not supported
-= ===================
+================= ===================
+|:x:| Not available
+|:red_square:| Not supported
+|:yellow_square:| WIP/partial support
+|:green_square:| Supported
+================= ===================
Supported Boards
================
@@ -132,11 +134,6 @@ The board support code is only used for self-contained examples and testing. It
The following boards are supported (sorted alphabetically):
-Broadcom
---------
-
-- `Raspberry Pi CM4 `__
-
Dialog DA146xx
--------------
@@ -146,25 +143,12 @@ Dialog DA146xx
Espressif ESP32-S2
------------------
-- `Adafruit Feather ESP32-S2 `__
+- Adafruit Feather ESP32-S2
- `Adafruit Magtag 2.9" E-Ink WiFi Display `__
- `Adafruit Metro ESP32-S2 `__
- `ESP32-S2-Kaluga-1 `__
- `ESP32-S2-Saola-1 `__
-GigaDevice
-----------
-
-- `Sipeed Longan Nano `__
-
-Infineon
----------
-
-XMC4000
-^^^^^^^
-
-- `XMC4500 Relax (Lite) Kit `__
-
MicroChip
---------
@@ -175,7 +159,7 @@ SAMD11 & SAMD21
- `Adafruit Feather M0 Express `__
- `Adafruit ItsyBitsy M0 Express `__
- `Adafruit Metro M0 Express `__
-- `Great Scott Gadgets Cynthion `__
+- `Great Scott Gadgets LUNA `__
- `Microchip SAMD11 Xplained Pro `__
- `Microchip SAMD21 Xplained Pro `__
- `Seeeduino Xiao `__
@@ -247,15 +231,11 @@ iMX RT
- `MIMX RT1060 Evaluation Kit `__
- `MIMX RT1064 Evaluation Kit `__
- `Teensy 4.0 Development Board `__
-- `Teensy 4.1 Development Board `__
Kinetis
^^^^^^^
-- `Freedom FRDM-KL25Z `__
-- `Freedom FRDM-K32L2A4S `__
-- `Freedom FRDM-K32L2B3 `__
-- `KUIIC `__
+- `FRDM-KL25Z `__
LPC 11-13-15
^^^^^^^^^^^^
@@ -298,17 +278,8 @@ LPC55
- `LPCXpresso 55s69 EVK `__
- `MCU-Link `__
-Renesas
--------
-
-RA
-^^
-
-- `Evaluation Kit for RA4M1 `__
-- `Evaluation Kit for RA4M3 `__
-
-RX
-^^
+Renesas RX
+----------
- `GR-CITRUS `__
- `Renesas RX65N Target Board `__
@@ -334,85 +305,40 @@ Sony
ST STM32
--------
-F0
-^^
+- `Adafruit Feather STM32F405 `__
+- `Micro Python PyBoard v1.1 `__
+- `STLink-V3 Mini `__
+- `STM32 L035c8 Discovery `__
+- `STM32 L4R5zi Nucleo `__
- `STM32 F070rb Nucleo `__
- `STM32 F072 Evaluation `__
- `STM32 F072rb Discovery `__
-
-F1
-^^
- `STM32 F103c8 Blue Pill `__
- `STM32 F103rc Mini v2.0 `__
-
-F2
-^^
- `STM32 F207zg Nucleo `__
-
-F3
-^^
- `STM32 F303vc Discovery `__
-
-F4
-^^
-- `Adafruit Feather STM32F405 `__
-- `Micro Python PyBoard v1.1 `__
- `STM32 F401cc Black Pill `__
- `STM32 F407vg Discovery `__
- `STM32 F411ce Black Pill `__
- `STM32 F411ve Discovery `__
- `STM32 F412zg Discovery `__
- `STM32 F412zg Nucleo `__
-- `STM32 F439zi Nucleo `__
-
-F7
-^^
-
-- `STLink-V3 Mini `__
- `STM32 F723e Discovery `__
- `STM32 F746zg Nucleo `__
- `STM32 F746g Discovery `__
- `STM32 F767zi Nucleo `__
- `STM32 F769i Discovery `__
-
-H7
-^^
- `STM32 H743zi Nucleo `__
- `STM32 H743i Evaluation `__
- `STM32 H745i Discovery `__
- `Waveshare OpenH743I-C `__
-G4
-^^
-- `STM32 G474RE Nucleo `__
-
-L0
-^^
-- `STM32 L035c8 Discovery `__
-
-L4
-^^
-- `STM32 L476vg Discovery `__
-- `STM32 L4P5zg Nucleo `__
-- `STM32 L4R5zi Nucleo `__
-
-WB
-^^
-- `STM32 WB55 Nucleo `__
-
TI
--
- `MSP430F5529 USB LaunchPad Evaluation Kit `__
-- `MSP-EXP432E401Y LaunchPad Evaluation Kit `__
-- `TM4C123GXL LaunchPad Evaluation Kit `__
Tomu
----
- `Fomu `__
-
-WCH
----
-
-- `CH32V307V-R1-1v0 `
diff --git a/docs/requirements.txt b/docs/requirements.txt
index ad5c89922..e415ae03e 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -1,4 +1,4 @@
-sphinx>=5.0
+sphinx~=3.0
furo>=2020.12.30.b24
+sphinxemoji>=0.1.8
sphinx-autodoc-typehints>=1.10
-jinja2>=3.0.3
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
deleted file mode 100644
index c603d0c22..000000000
--- a/examples/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-cmake_minimum_required(VERSION 3.17)
-
-#set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-include(${CMAKE_CURRENT_SOURCE_DIR}/../hw/bsp/family_support.cmake)
-
-project(tinyusb_examples C CXX ASM)
-
-add_subdirectory(device)
-add_subdirectory(dual)
-add_subdirectory(host)
-add_subdirectory(typec)
diff --git a/examples/device/99-tinyusb.rules b/examples/device/99-tinyusb.rules
index d306bada5..e6372ed58 100644
--- a/examples/device/99-tinyusb.rules
+++ b/examples/device/99-tinyusb.rules
@@ -12,10 +12,3 @@ ATTRS{idVendor}=="cafe", MODE="0666", GROUP="dialout"
# Rule to blacklist TinyUSB example from being manipulated by ModemManager.
SUBSYSTEMS=="usb", ATTRS{idVendor}=="cafe", ENV{ID_MM_DEVICE_IGNORE}="1"
-
-# Xplained Pro SamG55 Device
-SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2111", MODE="0666", GROUP="users", ENV{ID_MM_DEVICE_IGNORE}="1"
-SUBSYSTEMS=="tty", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2111", MODE="0666", GROUP="users", ENV{ID_MM_DEVICE_IGNORE}="1"
-
-# TI Stellaris/Tiva-C Launchpad ICDI
-SUBSYSTEM=="usb", ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00fd", MODE="0666"
diff --git a/examples/device/CMakeLists.txt b/examples/device/CMakeLists.txt
index 0a2e49ef0..edf5ab805 100644
--- a/examples/device/CMakeLists.txt
+++ b/examples/device/CMakeLists.txt
@@ -1,23 +1,20 @@
-cmake_minimum_required(VERSION 3.17)
+cmake_minimum_required(VERSION 3.5)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/family_support.cmake)
-project(tinyusb_device_examples C CXX ASM)
+project(tinyusb_device_examples)
family_initialize_project(tinyusb_device_examples ${CMAKE_CURRENT_LIST_DIR})
# family_add_subdirectory will filter what to actually add based on selected FAMILY
family_add_subdirectory(audio_4_channel_mic)
family_add_subdirectory(audio_test)
-family_add_subdirectory(audio_test_multi_rate)
family_add_subdirectory(board_test)
family_add_subdirectory(cdc_dual_ports)
family_add_subdirectory(cdc_msc)
family_add_subdirectory(cdc_msc_freertos)
-family_add_subdirectory(cdc_uac2)
family_add_subdirectory(dfu)
family_add_subdirectory(dfu_runtime)
family_add_subdirectory(dynamic_configuration)
-family_add_subdirectory(hid_boot_interface)
family_add_subdirectory(hid_composite)
family_add_subdirectory(hid_composite_freertos)
family_add_subdirectory(hid_generic_inout)
diff --git a/tools/codespell/exclude-file.txt b/examples/device/audio_4_channel_mic/.skip.MCU_SAMD11
similarity index 100%
rename from tools/codespell/exclude-file.txt
rename to examples/device/audio_4_channel_mic/.skip.MCU_SAMD11
diff --git a/examples/device/audio_4_channel_mic/.skip.MCU_SAME5X b/examples/device/audio_4_channel_mic/.skip.MCU_SAME5X
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/device/audio_4_channel_mic/.skip.MCU_SAMG b/examples/device/audio_4_channel_mic/.skip.MCU_SAMG
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/device/audio_4_channel_mic/CMakeLists.txt b/examples/device/audio_4_channel_mic/CMakeLists.txt
index 0f5d36193..f6e10e2ea 100644
--- a/examples/device/audio_4_channel_mic/CMakeLists.txt
+++ b/examples/device/audio_4_channel_mic/CMakeLists.txt
@@ -1,38 +1,28 @@
-cmake_minimum_required(VERSION 3.17)
+cmake_minimum_required(VERSION 3.5)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
# gets PROJECT name for the example (e.g. -)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
# Example source
target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- )
+)
# Example include
target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
- )
+)
-# Add libm for GCC
-if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_link_libraries(${PROJECT} PUBLIC m)
-endif()
-
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
diff --git a/examples/device/audio_4_channel_mic/Makefile b/examples/device/audio_4_channel_mic/Makefile
index 8ee6a01ec..5a455078e 100644
--- a/examples/device/audio_4_channel_mic/Makefile
+++ b/examples/device/audio_4_channel_mic/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
@@ -5,10 +6,7 @@ INC += \
$(TOP)/hw \
# Example source
-EXAMPLE_SOURCE += \
- src/main.c \
- src/usb_descriptors.c \
-
+EXAMPLE_SOURCE += $(wildcard src/*.c)
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
include ../../rules.mk
diff --git a/examples/device/audio_4_channel_mic/skip.txt b/examples/device/audio_4_channel_mic/skip.txt
deleted file mode 100644
index 3c42a96d9..000000000
--- a/examples/device/audio_4_channel_mic/skip.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-mcu:SAMD11
-mcu:SAME5X
-mcu:SAMG
-family:broadcom_64bit
diff --git a/examples/device/audio_4_channel_mic/src/main.c b/examples/device/audio_4_channel_mic/src/main.c
index 9c37315c8..983b87e5b 100644
--- a/examples/device/audio_4_channel_mic/src/main.c
+++ b/examples/device/audio_4_channel_mic/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Reinhard Panhuber
@@ -34,16 +34,17 @@
#include
#include
#include
-#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
-#include "tusb_config.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+
-#define AUDIO_SAMPLE_RATE CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE
+
+#ifndef AUDIO_SAMPLE_RATE
+#define AUDIO_SAMPLE_RATE 48000
+#endif
/* Blink pattern
* - 250 ms : device not mounted
@@ -69,13 +70,8 @@ uint8_t clkValid;
audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX+1]; // Volume range state
audio_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
-#if CFG_TUD_AUDIO_ENABLE_ENCODING
-// Audio test data, each buffer contains 2 channels, buffer[0] for CH0-1, buffer[1] for CH1-2
+// Audio test data
uint16_t i2s_dummy_buffer[CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO][CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ/2]; // Ensure half word aligned
-#else
-// Audio test data, 4 channels muxed together, buffer[0] for CH0, buffer[1] for CH1, buffer[2] for CH2, buffer[3] for CH3
-uint16_t i2s_dummy_buffer[CFG_TUD_AUDIO_EP_SZ_IN]; // Ensure half word aligned
-#endif
void led_blinking_task(void);
void audio_task(void);
@@ -85,12 +81,7 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
// Init values
sampFreq = AUDIO_SAMPLE_RATE;
@@ -101,51 +92,15 @@ int main(void)
sampleFreqRng.subrange[0].bMax = AUDIO_SAMPLE_RATE;
sampleFreqRng.subrange[0].bRes = 0;
- // Generate dummy data
-#if CFG_TUD_AUDIO_ENABLE_ENCODING
- uint16_t * p_buff = i2s_dummy_buffer[0];
- uint16_t dataVal = 1;
- for (uint16_t cnt = 0; cnt < AUDIO_SAMPLE_RATE/1000; cnt++)
- {
- // CH0 saw wave
- *p_buff++ = dataVal;
- // CH1 inverted saw wave
- *p_buff++ = 60 + AUDIO_SAMPLE_RATE/1000 - dataVal;
- dataVal++;
- }
- p_buff = i2s_dummy_buffer[1];
- for (uint16_t cnt = 0; cnt < AUDIO_SAMPLE_RATE/1000; cnt++)
- {
- // CH3 square wave
- *p_buff++ = cnt < (AUDIO_SAMPLE_RATE/1000/2) ? 120:170;
- // CH4 sinus wave
- float t = 2*3.1415f * cnt / (AUDIO_SAMPLE_RATE/1000);
- *p_buff++ = (uint16_t)(sinf(t) * 25) + 200;
- }
-#else
- uint16_t * p_buff = i2s_dummy_buffer;
- uint16_t dataVal = 1;
- for (uint16_t cnt = 0; cnt < AUDIO_SAMPLE_RATE/1000; cnt++)
- {
- // CH0 saw wave
- *p_buff++ = dataVal;
- // CH1 inverted saw wave
- *p_buff++ = 60 + AUDIO_SAMPLE_RATE/1000 - dataVal;
- dataVal++;
- // CH3 square wave
- *p_buff++ = cnt < (AUDIO_SAMPLE_RATE/1000/2) ? 120:170;
- // CH4 sinus wave
- float t = 2*3.1415f * cnt / (AUDIO_SAMPLE_RATE/1000);
- *p_buff++ = (uint16_t)(sinf(t) * 25) + 200;
- }
-#endif
-
while (1)
{
tud_task(); // tinyusb device task
led_blinking_task();
audio_task();
}
+
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -176,7 +131,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
@@ -186,7 +141,7 @@ void tud_resume_cb(void)
void audio_task(void)
{
// Yet to be filled - e.g. put meas data into TX FIFOs etc.
- // asm("nop");
+ asm("nop");
}
//--------------------------------------------------------------------+
@@ -265,7 +220,7 @@ bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
// Request uses format layout 2
TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_2_t));
- volume[channelNum] = (uint16_t) ((audio_control_cur_2_t*) pBuff)->bCur;
+ volume[channelNum] = ((audio_control_cur_2_t*) pBuff)->bCur;
TU_LOG2(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
return true;
@@ -334,7 +289,7 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
// Those are dummy values for now
ret.bNrChannels = 1;
- ret.bmChannelConfig = (audio_channel_config_t) 0;
+ ret.bmChannelConfig = 0;
ret.iChannelNames = 0;
TU_LOG2(" Get terminal connector\r\n");
@@ -407,8 +362,7 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
{
case AUDIO_CS_REQ_CUR:
TU_LOG2(" Get Sample Freq.\r\n");
- // Buffered control transfer is needed for IN flow control to work
- return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &sampFreq, sizeof(sampFreq));
+ return tud_control_xfer(rhport, p_request, &sampFreq, sizeof(sampFreq));
case AUDIO_CS_REQ_RANGE:
TU_LOG2(" Get Sample Freq. range\r\n");
@@ -444,24 +398,11 @@ bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t itf, uint8_t ep_in, u
(void) ep_in;
(void) cur_alt_setting;
-
- // In read world application data flow is driven by I2S clock,
- // both tud_audio_tx_done_pre_load_cb() & tud_audio_tx_done_post_load_cb() are hardly used.
- // For example in your I2S receive callback:
- // void I2S_Rx_Callback(int channel, const void* data, uint16_t samples)
- // {
- // tud_audio_write_support_ff(channel, data, samples * N_BYTES_PER_SAMPLE * N_CHANNEL_PER_FIFO);
- // }
-
-#if CFG_TUD_AUDIO_ENABLE_ENCODING
- // Write I2S buffer into FIFO
- for (uint8_t cnt=0; cnt < 2; cnt++)
+ for (uint8_t cnt=0; cnt < CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO; cnt++)
{
tud_audio_write_support_ff(cnt, i2s_dummy_buffer[cnt], AUDIO_SAMPLE_RATE/1000 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX);
}
-#else
- tud_audio_write(i2s_dummy_buffer, AUDIO_SAMPLE_RATE/1000 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX);
-#endif
+
return true;
}
@@ -473,6 +414,22 @@ bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uin
(void) ep_in;
(void) cur_alt_setting;
+ uint16_t dataVal;
+
+ // Generate dummy data
+ for (uint16_t cnt = 0; cnt < CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO; cnt++)
+ {
+ uint16_t * p_buff = i2s_dummy_buffer[cnt]; // 2 bytes per sample
+ dataVal = 1;
+ for (uint16_t cnt2 = 0; cnt2 < AUDIO_SAMPLE_RATE/1000; cnt2++)
+ {
+ for (uint8_t cnt3 = 0; cnt3 < CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX; cnt3++)
+ {
+ *p_buff++ = dataVal;
+ }
+ dataVal++;
+ }
+ }
return true;
}
diff --git a/examples/device/audio_4_channel_mic/src/plot_audio_samples.py b/examples/device/audio_4_channel_mic/src/plot_audio_samples.py
index d17a908b6..9ab15135d 100644
--- a/examples/device/audio_4_channel_mic/src/plot_audio_samples.py
+++ b/examples/device/audio_4_channel_mic/src/plot_audio_samples.py
@@ -10,11 +10,11 @@ if __name__ == '__main__':
# print(sd.query_devices())
fs = 48000 # Sample rate
- duration = 1 # Duration of recording
+ duration = 100e-3 # Duration of recording
if platform.system() == 'Windows':
# WDM-KS is needed since there are more than one MicNode device APIs (at least in Windows)
- device = 'Microphone (MicNode_4_Ch), Windows WASAPI'
+ device = 'Microphone (MicNode_4_Ch), Windows WDM-KS'
elif platform.system() == 'Darwin':
device = 'MicNode_4_Ch'
else:
@@ -25,13 +25,10 @@ if __name__ == '__main__':
sd.wait() # Wait until recording is finished
print('Done!')
-
time = np.arange(0, duration, 1 / fs) # time vector
- # strip starting zero
-
plt.plot(time, myrecording)
plt.xlabel('Time [s]')
plt.ylabel('Amplitude')
plt.title('MicNode 4 Channel')
- plt.legend(['CH-1', 'CH-2', 'CH-3','CH-4'])
plt.show()
+
\ No newline at end of file
diff --git a/examples/device/audio_4_channel_mic/src/tusb_config.h b/examples/device/audio_4_channel_mic/src/tusb_config.h
index cf44918e2..44be5a0d7 100644
--- a/examples/device/audio_4_channel_mic/src/tusb_config.h
+++ b/examples/device/audio_4_channel_mic/src/tusb_config.h
@@ -30,20 +30,6 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
@@ -53,19 +39,22 @@ extern "C" {
#error CFG_TUSB_MCU must be defined
#endif
+#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
+#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED)
+#else
+#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
+#endif
+
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
+#define CFG_TUSB_DEBUG 0
#endif
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -79,7 +68,7 @@ extern "C" {
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
@@ -91,11 +80,11 @@ extern "C" {
#endif
//------------- CLASS -------------//
-#define CFG_TUD_AUDIO 1
#define CFG_TUD_CDC 0
#define CFG_TUD_MSC 0
#define CFG_TUD_HID 0
#define CFG_TUD_MIDI 0
+#define CFG_TUD_AUDIO 1
#define CFG_TUD_VENDOR 0
//--------------------------------------------------------------------
@@ -103,37 +92,24 @@ extern "C" {
//--------------------------------------------------------------------
// Have a look into audio_device.h for all configurations
-#define CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE 48000
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_MIC_FOUR_CH_DESC_LEN
+#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_MIC_FOUR_CH_DESC_LEN
-#define CFG_TUD_AUDIO_FUNC_1_N_AS_INT 1
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64
+#define CFG_TUD_AUDIO_FUNC_1_N_AS_INT 1
+#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64
-#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
-#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX 2 // This value is not required by the driver, it parses this information from the descriptor once the alternate interface is set by the host - we use it for the setup
-#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 4 // This value is not required by the driver, it parses this information from the descriptor once the alternate interface is set by the host - we use it for the setup
-#define CFG_TUD_AUDIO_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
+#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX 2 // This value is not required by the driver, it parses this information from the descriptor once the alternate interface is set by the host - we use it for the setup
+#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 4 // This value is not required by the driver, it parses this information from the descriptor once the alternate interface is set by the host - we use it for the setup
+#define CFG_TUD_AUDIO_EP_SZ_IN (48 + 1) * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX // 48 Samples (48 kHz) x 2 Bytes/Sample x CFG_TUD_AUDIO_N_CHANNELS_TX Channels - the Windows driver always needs an extra sample per channel of space more, otherwise it complains... found by trial and error
+#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX CFG_TUD_AUDIO_EP_SZ_IN
+#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ CFG_TUD_AUDIO_EP_SZ_IN
-#define CFG_TUD_AUDIO_ENABLE_ENCODING 1
-#define CFG_TUD_AUDIO_EP_IN_FLOW_CONTROL 1
-
-#if CFG_TUD_AUDIO_ENABLE_ENCODING
-
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX CFG_TUD_AUDIO_EP_SZ_IN
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ CFG_TUD_AUDIO_EP_SZ_IN
-
-#define CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING 1
-#define CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX 2 // One I2S stream contains two channels, each stream is saved within one support FIFO - this value is currently fixed, the driver does not support a changing value
-#define CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO (CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX / CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX)
-#define CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ 4 * (CFG_TUD_AUDIO_EP_SZ_IN / CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO) // Minimum 4*EP size is needed for flow control
-
-#else
-
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX CFG_TUD_AUDIO_EP_SZ_IN
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ 4 * CFG_TUD_AUDIO_EP_SZ_IN // Minimum 4*EP size is needed for flow control
-
-#endif
+#define CFG_TUD_AUDIO_ENABLE_ENCODING 1
+#define CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING 1
+#define CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX 2 // One I2S stream contains two channels, each stream is saved within one support FIFO - this value is currently fixed, the driver does not support a changing value
+#define CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO (CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX / CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX)
+#define CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ (CFG_TUD_AUDIO_EP_SZ_IN / CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO)
#ifdef __cplusplus
}
diff --git a/examples/device/audio_4_channel_mic/src/usb_descriptors.c b/examples/device/audio_4_channel_mic/src/usb_descriptors.c
index 728a5f9ce..b6a5bd5c2 100644
--- a/examples/device/audio_4_channel_mic/src/usb_descriptors.c
+++ b/examples/device/audio_4_channel_mic/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
@@ -45,7 +44,7 @@ tusb_desc_device_t const desc_device =
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
- // Use Interface Association Descriptor (IAD) for Audio
+ // 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,
@@ -82,12 +81,12 @@ enum
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_MIC_FOUR_CH_DESC_LEN)
-#if TU_CHECK_MCU(OPT_MCU_LPC175X_6X, OPT_MCU_LPC177X_8X, OPT_MCU_LPC40XX)
+#if TU_CHECK_MCU(LPC175X_6X) || TU_CHECK_MCU(LPC177X_8X) || TU_CHECK_MCU(LPC40XX)
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
// 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
#define EPNUM_AUDIO 0x03
-#elif TU_CHECK_MCU(OPT_MCU_NRF5X)
+#elif TU_CHECK_MCU(NRF5X)
// nRF5x ISO can only be endpoint 8
#define EPNUM_AUDIO 0x08
@@ -97,11 +96,11 @@ enum
uint8_t const desc_configuration[] =
{
- // Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
+ // Interface count, string index, total length, attribute, power in mA
+ TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
- // Interface number, string index, EP Out & EP In address, EP size
- TUD_AUDIO_MIC_FOUR_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
+ // Interface number, string index, EP Out & EP In address, EP size
+ TUD_AUDIO_MIC_FOUR_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
};
// Invoked when received GET CONFIGURATION DESCRIPTOR
@@ -117,63 +116,50 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const* string_desc_arr [] = {
- (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
- "PaniRCorp", // 1: Manufacturer
- "MicNode_4_Ch", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
- "UAC2", // 4: Audio Interface
+char const* string_desc_arr [] =
+{
+ (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
+ "PaniRCorp", // 1: Manufacturer
+ "MicNode_4_Ch", // 2: Product
+ "123458", // 3: Serials, should use chip ID
+ "UAC2", // 4: Audio Interface
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Convert ASCII string into UTF-16
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
# Example source
target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- )
+)
# Example include
target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
- )
+)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/audio_test/Makefile b/examples/device/audio_test/Makefile
index 2a3d854fb..5a455078e 100644
--- a/examples/device/audio_test/Makefile
+++ b/examples/device/audio_test/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/audio_test/skip.txt b/examples/device/audio_test/skip.txt
deleted file mode 100644
index 1ee86a485..000000000
--- a/examples/device/audio_test/skip.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-mcu:SAMD11
-mcu:SAME5X
-mcu:SAMG
diff --git a/examples/device/audio_test/src/main.c b/examples/device/audio_test/src/main.c
index 06783ccfb..9a2fdd3a1 100644
--- a/examples/device/audio_test/src/main.c
+++ b/examples/device/audio_test/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Reinhard Panhuber
@@ -35,7 +35,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//--------------------------------------------------------------------+
@@ -71,7 +71,7 @@ audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX+1];
audio_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
// Audio test data
-uint16_t test_buffer_audio[(CFG_TUD_AUDIO_EP_SZ_IN - 2) / 2];
+uint16_t test_buffer_audio[CFG_TUD_AUDIO_EP_SZ_IN/2];
uint16_t startVal = 0;
void led_blinking_task(void);
@@ -82,12 +82,7 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
// Init values
sampFreq = AUDIO_SAMPLE_RATE;
@@ -104,6 +99,9 @@ int main(void)
led_blinking_task();
audio_task();
}
+
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -134,7 +132,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
@@ -144,7 +142,7 @@ void tud_resume_cb(void)
void audio_task(void)
{
// Yet to be filled - e.g. put meas data into TX FIFOs etc.
- // asm("nop");
+ asm("nop");
}
//--------------------------------------------------------------------+
@@ -223,7 +221,7 @@ bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
// Request uses format layout 2
TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_2_t));
- volume[channelNum] = (uint16_t) ((audio_control_cur_2_t*) pBuff)->bCur;
+ volume[channelNum] = ((audio_control_cur_2_t*) pBuff)->bCur;
TU_LOG2(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
return true;
@@ -292,7 +290,7 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *
// Those are dummy values for now
ret.bNrChannels = 1;
- ret.bmChannelConfig = (audio_channel_config_t) 0;
+ ret.bmChannelConfig = 0;
ret.iChannelNames = 0;
TU_LOG2(" Get terminal connector\r\n");
@@ -401,7 +399,7 @@ bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t itf, uint8_t ep_in, u
(void) ep_in;
(void) cur_alt_setting;
- tud_audio_write ((uint8_t *)test_buffer_audio, CFG_TUD_AUDIO_EP_SZ_IN - 2);
+ tud_audio_write ((uint8_t *)test_buffer_audio, CFG_TUD_AUDIO_EP_SZ_IN);
return true;
}
@@ -414,7 +412,7 @@ bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uin
(void) ep_in;
(void) cur_alt_setting;
- for (size_t cnt = 0; cnt < (CFG_TUD_AUDIO_EP_SZ_IN - 2) / 2; cnt++)
+ for (size_t cnt = 0; cnt < CFG_TUD_AUDIO_EP_SZ_IN/2; cnt++)
{
test_buffer_audio[cnt] = startVal++;
}
diff --git a/examples/device/audio_test/src/plot_audio_samples.py b/examples/device/audio_test/src/plot_audio_samples.py
index 1504684a6..6e3c4978e 100644
--- a/examples/device/audio_test/src/plot_audio_samples.py
+++ b/examples/device/audio_test/src/plot_audio_samples.py
@@ -2,7 +2,6 @@ import sounddevice as sd
import matplotlib.pyplot as plt
import numpy as np
import platform
-import csv
if __name__ == '__main__':
@@ -32,6 +31,4 @@ if __name__ == '__main__':
plt.ylabel('Amplitude')
plt.title('MicNode')
plt.show()
-
- samples = np.array(myrecording)
- np.savetxt('Output.csv', samples, delimiter=",", fmt='%s')
+
\ No newline at end of file
diff --git a/examples/device/audio_test/src/tusb_config.h b/examples/device/audio_test/src/tusb_config.h
index 9f38612a9..683a1a567 100644
--- a/examples/device/audio_test/src/tusb_config.h
+++ b/examples/device/audio_test/src/tusb_config.h
@@ -30,20 +30,6 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
@@ -53,6 +39,12 @@ extern "C" {
#error CFG_TUSB_MCU must be defined
#endif
+#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
+#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED)
+#else
+#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
+#endif
+
#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
#endif
@@ -61,12 +53,6 @@ extern "C" {
#define CFG_TUSB_DEBUG 0
#endif
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
-
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
@@ -94,11 +80,11 @@ extern "C" {
#endif
//------------- CLASS -------------//
-#define CFG_TUD_AUDIO 1
#define CFG_TUD_CDC 0
#define CFG_TUD_MSC 0
#define CFG_TUD_HID 0
#define CFG_TUD_MIDI 0
+#define CFG_TUD_AUDIO 1
#define CFG_TUD_VENDOR 0
//--------------------------------------------------------------------
@@ -114,7 +100,7 @@ extern "C" {
#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX 2 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below
#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 1 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below - be aware: for different number of channels you need another descriptor!
-#define CFG_TUD_AUDIO_EP_SZ_IN (48 + 1) * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX // 48 Samples (48 kHz) x 2 Bytes/Sample x CFG_TUD_AUDIO_N_CHANNELS_TX Channels - One extra sample is needed for asynchronous transfer adjustment, see feedback EP
+#define CFG_TUD_AUDIO_EP_SZ_IN 48 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX // 48 Samples (48 kHz) x 2 Bytes/Sample x 1 Channel
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX CFG_TUD_AUDIO_EP_SZ_IN // Maximum EP IN size for all AS alternate settings used
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ CFG_TUD_AUDIO_EP_SZ_IN + 1
diff --git a/examples/device/audio_test/src/usb_descriptors.c b/examples/device/audio_test/src/usb_descriptors.c
index 9864377f6..348f5eede 100644
--- a/examples/device/audio_test/src/usb_descriptors.c
+++ b/examples/device/audio_test/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
@@ -45,7 +44,7 @@ tusb_desc_device_t const desc_device =
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
- // Use Interface Association Descriptor (IAD) for Audio
+ // 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,
@@ -87,7 +86,7 @@ enum
// 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
#define EPNUM_AUDIO 0x03
-#elif TU_CHECK_MCU(OPT_MCU_NRF5X)
+#elif TU_CHECK_MCU(NRF5X)
// nRF5x ISO can only be endpoint 8
#define EPNUM_AUDIO 0x08
@@ -97,7 +96,7 @@ enum
uint8_t const desc_configuration[] =
{
- // Config number, interface count, string index, total length, attribute, power in mA
+ // Interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP Out & EP In address, EP size
@@ -117,65 +116,50 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
char const* string_desc_arr [] =
{
- (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
- "PaniRCorp", // 1: Manufacturer
- "MicNode", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
- "UAC2", // 4: Audio Interface
-
+ (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
+ "PaniRCorp", // 1: Manufacturer
+ "MicNode", // 2: Product
+ "123456", // 3: Serials, should use chip ID
+ "UAC2", // 4: Audio Interface
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Convert ASCII string into UTF-16
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ for(uint8_t i=0; i-)
-family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-
-project(${PROJECT} C CXX ASM)
-
-# Checks this example is valid for the family and initializes the project
-family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
-add_executable(${PROJECT})
-
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- )
-
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
-
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
diff --git a/examples/device/audio_test_multi_rate/Makefile b/examples/device/audio_test_multi_rate/Makefile
deleted file mode 100644
index 2a3d854fb..000000000
--- a/examples/device/audio_test_multi_rate/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-include ../../make.mk
-
-INC += \
- src \
- $(TOP)/hw \
-
-# Example source
-EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
-
-include ../../rules.mk
diff --git a/examples/device/audio_test_multi_rate/skip.txt b/examples/device/audio_test_multi_rate/skip.txt
deleted file mode 100644
index 1ee86a485..000000000
--- a/examples/device/audio_test_multi_rate/skip.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-mcu:SAMD11
-mcu:SAME5X
-mcu:SAMG
diff --git a/examples/device/audio_test_multi_rate/src/main.c b/examples/device/audio_test_multi_rate/src/main.c
deleted file mode 100644
index 3e7f40dac..000000000
--- a/examples/device/audio_test_multi_rate/src/main.c
+++ /dev/null
@@ -1,525 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Reinhard Panhuber
- * Copyright (c) 2022 HiFiPhile
- *
- * 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.
- *
- */
-
-/* plot_audio_samples.py requires following modules:
- * $ sudo apt install libportaudio
- * $ pip3 install sounddevice matplotlib
- *
- * Then run
- * $ python3 plot_audio_samples.py
- */
-
-#include
-#include
-#include
-
-#include "bsp/board_api.h"
-#include "tusb.h"
-#include "usb_descriptors.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF PROTYPES
-//--------------------------------------------------------------------+
-
-/* Blink pattern
- * - 250 ms : device not mounted
- * - 1000 ms : device mounted
- * - 2500 ms : device is suspended
- */
-enum {
- BLINK_NOT_MOUNTED = 250,
- BLINK_MOUNTED = 1000,
- BLINK_SUSPENDED = 2500,
-};
-
-static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
-
-// Audio controls
-// Current states
-bool mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1]; // +1 for master channel 0
-uint16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1]; // +1 for master channel 0
-uint32_t sampFreq;
-uint8_t bytesPerSample;
-uint8_t clkValid;
-
-// Range states
-// List of supported sample rates
-static const uint32_t sampleRatesList[] =
-{
- 32000, 48000, 96000
-};
-
-#define N_sampleRates TU_ARRAY_SIZE(sampleRatesList)
-
-// Bytes per format of every Alt settings
-static const uint8_t bytesPerSampleAltList[CFG_TUD_AUDIO_FUNC_1_N_FORMATS] =
-{
- CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX,
- CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX,
-};
-
-audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX+1]; // Volume range state
-
-
-// Audio test data
-CFG_TUSB_MEM_ALIGN uint8_t test_buffer_audio[CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX];
-uint16_t startVal = 0;
-
-void led_blinking_task(void);
-void audio_task(void);
-
-/*------------- MAIN -------------*/
-int main(void)
-{
- board_init();
-
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
-
- // Init values
- sampFreq = sampleRatesList[0];
- clkValid = 1;
-
- while (1)
- {
- tud_task(); // tinyusb device task
- led_blinking_task();
- audio_task();
- }
-
-
- return 0;
-}
-
-//--------------------------------------------------------------------+
-// Device callbacks
-//--------------------------------------------------------------------+
-
-// Invoked when device is mounted
-void tud_mount_cb(void)
-{
- blink_interval_ms = BLINK_MOUNTED;
-}
-
-// Invoked when device is unmounted
-void tud_umount_cb(void)
-{
- blink_interval_ms = BLINK_NOT_MOUNTED;
-}
-
-// Invoked when usb bus is suspended
-// remote_wakeup_en : if host allow us to perform remote wakeup
-// Within 7ms, device must draw an average of current less than 2.5 mA from bus
-void tud_suspend_cb(bool remote_wakeup_en)
-{
- (void) remote_wakeup_en;
- blink_interval_ms = BLINK_SUSPENDED;
-}
-
-// Invoked when usb bus is resumed
-void tud_resume_cb(void)
-{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
-}
-
-//--------------------------------------------------------------------+
-// AUDIO Task
-//--------------------------------------------------------------------+
-
-void audio_task(void)
-{
- // Yet to be filled - e.g. put meas data into TX FIFOs etc.
- // asm("nop");
-}
-
-//--------------------------------------------------------------------+
-// Application Callback API Implementations
-//--------------------------------------------------------------------+
-
-// Invoked when set interface is called, typically on start/stop streaming or format change
-bool tud_audio_set_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- (void)rhport;
- //uint8_t const itf = tu_u16_low(tu_le16toh(p_request->wIndex));
- uint8_t const alt = tu_u16_low(tu_le16toh(p_request->wValue));
-
- // Clear buffer when streaming format is changed
- if(alt != 0)
- {
- bytesPerSample = bytesPerSampleAltList[alt-1];
- }
- return true;
-}
-
-// Invoked when audio class specific set request received for an EP
-bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff)
-{
- (void) rhport;
- (void) pBuff;
-
- // We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
-
- // Page 91 in UAC2 specification
- uint8_t channelNum = TU_U16_LOW(p_request->wValue);
- uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- uint8_t ep = TU_U16_LOW(p_request->wIndex);
-
- (void) channelNum; (void) ctrlSel; (void) ep;
-
- return false; // Yet not implemented
-}
-
-// Invoked when audio class specific set request received for an interface
-bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff)
-{
- (void) rhport;
- (void) pBuff;
-
- // We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
-
- // Page 91 in UAC2 specification
- uint8_t channelNum = TU_U16_LOW(p_request->wValue);
- uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- uint8_t itf = TU_U16_LOW(p_request->wIndex);
-
- (void) channelNum; (void) ctrlSel; (void) itf;
-
- return false; // Yet not implemented
-}
-
-// Invoked when audio class specific set request received for an entity
-bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff)
-{
- (void) rhport;
-
- // Page 91 in UAC2 specification
- uint8_t channelNum = TU_U16_LOW(p_request->wValue);
- uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- uint8_t itf = TU_U16_LOW(p_request->wIndex);
- uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
-
- (void) itf;
-
- // We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
-
- // If request is for our feature unit
- if ( entityID == UAC2_ENTITY_FEATURE_UNIT )
- {
- switch ( ctrlSel )
- {
- case AUDIO_FU_CTRL_MUTE:
- // Request uses format layout 1
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_1_t));
-
- mute[channelNum] = ((audio_control_cur_1_t*) pBuff)->bCur;
-
- TU_LOG2(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
- return true;
-
- case AUDIO_FU_CTRL_VOLUME:
- // Request uses format layout 2
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_2_t));
-
- volume[channelNum] = (uint16_t) ((audio_control_cur_2_t*) pBuff)->bCur;
-
- TU_LOG2(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
- return true;
-
- // Unknown/Unsupported control
- default:
- TU_BREAKPOINT();
- return false;
- }
- }
-
- // Clock Source unit
- if ( entityID == UAC2_ENTITY_CLOCK )
- {
- switch ( ctrlSel )
- {
- case AUDIO_CS_CTRL_SAM_FREQ:
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_4_t));
-
- sampFreq = (uint32_t)((audio_control_cur_4_t *)pBuff)->bCur;
-
- TU_LOG2("Clock set current freq: %lu\r\n", sampFreq);
-
- return true;
- break;
-
- // Unknown/Unsupported control
- default:
- TU_BREAKPOINT();
- return false;
- }
- }
-
- return false; // Yet not implemented
-}
-
-// Invoked when audio class specific get request received for an EP
-bool tud_audio_get_req_ep_cb(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- (void) rhport;
-
- // Page 91 in UAC2 specification
- uint8_t channelNum = TU_U16_LOW(p_request->wValue);
- uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- uint8_t ep = TU_U16_LOW(p_request->wIndex);
-
- (void) channelNum; (void) ctrlSel; (void) ep;
-
- // return tud_control_xfer(rhport, p_request, &tmp, 1);
-
- return false; // Yet not implemented
-}
-
-// Invoked when audio class specific get request received for an interface
-bool tud_audio_get_req_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- (void) rhport;
-
- // Page 91 in UAC2 specification
- uint8_t channelNum = TU_U16_LOW(p_request->wValue);
- uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- uint8_t itf = TU_U16_LOW(p_request->wIndex);
-
- (void) channelNum; (void) ctrlSel; (void) itf;
-
- return false; // Yet not implemented
-}
-
-// Invoked when audio class specific get request received for an entity
-bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- (void) rhport;
-
- // Page 91 in UAC2 specification
- uint8_t channelNum = TU_U16_LOW(p_request->wValue);
- uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- // uint8_t itf = TU_U16_LOW(p_request->wIndex); // Since we have only one audio function implemented, we do not need the itf value
- uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
-
- // Input terminal (Microphone input)
- if (entityID == UAC2_ENTITY_INPUT_TERMINAL)
- {
- switch ( ctrlSel )
- {
- case AUDIO_TE_CTRL_CONNECTOR:
- {
- // The terminal connector control only has a get request with only the CUR attribute.
- audio_desc_channel_cluster_t ret;
-
- // Those are dummy values for now
- ret.bNrChannels = 1;
- ret.bmChannelConfig = 0;
- ret.iChannelNames = 0;
-
- TU_LOG2(" Get terminal connector\r\n");
-
- return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, (void*) &ret, sizeof(ret));
- }
- break;
-
- // Unknown/Unsupported control selector
- default:
- TU_BREAKPOINT();
- return false;
- }
- }
-
- // Feature unit
- if (entityID == UAC2_ENTITY_FEATURE_UNIT)
- {
- switch ( ctrlSel )
- {
- case AUDIO_FU_CTRL_MUTE:
- // Audio control mute cur parameter block consists of only one byte - we thus can send it right away
- // There does not exist a range parameter block for mute
- TU_LOG2(" Get Mute of channel: %u\r\n", channelNum);
- return tud_control_xfer(rhport, p_request, &mute[channelNum], 1);
-
- case AUDIO_FU_CTRL_VOLUME:
- switch ( p_request->bRequest )
- {
- case AUDIO_CS_REQ_CUR:
- TU_LOG2(" Get Volume of channel: %u\r\n", channelNum);
- return tud_control_xfer(rhport, p_request, &volume[channelNum], sizeof(volume[channelNum]));
-
- case AUDIO_CS_REQ_RANGE:
- TU_LOG2(" Get Volume range of channel: %u\r\n", channelNum);
-
- // Copy values - only for testing - better is version below
- audio_control_range_2_n_t(1)
- ret;
-
- ret.wNumSubRanges = 1;
- ret.subrange[0].bMin = -90; // -90 dB
- ret.subrange[0].bMax = 30; // +30 dB
- ret.subrange[0].bRes = 1; // 1 dB steps
-
- return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, (void*) &ret, sizeof(ret));
-
- // Unknown/Unsupported control
- default:
- TU_BREAKPOINT();
- return false;
- }
- break;
-
- // Unknown/Unsupported control
- default:
- TU_BREAKPOINT();
- return false;
- }
- }
-
- // Clock Source unit
- if ( entityID == UAC2_ENTITY_CLOCK )
- {
- switch ( ctrlSel )
- {
- case AUDIO_CS_CTRL_SAM_FREQ:
- // channelNum is always zero in this case
- switch ( p_request->bRequest )
- {
- case AUDIO_CS_REQ_CUR:
- TU_LOG2(" Get Sample Freq.\r\n");
- return tud_control_xfer(rhport, p_request, &sampFreq, sizeof(sampFreq));
-
- case AUDIO_CS_REQ_RANGE:
- {
- TU_LOG2(" Get Sample Freq. range\r\n");
- audio_control_range_4_n_t(N_sampleRates) rangef =
- {
- .wNumSubRanges = tu_htole16(N_sampleRates)
- };
- TU_LOG1("Clock get %d freq ranges\r\n", N_sampleRates);
- for(uint8_t i = 0; i < N_sampleRates; i++)
- {
- rangef.subrange[i].bMin = (int32_t)sampleRatesList[i];
- rangef.subrange[i].bMax = (int32_t)sampleRatesList[i];
- rangef.subrange[i].bRes = 0;
- TU_LOG1("Range %d (%d, %d, %d)\r\n", i, (int)rangef.subrange[i].bMin, (int)rangef.subrange[i].bMax, (int)rangef.subrange[i].bRes);
- }
- return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &rangef, sizeof(rangef));
- }
- // Unknown/Unsupported control
- default:
- TU_BREAKPOINT();
- return false;
- }
- break;
-
- case AUDIO_CS_CTRL_CLK_VALID:
- // Only cur attribute exists for this request
- TU_LOG2(" Get Sample Freq. valid\r\n");
- return tud_control_xfer(rhport, p_request, &clkValid, sizeof(clkValid));
-
- // Unknown/Unsupported control
- default:
- TU_BREAKPOINT();
- return false;
- }
- }
-
- TU_LOG2(" Unsupported entity: %d\r\n", entityID);
- return false; // Yet not implemented
-}
-
-bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t itf, uint8_t ep_in, uint8_t cur_alt_setting)
-{
- (void) rhport;
- (void) itf;
- (void) ep_in;
- (void) cur_alt_setting;
-
- tud_audio_write((uint8_t *)test_buffer_audio, (uint16_t)(sampFreq / (TUD_OPT_HIGH_SPEED ? 8000 : 1000) * bytesPerSample));
-
- return true;
-}
-
-bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uint8_t itf, uint8_t ep_in, uint8_t cur_alt_setting)
-{
- (void) rhport;
- (void) n_bytes_copied;
- (void) itf;
- (void) ep_in;
- (void) cur_alt_setting;
-
- // 16bit
- if(bytesPerSample == 2)
- {
- uint16_t* pData_16 = (uint16_t*)((void*)test_buffer_audio);
- for (size_t cnt = 0; cnt < sampFreq / (TUD_OPT_HIGH_SPEED ? 8000 : 1000); cnt++)
- {
- pData_16[cnt] = startVal++;
- }
- }
- // 24bit in 32bit slot
- else if(bytesPerSample == 4)
- {
- uint32_t* pData_32 = (uint32_t*)((void*)test_buffer_audio);
- for (size_t cnt = 0; cnt < sampFreq / (TUD_OPT_HIGH_SPEED ? 8000 : 1000); cnt++)
- {
- pData_32[cnt] = (uint32_t)startVal++ << 16U;
- }
- }
-
- return true;
-}
-
-bool tud_audio_set_itf_close_EP_cb(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- (void) rhport;
- (void) p_request;
- startVal = 0;
-
- return true;
-}
-
-//--------------------------------------------------------------------+
-// BLINKING TASK
-//--------------------------------------------------------------------+
-void led_blinking_task(void)
-{
- static uint32_t start_ms = 0;
- static bool led_state = false;
-
- // Blink every interval ms
- if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
- start_ms += blink_interval_ms;
-
- board_led_write(led_state);
- led_state = 1 - led_state; // toggle
-}
diff --git a/examples/device/audio_test_multi_rate/src/plot_audio_samples.py b/examples/device/audio_test_multi_rate/src/plot_audio_samples.py
deleted file mode 100644
index c92e49957..000000000
--- a/examples/device/audio_test_multi_rate/src/plot_audio_samples.py
+++ /dev/null
@@ -1,37 +0,0 @@
-import sounddevice as sd
-import matplotlib.pyplot as plt
-import numpy as np
-import platform
-import csv
-
-if __name__ == '__main__':
-
- # If you got "ValueError: No input device matching", that is because your PC name example device
- # differently from tested list below. Uncomment the next line to see full list and try to pick correct one
- # print(sd.query_devices())
-
- fs = 96000 # Sample rate
- duration = 100e-3 # Duration of recording
-
- if platform.system() == 'Windows':
- # MME is needed since there are more than one MicNode device APIs (at least in Windows)
- device = 'Microphone (MicNode) MME'
- elif platform.system() == 'Darwin':
- device = 'MicNode'
- else:
- device ='default'
-
- myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='int16', device=device)
- print('Waiting...')
- sd.wait() # Wait until recording is finished
- print('Done!')
-
- time = np.arange(0, duration, 1 / fs) # time vector
- plt.plot(time, myrecording)
- plt.xlabel('Time [s]')
- plt.ylabel('Amplitude')
- plt.title('MicNode')
- plt.show()
-
- samples = np.array(myrecording)
- np.savetxt('Output.csv', samples, delimiter=",", fmt='%s')
diff --git a/examples/device/audio_test_multi_rate/src/tusb_config.h b/examples/device/audio_test_multi_rate/src/tusb_config.h
deleted file mode 100644
index 1c8288bce..000000000
--- a/examples/device/audio_test_multi_rate/src/tusb_config.h
+++ /dev/null
@@ -1,141 +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 _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "usb_descriptors.h"
-
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
-//--------------------------------------------------------------------
-// COMMON CONFIGURATION
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
-#endif
-
-#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
-#endif
-
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
-
-// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
-// #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
-//--------------------------------------------------------------------
-
-#ifndef CFG_TUD_ENDPOINT0_SIZE
-#define CFG_TUD_ENDPOINT0_SIZE 64
-#endif
-
-//------------- CLASS -------------//
-#define CFG_TUD_AUDIO 1
-#define CFG_TUD_CDC 0
-#define CFG_TUD_MSC 0
-#define CFG_TUD_HID 0
-#define CFG_TUD_MIDI 0
-#define CFG_TUD_VENDOR 0
-
-//--------------------------------------------------------------------
-// AUDIO CLASS DRIVER CONFIGURATION
-//--------------------------------------------------------------------
-
-#define CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE 96000
-
-// How many formats are used, need to adjust USB descriptor if changed
-#define CFG_TUD_AUDIO_FUNC_1_N_FORMATS 2
-
-// 16bit in 16bit slots
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX 2
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX 16
-
-// 24bit in 32bit slots
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX 4
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX 24
-
-// Have a look into audio_device.h for all configurations
-
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_MIC_ONE_CH_2_FORMAT_DESC_LEN
-#define CFG_TUD_AUDIO_FUNC_1_N_AS_INT 1 // Number of Standard AS Interface Descriptors (4.9.1) defined per audio function - this is required to be able to remember the current alternate settings of these interfaces - We restrict us here to have a constant number for all audio functions (which means this has to be the maximum number of AS interfaces an audio function has and a second audio function with less AS interfaces just wastes a few bytes)
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64 // Size of control request buffer
-
-#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
-#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 1 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below - be aware: for different number of channels you need another descriptor!
-
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
-
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX TU_MAX(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN) // Maximum EP IN size for all AS alternate settings used
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _TUSB_CONFIG_H_ */
diff --git a/examples/device/audio_test_multi_rate/src/usb_descriptors.c b/examples/device/audio_test_multi_rate/src/usb_descriptors.c
deleted file mode 100644
index f50e70a25..000000000
--- a/examples/device/audio_test_multi_rate/src/usb_descriptors.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- * Copyright (c) 2022 HiFiPhile
- *
- * 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 "bsp/board_api.h"
-#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.
- *
- * Auto ProductID layout's Bitmap:
- * [MSB] AUDIO | MIDI | HID | MSC | CDC [LSB]
- */
-#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
-#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
- _PID_MAP(MIDI, 3) | _PID_MAP(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
-
-//--------------------------------------------------------------------+
-// Device Descriptors
-//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
-{
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
- .bcdUSB = 0x0200,
-
- // Use Interface Association Descriptor (IAD) for Audio
- // 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,
- .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
-
- .idVendor = 0xCafe,
- .idProduct = USB_PID,
- .bcdDevice = 0x0100,
-
- .iManufacturer = 0x01,
- .iProduct = 0x02,
- .iSerialNumber = 0x03,
-
- .bNumConfigurations = 0x01
-};
-
-// Invoked when received GET DEVICE DESCRIPTOR
-// Application return pointer to descriptor
-uint8_t const * tud_descriptor_device_cb(void)
-{
- return (uint8_t const *) &desc_device;
-}
-
-//--------------------------------------------------------------------+
-// Configuration Descriptor
-//--------------------------------------------------------------------+
-enum
-{
- ITF_NUM_AUDIO_CONTROL = 0,
- ITF_NUM_AUDIO_STREAMING,
- ITF_NUM_TOTAL
-};
-
-#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_MIC_ONE_CH_2_FORMAT_DESC_LEN)
-
-#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
- // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
- // 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
- #define EPNUM_AUDIO 0x03
-
-#elif TU_CHECK_MCU(OPT_MCU_NRF5X)
- // nRF5x ISO can only be endpoint 8
- #define EPNUM_AUDIO 0x08
-
-#else
- #define EPNUM_AUDIO 0x01
-#endif
-
-uint8_t const desc_configuration[] =
-{
- // Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
-
- // Interface number, string index, EP Out & EP In address, EP size
- TUD_AUDIO_MIC_ONE_CH_2_FORMAT_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_epin*/ 0x80 | EPNUM_AUDIO)
-};
-
-TU_VERIFY_STATIC(sizeof(desc_configuration) == CONFIG_TOTAL_LEN, "Incorrect size");
-
-// Invoked when received GET CONFIGURATION DESCRIPTOR
-// Application return pointer to descriptor
-// Descriptor contents must exist long enough for transfer to complete
-uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
-{
- (void) index; // for multiple configurations
- return desc_configuration;
-}
-
-//--------------------------------------------------------------------+
-// String Descriptors
-//--------------------------------------------------------------------+
-
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
-// array of pointer to string descriptors
-char const* string_desc_arr [] =
-{
- (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
- "PaniRCorp", // 1: Manufacturer
- "MicNode", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
- "UAC2", // 4: Audio Interface
-
-};
-
-static uint16_t _desc_str[32 + 1];
-
-// Invoked when received GET STRING DESCRIPTOR request
-// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
- (void) langid;
- size_t chr_count;
-
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
-
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
-
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
-
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
-
- const char *str = string_desc_arr[index];
-
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
- }
-
- // first byte is length (including header), second byte is string type
- _desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
-
- return _desc_str;
-}
diff --git a/examples/device/audio_test_multi_rate/src/usb_descriptors.h b/examples/device/audio_test_multi_rate/src/usb_descriptors.h
deleted file mode 100644
index 8381e31f5..000000000
--- a/examples/device/audio_test_multi_rate/src/usb_descriptors.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2022 HiFiPhile
- *
- * 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_
-
-// #include "tusb.h"
-
-// Unit numbers are arbitrary selected
-#define UAC2_ENTITY_CLOCK 0x04
-#define UAC2_ENTITY_INPUT_TERMINAL 0x01
-#define UAC2_ENTITY_OUTPUT_TERMINAL 0x03
-#define UAC2_ENTITY_FEATURE_UNIT 0x02
-
-
-#define TUD_AUDIO_MIC_ONE_CH_2_FORMAT_DESC_LEN (TUD_AUDIO_DESC_IAD_LEN\
- + TUD_AUDIO_DESC_STD_AC_LEN\
- + TUD_AUDIO_DESC_CS_AC_LEN\
- + TUD_AUDIO_DESC_CLK_SRC_LEN\
- + TUD_AUDIO_DESC_INPUT_TERM_LEN\
- + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
- + TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN\
- /* Interface 1, Alternate 0 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- /* Interface 1, Alternate 1 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
- /* Interface 1, Alternate 2 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN)
-
-
-#define TUD_AUDIO_MIC_ONE_CH_2_FORMAT_DESCRIPTOR(_itfnum, _stridx, _epin) \
- /* Standard Interface Association Descriptor (IAD) */\
- TUD_AUDIO_DESC_IAD(/*_firstitf*/ _itfnum, /*_nitfs*/ 0x02, /*_stridx*/ 0x00),\
- /* Standard AC Interface Descriptor(4.7.1) */\
- TUD_AUDIO_DESC_STD_AC(/*_itfnum*/ _itfnum, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
- /* Class-Specific AC Interface Header Descriptor(4.7.2) */\
- TUD_AUDIO_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO_FUNC_MICROPHONE, /*_totallen*/ TUD_AUDIO_DESC_CLK_SRC_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN+TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN, /*_ctrl*/ AUDIO_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
- /* Clock Source Descriptor(4.7.2.1) */\
- TUD_AUDIO_DESC_CLK_SRC(/*_clkid*/ UAC2_ENTITY_CLOCK, /*_attr*/ AUDIO_CLOCK_SOURCE_ATT_INT_PRO_CLK, /*_ctrl*/ AUDIO_CTRL_RW << AUDIO_CLOCK_SOURCE_CTRL_CLK_FRQ_POS | AUDIO_CTRL_R << AUDIO_CLOCK_SOURCE_CTRL_CLK_VAL_POS, /*_assocTerm*/ 0x01, /*_stridx*/ 0x00),\
- /* Input Terminal Descriptor(4.7.2.4) */\
- TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS, /*_stridx*/ 0x00),\
- /* Output Terminal Descriptor(4.7.2.5) */\
- TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ UAC2_ENTITY_INPUT_TERMINAL, /*_srcid*/ UAC2_ENTITY_FEATURE_UNIT, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
- /* Feature Unit Descriptor(4.7.2.8) */\
- TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL(/*_unitid*/ UAC2_ENTITY_FEATURE_UNIT, /*_srcid*/ 0x01, /*_ctrlch0master*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch1*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_stridx*/ 0x00),\
- /* Standard AS Interface Descriptor(4.9.1) */\
- /* Interface 1, Alternate 0 - default alternate setting with 0 bandwidth */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x00),\
- /* Standard AS Interface Descriptor(4.9.1) */\
- /* Interface 1, Alternate 1 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x00),\
- /* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
- /* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX),\
- /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN, /*_interval*/ 0x01),\
- /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
- /* Interface 1, Alternate 2 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x00),\
- /* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
- /* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX),\
- /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN, /*_interval*/ 0x01),\
- /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
-
-
-#endif
diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt
index 012eff095..37113578e 100644
--- a/examples/device/board_test/CMakeLists.txt
+++ b/examples/device/board_test/CMakeLists.txt
@@ -1,32 +1,42 @@
-cmake_minimum_required(VERSION 3.17)
+cmake_minimum_required(VERSION 3.5)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
-# gets PROJECT name for the example (e.g. -)
-family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
+# Check for -DFAMILY=
+if(FAMILY MATCHES "^esp32s[2-3]")
+ # use BOARD-Directory name for project id
+ get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+ set(PROJECT ${BOARD}-${PROJECT})
-project(${PROJECT} C CXX ASM)
+ # TOP is absolute path to root directory of TinyUSB git repo
+ set(TOP "../../..")
+ get_filename_component(TOP "${TOP}" REALPATH)
-# Checks this example is valid for the family and initializes the project
-family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
+ project(${PROJECT})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
+else()
+
+ # gets PROJECT name for the example (e.g. -)
+ family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
+
+ project(${PROJECT})
+
+ # Checks this example is valid for the family and initializes the project
+ family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
+
+ add_executable(${PROJECT})
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Configure compilation flags and libraries for the example... see the corresponding function
+ # in hw/bsp/FAMILY/family.cmake for details.
+ family_configure_device_example(${PROJECT})
endif()
-
-add_executable(${PROJECT})
-
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- )
-
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
-
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
diff --git a/examples/device/board_test/Makefile b/examples/device/board_test/Makefile
index 2a3d854fb..b65575ce6 100644
--- a/examples/device/board_test/Makefile
+++ b/examples/device/board_test/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
@@ -8,4 +9,10 @@ INC += \
EXAMPLE_SOURCE += $(wildcard src/*.c)
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+# board_test example is special example that doesn't enable device or host stack
+# This can cause some TinyUSB API missing, this hack to allow us to fill those API
+# to pass the compilation process
+CFLAGS += \
+ -D"tud_int_handler(x)= " \
+
include ../../rules.mk
diff --git a/examples/device/board_test/src/CMakeLists.txt b/examples/device/board_test/src/CMakeLists.txt
index 8d85dcafd..e4e1f4e9a 100644
--- a/examples/device/board_test/src/CMakeLists.txt
+++ b/examples/device/board_test/src/CMakeLists.txt
@@ -1,3 +1,17 @@
+# FAMILY = esp32sx
idf_component_register(SRCS "main.c"
INCLUDE_DIRS "."
- REQUIRES boards tinyusb_src)
+ REQUIRES freertos soc)
+
+file(TO_NATIVE_PATH "${TOP}/hw/bsp/${FAMILY}/boards/${BOARD}/board.cmake" board_cmake)
+
+if(EXISTS ${board_cmake})
+ include(${board_cmake})
+endif()
+
+idf_component_get_property( FREERTOS_ORIG_INCLUDE_PATH freertos ORIG_INCLUDE_PATH)
+target_include_directories(${COMPONENT_TARGET} PUBLIC
+ "${FREERTOS_ORIG_INCLUDE_PATH}"
+ "${TOP}/hw"
+ "${TOP}/src"
+)
diff --git a/examples/device/board_test/src/main.c b/examples/device/board_test/src/main.c
index 0a134a2e6..c77dd5647 100644
--- a/examples/device/board_test/src/main.c
+++ b/examples/device/board_test/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,10 +27,10 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF PROTOTYPES
+// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+
/* Blink pattern
@@ -47,7 +47,6 @@ enum {
int main(void)
{
board_init();
- board_led_write(true);
uint32_t start_ms = 0;
bool led_state = false;
@@ -56,7 +55,7 @@ int main(void)
{
uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED;
- // Blink and print every interval ms
+ // Blink every interval ms
if ( !(board_millis() - start_ms < interval_ms) )
{
board_uart_write(HELLO_STR, strlen(HELLO_STR));
@@ -66,14 +65,9 @@ int main(void)
board_led_write(led_state);
led_state = 1 - led_state; // toggle
}
-
- // echo
- uint8_t ch;
- if ( board_uart_read(&ch, 1) > 0 )
- {
- board_uart_write(&ch, 1);
- }
}
+
+ return 0;
}
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
diff --git a/examples/device/board_test/src/tusb_config.h b/examples/device/board_test/src/tusb_config.h
index 2c2eb5280..da33729e7 100644
--- a/examples/device/board_test/src/tusb_config.h
+++ b/examples/device/board_test/src/tusb_config.h
@@ -30,11 +30,6 @@
extern "C" {
#endif
-// board_test example is special example that doesn't enable device or host stack
-// This can cause some TinyUSB API missing, this define hack to allow us to fill those API
-// to pass the compilation process
-#define tud_int_handler(x)
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
@@ -48,9 +43,7 @@
#define CFG_TUSB_OS OPT_OS_NONE
#endif
-// This example only test LED & GPIO, disable both device and host stack
-#define CFG_TUD_ENABLED 0
-#define CFG_TUH_ENABLED 0
+#define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
@@ -70,6 +63,21 @@
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
+//--------------------------------------------------------------------
+// DEVICE CONFIGURATION
+//--------------------------------------------------------------------
+
+#ifndef CFG_TUD_ENDPOINT0_SIZE
+#define CFG_TUD_ENDPOINT0_SIZE 64
+#endif
+
+//------------- CLASS -------------//
+#define CFG_TUD_CDC 0
+#define CFG_TUD_MSC 0
+#define CFG_TUD_HID 0
+#define CFG_TUD_MIDI 0
+#define CFG_TUD_VENDOR 0
+
#ifdef __cplusplus
}
#endif
diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt
index f61e1b640..abc4d91da 100644
--- a/examples/device/cdc_dual_ports/CMakeLists.txt
+++ b/examples/device/cdc_dual_ports/CMakeLists.txt
@@ -1,33 +1,28 @@
-cmake_minimum_required(VERSION 3.17)
+cmake_minimum_required(VERSION 3.5)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
# gets PROJECT name for the example (e.g. -)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
# Example source
target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- )
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
# Example include
target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/cdc_dual_ports/Makefile b/examples/device/cdc_dual_ports/Makefile
index 2a3d854fb..5a455078e 100644
--- a/examples/device/cdc_dual_ports/Makefile
+++ b/examples/device/cdc_dual_ports/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c
index 98f3ab923..34cd29edd 100644
--- a/examples/device/cdc_dual_ports/src/main.c
+++ b/examples/device/cdc_dual_ports/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -28,7 +28,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//------------- prototypes -------------//
@@ -39,37 +39,32 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
tud_task(); // tinyusb device task
cdc_task();
}
+
+ return 0;
}
// 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)
{
- uint8_t const case_diff = 'a' - 'A';
-
for(uint32_t i=0; i 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
# Example source
target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- )
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
# Example include
target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
# Configure compilation flags and libraries for the example... see the corresponding function
# in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/cdc_msc/Makefile b/examples/device/cdc_msc/Makefile
index 429959e70..69b633fea 100644
--- a/examples/device/cdc_msc/Makefile
+++ b/examples/device/cdc_msc/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
@@ -5,11 +6,7 @@ INC += \
$(TOP)/hw \
# Example source
-EXAMPLE_SOURCE += \
- src/main.c \
- src/msc_disk.c \
- src/usb_descriptors.c \
-
+EXAMPLE_SOURCE += $(wildcard src/*.c)
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
include ../../rules.mk
diff --git a/examples/device/cdc_msc/skip.txt b/examples/device/cdc_msc/skip.txt
deleted file mode 100644
index eadb6e74a..000000000
--- a/examples/device/cdc_msc/skip.txt
+++ /dev/null
@@ -1 +0,0 @@
-mcu:SAMD11
diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c
index 172f48ae0..131ae6549 100644
--- a/examples/device/cdc_msc/src/main.c
+++ b/examples/device/cdc_msc/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,7 +27,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//--------------------------------------------------------------------+
@@ -54,13 +54,7 @@ void cdc_task(void);
int main(void)
{
board_init();
-
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
@@ -69,6 +63,8 @@ int main(void)
cdc_task();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -99,7 +95,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
@@ -115,7 +111,7 @@ void cdc_task(void)
// connected and there are data available
if ( tud_cdc_available() )
{
- // read data
+ // read datas
char buf[64];
uint32_t count = tud_cdc_read(buf, sizeof(buf));
(void) count;
diff --git a/examples/device/cdc_msc/src/msc_disk.c b/examples/device/cdc_msc/src/msc_disk.c
index d2f8628f1..cad2602a2 100644
--- a/examples/device/cdc_msc/src/msc_disk.c
+++ b/examples/device/cdc_msc/src/msc_disk.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,7 @@
*
*/
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#if CFG_TUD_MSC
@@ -142,7 +142,6 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun)
// RAM disk is ready until ejected
if (ejected) {
- // Additional Sense 3A-00 is NOT_FOUND
tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x3a, 0x00);
return false;
}
@@ -195,7 +194,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
uint8_t const* addr = msc_disk[lba] + offset;
memcpy(buffer, addr, bufsize);
- return (int32_t) bufsize;
+ return bufsize;
}
bool tud_msc_is_writable_cb (uint8_t lun)
@@ -225,7 +224,7 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
(void) lba; (void) offset; (void) buffer;
#endif
- return (int32_t) bufsize;
+ return bufsize;
}
// Callback invoked when received an SCSI command not in built-in list below
@@ -243,6 +242,11 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
switch (scsi_cmd[0])
{
+ case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
+ // Host is about to read/write etc ... better not to disconnect disk
+ resplen = 0;
+ break;
+
default:
// Set Sense = Invalid Command Operation
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
@@ -259,14 +263,14 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
{
if(in_xfer)
{
- memcpy(buffer, response, (size_t) resplen);
+ memcpy(buffer, response, resplen);
}else
{
// SCSI output
}
}
- return (int32_t) resplen;
+ return resplen;
}
#endif
diff --git a/examples/device/cdc_msc/src/tusb_config.h b/examples/device/cdc_msc/src/tusb_config.h
index 03e0e649c..bf6af06bc 100644
--- a/examples/device/cdc_msc/src/tusb_config.h
+++ b/examples/device/cdc_msc/src/tusb_config.h
@@ -30,42 +30,47 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
+//--------------------------------------------------------------------
+// COMMON CONFIGURATION
+//--------------------------------------------------------------------
+
+// defined by board.mk
+#ifndef CFG_TUSB_MCU
+ #error CFG_TUSB_MCU must be defined
+#endif
// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
#endif
// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56 || CFG_TUSB_MCU == OPT_MCU_SAMX7X)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
#endif
-//--------------------------------------------------------------------
-// Common Configuration
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
+// This example doesn't use an RTOS
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -79,7 +84,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/device/cdc_msc/src/usb_descriptors.c b/examples/device/cdc_msc/src/usb_descriptors.c
index 2afa24903..524c5bfb4 100644
--- a/examples/device/cdc_msc/src/usb_descriptors.c
+++ b/examples/device/cdc_msc/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
@@ -42,33 +41,35 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
- .bcdUSB = USB_BCD,
+tusb_desc_device_t const desc_device =
+{
+ .bLength = sizeof(tusb_desc_device_t),
+ .bDescriptorType = TUSB_DESC_DEVICE,
+ .bcdUSB = USB_BCD,
- // 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,
+ // 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,
- .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
- .idVendor = USB_VID,
- .idProduct = USB_PID,
- .bcdDevice = 0x0100,
+ .idVendor = USB_VID,
+ .idProduct = USB_PID,
+ .bcdDevice = 0x0100,
- .iManufacturer = 0x01,
- .iProduct = 0x02,
- .iSerialNumber = 0x03,
+ .iManufacturer = 0x01,
+ .iProduct = 0x02,
+ .iSerialNumber = 0x03,
- .bNumConfigurations = 0x01
+ .bNumConfigurations = 0x01
};
// Invoked when received GET DEVICE DESCRIPTOR
// Application return pointer to descriptor
-uint8_t const *tud_descriptor_device_cb(void) {
+uint8_t const * tud_descriptor_device_cb(void)
+{
return (uint8_t const *) &desc_device;
}
@@ -76,7 +77,8 @@ uint8_t const *tud_descriptor_device_cb(void) {
// Configuration Descriptor
//--------------------------------------------------------------------+
-enum {
+enum
+{
ITF_NUM_CDC = 0,
ITF_NUM_CDC_DATA,
ITF_NUM_MSC,
@@ -93,7 +95,7 @@ enum {
#define EPNUM_MSC_OUT 0x05
#define EPNUM_MSC_IN 0x85
-#elif CFG_TUSB_MCU == OPT_MCU_SAMG || CFG_TUSB_MCU == OPT_MCU_SAMX7X
+#elif CFG_TUSB_MCU == OPT_MCU_SAMG || CFG_TUSB_MCU == OPT_MCU_SAMX7X
// SAMG & SAME70 don't support a same endpoint number with different direction IN and OUT
// e.g EP1 OUT & EP1 IN cannot exist together
#define EPNUM_CDC_NOTIF 0x81
@@ -115,16 +117,6 @@ enum {
#define EPNUM_MSC_OUT 0x05
#define EPNUM_MSC_IN 0x84
-#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
- // FT9XX doesn't support a same endpoint number with different direction IN and OUT
- // e.g EP1 OUT & EP1 IN cannot exist together
- #define EPNUM_CDC_NOTIF 0x81
- #define EPNUM_CDC_OUT 0x02
- #define EPNUM_CDC_IN 0x83
-
- #define EPNUM_MSC_OUT 0x04
- #define EPNUM_MSC_IN 0x85
-
#else
#define EPNUM_CDC_NOTIF 0x81
#define EPNUM_CDC_OUT 0x02
@@ -138,62 +130,67 @@ enum {
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN)
// full speed configuration
-uint8_t const desc_fs_configuration[] = {
- // Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
+uint8_t const desc_fs_configuration[] =
+{
+ // Config number, interface count, string index, total length, attribute, power in mA
+ TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
- // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
- TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
+ // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
+ TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
- // Interface number, string index, EP Out & EP In address, EP size
- TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 64),
+ // Interface number, string index, EP Out & EP In address, EP size
+ TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 64),
};
#if TUD_OPT_HIGH_SPEED
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
// high speed configuration
-uint8_t const desc_hs_configuration[] = {
- // Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
+uint8_t const desc_hs_configuration[] =
+{
+ // Config number, interface count, string index, total length, attribute, power in mA
+ TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
- // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
- TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 512),
+ // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
+ TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 512),
- // Interface number, string index, EP Out & EP In address, EP size
- TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 512),
+ // Interface number, string index, EP Out & EP In address, EP size
+ TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 512),
};
// other speed configuration
uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier = {
- .bLength = sizeof(tusb_desc_device_qualifier_t),
- .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
- .bcdUSB = USB_BCD,
+tusb_desc_device_qualifier_t const desc_device_qualifier =
+{
+ .bLength = sizeof(tusb_desc_device_qualifier_t),
+ .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
+ .bcdUSB = USB_BCD,
- .bDeviceClass = TUSB_CLASS_MISC,
- .bDeviceSubClass = MISC_SUBCLASS_COMMON,
- .bDeviceProtocol = MISC_PROTOCOL_IAD,
+ .bDeviceClass = TUSB_CLASS_MISC,
+ .bDeviceSubClass = MISC_SUBCLASS_COMMON,
+ .bDeviceProtocol = MISC_PROTOCOL_IAD,
- .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
- .bNumConfigurations = 0x01,
- .bReserved = 0x00
+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
+ .bNumConfigurations = 0x01,
+ .bReserved = 0x00
};
// Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
// device_qualifier descriptor describes information about a high-speed capable device that would
// change if the device were operating at the other speed. If not highspeed capable stall this request.
-uint8_t const *tud_descriptor_device_qualifier_cb(void) {
- return (uint8_t const *) &desc_device_qualifier;
+uint8_t const* tud_descriptor_device_qualifier_cb(void)
+{
+ return (uint8_t const*) &desc_device_qualifier;
}
// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
-uint8_t const *tud_descriptor_other_speed_configuration_cb(uint8_t index) {
+uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index)
+{
(void) index; // for multiple configurations
// if link speed is high return fullspeed config, and vice versa
@@ -213,12 +210,13 @@ uint8_t const *tud_descriptor_other_speed_configuration_cb(uint8_t index) {
// Invoked when received GET CONFIGURATION DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
-uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
+uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
+{
(void) index; // for multiple configurations
#if TUD_OPT_HIGH_SPEED
// Although we are highspeed, host may be fullspeed.
- return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_hs_configuration : desc_fs_configuration;
+ return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_hs_configuration : desc_fs_configuration;
#else
return desc_fs_configuration;
#endif
@@ -228,64 +226,53 @@ uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] = {
- (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
- "TinyUSB", // 1: Manufacturer
- "TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
- "TinyUSB CDC", // 4: CDC Interface
- "TinyUSB MSC", // 5: MSC Interface
+char const* string_desc_arr [] =
+{
+ (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
+ "TinyUSB", // 1: Manufacturer
+ "TinyUSB Device", // 2: Product
+ "123456789012", // 3: Serials, should use chip ID
+ "TinyUSB CDC", // 4: CDC Interface
+ "TinyUSB MSC", // 5: MSC Interface
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
+# Check for -DFAMILY=
+if(FAMILY MATCHES "^esp32s[2-3]")
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}")
endif()
-
-add_executable(${PROJECT})
-
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/freertos_hook.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- )
-
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
-
-# Configure compilation flags and libraries for the example with FreeRTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} freertos)
diff --git a/examples/device/cdc_msc_freertos/Makefile b/examples/device/cdc_msc_freertos/Makefile
index 84c833fb5..677dcac9c 100644
--- a/examples/device/cdc_msc_freertos/Makefile
+++ b/examples/device/cdc_msc_freertos/Makefile
@@ -1,15 +1,17 @@
+DEPS_SUBMODULES += lib/FreeRTOS-Kernel
+
+include ../../../tools/top.mk
include ../../make.mk
FREERTOS_SRC = lib/FreeRTOS-Kernel
-FREERTOS_PORTABLE_PATH= $(FREERTOS_SRC)/portable/$(if $(USE_IAR),IAR,GCC)
INC += \
src \
src/FreeRTOSConfig \
$(TOP)/hw \
$(TOP)/$(FREERTOS_SRC)/include \
- $(TOP)/$(FREERTOS_PORTABLE_SRC) \
-
+ $(TOP)/$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT)
+
# Example source
EXAMPLE_SOURCE = \
src/freertos_hook.c \
@@ -25,22 +27,9 @@ SRC_C += \
$(FREERTOS_SRC)/queue.c \
$(FREERTOS_SRC)/tasks.c \
$(FREERTOS_SRC)/timers.c \
- $(subst $(TOP)/,,$(wildcard $(TOP)/$(FREERTOS_PORTABLE_SRC)/*.c))
-
-SRC_S += \
- $(subst $(TOP)/,,$(wildcard $(TOP)/$(FREERTOS_PORTABLE_SRC)/*.s))
-
-# include heap manage if configSUPPORT_DYNAMIC_ALLOCATION = 1
-# SRC_C += $(FREERTOS_SRC)/portable/MemMang/heap_1.c
-# CFLAGS += -Wno-error=sign-compare
-
-# Suppress FreeRTOSConfig.h warnings
-CFLAGS_GCC += -Wno-error=redundant-decls
-
-# Suppress FreeRTOS source warnings
-CFLAGS_GCC += -Wno-error=cast-qual
+ $(subst ../../../,,$(wildcard ../../../$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT)/*.c))
# FreeRTOS (lto + Os) linker issue
-LDFLAGS_GCC += -Wl,--undefined=vTaskSwitchContext
+LDFLAGS += -Wl,--undefined=vTaskSwitchContext
include ../../rules.mk
diff --git a/examples/device/cdc_msc_freertos/skip.txt b/examples/device/cdc_msc_freertos/skip.txt
deleted file mode 100644
index a6f96b288..000000000
--- a/examples/device/cdc_msc_freertos/skip.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-mcu:CH32V307
-mcu:CXD56
-mcu:F1C100S
-mcu:GD32VF103
-mcu:MKL25ZXX
-mcu:MSP430x5xx
-mcu:RP2040
-mcu:SAMD11
-mcu:SAMX7X
-mcu:VALENTYUSB_EPTRI
-mcu:RAXXX
-family:broadcom_32bit
-family:broadcom_64bit
diff --git a/examples/device/cdc_msc_freertos/src/CMakeLists.txt b/examples/device/cdc_msc_freertos/src/CMakeLists.txt
index fee264363..07fc4df89 100644
--- a/examples/device/cdc_msc_freertos/src/CMakeLists.txt
+++ b/examples/device/cdc_msc_freertos/src/CMakeLists.txt
@@ -1,4 +1,31 @@
-# This file is for ESP-IDF only
idf_component_register(SRCS "main.c" "usb_descriptors.c" "msc_disk.c"
INCLUDE_DIRS "."
- REQUIRES boards tinyusb_src)
+ REQUIRES freertos soc)
+
+file(TO_NATIVE_PATH "${TOP}/hw/bsp/${FAMILY}/boards/${BOARD}/board.cmake" board_cmake)
+
+if(EXISTS ${board_cmake})
+ include(${board_cmake})
+endif()
+
+target_include_directories(${COMPONENT_TARGET} PUBLIC
+ "${TOP}/hw"
+ "${TOP}/src"
+)
+
+target_sources(${COMPONENT_TARGET} PUBLIC
+ "${TOP}/src/tusb.c"
+ "${TOP}/src/common/tusb_fifo.c"
+ "${TOP}/src/device/usbd.c"
+ "${TOP}/src/device/usbd_control.c"
+ "${TOP}/src/class/cdc/cdc_device.c"
+ "${TOP}/src/class/dfu/dfu_rt_device.c"
+ "${TOP}/src/class/hid/hid_device.c"
+ "${TOP}/src/class/midi/midi_device.c"
+ "${TOP}/src/class/msc/msc_device.c"
+ "${TOP}/src/class/net/ecm_rndis_device.c"
+ "${TOP}/src/class/net/ncm_device.c"
+ "${TOP}/src/class/usbtmc/usbtmc_device.c"
+ "${TOP}/src/class/vendor/vendor_device.c"
+ "${TOP}/src/portable/espressif/esp32sx/dcd_esp32sx.c"
+)
diff --git a/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h b/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h
index 69d638288..ccb620720 100644
--- a/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h
+++ b/examples/device/cdc_msc_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h
@@ -42,9 +42,6 @@
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
-// skip if included from IAR assembler
-#ifndef __IASMARM__
-
// Include MCU header
#include "bsp/board_mcu.h"
@@ -56,12 +53,9 @@
#if CFG_TUSB_MCU == OPT_MCU_MM32F327X
extern u32 SystemCoreClock;
#else
- // FIXME cause redundant-decls warnings
extern uint32_t SystemCoreClock;
#endif
-#endif
-
/* Cortex M23/M33 port configuration. */
#define configENABLE_MPU 0
#define configENABLE_FPU 1
@@ -74,14 +68,14 @@
#define configTICK_RATE_HZ ( 1000 )
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( 128 )
-#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION*4*1024 )
+#define configTOTAL_HEAP_SIZE ( 0*1024 ) // dynamic is not used
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
-#define configQUEUE_REGISTRY_SIZE 4
+#define configQUEUE_REGISTRY_SIZE 2
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
@@ -149,10 +143,10 @@
#ifdef __RX__
/* Renesas RX series */
-#define vSoftwareInterruptISR INT_Excep_ICU_SWINT
-#define vTickISR INT_Excep_CMT0_CMI0
-#define configPERIPHERAL_CLOCK_HZ (configCPU_CLOCK_HZ/2)
-#define configKERNEL_INTERRUPT_PRIORITY 1
+#define vSoftwareInterruptISR INT_Excep_ICU_SWINT
+#define vTickISR INT_Excep_CMT0_CMI0
+#define configPERIPHERAL_CLOCK_HZ (configCPU_CLOCK_HZ/2)
+#define configKERNEL_INTERRUPT_PRIORITY 1
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 4
#else
@@ -168,18 +162,9 @@
#if defined(__NVIC_PRIO_BITS)
// For Cortex-M specific: __NVIC_PRIO_BITS is defined in core_cmx.h
#define configPRIO_BITS __NVIC_PRIO_BITS
-
#elif defined(__ECLIC_INTCTLBITS)
// RISC-V Bumblebee core from nuclei
#define configPRIO_BITS __ECLIC_INTCTLBITS
-
-#elif defined(__IASMARM__)
- // FIXME: IAR Assembler cannot include mcu header directly to get __NVIC_PRIO_BITS.
- // Therefore we will hard coded it to minimum value of 2 to get pass ci build.
- // IAR user must update this to correct value of the target MCU
- #message "configPRIO_BITS is hard coded to 2 to pass IAR build only. User should update it per MCU"
- #define configPRIO_BITS 2
-
#else
#error "FreeRTOS configPRIO_BITS to be defined"
#endif
diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c
index 1dadc4513..65b7fda3b 100644
--- a/examples/device/cdc_msc_freertos/src/main.c
+++ b/examples/device/cdc_msc_freertos/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,10 +27,10 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
-#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+#if TU_CHECK_MCU(ESP32S2) || TU_CHECK_MCU(ESP32S3)
// ESP-IDF need "freertos/" prefix in include path.
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
#include "freertos/FreeRTOS.h"
@@ -38,24 +38,16 @@
#include "freertos/queue.h"
#include "freertos/task.h"
#include "freertos/timers.h"
-
- #define USBD_STACK_SIZE 4096
#else
-
#include "FreeRTOS.h"
#include "semphr.h"
#include "queue.h"
#include "task.h"
#include "timers.h"
-
- // Increase stack size when debug log is enabled
- #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
#endif
-#define CDC_STACK_SZIE configMINIMAL_STACK_SIZE
-
//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF PROTOTYPES
+// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+
/* Blink pattern
@@ -63,88 +55,85 @@
* - 1000 ms : device mounted
* - 2500 ms : device is suspended
*/
-enum {
+enum {
BLINK_NOT_MOUNTED = 250,
BLINK_MOUNTED = 1000,
BLINK_SUSPENDED = 2500,
};
-// static timer & task
-#if configSUPPORT_STATIC_ALLOCATION
+// static timer
StaticTimer_t blinky_tmdef;
+TimerHandle_t blinky_tm;
+
+// static task for usbd
+// Increase stack size when debug log is enabled
+#if CFG_TUSB_DEBUG
+ #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE)
+#else
+ #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2)
+#endif
StackType_t usb_device_stack[USBD_STACK_SIZE];
StaticTask_t usb_device_taskdef;
+// static task for cdc
+#define CDC_STACK_SZIE configMINIMAL_STACK_SIZE
StackType_t cdc_stack[CDC_STACK_SZIE];
StaticTask_t cdc_taskdef;
-#endif
-TimerHandle_t blinky_tm;
-static void led_blinky_cb(TimerHandle_t xTimer);
-static void usb_device_task(void *param);
-void cdc_task(void *params);
+void led_blinky_cb(TimerHandle_t xTimer);
+void usb_device_task(void* param);
+void cdc_task(void* params);
//--------------------------------------------------------------------+
// Main
//--------------------------------------------------------------------+
-int main(void) {
+int main(void)
+{
board_init();
-#if configSUPPORT_STATIC_ALLOCATION
// soft timer for blinky
blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb, &blinky_tmdef);
-
- // Create a task for tinyusb device stack
- xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
-
- // Create CDC task
- xTaskCreateStatic(cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
-#else
- blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb);
- xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
- xTaskCreate(cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES - 2, NULL);
-#endif
-
xTimerStart(blinky_tm, 0);
+ // Create a task for tinyusb device stack
+ (void) xTaskCreateStatic( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
+
+ // Create CDC task
+ (void) xTaskCreateStatic( cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
+
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
-#if !TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+#if !( TU_CHECK_MCU(ESP32S2) || TU_CHECK_MCU(ESP32S3) )
vTaskStartScheduler();
#endif
return 0;
}
-#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
-void app_main(void) {
+#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
+void app_main(void)
+{
main();
}
#endif
// USB Device Driver task
// This top level thread process all usb events and invoke callbacks
-static void usb_device_task(void *param) {
+void usb_device_task(void* param)
+{
(void) param;
- // init device stack on configured roothub port
// This should be called after scheduler/kernel is started.
// Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API.
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
// RTOS forever loop
- while (1) {
- // put this thread to waiting state until there is new events
+ while (1)
+ {
+ // tinyusb device task
tud_task();
-
- // following code only run if tud_task() process at least 1 event
- tud_cdc_write_flush();
}
}
@@ -153,46 +142,49 @@ static void usb_device_task(void *param) {
//--------------------------------------------------------------------+
// Invoked when device is mounted
-void tud_mount_cb(void) {
+void tud_mount_cb(void)
+{
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
}
// Invoked when device is unmounted
-void tud_umount_cb(void) {
+void tud_umount_cb(void)
+{
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
}
// Invoked when usb bus is suspended
// remote_wakeup_en : if host allow us to perform remote wakeup
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
-void tud_suspend_cb(bool remote_wakeup_en) {
+void tud_suspend_cb(bool remote_wakeup_en)
+{
(void) remote_wakeup_en;
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_SUSPENDED), 0);
}
// Invoked when usb bus is resumed
-void tud_resume_cb(void) {
- if (tud_mounted()) {
- xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
- } else {
- xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
- }
+void tud_resume_cb(void)
+{
+ xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
}
//--------------------------------------------------------------------+
// USB CDC
//--------------------------------------------------------------------+
-void cdc_task(void *params) {
+void cdc_task(void* params)
+{
(void) params;
// RTOS forever loop
- while (1) {
+ while ( 1 )
+ {
// connected() check for DTR bit
// Most but not all terminal client set this when making connection
// if ( tud_cdc_connected() )
{
// There are data available
- while (tud_cdc_available()) {
+ if ( tud_cdc_available() )
+ {
uint8_t buf[64];
// read and echo back
@@ -204,38 +196,42 @@ void cdc_task(void *params) {
// for throughput test e.g
// $ dd if=/dev/zero of=/dev/ttyACM0 count=10000
tud_cdc_write(buf, count);
+ tud_cdc_write_flush();
}
-
- tud_cdc_write_flush();
}
- // For ESP32-Sx this delay is essential to allow idle how to run and reset watchdog
- vTaskDelay(1);
+ // For ESP32-S2 this delay is essential to allow idle how to run and reset wdt
+ vTaskDelay(pdMS_TO_TICKS(10));
}
}
// Invoked when cdc when line state changed e.g connected/disconnected
-void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
+void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
+{
(void) itf;
(void) rts;
// TODO set some indicator
- if (dtr) {
+ if ( dtr )
+ {
// Terminal connected
- } else {
+ }else
+ {
// Terminal disconnected
}
}
// Invoked when CDC interface received data from host
-void tud_cdc_rx_cb(uint8_t itf) {
+void tud_cdc_rx_cb(uint8_t itf)
+{
(void) itf;
}
//--------------------------------------------------------------------+
// BLINKING TASK
//--------------------------------------------------------------------+
-static void led_blinky_cb(TimerHandle_t xTimer) {
+void led_blinky_cb(TimerHandle_t xTimer)
+{
(void) xTimer;
static bool led_state = false;
diff --git a/examples/device/cdc_msc_freertos/src/msc_disk.c b/examples/device/cdc_msc_freertos/src/msc_disk.c
index 9520dfec1..b9205f0c2 100644
--- a/examples/device/cdc_msc_freertos/src/msc_disk.c
+++ b/examples/device/cdc_msc_freertos/src/msc_disk.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,7 @@
*
*/
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#if CFG_TUD_MSC
@@ -221,6 +221,11 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
switch (scsi_cmd[0])
{
+ case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
+ // Host is about to read/write etc ... better not to disconnect disk
+ resplen = 0;
+ break;
+
default:
// Set Sense = Invalid Command Operation
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
diff --git a/examples/device/cdc_msc_freertos/src/tusb_config.h b/examples/device/cdc_msc_freertos/src/tusb_config.h
index 91efe7d40..d4bbdee48 100644
--- a/examples/device/cdc_msc_freertos/src/tusb_config.h
+++ b/examples/device/cdc_msc_freertos/src/tusb_config.h
@@ -30,50 +30,53 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
// This examples use FreeRTOS
-#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_FREERTOS
-#endif
+#define CFG_TUSB_OS OPT_OS_FREERTOS
// Espressif IDF requires "freertos/" prefix in include path
-#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
-#define CFG_TUSB_OS_INC_PATH freertos/
+#if TU_CHECK_MCU(ESP32S2) || TU_CHECK_MCU(ESP32S3)
+ #define CFG_TUSB_OS_INC_PATH freertos/
#endif
// can be defined by compiler in DEBUG build
#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
+ #define CFG_TUSB_DEBUG 0
#endif
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
-
/* 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.
@@ -86,7 +89,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
@@ -94,7 +97,7 @@
//--------------------------------------------------------------------
#ifndef CFG_TUD_ENDPOINT0_SIZE
-#define CFG_TUD_ENDPOINT0_SIZE 64
+#define CFG_TUD_ENDPOINT0_SIZE 64
#endif
//------------- CLASS -------------//
diff --git a/examples/device/cdc_msc_freertos/src/usb_descriptors.c b/examples/device/cdc_msc_freertos/src/usb_descriptors.c
index 9c29701c7..9585822a3 100644
--- a/examples/device/cdc_msc_freertos/src/usb_descriptors.c
+++ b/examples/device/cdc_msc_freertos/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
@@ -213,65 +212,53 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456789012", // 3: Serials, should use chip ID
"TinyUSB CDC", // 4: CDC Interface
"TinyUSB MSC", // 5: MSC Interface
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
-family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-
-project(${PROJECT} C CXX ASM)
-
-# Checks this example is valid for the family and initializes the project
-family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
-add_executable(${PROJECT})
-
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/cdc_app.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/uac2_app.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- )
-
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
-
-# Configure compilation flags and libraries for the example... see the corresponding function
-# in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
-
-# Uncomment me to enable UART based debugging
-# pico_enable_stdio_uart(${PROJECT} 1)
diff --git a/examples/device/cdc_uac2/Makefile b/examples/device/cdc_uac2/Makefile
deleted file mode 100644
index b7a8302ce..000000000
--- a/examples/device/cdc_uac2/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-include ../../make.mk
-
-INC += \
- src \
- $(TOP)/hw \
-
-# Example source
-EXAMPLE_SOURCE += \
- src/cdc_app.c \
- src/main.c \
- src/uac2_app.c \
- src/usb_descriptors.c \
-
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
-
-include ../../rules.mk
diff --git a/examples/device/cdc_uac2/README.md b/examples/device/cdc_uac2/README.md
deleted file mode 100644
index 5d120be7d..000000000
--- a/examples/device/cdc_uac2/README.md
+++ /dev/null
@@ -1,52 +0,0 @@
-#### Composite CDC + UAC2 on Pico
-
-This example provides a composite CDC + UAC2 device on top of a Raspberry Pi
-Pico board.
-
-
-#### Use Cases
-
-- The CDC + UAC2 composite device happens to be important, especially in the
- amateur radio community.
-
- Modern radios (`rigs`) like Icom IC-7300 + IC-705 expose a sound card and a
- serial device (`composite device`) to the computer over a single USB cable.
- This allows for Audio I/O and CAT control over a single USB cable which is
- very convenient.
-
- By including and maintaining this example in TinyUSB repository, we enable
- the amateur radio community to build (`homebrew`) radios with similar
- functionality as the (expensive) commercial rigs.
-
- This PR is important in bridging this specific gap between the commercial
- rigs and homebrew equipment.
-
-- https://digirig.net/digirig-mobile-rev-1-9/ is a digital interface for
- interfacing radios (that lack an inbuilt digital interface) with computers.
- Digirig Mobile works brilliantly (is OSS!) and is a big improvement over
- traditional digital interfaces (like the SignaLink USB Interface). By using a
- Raspberry Pi Pico powered CDC + UAC2 composite device, we can simplify the
- Digirig Mobile schematic, drastically reduce the manufacturing cost, and
- (again) enable the homebrewers community to homebrew a modern digital interface
- with ease themselves.
-
-
-#### Build Steps
-
-```
-cd examples/device/cdc_uac2
-
-export PICO_SDK_PATH=$HOME/pico-sdk
-
-cmake -DFAMILY=rp2040 pico .
-
-cmake -DFAMILY=rp2040 -DCMAKE_BUILD_TYPE=Debug # use this for debugging
-
-make BOARD=raspberry_pi_pico all
-```
-
-
-#### Development Notes
-
-Please try to keep this code synchronized with the `uac2_headset` example
-included in this repository.
diff --git a/examples/device/cdc_uac2/src/cdc_app.c b/examples/device/cdc_uac2/src/cdc_app.c
deleted file mode 100644
index 2166c1d6b..000000000
--- a/examples/device/cdc_uac2/src/cdc_app.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- * Copyright (c) 2022 Angel Molina (angelmolinu@gmail.com)
- *
- * 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 "bsp/board_api.h"
-#include "tusb.h"
-#include "common.h"
-
-// Invoked when cdc when line state changed e.g connected/disconnected
-void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
-{
- (void) itf;
- (void) rts;
-
- if (dtr)
- {
- // Terminal connected
- }
- else
- {
- // Terminal disconnected
- }
-}
-
-// Invoked when CDC interface received data from host
-void tud_cdc_rx_cb(uint8_t itf)
-{
- uint8_t buf[64];
- uint32_t count;
-
- // connected() check for DTR bit
- // Most but not all terminal client set this when making connection
- if (tud_cdc_connected())
- {
- if (tud_cdc_available()) // data is available
- {
- count = tud_cdc_n_read(itf, buf, sizeof(buf));
- (void) count;
-
- tud_cdc_n_write(itf, buf, count);
- tud_cdc_n_write_flush(itf);
- // dummy code to check that cdc serial is responding
- board_led_write(0);
- board_delay(50);
- board_led_write(1);
- board_delay(50);
- board_led_write(0);
- }
- }
-}
diff --git a/examples/device/cdc_uac2/src/common.h b/examples/device/cdc_uac2/src/common.h
deleted file mode 100644
index f281024c7..000000000
--- a/examples/device/cdc_uac2/src/common.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef __COMMON_H__
-#define __COMMON_H__
-
-/* Blink pattern
- * - 25 ms : streaming data
- * - 250 ms : device not mounted
- * - 1000 ms : device mounted
- * - 2500 ms : device is suspended
- */
-enum
-{
- BLINK_STREAMING = 25,
- BLINK_NOT_MOUNTED = 250,
- BLINK_MOUNTED = 1000,
- BLINK_SUSPENDED = 2500,
-};
-
-enum
-{
- VOLUME_CTRL_0_DB = 0,
- VOLUME_CTRL_10_DB = 2560,
- VOLUME_CTRL_20_DB = 5120,
- VOLUME_CTRL_30_DB = 7680,
- VOLUME_CTRL_40_DB = 10240,
- VOLUME_CTRL_50_DB = 12800,
- VOLUME_CTRL_60_DB = 15360,
- VOLUME_CTRL_70_DB = 17920,
- VOLUME_CTRL_80_DB = 20480,
- VOLUME_CTRL_90_DB = 23040,
- VOLUME_CTRL_100_DB = 25600,
- VOLUME_CTRL_SILENCE = 0x8000,
-};
-
-#endif
diff --git a/examples/device/cdc_uac2/src/main.c b/examples/device/cdc_uac2/src/main.c
deleted file mode 100644
index 7afa96c1a..000000000
--- a/examples/device/cdc_uac2/src/main.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Jerzy Kasenberg
- * Copyright (c) 2022 Angel Molina
- * Copyright (c) 2023 Dhiru Kholia
- *
- * 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
-#include
-
-#include "bsp/board_api.h"
-#include "tusb.h"
-#include "common.h"
-
-extern uint32_t blink_interval_ms;
-
-#if (CFG_TUSB_MCU == OPT_MCU_RP2040)
-#include "pico/stdlib.h"
-#endif
-
-void led_blinking_task(void);
-
-/*------------- MAIN -------------*/
-int main(void)
-{
- board_init();
-
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
-#if (CFG_TUSB_MCU == OPT_MCU_RP2040)
- stdio_init_all();
-#endif
-
- TU_LOG1("CDC UAC2 example running\r\n");
-
- while (1)
- {
- tud_task(); // TinyUSB device task
- led_blinking_task();
-
-#if (CFG_TUSB_MCU == OPT_MCU_RP2040)
- // printf("Hello, world!\n");
-#endif
- }
-
- return 0;
-}
-
-//--------------------------------------------------------------------+
-// Device callbacks
-//--------------------------------------------------------------------+
-
-// Invoked when device is mounted
-void tud_mount_cb(void)
-{
- blink_interval_ms = BLINK_MOUNTED;
-}
-
-// Invoked when device is unmounted
-void tud_umount_cb(void)
-{
- blink_interval_ms = BLINK_NOT_MOUNTED;
-}
-
-// Invoked when usb bus is suspended
-// remote_wakeup_en : if host allow us to perform remote wakeup
-// Within 7ms, device must draw an average of current less than 2.5 mA from bus
-void tud_suspend_cb(bool remote_wakeup_en)
-{
- (void)remote_wakeup_en;
- blink_interval_ms = BLINK_SUSPENDED;
-}
-
-// Invoked when usb bus is resumed
-void tud_resume_cb(void)
-{
- blink_interval_ms = BLINK_MOUNTED;
-}
diff --git a/examples/device/cdc_uac2/src/tusb_config.h b/examples/device/cdc_uac2/src/tusb_config.h
deleted file mode 100644
index 373f0b01f..000000000
--- a/examples/device/cdc_uac2/src/tusb_config.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Ha Thach (tinyusb.org)
- * Copyright (c) 2020 Jerzy Kasenberg
- *
- * 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_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "usb_descriptors.h"
-
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
-//--------------------------------------------------------------------
-// Common Configuration
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
-#endif
-
-#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
-#endif
-
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
-
-/* 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
-//--------------------------------------------------------------------
-
-#ifndef CFG_TUD_ENDPOINT0_SIZE
-#define CFG_TUD_ENDPOINT0_SIZE 64
-#endif
-
-//------------- CLASS -------------//
-#define CFG_TUD_CDC 1
-#define CFG_TUD_MSC 0
-#define CFG_TUD_HID 0
-#define CFG_TUD_MIDI 0
-#define CFG_TUD_AUDIO 1
-#define CFG_TUD_VENDOR 0
-
-//--------------------------------------------------------------------
-// AUDIO CLASS DRIVER CONFIGURATION
-//--------------------------------------------------------------------
-
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_HEADSET_STEREO_DESC_LEN
-
-// How many formats are used, need to adjust USB descriptor if changed
-#define CFG_TUD_AUDIO_FUNC_1_N_FORMATS 2
-
-// Audio format type I specifications
-#if defined(__RX__)
-#define CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE 48000 // 16bit/48kHz is the best quality for Renesas RX
-#else
-#define CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE 96000 // 24bit/96kHz is the best quality for full-speed, high-speed is needed beyond this
-#endif
-#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 1
-#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX 1 // Changed
-
-// 16bit in 16bit slots
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX 2
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_TX 16
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX 2
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX 16
-
-#if defined(__RX__)
-// 8bit in 8bit slots
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX 1
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_TX 8
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX 1
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX 8
-#else
-// 24bit in 32bit slots
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX 4
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_TX 24
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX 4
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX 24
-#endif
-
-// EP and buffer size - for isochronous EP´s, the buffer and EP size are equal (different sizes would not make sense)
-#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
-
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
-
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ TU_MAX(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN)
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX TU_MAX(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN) // Maximum EP IN size for all AS alternate settings used
-
-// EP and buffer size - for isochronous EP´s, the buffer and EP size are equal (different sizes would not make sense)
-#define CFG_TUD_AUDIO_ENABLE_EP_OUT 1
-
-#define CFG_TUD_AUDIO_UNC_1_FORMAT_1_EP_SZ_OUT TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
-#define CFG_TUD_AUDIO_UNC_1_FORMAT_2_EP_SZ_OUT TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
-
-#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ TU_MAX(CFG_TUD_AUDIO_UNC_1_FORMAT_1_EP_SZ_OUT, CFG_TUD_AUDIO_UNC_1_FORMAT_1_EP_SZ_OUT)
-#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX TU_MAX(CFG_TUD_AUDIO_UNC_1_FORMAT_1_EP_SZ_OUT, CFG_TUD_AUDIO_UNC_1_FORMAT_1_EP_SZ_OUT) // Maximum EP IN size for all AS alternate settings used
-
-// Number of Standard AS Interface Descriptors (4.9.1) defined per audio function - this is required to be able to remember the current alternate settings of these interfaces - We restrict us here to have a constant number for all audio functions (which means this has to be the maximum number of AS interfaces an audio function has and a second audio function with less AS interfaces just wastes a few bytes)
-#define CFG_TUD_AUDIO_FUNC_1_N_AS_INT 2
-
-// Size of control request buffer
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64
-
-// CDC FIFO size of TX and RX
-#define CFG_TUD_CDC_RX_BUFSIZE 64
-#define CFG_TUD_CDC_TX_BUFSIZE 64
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _TUSB_CONFIG_H_ */
diff --git a/examples/device/cdc_uac2/src/uac2_app.c b/examples/device/cdc_uac2/src/uac2_app.c
deleted file mode 100644
index 98659ea68..000000000
--- a/examples/device/cdc_uac2/src/uac2_app.c
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Jerzy Kasenberg
- * Copyright (c) 2022 Angel Molina (angelmolinu@gmail.com)
- *
- * 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
-#include
-
-#include "bsp/board_api.h"
-#include "tusb.h"
-#include "usb_descriptors.h"
-#include "common.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF PROTOTYPES
-//--------------------------------------------------------------------+
-
-// List of supported sample rates
-const uint32_t sample_rates[] = {44100, 48000};
-uint32_t current_sample_rate = 44100;
-
-#define N_SAMPLE_RATES TU_ARRAY_SIZE(sample_rates)
-
-uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
-
-// Audio controls
-// Current states
-int8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1]; // +1 for master channel 0
-int16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1]; // +1 for master channel 0
-
-// Buffer for microphone data
-int32_t mic_buf[CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ / 4];
-// Buffer for speaker data
-int32_t spk_buf[CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ / 4];
-// Speaker data size received in the last frame
-int spk_data_size;
-// Resolution per format
-const uint8_t resolutions_per_format[CFG_TUD_AUDIO_FUNC_1_N_FORMATS] = {CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX};
-// Current resolution, update on format change
-uint8_t current_resolution;
-
-// Helper for clock get requests
-static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t const *request)
-{
- TU_ASSERT(request->bEntityID == UAC2_ENTITY_CLOCK);
-
- if (request->bControlSelector == AUDIO_CS_CTRL_SAM_FREQ)
- {
- if (request->bRequest == AUDIO_CS_REQ_CUR)
- {
- TU_LOG1("Clock get current freq %lu\r\n", current_sample_rate);
-
- audio_control_cur_4_t curf = { (int32_t) tu_htole32(current_sample_rate) };
- return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &curf, sizeof(curf));
- }
- else if (request->bRequest == AUDIO_CS_REQ_RANGE)
- {
- audio_control_range_4_n_t(N_SAMPLE_RATES) rangef =
- {
- .wNumSubRanges = tu_htole16(N_SAMPLE_RATES)
- };
- TU_LOG1("Clock get %d freq ranges\r\n", N_SAMPLE_RATES);
- for(uint8_t i = 0; i < N_SAMPLE_RATES; i++)
- {
- rangef.subrange[i].bMin = (int32_t) sample_rates[i];
- rangef.subrange[i].bMax = (int32_t) sample_rates[i];
- rangef.subrange[i].bRes = 0;
- TU_LOG1("Range %d (%d, %d, %d)\r\n", i, (int)rangef.subrange[i].bMin, (int)rangef.subrange[i].bMax, (int)rangef.subrange[i].bRes);
- }
-
- return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &rangef, sizeof(rangef));
- }
- }
- else if (request->bControlSelector == AUDIO_CS_CTRL_CLK_VALID &&
- request->bRequest == AUDIO_CS_REQ_CUR)
- {
- audio_control_cur_1_t cur_valid = { .bCur = 1 };
- TU_LOG1("Clock get is valid %u\r\n", cur_valid.bCur);
- return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &cur_valid, sizeof(cur_valid));
- }
- TU_LOG1("Clock get request not supported, entity = %u, selector = %u, request = %u\r\n",
- request->bEntityID, request->bControlSelector, request->bRequest);
- return false;
-}
-
-// Helper for clock set requests
-static bool tud_audio_clock_set_request(uint8_t rhport, audio_control_request_t const *request, uint8_t const *buf)
-{
- (void)rhport;
-
- TU_ASSERT(request->bEntityID == UAC2_ENTITY_CLOCK);
- TU_VERIFY(request->bRequest == AUDIO_CS_REQ_CUR);
-
- if (request->bControlSelector == AUDIO_CS_CTRL_SAM_FREQ)
- {
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_4_t));
-
- current_sample_rate = (uint32_t) ((audio_control_cur_4_t const *)buf)->bCur;
-
- TU_LOG1("Clock set current freq: %ld\r\n", current_sample_rate);
-
- return true;
- }
- else
- {
- TU_LOG1("Clock set request not supported, entity = %u, selector = %u, request = %u\r\n",
- request->bEntityID, request->bControlSelector, request->bRequest);
- return false;
- }
-}
-
-// Helper for feature unit get requests
-static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio_control_request_t const *request)
-{
- TU_ASSERT(request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT);
-
- if (request->bControlSelector == AUDIO_FU_CTRL_MUTE && request->bRequest == AUDIO_CS_REQ_CUR)
- {
- audio_control_cur_1_t mute1 = { .bCur = mute[request->bChannelNumber] };
- TU_LOG1("Get channel %u mute %d\r\n", request->bChannelNumber, mute1.bCur);
- return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &mute1, sizeof(mute1));
- }
- else if (UAC2_ENTITY_SPK_FEATURE_UNIT && request->bControlSelector == AUDIO_FU_CTRL_VOLUME)
- {
- if (request->bRequest == AUDIO_CS_REQ_RANGE)
- {
- audio_control_range_2_n_t(1) range_vol = {
- .wNumSubRanges = tu_htole16(1),
- .subrange[0] = { .bMin = tu_htole16(-VOLUME_CTRL_50_DB), tu_htole16(VOLUME_CTRL_0_DB), tu_htole16(256) }
- };
- TU_LOG1("Get channel %u volume range (%d, %d, %u) dB\r\n", request->bChannelNumber,
- range_vol.subrange[0].bMin / 256, range_vol.subrange[0].bMax / 256, range_vol.subrange[0].bRes / 256);
- return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &range_vol, sizeof(range_vol));
- }
- else if (request->bRequest == AUDIO_CS_REQ_CUR)
- {
- audio_control_cur_2_t cur_vol = { .bCur = tu_htole16(volume[request->bChannelNumber]) };
- TU_LOG1("Get channel %u volume %d dB\r\n", request->bChannelNumber, cur_vol.bCur / 256);
- return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &cur_vol, sizeof(cur_vol));
- }
- }
- TU_LOG1("Feature unit get request not supported, entity = %u, selector = %u, request = %u\r\n",
- request->bEntityID, request->bControlSelector, request->bRequest);
-
- return false;
-}
-
-// Helper for feature unit set requests
-static bool tud_audio_feature_unit_set_request(uint8_t rhport, audio_control_request_t const *request, uint8_t const *buf)
-{
- (void)rhport;
-
- TU_ASSERT(request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT);
- TU_VERIFY(request->bRequest == AUDIO_CS_REQ_CUR);
-
- if (request->bControlSelector == AUDIO_FU_CTRL_MUTE)
- {
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_1_t));
-
- mute[request->bChannelNumber] = ((audio_control_cur_1_t const *)buf)->bCur;
-
- TU_LOG1("Set channel %d Mute: %d\r\n", request->bChannelNumber, mute[request->bChannelNumber]);
-
- return true;
- }
- else if (request->bControlSelector == AUDIO_FU_CTRL_VOLUME)
- {
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_2_t));
-
- volume[request->bChannelNumber] = ((audio_control_cur_2_t const *)buf)->bCur;
-
- TU_LOG1("Set channel %d volume: %d dB\r\n", request->bChannelNumber, volume[request->bChannelNumber] / 256);
-
- return true;
- }
- else
- {
- TU_LOG1("Feature unit set request not supported, entity = %u, selector = %u, request = %u\r\n",
- request->bEntityID, request->bControlSelector, request->bRequest);
- return false;
- }
-}
-
-//--------------------------------------------------------------------+
-// Application Callback API Implementations
-//--------------------------------------------------------------------+
-
-// Invoked when audio class specific get request received for an entity
-bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request)
-{
- audio_control_request_t const *request = (audio_control_request_t const *)p_request;
-
- if (request->bEntityID == UAC2_ENTITY_CLOCK)
- return tud_audio_clock_get_request(rhport, request);
- if (request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT)
- return tud_audio_feature_unit_get_request(rhport, request);
- else
- {
- TU_LOG1("Get request not handled, entity = %d, selector = %d, request = %d\r\n",
- request->bEntityID, request->bControlSelector, request->bRequest);
- }
- return false;
-}
-
-// Invoked when audio class specific set request received for an entity
-bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *buf)
-{
- audio_control_request_t const *request = (audio_control_request_t const *)p_request;
-
- if (request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT)
- return tud_audio_feature_unit_set_request(rhport, request, buf);
- if (request->bEntityID == UAC2_ENTITY_CLOCK)
- return tud_audio_clock_set_request(rhport, request, buf);
- TU_LOG1("Set request not handled, entity = %d, selector = %d, request = %d\r\n",
- request->bEntityID, request->bControlSelector, request->bRequest);
-
- return false;
-}
-
-bool tud_audio_set_itf_close_EP_cb(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- (void)rhport;
-
- uint8_t const itf = tu_u16_low(tu_le16toh(p_request->wIndex));
- uint8_t const alt = tu_u16_low(tu_le16toh(p_request->wValue));
-
- if (ITF_NUM_AUDIO_STREAMING_SPK == itf && alt == 0) {
- // Audio streaming stop
- blink_interval_ms = BLINK_MOUNTED;
- }
-
- return true;
-}
-
-bool tud_audio_set_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- (void)rhport;
- uint8_t const itf = tu_u16_low(tu_le16toh(p_request->wIndex));
- uint8_t const alt = tu_u16_low(tu_le16toh(p_request->wValue));
-
- TU_LOG2("Set interface %d alt %d\r\n", itf, alt);
- if (ITF_NUM_AUDIO_STREAMING_SPK == itf && alt != 0) {
- // Audio streaming start
- blink_interval_ms = BLINK_STREAMING;
- }
-
- // Clear buffer when streaming format is changed
- spk_data_size = 0;
- if(alt != 0)
- {
- current_resolution = resolutions_per_format[alt-1];
- }
-
- return true;
-}
-
-bool tud_audio_rx_done_pre_read_cb(uint8_t rhport, uint16_t n_bytes_received, uint8_t func_id, uint8_t ep_out, uint8_t cur_alt_setting)
-{
- (void)rhport;
- (void)func_id;
- (void)ep_out;
- (void)cur_alt_setting;
-
- spk_data_size = tud_audio_read(spk_buf, n_bytes_received);
- tud_audio_write(spk_buf, n_bytes_received);
-
- return true;
-}
-
-bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t itf, uint8_t ep_in, uint8_t cur_alt_setting)
-{
- (void)rhport;
- (void)itf;
- (void)ep_in;
- (void)cur_alt_setting;
-
- // This callback could be used to fill microphone data separately
- return true;
-}
-
-//--------------------------------------------------------------------+
-// BLINKING TASK
-//--------------------------------------------------------------------+
-void led_blinking_task(void)
-{
- static uint32_t start_ms = 0;
- static bool led_state = false;
-
- // Blink every interval ms
- if (board_millis() - start_ms < blink_interval_ms) return;
- start_ms += blink_interval_ms;
-
- board_led_write(led_state);
- led_state = 1 - led_state;
-}
diff --git a/examples/device/cdc_uac2/src/usb_descriptors.c b/examples/device/cdc_uac2/src/usb_descriptors.c
deleted file mode 100644
index 72a695622..000000000
--- a/examples/device/cdc_uac2/src/usb_descriptors.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Ha Thach (tinyusb.org)
- * Copyright (c) 2020 Jerzy Kasenberg
- * Copyright (c) 2022 Angel Molina (angelmolinu@gmail.com)
- *
- * 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 "bsp/board_api.h"
-#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.
- *
- * Auto ProductID layout's Bitmap:
- * [MSB] AUDIO | MIDI | HID | MSC | CDC [LSB]
- */
-#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
-#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
- _PID_MAP(MIDI, 3) | _PID_MAP(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
-
-//--------------------------------------------------------------------+
-// Device Descriptors
-//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
-{
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
- .bcdUSB = 0x0200,
-
- // Use Interface Association Descriptor (IAD)
- // 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,
- .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
-
- .idVendor = 0xCafe,
- .idProduct = USB_PID,
- .bcdDevice = 0x0100,
-
- .iManufacturer = 0x01,
- .iProduct = 0x02,
- .iSerialNumber = 0x03,
-
- .bNumConfigurations = 0x01
-};
-
-// Invoked when received GET DEVICE DESCRIPTOR
-// Application return pointer to descriptor
-uint8_t const * tud_descriptor_device_cb(void)
-{
- return (uint8_t const *)&desc_device;
-}
-
-//--------------------------------------------------------------------+
-// Configuration Descriptor
-//--------------------------------------------------------------------+
-#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_HEADSET_STEREO_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN)
-
-#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
- // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
- // 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
- #define EPNUM_AUDIO_IN 0x03
- #define EPNUM_AUDIO_OUT 0x03
-
- #define EPNUM_CDC_NOTIF 0x84
- #define EPNUM_CDC_OUT 0x05
- #define EPNUM_CDC_IN 0x85
-
-#elif CFG_TUSB_MCU == OPT_MCU_NRF5X
- // ISO endpoints for NRF5x are fixed to 0x08 (0x88)
- #define EPNUM_AUDIO_IN 0x08
- #define EPNUM_AUDIO_OUT 0x08
-
- #define EPNUM_CDC_NOTIF 0x81
- #define EPNUM_CDC_OUT 0x02
- #define EPNUM_CDC_IN 0x82
-
-#elif CFG_TUSB_MCU == OPT_MCU_SAMG || CFG_TUSB_MCU == OPT_MCU_SAMX7X
- // SAMG & SAME70 don't support a same endpoint number with different direction IN and OUT
- // e.g EP1 OUT & EP1 IN cannot exist together
- #define EPNUM_AUDIO_IN 0x01
- #define EPNUM_AUDIO_OUT 0x02
-
- #define EPNUM_CDC_NOTIF 0x83
- #define EPNUM_CDC_OUT 0x04
- #define EPNUM_CDC_IN 0x85
-
-#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
- // FT9XX doesn't support a same endpoint number with different direction IN and OUT
- // e.g EP1 OUT & EP1 IN cannot exist together
- #define EPNUM_AUDIO_IN 0x01
- #define EPNUM_AUDIO_OUT 0x02
-
- #define EPNUM_CDC_NOTIF 0x83
- #define EPNUM_CDC_OUT 0x04
- #define EPNUM_CDC_IN 0x85
-
-#else
- #define EPNUM_AUDIO_IN 0x01
- #define EPNUM_AUDIO_OUT 0x01
-
- #define EPNUM_CDC_NOTIF 0x83
- #define EPNUM_CDC_OUT 0x04
- #define EPNUM_CDC_IN 0x84
-#endif
-
-uint8_t const desc_configuration[] =
-{
- // Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
-
- // Interface number, string index, EP Out & EP In address, EP size
- TUD_AUDIO_HEADSET_STEREO_DESCRIPTOR(2, EPNUM_AUDIO_OUT, EPNUM_AUDIO_IN | 0x80),
-
- // CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
- TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 6, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64)
-};
-
-// Invoked when received GET CONFIGURATION DESCRIPTOR
-// Application return pointer to descriptor
-// Descriptor contents must exist long enough for transfer to complete
-uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
-{
- (void)index; // for multiple configurations
- return desc_configuration;
-}
-
-//--------------------------------------------------------------------+
-// String Descriptors
-//--------------------------------------------------------------------+
-
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
-// array of pointer to string descriptors
-char const *string_desc_arr[] =
-{
- (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
- "TinyUSB", // 1: Manufacturer
- "TinyUSB headset", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
- "TinyUSB Speakers", // 4: Audio Interface
- "TinyUSB Microphone", // 5: Audio Interface
- "TinyUSB CDC", // 6: Audio Interface
-};
-
-static uint16_t _desc_str[32 + 1];
-
-// Invoked when received GET STRING DESCRIPTOR request
-// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
- (void) langid;
- size_t chr_count;
-
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
-
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
-
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
-
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
-
- const char *str = string_desc_arr[index];
-
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
- }
-
- // first byte is length (including header), second byte is string type
- _desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
-
- return _desc_str;
-}
diff --git a/examples/device/cdc_uac2/src/usb_descriptors.h b/examples/device/cdc_uac2/src/usb_descriptors.h
deleted file mode 100644
index 736feeefe..000000000
--- a/examples/device/cdc_uac2/src/usb_descriptors.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Jerzy Kasenbreg
- * Copyright (c) 2022 Angel Molina (angelmolinu@gmail.com)
- *
- * 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_
-
-// #include "tusb.h"
-
-// Unit numbers are arbitrary selected
-#define UAC2_ENTITY_CLOCK 0x04
-// Speaker path
-#define UAC2_ENTITY_SPK_INPUT_TERMINAL 0x01
-#define UAC2_ENTITY_SPK_FEATURE_UNIT 0x02
-#define UAC2_ENTITY_SPK_OUTPUT_TERMINAL 0x03
-// Microphone path
-#define UAC2_ENTITY_MIC_INPUT_TERMINAL 0x11
-#define UAC2_ENTITY_MIC_OUTPUT_TERMINAL 0x13
-
-enum
-{
- ITF_NUM_AUDIO_CONTROL = 0,
- ITF_NUM_AUDIO_STREAMING_SPK,
- ITF_NUM_AUDIO_STREAMING_MIC,
- ITF_NUM_CDC,
- ITF_NUM_CDC_DATA,
- ITF_NUM_TOTAL
-};
-
-#define TUD_AUDIO_HEADSET_STEREO_DESC_LEN (TUD_AUDIO_DESC_IAD_LEN\
- + TUD_AUDIO_DESC_STD_AC_LEN\
- + TUD_AUDIO_DESC_CS_AC_LEN\
- + TUD_AUDIO_DESC_CLK_SRC_LEN\
- + TUD_AUDIO_DESC_INPUT_TERM_LEN\
- + TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL_LEN\
- + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
- + TUD_AUDIO_DESC_INPUT_TERM_LEN\
- + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
- /* Interface 1, Alternate 0 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- /* Interface 1, Alternate 0 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
- /* Interface 1, Alternate 2 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
- /* Interface 2, Alternate 0 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- /* Interface 2, Alternate 1 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
- /* Interface 2, Alternate 2 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN)
-
-#define TUD_AUDIO_HEADSET_STEREO_DESCRIPTOR(_stridx, _epout, _epin) \
- /* Standard Interface Association Descriptor (IAD) */\
- TUD_AUDIO_DESC_IAD(/*_firstitfs*/ ITF_NUM_AUDIO_CONTROL, /*_nitfs*/ 3, /*_stridx*/ 0x00),\
- /* Standard AC Interface Descriptor(4.7.1) */\
- TUD_AUDIO_DESC_STD_AC(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
- /* Class-Specific AC Interface Header Descriptor(4.7.2) */\
- TUD_AUDIO_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO_FUNC_HEADSET, /*_totallen*/ TUD_AUDIO_DESC_CLK_SRC_LEN+TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN, /*_ctrl*/ AUDIO_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
- /* Clock Source Descriptor(4.7.2.1) */\
- TUD_AUDIO_DESC_CLK_SRC(/*_clkid*/ UAC2_ENTITY_CLOCK, /*_attr*/ 3, /*_ctrl*/ 7, /*_assocTerm*/ 0x00, /*_stridx*/ 0x00), \
- /* Input Terminal Descriptor(4.7.2.4) */\
- TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x02, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
- /* Feature Unit Descriptor(4.7.2.8) */\
- TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL(/*_unitid*/ UAC2_ENTITY_SPK_FEATURE_UNIT, /*_srcid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrlch0master*/ (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch1*/ (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch2*/ (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_stridx*/ 0x00),\
- /* Output Terminal Descriptor(4.7.2.5) */\
- TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_SPK_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_OUT_HEADPHONES, /*_assocTerm*/ 0x00, /*_srcid*/ UAC2_ENTITY_SPK_FEATURE_UNIT, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
- /* Input Terminal Descriptor(4.7.2.4) */\
- TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_MIC_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ 0x00, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
- /* Output Terminal Descriptor(4.7.2.5) */\
- TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_srcid*/ UAC2_ENTITY_MIC_INPUT_TERMINAL, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
- /* Standard AS Interface Descriptor(4.9.1) */\
- /* Interface 1, Alternate 0 - default alternate setting with 0 bandwidth */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x05),\
- /* Standard AS Interface Descriptor(4.9.1) */\
- /* Interface 1, Alternate 1 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x05),\
- /* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
- /* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX),\
- /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ADAPTIVE | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
- /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
- /* Interface 1, Alternate 2 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x05),\
- /* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
- /* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX),\
- /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ADAPTIVE | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
- /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
- /* Standard AS Interface Descriptor(4.9.1) */\
- /* Interface 2, Alternate 0 - default alternate setting with 0 bandwidth */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x04),\
- /* Standard AS Interface Descriptor(4.9.1) */\
- /* Interface 2, Alternate 1 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x04),\
- /* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
- /* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_TX),\
- /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
- /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
- /* Interface 2, Alternate 2 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x04),\
- /* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
- /* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_TX),\
- /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
- /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
-
-#endif
diff --git a/examples/device/dfu/CMakeLists.txt b/examples/device/dfu/CMakeLists.txt
index a01eb3456..abc4d91da 100644
--- a/examples/device/dfu/CMakeLists.txt
+++ b/examples/device/dfu/CMakeLists.txt
@@ -1,18 +1,14 @@
-cmake_minimum_required(VERSION 3.17)
+cmake_minimum_required(VERSION 3.5)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
# gets PROJECT name for the example (e.g. -)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
add_executable(${PROJECT})
@@ -27,6 +23,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/dfu/Makefile b/examples/device/dfu/Makefile
index b3f2cc588..69b633fea 100644
--- a/examples/device/dfu/Makefile
+++ b/examples/device/dfu/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
@@ -5,10 +6,7 @@ INC += \
$(TOP)/hw \
# Example source
-EXAMPLE_SOURCE = \
- src/main.c \
- src/usb_descriptors.c
-
+EXAMPLE_SOURCE += $(wildcard src/*.c)
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
include ../../rules.mk
diff --git a/examples/device/dfu/skip.txt b/examples/device/dfu/skip.txt
deleted file mode 100644
index 9ac346bad..000000000
--- a/examples/device/dfu/skip.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-mcu:TM4C123
-mcu:BCM2835
diff --git a/examples/device/dfu/src/main.c b/examples/device/dfu/src/main.c
index 81fc0a62c..5c8464526 100644
--- a/examples/device/dfu/src/main.c
+++ b/examples/device/dfu/src/main.c
@@ -42,7 +42,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//--------------------------------------------------------------------+
@@ -74,18 +74,15 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
tud_task(); // tinyusb device task
led_blinking_task();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -116,7 +113,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
diff --git a/examples/device/dfu/src/tusb_config.h b/examples/device/dfu/src/tusb_config.h
index 38064147c..66e357021 100644
--- a/examples/device/dfu/src/tusb_config.h
+++ b/examples/device/dfu/src/tusb_config.h
@@ -12,42 +12,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
-// defined by compiler flags for flexibility
+// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -61,7 +65,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
@@ -73,10 +77,10 @@
#endif
//------------- CLASS -------------//
-#define CFG_TUD_DFU 1
+#define CFG_TUD_DFU 1
// DFU buffer size, it has to be set to the buffer size used in TUD_DFU_DESCRIPTOR
-#define CFG_TUD_DFU_XFER_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
+#define CFG_TUD_DFU_XFER_BUFSIZE 512
#ifdef __cplusplus
}
diff --git a/examples/device/dfu/src/usb_descriptors.c b/examples/device/dfu/src/usb_descriptors.c
index fd469aaf2..350334aa5 100644
--- a/examples/device/dfu/src/usb_descriptors.c
+++ b/examples/device/dfu/src/usb_descriptors.c
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
#include "class/dfu/dfu_device.h"
@@ -117,65 +116,56 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
"FLASH", // 4: DFU Partition 1
"EEPROM", // 5: DFU Partition 2
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
+
size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }
+ else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ const char* str = string_desc_arr[index];
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) {
+ chr_count = 31;
+ }
- const char *str = string_desc_arr[index];
-
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
add_executable(${PROJECT})
@@ -27,6 +23,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/dfu_runtime/Makefile b/examples/device/dfu_runtime/Makefile
index da088ea6b..69b633fea 100644
--- a/examples/device/dfu_runtime/Makefile
+++ b/examples/device/dfu_runtime/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/dfu_runtime/src/main.c b/examples/device/dfu_runtime/src/main.c
index 170dde932..823c71ae5 100644
--- a/examples/device/dfu_runtime/src/main.c
+++ b/examples/device/dfu_runtime/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -31,7 +31,7 @@
*
* $ dfu-util -e
*
- * This will send DETACH command to put device into bootloader. Since this example
+ * This will send DETTACH command to put device into bootloader. Since this example
* is minimal, it doesn't actually go into DFU mode but rather change the LED blinking
* pattern to fast rate as indicator.
*/
@@ -40,7 +40,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//--------------------------------------------------------------------+
@@ -69,18 +69,15 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
tud_task(); // tinyusb device task
led_blinking_task();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -111,7 +108,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
// Invoked on DFU_DETACH request to reboot to the bootloader
diff --git a/examples/device/dfu_runtime/src/tusb_config.h b/examples/device/dfu_runtime/src/tusb_config.h
index fa1ae6ed3..bdae1d2e9 100644
--- a/examples/device/dfu_runtime/src/tusb_config.h
+++ b/examples/device/dfu_runtime/src/tusb_config.h
@@ -12,42 +12,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
-// defined by compiler flags for flexibility
+// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
diff --git a/examples/device/dfu_runtime/src/usb_descriptors.c b/examples/device/dfu_runtime/src/usb_descriptors.c
index 7ac53d255..060943289 100644
--- a/examples/device/dfu_runtime/src/usb_descriptors.c
+++ b/examples/device/dfu_runtime/src/usb_descriptors.c
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
#include "class/dfu/dfu_rt_device.h"
@@ -113,64 +112,55 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
"TinyUSB DFU runtime", // 4: DFU runtime
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
+
size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }
+ else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ const char* str = string_desc_arr[index];
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) {
+ chr_count = 31;
+ }
- const char *str = string_desc_arr[index];
-
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
add_executable(${PROJECT})
@@ -28,6 +24,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/dynamic_configuration/Makefile b/examples/device/dynamic_configuration/Makefile
index da088ea6b..69b633fea 100644
--- a/examples/device/dynamic_configuration/Makefile
+++ b/examples/device/dynamic_configuration/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/dynamic_configuration/skip.txt b/examples/device/dynamic_configuration/skip.txt
deleted file mode 100644
index eadb6e74a..000000000
--- a/examples/device/dynamic_configuration/skip.txt
+++ /dev/null
@@ -1 +0,0 @@
-mcu:SAMD11
diff --git a/examples/device/dynamic_configuration/src/main.c b/examples/device/dynamic_configuration/src/main.c
index b6409c8e1..4c10f55b0 100644
--- a/examples/device/dynamic_configuration/src/main.c
+++ b/examples/device/dynamic_configuration/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,7 +27,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//--------------------------------------------------------------------+
@@ -55,13 +55,7 @@ void midi_task(void);
int main(void)
{
board_init();
-
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
@@ -70,6 +64,8 @@ int main(void)
cdc_task();
midi_task();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -100,7 +96,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
@@ -183,7 +179,7 @@ void midi_task(void)
start_ms += 286;
// Previous positions in the note sequence.
- int previous = (int) (note_pos - 1);
+ int previous = note_pos - 1;
// If we currently are at position 0, set the
// previous position to the last note in the sequence.
diff --git a/examples/device/dynamic_configuration/src/msc_disk.c b/examples/device/dynamic_configuration/src/msc_disk.c
index 10c3ac6fe..b9205f0c2 100644
--- a/examples/device/dynamic_configuration/src/msc_disk.c
+++ b/examples/device/dynamic_configuration/src/msc_disk.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,7 @@
*
*/
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#if CFG_TUD_MSC
@@ -184,7 +184,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
uint8_t const* addr = msc_disk[lba] + offset;
memcpy(buffer, addr, bufsize);
- return (int32_t) bufsize;
+ return bufsize;
}
// Callback invoked when received WRITE10 command.
@@ -203,7 +203,7 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
(void) lba; (void) offset; (void) buffer;
#endif
- return (int32_t) bufsize;
+ return bufsize;
}
// Callback invoked when received an SCSI command not in built-in list below
@@ -221,6 +221,11 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
switch (scsi_cmd[0])
{
+ case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
+ // Host is about to read/write etc ... better not to disconnect disk
+ resplen = 0;
+ break;
+
default:
// Set Sense = Invalid Command Operation
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
@@ -237,7 +242,7 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
{
if(in_xfer)
{
- memcpy(buffer, response, (size_t) resplen);
+ memcpy(buffer, response, resplen);
}else
{
// SCSI output
diff --git a/examples/device/dynamic_configuration/src/tusb_config.h b/examples/device/dynamic_configuration/src/tusb_config.h
index b9b3878cc..23073faf3 100644
--- a/examples/device/dynamic_configuration/src/tusb_config.h
+++ b/examples/device/dynamic_configuration/src/tusb_config.h
@@ -30,42 +30,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
-// defined by compiler flags for flexibility
+// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -79,7 +83,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/device/dynamic_configuration/src/usb_descriptors.c b/examples/device/dynamic_configuration/src/usb_descriptors.c
index 7f35b4b22..3352972a5 100644
--- a/examples/device/dynamic_configuration/src/usb_descriptors.c
+++ b/examples/device/dynamic_configuration/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,8 +23,8 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
+#include "bsp/board.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.
@@ -145,19 +145,6 @@ enum
#define EPNUM_1_MSC_OUT 0x01
#define EPNUM_1_MSC_IN 0x82
-#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
- // FT9XX doesn't support a same endpoint number with different direction IN and OUT
- // e.g EP1 OUT & EP1 IN cannot exist together
- #define EPNUM_0_CDC_NOTIF 0x81
- #define EPNUM_0_CDC_OUT 0x02
- #define EPNUM_0_CDC_IN 0x83
-
- #define EPNUM_0_MIDI_OUT 0x04
- #define EPNUM_0_MIDI_IN 0x85
-
- #define EPNUM_1_MSC_OUT 0x01
- #define EPNUM_1_MSC_IN 0x82
-
#else
#define EPNUM_0_CDC_NOTIF 0x81
#define EPNUM_0_CDC_OUT 0x02
@@ -176,14 +163,14 @@ uint8_t const desc_configuration_0[] =
TUD_CONFIG_DESCRIPTOR(1, ITF_0_NUM_TOTAL, 0, CONFIG_0_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
- TUD_CDC_DESCRIPTOR(ITF_0_NUM_CDC, 0, EPNUM_0_CDC_NOTIF, 8, EPNUM_0_CDC_OUT, EPNUM_0_CDC_IN, TUD_OPT_HIGH_SPEED ? 512 : 64),
+ TUD_CDC_DESCRIPTOR(ITF_0_NUM_CDC, 0, EPNUM_0_CDC_NOTIF, 8, EPNUM_0_CDC_OUT, EPNUM_0_CDC_IN, 64),
// Interface number, string index, EP Out & EP In address, EP size
TUD_MIDI_DESCRIPTOR(ITF_0_NUM_MIDI, 0, EPNUM_0_MIDI_OUT, EPNUM_0_MIDI_IN, TUD_OPT_HIGH_SPEED ? 512 : 64),
};
-uint8_t const desc_configuration_1[] =
+uint8_t const desc_configuraiton_1[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_1_NUM_TOTAL, 0, CONFIG_1_TOTAL_LEN, 0x00, 100),
@@ -199,70 +186,58 @@ uint8_t const desc_configuration_1[] =
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
{
(void) index; // for multiple configurations
- return mode ? desc_configuration_1 : desc_configuration_0;
+ return mode ? desc_configuraiton_1 : desc_configuration_0;
}
//--------------------------------------------------------------------+
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
add_executable(${PROJECT})
@@ -27,6 +23,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/hid_boot_interface/Makefile b/examples/device/hid_boot_interface/Makefile
index b3f2cc588..c6a9c5b21 100644
--- a/examples/device/hid_boot_interface/Makefile
+++ b/examples/device/hid_boot_interface/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
@@ -8,7 +9,7 @@ INC += \
EXAMPLE_SOURCE = \
src/main.c \
src/usb_descriptors.c
-
+
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
include ../../rules.mk
diff --git a/examples/device/hid_boot_interface/src/main.c b/examples/device/hid_boot_interface/src/main.c
index 7ad5c53c2..e5e2f6856 100644
--- a/examples/device/hid_boot_interface/src/main.c
+++ b/examples/device/hid_boot_interface/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,7 +27,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -55,13 +55,7 @@ void hid_task(void);
int main(void)
{
board_init();
-
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
@@ -102,7 +96,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
@@ -161,11 +155,11 @@ void hid_task(void)
{
uint8_t const report_id = 0;
uint8_t const button_mask = 0;
- uint8_t const vertical = 0;
+ uint8_t const veritical = 0;
uint8_t const horizontal = 0;
int8_t const delta = 5;
- tud_hid_n_mouse_report(ITF_NUM_MOUSE, report_id, button_mask, delta, delta, vertical, horizontal);
+ tud_hid_n_mouse_report(ITF_NUM_MOUSE, report_id, button_mask, delta, delta, veritical, horizontal);
}
}
}
@@ -179,13 +173,13 @@ void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol)
(void) protocol;
// nothing to do since we use the same compatible boot report for both Boot and Report mode.
- // TODO set a indicator for user
+ // TOOD set a indicator for user
}
// Invoked when sent REPORT successfully to host
// Application can use this to send the next report
// Note: For composite reports, report[0] is report ID
-void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint16_t len)
+void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint8_t len)
{
(void) instance;
(void) report;
diff --git a/examples/device/hid_boot_interface/src/tusb_config.h b/examples/device/hid_boot_interface/src/tusb_config.h
index 52723e09f..59fb9962c 100644
--- a/examples/device/hid_boot_interface/src/tusb_config.h
+++ b/examples/device/hid_boot_interface/src/tusb_config.h
@@ -30,42 +30,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
-// defined by compiler flags for flexibility
+// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56 || CFG_TUSB_MCU == OPT_MCU_SAMX7X)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -79,7 +83,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/device/hid_boot_interface/src/usb_descriptors.c b/examples/device/hid_boot_interface/src/usb_descriptors.c
index d68ef16d9..3fa48d98d 100644
--- a/examples/device/hid_boot_interface/src/usb_descriptors.c
+++ b/examples/device/hid_boot_interface/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -131,63 +130,51 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
add_executable(${PROJECT})
@@ -27,6 +23,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/hid_composite/Makefile b/examples/device/hid_composite/Makefile
index da088ea6b..69b633fea 100644
--- a/examples/device/hid_composite/Makefile
+++ b/examples/device/hid_composite/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c
index dcf13079f..fd25e620a 100644
--- a/examples/device/hid_composite/src/main.c
+++ b/examples/device/hid_composite/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,7 +27,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -56,13 +56,7 @@ void hid_task(void);
int main(void)
{
board_init();
-
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
@@ -71,6 +65,8 @@ int main(void)
hid_task();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -101,7 +97,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
@@ -227,12 +223,12 @@ void hid_task(void)
// Invoked when sent REPORT successfully to host
// Application can use this to send the next report
// Note: For composite reports, report[0] is report ID
-void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint16_t len)
+void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint8_t len)
{
(void) instance;
(void) len;
- uint8_t next_report_id = report[0] + 1u;
+ uint8_t next_report_id = report[0] + 1;
if (next_report_id < REPORT_ID_COUNT)
{
diff --git a/examples/device/hid_composite/src/tusb_config.h b/examples/device/hid_composite/src/tusb_config.h
index 6bd32c427..868424e6d 100644
--- a/examples/device/hid_composite/src/tusb_config.h
+++ b/examples/device/hid_composite/src/tusb_config.h
@@ -30,42 +30,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
-// defined by compiler flags for flexibility
+// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56 || CFG_TUSB_MCU == OPT_MCU_SAMX7X)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
diff --git a/examples/device/hid_composite/src/usb_descriptors.c b/examples/device/hid_composite/src/usb_descriptors.c
index e174db46d..e760b20ba 100644
--- a/examples/device/hid_composite/src/usb_descriptors.c
+++ b/examples/device/hid_composite/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -178,63 +177,51 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
-family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
-project(${PROJECT} C CXX ASM)
-
-# Checks this example is valid for the family and initializes the project
-family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
+# Check for -DFAMILY=
+if(FAMILY MATCHES "^esp32s[2-3]")
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+ project(${PROJECT})
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}")
endif()
-
-add_executable(${PROJECT})
-
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/freertos_hook.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- )
-
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
-
-# Configure compilation flags and libraries for the example with FreeRTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} freertos)
diff --git a/examples/device/hid_composite_freertos/Makefile b/examples/device/hid_composite_freertos/Makefile
index a892e7d1d..256db3d8c 100644
--- a/examples/device/hid_composite_freertos/Makefile
+++ b/examples/device/hid_composite_freertos/Makefile
@@ -1,23 +1,23 @@
DEPS_SUBMODULES += lib/FreeRTOS-Kernel
+include ../../../tools/top.mk
include ../../make.mk
FREERTOS_SRC = lib/FreeRTOS-Kernel
-FREERTOS_PORTABLE_PATH= $(FREERTOS_SRC)/portable/$(if $(USE_IAR),IAR,GCC)
INC += \
src \
src/FreeRTOSConfig \
$(TOP)/hw \
$(TOP)/$(FREERTOS_SRC)/include \
- $(TOP)/$(FREERTOS_PORTABLE_SRC)
+ $(TOP)/$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT)
# Example source
EXAMPLE_SOURCE = \
src/freertos_hook.c \
src/main.c \
src/usb_descriptors.c
-
+
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
# FreeRTOS source, all files in port folder
@@ -26,22 +26,9 @@ SRC_C += \
$(FREERTOS_SRC)/queue.c \
$(FREERTOS_SRC)/tasks.c \
$(FREERTOS_SRC)/timers.c \
- $(subst $(TOP)/,,$(wildcard $(TOP)/$(FREERTOS_PORTABLE_SRC)/*.c))
-
-SRC_S += \
- $(subst $(TOP)/,,$(wildcard $(TOP)/$(FREERTOS_PORTABLE_SRC)/*.s))
-
-# include heap manage if configSUPPORT_DYNAMIC_ALLOCATION = 1
-# SRC_C += $(FREERTOS_SRC)/portable/MemMang/heap_1.c
-# CFLAGS += -Wno-error=sign-compare
-
-# Suppress FreeRTOSConfig.h warnings
-CFLAGS_GCC += -Wno-error=redundant-decls
-
-# Suppress FreeRTOS source warnings
-CFLAGS_GCC += -Wno-error=cast-qual
+ $(subst ../../../,,$(wildcard ../../../$(FREERTOS_SRC)/portable/GCC/$(FREERTOS_PORT)/*.c))
# FreeRTOS (lto + Os) linker issue
-LDFLAGS_GCC += -Wl,--undefined=vTaskSwitchContext
+LDFLAGS += -Wl,--undefined=vTaskSwitchContext
include ../../rules.mk
diff --git a/examples/device/hid_composite_freertos/skip.txt b/examples/device/hid_composite_freertos/skip.txt
deleted file mode 100644
index a6f96b288..000000000
--- a/examples/device/hid_composite_freertos/skip.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-mcu:CH32V307
-mcu:CXD56
-mcu:F1C100S
-mcu:GD32VF103
-mcu:MKL25ZXX
-mcu:MSP430x5xx
-mcu:RP2040
-mcu:SAMD11
-mcu:SAMX7X
-mcu:VALENTYUSB_EPTRI
-mcu:RAXXX
-family:broadcom_32bit
-family:broadcom_64bit
diff --git a/examples/device/hid_composite_freertos/src/CMakeLists.txt b/examples/device/hid_composite_freertos/src/CMakeLists.txt
index 6d912854f..6f156379f 100644
--- a/examples/device/hid_composite_freertos/src/CMakeLists.txt
+++ b/examples/device/hid_composite_freertos/src/CMakeLists.txt
@@ -1,3 +1,31 @@
idf_component_register(SRCS "main.c" "usb_descriptors.c"
INCLUDE_DIRS "."
- REQUIRES boards tinyusb_src)
+ REQUIRES freertos soc)
+
+file(TO_NATIVE_PATH "${TOP}/hw/bsp/${FAMILY}/boards/${BOARD}/board.cmake" board_cmake)
+
+if(EXISTS ${board_cmake})
+ include(${board_cmake})
+endif()
+
+target_include_directories(${COMPONENT_TARGET} PUBLIC
+ "${TOP}/hw"
+ "${TOP}/src"
+)
+
+target_sources(${COMPONENT_TARGET} PUBLIC
+ "${TOP}/src/tusb.c"
+ "${TOP}/src/common/tusb_fifo.c"
+ "${TOP}/src/device/usbd.c"
+ "${TOP}/src/device/usbd_control.c"
+ "${TOP}/src/class/cdc/cdc_device.c"
+ "${TOP}/src/class/dfu/dfu_rt_device.c"
+ "${TOP}/src/class/hid/hid_device.c"
+ "${TOP}/src/class/midi/midi_device.c"
+ "${TOP}/src/class/msc/msc_device.c"
+ "${TOP}/src/class/net/ecm_rndis_device.c"
+ "${TOP}/src/class/net/ncm_device.c"
+ "${TOP}/src/class/usbtmc/usbtmc_device.c"
+ "${TOP}/src/class/vendor/vendor_device.c"
+ "${TOP}/src/portable/espressif/esp32sx/dcd_esp32sx.c"
+)
diff --git a/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h b/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h
index 69d638288..bfdf1e926 100644
--- a/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h
+++ b/examples/device/hid_composite_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h
@@ -42,26 +42,20 @@
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
-// skip if included from IAR assembler
-#ifndef __IASMARM__
-
// Include MCU header
#include "bsp/board_mcu.h"
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
- #error "ESP32-Sx should use IDF's FreeRTOSConfig.h"
+#error "ESP32-Sx should use IDF's FreeRTOSConfig.h"
#endif
-// TODO fix later
#if CFG_TUSB_MCU == OPT_MCU_MM32F327X
+ // TODO fix/remove later
extern u32 SystemCoreClock;
#else
- // FIXME cause redundant-decls warnings
extern uint32_t SystemCoreClock;
#endif
-#endif
-
/* Cortex M23/M33 port configuration. */
#define configENABLE_MPU 0
#define configENABLE_FPU 1
@@ -74,14 +68,14 @@
#define configTICK_RATE_HZ ( 1000 )
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( 128 )
-#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION*4*1024 )
+#define configTOTAL_HEAP_SIZE ( 0*1024 ) // dynamic is not used
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
-#define configQUEUE_REGISTRY_SIZE 4
+#define configQUEUE_REGISTRY_SIZE 2
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
@@ -149,10 +143,10 @@
#ifdef __RX__
/* Renesas RX series */
-#define vSoftwareInterruptISR INT_Excep_ICU_SWINT
-#define vTickISR INT_Excep_CMT0_CMI0
-#define configPERIPHERAL_CLOCK_HZ (configCPU_CLOCK_HZ/2)
-#define configKERNEL_INTERRUPT_PRIORITY 1
+#define vSoftwareInterruptISR INT_Excep_ICU_SWINT
+#define vTickISR INT_Excep_CMT0_CMI0
+#define configPERIPHERAL_CLOCK_HZ (configCPU_CLOCK_HZ/2)
+#define configKERNEL_INTERRUPT_PRIORITY 1
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 4
#else
@@ -168,18 +162,9 @@
#if defined(__NVIC_PRIO_BITS)
// For Cortex-M specific: __NVIC_PRIO_BITS is defined in core_cmx.h
#define configPRIO_BITS __NVIC_PRIO_BITS
-
#elif defined(__ECLIC_INTCTLBITS)
// RISC-V Bumblebee core from nuclei
#define configPRIO_BITS __ECLIC_INTCTLBITS
-
-#elif defined(__IASMARM__)
- // FIXME: IAR Assembler cannot include mcu header directly to get __NVIC_PRIO_BITS.
- // Therefore we will hard coded it to minimum value of 2 to get pass ci build.
- // IAR user must update this to correct value of the target MCU
- #message "configPRIO_BITS is hard coded to 2 to pass IAR build only. User should update it per MCU"
- #define configPRIO_BITS 2
-
#else
#error "FreeRTOS configPRIO_BITS to be defined"
#endif
diff --git a/examples/device/hid_composite_freertos/src/main.c b/examples/device/hid_composite_freertos/src/main.c
index ff2cb635e..b25c71f64 100644
--- a/examples/device/hid_composite_freertos/src/main.c
+++ b/examples/device/hid_composite_freertos/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,11 +27,11 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#include "usb_descriptors.h"
-#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+#if TU_CHECK_MCU(ESP32S2) || TU_CHECK_MCU(ESP32S3)
// ESP-IDF need "freertos/" prefix in include path.
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
#include "freertos/FreeRTOS.h"
@@ -39,22 +39,14 @@
#include "freertos/queue.h"
#include "freertos/task.h"
#include "freertos/timers.h"
-
- #define USBD_STACK_SIZE 4096
-
#else
#include "FreeRTOS.h"
#include "semphr.h"
#include "queue.h"
#include "task.h"
#include "timers.h"
-
- // Increase stack size when debug log is enabled
- #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
#endif
-#define HID_STACK_SZIE configMINIMAL_STACK_SIZE
-
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+
@@ -70,18 +62,25 @@ enum {
BLINK_SUSPENDED = 2500,
};
-// static timer & task
-#if configSUPPORT_STATIC_ALLOCATION
+// static timer
StaticTimer_t blinky_tmdef;
+TimerHandle_t blinky_tm;
+
+// static task for usbd
+#if CFG_TUSB_DEBUG
+ #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE)
+#else
+ #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2)
+#endif
StackType_t usb_device_stack[USBD_STACK_SIZE];
StaticTask_t usb_device_taskdef;
+// static task for hid
+#define HID_STACK_SZIE configMINIMAL_STACK_SIZE
StackType_t hid_stack[HID_STACK_SZIE];
StaticTask_t hid_taskdef;
-#endif
-TimerHandle_t blinky_tm;
void led_blinky_cb(TimerHandle_t xTimer);
void usb_device_task(void* param);
@@ -95,32 +94,25 @@ int main(void)
{
board_init();
-#if configSUPPORT_STATIC_ALLOCATION
// soft timer for blinky
blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb, &blinky_tmdef);
-
- // Create a task for tinyusb device stack
- xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
-
- // Create HID task
- xTaskCreateStatic(hid_task, "hid", HID_STACK_SZIE, NULL, configMAX_PRIORITIES-2, hid_stack, &hid_taskdef);
-#else
- blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb);
- xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL);
- xTaskCreate(hid_task, "hid", HID_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL);
-#endif
-
xTimerStart(blinky_tm, 0);
+ // Create a task for tinyusb device stack
+ (void) xTaskCreateStatic( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
+
+ // Create HID task
+ (void) xTaskCreateStatic( hid_task, "hid", HID_STACK_SZIE, NULL, configMAX_PRIORITIES-2, hid_stack, &hid_taskdef);
+
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
-#if !TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+#if !( TU_CHECK_MCU(ESP32S2) || TU_CHECK_MCU(ESP32S3) )
vTaskStartScheduler();
#endif
return 0;
}
-#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
void app_main(void)
{
main();
@@ -133,22 +125,15 @@ void usb_device_task(void* param)
{
(void) param;
- // init device stack on configured roothub port
// This should be called after scheduler/kernel is started.
// Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API.
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
// RTOS forever loop
while (1)
{
- // put this thread to waiting state until there is new events
+ // tinyusb device task
tud_task();
-
- // following code only run if tud_task() process at least 1 event
}
}
@@ -180,14 +165,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- if (tud_mounted())
- {
- xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
- }
- else
- {
- xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
- }
+ xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
}
//--------------------------------------------------------------------+
@@ -313,7 +291,7 @@ void hid_task(void* param)
// Invoked when sent REPORT successfully to host
// Application can use this to send the next report
// Note: For composite reports, report[0] is report ID
-void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint16_t len)
+void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint8_t len)
{
(void) instance;
(void) len;
diff --git a/examples/device/hid_composite_freertos/src/tusb_config.h b/examples/device/hid_composite_freertos/src/tusb_config.h
index 3ba9bf311..b061dce3f 100644
--- a/examples/device/hid_composite_freertos/src/tusb_config.h
+++ b/examples/device/hid_composite_freertos/src/tusb_config.h
@@ -30,50 +30,53 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
// This examples use FreeRTOS
-#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_FREERTOS
-#endif
+#define CFG_TUSB_OS OPT_OS_FREERTOS
// Espressif IDF requires "freertos/" prefix in include path
-#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
-#define CFG_TUSB_OS_INC_PATH freertos/
+#if TU_CHECK_MCU(ESP32S2) || TU_CHECK_MCU(ESP32S3)
+ #define CFG_TUSB_OS_INC_PATH freertos/
#endif
-// can be defined by compiler in DEBUG build
+
#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
+#define CFG_TUSB_DEBUG 0
#endif
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
-
/* 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.
diff --git a/examples/device/hid_composite_freertos/src/usb_descriptors.c b/examples/device/hid_composite_freertos/src/usb_descriptors.c
index 85820de55..791813fdf 100644
--- a/examples/device/hid_composite_freertos/src/usb_descriptors.c
+++ b/examples/device/hid_composite_freertos/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -176,63 +175,51 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
add_executable(${PROJECT})
@@ -27,6 +23,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/hid_generic_inout/Makefile b/examples/device/hid_generic_inout/Makefile
index da088ea6b..69b633fea 100644
--- a/examples/device/hid_generic_inout/Makefile
+++ b/examples/device/hid_generic_inout/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/hid_generic_inout/hid_test.js b/examples/device/hid_generic_inout/hid_test.js
index 16bc723e2..daa958fd5 100644
--- a/examples/device/hid_generic_inout/hid_test.js
+++ b/examples/device/hid_generic_inout/hid_test.js
@@ -48,7 +48,7 @@ if( deviceInfo ) {
function anySupportedBoard(d) {
-
+
for (var key in boards) {
if (boards.hasOwnProperty(key)) {
if (isDevice(boards[key],d)) {
@@ -65,3 +65,4 @@ function isDevice(board,d){
// product id 0xff is matches all
return d.vendorId==board[0] && (d.productId==board[1] || board[1] == 0xFFFF);
}
+
diff --git a/examples/device/hid_generic_inout/hid_test.py b/examples/device/hid_generic_inout/hid_test.py
index 5bdba9db0..a42930fb5 100644
--- a/examples/device/hid_generic_inout/hid_test.py
+++ b/examples/device/hid_generic_inout/hid_test.py
@@ -1,22 +1,20 @@
# Install python3 HID package https://pypi.org/project/hid/
import hid
-# default is TinyUSB (0xcafe), Adafruit (0x239a), RaspberryPi (0x2e8a), Espressif (0x303a) VID
-USB_VID = (0xcafe, 0x239a, 0x2e8a, 0x303a)
+USB_VID = 0xcafe
-print("VID list: " + ", ".join('%02x' % v for v in USB_VID))
+print("Openning HID device with VID = 0x%X" % USB_VID)
-for vid in USB_VID:
- for dict in hid.enumerate(vid):
- print(dict)
- dev = hid.Device(dict['vendor_id'], dict['product_id'])
- if dev:
- while True:
- # Get input from console and encode to UTF8 for array of chars.
- # hid generic in/out is single report therefore by HIDAPI requirement
- # it must be preceded, with 0x00 as dummy reportID
- str_out = b'\x00'
- str_out += input("Send text to HID Device : ").encode('utf-8')
- dev.write(str_out)
- str_in = dev.read(64)
- print("Received from HID Device:", str_in, '\n')
+for dict in hid.enumerate(USB_VID):
+ print(dict)
+ dev = hid.Device(dict['vendor_id'], dict['product_id'])
+ if dev:
+ while True:
+ # Get input from console and encode to UTF8 for array of chars.
+ # hid generic inout is single report therefore by HIDAPI requirement
+ # it must be preceeded with 0x00 as dummy reportID
+ str_out = b'\x00'
+ str_out += input("Send text to HID Device : ").encode('utf-8')
+ dev.write(str_out)
+ str_in = dev.read(64)
+ print("Received from HID Device:", str_in, '\n')
diff --git a/examples/device/hid_generic_inout/src/main.c b/examples/device/hid_generic_inout/src/main.c
index cfa9f6283..32185560e 100644
--- a/examples/device/hid_generic_inout/src/main.c
+++ b/examples/device/hid_generic_inout/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,7 +27,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
/* This example demonstrate HID Generic raw Input & Output.
@@ -80,18 +80,15 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
tud_task(); // tinyusb device task
led_blinking_task();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -122,7 +119,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
diff --git a/examples/device/hid_generic_inout/src/tusb_config.h b/examples/device/hid_generic_inout/src/tusb_config.h
index 98143ac4d..1b8b91c41 100644
--- a/examples/device/hid_generic_inout/src/tusb_config.h
+++ b/examples/device/hid_generic_inout/src/tusb_config.h
@@ -30,42 +30,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
-// defined by compiler flags for flexibility
+// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -79,7 +83,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/device/hid_generic_inout/src/usb_descriptors.c b/examples/device/hid_generic_inout/src/usb_descriptors.c
index 64f6d17ae..5dabf42a3 100644
--- a/examples/device/hid_generic_inout/src/usb_descriptors.c
+++ b/examples/device/hid_generic_inout/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
@@ -104,7 +103,7 @@ uint8_t const desc_configuration[] =
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
- // Interface number, string index, protocol, report descriptor len, EP Out & In address, size & polling interval
+ // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
TUD_HID_INOUT_DESCRIPTOR(ITF_NUM_HID, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, 0x80 | EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10)
};
@@ -121,63 +120,51 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
add_executable(${PROJECT})
@@ -27,6 +23,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/hid_multiple_interface/Makefile b/examples/device/hid_multiple_interface/Makefile
index da088ea6b..69b633fea 100644
--- a/examples/device/hid_multiple_interface/Makefile
+++ b/examples/device/hid_multiple_interface/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/hid_multiple_interface/src/main.c b/examples/device/hid_multiple_interface/src/main.c
index 30b4ae055..7cb1d75a7 100644
--- a/examples/device/hid_multiple_interface/src/main.c
+++ b/examples/device/hid_multiple_interface/src/main.c
@@ -27,7 +27,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//--------------------------------------------------------------------+
@@ -60,13 +60,7 @@ void hid_task(void);
int main(void)
{
board_init();
-
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
@@ -75,6 +69,8 @@ int main(void)
hid_task();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -105,7 +101,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
diff --git a/examples/device/hid_multiple_interface/src/tusb_config.h b/examples/device/hid_multiple_interface/src/tusb_config.h
index 49dc962fe..a0aa17a90 100644
--- a/examples/device/hid_multiple_interface/src/tusb_config.h
+++ b/examples/device/hid_multiple_interface/src/tusb_config.h
@@ -30,42 +30,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
-// defined by compiler flags for flexibility
+// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
diff --git a/examples/device/hid_multiple_interface/src/usb_descriptors.c b/examples/device/hid_multiple_interface/src/usb_descriptors.c
index 86f567e8e..9eef21504 100644
--- a/examples/device/hid_multiple_interface/src/usb_descriptors.c
+++ b/examples/device/hid_multiple_interface/src/usb_descriptors.c
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
@@ -137,65 +136,53 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
"Keyboard Interface", // 4: Interface 1 String
"Mouse Interface", // 5: Interface 2 String
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
add_executable(${PROJECT})
+
# Example source
target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
@@ -26,6 +23,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/midi_test/Makefile b/examples/device/midi_test/Makefile
index 2a3d854fb..5a455078e 100644
--- a/examples/device/midi_test/Makefile
+++ b/examples/device/midi_test/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/midi_test/src/main.c b/examples/device/midi_test/src/main.c
index b1d51598f..193748477 100644
--- a/examples/device/midi_test/src/main.c
+++ b/examples/device/midi_test/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,7 +27,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
/* This MIDI example send sequence of note (on/off) repeatedly. To test on PC, you need to install
@@ -62,12 +62,7 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
@@ -75,6 +70,9 @@ int main(void)
led_blinking_task();
midi_task();
}
+
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -105,7 +103,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
@@ -141,7 +139,7 @@ void midi_task(void)
start_ms += 286;
// Previous positions in the note sequence.
- int previous = (int) (note_pos - 1);
+ int previous = note_pos - 1;
// If we currently are at position 0, set the
// previous position to the last note in the sequence.
diff --git a/examples/device/midi_test/src/tusb_config.h b/examples/device/midi_test/src/tusb_config.h
index 314dde438..61b9b6552 100644
--- a/examples/device/midi_test/src/tusb_config.h
+++ b/examples/device/midi_test/src/tusb_config.h
@@ -30,42 +30,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
-// defined by compiler flags for flexibility
+// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -79,7 +83,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/device/midi_test/src/usb_descriptors.c b/examples/device/midi_test/src/usb_descriptors.c
index 9781d3d6f..bd5a0eeab 100644
--- a/examples/device/midi_test/src/usb_descriptors.c
+++ b/examples/device/midi_test/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,14 +23,13 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.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.
*
* Auto ProductID layout's Bitmap:
- * [MSB] HID | MSC | CDC [LSB]
+ * [MSB] MIDI | HID | MSC | CDC [LSB]
*/
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
@@ -84,15 +83,9 @@ enum
#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
// 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
- #define EPNUM_MIDI_OUT 0x02
- #define EPNUM_MIDI_IN 0x02
-#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
- // On Bridgetek FT9xx endpoint numbers must be unique...
- #define EPNUM_MIDI_OUT 0x02
- #define EPNUM_MIDI_IN 0x03
+ #define EPNUM_MIDI 0x02
#else
- #define EPNUM_MIDI_OUT 0x01
- #define EPNUM_MIDI_IN 0x01
+ #define EPNUM_MIDI 0x01
#endif
uint8_t const desc_fs_configuration[] =
@@ -101,7 +94,7 @@ uint8_t const desc_fs_configuration[] =
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP Out & EP In address, EP size
- TUD_MIDI_DESCRIPTOR(ITF_NUM_MIDI, 0, EPNUM_MIDI_OUT, (0x80 | EPNUM_MIDI_IN), 64)
+ TUD_MIDI_DESCRIPTOR(ITF_NUM_MIDI, 0, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 64)
};
#if TUD_OPT_HIGH_SPEED
@@ -111,7 +104,7 @@ uint8_t const desc_hs_configuration[] =
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP Out & EP In address, EP size
- TUD_MIDI_DESCRIPTOR(ITF_NUM_MIDI, 0, EPNUM_MIDI_OUT, (0x80 | EPNUM_MIDI_IN), 512)
+ TUD_MIDI_DESCRIPTOR(ITF_NUM_MIDI, 0, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 512)
};
#endif
@@ -134,63 +127,51 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
# Example source
target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- )
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
# Example include
target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/msc_dual_lun/Makefile b/examples/device/msc_dual_lun/Makefile
index 2a3d854fb..5a455078e 100644
--- a/examples/device/msc_dual_lun/Makefile
+++ b/examples/device/msc_dual_lun/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/msc_dual_lun/skip.txt b/examples/device/msc_dual_lun/skip.txt
deleted file mode 100644
index 47e561cf0..000000000
--- a/examples/device/msc_dual_lun/skip.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-mcu:SAMD11
-mcu:MKL25ZXX
diff --git a/examples/device/msc_dual_lun/src/main.c b/examples/device/msc_dual_lun/src/main.c
index de402d3da..0293261ad 100644
--- a/examples/device/msc_dual_lun/src/main.c
+++ b/examples/device/msc_dual_lun/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,7 +27,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//--------------------------------------------------------------------+
@@ -54,18 +54,15 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
tud_task(); // tinyusb device task
led_blinking_task();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -96,7 +93,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
diff --git a/examples/device/msc_dual_lun/src/msc_disk_dual.c b/examples/device/msc_dual_lun/src/msc_disk_dual.c
index 4f0f6410f..18d3ca0d7 100644
--- a/examples/device/msc_dual_lun/src/msc_disk_dual.c
+++ b/examples/device/msc_dual_lun/src/msc_disk_dual.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,14 +23,11 @@
*
*/
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#if CFG_TUD_MSC
-// When button is pressed, LUN1 will be set to not ready to simulate
-// medium not present (e.g SD card removed)
-
// Some MCU doesn't have enough 8KB SRAM to store the whole disk
// We will use Flash as read-only disk with board that has
// CFG_EXAMPLE_MSC_READONLY defined
@@ -230,7 +227,7 @@ void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16
// return true allowing host to read/write this LUN e.g SD card inserted
bool tud_msc_test_unit_ready_cb(uint8_t lun)
{
- if ( lun == 1 && board_button_read() ) return false;
+ (void) lun;
return true; // RAM disk is always ready
}
@@ -277,7 +274,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
uint8_t const* addr = (lun ? msc_disk1[lba] : msc_disk0[lba]) + offset;
memcpy(buffer, addr, bufsize);
- return (int32_t) bufsize;
+ return bufsize;
}
bool tud_msc_is_writable_cb (uint8_t lun)
@@ -305,7 +302,7 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
(void) lun; (void) lba; (void) offset; (void) buffer;
#endif
- return (int32_t) bufsize;
+ return bufsize;
}
// Callback invoked when received an SCSI command not in built-in list below
@@ -323,6 +320,23 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
switch (scsi_cmd[0])
{
+ case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
+ // Host is about to read/write etc ... better not to disconnect disk
+ resplen = 0;
+ break;
+
+ case SCSI_CMD_START_STOP_UNIT:
+ // Host try to eject/safe remove/poweroff us. We could safely disconnect with disk storage, or go into lower power
+ /* scsi_start_stop_unit_t const * start_stop = (scsi_start_stop_unit_t const *) scsi_cmd;
+ // Start bit = 0 : low power mode, if load_eject = 1 : unmount disk storage as well
+ // Start bit = 1 : Ready mode, if load_eject = 1 : mount disk storage
+ start_stop->start;
+ start_stop->load_eject;
+ */
+ resplen = 0;
+ break;
+
+
default:
// Set Sense = Invalid Command Operation
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
@@ -339,7 +353,7 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
{
if(in_xfer)
{
- memcpy(buffer, response, (size_t) resplen);
+ memcpy(buffer, response, resplen);
}else
{
// SCSI output
diff --git a/examples/device/msc_dual_lun/src/tusb_config.h b/examples/device/msc_dual_lun/src/tusb_config.h
index 9cbbbade9..44da21e54 100644
--- a/examples/device/msc_dual_lun/src/tusb_config.h
+++ b/examples/device/msc_dual_lun/src/tusb_config.h
@@ -30,42 +30,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
-// defined by compiler flags for flexibility
+// defined by board.mk
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+// RHPort number used for device can be defined by board.mk, default to port 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
+#endif
+
+// RHPort max operational speed can defined by board.mk
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
+#endif
+
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -79,7 +83,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/device/msc_dual_lun/src/usb_descriptors.c b/examples/device/msc_dual_lun/src/usb_descriptors.c
index c0610945f..2afd391af 100644
--- a/examples/device/msc_dual_lun/src/usb_descriptors.c
+++ b/examples/device/msc_dual_lun/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
@@ -91,12 +90,6 @@ enum
#define EPNUM_MSC_OUT 0x01
#define EPNUM_MSC_IN 0x82
-#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
- // FT9XX doesn't support a same endpoint number with different direction IN and OUT
- // e.g EP1 OUT & EP1 IN cannot exist together
- #define EPNUM_MSC_OUT 0x01
- #define EPNUM_MSC_IN 0x82
-
#else
#define EPNUM_MSC_OUT 0x01
#define EPNUM_MSC_IN 0x81
@@ -142,63 +135,51 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456789012", // 3: Serials, should use chip ID
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
-family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
+if (EXISTS ${TOP}/lib/lwip/src)
+ include(${TOP}/hw/bsp/family_support.cmake)
-set(LWIP ${TOP}/lib/lwip)
-if (NOT EXISTS ${LWIP}/src)
- family_example_missing_dependency(${PROJECT} "lib/lwip")
- return()
-endif()
+ # gets PROJECT name for the example (e.g. -)
+ family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+ project(${PROJECT})
-# Checks this example is valid for the family and initializes the project
-family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
+ # Checks this example is valid for the family and initializes the project
+ family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-add_executable(${PROJECT})
+ add_executable(${PROJECT})
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_LIST_DIR}/src/main.c
- ${CMAKE_CURRENT_LIST_DIR}/src/usb_descriptors.c
- )
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_LIST_DIR}/src
- ${LWIP}/src/include
- ${LWIP}/src/include/ipv4
- ${LWIP}/src/include/lwip/apps
- ${TOP}/lib/networking
- )
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ ${TOP}/lib/lwip/src/include
+ ${TOP}/lib/lwip/src/include/ipv4
+ ${TOP}/lib/lwip/src/include/lwip/apps
+ ${TOP}/lib/networking
+ )
-# lib/networking sources
-target_sources(${PROJECT} PUBLIC
- ${TOP}/lib/networking/dhserver.c
- ${TOP}/lib/networking/dnserver.c
- ${TOP}/lib/networking/rndis_reports.c
- )
+ target_sources(${PROJECT} PUBLIC
+ ${TOP}/lib/lwip/src/core/altcp.c
+ ${TOP}/lib/lwip/src/core/altcp_alloc.c
+ ${TOP}/lib/lwip/src/core/altcp_tcp.c
+ ${TOP}/lib/lwip/src/core/def.c
+ ${TOP}/lib/lwip/src/core/dns.c
+ ${TOP}/lib/lwip/src/core/inet_chksum.c
+ ${TOP}/lib/lwip/src/core/init.c
+ ${TOP}/lib/lwip/src/core/ip.c
+ ${TOP}/lib/lwip/src/core/mem.c
+ ${TOP}/lib/lwip/src/core/memp.c
+ ${TOP}/lib/lwip/src/core/netif.c
+ ${TOP}/lib/lwip/src/core/pbuf.c
+ ${TOP}/lib/lwip/src/core/raw.c
+ ${TOP}/lib/lwip/src/core/stats.c
+ ${TOP}/lib/lwip/src/core/sys.c
+ ${TOP}/lib/lwip/src/core/tcp.c
+ ${TOP}/lib/lwip/src/core/tcp_in.c
+ ${TOP}/lib/lwip/src/core/tcp_out.c
+ ${TOP}/lib/lwip/src/core/timeouts.c
+ ${TOP}/lib/lwip/src/core/udp.c
+ ${TOP}/lib/lwip/src/core/ipv4/autoip.c
+ ${TOP}/lib/lwip/src/core/ipv4/dhcp.c
+ ${TOP}/lib/lwip/src/core/ipv4/etharp.c
+ ${TOP}/lib/lwip/src/core/ipv4/icmp.c
+ ${TOP}/lib/lwip/src/core/ipv4/igmp.c
+ ${TOP}/lib/lwip/src/core/ipv4/ip4.c
+ ${TOP}/lib/lwip/src/core/ipv4/ip4_addr.c
+ ${TOP}/lib/lwip/src/core/ipv4/ip4_frag.c
+ ${TOP}/lib/lwip/src/netif/ethernet.c
+ ${TOP}/lib/lwip/src/netif/slipif.c
+ ${TOP}/lib/lwip/src/apps/http/httpd.c
+ ${TOP}/lib/lwip/src/apps/http/fs.c
+ ${TOP}/lib/networking/dhserver.c
+ ${TOP}/lib/networking/dnserver.c
+ ${TOP}/lib/networking/rndis_reports.c
+ )
-# lwip sources
-target_sources(${PROJECT} PUBLIC
- ${LWIP}/src/core/altcp.c
- ${LWIP}/src/core/altcp_alloc.c
- ${LWIP}/src/core/altcp_tcp.c
- ${LWIP}/src/core/def.c
- ${LWIP}/src/core/dns.c
- ${LWIP}/src/core/inet_chksum.c
- ${LWIP}/src/core/init.c
- ${LWIP}/src/core/ip.c
- ${LWIP}/src/core/mem.c
- ${LWIP}/src/core/memp.c
- ${LWIP}/src/core/netif.c
- ${LWIP}/src/core/pbuf.c
- ${LWIP}/src/core/raw.c
- ${LWIP}/src/core/stats.c
- ${LWIP}/src/core/sys.c
- ${LWIP}/src/core/tcp.c
- ${LWIP}/src/core/tcp_in.c
- ${LWIP}/src/core/tcp_out.c
- ${LWIP}/src/core/timeouts.c
- ${LWIP}/src/core/udp.c
- ${LWIP}/src/core/ipv4/autoip.c
- ${LWIP}/src/core/ipv4/dhcp.c
- ${LWIP}/src/core/ipv4/etharp.c
- ${LWIP}/src/core/ipv4/icmp.c
- ${LWIP}/src/core/ipv4/igmp.c
- ${LWIP}/src/core/ipv4/ip4.c
- ${LWIP}/src/core/ipv4/ip4_addr.c
- ${LWIP}/src/core/ipv4/ip4_frag.c
- ${LWIP}/src/netif/ethernet.c
- ${LWIP}/src/netif/slipif.c
- ${LWIP}/src/apps/http/httpd.c
- ${LWIP}/src/apps/http/fs.c
- )
+ target_compile_definitions(${PROJECT} PUBLIC
+ PBUF_POOL_SIZE=2
+ TCP_WND=2*TCP_MSS
+ HTTPD_USE_CUSTOM_FSDATA=0
+ )
-# due to warnings from other net source, we need to prevent error from some of the warnings options
-if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_options(${PROJECT} PUBLIC
- -Wno-error=null-dereference
- -Wno-error=conversion
- -Wno-error=sign-conversion
- -Wno-error=sign-compare
- )
-elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
-
-endif ()
-
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+ # Configure compilation flags and libraries for the example... see the corresponding function
+ # in hw/bsp/FAMILY/family.cmake for details.
+ family_configure_device_example(${PROJECT})
+endif()
\ No newline at end of file
diff --git a/examples/device/net_lwip_webserver/Makefile b/examples/device/net_lwip_webserver/Makefile
index 90b429d00..c3e0d8899 100644
--- a/examples/device/net_lwip_webserver/Makefile
+++ b/examples/device/net_lwip_webserver/Makefile
@@ -1,12 +1,12 @@
DEPS_SUBMODULES += lib/lwip
+include ../../../tools/top.mk
include ../../make.mk
-# suppress warning caused by lwip
-CFLAGS_GCC += \
- -Wno-error=null-dereference \
- -Wno-error=unused-parameter \
- -Wno-error=unused-variable
+CFLAGS += \
+ -DPBUF_POOL_SIZE=2 \
+ -DTCP_WND=2*TCP_MSS \
+ -DHTTPD_USE_CUSTOM_FSDATA=0
INC += \
src \
@@ -50,15 +50,6 @@ SRC_C += \
lib/lwip/src/core/ipv4/ip4.c \
lib/lwip/src/core/ipv4/ip4_addr.c \
lib/lwip/src/core/ipv4/ip4_frag.c \
- lib/lwip/src/core/ipv6/dhcp6.c \
- lib/lwip/src/core/ipv6/ethip6.c \
- lib/lwip/src/core/ipv6/icmp6.c \
- lib/lwip/src/core/ipv6/inet6.c \
- lib/lwip/src/core/ipv6/ip6.c \
- lib/lwip/src/core/ipv6/ip6_addr.c \
- lib/lwip/src/core/ipv6/ip6_frag.c \
- lib/lwip/src/core/ipv6/mld6.c \
- lib/lwip/src/core/ipv6/nd6.c \
lib/lwip/src/netif/ethernet.c \
lib/lwip/src/netif/slipif.c \
lib/lwip/src/apps/http/httpd.c \
diff --git a/examples/device/net_lwip_webserver/skip.txt b/examples/device/net_lwip_webserver/skip.txt
deleted file mode 100644
index e3a726a2b..000000000
--- a/examples/device/net_lwip_webserver/skip.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-mcu:LPC11UXX
-mcu:LPC13XX
-mcu:MSP430x5xx
-mcu:NUC121
-mcu:SAMD11
-mcu:STM32L0
-mcu:KINETIS_KL
-family:broadcom_64bit
-family:broadcom_32bit
-board:curiosity_nano
-board:frdm_kl25z
diff --git a/examples/device/net_lwip_webserver/src/arch/bpstruct.h b/examples/device/net_lwip_webserver/src/arch/bpstruct.h
deleted file mode 100644
index 74ead358f..000000000
--- a/examples/device/net_lwip_webserver/src/arch/bpstruct.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * This file is part of the lwIP TCP/IP stack.
- *
- * Author: Adam Dunkels
- *
- */
-
-#if defined(__ICCARM__)
-#pragma pack(1)
-#endif
diff --git a/examples/device/net_lwip_webserver/src/arch/cc.h b/examples/device/net_lwip_webserver/src/arch/cc.h
index 9f30b91cb..56a0cacf7 100644
--- a/examples/device/net_lwip_webserver/src/arch/cc.h
+++ b/examples/device/net_lwip_webserver/src/arch/cc.h
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
@@ -11,21 +11,21 @@
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
+ * derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
- *
+ *
* Author: Adam Dunkels
*
*/
@@ -42,7 +42,7 @@ typedef int sys_prot_t;
#if defined (__ICCARM__)
#define PACK_STRUCT_BEGIN
-#define PACK_STRUCT_STRUCT
+#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#define PACK_STRUCT_USE_INCLUDES
@@ -50,7 +50,7 @@ typedef int sys_prot_t;
#elif defined (__CC_ARM)
#define PACK_STRUCT_BEGIN __packed
-#define PACK_STRUCT_STRUCT
+#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
diff --git a/examples/device/net_lwip_webserver/src/arch/epstruct.h b/examples/device/net_lwip_webserver/src/arch/epstruct.h
deleted file mode 100644
index f6390959e..000000000
--- a/examples/device/net_lwip_webserver/src/arch/epstruct.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * This file is part of the lwIP TCP/IP stack.
- *
- * Author: Adam Dunkels
- *
- */
-
-#if defined(__ICCARM__)
-#pragma pack()
-#endif
diff --git a/examples/device/net_lwip_webserver/src/lwipopts.h b/examples/device/net_lwip_webserver/src/lwipopts.h
index 336c9243d..5a8096f50 100644
--- a/examples/device/net_lwip_webserver/src/lwipopts.h
+++ b/examples/device/net_lwip_webserver/src/lwipopts.h
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
@@ -11,21 +11,21 @@
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
+ * derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
- *
+ *
* Author: Simon Goldschmidt
*
*/
@@ -42,14 +42,11 @@
#define LWIP_ICMP 1
#define LWIP_UDP 1
#define LWIP_TCP 1
-#define LWIP_IPV4 1
-#define LWIP_IPV6 0
#define ETH_PAD_SIZE 0
#define LWIP_IP_ACCEPT_UDP_PORT(p) ((p) == PP_NTOHS(67))
#define TCP_MSS (1500 /*mtu*/ - 20 /*iphdr*/ - 20 /*tcphhr*/)
#define TCP_SND_BUF (2 * TCP_MSS)
-#define TCP_WND (TCP_MSS)
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
@@ -59,13 +56,4 @@
#define LWIP_SINGLE_NETIF 1
-#define PBUF_POOL_SIZE 2
-
-#define HTTPD_USE_CUSTOM_FSDATA 0
-
-#define LWIP_MULTICAST_PING 1
-#define LWIP_BROADCAST_PING 1
-#define LWIP_IPV6_MLD 0
-#define LWIP_IPV6_SEND_ROUTER_SOLICIT 0
-
#endif /* __LWIPOPTS_H__ */
diff --git a/examples/device/net_lwip_webserver/src/main.c b/examples/device/net_lwip_webserver/src/main.c
index 7d98aacbc..a5bd2153a 100644
--- a/examples/device/net_lwip_webserver/src/main.c
+++ b/examples/device/net_lwip_webserver/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Peter Lawrence
@@ -39,22 +39,19 @@ and likely their manufacturer has not tested such functionality. Some code work
The smartphone may only have an ECM driver, but refuse to automatically pick ECM (unlike the OSes above);
try modifying ./examples/devices/net_lwip_webserver/usb_descriptors.c so that CONFIG_ID_ECM is default.
-The smartphone may be artificially picky about which Ethernet MAC address to recognize; if this happens,
+The smartphone may be artificially picky about which Ethernet MAC address to recognize; if this happens,
try changing the first byte of tud_network_mac_address[] below from 0x02 to 0x00 (clearing bit 1).
*/
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#include "dhserver.h"
#include "dnserver.h"
#include "lwip/init.h"
#include "lwip/timeouts.h"
-#include "lwip/ethip6.h"
#include "httpd.h"
-#define INIT_IP4(a,b,c,d) { PP_HTONL(LWIP_MAKEU32(a,b,c,d)) }
-
/* lwip context */
static struct netif netif_data;
@@ -64,27 +61,27 @@ static struct pbuf *received_frame;
/* this is used by this code, ./class/net/net_driver.c, and usb_descriptors.c */
/* ideally speaking, this should be generated from the hardware's unique ID (if available) */
/* it is suggested that the first byte is 0x02 to indicate a link-local address */
-uint8_t tud_network_mac_address[6] = {0x02,0x02,0x84,0x6A,0x96,0x00};
+const uint8_t tud_network_mac_address[6] = {0x02,0x02,0x84,0x6A,0x96,0x00};
/* network parameters of this MCU */
-static const ip4_addr_t ipaddr = INIT_IP4(192, 168, 7, 1);
-static const ip4_addr_t netmask = INIT_IP4(255, 255, 255, 0);
-static const ip4_addr_t gateway = INIT_IP4(0, 0, 0, 0);
+static const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(192, 168, 7, 1);
+static const ip_addr_t netmask = IPADDR4_INIT_BYTES(255, 255, 255, 0);
+static const ip_addr_t gateway = IPADDR4_INIT_BYTES(0, 0, 0, 0);
/* database IP addresses that can be offered to the host; this must be in RAM to store assigned MAC addresses */
static dhcp_entry_t entries[] =
{
/* mac ip address lease time */
- { {0}, INIT_IP4(192, 168, 7, 2), 24 * 60 * 60 },
- { {0}, INIT_IP4(192, 168, 7, 3), 24 * 60 * 60 },
- { {0}, INIT_IP4(192, 168, 7, 4), 24 * 60 * 60 },
+ { {0}, IPADDR4_INIT_BYTES(192, 168, 7, 2), 24 * 60 * 60 },
+ { {0}, IPADDR4_INIT_BYTES(192, 168, 7, 3), 24 * 60 * 60 },
+ { {0}, IPADDR4_INIT_BYTES(192, 168, 7, 4), 24 * 60 * 60 },
};
static const dhcp_config_t dhcp_config =
{
- .router = INIT_IP4(0, 0, 0, 0), /* router address (if any) */
+ .router = IPADDR4_INIT_BYTES(0, 0, 0, 0), /* router address (if any) */
.port = 67, /* listen port */
- .dns = INIT_IP4(192, 168, 7, 1), /* dns server (if any) */
+ .dns = IPADDR4_INIT_BYTES(192, 168, 7, 1), /* dns server (if any) */
"usb", /* dns suffix */
TU_ARRAY_SIZE(entries), /* num entry */
entries /* entries */
@@ -111,18 +108,11 @@ static err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
}
}
-static err_t ip4_output_fn(struct netif *netif, struct pbuf *p, const ip4_addr_t *addr)
+static err_t output_fn(struct netif *netif, struct pbuf *p, const ip_addr_t *addr)
{
return etharp_output(netif, p, addr);
}
-#if LWIP_IPV6
-static err_t ip6_output_fn(struct netif *netif, struct pbuf *p, const ip6_addr_t *addr)
-{
- return ethip6_output(netif, p, addr);
-}
-#endif
-
static err_t netif_init_cb(struct netif *netif)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
@@ -132,10 +122,7 @@ static err_t netif_init_cb(struct netif *netif)
netif->name[0] = 'E';
netif->name[1] = 'X';
netif->linkoutput = linkoutput_fn;
- netif->output = ip4_output_fn;
-#if LWIP_IPV6
- netif->output_ip6 = ip6_output_fn;
-#endif
+ netif->output = output_fn;
return ERR_OK;
}
@@ -151,14 +138,11 @@ static void init_lwip(void)
netif->hwaddr[5] ^= 0x01;
netif = netif_add(netif, &ipaddr, &netmask, &gateway, NULL, netif_init_cb, ip_input);
-#if LWIP_IPV6
- netif_create_ip6_linklocal_address(netif, 1);
-#endif
netif_set_default(netif);
}
/* handle any DNS requests from dns-server */
-bool dns_query_proc(const char *name, ip4_addr_t *addr)
+bool dns_query_proc(const char *name, ip_addr_t *addr)
{
if (0 == strcmp(name, "tiny.usb"))
{
@@ -170,7 +154,7 @@ bool dns_query_proc(const char *name, ip4_addr_t *addr)
bool tud_network_recv_cb(const uint8_t *src, uint16_t size)
{
- /* this shouldn't happen, but if we get another packet before
+ /* this shouldn't happen, but if we get another packet before
parsing the previous, we must signal our inability to accept it */
if (received_frame) return false;
@@ -228,19 +212,13 @@ int main(void)
{
/* initialize TinyUSB */
board_init();
-
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
/* initialize lwip, dhcp-server, dns-server, and http */
init_lwip();
while (!netif_is_up(&netif_data));
while (dhserv_init(&dhcp_config) != ERR_OK);
- while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc) != ERR_OK);
+ while (dnserv_init(&ipaddr, 53, dns_query_proc) != ERR_OK);
httpd_init();
while (1)
diff --git a/examples/device/net_lwip_webserver/src/tusb_config.h b/examples/device/net_lwip_webserver/src/tusb_config.h
index fe72ecdfe..114961cb7 100644
--- a/examples/device/net_lwip_webserver/src/tusb_config.h
+++ b/examples/device/net_lwip_webserver/src/tusb_config.h
@@ -30,42 +30,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
+//--------------------------------------------------------------------
+// COMMON CONFIGURATION
+//--------------------------------------------------------------------
+
+// defined by board.mk
+#ifndef CFG_TUSB_MCU
+ #error CFG_TUSB_MCU must be defined
+#endif
// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
#endif
// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
#endif
-//--------------------------------------------------------------------
-// Common Configuration
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -79,7 +83,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/device/net_lwip_webserver/src/usb_descriptors.c b/examples/device/net_lwip_webserver/src/usb_descriptors.c
index da628c8be..2b4b2a0c3 100644
--- a/examples/device/net_lwip_webserver/src/usb_descriptors.c
+++ b/examples/device/net_lwip_webserver/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
@@ -78,7 +77,7 @@ tusb_desc_device_t const desc_device =
.bDeviceClass = TUSB_CLASS_MISC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
-
+
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.idVendor = 0xCafe,
@@ -191,60 +190,59 @@ static char const* string_desc_arr [] =
[STRID_LANGID] = (const char[]) { 0x09, 0x04 }, // supported language is English (0x0409)
[STRID_MANUFACTURER] = "TinyUSB", // Manufacturer
[STRID_PRODUCT] = "TinyUSB Device", // Product
- [STRID_SERIAL] = NULL, // Serials will use unique ID if possible
+ [STRID_SERIAL] = "123456", // Serial
[STRID_INTERFACE] = "TinyUSB Network Interface" // Interface Description
// STRID_MAC index is handled separately
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
+
unsigned int chr_count = 0;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ if (STRID_LANGID == index)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[STRID_LANGID], 2);
+ chr_count = 1;
+ }
+ else if (STRID_MAC == index)
+ {
+ // Convert MAC address into UTF-16
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ for (unsigned i=0; i> 4) & 0xf];
+ _desc_str[1+chr_count++] = "0123456789ABCDEF"[(tud_network_mac_address[i] >> 0) & 0xf];
+ }
+ }
+ else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- case STRID_MAC:
- // Convert MAC address into UTF-16
- for (unsigned i=0; i> 4) & 0xf];
- _desc_str[1+chr_count++] = "0123456789ABCDEF"[(tud_network_mac_address[i] >> 0) & 0xf];
- }
- break;
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ const char* str = string_desc_arr[index];
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > (TU_ARRAY_SIZE(_desc_str) - 1)) chr_count = TU_ARRAY_SIZE(_desc_str) - 1;
- const char *str = string_desc_arr[index];
-
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for (unsigned int i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
# Example source
@@ -28,6 +23,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/uac2_headset/Makefile b/examples/device/uac2_headset/Makefile
index 2a3d854fb..5a455078e 100644
--- a/examples/device/uac2_headset/Makefile
+++ b/examples/device/uac2_headset/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/uac2_headset/skip.txt b/examples/device/uac2_headset/skip.txt
deleted file mode 100644
index 70d8e8838..000000000
--- a/examples/device/uac2_headset/skip.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-mcu:LPC11UXX
-mcu:LPC13XX
-mcu:NUC121
-mcu:SAMD11
-mcu:SAME5X
-mcu:SAMG
-board:stm32l052dap52
diff --git a/examples/device/uac2_headset/src/main.c b/examples/device/uac2_headset/src/main.c
index 0ab72b2f3..790af088f 100644
--- a/examples/device/uac2_headset/src/main.c
+++ b/examples/device/uac2_headset/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Jerzy Kasenberg
@@ -26,7 +26,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -36,12 +36,11 @@
// List of supported sample rates
#if defined(__RX__)
- const uint32_t sample_rates[] = {44100, 48000};
+const uint32_t sample_rates[] = {44100, 48000};
#else
- const uint32_t sample_rates[] = {44100, 48000, 88200, 96000};
+const uint32_t sample_rates[] = {44100, 48000, 88200, 96000};
#endif
-
-uint32_t current_sample_rate = 44100;
+uint32_t current_sample_rate = 44100;
#define N_SAMPLE_RATES TU_ARRAY_SIZE(sample_rates)
@@ -79,8 +78,8 @@ static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
// Audio controls
// Current states
-int8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1]; // +1 for master channel 0
-int16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1]; // +1 for master channel 0
+int8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1]; // +1 for master channel 0
+int16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1]; // +1 for master channel 0
// Buffer for microphone data
int32_t mic_buf[CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ / 4];
@@ -102,12 +101,7 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
TU_LOG1("Headset running\r\n");
@@ -117,6 +111,8 @@ int main(void)
audio_task();
led_blinking_task();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -147,7 +143,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
// Helper for clock get requests
@@ -159,9 +155,9 @@ static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t
{
if (request->bRequest == AUDIO_CS_REQ_CUR)
{
- TU_LOG1("Clock get current freq %lu\r\n", current_sample_rate);
+ TU_LOG1("Clock get current freq %u\r\n", current_sample_rate);
- audio_control_cur_4_t curf = { (int32_t) tu_htole32(current_sample_rate) };
+ audio_control_cur_4_t curf = { tu_htole32(current_sample_rate) };
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &curf, sizeof(curf));
}
else if (request->bRequest == AUDIO_CS_REQ_RANGE)
@@ -173,12 +169,12 @@ static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t
TU_LOG1("Clock get %d freq ranges\r\n", N_SAMPLE_RATES);
for(uint8_t i = 0; i < N_SAMPLE_RATES; i++)
{
- rangef.subrange[i].bMin = (int32_t) sample_rates[i];
- rangef.subrange[i].bMax = (int32_t) sample_rates[i];
+ rangef.subrange[i].bMin = sample_rates[i];
+ rangef.subrange[i].bMax = sample_rates[i];
rangef.subrange[i].bRes = 0;
TU_LOG1("Range %d (%d, %d, %d)\r\n", i, (int)rangef.subrange[i].bMin, (int)rangef.subrange[i].bMax, (int)rangef.subrange[i].bRes);
}
-
+
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &rangef, sizeof(rangef));
}
}
@@ -206,9 +202,9 @@ static bool tud_audio_clock_set_request(uint8_t rhport, audio_control_request_t
{
TU_VERIFY(request->wLength == sizeof(audio_control_cur_4_t));
- current_sample_rate = (uint32_t) ((audio_control_cur_4_t const *)buf)->bCur;
+ current_sample_rate = ((audio_control_cur_4_t *)buf)->bCur;
- TU_LOG1("Clock set current freq: %ld\r\n", current_sample_rate);
+ TU_LOG1("Clock set current freq: %d\r\n", current_sample_rate);
return true;
}
@@ -268,7 +264,7 @@ static bool tud_audio_feature_unit_set_request(uint8_t rhport, audio_control_req
{
TU_VERIFY(request->wLength == sizeof(audio_control_cur_1_t));
- mute[request->bChannelNumber] = ((audio_control_cur_1_t const *)buf)->bCur;
+ mute[request->bChannelNumber] = ((audio_control_cur_1_t *)buf)->bCur;
TU_LOG1("Set channel %d Mute: %d\r\n", request->bChannelNumber, mute[request->bChannelNumber]);
@@ -299,7 +295,7 @@ static bool tud_audio_feature_unit_set_request(uint8_t rhport, audio_control_req
// Invoked when audio class specific get request received for an entity
bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request)
{
- audio_control_request_t const *request = (audio_control_request_t const *)p_request;
+ audio_control_request_t *request = (audio_control_request_t *)p_request;
if (request->bEntityID == UAC2_ENTITY_CLOCK)
return tud_audio_clock_get_request(rhport, request);
@@ -405,9 +401,9 @@ void audio_task(void)
// Combine two channels into one
int32_t left = *src++;
int32_t right = *src++;
- *dst++ = (int16_t) ((left >> 1) + (right >> 1));
+ *dst++ = (left >> 1) + (right >> 1);
}
- tud_audio_write((uint8_t *)mic_buf, (uint16_t) (spk_data_size / 2));
+ tud_audio_write((uint8_t *)mic_buf, spk_data_size / 2);
spk_data_size = 0;
}
else if (current_resolution == 24)
@@ -420,9 +416,9 @@ void audio_task(void)
// Combine two channels into one
int32_t left = *src++;
int32_t right = *src++;
- *dst++ = (int32_t) ((uint32_t) ((left >> 1) + (right >> 1)) & 0xffffff00ul);
+ *dst++ = ((left >> 1) + (right >> 1)) & 0xffffff00;
}
- tud_audio_write((uint8_t *)mic_buf, (uint16_t) (spk_data_size / 2));
+ tud_audio_write((uint8_t *)mic_buf, spk_data_size / 2);
spk_data_size = 0;
}
}
diff --git a/examples/device/uac2_headset/src/tusb_config.h b/examples/device/uac2_headset/src/tusb_config.h
index 1a3e23e95..e8d93f56a 100644
--- a/examples/device/uac2_headset/src/tusb_config.h
+++ b/examples/device/uac2_headset/src/tusb_config.h
@@ -31,45 +31,34 @@
extern "C" {
#endif
+//--------------------------------------------------------------------
+// COMMON CONFIGURATION
+//--------------------------------------------------------------------
+
#include "usb_descriptors.h"
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
-//--------------------------------------------------------------------
-// Common Configuration
-//--------------------------------------------------------------------
-
// defined by compiler flags for flexibility
#ifndef CFG_TUSB_MCU
#error CFG_TUSB_MCU must be defined
#endif
+#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
+#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED)
+#else
+#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
+#endif
+
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
+// Can be set during compilation i.e.: make LOG= BOARD=
+// Keep in mind that enabling logs when data is streaming can disrupt data flow.
+// It can be very helpful though when audio unit requests are tested/debugged.
+#define CFG_TUSB_DEBUG 0
#endif
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
-
/* 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.
@@ -82,7 +71,7 @@ extern "C" {
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/device/uac2_headset/src/usb_descriptors.c b/examples/device/uac2_headset/src/usb_descriptors.c
index 6d1e6a23f..9e97845b8 100644
--- a/examples/device/uac2_headset/src/usb_descriptors.c
+++ b/examples/device/uac2_headset/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Ha Thach (tinyusb.org)
@@ -24,7 +24,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -47,7 +46,7 @@ tusb_desc_device_t const desc_device =
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
- // Use Interface Association Descriptor (IAD) for Audio
+ // 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,
@@ -94,12 +93,6 @@ uint8_t const * tud_descriptor_device_cb(void)
#define EPNUM_AUDIO_IN 0x01
#define EPNUM_AUDIO_OUT 0x02
-#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
- // FT9XX doesn't support a same endpoint number with different direction IN and OUT
- // e.g EP1 OUT & EP1 IN cannot exist together
- #define EPNUM_AUDIO_IN 0x01
- #define EPNUM_AUDIO_OUT 0x02
-
#else
#define EPNUM_AUDIO_IN 0x01
#define EPNUM_AUDIO_OUT 0x01
@@ -107,7 +100,7 @@ uint8_t const * tud_descriptor_device_cb(void)
uint8_t const desc_configuration[] =
{
- // Config number, interface count, string index, total length, attribute, power in mA
+ // Interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP Out & EP In address, EP size
@@ -127,65 +120,52 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB headset", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "000001", // 3: Serials, should use chip ID
"TinyUSB Speakers", // 4: Audio Interface
"TinyUSB Microphone", // 5: Audio Interface
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
- (void) langid;
- size_t chr_count;
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
+ (void)langid;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if (index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }
+ else
+ {
+ // Convert ASCII string into UTF-16
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if (!(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0]))) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if (chr_count > 31) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ for (uint8_t i = 0; i < chr_count; i++)
+ {
+ _desc_str[1 + i] = str[i];
+ }
}
// first byte is length (including header), second byte is string type
- _desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
+ _desc_str[0] = (TUSB_DESC_STRING << 8 ) | (2 * chr_count + 2);
return _desc_str;
}
diff --git a/examples/device/uac2_headset/src/usb_descriptors.h b/examples/device/uac2_headset/src/usb_descriptors.h
index d7e170162..d9510ea4f 100644
--- a/examples/device/uac2_headset/src/usb_descriptors.h
+++ b/examples/device/uac2_headset/src/usb_descriptors.h
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Jerzy Kasenbreg
@@ -57,7 +57,7 @@ enum
+ TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
/* Interface 1, Alternate 0 */\
+ TUD_AUDIO_DESC_STD_AS_INT_LEN\
- /* Interface 1, Alternate 1 */\
+ /* Interface 1, Alternate 0 */\
+ TUD_AUDIO_DESC_STD_AS_INT_LEN\
+ TUD_AUDIO_DESC_CS_AS_INT_LEN\
+ TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
@@ -86,7 +86,7 @@ enum
#define TUD_AUDIO_HEADSET_STEREO_DESCRIPTOR(_stridx, _epout, _epin) \
/* Standard Interface Association Descriptor (IAD) */\
- TUD_AUDIO_DESC_IAD(/*_firstitf*/ ITF_NUM_AUDIO_CONTROL, /*_nitfs*/ ITF_NUM_TOTAL, /*_stridx*/ 0x00),\
+ TUD_AUDIO_DESC_IAD(/*_firstitfs*/ ITF_NUM_AUDIO_CONTROL, /*_nitfs*/ ITF_NUM_TOTAL, /*_stridx*/ 0x00),\
/* Standard AC Interface Descriptor(4.7.1) */\
TUD_AUDIO_DESC_STD_AC(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
/* Class-Specific AC Interface Header Descriptor(4.7.2) */\
@@ -114,7 +114,7 @@ enum
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ADAPTIVE | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
+ TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ADAPTIVE | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
/* Interface 1, Alternate 2 - alternate interface for data streaming */\
@@ -124,7 +124,7 @@ enum
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ADAPTIVE | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
+ TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ADAPTIVE | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
/* Standard AS Interface Descriptor(4.9.1) */\
@@ -138,7 +138,7 @@ enum
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_TX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
+ TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
/* Interface 2, Alternate 2 - alternate interface for data streaming */\
@@ -148,7 +148,7 @@ enum
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_TX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
+ TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt
index a63ca2d81..c49603c26 100644
--- a/examples/device/usbtmc/CMakeLists.txt
+++ b/examples/device/usbtmc/CMakeLists.txt
@@ -1,20 +1,15 @@
-cmake_minimum_required(VERSION 3.17)
+cmake_minimum_required(VERSION 3.5)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
# gets PROJECT name for the example (e.g. -)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
# Example source
@@ -29,6 +24,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/usbtmc/Makefile b/examples/device/usbtmc/Makefile
index da088ea6b..69b633fea 100644
--- a/examples/device/usbtmc/Makefile
+++ b/examples/device/usbtmc/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/usbtmc/skip.txt b/examples/device/usbtmc/skip.txt
deleted file mode 100644
index a43106cf0..000000000
--- a/examples/device/usbtmc/skip.txt
+++ /dev/null
@@ -1 +0,0 @@
-mcu:BCM2835
diff --git a/examples/device/usbtmc/src/main.c b/examples/device/usbtmc/src/main.c
index 9d8f0783d..1fce48f45 100644
--- a/examples/device/usbtmc/src/main.c
+++ b/examples/device/usbtmc/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,7 +27,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#include "usbtmc_app.h"
//--------------------------------------------------------------------+
@@ -54,12 +54,7 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
@@ -67,6 +62,8 @@ int main(void)
led_blinking_task();
usbtmc_app_task_iter();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -97,7 +94,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
diff --git a/examples/device/usbtmc/src/tusb_config.h b/examples/device/usbtmc/src/tusb_config.h
index ab486b108..a192d0dbc 100644
--- a/examples/device/usbtmc/src/tusb_config.h
+++ b/examples/device/usbtmc/src/tusb_config.h
@@ -12,42 +12,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
+//--------------------------------------------------------------------
+// COMMON CONFIGURATION
+//--------------------------------------------------------------------
+
+// defined by board.mk
+#ifndef CFG_TUSB_MCU
+ #error CFG_TUSB_MCU must be defined
+#endif
// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
#endif
// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
#endif
-//--------------------------------------------------------------------
-// Common Configuration
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -61,7 +65,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/device/usbtmc/src/usb_descriptors.c b/examples/device/usbtmc/src/usb_descriptors.c
index 54948291e..423482634 100644
--- a/examples/device/usbtmc/src/usb_descriptors.c
+++ b/examples/device/usbtmc/src/usb_descriptors.c
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
#include "class/usbtmc/usbtmc.h"
#include "class/usbtmc/usbtmc_device.h"
@@ -38,9 +37,6 @@
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
_PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )
-#define USB_VID 0xCafe
-#define USB_BCD 0x0200
-
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
@@ -55,9 +51,9 @@ tusb_desc_device_t const desc_device =
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
- .idVendor = USB_VID,
+ .idVendor = 0xCafe,
.idProduct = USB_PID,
- .bcdDevice = USB_BCD,
+ .bcdDevice = 0x0100,
.iManufacturer = 0x01,
.iProduct = 0x02,
@@ -79,22 +75,22 @@ uint8_t const * tud_descriptor_device_cb(void)
#if defined(CFG_TUD_USBTMC)
-# define TUD_USBTMC_DESC_MAIN(_itfnum,_bNumEndpoints, _bulkMaxPacketLength) \
+# define TUD_USBTMC_DESC_MAIN(_itfnum,_bNumEndpoints) \
TUD_USBTMC_IF_DESCRIPTOR(_itfnum, _bNumEndpoints, /*_stridx = */ 4u, TUD_USBTMC_PROTOCOL_USB488), \
- TUD_USBTMC_BULK_DESCRIPTORS(/* OUT = */0x01, /* IN = */ 0x81, /* packet size = */_bulkMaxPacketLength)
+ TUD_USBTMC_BULK_DESCRIPTORS(/* OUT = */0x01, /* IN = */ 0x81, /* packet size = */USBTMCD_MAX_PACKET_SIZE)
#if CFG_TUD_USBTMC_ENABLE_INT_EP
// USBTMC Interrupt xfer always has length of 2, but we use epMaxSize=8 for
// compatibility with mcus that only allow 8, 16, 32 or 64 for FS endpoints
-# define TUD_USBTMC_DESC(_itfnum, _bulkMaxPacketLength) \
- TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3, _bulkMaxPacketLength), \
+# define TUD_USBTMC_DESC(_itfnum) \
+ TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3), \
TUD_USBTMC_INT_DESCRIPTOR(/* INT ep # */ 0x82, /* epMaxSize = */ 8, /* bInterval = */16u )
# define TUD_USBTMC_DESC_LEN (TUD_USBTMC_IF_DESCRIPTOR_LEN + TUD_USBTMC_BULK_DESCRIPTORS_LEN + TUD_USBTMC_INT_DESCRIPTOR_LEN)
#else
-# define TUD_USBTMC_DESC(_itfnum, _bulkMaxPacketLength) \
- TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 2u, _bulkMaxPacketLength)
+# define TUD_USBTMC_DESC(_itfnum) \
+ TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 2u)
# define TUD_USBTMC_DESC_LEN (TUD_USBTMC_IF_DESCRIPTOR_LEN + TUD_USBTMC_BULK_DESCRIPTORS_LEN)
#endif /* CFG_TUD_USBTMC_ENABLE_INT_EP */
@@ -123,130 +119,76 @@ enum
#endif
-uint8_t const desc_fs_configuration[] =
+uint8_t const desc_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
- TUD_USBTMC_DESC(ITF_NUM_USBTMC, /* _bulkMaxPacketLength = */ 64),
+ TUD_USBTMC_DESC(ITF_NUM_USBTMC),
};
-#if TUD_OPT_HIGH_SPEED
-
-uint8_t const desc_hs_configuration[] =
-{
- // Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
-
- TUD_USBTMC_DESC(ITF_NUM_USBTMC, /* _bulkMaxPacketLength = */ 512),
-};
-
-// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
-
-// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier =
-{
- .bLength = sizeof(tusb_desc_device_qualifier_t),
- .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
- .bcdUSB = USB_BCD,
-
- .bDeviceClass = 0x00,
- .bDeviceSubClass = 0x00,
- .bDeviceProtocol = 0x00,
-
- .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
- .bNumConfigurations = 0x01,
- .bReserved = 0x00
-};
-
-// Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
-// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
-// device_qualifier descriptor describes information about a high-speed capable device that would
-// change if the device were operating at the other speed. If not highspeed capable stall this request.
-uint8_t const* tud_descriptor_device_qualifier_cb(void)
-{
- return (uint8_t const*) &desc_device_qualifier;
-}
-
-#endif
-
// Invoked when received GET CONFIGURATION DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
{
(void) index; // for multiple configurations
-#if TUD_OPT_HIGH_SPEED
- // Although we are highspeed, host may be fullspeed.
- return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_hs_configuration : desc_fs_configuration;
-#else
- return desc_fs_configuration;
-#endif
+ return desc_configuration;
}
//--------------------------------------------------------------------+
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
"TinyUSB USBTMC", // 4: USBTMC
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
+
size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }
+ else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ const char* str = string_desc_arr[index];
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) {
+ chr_count = 31;
+ }
- const char *str = string_desc_arr[index];
-
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i
+#include
#include /* atoi */
#include "tusb.h"
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "main.h"
#if (CFG_TUD_USBTMC_ENABLE_488)
@@ -88,6 +88,14 @@ static size_t buffer_tx_ix; // for transmitting using multiple transfers
static uint8_t buffer[225]; // A few packets long should be enough.
+static usbtmc_msg_dev_dep_msg_in_header_t rspMsg = {
+ .bmTransferAttributes =
+ {
+ .EOM = 1,
+ .UsingTermChar = 0
+ }
+};
+
void tud_usbtmc_open_cb(uint8_t interface_id)
{
(void)interface_id;
@@ -140,14 +148,11 @@ bool tud_usbtmc_msg_data_cb(void *data, size_t len, bool transfer_complete)
queryState = transfer_complete;
idnQuery = 0;
- if ( transfer_complete && (len >= 4) &&
- (!strncmp("*idn?", data, 4) || !strncmp("*IDN?", data, 4)) )
+ if(transfer_complete && (len >=4) && !strncasecmp("*idn?",data,4))
{
idnQuery = 1;
}
-
- if ( transfer_complete &&
- (!strncmp("delay ", data, 5) || !strncmp("DELAY ", data, 5)) )
+ if(transfer_complete && !strncasecmp("delay ",data,5))
{
queryState = 0;
int d = atoi((char*)data + 5);
@@ -179,6 +184,9 @@ static unsigned int msgReqLen;
bool tud_usbtmc_msgBulkIn_request_cb(usbtmc_msg_request_dev_dep_in const * request)
{
+ rspMsg.header.MsgID = request->header.MsgID,
+ rspMsg.header.bTag = request->header.bTag,
+ rspMsg.header.bTagInverse = request->header.bTagInverse;
msgReqLen = request->TransferSize;
#ifdef xDEBUG
@@ -242,6 +250,7 @@ void usbtmc_app_task_iter(void) {
break;
default:
TU_ASSERT(false,);
+ return;
}
}
diff --git a/examples/device/usbtmc/visaQuery.py b/examples/device/usbtmc/visaQuery.py
index ca65daf97..50a765a03 100644
--- a/examples/device/usbtmc/visaQuery.py
+++ b/examples/device/usbtmc/visaQuery.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
-import pyvisa
+import visa
import time
import sys
@@ -36,8 +36,8 @@ def test_trig():
time.sleep(0.3) # SRQ may have some delay
assert (inst.read_stb() & 0x40), "SRQ not set after 0.3 seconds"
assert (inst.read_stb() == 0)
-
-
+
+
def test_mav():
inst.write("delay 50")
inst.read_stb() # clear STB
@@ -45,18 +45,18 @@ def test_mav():
inst.write("123")
time.sleep(0.3)
assert (inst.read_stb() & 0x10), "MAV not set after 0.5 seconds"
-
+
rsp = inst.read()
assert(rsp == "123\r\n")
-
-
+
+
def test_srq():
assert (inst.read_stb() == 0)
inst.write("123")
-
- #inst.enable_event(pyvisa.constants.VI_EVENT_SERVICE_REQ, pyvisa.constants.VI_QUEUE)
- #waitrsp = inst.wait_on_event(pyvisa.constants.VI_EVENT_SERVICE_REQ, 5000)
- #inst.discard_events(pyvisa.constants.VI_EVENT_SERVICE_REQ, pyvisa.constants.VI_QUEUE)
+
+ #inst.enable_event(visa.constants.VI_EVENT_SERVICE_REQ, visa.constants.VI_QUEUE)
+ #waitrsp = inst.wait_on_event(visa.constants.VI_EVENT_SERVICE_REQ, 5000)
+ #inst.discard_events(visa.constants.VI_EVENT_SERVICE_REQ, visa.constants.VI_QUEUE)
#inst.wait_for_srq()
time.sleep(0.3)
stb = inst.read_stb()
@@ -64,7 +64,7 @@ def test_srq():
assert (stb == 0x50),msg
assert (inst.read_stb() == 0x10), "SRQ set at second read!"
-
+
rsp = inst.read()
assert(rsp == "123\r\n")
@@ -77,8 +77,8 @@ def test_read_timeout():
t0 = time.monotonic()
try:
rsp = inst.read()
- assert(False), "Read should have resulted in timeout"
- except pyvisa.VisaIOError:
+ assert(false), "Read should have resulted in timeout"
+ except visa.VisaIOError:
print(" Got expected exception")
t = time.monotonic() - t0
assert ((t*1000.0) > (inst.timeout - 300))
@@ -99,29 +99,25 @@ def test_abort_in():
t0 = time.monotonic()
try:
rsp = inst.read()
- assert(False), "Read should have resulted in timeout"
- except pyvisa.VisaIOError:
+ assert(false), "Read should have resulted in timeout"
+ except visa.VisaIOError:
print(" Got expected exception")
t = time.monotonic() - t0
assert ((t*1000.0) > (inst.timeout - 300))
assert ((t*1000.0) < (inst.timeout + 300))
print(f" Delay was {t:0.3}")
- # Response is still in queue, so read it out (to be more helpful to the next test)
+ # Response is still in queue, so send a clear (to be more helpful to the next test)
inst.timeout = 800
y = inst.read()
assert(y == "xxx\r\n")
-
+
def test_indicate():
# perform indicator pulse
- usb_iface = inst.get_visa_attribute(pyvisa.constants.VI_ATTR_USB_INTFC_NUM)
+ usb_iface = inst.get_visa_attribute(visa.constants.VI_ATTR_USB_INTFC_NUM)
retv = inst.control_in(request_type_bitmap_field=0xA1, request_id=64, request_value=0x0000, index=usb_iface, length=0x0001)
- # pyvisa used to return (statuscode,bytes), but now only returns bytes, so we need to handle both cases
- if(isinstance(retv,bytes)):
- assert(retv == b'\x01')
- else:
- assert((retv[1] == pyvisa.constants.StatusCode(0)) and (retv[0] == b'\x01')), f"indicator pulse failed: retv={retv}"
-
-
+ assert((retv[1] == visa.constants.StatusCode(0)) and (retv[0] == b'\x01')), f"indicator pulse failed: retv={retv}"
+
+
def test_multi_read():
old_chunk_size = inst.chunk_size
longstr = "0123456789abcdefghijklmnopqrstuvwxyz" * 10
@@ -133,27 +129,27 @@ def test_multi_read():
y = inst.read()
assert (x + "\r\n" == y)
#inst.chunk_size = old_chunk_size
-
+
def test_stall_ep0():
- usb_iface = inst.get_visa_attribute(pyvisa.constants.VI_ATTR_USB_INTFC_NUM)
+ usb_iface = inst.get_visa_attribute(visa.constants.VI_ATTR_USB_INTFC_NUM)
inst.read_stb()
# This is an invalid request, should create stall.
try:
retv = inst.control_in(request_type_bitmap_field=0xA1, request_id=60, request_value=0x0000, index=usb_iface, length=0x0001)
- assert(False)
- except pyvisa.VisaIOError:
+ assert false
+ except visa.VisaIOError:
pass
-
+
assert (inst.read_stb() == 0)
-rm = pyvisa.ResourceManager()
+rm = visa.ResourceManager()
reslist = rm.list_resources("USB?::?*::INSTR")
print(reslist)
if (len(reslist) == 0):
sys.exit()
-
+
inst = rm.open_resource(reslist[0]);
inst.timeout = 3000
@@ -171,6 +167,7 @@ inst.timeout = 2000
print("+ multi read")
test_multi_read()
+
print("+ echo delay=0")
inst.write("delay 0")
test_echo(1,175)
diff --git a/examples/device/video_capture/.skip.MCU_MSP430x5xx b/examples/device/video_capture/.skip.MCU_MSP430x5xx
new file mode 100644
index 000000000..17600f062
--- /dev/null
+++ b/examples/device/video_capture/.skip.MCU_MSP430x5xx
@@ -0,0 +1 @@
+too many warnings for 16-bit integer overflow
diff --git a/examples/device/video_capture/.skip.MCU_SAMD11 b/examples/device/video_capture/.skip.MCU_SAMD11
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/device/video_capture/CMakeLists.txt b/examples/device/video_capture/CMakeLists.txt
index 80dc39ca5..cb321f9a8 100644
--- a/examples/device/video_capture/CMakeLists.txt
+++ b/examples/device/video_capture/CMakeLists.txt
@@ -1,28 +1,17 @@
-cmake_minimum_required(VERSION 3.17)
+cmake_minimum_required(VERSION 3.5)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
# gets PROJECT name for the example (e.g. -)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
-if (FORCE_READONLY)
-target_compile_definitions(${PROJECT} PRIVATE
- CFG_EXAMPLE_VIDEO_READONLY
-)
-endif()
-
# Example source
target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
@@ -34,6 +23,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/video_capture/Makefile b/examples/device/video_capture/Makefile
index 90d174c32..69b633fea 100644
--- a/examples/device/video_capture/Makefile
+++ b/examples/device/video_capture/Makefile
@@ -1,12 +1,6 @@
+include ../../../tools/top.mk
include ../../make.mk
-ifeq ($(DISABLE_MJPEG),1)
-CFLAGS += -DCFG_EXAMPLE_VIDEO_DISABLE_MJPEG
-endif
-ifeq ($(FORCE_READONLY),1)
-CFLAGS += -DCFG_EXAMPLE_VIDEO_READONLY
-endif
-
INC += \
src \
$(TOP)/hw \
diff --git a/examples/device/video_capture/skip.txt b/examples/device/video_capture/skip.txt
deleted file mode 100644
index 5898664a2..000000000
--- a/examples/device/video_capture/skip.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-mcu:MSP430x5xx
-mcu:NUC121
-mcu:SAMD11
diff --git a/examples/device/video_capture/src/images.h b/examples/device/video_capture/src/images.h
index 0398428b3..1b13cfe81 100644
--- a/examples/device/video_capture/src/images.h
+++ b/examples/device/video_capture/src/images.h
@@ -1,4 +1,3 @@
-#if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPG)
static const unsigned char frame_buffer[128 * (96 + 1) * 2] = {
/* 0 */
0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80,
@@ -1650,287 +1649,3 @@ static const unsigned char frame_buffer[128 * (96 + 1) * 2] = {
0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80,
0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80,
};
-#else
-
-#define color_bar_0_jpg_len 511
-#define color_bar_1_jpg_len 512
-#define color_bar_2_jpg_len 511
-#define color_bar_3_jpg_len 511
-#define color_bar_4_jpg_len 511
-#define color_bar_5_jpg_len 512
-#define color_bar_6_jpg_len 511
-#define color_bar_7_jpg_len 511
-
-unsigned char color_bar_0_jpg[] = {
- 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x11,
- 0x08, 0x00, 0x60, 0x00, 0x80, 0x03, 0x01, 0x21, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff,
- 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x92, 0x8a, 0x00,
- 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45,
- 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89,
- 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad,
- 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25,
- 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3,
- 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1,
- 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00,
- 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45,
- 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89,
- 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad,
- 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25,
- 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3,
- 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1,
- 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00,
- 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45,
- 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89,
- 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad,
- 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25,
- 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3,
- 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1,
- 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0xff, 0xd9
-};
-unsigned char color_bar_1_jpg[] = {
- 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x11,
- 0x08, 0x00, 0x60, 0x00, 0x80, 0x03, 0x01, 0x21, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff,
- 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x7d, 0x15, 0x98,
- 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94,
- 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32,
- 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51,
- 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63,
- 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45,
- 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84,
- 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98,
- 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94,
- 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32,
- 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51,
- 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63,
- 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45,
- 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84,
- 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98,
- 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94,
- 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32,
- 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51,
- 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63,
- 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45,
- 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84,
- 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x7f, 0xff, 0xd9
-};
-unsigned char color_bar_2_jpg[] = {
- 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x11,
- 0x08, 0x00, 0x60, 0x00, 0x80, 0x03, 0x01, 0x21, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff,
- 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x75, 0x14, 0xcc,
- 0xc4, 0xa2, 0xb3, 0x18, 0xda, 0x2b, 0x63, 0x61, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94,
- 0x56, 0x63, 0x2c, 0x51, 0x40, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x18,
- 0xda, 0x2b, 0x63, 0x61, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x2c, 0x51,
- 0x40, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x18, 0xda, 0x2b, 0x63, 0x61,
- 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x2c, 0x51, 0x40, 0x09, 0x45, 0x66,
- 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x18, 0xda, 0x2b, 0x63, 0x61, 0x28, 0xac, 0xc6, 0x25,
- 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x2c, 0x51, 0x40, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c,
- 0x84, 0xa2, 0xb3, 0x18, 0xda, 0x2b, 0x63, 0x61, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94,
- 0x56, 0x63, 0x2c, 0x51, 0x40, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x18,
- 0xda, 0x2b, 0x63, 0x61, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x2c, 0x51,
- 0x40, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x18, 0xda, 0x2b, 0x63, 0x61,
- 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x2c, 0x51, 0x40, 0x09, 0x45, 0x66,
- 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x18, 0xda, 0x2b, 0x63, 0x61, 0x28, 0xac, 0xc6, 0x25,
- 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x2c, 0x51, 0x40, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c,
- 0x84, 0xa2, 0xb3, 0x18, 0xda, 0x2b, 0x63, 0x61, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94,
- 0x56, 0x63, 0x2c, 0x51, 0x40, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x18,
- 0xda, 0x2b, 0x63, 0x61, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x2c, 0x51,
- 0x40, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x18, 0xda, 0x2b, 0x63, 0x61,
- 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x2c, 0x51, 0x40, 0x09, 0x45, 0x66,
- 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x18, 0xda, 0x2b, 0x63, 0x61, 0x28, 0xac, 0xc6, 0x25,
- 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x2c, 0x51, 0x40, 0x09, 0x45, 0x66, 0x33, 0xff, 0xd9
-};
-unsigned char color_bar_3_jpg[] = {
- 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x11,
- 0x08, 0x00, 0x60, 0x00, 0x80, 0x03, 0x01, 0x21, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff,
- 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x5a, 0x2a, 0x08,
- 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a,
- 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c,
- 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac,
- 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4,
- 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9,
- 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12,
- 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63,
- 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a,
- 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c,
- 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac,
- 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4,
- 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9,
- 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12,
- 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63,
- 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a,
- 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c,
- 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac,
- 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4,
- 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9,
- 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12,
- 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x91, 0xff, 0xd9
-};
-unsigned char color_bar_4_jpg[] = {
- 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x11,
- 0x08, 0x00, 0x60, 0x00, 0x80, 0x03, 0x01, 0x21, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff,
- 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x4a, 0x2a, 0xcb,
- 0x12, 0x8a, 0xcc, 0x62, 0x51, 0x5a, 0x99, 0x09, 0x45, 0x66, 0x32, 0xc5, 0x14, 0x00, 0x94, 0x56,
- 0x63, 0x12, 0x8a, 0xd4, 0xc8, 0x4a, 0x2b, 0x31, 0x8d, 0xa2, 0xb6, 0x36, 0x12, 0x8a, 0xcc, 0x62,
- 0x51, 0x5a, 0x99, 0x09, 0x45, 0x66, 0x32, 0xc5, 0x14, 0x00, 0x94, 0x56, 0x63, 0x12, 0x8a, 0xd4,
- 0xc8, 0x4a, 0x2b, 0x31, 0x8d, 0xa2, 0xb6, 0x36, 0x12, 0x8a, 0xcc, 0x62, 0x51, 0x5a, 0x99, 0x09,
- 0x45, 0x66, 0x32, 0xc5, 0x14, 0x00, 0x94, 0x56, 0x63, 0x12, 0x8a, 0xd4, 0xc8, 0x4a, 0x2b, 0x31,
- 0x8d, 0xa2, 0xb6, 0x36, 0x12, 0x8a, 0xcc, 0x62, 0x51, 0x5a, 0x99, 0x09, 0x45, 0x66, 0x32, 0xc5,
- 0x14, 0x00, 0x94, 0x56, 0x63, 0x12, 0x8a, 0xd4, 0xc8, 0x4a, 0x2b, 0x31, 0x8d, 0xa2, 0xb6, 0x36,
- 0x12, 0x8a, 0xcc, 0x62, 0x51, 0x5a, 0x99, 0x09, 0x45, 0x66, 0x32, 0xc5, 0x14, 0x00, 0x94, 0x56,
- 0x63, 0x12, 0x8a, 0xd4, 0xc8, 0x4a, 0x2b, 0x31, 0x8d, 0xa2, 0xb6, 0x36, 0x12, 0x8a, 0xcc, 0x62,
- 0x51, 0x5a, 0x99, 0x09, 0x45, 0x66, 0x32, 0xc5, 0x14, 0x00, 0x94, 0x56, 0x63, 0x12, 0x8a, 0xd4,
- 0xc8, 0x4a, 0x2b, 0x31, 0x8d, 0xa2, 0xb6, 0x36, 0x12, 0x8a, 0xcc, 0x62, 0x51, 0x5a, 0x99, 0x09,
- 0x45, 0x66, 0x32, 0xc5, 0x14, 0x00, 0x94, 0x56, 0x63, 0x12, 0x8a, 0xd4, 0xc8, 0x4a, 0x2b, 0x31,
- 0x8d, 0xa2, 0xb6, 0x36, 0x12, 0x8a, 0xcc, 0x62, 0x51, 0x5a, 0x99, 0x09, 0x45, 0x66, 0x32, 0xc5,
- 0x14, 0x00, 0x94, 0x56, 0x63, 0x12, 0x8a, 0xd4, 0xc8, 0x4a, 0x2b, 0x31, 0x8d, 0xa2, 0xb6, 0x36,
- 0x12, 0x8a, 0xcc, 0x62, 0x51, 0x5a, 0x99, 0x09, 0x45, 0x66, 0x32, 0xc5, 0x14, 0x00, 0x94, 0x56,
- 0x63, 0x12, 0x8a, 0xd4, 0xc8, 0x4a, 0x2b, 0x31, 0x8d, 0xa2, 0xb6, 0x36, 0x12, 0x8a, 0xcc, 0x62,
- 0x51, 0x5a, 0x99, 0x09, 0x45, 0x66, 0x32, 0xc5, 0x14, 0x00, 0x94, 0x56, 0x63, 0x12, 0x8a, 0xd4,
- 0xc8, 0x4a, 0x2b, 0x31, 0x8d, 0xa2, 0xb6, 0x36, 0x12, 0x8a, 0xcc, 0x62, 0x51, 0x5a, 0x99, 0x09,
- 0x45, 0x66, 0x32, 0xc5, 0x14, 0x00, 0x94, 0x56, 0x63, 0x12, 0x8a, 0xd4, 0xc8, 0x4a, 0x2b, 0x31,
- 0x8d, 0xa2, 0xb6, 0x36, 0x12, 0x8a, 0xcc, 0x62, 0x51, 0x5a, 0x99, 0x09, 0x45, 0x66, 0x32, 0xc5,
- 0x14, 0x00, 0x94, 0x56, 0x63, 0x12, 0x8a, 0xd4, 0xc8, 0x4a, 0x2b, 0x31, 0x9f, 0xff, 0xd9
-};
-unsigned char color_bar_5_jpg[] = {
- 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x11,
- 0x08, 0x00, 0x60, 0x00, 0x80, 0x03, 0x01, 0x21, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff,
- 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x6d, 0x14, 0x8d,
- 0x04, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15,
- 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32,
- 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56,
- 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65,
- 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c,
- 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28,
- 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98,
- 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15,
- 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32,
- 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56,
- 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65,
- 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c,
- 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28,
- 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98,
- 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15,
- 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32,
- 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56,
- 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65,
- 0x8a, 0x28, 0x01, 0x28, 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c,
- 0x6c, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x65, 0x8a, 0x28, 0x01, 0x28,
- 0xac, 0xc6, 0x25, 0x15, 0xa9, 0x90, 0x94, 0x56, 0x63, 0x1b, 0x45, 0x6c, 0x6c, 0x7f, 0xff, 0xd9
-};
-unsigned char color_bar_6_jpg[] = {
- 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x11,
- 0x08, 0x00, 0x60, 0x00, 0x80, 0x03, 0x01, 0x21, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff,
- 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x65, 0x15, 0xa0,
- 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15,
- 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19,
- 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b,
- 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a,
- 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66,
- 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45,
- 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c,
- 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15,
- 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19,
- 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b,
- 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a,
- 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66,
- 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45,
- 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c,
- 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15,
- 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19,
- 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b,
- 0x1b, 0x09, 0x45, 0x66, 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a,
- 0x2b, 0x31, 0x89, 0x45, 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66,
- 0x31, 0x28, 0xad, 0x4c, 0x84, 0xa2, 0xb3, 0x19, 0x62, 0x8a, 0x00, 0x4a, 0x2b, 0x31, 0x89, 0x45,
- 0x6a, 0x64, 0x25, 0x15, 0x98, 0xc6, 0xd1, 0x5b, 0x1b, 0x09, 0x45, 0x66, 0x33, 0xff, 0xd9
-};
-unsigned char color_bar_7_jpg[] = {
- 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0x00, 0x43, 0x01, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x11,
- 0x08, 0x00, 0x60, 0x00, 0x80, 0x03, 0x01, 0x21, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff,
- 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x8e, 0x8a, 0x00,
- 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad,
- 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25,
- 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3,
- 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2,
- 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6,
- 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a,
- 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c,
- 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad,
- 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25,
- 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3,
- 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2,
- 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6,
- 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a,
- 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c,
- 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad,
- 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25,
- 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3,
- 0x18, 0x94, 0x56, 0xa6, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2,
- 0xb5, 0x32, 0x12, 0x8a, 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6,
- 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a,
- 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x47, 0xff, 0xd9
-};
-#endif
diff --git a/examples/device/video_capture/src/main.c b/examples/device/video_capture/src/main.c
index c653761c1..a2d95c8f9 100644
--- a/examples/device/video_capture/src/main.c
+++ b/examples/device/video_capture/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -27,7 +27,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -55,13 +55,7 @@ void video_task(void);
int main(void)
{
board_init();
-
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
@@ -70,6 +64,8 @@ int main(void)
video_task();
}
+
+ return 0;
}
//--------------------------------------------------------------------+
@@ -100,7 +96,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
@@ -114,23 +110,6 @@ static unsigned interval_ms = 1000 / FRAME_RATE;
/* YUY2 frame buffer */
#ifdef CFG_EXAMPLE_VIDEO_READONLY
#include "images.h"
-
-# if !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPG)
-static struct {
- uint32_t size;
- uint8_t const *buffer;
-} const frames[] = {
- {color_bar_0_jpg_len, color_bar_0_jpg},
- {color_bar_1_jpg_len, color_bar_1_jpg},
- {color_bar_2_jpg_len, color_bar_2_jpg},
- {color_bar_3_jpg_len, color_bar_3_jpg},
- {color_bar_4_jpg_len, color_bar_4_jpg},
- {color_bar_5_jpg_len, color_bar_5_jpg},
- {color_bar_6_jpg_len, color_bar_6_jpg},
- {color_bar_7_jpg_len, color_bar_7_jpg},
-};
-# endif
-
#else
static uint8_t frame_buffer[FRAME_WIDTH * FRAME_HEIGHT * 16 / 8];
static void fill_color_bar(uint8_t *buffer, unsigned start_position)
@@ -187,12 +166,8 @@ void video_task(void)
already_sent = 1;
start_ms = board_millis();
#ifdef CFG_EXAMPLE_VIDEO_READONLY
-# if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPG)
- tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
+ tud_video_n_frame_xfer(0, 0, (void*)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
FRAME_WIDTH * FRAME_HEIGHT * 16/8);
-# else
- tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)frames[frame_num % 8].buffer, frames[frame_num % 8].size);
-# endif
#else
fill_color_bar(frame_buffer, frame_num);
tud_video_n_frame_xfer(0, 0, (void*)frame_buffer, FRAME_WIDTH * FRAME_HEIGHT * 16/8);
@@ -205,12 +180,8 @@ void video_task(void)
start_ms += interval_ms;
#ifdef CFG_EXAMPLE_VIDEO_READONLY
-# if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPG)
- tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
+ tud_video_n_frame_xfer(0, 0, (void*)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
FRAME_WIDTH * FRAME_HEIGHT * 16/8);
-# else
- tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)frames[frame_num % 8].buffer, frames[frame_num % 8].size);
-# endif
#else
fill_color_bar(frame_buffer, frame_num);
tud_video_n_frame_xfer(0, 0, (void*)frame_buffer, FRAME_WIDTH * FRAME_HEIGHT * 16/8);
diff --git a/examples/device/video_capture/src/tusb_config.h b/examples/device/video_capture/src/tusb_config.h
index 274bf2b9c..4feb6a48a 100644
--- a/examples/device/video_capture/src/tusb_config.h
+++ b/examples/device/video_capture/src/tusb_config.h
@@ -30,42 +30,42 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
+//--------------------------------------------------------------------
+// COMMON CONFIGURATION
+//--------------------------------------------------------------------
// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
#endif
// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
#endif
-//--------------------------------------------------------------------
-// Common Configuration
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
+// This example doesn't use an RTOS
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -79,7 +79,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
@@ -100,9 +100,6 @@
// video streaming endpoint size
#define CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE 256
-// use bulk endpoint for streaming interface
-#define CFG_TUD_VIDEO_STREAMING_BULK 0
-
#ifdef __cplusplus
}
#endif
diff --git a/examples/device/video_capture/src/usb_descriptors.c b/examples/device/video_capture/src/usb_descriptors.c
index 292d86cd9..404ffe070 100644
--- a/examples/device/video_capture/src/usb_descriptors.c
+++ b/examples/device/video_capture/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -76,30 +75,14 @@ uint8_t const * tud_descriptor_device_cb(void)
// Configuration Descriptor
//--------------------------------------------------------------------+
-#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
-# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
-# define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_VIDEO_CAPTURE_DESC_MJPEG_BULK_LEN)
-# else
-# define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_VIDEO_CAPTURE_DESC_MJPEG_LEN)
-# endif
-#else
-# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
-# define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_VIDEO_CAPTURE_DESC_UNCOMPR_BULK_LEN)
-# else
-# define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_VIDEO_CAPTURE_DESC_UNCOMPR_LEN)
-# endif
-#endif
+#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_VIDEO_CAPTURE_DESC_LEN)
-#if TU_CHECK_MCU(OPT_MCU_LPC175X_6X, OPT_MCU_LPC177X_8X, OPT_MCU_LPC40XX)
+#if TU_CHECK_MCU(LPC175X_6X) || TU_CHECK_MCU(LPC177X_8X) || TU_CHECK_MCU(LPC40XX)
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
// 0 control, 1 In, 2 Bulk, 3 Iso, 4 In, 5 Bulk etc ...
-#if 1 == CFG_TUD_VIDEO_STREAMING_BULK
- #define EPNUM_VIDEO_IN 0x82
-#else
#define EPNUM_VIDEO_IN 0x83
-#endif
-#elif TU_CHECK_MCU(OPT_MCU_NRF5X)
+#elif TU_CHECK_MCU(NRF5X)
// nRF5x ISO can only be endpoint 8
#define EPNUM_VIDEO_IN 0x88
@@ -112,29 +95,10 @@ uint8_t const desc_fs_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0, 500),
-
// IAD for Video Control
-#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
-# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
- TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG_BULK(4, EPNUM_VIDEO_IN,
- FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
- 64)
-# else
- TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG(4, EPNUM_VIDEO_IN,
- FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
- CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
-# endif
-#else
-# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
- TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR_BULK(4, EPNUM_VIDEO_IN,
- FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
- 64)
-# else
- TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR(4, EPNUM_VIDEO_IN,
- FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
- CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
-# endif
-#endif
+ TUD_VIDEO_CAPTURE_DESCRIPTOR(4, EPNUM_VIDEO_IN,
+ FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
+ CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
};
// Invoked when received GET CONFIGURATION DESCRIPTOR
@@ -151,64 +115,52 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
"TinyUSB UVC", // 4: UVC Interface
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
# Example source
@@ -28,6 +23,6 @@ target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_device_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/device/webusb_serial/Makefile b/examples/device/webusb_serial/Makefile
index 2a3d854fb..5a455078e 100644
--- a/examples/device/webusb_serial/Makefile
+++ b/examples/device/webusb_serial/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
diff --git a/examples/device/webusb_serial/src/main.c b/examples/device/webusb_serial/src/main.c
index 800d435b8..aba4aedff 100644
--- a/examples/device/webusb_serial/src/main.c
+++ b/examples/device/webusb_serial/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -47,7 +47,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -71,7 +71,7 @@ enum {
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
-#define URL "example.tinyusb.org/webusb-serial/index.html"
+#define URL "example.tinyusb.org/webusb-serial/"
const tusb_desc_webusb_url_t desc_url =
{
@@ -93,12 +93,7 @@ int main(void)
{
board_init();
- // init device stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
@@ -107,6 +102,8 @@ int main(void)
webserial_task();
led_blinking_task();
}
+
+ return 0;
}
// send characters to both CDC and WebUSB
@@ -116,7 +113,6 @@ void echo_all(uint8_t buf[], uint32_t count)
if ( web_serial_connected )
{
tud_vendor_write(buf, count);
- tud_vendor_write_flush();
}
// echo to cdc
@@ -160,7 +156,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
+ blink_interval_ms = BLINK_MOUNTED;
}
//--------------------------------------------------------------------+
@@ -183,7 +179,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
case VENDOR_REQUEST_WEBUSB:
// match vendor request in BOS descriptor
// Get landing page url
- return tud_control_xfer(rhport, request, (void*)(uintptr_t) &desc_url, desc_url.bLength);
+ return tud_control_xfer(rhport, request, (void*) &desc_url, desc_url.bLength);
case VENDOR_REQUEST_MICROSOFT:
if ( request->wIndex == 7 )
@@ -192,7 +188,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
uint16_t total_len;
memcpy(&total_len, desc_ms_os_20+8, 2);
- return tud_control_xfer(rhport, request, (void*)(uintptr_t) desc_ms_os_20, total_len);
+ return tud_control_xfer(rhport, request, (void*) desc_ms_os_20, total_len);
}else
{
return false;
@@ -214,8 +210,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
board_led_write(true);
blink_interval_ms = BLINK_ALWAYS_ON;
- tud_vendor_write_str("\r\nWebUSB interface connected\r\n");
- tud_vendor_write_flush();
+ tud_vendor_write_str("\r\nTinyUSB WebUSB device example\r\n");
}else
{
blink_interval_ms = BLINK_MOUNTED;
diff --git a/examples/device/webusb_serial/src/tusb_config.h b/examples/device/webusb_serial/src/tusb_config.h
index fde732b9e..26b81b389 100644
--- a/examples/device/webusb_serial/src/tusb_config.h
+++ b/examples/device/webusb_serial/src/tusb_config.h
@@ -30,42 +30,46 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
+//--------------------------------------------------------------------
+// COMMON CONFIGURATION
+//--------------------------------------------------------------------
+
+// defined by board.mk
+#ifndef CFG_TUSB_MCU
+ #error CFG_TUSB_MCU must be defined
+#endif
// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
+#ifndef BOARD_DEVICE_RHPORT_NUM
+ #define BOARD_DEVICE_RHPORT_NUM 0
#endif
// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
+// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
+#ifndef BOARD_DEVICE_RHPORT_SPEED
+ #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
+ CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
+ #else
+ #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
+ #endif
#endif
-//--------------------------------------------------------------------
-// Common Configuration
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+// Device mode with rhport and speed defined by board.mk
+#if BOARD_DEVICE_RHPORT_NUM == 0
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#elif BOARD_DEVICE_RHPORT_NUM == 1
+ #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
+#else
+ #error "Incorrect RHPort configuration"
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack
-#define CFG_TUD_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -79,7 +83,7 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
-#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
diff --git a/examples/device/webusb_serial/src/usb_descriptors.c b/examples/device/webusb_serial/src/usb_descriptors.c
index b01fae8e3..93e802a90 100644
--- a/examples/device/webusb_serial/src/usb_descriptors.c
+++ b/examples/device/webusb_serial/src/usb_descriptors.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -23,7 +23,6 @@
*
*/
-#include "bsp/board_api.h"
#include "tusb.h"
#include "usb_descriptors.h"
@@ -98,13 +97,6 @@ enum
#define EPNUM_CDC_OUT 3
#define EPNUM_VENDOR_IN 4
#define EPNUM_VENDOR_OUT 5
-#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
- // FT9XX doesn't support a same endpoint number with different direction IN and OUT
- // e.g EP1 OUT & EP1 IN cannot exist together
- #define EPNUM_CDC_IN 2
- #define EPNUM_CDC_OUT 3
- #define EPNUM_VENDOR_IN 4
- #define EPNUM_VENDOR_OUT 5
#else
#define EPNUM_CDC_IN 2
#define EPNUM_CDC_OUT 2
@@ -208,65 +200,53 @@ TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size");
// String Descriptors
//--------------------------------------------------------------------+
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+ "123456", // 3: Serials, should use chip ID
"TinyUSB CDC", // 4: CDC Interface
"TinyUSB WebUSB" // 5: Vendor Interface
};
-static uint16_t _desc_str[32 + 1];
+static uint16_t _desc_str[32];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
(void) langid;
- size_t chr_count;
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
+ uint8_t chr_count;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ if ( index == 0)
+ {
+ memcpy(&_desc_str[1], string_desc_arr[0], 2);
+ chr_count = 1;
+ }else
+ {
+ // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
+ // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
+ if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ const char* str = string_desc_arr[index];
- const char *str = string_desc_arr[index];
+ // Cap at max char
+ chr_count = strlen(str);
+ if ( chr_count > 31 ) chr_count = 31;
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
+ // Convert ASCII string into UTF-16
+ for(uint8_t i=0; i-)
-family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-
-project(${PROJECT} C CXX ASM)
-
-# Checks this example is valid for the family and initializes the project
-family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-
-add_executable(${PROJECT})
-
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- )
-
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
-
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_dual_usb_example(${PROJECT} noos)
-
-# due to warnings from Pico-PIO-USB
-target_compile_options(${PROJECT} PUBLIC
- -Wno-error=shadow
- -Wno-error=cast-align
- -Wno-error=cast-qual
- -Wno-error=redundant-decls
- -Wno-error=sign-conversion
- -Wno-error=conversion
- -Wno-error=sign-compare
- -Wno-error=unused-function
- )
diff --git a/examples/dual/host_hid_to_device_cdc/Makefile b/examples/dual/host_hid_to_device_cdc/Makefile
deleted file mode 100644
index 95c88e7e8..000000000
--- a/examples/dual/host_hid_to_device_cdc/Makefile
+++ /dev/null
@@ -1,18 +0,0 @@
-include ../../make.mk
-
-INC += \
- src \
- $(TOP)/hw \
-
-# Example source
-EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
-
-CFLAGS += -Wno-error=cast-align -Wno-error=null-dereference
-
-SRC_C += \
- src/class/hid/hid_host.c \
- src/host/hub.c \
- src/host/usbh.c
-
-include ../../rules.mk
diff --git a/examples/dual/host_hid_to_device_cdc/only.txt b/examples/dual/host_hid_to_device_cdc/only.txt
deleted file mode 100644
index cfc87eb4e..000000000
--- a/examples/dual/host_hid_to_device_cdc/only.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-board:mimxrt1060_evk
-board:mimxrt1064_evk
-board:mcb1800
-mcu:RP2040
-mcu:ra6m5
-mcu:MAX3421
diff --git a/examples/dual/host_hid_to_device_cdc/src/main.c b/examples/dual/host_hid_to_device_cdc/src/main.c
deleted file mode 100644
index 96a2beff5..000000000
--- a/examples/dual/host_hid_to_device_cdc/src/main.c
+++ /dev/null
@@ -1,302 +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.
- *
- */
-
-// This example runs both host and device concurrently. The USB host receive
-// reports from HID device and print it out over USB Device CDC interface.
-
-#include
-#include
-#include
-
-#include "bsp/board_api.h"
-#include "tusb.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF PROTYPES
-//--------------------------------------------------------------------+
-
-// uncomment if you are using colemak layout
-// #define KEYBOARD_COLEMAK
-
-#ifdef KEYBOARD_COLEMAK
-const uint8_t colemak[128] = {
- 0 , 0, 0, 0, 0, 0, 0, 22,
- 9 , 23, 7, 0, 24, 17, 8, 12,
- 0 , 14, 28, 51, 0, 19, 21, 10,
- 15 , 0, 0, 0, 13, 0, 0, 0,
- 0 , 0, 0, 0, 0, 0, 0, 0,
- 0 , 0, 0, 0, 0, 0, 0, 0,
- 0 , 0, 0, 18, 0, 0, 0, 0,
- 0 , 0, 0, 0, 0, 0, 0, 0,
- 0 , 0, 0, 0, 0, 0, 0, 0,
- 0 , 0, 0, 0, 0, 0, 0, 0
-};
-#endif
-
-static uint8_t const keycode2ascii[128][2] = { HID_KEYCODE_TO_ASCII };
-
-/* Blink pattern
- * - 250 ms : device not mounted
- * - 1000 ms : device mounted
- * - 2500 ms : device is suspended
- */
-enum {
- BLINK_NOT_MOUNTED = 250,
- BLINK_MOUNTED = 1000,
- BLINK_SUSPENDED = 2500,
-};
-
-static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
-
-void led_blinking_task(void);
-
-/*------------- MAIN -------------*/
-int main(void)
-{
- board_init();
-
- printf("TinyUSB Host HID <-> Device CDC Example\r\n");
-
- // init device and host stack on configured roothub port
- tud_init(BOARD_TUD_RHPORT);
- tuh_init(BOARD_TUH_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
-
- while (1)
- {
- tud_task(); // tinyusb device task
- tuh_task(); // tinyusb host task
- led_blinking_task();
- }
-
- return 0;
-}
-
-//--------------------------------------------------------------------+
-// Device CDC
-//--------------------------------------------------------------------+
-
-// Invoked when device is mounted
-void tud_mount_cb(void)
-{
- blink_interval_ms = BLINK_MOUNTED;
-}
-
-// Invoked when device is unmounted
-void tud_umount_cb(void)
-{
- blink_interval_ms = BLINK_NOT_MOUNTED;
-}
-
-// Invoked when usb bus is suspended
-// remote_wakeup_en : if host allow us to perform remote wakeup
-// Within 7ms, device must draw an average of current less than 2.5 mA from bus
-void tud_suspend_cb(bool remote_wakeup_en)
-{
- (void) remote_wakeup_en;
- blink_interval_ms = BLINK_SUSPENDED;
-}
-
-// Invoked when usb bus is resumed
-void tud_resume_cb(void)
-{
- blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
-}
-
-// Invoked when CDC interface received data from host
-void tud_cdc_rx_cb(uint8_t itf)
-{
- (void) itf;
-
- char buf[64];
- uint32_t count = tud_cdc_read(buf, sizeof(buf));
-
- // TODO control LED on keyboard of host stack
- (void) count;
-}
-
-//--------------------------------------------------------------------+
-// Host HID
-//--------------------------------------------------------------------+
-
-// Invoked when device with hid interface is mounted
-// Report descriptor is also available for use. tuh_hid_parse_report_descriptor()
-// can be used to parse common/simple enough descriptor.
-// Note: if report descriptor length > CFG_TUH_ENUMERATION_BUFSIZE, it will be skipped
-// therefore report_desc = NULL, desc_len = 0
-void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len)
-{
- (void)desc_report;
- (void)desc_len;
-
- // Interface protocol (hid_interface_protocol_enum_t)
- const char* protocol_str[] = { "None", "Keyboard", "Mouse" };
- uint8_t const itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);
-
- uint16_t vid, pid;
- tuh_vid_pid_get(dev_addr, &vid, &pid);
-
- char tempbuf[256];
- int count = sprintf(tempbuf, "[%04x:%04x][%u] HID Interface%u, Protocol = %s\r\n", vid, pid, dev_addr, instance, protocol_str[itf_protocol]);
-
- tud_cdc_write(tempbuf, (uint32_t) count);
- tud_cdc_write_flush();
-
- // Receive report from boot keyboard & mouse only
- // tuh_hid_report_received_cb() will be invoked when report is available
- if (itf_protocol == HID_ITF_PROTOCOL_KEYBOARD || itf_protocol == HID_ITF_PROTOCOL_MOUSE)
- {
- if ( !tuh_hid_receive_report(dev_addr, instance) )
- {
- tud_cdc_write_str("Error: cannot request report\r\n");
- }
- }
-}
-
-// Invoked when device with hid interface is un-mounted
-void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance)
-{
- char tempbuf[256];
- int count = sprintf(tempbuf, "[%u] HID Interface%u is unmounted\r\n", dev_addr, instance);
- tud_cdc_write(tempbuf, (uint32_t) count);
- tud_cdc_write_flush();
-}
-
-// look up new key in previous keys
-static inline bool find_key_in_report(hid_keyboard_report_t const *report, uint8_t keycode)
-{
- for(uint8_t i=0; i<6; i++)
- {
- if (report->keycode[i] == keycode) return true;
- }
-
- return false;
-}
-
-
-// convert hid keycode to ascii and print via usb device CDC (ignore non-printable)
-static void process_kbd_report(uint8_t dev_addr, hid_keyboard_report_t const *report)
-{
- (void) dev_addr;
- static hid_keyboard_report_t prev_report = { 0, 0, {0} }; // previous report to check key released
- bool flush = false;
-
- for(uint8_t i=0; i<6; i++)
- {
- uint8_t keycode = report->keycode[i];
- if ( keycode )
- {
- if ( find_key_in_report(&prev_report, keycode) )
- {
- // exist in previous report means the current key is holding
- }else
- {
- // not existed in previous report means the current key is pressed
-
- // remap the key code for Colemak layout
- #ifdef KEYBOARD_COLEMAK
- uint8_t colemak_key_code = colemak[keycode];
- if (colemak_key_code != 0) keycode = colemak_key_code;
- #endif
-
- bool const is_shift = report->modifier & (KEYBOARD_MODIFIER_LEFTSHIFT | KEYBOARD_MODIFIER_RIGHTSHIFT);
- uint8_t ch = keycode2ascii[keycode][is_shift ? 1 : 0];
-
- if (ch)
- {
- if (ch == '\n') tud_cdc_write("\r", 1);
- tud_cdc_write(&ch, 1);
- flush = true;
- }
- }
- }
- // TODO example skips key released
- }
-
- if (flush) tud_cdc_write_flush();
-
- prev_report = *report;
-}
-
-// send mouse report to usb device CDC
-static void process_mouse_report(uint8_t dev_addr, hid_mouse_report_t const * report)
-{
- //------------- button state -------------//
- //uint8_t button_changed_mask = report->buttons ^ prev_report.buttons;
- char l = report->buttons & MOUSE_BUTTON_LEFT ? 'L' : '-';
- char m = report->buttons & MOUSE_BUTTON_MIDDLE ? 'M' : '-';
- char r = report->buttons & MOUSE_BUTTON_RIGHT ? 'R' : '-';
-
- char tempbuf[32];
- int count = sprintf(tempbuf, "[%u] %c%c%c %d %d %d\r\n", dev_addr, l, m, r, report->x, report->y, report->wheel);
-
- tud_cdc_write(tempbuf, (uint32_t) count);
- tud_cdc_write_flush();
-}
-
-// Invoked when received report from device via interrupt endpoint
-void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len)
-{
- (void) len;
- uint8_t const itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);
-
- switch(itf_protocol)
- {
- case HID_ITF_PROTOCOL_KEYBOARD:
- process_kbd_report(dev_addr, (hid_keyboard_report_t const*) report );
- break;
-
- case HID_ITF_PROTOCOL_MOUSE:
- process_mouse_report(dev_addr, (hid_mouse_report_t const*) report );
- break;
-
- default: break;
- }
-
- // continue to request to receive report
- if ( !tuh_hid_receive_report(dev_addr, instance) )
- {
- tud_cdc_write_str("Error: cannot request report\r\n");
- }
-}
-
-//--------------------------------------------------------------------+
-// Blinking Task
-//--------------------------------------------------------------------+
-void led_blinking_task(void)
-{
- static uint32_t start_ms = 0;
- static bool led_state = false;
-
- // Blink every interval ms
- if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
- start_ms += blink_interval_ms;
-
- board_led_write(led_state);
- led_state = 1 - led_state; // toggle
-}
diff --git a/examples/dual/host_hid_to_device_cdc/src/tusb_config.h b/examples/dual/host_hid_to_device_cdc/src/tusb_config.h
deleted file mode 100644
index 8133ed418..000000000
--- a/examples/dual/host_hid_to_device_cdc/src/tusb_config.h
+++ /dev/null
@@ -1,147 +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 _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-// RHPort number used for device can be defined by board.mk, default to port 0
-#ifndef BOARD_TUD_RHPORT
-#define BOARD_TUD_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUD_MAX_SPEED
-#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
-// RHPort number used for host can be defined by board.mk, default to port 1
-#ifndef BOARD_TUH_RHPORT
-#define BOARD_TUH_RHPORT 1
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUH_MAX_SPEED
-#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
-//--------------------------------------------------------------------
-// COMMON CONFIGURATION
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
-#endif
-
-#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
-#endif
-
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Device stack, Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUD_ENABLED 1
-#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
-
-// Enable Host stack, Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUH_ENABLED 1
-#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED
-
-#if CFG_TUSB_MCU == OPT_MCU_RP2040
-// Use pico-pio-usb as host controller for raspberry rp2040
-#define CFG_TUH_RPI_PIO_USB 1
-#endif
-
-/* 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_TUD_MEM_SECTION
-#define CFG_TUD_MEM_SECTION
-#endif
-
-#ifndef CFG_TUD_MEM_ALIGN
-#define CFG_TUD_MEM_ALIGN __attribute__ ((aligned(4)))
-#endif
-
-//--------------------------------------------------------------------
-// DEVICE CONFIGURATION
-//--------------------------------------------------------------------
-
-#ifndef CFG_TUD_ENDPOINT0_SIZE
-#define CFG_TUD_ENDPOINT0_SIZE 64
-#endif
-
-//------------- CLASS -------------//
-#define CFG_TUD_CDC 1
-
-// CDC FIFO size of TX and RX
-#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
-#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
-
-// CDC Endpoint transfer buffer size, more is faster
-#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
-
-//--------------------------------------------------------------------
-// HOST CONFIGURATION
-//--------------------------------------------------------------------
-
-// Size of buffer to hold descriptors and other data used for enumeration
-#define CFG_TUH_ENUMERATION_BUFSIZE 256
-
-#ifndef CFG_TUH_MEM_SECTION
-#define CFG_TUH_MEM_SECTION
-#endif
-
-#ifndef CFG_TUH_MEM_ALIGN
-#define CFG_TUH_MEM_ALIGN __attribute__ ((aligned(4)))
-#endif
-
-#define CFG_TUH_HUB 1
-// max device support (excluding hub device)
-#define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1) // hub typically has 4 ports
-
-#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX)
-#define CFG_TUH_HID_EPIN_BUFSIZE 64
-#define CFG_TUH_HID_EPOUT_BUFSIZE 64
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_CONFIG_H_ */
diff --git a/examples/dual/host_hid_to_device_cdc/src/usb_descriptors.c b/examples/dual/host_hid_to_device_cdc/src/usb_descriptors.c
deleted file mode 100644
index 293620042..000000000
--- a/examples/dual/host_hid_to_device_cdc/src/usb_descriptors.c
+++ /dev/null
@@ -1,278 +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.
- *
- */
-
-#include "bsp/board_api.h"
-#include "tusb.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.
- *
- * Auto ProductID layout's Bitmap:
- * [MSB] HID | MSC | CDC [LSB]
- */
-#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
-#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
- _PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )
-
-#define USB_VID 0xCafe
-#define USB_BCD 0x0200
-
-//--------------------------------------------------------------------+
-// Device Descriptors
-//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
-{
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
- .bcdUSB = USB_BCD,
-
- // 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,
-
- .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
-
- .idVendor = USB_VID,
- .idProduct = USB_PID,
- .bcdDevice = 0x0100,
-
- .iManufacturer = 0x01,
- .iProduct = 0x02,
- .iSerialNumber = 0x03,
-
- .bNumConfigurations = 0x01
-};
-
-// Invoked when received GET DEVICE DESCRIPTOR
-// Application return pointer to descriptor
-uint8_t const * tud_descriptor_device_cb(void)
-{
- return (uint8_t const *) &desc_device;
-}
-
-//--------------------------------------------------------------------+
-// Configuration Descriptor
-//--------------------------------------------------------------------+
-
-enum
-{
- ITF_NUM_CDC = 0,
- ITF_NUM_CDC_DATA,
- ITF_NUM_TOTAL
-};
-
-#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
- // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
- // 0 control, 1 In, 2 Bulk, 3 Iso, 4 In, 5 Bulk etc ...
- #define EPNUM_CDC_NOTIF 0x81
- #define EPNUM_CDC_OUT 0x02
- #define EPNUM_CDC_IN 0x82
-
-#elif CFG_TUSB_MCU == OPT_MCU_SAMG || CFG_TUSB_MCU == OPT_MCU_SAMX7X
- // SAMG & SAME70 don't support a same endpoint number with different direction IN and OUT
- // e.g EP1 OUT & EP1 IN cannot exist together
- #define EPNUM_CDC_NOTIF 0x81
- #define EPNUM_CDC_OUT 0x02
- #define EPNUM_CDC_IN 0x83
-
-#elif CFG_TUSB_MCU == OPT_MCU_CXD56
- // CXD56 doesn't support a same endpoint number with different direction IN and OUT
- // e.g EP1 OUT & EP1 IN cannot exist together
- // CXD56 USB driver has fixed endpoint type (bulk/interrupt/iso) and direction (IN/OUT) by its number
- // 0 control (IN/OUT), 1 Bulk (IN), 2 Bulk (OUT), 3 In (IN), 4 Bulk (IN), 5 Bulk (OUT), 6 In (IN)
- #define EPNUM_CDC_NOTIF 0x83
- #define EPNUM_CDC_OUT 0x02
- #define EPNUM_CDC_IN 0x81
-
-#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
- // FT9XX doesn't support a same endpoint number with different direction IN and OUT
- // e.g EP1 OUT & EP1 IN cannot exist together
- #define EPNUM_CDC_NOTIF 0x81
- #define EPNUM_CDC_OUT 0x02
- #define EPNUM_CDC_IN 0x83
-
-#else
- #define EPNUM_CDC_NOTIF 0x81
- #define EPNUM_CDC_OUT 0x02
- #define EPNUM_CDC_IN 0x82
-
-#endif
-
-#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
-
-// full speed configuration
-uint8_t const desc_fs_configuration[] =
-{
- // Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
-
- // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
- TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
-};
-
-#if TUD_OPT_HIGH_SPEED
-// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
-
-// high speed configuration
-uint8_t const desc_hs_configuration[] =
-{
- // Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
-
- // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
- TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 512),
-};
-
-// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
-
-// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier =
-{
- .bLength = sizeof(tusb_desc_device_qualifier_t),
- .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
- .bcdUSB = USB_BCD,
-
- .bDeviceClass = TUSB_CLASS_MISC,
- .bDeviceSubClass = MISC_SUBCLASS_COMMON,
- .bDeviceProtocol = MISC_PROTOCOL_IAD,
-
- .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
- .bNumConfigurations = 0x01,
- .bReserved = 0x00
-};
-
-// Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
-// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
-// device_qualifier descriptor describes information about a high-speed capable device that would
-// change if the device were operating at the other speed. If not highspeed capable stall this request.
-uint8_t const* tud_descriptor_device_qualifier_cb(void)
-{
- return (uint8_t const*) &desc_device_qualifier;
-}
-
-// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
-// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
-uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index)
-{
- (void) index; // for multiple configurations
-
- // if link speed is high return fullspeed config, and vice versa
- // Note: the descriptor type is OHER_SPEED_CONFIG instead of CONFIG
- memcpy(desc_other_speed_config,
- (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_fs_configuration : desc_hs_configuration,
- CONFIG_TOTAL_LEN);
-
- desc_other_speed_config[1] = TUSB_DESC_OTHER_SPEED_CONFIG;
-
- return desc_other_speed_config;
-}
-
-#endif // highspeed
-
-
-// Invoked when received GET CONFIGURATION DESCRIPTOR
-// Application return pointer to descriptor
-// Descriptor contents must exist long enough for transfer to complete
-uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
-{
- (void) index; // for multiple configurations
-
-#if TUD_OPT_HIGH_SPEED
- // Although we are highspeed, host may be fullspeed.
- return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_hs_configuration : desc_fs_configuration;
-#else
- return desc_fs_configuration;
-#endif
-}
-
-//--------------------------------------------------------------------+
-// String Descriptors
-//--------------------------------------------------------------------+
-
-// String Descriptor Index
-enum {
- STRID_LANGID = 0,
- STRID_MANUFACTURER,
- STRID_PRODUCT,
- STRID_SERIAL,
-};
-
-// array of pointer to string descriptors
-char const *string_desc_arr[] =
-{
- (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
- "TinyUSB", // 1: Manufacturer
- "TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
- "TinyUSB CDC", // 4: CDC Interface
-};
-
-static uint16_t _desc_str[32 + 1];
-
-// Invoked when received GET STRING DESCRIPTOR request
-// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
- (void) langid;
- size_t chr_count;
-
- switch ( index ) {
- case STRID_LANGID:
- memcpy(&_desc_str[1], string_desc_arr[0], 2);
- chr_count = 1;
- break;
-
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
-
- default:
- // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
- // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
-
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
-
- const char *str = string_desc_arr[index];
-
- // Cap at max char
- chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
-
- // Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
- }
- break;
- }
-
- // first byte is length (including header), second byte is string type
- _desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
-
- return _desc_str;
-}
diff --git a/examples/host/CMakeLists.txt b/examples/host/CMakeLists.txt
index bedd2220b..5c63ec0c0 100644
--- a/examples/host/CMakeLists.txt
+++ b/examples/host/CMakeLists.txt
@@ -1,12 +1,10 @@
-cmake_minimum_required(VERSION 3.17)
+cmake_minimum_required(VERSION 3.5)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/family_support.cmake)
-project(tinyusb_host_examples C CXX ASM)
+project(tinyusb_host_examples)
family_initialize_project(tinyusb_host_examples ${CMAKE_CURRENT_LIST_DIR})
# family_add_subdirectory will filter what to actually add based on selected FAMILY
-family_add_subdirectory(bare_api)
family_add_subdirectory(cdc_msc_hid)
family_add_subdirectory(hid_controller)
-family_add_subdirectory(msc_file_explorer)
diff --git a/examples/host/bare_api/CMakeLists.txt b/examples/host/bare_api/CMakeLists.txt
deleted file mode 100644
index 76182d6fa..000000000
--- a/examples/host/bare_api/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-cmake_minimum_required(VERSION 3.17)
-
-include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
-
-# gets PROJECT name for the example
-family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-
-project(${PROJECT} C CXX ASM)
-
-# Checks this example is valid for the family and initializes the project
-family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
-add_executable(${PROJECT})
-
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- )
-
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
-
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_host_example(${PROJECT} noos)
diff --git a/examples/host/bare_api/Makefile b/examples/host/bare_api/Makefile
deleted file mode 100644
index 161f8c774..000000000
--- a/examples/host/bare_api/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-include ../../make.mk
-
-INC += \
- src \
- $(TOP)/hw \
-
-# Example source
-EXAMPLE_SOURCE += \
- src/main.c
-
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
-
-include ../../rules.mk
diff --git a/examples/host/bare_api/only.txt b/examples/host/bare_api/only.txt
deleted file mode 100644
index fee10f9e2..000000000
--- a/examples/host/bare_api/only.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-mcu:KINETIS_KL
-mcu:LPC175X_6X
-mcu:LPC177X_8X
-mcu:LPC18XX
-mcu:LPC40XX
-mcu:LPC43XX
-mcu:MIMXRT1XXX
-mcu:MIMXRT10XX
-mcu:MIMXRT11XX
-mcu:RP2040
-mcu:MSP432E4
-mcu:RX65X
-mcu:RAXXX
-mcu:MAX3421
diff --git a/examples/host/bare_api/src/main.c b/examples/host/bare_api/src/main.c
deleted file mode 100644
index 14725996d..000000000
--- a/examples/host/bare_api/src/main.c
+++ /dev/null
@@ -1,424 +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.
- *
- */
-
-/* This example current worked and tested with following controller
- * - Sony DualShock 4 [CUH-ZCT2x] VID = 0x054c, PID = 0x09cc
- */
-
-
-#include
-#include
-#include
-
-#include "bsp/board_api.h"
-#include "tusb.h"
-
-// English
-#define LANGUAGE_ID 0x0409
-#define BUF_COUNT 4
-
-
-tusb_desc_device_t desc_device;
-
-uint8_t buf_pool[BUF_COUNT][64];
-uint8_t buf_owner[BUF_COUNT] = { 0 }; // device address that owns buffer
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF PROTYPES
-//--------------------------------------------------------------------+
-void led_blinking_task(void);
-
-static void print_utf16(uint16_t *temp_buf, size_t buf_len);
-void print_device_descriptor(tuh_xfer_t* xfer);
-void parse_config_descriptor(uint8_t dev_addr, tusb_desc_configuration_t const* desc_cfg);
-
-uint8_t* get_hid_buf(uint8_t daddr);
-void free_hid_buf(uint8_t daddr);
-
-/*------------- MAIN -------------*/
-int main(void)
-{
- board_init();
-
- printf("TinyUSB Bare API Example\r\n");
-
- // init host stack on configured roothub port
- tuh_init(BOARD_TUH_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
-
- while (1)
- {
- // tinyusb host task
- tuh_task();
- led_blinking_task();
- }
-
- return 0;
-}
-
-/*------------- TinyUSB Callbacks -------------*/
-
-// Invoked when device is mounted (configured)
-void tuh_mount_cb (uint8_t daddr)
-{
- printf("Device attached, address = %d\r\n", daddr);
-
- // Get Device Descriptor
- // TODO: invoking control transfer now has issue with mounting hub with multiple devices attached, fix later
- tuh_descriptor_get_device(daddr, &desc_device, 18, print_device_descriptor, 0);
-}
-
-/// Invoked when device is unmounted (bus reset/unplugged)
-void tuh_umount_cb(uint8_t daddr)
-{
- printf("Device removed, address = %d\r\n", daddr);
- free_hid_buf(daddr);
-}
-
-//--------------------------------------------------------------------+
-// Device Descriptor
-//--------------------------------------------------------------------+
-
-void print_device_descriptor(tuh_xfer_t* xfer)
-{
- if ( XFER_RESULT_SUCCESS != xfer->result )
- {
- printf("Failed to get device descriptor\r\n");
- return;
- }
-
- uint8_t const daddr = xfer->daddr;
-
- printf("Device %u: ID %04x:%04x\r\n", daddr, desc_device.idVendor, desc_device.idProduct);
- printf("Device Descriptor:\r\n");
- printf(" bLength %u\r\n" , desc_device.bLength);
- printf(" bDescriptorType %u\r\n" , desc_device.bDescriptorType);
- printf(" bcdUSB %04x\r\n" , desc_device.bcdUSB);
- printf(" bDeviceClass %u\r\n" , desc_device.bDeviceClass);
- printf(" bDeviceSubClass %u\r\n" , desc_device.bDeviceSubClass);
- printf(" bDeviceProtocol %u\r\n" , desc_device.bDeviceProtocol);
- printf(" bMaxPacketSize0 %u\r\n" , desc_device.bMaxPacketSize0);
- printf(" idVendor 0x%04x\r\n" , desc_device.idVendor);
- printf(" idProduct 0x%04x\r\n" , desc_device.idProduct);
- printf(" bcdDevice %04x\r\n" , desc_device.bcdDevice);
-
- // Get String descriptor using Sync API
- uint16_t temp_buf[128];
-
- printf(" iManufacturer %u " , desc_device.iManufacturer);
- if (XFER_RESULT_SUCCESS == tuh_descriptor_get_manufacturer_string_sync(daddr, LANGUAGE_ID, temp_buf, sizeof(temp_buf)) )
- {
- print_utf16(temp_buf, TU_ARRAY_SIZE(temp_buf));
- }
- printf("\r\n");
-
- printf(" iProduct %u " , desc_device.iProduct);
- if (XFER_RESULT_SUCCESS == tuh_descriptor_get_product_string_sync(daddr, LANGUAGE_ID, temp_buf, sizeof(temp_buf)))
- {
- print_utf16(temp_buf, TU_ARRAY_SIZE(temp_buf));
- }
- printf("\r\n");
-
- printf(" iSerialNumber %u " , desc_device.iSerialNumber);
- if (XFER_RESULT_SUCCESS == tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, temp_buf, sizeof(temp_buf)))
- {
- print_utf16(temp_buf, TU_ARRAY_SIZE(temp_buf));
- }
- printf("\r\n");
-
- printf(" bNumConfigurations %u\r\n" , desc_device.bNumConfigurations);
-
- // Get configuration descriptor with sync API
- if (XFER_RESULT_SUCCESS == tuh_descriptor_get_configuration_sync(daddr, 0, temp_buf, sizeof(temp_buf)))
- {
- parse_config_descriptor(daddr, (tusb_desc_configuration_t*) temp_buf);
- }
-}
-
-//--------------------------------------------------------------------+
-// Configuration Descriptor
-//--------------------------------------------------------------------+
-
-// count total length of an interface
-uint16_t count_interface_total_len(tusb_desc_interface_t const* desc_itf, uint8_t itf_count, uint16_t max_len);
-
-void open_hid_interface(uint8_t daddr, tusb_desc_interface_t const *desc_itf, uint16_t max_len);
-
-// simple configuration parser to open and listen to HID Endpoint IN
-void parse_config_descriptor(uint8_t dev_addr, tusb_desc_configuration_t const* desc_cfg)
-{
- uint8_t const* desc_end = ((uint8_t const*) desc_cfg) + tu_le16toh(desc_cfg->wTotalLength);
- uint8_t const* p_desc = tu_desc_next(desc_cfg);
-
- // parse each interfaces
- while( p_desc < desc_end )
- {
- uint8_t assoc_itf_count = 1;
-
- // Class will always starts with Interface Association (if any) and then Interface descriptor
- if ( TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc) )
- {
- tusb_desc_interface_assoc_t const * desc_iad = (tusb_desc_interface_assoc_t const *) p_desc;
- assoc_itf_count = desc_iad->bInterfaceCount;
-
- p_desc = tu_desc_next(p_desc); // next to Interface
- }
-
- // must be interface from now
- if( TUSB_DESC_INTERFACE != tu_desc_type(p_desc) ) return;
- tusb_desc_interface_t const* desc_itf = (tusb_desc_interface_t const*) p_desc;
-
- uint16_t const drv_len = count_interface_total_len(desc_itf, assoc_itf_count, (uint16_t) (desc_end-p_desc));
-
- // probably corrupted descriptor
- if(drv_len < sizeof(tusb_desc_interface_t)) return;
-
- // only open and listen to HID endpoint IN
- if (desc_itf->bInterfaceClass == TUSB_CLASS_HID)
- {
- open_hid_interface(dev_addr, desc_itf, drv_len);
- }
-
- // next Interface or IAD descriptor
- p_desc += drv_len;
- }
-}
-
-uint16_t count_interface_total_len(tusb_desc_interface_t const* desc_itf, uint8_t itf_count, uint16_t max_len)
-{
- uint8_t const* p_desc = (uint8_t const*) desc_itf;
- uint16_t len = 0;
-
- while (itf_count--)
- {
- // Next on interface desc
- len += tu_desc_len(desc_itf);
- p_desc = tu_desc_next(p_desc);
-
- while (len < max_len)
- {
- // return on IAD regardless of itf count
- if ( tu_desc_type(p_desc) == TUSB_DESC_INTERFACE_ASSOCIATION ) return len;
-
- if ( (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE) &&
- ((tusb_desc_interface_t const*) p_desc)->bAlternateSetting == 0 )
- {
- break;
- }
-
- len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
- }
-
- return len;
-}
-
-//--------------------------------------------------------------------+
-// HID Interface
-//--------------------------------------------------------------------+
-
-void hid_report_received(tuh_xfer_t* xfer);
-
-void open_hid_interface(uint8_t daddr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
-{
- // len = interface + hid + n*endpoints
- uint16_t const drv_len = (uint16_t) (sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) +
- desc_itf->bNumEndpoints * sizeof(tusb_desc_endpoint_t));
-
- // corrupted descriptor
- if (max_len < drv_len) return;
-
- uint8_t const *p_desc = (uint8_t const *) desc_itf;
-
- // HID descriptor
- p_desc = tu_desc_next(p_desc);
- tusb_hid_descriptor_hid_t const *desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
- if(HID_DESC_TYPE_HID != desc_hid->bDescriptorType) return;
-
- // Endpoint descriptor
- p_desc = tu_desc_next(p_desc);
- tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
-
- for(int i = 0; i < desc_itf->bNumEndpoints; i++)
- {
- if (TUSB_DESC_ENDPOINT != desc_ep->bDescriptorType) return;
-
- if(tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN)
- {
- // skip if failed to open endpoint
- if ( ! tuh_edpt_open(daddr, desc_ep) ) return;
-
- uint8_t* buf = get_hid_buf(daddr);
- if (!buf) return; // out of memory
-
- tuh_xfer_t xfer =
- {
- .daddr = daddr,
- .ep_addr = desc_ep->bEndpointAddress,
- .buflen = 64,
- .buffer = buf,
- .complete_cb = hid_report_received,
- .user_data = (uintptr_t) buf, // since buffer is not available in callback, use user data to store the buffer
- };
-
- // submit transfer for this EP
- tuh_edpt_xfer(&xfer);
-
- printf("Listen to [dev %u: ep %02x]\r\n", daddr, desc_ep->bEndpointAddress);
- }
-
- p_desc = tu_desc_next(p_desc);
- desc_ep = (tusb_desc_endpoint_t const *) p_desc;
- }
-}
-
-void hid_report_received(tuh_xfer_t* xfer)
-{
- // Note: not all field in xfer is available for use (i.e filled by tinyusb stack) in callback to save sram
- // For instance, xfer->buffer is NULL. We have used user_data to store buffer when submitted callback
- uint8_t* buf = (uint8_t*) xfer->user_data;
-
- if (xfer->result == XFER_RESULT_SUCCESS)
- {
- printf("[dev %u: ep %02x] HID Report:", xfer->daddr, xfer->ep_addr);
- for(uint32_t i=0; iactual_len; i++)
- {
- if (i%16 == 0) printf("\r\n ");
- printf("%02X ", buf[i]);
- }
- printf("\r\n");
- }
-
- // continue to submit transfer, with updated buffer
- // other field remain the same
- xfer->buflen = 64;
- xfer->buffer = buf;
-
- tuh_edpt_xfer(xfer);
-}
-
-//--------------------------------------------------------------------+
-// Buffer helper
-//--------------------------------------------------------------------+
-
-// get an buffer from pool
-uint8_t* get_hid_buf(uint8_t daddr)
-{
- for(size_t i=0; i> 6 & 0x1F));
- *utf8++ = (uint8_t)(0x80 | (chr >> 0 & 0x3F));
- } else {
- // TODO: Verify surrogate.
- *utf8++ = (uint8_t)(0xE0 | (chr >> 12 & 0x0F));
- *utf8++ = (uint8_t)(0x80 | (chr >> 6 & 0x3F));
- *utf8++ = (uint8_t)(0x80 | (chr >> 0 & 0x3F));
- }
- // TODO: Handle UTF-16 code points that take two entries.
- }
-}
-
-// Count how many bytes a utf-16-le encoded string will take in utf-8.
-static int _count_utf8_bytes(const uint16_t *buf, size_t len) {
- size_t total_bytes = 0;
- for (size_t i = 0; i < len; i++) {
- uint16_t chr = buf[i];
- if (chr < 0x80) {
- total_bytes += 1;
- } else if (chr < 0x800) {
- total_bytes += 2;
- } else {
- total_bytes += 3;
- }
- // TODO: Handle UTF-16 code points that take two entries.
- }
- return (int) total_bytes;
-}
-
-static void print_utf16(uint16_t *temp_buf, size_t buf_len) {
- if ((temp_buf[0] & 0xff) == 0) return; // empty
- size_t utf16_len = ((temp_buf[0] & 0xff) - 2) / sizeof(uint16_t);
- size_t utf8_len = (size_t) _count_utf8_bytes(temp_buf + 1, utf16_len);
- _convert_utf16le_to_utf8(temp_buf + 1, utf16_len, (uint8_t *) temp_buf, sizeof(uint16_t) * buf_len);
- ((uint8_t*) temp_buf)[utf8_len] = '\0';
-
- printf((char*)temp_buf);
-}
diff --git a/examples/host/bare_api/src/tusb_config.h b/examples/host/bare_api/src/tusb_config.h
deleted file mode 100644
index ede9618d3..000000000
--- a/examples/host/bare_api/src/tusb_config.h
+++ /dev/null
@@ -1,115 +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 _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-#if CFG_TUSB_MCU == OPT_MCU_RP2040
-// change to 1 if using pico-pio-usb as host controller for raspberry rp2040
-#define CFG_TUH_RPI_PIO_USB 0
-#define BOARD_TUH_RHPORT CFG_TUH_RPI_PIO_USB
-#endif
-
-// RHPort number used for host can be defined by board.mk, default to port 0
-#ifndef BOARD_TUH_RHPORT
-#define BOARD_TUH_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUH_MAX_SPEED
-#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
-//--------------------------------------------------------------------
-// COMMON CONFIGURATION
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
-#endif
-
-#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
-#endif
-
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Host stack
-#define CFG_TUH_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED
-
-/* 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_TUH_MEM_SECTION
-#define CFG_TUH_MEM_SECTION
-#endif
-
-#ifndef CFG_TUH_MEM_ALIGN
-#define CFG_TUH_MEM_ALIGN __attribute__ ((aligned(4)))
-#endif
-
-//--------------------------------------------------------------------
-// CONFIGURATION
-//--------------------------------------------------------------------
-
-// Size of buffer to hold descriptors and other data used for enumeration
-#define CFG_TUH_ENUMERATION_BUFSIZE 256
-
-// only hub class is enabled
-#define CFG_TUH_HUB 1
-
-// max device support (excluding hub device)
-// 1 hub typically has 4 ports
-#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1)
-
-// Max endpoint per device
-#define CFG_TUH_ENDPOINT_MAX 8
-
-// Enable tuh_edpt_xfer() API
-#define CFG_TUH_API_EDPT_XFER 1
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_CONFIG_H_ */
diff --git a/examples/host/cdc_msc_hid/.only.MCU_LPC175X_6X b/examples/host/cdc_msc_hid/.only.MCU_LPC175X_6X
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/cdc_msc_hid/.only.MCU_LPC177X_8X b/examples/host/cdc_msc_hid/.only.MCU_LPC177X_8X
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/cdc_msc_hid/.only.MCU_LPC18XX b/examples/host/cdc_msc_hid/.only.MCU_LPC18XX
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/cdc_msc_hid/.only.MCU_LPC40XX b/examples/host/cdc_msc_hid/.only.MCU_LPC40XX
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/cdc_msc_hid/.only.MCU_LPC43XX b/examples/host/cdc_msc_hid/.only.MCU_LPC43XX
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/cdc_msc_hid/.only.MCU_MIMXRT10XX b/examples/host/cdc_msc_hid/.only.MCU_MIMXRT10XX
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/cdc_msc_hid/.only.MCU_RP2040 b/examples/host/cdc_msc_hid/.only.MCU_RP2040
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/cdc_msc_hid/CMakeLists.txt b/examples/host/cdc_msc_hid/CMakeLists.txt
index a7c372a34..0a99bc3a9 100644
--- a/examples/host/cdc_msc_hid/CMakeLists.txt
+++ b/examples/host/cdc_msc_hid/CMakeLists.txt
@@ -1,35 +1,29 @@
-cmake_minimum_required(VERSION 3.17)
+cmake_minimum_required(VERSION 3.5)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
# gets PROJECT name for the example (e.g. -)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
# Example source
target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/cdc_app.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c
- )
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c
+ )
# Example include
target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_host_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_host_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/host/cdc_msc_hid/Makefile b/examples/host/cdc_msc_hid/Makefile
index 15b8a5b31..6a2b4d902 100644
--- a/examples/host/cdc_msc_hid/Makefile
+++ b/examples/host/cdc_msc_hid/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
@@ -5,12 +6,22 @@ INC += \
$(TOP)/hw \
# Example source
-EXAMPLE_SOURCE = \
- src/cdc_app.c \
- src/hid_app.c \
- src/main.c \
- src/msc_app.c \
-
+EXAMPLE_SOURCE += $(wildcard src/*.c)
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+CFLAGS += -Wno-error=cast-align
+
+# TinyUSB Host Stack source
+SRC_C += \
+ src/class/cdc/cdc_host.c \
+ src/class/hid/hid_host.c \
+ src/class/msc/msc_host.c \
+ src/host/hub.c \
+ src/host/usbh.c \
+ src/host/usbh_control.c \
+ src/portable/ehci/ehci.c \
+ src/portable/ohci/ohci.c \
+ src/portable/nxp/transdimension/hcd_transdimension.c \
+ src/portable/nxp/lpc17_40/hcd_lpc17_40.c
+
include ../../rules.mk
diff --git a/examples/host/cdc_msc_hid/only.txt b/examples/host/cdc_msc_hid/only.txt
deleted file mode 100644
index fee10f9e2..000000000
--- a/examples/host/cdc_msc_hid/only.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-mcu:KINETIS_KL
-mcu:LPC175X_6X
-mcu:LPC177X_8X
-mcu:LPC18XX
-mcu:LPC40XX
-mcu:LPC43XX
-mcu:MIMXRT1XXX
-mcu:MIMXRT10XX
-mcu:MIMXRT11XX
-mcu:RP2040
-mcu:MSP432E4
-mcu:RX65X
-mcu:RAXXX
-mcu:MAX3421
diff --git a/examples/host/cdc_msc_hid/src/cdc_app.c b/examples/host/cdc_msc_hid/src/cdc_app.c
deleted file mode 100644
index a1b26e49c..000000000
--- a/examples/host/cdc_msc_hid/src/cdc_app.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2022, 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.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb.h"
-#include "bsp/board_api.h"
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM DECLARATION
-//--------------------------------------------------------------------+
-
-
-//------------- IMPLEMENTATION -------------//
-
-size_t get_console_inputs(uint8_t* buf, size_t bufsize)
-{
- size_t count = 0;
- while (count < bufsize)
- {
- int ch = board_getchar();
- if ( ch <= 0 ) break;
-
- buf[count] = (uint8_t) ch;
- count++;
- }
-
- return count;
-}
-
-void cdc_app_task(void)
-{
- uint8_t buf[64+1]; // +1 for extra null character
- uint32_t const bufsize = sizeof(buf)-1;
-
- uint32_t count = get_console_inputs(buf, bufsize);
- buf[count] = 0;
-
- // loop over all mounted interfaces
- for(uint8_t idx=0; idx cdc interfaces
- if (count)
- {
- tuh_cdc_write(idx, buf, count);
- tuh_cdc_write_flush(idx);
- }
- }
- }
-}
-
-// Invoked when received new data
-void tuh_cdc_rx_cb(uint8_t idx)
-{
- uint8_t buf[64+1]; // +1 for extra null character
- uint32_t const bufsize = sizeof(buf)-1;
-
- // forward cdc interfaces -> console
- uint32_t count = tuh_cdc_read(idx, buf, bufsize);
- buf[count] = 0;
-
- printf((char*) buf);
-}
-
-void tuh_cdc_mount_cb(uint8_t idx)
-{
- tuh_itf_info_t itf_info = { 0 };
- tuh_cdc_itf_get_info(idx, &itf_info);
-
- printf("CDC Interface is mounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.desc.bInterfaceNumber);
-
-#ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
- // CFG_TUH_CDC_LINE_CODING_ON_ENUM must be defined for line coding is set by tinyusb in enumeration
- // otherwise you need to call tuh_cdc_set_line_coding() first
- cdc_line_coding_t line_coding = { 0 };
- if ( tuh_cdc_get_local_line_coding(idx, &line_coding) )
- {
- printf(" Baudrate: %lu, Stop Bits : %u\r\n", line_coding.bit_rate, line_coding.stop_bits);
- printf(" Parity : %u, Data Width: %u\r\n", line_coding.parity , line_coding.data_bits);
- }
-#endif
-}
-
-void tuh_cdc_umount_cb(uint8_t idx)
-{
- tuh_itf_info_t itf_info = { 0 };
- tuh_cdc_itf_get_info(idx, &itf_info);
-
- printf("CDC Interface is unmounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.desc.bInterfaceNumber);
-}
diff --git a/examples/host/cdc_msc_hid/src/hid_app.c b/examples/host/cdc_msc_hid/src/hid_app.c
index f0d42a08f..11437c2b4 100644
--- a/examples/host/cdc_msc_hid/src/hid_app.c
+++ b/examples/host/cdc_msc_hid/src/hid_app.c
@@ -23,7 +23,7 @@
*
*/
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//--------------------------------------------------------------------+
@@ -160,9 +160,7 @@ static void process_kbd_report(hid_keyboard_report_t const *report)
putchar(ch);
if ( ch == '\r' ) putchar('\n'); // added new line for enter key
- #ifndef __ICCARM__ // TODO IAR doesn't support stream control ?
fflush(stdout); // flush right away, else nanolib will wait for newline
- #endif
}
}
// TODO example skips key released
@@ -249,7 +247,7 @@ static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t c
// Composite report, 1st byte is report ID, data starts from 2nd byte
uint8_t const rpt_id = report[0];
- // Find report id in the array
+ // Find report id in the arrray
for(uint8_t i=0; i
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//--------------------------------------------------------------------+
@@ -35,7 +35,7 @@
//--------------------------------------------------------------------+
void led_blinking_task(void);
-extern void cdc_app_task(void);
+extern void cdc_task(void);
extern void hid_app_task(void);
/*------------- MAIN -------------*/
@@ -45,32 +45,38 @@ int main(void)
printf("TinyUSB Host CDC MSC HID Example\r\n");
- // init host stack on configured roothub port
- tuh_init(BOARD_TUH_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
// tinyusb host task
tuh_task();
-
led_blinking_task();
- cdc_app_task();
+
+#if CFG_TUH_CDC
+ cdc_task();
+#endif
+
+#if CFG_TUH_HID
hid_app_task();
+#endif
}
+
+ return 0;
}
//--------------------------------------------------------------------+
-// TinyUSB Callbacks
+// USB CDC
//--------------------------------------------------------------------+
+#if CFG_TUH_CDC
+CFG_TUSB_MEM_SECTION static char serial_in_buffer[64] = { 0 };
void tuh_mount_cb(uint8_t dev_addr)
{
// application set-up
printf("A device with address %d is mounted\r\n", dev_addr);
+
+ tuh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true); // schedule first transfer
}
void tuh_umount_cb(uint8_t dev_addr)
@@ -79,6 +85,29 @@ void tuh_umount_cb(uint8_t dev_addr)
printf("A device with address %d is unmounted \r\n", dev_addr);
}
+// invoked ISR context
+void tuh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes)
+{
+ (void) event;
+ (void) pipe_id;
+ (void) xferred_bytes;
+
+ printf(serial_in_buffer);
+ tu_memclr(serial_in_buffer, sizeof(serial_in_buffer));
+
+ tuh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true); // waiting for next data
+}
+
+void cdc_task(void)
+{
+
+}
+
+#endif
+
+//--------------------------------------------------------------------+
+// TinyUSB Callbacks
+//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// Blinking Task
diff --git a/examples/host/cdc_msc_hid/src/msc_app.c b/examples/host/cdc_msc_hid/src/msc_app.c
index e9c9676b8..77a72052d 100644
--- a/examples/host/cdc_msc_hid/src/msc_app.c
+++ b/examples/host/cdc_msc_hid/src/msc_app.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -25,16 +25,15 @@
#include "tusb.h"
+#if CFG_TUH_MSC
+
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
static scsi_inquiry_resp_t inquiry_resp;
-bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
+bool inquiry_complete_cb(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
{
- msc_cbw_t const* cbw = cb_data->cbw;
- msc_csw_t const* csw = cb_data->csw;
-
if (csw->status != 0)
{
printf("Inquiry failed\r\n");
@@ -60,11 +59,48 @@ void tuh_msc_mount_cb(uint8_t dev_addr)
printf("A MassStorage device is mounted\r\n");
uint8_t const lun = 0;
- tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, inquiry_complete_cb, 0);
+ tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, inquiry_complete_cb);
+//
+// //------------- file system (only 1 LUN support) -------------//
+// uint8_t phy_disk = dev_addr-1;
+// disk_initialize(phy_disk);
+//
+// if ( disk_is_ready(phy_disk) )
+// {
+// if ( f_mount(phy_disk, &fatfs[phy_disk]) != FR_OK )
+// {
+// puts("mount failed");
+// return;
+// }
+//
+// f_chdrive(phy_disk); // change to newly mounted drive
+// f_chdir("/"); // root as current dir
+//
+// cli_init();
+// }
}
void tuh_msc_umount_cb(uint8_t dev_addr)
{
(void) dev_addr;
printf("A MassStorage device is unmounted\r\n");
+
+// uint8_t phy_disk = dev_addr-1;
+//
+// f_mount(phy_disk, NULL); // unmount disk
+// disk_deinitialize(phy_disk);
+//
+// if ( phy_disk == f_get_current_drive() )
+// { // active drive is unplugged --> change to other drive
+// for(uint8_t i=0; i-)
-family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-
-project(${PROJECT} C CXX ASM)
-
-# Checks this example is valid for the family and initializes the project
-family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
-add_executable(${PROJECT})
-
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/cdc_app.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/freertos_hook.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c
- )
-
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
-
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_host_example(${PROJECT} freertos)
diff --git a/examples/host/cdc_msc_hid_freertos/Makefile b/examples/host/cdc_msc_hid_freertos/Makefile
deleted file mode 100644
index a9670b4f2..000000000
--- a/examples/host/cdc_msc_hid_freertos/Makefile
+++ /dev/null
@@ -1,34 +0,0 @@
-include ../../make.mk
-
-FREERTOS_SRC = lib/FreeRTOS-Kernel
-FREERTOS_PORTABLE_PATH= $(FREERTOS_SRC)/portable/$(if $(USE_IAR),IAR,GCC)
-
-INC += \
- src \
- src/FreeRTOSConfig \
- $(TOP)/hw \
- $(TOP)/$(FREERTOS_SRC)/include \
- $(TOP)/$(FREERTOS_PORTABLE_SRC) \
-
-# Example source
-EXAMPLE_SOURCE = \
- src/cdc_app.c \
- src/freertos_hook.c \
- src/hid_app.c \
- src/main.c \
- src/msc_app.c \
-
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
-
-# FreeRTOS source, all files in port folder
-SRC_C += \
- $(FREERTOS_SRC)/list.c \
- $(FREERTOS_SRC)/queue.c \
- $(FREERTOS_SRC)/tasks.c \
- $(FREERTOS_SRC)/timers.c \
- $(subst $(TOP)/,,$(wildcard $(TOP)/$(FREERTOS_PORTABLE_SRC)/*.c))
-
-SRC_S += \
- $(subst $(TOP)/,,$(wildcard $(TOP)/$(FREERTOS_PORTABLE_SRC)/*.s))
-
-include ../../rules.mk
diff --git a/examples/host/cdc_msc_hid_freertos/only.txt b/examples/host/cdc_msc_hid_freertos/only.txt
deleted file mode 100644
index 3837ac8a2..000000000
--- a/examples/host/cdc_msc_hid_freertos/only.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-mcu:LPC175X_6X
-mcu:LPC177X_8X
-mcu:LPC18XX
-mcu:LPC40XX
-mcu:LPC43XX
-mcu:MIMXRT1XXX
-mcu:MIMXRT10XX
-mcu:MIMXRT11XX
-mcu:RP2040
-mcu:MSP432E4
-mcu:RX65X
-mcu:RAXXX
-mcu:MAX3421
diff --git a/examples/host/cdc_msc_hid_freertos/src/CMakeLists.txt b/examples/host/cdc_msc_hid_freertos/src/CMakeLists.txt
deleted file mode 100644
index 6f057c106..000000000
--- a/examples/host/cdc_msc_hid_freertos/src/CMakeLists.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-# This file is for ESP-IDF only
-idf_component_register(SRCS "cdc_app.c" "hid_app.c" "main.c" "msc_app.c"
- INCLUDE_DIRS "."
- REQUIRES boards tinyusb_src)
-
-target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=format)
diff --git a/examples/host/cdc_msc_hid_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h b/examples/host/cdc_msc_hid_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h
deleted file mode 100644
index a1fc8bb09..000000000
--- a/examples/host/cdc_msc_hid_freertos/src/FreeRTOSConfig/FreeRTOSConfig.h
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * FreeRTOS Kernel V10.0.0
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * 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. If you wish to use our Amazon
- * FreeRTOS name, please do so in a fair use way that does not cause confusion.
- *
- * 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.
- *
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
- *
- * 1 tab == 4 spaces!
- */
-
-
-#ifndef FREERTOS_CONFIG_H
-#define FREERTOS_CONFIG_H
-
-/*-----------------------------------------------------------
- * Application specific definitions.
- *
- * These definitions should be adjusted for your particular hardware and
- * application requirements.
- *
- * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
- * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
- *
- * See http://www.freertos.org/a00110.html.
- *----------------------------------------------------------*/
-
-// skip if included from IAR assembler
-#ifndef __IASMARM__
-
-// Include MCU header
-#include "bsp/board_mcu.h"
-
-#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
- #error "ESP32-Sx should use IDF's FreeRTOSConfig.h"
-#endif
-
-#ifdef __GNUC__
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wredundant-decls"
-#endif
-
-// TODO fix later
-// FIXME cause redundant-decls warnings
-#if CFG_TUSB_MCU == OPT_MCU_MM32F327X
- extern u32 SystemCoreClock;
-#else
- extern uint32_t SystemCoreClock;
-#endif
-
-#ifdef __GNUC__
-#pragma GCC diagnostic pop
-#endif
-
-#endif
-
-/* Cortex M23/M33 port configuration. */
-#define configENABLE_MPU 0
-#define configENABLE_FPU 1
-#define configENABLE_TRUSTZONE 0
-#define configMINIMAL_SECURE_STACK_SIZE ( 1024 )
-
-#define configUSE_PREEMPTION 1
-#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
-#define configCPU_CLOCK_HZ SystemCoreClock
-#define configTICK_RATE_HZ ( 1000 )
-#define configMAX_PRIORITIES ( 5 )
-#define configMINIMAL_STACK_SIZE ( 128 )
-#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION*4*1024 )
-#define configMAX_TASK_NAME_LEN 16
-#define configUSE_16_BIT_TICKS 0
-#define configIDLE_SHOULD_YIELD 1
-#define configUSE_MUTEXES 1
-#define configUSE_RECURSIVE_MUTEXES 1
-#define configUSE_COUNTING_SEMAPHORES 1
-#define configQUEUE_REGISTRY_SIZE 4
-#define configUSE_QUEUE_SETS 0
-#define configUSE_TIME_SLICING 0
-#define configUSE_NEWLIB_REENTRANT 0
-#define configENABLE_BACKWARD_COMPATIBILITY 1
-#define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
-
-#define configSUPPORT_STATIC_ALLOCATION 1
-#define configSUPPORT_DYNAMIC_ALLOCATION 0
-
-/* Hook function related definitions. */
-#define configUSE_IDLE_HOOK 0
-#define configUSE_TICK_HOOK 0
-#define configUSE_MALLOC_FAILED_HOOK 0 // cause nested extern warning
-#define configCHECK_FOR_STACK_OVERFLOW 2
-
-/* Run time and task stats gathering related definitions. */
-#define configGENERATE_RUN_TIME_STATS 0
-#define configUSE_TRACE_FACILITY 1 // legacy trace
-#define configUSE_STATS_FORMATTING_FUNCTIONS 0
-
-/* Co-routine definitions. */
-#define configUSE_CO_ROUTINES 0
-#define configMAX_CO_ROUTINE_PRIORITIES 2
-
-/* Software timer related definitions. */
-#define configUSE_TIMERS 1
-#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES-2)
-#define configTIMER_QUEUE_LENGTH 32
-#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
-
-/* Optional functions - most linkers will remove unused functions anyway. */
-#define INCLUDE_vTaskPrioritySet 0
-#define INCLUDE_uxTaskPriorityGet 0
-#define INCLUDE_vTaskDelete 0
-#define INCLUDE_vTaskSuspend 1 // required for queue, semaphore, mutex to be blocked indefinitely with portMAX_DELAY
-#define INCLUDE_xResumeFromISR 0
-#define INCLUDE_vTaskDelayUntil 1
-#define INCLUDE_vTaskDelay 1
-#define INCLUDE_xTaskGetSchedulerState 0
-#define INCLUDE_xTaskGetCurrentTaskHandle 0
-#define INCLUDE_uxTaskGetStackHighWaterMark 0
-#define INCLUDE_xTaskGetIdleTaskHandle 0
-#define INCLUDE_xTimerGetTimerDaemonTaskHandle 0
-#define INCLUDE_pcTaskGetTaskName 0
-#define INCLUDE_eTaskGetState 0
-#define INCLUDE_xEventGroupSetBitFromISR 0
-#define INCLUDE_xTimerPendFunctionCall 0
-
-/* Define to trap errors during development. */
-// Halt CPU (breakpoint) when hitting error, only apply for Cortex M3, M4, M7
-#if defined(__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__)
- #define configASSERT(_exp) \
- do {\
- if ( !(_exp) ) { \
- volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL); /* Cortex M CoreDebug->DHCSR */ \
- if ( (*ARM_CM_DHCSR) & 1UL ) { /* Only halt mcu if debugger is attached */ \
- taskDISABLE_INTERRUPTS(); \
- __asm("BKPT #0\n"); \
- }\
- }\
- } while(0)
-#else
- #define configASSERT( x )
-#endif
-
-#ifdef __RX__
-/* Renesas RX series */
-#define vSoftwareInterruptISR INT_Excep_ICU_SWINT
-#define vTickISR INT_Excep_CMT0_CMI0
-#define configPERIPHERAL_CLOCK_HZ (configCPU_CLOCK_HZ/2)
-#define configKERNEL_INTERRUPT_PRIORITY 1
-#define configMAX_SYSCALL_INTERRUPT_PRIORITY 4
-
-#else
-
-/* FreeRTOS hooks to NVIC vectors */
-#define xPortPendSVHandler PendSV_Handler
-#define xPortSysTickHandler SysTick_Handler
-#define vPortSVCHandler SVC_Handler
-
-//--------------------------------------------------------------------+
-// Interrupt nesting behavior configuration.
-//--------------------------------------------------------------------+
-#if defined(__NVIC_PRIO_BITS)
- // For Cortex-M specific: __NVIC_PRIO_BITS is defined in core_cmx.h
- #define configPRIO_BITS __NVIC_PRIO_BITS
-
-#elif defined(__ECLIC_INTCTLBITS)
- // RISC-V Bumblebee core from nuclei
- #define configPRIO_BITS __ECLIC_INTCTLBITS
-
-#elif defined(__IASMARM__)
- // FIXME: IAR Assembler cannot include mcu header directly to get __NVIC_PRIO_BITS.
- // Therefore we will hard coded it to minimum value of 2 to get pass ci build.
- // IAR user must update this to correct value of the target MCU
- #message "configPRIO_BITS is hard coded to 2 to pass IAR build only. User should update it per MCU"
- #define configPRIO_BITS 2
-
-#else
- #error "FreeRTOS configPRIO_BITS to be defined"
-#endif
-
-/* The lowest interrupt priority that can be used in a call to a "set priority" function. */
-#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1< cdc interfaces
- tuh_cdc_write(idx, buf, count);
- tuh_cdc_write_flush(idx);
- }
- }
- }
-
- vTaskDelay(1);
- }
-}
-
-//--------------------------------------------------------------------+
-// TinyUSB Callbacks
-//--------------------------------------------------------------------+
-
-// Invoked when received new data
-void tuh_cdc_rx_cb(uint8_t idx) {
- uint8_t buf[64 + 1]; // +1 for extra null character
- uint32_t const bufsize = sizeof(buf) - 1;
-
- // forward cdc interfaces -> console
- uint32_t count = tuh_cdc_read(idx, buf, bufsize);
- buf[count] = 0;
-
- printf((char *) buf);
-}
-
-void tuh_cdc_mount_cb(uint8_t idx) {
- tuh_itf_info_t itf_info = { 0 };
- tuh_cdc_itf_get_info(idx, &itf_info);
-
- printf("CDC Interface is mounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.desc.bInterfaceNumber);
-
-#ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
- // CFG_TUH_CDC_LINE_CODING_ON_ENUM must be defined for line coding is set by tinyusb in enumeration
- // otherwise you need to call tuh_cdc_set_line_coding() first
- cdc_line_coding_t line_coding = { 0 };
- if (tuh_cdc_get_local_line_coding(idx, &line_coding)) {
- printf(" Baudrate: %lu, Stop Bits : %u\r\n", line_coding.bit_rate, line_coding.stop_bits);
- printf(" Parity : %u, Data Width: %u\r\n", line_coding.parity, line_coding.data_bits);
- }
-#endif
-}
-
-void tuh_cdc_umount_cb(uint8_t idx) {
- tuh_itf_info_t itf_info = { 0 };
- tuh_cdc_itf_get_info(idx, &itf_info);
-
- printf("CDC Interface is unmounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.desc.bInterfaceNumber);
-}
diff --git a/examples/host/cdc_msc_hid_freertos/src/freertos_hook.c b/examples/host/cdc_msc_hid_freertos/src/freertos_hook.c
deleted file mode 100644
index 07d159fd5..000000000
--- a/examples/host/cdc_msc_hid_freertos/src/freertos_hook.c
+++ /dev/null
@@ -1,111 +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.
- *
- */
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "FreeRTOS.h"
-#include "task.h"
-#include "common/tusb_common.h"
-
-void vApplicationMallocFailedHook(void) {
- taskDISABLE_INTERRUPTS();
- TU_ASSERT(false,);
-}
-
-void vApplicationStackOverflowHook(xTaskHandle pxTask, char *pcTaskName) {
- (void) pxTask;
- (void) pcTaskName;
-
- taskDISABLE_INTERRUPTS();
- TU_ASSERT(false,);
-}
-
-/* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an
- * implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
- * used by the Idle task. */
-void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer,
- uint32_t *pulIdleTaskStackSize) {
- /* If the buffers to be provided to the Idle task are declared inside this
- * function then they must be declared static - otherwise they will be allocated on
- * the stack and so not exists after this function exits. */
- static StaticTask_t xIdleTaskTCB;
- static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];
-
- /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
- state will be stored. */
- *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
-
- /* Pass out the array that will be used as the Idle task's stack. */
- *ppxIdleTaskStackBuffer = uxIdleTaskStack;
-
- /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
- Note that, as the array is necessarily of type StackType_t,
- configMINIMAL_STACK_SIZE is specified in words, not bytes. */
- *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
-}
-
-/* configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
- * application must provide an implementation of vApplicationGetTimerTaskMemory()
- * to provide the memory that is used by the Timer service task. */
-void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer,
- uint32_t *pulTimerTaskStackSize) {
- /* If the buffers to be provided to the Timer task are declared inside this
- * function then they must be declared static - otherwise they will be allocated on
- * the stack and so not exists after this function exits. */
- static StaticTask_t xTimerTaskTCB;
- static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];
-
- /* Pass out a pointer to the StaticTask_t structure in which the Timer
- task's state will be stored. */
- *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
-
- /* Pass out the array that will be used as the Timer task's stack. */
- *ppxTimerTaskStackBuffer = uxTimerTaskStack;
-
- /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
- Note that, as the array is necessarily of type StackType_t,
- configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */
- *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
-}
-
-#if CFG_TUSB_MCU == OPT_MCU_RX63X | CFG_TUSB_MCU == OPT_MCU_RX65X
-#include "iodefine.h"
-void vApplicationSetupTimerInterrupt(void)
-{
- /* Enable CMT0 */
- SYSTEM.PRCR.WORD = (0xA5u<<8) | TU_BIT(1);
- MSTP(CMT0) = 0;
- SYSTEM.PRCR.WORD = (0xA5u<<8);
-
- CMT0.CMCNT = 0;
- CMT0.CMCOR = (unsigned short)(((configPERIPHERAL_CLOCK_HZ/configTICK_RATE_HZ)-1)/128);
- CMT0.CMCR.WORD = TU_BIT(6) | 2;
- IR(CMT0, CMI0) = 0;
- IPR(CMT0, CMI0) = configKERNEL_INTERRUPT_PRIORITY;
- IEN(CMT0, CMI0) = 1;
- CMT.CMSTR0.BIT.STR0 = 1;
-}
-#endif
diff --git a/examples/host/cdc_msc_hid_freertos/src/hid_app.c b/examples/host/cdc_msc_hid_freertos/src/hid_app.c
deleted file mode 100644
index 9ea5c1be0..000000000
--- a/examples/host/cdc_msc_hid_freertos/src/hid_app.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2021, 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.
- *
- */
-
-#include "bsp/board_api.h"
-#include "tusb.h"
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM DECLARATION
-//--------------------------------------------------------------------+
-
-// If your host terminal support ansi escape code such as TeraTerm
-// it can be use to simulate mouse cursor movement within terminal
-#define USE_ANSI_ESCAPE 0
-
-#define MAX_REPORT 4
-
-static uint8_t const keycode2ascii[128][2] = { HID_KEYCODE_TO_ASCII };
-
-// Each HID instance can has multiple reports
-static struct {
- uint8_t report_count;
- tuh_hid_report_info_t report_info[MAX_REPORT];
-} hid_info[CFG_TUH_HID];
-
-static void process_kbd_report(hid_keyboard_report_t const *report);
-static void process_mouse_report(hid_mouse_report_t const *report);
-static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t const *report, uint16_t len);
-
-void hid_app_init(void) {
- // nothing to do
-}
-
-//--------------------------------------------------------------------+
-// TinyUSB Callbacks
-//--------------------------------------------------------------------+
-
-// Invoked when device with hid interface is mounted
-// Report descriptor is also available for use. tuh_hid_parse_report_descriptor()
-// can be used to parse common/simple enough descriptor.
-// Note: if report descriptor length > CFG_TUH_ENUMERATION_BUFSIZE, it will be skipped
-// therefore report_desc = NULL, desc_len = 0
-void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const *desc_report, uint16_t desc_len) {
- printf("HID device address = %d, instance = %d is mounted\r\n", dev_addr, instance);
-
- // Interface protocol (hid_interface_protocol_enum_t)
- const char *protocol_str[] = { "None", "Keyboard", "Mouse" };
- uint8_t const itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);
-
- printf("HID Interface Protocol = %s\r\n", protocol_str[itf_protocol]);
-
- // By default host stack will use activate boot protocol on supported interface.
- // Therefore for this simple example, we only need to parse generic report descriptor (with built-in parser)
- if (itf_protocol == HID_ITF_PROTOCOL_NONE) {
- hid_info[instance].report_count = tuh_hid_parse_report_descriptor(hid_info[instance].report_info, MAX_REPORT,
- desc_report, desc_len);
- printf("HID has %u reports \r\n", hid_info[instance].report_count);
- }
-
- // request to receive report
- // tuh_hid_report_received_cb() will be invoked when report is available
- if (!tuh_hid_receive_report(dev_addr, instance)) {
- printf("Error: cannot request to receive report\r\n");
- }
-}
-
-// Invoked when device with hid interface is un-mounted
-void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) {
- printf("HID device address = %d, instance = %d is unmounted\r\n", dev_addr, instance);
-}
-
-// Invoked when received report from device via interrupt endpoint
-void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const *report, uint16_t len) {
- uint8_t const itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);
-
- switch (itf_protocol) {
- case HID_ITF_PROTOCOL_KEYBOARD:
- TU_LOG2("HID receive boot keyboard report\r\n");
- process_kbd_report((hid_keyboard_report_t const *) report);
- break;
-
- case HID_ITF_PROTOCOL_MOUSE:
- TU_LOG2("HID receive boot mouse report\r\n");
- process_mouse_report((hid_mouse_report_t const *) report);
- break;
-
- default:
- // Generic report requires matching ReportID and contents with previous parsed report info
- process_generic_report(dev_addr, instance, report, len);
- break;
- }
-
- // continue to request to receive report
- if (!tuh_hid_receive_report(dev_addr, instance)) {
- printf("Error: cannot request to receive report\r\n");
- }
-}
-
-//--------------------------------------------------------------------+
-// Keyboard
-//--------------------------------------------------------------------+
-
-// look up new key in previous keys
-static inline bool find_key_in_report(hid_keyboard_report_t const *report, uint8_t keycode) {
- for (uint8_t i = 0; i < 6; i++) {
- if (report->keycode[i] == keycode) return true;
- }
-
- return false;
-}
-
-static void process_kbd_report(hid_keyboard_report_t const *report) {
- static hid_keyboard_report_t prev_report = { 0, 0, { 0 } }; // previous report to check key released
-
- //------------- example code ignore control (non-printable) key affects -------------//
- for (uint8_t i = 0; i < 6; i++) {
- if (report->keycode[i]) {
- if (find_key_in_report(&prev_report, report->keycode[i])) {
- // exist in previous report means the current key is holding
- } else {
- // not existed in previous report means the current key is pressed
- bool const is_shift = report->modifier & (KEYBOARD_MODIFIER_LEFTSHIFT | KEYBOARD_MODIFIER_RIGHTSHIFT);
- uint8_t ch = keycode2ascii[report->keycode[i]][is_shift ? 1 : 0];
- putchar(ch);
- if (ch == '\r') putchar('\n'); // added new line for enter key
-
- #ifndef __ICCARM__ // TODO IAR doesn't support stream control ?
- fflush(stdout); // flush right away, else nanolib will wait for newline
- #endif
- }
- }
- // TODO example skips key released
- }
-
- prev_report = *report;
-}
-
-//--------------------------------------------------------------------+
-// Mouse
-//--------------------------------------------------------------------+
-
-void cursor_movement(int8_t x, int8_t y, int8_t wheel) {
-#if USE_ANSI_ESCAPE
- // Move X using ansi escape
- if ( x < 0) {
- printf(ANSI_CURSOR_BACKWARD(%d), (-x)); // move left
- }else if ( x > 0) {
- printf(ANSI_CURSOR_FORWARD(%d), x); // move right
- }
-
- // Move Y using ansi escape
- if ( y < 0) {
- printf(ANSI_CURSOR_UP(%d), (-y)); // move up
- }else if ( y > 0) {
- printf(ANSI_CURSOR_DOWN(%d), y); // move down
- }
-
- // Scroll using ansi escape
- if (wheel < 0) {
- printf(ANSI_SCROLL_UP(%d), (-wheel)); // scroll up
- }else if (wheel > 0) {
- printf(ANSI_SCROLL_DOWN(%d), wheel); // scroll down
- }
-
- printf("\r\n");
-#else
- printf("(%d %d %d)\r\n", x, y, wheel);
-#endif
-}
-
-static void process_mouse_report(hid_mouse_report_t const *report) {
- static hid_mouse_report_t prev_report = { 0 };
-
- //------------- button state -------------//
- uint8_t button_changed_mask = report->buttons ^ prev_report.buttons;
- if (button_changed_mask & report->buttons) {
- printf(" %c%c%c ",
- report->buttons & MOUSE_BUTTON_LEFT ? 'L' : '-',
- report->buttons & MOUSE_BUTTON_MIDDLE ? 'M' : '-',
- report->buttons & MOUSE_BUTTON_RIGHT ? 'R' : '-');
- }
-
- //------------- cursor movement -------------//
- cursor_movement(report->x, report->y, report->wheel);
-}
-
-//--------------------------------------------------------------------+
-// Generic Report
-//--------------------------------------------------------------------+
-static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t const *report, uint16_t len) {
- (void) dev_addr;
-
- uint8_t const rpt_count = hid_info[instance].report_count;
- tuh_hid_report_info_t *rpt_info_arr = hid_info[instance].report_info;
- tuh_hid_report_info_t *rpt_info = NULL;
-
- if (rpt_count == 1 && rpt_info_arr[0].report_id == 0) {
- // Simple report without report ID as 1st byte
- rpt_info = &rpt_info_arr[0];
- } else {
- // Composite report, 1st byte is report ID, data starts from 2nd byte
- uint8_t const rpt_id = report[0];
-
- // Find report id in the array
- for (uint8_t i = 0; i < rpt_count; i++) {
- if (rpt_id == rpt_info_arr[i].report_id) {
- rpt_info = &rpt_info_arr[i];
- break;
- }
- }
-
- report++;
- len--;
- }
-
- if (!rpt_info) {
- printf("Couldn't find report info !\r\n");
- return;
- }
-
- // For complete list of Usage Page & Usage checkout src/class/hid/hid.h. For examples:
- // - Keyboard : Desktop, Keyboard
- // - Mouse : Desktop, Mouse
- // - Gamepad : Desktop, Gamepad
- // - Consumer Control (Media Key) : Consumer, Consumer Control
- // - System Control (Power key) : Desktop, System Control
- // - Generic (vendor) : 0xFFxx, xx
- if (rpt_info->usage_page == HID_USAGE_PAGE_DESKTOP) {
- switch (rpt_info->usage) {
- case HID_USAGE_DESKTOP_KEYBOARD:
- TU_LOG1("HID receive keyboard report\r\n");
- // Assume keyboard follow boot report layout
- process_kbd_report((hid_keyboard_report_t const *) report);
- break;
-
- case HID_USAGE_DESKTOP_MOUSE:
- TU_LOG1("HID receive mouse report\r\n");
- // Assume mouse follow boot report layout
- process_mouse_report((hid_mouse_report_t const *) report);
- break;
-
- default:
- break;
- }
- }
-}
diff --git a/examples/host/cdc_msc_hid_freertos/src/main.c b/examples/host/cdc_msc_hid_freertos/src/main.c
deleted file mode 100644
index 691ff3e29..000000000
--- a/examples/host/cdc_msc_hid_freertos/src/main.c
+++ /dev/null
@@ -1,165 +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.
- *
- */
-
-#include
-#include
-#include
-
-#include "bsp/board_api.h"
-#include "tusb.h"
-
-#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
- // ESP-IDF need "freertos/" prefix in include path.
- // CFG_TUSB_OS_INC_PATH should be defined accordingly.
- #include "freertos/FreeRTOS.h"
- #include "freertos/semphr.h"
- #include "freertos/queue.h"
- #include "freertos/task.h"
- #include "freertos/timers.h"
-
- #define USBH_STACK_SIZE 4096
-#else
- #include "FreeRTOS.h"
- #include "semphr.h"
- #include "queue.h"
- #include "task.h"
- #include "timers.h"
-
- // Increase stack size when debug log is enabled
- #define USBH_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
-#endif
-
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF PROTOTYPES
-//--------------------------------------------------------------------+
-/* Blink pattern
- * - 250 ms : device not mounted
- * - 1000 ms : device mounted
- * - 2500 ms : device is suspended
- */
-enum {
- BLINK_NOT_MOUNTED = 250,
- BLINK_MOUNTED = 1000,
- BLINK_SUSPENDED = 2500,
-};
-
-// static timer & task
-#if configSUPPORT_STATIC_ALLOCATION
-StaticTimer_t blinky_tmdef;
-
-StackType_t usb_host_stack[USBH_STACK_SIZE];
-StaticTask_t usb_host_taskdef;
-#endif
-
-TimerHandle_t blinky_tm;
-
-static void led_blinky_cb(TimerHandle_t xTimer);
-static void usb_host_task(void* param);
-
-extern void cdc_app_init(void);
-extern void hid_app_init(void);
-extern void msc_app_init(void);
-
-/*------------- MAIN -------------*/
-int main(void) {
- board_init();
-
- printf("TinyUSB Host CDC MSC HID with FreeRTOS Example\r\n");
-
- // Create soft timer for blinky, task for tinyusb stack
-#if configSUPPORT_STATIC_ALLOCATION
- blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_MOUNTED), true, NULL, led_blinky_cb, &blinky_tmdef);
- xTaskCreateStatic(usb_host_task, "usbh", USBH_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_host_stack, &usb_host_taskdef);
-#else
- blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb);
- xTaskCreate(usb_host_task, "usbd", USBH_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL);
-#endif
-
- xTimerStart(blinky_tm, 0);
-
- // skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
-#if !TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
- vTaskStartScheduler();
-#endif
-
- return 0;
-}
-
-#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
-void app_main(void) {
- main();
-}
-#endif
-
-// USB Host task
-// This top level thread process all usb events and invoke callbacks
-static void usb_host_task(void *param) {
- (void) param;
-
- // init host stack on configured roothub port
- tuh_init(BOARD_TUH_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
-
- cdc_app_init();
- hid_app_init();
- msc_app_init();
-
- // RTOS forever loop
- while (1) {
- // put this thread to waiting state until there is new events
- tuh_task();
-
- // following code only run if tuh_task() process at least 1 event
- }
-}
-
-//--------------------------------------------------------------------+
-// TinyUSB Callbacks
-//--------------------------------------------------------------------+
-
-void tuh_mount_cb(uint8_t dev_addr) {
- // application set-up
- printf("A device with address %d is mounted\r\n", dev_addr);
-}
-
-void tuh_umount_cb(uint8_t dev_addr) {
- // application tear-down
- printf("A device with address %d is unmounted \r\n", dev_addr);
-}
-
-//--------------------------------------------------------------------+
-// BLINKING TASK
-//--------------------------------------------------------------------+
-static void led_blinky_cb(TimerHandle_t xTimer) {
- (void) xTimer;
- static bool led_state = false;
-
- board_led_write(led_state);
- led_state = 1 - led_state; // toggle
-}
diff --git a/examples/host/cdc_msc_hid_freertos/src/msc_app.c b/examples/host/cdc_msc_hid_freertos/src/msc_app.c
deleted file mode 100644
index ee02ba917..000000000
--- a/examples/host/cdc_msc_hid_freertos/src/msc_app.c
+++ /dev/null
@@ -1,67 +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.
- *
- */
-
-#include "tusb.h"
-
-static scsi_inquiry_resp_t inquiry_resp;
-
-void msc_app_init(void) {
- // nothing to do
-}
-
-bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const *cb_data) {
- msc_cbw_t const *cbw = cb_data->cbw;
- msc_csw_t const *csw = cb_data->csw;
-
- if (csw->status != 0) {
- printf("Inquiry failed\r\n");
- return false;
- }
-
- // Print out Vendor ID, Product ID and Rev
- printf("%.8s %.16s rev %.4s\r\n", inquiry_resp.vendor_id, inquiry_resp.product_id, inquiry_resp.product_rev);
-
- // Get capacity of device
- uint32_t const block_count = tuh_msc_get_block_count(dev_addr, cbw->lun);
- uint32_t const block_size = tuh_msc_get_block_size(dev_addr, cbw->lun);
-
- printf("Disk Size: %lu MB\r\n", block_count / ((1024 * 1024) / block_size));
- printf("Block Count = %lu, Block Size: %lu\r\n", block_count, block_size);
-
- return true;
-}
-
-//------------- IMPLEMENTATION -------------//
-void tuh_msc_mount_cb(uint8_t dev_addr) {
- printf("A MassStorage device is mounted\r\n");
-
- uint8_t const lun = 0;
- tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, inquiry_complete_cb, 0);
-}
-
-void tuh_msc_umount_cb(uint8_t dev_addr) {
- (void) dev_addr;
- printf("A MassStorage device is unmounted\r\n");
-}
diff --git a/examples/host/cdc_msc_hid_freertos/src/tusb_config.h b/examples/host/cdc_msc_hid_freertos/src/tusb_config.h
deleted file mode 100644
index 1bed9a9b3..000000000
--- a/examples/host/cdc_msc_hid_freertos/src/tusb_config.h
+++ /dev/null
@@ -1,133 +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 _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
-#if CFG_TUSB_MCU == OPT_MCU_RP2040
- // change to 1 if using pico-pio-usb as host controller for raspberry rp2040
- #define CFG_TUH_RPI_PIO_USB 0
- #define BOARD_TUH_RHPORT CFG_TUH_RPI_PIO_USB
-#endif
-
-// RHPort number used for host can be defined by board.mk, default to port 0
-#ifndef BOARD_TUH_RHPORT
-#define BOARD_TUH_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUH_MAX_SPEED
-#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
-//--------------------------------------------------------------------
-// COMMON CONFIGURATION
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
-#endif
-
-#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_FREERTOS
-#endif
-
-// Espressif IDF requires "freertos/" prefix in include path
-#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
-#define CFG_TUSB_OS_INC_PATH freertos/
-#endif
-
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Host stack
-#define CFG_TUH_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED
-
-/* 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_TUH_MEM_SECTION
-#define CFG_TUH_MEM_SECTION
-#endif
-
-#ifndef CFG_TUH_MEM_ALIGN
-#define CFG_TUH_MEM_ALIGN __attribute__ ((aligned(4)))
-#endif
-
-//--------------------------------------------------------------------
-// CONFIGURATION
-//--------------------------------------------------------------------
-
-// Size of buffer to hold descriptors and other data used for enumeration
-#define CFG_TUH_ENUMERATION_BUFSIZE 256
-
-#define CFG_TUH_HUB 1 // number of supported hubs
-#define CFG_TUH_CDC 1 // CDC ACM
-#define CFG_TUH_CDC_FTDI 1 // FTDI Serial. FTDI is not part of CDC class, only to re-use CDC driver API
-#define CFG_TUH_CDC_CP210X 1 // CP210x Serial. CP210X is not part of CDC class, only to re-use CDC driver API
-#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX) // typical keyboard + mouse device can have 3-4 HID interfaces
-#define CFG_TUH_MSC 1
-#define CFG_TUH_VENDOR 0
-
-// max device support (excluding hub device): 1 hub typically has 4 ports
-#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1)
-
-//------------- HID -------------//
-#define CFG_TUH_HID_EPIN_BUFSIZE 64
-#define CFG_TUH_HID_EPOUT_BUFSIZE 64
-
-//------------- CDC -------------//
-
-// Set Line Control state on enumeration/mounted:
-// DTR ( bit 0), RTS (bit 1)
-#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03
-
-// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t
-// bit rate = 115200, 1 stop bit, no parity, 8 bit data width
-#define CFG_TUH_CDC_LINE_CODING_ON_ENUM { 115200, CDC_LINE_CONDING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 }
-
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_CONFIG_H_ */
diff --git a/examples/host/hid_controller/.only.MCU_LPC175X_6X b/examples/host/hid_controller/.only.MCU_LPC175X_6X
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/hid_controller/.only.MCU_LPC177X_8X b/examples/host/hid_controller/.only.MCU_LPC177X_8X
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/hid_controller/.only.MCU_LPC18XX b/examples/host/hid_controller/.only.MCU_LPC18XX
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/hid_controller/.only.MCU_LPC40XX b/examples/host/hid_controller/.only.MCU_LPC40XX
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/hid_controller/.only.MCU_LPC43XX b/examples/host/hid_controller/.only.MCU_LPC43XX
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/hid_controller/.only.MCU_MIMXRT10XX b/examples/host/hid_controller/.only.MCU_MIMXRT10XX
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/hid_controller/.only.MCU_RP2040 b/examples/host/hid_controller/.only.MCU_RP2040
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/host/hid_controller/CMakeLists.txt b/examples/host/hid_controller/CMakeLists.txt
index c1b500dd8..aaf8bc34f 100644
--- a/examples/host/hid_controller/CMakeLists.txt
+++ b/examples/host/hid_controller/CMakeLists.txt
@@ -1,33 +1,28 @@
-cmake_minimum_required(VERSION 3.17)
+cmake_minimum_required(VERSION 3.5)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
# gets PROJECT name for the example (e.g. -)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-project(${PROJECT} C CXX ASM)
+project(${PROJECT})
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
add_executable(${PROJECT})
# Example source
target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- )
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ )
# Example include
target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_host_example(${PROJECT} noos)
+# Configure compilation flags and libraries for the example... see the corresponding function
+# in hw/bsp/FAMILY/family.cmake for details.
+family_configure_host_example(${PROJECT})
\ No newline at end of file
diff --git a/examples/host/hid_controller/Makefile b/examples/host/hid_controller/Makefile
index e7f603f25..6f59faeee 100644
--- a/examples/host/hid_controller/Makefile
+++ b/examples/host/hid_controller/Makefile
@@ -1,3 +1,4 @@
+include ../../../tools/top.mk
include ../../make.mk
INC += \
@@ -8,7 +9,22 @@ INC += \
EXAMPLE_SOURCE += \
src/hid_app.c \
src/main.c
-
+
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+CFLAGS += -Wno-error=cast-align
+
+# TinyUSB Host Stack source
+SRC_C += \
+ src/class/cdc/cdc_host.c \
+ src/class/hid/hid_host.c \
+ src/class/msc/msc_host.c \
+ src/host/hub.c \
+ src/host/usbh.c \
+ src/host/usbh_control.c \
+ src/portable/ehci/ehci.c \
+ src/portable/ohci/ohci.c \
+ src/portable/nxp/transdimension/hcd_transdimension.c \
+ src/portable/nxp/lpc17_40/hcd_lpc17_40.c
+
include ../../rules.mk
diff --git a/examples/host/hid_controller/only.txt b/examples/host/hid_controller/only.txt
deleted file mode 100644
index fee10f9e2..000000000
--- a/examples/host/hid_controller/only.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-mcu:KINETIS_KL
-mcu:LPC175X_6X
-mcu:LPC177X_8X
-mcu:LPC18XX
-mcu:LPC40XX
-mcu:LPC43XX
-mcu:MIMXRT1XXX
-mcu:MIMXRT10XX
-mcu:MIMXRT11XX
-mcu:RP2040
-mcu:MSP432E4
-mcu:RX65X
-mcu:RAXXX
-mcu:MAX3421
diff --git a/examples/host/hid_controller/src/hid_app.c b/examples/host/hid_controller/src/hid_app.c
index bff830ca2..bbfea8182 100644
--- a/examples/host/hid_controller/src/hid_app.c
+++ b/examples/host/hid_controller/src/hid_app.c
@@ -23,7 +23,7 @@
*
*/
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
/* From https://www.kernel.org/doc/html/latest/input/gamepad.html
@@ -91,8 +91,9 @@ typedef struct TU_ATTR_PACKED
uint8_t counter : 6; // +1 each report
};
- uint8_t l2_trigger; // 0 released, 0xff fully pressed
- uint8_t r2_trigger; // as above
+ // comment out since not used by this example
+ // uint8_t l2_trigger; // 0 released, 0xff fully pressed
+ // uint8_t r2_trigger; // as above
// uint16_t timestamp;
// uint8_t battery;
@@ -104,54 +105,15 @@ typedef struct TU_ATTR_PACKED
} sony_ds4_report_t;
-typedef struct TU_ATTR_PACKED {
- // First 16 bits set what data is pertinent in this structure (1 = set; 0 = not set)
- uint8_t set_rumble : 1;
- uint8_t set_led : 1;
- uint8_t set_led_blink : 1;
- uint8_t set_ext_write : 1;
- uint8_t set_left_volume : 1;
- uint8_t set_right_volume : 1;
- uint8_t set_mic_volume : 1;
- uint8_t set_speaker_volume : 1;
- uint8_t set_flags2;
-
- uint8_t reserved;
-
- uint8_t motor_right;
- uint8_t motor_left;
-
- uint8_t lightbar_red;
- uint8_t lightbar_green;
- uint8_t lightbar_blue;
- uint8_t lightbar_blink_on;
- uint8_t lightbar_blink_off;
-
- uint8_t ext_data[8];
-
- uint8_t volume_left;
- uint8_t volume_right;
- uint8_t volume_mic;
- uint8_t volume_speaker;
-
- uint8_t other[9];
-} sony_ds4_output_report_t;
-
-static bool ds4_mounted = false;
-static uint8_t ds4_dev_addr = 0;
-static uint8_t ds4_instance = 0;
-static uint8_t motor_left = 0;
-static uint8_t motor_right = 0;
-
// check if device is Sony DualShock 4
static inline bool is_sony_ds4(uint8_t dev_addr)
{
uint16_t vid, pid;
tuh_vid_pid_get(dev_addr, &vid, &pid);
- return ( (vid == 0x054c && (pid == 0x09cc || pid == 0x05c4)) // Sony DualShock4
- || (vid == 0x0f0d && pid == 0x005e) // Hori FC4
- || (vid == 0x0f0d && pid == 0x00ee) // Hori PS4 Mini (PS4-099U)
+ return ( (vid == 0x054c && (pid == 0x09cc || pid == 0x05c4)) // Sony DualShock4
+ || (vid == 0x0f0d && pid == 0x005e) // Hori FC4
+ || (vid == 0x0f0d && pid == 0x00ee) // Hori PS4 Mini (PS4-099U)
|| (vid == 0x1f4f && pid == 0x1002) // ASW GG xrd controller
);
}
@@ -162,23 +124,7 @@ static inline bool is_sony_ds4(uint8_t dev_addr)
void hid_app_task(void)
{
- if (ds4_mounted)
- {
- const uint32_t interval_ms = 200;
- static uint32_t start_ms = 0;
-
- uint32_t current_time_ms = board_millis();
- if ( current_time_ms - start_ms >= interval_ms)
- {
- start_ms = current_time_ms;
-
- sony_ds4_output_report_t output_report = {0};
- output_report.set_rumble = 1;
- output_report.motor_left = motor_left;
- output_report.motor_right = motor_right;
- tuh_hid_send_report(ds4_dev_addr, ds4_instance, 5, &output_report, sizeof(output_report));
- }
- }
+ // nothing to do
}
//--------------------------------------------------------------------+
@@ -192,8 +138,6 @@ void hid_app_task(void)
// therefore report_desc = NULL, desc_len = 0
void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len)
{
- (void)desc_report;
- (void)desc_len;
uint16_t vid, pid;
tuh_vid_pid_get(dev_addr, &vid, &pid);
@@ -203,14 +147,6 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
// Sony DualShock 4 [CUH-ZCT2x]
if ( is_sony_ds4(dev_addr) )
{
- if (!ds4_mounted)
- {
- ds4_dev_addr = dev_addr;
- ds4_instance = instance;
- motor_left = 0;
- motor_right = 0;
- ds4_mounted = true;
- }
// request to receive report
// tuh_hid_report_received_cb() will be invoked when report is available
if ( !tuh_hid_receive_report(dev_addr, instance) )
@@ -224,10 +160,7 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance)
{
printf("HID device address = %d, instance = %d is unmounted\r\n", dev_addr, instance);
- if (ds4_mounted && ds4_dev_addr == dev_addr && ds4_instance == instance)
- {
- ds4_mounted = false;
- }
+
}
// check if different than 2
@@ -245,8 +178,8 @@ bool diff_report(sony_ds4_report_t const* rpt1, sony_ds4_report_t const* rpt2)
result = diff_than_2(rpt1->x, rpt2->x) || diff_than_2(rpt1->y , rpt2->y ) ||
diff_than_2(rpt1->z, rpt2->z) || diff_than_2(rpt1->rz, rpt2->rz);
- // check the rest with mem compare
- result |= memcmp(&rpt1->rz + 1, &rpt2->rz + 1, sizeof(sony_ds4_report_t)-6);
+ // check the reset with mem compare
+ result |= memcmp(&rpt1->rz + 1, &rpt2->rz + 1, sizeof(sony_ds4_report_t)-4);
return result;
}
@@ -300,10 +233,6 @@ void process_sony_ds4(uint8_t const* report, uint16_t len)
printf("\r\n");
}
- // The left and right triggers control the intensity of the left and right rumble motors
- motor_left = ds4_report.l2_trigger;
- motor_right = ds4_report.r2_trigger;
-
prev_report = ds4_report;
}
}
diff --git a/examples/host/hid_controller/src/main.c b/examples/host/hid_controller/src/main.c
index 05a5ae176..b9b37a4d2 100644
--- a/examples/host/hid_controller/src/main.c
+++ b/examples/host/hid_controller/src/main.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -32,7 +32,7 @@
#include
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include "tusb.h"
//--------------------------------------------------------------------+
@@ -49,14 +49,9 @@ int main(void)
board_init();
printf("TinyUSB Host HID Controller Example\r\n");
- printf("Note: Events only displayed for explicit supported controllers\r\n");
+ printf("Note: Events only displayed for explictly supported controllers\r\n");
- // init host stack on configured roothub port
- tuh_init(BOARD_TUH_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
+ tusb_init();
while (1)
{
@@ -72,6 +67,8 @@ int main(void)
hid_app_task();
#endif
}
+
+ return 0;
}
//--------------------------------------------------------------------+
diff --git a/examples/host/hid_controller/src/tusb_config.h b/examples/host/hid_controller/src/tusb_config.h
index d37fc02d2..74b471ae4 100644
--- a/examples/host/hid_controller/src/tusb_config.h
+++ b/examples/host/hid_controller/src/tusb_config.h
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -30,48 +30,27 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Board Specific Configuration
-//--------------------------------------------------------------------+
-
- #if CFG_TUSB_MCU == OPT_MCU_RP2040
-// change to 1 if using pico-pio-usb as host controller for raspberry rp2040
-#define CFG_TUH_RPI_PIO_USB 0
-#define BOARD_TUH_RHPORT CFG_TUH_RPI_PIO_USB
-#endif
-
-// RHPort number used for host can be defined by board.mk, default to port 0
-#ifndef BOARD_TUH_RHPORT
-#define BOARD_TUH_RHPORT 0
-#endif
-
-// RHPort max operational speed can defined by board.mk
-#ifndef BOARD_TUH_MAX_SPEED
-#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
-#endif
-
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
// defined by compiler flags for flexibility
#ifndef CFG_TUSB_MCU
-#error CFG_TUSB_MCU must be defined
+ #error CFG_TUSB_MCU must be defined
+#endif
+
+#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | OPT_MODE_HIGH_SPEED)
+#else
+ #define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST
#endif
#ifndef CFG_TUSB_OS
-#define CFG_TUSB_OS OPT_OS_NONE
+#define CFG_TUSB_OS OPT_OS_NONE
#endif
-#ifndef CFG_TUSB_DEBUG
-#define CFG_TUSB_DEBUG 0
-#endif
-
-// Enable Host stack
-#define CFG_TUH_ENABLED 1
-
-// Default is max speed that hardware controller could support with on-chip PHY
-#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED
+// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
+// #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
@@ -80,12 +59,12 @@
* - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") ))
* - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4)))
*/
-#ifndef CFG_TUH_MEM_SECTION
-#define CFG_TUH_MEM_SECTION
+#ifndef CFG_TUSB_MEM_SECTION
+#define CFG_TUSB_MEM_SECTION
#endif
-#ifndef CFG_TUH_MEM_ALIGN
-#define CFG_TUH_MEM_ALIGN __attribute__ ((aligned(4)))
+#ifndef CFG_TUSB_MEM_ALIGN
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
@@ -97,12 +76,13 @@
#define CFG_TUH_HUB 0
#define CFG_TUH_CDC 0
-#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX) // typical keyboard + mouse device can have 3-4 HID interfaces
+#define CFG_TUH_HID 4 // typical keyboard + mouse device can have 3-4 HID interfaces
#define CFG_TUH_MSC 0
#define CFG_TUH_VENDOR 0
-// max device support (excluding hub device): 1 hub typically has 4 ports
-#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1)
+// max device support (excluding hub device)
+// 1 hub typically has 4 ports
+#define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1)
//------------- HID -------------//
diff --git a/examples/host/msc_file_explorer/CMakeLists.txt b/examples/host/msc_file_explorer/CMakeLists.txt
deleted file mode 100644
index 1a57c7466..000000000
--- a/examples/host/msc_file_explorer/CMakeLists.txt
+++ /dev/null
@@ -1,47 +0,0 @@
-cmake_minimum_required(VERSION 3.17)
-
-include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
-
-# gets PROJECT name for the example (e.g. -)
-family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-
-project(${PROJECT} C CXX ASM)
-
-# Checks this example is valid for the family and initializes the project
-family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
-add_executable(${PROJECT})
-
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c
- ${TOP}/lib/fatfs/source/ff.c
- ${TOP}/lib/fatfs/source/ffsystem.c
- ${TOP}/lib/fatfs/source/ffunicode.c
- )
-
-# Suppress warnings on fatfs
-if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- set_source_files_properties(
- ${TOP}/lib/fatfs/source/ff.c
- PROPERTIES
- COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual"
- )
-endif ()
-
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- ${TOP}/lib/fatfs/source
- ${TOP}/lib/embedded-cli
- )
-
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_host_example(${PROJECT} noos)
diff --git a/examples/host/msc_file_explorer/Makefile b/examples/host/msc_file_explorer/Makefile
deleted file mode 100644
index 8319d3c2b..000000000
--- a/examples/host/msc_file_explorer/Makefile
+++ /dev/null
@@ -1,27 +0,0 @@
-include ../../make.mk
-
-FATFS_PATH = lib/fatfs/source
-
-INC += \
- src \
- $(TOP)/hw \
- $(TOP)/$(FATFS_PATH) \
- $(TOP)/lib/embedded-cli \
-
-# Example source
-EXAMPLE_SOURCE = \
- src/main.c \
- src/msc_app.c \
-
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
-
-# FatFS source
-SRC_C += \
- $(FATFS_PATH)/ff.c \
- $(FATFS_PATH)/ffsystem.c \
- $(FATFS_PATH)/ffunicode.c \
-
-# suppress warning caused by fatfs
-CFLAGS += -Wno-error=cast-qual
-
-include ../../rules.mk
diff --git a/examples/host/msc_file_explorer/only.txt b/examples/host/msc_file_explorer/only.txt
deleted file mode 100644
index fee10f9e2..000000000
--- a/examples/host/msc_file_explorer/only.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-mcu:KINETIS_KL
-mcu:LPC175X_6X
-mcu:LPC177X_8X
-mcu:LPC18XX
-mcu:LPC40XX
-mcu:LPC43XX
-mcu:MIMXRT1XXX
-mcu:MIMXRT10XX
-mcu:MIMXRT11XX
-mcu:RP2040
-mcu:MSP432E4
-mcu:RX65X
-mcu:RAXXX
-mcu:MAX3421
diff --git a/examples/host/msc_file_explorer/src/main.c b/examples/host/msc_file_explorer/src/main.c
deleted file mode 100644
index 73f3e9eb5..000000000
--- a/examples/host/msc_file_explorer/src/main.c
+++ /dev/null
@@ -1,132 +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.
- *
- */
-
-/* Example to show how to navigate mass storage device with built-in command line.
- * Type help for list of supported commands and syntax (mostly linux commands)
-
- > help
- * help
- Print list of commands
- * cat
- Usage: cat [FILE]...
- Concatenate FILE(s) to standard output..
- * cd
- Usage: cd [DIR]...
- Change the current directory to DIR.
- * cp
- Usage: cp SOURCE DEST
- Copy SOURCE to DEST.
- * ls
- Usage: ls [DIR]...
- List information about the FILEs (the current directory by default).
- * pwd
- Usage: pwd
- Print the name of the current working directory.
- * mkdir
- Usage: mkdir DIR...
- Create the DIRECTORY(ies), if they do not already exist..
- * mv
- Usage: mv SOURCE DEST...
- Rename SOURCE to DEST.
- * rm
- Usage: rm [FILE]...
- Remove (unlink) the FILE(s).
- */
-
-#include
-#include
-#include
-
-#include "bsp/board_api.h"
-#include "tusb.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF PROTYPES
-//--------------------------------------------------------------------+
-void led_blinking_task(void);
-
-// from msc_app.c
-extern bool msc_app_init(void);
-extern void msc_app_task(void);
-
-/*------------- MAIN -------------*/
-int main(void)
-{
- board_init();
-
- printf("TinyUSB Host MassStorage Explorer Example\r\n");
-
- // init host stack on configured roothub port
- tuh_init(BOARD_TUH_RHPORT);
-
- if (board_init_after_tusb) {
- board_init_after_tusb();
- }
-
- msc_app_init();
-
- while (1)
- {
- // tinyusb host task
- tuh_task();
-
- msc_app_task();
- led_blinking_task();
- }
-
- return 0;
-}
-
-//--------------------------------------------------------------------+
-// TinyUSB Callbacks
-//--------------------------------------------------------------------+
-
-void tuh_mount_cb(uint8_t dev_addr)
-{
- (void) dev_addr;
-}
-
-void tuh_umount_cb(uint8_t dev_addr)
-{
- (void) dev_addr;
-}
-
-//--------------------------------------------------------------------+
-// Blinking Task
-//--------------------------------------------------------------------+
-void led_blinking_task(void)
-{
- const uint32_t interval_ms = 1000;
- static uint32_t start_ms = 0;
-
- static bool led_state = false;
-
- // Blink every interval ms
- if ( board_millis() - start_ms < interval_ms) return; // not enough time
- start_ms += interval_ms;
-
- board_led_write(led_state);
- led_state = 1 - led_state; // toggle
-}
diff --git a/examples/host/msc_file_explorer/src/msc_app.c b/examples/host/msc_file_explorer/src/msc_app.c
deleted file mode 100644
index ecea614a2..000000000
--- a/examples/host/msc_file_explorer/src/msc_app.c
+++ /dev/null
@@ -1,643 +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.
- *
- */
-
-#include
-#include "tusb.h"
-#include "bsp/board_api.h"
-
-#include "ff.h"
-#include "diskio.h"
-
-// lib/embedded-cli
-#define EMBEDDED_CLI_IMPL
-#include "embedded_cli.h"
-
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM DECLARATION
-//--------------------------------------------------------------------+
-
-//------------- embedded-cli -------------//
-#define CLI_BUFFER_SIZE 512
-#define CLI_RX_BUFFER_SIZE 16
-#define CLI_CMD_BUFFER_SIZE 64
-#define CLI_HISTORY_SIZE 32
-#define CLI_BINDING_COUNT 8
-
-static EmbeddedCli *_cli;
-static CLI_UINT cli_buffer[BYTES_TO_CLI_UINTS(CLI_BUFFER_SIZE)];
-
-//------------- Elm Chan FatFS -------------//
-static FATFS fatfs[CFG_TUH_DEVICE_MAX]; // for simplicity only support 1 LUN per device
-static volatile bool _disk_busy[CFG_TUH_DEVICE_MAX];
-
-static scsi_inquiry_resp_t inquiry_resp;
-
-//--------------------------------------------------------------------+
-//
-//--------------------------------------------------------------------+
-
-bool cli_init(void);
-
-bool msc_app_init(void)
-{
- for(size_t i=0; i 0 )
- {
- while( ch > 0 )
- {
- embeddedCliReceiveChar(_cli, (char) ch);
- ch = board_getchar();
- }
- embeddedCliProcess(_cli);
- }
-}
-
-//--------------------------------------------------------------------+
-//
-//--------------------------------------------------------------------+
-
-
-bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
-{
- msc_cbw_t const* cbw = cb_data->cbw;
- msc_csw_t const* csw = cb_data->csw;
-
- if (csw->status != 0)
- {
- printf("Inquiry failed\r\n");
- return false;
- }
-
- // Print out Vendor ID, Product ID and Rev
- printf("%.8s %.16s rev %.4s\r\n", inquiry_resp.vendor_id, inquiry_resp.product_id, inquiry_resp.product_rev);
-
- // Get capacity of device
- uint32_t const block_count = tuh_msc_get_block_count(dev_addr, cbw->lun);
- uint32_t const block_size = tuh_msc_get_block_size(dev_addr, cbw->lun);
-
- printf("Disk Size: %lu MB\r\n", block_count / ((1024*1024)/block_size));
- // printf("Block Count = %lu, Block Size: %lu\r\n", block_count, block_size);
-
- // For simplicity: we only mount 1 LUN per device
- uint8_t const drive_num = dev_addr-1;
- char drive_path[3] = "0:";
- drive_path[0] += drive_num;
-
- if ( f_mount(&fatfs[drive_num], drive_path, 1) != FR_OK )
- {
- puts("mount failed");
- }
-
- // change to newly mounted drive
- f_chdir(drive_path);
-
- // print the drive label
-// char label[34];
-// if ( FR_OK == f_getlabel(drive_path, label, NULL) )
-// {
-// puts(label);
-// }
-
- return true;
-}
-
-//------------- IMPLEMENTATION -------------//
-void tuh_msc_mount_cb(uint8_t dev_addr)
-{
- printf("A MassStorage device is mounted\r\n");
-
- uint8_t const lun = 0;
- tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, inquiry_complete_cb, 0);
-}
-
-void tuh_msc_umount_cb(uint8_t dev_addr)
-{
- printf("A MassStorage device is unmounted\r\n");
-
- uint8_t const drive_num = dev_addr-1;
- char drive_path[3] = "0:";
- drive_path[0] += drive_num;
-
- f_unmount(drive_path);
-
-// if ( phy_disk == f_get_current_drive() )
-// { // active drive is unplugged --> change to other drive
-// for(uint8_t i=0; iname);
-}
-
-bool cli_init(void)
-{
- EmbeddedCliConfig *config = embeddedCliDefaultConfig();
- config->cliBuffer = cli_buffer;
- config->cliBufferSize = CLI_BUFFER_SIZE;
- config->rxBufferSize = CLI_RX_BUFFER_SIZE;
- config->cmdBufferSize = CLI_CMD_BUFFER_SIZE;
- config->historyBufferSize = CLI_HISTORY_SIZE;
- config->maxBindingCount = CLI_BINDING_COUNT;
-
- TU_ASSERT(embeddedCliRequiredSize(config) <= CLI_BUFFER_SIZE);
-
- _cli = embeddedCliNew(config);
- TU_ASSERT(_cli != NULL);
-
- _cli->writeChar = cli_write_char;
-
- embeddedCliAddBinding(_cli, (CliCommandBinding) {
- "cat",
- "Usage: cat [FILE]...\r\n\tConcatenate FILE(s) to standard output..",
- true,
- NULL,
- cli_cmd_cat
- });
-
- embeddedCliAddBinding(_cli, (CliCommandBinding) {
- "cd",
- "Usage: cd [DIR]...\r\n\tChange the current directory to DIR.",
- true,
- NULL,
- cli_cmd_cd
- });
-
- embeddedCliAddBinding(_cli, (CliCommandBinding) {
- "cp",
- "Usage: cp SOURCE DEST\r\n\tCopy SOURCE to DEST.",
- true,
- NULL,
- cli_cmd_cp
- });
-
- embeddedCliAddBinding(_cli, (CliCommandBinding) {
- "ls",
- "Usage: ls [DIR]...\r\n\tList information about the FILEs (the current directory by default).",
- true,
- NULL,
- cli_cmd_ls
- });
-
- embeddedCliAddBinding(_cli, (CliCommandBinding) {
- "pwd",
- "Usage: pwd\r\n\tPrint the name of the current working directory.",
- true,
- NULL,
- cli_cmd_pwd
- });
-
- embeddedCliAddBinding(_cli, (CliCommandBinding) {
- "mkdir",
- "Usage: mkdir DIR...\r\n\tCreate the DIRECTORY(ies), if they do not already exist..",
- true,
- NULL,
- cli_cmd_mkdir
- });
-
- embeddedCliAddBinding(_cli, (CliCommandBinding) {
- "mv",
- "Usage: mv SOURCE DEST...\r\n\tRename SOURCE to DEST.",
- true,
- NULL,
- cli_cmd_mv
- });
-
- embeddedCliAddBinding(_cli, (CliCommandBinding) {
- "rm",
- "Usage: rm [FILE]...\r\n\tRemove (unlink) the FILE(s).",
- true,
- NULL,
- cli_cmd_rm
- });
-
- return true;
-}
-
-void cli_cmd_cat(EmbeddedCli *cli, char *args, void *context)
-{
- (void) cli; (void) context;
-
- uint16_t argc = embeddedCliGetTokenCount(args);
-
- // need at least 1 argument
- if ( argc == 0 )
- {
- printf("invalid arguments\r\n");
- return;
- }
-
- for(uint16_t i=0; i 0) )
- {
- for(UINT c = 0; c < count; c++)
- {
- const uint8_t ch = buf[c];
- if (isprint(ch) || iscntrl(ch))
- {
- putchar(ch);
- }else
- {
- putchar('.');
- }
- }
- }
- }
-
- f_close(&fi);
- }
-}
-
-void cli_cmd_cd(EmbeddedCli *cli, char *args, void *context)
-{
- (void) cli; (void) context;
-
- uint16_t argc = embeddedCliGetTokenCount(args);
-
- // only support 1 argument
- if ( argc != 1 )
- {
- printf("invalid arguments\r\n");
- return;
- }
-
- // default is current directory
- const char* dpath = args;
-
- if ( FR_OK != f_chdir(dpath) )
- {
- printf("%s: No such file or directory\r\n", dpath);
- return;
- }
-}
-
-void cli_cmd_cp(EmbeddedCli *cli, char *args, void *context)
-{
- (void) cli; (void) context;
-
- uint16_t argc = embeddedCliGetTokenCount(args);
- if ( argc != 2 )
- {
- printf("invalid arguments\r\n");
- return;
- }
-
- // default is current directory
- const char* src = embeddedCliGetToken(args, 1);
- const char* dst = embeddedCliGetToken(args, 2);
-
- FIL f_src;
- FIL f_dst;
-
- if ( FR_OK != f_open(&f_src, src, FA_READ) )
- {
- printf("cannot stat '%s': No such file or directory\r\n", src);
- return;
- }
-
- if ( FR_OK != f_open(&f_dst, dst, FA_WRITE | FA_CREATE_ALWAYS) )
- {
- printf("cannot create '%s'\r\n", dst);
- return;
- }else
- {
- uint8_t buf[512];
- UINT rd_count = 0;
- while ( (FR_OK == f_read(&f_src, buf, sizeof(buf), &rd_count)) && (rd_count > 0) )
- {
- UINT wr_count = 0;
-
- if ( FR_OK != f_write(&f_dst, buf, rd_count, &wr_count) )
- {
- printf("cannot write to '%s'\r\n", dst);
- break;
- }
- }
- }
-
- f_close(&f_src);
- f_close(&f_dst);
-}
-
-void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context)
-{
- (void) cli; (void) context;
-
- uint16_t argc = embeddedCliGetTokenCount(args);
-
- // only support 1 argument
- if ( argc > 1 )
- {
- printf("invalid arguments\r\n");
- return;
- }
-
- // default is current directory
- const char* dpath = ".";
- if (argc) dpath = args;
-
- DIR dir;
- if ( FR_OK != f_opendir(&dir, dpath) )
- {
- printf("cannot access '%s': No such file or directory\r\n", dpath);
- return;
- }
-
- FILINFO fno;
- while( (f_readdir(&dir, &fno) == FR_OK) && (fno.fname[0] != 0) )
- {
- if ( fno.fname[0] != '.' ) // ignore . and .. entry
- {
- if ( fno.fattrib & AM_DIR )
- {
- // directory
- printf("/%s\r\n", fno.fname);
- }else
- {
- printf("%-40s", fno.fname);
- if (fno.fsize < 1024)
- {
- printf("%lu B\r\n", fno.fsize);
- }else
- {
- printf("%lu KB\r\n", fno.fsize / 1024);
- }
- }
- }
- }
-
- f_closedir(&dir);
-}
-
-void cli_cmd_pwd(EmbeddedCli *cli, char *args, void *context)
-{
- (void) cli; (void) context;
- uint16_t argc = embeddedCliGetTokenCount(args);
-
- if (argc != 0)
- {
- printf("invalid arguments\r\n");
- return;
- }
-
- char path[256];
- if (FR_OK != f_getcwd(path, sizeof(path)))
- {
- printf("cannot get current working directory\r\n");
- }
-
- puts(path);
-}
-
-void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context)
-{
- (void) cli; (void) context;
-
- uint16_t argc = embeddedCliGetTokenCount(args);
-
- // only support 1 argument
- if ( argc != 1 )
- {
- printf("invalid arguments\r\n");
- return;
- }
-
- // default is current directory
- const char* dpath = args;
-
- if ( FR_OK != f_mkdir(dpath) )
- {
- printf("%s: cannot create this directory\r\n", dpath);
- return;
- }
-}
-
-void cli_cmd_mv(EmbeddedCli *cli, char *args, void *context)
-{
- (void) cli; (void) context;
-
- uint16_t argc = embeddedCliGetTokenCount(args);
- if ( argc != 2 )
- {
- printf("invalid arguments\r\n");
- return;
- }
-
- // default is current directory
- const char* src = embeddedCliGetToken(args, 1);
- const char* dst = embeddedCliGetToken(args, 2);
-
- if ( FR_OK != f_rename(src, dst) )
- {
- printf("cannot mv %s to %s\r\n", src, dst);
- return;
- }
-}
-
-void cli_cmd_rm(EmbeddedCli *cli, char *args, void *context)
-{
- (void) cli; (void) context;
-
- uint16_t argc = embeddedCliGetTokenCount(args);
-
- // need at least 1 argument
- if ( argc == 0 )
- {
- printf("invalid arguments\r\n");
- return;
- }
-
- for(uint16_t i=0; i $@
- @echo loadfile $^ >> $@
- @echo r >> $@
- @echo go >> $@
- @echo exit >> $@
-
# Flash using jlink
-flash-jlink: $(BUILD)/$(BOARD).jlink
- $(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $<
+flash-jlink: $(BUILD)/$(PROJECT).hex
+ @echo halt > $(BUILD)/$(BOARD).jlink
+ @echo r > $(BUILD)/$(BOARD).jlink
+ @echo loadfile $^ >> $(BUILD)/$(BOARD).jlink
+ @echo r >> $(BUILD)/$(BOARD).jlink
+ @echo go >> $(BUILD)/$(BOARD).jlink
+ @echo exit >> $(BUILD)/$(BOARD).jlink
+ $(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink
-# --------------- stm32 cube programmer -----------------
-# Flash STM32 MCU using stlink with STM32 Cube Programmer CLI
+# flash STM32 MCU using stlink with STM32 Cube Programmer CLI
flash-stlink: $(BUILD)/$(PROJECT).elf
STM32_Programmer_CLI --connect port=swd --write $< --go
-# --------------- xfel -----------------
-$(BUILD)/$(PROJECT)-sunxi.bin: $(BUILD)/$(PROJECT).bin
- $(PYTHON) $(TOP)/tools/mksunxi.py $< $@
-
-flash-xfel: $(BUILD)/$(PROJECT)-sunxi.bin
- xfel spinor write 0 $<
- xfel reset
-
-# --------------- pyocd -----------------
+# flash with pyocd
PYOCD_OPTION ?=
flash-pyocd: $(BUILD)/$(PROJECT).hex
pyocd flash -t $(PYOCD_TARGET) $(PYOCD_OPTION) $<
- #pyocd reset -t $(PYOCD_TARGET)
+ pyocd reset -t $(PYOCD_TARGET)
-# --------------- openocd -----------------
-OPENOCD_OPTION ?=
-flash-openocd: $(BUILD)/$(PROJECT).elf
- openocd $(OPENOCD_OPTION) -c "program $< verify reset exit"
+# flash with Black Magic Probe
-# --------------- dfu-util -----------------
-DFU_UTIL_OPTION ?= -a 0
-flash-dfu-util: $(BUILD)/$(PROJECT).bin
- dfu-util -R $(DFU_UTIL_OPTION) -D $<
-
-# --------------- Black Magic -----------------
# This symlink is created by https://github.com/blacksphere/blackmagic/blob/master/driver/99-blackmagic.rules
BMP ?= /dev/ttyBmpGdb
@@ -153,11 +202,7 @@ debug-bmp: $(BUILD)/$(PROJECT).elf
# Create binary directory
$(BIN):
-ifeq ($(CMDEXE),1)
- @$(MKDIR) $(subst /,\,$@)
-else
@$(MKDIR) -p $@
-endif
# Copy binaries .elf, .bin, .hex, .uf2 to BIN for upload
# due to large size of combined artifacts, only uf2 is uploaded for now
@@ -170,4 +215,4 @@ copy-artifact: $(BIN)
# Print out the value of a make variable.
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
print-%:
- @echo $* = $($*)
+ @echo $* = $($*)
\ No newline at end of file
diff --git a/examples/typec/CMakeLists.txt b/examples/typec/CMakeLists.txt
deleted file mode 100644
index c7641494e..000000000
--- a/examples/typec/CMakeLists.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-cmake_minimum_required(VERSION 3.17)
-
-include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/family_support.cmake)
-
-project(tinyusb_host_examples C CXX ASM)
-family_initialize_project(tinyusb_host_examples ${CMAKE_CURRENT_LIST_DIR})
-
-# family_add_subdirectory will filter what to actually add based on selected FAMILY
-family_add_subdirectory(power_delivery)
diff --git a/examples/typec/power_delivery/CMakeLists.txt b/examples/typec/power_delivery/CMakeLists.txt
deleted file mode 100644
index 012eff095..000000000
--- a/examples/typec/power_delivery/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-cmake_minimum_required(VERSION 3.17)
-
-include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
-
-# gets PROJECT name for the example (e.g. -)
-family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
-
-project(${PROJECT} C CXX ASM)
-
-# Checks this example is valid for the family and initializes the project
-family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
-
-# Espressif has its own cmake build system
-if(FAMILY STREQUAL "espressif")
- return()
-endif()
-
-add_executable(${PROJECT})
-
-# Example source
-target_sources(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
- )
-
-# Example include
-target_include_directories(${PROJECT} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/src
- )
-
-# Configure compilation flags and libraries for the example without RTOS.
-# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_device_example(${PROJECT} noos)
diff --git a/examples/typec/power_delivery/Makefile b/examples/typec/power_delivery/Makefile
deleted file mode 100644
index 2a3d854fb..000000000
--- a/examples/typec/power_delivery/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-include ../../make.mk
-
-INC += \
- src \
- $(TOP)/hw \
-
-# Example source
-EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
-
-include ../../rules.mk
diff --git a/examples/typec/power_delivery/only.txt b/examples/typec/power_delivery/only.txt
deleted file mode 100644
index 657aeaac5..000000000
--- a/examples/typec/power_delivery/only.txt
+++ /dev/null
@@ -1 +0,0 @@
-mcu:STM32G4
diff --git a/examples/typec/power_delivery/src/main.c b/examples/typec/power_delivery/src/main.c
deleted file mode 100644
index 489d01aa1..000000000
--- a/examples/typec/power_delivery/src/main.c
+++ /dev/null
@@ -1,193 +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.
- *
- */
-
-#include
-#include
-#include
-
-#include "bsp/board_api.h"
-#include "tusb.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF PROTOTYPES
-//--------------------------------------------------------------------+
-
-// Voltage and current for selecting PDO
-// DANGEROUS: Please make sure your board can withstand the voltage and current
-// defined here. Otherwise, you may damage your board, smoke can come out
-#define VOLTAGE_MAX_MV 5000 // maximum voltage in mV
-#define CURRENT_MAX_MA 500 // maximum current in mA
-#define CURRENT_OPERATING_MA 100 // operating current in mA
-
-/* Blink pattern
- * - 250 ms : button is not pressed
- * - 1000 ms : button is pressed (and hold)
- */
-enum {
- BLINK_PRESSED = 250,
- BLINK_UNPRESSED = 1000
-};
-
-static uint32_t blink_interval_ms = BLINK_UNPRESSED;
-
-void led_blinking_task(void);
-
-#define HELLO_STR "Hello from TinyUSB\r\n"
-
-int main(void)
-{
- board_init();
- board_led_write(true);
-
- tuc_init(0, TUSB_TYPEC_PORT_SNK);
-
- while (1) {
- led_blinking_task();
-
- // tinyusb typec task
- tuc_task();
- }
-}
-
-#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
-void app_main(void)
-{
- main();
-}
-#endif
-
-//--------------------------------------------------------------------+
-// TypeC PD callbacks
-//--------------------------------------------------------------------+
-
-bool tuc_pd_data_received_cb(uint8_t rhport, pd_header_t const* header, uint8_t const* dobj, uint8_t const* p_end) {
- switch (header->msg_type) {
- case PD_DATA_SOURCE_CAP: {
- printf("PD Source Capabilities\r\n");
- // Examine source capability and select a suitable PDO (starting from 1 with safe5v)
- uint8_t selected_pos = 1;
-
- for(size_t i=0; in_data_obj; i++) {
- TU_VERIFY(dobj < p_end);
- uint32_t const pdo = tu_le32toh(tu_unaligned_read32(dobj));
-
- switch ((pdo >> 30) & 0x03ul) {
- case PD_PDO_TYPE_FIXED: {
- pd_pdo_fixed_t const* fixed = (pd_pdo_fixed_t const*) &pdo;
- uint32_t const voltage_mv = fixed->voltage_50mv*50;
- uint32_t const current_ma = fixed->current_max_10ma*10;
- printf("[Fixed] %lu mV %lu mA\r\n", voltage_mv, current_ma);
-
- if (voltage_mv <= VOLTAGE_MAX_MV && current_ma >= CURRENT_MAX_MA) {
- // Found a suitable PDO
- selected_pos = i+1;
- }
-
- break;
- }
-
- case PD_PDO_TYPE_BATTERY:
- break;
-
- case PD_PDO_TYPE_VARIABLE:
- break;
-
- case PD_PDO_TYPE_APDO:
- break;
- }
-
- dobj += 4;
- }
-
- //------------- Response with selected PDO -------------//
- // Be careful and make sure your board can withstand the selected PDO
- // voltage other than safe5v e.g 12v or 20v
-
- printf("Selected PDO %u\r\n", selected_pos);
-
- // Send request with selected PDO position as response to Source Cap
- pd_rdo_fixed_variable_t rdo = {
- .current_extremum_10ma = 50, // max 500mA
- .current_operate_10ma = 30, // 300mA
- .reserved = 0,
- .epr_mode_capable = 0,
- .unchunked_ext_msg_support = 0,
- .no_usb_suspend = 0,
- .usb_comm_capable = 1,
- .capability_mismatch = 0,
- .give_back_flag = 0, // exteremum is max
- .object_position = selected_pos,
- };
- tuc_msg_request(rhport, &rdo);
-
- break;
- }
-
- default: break;
- }
-
- return true;
-}
-
-bool tuc_pd_control_received_cb(uint8_t rhport, pd_header_t const* header) {
- (void) rhport;
- switch (header->msg_type) {
- case PD_CTRL_ACCEPT:
- printf("PD Request Accepted\r\n");
- // preparing for power transition
- break;
-
- case PD_CTRL_REJECT:
- printf("PD Request Rejected\r\n");
- // try to negotiate further power
- break;
-
- case PD_CTRL_PS_READY:
- printf("PD Power Ready\r\n");
- // Source is ready to supply power
- break;
-
- default:
- break;
- }
-
- return true;
-}
-
-//--------------------------------------------------------------------+
-// BLINKING TASK
-//--------------------------------------------------------------------+
-void led_blinking_task(void)
-{
- static uint32_t start_ms = 0;
- static bool led_state = false;
-
- // Blink every interval ms
- if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
- start_ms += blink_interval_ms;
-
- board_led_write(led_state);
- led_state = 1 - led_state; // toggle
-}
diff --git a/examples/typec/power_delivery/src/tusb_config.h b/examples/typec/power_delivery/src/tusb_config.h
deleted file mode 100644
index f7cb3cc04..000000000
--- a/examples/typec/power_delivery/src/tusb_config.h
+++ /dev/null
@@ -1,83 +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 _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------
-// COMMON CONFIGURATION
-//--------------------------------------------------------------------
-
-// defined by compiler flags for flexibility
-#ifndef CFG_TUSB_MCU
- #error CFG_TUSB_MCU must be defined
-#endif
-
-#ifndef CFG_TUSB_OS
- #define CFG_TUSB_OS OPT_OS_NONE
-#endif
-
-#define CFG_TUD_ENABLED 0
-#define CFG_TUH_ENABLED 0
-
-// Enable TYPEC stack
-#define CFG_TUC_ENABLED 1
-
-
-// special example that doesn't enable device or host stack
-// This can cause some TinyUSB API missing, this define hack to allow us to fill those API
-// to pass the compilation process
-#if CFG_TUD_ENABLED == 0
-#define tud_int_handler(x)
-#endif
-
-
-// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
-// #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
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_CONFIG_H_ */
diff --git a/hw/bsp/ansi_escape.h b/hw/bsp/ansi_escape.h
index 15af2f3ab..35342cfe5 100644
--- a/hw/bsp/ansi_escape.h
+++ b/hw/bsp/ansi_escape.h
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -25,7 +25,7 @@
*/
/** \ingroup group_board
- * \defgroup group_ansi_esc ANSI Escape Code
+ * \defgroup group_ansi_esc ANSI Esacpe Code
* @{ */
#ifndef _TUSB_ANSI_ESC_CODE_H_
diff --git a/hw/bsp/board.c b/hw/bsp/board.c
index 562792625..6a26f55b7 100644
--- a/hw/bsp/board.c
+++ b/hw/bsp/board.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
@@ -23,15 +23,62 @@
*
*/
-#include "board_api.h"
+#include "board.h"
+
+#if 0
+#define LED_PHASE_MAX 8
+
+static struct
+{
+ uint32_t phase[LED_PHASE_MAX];
+ uint8_t phase_count;
+
+ bool led_state;
+ uint8_t current_phase;
+ uint32_t current_ms;
+}led_pattern;
+
+void board_led_pattern(uint32_t const phase_ms[], uint8_t count)
+{
+ memcpy(led_pattern.phase, phase_ms, 4*count);
+ led_pattern.phase_count = count;
+
+ // reset with 1st phase is on
+ led_pattern.current_ms = board_millis();
+ led_pattern.current_phase = 0;
+ led_pattern.led_state = true;
+ board_led_on();
+}
+
+void board_led_task(void)
+{
+ if ( led_pattern.phase_count == 0 ) return;
+
+ uint32_t const duration = led_pattern.phase[led_pattern.current_phase];
+
+ // return if not enough time
+ if (board_millis() - led_pattern.current_ms < duration) return;
+
+ led_pattern.led_state = !led_pattern.led_state;
+ board_led_write(led_pattern.led_state);
+
+ led_pattern.current_ms += duration;
+ led_pattern.current_phase++;
+
+ if (led_pattern.current_phase == led_pattern.phase_count)
+ {
+ led_pattern.current_phase = 0;
+ led_pattern.led_state = true;
+ board_led_on();
+ }
+}
+#endif
//--------------------------------------------------------------------+
// newlib read()/write() retarget
//--------------------------------------------------------------------+
-#ifdef __ICCARM__
- #define sys_write __write
- #define sys_read __read
-#elif defined(__MSP430__) || defined(__RX__)
+
+#if defined(__MSP430__) || defined(__RX__)
#define sys_write write
#define sys_read read
#else
@@ -44,21 +91,20 @@
// If using SES IDE, use the Syscalls/SEGGER_RTT_Syscalls_SES.c instead
#if !(defined __SES_ARM) && !(defined __SES_RISCV) && !(defined __CROSSWORKS_ARM)
-
#include "SEGGER_RTT.h"
-TU_ATTR_USED int sys_write(int fhdl, const void *buf, size_t count) {
+TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
+{
(void) fhdl;
- SEGGER_RTT_Write(0, (const char *) buf, (int) count);
+ SEGGER_RTT_Write(0, (char*) buf, (int) count);
return count;
}
-TU_ATTR_USED int sys_read(int fhdl, char *buf, size_t count) {
+TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
+{
(void) fhdl;
- int rd = (int) SEGGER_RTT_Read(0, buf, count);
- return (rd > 0) ? rd : -1;
+ return SEGGER_RTT_Read(0, buf, count);
}
-
#endif
#elif defined(LOGGER_SWO)
@@ -66,41 +112,36 @@ TU_ATTR_USED int sys_read(int fhdl, char *buf, size_t count) {
#include "board_mcu.h"
-TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count) {
+TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
+{
(void) fhdl;
uint8_t const* buf8 = (uint8_t const*) buf;
-
- for(size_t i=0; i 0) ? rd : -1;
+ return board_uart_read((uint8_t*) buf, count);
}
#endif
-
-int board_getchar(void) {
- char c;
- return (sys_read(0, &c, 1) > 0) ? (int) c : (-1);
-}
diff --git a/hw/bsp/board_api.h b/hw/bsp/board.h
similarity index 50%
rename from hw/bsp/board_api.h
rename to hw/bsp/board.h
index a7dcabfcc..782e0939c 100644
--- a/hw/bsp/board_api.h
+++ b/hw/bsp/board.h
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -24,22 +24,24 @@
* This file is part of the TinyUSB stack.
*/
-#ifndef _BOARD_API_H_
-#define _BOARD_API_H_
+/** \ingroup group_demo
+ * \defgroup group_board Boards Abstraction Layer
+ * @{ */
+
+#ifndef _BSP_BOARD_H_
+#define _BSP_BOARD_H_
#ifdef __cplusplus
-extern "C" {
+ extern "C" {
#endif
#include
#include
+#include "ansi_escape.h"
#include "tusb.h"
-// Define the default baudrate
-#ifndef CFG_BOARD_UART_BAUDRATE
-#define CFG_BOARD_UART_BAUDRATE 115200 ///< Default baud rate
-#endif
+#define CFG_BOARD_UART_BAUDRATE 115200
//--------------------------------------------------------------------+
// Board Porting API
@@ -49,9 +51,6 @@ extern "C" {
// Initialize on-board peripherals : led, button, uart and USB
void board_init(void);
-// Init board after tinyusb is initialized
-void board_init_after_tusb(void) TU_ATTR_WEAK;
-
// Turn LED on or off
void board_led_write(bool state);
@@ -63,39 +62,40 @@ void board_led_write(bool state);
// a '1' means active (pressed), a '0' means inactive.
uint32_t board_button_read(void);
-// Get board unique ID for USB serial number. Return number of bytes. Note max_len is typically 16
-TU_ATTR_WEAK size_t board_get_unique_id(uint8_t id[], size_t max_len);
+// Get characters from UART
+int board_uart_read(uint8_t* buf, int len);
-// Get characters from UART. Return number of read bytes
-int board_uart_read(uint8_t *buf, int len);
-
-// Send characters to UART. Return number of sent bytes
-int board_uart_write(void const *buf, int len);
+// Send characters to UART
+int board_uart_write(void const * buf, int len);
#if CFG_TUSB_OS == OPT_OS_NONE
-// Get current milliseconds, must be implemented when no RTOS is used
-uint32_t board_millis(void);
+ // Get current milliseconds, must be implemented when no RTOS is used
+ uint32_t board_millis(void);
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
-static inline uint32_t board_millis(void) {
- return ( ( ((uint64_t) xTaskGetTickCount()) * 1000) / configTICK_RATE_HZ );
-}
+ static inline uint32_t board_millis(void)
+ {
+ return ( ( ((uint64_t) xTaskGetTickCount()) * 1000) / configTICK_RATE_HZ );
+ }
#elif CFG_TUSB_OS == OPT_OS_MYNEWT
-static inline uint32_t board_millis(void) {
- return os_time_ticks_to_ms32( os_time_get() );
-}
+ static inline uint32_t board_millis(void)
+ {
+ return os_time_ticks_to_ms32( os_time_get() );
+ }
#elif CFG_TUSB_OS == OPT_OS_PICO
-#include "pico/time.h"
-static inline uint32_t board_millis(void) {
- return to_ms_since_boot(get_absolute_time());
-}
+ #include "pico/time.h"
+ static inline uint32_t board_millis(void)
+ {
+ return to_ms_since_boot(get_absolute_time());
+ }
#elif CFG_TUSB_OS == OPT_OS_RTTHREAD
-static inline uint32_t board_millis(void) {
- return (((uint64_t)rt_tick_get()) * 1000 / RT_TICK_PER_SECOND);
-}
+ static inline uint32_t board_millis(void)
+ {
+ return (((uint64_t)rt_tick_get()) * 1000 / RT_TICK_PER_SECOND);
+ }
#else
#error "board_millis() is not implemented for this OS"
@@ -104,66 +104,44 @@ static inline uint32_t board_millis(void) {
//--------------------------------------------------------------------+
// Helper functions
//--------------------------------------------------------------------+
-static inline void board_led_on(void) {
+static inline void board_led_on(void)
+{
board_led_write(true);
}
-static inline void board_led_off(void) {
+static inline void board_led_off(void)
+{
board_led_write(false);
}
-// Get USB Serial number string from unique ID if available. Return number of character.
-// Input is string descriptor from index 1 (index 0 is type + len)
-static inline size_t board_usb_get_serial(uint16_t desc_str1[], size_t max_chars) {
- uint8_t uid[16] TU_ATTR_ALIGNED(4);
- size_t uid_len;
-
- if ( board_get_unique_id ) {
- uid_len = board_get_unique_id(uid, sizeof(uid));
- }else {
- // fixed serial string is 01234567889ABCDEF
- uint32_t* uid32 = (uint32_t*) (uintptr_t) uid;
- uid32[0] = 0x67452301;
- uid32[1] = 0xEFCDAB89;
- uid_len = 8;
- }
-
- if ( uid_len > max_chars / 2 ) uid_len = max_chars / 2;
-
- for ( size_t i = 0; i < uid_len; i++ ) {
- for ( size_t j = 0; j < 2; j++ ) {
- const char nibble_to_hex[16] = {
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
- };
- uint8_t const nibble = (uid[i] >> (j * 4)) & 0xf;
- desc_str1[i * 2 + (1 - j)] = nibble_to_hex[nibble]; // UTF-16-LE
- }
- }
-
- return 2 * uid_len;
-}
-
// TODO remove
-static inline void board_delay(uint32_t ms) {
+static inline void board_delay(uint32_t ms)
+{
uint32_t start_ms = board_millis();
- while ( board_millis() - start_ms < ms ) {
+ while (board_millis() - start_ms < ms)
+ {
+ #if TUSB_OPT_DEVICE_ENABLED
// take chance to run usb background
- #if CFG_TUD_ENABLED
tud_task();
#endif
-
- #if CFG_TUH_ENABLED
- tuh_task();
- #endif
}
}
-// stdio getchar() is blocking, this is non-blocking version
-int board_getchar(void);
+static inline int board_uart_getchar(void)
+{
+ uint8_t c;
+ return board_uart_read(&c, 1) ? (int) c : (-1);
+}
+
+static inline int board_uart_putchar(uint8_t c)
+{
+ return board_uart_write(&c, 1);
+}
#ifdef __cplusplus
-}
+ }
#endif
-#endif
+#endif /* _BSP_BOARD_H_ */
+
+/** @} */
diff --git a/hw/bsp/board_mcu.h b/hw/bsp/board_mcu.h
index e5d2bb608..a4d57597c 100644
--- a/hw/bsp/board_mcu.h
+++ b/hw/bsp/board_mcu.h
@@ -31,23 +31,23 @@
#include "tusb_option.h"
//--------------------------------------------------------------------+
-// Low Level MCU header include. Example should be
-// platform independent and mostly doesn't need to include this file.
+// Low Level MCU header include. TinyUSB stack and example should be
+// platform independent and mostly doens't need to include this file.
// However there are still certain situation where this file is needed:
// - FreeRTOSConfig.h to set up correct clock and NVIC interrupts for ARM Cortex
// - SWO logging for Cortex M with ITM_SendChar() / ITM_ReceiveChar()
//--------------------------------------------------------------------+
// Include order follows OPT_MCU_ number
-#if TU_CHECK_MCU(OPT_MCU_LPC11UXX, OPT_MCU_LPC13XX, OPT_MCU_LPC15XX) || \
- TU_CHECK_MCU(OPT_MCU_LPC175X_6X, OPT_MCU_LPC177X_8X, OPT_MCU_LPC18XX) || \
- TU_CHECK_MCU(OPT_MCU_LPC40XX, OPT_MCU_LPC43XX)
+#if CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13XX || \
+ CFG_TUSB_MCU == OPT_MCU_LPC15XX || CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || \
+ CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC18XX || \
+ CFG_TUSB_MCU == OPT_MCU_LPC40XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX
#include "chip.h"
-#elif TU_CHECK_MCU(OPT_MCU_LPC51UXX, OPT_MCU_LPC54XXX, OPT_MCU_LPC55XX, OPT_MCU_MCXN9)
- #include "fsl_device_registers.h"
-
-#elif TU_CHECK_MCU(OPT_MCU_KINETIS_KL, OPT_MCU_KINETIS_K32L)
+#elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX || CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \
+ CFG_TUSB_MCU == OPT_MCU_LPC55XX || CFG_TUSB_MCU == OPT_MCU_MKL25ZXX || \
+ CFG_TUSB_MCU == OPT_MCU_K32L2BXX
#include "fsl_device_registers.h"
#elif CFG_TUSB_MCU == OPT_MCU_NRF5X
@@ -80,9 +80,6 @@
#elif CFG_TUSB_MCU == OPT_MCU_STM32F7
#include "stm32f7xx.h"
-#elif CFG_TUSB_MCU == OPT_MCU_STM32G4
- #include "stm32g4xx.h"
-
#elif CFG_TUSB_MCU == OPT_MCU_STM32H7
#include "stm32h7xx.h"
@@ -95,28 +92,16 @@
#elif CFG_TUSB_MCU == OPT_MCU_STM32L4
#include "stm32l4xx.h"
-#elif CFG_TUSB_MCU == OPT_MCU_STM32WB
- #include "stm32wbxx.h"
-
-#elif CFG_TUSB_MCU == OPT_MCU_STM32U5
- #include "stm32u5xx.h"
-
-#elif CFG_TUSB_MCU == OPT_MCU_STM32G0
- #include "stm32g0xx.h"
-
#elif CFG_TUSB_MCU == OPT_MCU_CXD56
// no header needed
#elif CFG_TUSB_MCU == OPT_MCU_MSP430x5xx
#include "msp430.h"
-#elif CFG_TUSB_MCU == OPT_MCU_MSP432E4
- #include "msp.h"
-
#elif CFG_TUSB_MCU == OPT_MCU_VALENTYUSB_EPTRI
// no header needed
-#elif CFG_TUSB_MCU == OPT_MCU_MIMXRT1XXX
+#elif CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
#include "fsl_device_registers.h"
#elif CFG_TUSB_MCU == OPT_MCU_NUC120
@@ -139,31 +124,18 @@
#elif CFG_TUSB_MCU == OPT_MCU_RP2040
#include "pico.h"
-
-#elif CFG_TUSB_MCU == OPT_MCU_EFM32GG
+
+#elif CFG_TUSB_MCU == OPT_MCU_EFM32GG || CFG_TUSB_MCU == OPT_MCU_EFM32GG11 || CFG_TUSB_MCU == OPT_MCU_EFM32GG12
#include "em_device.h"
#elif CFG_TUSB_MCU == OPT_MCU_RX63X || CFG_TUSB_MCU == OPT_MCU_RX65X
// no header needed
-#elif CFG_TUSB_MCU == OPT_MCU_RAXXX
- #include "bsp_api.h"
-
#elif CFG_TUSB_MCU == OPT_MCU_GD32VF103
#include "gd32vf103.h"
#elif CFG_TUSB_MCU == OPT_MCU_MM32F327X
#include "mm32_device.h"
-
-#elif CFG_TUSB_MCU == OPT_MCU_XMC4000
- #include "xmc_device.h"
-
-#elif CFG_TUSB_MCU == OPT_MCU_TM4C123
- #include "TM4C123.h"
-
-#elif TU_CHECK_MCU(OPT_MCU_BCM2711, OPT_MCU_BCM2835, OPT_MCU_BCM2837)
- // no header needed
-
#else
#error "Missing MCU header"
#endif
diff --git a/hw/bsp/broadcom_32bit/boards/raspberrypi_zero_w/board.h b/hw/bsp/broadcom_32bit/boards/raspberrypi_zero_w/board.h
deleted file mode 100644
index 84a106346..000000000
--- a/hw/bsp/broadcom_32bit/boards/raspberrypi_zero_w/board.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020, 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.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef BOARD_H_
-#define BOARD_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* BOARD_H_ */
diff --git a/hw/bsp/broadcom_32bit/boards/raspberrypi_zero_w/board.mk b/hw/bsp/broadcom_32bit/boards/raspberrypi_zero_w/board.mk
deleted file mode 100644
index 052033230..000000000
--- a/hw/bsp/broadcom_32bit/boards/raspberrypi_zero_w/board.mk
+++ /dev/null
@@ -1,5 +0,0 @@
-CPU_CORE = arm1176
-CFLAGS += -DBCM_VERSION=2835 \
- -DCFG_TUSB_MCU=OPT_MCU_BCM2835
-
-SUFFIX =
diff --git a/hw/bsp/broadcom_32bit/family.c b/hw/bsp/broadcom_32bit/family.c
deleted file mode 100644
index 664b4dcaf..000000000
--- a/hw/bsp/broadcom_32bit/family.c
+++ /dev/null
@@ -1,156 +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.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "bsp/board_api.h"
-#include "board.h"
-
-#include "broadcom/cpu.h"
-#include "broadcom/gpio.h"
-#include "broadcom/interrupts.h"
-#include "broadcom/mmu.h"
-#include "broadcom/caches.h"
-#include "broadcom/vcmailbox.h"
-
-// LED
-#define LED_PIN 18
-#define LED_STATE_ON 1
-
-// UART TX
-#define UART_TX_PIN 14
-
-//--------------------------------------------------------------------+
-// Forward USB interrupt events to TinyUSB IRQ Handler
-//--------------------------------------------------------------------+
-void USB_IRQHandler(void)
-{
- tud_int_handler(0);
-}
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM
-//--------------------------------------------------------------------+
-
-//--------------------------------------------------------------------+
-// Board porting API
-//--------------------------------------------------------------------+
-void board_init(void)
-{
- setup_mmu_flat_map();
- init_caches();
-
- // LED
- gpio_set_function(LED_PIN, GPIO_FUNCTION_OUTPUT);
- gpio_set_pull(LED_PIN, BP_PULL_NONE);
- board_led_write(true);
-
- // Uart
- COMPLETE_MEMORY_READS;
- AUX->ENABLES_b.UART_1 = true;
-
- UART1->IER = 0;
- UART1->CNTL = 0;
- UART1->LCR_b.DATA_SIZE = UART1_LCR_DATA_SIZE_MODE_8BIT;
- UART1->MCR = 0;
- UART1->IER = 0;
-
- uint32_t source_clock = vcmailbox_get_clock_rate_measured(VCMAILBOX_CLOCK_CORE);
- UART1->BAUD = ((source_clock / (115200 * 8)) - 1);
- UART1->CNTL |= UART1_CNTL_TX_ENABLE_Msk;
- COMPLETE_MEMORY_READS;
-
- gpio_set_function(UART_TX_PIN, GPIO_FUNCTION_ALT5);
-
- // Turn on USB peripheral.
- vcmailbox_set_power_state(VCMAILBOX_DEVICE_USB_HCD, true);
-
- // Timer 1/1024 second tick
- SYSTMR->CS_b.M1 = 1;
- SYSTMR->C1 = SYSTMR->CLO + 977;
- BP_EnableIRQ(TIMER_1_IRQn);
-
- BP_SetPriority(USB_IRQn, 0x00);
- BP_ClearPendingIRQ(USB_IRQn);
- BP_EnableIRQ(USB_IRQn);
- BP_EnableIRQs();
-}
-
-void board_led_write(bool state)
-{
- gpio_set_value(LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
-}
-
-uint32_t board_button_read(void)
-{
- return 0;
-}
-
-int board_uart_read(uint8_t* buf, int len)
-{
- (void) buf; (void) len;
- return 0;
-}
-
-int board_uart_write(void const * buf, int len)
-{
- for (int i = 0; i < len; i++) {
- const char* cbuf = buf;
- while (!UART1->STAT_b.TX_READY) {}
- if (cbuf[i] == '\n') {
- UART1->IO = '\r';
- while (!UART1->STAT_b.TX_READY) {}
- }
- UART1->IO = cbuf[i];
- }
- return len;
-}
-
-#if CFG_TUSB_OS == OPT_OS_NONE
-volatile uint32_t system_ticks = 0;
-
-void TIMER_1_IRQHandler(void)
-{
- system_ticks++;
- SYSTMR->C1 += 977;
- SYSTMR->CS_b.M1 = 1;
-}
-
-uint32_t board_millis(void)
-{
- return system_ticks;
-}
-#endif
-
-void HardFault_Handler (void)
-{
- // asm("bkpt");
-}
-
-// Required by __libc_init_array in startup code if we are compiling using
-// -nostdlib/-nostartfiles.
-void _init(void)
-{
-
-}
diff --git a/hw/bsp/broadcom_32bit/family.mk b/hw/bsp/broadcom_32bit/family.mk
deleted file mode 100644
index cf68e21ee..000000000
--- a/hw/bsp/broadcom_32bit/family.mk
+++ /dev/null
@@ -1,46 +0,0 @@
-MCU_DIR = hw/mcu/broadcom
-DEPS_SUBMODULES += $(MCU_DIR)
-
-include $(TOP)/$(BOARD_PATH)/board.mk
-
-CFLAGS += \
- -Wall \
- -O0 \
- -ffreestanding \
- -nostdlib \
- -nostartfiles \
- -mgeneral-regs-only \
- -fno-exceptions \
- -std=c17
-
-CROSS_COMPILE = arm-none-eabi-
-
-# mcu driver cause following warnings
-CFLAGS += -Wno-error=cast-qual -Wno-error=redundant-decls
-
-SRC_C += \
- src/portable/synopsys/dwc2/dcd_dwc2.c \
- $(MCU_DIR)/broadcom/gen/interrupt_handlers.c \
- $(MCU_DIR)/broadcom/gpio.c \
- $(MCU_DIR)/broadcom/interrupts.c \
- $(MCU_DIR)/broadcom/mmu.c \
- $(MCU_DIR)/broadcom/caches.c \
- $(MCU_DIR)/broadcom/vcmailbox.c
-
-SKIP_NANOLIB = 1
-
-LD_FILE = $(MCU_DIR)/broadcom/link$(SUFFIX).ld
-
-INC += \
- $(TOP)/$(BOARD_PATH) \
- $(TOP)/$(MCU_DIR)
-
-SRC_S += $(MCU_DIR)/broadcom/boot$(SUFFIX).S
-
-$(BUILD)/kernel$(SUFFIX).img: $(BUILD)/$(PROJECT).elf
- $(OBJCOPY) -O binary $^ $@
-
-# Copy to kernel to netboot drive or SD card
-# Change destinaation to fit your need
-flash: $(BUILD)/kernel$(SUFFIX).img
- @$(CP) $< /home/$(USER)/Documents/code/pi_tinyusb/boot_cpy
diff --git a/hw/bsp/broadcom_64bit/boards/raspberrypi_cm4/board.h b/hw/bsp/broadcom_64bit/boards/raspberrypi_cm4/board.h
deleted file mode 100644
index 84a106346..000000000
--- a/hw/bsp/broadcom_64bit/boards/raspberrypi_cm4/board.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020, 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.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef BOARD_H_
-#define BOARD_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* BOARD_H_ */
diff --git a/hw/bsp/broadcom_64bit/boards/raspberrypi_cm4/board.mk b/hw/bsp/broadcom_64bit/boards/raspberrypi_cm4/board.mk
deleted file mode 100644
index 702f10137..000000000
--- a/hw/bsp/broadcom_64bit/boards/raspberrypi_cm4/board.mk
+++ /dev/null
@@ -1,3 +0,0 @@
-CPU_CORE = cortex-a72
-CFLAGS += -DBCM_VERSION=2711 \
- -DCFG_TUSB_MCU=OPT_MCU_BCM2711
diff --git a/hw/bsp/broadcom_64bit/boards/raspberrypi_zero2w/board.h b/hw/bsp/broadcom_64bit/boards/raspberrypi_zero2w/board.h
deleted file mode 100644
index 84a106346..000000000
--- a/hw/bsp/broadcom_64bit/boards/raspberrypi_zero2w/board.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020, 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.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef BOARD_H_
-#define BOARD_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* BOARD_H_ */
diff --git a/hw/bsp/broadcom_64bit/boards/raspberrypi_zero2w/board.mk b/hw/bsp/broadcom_64bit/boards/raspberrypi_zero2w/board.mk
deleted file mode 100644
index da3fe17bc..000000000
--- a/hw/bsp/broadcom_64bit/boards/raspberrypi_zero2w/board.mk
+++ /dev/null
@@ -1,3 +0,0 @@
-CPU_CORE = cortex-a53
-CFLAGS += -DBCM_VERSION=2837 \
- -DCFG_TUSB_MCU=OPT_MCU_BCM2837
diff --git a/hw/bsp/broadcom_64bit/family.c b/hw/bsp/broadcom_64bit/family.c
deleted file mode 100644
index 664b4dcaf..000000000
--- a/hw/bsp/broadcom_64bit/family.c
+++ /dev/null
@@ -1,156 +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.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "bsp/board_api.h"
-#include "board.h"
-
-#include "broadcom/cpu.h"
-#include "broadcom/gpio.h"
-#include "broadcom/interrupts.h"
-#include "broadcom/mmu.h"
-#include "broadcom/caches.h"
-#include "broadcom/vcmailbox.h"
-
-// LED
-#define LED_PIN 18
-#define LED_STATE_ON 1
-
-// UART TX
-#define UART_TX_PIN 14
-
-//--------------------------------------------------------------------+
-// Forward USB interrupt events to TinyUSB IRQ Handler
-//--------------------------------------------------------------------+
-void USB_IRQHandler(void)
-{
- tud_int_handler(0);
-}
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM
-//--------------------------------------------------------------------+
-
-//--------------------------------------------------------------------+
-// Board porting API
-//--------------------------------------------------------------------+
-void board_init(void)
-{
- setup_mmu_flat_map();
- init_caches();
-
- // LED
- gpio_set_function(LED_PIN, GPIO_FUNCTION_OUTPUT);
- gpio_set_pull(LED_PIN, BP_PULL_NONE);
- board_led_write(true);
-
- // Uart
- COMPLETE_MEMORY_READS;
- AUX->ENABLES_b.UART_1 = true;
-
- UART1->IER = 0;
- UART1->CNTL = 0;
- UART1->LCR_b.DATA_SIZE = UART1_LCR_DATA_SIZE_MODE_8BIT;
- UART1->MCR = 0;
- UART1->IER = 0;
-
- uint32_t source_clock = vcmailbox_get_clock_rate_measured(VCMAILBOX_CLOCK_CORE);
- UART1->BAUD = ((source_clock / (115200 * 8)) - 1);
- UART1->CNTL |= UART1_CNTL_TX_ENABLE_Msk;
- COMPLETE_MEMORY_READS;
-
- gpio_set_function(UART_TX_PIN, GPIO_FUNCTION_ALT5);
-
- // Turn on USB peripheral.
- vcmailbox_set_power_state(VCMAILBOX_DEVICE_USB_HCD, true);
-
- // Timer 1/1024 second tick
- SYSTMR->CS_b.M1 = 1;
- SYSTMR->C1 = SYSTMR->CLO + 977;
- BP_EnableIRQ(TIMER_1_IRQn);
-
- BP_SetPriority(USB_IRQn, 0x00);
- BP_ClearPendingIRQ(USB_IRQn);
- BP_EnableIRQ(USB_IRQn);
- BP_EnableIRQs();
-}
-
-void board_led_write(bool state)
-{
- gpio_set_value(LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
-}
-
-uint32_t board_button_read(void)
-{
- return 0;
-}
-
-int board_uart_read(uint8_t* buf, int len)
-{
- (void) buf; (void) len;
- return 0;
-}
-
-int board_uart_write(void const * buf, int len)
-{
- for (int i = 0; i < len; i++) {
- const char* cbuf = buf;
- while (!UART1->STAT_b.TX_READY) {}
- if (cbuf[i] == '\n') {
- UART1->IO = '\r';
- while (!UART1->STAT_b.TX_READY) {}
- }
- UART1->IO = cbuf[i];
- }
- return len;
-}
-
-#if CFG_TUSB_OS == OPT_OS_NONE
-volatile uint32_t system_ticks = 0;
-
-void TIMER_1_IRQHandler(void)
-{
- system_ticks++;
- SYSTMR->C1 += 977;
- SYSTMR->CS_b.M1 = 1;
-}
-
-uint32_t board_millis(void)
-{
- return system_ticks;
-}
-#endif
-
-void HardFault_Handler (void)
-{
- // asm("bkpt");
-}
-
-// Required by __libc_init_array in startup code if we are compiling using
-// -nostdlib/-nostartfiles.
-void _init(void)
-{
-
-}
diff --git a/hw/bsp/broadcom_64bit/family.mk b/hw/bsp/broadcom_64bit/family.mk
deleted file mode 100644
index 97af6d64a..000000000
--- a/hw/bsp/broadcom_64bit/family.mk
+++ /dev/null
@@ -1,46 +0,0 @@
-MCU_DIR = hw/mcu/broadcom
-DEPS_SUBMODULES += $(MCU_DIR)
-
-include $(TOP)/$(BOARD_PATH)/board.mk
-
-CFLAGS += \
- -Wall \
- -O0 \
- -ffreestanding \
- -nostdlib \
- -nostartfiles \
- -mgeneral-regs-only \
- -std=c17
-
-CROSS_COMPILE = aarch64-none-elf-
-
-# mcu driver cause following warnings
-CFLAGS += -Wno-error=cast-qual -Wno-error=redundant-decls
-
-SRC_C += \
- src/portable/synopsys/dwc2/dcd_dwc2.c \
- $(MCU_DIR)/broadcom/gen/interrupt_handlers.c \
- $(MCU_DIR)/broadcom/gpio.c \
- $(MCU_DIR)/broadcom/interrupts.c \
- $(MCU_DIR)/broadcom/mmu.c \
- $(MCU_DIR)/broadcom/caches.c \
- $(MCU_DIR)/broadcom/vcmailbox.c
-
-SKIP_NANOLIB = 1
-
-LD_FILE = $(MCU_DIR)/broadcom/link8.ld
-
-INC += \
- $(TOP)/$(BOARD_PATH) \
- $(TOP)/$(MCU_DIR) \
- $(TOP)/lib/CMSIS_5/CMSIS/Core_A/Include
-
-SRC_S += $(MCU_DIR)/broadcom/boot8.S
-
-$(BUILD)/kernel8.img: $(BUILD)/$(PROJECT).elf
- $(OBJCOPY) -O binary $^ $@
-
-# Copy to kernel to netboot drive or SD card
-# Change destinaation to fit your need
-flash: $(BUILD)/kernel8.img
- @$(CP) $< /home/$(USER)/Documents/code/pi_tinyusb/boot_cpy
diff --git a/hw/bsp/brtmm90x/family.c b/hw/bsp/brtmm90x/family.c
deleted file mode 100644
index 4d81e7d52..000000000
--- a/hw/bsp/brtmm90x/family.c
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright 2021 Bridgetek Pte Ltd
- *
- * 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.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "bsp/board_api.h"
-#include "board.h"
-
-#include
-#include
-
-#if CFG_TUD_ENABLED
-int8_t board_ft9xx_vbus(void); // Board specific implementation of VBUS detection for USB device.
-extern void ft9xx_usbd_pm_ISR(uint16_t pmcfg); // Interrupt handler for USB device power management
-#endif
-
-#ifdef BOARD_GPIO_REMOTE_WAKEUP
-void gpio_ISR(void);
-#endif
-void timer_ISR(void);
-volatile unsigned int timer_ms = 0;
-void board_pm_ISR(void);
-
-#define WELCOME_MSG "\x1B[2J\x1B[H" \
- "MM900EVxB board\r\n"
-
-// Initialize on-board peripherals : led, button, uart and USB
-void board_init(void)
-{
- sys_reset_all();
-
- // Enable the UART Device.
- sys_enable(sys_device_uart0);
- // Set BOARD_UART GPIO function pins for TXD and RXD.
-#ifdef BOARD_GPIO_UART_TX
- gpio_function(BOARD_GPIO_UART_TX, pad_uart0_txd); /* UART0 TXD */
-#endif
-#ifdef BOARD_GPIO_UART_RX
- gpio_function(BOARD_GPIO_UART_RX, pad_uart0_rxd); /* UART0 RXD */
-#endif
- uart_open(BOARD_UART, /* Device */
- 1, /* Prescaler = 1 */
- UART_DIVIDER_19200_BAUD, /* Divider = 1302 */
- uart_data_bits_8, /* No. Data Bits */
- uart_parity_none, /* Parity */
- uart_stop_bits_1); /* No. Stop Bits */
- // Print out a welcome message.
- // Use sizeof to avoid pulling in strlen unnecessarily.
- board_uart_write(WELCOME_MSG, sizeof(WELCOME_MSG));
-
-#ifdef BOARD_GPIO_LED
- gpio_function(BOARD_GPIO_LED, pad_func_0);
- gpio_idrive(BOARD_GPIO_LED, pad_drive_12mA);
- gpio_dir(BOARD_GPIO_LED, pad_dir_output);
-#endif
-
-#ifdef BOARD_GPIO_BUTTON
- gpio_function(BOARD_GPIO_BUTTON, pad_func_0);
- // Pull up if active low. Down if active high.
- gpio_pull(BOARD_GPIO_BUTTON, (BOARD_GPIO_BUTTON_STATE_ACTIVE == 0)?pad_pull_pullup:pad_pull_pulldown);
- gpio_dir(BOARD_GPIO_BUTTON, pad_dir_input);
-#endif
-
- sys_enable(sys_device_timer_wdt);
- /* Timer A = 1ms */
- timer_prescaler(timer_select_a, 1000);
- timer_init(timer_select_a, 100, timer_direction_down, timer_prescaler_select_on, timer_mode_continuous);
- timer_enable_interrupt(timer_select_a);
- timer_start(timer_select_a);
- interrupt_attach(interrupt_timers, (int8_t)interrupt_timers, timer_ISR);
-
- // Setup VBUS detect GPIO. If the device is connected then this
- // will set the MASK_SYS_PMCFG_DEV_DETECT_EN bit in PMCFG.
- gpio_interrupt_disable(BOARD_USBD_VBUS_DTC_PIN);
- gpio_function(BOARD_USBD_VBUS_DTC_PIN, pad_vbus_dtc);
- gpio_pull(BOARD_USBD_VBUS_DTC_PIN, pad_pull_pulldown);
- gpio_dir(BOARD_USBD_VBUS_DTC_PIN, pad_dir_input);
-
- interrupt_attach(interrupt_0, (int8_t)interrupt_0, board_pm_ISR);
-
-#ifdef BOARD_GPIO_REMOTE_WAKEUP
- // Configuring GPIO pin to wakeup.
- // Set up the wakeup pin.
- gpio_dir(BOARD_GPIO_REMOTE_WAKEUP, pad_dir_input);
- gpio_pull(BOARD_GPIO_REMOTE_WAKEUP, pad_pull_pullup);
-
- // Attach an interrupt handler.
- interrupt_attach(interrupt_gpio, (uint8_t)interrupt_gpio, gpio_ISR);
- gpio_interrupt_enable(BOARD_GPIO_REMOTE_WAKEUP, gpio_int_edge_falling);
-#endif
-
- uart_disable_interrupt(BOARD_UART, uart_interrupt_tx);
- uart_disable_interrupt(BOARD_UART, uart_interrupt_rx);
-
- // Enable all peripheral interrupts.
- interrupt_enable_globally();
-
- TU_LOG1("MM900EV1B board setup complete\r\n");
-};
-
-void timer_ISR(void)
-{
- if (timer_is_interrupted(timer_select_a))
- {
- timer_ms++;
- }
-}
-
-#ifdef BOARD_GPIO_REMOTE_WAKEUP
-void gpio_ISR(void)
-{
- if (gpio_is_interrupted(BOARD_GPIO_REMOTE_WAKEUP))
- {
- }
-}
-#endif
-
-/* Power management ISR */
-void board_pm_ISR(void)
-{
- uint16_t pmcfg = SYS->PMCFG_H;
-
-#if defined(__FT930__)
- if (pmcfg & MASK_SYS_PMCFG_SLAVE_PERI_IRQ_PEND)
- {
- // Clear d2xx hw engine wakeup.
- SYS->PMCFG_H = MASK_SYS_PMCFG_SLAVE_PERI_IRQ_PEND;
- }
-#endif
- if (pmcfg & MASK_SYS_PMCFG_PM_GPIO_IRQ_PEND)
- {
- // Clear GPIO wakeup pending.
- SYS->PMCFG_H = MASK_SYS_PMCFG_PM_GPIO_IRQ_PEND;
- }
-
-#if defined(__FT900__)
- // USB device power management interrupts.
- if (pmcfg & (MASK_SYS_PMCFG_DEV_CONN_DEV |
- MASK_SYS_PMCFG_DEV_DIS_DEV |
- MASK_SYS_PMCFG_HOST_RST_DEV |
- MASK_SYS_PMCFG_HOST_RESUME_DEV)
- )
- {
-#if CFG_TUD_ENABLED
- ft9xx_usbd_pm_ISR(pmcfg);
-#endif
- }
-#endif
-}
-
-#if CFG_TUD_ENABLED
-int8_t board_ft9xx_vbus(void)
-{
- return gpio_read(BOARD_USBD_VBUS_DTC_PIN);
-}
-#endif
-
-//--------------------------------------------------------------------+
-// Board porting API
-//--------------------------------------------------------------------+
-
-// Turn LED on or off
-void board_led_write(bool state)
-{
-#ifdef BOARD_GPIO_LED
- gpio_write(BOARD_GPIO_LED, (state == 0)?(BOARD_GPIO_LED_STATE_ON?0:1):BOARD_GPIO_LED_STATE_ON);
-#endif
-}
-
-// Get the current state of button
-// a '1' means active (pressed), a '0' means inactive.
-uint32_t board_button_read(void)
-{
- uint32_t state = 0;
-#ifdef BOARD_GPIO_BUTTON
- state = (gpio_read(BOARD_GPIO_BUTTON) == BOARD_GPIO_BUTTON_STATE_ACTIVE)?1:0;
-#endif
- return state;
-}
-
-// Get characters from UART
-int board_uart_read(uint8_t *buf, int len)
-{
- int r = 0;
-
-#ifdef BOARD_UART
- if (uart_rx_has_data(BOARD_UART))
- {
- r = uart_readn(BOARD_UART, (uint8_t *)buf, len);
- }
-#endif
-
- return r;
-}
-
-// Send characters to UART
-int board_uart_write(void const *buf, int len)
-{
- int r = 0;
-
-#ifdef BOARD_UART
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wcast-qual" // uart_writen does not have const for buffer parameter.
- r = uart_writen(BOARD_UART, (uint8_t *)((const void *)buf), len);
-#pragma GCC diagnostic pop
-#endif
-
- return r;
-}
-
-// Get current milliseconds
-uint32_t board_millis(void)
-{
- uint32_t safe_ms;
-
- CRITICAL_SECTION_BEGIN
- safe_ms = timer_ms;
- CRITICAL_SECTION_END
-
- return safe_ms;
-}
-
-// Restart the program
-// Called in the event of a watchdog timeout
-void chip_reboot(void)
-{
- // SOFT reset
- __asm__("call 0");
- #if 0
- // HARD reset
- // Initiates data transfer from Flash Memory to Data Memory (DBG_CMDF2D3)
- // followed by a system reboot
- dbg_memory_copy(0xfe, 0, 0, 255);
-#endif
-}
diff --git a/hw/bsp/brtmm90x/family.mk b/hw/bsp/brtmm90x/family.mk
deleted file mode 100644
index 6df0bfdfe..000000000
--- a/hw/bsp/brtmm90x/family.mk
+++ /dev/null
@@ -1,67 +0,0 @@
-# GCC prefix for FT90X compile tools.
-CROSS_COMPILE = ft32-elf-
-SKIP_NANOLIB = 1
-
-# Set to use FT90X prebuilt libraries.
-FT9XX_PREBUILT_LIBS = 0
-ifeq ($(FT9XX_PREBUILT_LIBS),1)
-# If the FT90X toolchain is installed on Windows systems then the SDK
-# include files and prebuilt libraries are at: %FT90X_TOOLCHAIN%/hardware
-FT9XX_SDK = $(FT90X_TOOLCHAIN)/hardware
-INC += "$(FT9XX_SDK)/include"
-else
-# The submodule BRTSG-FOSS/ft90x-sdk contains header files and source
-# code for the Bridgetek SDK. This can be used instead of the prebuilt
-# library.
-DEPS_SUBMODULES += hw/mcu/bridgetek/ft9xx/ft90x-sdk
-# The SDK can be used to load specific files from the Bridgetek SDK.
-FT9XX_SDK = hw/mcu/bridgetek/ft9xx/ft90x-sdk/Source
-INC += "$(TOP)/$(FT9XX_SDK)/include"
-endif
-
-# Add include files which are within the TinyUSB directory structure.
-INC += \
- $(TOP)/$(BOARD_PATH)
-
-# Add required C Compiler flags for FT90X.
-CFLAGS += \
- -D__FT900__ \
- -fvar-tracking \
- -fvar-tracking-assignments \
- -fmessage-length=0 \
- -ffunction-sections \
- -DCFG_TUSB_MCU=OPT_MCU_FT90X
-
-# Maximum USB device speed supported by the board
-CFLAGS += -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED
-
-# lwip/src/core/raw.c:334:43: error: declaration of 'recv' shadows a global declaration
-CFLAGS += -Wno-error=shadow
-
-# Set Linker flags.
-LD_FILE = hw/mcu/bridgetek/ft9xx/scripts/ldscript.ld
-LDFLAGS += $(addprefix -L,$(LDINC)) \
- -Xlinker --entry=_start \
- -Wl,-lc
-
-# Additional Source files for FT90X.
-SRC_C += src/portable/bridgetek/ft9xx/dcd_ft9xx.c
-
-# Linker library.
-ifneq ($(FT9XX_PREBUILT_LIBS),1)
-# Optionally add in files from the Bridgetek SDK instead of the prebuilt
-# library. These are the minimum required.
-SRC_C += $(FT9XX_SDK)/src/sys.c
-SRC_C += $(FT9XX_SDK)/src/interrupt.c
-SRC_C += $(FT9XX_SDK)/src/delay.c
-SRC_C += $(FT9XX_SDK)/src/timers.c
-SRC_C += $(FT9XX_SDK)/src/uart_simple.c
-SRC_C += $(FT9XX_SDK)/src/gpio.c
-else
-# Or if using the prebuilt libraries add them.
-LDFLAGS += -L"$(FT9XX_SDK)/lib"
-LIBS += -lft900
-endif
-
-# Not required crt0 file for FT90X. Use compiler built-in file.
-#SRC_S += hw/mcu/bridgetek/ft9xx/scripts/crt0.S
diff --git a/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/board.h b/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/board.h
deleted file mode 100644
index 7b488096e..000000000
--- a/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/board.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2023 Ha Thach (tinyusb.org) for Adafruit Industries
- *
- * 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 BOARD_H_
-#define BOARD_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-// LED: need to wire pin LED1 to PC0 in the J3 header
-#define LED_PORT GPIOC
-#define LED_PIN GPIO_Pin_0
-#define LED_STATE_ON 0
-#define LED_CLOCK_EN() RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE)
-
-// Button: need to wire pin KEY to PC1 in the J3 header
-#define BUTTON_PORT GPIOC
-#define BUTTON_PIN GPIO_Pin_1
-#define BUTTON_STATE_ACTIVE 0
-#define BUTTON_CLOCK_EN() do { } while(0) // same as LED clock, no need to do anything
-
-// TODO UART port
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif
diff --git a/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/board.mk b/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/board.mk
deleted file mode 100644
index 4e91d8938..000000000
--- a/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/board.mk
+++ /dev/null
@@ -1 +0,0 @@
-LD_FILE = $(FAMILY_PATH)/ch32v307.ld
diff --git a/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/debug_uart.c b/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/debug_uart.c
deleted file mode 100644
index db3551ca7..000000000
--- a/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/debug_uart.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2022 Greg Davill
- *
- * 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.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "debug_uart.h"
-#include
-
-
-#define UART_RINGBUFFER_SIZE_TX 64
-#define UART_RINGBUFFER_MASK_TX (UART_RINGBUFFER_SIZE_TX-1)
-
-static char tx_buf[UART_RINGBUFFER_SIZE_TX];
-static unsigned int tx_produce;
-static volatile unsigned int tx_consume;
-
-void USART1_IRQHandler(void) __attribute__((naked));
-void USART1_IRQHandler(void) {
- __asm volatile ("call USART1_IRQHandler_impl; mret");
-}
-
-__attribute__((used)) void USART1_IRQHandler_impl(void)
-{
- if(USART_GetITStatus(USART1, USART_IT_TC) != RESET)
- {
- USART_ClearITPendingBit(USART1, USART_IT_TC);
-
- if(tx_consume != tx_produce) {
- USART_SendData(USART1, tx_buf[tx_consume]);
- tx_consume = (tx_consume + 1) & UART_RINGBUFFER_MASK_TX;
- }
- }
-
-}
-
-void uart_write(char c)
-{
- unsigned int tx_produce_next = (tx_produce + 1) & UART_RINGBUFFER_MASK_TX;
-
- NVIC_DisableIRQ(USART1_IRQn);
- if((tx_consume != tx_produce) || (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)) {
- tx_buf[tx_produce] = c;
- tx_produce = tx_produce_next;
- } else {
- USART_SendData(USART1, c);
- }
- NVIC_EnableIRQ(USART1_IRQn);
-}
-
-
-void uart_sync(void)
-{
- while(tx_consume != tx_produce);
-}
-
-
-void usart_printf_init(uint32_t baudrate)
-{
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
-
- tx_produce = 0;
- tx_consume = 0;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- USART_InitStructure.USART_BaudRate = baudrate;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Tx;
-
- USART_Init(USART1, &USART_InitStructure);
- USART_ITConfig(USART1, USART_IT_TC, ENABLE);
- USART_Cmd(USART1, ENABLE);
-
- NVIC_InitTypeDef NVIC_InitStructure = { 0 };
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-}
diff --git a/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/debug_uart.h b/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/debug_uart.h
deleted file mode 100644
index a7e070585..000000000
--- a/hw/bsp/ch32v307/boards/ch32v307v_r1_1v0/debug_uart.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2022 Greg Davill
- *
- * 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.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include
-
-void uart_write(char c);
-void uart_sync(void);
-void usart_printf_init(uint32_t baudrate);
diff --git a/hw/bsp/ch32v307/ch32v307.ld b/hw/bsp/ch32v307/ch32v307.ld
deleted file mode 100644
index 55bd10cd0..000000000
--- a/hw/bsp/ch32v307/ch32v307.ld
+++ /dev/null
@@ -1,167 +0,0 @@
-ENTRY( _start )
-
-__stack_size = 4096;
-
-PROVIDE( _stack_size = __stack_size );
-
-
-MEMORY
-{
- FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 288K
- RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
-}
-
-
-SECTIONS
-{
-
- .init :
- {
- _sinit = .;
- . = ALIGN(4);
- KEEP(*(SORT_NONE(.init)))
- . = ALIGN(4);
- _einit = .;
- } >FLASH AT>FLASH
-
- .vector :
- {
- *(.vector);
- . = ALIGN(64);
- } >FLASH AT>FLASH
-
- .text :
- {
- . = ALIGN(4);
- *(.text)
- *(.text.*)
- *(.rodata)
- *(.rodata*)
- *(.glue_7)
- *(.glue_7t)
- *(.gnu.linkonce.t.*)
- . = ALIGN(4);
- } >FLASH AT>FLASH
-
- .fini :
- {
- KEEP(*(SORT_NONE(.fini)))
- . = ALIGN(4);
- } >FLASH AT>FLASH
-
- PROVIDE( _etext = . );
- PROVIDE( _eitcm = . );
-
- .preinit_array :
- {
- PROVIDE_HIDDEN (__preinit_array_start = .);
- KEEP (*(.preinit_array))
- PROVIDE_HIDDEN (__preinit_array_end = .);
- } >FLASH AT>FLASH
-
- .init_array :
- {
- PROVIDE_HIDDEN (__init_array_start = .);
- KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
- KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
- PROVIDE_HIDDEN (__init_array_end = .);
- } >FLASH AT>FLASH
-
- .fini_array :
- {
- PROVIDE_HIDDEN (__fini_array_start = .);
- KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
- KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
- PROVIDE_HIDDEN (__fini_array_end = .);
- } >FLASH AT>FLASH
-
- .ctors :
- {
- /* gcc uses crtbegin.o to find the start of
- the constructors, so we make sure it is
- first. Because this is a wildcard, it
- doesn't matter if the user does not
- actually link against crtbegin.o; the
- linker won't look for a file to match a
- wildcard. The wildcard also means that it
- doesn't matter which directory crtbegin.o
- is in. */
- KEEP (*crtbegin.o(.ctors))
- KEEP (*crtbegin?.o(.ctors))
- /* We don't want to include the .ctor section from
- the crtend.o file until after the sorted ctors.
- The .ctor section from the crtend file contains the
- end of ctors marker and it must be last */
- KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
- KEEP (*(SORT(.ctors.*)))
- KEEP (*(.ctors))
- } >FLASH AT>FLASH
-
- .dtors :
- {
- KEEP (*crtbegin.o(.dtors))
- KEEP (*crtbegin?.o(.dtors))
- KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
- KEEP (*(SORT(.dtors.*)))
- KEEP (*(.dtors))
- } >FLASH AT>FLASH
-
- .dalign :
- {
- . = ALIGN(4);
- PROVIDE(_data_vma = .);
- } >RAM AT>FLASH
-
- .dlalign :
- {
- . = ALIGN(4);
- PROVIDE(_data_lma = .);
- } >FLASH AT>FLASH
-
- .data :
- {
- *(.gnu.linkonce.r.*)
- *(.data .data.*)
- *(.gnu.linkonce.d.*)
- . = ALIGN(8);
- PROVIDE( __global_pointer$ = . + 0x800 );
- *(.sdata .sdata.*)
- *(.sdata2.*)
- *(.gnu.linkonce.s.*)
- . = ALIGN(8);
- *(.srodata.cst16)
- *(.srodata.cst8)
- *(.srodata.cst4)
- *(.srodata.cst2)
- *(.srodata .srodata.*)
- . = ALIGN(4);
- PROVIDE( _edata = .);
- } >RAM AT>FLASH
-
- .bss :
- {
- . = ALIGN(4);
- PROVIDE( _sbss = .);
- *(.sbss*)
- *(.gnu.linkonce.sb.*)
- *(.bss*)
- *(.gnu.linkonce.b.*)
- *(COMMON*)
- . = ALIGN(4);
- PROVIDE( _ebss = .);
- } >RAM AT>FLASH
-
- PROVIDE( _end = _ebss);
- PROVIDE( end = . );
-
- .stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
- {
- PROVIDE( _heap_end = . );
- . = ALIGN(4);
- PROVIDE(_susrstack = . );
- . = . + __stack_size;
- PROVIDE( _eusrstack = .);
- __freertos_irq_stack_top = .;
- } >RAM
-
-}
diff --git a/hw/bsp/ch32v307/ch32v30x_conf.h b/hw/bsp/ch32v307/ch32v30x_conf.h
deleted file mode 100644
index 0b86ad390..000000000
--- a/hw/bsp/ch32v307/ch32v30x_conf.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/********************************** (C) COPYRIGHT *******************************
-* File Name : ch32v30x_conf.h
-* Author : WCH
-* Version : V1.0.0
-* Date : 2021/06/06
-* Description : Library configuration file.
-* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
-* SPDX-License-Identifier: Apache-2.0
-*******************************************************************************/
-#ifndef __CH32V30x_CONF_H
-#define __CH32V30x_CONF_H
-
-#include "ch32v30x_adc.h"
-#include "ch32v30x_bkp.h"
-#include "ch32v30x_can.h"
-#include "ch32v30x_crc.h"
-#include "ch32v30x_dac.h"
-#include "ch32v30x_dbgmcu.h"
-#include "ch32v30x_dma.h"
-#include "ch32v30x_exti.h"
-#include "ch32v30x_flash.h"
-#include "ch32v30x_fsmc.h"
-#include "ch32v30x_gpio.h"
-#include "ch32v30x_i2c.h"
-#include "ch32v30x_iwdg.h"
-#include "ch32v30x_pwr.h"
-#include "ch32v30x_rcc.h"
-#include "ch32v30x_rtc.h"
-#include "ch32v30x_sdio.h"
-#include "ch32v30x_spi.h"
-#include "ch32v30x_tim.h"
-#include "ch32v30x_usart.h"
-#include "ch32v30x_wwdg.h"
-#include "ch32v30x_it.h"
-#include "ch32v30x_misc.h"
-
-
-#endif /* __CH32V30x_CONF_H */
diff --git a/hw/bsp/ch32v307/ch32v30x_it.c b/hw/bsp/ch32v307/ch32v30x_it.c
deleted file mode 100644
index c329c5613..000000000
--- a/hw/bsp/ch32v307/ch32v30x_it.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/********************************** (C) COPYRIGHT *******************************
-* File Name : ch32v30x_it.c
-* Author : WCH
-* Version : V1.0.0
-* Date : 2021/06/06
-* Description : Main Interrupt Service Routines.
-* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
-* SPDX-License-Identifier: Apache-2.0
-*******************************************************************************/
-#include "ch32v30x_it.h"
-
-void NMI_Handler(void) __attribute__((naked));
-void HardFault_Handler(void) __attribute__((naked));
-
-/*********************************************************************
- * @fn NMI_Handler
- *
- * @brief This function handles NMI exception.
- *
- * @return none
- */
-void NMI_Handle(void){
- __asm volatile ("call NMI_Handler_impl; mret");
-}
-
-__attribute__((used)) void NMI_Handler_impl(void)
-{
-
-}
-
-/*********************************************************************
- * @fn HardFault_Handler
- *
- * @brief This function handles Hard Fault exception.
- *
- * @return none
- */
-void HardFault_Handler(void){
- __asm volatile ("call HardFault_Handler_impl; mret");
-}
-
-__attribute__((used)) void HardFault_Handler_impl(void)
-{
- while (1)
- {
- }
-}
diff --git a/hw/bsp/ch32v307/ch32v30x_it.h b/hw/bsp/ch32v307/ch32v30x_it.h
deleted file mode 100644
index f3977a8be..000000000
--- a/hw/bsp/ch32v307/ch32v30x_it.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/********************************** (C) COPYRIGHT *******************************
-* File Name : ch32v30x_it.h
-* Author : WCH
-* Version : V1.0.0
-* Date : 2021/06/06
-* Description : This file contains the headers of the interrupt handlers.
-* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
-* SPDX-License-Identifier: Apache-2.0
-*******************************************************************************/
-#ifndef __CH32V30x_IT_H
-#define __CH32V30x_IT_H
-
-// #include "debug.h"
-
-
-#endif /* __CH32V30x_IT_H */
diff --git a/hw/bsp/ch32v307/core_riscv.h b/hw/bsp/ch32v307/core_riscv.h
deleted file mode 100644
index a7ce10a00..000000000
--- a/hw/bsp/ch32v307/core_riscv.h
+++ /dev/null
@@ -1,379 +0,0 @@
-/********************************** (C) COPYRIGHT *******************************
-* File Name : core_riscv.h
-* Author : WCH
-* Version : V1.0.0
-* Date : 2021/06/06
-* Description : RISC-V Core Peripheral Access Layer Header File for CH32V30x
-* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
-* SPDX-License-Identifier: Apache-2.0
-*******************************************************************************/
-#ifndef __CORE_RISCV_H__
-#define __CORE_RISCV_H__
-
-/* IO definitions */
-#ifdef __cplusplus
- #define __I volatile /* defines 'read only' permissions */
-#else
- #define __I volatile const /* defines 'read only' permissions */
-#endif
-#define __O volatile /* defines 'write only' permissions */
-#define __IO volatile /* defines 'read / write' permissions */
-
-/* Standard Peripheral Library old types (maintained for legacy purpose) */
-typedef __I uint64_t vuc64; /* Read Only */
-typedef __I uint32_t vuc32; /* Read Only */
-typedef __I uint16_t vuc16; /* Read Only */
-typedef __I uint8_t vuc8; /* Read Only */
-
-typedef const uint64_t uc64; /* Read Only */
-typedef const uint32_t uc32; /* Read Only */
-typedef const uint16_t uc16; /* Read Only */
-typedef const uint8_t uc8; /* Read Only */
-
-typedef __I int64_t vsc64; /* Read Only */
-typedef __I int32_t vsc32; /* Read Only */
-typedef __I int16_t vsc16; /* Read Only */
-typedef __I int8_t vsc8; /* Read Only */
-
-typedef const int64_t sc64; /* Read Only */
-typedef const int32_t sc32; /* Read Only */
-typedef const int16_t sc16; /* Read Only */
-typedef const int8_t sc8; /* Read Only */
-
-typedef __IO uint64_t vu64;
-typedef __IO uint32_t vu32;
-typedef __IO uint16_t vu16;
-typedef __IO uint8_t vu8;
-
-typedef uint64_t u64;
-typedef uint32_t u32;
-typedef uint16_t u16;
-typedef uint8_t u8;
-
-typedef __IO int64_t vs64;
-typedef __IO int32_t vs32;
-typedef __IO int16_t vs16;
-typedef __IO int8_t vs8;
-
-typedef int64_t s64;
-typedef int32_t s32;
-typedef int16_t s16;
-typedef int8_t s8;
-
-typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
-
-typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
-
-typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
-
-#define RV_STATIC_INLINE static inline
-
-/* memory mapped structure for Program Fast Interrupt Controller (PFIC) */
-typedef struct{
- __I uint32_t ISR[8];
- __I uint32_t IPR[8];
- __IO uint32_t ITHRESDR;
- __IO uint32_t RESERVED;
- __IO uint32_t CFGR;
- __I uint32_t GISR;
- uint8_t VTFIDR[4];
- uint8_t RESERVED0[12];
- __IO uint32_t VTFADDR[4];
- uint8_t RESERVED1[0x90];
- __O uint32_t IENR[8];
- uint8_t RESERVED2[0x60];
- __O uint32_t IRER[8];
- uint8_t RESERVED3[0x60];
- __O uint32_t IPSR[8];
- uint8_t RESERVED4[0x60];
- __O uint32_t IPRR[8];
- uint8_t RESERVED5[0x60];
- __IO uint32_t IACTR[8];
- uint8_t RESERVED6[0xE0];
- __IO uint8_t IPRIOR[256];
- uint8_t RESERVED7[0x810];
- __IO uint32_t SCTLR;
-}PFIC_Type;
-
-/* memory mapped structure for SysTick */
-typedef struct
-{
- __IO u32 CTLR;
- __IO u32 SR;
- __IO u64 CNT;
- __IO u64 CMP;
-}SysTick_Type;
-
-
-#define PFIC ((PFIC_Type *) 0xE000E000 )
-#define NVIC PFIC
-#define NVIC_KEY1 ((uint32_t)0xFA050000)
-#define NVIC_KEY2 ((uint32_t)0xBCAF0000)
-#define NVIC_KEY3 ((uint32_t)0xBEEF0000)
-
-#define SysTick ((SysTick_Type *) 0xE000F000)
-
-
-/*********************************************************************
- * @fn __enable_irq
- *
- * @brief Enable Global Interrupt
- *
- * @return none
- */
-RV_STATIC_INLINE void __enable_irq(void)
-{
- __asm volatile ("csrw 0x800, %0" : : "r" (0x6088) );
-}
-
-/*********************************************************************
- * @fn __disable_irq
- *
- * @brief Disable Global Interrupt
- *
- * @return none
- */
-RV_STATIC_INLINE void __disable_irq(void)
-{
- __asm volatile ("csrw 0x800, %0" : : "r" (0x6000) );
-}
-
-/*********************************************************************
- * @fn __NOP
- *
- * @brief nop
- *
- * @return none
- */
-RV_STATIC_INLINE void __NOP(void)
-{
- __asm volatile ("nop");
-}
-
-/*********************************************************************
- * @fn NVIC_EnableIRQ
- *
- * @brief Enable Interrupt
- *
- * @param IRQn: Interrupt Numbers
- *
- * @return none
- */
-RV_STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
-{
- NVIC->IENR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));
-}
-
-/*********************************************************************
- * @fn NVIC_DisableIRQ
- *
- * @brief Disable Interrupt
- *
- * @param IRQn: Interrupt Numbers
- *
- * @return none
- */
-RV_STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
-{
- NVIC->IRER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));
-}
-
-/*********************************************************************
- * @fn NVIC_GetStatusIRQ
- *
- * @brief Get Interrupt Enable State
- *
- * @param IRQn: Interrupt Numbers
- *
- * @return 1 - Interrupt Enable
- * 0 - Interrupt Disable
- */
-RV_STATIC_INLINE uint32_t NVIC_GetStatusIRQ(IRQn_Type IRQn)
-{
- return((uint32_t) ((NVIC->ISR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
-}
-
-/*********************************************************************
- * @fn NVIC_GetPendingIRQ
- *
- * @brief Get Interrupt Pending State
- *
- * @param IRQn: Interrupt Numbers
- *
- * @return 1 - Interrupt Pending Enable
- * 0 - Interrupt Pending Disable
- */
-RV_STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
-{
- return((uint32_t) ((NVIC->IPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
-}
-
-/*********************************************************************
- * @fn NVIC_SetPendingIRQ
- *
- * @brief Set Interrupt Pending
- *
- * @param IRQn: Interrupt Numbers
- *
- * @return None
- */
-RV_STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
-{
- NVIC->IPSR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));
-}
-
-/*********************************************************************
- * @fn NVIC_ClearPendingIRQ
- *
- * @brief Clear Interrupt Pending
- *
- * @param IRQn: Interrupt Numbers
- *
- * @return None
- */
-RV_STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
-{
- NVIC->IPRR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));
-}
-
-/*********************************************************************
- * @fn NVIC_GetActive
- *
- * @brief Get Interrupt Active State
- *
- * @param IRQn: Interrupt Numbers
- *
- * @return 1 - Interrupt Active
- * 0 - Interrupt No Active
- */
-RV_STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
-{
- return((uint32_t)((NVIC->IACTR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
-}
-
-/*********************************************************************
- * @fn NVIC_SetPriority
- *
- * @brief Set Interrupt Priority
- *
- * @param IRQn - Interrupt Numbers
- * priority -
- * bit7 - pre-emption priority
- * bit6~bit4 - subpriority
- * @return None
- */
-RV_STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint8_t priority)
-{
- NVIC->IPRIOR[(uint32_t)(IRQn)] = priority;
-}
-
-/*********************************************************************
- * @fn __WFI
- *
- * @brief Wait for Interrupt
- *
- * @return None
- */
-__attribute__( ( always_inline ) ) RV_STATIC_INLINE void __WFI(void)
-{
- NVIC->SCTLR &= ~(1<<3); // wfi
- asm volatile ("wfi");
-}
-
-/*********************************************************************
- * @fn __WFE
- *
- * @brief Wait for Events
- *
- * @return None
- */
-__attribute__( ( always_inline ) ) RV_STATIC_INLINE void __WFE(void)
-{
- uint32_t t;
-
- t = NVIC->SCTLR;
- NVIC->SCTLR |= (1<<3)|(1<<5); // (wfi->wfe)+(__sev)
- NVIC->SCTLR = (NVIC->SCTLR & ~(1<<5)) | ( t & (1<<5));
- asm volatile ("wfi");
- asm volatile ("wfi");
-}
-
-/*********************************************************************
- * @fn SetVTFIRQ
- *
- * @brief Set VTF Interrupt
- *
- * @param add - VTF interrupt service function base address.
- * IRQn -Interrupt Numbers
- * num - VTF Interrupt Numbers
- * NewState - DISABLE or ENABLE
- * @return None
- */
-RV_STATIC_INLINE void SetVTFIRQ(uint32_t addr, IRQn_Type IRQn, uint8_t num, FunctionalState NewState){
- if(num > 3) return ;
-
- if (NewState != DISABLE)
- {
- NVIC->VTFIDR[num] = IRQn;
- NVIC->VTFADDR[num] = ((addr&0xFFFFFFFE)|0x1);
- }
- else{
- NVIC->VTFIDR[num] = IRQn;
- NVIC->VTFADDR[num] = ((addr&0xFFFFFFFE)&(~0x1));
- }
-}
-
-/*********************************************************************
- * @fn NVIC_SystemReset
- *
- * @brief Initiate a system reset request
- *
- * @return None
- */
-RV_STATIC_INLINE void NVIC_SystemReset(void)
-{
- NVIC->CFGR = NVIC_KEY3|(1<<7);
-}
-
-
-/* Core_Exported_Functions */
-extern uint32_t __get_FFLAGS(void);
-extern void __set_FFLAGS(uint32_t value);
-extern uint32_t __get_FRM(void);
-extern void __set_FRM(uint32_t value);
-extern uint32_t __get_FCSR(void);
-extern void __set_FCSR(uint32_t value);
-extern uint32_t __get_MSTATUS(void);
-extern void __set_MSTATUS(uint32_t value);
-extern uint32_t __get_MISA(void);
-extern void __set_MISA(uint32_t value);
-extern uint32_t __get_MIE(void);
-extern void __set_MIE(uint32_t value);
-extern uint32_t __get_MTVEC(void);
-extern void __set_MTVEC(uint32_t value);
-extern uint32_t __get_MSCRATCH(void);
-extern void __set_MSCRATCH(uint32_t value);
-extern uint32_t __get_MEPC(void);
-extern void __set_MEPC(uint32_t value);
-extern uint32_t __get_MCAUSE(void);
-extern void __set_MCAUSE(uint32_t value);
-extern uint32_t __get_MTVAL(void);
-extern void __set_MTVAL(uint32_t value);
-extern uint32_t __get_MIP(void);
-extern void __set_MIP(uint32_t value);
-extern uint32_t __get_MCYCLE(void);
-extern void __set_MCYCLE(uint32_t value);
-extern uint32_t __get_MCYCLEH(void);
-extern void __set_MCYCLEH(uint32_t value);
-extern uint32_t __get_MINSTRET(void);
-extern void __set_MINSTRET(uint32_t value);
-extern uint32_t __get_MINSTRETH(void);
-extern void __set_MINSTRETH(uint32_t value);
-extern uint32_t __get_MVENDORID(void);
-extern uint32_t __get_MARCHID(void);
-extern uint32_t __get_MIMPID(void);
-extern uint32_t __get_MHARTID(void);
-extern uint32_t __get_SP(void);
-
-
-#endif
diff --git a/hw/bsp/ch32v307/family.c b/hw/bsp/ch32v307/family.c
deleted file mode 100644
index 245fa5674..000000000
--- a/hw/bsp/ch32v307/family.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2022 Greg Davill
- *
- * 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.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "stdio.h"
-#include "debug_uart.h"
-#include "ch32v30x.h"
-
-#include "bsp/board_api.h"
-#include "board.h"
-
-//--------------------------------------------------------------------+
-// Forward USB interrupt events to TinyUSB IRQ Handler
-//--------------------------------------------------------------------+
-
-void USBHS_IRQHandler (void) __attribute__((naked));
-void USBHS_IRQHandler (void)
-{
- __asm volatile ("call USBHS_IRQHandler_impl; mret");
-}
-
-__attribute__ ((used)) void USBHS_IRQHandler_impl (void)
-{
- tud_int_handler(0);
-}
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM
-//--------------------------------------------------------------------+
-
-uint32_t SysTick_Config(uint32_t ticks)
-{
- NVIC_EnableIRQ(SysTicK_IRQn);
- SysTick->CTLR=0;
- SysTick->SR=0;
- SysTick->CNT=0;
- SysTick->CMP=ticks-1;
- SysTick->CTLR=0xF;
- return 0;
-}
-
-void board_init(void) {
-
- /* Disable interrupts during init */
- __disable_irq();
-
-#if CFG_TUSB_OS == OPT_OS_NONE
- SysTick_Config(SystemCoreClock / 1000);
-#endif
-
- usart_printf_init(115200);
-
- RCC_USBCLK48MConfig(RCC_USBCLK48MCLKSource_USBPHY);
- RCC_USBHSPLLCLKConfig(RCC_HSBHSPLLCLKSource_HSE);
- RCC_USBHSConfig(RCC_USBPLL_Div2);
- RCC_USBHSPLLCKREFCLKConfig(RCC_USBHSPLLCKREFCLK_4M);
- RCC_USBHSPHYPLLALIVEcmd(ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_USBHS, ENABLE);
-
- GPIO_InitTypeDef GPIO_InitStructure = {0};
-
- // LED
- LED_CLOCK_EN();
- GPIO_InitStructure.GPIO_Pin = LED_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(LED_PORT, &GPIO_InitStructure);
-
- // Button
- BUTTON_CLOCK_EN();
- GPIO_InitStructure.GPIO_Pin = BUTTON_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(BUTTON_PORT, &GPIO_InitStructure);
-
- /* Enable interrupts globally */
- __enable_irq();
-
- board_delay(2);
-}
-
-#if CFG_TUSB_OS == OPT_OS_NONE
-
-volatile uint32_t system_ticks = 0;
-
-/* Small workaround to support HW stack save/restore */
-void SysTick_Handler (void) __attribute__((naked));
-void SysTick_Handler (void)
-{
- __asm volatile ("call SysTick_Handler_impl; mret");
-}
-
-__attribute__((used)) void SysTick_Handler_impl (void)
-{
- SysTick->SR = 0;
- system_ticks++;
-}
-
-uint32_t board_millis (void)
-{
- return system_ticks;
-}
-
-#endif
-
-//--------------------------------------------------------------------+
-// Board porting API
-//--------------------------------------------------------------------+
-
-void board_led_write (bool state)
-{
- GPIO_WriteBit(LED_PORT, LED_PIN, state);
-}
-
-uint32_t board_button_read (void)
-{
- return BUTTON_STATE_ACTIVE == GPIO_ReadInputDataBit(BUTTON_PORT, BUTTON_PIN);
-}
-
-int board_uart_read (uint8_t *buf, int len)
-{
- (void) buf;
- (void) len;
- return 0;
-}
-
-int board_uart_write (void const *buf, int len)
-{
- int txsize = len;
- while ( txsize-- )
- {
- uart_write(*(uint8_t const*) buf);
- buf++;
- }
- return len;
-}
-
-
-
-#ifdef USE_FULL_ASSERT
-/**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
-void assert_failed(char* file, uint32_t line) {
- /* USER CODE BEGIN 6 */
- /* User can add his own implementation to report the file name and line
- number,
- tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line)
- */
- /* USER CODE END 6 */
-}
-#endif /* USE_FULL_ASSERT */
diff --git a/hw/bsp/ch32v307/family.mk b/hw/bsp/ch32v307/family.mk
deleted file mode 100644
index 4b06cf429..000000000
--- a/hw/bsp/ch32v307/family.mk
+++ /dev/null
@@ -1,64 +0,0 @@
-# https://www.embecosm.com/resources/tool-chain-downloads/#riscv-stable
-#CROSS_COMPILE ?= riscv32-unknown-elf-
-
-# Toolchain from https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack
-CROSS_COMPILE ?= riscv-none-embed-
-
-# Submodules
-CH32V307_SDK = hw/mcu/wch/ch32v307
-DEPS_SUBMODULES += $(CH32V307_SDK)
-
-# WCH-SDK paths
-CH32V307_SDK_SRC = $(CH32V307_SDK)/EVT/EXAM/SRC
-
-include $(TOP)/$(BOARD_PATH)/board.mk
-
-CFLAGS += \
- -flto \
- -march=rv32imac \
- -mabi=ilp32 \
- -msmall-data-limit=8 \
- -mno-save-restore -Os \
- -fmessage-length=0 \
- -fsigned-char \
- -ffunction-sections \
- -fdata-sections \
- -nostdlib -nostartfiles \
- -DCFG_TUSB_MCU=OPT_MCU_CH32V307 \
- -Xlinker --gc-sections \
- -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED
-
-SRC_C += \
- src/portable/wch/ch32v307/dcd_usbhs.c \
- $(CH32V307_SDK_SRC)/Core/core_riscv.c \
- $(CH32V307_SDK_SRC)/Peripheral/src/ch32v30x_gpio.c \
- $(CH32V307_SDK_SRC)/Peripheral/src/ch32v30x_misc.c \
- $(CH32V307_SDK_SRC)/Peripheral/src/ch32v30x_rcc.c \
- $(CH32V307_SDK_SRC)/Peripheral/src/ch32v30x_usart.c
-
-SRC_S += \
- $(CH32V307_SDK_SRC)/Startup/startup_ch32v30x_D8C.S
-
-INC += \
- $(TOP)/$(BOARD_PATH) \
- $(TOP)/$(CH32V307_SDK_SRC)/Peripheral/inc
-
-# For freeRTOS port source
-FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/RISC-V
-
-# wch-link is not supported yet in official openOCD yet. We need to either use
-# 1. download openocd as part of mounriver studio http://www.mounriver.com/download or
-# 2. compiled from modified source https://github.com/kprasadvnsi/riscv-openocd-wch
-#
-# Note: For Linux, somehow openocd in mounriver studio does not seem to have wch-link enable,
-# therefore we need to compile it from source as follows:
-# git clone https://github.com/kprasadvnsi/riscv-openocd-wch
-# cd riscv-openocd-wch
-# ./bootstrap
-# ./configure CFLAGS="-Wno-error" --enable-wlink
-# make
-# openocd binaries will be generated in riscv-openocd-wch/src
-
-# flash target ROM bootloader
-flash: $(BUILD)/$(PROJECT).elf
- openocd -f $(TOP)/$(FAMILY_PATH)/wch-riscv.cfg -c init -c halt -c "program $<" -c wlink_reset_resume -c exit
diff --git a/hw/bsp/ch32v307/system_ch32v30x.c b/hw/bsp/ch32v307/system_ch32v30x.c
deleted file mode 100644
index 23f783df4..000000000
--- a/hw/bsp/ch32v307/system_ch32v30x.c
+++ /dev/null
@@ -1,776 +0,0 @@
-/********************************** (C) COPYRIGHT *******************************
-* File Name : system_ch32v30x.c
-* Author : WCH
-* Version : V1.0.0
-* Date : 2021/06/06
-* Description : CH32V30x Device Peripheral Access Layer System Source File.
-* For HSE = 8Mhz
-* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
-* SPDX-License-Identifier: Apache-2.0
-*********************************************************************************/
-#include "ch32v30x.h"
-
-/*
-* Uncomment the line corresponding to the desired System clock (SYSCLK) frequency (after
-* reset the HSI is used as SYSCLK source).
-* If none of the define below is enabled, the HSI is used as System clock source.
-*/
-// #define SYSCLK_FREQ_HSE HSE_VALUE
-/* #define SYSCLK_FREQ_24MHz 24000000 */
-//#define SYSCLK_FREQ_48MHz 48000000
-/* #define SYSCLK_FREQ_56MHz 56000000 */
-//#define SYSCLK_FREQ_72MHz 72000000
-//#define SYSCLK_FREQ_96MHz 96000000
-//#define SYSCLK_FREQ_120MHz 120000000
-#define SYSCLK_FREQ_144MHz 144000000
-
-/* Clock Definitions */
-#ifdef SYSCLK_FREQ_HSE
- uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /* System Clock Frequency (Core Clock) */
-#elif defined SYSCLK_FREQ_24MHz
- uint32_t SystemCoreClock = SYSCLK_FREQ_24MHz; /* System Clock Frequency (Core Clock) */
-#elif defined SYSCLK_FREQ_48MHz
- uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz; /* System Clock Frequency (Core Clock) */
-#elif defined SYSCLK_FREQ_56MHz
- uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz; /* System Clock Frequency (Core Clock) */
-#elif defined SYSCLK_FREQ_72MHz
- uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz; /* System Clock Frequency (Core Clock) */
-
-#elif defined SYSCLK_FREQ_96MHz
- uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz; /* System Clock Frequency (Core Clock) */
-#elif defined SYSCLK_FREQ_120MHz
- uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz; /* System Clock Frequency (Core Clock) */
-#elif defined SYSCLK_FREQ_144MHz
- uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz; /* System Clock Frequency (Core Clock) */
-
-#else /* HSI Selected as System Clock source */
- uint32_t SystemCoreClock = HSI_VALUE; /* System Clock Frequency (Core Clock) */
-#endif
-
-__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
-
-
-/* system_private_function_proto_types */
-static void SetSysClock(void);
-
-#ifdef SYSCLK_FREQ_HSE
- static void SetSysClockToHSE(void);
-#elif defined SYSCLK_FREQ_24MHz
- static void SetSysClockTo24(void);
-#elif defined SYSCLK_FREQ_48MHz
- static void SetSysClockTo48(void);
-#elif defined SYSCLK_FREQ_56MHz
- static void SetSysClockTo56(void);
-#elif defined SYSCLK_FREQ_72MHz
- static void SetSysClockTo72(void);
-
-#elif defined SYSCLK_FREQ_96MHz
- static void SetSysClockTo96(void);
-#elif defined SYSCLK_FREQ_120MHz
- static void SetSysClockTo120(void);
-#elif defined SYSCLK_FREQ_144MHz
- static void SetSysClockTo144(void);
-
-#endif
-
-
-/*********************************************************************
- * @fn SystemInit
- *
- * @brief Setup the microcontroller system Initialize the Embedded Flash Interface,
- * the PLL and update the SystemCoreClock variable.
- *
- * @return none
- */
-void SystemInit (void)
-{
- RCC->CTLR |= (uint32_t)0x00000001;
-
-#ifdef CH32V30x_D8C
- RCC->CFGR0 &= (uint32_t)0xF8FF0000;
-#else
- RCC->CFGR0 &= (uint32_t)0xF0FF0000;
-#endif
-
- RCC->CTLR &= (uint32_t)0xFEF6FFFF;
- RCC->CTLR &= (uint32_t)0xFFFBFFFF;
- RCC->CFGR0 &= (uint32_t)0xFF80FFFF;
-
-#ifdef CH32V30x_D8C
- RCC->CTLR &= (uint32_t)0xEBFFFFFF;
- RCC->INTR = 0x00FF0000;
- RCC->CFGR2 = 0x00000000;
-#else
- RCC->INTR = 0x009F0000;
-#endif
- SetSysClock();
-}
-
-/*********************************************************************
- * @fn SystemCoreClockUpdate
- *
- * @brief Update SystemCoreClock variable according to Clock Register Values.
- *
- * @return none
- */
-void SystemCoreClockUpdate (void)
-{
- uint32_t tmp = 0, pllmull = 0, pllsource = 0, Pll_6_5 = 0;
-
- tmp = RCC->CFGR0 & RCC_SWS;
-
- switch (tmp)
- {
- case 0x00:
- SystemCoreClock = HSI_VALUE;
- break;
- case 0x04:
- SystemCoreClock = HSE_VALUE;
- break;
- case 0x08:
- pllmull = RCC->CFGR0 & RCC_PLLMULL;
- pllsource = RCC->CFGR0 & RCC_PLLSRC;
- pllmull = ( pllmull >> 18) + 2;
-
-#ifdef CH32V30x_D8
- if(pllmull == 17) pllmull = 18;
-#else
- if(pllmull == 2) pllmull = 18;
- if(pllmull == 15){
- pllmull = 13; /* *6.5 */
- Pll_6_5 = 1;
- }
- if(pllmull == 16) pllmull = 15;
- if(pllmull == 17) pllmull = 16;
-#endif
-
- if (pllsource == 0x00)
- {
- SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
- }
- else
- {
- if ((RCC->CFGR0 & RCC_PLLXTPRE) != (uint32_t)RESET)
- {
- SystemCoreClock = (HSE_VALUE >> 1) * pllmull;
- }
- else
- {
- SystemCoreClock = HSE_VALUE * pllmull;
- }
- }
-
- if(Pll_6_5 == 1) SystemCoreClock = (SystemCoreClock / 2);
-
- break;
- default:
- SystemCoreClock = HSI_VALUE;
- break;
- }
-
- tmp = AHBPrescTable[((RCC->CFGR0 & RCC_HPRE) >> 4)];
- SystemCoreClock >>= tmp;
-}
-
-/*********************************************************************
- * @fn SetSysClock
- *
- * @brief Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers.
- *
- * @return none
- */
-static void SetSysClock(void)
-{
-#ifdef SYSCLK_FREQ_HSE
- SetSysClockToHSE();
-#elif defined SYSCLK_FREQ_24MHz
- SetSysClockTo24();
-#elif defined SYSCLK_FREQ_48MHz
- SetSysClockTo48();
-#elif defined SYSCLK_FREQ_56MHz
- SetSysClockTo56();
-#elif defined SYSCLK_FREQ_72MHz
- SetSysClockTo72();
-#elif defined SYSCLK_FREQ_96MHz
- SetSysClockTo96();
-#elif defined SYSCLK_FREQ_120MHz
- SetSysClockTo120();
-#elif defined SYSCLK_FREQ_144MHz
- SetSysClockTo144();
-
-#endif
-
- /* If none of the define above is enabled, the HSI is used as System clock
- * source (default after reset)
- */
-}
-
-
-#ifdef SYSCLK_FREQ_HSE
-
-/*********************************************************************
- * @fn SetSysClockToHSE
- *
- * @brief Sets HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
- *
- * @return none
- */
-static void SetSysClockToHSE(void)
-{
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
- RCC->CTLR |= ((uint32_t)RCC_HSEON);
-
- /* Wait till HSE is ready and if Time out is reached exit */
- do
- {
- HSEStatus = RCC->CTLR & RCC_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
-
- if ((RCC->CTLR & RCC_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
-
- if (HSEStatus == (uint32_t)0x01)
- {
- /* HCLK = SYSCLK */
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
- /* PCLK2 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
- /* PCLK1 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1;
-
- /* Select HSE as system clock source */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
- RCC->CFGR0 |= (uint32_t)RCC_SW_HSE;
-
- /* Wait till HSE is used as system clock source */
- while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x04)
- {
- }
- }
- else
- {
- /* If HSE fails to start-up, the application will have wrong clock
- * configuration. User can add here some code to deal with this error
- */
- }
-}
-
-#elif defined SYSCLK_FREQ_24MHz
-
-/*********************************************************************
- * @fn SetSysClockTo24
- *
- * @brief Sets System clock frequency to 24MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
- *
- * @return none
- */
-static void SetSysClockTo24(void)
-{
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
- RCC->CTLR |= ((uint32_t)RCC_HSEON);
-
- /* Wait till HSE is ready and if Time out is reached exit */
- do
- {
- HSEStatus = RCC->CTLR & RCC_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
-
- if ((RCC->CTLR & RCC_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
- if (HSEStatus == (uint32_t)0x01)
- {
- /* HCLK = SYSCLK */
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
- /* PCLK2 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
- /* PCLK1 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1;
-
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
-
-#ifdef CH32V30x_D8
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL3);
-#else
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL3_EXTEN);
-#endif
- /* Enable PLL */
- RCC->CTLR |= RCC_PLLON;
-
- /* Wait till PLL is ready */
- while((RCC->CTLR & RCC_PLLRDY) == 0)
- {
- }
- /* Select PLL as system clock source */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
- /* Wait till PLL is used as system clock source */
- while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- /* If HSE fails to start-up, the application will have wrong clock
- * configuration. User can add here some code to deal with this error
- */
- }
-}
-
-#elif defined SYSCLK_FREQ_48MHz
-
-/*********************************************************************
- * @fn SetSysClockTo48
- *
- * @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
- *
- * @return none
- */
-static void SetSysClockTo48(void)
-{
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
-
- RCC->CTLR |= ((uint32_t)RCC_HSEON);
- /* Wait till HSE is ready and if Time out is reached exit */
- do
- {
- HSEStatus = RCC->CTLR & RCC_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
-
- if ((RCC->CTLR & RCC_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
-
- if (HSEStatus == (uint32_t)0x01)
- {
- /* HCLK = SYSCLK */
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
- /* PCLK2 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
- /* PCLK1 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
-
- /* PLL configuration: PLLCLK = HSE * 6 = 48 MHz */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
-
-#ifdef CH32V30x_D8
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL6);
-#else
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL6_EXTEN);
-#endif
-
- /* Enable PLL */
- RCC->CTLR |= RCC_PLLON;
- /* Wait till PLL is ready */
- while((RCC->CTLR & RCC_PLLRDY) == 0)
- {
- }
- /* Select PLL as system clock source */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
- /* Wait till PLL is used as system clock source */
- while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- /*
- * If HSE fails to start-up, the application will have wrong clock
- * configuration. User can add here some code to deal with this error
- */
- }
-}
-
-#elif defined SYSCLK_FREQ_56MHz
-
-/*********************************************************************
- * @fn SetSysClockTo56
- *
- * @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
- *
- * @return none
- */
-static void SetSysClockTo56(void)
-{
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
- RCC->CTLR |= ((uint32_t)RCC_HSEON);
-
- /* Wait till HSE is ready and if Time out is reached exit */
- do
- {
- HSEStatus = RCC->CTLR & RCC_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
-
- if ((RCC->CTLR & RCC_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
-
- if (HSEStatus == (uint32_t)0x01)
- {
- /* HCLK = SYSCLK */
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
- /* PCLK2 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
- /* PCLK1 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
-
- /* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
-
-#ifdef CH32V30x_D8
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL7);
-#else
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL7_EXTEN);
-#endif
-
- /* Enable PLL */
- RCC->CTLR |= RCC_PLLON;
- /* Wait till PLL is ready */
- while((RCC->CTLR & RCC_PLLRDY) == 0)
- {
- }
-
- /* Select PLL as system clock source */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
- /* Wait till PLL is used as system clock source */
- while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- /*
- * If HSE fails to start-up, the application will have wrong clock
- * configuration. User can add here some code to deal with this error
- */
- }
-}
-
-#elif defined SYSCLK_FREQ_72MHz
-
-/*********************************************************************
- * @fn SetSysClockTo72
- *
- * @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
- *
- * @return none
- */
-static void SetSysClockTo72(void)
-{
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
- RCC->CTLR |= ((uint32_t)RCC_HSEON);
-
- /* Wait till HSE is ready and if Time out is reached exit */
- do
- {
- HSEStatus = RCC->CTLR & RCC_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
-
- if ((RCC->CTLR & RCC_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
-
- if (HSEStatus == (uint32_t)0x01)
- {
- /* HCLK = SYSCLK */
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
- /* PCLK2 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
- /* PCLK1 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
-
- /* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
- RCC_PLLMULL));
-
-#ifdef CH32V30x_D8
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL9);
-#else
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL9_EXTEN);
-#endif
-
- /* Enable PLL */
- RCC->CTLR |= RCC_PLLON;
- /* Wait till PLL is ready */
- while((RCC->CTLR & RCC_PLLRDY) == 0)
- {
- }
- /* Select PLL as system clock source */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
- /* Wait till PLL is used as system clock source */
- while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- /*
- * If HSE fails to start-up, the application will have wrong clock
- * configuration. User can add here some code to deal with this error
- */
- }
-}
-
-
-#elif defined SYSCLK_FREQ_96MHz
-
-/*********************************************************************
- * @fn SetSysClockTo96
- *
- * @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
- *
- * @return none
- */
-static void SetSysClockTo96(void)
-{
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
- RCC->CTLR |= ((uint32_t)RCC_HSEON);
-
- /* Wait till HSE is ready and if Time out is reached exit */
- do
- {
- HSEStatus = RCC->CTLR & RCC_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
-
- if ((RCC->CTLR & RCC_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
-
- if (HSEStatus == (uint32_t)0x01)
- {
- /* HCLK = SYSCLK */
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
- /* PCLK2 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
- /* PCLK1 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
-
- /* PLL configuration: PLLCLK = HSE * 12 = 96 MHz */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
- RCC_PLLMULL));
-
-#ifdef CH32V30x_D8
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL12);
-#else
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL12_EXTEN);
-#endif
-
- /* Enable PLL */
- RCC->CTLR |= RCC_PLLON;
- /* Wait till PLL is ready */
- while((RCC->CTLR & RCC_PLLRDY) == 0)
- {
- }
- /* Select PLL as system clock source */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
- /* Wait till PLL is used as system clock source */
- while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- /*
- * If HSE fails to start-up, the application will have wrong clock
- * configuration. User can add here some code to deal with this error
- */
- }
-}
-
-
-#elif defined SYSCLK_FREQ_120MHz
-
-/*********************************************************************
- * @fn SetSysClockTo120
- *
- * @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
- *
- * @return none
- */
-static void SetSysClockTo120(void)
-{
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
- RCC->CTLR |= ((uint32_t)RCC_HSEON);
-
- /* Wait till HSE is ready and if Time out is reached exit */
- do
- {
- HSEStatus = RCC->CTLR & RCC_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
-
- if ((RCC->CTLR & RCC_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
-
- if (HSEStatus == (uint32_t)0x01)
- {
- /* HCLK = SYSCLK */
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
- /* PCLK2 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
- /* PCLK1 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
-
- /* PLL configuration: PLLCLK = HSE * 15 = 120 MHz */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
- RCC_PLLMULL));
-
-#ifdef CH32V30x_D8
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL15);
-#else
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL15_EXTEN);
-#endif
-
- /* Enable PLL */
- RCC->CTLR |= RCC_PLLON;
- /* Wait till PLL is ready */
- while((RCC->CTLR & RCC_PLLRDY) == 0)
- {
- }
- /* Select PLL as system clock source */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
- /* Wait till PLL is used as system clock source */
- while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- /*
- * If HSE fails to start-up, the application will have wrong clock
- * configuration. User can add here some code to deal with this error
- */
- }
-}
-
-
-#elif defined SYSCLK_FREQ_144MHz
-
-/*********************************************************************
- * @fn SetSysClockTo144
- *
- * @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
- *
- * @return none
- */
-static void SetSysClockTo144(void)
-{
- __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
-
- RCC->CTLR |= ((uint32_t)RCC_HSEON);
-
- /* Wait till HSE is ready and if Time out is reached exit */
- do
- {
- HSEStatus = RCC->CTLR & RCC_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
-
- if ((RCC->CTLR & RCC_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
-
- if (HSEStatus == (uint32_t)0x01)
- {
- /* HCLK = SYSCLK */
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
- /* PCLK2 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
- /* PCLK1 = HCLK */
- RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
-
- /* PLL configuration: PLLCLK = HSE * 18 = 144 MHz */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
- RCC_PLLMULL));
-
-#ifdef CH32V30x_D8
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL18);
-#else
- RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL18_EXTEN);
-#endif
-
- /* Enable PLL */
- RCC->CTLR |= RCC_PLLON;
- /* Wait till PLL is ready */
- while((RCC->CTLR & RCC_PLLRDY) == 0)
- {
- }
- /* Select PLL as system clock source */
- RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
- /* Wait till PLL is used as system clock source */
- while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
- {
- }
- }
- else
- {
- /*
- * If HSE fails to start-up, the application will have wrong clock
- * configuration. User can add here some code to deal with this error
- */
- }
-}
-
-
-#endif
diff --git a/hw/bsp/ch32v307/system_ch32v30x.h b/hw/bsp/ch32v307/system_ch32v30x.h
deleted file mode 100644
index ad81058c7..000000000
--- a/hw/bsp/ch32v307/system_ch32v30x.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/********************************** (C) COPYRIGHT *******************************
-* File Name : system_ch32v30x.h
-* Author : WCH
-* Version : V1.0.0
-* Date : 2021/06/06
-* Description : CH32V30x Device Peripheral Access Layer System Header File.
-* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
-* SPDX-License-Identifier: Apache-2.0
-*******************************************************************************/
-#ifndef __SYSTEM_CH32V30x_H
-#define __SYSTEM_CH32V30x_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-extern uint32_t SystemCoreClock; /* System Clock Frequency (Core Clock) */
-
-/* System_Exported_Functions */
-extern void SystemInit(void);
-extern void SystemCoreClockUpdate(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*__CH32V30x_SYSTEM_H */
diff --git a/hw/bsp/ch32v307/wch-riscv.cfg b/hw/bsp/ch32v307/wch-riscv.cfg
deleted file mode 100644
index 0d24d16ca..000000000
--- a/hw/bsp/ch32v307/wch-riscv.cfg
+++ /dev/null
@@ -1,15 +0,0 @@
-#interface wlink
-adapter driver wlink
-wlink_set
-set _CHIPNAME riscv
-jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x00001
-
-set _TARGETNAME $_CHIPNAME.cpu
-
-target create $_TARGETNAME.0 riscv -chain-position $_TARGETNAME
-$_TARGETNAME.0 configure -work-area-phys 0x80000000 -work-area-size 10000 -work-area-backup 1
-set _FLASHNAME $_CHIPNAME.flash
-
-flash bank $_FLASHNAME wch_riscv 0x00000000 0 0 0 $_TARGETNAME.0
-
-echo "Ready for Remote Connections"
diff --git a/hw/bsp/d5035_01/board.mk b/hw/bsp/d5035_01/board.mk
new file mode 100644
index 000000000..1d09bd3d4
--- /dev/null
+++ b/hw/bsp/d5035_01/board.mk
@@ -0,0 +1,58 @@
+DEPS_SUBMODULES += hw/mcu/microchip
+HWREV ?= 1
+
+CFLAGS += \
+ -mthumb \
+ -mabi=aapcs \
+ -mlong-calls \
+ -mcpu=cortex-m4 \
+ -mfloat-abi=hard \
+ -mfpu=fpv4-sp-d16 \
+ -nostdlib -nostartfiles \
+ -D__SAME51J19A__ \
+ -DCONF_CPU_FREQUENCY=80000000 \
+ -DCONF_GCLK_USB_FREQUENCY=48000000 \
+ -DCFG_TUSB_MCU=OPT_MCU_SAME5X \
+ -DD5035_01=1 \
+ -DBOARD_NAME="\"D5035-01\"" \
+ -DSVC_Handler=SVCall_Handler \
+ -DHWREV=$(HWREV)
+
+# All source paths should be relative to the top level.
+LD_FILE = hw/bsp/$(BOARD)/same51j19a_flash.ld
+
+SRC_C += \
+ src/portable/microchip/samd/dcd_samd.c \
+ hw/mcu/microchip/same51/gcc/gcc/startup_same51.c \
+ hw/mcu/microchip/same51/gcc/system_same51.c
+
+ifdef SYSCALLS
+ifneq ($(SYSCALLS),0)
+ SRC_C += hw/mcu/microchip/same51/hal/utils/src/utils_syscalls.c
+endif
+endif
+
+ifdef LOG
+ifneq ($(LOG),0)
+ SRC_C += hw/mcu/microchip/same51/hal/utils/src/utils_syscalls.c
+endif
+endif
+
+INC += \
+ $(TOP)/hw/mcu/microchip/same51/ \
+ $(TOP)/hw/mcu/microchip/same51/config \
+ $(TOP)/hw/mcu/microchip/same51/include \
+ $(TOP)/hw/mcu/microchip/same51/hal/include \
+ $(TOP)/hw/mcu/microchip/same51/hal/utils/include \
+ $(TOP)/hw/mcu/microchip/same51/hpl/port \
+ $(TOP)/hw/mcu/microchip/same51/hri \
+ $(TOP)/hw/mcu/microchip/same51/CMSIS/Include
+
+# For freeRTOS port source
+FREERTOS_PORT = ARM_CM4F
+
+# For flash-jlink target
+JLINK_DEVICE = ATSAME51J19
+
+# flash using jlink
+flash: flash-jlink
diff --git a/hw/bsp/same5x/boards/d5035_01/d5035_01.c b/hw/bsp/d5035_01/d5035_01.c
similarity index 99%
rename from hw/bsp/same5x/boards/d5035_01/d5035_01.c
rename to hw/bsp/d5035_01/d5035_01.c
index eb5768d0d..5685ff16f 100644
--- a/hw/bsp/same5x/boards/d5035_01/d5035_01.c
+++ b/hw/bsp/d5035_01/d5035_01.c
@@ -24,7 +24,7 @@
*/
#include
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include
@@ -270,7 +270,7 @@ void board_init(void)
#endif
-#if CFG_TUD_ENABLED
+#if TUSB_OPT_DEVICE_ENABLED
#if CFG_TUSB_DEBUG >= 2
uart_send_str(BOARD_NAME " USB device enabled\n");
#endif
diff --git a/hw/bsp/same5x/boards/d5035_01/same51j19a_flash.ld b/hw/bsp/d5035_01/same51j19a_flash.ld
similarity index 99%
rename from hw/bsp/same5x/boards/d5035_01/same51j19a_flash.ld
rename to hw/bsp/d5035_01/same51j19a_flash.ld
index a8dd44336..328d1c72f 100644
--- a/hw/bsp/same5x/boards/d5035_01/same51j19a_flash.ld
+++ b/hw/bsp/d5035_01/same51j19a_flash.ld
@@ -160,5 +160,4 @@ SECTIONS
. = ALIGN(4);
_end = . ;
- end = .;
}
diff --git a/hw/bsp/da14695_dk_usb/board.mk b/hw/bsp/da14695_dk_usb/board.mk
index 1f7bc1588..e969c79c2 100644
--- a/hw/bsp/da14695_dk_usb/board.mk
+++ b/hw/bsp/da14695_dk_usb/board.mk
@@ -31,7 +31,7 @@ INC += \
$(TOP)/$(MCU_FAMILY_DIR)/SDK_10.0.8.105/sdk/bsp/include
# For freeRTOS port source
-FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM33_NTZ/non_secure
+FREERTOS_PORT = ARM_CM33_NTZ/non_secure
# For flash-jlink target
JLINK_DEVICE = DA14695
@@ -52,3 +52,4 @@ flash-dialog: $(BUILD)/$(PROJECT).bin
@echo go >> $(BUILD)/$(BOARD).jlink
@echo exit >> $(BUILD)/$(BOARD).jlink
$(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink
+
diff --git a/hw/bsp/da14695_dk_usb/da14695_dk_usb.c b/hw/bsp/da14695_dk_usb/da14695_dk_usb.c
index 667b83de3..95fe70d01 100644
--- a/hw/bsp/da14695_dk_usb/da14695_dk_usb.c
+++ b/hw/bsp/da14695_dk_usb/da14695_dk_usb.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Jerzy Kasenberg
@@ -24,7 +24,7 @@
* This file is part of the TinyUSB stack.
*/
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include
#include
@@ -73,7 +73,7 @@ void board_init(void)
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
-#if CFG_TUD_ENABLED
+#if TUSB_OPT_DEVICE_ENABLED
// This board is USB powered there is no need to monitor
// VBUS line. Notify driver that VBUS is present.
tusb_vbus_changed(true);
diff --git a/hw/bsp/da14695_dk_usb/da1469x.ld b/hw/bsp/da14695_dk_usb/da1469x.ld
index 8cc1d9d99..96507d6e7 100644
--- a/hw/bsp/da14695_dk_usb/da1469x.ld
+++ b/hw/bsp/da14695_dk_usb/da1469x.ld
@@ -242,3 +242,4 @@ SECTIONS
/* Check that intvect is at the beginning of RAM */
ASSERT(__intvect_start__ == ORIGIN(RAM), "intvect is not at beginning of RAM")
}
+
diff --git a/hw/bsp/da1469x_dk_pro/board.mk b/hw/bsp/da1469x_dk_pro/board.mk
index f9bf480de..980fc422f 100644
--- a/hw/bsp/da1469x_dk_pro/board.mk
+++ b/hw/bsp/da1469x_dk_pro/board.mk
@@ -31,7 +31,7 @@ INC += \
$(TOP)/$(MCU_FAMILY_DIR)/SDK_10.0.8.105/sdk/bsp/include
# For freeRTOS port source
-FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM33_NTZ/non_secure
+FREERTOS_PORT = ARM_CM33_NTZ/non_secure
# For flash-jlink target
JLINK_DEVICE = DA14699
@@ -52,3 +52,4 @@ flash-dialog: $(BUILD)/$(PROJECT).bin
@echo go >> $(BUILD)/$(BOARD).jlink
@echo exit >> $(BUILD)/$(BOARD).jlink
$(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink
+
diff --git a/hw/bsp/da1469x_dk_pro/da1469x-dk-pro.c b/hw/bsp/da1469x_dk_pro/da1469x-dk-pro.c
index 21bd62714..0441c000c 100644
--- a/hw/bsp/da1469x_dk_pro/da1469x-dk-pro.c
+++ b/hw/bsp/da1469x_dk_pro/da1469x-dk-pro.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Jerzy Kasenberg
@@ -24,7 +24,7 @@
* This file is part of the TinyUSB stack.
*/
-#include "bsp/board_api.h"
+#include "bsp/board.h"
#include