Merge branch 'master' into Serial2
This commit is contained in:
293 files changed
+66758
-23994
No files matched your search
@@ -1,7 +1,7 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[Bug]"
|
||||
title: ''
|
||||
labels: Bug
|
||||
assignees: ''
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: "[Feature]"
|
||||
title: ''
|
||||
labels: Feature
|
||||
assignees: ''
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name: Questions please use our forum support
|
||||
about: Don't open issue, post your question at forums.adafruit.com
|
||||
title: ''
|
||||
labels: ''
|
||||
labels: wontfix
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
name: Build
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
arduino-platform: ['feather52832', 'feather52840', 'cplaynrf52840', 'itsybitsy52840', 'cluenrf52840' ]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Checkout submodules
|
||||
shell: bash
|
||||
run: |
|
||||
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
|
||||
git submodule sync --recursive
|
||||
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive
|
||||
|
||||
- name: Install Arduino CLI and Tools
|
||||
run: |
|
||||
pip3 install adafruit-nrfutil
|
||||
# make all our directories we need for files and libraries
|
||||
mkdir $HOME/.arduino15
|
||||
mkdir $HOME/.arduino15/packages
|
||||
mkdir $HOME/Arduino
|
||||
mkdir $HOME/Arduino/libraries
|
||||
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
|
||||
echo "::add-path::$GITHUB_WORKSPACE/bin"
|
||||
|
||||
- name: Install BSP and Libraries
|
||||
env:
|
||||
BSP_URL: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
|
||||
BSP_PATH: .arduino15/packages/adafruit/hardware/nrf52
|
||||
run: |
|
||||
arduino-cli config init
|
||||
arduino-cli core update-index
|
||||
arduino-cli core update-index --additional-urls $BSP_URL
|
||||
arduino-cli core install adafruit:nrf52 --additional-urls $BSP_URL
|
||||
# Repalce release BSP with our code
|
||||
BSP_VERSION=`eval ls $HOME/$BSP_PATH`
|
||||
rm -r $HOME/$BSP_PATH/*
|
||||
ln -s $GITHUB_WORKSPACE $HOME/$BSP_PATH/$BSP_VERSION
|
||||
# Install library dependency
|
||||
arduino-cli lib install "Adafruit GFX Library" "Adafruit SSD1306" "Adafruit ILI9341" "Adafruit HX8357 Library" "Adafruit EPD"
|
||||
arduino-cli lib install "Adafruit Circuit Playground" "Adafruit NeoPixel" "Adafruit NeoMatrix" "MIDI Library" "Firmata"
|
||||
|
||||
- name: Build examples
|
||||
run: python3 tools/build_all.py ${{ matrix.arduino-platform }}
|
||||
@@ -2,6 +2,9 @@
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Visual Studio Code
|
||||
**/.vscode/
|
||||
|
||||
# Executables
|
||||
*.out
|
||||
*.app
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
[submodule "cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore"]
|
||||
path = cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore
|
||||
url = https://github.com/adafruit/Adafruit_TinyUSB_ArduinoCore.git
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
language: c
|
||||
dist: xenial
|
||||
git:
|
||||
depth: false
|
||||
quiet: true
|
||||
|
||||
env:
|
||||
- BSP_PATH="$HOME/.arduino15/packages/adafruit/hardware/nrf52"
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- python3
|
||||
- python3-pip
|
||||
- python3-setuptools
|
||||
snaps:
|
||||
- name: ubuntu-make
|
||||
confinement: classic
|
||||
|
||||
install:
|
||||
- pip3 install --user adafruit-nrfutil
|
||||
- umake electronics arduino $HOME/arduino_ide
|
||||
- export PATH=$HOME/arduino_ide:$PATH
|
||||
- arduino --pref "boardsmanager.additional.urls=https://adafruit.github.io/arduino-board-index/package_adafruit_index.json" --save-prefs
|
||||
# Install BSP for tools, then remove and create symlink the git code
|
||||
- arduino --install-boards adafruit:nrf52
|
||||
- BSP_VERSION=`eval ls $BSP_PATH`
|
||||
- rm -r $BSP_PATH/*
|
||||
- ln -s $TRAVIS_BUILD_DIR $BSP_PATH/$BSP_VERSION
|
||||
- arduino --install-library "Adafruit NeoPixel","Adafruit NeoMatrix","Adafruit GFX Library","Adafruit SSD1306","MIDI Library",
|
||||
|
||||
before_script:
|
||||
|
||||
script:
|
||||
- python3 tools/build_all.py
|
||||
@@ -0,0 +1,68 @@
|
||||
sudo: required
|
||||
language: c
|
||||
dist: xenial
|
||||
git:
|
||||
depth: false
|
||||
quiet: true
|
||||
|
||||
env:
|
||||
global:
|
||||
- BSP_PATH="$HOME/.arduino15/packages/adafruit/hardware/nrf52"
|
||||
jobs:
|
||||
# empty env required, else allow_failures will SILENTY IGNORE matching against env...
|
||||
-
|
||||
|
||||
jobs:
|
||||
fast_finish: true
|
||||
include:
|
||||
- name: "Feather nRF52840"
|
||||
env: VARIANT="feather52840"
|
||||
- name: "Feather nRF52840 (All warnings)"
|
||||
env: ALL_WARNINGS="true" VARIANT="feather52840"
|
||||
- name: "Circuit Playground nRF52840"
|
||||
env: VARIANT="cplaynrf52840"
|
||||
- name: "Circuit Playground nRF52840 (All warnings)"
|
||||
env: ALL_WARNINGS="true" VARIANT="cplaynrf52840"
|
||||
- name: "Feather nRF52832"
|
||||
env: VARIANT="feather52832"
|
||||
- name: "Feather nRF52832 (All warnings)"
|
||||
env: ALL_WARNINGS="true" VARIANT="feather52832"
|
||||
- name: "ItsyBitsy nRF52840 Express"
|
||||
env: VARIANT="itsybitsy52840"
|
||||
- name: "Clue nRF52840"
|
||||
env: VARIANT="cluenrf52840"
|
||||
allow_failures:
|
||||
- env: ALL_WARNINGS="true" VARIANT="feather52840"
|
||||
- env: ALL_WARNINGS="true" VARIANT="cplaynrf52840"
|
||||
- env: ALL_WARNINGS="true" VARIANT="feather52832"
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- python3
|
||||
- python3-pip
|
||||
- python3-setuptools
|
||||
snaps:
|
||||
- name: ubuntu-make
|
||||
confinement: classic
|
||||
|
||||
install:
|
||||
# Filter only mDNS / Bonjour traffic
|
||||
- sudo iptables --insert INPUT --jump DROP --protocol udp --dport 5353 -m comment --comment "silently drop all 5353/udp input"
|
||||
- sudo iptables --insert INPUT --jump DROP --destination 224.0.0.251 -m comment --comment "silently drop all mDNS ipv4 broadcast"
|
||||
# Install the nRF52 support files for arduino
|
||||
- pip3 install --user adafruit-nrfutil
|
||||
- umake electronics arduino $HOME/arduino_ide
|
||||
- export PATH=$HOME/arduino_ide:$PATH
|
||||
- arduino --pref "boardsmanager.additional.urls=https://adafruit.github.io/arduino-board-index/package_adafruit_index.json" --save-prefs
|
||||
# Install BSP for tools, then remove and create symlink the git code
|
||||
- arduino --install-boards adafruit:nrf52
|
||||
- BSP_VERSION=`eval ls $BSP_PATH`
|
||||
- rm -r $BSP_PATH/*
|
||||
- ln -s $TRAVIS_BUILD_DIR $BSP_PATH/$BSP_VERSION
|
||||
- arduino --install-library "Adafruit NeoPixel","Adafruit NeoMatrix","Adafruit GFX Library","Adafruit SSD1306","MIDI Library","Adafruit ILI9341","Adafruit HX8357 Library","Adafruit Circuit Playground"
|
||||
|
||||
before_script:
|
||||
|
||||
script:
|
||||
- python3 tools/build_all_travis.py
|
||||
@@ -1,9 +1,14 @@
|
||||
# Arduino Core for Adafruit Bluefruit nRF52 Boards
|
||||
|
||||
[](https://github.com/adafruit/Adafruit_nRF52_Arduino/actions)
|
||||
|
||||
This repository contains the Arduino BSP for Adafruit Bluefruit nRF52 series:
|
||||
|
||||
- Adafruit CLUE nRF52840
|
||||
- [Adafruit Feather nRF52832](https://www.adafruit.com/product/3406)
|
||||
- [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
|
||||
- [Adafruit Circuit Playground Bluefruit](https://www.adafruit.com/product/4333)
|
||||
- Adafruit ItsyBitsy nRF52840
|
||||
- Adafruit Metro nRF52840 Express
|
||||
|
||||
Following boards are also included but are not officially supported:
|
||||
@@ -36,7 +41,7 @@ There are two methods that you can use to install this BSP. We highly recommend
|
||||
* Linux : `~/Arduino`
|
||||
* Windows: `~/Documents/Arduino`
|
||||
4. Create a folder named `hardware/Adafruit`, if it does not exist, and change directories to it
|
||||
5. Clone this repo: `git clone https://github.com/adafruit/Adafruit_nRF52_Arduino.git`
|
||||
5. Clone this repo & its submodules: `git clone --recurse-submodules https://github.com/adafruit/Adafruit_nRF52_Arduino.git`
|
||||
6. Restart the Arduino IDE
|
||||
7. Once the BSP is installed, select 'Adafruit Bluefruit nRF52 Feather' from the Tools -> Board menu, which will update your system config to use the right compiler and settings for the nRF52.
|
||||
|
||||
@@ -47,9 +52,9 @@ There are two methods that you can use to install this BSP. We highly recommend
|
||||
- For Windows and macOS, pre-built executable binaries are included in the BSP at `tools/adafruit-nrfutil/`. It should work out of the box.
|
||||
- Linux user need to run follow command to install it from PyPi
|
||||
|
||||
```
|
||||
$ pip3 install adafruit-nrfutil --user
|
||||
```
|
||||
```
|
||||
$ pip3 install adafruit-nrfutil --user
|
||||
```
|
||||
|
||||
### Drivers
|
||||
|
||||
@@ -74,7 +79,7 @@ To burn the bootloader from within the Arduino IDE, you will need the following
|
||||
on your system and available in the system path:
|
||||
|
||||
- Segger [JLink Software and Documentation Pack](https://www.segger.com/downloads/jlink)
|
||||
- Nordic [nRF5x Command Line Tools](http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.tools%2Fdita%2Ftools%2Fnrf5x_command_line_tools%2Fnrf5x_installation.html)
|
||||
- Nordic [nRF5x Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
|
||||
|
||||
Check to make sure you can run `nrfjprog` from your terminal/command prompt
|
||||
|
||||
|
||||
+227
-12
@@ -32,7 +32,7 @@ feather52832.upload.use_1200bps_touch=false
|
||||
feather52832.upload.wait_for_upload_port=false
|
||||
feather52832.upload.native_usb=false
|
||||
feather52832.upload.maximum_size=290816
|
||||
feather52832.upload.maximum_data_size=51072
|
||||
feather52832.upload.maximum_data_size=52224
|
||||
|
||||
# Build
|
||||
feather52832.build.mcu=cortex-m4
|
||||
@@ -40,11 +40,11 @@ feather52832.build.f_cpu=64000000
|
||||
feather52832.build.board=NRF52832_FEATHER
|
||||
feather52832.build.core=nRF5
|
||||
feather52832.build.variant=feather_nrf52832
|
||||
feather52832.build.extra_flags=-DNRF52832_XXAA -DNRF52 -DARDUINO_NRF52_FEATHER
|
||||
feather52832.build.extra_flags=-DNRF52832_XXAA -DNRF52
|
||||
feather52832.build.ldscript=nrf52832_s132_v6.ld
|
||||
|
||||
# SofDevice Menu
|
||||
feather52832.menu.softdevice.s132v6=0.2.11 SoftDevice s132 6.1.1
|
||||
feather52832.menu.softdevice.s132v6=0.3.0 SoftDevice s132 6.1.1
|
||||
feather52832.menu.softdevice.s132v6.build.sd_name=s132
|
||||
feather52832.menu.softdevice.s132v6.build.sd_version=6.1.1
|
||||
feather52832.menu.softdevice.s132v6.build.sd_fwid=0x00B7
|
||||
@@ -81,7 +81,7 @@ feather52840.upload.protocol=nrfutil
|
||||
feather52840.upload.use_1200bps_touch=true
|
||||
feather52840.upload.wait_for_upload_port=true
|
||||
feather52840.upload.maximum_size=815104
|
||||
feather52840.upload.maximum_data_size=248832
|
||||
feather52840.upload.maximum_data_size=237568
|
||||
|
||||
# Build
|
||||
feather52840.build.mcu=cortex-m4
|
||||
@@ -91,13 +91,13 @@ feather52840.build.core=nRF5
|
||||
feather52840.build.variant=feather_nrf52840_express
|
||||
feather52840.build.usb_manufacturer="Adafruit LLC"
|
||||
feather52840.build.usb_product="Feather nRF52840 Express"
|
||||
feather52840.build.extra_flags=-DNRF52840_XXAA -DARDUINO_NRF52_FEATHER {build.flags.usb}
|
||||
feather52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
|
||||
feather52840.build.ldscript=nrf52840_s140_v6.ld
|
||||
feather52840.build.vid=0x239A
|
||||
feather52840.build.pid=0x8029
|
||||
|
||||
# SofDevice Menu
|
||||
feather52840.menu.softdevice.s140v6=0.2.11 SoftDevice s140 6.1.1
|
||||
feather52840.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
|
||||
feather52840.menu.softdevice.s140v6.build.sd_name=s140
|
||||
feather52840.menu.softdevice.s140v6.build.sd_version=6.1.1
|
||||
feather52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
|
||||
@@ -112,6 +112,167 @@ feather52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
|
||||
feather52840.menu.debug.l3=Level 3 (Segger SystemView)
|
||||
feather52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
|
||||
|
||||
|
||||
# ----------------------------------
|
||||
# Bluefruit ItsyBitsy nRF52840 Express
|
||||
# ----------------------------------
|
||||
itsybitsy52840.name=Adafruit ItsyBitsy nRF52840 Express
|
||||
|
||||
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
|
||||
itsybitsy52840.vid.0=0x239A
|
||||
itsybitsy52840.pid.0=0x8051
|
||||
itsybitsy52840.vid.1=0x239A
|
||||
itsybitsy52840.pid.1=0x0051
|
||||
itsybitsy52840.vid.2=0x239A
|
||||
itsybitsy52840.pid.2=0x0052
|
||||
itsybitsy52840.vid.3=0x239A
|
||||
itsybitsy52840.pid.3=0x8052
|
||||
|
||||
# Upload
|
||||
itsybitsy52840.bootloader.tool=bootburn
|
||||
itsybitsy52840.upload.tool=nrfutil
|
||||
itsybitsy52840.upload.protocol=nrfutil
|
||||
itsybitsy52840.upload.use_1200bps_touch=true
|
||||
itsybitsy52840.upload.wait_for_upload_port=true
|
||||
itsybitsy52840.upload.maximum_size=815104
|
||||
itsybitsy52840.upload.maximum_data_size=237568
|
||||
|
||||
# Build
|
||||
itsybitsy52840.build.mcu=cortex-m4
|
||||
itsybitsy52840.build.f_cpu=64000000
|
||||
itsybitsy52840.build.board=NRF52840_ITSYBITSY
|
||||
itsybitsy52840.build.core=nRF5
|
||||
itsybitsy52840.build.variant=itsybitsy_nrf52840_express
|
||||
itsybitsy52840.build.usb_manufacturer="Adafruit LLC"
|
||||
itsybitsy52840.build.usb_product="ItsyBitsy nRF52840 Express"
|
||||
itsybitsy52840.build.extra_flags=-DNRF52840_XXAA -DARDUINO_NRF52_ITSYBITSY {build.flags.usb}
|
||||
itsybitsy52840.build.ldscript=nrf52840_s140_v6.ld
|
||||
itsybitsy52840.build.vid=0x239A
|
||||
itsybitsy52840.build.pid=0x8051
|
||||
|
||||
# SofDevice Menu
|
||||
itsybitsy52840.menu.softdevice.s140v6=0.2.11 SoftDevice s140 6.1.1
|
||||
itsybitsy52840.menu.softdevice.s140v6.build.sd_name=s140
|
||||
itsybitsy52840.menu.softdevice.s140v6.build.sd_version=6.1.1
|
||||
itsybitsy52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
|
||||
|
||||
# Debug Menu
|
||||
itsybitsy52840.menu.debug.l0=Level 0 (Release)
|
||||
itsybitsy52840.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
|
||||
itsybitsy52840.menu.debug.l1=Level 1 (Error Message)
|
||||
itsybitsy52840.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
|
||||
itsybitsy52840.menu.debug.l2=Level 2 (Full Debug)
|
||||
itsybitsy52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
|
||||
itsybitsy52840.menu.debug.l3=Level 3 (Segger SystemView)
|
||||
itsybitsy52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
|
||||
|
||||
# ---------------------------------------------
|
||||
# Bluefruit Circuit Playground nRF52840 Express
|
||||
# ---------------------------------------------
|
||||
cplaynrf52840.name=Adafruit Circuit Playground Bluefruit
|
||||
|
||||
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
|
||||
cplaynrf52840.vid.0=0x239A
|
||||
cplaynrf52840.pid.0=0x8045
|
||||
cplaynrf52840.vid.1=0x239A
|
||||
cplaynrf52840.pid.1=0x0045
|
||||
cplaynrf52840.vid.2=0x239A
|
||||
cplaynrf52840.pid.2=0x0046
|
||||
cplaynrf52840.vid.3=0x239A
|
||||
cplaynrf52840.pid.3=0x8046
|
||||
|
||||
# Upload
|
||||
cplaynrf52840.bootloader.tool=bootburn
|
||||
cplaynrf52840.upload.tool=nrfutil
|
||||
cplaynrf52840.upload.protocol=nrfutil
|
||||
cplaynrf52840.upload.use_1200bps_touch=true
|
||||
cplaynrf52840.upload.wait_for_upload_port=true
|
||||
cplaynrf52840.upload.maximum_size=815104
|
||||
cplaynrf52840.upload.maximum_data_size=237568
|
||||
|
||||
# Build
|
||||
cplaynrf52840.build.mcu=cortex-m4
|
||||
cplaynrf52840.build.f_cpu=64000000
|
||||
cplaynrf52840.build.board=NRF52840_CIRCUITPLAY
|
||||
cplaynrf52840.build.core=nRF5
|
||||
cplaynrf52840.build.variant=circuitplayground_nrf52840
|
||||
cplaynrf52840.build.usb_manufacturer="Adafruit LLC"
|
||||
cplaynrf52840.build.usb_product="Adafruit Circuit Playground Bluefruit"
|
||||
cplaynrf52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
|
||||
cplaynrf52840.build.ldscript=nrf52840_s140_v6.ld
|
||||
cplaynrf52840.build.vid=0x239A
|
||||
cplaynrf52840.build.pid=0x8045
|
||||
|
||||
# SofDevice Menu
|
||||
cplaynrf52840.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
|
||||
cplaynrf52840.menu.softdevice.s140v6.build.sd_name=s140
|
||||
cplaynrf52840.menu.softdevice.s140v6.build.sd_version=6.1.1
|
||||
cplaynrf52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
|
||||
|
||||
# Debug Menu
|
||||
cplaynrf52840.menu.debug.l0=Level 0 (Release)
|
||||
cplaynrf52840.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
|
||||
cplaynrf52840.menu.debug.l1=Level 1 (Error Message)
|
||||
cplaynrf52840.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
|
||||
cplaynrf52840.menu.debug.l2=Level 2 (Full Debug)
|
||||
cplaynrf52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
|
||||
cplaynrf52840.menu.debug.l3=Level 3 (Segger SystemView)
|
||||
cplaynrf52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
|
||||
|
||||
|
||||
# ---------------------------------------------
|
||||
# Clue nRF52840
|
||||
# ---------------------------------------------
|
||||
cluenrf52840.name=Adafruit CLUE
|
||||
|
||||
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
|
||||
cluenrf52840.vid.0=0x239A
|
||||
cluenrf52840.pid.0=0x8072
|
||||
cluenrf52840.vid.1=0x239A
|
||||
cluenrf52840.pid.1=0x0072
|
||||
cluenrf52840.vid.2=0x239A
|
||||
cluenrf52840.pid.2=0x0071
|
||||
cluenrf52840.vid.3=0x239A
|
||||
cluenrf52840.pid.3=0x8071
|
||||
|
||||
# Upload
|
||||
cluenrf52840.bootloader.tool=bootburn
|
||||
cluenrf52840.upload.tool=nrfutil
|
||||
cluenrf52840.upload.protocol=nrfutil
|
||||
cluenrf52840.upload.use_1200bps_touch=true
|
||||
cluenrf52840.upload.wait_for_upload_port=true
|
||||
cluenrf52840.upload.maximum_size=815104
|
||||
cluenrf52840.upload.maximum_data_size=248832
|
||||
|
||||
# Build
|
||||
cluenrf52840.build.mcu=cortex-m4
|
||||
cluenrf52840.build.f_cpu=64000000
|
||||
cluenrf52840.build.board=NRF52840_CLUE
|
||||
cluenrf52840.build.core=nRF5
|
||||
cluenrf52840.build.variant=clue_nrf52840
|
||||
cluenrf52840.build.usb_manufacturer="Adafruit LLC"
|
||||
cluenrf52840.build.usb_product="Adafruit Clue"
|
||||
cluenrf52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
|
||||
cluenrf52840.build.ldscript=nrf52840_s140_v6.ld
|
||||
cluenrf52840.build.vid=0x239A
|
||||
cluenrf52840.build.pid=0x8071
|
||||
|
||||
# SofDevice Menu
|
||||
cluenrf52840.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
|
||||
cluenrf52840.menu.softdevice.s140v6.build.sd_name=s140
|
||||
cluenrf52840.menu.softdevice.s140v6.build.sd_version=6.1.1
|
||||
cluenrf52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
|
||||
|
||||
# Debug Menu
|
||||
cluenrf52840.menu.debug.l0=Level 0 (Release)
|
||||
cluenrf52840.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
|
||||
cluenrf52840.menu.debug.l1=Level 1 (Error Message)
|
||||
cluenrf52840.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
|
||||
cluenrf52840.menu.debug.l2=Level 2 (Full Debug)
|
||||
cluenrf52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
|
||||
cluenrf52840.menu.debug.l3=Level 3 (Segger SystemView)
|
||||
cluenrf52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
|
||||
|
||||
# ----------------------------------
|
||||
# Bluefruit Metro nRF52840 Express
|
||||
# ----------------------------------
|
||||
@@ -134,7 +295,7 @@ metro52840.upload.protocol=nrfutil
|
||||
metro52840.upload.use_1200bps_touch=true
|
||||
metro52840.upload.wait_for_upload_port=true
|
||||
metro52840.upload.maximum_size=815104
|
||||
metro52840.upload.maximum_data_size=248832
|
||||
metro52840.upload.maximum_data_size=237568
|
||||
|
||||
# Build
|
||||
metro52840.build.mcu=cortex-m4
|
||||
@@ -144,13 +305,13 @@ metro52840.build.core=nRF5
|
||||
metro52840.build.variant=metro_nrf52840_express
|
||||
metro52840.build.usb_manufacturer="Adafruit LLC"
|
||||
metro52840.build.usb_product="Metro nRF52840 Express"
|
||||
metro52840.build.extra_flags=-DNRF52840_XXAA -DARDUINO_NRF52_FEATHER {build.flags.usb}
|
||||
metro52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
|
||||
metro52840.build.ldscript=nrf52840_s140_v6.ld
|
||||
metro52840.build.vid=0x239A
|
||||
metro52840.build.pid=0x803F
|
||||
|
||||
# SofDevice Menu
|
||||
metro52840.menu.softdevice.s140v6=0.2.11 SoftDevice s140 6.1.1
|
||||
metro52840.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
|
||||
metro52840.menu.softdevice.s140v6.build.sd_name=s140
|
||||
metro52840.menu.softdevice.s140v6.build.sd_version=6.1.1
|
||||
metro52840.menu.softdevice.s140v6.build.sd_fwid=0x00B6
|
||||
@@ -168,7 +329,7 @@ metro52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
|
||||
# ----------------------------------
|
||||
# Nordic nRF52840DK (PCA10056)
|
||||
# ----------------------------------
|
||||
pca10056.name=Noridc nRF52840DK (PCA10056)
|
||||
pca10056.name=Nordic nRF52840DK (PCA10056)
|
||||
pca10056.bootloader.tool=bootburn
|
||||
|
||||
# Upload
|
||||
@@ -177,7 +338,7 @@ pca10056.upload.protocol=nrfutil
|
||||
pca10056.upload.use_1200bps_touch=true
|
||||
pca10056.upload.wait_for_upload_port=true
|
||||
pca10056.upload.maximum_size=815104
|
||||
pca10056.upload.maximum_data_size=248832
|
||||
pca10056.upload.maximum_data_size=237568
|
||||
|
||||
# Build
|
||||
pca10056.build.mcu=cortex-m4
|
||||
@@ -193,7 +354,7 @@ pca10056.build.vid=0x239A
|
||||
pca10056.build.pid=0x8029
|
||||
|
||||
# SofDevice Menu
|
||||
pca10056.menu.softdevice.s140v6=0.2.11 SoftDevice s140 6.1.1
|
||||
pca10056.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
|
||||
pca10056.menu.softdevice.s140v6.build.sd_name=s140
|
||||
pca10056.menu.softdevice.s140v6.build.sd_version=6.1.1
|
||||
pca10056.menu.softdevice.s140v6.build.sd_fwid=0x00B6
|
||||
@@ -207,3 +368,57 @@ pca10056.menu.debug.l2=Level 2 (Full Debug)
|
||||
pca10056.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
|
||||
pca10056.menu.debug.l3=Level 3 (Segger SystemView)
|
||||
pca10056.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
|
||||
|
||||
# ----------------------------------
|
||||
# Raytac MDBT50Q – RX
|
||||
# ----------------------------------
|
||||
mdbt50qrx.name=Raytac MDBT50Q-RX Dongle
|
||||
|
||||
# VID/PID for bootloader with/without UF2, Arduino + Circuitpython App
|
||||
mdbt50qrx.vid.0=0x239A
|
||||
mdbt50qrx.pid.0=0x8029
|
||||
mdbt50qrx.vid.1=0x239A
|
||||
mdbt50qrx.pid.1=0x0029
|
||||
mdbt50qrx.vid.2=0x239A
|
||||
mdbt50qrx.pid.2=0x002A
|
||||
mdbt50qrx.vid.3=0x239A
|
||||
mdbt50qrx.pid.3=0x802A
|
||||
|
||||
# Upload
|
||||
mdbt50qrx.bootloader.tool=bootburn
|
||||
mdbt50qrx.upload.tool=nrfutil
|
||||
mdbt50qrx.upload.protocol=nrfutil
|
||||
mdbt50qrx.upload.use_1200bps_touch=true
|
||||
mdbt50qrx.upload.wait_for_upload_port=true
|
||||
mdbt50qrx.upload.maximum_size=815104
|
||||
mdbt50qrx.upload.maximum_data_size=248832
|
||||
|
||||
# Build
|
||||
mdbt50qrx.build.mcu=cortex-m4
|
||||
mdbt50qrx.build.f_cpu=64000000
|
||||
mdbt50qrx.build.board=MDBT50Q_RX
|
||||
mdbt50qrx.build.core=nRF5
|
||||
mdbt50qrx.build.variant=raytac_mdbt50q_rx
|
||||
mdbt50qrx.build.usb_manufacturer="Raytac Corporation"
|
||||
mdbt50qrx.build.usb_product="Raytac MDBT50Q - RX"
|
||||
mdbt50qrx.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
|
||||
mdbt50qrx.build.ldscript=nrf52840_s140_v6.ld
|
||||
mdbt50qrx.build.vid=0x239A
|
||||
mdbt50qrx.build.pid=0x8029
|
||||
|
||||
# SofDevice Menu
|
||||
mdbt50qrx.menu.softdevice.s140v6=0.3.0 SoftDevice s140 6.1.1
|
||||
mdbt50qrx.menu.softdevice.s140v6.build.sd_name=s140
|
||||
mdbt50qrx.menu.softdevice.s140v6.build.sd_version=6.1.1
|
||||
mdbt50qrx.menu.softdevice.s140v6.build.sd_fwid=0x00B6
|
||||
|
||||
# Debug Menu
|
||||
mdbt50qrx.menu.debug.l0=Level 0 (Release)
|
||||
mdbt50qrx.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0
|
||||
mdbt50qrx.menu.debug.l1=Level 1 (Error Message)
|
||||
mdbt50qrx.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1
|
||||
mdbt50qrx.menu.debug.l2=Level 2 (Full Debug)
|
||||
mdbt50qrx.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
|
||||
mdbt50qrx.menu.debug.l3=Level 3 (Segger SystemView)
|
||||
mdbt50qrx.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
|
||||
|
||||
+11526
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+1827
-1756
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+1236
-1233
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+11528
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+11524
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+11527
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+1799
-1721
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+1810
-1758
File diff suppressed because it is too large.
Load diff
BIN
Binary file not shown.
+100
-1
@@ -1,6 +1,105 @@
|
||||
# Adafruit nRF52 Arduino Core Changelog
|
||||
|
||||
## Next Release
|
||||
## 0.16.0 - 2020.01.10
|
||||
|
||||
- Fix Little FileSystem (LFS) reentrance issue, by serialize access to lfs_* API(). Huge thanks to @hentrygab for spending lots of his time on PR #397
|
||||
- Fix SPIM transfer with length > 64 KB bytes
|
||||
- Fix #352 PDM issue
|
||||
- SchedulerRTOS::startLoop() support stack size and task priority parameters
|
||||
|
||||
## 0.15.1 - 2019.12.31
|
||||
|
||||
- Print::availableForWrite() return int instead of size_t
|
||||
- Migrate CI from travis to actions
|
||||
|
||||
## 0.15.0 - 2019.12.30
|
||||
|
||||
### Core
|
||||
|
||||
- Add Clue variant
|
||||
- Clean up warnings, thanks to @henrygab
|
||||
- Enhance Software Timer
|
||||
|
||||
### BLE
|
||||
|
||||
- Increase sd attribute table size from 0x800 to 0xC00, increase linker memory for SD 840 from 3400 to 6000
|
||||
- Add Adafruit BLE Service library (used by Circuit Playground Bluefruit App): Temperature, Addressable Pixel, Accel, Button
|
||||
- Add `cplay_ble.ino` example sketch
|
||||
- Change BLEUuid begin's return type to bool
|
||||
- BLECharacteristic allow user to set buffer
|
||||
|
||||
### USB
|
||||
|
||||
- Moved TinyUSB core into submodule at https://github.com/adafruit/Adafruit_TinyUSB_ArduinoCore
|
||||
- Added USBD detach/attach API
|
||||
- Synced TinyUSB with upstream
|
||||
|
||||
## 0.14.6 - 2019.10.30
|
||||
|
||||
- Added power switch pin for Circuit Playground Bluefruit
|
||||
- Make min/max templates
|
||||
|
||||
## 0.14.5 - 2019.10.21
|
||||
|
||||
- Added Itsy nRF52840 Express support
|
||||
- Replace legacy SPI by SPIM3 with maximum 32Mhz for nRF52840
|
||||
- Added support for 2nd I2C interface aka Wire1
|
||||
- Macro defines clean up
|
||||
- remove ARDUINO_FEATHER52
|
||||
- remove ARDUINO_NRF52_FEATHER use either ARDUINO_NRF52832_FEATHER or ARDUINO_NRF52840_FEATHER
|
||||
- use ARDUINO_NRF52840_CIRCUITPLAY for Circuit Playground Bluefruit
|
||||
- ARDUINO_NRF52840_CIRCUITPLAY defined for circuit playground bluefruit
|
||||
- Updated nrfx module to 1.7.2
|
||||
- Fixed more warnings. better describe flash caching, PR #347 thanks to @henrygab
|
||||
- Improve tinyUSB thanks to @kaysievers
|
||||
- Fixed warnings
|
||||
- Allows configuration of power setting
|
||||
- Allows to set USB Manufacturer/product ID
|
||||
- Allow to set configuration descriptor buffer
|
||||
- Fixed missing bootloader binaries
|
||||
|
||||
## 0.14.0 - 2019.09.27
|
||||
|
||||
- Core
|
||||
- Ada Callback task dynamically resize its queue size on demand. Also invoke function immediately if callback failed to allocate memory for deferring.
|
||||
- Changde stack size for following task
|
||||
- Task loop : from 256*6 to 256*4
|
||||
- Task Callback : from 256*4 to 256*3
|
||||
- Task USBD : from 150 to 200
|
||||
- Task BLE : from 256*6 to 256*5
|
||||
- Added _sbkr() to handle heap overflowed
|
||||
- BLEUart
|
||||
- Added setRxOverflowCallback()
|
||||
- Added deferred option for setRxCallback()
|
||||
- Update `image_upload` example to work with both nRF52832 & nRF52840 with maximum throughput, also support 16 or 24-bit color
|
||||
- Update bootloader binary to to 0.2.13 version (upgrade is optional)
|
||||
- Enhance BLEDis with new characteristic : system id, reg cert list, pnp id. PR #336 Thanks to @elral
|
||||
- Fixed SPI definition for circuitplayground Bluefruit
|
||||
|
||||
## 0.13.0 - 2019.08.22
|
||||
|
||||
- Update bootloader binary to to 0.2.12 version (upgrade is optional)
|
||||
- Added Circuit Playground Blueffuit nRF52840 support
|
||||
- Added variant support for Particle Xenon, PR #317
|
||||
- Added PDM support
|
||||
- Switch compiler optimization from -Os to -Ofast
|
||||
- Improve BLEConnection throughput
|
||||
- Added requestPHY() to initate PHY switching to 2 MB, 1MB
|
||||
- Added requestDataLengthUpdate() to initate Data Length Update process
|
||||
- Added requestMtuExchange() to iniate MTU exchange procoess
|
||||
- Added requestConnectionParameter() to initate connection parameter process
|
||||
- Updated throughput and added central_throughput sketch (WIP)
|
||||
- Added image_upload example
|
||||
- Enhance mutex lock/unlock for fifo used by bleuart
|
||||
- Fixed multiples warning with tinyUSB descriptor template, PR #322
|
||||
- Fixed typo, PR #326
|
||||
|
||||
## 0.12.0 - 2019.08.05
|
||||
|
||||
- Update tinyusb core to support webUSB & vendor class
|
||||
- Added a couple delete operators to make std=gnu++14/17, PR #312 thanks to @kevinfrei
|
||||
- Fix Serial.read() return clean 8-bit, PR #308 thanks to @pyro9
|
||||
- Added availableForWrite(), PR #311 thanks to @pyro9
|
||||
|
||||
## 0.11.1 - 2019.07.10
|
||||
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach 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.
|
||||
*/
|
||||
|
||||
#ifdef USE_TINYUSB
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Adafruit_USBD_CDC.h"
|
||||
|
||||
#define EPOUT 0x00
|
||||
#define EPIN 0x80
|
||||
|
||||
Adafruit_USBD_CDC Serial;
|
||||
|
||||
Adafruit_USBD_CDC::Adafruit_USBD_CDC(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint16_t Adafruit_USBD_CDC::getDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize)
|
||||
{
|
||||
// CDC is mostly always existed for DFU
|
||||
// usb core will automatically update endpoint number
|
||||
uint8_t desc[] = { TUD_CDC_DESCRIPTOR(itfnum, 0, EPIN, 8, EPOUT, EPIN, 64) };
|
||||
uint16_t const len = sizeof(desc);
|
||||
|
||||
if ( bufsize < len ) return 0;
|
||||
|
||||
memcpy(buf, desc, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Baud and config is ignore in CDC
|
||||
void Adafruit_USBD_CDC::begin (uint32_t baud)
|
||||
{
|
||||
(void) baud;
|
||||
}
|
||||
|
||||
void Adafruit_USBD_CDC::begin (uint32_t baud, uint8_t config)
|
||||
{
|
||||
(void) baud;
|
||||
(void) config;
|
||||
}
|
||||
|
||||
void Adafruit_USBD_CDC::end(void)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
Adafruit_USBD_CDC::operator bool()
|
||||
{
|
||||
bool ret = tud_cdc_connected();
|
||||
|
||||
// Add an yield to run usb background in case sketch block wait as follows
|
||||
// while( !Serial ) {}
|
||||
if ( !ret ) yield();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Adafruit_USBD_CDC::available(void)
|
||||
{
|
||||
uint32_t count = tud_cdc_available();
|
||||
|
||||
// Add an yield to run usb background in case sketch block wait as follows
|
||||
// while( !Serial.available() ) {}
|
||||
if (!count) yield();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int Adafruit_USBD_CDC::peek(void)
|
||||
{
|
||||
uint8_t ch;
|
||||
return tud_cdc_peek(0, &ch) ? (int) ch : -1;
|
||||
}
|
||||
|
||||
int Adafruit_USBD_CDC::read(void)
|
||||
{
|
||||
return tud_cdc_read_char();
|
||||
}
|
||||
|
||||
void Adafruit_USBD_CDC::flush(void)
|
||||
{
|
||||
tud_cdc_write_flush();
|
||||
}
|
||||
|
||||
size_t Adafruit_USBD_CDC::write(uint8_t ch)
|
||||
{
|
||||
return tud_cdc_write_char((char) ch);
|
||||
}
|
||||
|
||||
size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t remain = size;
|
||||
while ( remain && tud_cdc_connected() )
|
||||
{
|
||||
size_t wrcount = tud_cdc_write(buffer, remain);
|
||||
remain -= wrcount;
|
||||
buffer += wrcount;
|
||||
|
||||
// Write FIFO is full, run usb background to flush
|
||||
if ( remain ) yield();
|
||||
}
|
||||
|
||||
return size - remain;
|
||||
}
|
||||
|
||||
size_t Adafruit_USBD_CDC::availableForWrite(void)
|
||||
{
|
||||
return tud_cdc_write_available();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
// Invoked when cdc when line state changed e.g connected/disconnected
|
||||
// Use to reset to DFU when disconnect with 1200 bps
|
||||
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
|
||||
{
|
||||
(void) itf; // interface ID, not used
|
||||
(void) rts;
|
||||
|
||||
// DTR = false is counted as disconnected
|
||||
if ( !dtr )
|
||||
{
|
||||
cdc_line_coding_t coding;
|
||||
tud_cdc_get_line_coding(&coding);
|
||||
|
||||
if ( coding.bit_rate == 1200 ) Adafruit_TinyUSB_Core_touch1200();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // USE_TINYUSB
|
||||
@@ -1,209 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach 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.
|
||||
*/
|
||||
|
||||
#ifdef USE_TINYUSB
|
||||
|
||||
#include "Adafruit_USBD_Device.h"
|
||||
|
||||
#ifndef USB_MANUFACTURER
|
||||
#define USB_MANUFACTURER "Unknown"
|
||||
#endif
|
||||
|
||||
#ifndef USB_PRODUCT
|
||||
#define USB_PRODUCT "Unknown"
|
||||
#endif
|
||||
|
||||
extern uint8_t load_serial_number(uint16_t* serial_str);
|
||||
|
||||
Adafruit_USBD_Device USBDevice;
|
||||
|
||||
Adafruit_USBD_Device::Adafruit_USBD_Device(void)
|
||||
{
|
||||
tusb_desc_device_t const desc_dev =
|
||||
{
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = 0x0200,
|
||||
|
||||
// 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_ENDOINT0_SIZE,
|
||||
|
||||
.idVendor = 0,
|
||||
.idProduct = 0,
|
||||
.bcdDevice = 0x0100,
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
.iSerialNumber = 0x03,
|
||||
.bNumConfigurations = 0x01
|
||||
};
|
||||
|
||||
_desc_device = desc_dev;
|
||||
|
||||
tusb_desc_configuration_t const dev_cfg =
|
||||
{
|
||||
.bLength = sizeof(tusb_desc_configuration_t),
|
||||
.bDescriptorType = TUSB_DESC_CONFIGURATION,
|
||||
|
||||
// Total Length & Interface Number will be updated later
|
||||
.wTotalLength = 0,
|
||||
.bNumInterfaces = 0,
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0x00,
|
||||
.bmAttributes = TU_BIT(7) | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP,
|
||||
.bMaxPower = TUSB_DESC_CONFIG_POWER_MA(100)
|
||||
};
|
||||
|
||||
memcpy(_desc_cfg, &dev_cfg, sizeof(tusb_desc_configuration_t));
|
||||
|
||||
_desc_cfglen = sizeof(tusb_desc_configuration_t);
|
||||
_itf_count = 0;
|
||||
_epin_count = _epout_count = 1;
|
||||
}
|
||||
|
||||
// Add interface descriptor
|
||||
// - Interface number will be updated to match current count
|
||||
// - Endpoint number is updated to be unique
|
||||
bool Adafruit_USBD_Device::addInterface(Adafruit_USBD_Interface& itf)
|
||||
{
|
||||
uint8_t* desc = _desc_cfg+_desc_cfglen;
|
||||
uint16_t const len = itf.getDescriptor(_itf_count, desc, sizeof(_desc_cfg)-_desc_cfglen);
|
||||
uint8_t* desc_end = desc+len;
|
||||
|
||||
if ( !len ) return false;
|
||||
|
||||
while (desc < desc_end)
|
||||
{
|
||||
if (desc[1] == TUSB_DESC_INTERFACE)
|
||||
{
|
||||
tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) desc;
|
||||
if (desc_itf->bAlternateSetting == 0) _itf_count++;
|
||||
}else if (desc[1] == TUSB_DESC_ENDPOINT)
|
||||
{
|
||||
tusb_desc_endpoint_t* desc_ep = (tusb_desc_endpoint_t*) desc;
|
||||
desc_ep->bEndpointAddress |= (desc_ep->bEndpointAddress & 0x80) ? _epin_count++ : _epout_count++;
|
||||
}
|
||||
|
||||
if (desc[0] == 0) return false;
|
||||
desc += desc[0]; // next
|
||||
}
|
||||
|
||||
_desc_cfglen += len;
|
||||
|
||||
// Update configuration descriptor
|
||||
tusb_desc_configuration_t* config = (tusb_desc_configuration_t*)_desc_cfg;
|
||||
config->wTotalLength = _desc_cfglen;
|
||||
config->bNumInterfaces = _itf_count;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Adafruit_USBD_Device::setID(uint16_t vid, uint16_t pid)
|
||||
{
|
||||
_desc_device.idVendor = vid;
|
||||
_desc_device.idProduct = pid;
|
||||
}
|
||||
|
||||
void Adafruit_USBD_Device::setVersion(uint16_t bcd)
|
||||
{
|
||||
_desc_device.bcdUSB = bcd;
|
||||
}
|
||||
|
||||
bool Adafruit_USBD_Device::begin(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
// Invoked when received GET DEVICE DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
uint8_t const * tud_descriptor_device_cb(void)
|
||||
{
|
||||
return (uint8_t const *) &USBDevice._desc_device;
|
||||
}
|
||||
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor, whose 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 USBDevice._desc_cfg;
|
||||
}
|
||||
|
||||
// up to 32 unicode characters (header make it 33)
|
||||
static uint16_t _desc_str[33];
|
||||
|
||||
// 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)
|
||||
{
|
||||
uint8_t chr_count;
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
// language = English
|
||||
_desc_str[1] = 0x0409;
|
||||
chr_count = 1;
|
||||
break;
|
||||
|
||||
case 1: // Manufacturer
|
||||
case 2: // Product
|
||||
{
|
||||
char const * str = (index == 1) ? USB_MANUFACTURER : USB_PRODUCT;
|
||||
|
||||
// cap at max char
|
||||
chr_count = strlen(str);
|
||||
if ( chr_count > 32 ) chr_count = 32;
|
||||
|
||||
for(uint8_t i=0; i<chr_count; i++)
|
||||
{
|
||||
_desc_str[1+i] = str[i];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// serial Number
|
||||
chr_count = load_serial_number(_desc_str+1);
|
||||
break;
|
||||
|
||||
default: return NULL;
|
||||
}
|
||||
|
||||
// first byte is len, second byte is string type
|
||||
_desc_str[0] = TUD_DESC_STR_HEADER(chr_count);
|
||||
|
||||
return _desc_str;
|
||||
}
|
||||
|
||||
} // extern C
|
||||
|
||||
#endif // USE_TINYUSB
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach 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 ADAFRUIT_USBD_DEVICE_H_
|
||||
#define ADAFRUIT_USBD_DEVICE_H_
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
class Adafruit_USBD_Interface
|
||||
{
|
||||
public:
|
||||
virtual uint16_t getDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize) = 0;
|
||||
};
|
||||
|
||||
class Adafruit_USBD_Device
|
||||
{
|
||||
private:
|
||||
tusb_desc_device_t _desc_device;
|
||||
|
||||
uint8_t _desc_cfg[256];
|
||||
uint16_t _desc_cfglen;
|
||||
|
||||
uint8_t _itf_count;
|
||||
|
||||
uint8_t _epin_count;
|
||||
uint8_t _epout_count;
|
||||
|
||||
public:
|
||||
Adafruit_USBD_Device(void);
|
||||
|
||||
bool addInterface(Adafruit_USBD_Interface& itf);
|
||||
|
||||
void setID(uint16_t vid, uint16_t pid);
|
||||
void setVersion(uint16_t bcd);
|
||||
bool begin(void);
|
||||
|
||||
bool mounted (void) { return tud_mounted(); }
|
||||
bool suspended (void) { return tud_suspended(); }
|
||||
bool ready (void) { return tud_ready(); }
|
||||
bool remoteWakeup (void) { return tud_remote_wakeup(); }
|
||||
|
||||
friend uint8_t const * tud_descriptor_device_cb(void);
|
||||
friend uint8_t const * tud_descriptor_configuration_cb(uint8_t index);
|
||||
};
|
||||
|
||||
extern Adafruit_USBD_Device USBDevice;
|
||||
|
||||
#endif /* ADAFRUIT_USBD_DEVICE_H_ */
|
||||
@@ -1,100 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup group_class
|
||||
* \defgroup ClassDriver_Audio Audio
|
||||
* Currently only MIDI subclass is supported
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_AUDIO_H__
|
||||
#define _TUSB_AUDIO_H__
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// Audio Interface Subclass Codes
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_SUBCLASS_CONTROL = 0x01 , ///< Audio Control
|
||||
AUDIO_SUBCLASS_STREAMING , ///< Audio Streaming
|
||||
AUDIO_SUBCLASS_MIDI_STREAMING , ///< MIDI Streaming
|
||||
} audio_subclass_type_t;
|
||||
|
||||
/// Audio Protocol Codes
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_PROTOCOL_V1 = 0x00, ///< Version 1.0
|
||||
AUDIO_PROTOCOL_V2 = 0x20, ///< Version 2.0
|
||||
AUDIO_PROTOCOL_V3 = 0x30, ///< Version 3.0
|
||||
} audio_protocol_type_t;
|
||||
|
||||
/// Audio Function Category Codes
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_FUNC_DESKTOP_SPEAKER = 0x01,
|
||||
AUDIO_FUNC_HOME_THEATER = 0x02,
|
||||
AUDIO_FUNC_MICROPHONE = 0x03,
|
||||
AUDIO_FUNC_HEADSET = 0x04,
|
||||
AUDIO_FUNC_TELEPHONE = 0x05,
|
||||
AUDIO_FUNC_CONVERTER = 0x06,
|
||||
AUDIO_FUNC_SOUND_RECODER = 0x07,
|
||||
AUDIO_FUNC_IO_BOX = 0x08,
|
||||
AUDIO_FUNC_MUSICAL_INSTRUMENT = 0x09,
|
||||
AUDIO_FUNC_PRO_AUDIO = 0x0A,
|
||||
AUDIO_FUNC_AUDIO_VIDEO = 0x0B,
|
||||
AUDIO_FUNC_CONTROL_PANEL = 0x0C
|
||||
} audio_function_t;
|
||||
|
||||
/// Audio Class-Specific AC Interface Descriptor Subtypes
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_CS_INTERFACE_HEADER = 0x01,
|
||||
AUDIO_CS_INTERFACE_INPUT_TERMINAL = 0x02,
|
||||
AUDIO_CS_INTERFACE_OUTPUT_TERMINAL = 0x03,
|
||||
AUDIO_CS_INTERFACE_MIXER_UNIT = 0x04,
|
||||
AUDIO_CS_INTERFACE_SELECTOR_UNIT = 0x05,
|
||||
AUDIO_CS_INTERFACE_FEATURE_UNIT = 0x06,
|
||||
AUDIO_CS_INTERFACE_EFFECT_UNIT = 0x07,
|
||||
AUDIO_CS_INTERFACE_PROCESSING_UNIT = 0x08,
|
||||
AUDIO_CS_INTERFACE_EXTENSION_UNIT = 0x09,
|
||||
AUDIO_CS_INTERFACE_CLOCK_SOURCE = 0x0A,
|
||||
AUDIO_CS_INTERFACE_CLOCK_SELECTOR = 0x0B,
|
||||
AUDIO_CS_INTERFACE_CLOCK_MULTIPLIER = 0x0C,
|
||||
AUDIO_CS_INTERFACE_SAMPLE_RATE_CONVERTER = 0x0D,
|
||||
} audio_cs_interface_subtype_t;
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
@@ -1,405 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup group_class
|
||||
* \defgroup ClassDriver_CDC Communication Device Class (CDC)
|
||||
* Currently only Abstract Control Model subclass is supported
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_CDC_H__
|
||||
#define _TUSB_CDC_H__
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \defgroup ClassDriver_CDC_Common Common Definitions
|
||||
* @{ */
|
||||
|
||||
// TODO remove
|
||||
/// CDC Pipe ID, used to indicate which pipe the API is addressing to (Notification, Out, In)
|
||||
typedef enum
|
||||
{
|
||||
CDC_PIPE_NOTIFICATION , ///< Notification pipe
|
||||
CDC_PIPE_DATA_IN , ///< Data in pipe
|
||||
CDC_PIPE_DATA_OUT , ///< Data out pipe
|
||||
CDC_PIPE_ERROR , ///< Invalid Pipe ID
|
||||
}cdc_pipeid_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CDC Communication Interface Class
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// Communication Interface Subclass Codes
|
||||
typedef enum
|
||||
{
|
||||
CDC_COMM_SUBCLASS_DIRECT_LINE_CONTROL_MODEL = 0x01 , ///< Direct Line Control Model [USBPSTN1.2]
|
||||
CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL , ///< Abstract Control Model [USBPSTN1.2]
|
||||
CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL , ///< Telephone Control Model [USBPSTN1.2]
|
||||
CDC_COMM_SUBCLASS_MULTICHANNEL_CONTROL_MODEL , ///< Multi-Channel Control Model [USBISDN1.2]
|
||||
CDC_COMM_SUBCLASS_CAPI_CONTROL_MODEL , ///< CAPI Control Model [USBISDN1.2]
|
||||
CDC_COMM_SUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL , ///< Ethernet Networking Control Model [USBECM1.2]
|
||||
CDC_COMM_SUBCLASS_ATM_NETWORKING_CONTROL_MODEL , ///< ATM Networking Control Model [USBATM1.2]
|
||||
CDC_COMM_SUBCLASS_WIRELESS_HANDSET_CONTROL_MODEL , ///< Wireless Handset Control Model [USBWMC1.1]
|
||||
CDC_COMM_SUBCLASS_DEVICE_MANAGEMENT , ///< Device Management [USBWMC1.1]
|
||||
CDC_COMM_SUBCLASS_MOBILE_DIRECT_LINE_MODEL , ///< Mobile Direct Line Model [USBWMC1.1]
|
||||
CDC_COMM_SUBCLASS_OBEX , ///< OBEX [USBWMC1.1]
|
||||
CDC_COMM_SUBCLASS_ETHERNET_EMULATION_MODEL ///< Ethernet Emulation Model [USBEEM1.0]
|
||||
} cdc_comm_sublcass_type_t;
|
||||
|
||||
/// Communication Interface Protocol Codes
|
||||
typedef enum
|
||||
{
|
||||
CDC_COMM_PROTOCOL_NONE = 0x00 , ///< No specific protocol
|
||||
CDC_COMM_PROTOCOL_ATCOMMAND , ///< AT Commands: V.250 etc
|
||||
CDC_COMM_PROTOCOL_ATCOMMAND_PCCA_101 , ///< AT Commands defined by PCCA-101
|
||||
CDC_COMM_PROTOCOL_ATCOMMAND_PCCA_101_AND_ANNEXO , ///< AT Commands defined by PCCA-101 & Annex O
|
||||
CDC_COMM_PROTOCOL_ATCOMMAND_GSM_707 , ///< AT Commands defined by GSM 07.07
|
||||
CDC_COMM_PROTOCOL_ATCOMMAND_3GPP_27007 , ///< AT Commands defined by 3GPP 27.007
|
||||
CDC_COMM_PROTOCOL_ATCOMMAND_CDMA , ///< AT Commands defined by TIA for CDMA
|
||||
CDC_COMM_PROTOCOL_ETHERNET_EMULATION_MODEL ///< Ethernet Emulation Model
|
||||
} cdc_comm_protocol_type_t;
|
||||
|
||||
//------------- SubType Descriptor in COMM Functional Descriptor -------------//
|
||||
/// Communication Interface SubType Descriptor
|
||||
typedef enum
|
||||
{
|
||||
CDC_FUNC_DESC_HEADER = 0x00 , ///< Header Functional Descriptor, which marks the beginning of the concatenated set of functional descriptors for the interface.
|
||||
CDC_FUNC_DESC_CALL_MANAGEMENT = 0x01 , ///< Call Management Functional Descriptor.
|
||||
CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT = 0x02 , ///< Abstract Control Management Functional Descriptor.
|
||||
CDC_FUNC_DESC_DIRECT_LINE_MANAGEMENT = 0x03 , ///< Direct Line Management Functional Descriptor.
|
||||
CDC_FUNC_DESC_TELEPHONE_RINGER = 0x04 , ///< Telephone Ringer Functional Descriptor.
|
||||
CDC_FUNC_DESC_TELEPHONE_CALL_AND_LINE_STATE_REPORTING_CAPACITY = 0x05 , ///< Telephone Call and Line State Reporting Capabilities Functional Descriptor.
|
||||
CDC_FUNC_DESC_UNION = 0x06 , ///< Union Functional Descriptor
|
||||
CDC_FUNC_DESC_COUNTRY_SELECTION = 0x07 , ///< Country Selection Functional Descriptor
|
||||
CDC_FUNC_DESC_TELEPHONE_OPERATIONAL_MODES = 0x08 , ///< Telephone Operational ModesFunctional Descriptor
|
||||
CDC_FUNC_DESC_USB_TERMINAL = 0x09 , ///< USB Terminal Functional Descriptor
|
||||
CDC_FUNC_DESC_NETWORK_CHANNEL_TERMINAL = 0x0A , ///< Network Channel Terminal Descriptor
|
||||
CDC_FUNC_DESC_PROTOCOL_UNIT = 0x0B , ///< Protocol Unit Functional Descriptor
|
||||
CDC_FUNC_DESC_EXTENSION_UNIT = 0x0C , ///< Extension Unit Functional Descriptor
|
||||
CDC_FUNC_DESC_MULTICHANEL_MANAGEMENT = 0x0D , ///< Multi-Channel Management Functional Descriptor
|
||||
CDC_FUNC_DESC_CAPI_CONTROL_MANAGEMENT = 0x0E , ///< CAPI Control Management Functional Descriptor
|
||||
CDC_FUNC_DESC_ETHERNET_NETWORKING = 0x0F , ///< Ethernet Networking Functional Descriptor
|
||||
CDC_FUNC_DESC_ATM_NETWORKING = 0x10 , ///< ATM Networking Functional Descriptor
|
||||
CDC_FUNC_DESC_WIRELESS_HANDSET_CONTROL_MODEL = 0x11 , ///< Wireless Handset Control Model Functional Descriptor
|
||||
CDC_FUNC_DESC_MOBILE_DIRECT_LINE_MODEL = 0x12 , ///< Mobile Direct Line Model Functional Descriptor
|
||||
CDC_FUNC_DESC_MOBILE_DIRECT_LINE_MODEL_DETAIL = 0x13 , ///< MDLM Detail Functional Descriptor
|
||||
CDC_FUNC_DESC_DEVICE_MANAGEMENT_MODEL = 0x14 , ///< Device Management Model Functional Descriptor
|
||||
CDC_FUNC_DESC_OBEX = 0x15 , ///< OBEX Functional Descriptor
|
||||
CDC_FUNC_DESC_COMMAND_SET = 0x16 , ///< Command Set Functional Descriptor
|
||||
CDC_FUNC_DESC_COMMAND_SET_DETAIL = 0x17 , ///< Command Set Detail Functional Descriptor
|
||||
CDC_FUNC_DESC_TELEPHONE_CONTROL_MODEL = 0x18 , ///< Telephone Control Model Functional Descriptor
|
||||
CDC_FUNC_DESC_OBEX_SERVICE_IDENTIFIER = 0x19 ///< OBEX Service Identifier Functional Descriptor
|
||||
}cdc_func_desc_type_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CDC Data Interface Class
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// SUBCLASS code of Data Interface is not used and should/must be zero
|
||||
/// Data Interface Protocol Codes
|
||||
typedef enum{
|
||||
CDC_DATA_PROTOCOL_ISDN_BRI = 0x30, ///< Physical interface protocol for ISDN BRI
|
||||
CDC_DATA_PROTOCOL_HDLC = 0x31, ///< HDLC
|
||||
CDC_DATA_PROTOCOL_TRANSPARENT = 0x32, ///< Transparent
|
||||
CDC_DATA_PROTOCOL_Q921_MANAGEMENT = 0x50, ///< Management protocol for Q.921 data link protocol
|
||||
CDC_DATA_PROTOCOL_Q921_DATA_LINK = 0x51, ///< Data link protocol for Q.931
|
||||
CDC_DATA_PROTOCOL_Q921_TEI_MULTIPLEXOR = 0x52, ///< TEI-multiplexor for Q.921 data link protocol
|
||||
CDC_DATA_PROTOCOL_V42BIS_DATA_COMPRESSION = 0x90, ///< Data compression procedures
|
||||
CDC_DATA_PROTOCOL_EURO_ISDN = 0x91, ///< Euro-ISDN protocol control
|
||||
CDC_DATA_PROTOCOL_V24_RATE_ADAPTION_TO_ISDN = 0x92, ///< V.24 rate adaptation to ISDN
|
||||
CDC_DATA_PROTOCOL_CAPI_COMMAND = 0x93, ///< CAPI Commands
|
||||
CDC_DATA_PROTOCOL_HOST_BASED_DRIVER = 0xFD, ///< Host based driver. Note: This protocol code should only be used in messages between host and device to identify the host driver portion of a protocol stack.
|
||||
CDC_DATA_PROTOCOL_IN_PROTOCOL_UNIT_FUNCTIONAL_DESCRIPTOR = 0xFE ///< The protocol(s) are described using a ProtocolUnit Functional Descriptors on Communications Class Interface
|
||||
}cdc_data_protocol_type_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Management Element Request (Control Endpoint)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// Communication Interface Management Element Request Codes
|
||||
typedef enum
|
||||
{
|
||||
CDC_REQUEST_SEND_ENCAPSULATED_COMMAND = 0x00, ///< is used to issue a command in the format of the supported control protocol of the Communications Class interface
|
||||
CDC_REQUEST_GET_ENCAPSULATED_RESPONSE = 0x01, ///< is used to request a response in the format of the supported control protocol of the Communications Class interface.
|
||||
|
||||
CDC_REQUEST_SET_COMM_FEATURE = 0x02,
|
||||
CDC_REQUEST_GET_COMM_FEATURE = 0x03,
|
||||
CDC_REQUEST_CLEAR_COMM_FEATURE = 0x04,
|
||||
|
||||
CDC_REQUEST_SET_AUX_LINE_STATE = 0x10,
|
||||
CDC_REQUEST_SET_HOOK_STATE = 0x11,
|
||||
CDC_REQUEST_PULSE_SETUP = 0x12,
|
||||
CDC_REQUEST_SEND_PULSE = 0x13,
|
||||
CDC_REQUEST_SET_PULSE_TIME = 0x14,
|
||||
CDC_REQUEST_RING_AUX_JACK = 0x15,
|
||||
|
||||
CDC_REQUEST_SET_LINE_CODING = 0x20,
|
||||
CDC_REQUEST_GET_LINE_CODING = 0x21,
|
||||
CDC_REQUEST_SET_CONTROL_LINE_STATE = 0x22,
|
||||
CDC_REQUEST_SEND_BREAK = 0x23,
|
||||
|
||||
CDC_REQUEST_SET_RINGER_PARMS = 0x30,
|
||||
CDC_REQUEST_GET_RINGER_PARMS = 0x31,
|
||||
CDC_REQUEST_SET_OPERATION_PARMS = 0x32,
|
||||
CDC_REQUEST_GET_OPERATION_PARMS = 0x33,
|
||||
CDC_REQUEST_SET_LINE_PARMS = 0x34,
|
||||
CDC_REQUEST_GET_LINE_PARMS = 0x35,
|
||||
CDC_REQUEST_DIAL_DIGITS = 0x36,
|
||||
CDC_REQUEST_SET_UNIT_PARAMETER = 0x37,
|
||||
CDC_REQUEST_GET_UNIT_PARAMETER = 0x38,
|
||||
CDC_REQUEST_CLEAR_UNIT_PARAMETER = 0x39,
|
||||
CDC_REQUEST_GET_PROFILE = 0x3A,
|
||||
|
||||
CDC_REQUEST_SET_ETHERNET_MULTICAST_FILTERS = 0x40,
|
||||
CDC_REQUEST_SET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER = 0x41,
|
||||
CDC_REQUEST_GET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER = 0x42,
|
||||
CDC_REQUEST_SET_ETHERNET_PACKET_FILTER = 0x43,
|
||||
CDC_REQUEST_GET_ETHERNET_STATISTIC = 0x44,
|
||||
|
||||
CDC_REQUEST_SET_ATM_DATA_FORMAT = 0x50,
|
||||
CDC_REQUEST_GET_ATM_DEVICE_STATISTICS = 0x51,
|
||||
CDC_REQUEST_SET_ATM_DEFAULT_VC = 0x52,
|
||||
CDC_REQUEST_GET_ATM_VC_STATISTICS = 0x53,
|
||||
|
||||
CDC_REQUEST_MDLM_SEMANTIC_MODEL = 0x60,
|
||||
}cdc_management_request_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Management Elemenent Notification (Notification Endpoint)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// Communication Interface Management Element Notification Codes
|
||||
typedef enum
|
||||
{
|
||||
NETWORK_CONNECTION = 0x00, ///< This notification allows the device to notify the host about network connection status.
|
||||
RESPONSE_AVAILABLE = 0x01, ///< This notification allows the device to notify the hostthat a response is available. This response can be retrieved with a subsequent \ref CDC_REQUEST_GET_ENCAPSULATED_RESPONSE request.
|
||||
|
||||
AUX_JACK_HOOK_STATE = 0x08,
|
||||
RING_DETECT = 0x09,
|
||||
|
||||
SERIAL_STATE = 0x20,
|
||||
|
||||
CALL_STATE_CHANGE = 0x28,
|
||||
LINE_STATE_CHANGE = 0x29,
|
||||
CONNECTION_SPEED_CHANGE = 0x2A, ///< This notification allows the device to inform the host-networking driver that a change in either the upstream or the downstream bit rate of the connection has occurred
|
||||
MDLM_SEMANTIC_MODEL_NOTIFICATION = 0x40,
|
||||
}cdc_notification_request_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Specific Functional Descriptor (Communication Interface)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// Header Functional Descriptor (Communication Interface)
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUNC_DESC_
|
||||
uint16_t bcdCDC ; ///< CDC release number in Binary-Coded Decimal
|
||||
}cdc_desc_func_header_t;
|
||||
|
||||
/// Union Functional Descriptor (Communication Interface)
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
|
||||
uint8_t bControlInterface ; ///< Interface number of Communication Interface
|
||||
uint8_t bSubordinateInterface ; ///< Array of Interface number of Data Interface
|
||||
}cdc_desc_func_union_t;
|
||||
|
||||
#define cdc_desc_func_union_n_t(no_slave)\
|
||||
struct TU_ATTR_PACKED { \
|
||||
uint8_t bLength ;\
|
||||
uint8_t bDescriptorType ;\
|
||||
uint8_t bDescriptorSubType ;\
|
||||
uint8_t bControlInterface ;\
|
||||
uint8_t bSubordinateInterface[no_slave] ;\
|
||||
}
|
||||
|
||||
/// Country Selection Functional Descriptor (Communication Interface)
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
|
||||
uint8_t iCountryCodeRelDate ; ///< Index of a string giving the release date for the implemented ISO 3166 Country Codes.
|
||||
uint16_t wCountryCode ; ///< Country code in the format as defined in [ISO3166], release date as specified inoffset 3 for the first supported country.
|
||||
}cdc_desc_func_country_selection_t;
|
||||
|
||||
#define cdc_desc_func_country_selection_n_t(no_country) \
|
||||
struct TU_ATTR_PACKED {\
|
||||
uint8_t bLength ;\
|
||||
uint8_t bDescriptorType ;\
|
||||
uint8_t bDescriptorSubType ;\
|
||||
uint8_t iCountryCodeRelDate ;\
|
||||
uint16_t wCountryCode[no_country] ;\
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PUBLIC SWITCHED TELEPHONE NETWORK (PSTN) SUBCLASS
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// \brief Call Management Functional Descriptor
|
||||
/// \details This functional descriptor describes the processing of calls for the Communications Class interface.
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
|
||||
|
||||
struct {
|
||||
uint8_t handle_call : 1; ///< 0 - Device sends/receives call management information only over the Communications Class interface. 1 - Device can send/receive call management information over a Data Class interface.
|
||||
uint8_t send_recv_call : 1; ///< 0 - Device does not handle call management itself. 1 - Device handles call management itself.
|
||||
uint8_t : 0;
|
||||
} bmCapabilities;
|
||||
|
||||
uint8_t bDataInterface;
|
||||
}cdc_desc_func_call_management_t;
|
||||
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t support_comm_request : 1; ///< Device supports the request combination of Set_Comm_Feature, Clear_Comm_Feature, and Get_Comm_Feature.
|
||||
uint8_t support_line_request : 1; ///< Device supports the request combination of Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State.
|
||||
uint8_t support_send_break : 1; ///< Device supports the request Send_Break
|
||||
uint8_t support_notification_network_connection : 1; ///< Device supports the notification Network_Connection.
|
||||
uint8_t : 0;
|
||||
}cdc_acm_capability_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(cdc_acm_capability_t) == 1, "mostly problem with compiler");
|
||||
|
||||
/// \brief Abstract Control Management Functional Descriptor
|
||||
/// \details This functional descriptor describes the commands supported by by the Communications Class interface with SubClass code of \ref CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
|
||||
cdc_acm_capability_t bmCapabilities ;
|
||||
}cdc_desc_func_acm_t;
|
||||
|
||||
/// \brief Direct Line Management Functional Descriptor
|
||||
/// \details This functional descriptor describes the commands supported by the Communications Class interface with SubClass code of \ref CDC_FUNC_DESC_DIRECT_LINE_MANAGEMENT
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
|
||||
struct {
|
||||
uint8_t require_pulse_setup : 1; ///< Device requires extra Pulse_Setup request during pulse dialing sequence to disengage holding circuit.
|
||||
uint8_t support_aux_request : 1; ///< Device supports the request combination of Set_Aux_Line_State, Ring_Aux_Jack, and notification Aux_Jack_Hook_State.
|
||||
uint8_t support_pulse_request : 1; ///< Device supports the request combination of Pulse_Setup, Send_Pulse, and Set_Pulse_Time.
|
||||
uint8_t : 0;
|
||||
} bmCapabilities;
|
||||
}cdc_desc_func_direct_line_management_t;
|
||||
|
||||
/// \brief Telephone Ringer Functional Descriptor
|
||||
/// \details The Telephone Ringer functional descriptor describes the ringer capabilities supported by the Communications Class interface,
|
||||
/// with the SubClass code of \ref CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
|
||||
uint8_t bRingerVolSteps ;
|
||||
uint8_t bNumRingerPatterns ;
|
||||
}cdc_desc_func_telephone_ringer_t;
|
||||
|
||||
/// \brief Telephone Operational Modes Functional Descriptor
|
||||
/// \details The Telephone Operational Modes functional descriptor describes the operational modes supported by
|
||||
/// the Communications Class interface, with the SubClass code of \ref CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
|
||||
struct {
|
||||
uint8_t simple_mode : 1;
|
||||
uint8_t standalone_mode : 1;
|
||||
uint8_t computer_centric_mode : 1;
|
||||
uint8_t : 0;
|
||||
} bmCapabilities;
|
||||
}cdc_desc_func_telephone_operational_modes_t;
|
||||
|
||||
/// \brief Telephone Call and Line State Reporting Capabilities Descriptor
|
||||
/// \details The Telephone Call and Line State Reporting Capabilities functional descriptor describes the abilities of a
|
||||
/// telephone device to report optional call and line states.
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
|
||||
struct {
|
||||
uint32_t interrupted_dialtone : 1; ///< 0 : Reports only dialtone (does not differentiate between normal and interrupted dialtone). 1 : Reports interrupted dialtone in addition to normal dialtone
|
||||
uint32_t ringback_busy_fastbusy : 1; ///< 0 : Reports only dialing state. 1 : Reports ringback, busy, and fast busy states.
|
||||
uint32_t caller_id : 1; ///< 0 : Does not report caller ID. 1 : Reports caller ID information.
|
||||
uint32_t incoming_distinctive : 1; ///< 0 : Reports only incoming ringing. 1 : Reports incoming distinctive ringing patterns.
|
||||
uint32_t dual_tone_multi_freq : 1; ///< 0 : Cannot report dual tone multi-frequency (DTMF) digits input remotely over the telephone line. 1 : Can report DTMF digits input remotely over the telephone line.
|
||||
uint32_t line_state_change : 1; ///< 0 : Does not support line state change notification. 1 : Does support line state change notification
|
||||
uint32_t : 0;
|
||||
} bmCapabilities;
|
||||
}cdc_desc_func_telephone_call_state_reporting_capabilities_t;
|
||||
|
||||
static inline uint8_t cdc_functional_desc_typeof(uint8_t const * p_desc)
|
||||
{
|
||||
return p_desc[2];
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Requests
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint32_t bit_rate;
|
||||
uint8_t stop_bits; ///< 0: 1 stop bit - 1: 1.5 stop bits - 2: 2 stop bits
|
||||
uint8_t parity; ///< 0: None - 1: Odd - 2: Even - 3: Mark - 4: Space
|
||||
uint8_t data_bits; ///< can be 5, 6, 7, 8 or 16
|
||||
} cdc_line_coding_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(cdc_line_coding_t) == 7, "size is not correct");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint16_t dte_is_present : 1; ///< Indicates to DCE if DTE is presentor not. This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR.
|
||||
uint16_t half_duplex_carrier_control : 1;
|
||||
uint16_t : 14;
|
||||
} cdc_line_control_state_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(cdc_line_control_state_t) == 2, "size is not correct");
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
@@ -1,394 +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 "tusb_option.h"
|
||||
|
||||
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_CDC)
|
||||
|
||||
#include "cdc_device.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct
|
||||
{
|
||||
uint8_t itf_num;
|
||||
uint8_t ep_notif;
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out;
|
||||
|
||||
// Bit 0: DTR (Data Terminal Ready), Bit 1: RTS (Request to Send)
|
||||
uint8_t line_state;
|
||||
|
||||
/*------------- From this point, data is not cleared by bus reset -------------*/
|
||||
char wanted_char;
|
||||
cdc_line_coding_t line_coding;
|
||||
|
||||
// FIFO
|
||||
tu_fifo_t rx_ff;
|
||||
tu_fifo_t tx_ff;
|
||||
|
||||
uint8_t rx_ff_buf[CFG_TUD_CDC_RX_BUFSIZE];
|
||||
uint8_t tx_ff_buf[CFG_TUD_CDC_TX_BUFSIZE];
|
||||
|
||||
#if CFG_FIFO_MUTEX
|
||||
osal_mutex_def_t rx_ff_mutex;
|
||||
osal_mutex_def_t tx_ff_mutex;
|
||||
#endif
|
||||
|
||||
// Endpoint Transfer buffer
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_CDC_EPSIZE];
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_CDC_EPSIZE];
|
||||
|
||||
}cdcd_interface_t;
|
||||
|
||||
#define ITF_MEM_RESET_SIZE offsetof(cdcd_interface_t, wanted_char)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
|
||||
|
||||
static void _prep_out_transaction (uint8_t itf)
|
||||
{
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
|
||||
// skip if previous transfer not complete
|
||||
if ( usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_out) ) return;
|
||||
|
||||
// Prepare for incoming data but only allow what we can store in the ring buffer.
|
||||
uint16_t max_read = tu_fifo_remaining(&p_cdc->rx_ff);
|
||||
if ( max_read >= CFG_TUD_CDC_EPSIZE )
|
||||
{
|
||||
usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_cdc_n_connected(uint8_t itf)
|
||||
{
|
||||
// DTR (bit 0) active is considered as connected
|
||||
return tud_ready() && tu_bit_test(_cdcd_itf[itf].line_state, 0);
|
||||
}
|
||||
|
||||
uint8_t tud_cdc_n_get_line_state (uint8_t itf)
|
||||
{
|
||||
return _cdcd_itf[itf].line_state;
|
||||
}
|
||||
|
||||
void tud_cdc_n_get_line_coding (uint8_t itf, cdc_line_coding_t* coding)
|
||||
{
|
||||
(*coding) = _cdcd_itf[itf].line_coding;
|
||||
}
|
||||
|
||||
void tud_cdc_n_set_wanted_char (uint8_t itf, char wanted)
|
||||
{
|
||||
_cdcd_itf[itf].wanted_char = wanted;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// READ API
|
||||
//--------------------------------------------------------------------+
|
||||
uint32_t tud_cdc_n_available(uint8_t itf)
|
||||
{
|
||||
return tu_fifo_count(&_cdcd_itf[itf].rx_ff);
|
||||
}
|
||||
|
||||
uint32_t tud_cdc_n_read(uint8_t itf, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
uint32_t num_read = tu_fifo_read_n(&_cdcd_itf[itf].rx_ff, buffer, bufsize);
|
||||
_prep_out_transaction(itf);
|
||||
return num_read;
|
||||
}
|
||||
|
||||
bool tud_cdc_n_peek(uint8_t itf, int pos, uint8_t* chr)
|
||||
{
|
||||
return tu_fifo_peek_at(&_cdcd_itf[itf].rx_ff, pos, chr);
|
||||
}
|
||||
|
||||
void tud_cdc_n_read_flush (uint8_t itf)
|
||||
{
|
||||
tu_fifo_clear(&_cdcd_itf[itf].rx_ff);
|
||||
_prep_out_transaction(itf);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// WRITE API
|
||||
//--------------------------------------------------------------------+
|
||||
uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
uint16_t ret = tu_fifo_write_n(&_cdcd_itf[itf].tx_ff, buffer, bufsize);
|
||||
|
||||
#if 0 // TODO issue with circuitpython's REPL
|
||||
// flush if queue more than endpoint size
|
||||
if ( tu_fifo_count(&_cdcd_itf[itf].tx_ff) >= CFG_TUD_CDC_EPSIZE )
|
||||
{
|
||||
tud_cdc_n_write_flush(itf);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool tud_cdc_n_write_flush (uint8_t itf)
|
||||
{
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete
|
||||
|
||||
uint16_t count = tu_fifo_read_n(&_cdcd_itf[itf].tx_ff, p_cdc->epin_buf, CFG_TUD_CDC_EPSIZE);
|
||||
if ( count )
|
||||
{
|
||||
TU_VERIFY( tud_cdc_n_connected(itf) ); // fifo is empty if not connected
|
||||
TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epin_buf, count) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t tud_cdc_n_write_available (uint8_t itf)
|
||||
{
|
||||
return tu_fifo_remaining(&_cdcd_itf[itf].tx_ff);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
void cdcd_init(void)
|
||||
{
|
||||
tu_memclr(_cdcd_itf, sizeof(_cdcd_itf));
|
||||
|
||||
for(uint8_t i=0; i<CFG_TUD_CDC; i++)
|
||||
{
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[i];
|
||||
|
||||
p_cdc->wanted_char = -1;
|
||||
|
||||
// default line coding is : stop bit = 1, parity = none, data bits = 8
|
||||
p_cdc->line_coding.bit_rate = 115200;
|
||||
p_cdc->line_coding.stop_bits = 0;
|
||||
p_cdc->line_coding.parity = 0;
|
||||
p_cdc->line_coding.data_bits = 8;
|
||||
|
||||
// config fifo
|
||||
tu_fifo_config(&p_cdc->rx_ff, p_cdc->rx_ff_buf, CFG_TUD_CDC_RX_BUFSIZE, 1, false);
|
||||
tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, CFG_TUD_CDC_TX_BUFSIZE, 1, false);
|
||||
|
||||
#if CFG_FIFO_MUTEX
|
||||
tu_fifo_config_mutex(&p_cdc->rx_ff, osal_mutex_create(&p_cdc->rx_ff_mutex));
|
||||
tu_fifo_config_mutex(&p_cdc->tx_ff, osal_mutex_create(&p_cdc->tx_ff_mutex));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void cdcd_reset(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
for(uint8_t i=0; i<CFG_TUD_CDC; i++)
|
||||
{
|
||||
tu_memclr(&_cdcd_itf[i], ITF_MEM_RESET_SIZE);
|
||||
tu_fifo_clear(&_cdcd_itf[i].rx_ff);
|
||||
tu_fifo_clear(&_cdcd_itf[i].tx_ff);
|
||||
}
|
||||
}
|
||||
|
||||
bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length)
|
||||
{
|
||||
// Only support ACM subclass
|
||||
TU_ASSERT ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass);
|
||||
|
||||
// Only support AT commands, no protocol and vendor specific commands.
|
||||
TU_ASSERT(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) ||
|
||||
itf_desc->bInterfaceProtocol == 0xff);
|
||||
|
||||
// Find available interface
|
||||
cdcd_interface_t * p_cdc = NULL;
|
||||
uint8_t cdc_id;
|
||||
for(cdc_id=0; cdc_id<CFG_TUD_CDC; cdc_id++)
|
||||
{
|
||||
if ( _cdcd_itf[cdc_id].ep_in == 0 )
|
||||
{
|
||||
p_cdc = &_cdcd_itf[cdc_id];
|
||||
break;
|
||||
}
|
||||
}
|
||||
TU_ASSERT(p_cdc);
|
||||
|
||||
//------------- Control Interface -------------//
|
||||
p_cdc->itf_num = itf_desc->bInterfaceNumber;
|
||||
|
||||
uint8_t const * p_desc = tu_desc_next( itf_desc );
|
||||
(*p_length) = sizeof(tusb_desc_interface_t);
|
||||
|
||||
// Communication Functional Descriptors
|
||||
while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) )
|
||||
{
|
||||
(*p_length) += tu_desc_len(p_desc);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
|
||||
if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
|
||||
{
|
||||
// notification endpoint if any
|
||||
TU_ASSERT( dcd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc) );
|
||||
|
||||
p_cdc->ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
|
||||
|
||||
(*p_length) += p_desc[DESC_OFFSET_LEN];
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
|
||||
//------------- Data Interface (if any) -------------//
|
||||
if ( (TUSB_DESC_INTERFACE == p_desc[DESC_OFFSET_TYPE]) &&
|
||||
(TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) )
|
||||
{
|
||||
// next to endpoint descriptor
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
|
||||
// Open endpoint pair
|
||||
TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &p_cdc->ep_out, &p_cdc->ep_in) );
|
||||
|
||||
(*p_length) += sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
|
||||
}
|
||||
|
||||
// Prepare for incoming data
|
||||
_prep_out_transaction(cdc_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Invoked when class request DATA stage is finished.
|
||||
// return false to stall control endpoint (e.g Host send non-sense DATA)
|
||||
bool cdcd_control_complete(uint8_t rhport, tusb_control_request_t const * request)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
//------------- Class Specific Request -------------//
|
||||
TU_VERIFY (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
|
||||
|
||||
// TODO Support multiple interfaces
|
||||
uint8_t const itf = 0;
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
|
||||
// Invoke callback
|
||||
if ( CDC_REQUEST_SET_LINE_CODING == request->bRequest )
|
||||
{
|
||||
if ( tud_cdc_line_coding_cb ) tud_cdc_line_coding_cb(itf, &p_cdc->line_coding);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle class control request
|
||||
// return false to stall control endpoint (e.g unsupported request)
|
||||
bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request)
|
||||
{
|
||||
//------------- Class Specific Request -------------//
|
||||
TU_ASSERT(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
|
||||
|
||||
// TODO Support multiple interfaces
|
||||
uint8_t const itf = 0;
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
|
||||
switch ( request->bRequest )
|
||||
{
|
||||
case CDC_REQUEST_SET_LINE_CODING:
|
||||
tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
|
||||
break;
|
||||
|
||||
case CDC_REQUEST_GET_LINE_CODING:
|
||||
tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
|
||||
break;
|
||||
|
||||
case CDC_REQUEST_SET_CONTROL_LINE_STATE:
|
||||
// CDC PSTN v1.2 section 6.3.12
|
||||
// Bit 0: Indicates if DTE is present or not.
|
||||
// This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR (Data Terminal Ready)
|
||||
// Bit 1: Carrier control for half-duplex modems.
|
||||
// This signal corresponds to V.24 signal 105 and RS-232 signal RTS (Request to Send)
|
||||
p_cdc->line_state = (uint8_t) request->wValue;
|
||||
|
||||
tud_control_status(rhport, request);
|
||||
|
||||
// Invoke callback
|
||||
if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, tu_bit_test(request->wValue, 0), tu_bit_test(request->wValue, 1));
|
||||
break;
|
||||
|
||||
default: return false; // stall unsupported request
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
||||
{
|
||||
(void) rhport;
|
||||
(void) result;
|
||||
|
||||
// TODO Support multiple interfaces
|
||||
uint8_t const itf = 0;
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
|
||||
// Received new data
|
||||
if ( ep_addr == p_cdc->ep_out )
|
||||
{
|
||||
for(uint32_t i=0; i<xferred_bytes; i++)
|
||||
{
|
||||
tu_fifo_write(&p_cdc->rx_ff, &p_cdc->epout_buf[i]);
|
||||
|
||||
// Check for wanted char and invoke callback if needed
|
||||
if ( tud_cdc_rx_wanted_cb && ( ((signed char) p_cdc->wanted_char) != -1 ) && ( p_cdc->wanted_char == p_cdc->epout_buf[i] ) )
|
||||
{
|
||||
tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
|
||||
}
|
||||
}
|
||||
|
||||
// invoke receive callback (if there is still data)
|
||||
if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
|
||||
|
||||
// prepare for OUT transaction
|
||||
_prep_out_transaction(itf);
|
||||
}
|
||||
|
||||
// Data sent to host, we could continue to fetch data tx fifo to send.
|
||||
// But it will cause incorrect baudrate set in line coding.
|
||||
// Though maybe the baudrate is not really important !!!
|
||||
// if ( ep_addr == p_cdc->ep_in )
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
// nothing to do with notif endpoint for now
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,213 +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.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_CDC_DEVICE_H_
|
||||
#define _TUSB_CDC_DEVICE_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/usbd.h"
|
||||
#include "cdc.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Driver Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
#ifndef CFG_TUD_CDC_EPSIZE
|
||||
#define CFG_TUD_CDC_EPSIZE 64
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \addtogroup CDC_Serial Serial
|
||||
* @{
|
||||
* \defgroup CDC_Serial_Device Device
|
||||
* @{ */
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Multiple Interfaces)
|
||||
// CFG_TUD_CDC > 1
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_cdc_n_connected (uint8_t itf);
|
||||
uint8_t tud_cdc_n_get_line_state (uint8_t itf);
|
||||
void tud_cdc_n_get_line_coding (uint8_t itf, cdc_line_coding_t* coding);
|
||||
void tud_cdc_n_set_wanted_char (uint8_t itf, char wanted);
|
||||
|
||||
uint32_t tud_cdc_n_available (uint8_t itf);
|
||||
uint32_t tud_cdc_n_read (uint8_t itf, void* buffer, uint32_t bufsize);
|
||||
void tud_cdc_n_read_flush (uint8_t itf);
|
||||
bool tud_cdc_n_peek (uint8_t itf, int pos, uint8_t* u8);
|
||||
static inline int32_t tud_cdc_n_read_char (uint8_t itf);
|
||||
|
||||
uint32_t tud_cdc_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
|
||||
bool tud_cdc_n_write_flush (uint8_t itf);
|
||||
uint32_t tud_cdc_n_write_available (uint8_t itf);
|
||||
static inline uint32_t tud_cdc_n_write_char (uint8_t itf, char ch);
|
||||
static inline uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Interface0)
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool tud_cdc_connected (void);
|
||||
static inline uint8_t tud_cdc_get_line_state (void);
|
||||
static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding);
|
||||
static inline void tud_cdc_set_wanted_char (char wanted);
|
||||
|
||||
static inline uint32_t tud_cdc_available (void);
|
||||
static inline int32_t tud_cdc_read_char (void);
|
||||
static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize);
|
||||
static inline void tud_cdc_read_flush (void);
|
||||
static inline bool tud_cdc_peek (int pos, uint8_t* u8);
|
||||
|
||||
static inline uint32_t tud_cdc_write_char (char ch);
|
||||
static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize);
|
||||
static inline uint32_t tud_cdc_write_str (char const* str);
|
||||
static inline bool tud_cdc_write_flush (void);
|
||||
static inline uint32_t tud_cdc_write_available (void);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application Callback API (weak is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when received new data
|
||||
TU_ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf);
|
||||
|
||||
// Invoked when received `wanted_char`
|
||||
TU_ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
|
||||
|
||||
// Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE
|
||||
TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
|
||||
|
||||
// Invoked when line coding is change via SET_LINE_CODING
|
||||
TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Inline Functions
|
||||
//--------------------------------------------------------------------+
|
||||
static inline int32_t tud_cdc_n_read_char (uint8_t itf)
|
||||
{
|
||||
uint8_t ch;
|
||||
return tud_cdc_n_read(itf, &ch, 1) ? (int32_t) ch : -1;
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_n_write_char(uint8_t itf, char ch)
|
||||
{
|
||||
return tud_cdc_n_write(itf, &ch, 1);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str)
|
||||
{
|
||||
return tud_cdc_n_write(itf, str, strlen(str));
|
||||
}
|
||||
|
||||
static inline bool tud_cdc_connected (void)
|
||||
{
|
||||
return tud_cdc_n_connected(0);
|
||||
}
|
||||
|
||||
static inline uint8_t tud_cdc_get_line_state (void)
|
||||
{
|
||||
return tud_cdc_n_get_line_state(0);
|
||||
}
|
||||
|
||||
static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding)
|
||||
{
|
||||
return tud_cdc_n_get_line_coding(0, coding);
|
||||
}
|
||||
|
||||
static inline void tud_cdc_set_wanted_char (char wanted)
|
||||
{
|
||||
tud_cdc_n_set_wanted_char(0, wanted);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_available (void)
|
||||
{
|
||||
return tud_cdc_n_available(0);
|
||||
}
|
||||
|
||||
static inline int32_t tud_cdc_read_char (void)
|
||||
{
|
||||
return tud_cdc_n_read_char(0);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize)
|
||||
{
|
||||
return tud_cdc_n_read(0, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline void tud_cdc_read_flush (void)
|
||||
{
|
||||
tud_cdc_n_read_flush(0);
|
||||
}
|
||||
|
||||
static inline bool tud_cdc_peek (int pos, uint8_t* u8)
|
||||
{
|
||||
return tud_cdc_n_peek(0, pos, u8);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_write_char (char ch)
|
||||
{
|
||||
return tud_cdc_n_write_char(0, ch);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
return tud_cdc_n_write(0, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_write_str (char const* str)
|
||||
{
|
||||
return tud_cdc_n_write_str(0, str);
|
||||
}
|
||||
|
||||
static inline bool tud_cdc_write_flush (void)
|
||||
{
|
||||
return tud_cdc_n_write_flush(0);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_write_available(void)
|
||||
{
|
||||
return tud_cdc_n_write_available(0);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL USBD-CLASS DRIVER API
|
||||
//--------------------------------------------------------------------+
|
||||
void cdcd_init (void);
|
||||
void cdcd_reset (uint8_t rhport);
|
||||
bool cdcd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
|
||||
bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool cdcd_control_complete (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_CDC_DEVICE_H_ */
|
||||
@@ -1,873 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup group_class
|
||||
* \defgroup ClassDriver_HID Human Interface Device (HID)
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_HID_H_
|
||||
#define _TUSB_HID_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Common Definitions
|
||||
//--------------------------------------------------------------------+
|
||||
/** \defgroup ClassDriver_HID_Common Common Definitions
|
||||
* @{ */
|
||||
|
||||
/// USB HID Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
|
||||
uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
|
||||
|
||||
uint16_t bcdHID; /**< Numeric expression identifying the HID Class Specification release */
|
||||
uint8_t bCountryCode; /**< Numeric expression identifying country code of the localized hardware. */
|
||||
uint8_t bNumDescriptors; /**< Numeric expression specifying the number of class descriptors */
|
||||
|
||||
uint8_t bReportType; /**< Type of HID class report. */
|
||||
uint16_t wReportLength; /**< the total size of the Report descriptor. */
|
||||
} tusb_hid_descriptor_hid_t;
|
||||
|
||||
/// HID Subclass
|
||||
typedef enum
|
||||
{
|
||||
HID_SUBCLASS_NONE = 0, ///< No Subclass
|
||||
HID_SUBCLASS_BOOT = 1 ///< Boot Interface Subclass
|
||||
}hid_subclass_type_t;
|
||||
|
||||
/// HID Protocol
|
||||
typedef enum
|
||||
{
|
||||
HID_PROTOCOL_NONE = 0, ///< None
|
||||
HID_PROTOCOL_KEYBOARD = 1, ///< Keyboard
|
||||
HID_PROTOCOL_MOUSE = 2 ///< Mouse
|
||||
}hid_protocol_type_t;
|
||||
|
||||
/// HID Descriptor Type
|
||||
typedef enum
|
||||
{
|
||||
HID_DESC_TYPE_HID = 0x21, ///< HID Descriptor
|
||||
HID_DESC_TYPE_REPORT = 0x22, ///< Report Descriptor
|
||||
HID_DESC_TYPE_PHYSICAL = 0x23 ///< Physical Descriptor
|
||||
}hid_descriptor_type_t;
|
||||
|
||||
/// HID Request Report Type
|
||||
typedef enum
|
||||
{
|
||||
HID_REPORT_TYPE_INVALID = 0,
|
||||
HID_REPORT_TYPE_INPUT, ///< Input
|
||||
HID_REPORT_TYPE_OUTPUT, ///< Output
|
||||
HID_REPORT_TYPE_FEATURE ///< Feature
|
||||
}hid_report_type_t;
|
||||
|
||||
/// HID Class Specific Control Request
|
||||
typedef enum
|
||||
{
|
||||
HID_REQ_CONTROL_GET_REPORT = 0x01, ///< Get Report
|
||||
HID_REQ_CONTROL_GET_IDLE = 0x02, ///< Get Idle
|
||||
HID_REQ_CONTROL_GET_PROTOCOL = 0x03, ///< Get Protocol
|
||||
HID_REQ_CONTROL_SET_REPORT = 0x09, ///< Set Report
|
||||
HID_REQ_CONTROL_SET_IDLE = 0x0a, ///< Set Idle
|
||||
HID_REQ_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol
|
||||
}hid_request_type_t;
|
||||
|
||||
/// HID Country Code
|
||||
typedef enum
|
||||
{
|
||||
HID_LOCAL_NotSupported = 0 , ///< NotSupported
|
||||
HID_LOCAL_Arabic , ///< Arabic
|
||||
HID_LOCAL_Belgian , ///< Belgian
|
||||
HID_LOCAL_Canadian_Bilingual , ///< Canadian_Bilingual
|
||||
HID_LOCAL_Canadian_French , ///< Canadian_French
|
||||
HID_LOCAL_Czech_Republic , ///< Czech_Republic
|
||||
HID_LOCAL_Danish , ///< Danish
|
||||
HID_LOCAL_Finnish , ///< Finnish
|
||||
HID_LOCAL_French , ///< French
|
||||
HID_LOCAL_German , ///< German
|
||||
HID_LOCAL_Greek , ///< Greek
|
||||
HID_LOCAL_Hebrew , ///< Hebrew
|
||||
HID_LOCAL_Hungary , ///< Hungary
|
||||
HID_LOCAL_International , ///< International
|
||||
HID_LOCAL_Italian , ///< Italian
|
||||
HID_LOCAL_Japan_Katakana , ///< Japan_Katakana
|
||||
HID_LOCAL_Korean , ///< Korean
|
||||
HID_LOCAL_Latin_American , ///< Latin_American
|
||||
HID_LOCAL_Netherlands_Dutch , ///< Netherlands/Dutch
|
||||
HID_LOCAL_Norwegian , ///< Norwegian
|
||||
HID_LOCAL_Persian_Farsi , ///< Persian (Farsi)
|
||||
HID_LOCAL_Poland , ///< Poland
|
||||
HID_LOCAL_Portuguese , ///< Portuguese
|
||||
HID_LOCAL_Russia , ///< Russia
|
||||
HID_LOCAL_Slovakia , ///< Slovakia
|
||||
HID_LOCAL_Spanish , ///< Spanish
|
||||
HID_LOCAL_Swedish , ///< Swedish
|
||||
HID_LOCAL_Swiss_French , ///< Swiss/French
|
||||
HID_LOCAL_Swiss_German , ///< Swiss/German
|
||||
HID_LOCAL_Switzerland , ///< Switzerland
|
||||
HID_LOCAL_Taiwan , ///< Taiwan
|
||||
HID_LOCAL_Turkish_Q , ///< Turkish-Q
|
||||
HID_LOCAL_UK , ///< UK
|
||||
HID_LOCAL_US , ///< US
|
||||
HID_LOCAL_Yugoslavia , ///< Yugoslavia
|
||||
HID_LOCAL_Turkish_F ///< Turkish-F
|
||||
} hid_country_code_t;
|
||||
|
||||
/** @} */
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MOUSE
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Mouse Mouse
|
||||
* @{ */
|
||||
|
||||
/// Standard HID Boot Protocol Mouse Report.
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t buttons; /**< buttons mask for currently pressed buttons in the mouse. */
|
||||
int8_t x; /**< Current delta x movement of the mouse. */
|
||||
int8_t y; /**< Current delta y movement on the mouse. */
|
||||
int8_t wheel; /**< Current delta wheel movement on the mouse. */
|
||||
int8_t pan; // using AC Pan
|
||||
} hid_mouse_report_t;
|
||||
|
||||
/// Standard Mouse Buttons Bitmap
|
||||
typedef enum
|
||||
{
|
||||
MOUSE_BUTTON_LEFT = TU_BIT(0), ///< Left button
|
||||
MOUSE_BUTTON_RIGHT = TU_BIT(1), ///< Right button
|
||||
MOUSE_BUTTON_MIDDLE = TU_BIT(2), ///< Middle button
|
||||
MOUSE_BUTTON_BACKWARD = TU_BIT(3), ///< Backward button,
|
||||
MOUSE_BUTTON_FORWARD = TU_BIT(4), ///< Forward button,
|
||||
}hid_mouse_button_bm_t;
|
||||
|
||||
/// @}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Keyboard
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
|
||||
* @{ */
|
||||
|
||||
/// Standard HID Boot Protocol Keyboard Report.
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t modifier; /**< Keyboard modifier (KEYBOARD_MODIFER_* masks). */
|
||||
uint8_t reserved; /**< Reserved for OEM use, always set to 0. */
|
||||
uint8_t keycode[6]; /**< Key codes of the currently pressed keys. */
|
||||
} hid_keyboard_report_t;
|
||||
|
||||
/// Keyboard modifier codes bitmap
|
||||
typedef enum
|
||||
{
|
||||
KEYBOARD_MODIFIER_LEFTCTRL = TU_BIT(0), ///< Left Control
|
||||
KEYBOARD_MODIFIER_LEFTSHIFT = TU_BIT(1), ///< Left Shift
|
||||
KEYBOARD_MODIFIER_LEFTALT = TU_BIT(2), ///< Left Alt
|
||||
KEYBOARD_MODIFIER_LEFTGUI = TU_BIT(3), ///< Left Window
|
||||
KEYBOARD_MODIFIER_RIGHTCTRL = TU_BIT(4), ///< Right Control
|
||||
KEYBOARD_MODIFIER_RIGHTSHIFT = TU_BIT(5), ///< Right Shift
|
||||
KEYBOARD_MODIFIER_RIGHTALT = TU_BIT(6), ///< Right Alt
|
||||
KEYBOARD_MODIFIER_RIGHTGUI = TU_BIT(7) ///< Right Window
|
||||
}hid_keyboard_modifier_bm_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KEYBOARD_LED_NUMLOCK = TU_BIT(0), ///< Num Lock LED
|
||||
KEYBOARD_LED_CAPSLOCK = TU_BIT(1), ///< Caps Lock LED
|
||||
KEYBOARD_LED_SCROLLLOCK = TU_BIT(2), ///< Scroll Lock LED
|
||||
KEYBOARD_LED_COMPOSE = TU_BIT(3), ///< Composition Mode
|
||||
KEYBOARD_LED_KANA = TU_BIT(4) ///< Kana mode
|
||||
}hid_keyboard_led_bm_t;
|
||||
|
||||
/// @}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HID KEYCODE
|
||||
//--------------------------------------------------------------------+
|
||||
#define HID_KEY_NONE 0x00
|
||||
#define HID_KEY_A 0x04
|
||||
#define HID_KEY_B 0x05
|
||||
#define HID_KEY_C 0x06
|
||||
#define HID_KEY_D 0x07
|
||||
#define HID_KEY_E 0x08
|
||||
#define HID_KEY_F 0x09
|
||||
#define HID_KEY_G 0x0A
|
||||
#define HID_KEY_H 0x0B
|
||||
#define HID_KEY_I 0x0C
|
||||
#define HID_KEY_J 0x0D
|
||||
#define HID_KEY_K 0x0E
|
||||
#define HID_KEY_L 0x0F
|
||||
#define HID_KEY_M 0x10
|
||||
#define HID_KEY_N 0x11
|
||||
#define HID_KEY_O 0x12
|
||||
#define HID_KEY_P 0x13
|
||||
#define HID_KEY_Q 0x14
|
||||
#define HID_KEY_R 0x15
|
||||
#define HID_KEY_S 0x16
|
||||
#define HID_KEY_T 0x17
|
||||
#define HID_KEY_U 0x18
|
||||
#define HID_KEY_V 0x19
|
||||
#define HID_KEY_W 0x1A
|
||||
#define HID_KEY_X 0x1B
|
||||
#define HID_KEY_Y 0x1C
|
||||
#define HID_KEY_Z 0x1D
|
||||
#define HID_KEY_1 0x1E
|
||||
#define HID_KEY_2 0x1F
|
||||
#define HID_KEY_3 0x20
|
||||
#define HID_KEY_4 0x21
|
||||
#define HID_KEY_5 0x22
|
||||
#define HID_KEY_6 0x23
|
||||
#define HID_KEY_7 0x24
|
||||
#define HID_KEY_8 0x25
|
||||
#define HID_KEY_9 0x26
|
||||
#define HID_KEY_0 0x27
|
||||
#define HID_KEY_RETURN 0x28
|
||||
#define HID_KEY_ESCAPE 0x29
|
||||
#define HID_KEY_BACKSPACE 0x2A
|
||||
#define HID_KEY_TAB 0x2B
|
||||
#define HID_KEY_SPACE 0x2C
|
||||
#define HID_KEY_MINUS 0x2D
|
||||
#define HID_KEY_EQUAL 0x2E
|
||||
#define HID_KEY_BRACKET_LEFT 0x2F
|
||||
#define HID_KEY_BRACKET_RIGHT 0x30
|
||||
#define HID_KEY_BACKSLASH 0x31
|
||||
#define HID_KEY_EUROPE_1 0x32
|
||||
#define HID_KEY_SEMICOLON 0x33
|
||||
#define HID_KEY_APOSTROPHE 0x34
|
||||
#define HID_KEY_GRAVE 0x35
|
||||
#define HID_KEY_COMMA 0x36
|
||||
#define HID_KEY_PERIOD 0x37
|
||||
#define HID_KEY_SLASH 0x38
|
||||
#define HID_KEY_CAPS_LOCK 0x39
|
||||
#define HID_KEY_F1 0x3A
|
||||
#define HID_KEY_F2 0x3B
|
||||
#define HID_KEY_F3 0x3C
|
||||
#define HID_KEY_F4 0x3D
|
||||
#define HID_KEY_F5 0x3E
|
||||
#define HID_KEY_F6 0x3F
|
||||
#define HID_KEY_F7 0x40
|
||||
#define HID_KEY_F8 0x41
|
||||
#define HID_KEY_F9 0x42
|
||||
#define HID_KEY_F10 0x43
|
||||
#define HID_KEY_F11 0x44
|
||||
#define HID_KEY_F12 0x45
|
||||
#define HID_KEY_PRINT_SCREEN 0x46
|
||||
#define HID_KEY_SCROLL_LOCK 0x47
|
||||
#define HID_KEY_PAUSE 0x48
|
||||
#define HID_KEY_INSERT 0x49
|
||||
#define HID_KEY_HOME 0x4A
|
||||
#define HID_KEY_PAGE_UP 0x4B
|
||||
#define HID_KEY_DELETE 0x4C
|
||||
#define HID_KEY_END 0x4D
|
||||
#define HID_KEY_PAGE_DOWN 0x4E
|
||||
#define HID_KEY_ARROW_RIGHT 0x4F
|
||||
#define HID_KEY_ARROW_LEFT 0x50
|
||||
#define HID_KEY_ARROW_DOWN 0x51
|
||||
#define HID_KEY_ARROW_UP 0x52
|
||||
#define HID_KEY_NUM_LOCK 0x53
|
||||
#define HID_KEY_KEYPAD_DIVIDE 0x54
|
||||
#define HID_KEY_KEYPAD_MULTIPLY 0x55
|
||||
#define HID_KEY_KEYPAD_SUBTRACT 0x56
|
||||
#define HID_KEY_KEYPAD_ADD 0x57
|
||||
#define HID_KEY_KEYPAD_ENTER 0x58
|
||||
#define HID_KEY_KEYPAD_1 0x59
|
||||
#define HID_KEY_KEYPAD_2 0x5A
|
||||
#define HID_KEY_KEYPAD_3 0x5B
|
||||
#define HID_KEY_KEYPAD_4 0x5C
|
||||
#define HID_KEY_KEYPAD_5 0x5D
|
||||
#define HID_KEY_KEYPAD_6 0x5E
|
||||
#define HID_KEY_KEYPAD_7 0x5F
|
||||
#define HID_KEY_KEYPAD_8 0x60
|
||||
#define HID_KEY_KEYPAD_9 0x61
|
||||
#define HID_KEY_KEYPAD_0 0x62
|
||||
#define HID_KEY_KEYPAD_DECIMAL 0x63
|
||||
#define HID_KEY_EUROPE_2 0x64
|
||||
#define HID_KEY_APPLICATION 0x65
|
||||
#define HID_KEY_POWER 0x66
|
||||
#define HID_KEY_KEYPAD_EQUAL 0x67
|
||||
#define HID_KEY_F13 0x68
|
||||
#define HID_KEY_F14 0x69
|
||||
#define HID_KEY_F15 0x6A
|
||||
#define HID_KEY_CONTROL_LEFT 0xE0
|
||||
#define HID_KEY_SHIFT_LEFT 0xE1
|
||||
#define HID_KEY_ALT_LEFT 0xE2
|
||||
#define HID_KEY_GUI_LEFT 0xE3
|
||||
#define HID_KEY_CONTROL_RIGHT 0xE4
|
||||
#define HID_KEY_SHIFT_RIGHT 0xE5
|
||||
#define HID_KEY_ALT_RIGHT 0xE6
|
||||
#define HID_KEY_GUI_RIGHT 0xE7
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// REPORT DESCRIPTOR
|
||||
//--------------------------------------------------------------------+
|
||||
//------------- ITEM & TAG -------------//
|
||||
#define HID_REPORT_DATA_0(data)
|
||||
#define HID_REPORT_DATA_1(data) , data
|
||||
#define HID_REPORT_DATA_2(data) , U16_TO_U8S_LE(data)
|
||||
#define HID_REPORT_DATA_3(data) , U32_TO_U8S_LE(data)
|
||||
|
||||
#define HID_REPORT_ITEM(data, tag, type, size) \
|
||||
(((tag) << 4) | ((type) << 2) | (size)) HID_REPORT_DATA_##size(data)
|
||||
|
||||
#define RI_TYPE_MAIN 0
|
||||
#define RI_TYPE_GLOBAL 1
|
||||
#define RI_TYPE_LOCAL 2
|
||||
|
||||
//------------- MAIN ITEMS 6.2.2.4 -------------//
|
||||
#define HID_INPUT(x) HID_REPORT_ITEM(x, 8, RI_TYPE_MAIN, 1)
|
||||
#define HID_OUTPUT(x) HID_REPORT_ITEM(x, 9, RI_TYPE_MAIN, 1)
|
||||
#define HID_COLLECTION(x) HID_REPORT_ITEM(x, 10, RI_TYPE_MAIN, 1)
|
||||
#define HID_FEATURE(x) HID_REPORT_ITEM(x, 11, RI_TYPE_MAIN, 1)
|
||||
#define HID_COLLECTION_END HID_REPORT_ITEM(x, 12, RI_TYPE_MAIN, 0)
|
||||
|
||||
//------------- INPUT, OUTPUT, FEATURE 6.2.2.5 -------------//
|
||||
#define HID_DATA (0<<0)
|
||||
#define HID_CONSTANT (1<<0)
|
||||
|
||||
#define HID_ARRAY (0<<1)
|
||||
#define HID_VARIABLE (1<<1)
|
||||
|
||||
#define HID_ABSOLUTE (0<<2)
|
||||
#define HID_RELATIVE (1<<2)
|
||||
|
||||
#define HID_WRAP_NO (0<<3)
|
||||
#define HID_WRAP (1<<3)
|
||||
|
||||
#define HID_LINEAR (0<<4)
|
||||
#define HID_NONLINEAR (1<<4)
|
||||
|
||||
#define HID_PREFERRED_STATE (0<<5)
|
||||
#define HID_PREFERRED_NO (1<<5)
|
||||
|
||||
#define HID_NO_NULL_POSITION (0<<6)
|
||||
#define HID_NULL_STATE (1<<6)
|
||||
|
||||
#define HID_NON_VOLATILE (0<<7)
|
||||
#define HID_VOLATILE (1<<7)
|
||||
|
||||
#define HID_BITFIELD (0<<8)
|
||||
#define HID_BUFFERED_BYTES (1<<8)
|
||||
|
||||
//------------- COLLECTION ITEM 6.2.2.6 -------------//
|
||||
enum {
|
||||
HID_COLLECTION_PHYSICAL = 0,
|
||||
HID_COLLECTION_APPLICATION,
|
||||
HID_COLLECTION_LOGICAL,
|
||||
HID_COLLECTION_REPORT,
|
||||
HID_COLLECTION_NAMED_ARRAY,
|
||||
HID_COLLECTION_USAGE_SWITCH,
|
||||
HID_COLLECTION_USAGE_MODIFIER
|
||||
};
|
||||
|
||||
//------------- GLOBAL ITEMS 6.2.2.7 -------------//
|
||||
#define HID_USAGE_PAGE(x) HID_REPORT_ITEM(x, 0, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_USAGE_PAGE_N(x, n) HID_REPORT_ITEM(x, 0, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_LOGICAL_MIN(x) HID_REPORT_ITEM(x, 1, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_LOGICAL_MIN_N(x, n) HID_REPORT_ITEM(x, 1, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_LOGICAL_MAX(x) HID_REPORT_ITEM(x, 2, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_LOGICAL_MAX_N(x, n) HID_REPORT_ITEM(x, 2, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_PHYSICAL_MIN(x) HID_REPORT_ITEM(x, 3, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_PHYSICAL_MIN_N(x, n) HID_REPORT_ITEM(x, 3, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_PHYSICAL_MAX(x) HID_REPORT_ITEM(x, 4, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_PHYSICAL_MAX_N(x, n) HID_REPORT_ITEM(x, 4, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_UNIT_EXPONENT(x) HID_REPORT_ITEM(x, 5, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_UNIT_EXPONENT_N(x, n) HID_REPORT_ITEM(x, 5, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_UNIT(x) HID_REPORT_ITEM(x, 6, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_UNIT_N(x, n) HID_REPORT_ITEM(x, 6, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_REPORT_SIZE(x) HID_REPORT_ITEM(x, 7, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_REPORT_SIZE_N(x, n) HID_REPORT_ITEM(x, 7, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_REPORT_ID(x) HID_REPORT_ITEM(x, 8, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_REPORT_ID_N(x) HID_REPORT_ITEM(x, 8, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_REPORT_COUNT(x) HID_REPORT_ITEM(x, 9, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_REPORT_COUNT_N(x, n) HID_REPORT_ITEM(x, 9, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_PUSH HID_REPORT_ITEM(x, 10, RI_TYPE_GLOBAL, 0)
|
||||
#define HID_POP HID_REPORT_ITEM(x, 11, RI_TYPE_GLOBAL, 0)
|
||||
|
||||
//------------- LOCAL ITEMS 6.2.2.8 -------------//
|
||||
#define HID_USAGE(x) HID_REPORT_ITEM(x, 0, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_N(x, n) HID_REPORT_ITEM(x, 0, RI_TYPE_LOCAL, n)
|
||||
|
||||
#define HID_USAGE_MIN(x) HID_REPORT_ITEM(x, 1, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_MIN_N(x, n) HID_REPORT_ITEM(x, 1, RI_TYPE_LOCAL, n)
|
||||
|
||||
#define HID_USAGE_MAX(x) HID_REPORT_ITEM(x, 2, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_MAX_N(x, n) HID_REPORT_ITEM(x, 2, RI_TYPE_LOCAL, n)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Usage Table
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// HID Usage Table - Table 1: Usage Page Summary
|
||||
enum {
|
||||
HID_USAGE_PAGE_DESKTOP = 0x01,
|
||||
HID_USAGE_PAGE_SIMULATE = 0x02,
|
||||
HID_USAGE_PAGE_VIRTUAL_REALITY = 0x03,
|
||||
HID_USAGE_PAGE_SPORT = 0x04,
|
||||
HID_USAGE_PAGE_GAME = 0x05,
|
||||
HID_USAGE_PAGE_GENERIC_DEVICE = 0x06,
|
||||
HID_USAGE_PAGE_KEYBOARD = 0x07,
|
||||
HID_USAGE_PAGE_LED = 0x08,
|
||||
HID_USAGE_PAGE_BUTTON = 0x09,
|
||||
HID_USAGE_PAGE_ORDINAL = 0x0a,
|
||||
HID_USAGE_PAGE_TELEPHONY = 0x0b,
|
||||
HID_USAGE_PAGE_CONSUMER = 0x0c,
|
||||
HID_USAGE_PAGE_DIGITIZER = 0x0d,
|
||||
HID_USAGE_PAGE_PID = 0x0f,
|
||||
HID_USAGE_PAGE_UNICODE = 0x10,
|
||||
HID_USAGE_PAGE_ALPHA_DISPLAY = 0x14,
|
||||
HID_USAGE_PAGE_MEDICAL = 0x40,
|
||||
HID_USAGE_PAGE_MONITOR = 0x80, //0x80 - 0x83
|
||||
HID_USAGE_PAGE_POWER = 0x84, // 0x084 - 0x87
|
||||
HID_USAGE_PAGE_BARCODE_SCANNER = 0x8c,
|
||||
HID_USAGE_PAGE_SCALE = 0x8d,
|
||||
HID_USAGE_PAGE_MSR = 0x8e,
|
||||
HID_USAGE_PAGE_CAMERA = 0x90,
|
||||
HID_USAGE_PAGE_ARCADE = 0x91,
|
||||
HID_USAGE_PAGE_VENDOR = 0xFF00 // 0xFF00 - 0xFFFF
|
||||
};
|
||||
|
||||
/// HID Usage Table - Table 6: Generic Desktop Page
|
||||
enum {
|
||||
HID_USAGE_DESKTOP_POINTER = 0x01,
|
||||
HID_USAGE_DESKTOP_MOUSE = 0x02,
|
||||
HID_USAGE_DESKTOP_JOYSTICK = 0x04,
|
||||
HID_USAGE_DESKTOP_GAMEPAD = 0x05,
|
||||
HID_USAGE_DESKTOP_KEYBOARD = 0x06,
|
||||
HID_USAGE_DESKTOP_KEYPAD = 0x07,
|
||||
HID_USAGE_DESKTOP_MULTI_AXIS_CONTROLLER = 0x08,
|
||||
HID_USAGE_DESKTOP_TABLET_PC_SYSTEM = 0x09,
|
||||
HID_USAGE_DESKTOP_X = 0x30,
|
||||
HID_USAGE_DESKTOP_Y = 0x31,
|
||||
HID_USAGE_DESKTOP_Z = 0x32,
|
||||
HID_USAGE_DESKTOP_RX = 0x33,
|
||||
HID_USAGE_DESKTOP_RY = 0x34,
|
||||
HID_USAGE_DESKTOP_RZ = 0x35,
|
||||
HID_USAGE_DESKTOP_SLIDER = 0x36,
|
||||
HID_USAGE_DESKTOP_DIAL = 0x37,
|
||||
HID_USAGE_DESKTOP_WHEEL = 0x38,
|
||||
HID_USAGE_DESKTOP_HAT_SWITCH = 0x39,
|
||||
HID_USAGE_DESKTOP_COUNTED_BUFFER = 0x3a,
|
||||
HID_USAGE_DESKTOP_BYTE_COUNT = 0x3b,
|
||||
HID_USAGE_DESKTOP_MOTION_WAKEUP = 0x3c,
|
||||
HID_USAGE_DESKTOP_START = 0x3d,
|
||||
HID_USAGE_DESKTOP_SELECT = 0x3e,
|
||||
HID_USAGE_DESKTOP_VX = 0x40,
|
||||
HID_USAGE_DESKTOP_VY = 0x41,
|
||||
HID_USAGE_DESKTOP_VZ = 0x42,
|
||||
HID_USAGE_DESKTOP_VBRX = 0x43,
|
||||
HID_USAGE_DESKTOP_VBRY = 0x44,
|
||||
HID_USAGE_DESKTOP_VBRZ = 0x45,
|
||||
HID_USAGE_DESKTOP_VNO = 0x46,
|
||||
HID_USAGE_DESKTOP_FEATURE_NOTIFICATION = 0x47,
|
||||
HID_USAGE_DESKTOP_RESOLUTION_MULTIPLIER = 0x48,
|
||||
HID_USAGE_DESKTOP_SYSTEM_CONTROL = 0x80,
|
||||
HID_USAGE_DESKTOP_SYSTEM_POWER_DOWN = 0x81,
|
||||
HID_USAGE_DESKTOP_SYSTEM_SLEEP = 0x82,
|
||||
HID_USAGE_DESKTOP_SYSTEM_WAKE_UP = 0x83,
|
||||
HID_USAGE_DESKTOP_SYSTEM_CONTEXT_MENU = 0x84,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MAIN_MENU = 0x85,
|
||||
HID_USAGE_DESKTOP_SYSTEM_APP_MENU = 0x86,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_HELP = 0x87,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_EXIT = 0x88,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_SELECT = 0x89,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_RIGHT = 0x8A,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_LEFT = 0x8B,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_UP = 0x8C,
|
||||
HID_USAGE_DESKTOP_SYSTEM_MENU_DOWN = 0x8D,
|
||||
HID_USAGE_DESKTOP_SYSTEM_COLD_RESTART = 0x8E,
|
||||
HID_USAGE_DESKTOP_SYSTEM_WARM_RESTART = 0x8F,
|
||||
HID_USAGE_DESKTOP_DPAD_UP = 0x90,
|
||||
HID_USAGE_DESKTOP_DPAD_DOWN = 0x91,
|
||||
HID_USAGE_DESKTOP_DPAD_RIGHT = 0x92,
|
||||
HID_USAGE_DESKTOP_DPAD_LEFT = 0x93,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DOCK = 0xA0,
|
||||
HID_USAGE_DESKTOP_SYSTEM_UNDOCK = 0xA1,
|
||||
HID_USAGE_DESKTOP_SYSTEM_SETUP = 0xA2,
|
||||
HID_USAGE_DESKTOP_SYSTEM_BREAK = 0xA3,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DEBUGGER_BREAK = 0xA4,
|
||||
HID_USAGE_DESKTOP_APPLICATION_BREAK = 0xA5,
|
||||
HID_USAGE_DESKTOP_APPLICATION_DEBUGGER_BREAK = 0xA6,
|
||||
HID_USAGE_DESKTOP_SYSTEM_SPEAKER_MUTE = 0xA7,
|
||||
HID_USAGE_DESKTOP_SYSTEM_HIBERNATE = 0xA8,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INVERT = 0xB0,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INTERNAL = 0xB1,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_EXTERNAL = 0xB2,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_BOTH = 0xB3,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_DUAL = 0xB4,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_TOGGLE_INT_EXT = 0xB5,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_SWAP_PRIMARY_SECONDARY = 0xB6,
|
||||
HID_USAGE_DESKTOP_SYSTEM_DISPLAY_LCD_AUTOSCALE = 0xB7
|
||||
};
|
||||
|
||||
|
||||
/// HID Usage Table: Consumer Page (0x0C)
|
||||
/// Only contains controls that supported by Windows (whole list is too long)
|
||||
enum
|
||||
{
|
||||
// Generic Control
|
||||
HID_USAGE_CONSUMER_CONTROL = 0x0001,
|
||||
|
||||
// Power Control
|
||||
HID_USAGE_CONSUMER_POWER = 0x0030,
|
||||
HID_USAGE_CONSUMER_RESET = 0x0031,
|
||||
HID_USAGE_CONSUMER_SLEEP = 0x0032,
|
||||
|
||||
// Screen Brightness
|
||||
HID_USAGE_CONSUMER_BRIGHTNESS_INCREMENT = 0x006F,
|
||||
HID_USAGE_CONSUMER_BRIGHTNESS_DECREMENT = 0x0070,
|
||||
|
||||
// These HID usages operate only on mobile systems (battery powered) and
|
||||
// require Windows 8 (build 8302 or greater).
|
||||
HID_USAGE_CONSUMER_WIRELESS_RADIO_CONTROLS = 0x000C,
|
||||
HID_USAGE_CONSUMER_WIRELESS_RADIO_BUTTONS = 0x00C6,
|
||||
HID_USAGE_CONSUMER_WIRELESS_RADIO_LED = 0x00C7,
|
||||
HID_USAGE_CONSUMER_WIRELESS_RADIO_SLIDER_SWITCH = 0x00C8,
|
||||
|
||||
// Media Control
|
||||
HID_USAGE_CONSUMER_PLAY_PAUSE = 0x00CD,
|
||||
HID_USAGE_CONSUMER_SCAN_NEXT = 0x00B5,
|
||||
HID_USAGE_CONSUMER_SCAN_PREVIOUS = 0x00B6,
|
||||
HID_USAGE_CONSUMER_STOP = 0x00B7,
|
||||
HID_USAGE_CONSUMER_VOLUME = 0x00E0,
|
||||
HID_USAGE_CONSUMER_MUTE = 0x00E2,
|
||||
HID_USAGE_CONSUMER_BASS = 0x00E3,
|
||||
HID_USAGE_CONSUMER_TREBLE = 0x00E4,
|
||||
HID_USAGE_CONSUMER_BASS_BOOST = 0x00E5,
|
||||
HID_USAGE_CONSUMER_VOLUME_INCREMENT = 0x00E9,
|
||||
HID_USAGE_CONSUMER_VOLUME_DECREMENT = 0x00EA,
|
||||
HID_USAGE_CONSUMER_BASS_INCREMENT = 0x0152,
|
||||
HID_USAGE_CONSUMER_BASS_DECREMENT = 0x0153,
|
||||
HID_USAGE_CONSUMER_TREBLE_INCREMENT = 0x0154,
|
||||
HID_USAGE_CONSUMER_TREBLE_DECREMENT = 0x0155,
|
||||
|
||||
// Application Launcher
|
||||
HID_USAGE_CONSUMER_AL_CONSUMER_CONTROL_CONFIGURATION = 0x0183,
|
||||
HID_USAGE_CONSUMER_AL_EMAIL_READER = 0x018A,
|
||||
HID_USAGE_CONSUMER_AL_CALCULATOR = 0x0192,
|
||||
HID_USAGE_CONSUMER_AL_LOCAL_BROWSER = 0x0194,
|
||||
|
||||
// Browser/Explorer Specific
|
||||
HID_USAGE_CONSUMER_AC_SEARCH = 0x0221,
|
||||
HID_USAGE_CONSUMER_AC_HOME = 0x0223,
|
||||
HID_USAGE_CONSUMER_AC_BACK = 0x0224,
|
||||
HID_USAGE_CONSUMER_AC_FORWARD = 0x0225,
|
||||
HID_USAGE_CONSUMER_AC_STOP = 0x0226,
|
||||
HID_USAGE_CONSUMER_AC_REFRESH = 0x0227,
|
||||
HID_USAGE_CONSUMER_AC_BOOKMARKS = 0x022A,
|
||||
|
||||
// Mouse Horizontal scroll
|
||||
HID_USAGE_CONSUMER_AC_PAN = 0x0238,
|
||||
};
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
* ASCII to KEYCODE Conversion
|
||||
* Expand to array of [128][2] (shift, keycode)
|
||||
*
|
||||
* Usage: example to convert input chr into keyboard report (modifier + keycode)
|
||||
*
|
||||
* uint8_t const conv_table[128][2] = { HID_ASCII_TO_KEYCODE };
|
||||
*
|
||||
* uint8_t keycode[6] = { 0 };
|
||||
* uint8_t modifier = 0;
|
||||
*
|
||||
* if ( conv_table[chr][0] ) modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
|
||||
* keycode[0] = conv_table[chr][1];
|
||||
* tud_hid_keyboard_report(report_id, modifier, keycode);
|
||||
*
|
||||
*--------------------------------------------------------------------*/
|
||||
#define HID_ASCII_TO_KEYCODE \
|
||||
{0, 0 }, /* 0x00 Null */ \
|
||||
{0, 0 }, /* 0x01 */ \
|
||||
{0, 0 }, /* 0x02 */ \
|
||||
{0, 0 }, /* 0x03 */ \
|
||||
{0, 0 }, /* 0x04 */ \
|
||||
{0, 0 }, /* 0x05 */ \
|
||||
{0, 0 }, /* 0x06 */ \
|
||||
{0, 0 }, /* 0x07 */ \
|
||||
{0, HID_KEY_BACKSPACE }, /* 0x08 Backspace */ \
|
||||
{0, HID_KEY_TAB }, /* 0x09 Tab */ \
|
||||
{0, HID_KEY_RETURN }, /* 0x0A Line Feed */ \
|
||||
{0, 0 }, /* 0x0B */ \
|
||||
{0, 0 }, /* 0x0C */ \
|
||||
{0, HID_KEY_RETURN }, /* 0x0D CR */ \
|
||||
{0, 0 }, /* 0x0E */ \
|
||||
{0, 0 }, /* 0x0F */ \
|
||||
{0, 0 }, /* 0x10 */ \
|
||||
{0, 0 }, /* 0x11 */ \
|
||||
{0, 0 }, /* 0x12 */ \
|
||||
{0, 0 }, /* 0x13 */ \
|
||||
{0, 0 }, /* 0x14 */ \
|
||||
{0, 0 }, /* 0x15 */ \
|
||||
{0, 0 }, /* 0x16 */ \
|
||||
{0, 0 }, /* 0x17 */ \
|
||||
{0, 0 }, /* 0x18 */ \
|
||||
{0, 0 }, /* 0x19 */ \
|
||||
{0, 0 }, /* 0x1A */ \
|
||||
{0, HID_KEY_ESCAPE }, /* 0x1B Escape */ \
|
||||
{0, 0 }, /* 0x1C */ \
|
||||
{0, 0 }, /* 0x1D */ \
|
||||
{0, 0 }, /* 0x1E */ \
|
||||
{0, 0 }, /* 0x1F */ \
|
||||
\
|
||||
{0, HID_KEY_SPACE }, /* 0x20 */ \
|
||||
{1, HID_KEY_1 }, /* 0x21 ! */ \
|
||||
{1, HID_KEY_APOSTROPHE }, /* 0x22 " */ \
|
||||
{1, HID_KEY_3 }, /* 0x23 # */ \
|
||||
{1, HID_KEY_4 }, /* 0x24 $ */ \
|
||||
{1, HID_KEY_5 }, /* 0x25 % */ \
|
||||
{1, HID_KEY_7 }, /* 0x26 & */ \
|
||||
{0, HID_KEY_APOSTROPHE }, /* 0x27 ' */ \
|
||||
{1, HID_KEY_9 }, /* 0x28 ( */ \
|
||||
{1, HID_KEY_0 }, /* 0x29 ) */ \
|
||||
{1, HID_KEY_8 }, /* 0x2A * */ \
|
||||
{1, HID_KEY_EQUAL }, /* 0x2B + */ \
|
||||
{0, HID_KEY_COMMA }, /* 0x2C , */ \
|
||||
{0, HID_KEY_MINUS }, /* 0x2D - */ \
|
||||
{0, HID_KEY_PERIOD }, /* 0x2E . */ \
|
||||
{0, HID_KEY_SLASH }, /* 0x2F / */ \
|
||||
{0, HID_KEY_0 }, /* 0x30 0 */ \
|
||||
{0, HID_KEY_1 }, /* 0x31 1 */ \
|
||||
{0, HID_KEY_2 }, /* 0x32 2 */ \
|
||||
{0, HID_KEY_3 }, /* 0x33 3 */ \
|
||||
{0, HID_KEY_4 }, /* 0x34 4 */ \
|
||||
{0, HID_KEY_5 }, /* 0x35 5 */ \
|
||||
{0, HID_KEY_6 }, /* 0x36 6 */ \
|
||||
{0, HID_KEY_7 }, /* 0x37 7 */ \
|
||||
{0, HID_KEY_8 }, /* 0x38 8 */ \
|
||||
{0, HID_KEY_9 }, /* 0x39 9 */ \
|
||||
{1, HID_KEY_SEMICOLON }, /* 0x3A : */ \
|
||||
{0, HID_KEY_SEMICOLON }, /* 0x3B ; */ \
|
||||
{1, HID_KEY_COMMA }, /* 0x3C < */ \
|
||||
{0, HID_KEY_EQUAL }, /* 0x3D = */ \
|
||||
{1, HID_KEY_PERIOD }, /* 0x3E > */ \
|
||||
{1, HID_KEY_SLASH }, /* 0x3F ? */ \
|
||||
\
|
||||
{1, HID_KEY_2 }, /* 0x40 @ */ \
|
||||
{1, HID_KEY_A }, /* 0x41 A */ \
|
||||
{1, HID_KEY_B }, /* 0x42 B */ \
|
||||
{1, HID_KEY_C }, /* 0x43 C */ \
|
||||
{1, HID_KEY_D }, /* 0x44 D */ \
|
||||
{1, HID_KEY_E }, /* 0x45 E */ \
|
||||
{1, HID_KEY_F }, /* 0x46 F */ \
|
||||
{1, HID_KEY_G }, /* 0x47 G */ \
|
||||
{1, HID_KEY_H }, /* 0x48 H */ \
|
||||
{1, HID_KEY_I }, /* 0x49 I */ \
|
||||
{1, HID_KEY_J }, /* 0x4A J */ \
|
||||
{1, HID_KEY_K }, /* 0x4B K */ \
|
||||
{1, HID_KEY_L }, /* 0x4C L */ \
|
||||
{1, HID_KEY_M }, /* 0x4D M */ \
|
||||
{1, HID_KEY_N }, /* 0x4E N */ \
|
||||
{1, HID_KEY_O }, /* 0x4F O */ \
|
||||
{1, HID_KEY_P }, /* 0x50 P */ \
|
||||
{1, HID_KEY_Q }, /* 0x51 Q */ \
|
||||
{1, HID_KEY_R }, /* 0x52 R */ \
|
||||
{1, HID_KEY_S }, /* 0x53 S */ \
|
||||
{1, HID_KEY_T }, /* 0x55 T */ \
|
||||
{1, HID_KEY_U }, /* 0x55 U */ \
|
||||
{1, HID_KEY_V }, /* 0x56 V */ \
|
||||
{1, HID_KEY_W }, /* 0x57 W */ \
|
||||
{1, HID_KEY_X }, /* 0x58 X */ \
|
||||
{1, HID_KEY_Y }, /* 0x59 Y */ \
|
||||
{1, HID_KEY_Z }, /* 0x5A Z */ \
|
||||
{0, HID_KEY_BRACKET_LEFT }, /* 0x5B [ */ \
|
||||
{0, HID_KEY_BACKSLASH }, /* 0x5C '\' */ \
|
||||
{0, HID_KEY_BRACKET_RIGHT }, /* 0x5D ] */ \
|
||||
{1, HID_KEY_6 }, /* 0x5E ^ */ \
|
||||
{1, HID_KEY_MINUS }, /* 0x5F _ */ \
|
||||
\
|
||||
{0, HID_KEY_GRAVE }, /* 0x60 ` */ \
|
||||
{0, HID_KEY_A }, /* 0x61 a */ \
|
||||
{0, HID_KEY_B }, /* 0x62 b */ \
|
||||
{0, HID_KEY_C }, /* 0x63 c */ \
|
||||
{0, HID_KEY_D }, /* 0x66 d */ \
|
||||
{0, HID_KEY_E }, /* 0x65 e */ \
|
||||
{0, HID_KEY_F }, /* 0x66 f */ \
|
||||
{0, HID_KEY_G }, /* 0x67 g */ \
|
||||
{0, HID_KEY_H }, /* 0x68 h */ \
|
||||
{0, HID_KEY_I }, /* 0x69 i */ \
|
||||
{0, HID_KEY_J }, /* 0x6A j */ \
|
||||
{0, HID_KEY_K }, /* 0x6B k */ \
|
||||
{0, HID_KEY_L }, /* 0x6C l */ \
|
||||
{0, HID_KEY_M }, /* 0x6D m */ \
|
||||
{0, HID_KEY_N }, /* 0x6E n */ \
|
||||
{0, HID_KEY_O }, /* 0x6F o */ \
|
||||
{0, HID_KEY_P }, /* 0x70 p */ \
|
||||
{0, HID_KEY_Q }, /* 0x71 q */ \
|
||||
{0, HID_KEY_R }, /* 0x72 r */ \
|
||||
{0, HID_KEY_S }, /* 0x73 s */ \
|
||||
{0, HID_KEY_T }, /* 0x75 t */ \
|
||||
{0, HID_KEY_U }, /* 0x75 u */ \
|
||||
{0, HID_KEY_V }, /* 0x76 v */ \
|
||||
{0, HID_KEY_W }, /* 0x77 w */ \
|
||||
{0, HID_KEY_X }, /* 0x78 x */ \
|
||||
{0, HID_KEY_Y }, /* 0x79 y */ \
|
||||
{0, HID_KEY_Z }, /* 0x7A z */ \
|
||||
{1, HID_KEY_BRACKET_LEFT }, /* 0x7B { */ \
|
||||
{1, HID_KEY_BACKSLASH }, /* 0x7C | */ \
|
||||
{1, HID_KEY_BRACKET_RIGHT }, /* 0x7D } */ \
|
||||
{1, HID_KEY_GRAVE }, /* 0x7E ~ */ \
|
||||
{0, HID_KEY_DELETE } /* 0x7F Delete */ \
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
* KEYCODE to Ascii Conversion
|
||||
* Expand to array of [128][2] (ascii without shift, ascii with shift)
|
||||
*
|
||||
* Usage: example to convert ascii from keycode (key) and shift modifier (shift).
|
||||
* Here we assume key < 128 ( printable )
|
||||
*
|
||||
* uint8_t const conv_table[128][2] = { HID_KEYCODE_TO_ASCII };
|
||||
* char ch = shift ? conv_table[chr][1] : conv_table[chr][0];
|
||||
*
|
||||
*--------------------------------------------------------------------*/
|
||||
#define HID_KEYCODE_TO_ASCII \
|
||||
{0 , 0 }, /* 0x00 */ \
|
||||
{0 , 0 }, /* 0x01 */ \
|
||||
{0 , 0 }, /* 0x02 */ \
|
||||
{0 , 0 }, /* 0x03 */ \
|
||||
{'a' , 'A' }, /* 0x04 */ \
|
||||
{'b' , 'B' }, /* 0x05 */ \
|
||||
{'c' , 'C' }, /* 0x06 */ \
|
||||
{'d' , 'D' }, /* 0x07 */ \
|
||||
{'e' , 'E' }, /* 0x08 */ \
|
||||
{'f' , 'F' }, /* 0x09 */ \
|
||||
{'g' , 'G' }, /* 0x0a */ \
|
||||
{'h' , 'H' }, /* 0x0b */ \
|
||||
{'i' , 'I' }, /* 0x0c */ \
|
||||
{'j' , 'J' }, /* 0x0d */ \
|
||||
{'k' , 'K' }, /* 0x0e */ \
|
||||
{'l' , 'L' }, /* 0x0f */ \
|
||||
{'m' , 'M' }, /* 0x10 */ \
|
||||
{'n' , 'N' }, /* 0x11 */ \
|
||||
{'o' , 'O' }, /* 0x12 */ \
|
||||
{'p' , 'P' }, /* 0x13 */ \
|
||||
{'q' , 'Q' }, /* 0x14 */ \
|
||||
{'r' , 'R' }, /* 0x15 */ \
|
||||
{'s' , 'S' }, /* 0x16 */ \
|
||||
{'t' , 'T' }, /* 0x17 */ \
|
||||
{'u' , 'U' }, /* 0x18 */ \
|
||||
{'v' , 'V' }, /* 0x19 */ \
|
||||
{'w' , 'W' }, /* 0x1a */ \
|
||||
{'x' , 'X' }, /* 0x1b */ \
|
||||
{'y' , 'Y' }, /* 0x1c */ \
|
||||
{'z' , 'Z' }, /* 0x1d */ \
|
||||
{'1' , '!' }, /* 0x1e */ \
|
||||
{'2' , '@' }, /* 0x1f */ \
|
||||
{'3' , '#' }, /* 0x20 */ \
|
||||
{'4' , '$' }, /* 0x21 */ \
|
||||
{'5' , '%' }, /* 0x22 */ \
|
||||
{'6' , '^' }, /* 0x23 */ \
|
||||
{'7' , '&' }, /* 0x24 */ \
|
||||
{'8' , '*' }, /* 0x25 */ \
|
||||
{'9' , '(' }, /* 0x26 */ \
|
||||
{'0' , ')' }, /* 0x27 */ \
|
||||
{'\r' , '\r' }, /* 0x28 */ \
|
||||
{'\x1b', '\x1b' }, /* 0x29 */ \
|
||||
{'\b' , '\b' }, /* 0x2a */ \
|
||||
{'\t' , '\t' }, /* 0x2b */ \
|
||||
{' ' , ' ' }, /* 0x2c */ \
|
||||
{'-' , '_' }, /* 0x2d */ \
|
||||
{'=' , '+' }, /* 0x2e */ \
|
||||
{'[' , '{' }, /* 0x2f */ \
|
||||
{']' , '}' }, /* 0x30 */ \
|
||||
{'\\' , '|' }, /* 0x31 */ \
|
||||
{'#' , '~' }, /* 0x32 */ \
|
||||
{';' , ':' }, /* 0x33 */ \
|
||||
{'\'' , '\"' }, /* 0x34 */ \
|
||||
{0 , 0 }, /* 0x35 */ \
|
||||
{',' , '<' }, /* 0x36 */ \
|
||||
{'.' , '>' }, /* 0x37 */ \
|
||||
{'/' , '?' }, /* 0x38 */ \
|
||||
\
|
||||
{0 , 0 }, /* 0x39 */ \
|
||||
{0 , 0 }, /* 0x3a */ \
|
||||
{0 , 0 }, /* 0x3b */ \
|
||||
{0 , 0 }, /* 0x3c */ \
|
||||
{0 , 0 }, /* 0x3d */ \
|
||||
{0 , 0 }, /* 0x3e */ \
|
||||
{0 , 0 }, /* 0x3f */ \
|
||||
{0 , 0 }, /* 0x40 */ \
|
||||
{0 , 0 }, /* 0x41 */ \
|
||||
{0 , 0 }, /* 0x42 */ \
|
||||
{0 , 0 }, /* 0x43 */ \
|
||||
{0 , 0 }, /* 0x44 */ \
|
||||
{0 , 0 }, /* 0x45 */ \
|
||||
{0 , 0 }, /* 0x46 */ \
|
||||
{0 , 0 }, /* 0x47 */ \
|
||||
{0 , 0 }, /* 0x48 */ \
|
||||
{0 , 0 }, /* 0x49 */ \
|
||||
{0 , 0 }, /* 0x4a */ \
|
||||
{0 , 0 }, /* 0x4b */ \
|
||||
{0 , 0 }, /* 0x4c */ \
|
||||
{0 , 0 }, /* 0x4d */ \
|
||||
{0 , 0 }, /* 0x4e */ \
|
||||
{0 , 0 }, /* 0x4f */ \
|
||||
{0 , 0 }, /* 0x50 */ \
|
||||
{0 , 0 }, /* 0x51 */ \
|
||||
{0 , 0 }, /* 0x52 */ \
|
||||
{0 , 0 }, /* 0x53 */ \
|
||||
\
|
||||
{'/' , '/' }, /* 0x54 */ \
|
||||
{'*' , '*' }, /* 0x55 */ \
|
||||
{'-' , '-' }, /* 0x56 */ \
|
||||
{'+' , '+' }, /* 0x57 */ \
|
||||
{'\r' , '\r' }, /* 0x58 */ \
|
||||
{'1' , 0 }, /* 0x59 */ \
|
||||
{'2' , 0 }, /* 0x5a */ \
|
||||
{'3' , 0 }, /* 0x5b */ \
|
||||
{'4' , 0 }, /* 0x5c */ \
|
||||
{'5' , '5' }, /* 0x5d */ \
|
||||
{'6' , 0 }, /* 0x5e */ \
|
||||
{'7' , 0 }, /* 0x5f */ \
|
||||
{'8' , 0 }, /* 0x60 */ \
|
||||
{'9' , 0 }, /* 0x61 */ \
|
||||
{'0' , 0 }, /* 0x62 */ \
|
||||
{'0' , 0 }, /* 0x63 */ \
|
||||
{'=' , '=' }, /* 0x67 */ \
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_HID_H__ */
|
||||
|
||||
/// @}
|
||||
@@ -1,315 +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 "tusb_option.h"
|
||||
|
||||
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_HID)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "common/tusb_common.h"
|
||||
#include "hid_device.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct
|
||||
{
|
||||
uint8_t itf_num;
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out; // optional Out endpoint
|
||||
uint8_t boot_protocol; // Boot mouse or keyboard
|
||||
bool boot_mode; // default = false (Report)
|
||||
uint8_t idle_rate; // up to application to handle idle rate
|
||||
uint16_t reprot_desc_len;
|
||||
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_HID_BUFSIZE];
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_HID_BUFSIZE];
|
||||
|
||||
}hidd_interface_t;
|
||||
|
||||
CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[CFG_TUD_HID];
|
||||
|
||||
/*------------- Helpers -------------*/
|
||||
static inline hidd_interface_t* get_interface_by_itfnum(uint8_t itf_num)
|
||||
{
|
||||
for (uint8_t i=0; i < CFG_TUD_HID; i++ )
|
||||
{
|
||||
if ( itf_num == _hidd_itf[i].itf_num ) return &_hidd_itf[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_hid_ready(void)
|
||||
{
|
||||
uint8_t itf = 0;
|
||||
uint8_t const ep_in = _hidd_itf[itf].ep_in;
|
||||
return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
|
||||
}
|
||||
|
||||
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
|
||||
{
|
||||
TU_VERIFY( tud_hid_ready() );
|
||||
|
||||
uint8_t itf = 0;
|
||||
hidd_interface_t * p_hid = &_hidd_itf[itf];
|
||||
|
||||
if (report_id)
|
||||
{
|
||||
len = tu_min8(len, CFG_TUD_HID_BUFSIZE-1);
|
||||
|
||||
p_hid->epin_buf[0] = report_id;
|
||||
memcpy(p_hid->epin_buf+1, report, len);
|
||||
len++;
|
||||
}else
|
||||
{
|
||||
// If report id = 0, skip ID field
|
||||
len = tu_min8(len, CFG_TUD_HID_BUFSIZE);
|
||||
memcpy(p_hid->epin_buf, report, len);
|
||||
}
|
||||
|
||||
return usbd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
|
||||
}
|
||||
|
||||
bool tud_hid_boot_mode(void)
|
||||
{
|
||||
uint8_t itf = 0;
|
||||
return _hidd_itf[itf].boot_mode;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
|
||||
{
|
||||
hid_keyboard_report_t report;
|
||||
|
||||
report.modifier = modifier;
|
||||
|
||||
if ( keycode )
|
||||
{
|
||||
memcpy(report.keycode, keycode, 6);
|
||||
}else
|
||||
{
|
||||
tu_memclr(report.keycode, 6);
|
||||
}
|
||||
|
||||
return tud_hid_report(report_id, &report, sizeof(report));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MOUSE APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
|
||||
{
|
||||
hid_mouse_report_t report =
|
||||
{
|
||||
.buttons = buttons,
|
||||
.x = x,
|
||||
.y = y,
|
||||
.wheel = vertical,
|
||||
.pan = horizontal
|
||||
};
|
||||
|
||||
return tud_hid_report(report_id, &report, sizeof(report));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD-CLASS API
|
||||
//--------------------------------------------------------------------+
|
||||
void hidd_init(void)
|
||||
{
|
||||
hidd_reset(TUD_OPT_RHPORT);
|
||||
}
|
||||
|
||||
void hidd_reset(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
tu_memclr(_hidd_itf, sizeof(_hidd_itf));
|
||||
}
|
||||
|
||||
bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_len)
|
||||
{
|
||||
uint8_t const *p_desc = (uint8_t const *) desc_itf;
|
||||
|
||||
// TODO support multiple HID interface
|
||||
uint8_t const itf = 0;
|
||||
hidd_interface_t * p_hid = &_hidd_itf[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;
|
||||
TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType);
|
||||
|
||||
//------------- Endpoint Descriptor -------------//
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, desc_itf->bNumEndpoints, TUSB_XFER_INTERRUPT, &p_hid->ep_out, &p_hid->ep_in));
|
||||
|
||||
if ( desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT ) p_hid->boot_protocol = desc_itf->bInterfaceProtocol;
|
||||
|
||||
p_hid->boot_mode = false; // default mode is REPORT
|
||||
p_hid->itf_num = desc_itf->bInterfaceNumber;
|
||||
p_hid->reprot_desc_len = desc_hid->wReportLength;
|
||||
|
||||
*p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
// Prepare for output endpoint
|
||||
if (p_hid->ep_out) TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle class control request
|
||||
// return false to stall control endpoint (e.g unsupported request)
|
||||
bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex );
|
||||
TU_ASSERT(p_hid);
|
||||
|
||||
if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
|
||||
{
|
||||
//------------- STD Request -------------//
|
||||
uint8_t const desc_type = tu_u16_high(p_request->wValue);
|
||||
uint8_t const desc_index = tu_u16_low (p_request->wValue);
|
||||
(void) desc_index;
|
||||
|
||||
if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
||||
{
|
||||
uint8_t const * desc_report = tud_hid_descriptor_report_cb();
|
||||
tud_control_xfer(rhport, p_request, (void*) desc_report, p_hid->reprot_desc_len);
|
||||
}else
|
||||
{
|
||||
return false; // stall unsupported request
|
||||
}
|
||||
}
|
||||
else if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS)
|
||||
{
|
||||
//------------- Class Specific Request -------------//
|
||||
switch( p_request->bRequest )
|
||||
{
|
||||
case HID_REQ_CONTROL_GET_REPORT:
|
||||
{
|
||||
// wValue = Report Type | Report ID
|
||||
uint8_t const report_type = tu_u16_high(p_request->wValue);
|
||||
uint8_t const report_id = tu_u16_low(p_request->wValue);
|
||||
|
||||
uint16_t xferlen = tud_hid_get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epin_buf, p_request->wLength);
|
||||
TU_ASSERT( xferlen > 0 );
|
||||
|
||||
tud_control_xfer(rhport, p_request, p_hid->epin_buf, xferlen);
|
||||
}
|
||||
break;
|
||||
|
||||
case HID_REQ_CONTROL_SET_REPORT:
|
||||
tud_control_xfer(rhport, p_request, p_hid->epout_buf, p_request->wLength);
|
||||
break;
|
||||
|
||||
case HID_REQ_CONTROL_SET_IDLE:
|
||||
p_hid->idle_rate = tu_u16_high(p_request->wValue);
|
||||
if ( tud_hid_set_idle_cb )
|
||||
{
|
||||
// stall request if callback return false
|
||||
if ( !tud_hid_set_idle_cb(p_hid->idle_rate) ) return false;
|
||||
}
|
||||
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
case HID_REQ_CONTROL_GET_IDLE:
|
||||
// TODO idle rate of report
|
||||
tud_control_xfer(rhport, p_request, &p_hid->idle_rate, 1);
|
||||
break;
|
||||
|
||||
case HID_REQ_CONTROL_GET_PROTOCOL:
|
||||
{
|
||||
uint8_t protocol = 1-p_hid->boot_mode; // 0 is Boot, 1 is Report protocol
|
||||
tud_control_xfer(rhport, p_request, &protocol, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case HID_REQ_CONTROL_SET_PROTOCOL:
|
||||
p_hid->boot_mode = 1 - p_request->wValue; // 0 is Boot, 1 is Report protocol
|
||||
|
||||
if (tud_hid_boot_mode_cb) tud_hid_boot_mode_cb(p_hid->boot_mode);
|
||||
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
default: return false; // stall unsupported request
|
||||
}
|
||||
}else
|
||||
{
|
||||
return false; // stall unsupported request
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Invoked when class request DATA stage is finished.
|
||||
// return false to stall control endpoint (e.g Host send non-sense DATA)
|
||||
bool hidd_control_complete(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
(void) rhport;
|
||||
hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex );
|
||||
TU_ASSERT(p_hid);
|
||||
|
||||
if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
|
||||
p_request->bRequest == HID_REQ_CONTROL_SET_REPORT)
|
||||
{
|
||||
// wValue = Report Type | Report ID
|
||||
uint8_t const report_type = tu_u16_high(p_request->wValue);
|
||||
uint8_t const report_id = tu_u16_low(p_request->wValue);
|
||||
|
||||
tud_hid_set_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epout_buf, p_request->wLength);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
||||
{
|
||||
(void) result;
|
||||
|
||||
// TODO support multiple HID interface
|
||||
uint8_t const itf = 0;
|
||||
hidd_interface_t * p_hid = &_hidd_itf[itf];
|
||||
|
||||
if (ep_addr == p_hid->ep_out)
|
||||
{
|
||||
tud_hid_set_report_cb(0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes);
|
||||
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,315 +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.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_HID_DEVICE_H_
|
||||
#define _TUSB_HID_DEVICE_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/usbd.h"
|
||||
#include "hid.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Driver Default Configure & Validation
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#ifndef CFG_TUD_HID_BUFSIZE
|
||||
#define CFG_TUD_HID_BUFSIZE 16
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Check if the interface is ready to use
|
||||
bool tud_hid_ready(void);
|
||||
|
||||
// Check if current mode is Boot (true) or Report (false)
|
||||
bool tud_hid_boot_mode(void);
|
||||
|
||||
// Send report to host
|
||||
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len);
|
||||
|
||||
// KEYBOARD: convenient helper to send keyboard report if application
|
||||
// use template layout report as defined by hid_keyboard_report_t
|
||||
bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
|
||||
|
||||
// MOUSE: convenient helper to send mouse report if application
|
||||
// use template layout report as defined by hid_mouse_report_t
|
||||
bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Callbacks (Weak is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when received GET HID REPORT DESCRIPTOR request
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||
TU_ATTR_WEAK uint8_t const * tud_hid_descriptor_report_cb(void);
|
||||
|
||||
// Invoked when received GET_REPORT control request
|
||||
// Application must fill buffer report's content and return its length.
|
||||
// Return zero will cause the stack to STALL request
|
||||
TU_ATTR_WEAK uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
|
||||
|
||||
// Invoked when received SET_REPORT control request or
|
||||
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
|
||||
TU_ATTR_WEAK void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
|
||||
|
||||
// Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report )
|
||||
TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
|
||||
|
||||
// Invoked when received SET_IDLE request. return false will stall the request
|
||||
// - Idle Rate = 0 : only send report if there is changes, i.e skip duplication
|
||||
// - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
|
||||
TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
|
||||
|
||||
/* --------------------------------------------------------------------+
|
||||
* HID Report Descriptor Template
|
||||
*
|
||||
* Convenient for declaring popular HID device (keyboard, mouse, consumer,
|
||||
* gamepad etc...). Templates take "HID_REPORT_ID(n)," as input, leave
|
||||
* empty if multiple reports is not used
|
||||
*
|
||||
* - Only 1 report: no parameter
|
||||
* uint8_t const report_desc[] = { TUD_HID_REPORT_DESC_KEYBOARD() };
|
||||
*
|
||||
* - Multiple Reports: "HID_REPORT_ID(ID)," must be passed to template
|
||||
* uint8_t const report_desc[] =
|
||||
* {
|
||||
* TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(1), ) ,
|
||||
* TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(2), )
|
||||
* };
|
||||
*--------------------------------------------------------------------*/
|
||||
|
||||
// Keyboard Report Descriptor Template
|
||||
#define TUD_HID_REPORT_DESC_KEYBOARD(...) \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ) ,\
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
|
||||
/* Report ID if any */\
|
||||
__VA_ARGS__ \
|
||||
/* 8 bits Modifier Keys (Shfit, Control, Alt) */ \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ) ,\
|
||||
HID_USAGE_MIN ( 224 ) ,\
|
||||
HID_USAGE_MAX ( 231 ) ,\
|
||||
HID_LOGICAL_MIN ( 0 ) ,\
|
||||
HID_LOGICAL_MAX ( 1 ) ,\
|
||||
HID_REPORT_COUNT ( 8 ) ,\
|
||||
HID_REPORT_SIZE ( 1 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
|
||||
/* 8 bit reserved */ \
|
||||
HID_REPORT_COUNT ( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 8 ) ,\
|
||||
HID_INPUT ( HID_CONSTANT ) ,\
|
||||
/* 6-byte Keycodes */ \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ) ,\
|
||||
HID_USAGE_MIN ( 0 ) ,\
|
||||
HID_USAGE_MAX ( 255 ) ,\
|
||||
HID_LOGICAL_MIN ( 0 ) ,\
|
||||
HID_LOGICAL_MAX ( 255 ) ,\
|
||||
HID_REPORT_COUNT ( 6 ) ,\
|
||||
HID_REPORT_SIZE ( 8 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
|
||||
/* 5-bit LED Indicator Kana | Compose | ScrollLock | CapsLock | NumLock */ \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ) ,\
|
||||
HID_USAGE_MIN ( 1 ) ,\
|
||||
HID_USAGE_MAX ( 5 ) ,\
|
||||
HID_REPORT_COUNT ( 5 ) ,\
|
||||
HID_REPORT_SIZE ( 1 ) ,\
|
||||
HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
|
||||
/* led padding */ \
|
||||
HID_REPORT_COUNT ( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 3 ) ,\
|
||||
HID_OUTPUT ( HID_CONSTANT ) ,\
|
||||
HID_COLLECTION_END \
|
||||
|
||||
// Mouse Report Descriptor Template
|
||||
#define TUD_HID_REPORT_DESC_MOUSE(...) \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
|
||||
/* Report ID if any */\
|
||||
__VA_ARGS__ \
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_POINTER ) ,\
|
||||
HID_COLLECTION ( HID_COLLECTION_PHYSICAL ) ,\
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
|
||||
HID_USAGE_MIN ( 1 ) ,\
|
||||
HID_USAGE_MAX ( 5 ) ,\
|
||||
HID_LOGICAL_MIN ( 0 ) ,\
|
||||
HID_LOGICAL_MAX ( 1 ) ,\
|
||||
/* Left, Right, Middle, Backward, Forward buttons */ \
|
||||
HID_REPORT_COUNT( 5 ) ,\
|
||||
HID_REPORT_SIZE ( 1 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
|
||||
/* 3 bit padding */ \
|
||||
HID_REPORT_COUNT( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 3 ) ,\
|
||||
HID_INPUT ( HID_CONSTANT ) ,\
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
/* X, Y position [-127, 127] */ \
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
|
||||
HID_LOGICAL_MIN ( 0x81 ) ,\
|
||||
HID_LOGICAL_MAX ( 0x7f ) ,\
|
||||
HID_REPORT_COUNT( 2 ) ,\
|
||||
HID_REPORT_SIZE ( 8 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
|
||||
/* Verital wheel scroll [-127, 127] */ \
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ) ,\
|
||||
HID_LOGICAL_MIN ( 0x81 ) ,\
|
||||
HID_LOGICAL_MAX ( 0x7f ) ,\
|
||||
HID_REPORT_COUNT( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 8 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ), \
|
||||
/* Horizontal wheel scroll [-127, 127] */ \
|
||||
HID_USAGE_N ( HID_USAGE_CONSUMER_AC_PAN, 2 ), \
|
||||
HID_LOGICAL_MIN ( 0x81 ), \
|
||||
HID_LOGICAL_MAX ( 0x7f ), \
|
||||
HID_REPORT_COUNT( 1 ), \
|
||||
HID_REPORT_SIZE ( 8 ), \
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), \
|
||||
HID_COLLECTION_END , \
|
||||
HID_COLLECTION_END \
|
||||
|
||||
// Consumer Control Report Descriptor Template
|
||||
#define TUD_HID_REPORT_DESC_CONSUMER(...) \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ) ,\
|
||||
HID_USAGE ( HID_USAGE_CONSUMER_CONTROL ) ,\
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
|
||||
/* Report ID if any */\
|
||||
__VA_ARGS__ \
|
||||
HID_LOGICAL_MIN ( 0x00 ) ,\
|
||||
HID_LOGICAL_MAX_N( 0x03FF, 2 ) ,\
|
||||
HID_USAGE_MIN ( 0x00 ) ,\
|
||||
HID_USAGE_MAX_N ( 0x03FF, 2 ) ,\
|
||||
HID_REPORT_COUNT ( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 16 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
|
||||
HID_COLLECTION_END \
|
||||
|
||||
/* System Control Report Descriptor Template
|
||||
* 0x00 - do nothing
|
||||
* 0x01 - Power Off
|
||||
* 0x02 - Standby
|
||||
* 0x04 - Wake Host
|
||||
*/
|
||||
#define TUD_HID_REPORT_DESC_SYSTEM_CONTROL(...) \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_CONTROL ) ,\
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
|
||||
/* Report ID if any */\
|
||||
__VA_ARGS__ \
|
||||
/* 2 bit system power control */ \
|
||||
HID_LOGICAL_MIN ( 1 ) ,\
|
||||
HID_LOGICAL_MAX ( 3 ) ,\
|
||||
HID_REPORT_COUNT ( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 2 ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_SLEEP ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_POWER_DOWN ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_WAKE_UP ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
|
||||
/* 6 bit padding */ \
|
||||
HID_REPORT_COUNT ( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 6 ) ,\
|
||||
HID_INPUT ( HID_CONSTANT ) ,\
|
||||
HID_COLLECTION_END \
|
||||
|
||||
// Gamepad Report Descriptor Template
|
||||
// with 16 buttons and 2 joysticks with following layout
|
||||
// | Button Map (2 bytes) | X | Y | Z | Rz
|
||||
#define TUD_HID_REPORT_DESC_GAMEPAD(...) \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_GAMEPAD ) ,\
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
|
||||
/* Report ID if any */\
|
||||
__VA_ARGS__ \
|
||||
/* 16 bit Button Map */ \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
|
||||
HID_USAGE_MIN ( 1 ) ,\
|
||||
HID_USAGE_MAX ( 16 ) ,\
|
||||
HID_LOGICAL_MIN ( 0 ) ,\
|
||||
HID_LOGICAL_MAX ( 1 ) ,\
|
||||
HID_REPORT_COUNT ( 16 ) ,\
|
||||
HID_REPORT_SIZE ( 1 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
|
||||
/* X, Y, Z, Rz (min -127, max 127 ) */ \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
HID_LOGICAL_MIN ( 0x81 ) ,\
|
||||
HID_LOGICAL_MAX ( 0x7f ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_Z ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_RZ ) ,\
|
||||
HID_REPORT_COUNT ( 4 ) ,\
|
||||
HID_REPORT_SIZE ( 8 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
|
||||
HID_COLLECTION_END \
|
||||
|
||||
// HID Generic Input & Output
|
||||
// - 1st parameter is report size (mandatory)
|
||||
// - 2nd parameter is report id HID_REPORT_ID(n) (optional)
|
||||
#define TUD_HID_REPORT_DESC_GENERIC_INOUT(report_size, ...) \
|
||||
HID_USAGE_PAGE_N ( HID_USAGE_PAGE_VENDOR, 2 ),\
|
||||
HID_USAGE ( 0x01 ),\
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),\
|
||||
/* Report ID if any */\
|
||||
__VA_ARGS__ \
|
||||
/* Input */ \
|
||||
HID_USAGE ( 0x02 ),\
|
||||
HID_LOGICAL_MIN ( 0x00 ),\
|
||||
HID_LOGICAL_MAX ( 0xff ),\
|
||||
HID_REPORT_SIZE ( 8 ),\
|
||||
HID_REPORT_COUNT( report_size ),\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\
|
||||
/* Output */ \
|
||||
HID_USAGE ( 0x03 ),\
|
||||
HID_LOGICAL_MIN ( 0x00 ),\
|
||||
HID_LOGICAL_MAX ( 0xff ),\
|
||||
HID_REPORT_SIZE ( 8 ),\
|
||||
HID_REPORT_COUNT( report_size ),\
|
||||
HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\
|
||||
HID_COLLECTION_END \
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal Class Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
void hidd_init (void);
|
||||
void hidd_reset (uint8_t rhport);
|
||||
bool hidd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
|
||||
bool hidd_control_request (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool hidd_control_complete (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool hidd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_HID_DEVICE_H_ */
|
||||
|
||||
@@ -1,167 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup group_class
|
||||
* \defgroup ClassDriver_CDC Communication Device Class (CDC)
|
||||
* Currently only Abstract Control Model subclass is supported
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_MIDI_H__
|
||||
#define _TUSB_MIDI_H__
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Specific Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MIDI_CS_INTERFACE_HEADER = 0x01,
|
||||
MIDI_CS_INTERFACE_IN_JACK = 0x02,
|
||||
MIDI_CS_INTERFACE_OUT_JACK = 0x03,
|
||||
MIDI_CS_INTERFACE_ELEMENT = 0x04,
|
||||
} midi_cs_interface_subtype_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MIDI_CS_ENDPOINT_GENERAL = 0x01
|
||||
} midi_cs_endpoint_subtype_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MIDI_JACK_EMBEDDED = 0x01,
|
||||
MIDI_JACK_EXTERNAL = 0x02
|
||||
} midi_jack_type_t;
|
||||
|
||||
/// MIDI Interface Header Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType
|
||||
uint16_t bcdMSC ; ///< MidiStreaming SubClass release number in Binary-Coded Decimal
|
||||
uint16_t wTotalLength ;
|
||||
} midi_desc_header_t;
|
||||
|
||||
/// MIDI In Jack Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType
|
||||
uint8_t bJackType ; ///< Embedded or External
|
||||
uint8_t bJackID ; ///< Unique ID for MIDI IN Jack
|
||||
uint8_t iJack ; ///< string descriptor
|
||||
} midi_desc_in_jack_t;
|
||||
|
||||
|
||||
/// MIDI Out Jack Descriptor with single pin
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType
|
||||
uint8_t bJackType ; ///< Embedded or External
|
||||
uint8_t bJackID ; ///< Unique ID for MIDI IN Jack
|
||||
uint8_t bNrInputPins;
|
||||
|
||||
uint8_t baSourceID;
|
||||
uint8_t baSourcePin;
|
||||
|
||||
uint8_t iJack ; ///< string descriptor
|
||||
} midi_desc_out_jack_t ;
|
||||
|
||||
/// MIDI Out Jack Descriptor with multiple pins
|
||||
#define midi_desc_out_jack_n_t(input_num) \
|
||||
struct TU_ATTR_PACKED { \
|
||||
uint8_t bLength ; \
|
||||
uint8_t bDescriptorType ; \
|
||||
uint8_t bDescriptorSubType ; \
|
||||
uint8_t bJackType ; \
|
||||
uint8_t bJackID ; \
|
||||
uint8_t bNrInputPins ; \
|
||||
struct TU_ATTR_PACKED { \
|
||||
uint8_t baSourceID; \
|
||||
uint8_t baSourcePin; \
|
||||
} pins[input_num]; \
|
||||
uint8_t iJack ; \
|
||||
}
|
||||
|
||||
/// MIDI Element Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
|
||||
uint8_t bDescriptorSubType ; ///< Descriptor SubType
|
||||
uint8_t bElementID;
|
||||
|
||||
uint8_t bNrInputPins;
|
||||
uint8_t baSourceID;
|
||||
uint8_t baSourcePin;
|
||||
|
||||
uint8_t bNrOutputPins;
|
||||
uint8_t bInTerminalLink;
|
||||
uint8_t bOutTerminalLink;
|
||||
uint8_t bElCapsSize;
|
||||
|
||||
uint16_t bmElementCaps;
|
||||
uint8_t iElement;
|
||||
} midi_desc_element_t;
|
||||
|
||||
/// MIDI Element Descriptor with multiple pins
|
||||
#define midi_desc_element_n_t(input_num) \
|
||||
struct TU_ATTR_PACKED { \
|
||||
uint8_t bLength; \
|
||||
uint8_t bDescriptorType; \
|
||||
uint8_t bDescriptorSubType; \
|
||||
uint8_t bElementID; \
|
||||
uint8_t bNrInputPins; \
|
||||
struct TU_ATTR_PACKED { \
|
||||
uint8_t baSourceID; \
|
||||
uint8_t baSourcePin; \
|
||||
} pins[input_num]; \
|
||||
uint8_t bNrOutputPins; \
|
||||
uint8_t bInTerminalLink; \
|
||||
uint8_t bOutTerminalLink; \
|
||||
uint8_t bElCapsSize; \
|
||||
uint16_t bmElementCaps; \
|
||||
uint8_t iElement; \
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
@@ -1,342 +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 "tusb_option.h"
|
||||
|
||||
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_MIDI)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "midi_device.h"
|
||||
#include "class/audio/audio.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct
|
||||
{
|
||||
uint8_t itf_num;
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out;
|
||||
|
||||
/*------------- From this point, data is not cleared by bus reset -------------*/
|
||||
// FIFO
|
||||
tu_fifo_t rx_ff;
|
||||
tu_fifo_t tx_ff;
|
||||
uint8_t rx_ff_buf[CFG_TUD_MIDI_RX_BUFSIZE];
|
||||
uint8_t tx_ff_buf[CFG_TUD_MIDI_TX_BUFSIZE];
|
||||
|
||||
#if CFG_FIFO_MUTEX
|
||||
osal_mutex_def_t rx_ff_mutex;
|
||||
osal_mutex_def_t tx_ff_mutex;
|
||||
#endif
|
||||
|
||||
// We need to pack messages into words before queueing their transmission so buffer across write
|
||||
// calls.
|
||||
uint8_t message_buffer[4];
|
||||
uint8_t message_buffer_length;
|
||||
uint8_t message_target_length;
|
||||
|
||||
// Endpoint Transfer buffer
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_MIDI_EPSIZE];
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_MIDI_EPSIZE];
|
||||
|
||||
} midid_interface_t;
|
||||
|
||||
#define ITF_MEM_RESET_SIZE offsetof(midid_interface_t, rx_ff)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
CFG_TUSB_MEM_SECTION midid_interface_t _midid_itf[CFG_TUD_MIDI];
|
||||
|
||||
bool tud_midi_n_mounted (uint8_t itf)
|
||||
{
|
||||
midid_interface_t* midi = &_midid_itf[itf];
|
||||
return midi->ep_in && midi->ep_out;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// READ API
|
||||
//--------------------------------------------------------------------+
|
||||
uint32_t tud_midi_n_available(uint8_t itf, uint8_t jack_id)
|
||||
{
|
||||
return tu_fifo_count(&_midid_itf[itf].rx_ff);
|
||||
}
|
||||
|
||||
uint32_t tud_midi_n_read(uint8_t itf, uint8_t jack_id, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
return tu_fifo_read_n(&_midid_itf[itf].rx_ff, buffer, bufsize);
|
||||
}
|
||||
|
||||
void tud_midi_n_read_flush (uint8_t itf, uint8_t jack_id)
|
||||
{
|
||||
tu_fifo_clear(&_midid_itf[itf].rx_ff);
|
||||
}
|
||||
|
||||
void midi_rx_done_cb(midid_interface_t* midi, uint8_t const* buffer, uint32_t bufsize) {
|
||||
if (bufsize % 4 != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(uint32_t i=0; i<bufsize; i += 4) {
|
||||
uint8_t header = buffer[i];
|
||||
// uint8_t cable_number = (header & 0xf0) >> 4;
|
||||
uint8_t code_index = header & 0x0f;
|
||||
// We always copy over the first byte.
|
||||
uint8_t count = 1;
|
||||
// Ignore subsequent bytes based on the code.
|
||||
if (code_index != 0x5 && code_index != 0xf) {
|
||||
count = 2;
|
||||
if (code_index != 0x2 && code_index != 0x6 && code_index != 0xc && code_index != 0xd) {
|
||||
count = 3;
|
||||
}
|
||||
}
|
||||
tu_fifo_write_n(&midi->rx_ff, &buffer[i + 1], count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// WRITE API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static bool maybe_transmit(midid_interface_t* midi, uint8_t itf_index)
|
||||
{
|
||||
// skip if previous transfer not complete
|
||||
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, midi->ep_in) );
|
||||
|
||||
uint16_t count = tu_fifo_read_n(&midi->tx_ff, midi->epin_buf, CFG_TUD_MIDI_EPSIZE);
|
||||
if (count > 0)
|
||||
{
|
||||
TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, midi->ep_in, midi->epin_buf, count) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t tud_midi_n_write(uint8_t itf, uint8_t jack_id, uint8_t const* buffer, uint32_t bufsize)
|
||||
{
|
||||
midid_interface_t* midi = &_midid_itf[itf];
|
||||
if (midi->itf_num == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t i = 0;
|
||||
while (i < bufsize) {
|
||||
uint8_t data = buffer[i];
|
||||
if (midi->message_buffer_length == 0) {
|
||||
uint8_t msg = data >> 4;
|
||||
midi->message_buffer[1] = data;
|
||||
midi->message_buffer_length = 2;
|
||||
// Check to see if we're still in a SysEx transmit.
|
||||
if (midi->message_buffer[0] == 0x4) {
|
||||
if (data == 0xf7) {
|
||||
midi->message_buffer[0] = 0x5;
|
||||
} else {
|
||||
midi->message_buffer_length = 4;
|
||||
}
|
||||
} else if ((msg >= 0x8 && msg <= 0xB) || msg == 0xE) {
|
||||
midi->message_buffer[0] = jack_id << 4 | msg;
|
||||
midi->message_target_length = 4;
|
||||
} else if (msg == 0xf) {
|
||||
if (data == 0xf0) {
|
||||
midi->message_buffer[0] = 0x4;
|
||||
midi->message_target_length = 4;
|
||||
} else if (data == 0xf1 || data == 0xf3) {
|
||||
midi->message_buffer[0] = 0x2;
|
||||
midi->message_target_length = 3;
|
||||
} else if (data == 0xf2) {
|
||||
midi->message_buffer[0] = 0x3;
|
||||
midi->message_target_length = 4;
|
||||
} else {
|
||||
midi->message_buffer[0] = 0x5;
|
||||
midi->message_target_length = 2;
|
||||
}
|
||||
} else {
|
||||
// Pack individual bytes if we don't support packing them into words.
|
||||
midi->message_buffer[0] = jack_id << 4 | 0xf;
|
||||
midi->message_buffer[2] = 0;
|
||||
midi->message_buffer[3] = 0;
|
||||
midi->message_buffer_length = 2;
|
||||
midi->message_target_length = 2;
|
||||
}
|
||||
} else {
|
||||
midi->message_buffer[midi->message_buffer_length] = data;
|
||||
midi->message_buffer_length += 1;
|
||||
// See if this byte ends a SysEx.
|
||||
if (midi->message_buffer[0] == 0x4 && data == 0xf7) {
|
||||
midi->message_buffer[0] = 0x4 + (midi->message_buffer_length - 1);
|
||||
midi->message_target_length = midi->message_buffer_length;
|
||||
}
|
||||
}
|
||||
|
||||
if (midi->message_buffer_length == midi->message_target_length) {
|
||||
uint16_t written = tu_fifo_write_n(&midi->tx_ff, midi->message_buffer, 4);
|
||||
if (written < 4) {
|
||||
TU_ASSERT( written == 0 );
|
||||
break;
|
||||
}
|
||||
midi->message_buffer_length = 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
maybe_transmit(midi, itf);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
void midid_init(void)
|
||||
{
|
||||
tu_memclr(_midid_itf, sizeof(_midid_itf));
|
||||
|
||||
for(uint8_t i=0; i<CFG_TUD_MIDI; i++)
|
||||
{
|
||||
midid_interface_t* midi = &_midid_itf[i];
|
||||
|
||||
// config fifo
|
||||
tu_fifo_config(&midi->rx_ff, midi->rx_ff_buf, CFG_TUD_MIDI_RX_BUFSIZE, 1, true);
|
||||
tu_fifo_config(&midi->tx_ff, midi->tx_ff_buf, CFG_TUD_MIDI_TX_BUFSIZE, 1, true);
|
||||
|
||||
#if CFG_FIFO_MUTEX
|
||||
tu_fifo_config_mutex(&midi->rx_ff, osal_mutex_create(&midi->rx_ff_mutex));
|
||||
tu_fifo_config_mutex(&midi->tx_ff, osal_mutex_create(&midi->tx_ff_mutex));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void midid_reset(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
for(uint8_t i=0; i<CFG_TUD_MIDI; i++)
|
||||
{
|
||||
midid_interface_t* midi = &_midid_itf[i];
|
||||
tu_memclr(midi, ITF_MEM_RESET_SIZE);
|
||||
tu_fifo_clear(&midi->rx_ff);
|
||||
tu_fifo_clear(&midi->tx_ff);
|
||||
}
|
||||
}
|
||||
|
||||
bool midid_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length)
|
||||
{
|
||||
// For now handle the audio control interface as well.
|
||||
if ( AUDIO_SUBCLASS_CONTROL == p_interface_desc->bInterfaceSubClass) {
|
||||
uint8_t const * p_desc = tu_desc_next ( (uint8_t const *) p_interface_desc );
|
||||
(*p_length) = sizeof(tusb_desc_interface_t);
|
||||
|
||||
// Skip over the class specific descriptor.
|
||||
(*p_length) += tu_desc_len(p_desc);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
return true;
|
||||
}
|
||||
|
||||
TU_VERIFY(AUDIO_SUBCLASS_MIDI_STREAMING == p_interface_desc->bInterfaceSubClass &&
|
||||
AUDIO_PROTOCOL_V1 == p_interface_desc->bInterfaceProtocol );
|
||||
|
||||
// Find available interface
|
||||
midid_interface_t * p_midi = NULL;
|
||||
for(uint8_t i=0; i<CFG_TUD_MIDI; i++)
|
||||
{
|
||||
if ( _midid_itf[i].ep_in == 0 && _midid_itf[i].ep_out == 0 )
|
||||
{
|
||||
p_midi = &_midid_itf[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
p_midi->itf_num = p_interface_desc->bInterfaceNumber;
|
||||
|
||||
uint8_t const * p_desc = tu_desc_next( (uint8_t const *) p_interface_desc );
|
||||
(*p_length) = sizeof(tusb_desc_interface_t);
|
||||
|
||||
uint8_t found_endpoints = 0;
|
||||
while (found_endpoints < p_interface_desc->bNumEndpoints)
|
||||
{
|
||||
if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE])
|
||||
{
|
||||
TU_ASSERT( dcd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc), false);
|
||||
uint8_t ep_addr = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
|
||||
if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) {
|
||||
p_midi->ep_in = ep_addr;
|
||||
} else {
|
||||
p_midi->ep_out = ep_addr;
|
||||
}
|
||||
|
||||
(*p_length) += p_desc[DESC_OFFSET_LEN];
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
found_endpoints += 1;
|
||||
}
|
||||
(*p_length) += p_desc[DESC_OFFSET_LEN];
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
|
||||
// Prepare for incoming data
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EPSIZE), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool midid_control_complete(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool midid_control_request(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
//------------- Class Specific Request -------------//
|
||||
if (p_request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS) return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
||||
{
|
||||
// TODO Support multiple interfaces
|
||||
uint8_t const itf = 0;
|
||||
midid_interface_t* p_midi = &_midid_itf[itf];
|
||||
|
||||
// receive new data
|
||||
if ( ep_addr == p_midi->ep_out )
|
||||
{
|
||||
midi_rx_done_cb(p_midi, p_midi->epout_buf, xferred_bytes);
|
||||
|
||||
// prepare for next
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EPSIZE), false );
|
||||
} else if ( ep_addr == p_midi->ep_in ) {
|
||||
maybe_transmit(p_midi, itf);
|
||||
}
|
||||
|
||||
// nothing to do with in and notif endpoint
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,138 +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.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_MIDI_DEVICE_H_
|
||||
#define _TUSB_MIDI_DEVICE_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/usbd.h"
|
||||
|
||||
#include "class/audio/audio.h"
|
||||
#include "midi.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Driver Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
#ifndef CFG_TUD_MIDI_EPSIZE
|
||||
#define CFG_TUD_MIDI_EPSIZE 64
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \addtogroup MIDI_Serial Serial
|
||||
* @{
|
||||
* \defgroup MIDI_Serial_Device Device
|
||||
* @{ */
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Multiple Interfaces)
|
||||
// CFG_TUD_MIDI > 1
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_midi_n_mounted (uint8_t itf);
|
||||
uint32_t tud_midi_n_available (uint8_t itf, uint8_t jack_id);
|
||||
uint32_t tud_midi_n_read (uint8_t itf, uint8_t jack_id, void* buffer, uint32_t bufsize);
|
||||
void tud_midi_n_read_flush (uint8_t itf, uint8_t jack_id);
|
||||
uint32_t tud_midi_n_write (uint8_t itf, uint8_t jack_id, uint8_t const* buffer, uint32_t bufsize);
|
||||
|
||||
static inline
|
||||
uint32_t tud_midi_n_write24 (uint8_t itf, uint8_t jack_id, uint8_t b1, uint8_t b2, uint8_t b3);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Interface0)
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool tud_midi_mounted (void);
|
||||
static inline uint32_t tud_midi_available (void);
|
||||
static inline uint32_t tud_midi_read (void* buffer, uint32_t bufsize);
|
||||
static inline void tud_midi_read_flush (void);
|
||||
static inline uint32_t tud_midi_write (uint8_t jack_id, uint8_t const* buffer, uint32_t bufsize);
|
||||
static inline uint32_t tudi_midi_write24 (uint8_t jack_id, uint8_t b1, uint8_t b2, uint8_t b3);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application Callback API (weak is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
TU_ATTR_WEAK void tud_midi_rx_cb(uint8_t itf);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Inline Functions
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static inline uint32_t tud_midi_n_write24 (uint8_t itf, uint8_t jack_id, uint8_t b1, uint8_t b2, uint8_t b3)
|
||||
{
|
||||
uint8_t msg[3] = { b1, b2, b3 };
|
||||
return tud_midi_n_write(itf, jack_id, msg, 3);
|
||||
}
|
||||
|
||||
static inline bool tud_midi_mounted (void)
|
||||
{
|
||||
return tud_midi_n_mounted(0);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_midi_available (void)
|
||||
{
|
||||
return tud_midi_n_available(0, 0);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_midi_read (void* buffer, uint32_t bufsize)
|
||||
{
|
||||
return tud_midi_n_read(0, 0, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline void tud_midi_read_flush (void)
|
||||
{
|
||||
tud_midi_n_read_flush(0, 0);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_midi_write (uint8_t jack_id, uint8_t const* buffer, uint32_t bufsize)
|
||||
{
|
||||
return tud_midi_n_write(0, jack_id, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline uint32_t tudi_midi_write24 (uint8_t jack_id, uint8_t b1, uint8_t b2, uint8_t b3)
|
||||
{
|
||||
uint8_t msg[3] = { b1, b2, b3 };
|
||||
return tud_midi_write(jack_id, msg, 3);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal Class Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
void midid_init (void);
|
||||
void midid_reset (uint8_t rhport);
|
||||
bool midid_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
|
||||
bool midid_control_request (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool midid_control_complete (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool midid_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_MIDI_DEVICE_H_ */
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
@@ -1,392 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup group_class
|
||||
* \defgroup ClassDriver_MSC MassStorage (MSC)
|
||||
* @{ */
|
||||
|
||||
/** \defgroup ClassDriver_MSC_Common Common Definitions
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_MSC_H_
|
||||
#define _TUSB_MSC_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Mass Storage Class Constant
|
||||
//--------------------------------------------------------------------+
|
||||
/// MassStorage Subclass
|
||||
typedef enum
|
||||
{
|
||||
MSC_SUBCLASS_RBC = 1 , ///< Reduced Block Commands (RBC) T10 Project 1240-D
|
||||
MSC_SUBCLASS_SFF_MMC , ///< SFF-8020i, MMC-2 (ATAPI). Typically used by a CD/DVD device
|
||||
MSC_SUBCLASS_QIC , ///< QIC-157. Typically used by a tape device
|
||||
MSC_SUBCLASS_UFI , ///< UFI. Typically used by Floppy Disk Drive (FDD) device
|
||||
MSC_SUBCLASS_SFF , ///< SFF-8070i. Can be used by Floppy Disk Drive (FDD) device
|
||||
MSC_SUBCLASS_SCSI ///< SCSI transparent command set
|
||||
}msc_subclass_type_t;
|
||||
|
||||
enum {
|
||||
MSC_CBW_SIGNATURE = 0x43425355, ///< Constant value of 43425355h (little endian)
|
||||
MSC_CSW_SIGNATURE = 0x53425355 ///< Constant value of 53425355h (little endian)
|
||||
};
|
||||
|
||||
/// \brief MassStorage Protocol.
|
||||
/// \details CBI only approved to use with full-speed floopy disk & should not used with highspeed or device other than floopy
|
||||
typedef enum
|
||||
{
|
||||
MSC_PROTOCOL_CBI = 0 , ///< Control/Bulk/Interrupt protocol (with command completion interrupt)
|
||||
MSC_PROTOCOL_CBI_NO_INTERRUPT = 1 , ///< Control/Bulk/Interrupt protocol (without command completion interrupt)
|
||||
MSC_PROTOCOL_BOT = 0x50 ///< Bulk-Only Transport
|
||||
}msc_protocol_type_t;
|
||||
|
||||
/// MassStorage Class-Specific Control Request
|
||||
typedef enum
|
||||
{
|
||||
MSC_REQ_GET_MAX_LUN = 254, ///< The Get Max LUN device request is used to determine the number of logical units supported by the device. Logical Unit Numbers on the device shall be numbered contiguously starting from LUN 0 to a maximum LUN of 15
|
||||
MSC_REQ_RESET = 255 ///< This request is used to reset the mass storage device and its associated interface. This class-specific request shall ready the device for the next CBW from the host.
|
||||
}msc_request_type_t;
|
||||
|
||||
/// \brief Command Block Status Values
|
||||
/// \details Indicates the success or failure of the command. The device shall set this byte to zero if the command completed
|
||||
/// successfully. A non-zero value shall indicate a failure during command execution according to the following
|
||||
typedef enum
|
||||
{
|
||||
MSC_CSW_STATUS_PASSED = 0 , ///< MSC_CSW_STATUS_PASSED
|
||||
MSC_CSW_STATUS_FAILED , ///< MSC_CSW_STATUS_FAILED
|
||||
MSC_CSW_STATUS_PHASE_ERROR ///< MSC_CSW_STATUS_PHASE_ERROR
|
||||
}msc_csw_status_t;
|
||||
|
||||
/// Command Block Wrapper
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint32_t signature; ///< Signature that helps identify this data packet as a CBW. The signature field shall contain the value 43425355h (little endian), indicating a CBW.
|
||||
uint32_t tag; ///< Tag sent by the host. The device shall echo the contents of this field back to the host in the dCSWTagfield of the associated CSW. The dCSWTagpositively associates a CSW with the corresponding CBW.
|
||||
uint32_t total_bytes; ///< The number of bytes of data that the host expects to transfer on the Bulk-In or Bulk-Out endpoint (as indicated by the Direction bit) during the execution of this command. If this field is zero, the device and the host shall transfer no data between the CBW and the associated CSW, and the device shall ignore the value of the Direction bit in bmCBWFlags.
|
||||
uint8_t dir; ///< Bit 7 of this field define transfer direction \n - 0 : Data-Out from host to the device. \n - 1 : Data-In from the device to the host.
|
||||
uint8_t lun; ///< The device Logical Unit Number (LUN) to which the command block is being sent. For devices that support multiple LUNs, the host shall place into this field the LUN to which this command block is addressed. Otherwise, the host shall set this field to zero.
|
||||
uint8_t cmd_len; ///< The valid length of the CBWCBin bytes. This defines the valid length of the command block. The only legal values are 1 through 16
|
||||
uint8_t command[16]; ///< The command block to be executed by the device. The device shall interpret the first cmd_len bytes in this field as a command block
|
||||
}msc_cbw_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(msc_cbw_t) == 31, "size is not correct");
|
||||
|
||||
/// Command Status Wrapper
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint32_t signature ; ///< Signature that helps identify this data packet as a CSW. The signature field shall contain the value 53425355h (little endian), indicating CSW.
|
||||
uint32_t tag ; ///< The device shall set this field to the value received in the dCBWTag of the associated CBW.
|
||||
uint32_t data_residue ; ///< For Data-Out the device shall report in the dCSWDataResiduethe difference between the amount of data expected as stated in the dCBWDataTransferLength, and the actual amount of data processed by the device. For Data-In the device shall report in the dCSWDataResiduethe difference between the amount of data expected as stated in the dCBWDataTransferLengthand the actual amount of relevant data sent by the device
|
||||
uint8_t status ; ///< indicates the success or failure of the command. Values from \ref msc_csw_status_t
|
||||
}msc_csw_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(msc_csw_t) == 13, "size is not correct");
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// SCSI Constant
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// SCSI Command Operation Code
|
||||
typedef enum
|
||||
{
|
||||
SCSI_CMD_TEST_UNIT_READY = 0x00, ///< The SCSI Test Unit Ready command is used to determine if a device is ready to transfer data (read/write), i.e. if a disk has spun up, if a tape is loaded and ready etc. The device does not perform a self-test operation.
|
||||
SCSI_CMD_INQUIRY = 0x12, ///< The SCSI Inquiry command is used to obtain basic information from a target device.
|
||||
SCSI_CMD_MODE_SELECT_6 = 0x15, ///< provides a means for the application client to specify medium, logical unit, or peripheral device parameters to the device server. Device servers that implement the MODE SELECT(6) command shall also implement the MODE SENSE(6) command. Application clients should issue MODE SENSE(6) prior to each MODE SELECT(6) to determine supported mode pages, page lengths, and other parameters.
|
||||
SCSI_CMD_MODE_SENSE_6 = 0x1A, ///< provides a means for a device server to report parameters to an application client. It is a complementary command to the MODE SELECT(6) command. Device servers that implement the MODE SENSE(6) command shall also implement the MODE SELECT(6) command.
|
||||
SCSI_CMD_START_STOP_UNIT = 0x1B,
|
||||
SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
|
||||
SCSI_CMD_READ_CAPACITY_10 = 0x25, ///< The SCSI Read Capacity command is used to obtain data capacity information from a target device.
|
||||
SCSI_CMD_REQUEST_SENSE = 0x03, ///< The SCSI Request Sense command is part of the SCSI computer protocol standard. This command is used to obtain sense data -- status/error information -- from a target device.
|
||||
SCSI_CMD_READ_FORMAT_CAPACITY = 0x23, ///< The command allows the Host to request a list of the possible format capacities for an installed writable media. This command also has the capability to report the writable capacity for a media when it is installed
|
||||
SCSI_CMD_READ_10 = 0x28, ///< The READ (10) command requests that the device server read the specified logical block(s) and transfer them to the data-in buffer.
|
||||
SCSI_CMD_WRITE_10 = 0x2A, ///< The WRITE (10) command requests thatthe device server transfer the specified logical block(s) from the data-out buffer and write them.
|
||||
}scsi_cmd_type_t;
|
||||
|
||||
/// SCSI Sense Key
|
||||
typedef enum
|
||||
{
|
||||
SCSI_SENSE_NONE = 0x00, ///< no specific Sense Key. This would be the case for a successful command
|
||||
SCSI_SENSE_RECOVERED_ERROR = 0x01, ///< ndicates the last command completed successfully with some recovery action performed by the disc drive.
|
||||
SCSI_SENSE_NOT_READY = 0x02, ///< Indicates the logical unit addressed cannot be accessed.
|
||||
SCSI_SENSE_MEDIUM_ERROR = 0x03, ///< Indicates the command terminated with a non-recovered error condition.
|
||||
SCSI_SENSE_HARDWARE_ERROR = 0x04, ///< Indicates the disc drive detected a nonrecoverable hardware failure while performing the command or during a self test.
|
||||
SCSI_SENSE_ILLEGAL_REQUEST = 0x05, ///< Indicates an illegal parameter in the command descriptor block or in the additional parameters
|
||||
SCSI_SENSE_UNIT_ATTENTION = 0x06, ///< Indicates the disc drive may have been reset.
|
||||
SCSI_SENSE_DATA_PROTECT = 0x07, ///< Indicates that a command that reads or writes the medium was attempted on a block that is protected from this operation. The read or write operation is not performed.
|
||||
SCSI_SENSE_FIRMWARE_ERROR = 0x08, ///< Vendor specific sense key.
|
||||
SCSI_SENSE_ABORTED_COMMAND = 0x0b, ///< Indicates the disc drive aborted the command.
|
||||
SCSI_SENSE_EQUAL = 0x0c, ///< Indicates a SEARCH DATA command has satisfied an equal comparison.
|
||||
SCSI_SENSE_VOLUME_OVERFLOW = 0x0d, ///< Indicates a buffered peripheral device has reached the end of medium partition and data remains in the buffer that has not been written to the medium.
|
||||
SCSI_SENSE_MISCOMPARE = 0x0e ///< ndicates that the source data did not match the data read from the medium.
|
||||
}scsi_sense_key_type_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// SCSI Primary Command (SPC-4)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// SCSI Test Unit Ready Command
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_TEST_UNIT_READY
|
||||
uint8_t lun ; ///< Logical Unit
|
||||
uint8_t reserved[3] ;
|
||||
uint8_t control ;
|
||||
} scsi_test_unit_ready_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct");
|
||||
|
||||
/// SCSI Inquiry Command
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_INQUIRY
|
||||
uint8_t reserved1 ;
|
||||
uint8_t page_code ;
|
||||
uint8_t reserved2 ;
|
||||
uint8_t alloc_length ; ///< specifies the maximum number of bytes that USB host has allocated in the Data-In Buffer. An allocation length of zero specifies that no data shall be transferred.
|
||||
uint8_t control ;
|
||||
} scsi_inquiry_t, scsi_request_sense_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(scsi_inquiry_t) == 6, "size is not correct");
|
||||
|
||||
/// SCSI Inquiry Response Data
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t peripheral_device_type : 5;
|
||||
uint8_t peripheral_qualifier : 3;
|
||||
|
||||
uint8_t : 7;
|
||||
uint8_t is_removable : 1;
|
||||
|
||||
uint8_t version;
|
||||
|
||||
uint8_t response_data_format : 4;
|
||||
uint8_t hierarchical_support : 1;
|
||||
uint8_t normal_aca : 1;
|
||||
uint8_t : 2;
|
||||
|
||||
uint8_t additional_length;
|
||||
|
||||
uint8_t protect : 1;
|
||||
uint8_t : 2;
|
||||
uint8_t third_party_copy : 1;
|
||||
uint8_t target_port_group_support : 2;
|
||||
uint8_t access_control_coordinator : 1;
|
||||
uint8_t scc_support : 1;
|
||||
|
||||
uint8_t addr16 : 1;
|
||||
uint8_t : 3;
|
||||
uint8_t multi_port : 1;
|
||||
uint8_t : 1; // vendor specific
|
||||
uint8_t enclosure_service : 1;
|
||||
uint8_t : 1;
|
||||
|
||||
uint8_t : 1; // vendor specific
|
||||
uint8_t cmd_que : 1;
|
||||
uint8_t : 2;
|
||||
uint8_t sync : 1;
|
||||
uint8_t wbus16 : 1;
|
||||
uint8_t : 2;
|
||||
|
||||
uint8_t vendor_id[8] ; ///< 8 bytes of ASCII data identifying the vendor of the product.
|
||||
uint8_t product_id[16]; ///< 16 bytes of ASCII data defined by the vendor.
|
||||
uint8_t product_rev[4]; ///< 4 bytes of ASCII data defined by the vendor.
|
||||
} scsi_inquiry_resp_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(scsi_inquiry_resp_t) == 36, "size is not correct");
|
||||
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t response_code : 7; ///< 70h - current errors, Fixed Format 71h - deferred errors, Fixed Format
|
||||
uint8_t valid : 1;
|
||||
|
||||
uint8_t reserved;
|
||||
|
||||
uint8_t sense_key : 4;
|
||||
uint8_t : 1;
|
||||
uint8_t ili : 1; ///< Incorrect length indicator
|
||||
uint8_t end_of_medium : 1;
|
||||
uint8_t filemark : 1;
|
||||
|
||||
uint32_t information;
|
||||
uint8_t add_sense_len;
|
||||
uint32_t command_specific_info;
|
||||
uint8_t add_sense_code;
|
||||
uint8_t add_sense_qualifier;
|
||||
uint8_t field_replaceable_unit_code;
|
||||
|
||||
uint8_t sense_key_specific[3]; ///< sense key specific valid bit is bit 7 of key[0], aka MSB in Big Endian layout
|
||||
|
||||
} scsi_sense_fixed_resp_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(scsi_sense_fixed_resp_t) == 18, "size is not correct");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_MODE_SENSE_6
|
||||
|
||||
uint8_t : 3;
|
||||
uint8_t disable_block_descriptor : 1;
|
||||
uint8_t : 0;
|
||||
|
||||
uint8_t page_code : 6;
|
||||
uint8_t page_control : 2;
|
||||
|
||||
uint8_t subpage_code;
|
||||
uint8_t alloc_length;
|
||||
uint8_t control;
|
||||
} scsi_mode_sense6_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_t) == 6, "size is not correct");
|
||||
|
||||
// This is only a Mode parameter header(6).
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t data_len;
|
||||
uint8_t medium_type;
|
||||
|
||||
uint8_t reserved : 7;
|
||||
bool write_protected : 1;
|
||||
|
||||
uint8_t block_descriptor_len;
|
||||
} scsi_mode_sense6_resp_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_resp_t) == 4, "size is not correct");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t cmd_code; ///< SCSI OpCode for \ref SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL
|
||||
uint8_t reserved[3];
|
||||
uint8_t prohibit_removal;
|
||||
uint8_t control;
|
||||
} scsi_prevent_allow_medium_removal_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t cmd_code;
|
||||
|
||||
uint8_t immded : 1;
|
||||
uint8_t : 7;
|
||||
|
||||
uint8_t TU_RESERVED;
|
||||
|
||||
uint8_t power_condition_mod : 4;
|
||||
uint8_t : 4;
|
||||
|
||||
uint8_t start : 1;
|
||||
uint8_t load_eject : 1;
|
||||
uint8_t no_flush : 1;
|
||||
uint8_t : 1;
|
||||
uint8_t power_condition : 4;
|
||||
|
||||
uint8_t control;
|
||||
} scsi_start_stop_unit_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(scsi_start_stop_unit_t) == 6, "size is not correct");
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// SCSI MMC
|
||||
//--------------------------------------------------------------------+
|
||||
/// SCSI Read Format Capacity: Write Capacity
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t cmd_code;
|
||||
uint8_t reserved[6];
|
||||
uint16_t alloc_length;
|
||||
uint8_t control;
|
||||
} scsi_read_format_capacity_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct");
|
||||
|
||||
typedef struct TU_ATTR_PACKED{
|
||||
uint8_t reserved[3];
|
||||
uint8_t list_length; /// must be 8*n, length in bytes of formattable capacity descriptor followed it.
|
||||
|
||||
uint32_t block_num; /// Number of Logical Blocks
|
||||
uint8_t descriptor_type; // 00: reserved, 01 unformatted media , 10 Formatted media, 11 No media present
|
||||
|
||||
uint8_t reserved2;
|
||||
uint16_t block_size_u16;
|
||||
|
||||
} scsi_read_format_capacity_data_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not correct");
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// SCSI Block Command (SBC-3)
|
||||
// NOTE: All data in SCSI command are in Big Endian
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// SCSI Read Capacity 10 Command: Read Capacity
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_READ_CAPACITY_10
|
||||
uint8_t reserved1 ;
|
||||
uint32_t lba ; ///< The first Logical Block Address (LBA) accessed by this command
|
||||
uint16_t reserved2 ;
|
||||
uint8_t partial_medium_indicator ;
|
||||
uint8_t control ;
|
||||
} scsi_read_capacity10_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_t) == 10, "size is not correct");
|
||||
|
||||
/// SCSI Read Capacity 10 Response Data
|
||||
typedef struct {
|
||||
uint32_t last_lba ; ///< The last Logical Block Address of the device
|
||||
uint32_t block_size ; ///< Block size in bytes
|
||||
} scsi_read_capacity10_resp_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_resp_t) == 8, "size is not correct");
|
||||
|
||||
/// SCSI Read 10 Command
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t cmd_code ; ///< SCSI OpCode
|
||||
uint8_t reserved ; // has LUN according to wiki
|
||||
uint32_t lba ; ///< The first Logical Block Address (LBA) accessed by this command
|
||||
uint8_t reserved2 ;
|
||||
uint16_t block_count ; ///< Number of Blocks used by this command
|
||||
uint8_t control ;
|
||||
} scsi_read10_t, scsi_write10_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(scsi_read10_t) == 10, "size is not correct");
|
||||
TU_VERIFY_STATIC(sizeof(scsi_write10_t) == 10, "size is not correct");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_MSC_H_ */
|
||||
|
||||
/// @}
|
||||
/// @}
|
||||
@@ -1,640 +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 "tusb_option.h"
|
||||
|
||||
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_MSC)
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "msc_device.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
enum
|
||||
{
|
||||
MSC_STAGE_CMD = 0,
|
||||
MSC_STAGE_DATA,
|
||||
MSC_STAGE_STATUS
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CFG_TUSB_MEM_ALIGN msc_cbw_t cbw;
|
||||
CFG_TUSB_MEM_ALIGN msc_csw_t csw;
|
||||
|
||||
uint8_t itf_num;
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out;
|
||||
|
||||
// Bulk Only Transfer (BOT) Protocol
|
||||
uint8_t stage;
|
||||
uint32_t total_len;
|
||||
uint32_t xferred_len; // numbered of bytes transferred so far in the Data Stage
|
||||
|
||||
// Sense Response Data
|
||||
uint8_t sense_key;
|
||||
uint8_t add_sense_code;
|
||||
uint8_t add_sense_qualifier;
|
||||
}mscd_interface_t;
|
||||
|
||||
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static mscd_interface_t _mscd_itf;
|
||||
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t _mscd_buf[CFG_TUD_MSC_BUFSIZE];
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc);
|
||||
static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc);
|
||||
|
||||
static inline uint32_t rdwr10_get_lba(uint8_t const command[])
|
||||
{
|
||||
// read10 & write10 has the same format
|
||||
scsi_write10_t* p_rdwr10 = (scsi_write10_t*) command;
|
||||
|
||||
// copy first to prevent mis-aligned access
|
||||
uint32_t lba;
|
||||
memcpy(&lba, &p_rdwr10->lba, 4);
|
||||
|
||||
// lba is in Big Endian format
|
||||
return tu_ntohl(lba);
|
||||
}
|
||||
|
||||
static inline uint16_t rdwr10_get_blockcount(uint8_t const command[])
|
||||
{
|
||||
// read10 & write10 has the same format
|
||||
scsi_write10_t* p_rdwr10 = (scsi_write10_t*) command;
|
||||
|
||||
// copy first to prevent mis-aligned access
|
||||
uint16_t block_count;
|
||||
memcpy(&block_count, &p_rdwr10->block_count, 2);
|
||||
|
||||
return tu_ntohs(block_count);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier)
|
||||
{
|
||||
(void) lun;
|
||||
|
||||
_mscd_itf.sense_key = sense_key;
|
||||
_mscd_itf.add_sense_code = add_sense_code;
|
||||
_mscd_itf.add_sense_qualifier = add_sense_qualifier;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
void mscd_init(void)
|
||||
{
|
||||
tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
|
||||
}
|
||||
|
||||
void mscd_reset(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
|
||||
}
|
||||
|
||||
bool mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_len)
|
||||
{
|
||||
// only support SCSI's BOT protocol
|
||||
TU_ASSERT(MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass &&
|
||||
MSC_PROTOCOL_BOT == itf_desc->bInterfaceProtocol);
|
||||
|
||||
mscd_interface_t * p_msc = &_mscd_itf;
|
||||
|
||||
// Open endpoint pair
|
||||
TU_ASSERT( usbd_open_edpt_pair(rhport, tu_desc_next(itf_desc), 2, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in) );
|
||||
|
||||
p_msc->itf_num = itf_desc->bInterfaceNumber;
|
||||
(*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
// Prepare for Command Block Wrapper
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle class control request
|
||||
// return false to stall control endpoint (e.g unsupported request)
|
||||
bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
TU_ASSERT(p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
|
||||
|
||||
switch ( p_request->bRequest )
|
||||
{
|
||||
case MSC_REQ_RESET:
|
||||
// TODO: Actually reset interface.
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
case MSC_REQ_GET_MAX_LUN:
|
||||
{
|
||||
uint8_t maxlun = 1;
|
||||
if (tud_msc_get_maxlun_cb) maxlun = tud_msc_get_maxlun_cb();
|
||||
TU_VERIFY(maxlun);
|
||||
|
||||
// MAX LUN is minus 1 by specs
|
||||
maxlun--;
|
||||
|
||||
tud_control_xfer(rhport, p_request, &maxlun, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
default: return false; // stall unsupported request
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Invoked when class request DATA stage is finished.
|
||||
// return false to stall control endpoint (e.g Host send non-sense DATA)
|
||||
bool mscd_control_complete(uint8_t rhport, tusb_control_request_t const * request)
|
||||
{
|
||||
(void) rhport;
|
||||
(void) request;
|
||||
|
||||
// nothing to do
|
||||
return true;
|
||||
}
|
||||
|
||||
// return response's length (copied to buffer). Negative if it is not an built-in command or indicate Failed status (CSW)
|
||||
// In case of a failed status, sense key must be set for reason of failure
|
||||
int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_t* buffer, uint32_t bufsize)
|
||||
{
|
||||
(void) bufsize; // TODO refractor later
|
||||
int32_t resplen;
|
||||
|
||||
switch ( scsi_cmd[0] )
|
||||
{
|
||||
case SCSI_CMD_TEST_UNIT_READY:
|
||||
resplen = 0;
|
||||
if ( !tud_msc_test_unit_ready_cb(lun) )
|
||||
{
|
||||
// Failed status response
|
||||
resplen = - 1;
|
||||
|
||||
// If sense key is not set by callback, default to Logical Unit Not Ready, Cause Not Reportable
|
||||
if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
|
||||
}
|
||||
break;
|
||||
|
||||
case SCSI_CMD_START_STOP_UNIT:
|
||||
resplen = 0;
|
||||
|
||||
if (tud_msc_start_stop_cb)
|
||||
{
|
||||
scsi_start_stop_unit_t const * start_stop = (scsi_start_stop_unit_t const *) scsi_cmd;
|
||||
if ( !tud_msc_start_stop_cb(lun, start_stop->power_condition, start_stop->start, start_stop->load_eject) )
|
||||
{
|
||||
// Failed status response
|
||||
resplen = - 1;
|
||||
|
||||
// If sense key is not set by callback, default to Logical Unit Not Ready, Cause Not Reportable
|
||||
if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCSI_CMD_READ_CAPACITY_10:
|
||||
{
|
||||
uint32_t block_count;
|
||||
uint32_t block_size;
|
||||
uint16_t block_size_u16;
|
||||
|
||||
tud_msc_capacity_cb(lun, &block_count, &block_size_u16);
|
||||
block_size = (uint32_t) block_size_u16;
|
||||
|
||||
// Invalid block size/count from callback, possibly unit is not ready
|
||||
// stall this request, set sense key to NOT READY
|
||||
if (block_count == 0 || block_size == 0)
|
||||
{
|
||||
resplen = -1;
|
||||
|
||||
// If sense key is not set by callback, default to Logical Unit Not Ready, Cause Not Reportable
|
||||
if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
|
||||
}else
|
||||
{
|
||||
scsi_read_capacity10_resp_t read_capa10;
|
||||
|
||||
read_capa10.last_lba = tu_htonl(block_count-1);
|
||||
read_capa10.block_size = tu_htonl(block_size);
|
||||
|
||||
resplen = sizeof(read_capa10);
|
||||
memcpy(buffer, &read_capa10, resplen);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCSI_CMD_READ_FORMAT_CAPACITY:
|
||||
{
|
||||
scsi_read_format_capacity_data_t read_fmt_capa =
|
||||
{
|
||||
.list_length = 8,
|
||||
.block_num = 0,
|
||||
.descriptor_type = 2, // formatted media
|
||||
.block_size_u16 = 0
|
||||
};
|
||||
|
||||
uint32_t block_count;
|
||||
uint16_t block_size;
|
||||
|
||||
tud_msc_capacity_cb(lun, &block_count, &block_size);
|
||||
|
||||
// Invalid block size/count from callback, possibly unit is not ready
|
||||
// stall this request, set sense key to NOT READY
|
||||
if (block_count == 0 || block_size == 0)
|
||||
{
|
||||
resplen = -1;
|
||||
|
||||
// If sense key is not set by callback, default to Logical Unit Not Ready, Cause Not Reportable
|
||||
if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
|
||||
}else
|
||||
{
|
||||
read_fmt_capa.block_num = tu_htonl(block_count);
|
||||
read_fmt_capa.block_size_u16 = tu_htons(block_size);
|
||||
|
||||
resplen = sizeof(read_fmt_capa);
|
||||
memcpy(buffer, &read_fmt_capa, resplen);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCSI_CMD_INQUIRY:
|
||||
{
|
||||
scsi_inquiry_resp_t inquiry_rsp =
|
||||
{
|
||||
.is_removable = 1,
|
||||
.version = 2,
|
||||
.response_data_format = 2,
|
||||
};
|
||||
|
||||
// vendor_id, product_id, product_rev is space padded string
|
||||
memset(inquiry_rsp.vendor_id , ' ', sizeof(inquiry_rsp.vendor_id));
|
||||
memset(inquiry_rsp.product_id , ' ', sizeof(inquiry_rsp.product_id));
|
||||
memset(inquiry_rsp.product_rev, ' ', sizeof(inquiry_rsp.product_rev));
|
||||
|
||||
tud_msc_inquiry_cb(lun, inquiry_rsp.vendor_id, inquiry_rsp.product_id, inquiry_rsp.product_rev);
|
||||
|
||||
resplen = sizeof(inquiry_rsp);
|
||||
memcpy(buffer, &inquiry_rsp, resplen);
|
||||
}
|
||||
break;
|
||||
|
||||
case SCSI_CMD_MODE_SENSE_6:
|
||||
{
|
||||
scsi_mode_sense6_resp_t mode_resp =
|
||||
{
|
||||
.data_len = 3,
|
||||
.medium_type = 0,
|
||||
.write_protected = false,
|
||||
.reserved = 0,
|
||||
.block_descriptor_len = 0 // no block descriptor are included
|
||||
};
|
||||
|
||||
bool writable = true;
|
||||
if (tud_msc_is_writable_cb) {
|
||||
writable = tud_msc_is_writable_cb(lun);
|
||||
}
|
||||
mode_resp.write_protected = !writable;
|
||||
|
||||
resplen = sizeof(mode_resp);
|
||||
memcpy(buffer, &mode_resp, resplen);
|
||||
}
|
||||
break;
|
||||
|
||||
case SCSI_CMD_REQUEST_SENSE:
|
||||
{
|
||||
scsi_sense_fixed_resp_t sense_rsp =
|
||||
{
|
||||
.response_code = 0x70,
|
||||
.valid = 1
|
||||
};
|
||||
|
||||
sense_rsp.add_sense_len = sizeof(scsi_sense_fixed_resp_t) - 8;
|
||||
|
||||
sense_rsp.sense_key = _mscd_itf.sense_key;
|
||||
sense_rsp.add_sense_code = _mscd_itf.add_sense_code;
|
||||
sense_rsp.add_sense_qualifier = _mscd_itf.add_sense_qualifier;
|
||||
|
||||
resplen = sizeof(sense_rsp);
|
||||
memcpy(buffer, &sense_rsp, resplen);
|
||||
|
||||
// Clear sense data after copy
|
||||
tud_msc_set_sense(lun, 0, 0, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
default: resplen = -1; break;
|
||||
}
|
||||
|
||||
return resplen;
|
||||
}
|
||||
|
||||
bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
mscd_interface_t* p_msc = &_mscd_itf;
|
||||
msc_cbw_t const * p_cbw = &p_msc->cbw;
|
||||
msc_csw_t * p_csw = &p_msc->csw;
|
||||
|
||||
switch (p_msc->stage)
|
||||
{
|
||||
case MSC_STAGE_CMD:
|
||||
//------------- new CBW received -------------//
|
||||
// Complete IN while waiting for CMD is usually Status of previous SCSI op, ignore it
|
||||
if(ep_addr != p_msc->ep_out) return true;
|
||||
|
||||
TU_ASSERT( event == XFER_RESULT_SUCCESS &&
|
||||
xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE );
|
||||
|
||||
p_csw->signature = MSC_CSW_SIGNATURE;
|
||||
p_csw->tag = p_cbw->tag;
|
||||
p_csw->data_residue = 0;
|
||||
|
||||
/*------------- Parse command and prepare DATA -------------*/
|
||||
p_msc->stage = MSC_STAGE_DATA;
|
||||
p_msc->total_len = p_cbw->total_bytes;
|
||||
p_msc->xferred_len = 0;
|
||||
|
||||
if (SCSI_CMD_READ_10 == p_cbw->command[0])
|
||||
{
|
||||
proc_read10_cmd(rhport, p_msc);
|
||||
}
|
||||
else if (SCSI_CMD_WRITE_10 == p_cbw->command[0])
|
||||
{
|
||||
proc_write10_cmd(rhport, p_msc);
|
||||
}
|
||||
else
|
||||
{
|
||||
// For other SCSI commands
|
||||
// 1. OUT : queue transfer (invoke app callback after done)
|
||||
// 2. IN & Zero: Process if is built-in, else Invoke app callback. Skip DATA if zero length
|
||||
if ( (p_cbw->total_bytes > 0 ) && !tu_bit_test(p_cbw->dir, 7) )
|
||||
{
|
||||
// queue transfer
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
|
||||
}else
|
||||
{
|
||||
int32_t resplen;
|
||||
|
||||
// First process if it is a built-in commands
|
||||
resplen = proc_builtin_scsi(p_cbw->lun, p_cbw->command, _mscd_buf, sizeof(_mscd_buf));
|
||||
|
||||
// Not built-in, invoke user callback
|
||||
if ( (resplen < 0) && (p_msc->sense_key == 0) )
|
||||
{
|
||||
resplen = tud_msc_scsi_cb(p_cbw->lun, p_cbw->command, _mscd_buf, p_msc->total_len);
|
||||
}
|
||||
|
||||
if ( resplen < 0 )
|
||||
{
|
||||
p_msc->total_len = 0;
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
|
||||
// failed but senskey is not set: default to Illegal Request
|
||||
if ( p_msc->sense_key == 0 ) tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
|
||||
|
||||
// Stall bulk In if needed
|
||||
if (p_cbw->total_bytes) usbd_edpt_stall(rhport, p_msc->ep_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
p_msc->total_len = (uint32_t) resplen;
|
||||
p_csw->status = MSC_CSW_STATUS_PASSED;
|
||||
|
||||
if (p_msc->total_len)
|
||||
{
|
||||
TU_ASSERT( p_cbw->total_bytes >= p_msc->total_len ); // cannot return more than host expect
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len) );
|
||||
}else
|
||||
{
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MSC_STAGE_DATA:
|
||||
// OUT transfer, invoke callback if needed
|
||||
if ( !tu_bit_test(p_cbw->dir, 7) )
|
||||
{
|
||||
if ( SCSI_CMD_WRITE_10 != p_cbw->command[0] )
|
||||
{
|
||||
int32_t cb_result = tud_msc_scsi_cb(p_cbw->lun, p_cbw->command, _mscd_buf, p_msc->total_len);
|
||||
|
||||
if ( cb_result < 0 )
|
||||
{
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation
|
||||
}else
|
||||
{
|
||||
p_csw->status = MSC_CSW_STATUS_PASSED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t const block_sz = p_cbw->total_bytes / rdwr10_get_blockcount(p_cbw->command);
|
||||
|
||||
// Adjust lba with transferred bytes
|
||||
uint32_t const lba = rdwr10_get_lba(p_cbw->command) + (p_msc->xferred_len / block_sz);
|
||||
|
||||
// Application can consume smaller bytes
|
||||
int32_t nbytes = tud_msc_write10_cb(p_cbw->lun, lba, p_msc->xferred_len % block_sz, _mscd_buf, xferred_bytes);
|
||||
|
||||
if ( nbytes < 0 )
|
||||
{
|
||||
// negative means error -> skip to status phase, status in CSW set to failed
|
||||
p_csw->data_residue = p_cbw->total_bytes - p_msc->xferred_len;
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
|
||||
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation
|
||||
break;
|
||||
}else
|
||||
{
|
||||
// Application consume less than what we got (including zero)
|
||||
if ( nbytes < (int32_t) xferred_bytes )
|
||||
{
|
||||
if ( nbytes > 0 )
|
||||
{
|
||||
p_msc->xferred_len += nbytes;
|
||||
memmove(_mscd_buf, _mscd_buf+nbytes, xferred_bytes-nbytes);
|
||||
}
|
||||
|
||||
// simulate an transfer complete with adjusted parameters --> this driver callback will fired again
|
||||
dcd_event_xfer_complete(rhport, p_msc->ep_out, xferred_bytes-nbytes, XFER_RESULT_SUCCESS, false);
|
||||
|
||||
return true; // skip the rest
|
||||
}
|
||||
else
|
||||
{
|
||||
// Application consume all bytes in our buffer. Nothing to do, process with normal flow
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Accumulate data so far
|
||||
p_msc->xferred_len += xferred_bytes;
|
||||
|
||||
if ( p_msc->xferred_len >= p_msc->total_len )
|
||||
{
|
||||
// Data Stage is complete
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// READ10 & WRITE10 Can be executed with large bulk of data e.g write 8K bytes (several flash write)
|
||||
// We break it into multiple smaller command whose data size is up to CFG_TUD_MSC_BUFSIZE
|
||||
if (SCSI_CMD_READ_10 == p_cbw->command[0])
|
||||
{
|
||||
proc_read10_cmd(rhport, p_msc);
|
||||
}
|
||||
else if (SCSI_CMD_WRITE_10 == p_cbw->command[0])
|
||||
{
|
||||
proc_write10_cmd(rhport, p_msc);
|
||||
}else
|
||||
{
|
||||
// No other command take more than one transfer yet -> unlikely error
|
||||
TU_BREAKPOINT();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MSC_STAGE_STATUS: break; // processed immediately after this switch
|
||||
default : break;
|
||||
}
|
||||
|
||||
if ( p_msc->stage == MSC_STAGE_STATUS )
|
||||
{
|
||||
// Either endpoints is stalled, need to wait until it is cleared by host
|
||||
if ( usbd_edpt_stalled(rhport, p_msc->ep_in) || usbd_edpt_stalled(rhport, p_msc->ep_out) )
|
||||
{
|
||||
// simulate an transfer complete with adjusted parameters --> this driver callback will fired again
|
||||
dcd_event_xfer_complete(rhport, p_msc->ep_out, 0, XFER_RESULT_SUCCESS, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move to default CMD stage when sending status
|
||||
p_msc->stage = MSC_STAGE_CMD;
|
||||
|
||||
// Send SCSI Status
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
|
||||
|
||||
// Invoke complete callback if defined
|
||||
if ( SCSI_CMD_READ_10 == p_cbw->command[0])
|
||||
{
|
||||
if ( tud_msc_read10_complete_cb ) tud_msc_read10_complete_cb(p_cbw->lun);
|
||||
}
|
||||
else if ( SCSI_CMD_WRITE_10 == p_cbw->command[0] )
|
||||
{
|
||||
if ( tud_msc_write10_complete_cb ) tud_msc_write10_complete_cb(p_cbw->lun);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( tud_msc_scsi_complete_cb ) tud_msc_scsi_complete_cb(p_cbw->lun, p_cbw->command);
|
||||
}
|
||||
|
||||
// Queue for the next CBW
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* SCSI Command Process
|
||||
*------------------------------------------------------------------*/
|
||||
static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
|
||||
{
|
||||
msc_cbw_t const * p_cbw = &p_msc->cbw;
|
||||
msc_csw_t * p_csw = &p_msc->csw;
|
||||
|
||||
uint16_t const block_sz = p_cbw->total_bytes / rdwr10_get_blockcount(p_cbw->command);
|
||||
|
||||
// Adjust lba with transferred bytes
|
||||
uint32_t const lba = rdwr10_get_lba(p_cbw->command) + (p_msc->xferred_len / block_sz);
|
||||
|
||||
// remaining bytes capped at class buffer
|
||||
int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
|
||||
|
||||
// Application can consume smaller bytes
|
||||
nbytes = tud_msc_read10_cb(p_cbw->lun, lba, p_msc->xferred_len % block_sz, _mscd_buf, (uint32_t) nbytes);
|
||||
|
||||
if ( nbytes < 0 )
|
||||
{
|
||||
// negative means error -> pipe is stalled & status in CSW set to failed
|
||||
p_csw->data_residue = p_cbw->total_bytes - p_msc->xferred_len;
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
|
||||
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation
|
||||
usbd_edpt_stall(rhport, p_msc->ep_in);
|
||||
}
|
||||
else if ( nbytes == 0 )
|
||||
{
|
||||
// zero means not ready -> simulate an transfer complete so that this driver callback will fired again
|
||||
dcd_event_xfer_complete(rhport, p_msc->ep_in, 0, XFER_RESULT_SUCCESS, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, nbytes), );
|
||||
}
|
||||
}
|
||||
|
||||
static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
|
||||
{
|
||||
msc_cbw_t const * p_cbw = &p_msc->cbw;
|
||||
bool writable = true;
|
||||
if (tud_msc_is_writable_cb) {
|
||||
writable = tud_msc_is_writable_cb(p_cbw->lun);
|
||||
}
|
||||
if (!writable) {
|
||||
msc_csw_t* p_csw = &p_msc->csw;
|
||||
p_csw->data_residue = p_cbw->total_bytes;
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
|
||||
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_DATA_PROTECT, 0x27, 0x00); // Sense = Write protected
|
||||
usbd_edpt_stall(rhport, p_msc->ep_out);
|
||||
return;
|
||||
}
|
||||
|
||||
// remaining bytes capped at class buffer
|
||||
int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
|
||||
|
||||
// Write10 callback will be called later when usb transfer complete
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, nbytes), );
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_MSC_DEVICE_H_
|
||||
#define _TUSB_MSC_DEVICE_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/usbd.h"
|
||||
#include "msc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Driver Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
TU_VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct");
|
||||
|
||||
#ifndef CFG_TUD_MSC_BUFSIZE
|
||||
#error CFG_TUD_MSC_BUFSIZE must be defined, value of a block size should work well, the more the better
|
||||
#endif
|
||||
|
||||
/** \addtogroup ClassDriver_MSC
|
||||
* @{
|
||||
* \defgroup MSC_Device Device
|
||||
* @{ */
|
||||
|
||||
bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application Callbacks (WEAK is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/**
|
||||
* Invoked when received \ref SCSI_CMD_READ_10 command
|
||||
* \param[in] lun Logical unit number
|
||||
* \param[in] lba Logical Block Address to be read
|
||||
* \param[in] offset Byte offset from LBA
|
||||
* \param[out] buffer Buffer which application need to update with the response data.
|
||||
* \param[in] bufsize Requested bytes
|
||||
*
|
||||
* \return Number of byte read, if it is less than requested bytes by \a \b bufsize. Tinyusb will transfer
|
||||
* this amount first and invoked this again for remaining data.
|
||||
*
|
||||
* \retval zero Indicate application is not ready yet to response e.g disk I/O is not complete.
|
||||
* tinyusb will invoke this callback with the same parameters again some time later.
|
||||
*
|
||||
* \retval negative Indicate error e.g reading disk I/O. tinyusb will \b STALL the corresponding
|
||||
* endpoint and return failed status in command status wrapper phase.
|
||||
*/
|
||||
TU_ATTR_WEAK int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize);
|
||||
|
||||
/**
|
||||
* Invoked when received \ref SCSI_CMD_WRITE_10 command
|
||||
* \param[in] lun Logical unit number
|
||||
* \param[in] lba Logical Block Address to be write
|
||||
* \param[in] offset Byte offset from LBA
|
||||
* \param[out] buffer Buffer which holds written data.
|
||||
* \param[in] bufsize Requested bytes
|
||||
*
|
||||
* \return Number of byte written, if it is less than requested bytes by \a \b bufsize. Tinyusb will proceed with
|
||||
* other work and invoked this again with adjusted parameters.
|
||||
*
|
||||
* \retval zero Indicate application is not ready yet e.g disk I/O is not complete.
|
||||
* Tinyusb will invoke this callback with the same parameters again some time later.
|
||||
*
|
||||
* \retval negative Indicate error writing disk I/O. Tinyusb will \b STALL the corresponding
|
||||
* endpoint and return failed status in command status wrapper phase.
|
||||
*/
|
||||
TU_ATTR_WEAK int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize);
|
||||
|
||||
// Invoked when received SCSI_CMD_INQUIRY
|
||||
// Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively
|
||||
TU_ATTR_WEAK void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]);
|
||||
|
||||
// Invoked when received Test Unit Ready command.
|
||||
// return true allowing host to read/write this LUN e.g SD card inserted
|
||||
TU_ATTR_WEAK bool tud_msc_test_unit_ready_cb(uint8_t lun);
|
||||
|
||||
// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size
|
||||
// Application update block count and block size
|
||||
TU_ATTR_WEAK void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size);
|
||||
|
||||
/**
|
||||
* Invoked when received an SCSI command not in built-in list below.
|
||||
* - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, TEST_UNIT_READY, START_STOP_UNIT, MODE_SENSE6, REQUEST_SENSE
|
||||
* - READ10 and WRITE10 has their own callbacks
|
||||
*
|
||||
* \param[in] lun Logical unit number
|
||||
* \param[in] scsi_cmd SCSI command contents which application must examine to response accordingly
|
||||
* \param[out] buffer Buffer for SCSI Data Stage.
|
||||
* - For INPUT: application must fill this with response.
|
||||
* - For OUTPUT it holds the Data from host
|
||||
* \param[in] bufsize Buffer's length.
|
||||
*
|
||||
* \return Actual bytes processed, can be zero for no-data command.
|
||||
* \retval negative Indicate error e.g unsupported command, tinyusb will \b STALL the corresponding
|
||||
* endpoint and return failed status in command status wrapper phase.
|
||||
*/
|
||||
TU_ATTR_WEAK int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize);
|
||||
|
||||
/*------------- Optional callbacks -------------*/
|
||||
|
||||
// Invoked when received GET_MAX_LUN request, required for multiple LUNs implementation
|
||||
TU_ATTR_WEAK uint8_t tud_msc_get_maxlun_cb(void);
|
||||
|
||||
// Invoked when received Start Stop Unit command
|
||||
// - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage
|
||||
// - Start = 1 : active mode, if load_eject = 1 : load disk storage
|
||||
TU_ATTR_WEAK bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject);
|
||||
|
||||
// Invoked when Read10 command is complete
|
||||
TU_ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun);
|
||||
|
||||
// Invoke when Write10 command is complete, can be used to flush flash caching
|
||||
TU_ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun);
|
||||
|
||||
// Invoked when command in tud_msc_scsi_cb is complete
|
||||
TU_ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[16]);
|
||||
|
||||
// Hook to make a mass storage device read-only. TODO remove
|
||||
TU_ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun);
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal Class Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
void mscd_init (void);
|
||||
void mscd_reset (uint8_t rhport);
|
||||
bool mscd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
|
||||
bool mscd_control_request (uint8_t rhport, tusb_control_request_t const * p_request);
|
||||
bool mscd_control_complete (uint8_t rhport, tusb_control_request_t const * p_request);
|
||||
bool mscd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_MSC_DEVICE_H_ */
|
||||
@@ -1,218 +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 "tusb_option.h"
|
||||
|
||||
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_VENDOR)
|
||||
|
||||
#include "vendor_device.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct
|
||||
{
|
||||
uint8_t itf_num;
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out;
|
||||
|
||||
/*------------- From this point, data is not cleared by bus reset -------------*/
|
||||
tu_fifo_t rx_ff;
|
||||
tu_fifo_t tx_ff;
|
||||
|
||||
uint8_t rx_ff_buf[CFG_TUD_VENDOR_RX_BUFSIZE];
|
||||
uint8_t tx_ff_buf[CFG_TUD_VENDOR_TX_BUFSIZE];
|
||||
|
||||
#if CFG_FIFO_MUTEX
|
||||
osal_mutex_def_t rx_ff_mutex;
|
||||
osal_mutex_def_t tx_ff_mutex;
|
||||
#endif
|
||||
|
||||
// Endpoint Transfer buffer
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_VENDOR_EPSIZE];
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_VENDOR_EPSIZE];
|
||||
} vendord_interface_t;
|
||||
|
||||
CFG_TUSB_MEM_SECTION static vendord_interface_t _vendord_itf[CFG_TUD_VENDOR];
|
||||
|
||||
#define ITF_MEM_RESET_SIZE offsetof(vendord_interface_t, rx_ff)
|
||||
|
||||
|
||||
bool tud_vendor_n_mounted (uint8_t itf)
|
||||
{
|
||||
return _vendord_itf[itf].ep_in && _vendord_itf[itf].ep_out;
|
||||
}
|
||||
|
||||
uint32_t tud_vendor_n_available (uint8_t itf)
|
||||
{
|
||||
return tu_fifo_count(&_vendord_itf[itf].rx_ff);
|
||||
}
|
||||
|
||||
bool tud_vendor_n_peek(uint8_t itf, int pos, uint8_t* u8)
|
||||
{
|
||||
return tu_fifo_peek_at(&_vendord_itf[itf].rx_ff, pos, u8);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Read API
|
||||
//--------------------------------------------------------------------+
|
||||
static void _prep_out_transaction (vendord_interface_t* p_itf)
|
||||
{
|
||||
// skip if previous transfer not complete
|
||||
if ( usbd_edpt_busy(TUD_OPT_RHPORT, p_itf->ep_out) ) return;
|
||||
|
||||
// Prepare for incoming data but only allow what we can store in the ring buffer.
|
||||
uint16_t max_read = tu_fifo_remaining(&p_itf->rx_ff);
|
||||
if ( max_read >= CFG_TUD_VENDOR_EPSIZE )
|
||||
{
|
||||
usbd_edpt_xfer(TUD_OPT_RHPORT, p_itf->ep_out, p_itf->epout_buf, CFG_TUD_VENDOR_EPSIZE);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
vendord_interface_t* p_itf = &_vendord_itf[itf];
|
||||
uint32_t num_read = tu_fifo_read_n(&p_itf->rx_ff, buffer, bufsize);
|
||||
_prep_out_transaction(p_itf);
|
||||
return num_read;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Write API
|
||||
//--------------------------------------------------------------------+
|
||||
static bool maybe_transmit(vendord_interface_t* p_itf)
|
||||
{
|
||||
// skip if previous transfer not complete
|
||||
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, p_itf->ep_in) );
|
||||
|
||||
uint16_t count = tu_fifo_read_n(&p_itf->tx_ff, p_itf->epin_buf, CFG_TUD_VENDOR_EPSIZE);
|
||||
if (count > 0)
|
||||
{
|
||||
TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, p_itf->ep_in, p_itf->epin_buf, count) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
vendord_interface_t* p_itf = &_vendord_itf[itf];
|
||||
uint16_t ret = tu_fifo_write_n(&p_itf->tx_ff, buffer, bufsize);
|
||||
maybe_transmit(p_itf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
void vendord_init(void)
|
||||
{
|
||||
tu_memclr(_vendord_itf, sizeof(_vendord_itf));
|
||||
|
||||
for(uint8_t i=0; i<CFG_TUD_VENDOR; i++)
|
||||
{
|
||||
vendord_interface_t* p_itf = &_vendord_itf[i];
|
||||
|
||||
// config fifo
|
||||
tu_fifo_config(&p_itf->rx_ff, p_itf->rx_ff_buf, CFG_TUD_VENDOR_RX_BUFSIZE, 1, false);
|
||||
tu_fifo_config(&p_itf->tx_ff, p_itf->tx_ff_buf, CFG_TUD_VENDOR_TX_BUFSIZE, 1, false);
|
||||
|
||||
#if CFG_FIFO_MUTEX
|
||||
tu_fifo_config_mutex(&p_itf->rx_ff, osal_mutex_create(&p_itf->rx_ff_mutex));
|
||||
tu_fifo_config_mutex(&p_itf->tx_ff, osal_mutex_create(&p_itf->tx_ff_mutex));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void vendord_reset(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
for(uint8_t i=0; i<CFG_TUD_VENDOR; i++)
|
||||
{
|
||||
vendord_interface_t* p_itf = &_vendord_itf[i];
|
||||
|
||||
tu_memclr(p_itf, ITF_MEM_RESET_SIZE);
|
||||
tu_fifo_clear(&p_itf->rx_ff);
|
||||
tu_fifo_clear(&p_itf->tx_ff);
|
||||
}
|
||||
}
|
||||
|
||||
bool vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_len)
|
||||
{
|
||||
// Find available interface
|
||||
vendord_interface_t* p_vendor = NULL;
|
||||
for(uint8_t i=0; i<CFG_TUD_VENDOR; i++)
|
||||
{
|
||||
if ( _vendord_itf[i].ep_in == 0 && _vendord_itf[i].ep_out == 0 )
|
||||
{
|
||||
p_vendor = &_vendord_itf[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
TU_VERIFY(p_vendor);
|
||||
|
||||
// Open endpoint pair with usbd helper
|
||||
TU_ASSERT(usbd_open_edpt_pair(rhport, tu_desc_next(itf_desc), 2, TUSB_XFER_BULK, &p_vendor->ep_out, &p_vendor->ep_in));
|
||||
|
||||
p_vendor->itf_num = itf_desc->bInterfaceNumber;
|
||||
(*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
// Prepare for incoming data
|
||||
TU_ASSERT(usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, sizeof(p_vendor->epout_buf)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
||||
{
|
||||
(void) rhport;
|
||||
(void) result;
|
||||
|
||||
// TODO Support multiple interfaces
|
||||
uint8_t const itf = 0;
|
||||
vendord_interface_t* p_itf = &_vendord_itf[itf];
|
||||
|
||||
if ( ep_addr == p_itf->ep_out )
|
||||
{
|
||||
// Receive new data
|
||||
tu_fifo_write_n(&p_itf->rx_ff, p_itf->epout_buf, xferred_bytes);
|
||||
|
||||
// Invoked callback if any
|
||||
if (tud_vendor_rx_cb) tud_vendor_rx_cb(itf);
|
||||
|
||||
_prep_out_transaction(p_itf);
|
||||
}
|
||||
else if ( ep_addr == p_itf->ep_in )
|
||||
{
|
||||
// Send complete, try to send more if possible
|
||||
maybe_transmit(p_itf);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,121 +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.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_VENDOR_DEVICE_H_
|
||||
#define _TUSB_VENDOR_DEVICE_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/usbd.h"
|
||||
|
||||
#ifndef CFG_TUD_VENDOR_EPSIZE
|
||||
#define CFG_TUD_VENDOR_EPSIZE 64
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Multiple Interfaces)
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_vendor_n_mounted (uint8_t itf);
|
||||
uint32_t tud_vendor_n_available (uint8_t itf);
|
||||
uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize);
|
||||
bool tud_vendor_n_peek (uint8_t itf, int pos, uint8_t* u8);
|
||||
uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
|
||||
|
||||
static inline
|
||||
uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Single Port)
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool tud_vendor_mounted (void);
|
||||
static inline uint32_t tud_vendor_available (void);
|
||||
static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize);
|
||||
static inline bool tud_vendor_peek (int pos, uint8_t* u8);
|
||||
static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize);
|
||||
static inline uint32_t tud_vendor_write_str (char const* str);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application Callback API (weak is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when received new data
|
||||
TU_ATTR_WEAK void tud_vendor_rx_cb(uint8_t itf);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Inline Functions
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str)
|
||||
{
|
||||
return tud_vendor_n_write(itf, str, strlen(str));
|
||||
}
|
||||
|
||||
static inline bool tud_vendor_mounted (void)
|
||||
{
|
||||
return tud_vendor_n_mounted(0);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_vendor_available (void)
|
||||
{
|
||||
return tud_vendor_n_available(0);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize)
|
||||
{
|
||||
return tud_vendor_n_read(0, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline bool tud_vendor_peek (int pos, uint8_t* u8)
|
||||
{
|
||||
return tud_vendor_n_peek(0, pos, u8);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
return tud_vendor_n_write(0, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_vendor_write_str (char const* str)
|
||||
{
|
||||
return tud_vendor_n_write_str(0, str);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal Class Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
void vendord_init(void);
|
||||
void vendord_reset(uint8_t rhport);
|
||||
bool vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
|
||||
bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_VENDOR_DEVICE_H_ */
|
||||
@@ -1,871 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*
|
||||
* @(#)queue.h 8.5 (Berkeley) 8/20/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _SYS_QUEUE_H_
|
||||
#define _SYS_QUEUE_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
/*
|
||||
* This file defines four types of data structures: singly-linked lists,
|
||||
* singly-linked tail queues, lists and tail queues.
|
||||
*
|
||||
* A singly-linked list is headed by a single forward pointer. The elements
|
||||
* are singly linked for minimum space and pointer manipulation overhead at
|
||||
* the expense of O(n) removal for arbitrary elements. New elements can be
|
||||
* added to the list after an existing element or at the head of the list.
|
||||
* Elements being removed from the head of the list should use the explicit
|
||||
* macro for this purpose for optimum efficiency. A singly-linked list may
|
||||
* only be traversed in the forward direction. Singly-linked lists are ideal
|
||||
* for applications with large datasets and few or no removals or for
|
||||
* implementing a LIFO queue.
|
||||
*
|
||||
* A singly-linked tail queue is headed by a pair of pointers, one to the
|
||||
* head of the list and the other to the tail of the list. The elements are
|
||||
* singly linked for minimum space and pointer manipulation overhead at the
|
||||
* expense of O(n) removal for arbitrary elements. New elements can be added
|
||||
* to the list after an existing element, at the head of the list, or at the
|
||||
* end of the list. Elements being removed from the head of the tail queue
|
||||
* should use the explicit macro for this purpose for optimum efficiency.
|
||||
* A singly-linked tail queue may only be traversed in the forward direction.
|
||||
* Singly-linked tail queues are ideal for applications with large datasets
|
||||
* and few or no removals or for implementing a FIFO queue.
|
||||
*
|
||||
* A list is headed by a single forward pointer (or an array of forward
|
||||
* pointers for a hash table header). The elements are doubly linked
|
||||
* so that an arbitrary element can be removed without a need to
|
||||
* traverse the list. New elements can be added to the list before
|
||||
* or after an existing element or at the head of the list. A list
|
||||
* may be traversed in either direction.
|
||||
*
|
||||
* A tail queue is headed by a pair of pointers, one to the head of the
|
||||
* list and the other to the tail of the list. The elements are doubly
|
||||
* linked so that an arbitrary element can be removed without a need to
|
||||
* traverse the list. New elements can be added to the list before or
|
||||
* after an existing element, at the head of the list, or at the end of
|
||||
* the list. A tail queue may be traversed in either direction.
|
||||
*
|
||||
* For details on the use of these macros, see the queue(3) manual page.
|
||||
*
|
||||
* Below is a summary of implemented functions where:
|
||||
* + means the macro is available
|
||||
* - means the macro is not available
|
||||
* s means the macro is available but is slow (runs in O(n) time)
|
||||
*
|
||||
* SLIST LIST STAILQ TAILQ
|
||||
* _HEAD + + + +
|
||||
* _CLASS_HEAD + + + +
|
||||
* _HEAD_INITIALIZER + + + +
|
||||
* _ENTRY + + + +
|
||||
* _CLASS_ENTRY + + + +
|
||||
* _INIT + + + +
|
||||
* _EMPTY + + + +
|
||||
* _FIRST + + + +
|
||||
* _NEXT + + + +
|
||||
* _PREV - + - +
|
||||
* _LAST - - + +
|
||||
* _LAST_FAST - - - +
|
||||
* _FOREACH + + + +
|
||||
* _FOREACH_FROM + + + +
|
||||
* _FOREACH_SAFE + + + +
|
||||
* _FOREACH_FROM_SAFE + + + +
|
||||
* _FOREACH_REVERSE - - - +
|
||||
* _FOREACH_REVERSE_FROM - - - +
|
||||
* _FOREACH_REVERSE_SAFE - - - +
|
||||
* _FOREACH_REVERSE_FROM_SAFE - - - +
|
||||
* _INSERT_HEAD + + + +
|
||||
* _INSERT_BEFORE - + - +
|
||||
* _INSERT_AFTER + + + +
|
||||
* _INSERT_TAIL - - + +
|
||||
* _CONCAT s s + +
|
||||
* _REMOVE_AFTER + - + -
|
||||
* _REMOVE_HEAD + - + -
|
||||
* _REMOVE s + s +
|
||||
* _SWAP + + + +
|
||||
*
|
||||
*/
|
||||
#ifdef QUEUE_MACRO_DEBUG
|
||||
#warn Use QUEUE_MACRO_DEBUG_TRACE and/or QUEUE_MACRO_DEBUG_TRASH
|
||||
#define QUEUE_MACRO_DEBUG_TRACE
|
||||
#define QUEUE_MACRO_DEBUG_TRASH
|
||||
#endif
|
||||
|
||||
#ifdef QUEUE_MACRO_DEBUG_TRACE
|
||||
/* Store the last 2 places the queue element or head was altered */
|
||||
struct qm_trace {
|
||||
unsigned long lastline;
|
||||
unsigned long prevline;
|
||||
const char *lastfile;
|
||||
const char *prevfile;
|
||||
};
|
||||
|
||||
#define TRACEBUF struct qm_trace trace;
|
||||
#define TRACEBUF_INITIALIZER { __LINE__, 0, __FILE__, NULL } ,
|
||||
|
||||
#define QMD_TRACE_HEAD(head) do { \
|
||||
(head)->trace.prevline = (head)->trace.lastline; \
|
||||
(head)->trace.prevfile = (head)->trace.lastfile; \
|
||||
(head)->trace.lastline = __LINE__; \
|
||||
(head)->trace.lastfile = __FILE__; \
|
||||
} while (0)
|
||||
|
||||
#define QMD_TRACE_ELEM(elem) do { \
|
||||
(elem)->trace.prevline = (elem)->trace.lastline; \
|
||||
(elem)->trace.prevfile = (elem)->trace.lastfile; \
|
||||
(elem)->trace.lastline = __LINE__; \
|
||||
(elem)->trace.lastfile = __FILE__; \
|
||||
} while (0)
|
||||
|
||||
#else /* !QUEUE_MACRO_DEBUG_TRACE */
|
||||
#define QMD_TRACE_ELEM(elem)
|
||||
#define QMD_TRACE_HEAD(head)
|
||||
#define TRACEBUF
|
||||
#define TRACEBUF_INITIALIZER
|
||||
#endif /* QUEUE_MACRO_DEBUG_TRACE */
|
||||
|
||||
#ifdef QUEUE_MACRO_DEBUG_TRASH
|
||||
#define TRASHIT(x) do {(x) = (void *)-1;} while (0)
|
||||
#define QMD_IS_TRASHED(x) ((x) == (void *)(intptr_t)-1)
|
||||
#else /* !QUEUE_MACRO_DEBUG_TRASH */
|
||||
#define TRASHIT(x)
|
||||
#define QMD_IS_TRASHED(x) 0
|
||||
#endif /* QUEUE_MACRO_DEBUG_TRASH */
|
||||
|
||||
#if defined(QUEUE_MACRO_DEBUG_TRACE) || defined(QUEUE_MACRO_DEBUG_TRASH)
|
||||
#define QMD_SAVELINK(name, link) void **name = (void *)&(link)
|
||||
#else /* !QUEUE_MACRO_DEBUG_TRACE && !QUEUE_MACRO_DEBUG_TRASH */
|
||||
#define QMD_SAVELINK(name, link)
|
||||
#endif /* QUEUE_MACRO_DEBUG_TRACE || QUEUE_MACRO_DEBUG_TRASH */
|
||||
|
||||
#ifdef __cplusplus
|
||||
/*
|
||||
* In C++ there can be structure lists and class lists:
|
||||
*/
|
||||
#define QUEUE_TYPEOF(type) type
|
||||
#else
|
||||
#define QUEUE_TYPEOF(type) struct type
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Singly-linked List declarations.
|
||||
*/
|
||||
#define SLIST_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *slh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define SLIST_CLASS_HEAD(name, type) \
|
||||
struct name { \
|
||||
class type *slh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define SLIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
|
||||
#define SLIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *sle_next; /* next element */ \
|
||||
}
|
||||
|
||||
#define SLIST_CLASS_ENTRY(type) \
|
||||
struct { \
|
||||
class type *sle_next; /* next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Singly-linked List functions.
|
||||
*/
|
||||
#if (defined(_KERNEL) && defined(INVARIANTS))
|
||||
#define QMD_SLIST_CHECK_PREVPTR(prevp, elm) do { \
|
||||
if (*(prevp) != (elm)) \
|
||||
panic("Bad prevptr *(%p) == %p != %p", \
|
||||
(prevp), *(prevp), (elm)); \
|
||||
} while (0)
|
||||
#else
|
||||
#define QMD_SLIST_CHECK_PREVPTR(prevp, elm)
|
||||
#endif
|
||||
|
||||
#define SLIST_CONCAT(head1, head2, type, field) do { \
|
||||
QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head1); \
|
||||
if (curelm == NULL) { \
|
||||
if ((SLIST_FIRST(head1) = SLIST_FIRST(head2)) != NULL) \
|
||||
SLIST_INIT(head2); \
|
||||
} else if (SLIST_FIRST(head2) != NULL) { \
|
||||
while (SLIST_NEXT(curelm, field) != NULL) \
|
||||
curelm = SLIST_NEXT(curelm, field); \
|
||||
SLIST_NEXT(curelm, field) = SLIST_FIRST(head2); \
|
||||
SLIST_INIT(head2); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
|
||||
|
||||
#define SLIST_FIRST(head) ((head)->slh_first)
|
||||
|
||||
#define SLIST_FOREACH(var, head, field) \
|
||||
for ((var) = SLIST_FIRST((head)); \
|
||||
(var); \
|
||||
(var) = SLIST_NEXT((var), field))
|
||||
|
||||
#define SLIST_FOREACH_FROM(var, head, field) \
|
||||
for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \
|
||||
(var); \
|
||||
(var) = SLIST_NEXT((var), field))
|
||||
|
||||
#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
|
||||
for ((var) = SLIST_FIRST((head)); \
|
||||
(var) && ((tvar) = SLIST_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define SLIST_FOREACH_FROM_SAFE(var, head, field, tvar) \
|
||||
for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \
|
||||
(var) && ((tvar) = SLIST_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
|
||||
for ((varp) = &SLIST_FIRST((head)); \
|
||||
((var) = *(varp)) != NULL; \
|
||||
(varp) = &SLIST_NEXT((var), field))
|
||||
|
||||
#define SLIST_INIT(head) do { \
|
||||
SLIST_FIRST((head)) = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
|
||||
SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
|
||||
SLIST_NEXT((slistelm), field) = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_INSERT_HEAD(head, elm, field) do { \
|
||||
SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \
|
||||
SLIST_FIRST((head)) = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
|
||||
|
||||
#define SLIST_REMOVE(head, elm, type, field) do { \
|
||||
QMD_SAVELINK(oldnext, (elm)->field.sle_next); \
|
||||
if (SLIST_FIRST((head)) == (elm)) { \
|
||||
SLIST_REMOVE_HEAD((head), field); \
|
||||
} \
|
||||
else { \
|
||||
QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head); \
|
||||
while (SLIST_NEXT(curelm, field) != (elm)) \
|
||||
curelm = SLIST_NEXT(curelm, field); \
|
||||
SLIST_REMOVE_AFTER(curelm, field); \
|
||||
} \
|
||||
TRASHIT(*oldnext); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_REMOVE_AFTER(elm, field) do { \
|
||||
SLIST_NEXT(elm, field) = \
|
||||
SLIST_NEXT(SLIST_NEXT(elm, field), field); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_REMOVE_HEAD(head, field) do { \
|
||||
SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_REMOVE_PREVPTR(prevp, elm, field) do { \
|
||||
QMD_SLIST_CHECK_PREVPTR(prevp, elm); \
|
||||
*(prevp) = SLIST_NEXT(elm, field); \
|
||||
TRASHIT((elm)->field.sle_next); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_SWAP(head1, head2, type) do { \
|
||||
QUEUE_TYPEOF(type) *swap_first = SLIST_FIRST(head1); \
|
||||
SLIST_FIRST(head1) = SLIST_FIRST(head2); \
|
||||
SLIST_FIRST(head2) = swap_first; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Singly-linked Tail queue declarations.
|
||||
*/
|
||||
#define STAILQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *stqh_first;/* first element */ \
|
||||
struct type **stqh_last;/* addr of last next element */ \
|
||||
}
|
||||
|
||||
#define STAILQ_CLASS_HEAD(name, type) \
|
||||
struct name { \
|
||||
class type *stqh_first; /* first element */ \
|
||||
class type **stqh_last; /* addr of last next element */ \
|
||||
}
|
||||
|
||||
#define STAILQ_HEAD_INITIALIZER(head) \
|
||||
{ NULL, &(head).stqh_first }
|
||||
|
||||
#define STAILQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *stqe_next; /* next element */ \
|
||||
}
|
||||
|
||||
#define STAILQ_CLASS_ENTRY(type) \
|
||||
struct { \
|
||||
class type *stqe_next; /* next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Singly-linked Tail queue functions.
|
||||
*/
|
||||
#define STAILQ_CONCAT(head1, head2) do { \
|
||||
if (!STAILQ_EMPTY((head2))) { \
|
||||
*(head1)->stqh_last = (head2)->stqh_first; \
|
||||
(head1)->stqh_last = (head2)->stqh_last; \
|
||||
STAILQ_INIT((head2)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
|
||||
|
||||
#define STAILQ_FIRST(head) ((head)->stqh_first)
|
||||
|
||||
#define STAILQ_FOREACH(var, head, field) \
|
||||
for((var) = STAILQ_FIRST((head)); \
|
||||
(var); \
|
||||
(var) = STAILQ_NEXT((var), field))
|
||||
|
||||
#define STAILQ_FOREACH_FROM(var, head, field) \
|
||||
for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \
|
||||
(var); \
|
||||
(var) = STAILQ_NEXT((var), field))
|
||||
|
||||
#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
|
||||
for ((var) = STAILQ_FIRST((head)); \
|
||||
(var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define STAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \
|
||||
for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \
|
||||
(var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define STAILQ_INIT(head) do { \
|
||||
STAILQ_FIRST((head)) = NULL; \
|
||||
(head)->stqh_last = &STAILQ_FIRST((head)); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
|
||||
if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
|
||||
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
|
||||
STAILQ_NEXT((tqelm), field) = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_INSERT_HEAD(head, elm, field) do { \
|
||||
if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
|
||||
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
|
||||
STAILQ_FIRST((head)) = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_INSERT_TAIL(head, elm, field) do { \
|
||||
STAILQ_NEXT((elm), field) = NULL; \
|
||||
*(head)->stqh_last = (elm); \
|
||||
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_LAST(head, type, field) \
|
||||
(STAILQ_EMPTY((head)) ? NULL : \
|
||||
__containerof((head)->stqh_last, \
|
||||
QUEUE_TYPEOF(type), field.stqe_next))
|
||||
|
||||
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
|
||||
|
||||
#define STAILQ_REMOVE(head, elm, type, field) do { \
|
||||
QMD_SAVELINK(oldnext, (elm)->field.stqe_next); \
|
||||
if (STAILQ_FIRST((head)) == (elm)) { \
|
||||
STAILQ_REMOVE_HEAD((head), field); \
|
||||
} \
|
||||
else { \
|
||||
QUEUE_TYPEOF(type) *curelm = STAILQ_FIRST(head); \
|
||||
while (STAILQ_NEXT(curelm, field) != (elm)) \
|
||||
curelm = STAILQ_NEXT(curelm, field); \
|
||||
STAILQ_REMOVE_AFTER(head, curelm, field); \
|
||||
} \
|
||||
TRASHIT(*oldnext); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_REMOVE_AFTER(head, elm, field) do { \
|
||||
if ((STAILQ_NEXT(elm, field) = \
|
||||
STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \
|
||||
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_REMOVE_HEAD(head, field) do { \
|
||||
if ((STAILQ_FIRST((head)) = \
|
||||
STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
|
||||
(head)->stqh_last = &STAILQ_FIRST((head)); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_SWAP(head1, head2, type) do { \
|
||||
QUEUE_TYPEOF(type) *swap_first = STAILQ_FIRST(head1); \
|
||||
QUEUE_TYPEOF(type) **swap_last = (head1)->stqh_last; \
|
||||
STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \
|
||||
(head1)->stqh_last = (head2)->stqh_last; \
|
||||
STAILQ_FIRST(head2) = swap_first; \
|
||||
(head2)->stqh_last = swap_last; \
|
||||
if (STAILQ_EMPTY(head1)) \
|
||||
(head1)->stqh_last = &STAILQ_FIRST(head1); \
|
||||
if (STAILQ_EMPTY(head2)) \
|
||||
(head2)->stqh_last = &STAILQ_FIRST(head2); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*
|
||||
* List declarations.
|
||||
*/
|
||||
#define LIST_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *lh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define LIST_CLASS_HEAD(name, type) \
|
||||
struct name { \
|
||||
class type *lh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define LIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
|
||||
#define LIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *le_next; /* next element */ \
|
||||
struct type **le_prev; /* address of previous next element */ \
|
||||
}
|
||||
|
||||
#define LIST_CLASS_ENTRY(type) \
|
||||
struct { \
|
||||
class type *le_next; /* next element */ \
|
||||
class type **le_prev; /* address of previous next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* List functions.
|
||||
*/
|
||||
|
||||
#if (defined(_KERNEL) && defined(INVARIANTS))
|
||||
/*
|
||||
* QMD_LIST_CHECK_HEAD(LIST_HEAD *head, LIST_ENTRY NAME)
|
||||
*
|
||||
* If the list is non-empty, validates that the first element of the list
|
||||
* points back at 'head.'
|
||||
*/
|
||||
#define QMD_LIST_CHECK_HEAD(head, field) do { \
|
||||
if (LIST_FIRST((head)) != NULL && \
|
||||
LIST_FIRST((head))->field.le_prev != \
|
||||
&LIST_FIRST((head))) \
|
||||
panic("Bad list head %p first->prev != head", (head)); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* QMD_LIST_CHECK_NEXT(TYPE *elm, LIST_ENTRY NAME)
|
||||
*
|
||||
* If an element follows 'elm' in the list, validates that the next element
|
||||
* points back at 'elm.'
|
||||
*/
|
||||
#define QMD_LIST_CHECK_NEXT(elm, field) do { \
|
||||
if (LIST_NEXT((elm), field) != NULL && \
|
||||
LIST_NEXT((elm), field)->field.le_prev != \
|
||||
&((elm)->field.le_next)) \
|
||||
panic("Bad link elm %p next->prev != elm", (elm)); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* QMD_LIST_CHECK_PREV(TYPE *elm, LIST_ENTRY NAME)
|
||||
*
|
||||
* Validates that the previous element (or head of the list) points to 'elm.'
|
||||
*/
|
||||
#define QMD_LIST_CHECK_PREV(elm, field) do { \
|
||||
if (*(elm)->field.le_prev != (elm)) \
|
||||
panic("Bad link elm %p prev->next != elm", (elm)); \
|
||||
} while (0)
|
||||
#else
|
||||
#define QMD_LIST_CHECK_HEAD(head, field)
|
||||
#define QMD_LIST_CHECK_NEXT(elm, field)
|
||||
#define QMD_LIST_CHECK_PREV(elm, field)
|
||||
#endif /* (_KERNEL && INVARIANTS) */
|
||||
|
||||
#define LIST_CONCAT(head1, head2, type, field) do { \
|
||||
QUEUE_TYPEOF(type) *curelm = LIST_FIRST(head1); \
|
||||
if (curelm == NULL) { \
|
||||
if ((LIST_FIRST(head1) = LIST_FIRST(head2)) != NULL) { \
|
||||
LIST_FIRST(head2)->field.le_prev = \
|
||||
&LIST_FIRST((head1)); \
|
||||
LIST_INIT(head2); \
|
||||
} \
|
||||
} else if (LIST_FIRST(head2) != NULL) { \
|
||||
while (LIST_NEXT(curelm, field) != NULL) \
|
||||
curelm = LIST_NEXT(curelm, field); \
|
||||
LIST_NEXT(curelm, field) = LIST_FIRST(head2); \
|
||||
LIST_FIRST(head2)->field.le_prev = &LIST_NEXT(curelm, field); \
|
||||
LIST_INIT(head2); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
|
||||
|
||||
#define LIST_FIRST(head) ((head)->lh_first)
|
||||
|
||||
#define LIST_FOREACH(var, head, field) \
|
||||
for ((var) = LIST_FIRST((head)); \
|
||||
(var); \
|
||||
(var) = LIST_NEXT((var), field))
|
||||
|
||||
#define LIST_FOREACH_FROM(var, head, field) \
|
||||
for ((var) = ((var) ? (var) : LIST_FIRST((head))); \
|
||||
(var); \
|
||||
(var) = LIST_NEXT((var), field))
|
||||
|
||||
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
|
||||
for ((var) = LIST_FIRST((head)); \
|
||||
(var) && ((tvar) = LIST_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define LIST_FOREACH_FROM_SAFE(var, head, field, tvar) \
|
||||
for ((var) = ((var) ? (var) : LIST_FIRST((head))); \
|
||||
(var) && ((tvar) = LIST_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define LIST_INIT(head) do { \
|
||||
LIST_FIRST((head)) = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
|
||||
QMD_LIST_CHECK_NEXT(listelm, field); \
|
||||
if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
|
||||
LIST_NEXT((listelm), field)->field.le_prev = \
|
||||
&LIST_NEXT((elm), field); \
|
||||
LIST_NEXT((listelm), field) = (elm); \
|
||||
(elm)->field.le_prev = &LIST_NEXT((listelm), field); \
|
||||
} while (0)
|
||||
|
||||
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
|
||||
QMD_LIST_CHECK_PREV(listelm, field); \
|
||||
(elm)->field.le_prev = (listelm)->field.le_prev; \
|
||||
LIST_NEXT((elm), field) = (listelm); \
|
||||
*(listelm)->field.le_prev = (elm); \
|
||||
(listelm)->field.le_prev = &LIST_NEXT((elm), field); \
|
||||
} while (0)
|
||||
|
||||
#define LIST_INSERT_HEAD(head, elm, field) do { \
|
||||
QMD_LIST_CHECK_HEAD((head), field); \
|
||||
if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
|
||||
LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
|
||||
LIST_FIRST((head)) = (elm); \
|
||||
(elm)->field.le_prev = &LIST_FIRST((head)); \
|
||||
} while (0)
|
||||
|
||||
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
|
||||
|
||||
#define LIST_PREV(elm, head, type, field) \
|
||||
((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL : \
|
||||
__containerof((elm)->field.le_prev, \
|
||||
QUEUE_TYPEOF(type), field.le_next))
|
||||
|
||||
#define LIST_REMOVE(elm, field) do { \
|
||||
QMD_SAVELINK(oldnext, (elm)->field.le_next); \
|
||||
QMD_SAVELINK(oldprev, (elm)->field.le_prev); \
|
||||
QMD_LIST_CHECK_NEXT(elm, field); \
|
||||
QMD_LIST_CHECK_PREV(elm, field); \
|
||||
if (LIST_NEXT((elm), field) != NULL) \
|
||||
LIST_NEXT((elm), field)->field.le_prev = \
|
||||
(elm)->field.le_prev; \
|
||||
*(elm)->field.le_prev = LIST_NEXT((elm), field); \
|
||||
TRASHIT(*oldnext); \
|
||||
TRASHIT(*oldprev); \
|
||||
} while (0)
|
||||
|
||||
#define LIST_SWAP(head1, head2, type, field) do { \
|
||||
QUEUE_TYPEOF(type) *swap_tmp = LIST_FIRST(head1); \
|
||||
LIST_FIRST((head1)) = LIST_FIRST((head2)); \
|
||||
LIST_FIRST((head2)) = swap_tmp; \
|
||||
if ((swap_tmp = LIST_FIRST((head1))) != NULL) \
|
||||
swap_tmp->field.le_prev = &LIST_FIRST((head1)); \
|
||||
if ((swap_tmp = LIST_FIRST((head2))) != NULL) \
|
||||
swap_tmp->field.le_prev = &LIST_FIRST((head2)); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Tail queue declarations.
|
||||
*/
|
||||
#define TAILQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *tqh_first; /* first element */ \
|
||||
struct type **tqh_last; /* addr of last next element */ \
|
||||
TRACEBUF \
|
||||
}
|
||||
|
||||
#define TAILQ_CLASS_HEAD(name, type) \
|
||||
struct name { \
|
||||
class type *tqh_first; /* first element */ \
|
||||
class type **tqh_last; /* addr of last next element */ \
|
||||
TRACEBUF \
|
||||
}
|
||||
|
||||
#define TAILQ_HEAD_INITIALIZER(head) \
|
||||
{ NULL, &(head).tqh_first, TRACEBUF_INITIALIZER }
|
||||
|
||||
#define TAILQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *tqe_next; /* next element */ \
|
||||
struct type **tqe_prev; /* address of previous next element */ \
|
||||
TRACEBUF \
|
||||
}
|
||||
|
||||
#define TAILQ_CLASS_ENTRY(type) \
|
||||
struct { \
|
||||
class type *tqe_next; /* next element */ \
|
||||
class type **tqe_prev; /* address of previous next element */ \
|
||||
TRACEBUF \
|
||||
}
|
||||
|
||||
/*
|
||||
* Tail queue functions.
|
||||
*/
|
||||
#if (defined(_KERNEL) && defined(INVARIANTS))
|
||||
/*
|
||||
* QMD_TAILQ_CHECK_HEAD(TAILQ_HEAD *head, TAILQ_ENTRY NAME)
|
||||
*
|
||||
* If the tailq is non-empty, validates that the first element of the tailq
|
||||
* points back at 'head.'
|
||||
*/
|
||||
#define QMD_TAILQ_CHECK_HEAD(head, field) do { \
|
||||
if (!TAILQ_EMPTY(head) && \
|
||||
TAILQ_FIRST((head))->field.tqe_prev != \
|
||||
&TAILQ_FIRST((head))) \
|
||||
panic("Bad tailq head %p first->prev != head", (head)); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* QMD_TAILQ_CHECK_TAIL(TAILQ_HEAD *head, TAILQ_ENTRY NAME)
|
||||
*
|
||||
* Validates that the tail of the tailq is a pointer to pointer to NULL.
|
||||
*/
|
||||
#define QMD_TAILQ_CHECK_TAIL(head, field) do { \
|
||||
if (*(head)->tqh_last != NULL) \
|
||||
panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* QMD_TAILQ_CHECK_NEXT(TYPE *elm, TAILQ_ENTRY NAME)
|
||||
*
|
||||
* If an element follows 'elm' in the tailq, validates that the next element
|
||||
* points back at 'elm.'
|
||||
*/
|
||||
#define QMD_TAILQ_CHECK_NEXT(elm, field) do { \
|
||||
if (TAILQ_NEXT((elm), field) != NULL && \
|
||||
TAILQ_NEXT((elm), field)->field.tqe_prev != \
|
||||
&((elm)->field.tqe_next)) \
|
||||
panic("Bad link elm %p next->prev != elm", (elm)); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* QMD_TAILQ_CHECK_PREV(TYPE *elm, TAILQ_ENTRY NAME)
|
||||
*
|
||||
* Validates that the previous element (or head of the tailq) points to 'elm.'
|
||||
*/
|
||||
#define QMD_TAILQ_CHECK_PREV(elm, field) do { \
|
||||
if (*(elm)->field.tqe_prev != (elm)) \
|
||||
panic("Bad link elm %p prev->next != elm", (elm)); \
|
||||
} while (0)
|
||||
#else
|
||||
#define QMD_TAILQ_CHECK_HEAD(head, field)
|
||||
#define QMD_TAILQ_CHECK_TAIL(head, headname)
|
||||
#define QMD_TAILQ_CHECK_NEXT(elm, field)
|
||||
#define QMD_TAILQ_CHECK_PREV(elm, field)
|
||||
#endif /* (_KERNEL && INVARIANTS) */
|
||||
|
||||
#define TAILQ_CONCAT(head1, head2, field) do { \
|
||||
if (!TAILQ_EMPTY(head2)) { \
|
||||
*(head1)->tqh_last = (head2)->tqh_first; \
|
||||
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
|
||||
(head1)->tqh_last = (head2)->tqh_last; \
|
||||
TAILQ_INIT((head2)); \
|
||||
QMD_TRACE_HEAD(head1); \
|
||||
QMD_TRACE_HEAD(head2); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
|
||||
|
||||
#define TAILQ_FIRST(head) ((head)->tqh_first)
|
||||
|
||||
#define TAILQ_FOREACH(var, head, field) \
|
||||
for ((var) = TAILQ_FIRST((head)); \
|
||||
(var); \
|
||||
(var) = TAILQ_NEXT((var), field))
|
||||
|
||||
#define TAILQ_FOREACH_FROM(var, head, field) \
|
||||
for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \
|
||||
(var); \
|
||||
(var) = TAILQ_NEXT((var), field))
|
||||
|
||||
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
|
||||
for ((var) = TAILQ_FIRST((head)); \
|
||||
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \
|
||||
for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \
|
||||
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
|
||||
for ((var) = TAILQ_LAST((head), headname); \
|
||||
(var); \
|
||||
(var) = TAILQ_PREV((var), headname, field))
|
||||
|
||||
#define TAILQ_FOREACH_REVERSE_FROM(var, head, headname, field) \
|
||||
for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \
|
||||
(var); \
|
||||
(var) = TAILQ_PREV((var), headname, field))
|
||||
|
||||
#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
|
||||
for ((var) = TAILQ_LAST((head), headname); \
|
||||
(var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define TAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \
|
||||
for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \
|
||||
(var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define TAILQ_INIT(head) do { \
|
||||
TAILQ_FIRST((head)) = NULL; \
|
||||
(head)->tqh_last = &TAILQ_FIRST((head)); \
|
||||
QMD_TRACE_HEAD(head); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
|
||||
QMD_TAILQ_CHECK_NEXT(listelm, field); \
|
||||
if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
|
||||
TAILQ_NEXT((elm), field)->field.tqe_prev = \
|
||||
&TAILQ_NEXT((elm), field); \
|
||||
else { \
|
||||
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
|
||||
QMD_TRACE_HEAD(head); \
|
||||
} \
|
||||
TAILQ_NEXT((listelm), field) = (elm); \
|
||||
(elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
|
||||
QMD_TRACE_ELEM(&(elm)->field); \
|
||||
QMD_TRACE_ELEM(&(listelm)->field); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
|
||||
QMD_TAILQ_CHECK_PREV(listelm, field); \
|
||||
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
|
||||
TAILQ_NEXT((elm), field) = (listelm); \
|
||||
*(listelm)->field.tqe_prev = (elm); \
|
||||
(listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
|
||||
QMD_TRACE_ELEM(&(elm)->field); \
|
||||
QMD_TRACE_ELEM(&(listelm)->field); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
|
||||
QMD_TAILQ_CHECK_HEAD(head, field); \
|
||||
if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
|
||||
TAILQ_FIRST((head))->field.tqe_prev = \
|
||||
&TAILQ_NEXT((elm), field); \
|
||||
else \
|
||||
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
|
||||
TAILQ_FIRST((head)) = (elm); \
|
||||
(elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
|
||||
QMD_TRACE_HEAD(head); \
|
||||
QMD_TRACE_ELEM(&(elm)->field); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
|
||||
QMD_TAILQ_CHECK_TAIL(head, field); \
|
||||
TAILQ_NEXT((elm), field) = NULL; \
|
||||
(elm)->field.tqe_prev = (head)->tqh_last; \
|
||||
*(head)->tqh_last = (elm); \
|
||||
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
|
||||
QMD_TRACE_HEAD(head); \
|
||||
QMD_TRACE_ELEM(&(elm)->field); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_LAST(head, headname) \
|
||||
(*(((struct headname *)((head)->tqh_last))->tqh_last))
|
||||
|
||||
/*
|
||||
* The FAST function is fast in that it causes no data access other
|
||||
* then the access to the head. The standard LAST function above
|
||||
* will cause a data access of both the element you want and
|
||||
* the previous element. FAST is very useful for instances when
|
||||
* you may want to prefetch the last data element.
|
||||
*/
|
||||
#define TAILQ_LAST_FAST(head, type, field) \
|
||||
(TAILQ_EMPTY(head) ? NULL : __containerof((head)->tqh_last, QUEUE_TYPEOF(type), field.tqe_next))
|
||||
|
||||
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
|
||||
|
||||
#define TAILQ_PREV(elm, headname, field) \
|
||||
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
|
||||
|
||||
#define TAILQ_REMOVE(head, elm, field) do { \
|
||||
QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \
|
||||
QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \
|
||||
QMD_TAILQ_CHECK_NEXT(elm, field); \
|
||||
QMD_TAILQ_CHECK_PREV(elm, field); \
|
||||
if ((TAILQ_NEXT((elm), field)) != NULL) \
|
||||
TAILQ_NEXT((elm), field)->field.tqe_prev = \
|
||||
(elm)->field.tqe_prev; \
|
||||
else { \
|
||||
(head)->tqh_last = (elm)->field.tqe_prev; \
|
||||
QMD_TRACE_HEAD(head); \
|
||||
} \
|
||||
*(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
|
||||
TRASHIT(*oldnext); \
|
||||
TRASHIT(*oldprev); \
|
||||
QMD_TRACE_ELEM(&(elm)->field); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_SWAP(head1, head2, type, field) do { \
|
||||
QUEUE_TYPEOF(type) *swap_first = (head1)->tqh_first; \
|
||||
QUEUE_TYPEOF(type) **swap_last = (head1)->tqh_last; \
|
||||
(head1)->tqh_first = (head2)->tqh_first; \
|
||||
(head1)->tqh_last = (head2)->tqh_last; \
|
||||
(head2)->tqh_first = swap_first; \
|
||||
(head2)->tqh_last = swap_last; \
|
||||
if ((swap_first = (head1)->tqh_first) != NULL) \
|
||||
swap_first->field.tqe_prev = &(head1)->tqh_first; \
|
||||
else \
|
||||
(head1)->tqh_last = &(head1)->tqh_first; \
|
||||
if ((swap_first = (head2)->tqh_first) != NULL) \
|
||||
swap_first->field.tqe_prev = &(head2)->tqh_first; \
|
||||
else \
|
||||
(head2)->tqh_last = &(head2)->tqh_first; \
|
||||
} while (0)
|
||||
|
||||
#endif /* !_SYS_QUEUE_H_ */
|
||||
@@ -1,207 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup Group_CommonH common.h
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_COMMON_H_
|
||||
#define _TUSB_COMMON_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Macros Helper
|
||||
//--------------------------------------------------------------------+
|
||||
#define TU_ARRAY_SZIE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
|
||||
#define TU_MIN(_x, _y) ( (_x) < (_y) ) ? (_x) : (_y) )
|
||||
#define TU_MAX(_x, _y) ( (_x) > (_y) ) ? (_x) : (_y) )
|
||||
|
||||
#define TU_U16_HIGH(u16) ((uint8_t) (((u16) >> 8) & 0x00ff))
|
||||
#define TU_U16_LOW(u16) ((uint8_t) ((u16) & 0x00ff))
|
||||
#define U16_TO_U8S_BE(u16) TU_U16_HIGH(u16), TU_U16_LOW(u16)
|
||||
#define U16_TO_U8S_LE(u16) TU_U16_LOW(u16), TU_U16_HIGH(u16)
|
||||
|
||||
#define U32_B1_U8(u32) ((uint8_t) (((u32) >> 24) & 0x000000ff)) // MSB
|
||||
#define U32_B2_U8(u32) ((uint8_t) (((u32) >> 16) & 0x000000ff))
|
||||
#define U32_B3_U8(u32) ((uint8_t) (((u32) >> 8) & 0x000000ff))
|
||||
#define U32_B4_U8(u32) ((uint8_t) ((u32) & 0x000000ff)) // LSB
|
||||
|
||||
#define U32_TO_U8S_BE(u32) U32_B1_U8(u32), U32_B2_U8(u32), U32_B3_U8(u32), U32_B4_U8(u32)
|
||||
#define U32_TO_U8S_LE(u32) U32_B4_U8(u32), U32_B3_U8(u32), U32_B2_U8(u32), U32_B1_U8(u32)
|
||||
|
||||
#define TU_BIT(n) (1U << (n))
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDES
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Standard Headers
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Tinyusb Common Headers
|
||||
#include "tusb_option.h"
|
||||
#include "tusb_compiler.h"
|
||||
#include "tusb_verify.h"
|
||||
#include "tusb_error.h" // TODO remove
|
||||
#include "tusb_timeout.h"
|
||||
#include "tusb_types.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INLINE FUNCTION
|
||||
//--------------------------------------------------------------------+
|
||||
#define tu_memclr(buffer, size) memset((buffer), 0, (size))
|
||||
#define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var)))
|
||||
|
||||
static inline uint32_t tu_u32(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4)
|
||||
{
|
||||
return ( ((uint32_t) b1) << 24) + ( ((uint32_t) b2) << 16) + ( ((uint32_t) b3) << 8) + b4;
|
||||
}
|
||||
|
||||
static inline uint16_t tu_u16(uint8_t high, uint8_t low)
|
||||
{
|
||||
return (((uint16_t) high) << 8) + low;
|
||||
}
|
||||
|
||||
static inline uint8_t tu_u16_high(uint16_t u16) { return (uint8_t) (((uint16_t) (u16 >> 8)) & 0x00ff); }
|
||||
static inline uint8_t tu_u16_low (uint16_t u16) { return (uint8_t) (u16 & 0x00ff); }
|
||||
|
||||
// Min
|
||||
static inline uint8_t tu_min8 (uint8_t x, uint8_t y ) { return (x < y) ? x : y; }
|
||||
static inline uint16_t tu_min16 (uint16_t x, uint16_t y) { return (x < y) ? x : y; }
|
||||
static inline uint32_t tu_min32 (uint32_t x, uint32_t y) { return (x < y) ? x : y; }
|
||||
|
||||
// Max
|
||||
static inline uint8_t tu_max8 (uint8_t x, uint8_t y ) { return (x > y) ? x : y; }
|
||||
static inline uint16_t tu_max16 (uint16_t x, uint16_t y) { return (x > y) ? x : y; }
|
||||
static inline uint32_t tu_max32 (uint32_t x, uint32_t y) { return (x > y) ? x : y; }
|
||||
|
||||
// Align
|
||||
static inline uint32_t tu_align32 (uint32_t value) { return (value & 0xFFFFFFE0UL); }
|
||||
static inline uint32_t tu_align16 (uint32_t value) { return (value & 0xFFFFFFF0UL); }
|
||||
static inline uint32_t tu_align4k (uint32_t value) { return (value & 0xFFFFF000UL); }
|
||||
static inline uint32_t tu_offset4k(uint32_t value) { return (value & 0xFFFUL); }
|
||||
|
||||
//------------- Mathematics -------------//
|
||||
static inline uint32_t tu_abs(int32_t value) { return (value < 0) ? (-value) : value; }
|
||||
|
||||
/// inclusive range checking
|
||||
static inline bool tu_within(uint32_t lower, uint32_t value, uint32_t upper)
|
||||
{
|
||||
return (lower <= value) && (value <= upper);
|
||||
}
|
||||
|
||||
// log2 of a value is its MSB's position
|
||||
// TODO use clz TODO remove
|
||||
static inline uint8_t tu_log2(uint32_t value)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
|
||||
while (value >>= 1)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Bit
|
||||
static inline uint32_t tu_bit_set (uint32_t value, uint8_t n) { return value | TU_BIT(n); }
|
||||
static inline uint32_t tu_bit_clear(uint32_t value, uint8_t n) { return value & (~TU_BIT(n)); }
|
||||
static inline bool tu_bit_test (uint32_t value, uint8_t n) { return (value & TU_BIT(n)) ? true : false; }
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Count number of arguments of __VA_ARGS__
|
||||
* - reference https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s
|
||||
* - _GET_NTH_ARG() takes args >= N (64) but only expand to Nth one (64th)
|
||||
* - _RSEQ_N() is reverse sequential to N to add padding to have
|
||||
* Nth position is the same as the number of arguments
|
||||
* - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma)
|
||||
*------------------------------------------------------------------*/
|
||||
#ifndef TU_ARGS_NUM
|
||||
|
||||
#define TU_ARGS_NUM(...) NARG_(_0, ##__VA_ARGS__,_RSEQ_N())
|
||||
|
||||
#define NARG_(...) _GET_NTH_ARG(__VA_ARGS__)
|
||||
#define _GET_NTH_ARG( \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
|
||||
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
|
||||
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
|
||||
_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
|
||||
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
|
||||
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
|
||||
_61,_62,_63,N,...) N
|
||||
#define _RSEQ_N() \
|
||||
62,61,60, \
|
||||
59,58,57,56,55,54,53,52,51,50, \
|
||||
49,48,47,46,45,44,43,42,41,40, \
|
||||
39,38,37,36,35,34,33,32,31,30, \
|
||||
29,28,27,26,25,24,23,22,21,20, \
|
||||
19,18,17,16,15,14,13,12,11,10, \
|
||||
9,8,7,6,5,4,3,2,1,0
|
||||
#endif
|
||||
|
||||
// To be removed
|
||||
//------------- Binary constant -------------//
|
||||
#if defined(__GNUC__) && !defined(__CC_ARM)
|
||||
|
||||
#define TU_BIN8(x) ((uint8_t) (0b##x))
|
||||
#define TU_BIN16(b1, b2) ((uint16_t) (0b##b1##b2))
|
||||
#define TU_BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4))
|
||||
|
||||
#else
|
||||
|
||||
// internal macro of B8, B16, B32
|
||||
#define _B8__(x) (((x&0x0000000FUL)?1:0) \
|
||||
+((x&0x000000F0UL)?2:0) \
|
||||
+((x&0x00000F00UL)?4:0) \
|
||||
+((x&0x0000F000UL)?8:0) \
|
||||
+((x&0x000F0000UL)?16:0) \
|
||||
+((x&0x00F00000UL)?32:0) \
|
||||
+((x&0x0F000000UL)?64:0) \
|
||||
+((x&0xF0000000UL)?128:0))
|
||||
|
||||
#define TU_BIN8(d) ((uint8_t) _B8__(0x##d##UL))
|
||||
#define TU_BIN16(dmsb,dlsb) (((uint16_t)TU_BIN8(dmsb)<<8) + TU_BIN8(dlsb))
|
||||
#define TU_BIN32(dmsb,db2,db3,dlsb) \
|
||||
(((uint32_t)TU_BIN8(dmsb)<<24) \
|
||||
+ ((uint32_t)TU_BIN8(db2)<<16) \
|
||||
+ ((uint32_t)TU_BIN8(db3)<<8) \
|
||||
+ TU_BIN8(dlsb))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_COMMON_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -1,88 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup Group_Compiler Compiler
|
||||
* \brief Group_Compiler brief
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_COMPILER_H_
|
||||
#define _TUSB_COMPILER_H_
|
||||
|
||||
#define TU_STRING(x) #x ///< stringify without expand
|
||||
#define TU_XSTRING(x) TU_STRING(x) ///< expand then stringify
|
||||
#define TU_STRCAT(a, b) a##b ///< concat without expand
|
||||
#define TU_XSTRCAT(a, b) TU_STRCAT(a, b) ///< expand then concat
|
||||
|
||||
#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
|
||||
#define _TU_COUNTER_ __COUNTER__
|
||||
#else
|
||||
#define _TU_COUNTER_ __LINE__
|
||||
#endif
|
||||
|
||||
// Compile-time Assert
|
||||
#if __STDC_VERSION__ >= 201112L
|
||||
#define TU_VERIFY_STATIC _Static_assert
|
||||
#else
|
||||
#define TU_VERIFY_STATIC(const_expr, _mess) enum { TU_XSTRCAT(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) }
|
||||
#endif
|
||||
|
||||
// for declaration of reserved field, make use of _TU_COUNTER_
|
||||
#define TU_RESERVED TU_XSTRCAT(reserved, _TU_COUNTER_)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Compiler porting with Attribute and Endian
|
||||
//--------------------------------------------------------------------+
|
||||
#if defined(__GNUC__)
|
||||
#define TU_ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
|
||||
#define TU_ATTR_SECTION(sec_name) __attribute__ ((section(#sec_name)))
|
||||
#define TU_ATTR_PACKED __attribute__ ((packed))
|
||||
#define TU_ATTR_PREPACKED
|
||||
#define TU_ATTR_WEAK __attribute__ ((weak))
|
||||
#define TU_ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used
|
||||
#define TU_ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused
|
||||
|
||||
// Endian conversion use well-known host to network (big endian) naming
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define tu_htonl(u32) __builtin_bswap32(u32)
|
||||
#define tu_ntohl(u32) __builtin_bswap32(u32)
|
||||
|
||||
#define tu_htons(u16) __builtin_bswap16(u16)
|
||||
#define tu_ntohs(u16) __builtin_bswap16(u16)
|
||||
#else
|
||||
#define tu_htonl(u32) (u32)
|
||||
#define tu_ntohl(u32) (u32)
|
||||
|
||||
#define tu_htons(u16) (u16)
|
||||
#define tu_ntohs(u16) (u16)
|
||||
#endif
|
||||
#else
|
||||
#error "Compiler attribute porting are required"
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_COMPILER_H_ */
|
||||
|
||||
/// @}
|
||||
@@ -1,74 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup Group_Error Error Codes
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_ERRORS_H_
|
||||
#define _TUSB_ERRORS_H_
|
||||
|
||||
#include "tusb_option.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ERROR_ENUM(x) x,
|
||||
#define ERROR_STRING(x) #x,
|
||||
|
||||
#define ERROR_TABLE(ENTRY) \
|
||||
ENTRY(TUSB_ERROR_NONE )\
|
||||
ENTRY(TUSB_ERROR_INVALID_PARA )\
|
||||
ENTRY(TUSB_ERROR_DEVICE_NOT_READY )\
|
||||
ENTRY(TUSB_ERROR_INTERFACE_IS_BUSY )\
|
||||
ENTRY(TUSB_ERROR_HCD_OPEN_PIPE_FAILED )\
|
||||
ENTRY(TUSB_ERROR_OSAL_TIMEOUT )\
|
||||
ENTRY(TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED )\
|
||||
ENTRY(TUSB_ERROR_MSCH_DEVICE_NOT_MOUNTED )\
|
||||
ENTRY(TUSB_ERROR_NOT_SUPPORTED )\
|
||||
ENTRY(TUSB_ERROR_NOT_ENOUGH_MEMORY )\
|
||||
ENTRY(TUSB_ERROR_FAILED )\
|
||||
|
||||
/// \brief Error Code returned
|
||||
typedef enum
|
||||
{
|
||||
ERROR_TABLE(ERROR_ENUM)
|
||||
TUSB_ERROR_COUNT
|
||||
}tusb_error_t;
|
||||
|
||||
#if CFG_TUSB_DEBUG
|
||||
/// Enum to String for debugging purposes. Only available if \ref CFG_TUSB_DEBUG > 0
|
||||
extern char const* const tusb_strerr[TUSB_ERROR_COUNT];
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_ERRORS_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -1,288 +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 <string.h>
|
||||
|
||||
#include "osal/osal.h"
|
||||
#include "tusb_fifo.h"
|
||||
|
||||
// implement mutex lock and unlock
|
||||
#if CFG_FIFO_MUTEX
|
||||
|
||||
static void tu_fifo_lock(tu_fifo_t *f)
|
||||
{
|
||||
if (f->mutex)
|
||||
{
|
||||
osal_mutex_lock(f->mutex, OSAL_TIMEOUT_WAIT_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
static void tu_fifo_unlock(tu_fifo_t *f)
|
||||
{
|
||||
if (f->mutex)
|
||||
{
|
||||
osal_mutex_unlock(f->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define tu_fifo_lock(_ff)
|
||||
#define tu_fifo_unlock(_ff)
|
||||
|
||||
#endif
|
||||
|
||||
bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable)
|
||||
{
|
||||
tu_fifo_lock(f);
|
||||
|
||||
f->buffer = (uint8_t*) buffer;
|
||||
f->depth = depth;
|
||||
f->item_size = item_size;
|
||||
f->overwritable = overwritable;
|
||||
|
||||
f->rd_idx = f->wr_idx = f->count = 0;
|
||||
|
||||
tu_fifo_unlock(f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// retrieve data from fifo
|
||||
static void _tu_ff_pull(tu_fifo_t* f, void * buffer)
|
||||
{
|
||||
memcpy(buffer,
|
||||
f->buffer + (f->rd_idx * f->item_size),
|
||||
f->item_size);
|
||||
|
||||
f->rd_idx = (f->rd_idx + 1) % f->depth;
|
||||
f->count--;
|
||||
}
|
||||
|
||||
// send data to fifo
|
||||
static void _tu_ff_push(tu_fifo_t* f, void const * data)
|
||||
{
|
||||
memcpy( f->buffer + (f->wr_idx * f->item_size),
|
||||
data,
|
||||
f->item_size);
|
||||
|
||||
f->wr_idx = (f->wr_idx + 1) % f->depth;
|
||||
|
||||
if (tu_fifo_full(f))
|
||||
{
|
||||
f->rd_idx = f->wr_idx; // keep the full state (rd == wr && len = size)
|
||||
}
|
||||
else
|
||||
{
|
||||
f->count++;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@brief Read one byte out of the RX buffer.
|
||||
|
||||
This function will return the byte located at the array index of the
|
||||
read pointer, and then increment the read pointer index. If the read
|
||||
pointer exceeds the maximum buffer size, it will roll over to zero.
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
@param[in] buffer
|
||||
Pointer to the place holder for data read from the buffer
|
||||
|
||||
@returns TRUE if the queue is not empty
|
||||
*/
|
||||
/******************************************************************************/
|
||||
bool tu_fifo_read(tu_fifo_t* f, void * buffer)
|
||||
{
|
||||
if( tu_fifo_empty(f) ) return false;
|
||||
|
||||
tu_fifo_lock(f);
|
||||
|
||||
_tu_ff_pull(f, buffer);
|
||||
|
||||
tu_fifo_unlock(f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@brief This function will read n elements into the array index specified by
|
||||
the write pointer and increment the write index. If the write index
|
||||
exceeds the max buffer size, then it will roll over to zero.
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
@param[in] buffer
|
||||
The pointer to data location
|
||||
@param[in] count
|
||||
Number of element that buffer can afford
|
||||
|
||||
@returns number of items read from the FIFO
|
||||
*/
|
||||
/******************************************************************************/
|
||||
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * buffer, uint16_t count)
|
||||
{
|
||||
if( tu_fifo_empty(f) ) return 0;
|
||||
|
||||
tu_fifo_lock(f);
|
||||
|
||||
/* Limit up to fifo's count */
|
||||
if ( count > f->count ) count = f->count;
|
||||
|
||||
uint8_t* buf8 = (uint8_t*) buffer;
|
||||
uint16_t len = 0;
|
||||
|
||||
while (len < count)
|
||||
{
|
||||
_tu_ff_pull(f, buf8);
|
||||
|
||||
len++;
|
||||
buf8 += f->item_size;
|
||||
}
|
||||
|
||||
tu_fifo_unlock(f);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@brief Reads one item without removing it from the FIFO
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
@param[in] pos
|
||||
Position to read from in the FIFO buffer
|
||||
@param[in] p_buffer
|
||||
Pointer to the place holder for data read from the buffer
|
||||
|
||||
@returns TRUE if the queue is not empty
|
||||
*/
|
||||
/******************************************************************************/
|
||||
bool tu_fifo_peek_at(tu_fifo_t* f, uint16_t pos, void * p_buffer)
|
||||
{
|
||||
if ( pos >= f->count ) return false;
|
||||
|
||||
// rd_idx is pos=0
|
||||
uint16_t index = (f->rd_idx + pos) % f->depth;
|
||||
memcpy(p_buffer,
|
||||
f->buffer + (index * f->item_size),
|
||||
f->item_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@brief Write one element into the RX buffer.
|
||||
|
||||
This function will write one element into the array index specified by
|
||||
the write pointer and increment the write index. If the write index
|
||||
exceeds the max buffer size, then it will roll over to zero.
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
@param[in] data
|
||||
The byte to add to the FIFO
|
||||
|
||||
@returns TRUE if the data was written to the FIFO (overwrittable
|
||||
FIFO will always return TRUE)
|
||||
*/
|
||||
/******************************************************************************/
|
||||
bool tu_fifo_write (tu_fifo_t* f, const void * data)
|
||||
{
|
||||
if ( tu_fifo_full(f) && !f->overwritable ) return false;
|
||||
|
||||
tu_fifo_lock(f);
|
||||
|
||||
_tu_ff_push(f, data);
|
||||
|
||||
tu_fifo_unlock(f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@brief This function will write n elements into the array index specified by
|
||||
the write pointer and increment the write index. If the write index
|
||||
exceeds the max buffer size, then it will roll over to zero.
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
@param[in] data
|
||||
The pointer to data to add to the FIFO
|
||||
@param[in] count
|
||||
Number of element
|
||||
@return Number of written elements
|
||||
*/
|
||||
/******************************************************************************/
|
||||
uint16_t tu_fifo_write_n (tu_fifo_t* f, const void * data, uint16_t count)
|
||||
{
|
||||
if ( count == 0 ) return 0;
|
||||
|
||||
tu_fifo_lock(f);
|
||||
|
||||
// Not overwritable limit up to full
|
||||
if (!f->overwritable) count = tu_min16(count, tu_fifo_remaining(f));
|
||||
|
||||
uint8_t const* buf8 = (uint8_t const*) data;
|
||||
uint16_t len = 0;
|
||||
|
||||
while (len < count)
|
||||
{
|
||||
_tu_ff_push(f, buf8);
|
||||
|
||||
len++;
|
||||
buf8 += f->item_size;
|
||||
}
|
||||
|
||||
tu_fifo_unlock(f);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@brief Clear the fifo read and write pointers and set length to zero
|
||||
|
||||
@param[in] f
|
||||
Pointer to the FIFO buffer to manipulate
|
||||
*/
|
||||
/******************************************************************************/
|
||||
bool tu_fifo_clear(tu_fifo_t *f)
|
||||
{
|
||||
tu_fifo_lock(f);
|
||||
|
||||
f->rd_idx = f->wr_idx = f->count = 0;
|
||||
|
||||
tu_fifo_unlock(f);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,131 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup group_fifo fifo
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_FIFO_H_
|
||||
#define _TUSB_FIFO_H_
|
||||
|
||||
// mutex is only needed for RTOS
|
||||
// for OS None, we don't get preempted
|
||||
#define CFG_FIFO_MUTEX (CFG_TUSB_OS != OPT_OS_NONE)
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if CFG_FIFO_MUTEX
|
||||
#define tu_fifo_mutex_t osal_mutex_t
|
||||
#endif
|
||||
|
||||
|
||||
/** \struct tu_fifo_t
|
||||
* \brief Simple Circular FIFO
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t* buffer ; ///< buffer pointer
|
||||
uint16_t depth ; ///< max items
|
||||
uint16_t item_size ; ///< size of each item
|
||||
bool overwritable ;
|
||||
|
||||
volatile uint16_t count ; ///< number of items in queue
|
||||
volatile uint16_t wr_idx ; ///< write pointer
|
||||
volatile uint16_t rd_idx ; ///< read pointer
|
||||
|
||||
#if CFG_FIFO_MUTEX
|
||||
tu_fifo_mutex_t mutex;
|
||||
#endif
|
||||
|
||||
} tu_fifo_t;
|
||||
|
||||
#define TU_FIFO_DEF(_name, _depth, _type, _overwritable) \
|
||||
uint8_t _name##_buf[_depth*sizeof(_type)]; \
|
||||
tu_fifo_t _name = { \
|
||||
.buffer = _name##_buf, \
|
||||
.depth = _depth, \
|
||||
.item_size = sizeof(_type), \
|
||||
.overwritable = _overwritable, \
|
||||
}
|
||||
|
||||
bool tu_fifo_clear(tu_fifo_t *f);
|
||||
bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable);
|
||||
|
||||
#if CFG_FIFO_MUTEX
|
||||
static inline void tu_fifo_config_mutex(tu_fifo_t *f, tu_fifo_mutex_t mutex_hdl)
|
||||
{
|
||||
f->mutex = mutex_hdl;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool tu_fifo_write (tu_fifo_t* f, void const * p_data);
|
||||
uint16_t tu_fifo_write_n (tu_fifo_t* f, void const * p_data, uint16_t count);
|
||||
|
||||
bool tu_fifo_read (tu_fifo_t* f, void * p_buffer);
|
||||
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t count);
|
||||
|
||||
bool tu_fifo_peek_at (tu_fifo_t* f, uint16_t pos, void * p_buffer);
|
||||
|
||||
static inline bool tu_fifo_peek(tu_fifo_t* f, void * p_buffer)
|
||||
{
|
||||
return tu_fifo_peek_at(f, 0, p_buffer);
|
||||
}
|
||||
|
||||
static inline bool tu_fifo_empty(tu_fifo_t* f)
|
||||
{
|
||||
return (f->count == 0);
|
||||
}
|
||||
|
||||
static inline bool tu_fifo_full(tu_fifo_t* f)
|
||||
{
|
||||
return (f->count == f->depth);
|
||||
}
|
||||
|
||||
static inline uint16_t tu_fifo_count(tu_fifo_t* f)
|
||||
{
|
||||
return f->count;
|
||||
}
|
||||
|
||||
static inline uint16_t tu_fifo_remaining(tu_fifo_t* f)
|
||||
{
|
||||
return f->depth - f->count;
|
||||
}
|
||||
|
||||
static inline uint16_t tu_fifo_depth(tu_fifo_t* f)
|
||||
{
|
||||
return f->depth;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_FIFO_H_ */
|
||||
@@ -1,487 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup group_usb_definitions
|
||||
* \defgroup USBDef_Type USB Types
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_TYPES_H_
|
||||
#define _TUSB_TYPES_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "tusb_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* CONSTANTS
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
/// defined base on EHCI specs value for Endpoint Speed
|
||||
typedef enum
|
||||
{
|
||||
TUSB_SPEED_FULL = 0,
|
||||
TUSB_SPEED_LOW ,
|
||||
TUSB_SPEED_HIGH
|
||||
}tusb_speed_t;
|
||||
|
||||
/// defined base on USB Specs Endpoint's bmAttributes
|
||||
typedef enum
|
||||
{
|
||||
TUSB_XFER_CONTROL = 0 ,
|
||||
TUSB_XFER_ISOCHRONOUS ,
|
||||
TUSB_XFER_BULK ,
|
||||
TUSB_XFER_INTERRUPT
|
||||
}tusb_xfer_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TUSB_DIR_OUT = 0,
|
||||
TUSB_DIR_IN = 1,
|
||||
|
||||
TUSB_DIR_IN_MASK = 0x80
|
||||
}tusb_dir_t;
|
||||
|
||||
/// USB Descriptor Types
|
||||
typedef enum
|
||||
{
|
||||
TUSB_DESC_DEVICE = 0x01,
|
||||
TUSB_DESC_CONFIGURATION = 0x02,
|
||||
TUSB_DESC_STRING = 0x03,
|
||||
TUSB_DESC_INTERFACE = 0x04,
|
||||
TUSB_DESC_ENDPOINT = 0x05,
|
||||
TUSB_DESC_DEVICE_QUALIFIER = 0x06,
|
||||
TUSB_DESC_OTHER_SPEED_CONFIG = 0x07,
|
||||
TUSB_DESC_INTERFACE_POWER = 0x08,
|
||||
TUSB_DESC_OTG = 0x09,
|
||||
TUSB_DESC_DEBUG = 0x0A,
|
||||
TUSB_DESC_INTERFACE_ASSOCIATION = 0x0B,
|
||||
|
||||
TUSB_DESC_BOS = 0x0F,
|
||||
TUSB_DESC_DEVICE_CAPABILITY = 0x10,
|
||||
|
||||
// Class Specific Descriptor
|
||||
TUSB_DESC_CS_DEVICE = 0x21,
|
||||
TUSB_DESC_CS_CONFIGURATION = 0x22,
|
||||
TUSB_DESC_CS_STRING = 0x23,
|
||||
TUSB_DESC_CS_INTERFACE = 0x24,
|
||||
TUSB_DESC_CS_ENDPOINT = 0x25,
|
||||
|
||||
TUSB_DESC_SUPERSPEED_ENDPOINT_COMPANION = 0x30,
|
||||
TUSB_DESC_SUPERSPEED_ISO_ENDPOINT_COMPANION = 0x31
|
||||
}tusb_desc_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TUSB_REQ_GET_STATUS = 0 ,
|
||||
TUSB_REQ_CLEAR_FEATURE = 1 ,
|
||||
TUSB_REQ_RESERVED = 2 ,
|
||||
TUSB_REQ_SET_FEATURE = 3 ,
|
||||
TUSB_REQ_RESERVED2 = 4 ,
|
||||
TUSB_REQ_SET_ADDRESS = 5 ,
|
||||
TUSB_REQ_GET_DESCRIPTOR = 6 ,
|
||||
TUSB_REQ_SET_DESCRIPTOR = 7 ,
|
||||
TUSB_REQ_GET_CONFIGURATION = 8 ,
|
||||
TUSB_REQ_SET_CONFIGURATION = 9 ,
|
||||
TUSB_REQ_GET_INTERFACE = 10 ,
|
||||
TUSB_REQ_SET_INTERFACE = 11 ,
|
||||
TUSB_REQ_SYNCH_FRAME = 12
|
||||
}tusb_request_code_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TUSB_REQ_FEATURE_EDPT_HALT = 0,
|
||||
TUSB_REQ_FEATURE_REMOTE_WAKEUP = 1,
|
||||
TUSB_REQ_FEATURE_TEST_MODE = 2
|
||||
}tusb_request_feature_selector_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TUSB_REQ_TYPE_STANDARD = 0,
|
||||
TUSB_REQ_TYPE_CLASS,
|
||||
TUSB_REQ_TYPE_VENDOR
|
||||
} tusb_request_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TUSB_REQ_RCPT_DEVICE =0,
|
||||
TUSB_REQ_RCPT_INTERFACE,
|
||||
TUSB_REQ_RCPT_ENDPOINT,
|
||||
TUSB_REQ_RCPT_OTHER
|
||||
} tusb_request_recipient_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TUSB_CLASS_UNSPECIFIED = 0 ,
|
||||
TUSB_CLASS_AUDIO = 1 ,
|
||||
TUSB_CLASS_CDC = 2 ,
|
||||
TUSB_CLASS_HID = 3 ,
|
||||
TUSB_CLASS_RESERVED_4 = 4 ,
|
||||
TUSB_CLASS_PHYSICAL = 5 ,
|
||||
TUSB_CLASS_IMAGE = 6 ,
|
||||
TUSB_CLASS_PRINTER = 7 ,
|
||||
TUSB_CLASS_MSC = 8 ,
|
||||
TUSB_CLASS_HUB = 9 ,
|
||||
TUSB_CLASS_CDC_DATA = 10 ,
|
||||
TUSB_CLASS_SMART_CARD = 11 ,
|
||||
TUSB_CLASS_RESERVED_12 = 12 ,
|
||||
TUSB_CLASS_CONTENT_SECURITY = 13 ,
|
||||
TUSB_CLASS_VIDEO = 14 ,
|
||||
TUSB_CLASS_PERSONAL_HEALTHCARE = 15 ,
|
||||
TUSB_CLASS_AUDIO_VIDEO = 16 ,
|
||||
|
||||
TUSB_CLASS_DIAGNOSTIC = 0xDC ,
|
||||
TUSB_CLASS_WIRELESS_CONTROLLER = 0xE0 ,
|
||||
TUSB_CLASS_MISC = 0xEF ,
|
||||
TUSB_CLASS_APPLICATION_SPECIFIC = 0xFE ,
|
||||
TUSB_CLASS_VENDOR_SPECIFIC = 0xFF
|
||||
}tusb_class_code_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MISC_SUBCLASS_COMMON = 2
|
||||
}misc_subclass_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MISC_PROTOCOL_IAD = 1
|
||||
}misc_protocol_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DEVICE_CAPABILITY_WIRELESS_USB = 0x01,
|
||||
DEVICE_CAPABILITY_USB20_EXTENSION = 0x02,
|
||||
DEVICE_CAPABILITY_SUPERSPEED_USB = 0x03,
|
||||
DEVICE_CAPABILITY_CONTAINER_id = 0x04,
|
||||
DEVICE_CAPABILITY_PLATFORM = 0x05,
|
||||
DEVICE_CAPABILITY_POWER_DELIVERY = 0x06,
|
||||
DEVICE_CAPABILITY_BATTERY_INFO = 0x07,
|
||||
DEVICE_CAPABILITY_PD_CONSUMER_PORT = 0x08,
|
||||
DEVICE_CAPABILITY_PD_PROVIDER_PORT = 0x09,
|
||||
DEVICE_CAPABILITY_SUPERSPEED_PLUS = 0x0A,
|
||||
DEVICE_CAPABILITY_PRECESION_TIME_MEASUREMENT = 0x0B,
|
||||
DEVICE_CAPABILITY_WIRELESS_USB_EXT = 0x0C,
|
||||
DEVICE_CAPABILITY_BILLBOARD = 0x0D,
|
||||
DEVICE_CAPABILITY_AUTHENTICATION = 0x0E,
|
||||
DEVICE_CAPABILITY_BILLBOARD_EX = 0x0F,
|
||||
DEVICE_CAPABILITY_CONFIGURATION_SUMMARY = 0x10
|
||||
}device_capability_type_t;
|
||||
|
||||
enum {
|
||||
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = TU_BIT(5),
|
||||
TUSB_DESC_CONFIG_ATT_SELF_POWERED = TU_BIT(6),
|
||||
};
|
||||
|
||||
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
|
||||
|
||||
/// Device State TODO remove
|
||||
typedef enum
|
||||
{
|
||||
TUSB_DEVICE_STATE_UNPLUG = 0 ,
|
||||
TUSB_DEVICE_STATE_CONFIGURED ,
|
||||
TUSB_DEVICE_STATE_SUSPENDED ,
|
||||
}tusb_device_state_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
XFER_RESULT_SUCCESS,
|
||||
XFER_RESULT_FAILED,
|
||||
XFER_RESULT_STALLED,
|
||||
}xfer_result_t;
|
||||
|
||||
enum // TODO remove
|
||||
{
|
||||
DESC_OFFSET_LEN = 0,
|
||||
DESC_OFFSET_TYPE = 1
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
INTERFACE_INVALID_NUMBER = 0xff
|
||||
};
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MS_OS_20_SET_HEADER_DESCRIPTOR = 0x00,
|
||||
MS_OS_20_SUBSET_HEADER_CONFIGURATION = 0x01,
|
||||
MS_OS_20_SUBSET_HEADER_FUNCTION = 0x02,
|
||||
MS_OS_20_FEATURE_COMPATBLE_ID = 0x03,
|
||||
MS_OS_20_FEATURE_REG_PROPERTY = 0x04,
|
||||
MS_OS_20_FEATURE_MIN_RESUME_TIME = 0x05,
|
||||
MS_OS_20_FEATURE_MODEL_ID = 0x06,
|
||||
MS_OS_20_FEATURE_CCGP_DEVICE = 0x07,
|
||||
MS_OS_20_FEATURE_VENDOR_REVISION = 0x08
|
||||
} microsoft_os_20_type_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USB Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// USB Device Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< DEVICE Descriptor Type.
|
||||
uint16_t bcdUSB ; ///< BUSB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). This field identifies the release of the USB Specification with which the device and its descriptors are compliant.
|
||||
|
||||
uint8_t bDeviceClass ; ///< Class code (assigned by the USB-IF). \li If this field is reset to zero, each interface within a configuration specifies its own class information and the various interfaces operate independently. \li If this field is set to a value between 1 and FEH, the device supports different class specifications on different interfaces and the interfaces may not operate independently. This value identifies the class definition used for the aggregate interfaces. \li If this field is set to FFH, the device class is vendor-specific.
|
||||
uint8_t bDeviceSubClass ; ///< Subclass code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass field. \li If the bDeviceClass field is reset to zero, this field must also be reset to zero. \li If the bDeviceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
|
||||
uint8_t bDeviceProtocol ; ///< Protocol code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass and the bDeviceSubClass fields. If a device supports class-specific protocols on a device basis as opposed to an interface basis, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use class-specific protocols on a device basis. However, it may use classspecific protocols on an interface basis. \li If this field is set to FFH, the device uses a vendor-specific protocol on a device basis.
|
||||
uint8_t bMaxPacketSize0 ; ///< Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid). For HS devices is fixed to 64.
|
||||
|
||||
uint16_t idVendor ; ///< Vendor ID (assigned by the USB-IF).
|
||||
uint16_t idProduct ; ///< Product ID (assigned by the manufacturer).
|
||||
uint16_t bcdDevice ; ///< Device release number in binary-coded decimal.
|
||||
uint8_t iManufacturer ; ///< Index of string descriptor describing manufacturer.
|
||||
uint8_t iProduct ; ///< Index of string descriptor describing product.
|
||||
uint8_t iSerialNumber ; ///< Index of string descriptor describing the device's serial number.
|
||||
|
||||
uint8_t bNumConfigurations ; ///< Number of possible configurations.
|
||||
} tusb_desc_device_t;
|
||||
|
||||
// USB Binary Device Object Store (BOS) Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes
|
||||
uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
|
||||
uint16_t wTotalLength ; ///< Total length of data returned for this descriptor
|
||||
uint8_t bNumDeviceCaps ; ///< Number of device capability descriptors in the BOS
|
||||
} tusb_desc_bos_t;
|
||||
|
||||
/// USB Configuration Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes
|
||||
uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
|
||||
uint16_t wTotalLength ; ///< Total length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface, endpoint, and class- or vendor-specific) returned for this configuration.
|
||||
|
||||
uint8_t bNumInterfaces ; ///< Number of interfaces supported by this configuration
|
||||
uint8_t bConfigurationValue ; ///< Value to use as an argument to the SetConfiguration() request to select this configuration.
|
||||
uint8_t iConfiguration ; ///< Index of string descriptor describing this configuration
|
||||
uint8_t bmAttributes ; ///< Configuration characteristics \n D7: Reserved (set to one)\n D6: Self-powered \n D5: Remote Wakeup \n D4...0: Reserved (reset to zero) \n D7 is reserved and must be set to one for historical reasons. \n A device configuration that uses power from the bus and a local source reports a non-zero value in bMaxPower to indicate the amount of bus power required and sets D6. The actual power source at runtime may be determined using the GetStatus(DEVICE) request (see USB 2.0 spec Section 9.4.5). \n If a device configuration supports remote wakeup, D5 is set to one.
|
||||
uint8_t bMaxPower ; ///< Maximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
|
||||
} tusb_desc_configuration_t;
|
||||
|
||||
/// USB Interface Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes
|
||||
uint8_t bDescriptorType ; ///< INTERFACE Descriptor Type
|
||||
|
||||
uint8_t bInterfaceNumber ; ///< Number of this interface. Zero-based value identifying the index in the array of concurrent interfaces supported by this configuration.
|
||||
uint8_t bAlternateSetting ; ///< Value used to select this alternate setting for the interface identified in the prior field
|
||||
uint8_t bNumEndpoints ; ///< Number of endpoints used by this interface (excluding endpoint zero). If this value is zero, this interface only uses the Default Control Pipe.
|
||||
uint8_t bInterfaceClass ; ///< Class code (assigned by the USB-IF). \li A value of zero is reserved for future standardization. \li If this field is set to FFH, the interface class is vendor-specific. \li All other values are reserved for assignment by the USB-IF.
|
||||
uint8_t bInterfaceSubClass ; ///< Subclass code (assigned by the USB-IF). \n These codes are qualified by the value of the bInterfaceClass field. \li If the bInterfaceClass field is reset to zero, this field must also be reset to zero. \li If the bInterfaceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
|
||||
uint8_t bInterfaceProtocol ; ///< Protocol code (assigned by the USB). \n These codes are qualified by the value of the bInterfaceClass and the bInterfaceSubClass fields. If an interface supports class-specific requests, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use a class-specific protocol on this interface. \li If this field is set to FFH, the device uses a vendor-specific protocol for this interface.
|
||||
uint8_t iInterface ; ///< Index of string descriptor describing this interface
|
||||
} tusb_desc_interface_t;
|
||||
|
||||
/// USB Endpoint Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes
|
||||
uint8_t bDescriptorType ; ///< ENDPOINT Descriptor Type
|
||||
|
||||
uint8_t bEndpointAddress ; ///< The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: \n Bit 3...0: The endpoint number \n Bit 6...4: Reserved, reset to zero \n Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint.
|
||||
|
||||
struct TU_ATTR_PACKED {
|
||||
uint8_t xfer : 2;
|
||||
uint8_t sync : 2;
|
||||
uint8_t usage : 2;
|
||||
uint8_t : 2;
|
||||
} bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host.
|
||||
|
||||
struct TU_ATTR_PACKED {
|
||||
uint16_t size : 11; ///< Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. \n For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. \n For all endpoints, bits 10..0 specify the maximum packet size (in bytes). \n For high-speed isochronous and interrupt endpoints: \n Bits 12..11 specify the number of additional transaction opportunities per microframe: \n- 00 = None (1 transaction per microframe) \n- 01 = 1 additional (2 per microframe) \n- 10 = 2 additional (3 per microframe) \n- 11 = Reserved \n Bits 15..13 are reserved and must be set to zero.
|
||||
uint16_t hs_period_mult : 2;
|
||||
uint16_t : 0;
|
||||
}wMaxPacketSize;
|
||||
|
||||
uint8_t bInterval ; ///< Interval for polling endpoint for data transfers. Expressed in frames or microframes depending on the device operating speed (i.e., either 1 millisecond or 125 us units). \n- For full-/high-speed isochronous endpoints, this value must be in the range from 1 to 16. The bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). \n- For full-/low-speed interrupt endpoints, the value of this field may be from 1 to 255. \n- For high-speed interrupt endpoints, the bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value must be from 1 to 16. \n- For high-speed bulk/control OUT endpoints, the bInterval must specify the maximum NAK rate of the endpoint. A value of 0 indicates the endpoint never NAKs. Other values indicate at most 1 NAK each bInterval number of microframes. This value must be in the range from 0 to 255. \n Refer to Chapter 5 of USB 2.0 specification for more information.
|
||||
} tusb_desc_endpoint_t;
|
||||
|
||||
/// USB Other Speed Configuration Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of descriptor
|
||||
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
|
||||
uint16_t wTotalLength ; ///< Total length of data returned
|
||||
|
||||
uint8_t bNumInterfaces ; ///< Number of interfaces supported by this speed configuration
|
||||
uint8_t bConfigurationValue ; ///< Value to use to select configuration
|
||||
uint8_t IConfiguration ; ///< Index of string descriptor
|
||||
uint8_t bmAttributes ; ///< Same as Configuration descriptor
|
||||
uint8_t bMaxPower ; ///< Same as Configuration descriptor
|
||||
} tusb_desc_other_speed_t;
|
||||
|
||||
/// USB Device Qualifier Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of descriptor
|
||||
uint8_t bDescriptorType ; ///< Device Qualifier Type
|
||||
uint16_t bcdUSB ; ///< USB specification version number (e.g., 0200H for V2.00)
|
||||
|
||||
uint8_t bDeviceClass ; ///< Class Code
|
||||
uint8_t bDeviceSubClass ; ///< SubClass Code
|
||||
uint8_t bDeviceProtocol ; ///< Protocol Code
|
||||
uint8_t bMaxPacketSize0 ; ///< Maximum packet size for other speed
|
||||
uint8_t bNumConfigurations ; ///< Number of Other-speed Configurations
|
||||
uint8_t bReserved ; ///< Reserved for future use, must be zero
|
||||
} tusb_desc_device_qualifier_t;
|
||||
|
||||
/// USB Interface Association Descriptor (IAD ECN)
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of descriptor
|
||||
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
|
||||
|
||||
uint8_t bFirstInterface ; ///< Index of the first associated interface.
|
||||
uint8_t bInterfaceCount ; ///< Total number of associated interfaces.
|
||||
|
||||
uint8_t bFunctionClass ; ///< Interface class ID.
|
||||
uint8_t bFunctionSubClass ; ///< Interface subclass ID.
|
||||
uint8_t bFunctionProtocol ; ///< Interface protocol ID.
|
||||
|
||||
uint8_t iFunction ; ///< Index of the string descriptor describing the interface association.
|
||||
} tusb_desc_interface_assoc_t;
|
||||
|
||||
// USB String Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type
|
||||
uint16_t unicode_string[];
|
||||
} tusb_desc_string_t;
|
||||
|
||||
// USB Binary Device Object Store (BOS)
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType ;
|
||||
uint8_t bDevCapabilityType;
|
||||
uint8_t bReserved;
|
||||
uint8_t PlatformCapabilityUUID[16];
|
||||
uint8_t CapabilityData[];
|
||||
} tusb_desc_bos_platform_t;
|
||||
|
||||
// USB WebuSB URL Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bScheme;
|
||||
char url[];
|
||||
} tusb_desc_webusb_url_t;
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Types
|
||||
*------------------------------------------------------------------*/
|
||||
typedef struct TU_ATTR_PACKED{
|
||||
union {
|
||||
struct TU_ATTR_PACKED {
|
||||
uint8_t recipient : 5; ///< Recipient type tusb_request_recipient_t.
|
||||
uint8_t type : 2; ///< Request type tusb_request_type_t.
|
||||
uint8_t direction : 1; ///< Direction type. tusb_dir_t
|
||||
} bmRequestType_bit;
|
||||
|
||||
uint8_t bmRequestType;
|
||||
};
|
||||
|
||||
uint8_t bRequest;
|
||||
uint16_t wValue;
|
||||
uint16_t wIndex;
|
||||
uint16_t wLength;
|
||||
} tusb_control_request_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_control_request_t) == 8, "mostly compiler option issue");
|
||||
|
||||
// TODO move to somewhere suitable
|
||||
static inline uint8_t bm_request_type(uint8_t direction, uint8_t type, uint8_t recipient)
|
||||
{
|
||||
return ((uint8_t) (direction << 7)) | ((uint8_t) (type << 5)) | (recipient);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Endpoint helper
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Get direction from Endpoint address
|
||||
static inline tusb_dir_t tu_edpt_dir(uint8_t addr)
|
||||
{
|
||||
return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
|
||||
}
|
||||
|
||||
// Get Endpoint number from address
|
||||
static inline uint8_t tu_edpt_number(uint8_t addr)
|
||||
{
|
||||
return addr & (~TUSB_DIR_IN_MASK);
|
||||
}
|
||||
|
||||
static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir)
|
||||
{
|
||||
return num | (dir ? TUSB_DIR_IN_MASK : 0);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Descriptor helper
|
||||
//--------------------------------------------------------------------+
|
||||
static inline uint8_t const * tu_desc_next(void const* desc)
|
||||
{
|
||||
uint8_t const* desc8 = (uint8_t const*) desc;
|
||||
return desc8 + desc8[DESC_OFFSET_LEN];
|
||||
}
|
||||
|
||||
static inline uint8_t tu_desc_type(void const* desc)
|
||||
{
|
||||
return ((uint8_t const*) desc)[DESC_OFFSET_TYPE];
|
||||
}
|
||||
|
||||
static inline uint8_t tu_desc_len(void const* desc)
|
||||
{
|
||||
return ((uint8_t const*) desc)[DESC_OFFSET_LEN];
|
||||
}
|
||||
|
||||
// Length of the string descriptors in bytes with slen characters
|
||||
#define TUD_DESC_STRLEN(_chr_count) (2*(_chr_count) + 2)
|
||||
|
||||
// Header of string descriptors with len + string type
|
||||
#define TUD_DESC_STR_HEADER(_chr_count) ( (uint16_t) ( (TUSB_DESC_STRING << 8 ) | TUD_DESC_STRLEN(_chr_count)) )
|
||||
|
||||
// Convert comma-separated string to descriptor unicode format
|
||||
#define TUD_DESC_STRCONV( ... ) (const uint16_t[]) { TUD_DESC_STR_HEADER(TU_ARGS_NUM(__VA_ARGS__)), __VA_ARGS__ }
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_TYPES_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -1,173 +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.
|
||||
*/
|
||||
#ifndef TUSB_VERIFY_H_
|
||||
#define TUSB_VERIFY_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "tusb_option.h"
|
||||
#include "tusb_compiler.h"
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* This file use an advanced macro technique to mimic the default parameter
|
||||
* as C++ for the sake of code simplicity. Beware of a headache macro
|
||||
* manipulation that you are told to stay away.
|
||||
*
|
||||
* e.g
|
||||
*
|
||||
* - TU_VERIFY( cond ) will return false if cond is false
|
||||
* - TU_VERIFY( cond, err) will return err instead if cond is false
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// TU_VERIFY Helper
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUSB_DEBUG
|
||||
#include <stdio.h>
|
||||
#define _MESS_ERR(_err) printf("%s: %d: failed, error = %s\n", __func__, __LINE__, tusb_strerr[_err])
|
||||
#define _MESS_FAILED() printf("%s: %d: failed\n", __func__, __LINE__)
|
||||
#else
|
||||
#define _MESS_ERR(_err)
|
||||
#define _MESS_FAILED()
|
||||
#endif
|
||||
|
||||
// Halt CPU (breakpoint) when hitting error, only apply for Cortex M3, M4, M7
|
||||
#if defined(__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__)
|
||||
|
||||
#define TU_BREAKPOINT() do \
|
||||
{ \
|
||||
volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL); /* Cortex M CoreDebug->DHCSR */ \
|
||||
if ( (*ARM_CM_DHCSR) & 1UL ) __asm("BKPT #0\n"); /* Only halt mcu if debugger is attached */ \
|
||||
} while(0)
|
||||
|
||||
#else
|
||||
#define TU_BREAKPOINT()
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Macro Generator
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
// Helper to implement optional parameter for TU_VERIFY Macro family
|
||||
#define GET_3RD_ARG(arg1, arg2, arg3, ...) arg3
|
||||
#define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
|
||||
|
||||
/*------------- Generator for TU_VERIFY and TU_VERIFY_HDLR -------------*/
|
||||
#define TU_VERIFY_DEFINE(_cond, _handler, _ret) do \
|
||||
{ \
|
||||
if ( !(_cond) ) { _handler; return _ret; } \
|
||||
} while(0)
|
||||
|
||||
/*------------- Generator for TU_VERIFY_ERR and TU_VERIFY_ERR_HDLR -------------*/
|
||||
#define TU_VERIFY_ERR_DEF2(_error, _handler) do \
|
||||
{ \
|
||||
uint32_t _err = (uint32_t)(_error); \
|
||||
if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _err; } \
|
||||
} while(0)
|
||||
|
||||
#define TU_VERIFY_ERR_DEF3(_error, _handler, _ret) do \
|
||||
{ \
|
||||
uint32_t _err = (uint32_t)(_error); \
|
||||
if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _ret; } \
|
||||
} while(0)
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* TU_VERIFY
|
||||
* - TU_VERIFY_1ARGS : return false if failed
|
||||
* - TU_VERIFY_2ARGS : return provided value if failed
|
||||
*------------------------------------------------------------------*/
|
||||
#define TU_VERIFY_1ARGS(_cond) TU_VERIFY_DEFINE(_cond, , false)
|
||||
#define TU_VERIFY_2ARGS(_cond, _ret) TU_VERIFY_DEFINE(_cond, , _ret)
|
||||
|
||||
#define TU_VERIFY(...) GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS)(__VA_ARGS__)
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* TU_VERIFY WITH HANDLER
|
||||
* - TU_VERIFY_HDLR_2ARGS : execute handler, return false if failed
|
||||
* - TU_VERIFY_HDLR_3ARGS : execute handler, return provided error if failed
|
||||
*------------------------------------------------------------------*/
|
||||
#define TU_VERIFY_HDLR_2ARGS(_cond, _handler) TU_VERIFY_DEFINE(_cond, _handler, false)
|
||||
#define TU_VERIFY_HDLR_3ARGS(_cond, _handler, _ret) TU_VERIFY_DEFINE(_cond, _handler, _ret)
|
||||
|
||||
#define TU_VERIFY_HDLR(...) GET_4TH_ARG(__VA_ARGS__, TU_VERIFY_HDLR_3ARGS, TU_VERIFY_HDLR_2ARGS)(__VA_ARGS__)
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* TU_VERIFY STATUS
|
||||
* - TU_VERIFY_ERR_1ARGS : return status of condition if failed
|
||||
* - TU_VERIFY_ERR_2ARGS : return provided status code if failed
|
||||
*------------------------------------------------------------------*/
|
||||
#define TU_VERIFY_ERR_1ARGS(_error) TU_VERIFY_ERR_DEF2(_error, )
|
||||
#define TU_VERIFY_ERR_2ARGS(_error, _ret) TU_VERIFY_ERR_DEF3(_error, ,_ret)
|
||||
|
||||
#define TU_VERIFY_ERR(...) GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_ERR_2ARGS, TU_VERIFY_ERR_1ARGS)(__VA_ARGS__)
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* TU_VERIFY STATUS WITH HANDLER
|
||||
* - TU_VERIFY_ERR_HDLR_2ARGS : execute handler, return status if failed
|
||||
* - TU_VERIFY_ERR_HDLR_3ARGS : execute handler, return provided error if failed
|
||||
*------------------------------------------------------------------*/
|
||||
#define TU_VERIFY_ERR_HDLR_2ARGS(_error, _handler) TU_VERIFY_ERR_DEF2(_error, _handler)
|
||||
#define TU_VERIFY_ERR_HDLR_3ARGS(_error, _handler, _ret) TU_VERIFY_ERR_DEF3(_error, _handler, _ret)
|
||||
|
||||
#define TU_VERIFY_ERR_HDLR(...) GET_4TH_ARG(__VA_ARGS__, TU_VERIFY_ERR_HDLR_3ARGS, TU_VERIFY_ERR_HDLR_2ARGS)(__VA_ARGS__)
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* ASSERT
|
||||
* basically TU_VERIFY with TU_BREAKPOINT() as handler
|
||||
* - 1 arg : return false if failed
|
||||
* - 2 arg : return error if failed
|
||||
*------------------------------------------------------------------*/
|
||||
#define ASSERT_1ARGS(_cond) TU_VERIFY_DEFINE(_cond, _MESS_FAILED(); TU_BREAKPOINT(), false)
|
||||
#define ASSERT_2ARGS(_cond, _ret) TU_VERIFY_DEFINE(_cond, _MESS_FAILED(); TU_BREAKPOINT(), _ret)
|
||||
|
||||
#define TU_ASSERT(...) GET_3RD_ARG(__VA_ARGS__, ASSERT_2ARGS, ASSERT_1ARGS)(__VA_ARGS__)
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* ASSERT Error
|
||||
* basically TU_VERIFY Error with TU_BREAKPOINT() as handler
|
||||
*------------------------------------------------------------------*/
|
||||
#define ASERT_ERR_1ARGS(_error) TU_VERIFY_ERR_DEF2(_error, TU_BREAKPOINT())
|
||||
#define ASERT_ERR_2ARGS(_error, _ret) TU_VERIFY_ERR_DEF3(_error, TU_BREAKPOINT(), _ret)
|
||||
|
||||
#define TU_ASSERT_ERR(...) GET_3RD_ARG(__VA_ARGS__, ASERT_ERR_2ARGS, ASERT_ERR_1ARGS)(__VA_ARGS__)
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* ASSERT HDLR
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TUSB_VERIFY_H_ */
|
||||
@@ -1,140 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup group_usbd
|
||||
* \defgroup group_dcd Device Controller Driver (DCD)
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_DCD_H_
|
||||
#define _TUSB_DCD_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DCD_EVENT_BUS_RESET = 1,
|
||||
DCD_EVENT_UNPLUGGED,
|
||||
DCD_EVENT_SOF,
|
||||
DCD_EVENT_SUSPEND,
|
||||
DCD_EVENT_RESUME,
|
||||
|
||||
DCD_EVENT_SETUP_RECEIVED,
|
||||
DCD_EVENT_XFER_COMPLETE,
|
||||
|
||||
// Not an DCD event, just a convenient way to defer ISR function
|
||||
USBD_EVENT_FUNC_CALL
|
||||
} dcd_eventid_t;
|
||||
|
||||
typedef struct TU_ATTR_ALIGNED(4)
|
||||
{
|
||||
uint8_t rhport;
|
||||
uint8_t event_id;
|
||||
|
||||
union {
|
||||
// USBD_EVT_SETUP_RECEIVED
|
||||
tusb_control_request_t setup_received;
|
||||
|
||||
// USBD_EVT_XFER_COMPLETE
|
||||
struct {
|
||||
uint8_t ep_addr;
|
||||
uint8_t result;
|
||||
uint32_t len;
|
||||
}xfer_complete;
|
||||
|
||||
// USBD_EVENT_FUNC_CALL
|
||||
struct {
|
||||
void (*func) (void*);
|
||||
void* param;
|
||||
}func_call;
|
||||
};
|
||||
} dcd_event_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(dcd_event_t) <= 12, "size is not correct");
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Device API
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
// Initialize controller to device mode
|
||||
void dcd_init (uint8_t rhport);
|
||||
|
||||
// Enable device interrupt
|
||||
void dcd_int_enable (uint8_t rhport);
|
||||
|
||||
// Disable device interrupt
|
||||
void dcd_int_disable(uint8_t rhport);
|
||||
|
||||
// Receive Set Address request, mcu port must also include status IN response
|
||||
void dcd_set_address(uint8_t rhport, uint8_t dev_addr);
|
||||
|
||||
// Receive Set Configure request
|
||||
void dcd_set_config (uint8_t rhport, uint8_t config_num);
|
||||
|
||||
// Wake up host
|
||||
void dcd_remote_wakeup(uint8_t rhport);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Endpoint API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Configure endpoint's registers according to descriptor
|
||||
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
|
||||
|
||||
// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to notify the stack
|
||||
bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
|
||||
|
||||
// Stall endpoint
|
||||
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
// clear stall, data toggle is also reset to DATA0
|
||||
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Event Function
|
||||
* Called by DCD to notify device stack
|
||||
*------------------------------------------------------------------*/
|
||||
void dcd_event_handler(dcd_event_t const * event, bool in_isr);
|
||||
|
||||
// helper to send bus signal event
|
||||
void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr);
|
||||
|
||||
// helper to send setup received
|
||||
void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr);
|
||||
|
||||
// helper to send transfer complete event
|
||||
void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_DCD_H_ */
|
||||
|
||||
/// @}
|
||||
@@ -1,842 +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 "tusb_option.h"
|
||||
|
||||
#if TUSB_OPT_DEVICE_ENABLED
|
||||
|
||||
#include "tusb.h"
|
||||
#include "usbd.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
#include "dcd.h"
|
||||
|
||||
#ifndef CFG_TUD_TASK_QUEUE_SZ
|
||||
#define CFG_TUD_TASK_QUEUE_SZ 16
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Device Data
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
volatile uint8_t connected : 1;
|
||||
volatile uint8_t configured : 1;
|
||||
volatile uint8_t suspended : 1;
|
||||
|
||||
uint8_t remote_wakeup_en : 1; // enable/disable by host
|
||||
uint8_t remote_wakeup_support : 1; // configuration descriptor's attribute
|
||||
uint8_t self_powered : 1; // configuration descriptor's attribute
|
||||
};
|
||||
|
||||
uint8_t ep_busy_map[2]; // bit mask for busy endpoint
|
||||
uint8_t ep_stall_map[2]; // bit map for stalled endpoint
|
||||
|
||||
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
|
||||
uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
|
||||
}usbd_device_t;
|
||||
|
||||
static usbd_device_t _usbd_dev = { 0 };
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Driver
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
uint8_t class_code;
|
||||
|
||||
void (* init ) (void);
|
||||
void (* reset ) (uint8_t rhport);
|
||||
bool (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t* p_length);
|
||||
bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool (* control_complete ) (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
void (* sof ) (uint8_t rhport);
|
||||
} usbd_class_driver_t;
|
||||
|
||||
static usbd_class_driver_t const usbd_class_drivers[] =
|
||||
{
|
||||
#if CFG_TUD_CDC
|
||||
{
|
||||
.class_code = TUSB_CLASS_CDC,
|
||||
.init = cdcd_init,
|
||||
.reset = cdcd_reset,
|
||||
.open = cdcd_open,
|
||||
.control_request = cdcd_control_request,
|
||||
.control_complete = cdcd_control_complete,
|
||||
.xfer_cb = cdcd_xfer_cb,
|
||||
.sof = NULL
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MSC
|
||||
{
|
||||
.class_code = TUSB_CLASS_MSC,
|
||||
.init = mscd_init,
|
||||
.reset = mscd_reset,
|
||||
.open = mscd_open,
|
||||
.control_request = mscd_control_request,
|
||||
.control_complete = mscd_control_complete,
|
||||
.xfer_cb = mscd_xfer_cb,
|
||||
.sof = NULL
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID
|
||||
{
|
||||
.class_code = TUSB_CLASS_HID,
|
||||
.init = hidd_init,
|
||||
.reset = hidd_reset,
|
||||
.open = hidd_open,
|
||||
.control_request = hidd_control_request,
|
||||
.control_complete = hidd_control_complete,
|
||||
.xfer_cb = hidd_xfer_cb,
|
||||
.sof = NULL
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MIDI
|
||||
{
|
||||
.class_code = TUSB_CLASS_AUDIO,
|
||||
.init = midid_init,
|
||||
.open = midid_open,
|
||||
.reset = midid_reset,
|
||||
.control_request = midid_control_request,
|
||||
.control_complete = midid_control_complete,
|
||||
.xfer_cb = midid_xfer_cb,
|
||||
.sof = NULL
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_VENDOR
|
||||
{
|
||||
.class_code = TUSB_CLASS_VENDOR_SPECIFIC,
|
||||
.init = vendord_init,
|
||||
.reset = vendord_reset,
|
||||
.open = vendord_open,
|
||||
.control_request = tud_vendor_control_request_cb,
|
||||
.control_complete = tud_vendor_control_complete_cb,
|
||||
.xfer_cb = vendord_xfer_cb,
|
||||
.sof = NULL
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
enum { USBD_CLASS_DRIVER_COUNT = TU_ARRAY_SZIE(usbd_class_drivers) };
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DCD Event
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Event queue
|
||||
// OPT_MODE_DEVICE is used by OS NONE for mutex (disable usb isr)
|
||||
OSAL_QUEUE_DEF(OPT_MODE_DEVICE, _usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t);
|
||||
static osal_queue_t _usbd_q;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Prototypes
|
||||
//--------------------------------------------------------------------+
|
||||
static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id);
|
||||
static bool process_control_request(uint8_t rhport, tusb_control_request_t const * p_request);
|
||||
static bool process_set_config(uint8_t rhport, uint8_t cfg_num);
|
||||
static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request);
|
||||
|
||||
void usbd_control_reset (uint8_t rhport);
|
||||
bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_request_t const * ) );
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_mounted(void)
|
||||
{
|
||||
return _usbd_dev.configured;
|
||||
}
|
||||
|
||||
bool tud_suspended(void)
|
||||
{
|
||||
return _usbd_dev.suspended;
|
||||
}
|
||||
|
||||
bool tud_remote_wakeup(void)
|
||||
{
|
||||
// only wake up host if this feature is supported and enabled and we are suspended
|
||||
TU_VERIFY (_usbd_dev.suspended && _usbd_dev.remote_wakeup_support && _usbd_dev.remote_wakeup_en );
|
||||
dcd_remote_wakeup(TUD_OPT_RHPORT);
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Task
|
||||
//--------------------------------------------------------------------+
|
||||
bool usbd_init (void)
|
||||
{
|
||||
tu_varclr(&_usbd_dev);
|
||||
|
||||
// Init device queue & task
|
||||
_usbd_q = osal_queue_create(&_usbd_qdef);
|
||||
TU_ASSERT(_usbd_q != NULL);
|
||||
|
||||
// Init class drivers
|
||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) usbd_class_drivers[i].init();
|
||||
|
||||
// Init device controller driver
|
||||
dcd_init(TUD_OPT_RHPORT);
|
||||
dcd_int_enable(TUD_OPT_RHPORT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void usbd_reset(uint8_t rhport)
|
||||
{
|
||||
tu_varclr(&_usbd_dev);
|
||||
|
||||
memset(_usbd_dev.itf2drv, 0xff, sizeof(_usbd_dev.itf2drv)); // invalid mapping
|
||||
memset(_usbd_dev.ep2drv , 0xff, sizeof(_usbd_dev.ep2drv )); // invalid mapping
|
||||
|
||||
usbd_control_reset(rhport);
|
||||
|
||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
|
||||
{
|
||||
if ( usbd_class_drivers[i].reset ) usbd_class_drivers[i].reset( rhport );
|
||||
}
|
||||
}
|
||||
|
||||
/* USB Device Driver task
|
||||
* This top level thread manages all device controller event and delegates events to class-specific drivers.
|
||||
* This should be called periodically within the mainloop or rtos thread.
|
||||
*
|
||||
@code
|
||||
int main(void)
|
||||
{
|
||||
application_init();
|
||||
tusb_init();
|
||||
|
||||
while(1) // the mainloop
|
||||
{
|
||||
application_code();
|
||||
tud_task(); // tinyusb device task
|
||||
}
|
||||
}
|
||||
@endcode
|
||||
*/
|
||||
void tud_task (void)
|
||||
{
|
||||
// Skip if stack is not initialized
|
||||
if ( !tusb_inited() ) return;
|
||||
|
||||
// Loop until there is no more events in the queue
|
||||
while (1)
|
||||
{
|
||||
dcd_event_t event;
|
||||
|
||||
if ( !osal_queue_receive(_usbd_q, &event) ) return;
|
||||
|
||||
switch ( event.event_id )
|
||||
{
|
||||
case DCD_EVENT_BUS_RESET:
|
||||
usbd_reset(event.rhport);
|
||||
break;
|
||||
|
||||
case DCD_EVENT_UNPLUGGED:
|
||||
usbd_reset(event.rhport);
|
||||
|
||||
// invoke callback
|
||||
if (tud_umount_cb) tud_umount_cb();
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SETUP_RECEIVED:
|
||||
// Mark as connected after receiving 1st setup packet.
|
||||
// But it is easier to set it every time instead of wasting time to check then set
|
||||
_usbd_dev.connected = 1;
|
||||
|
||||
// Process control request
|
||||
if ( !process_control_request(event.rhport, &event.setup_received) )
|
||||
{
|
||||
// Failed -> stall both control endpoint IN and OUT
|
||||
dcd_edpt_stall(event.rhport, 0);
|
||||
dcd_edpt_stall(event.rhport, 0 | TUSB_DIR_IN_MASK);
|
||||
}
|
||||
break;
|
||||
|
||||
case DCD_EVENT_XFER_COMPLETE:
|
||||
// Only handle xfer callback in ready state
|
||||
// if (_usbd_dev.connected && !_usbd_dev.suspended)
|
||||
{
|
||||
// Invoke the class callback associated with the endpoint address
|
||||
uint8_t const ep_addr = event.xfer_complete.ep_addr;
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
_usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_busy_map[dir], epnum);
|
||||
|
||||
if ( 0 == tu_edpt_number(ep_addr) )
|
||||
{
|
||||
// control transfer DATA stage callback
|
||||
usbd_control_xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t const drv_id = _usbd_dev.ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)];
|
||||
TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT,);
|
||||
|
||||
usbd_class_drivers[drv_id].xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SUSPEND:
|
||||
if (tud_suspend_cb) tud_suspend_cb(_usbd_dev.remote_wakeup_en);
|
||||
break;
|
||||
|
||||
case DCD_EVENT_RESUME:
|
||||
if (tud_resume_cb) tud_resume_cb();
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SOF:
|
||||
for ( uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++ )
|
||||
{
|
||||
if ( usbd_class_drivers[i].sof )
|
||||
{
|
||||
usbd_class_drivers[i].sof(event.rhport);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_EVENT_FUNC_CALL:
|
||||
if ( event.func_call.func ) event.func_call.func(event.func_call.param);
|
||||
break;
|
||||
|
||||
default:
|
||||
TU_BREAKPOINT();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Control Request Parser & Handling
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// This handles the actual request and its response.
|
||||
// return false will cause its caller to stall control endpoint
|
||||
static bool process_control_request(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
usbd_control_set_complete_callback(NULL);
|
||||
|
||||
// Vendor request
|
||||
if ( p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_VENDOR )
|
||||
{
|
||||
TU_VERIFY(tud_vendor_control_request_cb);
|
||||
|
||||
if (tud_vendor_control_complete_cb) usbd_control_set_complete_callback(tud_vendor_control_complete_cb);
|
||||
return tud_vendor_control_request_cb(rhport, p_request);
|
||||
}
|
||||
|
||||
switch ( p_request->bmRequestType_bit.recipient )
|
||||
{
|
||||
//------------- Device Requests e.g in enumeration -------------//
|
||||
case TUSB_REQ_RCPT_DEVICE:
|
||||
if ( TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type )
|
||||
{
|
||||
// Non standard request is not supported
|
||||
TU_BREAKPOINT();
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ( p_request->bRequest )
|
||||
{
|
||||
case TUSB_REQ_SET_ADDRESS:
|
||||
// Depending on mcu, status phase could be sent either before or after changing device address
|
||||
// Therefore DCD must include zero-length status response
|
||||
dcd_set_address(rhport, (uint8_t) p_request->wValue);
|
||||
return true; // skip status
|
||||
break;
|
||||
|
||||
case TUSB_REQ_GET_CONFIGURATION:
|
||||
{
|
||||
uint8_t cfgnum = _usbd_dev.configured ? 1 : 0;
|
||||
tud_control_xfer(rhport, p_request, &cfgnum, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_CONFIGURATION:
|
||||
{
|
||||
uint8_t const cfg_num = (uint8_t) p_request->wValue;
|
||||
|
||||
dcd_set_config(rhport, cfg_num);
|
||||
_usbd_dev.configured = cfg_num ? 1 : 0;
|
||||
|
||||
if ( cfg_num ) TU_ASSERT( process_set_config(rhport, cfg_num) );
|
||||
tud_control_status(rhport, p_request);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_REQ_GET_DESCRIPTOR:
|
||||
TU_VERIFY( process_get_descriptor(rhport, p_request) );
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_FEATURE:
|
||||
// Only support remote wakeup for device feature
|
||||
TU_VERIFY(TUSB_REQ_FEATURE_REMOTE_WAKEUP == p_request->wValue);
|
||||
|
||||
// Host may enable remote wake up before suspending especially HID device
|
||||
_usbd_dev.remote_wakeup_en = true;
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
case TUSB_REQ_CLEAR_FEATURE:
|
||||
// Only support remote wakeup for device feature
|
||||
TU_VERIFY(TUSB_REQ_FEATURE_REMOTE_WAKEUP == p_request->wValue);
|
||||
|
||||
// Host may disable remote wake up after resuming
|
||||
_usbd_dev.remote_wakeup_en = false;
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
case TUSB_REQ_GET_STATUS:
|
||||
{
|
||||
// Device status bit mask
|
||||
// - Bit 0: Self Powered
|
||||
// - Bit 1: Remote Wakeup enabled
|
||||
uint16_t status = (_usbd_dev.self_powered ? 1 : 0) | (_usbd_dev.remote_wakeup_en ? 2 : 0);
|
||||
tud_control_xfer(rhport, p_request, &status, 2);
|
||||
}
|
||||
break;
|
||||
|
||||
// Unknown/Unsupported request
|
||||
default: TU_BREAKPOINT(); return false;
|
||||
}
|
||||
break;
|
||||
|
||||
//------------- Class/Interface Specific Request -------------//
|
||||
case TUSB_REQ_RCPT_INTERFACE:
|
||||
{
|
||||
uint8_t const itf = tu_u16_low(p_request->wIndex);
|
||||
uint8_t const drvid = _usbd_dev.itf2drv[itf];
|
||||
|
||||
TU_VERIFY(drvid < USBD_CLASS_DRIVER_COUNT);
|
||||
|
||||
switch ( p_request->bRequest )
|
||||
{
|
||||
case TUSB_REQ_GET_INTERFACE:
|
||||
{
|
||||
// TODO not support alternate interface yet
|
||||
uint8_t alternate = 0;
|
||||
tud_control_xfer(rhport, p_request, &alternate, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_INTERFACE:
|
||||
{
|
||||
uint8_t alternate = (uint8_t) p_request->wValue;
|
||||
|
||||
// TODO not support alternate interface yet
|
||||
TU_ASSERT(alternate == 0);
|
||||
|
||||
tud_control_status(rhport, p_request);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// forward to class driver
|
||||
// stall control endpoint if driver return false
|
||||
usbd_control_set_complete_callback(usbd_class_drivers[drvid].control_complete);
|
||||
TU_ASSERT(usbd_class_drivers[drvid].control_request(rhport, p_request));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//------------- Endpoint Request -------------//
|
||||
case TUSB_REQ_RCPT_ENDPOINT:
|
||||
// Non standard request is not supported
|
||||
TU_VERIFY( TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type );
|
||||
|
||||
switch ( p_request->bRequest )
|
||||
{
|
||||
case TUSB_REQ_GET_STATUS:
|
||||
{
|
||||
uint16_t status = usbd_edpt_stalled(rhport, tu_u16_low(p_request->wIndex)) ? 0x0001 : 0x0000;
|
||||
tud_control_xfer(rhport, p_request, &status, 2);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_REQ_CLEAR_FEATURE:
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
||||
{
|
||||
usbd_edpt_clear_stall(rhport, tu_u16_low(p_request->wIndex));
|
||||
}
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_FEATURE:
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
||||
{
|
||||
usbd_edpt_stall(rhport, tu_u16_low(p_request->wIndex));
|
||||
}
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
// Unknown/Unsupported request
|
||||
default: TU_BREAKPOINT(); return false;
|
||||
}
|
||||
break;
|
||||
|
||||
// Unknown recipient
|
||||
default: TU_BREAKPOINT(); return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Process Set Configure Request
|
||||
// This function parse configuration descriptor & open drivers accordingly
|
||||
static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
||||
{
|
||||
tusb_desc_configuration_t const * desc_cfg = (tusb_desc_configuration_t const *) tud_descriptor_configuration_cb(cfg_num-1); // index is cfg_num-1
|
||||
TU_ASSERT(desc_cfg != NULL && desc_cfg->bDescriptorType == TUSB_DESC_CONFIGURATION);
|
||||
|
||||
// Parse configuration descriptor
|
||||
_usbd_dev.remote_wakeup_support = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP) ? 1 : 0;
|
||||
_usbd_dev.self_powered = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_SELF_POWERED) ? 1 : 0;
|
||||
|
||||
// Parse interface descriptor
|
||||
uint8_t const * p_desc = ((uint8_t const*) desc_cfg) + sizeof(tusb_desc_configuration_t);
|
||||
uint8_t const * desc_end = ((uint8_t const*) desc_cfg) + desc_cfg->wTotalLength;
|
||||
|
||||
while( p_desc < desc_end )
|
||||
{
|
||||
// Each interface always starts with Interface or Association descriptor
|
||||
if ( TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc) )
|
||||
{
|
||||
p_desc = tu_desc_next(p_desc); // ignore Interface Association
|
||||
}else
|
||||
{
|
||||
TU_ASSERT( TUSB_DESC_INTERFACE == tu_desc_type(p_desc) );
|
||||
|
||||
tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc;
|
||||
|
||||
// Check if class is supported
|
||||
uint8_t drv_id;
|
||||
for (drv_id = 0; drv_id < USBD_CLASS_DRIVER_COUNT; drv_id++)
|
||||
{
|
||||
if ( usbd_class_drivers[drv_id].class_code == desc_itf->bInterfaceClass ) break;
|
||||
}
|
||||
TU_ASSERT( drv_id < USBD_CLASS_DRIVER_COUNT );
|
||||
|
||||
// Interface number must not be used already TODO alternate interface
|
||||
TU_ASSERT( 0xff == _usbd_dev.itf2drv[desc_itf->bInterfaceNumber] );
|
||||
_usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id;
|
||||
|
||||
uint16_t itf_len=0;
|
||||
TU_ASSERT( usbd_class_drivers[drv_id].open(rhport, desc_itf, &itf_len) );
|
||||
TU_ASSERT( itf_len >= sizeof(tusb_desc_interface_t) );
|
||||
|
||||
mark_interface_endpoint(_usbd_dev.ep2drv, p_desc, itf_len, drv_id);
|
||||
|
||||
p_desc += itf_len; // next interface
|
||||
}
|
||||
}
|
||||
|
||||
// invoke callback
|
||||
if (tud_mount_cb) tud_mount_cb();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Helper marking endpoint of interface belongs to class driver
|
||||
static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id)
|
||||
{
|
||||
uint16_t len = 0;
|
||||
|
||||
while( len < desc_len )
|
||||
{
|
||||
if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
|
||||
{
|
||||
uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress;
|
||||
|
||||
ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = driver_id;
|
||||
}
|
||||
|
||||
len += tu_desc_len(p_desc);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
}
|
||||
|
||||
// return descriptor's buffer and update desc_len
|
||||
static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
tusb_desc_type_t const desc_type = (tusb_desc_type_t) tu_u16_high(p_request->wValue);
|
||||
uint8_t const desc_index = tu_u16_low( p_request->wValue );
|
||||
|
||||
switch(desc_type)
|
||||
{
|
||||
case TUSB_DESC_DEVICE:
|
||||
return tud_control_xfer(rhport, p_request, (void*) tud_descriptor_device_cb(), sizeof(tusb_desc_device_t));
|
||||
break;
|
||||
|
||||
case TUSB_DESC_BOS:
|
||||
{
|
||||
// requested by host if USB > 2.0 ( i.e 2.1 or 3.x )
|
||||
if (!tud_descriptor_bos_cb) return false;
|
||||
|
||||
tusb_desc_bos_t const* desc_bos = (tusb_desc_bos_t const*) tud_descriptor_bos_cb();
|
||||
uint16_t total_len;
|
||||
memcpy(&total_len, &desc_bos->wTotalLength, 2); // possibly mis-aligned memory
|
||||
|
||||
return tud_control_xfer(rhport, p_request, (void*) desc_bos, total_len);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_DESC_CONFIGURATION:
|
||||
{
|
||||
tusb_desc_configuration_t const* desc_config = (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(desc_index);
|
||||
uint16_t total_len;
|
||||
memcpy(&total_len, &desc_config->wTotalLength, 2); // possibly mis-aligned memory
|
||||
|
||||
return tud_control_xfer(rhport, p_request, (void*) desc_config, total_len);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_DESC_STRING:
|
||||
// String Descriptor always uses the desc set from user
|
||||
if ( desc_index == 0xEE )
|
||||
{
|
||||
// The 0xEE index string is a Microsoft OS Descriptors.
|
||||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
|
||||
return false;
|
||||
}else
|
||||
{
|
||||
uint8_t const* desc_str = (uint8_t const*) tud_descriptor_string_cb(desc_index);
|
||||
TU_ASSERT(desc_str);
|
||||
|
||||
// first byte of descriptor is its size
|
||||
return tud_control_xfer(rhport, p_request, (void*) desc_str, desc_str[0]);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_DESC_DEVICE_QUALIFIER:
|
||||
// TODO If not highspeed capable stall this request otherwise
|
||||
// return the descriptor that could work in highspeed
|
||||
return false;
|
||||
break;
|
||||
|
||||
default: return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DCD Event Handler
|
||||
//--------------------------------------------------------------------+
|
||||
void dcd_event_handler(dcd_event_t const * event, bool in_isr)
|
||||
{
|
||||
switch (event->event_id)
|
||||
{
|
||||
case DCD_EVENT_BUS_RESET:
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
break;
|
||||
|
||||
case DCD_EVENT_UNPLUGGED:
|
||||
_usbd_dev.connected = 0;
|
||||
_usbd_dev.configured = 0;
|
||||
_usbd_dev.suspended = 0;
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SOF:
|
||||
// nothing to do now
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SUSPEND:
|
||||
// NOTE: When plugging/unplugging device, the D+/D- state are unstable and can accidentally meet the
|
||||
// SUSPEND condition ( Idle for 3ms ). Some MCUs such as SAMD doesn't distinguish suspend vs disconnect as well.
|
||||
// We will skip handling SUSPEND/RESUME event if not currently connected
|
||||
if ( _usbd_dev.connected )
|
||||
{
|
||||
_usbd_dev.suspended = 1;
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
}
|
||||
break;
|
||||
|
||||
case DCD_EVENT_RESUME:
|
||||
if ( _usbd_dev.connected )
|
||||
{
|
||||
_usbd_dev.suspended = 0;
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
}
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SETUP_RECEIVED:
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
break;
|
||||
|
||||
case DCD_EVENT_XFER_COMPLETE:
|
||||
// skip zero-length control status complete event, should DCD notify us.
|
||||
// TODO could cause issue with actual zero length data used by class such as DFU
|
||||
if ( (0 == tu_edpt_number(event->xfer_complete.ep_addr)) && (event->xfer_complete.len == 0) ) break;
|
||||
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
TU_ASSERT(event->xfer_complete.result == XFER_RESULT_SUCCESS,);
|
||||
break;
|
||||
|
||||
// Not an DCD event, just a convenient way to defer ISR function should we need to
|
||||
case USBD_EVENT_FUNC_CALL:
|
||||
osal_queue_send(_usbd_q, event, in_isr);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
// helper to send bus signal event
|
||||
void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr)
|
||||
{
|
||||
dcd_event_t event = { .rhport = rhport, .event_id = eid, };
|
||||
dcd_event_handler(&event, in_isr);
|
||||
}
|
||||
|
||||
// helper to send setup received
|
||||
void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr)
|
||||
{
|
||||
dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_SETUP_RECEIVED };
|
||||
memcpy(&event.setup_received, setup, 8);
|
||||
|
||||
dcd_event_handler(&event, in_isr);
|
||||
}
|
||||
|
||||
// helper to send transfer complete event
|
||||
void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr)
|
||||
{
|
||||
dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_XFER_COMPLETE };
|
||||
|
||||
event.xfer_complete.ep_addr = ep_addr;
|
||||
event.xfer_complete.len = xferred_bytes;
|
||||
event.xfer_complete.result = result;
|
||||
|
||||
dcd_event_handler(&event, in_isr);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Helper
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Parse consecutive endpoint descriptors (IN & OUT)
|
||||
bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in)
|
||||
{
|
||||
for(int i=0; i<ep_count; i++)
|
||||
{
|
||||
tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
|
||||
|
||||
TU_VERIFY(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && xfer_type == desc_ep->bmAttributes.xfer);
|
||||
TU_ASSERT(dcd_edpt_open(rhport, desc_ep));
|
||||
|
||||
if ( tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN )
|
||||
{
|
||||
(*ep_in) = desc_ep->bEndpointAddress;
|
||||
}else
|
||||
{
|
||||
(*ep_out) = desc_ep->bEndpointAddress;
|
||||
}
|
||||
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Helper to defer an isr function
|
||||
void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr)
|
||||
{
|
||||
dcd_event_t event =
|
||||
{
|
||||
.rhport = 0,
|
||||
.event_id = USBD_EVENT_FUNC_CALL,
|
||||
};
|
||||
|
||||
event.func_call.func = func;
|
||||
event.func_call.param = param;
|
||||
|
||||
dcd_event_handler(&event, in_isr);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Endpoint API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
TU_VERIFY( dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes) );
|
||||
|
||||
_usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_busy_map[dir], epnum);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
return tu_bit_test(_usbd_dev.ep_busy_map[dir], epnum);
|
||||
}
|
||||
|
||||
|
||||
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
dcd_edpt_stall(rhport, ep_addr);
|
||||
_usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_stall_map[dir], epnum);
|
||||
}
|
||||
|
||||
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
dcd_edpt_clear_stall(rhport, ep_addr);
|
||||
_usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_stall_map[dir], epnum);
|
||||
}
|
||||
|
||||
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
return tu_bit_test(_usbd_dev.ep_stall_map[dir], epnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,288 +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.
|
||||
*/
|
||||
|
||||
/** \ingroup group_usbd
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_USBD_H_
|
||||
#define _TUSB_USBD_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "dcd.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Task function should be called in main/rtos loop
|
||||
void tud_task (void);
|
||||
|
||||
// Check if device is connected and configured
|
||||
bool tud_mounted(void);
|
||||
|
||||
// Check if device is suspended
|
||||
bool tud_suspended(void);
|
||||
|
||||
// Check if device is ready to transfer
|
||||
static inline bool tud_ready(void)
|
||||
{
|
||||
return tud_mounted() && !tud_suspended();
|
||||
}
|
||||
|
||||
// Remote wake up host, only if suspended and enabled by host
|
||||
bool tud_remote_wakeup(void);
|
||||
|
||||
// Carry out Data and Status stage of control transfer
|
||||
// - If len = 0, it is equivalent to sending status only
|
||||
// - If len > wLength : it will be truncated
|
||||
bool tud_control_xfer(uint8_t rhport, tusb_control_request_t const * request, void* buffer, uint16_t len);
|
||||
|
||||
// Send STATUS (zero length) packet
|
||||
bool tud_control_status(uint8_t rhport, tusb_control_request_t const * request);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application Callbacks (WEAK is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when received GET DEVICE DESCRIPTOR request
|
||||
// Application return pointer to descriptor
|
||||
uint8_t const * tud_descriptor_device_cb(void);
|
||||
|
||||
// Invoked when received GET BOS DESCRIPTOR request
|
||||
// Application return pointer to descriptor
|
||||
TU_ATTR_WEAK uint8_t const * tud_descriptor_bos_cb(void);
|
||||
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR request
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_descriptor_configuration_cb(uint8_t index);
|
||||
|
||||
// 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);
|
||||
|
||||
// Invoked when device is mounted (configured)
|
||||
TU_ATTR_WEAK void tud_mount_cb(void);
|
||||
|
||||
// Invoked when device is unmounted
|
||||
TU_ATTR_WEAK void tud_umount_cb(void);
|
||||
|
||||
// Invoked when usb bus is suspended
|
||||
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
|
||||
TU_ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en);
|
||||
|
||||
// Invoked when usb bus is resumed
|
||||
TU_ATTR_WEAK void tud_resume_cb(void);
|
||||
|
||||
// Invoked when received control request with VENDOR TYPE
|
||||
TU_ATTR_WEAK bool tud_vendor_control_request_cb(uint8_t rhport, tusb_control_request_t const * request);
|
||||
TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_request_t const * request);
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Binary Device Object Store (BOS) Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#define TUD_BOS_DESC_LEN 5
|
||||
|
||||
// total length, number of device caps
|
||||
#define TUD_BOS_DESCRIPTOR(_total_len, _caps_num) \
|
||||
5, TUSB_DESC_BOS, U16_TO_U8S_LE(_total_len), _caps_num
|
||||
|
||||
// Device Capability Platform 128-bit UUID + Data
|
||||
#define TUD_BOS_PLATFORM_DESCRIPTOR(...) \
|
||||
4+TU_ARGS_NUM(__VA_ARGS__), TUSB_DESC_DEVICE_CAPABILITY, DEVICE_CAPABILITY_PLATFORM, 0x00, __VA_ARGS__
|
||||
|
||||
//------------- WebUSB BOS Platform -------------//
|
||||
|
||||
// Descriptor Length
|
||||
#define TUD_BOS_WEBUSB_DESC_LEN 24
|
||||
|
||||
// Vendor Code, iLandingPage
|
||||
#define TUD_BOS_WEBUSB_DESCRIPTOR(_vendor_code, _ipage) \
|
||||
TUD_BOS_PLATFORM_DESCRIPTOR(TUD_BOS_WEBUSB_UUID, U16_TO_U8S_LE(0x0100), _vendor_code, _ipage)
|
||||
|
||||
#define TUD_BOS_WEBUSB_UUID \
|
||||
0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47, \
|
||||
0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65
|
||||
|
||||
//------------- Microsoft OS 2.0 Platform -------------//
|
||||
#define TUD_BOS_MICROSOFT_OS_DESC_LEN 28
|
||||
|
||||
// Total Length of descriptor set, vendor code
|
||||
#define TUD_BOS_MS_OS_20_DESCRIPTOR(_desc_set_len, _vendor_code) \
|
||||
TUD_BOS_PLATFORM_DESCRIPTOR(TUD_BOS_MS_OS_20_UUID, U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(_desc_set_len), _vendor_code, 0)
|
||||
|
||||
#define TUD_BOS_MS_OS_20_UUID \
|
||||
0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, \
|
||||
0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F
|
||||
|
||||
//------------- WebUSB URL -------------//
|
||||
// used to init tusb_desc_webusb_url_t
|
||||
#define TUD_WEBUSB_URL_DESCRIPTOR(_scheme, _url) \
|
||||
{ 3 + sizeof(_url) - 1, 3, _scheme, _url }
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Configuration & Interface Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//------------- Configuration -------------//
|
||||
#define TUD_CONFIG_DESC_LEN (9)
|
||||
|
||||
// Interface count, string index, total length, attribute, power in mA
|
||||
#define TUD_CONFIG_DESCRIPTOR(_itfcount, _stridx, _total_len, _attribute, _power_ma) \
|
||||
9, TUSB_DESC_CONFIGURATION, U16_TO_U8S_LE(_total_len), _itfcount, 1, _stridx, TU_BIT(7) | _attribute, (_power_ma)/2
|
||||
|
||||
//------------- CDC -------------//
|
||||
|
||||
// Length of template descriptor: 66 bytes
|
||||
#define TUD_CDC_DESC_LEN (8+9+5+5+4+5+7+9+7+7)
|
||||
|
||||
// CDC Descriptor Template
|
||||
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
#define TUD_CDC_DESCRIPTOR(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
|
||||
/* Interface Associate */\
|
||||
8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, 0,\
|
||||
/* CDC Control Interface */\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, _stridx,\
|
||||
/* CDC Header */\
|
||||
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\
|
||||
/* CDC Call */\
|
||||
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (_itfnum) + 1,\
|
||||
/* CDC ACM: support line request */\
|
||||
4, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 2,\
|
||||
/* CDC Union */\
|
||||
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (_itfnum) + 1,\
|
||||
/* Endpoint Notification */\
|
||||
7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 16,\
|
||||
/* CDC Data Interface */\
|
||||
9, TUSB_DESC_INTERFACE, (_itfnum)+1, 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
|
||||
/* Endpoint Out */\
|
||||
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
||||
|
||||
//------------- MSC -------------//
|
||||
|
||||
// Length of template descriptor: 23 bytes
|
||||
#define TUD_MSC_DESC_LEN (9 + 7 + 7)
|
||||
|
||||
// Interface number, string index, EP Out & EP In address, EP size
|
||||
#define TUD_MSC_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
|
||||
/* Interface */\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_MSC, MSC_SUBCLASS_SCSI, MSC_PROTOCOL_BOT, _stridx,\
|
||||
/* Endpoint Out */\
|
||||
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
||||
|
||||
//------------- HID -------------//
|
||||
|
||||
// Length of template descriptor: 25 bytes
|
||||
#define TUD_HID_DESC_LEN (9 + 9 + 7)
|
||||
|
||||
// HID Input only descriptor
|
||||
// Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
|
||||
#define TUD_HID_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epin, _epsize, _ep_interval) \
|
||||
/* Interface */\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_HID, (_boot_protocol) ? HID_SUBCLASS_BOOT : 0, _boot_protocol, _stridx,\
|
||||
/* HID descriptor */\
|
||||
9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval
|
||||
|
||||
// Length of template descriptor: 32 bytes
|
||||
#define TUD_HID_INOUT_DESC_LEN (9 + 9 + 7 + 7)
|
||||
|
||||
// HID Input & Output descriptor
|
||||
// Interface number, string index, protocol, report descriptor len, EP OUT & IN address, size & polling interval
|
||||
#define TUD_HID_INOUT_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epout, _epin, _epsize, _ep_interval) \
|
||||
/* Interface */\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_HID, (_boot_protocol) ? HID_SUBCLASS_BOOT : 0, _boot_protocol, _stridx,\
|
||||
/* HID descriptor */\
|
||||
9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
|
||||
/* Endpoint Out */\
|
||||
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval, \
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval
|
||||
|
||||
//------------- MIDI -------------//
|
||||
|
||||
// Length of template descriptor (96 bytes)
|
||||
#define TUD_MIDI_DESC_LEN (9 + 9 + 9 + 7 + 6 + 6 + 9 + 9 + 7 + 5 + 7 + 5)
|
||||
|
||||
// MIDI simple descriptor
|
||||
// - 1 Embedded Jack In connected to 1 External Jack Out
|
||||
// - 1 Embedded Jack out connected to 1 External Jack In
|
||||
#define TUD_MIDI_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
|
||||
/* Audio Control (AC) Interface */\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_PROTOCOL_V1, _stridx,\
|
||||
/* AC Header */\
|
||||
9, TUSB_DESC_CS_INTERFACE, AUDIO_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0009), 1, _itfnum+1,\
|
||||
/* MIDI Streaming (MS) Interface */\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum+1, 0, 2, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_MIDI_STREAMING, AUDIO_PROTOCOL_V1, 0,\
|
||||
/* MS Header */\
|
||||
7, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0025),\
|
||||
/* MS In Jack (Embedded) */\
|
||||
6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EMBEDDED, 1, 0,\
|
||||
/* MS In Jack (External) */\
|
||||
6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EXTERNAL, 2, 0,\
|
||||
/* MS Out Jack (Embedded), connected to In Jack External */\
|
||||
9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EMBEDDED, 3, 1, 2, 1, 0,\
|
||||
/* MS Out Jack (External), connected to In Jack Embedded */\
|
||||
9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EXTERNAL, 4, 1, 1, 1, 0,\
|
||||
/* Endpoint Out */\
|
||||
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
|
||||
/* MS Endpoint (connected to embedded jack in) */\
|
||||
5, TUSB_DESC_CS_ENDPOINT, MIDI_CS_ENDPOINT_GENERAL, 1, 1,\
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
|
||||
/* MS Endpoint (connected to embedded jack out) */\
|
||||
5, TUSB_DESC_CS_ENDPOINT, MIDI_CS_ENDPOINT_GENERAL, 1, 3
|
||||
|
||||
//------------- Vendor -------------//
|
||||
#define TUD_VENDOR_DESC_LEN (9+7+7)
|
||||
|
||||
// Interface number, string index, EP Out & IN address, EP size
|
||||
#define TUD_VENDOR_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
|
||||
/* Interface */\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_VENDOR_SPECIFIC, 0x00, 0x00, _stridx,\
|
||||
/* Endpoint Out */\
|
||||
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_USBD_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -1,159 +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 "tusb_option.h"
|
||||
|
||||
#if TUSB_OPT_DEVICE_ENABLED
|
||||
|
||||
#include "tusb.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
#include "dcd.h"
|
||||
|
||||
enum
|
||||
{
|
||||
EDPT_CTRL_OUT = 0x00,
|
||||
EDPT_CTRL_IN = 0x80
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tusb_control_request_t request;
|
||||
|
||||
void* buffer;
|
||||
uint16_t total_len;
|
||||
uint16_t total_transferred;
|
||||
|
||||
bool (*complete_cb) (uint8_t, tusb_control_request_t const *);
|
||||
} usbd_control_xfer_t;
|
||||
|
||||
static usbd_control_xfer_t _control_state;
|
||||
|
||||
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t _usbd_ctrl_buf[CFG_TUD_ENDOINT0_SIZE];
|
||||
|
||||
void usbd_control_reset (uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
tu_varclr(&_control_state);
|
||||
}
|
||||
|
||||
bool tud_control_status(uint8_t rhport, tusb_control_request_t const * request)
|
||||
{
|
||||
// status direction is reversed to one in the setup packet
|
||||
return dcd_edpt_xfer(rhport, request->bmRequestType_bit.direction ? EDPT_CTRL_OUT : EDPT_CTRL_IN, NULL, 0);
|
||||
}
|
||||
|
||||
// Each transaction is up to endpoint0's max packet size
|
||||
static bool start_control_data_xact(uint8_t rhport)
|
||||
{
|
||||
uint16_t const xact_len = tu_min16(_control_state.total_len - _control_state.total_transferred, CFG_TUD_ENDOINT0_SIZE);
|
||||
|
||||
uint8_t ep_addr = EDPT_CTRL_OUT;
|
||||
|
||||
if ( _control_state.request.bmRequestType_bit.direction == TUSB_DIR_IN )
|
||||
{
|
||||
ep_addr = EDPT_CTRL_IN;
|
||||
memcpy(_usbd_ctrl_buf, _control_state.buffer, xact_len);
|
||||
}
|
||||
|
||||
return dcd_edpt_xfer(rhport, ep_addr, _usbd_ctrl_buf, xact_len);
|
||||
}
|
||||
|
||||
// TODO may find a better way
|
||||
void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_request_t const * ) )
|
||||
{
|
||||
_control_state.complete_cb = fp;
|
||||
}
|
||||
|
||||
bool tud_control_xfer(uint8_t rhport, tusb_control_request_t const * request, void* buffer, uint16_t len)
|
||||
{
|
||||
_control_state.request = (*request);
|
||||
_control_state.buffer = buffer;
|
||||
_control_state.total_len = tu_min16(len, request->wLength);
|
||||
_control_state.total_transferred = 0;
|
||||
|
||||
if ( len )
|
||||
{
|
||||
TU_ASSERT(buffer);
|
||||
|
||||
// Data stage
|
||||
TU_ASSERT( start_control_data_xact(rhport) );
|
||||
}else
|
||||
{
|
||||
// Status stage
|
||||
TU_ASSERT( tud_control_status(rhport, request) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// callback when a transaction complete on DATA stage of control endpoint
|
||||
bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
||||
{
|
||||
(void) result;
|
||||
(void) ep_addr;
|
||||
|
||||
if ( _control_state.request.bmRequestType_bit.direction == TUSB_DIR_OUT )
|
||||
{
|
||||
TU_VERIFY(_control_state.buffer);
|
||||
memcpy(_control_state.buffer, _usbd_ctrl_buf, xferred_bytes);
|
||||
}
|
||||
|
||||
_control_state.total_transferred += xferred_bytes;
|
||||
_control_state.buffer += xferred_bytes;
|
||||
|
||||
if ( _control_state.total_len == _control_state.total_transferred || xferred_bytes < CFG_TUD_ENDOINT0_SIZE )
|
||||
{
|
||||
// DATA stage is complete
|
||||
bool is_ok = true;
|
||||
|
||||
// invoke complete callback if set
|
||||
// callback can still stall control in status phase e.g out data does not make sense
|
||||
if ( _control_state.complete_cb )
|
||||
{
|
||||
is_ok = _control_state.complete_cb(rhport, &_control_state.request);
|
||||
}
|
||||
|
||||
if ( is_ok )
|
||||
{
|
||||
// Send status
|
||||
TU_ASSERT( tud_control_status(rhport, &_control_state.request) );
|
||||
}else
|
||||
{
|
||||
// Stall both IN and OUT control endpoint
|
||||
dcd_edpt_stall(rhport, EDPT_CTRL_OUT);
|
||||
dcd_edpt_stall(rhport, EDPT_CTRL_IN);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// More data to transfer
|
||||
TU_ASSERT( start_control_data_xact(rhport) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,66 +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.
|
||||
*/
|
||||
#ifndef USBD_PVT_H_
|
||||
#define USBD_PVT_H_
|
||||
|
||||
#include "osal/osal.h"
|
||||
#include "common/tusb_fifo.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool usbd_init (void);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Endpoint API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
|
||||
|
||||
// Submit a usb transfer
|
||||
bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
|
||||
|
||||
// Check if endpoint transferring is complete
|
||||
bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr);
|
||||
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr);
|
||||
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Helper
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in);
|
||||
void usbd_defer_func( osal_task_func_t func, void* param, bool in_isr );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBD_PVT_H_ */
|
||||
@@ -1,101 +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.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_OSAL_H_
|
||||
#define _TUSB_OSAL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \addtogroup group_osal
|
||||
* @{ */
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
enum
|
||||
{
|
||||
OSAL_TIMEOUT_NOTIMEOUT = 0, // return immediately
|
||||
OSAL_TIMEOUT_NORMAL = 10, // default timeout
|
||||
OSAL_TIMEOUT_WAIT_FOREVER = 0xFFFFFFFFUL
|
||||
};
|
||||
|
||||
#define OSAL_TIMEOUT_CONTROL_XFER OSAL_TIMEOUT_WAIT_FOREVER
|
||||
|
||||
typedef void (*osal_task_func_t)( void * );
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
#include "osal_none.h"
|
||||
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
#include "osal_freertos.h"
|
||||
#elif CFG_TUSB_OS == OPT_OS_MYNEWT
|
||||
#include "osal_mynewt.h"
|
||||
#else
|
||||
#error OS is not supported yet
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// OSAL Porting API
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void osal_task_delay(uint32_t msec);
|
||||
|
||||
//------------- Semaphore -------------//
|
||||
static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef);
|
||||
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr);
|
||||
static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec);
|
||||
|
||||
static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl); // TODO removed
|
||||
|
||||
//------------- Mutex -------------//
|
||||
static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef);
|
||||
static inline bool osal_mutex_lock (osal_mutex_t sem_hdl, uint32_t msec);
|
||||
static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl);
|
||||
|
||||
//------------- Queue -------------//
|
||||
static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
|
||||
static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data);
|
||||
static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr);
|
||||
|
||||
#if 0 // TODO remove subtask related macros later
|
||||
// Sub Task
|
||||
#define OSAL_SUBTASK_BEGIN
|
||||
#define OSAL_SUBTASK_END return TUSB_ERROR_NONE;
|
||||
|
||||
#define STASK_RETURN(_error) return _error;
|
||||
#define STASK_INVOKE(_subtask, _status) (_status) = _subtask
|
||||
|
||||
// Sub Task Assert
|
||||
#define STASK_ASSERT_ERR(_err) TU_VERIFY_ERR(_err)
|
||||
#define STASK_ASSERT(_cond) TU_VERIFY(_cond, TUSB_ERROR_OSAL_TASK_FAILED)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* _TUSB_OSAL_H_ */
|
||||
@@ -1,135 +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.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_OSAL_FREERTOS_H_
|
||||
#define _TUSB_OSAL_FREERTOS_H_
|
||||
|
||||
// FreeRTOS Headers
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "queue.h"
|
||||
#include "task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// TASK API
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void osal_task_delay(uint32_t msec)
|
||||
{
|
||||
vTaskDelay( pdMS_TO_TICKS(msec) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Semaphore API
|
||||
//--------------------------------------------------------------------+
|
||||
typedef StaticSemaphore_t osal_semaphore_def_t;
|
||||
typedef SemaphoreHandle_t osal_semaphore_t;
|
||||
|
||||
static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
|
||||
{
|
||||
return xSemaphoreCreateBinaryStatic(semdef);
|
||||
}
|
||||
|
||||
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
|
||||
{
|
||||
return in_isr ? xSemaphoreGiveFromISR(sem_hdl, NULL) : xSemaphoreGive(sem_hdl);
|
||||
}
|
||||
|
||||
static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec)
|
||||
{
|
||||
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec);
|
||||
return xSemaphoreTake(sem_hdl, ticks);
|
||||
}
|
||||
|
||||
static inline void osal_semaphore_reset(osal_semaphore_t const sem_hdl)
|
||||
{
|
||||
xQueueReset(sem_hdl);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MUTEX API (priority inheritance)
|
||||
//--------------------------------------------------------------------+
|
||||
typedef StaticSemaphore_t osal_mutex_def_t;
|
||||
typedef SemaphoreHandle_t osal_mutex_t;
|
||||
|
||||
static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
|
||||
{
|
||||
return xSemaphoreCreateMutexStatic(mdef);
|
||||
}
|
||||
|
||||
static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec)
|
||||
{
|
||||
return osal_semaphore_wait(mutex_hdl, msec);
|
||||
}
|
||||
|
||||
static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
|
||||
{
|
||||
return xSemaphoreGive(mutex_hdl);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// QUEUE API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// role device/host is used by OS NONE for mutex (disable usb isr) only
|
||||
#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \
|
||||
static _type _name##_##buf[_depth];\
|
||||
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf };
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t depth;
|
||||
uint16_t item_sz;
|
||||
void* buf;
|
||||
|
||||
StaticQueue_t sq;
|
||||
}osal_queue_def_t;
|
||||
|
||||
typedef QueueHandle_t osal_queue_t;
|
||||
|
||||
static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
|
||||
{
|
||||
return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq);
|
||||
}
|
||||
|
||||
static inline bool osal_queue_receive(osal_queue_t const queue_hdl, void* data)
|
||||
{
|
||||
return xQueueReceive(queue_hdl, data, portMAX_DELAY);
|
||||
}
|
||||
|
||||
static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
|
||||
{
|
||||
return in_isr ? xQueueSendToBackFromISR(queue_hdl, data, NULL) : xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_OSAL_FREERTOS_H_ */
|
||||
@@ -1,168 +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.
|
||||
*/
|
||||
|
||||
#ifndef OSAL_MYNEWT_H_
|
||||
#define OSAL_MYNEWT_H_
|
||||
|
||||
#include "os/os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// TASK API
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void osal_task_delay(uint32_t msec)
|
||||
{
|
||||
os_time_delay( os_time_ms_to_ticks32(msec) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Semaphore API
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct os_sem osal_semaphore_def_t;
|
||||
typedef struct os_sem* osal_semaphore_t;
|
||||
|
||||
static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
|
||||
{
|
||||
return (os_sem_init(semdef, 0) == OS_OK) ? (osal_semaphore_t) semdef : NULL;
|
||||
}
|
||||
|
||||
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
|
||||
{
|
||||
(void) in_isr;
|
||||
return os_sem_release(sem_hdl) == OS_OK;
|
||||
}
|
||||
|
||||
static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec)
|
||||
{
|
||||
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? OS_TIMEOUT_NEVER : os_time_ms_to_ticks32(msec);
|
||||
return os_sem_pend(sem_hdl, ticks) == OS_OK;
|
||||
}
|
||||
|
||||
static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl)
|
||||
{
|
||||
// TODO implement later
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MUTEX API (priority inheritance)
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct os_mutex osal_mutex_def_t;
|
||||
typedef struct os_mutex* osal_mutex_t;
|
||||
|
||||
static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
|
||||
{
|
||||
return (os_mutex_init(mdef) == OS_OK) ? (osal_mutex_t) mdef : NULL;
|
||||
}
|
||||
|
||||
static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec)
|
||||
{
|
||||
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? OS_TIMEOUT_NEVER : os_time_ms_to_ticks32(msec);
|
||||
return os_mutex_pend(mutex_hdl, ticks) == OS_OK;
|
||||
}
|
||||
|
||||
static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
|
||||
{
|
||||
return os_mutex_release(mutex_hdl) == OS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// QUEUE API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// role device/host is used by OS NONE for mutex (disable usb isr) only
|
||||
#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \
|
||||
static _type _name##_##buf[_depth];\
|
||||
static struct os_event* _name##_##evbuf[_depth];\
|
||||
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf, .evbuf = _name##_##evbuf};\
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t depth;
|
||||
uint16_t item_sz;
|
||||
void* buf;
|
||||
void* evbuf;
|
||||
|
||||
struct os_mempool mpool;
|
||||
struct os_mempool epool;
|
||||
|
||||
struct os_eventq evq;
|
||||
}osal_queue_def_t;
|
||||
|
||||
typedef osal_queue_def_t* osal_queue_t;
|
||||
|
||||
static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
|
||||
{
|
||||
if ( OS_OK != os_mempool_init(&qdef->mpool, qdef->depth, qdef->item_sz, qdef->buf, "usbd queue") ) return NULL;
|
||||
if ( OS_OK != os_mempool_init(&qdef->epool, qdef->depth, sizeof(struct os_event), qdef->evbuf, "usbd evqueue") ) return NULL;
|
||||
|
||||
os_eventq_init(&qdef->evq);
|
||||
return (osal_queue_t) qdef;
|
||||
}
|
||||
|
||||
static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data)
|
||||
{
|
||||
struct os_event* ev;
|
||||
ev = os_eventq_get(&qhdl->evq);
|
||||
|
||||
memcpy(data, ev->ev_arg, qhdl->item_sz); // copy message
|
||||
os_memblock_put(&qhdl->mpool, ev->ev_arg); // put back mem block
|
||||
os_memblock_put(&qhdl->epool, ev); // put back ev block
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr)
|
||||
{
|
||||
(void) in_isr;
|
||||
|
||||
// get a block from mem pool for data
|
||||
void* ptr = os_memblock_get(&qhdl->mpool);
|
||||
if (!ptr) return false;
|
||||
memcpy(ptr, data, qhdl->item_sz);
|
||||
|
||||
// get a block from event pool to put into queue
|
||||
struct os_event* ev = (struct os_event*) os_memblock_get(&qhdl->epool);
|
||||
if (!ev)
|
||||
{
|
||||
os_memblock_put(&qhdl->mpool, ptr);
|
||||
return false;
|
||||
}
|
||||
tu_memclr(ev, sizeof(struct os_event));
|
||||
ev->ev_arg = ptr;
|
||||
|
||||
os_eventq_put(&qhdl->evq, ev);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OSAL_MYNEWT_H_ */
|
||||
@@ -1,204 +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.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_OSAL_NONE_H_
|
||||
#define _TUSB_OSAL_NONE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// TASK API
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void osal_task_delay(uint32_t msec)
|
||||
{
|
||||
(void) msec;
|
||||
// TODO only used by Host stack, will implement using SOF
|
||||
|
||||
// uint32_t start = tusb_hal_millis();
|
||||
// while ( ( tusb_hal_millis() - start ) < msec ) {}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Binary Semaphore API
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct
|
||||
{
|
||||
volatile uint16_t count;
|
||||
}osal_semaphore_def_t;
|
||||
|
||||
typedef osal_semaphore_def_t* osal_semaphore_t;
|
||||
|
||||
static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
|
||||
{
|
||||
semdef->count = 0;
|
||||
return semdef;
|
||||
}
|
||||
|
||||
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
|
||||
{
|
||||
(void) in_isr;
|
||||
sem_hdl->count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO blocking for now
|
||||
static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec)
|
||||
{
|
||||
(void) msec;
|
||||
|
||||
while (sem_hdl->count == 0) { }
|
||||
sem_hdl->count--;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl)
|
||||
{
|
||||
sem_hdl->count = 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MUTEX API
|
||||
// Within tinyusb, mutex is never used in ISR context
|
||||
//--------------------------------------------------------------------+
|
||||
typedef osal_semaphore_def_t osal_mutex_def_t;
|
||||
typedef osal_semaphore_t osal_mutex_t;
|
||||
|
||||
static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
|
||||
{
|
||||
mdef->count = 1;
|
||||
return mdef;
|
||||
}
|
||||
|
||||
static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec)
|
||||
{
|
||||
return osal_semaphore_wait(mutex_hdl, msec);
|
||||
}
|
||||
|
||||
static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
|
||||
{
|
||||
return osal_semaphore_post(mutex_hdl, false);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// QUEUE API
|
||||
//--------------------------------------------------------------------+
|
||||
#include "common/tusb_fifo.h"
|
||||
|
||||
// extern to avoid including dcd.h and hcd.h
|
||||
#if TUSB_OPT_DEVICE_ENABLED
|
||||
extern void dcd_int_disable(uint8_t rhport);
|
||||
extern void dcd_int_enable(uint8_t rhport);
|
||||
#endif
|
||||
|
||||
#if TUSB_OPT_HOST_ENABLED
|
||||
extern void hcd_int_disable(uint8_t rhport);
|
||||
extern void hcd_int_enable(uint8_t rhport);
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t role; // device or host
|
||||
tu_fifo_t ff;
|
||||
}osal_queue_def_t;
|
||||
|
||||
typedef osal_queue_def_t* osal_queue_t;
|
||||
|
||||
// role device/host is used by OS NONE for mutex (disable usb isr) only
|
||||
#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \
|
||||
uint8_t _name##_buf[_depth*sizeof(_type)]; \
|
||||
osal_queue_def_t _name = { \
|
||||
.role = _role, \
|
||||
.ff = { \
|
||||
.buffer = _name##_buf, \
|
||||
.depth = _depth, \
|
||||
.item_size = sizeof(_type), \
|
||||
.overwritable = false, \
|
||||
}\
|
||||
}
|
||||
|
||||
// lock queue by disable usb isr
|
||||
static inline void _osal_q_lock(osal_queue_t qhdl)
|
||||
{
|
||||
#if TUSB_OPT_DEVICE_ENABLED
|
||||
if (qhdl->role == OPT_MODE_DEVICE) dcd_int_disable(TUD_OPT_RHPORT);
|
||||
#endif
|
||||
|
||||
#if TUSB_OPT_HOST_ENABLED
|
||||
if (qhdl->role == OPT_MODE_HOST) hcd_int_disable(TUH_OPT_RHPORT);
|
||||
#endif
|
||||
}
|
||||
|
||||
// unlock queue
|
||||
static inline void _osal_q_unlock(osal_queue_t qhdl)
|
||||
{
|
||||
#if TUSB_OPT_DEVICE_ENABLED
|
||||
if (qhdl->role == OPT_MODE_DEVICE) dcd_int_enable(TUD_OPT_RHPORT);
|
||||
#endif
|
||||
|
||||
#if TUSB_OPT_HOST_ENABLED
|
||||
if (qhdl->role == OPT_MODE_HOST) hcd_int_enable(TUH_OPT_RHPORT);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
|
||||
{
|
||||
tu_fifo_clear(&qdef->ff);
|
||||
return (osal_queue_t) qdef;
|
||||
}
|
||||
|
||||
// non blocking
|
||||
static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data)
|
||||
{
|
||||
_osal_q_lock(qhdl);
|
||||
bool success = tu_fifo_read(&qhdl->ff, data);
|
||||
_osal_q_unlock(qhdl);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr)
|
||||
{
|
||||
if (!in_isr) {
|
||||
_osal_q_lock(qhdl);
|
||||
}
|
||||
|
||||
bool success = tu_fifo_write(&qhdl->ff, data);
|
||||
|
||||
if (!in_isr) {
|
||||
_osal_q_unlock(qhdl);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_OSAL_NONE_H_ */
|
||||
@@ -1,544 +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 "tusb_option.h"
|
||||
|
||||
#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_NRF5X
|
||||
|
||||
#include "nrf.h"
|
||||
#include "nrf_power.h"
|
||||
#include "nrf_usbd.h"
|
||||
#include "nrf_clock.h"
|
||||
|
||||
#include "device/dcd.h"
|
||||
|
||||
// TODO remove later
|
||||
#include "device/usbd.h"
|
||||
#include "device/usbd_pvt.h" // to use defer function helper
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* MACRO TYPEDEF CONSTANT ENUM
|
||||
*------------------------------------------------------------------*/
|
||||
enum
|
||||
{
|
||||
// Max allowed by USB specs
|
||||
MAX_PACKET_SIZE = 64,
|
||||
|
||||
// Mask of all END event (IN & OUT) for all endpoints. ENDEPIN0-7, ENDEPOUT0-7, ENDISOIN, ENDISOOUT
|
||||
EDPT_END_ALL_MASK = (0xff << USBD_INTEN_ENDEPIN0_Pos) | (0xff << USBD_INTEN_ENDEPOUT0_Pos) |
|
||||
USBD_INTENCLR_ENDISOIN_Msk | USBD_INTEN_ENDISOOUT_Msk
|
||||
};
|
||||
|
||||
// Transfer descriptor
|
||||
typedef struct
|
||||
{
|
||||
uint8_t* buffer;
|
||||
uint16_t total_len;
|
||||
volatile uint16_t actual_len;
|
||||
uint8_t mps; // max packet size
|
||||
|
||||
// nrf52840 will auto ACK OUT packet after DMA is done
|
||||
// indicate packet is already ACK
|
||||
volatile bool data_received;
|
||||
|
||||
} xfer_td_t;
|
||||
|
||||
// Data for managing dcd
|
||||
static struct
|
||||
{
|
||||
// All 8 endpoints including control IN & OUT (offset 1)
|
||||
xfer_td_t xfer[8][2];
|
||||
|
||||
// Only one DMA can run at a time
|
||||
volatile bool dma_running;
|
||||
}_dcd;
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Control / Bulk / Interrupt (CBI) Transfer
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
// helper to start DMA
|
||||
static void edpt_dma_start(volatile uint32_t* reg_startep)
|
||||
{
|
||||
// Only one dma can be active
|
||||
if ( _dcd.dma_running )
|
||||
{
|
||||
if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)
|
||||
{
|
||||
// If called within ISR, use usbd task to defer later
|
||||
usbd_defer_func( (osal_task_func_t) edpt_dma_start, (void*) reg_startep, true );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise simply block wait
|
||||
while ( _dcd.dma_running ) { }
|
||||
}
|
||||
}
|
||||
|
||||
_dcd.dma_running = true;
|
||||
|
||||
(*reg_startep) = 1;
|
||||
__ISB(); __DSB();
|
||||
}
|
||||
|
||||
// DMA is complete
|
||||
static void edpt_dma_end(void)
|
||||
{
|
||||
TU_ASSERT(_dcd.dma_running, );
|
||||
_dcd.dma_running = false;
|
||||
}
|
||||
|
||||
// helper getting td
|
||||
static inline xfer_td_t* get_td(uint8_t epnum, uint8_t dir)
|
||||
{
|
||||
return &_dcd.xfer[epnum][dir];
|
||||
}
|
||||
|
||||
/*------------- CBI OUT Transfer -------------*/
|
||||
|
||||
// Prepare for a CBI transaction OUT, call at the start
|
||||
// Allow ACK incoming data
|
||||
static void xact_out_prepare(uint8_t epnum)
|
||||
{
|
||||
if ( epnum == 0 )
|
||||
{
|
||||
NRF_USBD->TASKS_EP0RCVOUT = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write zero value to SIZE register will allow hw to ACK (accept data)
|
||||
// If it is not already done by DMA
|
||||
NRF_USBD->SIZE.EPOUT[epnum] = 0;
|
||||
}
|
||||
|
||||
__ISB(); __DSB();
|
||||
}
|
||||
|
||||
// Start DMA to move data from Endpoint -> RAM
|
||||
static void xact_out_dma(uint8_t epnum)
|
||||
{
|
||||
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT);
|
||||
|
||||
uint8_t const xact_len = NRF_USBD->SIZE.EPOUT[epnum];
|
||||
|
||||
// Trigger DMA move data from Endpoint -> SRAM
|
||||
NRF_USBD->EPOUT[epnum].PTR = (uint32_t) xfer->buffer;
|
||||
NRF_USBD->EPOUT[epnum].MAXCNT = xact_len;
|
||||
|
||||
edpt_dma_start(&NRF_USBD->TASKS_STARTEPOUT[epnum]);
|
||||
|
||||
xfer->buffer += xact_len;
|
||||
xfer->actual_len += xact_len;
|
||||
}
|
||||
|
||||
/*------------- CBI IN Transfer -------------*/
|
||||
|
||||
// Prepare for a CBI transaction IN, call at the start
|
||||
// it start DMA to transfer data from RAM -> Endpoint
|
||||
static void xact_in_prepare(uint8_t epnum)
|
||||
{
|
||||
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_IN);
|
||||
|
||||
// Each transaction is up to Max Packet Size
|
||||
uint8_t const xact_len = tu_min16(xfer->total_len - xfer->actual_len, xfer->mps);
|
||||
|
||||
NRF_USBD->EPIN[epnum].PTR = (uint32_t) xfer->buffer;
|
||||
NRF_USBD->EPIN[epnum].MAXCNT = xact_len;
|
||||
|
||||
xfer->buffer += xact_len;
|
||||
|
||||
edpt_dma_start(&NRF_USBD->TASKS_STARTEPIN[epnum]);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Controller API
|
||||
//--------------------------------------------------------------------+
|
||||
void dcd_init (uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
}
|
||||
|
||||
void dcd_int_enable(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
NVIC_EnableIRQ(USBD_IRQn);
|
||||
}
|
||||
|
||||
void dcd_int_disable(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
NVIC_DisableIRQ(USBD_IRQn);
|
||||
}
|
||||
|
||||
void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
(void) dev_addr;
|
||||
// Set Address is automatically update by hw controller, nothing to do
|
||||
|
||||
// Enable usbevent for suspend and resume detection
|
||||
// Since the bus signal D+/D- are stable now.
|
||||
|
||||
// Clear current pending first
|
||||
NRF_USBD->EVENTCAUSE |= NRF_USBD->EVENTCAUSE;
|
||||
NRF_USBD->EVENTS_USBEVENT = 0;
|
||||
|
||||
NRF_USBD->INTENSET = USBD_INTEN_USBEVENT_Msk;
|
||||
}
|
||||
|
||||
void dcd_set_config (uint8_t rhport, uint8_t config_num)
|
||||
{
|
||||
(void) rhport;
|
||||
(void) config_num;
|
||||
}
|
||||
|
||||
void dcd_remote_wakeup(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
// Bring controller out of low power mode
|
||||
NRF_USBD->LOWPOWER = 0;
|
||||
|
||||
// Initiate RESUME signal
|
||||
NRF_USBD->DPDMVALUE = USBD_DPDMVALUE_STATE_Resume;
|
||||
NRF_USBD->TASKS_DPDMDRIVE = 1;
|
||||
|
||||
// TODO There is no USBEVENT Resume interrupt
|
||||
// We may manually raise DCD_EVENT_RESUME event here
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Endpoint API
|
||||
//--------------------------------------------------------------------+
|
||||
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress);
|
||||
uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress);
|
||||
|
||||
_dcd.xfer[epnum][dir].mps = desc_edpt->wMaxPacketSize.size;
|
||||
|
||||
if ( dir == TUSB_DIR_OUT )
|
||||
{
|
||||
NRF_USBD->INTENSET = TU_BIT(USBD_INTEN_ENDEPOUT0_Pos + epnum);
|
||||
NRF_USBD->EPOUTEN |= TU_BIT(epnum);
|
||||
}else
|
||||
{
|
||||
NRF_USBD->INTENSET = TU_BIT(USBD_INTEN_ENDEPIN0_Pos + epnum);
|
||||
NRF_USBD->EPINEN |= TU_BIT(epnum);
|
||||
}
|
||||
__ISB(); __DSB();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
xfer_td_t* xfer = get_td(epnum, dir);
|
||||
|
||||
xfer->buffer = buffer;
|
||||
xfer->total_len = total_bytes;
|
||||
xfer->actual_len = 0;
|
||||
|
||||
// Control endpoint with zero-length packet --> status stage
|
||||
if ( epnum == 0 && total_bytes == 0 )
|
||||
{
|
||||
// Status Phase also require Easy DMA has to be free as well !!!!
|
||||
edpt_dma_start(&NRF_USBD->TASKS_EP0STATUS);
|
||||
edpt_dma_end();
|
||||
|
||||
// The nRF doesn't interrupt on status transmit so we queue up a success response.
|
||||
dcd_event_xfer_complete(0, ep_addr, 0, XFER_RESULT_SUCCESS, false);
|
||||
}
|
||||
else if ( dir == TUSB_DIR_OUT )
|
||||
{
|
||||
if ( xfer->data_received )
|
||||
{
|
||||
// nrf52840 auto ACK OUT packet after DMA is done
|
||||
// Data already received previously --> trigger DMA to copy to SRAM
|
||||
xact_out_dma(epnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
xact_out_prepare(epnum);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xact_in_prepare(epnum);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
if ( tu_edpt_number(ep_addr) == 0 )
|
||||
{
|
||||
NRF_USBD->TASKS_EP0STALL = 1;
|
||||
}else
|
||||
{
|
||||
NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_Stall << USBD_EPSTALL_STALL_Pos) | ep_addr;
|
||||
}
|
||||
|
||||
__ISB(); __DSB();
|
||||
}
|
||||
|
||||
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
if ( tu_edpt_number(ep_addr) )
|
||||
{
|
||||
// clear stall
|
||||
NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_UnStall << USBD_EPSTALL_STALL_Pos) | ep_addr;
|
||||
|
||||
// reset data toggle to DATA0
|
||||
NRF_USBD->DTOGGLE = (USBD_DTOGGLE_VALUE_Data0 << USBD_DTOGGLE_VALUE_Pos) | ep_addr;
|
||||
|
||||
__ISB(); __DSB();
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Interrupt Handler
|
||||
*------------------------------------------------------------------*/
|
||||
void bus_reset(void)
|
||||
{
|
||||
for(int i=0; i<8; i++)
|
||||
{
|
||||
NRF_USBD->TASKS_STARTEPIN[i] = 0;
|
||||
NRF_USBD->TASKS_STARTEPOUT[i] = 0;
|
||||
}
|
||||
|
||||
NRF_USBD->TASKS_STARTISOIN = 0;
|
||||
NRF_USBD->TASKS_STARTISOOUT = 0;
|
||||
|
||||
tu_varclr(&_dcd);
|
||||
_dcd.xfer[0][TUSB_DIR_IN].mps = MAX_PACKET_SIZE;
|
||||
_dcd.xfer[0][TUSB_DIR_OUT].mps = MAX_PACKET_SIZE;
|
||||
}
|
||||
|
||||
void USBD_IRQHandler(void)
|
||||
{
|
||||
uint32_t const inten = NRF_USBD->INTEN;
|
||||
uint32_t int_status = 0;
|
||||
|
||||
volatile uint32_t* regevt = &NRF_USBD->EVENTS_USBRESET;
|
||||
|
||||
for(uint8_t i=0; i<USBD_INTEN_EPDATA_Pos+1; i++)
|
||||
{
|
||||
if ( tu_bit_test(inten, i) && regevt[i] )
|
||||
{
|
||||
int_status |= TU_BIT(i);
|
||||
|
||||
// event clear
|
||||
regevt[i] = 0;
|
||||
__ISB(); __DSB();
|
||||
}
|
||||
}
|
||||
|
||||
if ( int_status & USBD_INTEN_USBRESET_Msk )
|
||||
{
|
||||
bus_reset();
|
||||
dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true);
|
||||
}
|
||||
|
||||
if ( int_status & USBD_INTEN_SOF_Msk )
|
||||
{
|
||||
dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
|
||||
}
|
||||
|
||||
if ( int_status & USBD_INTEN_USBEVENT_Msk )
|
||||
{
|
||||
uint32_t const evt_cause = NRF_USBD->EVENTCAUSE & (USBD_EVENTCAUSE_SUSPEND_Msk | USBD_EVENTCAUSE_RESUME_Msk);
|
||||
NRF_USBD->EVENTCAUSE = evt_cause; // clear interrupt
|
||||
|
||||
if ( evt_cause & USBD_EVENTCAUSE_SUSPEND_Msk )
|
||||
{
|
||||
dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
|
||||
|
||||
// Put controller into low power mode
|
||||
NRF_USBD->LOWPOWER = 1;
|
||||
|
||||
// Leave HFXO disable to application, since it may be used by other
|
||||
}
|
||||
|
||||
if ( evt_cause & USBD_EVENTCAUSE_RESUME_Msk )
|
||||
{
|
||||
dcd_event_bus_signal(0, DCD_EVENT_RESUME , true);
|
||||
}
|
||||
}
|
||||
|
||||
if ( int_status & EDPT_END_ALL_MASK )
|
||||
{
|
||||
// DMA complete move data from SRAM -> Endpoint
|
||||
edpt_dma_end();
|
||||
}
|
||||
|
||||
// Setup tokens are specific to the Control endpoint.
|
||||
if ( int_status & USBD_INTEN_EP0SETUP_Msk )
|
||||
{
|
||||
uint8_t const setup[8] = {
|
||||
NRF_USBD->BMREQUESTTYPE , NRF_USBD->BREQUEST, NRF_USBD->WVALUEL , NRF_USBD->WVALUEH,
|
||||
NRF_USBD->WINDEXL , NRF_USBD->WINDEXH , NRF_USBD->WLENGTHL, NRF_USBD->WLENGTHH
|
||||
};
|
||||
|
||||
// nrf5x hw auto handle set address, there is no need to inform usb stack
|
||||
tusb_control_request_t const * request = (tusb_control_request_t const *) setup;
|
||||
|
||||
if ( !(TUSB_REQ_RCPT_DEVICE == request->bmRequestType_bit.recipient &&
|
||||
TUSB_REQ_TYPE_STANDARD == request->bmRequestType_bit.type &&
|
||||
TUSB_REQ_SET_ADDRESS == request->bRequest) )
|
||||
{
|
||||
dcd_event_setup_received(0, setup, true);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
/* Control/Bulk/Interrupt (CBI) Transfer
|
||||
*
|
||||
* Data flow is:
|
||||
* (bus) (dma)
|
||||
* Host <-------> Endpoint <-------> RAM
|
||||
*
|
||||
* For CBI OUT:
|
||||
* - Host -> Endpoint
|
||||
* EPDATA (or EP0DATADONE) interrupted, check EPDATASTATUS.EPOUT[i]
|
||||
* to start DMA. This step can occur automatically (without sw),
|
||||
* which means data may or may not ready (data_received flag).
|
||||
* - Endpoint -> RAM
|
||||
* ENDEPOUT[i] interrupted, transaction complete, sw prepare next transaction
|
||||
*
|
||||
* For CBI IN:
|
||||
* - RAM -> Endpoint
|
||||
* ENDEPIN[i] interrupted indicate DMA is complete. HW will start
|
||||
* to move daat to host
|
||||
* - Endpoint -> Host
|
||||
* EPDATA (or EP0DATADONE) interrupted, check EPDATASTATUS.EPIN[i].
|
||||
* Transaction is complete, sw prepare next transaction
|
||||
*
|
||||
* Note: in both Control In and Out of Data stage from Host <-> Endpoint
|
||||
* EP0DATADONE will be set as interrupt source
|
||||
*/
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/* CBI OUT: Endpoint -> SRAM (aka transaction complete)
|
||||
* Note: Since nRF controller auto ACK next packet without SW awareness
|
||||
* We must handle this stage before Host -> Endpoint just in case
|
||||
* 2 event happens at once
|
||||
*/
|
||||
for(uint8_t epnum=0; epnum<8; epnum++)
|
||||
{
|
||||
if ( tu_bit_test(int_status, USBD_INTEN_ENDEPOUT0_Pos+epnum))
|
||||
{
|
||||
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT);
|
||||
uint8_t const xact_len = NRF_USBD->EPOUT[epnum].AMOUNT;
|
||||
|
||||
// Data in endpoint has been consumed
|
||||
xfer->data_received = false;
|
||||
|
||||
// Transfer complete if transaction len < Max Packet Size or total len is transferred
|
||||
if ( (xact_len == xfer->mps) && (xfer->actual_len < xfer->total_len) )
|
||||
{
|
||||
// Prepare for next transaction
|
||||
xact_out_prepare(epnum);
|
||||
}else
|
||||
{
|
||||
xfer->total_len = xfer->actual_len;
|
||||
|
||||
// CBI OUT complete
|
||||
dcd_event_xfer_complete(0, epnum, xfer->actual_len, XFER_RESULT_SUCCESS, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Ended event for CBI IN : nothing to do
|
||||
}
|
||||
|
||||
// Endpoint <-> Host
|
||||
if ( int_status & (USBD_INTEN_EPDATA_Msk | USBD_INTEN_EP0DATADONE_Msk) )
|
||||
{
|
||||
uint32_t data_status = NRF_USBD->EPDATASTATUS;
|
||||
nrf_usbd_epdatastatus_clear(data_status);
|
||||
|
||||
// EP0DATADONE is set with either Control Out on IN Data
|
||||
// Since EPDATASTATUS cannot be used to determine whether it is control OUT or IN.
|
||||
// We will use BMREQUESTTYPE in setup packet to determine the direction
|
||||
bool const is_control_in = (int_status & USBD_INTEN_EP0DATADONE_Msk) && (NRF_USBD->BMREQUESTTYPE & TUSB_DIR_IN_MASK);
|
||||
bool const is_control_out = (int_status & USBD_INTEN_EP0DATADONE_Msk) && !(NRF_USBD->BMREQUESTTYPE & TUSB_DIR_IN_MASK);
|
||||
|
||||
// CBI In: Endpoint -> Host (transaction complete)
|
||||
for(uint8_t epnum=0; epnum<8; epnum++)
|
||||
{
|
||||
if ( tu_bit_test(data_status, epnum ) || ( epnum == 0 && is_control_in) )
|
||||
{
|
||||
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_IN);
|
||||
|
||||
xfer->actual_len += NRF_USBD->EPIN[epnum].MAXCNT;
|
||||
|
||||
if ( xfer->actual_len < xfer->total_len )
|
||||
{
|
||||
// prepare next transaction
|
||||
xact_in_prepare(epnum);
|
||||
} else
|
||||
{
|
||||
// CBI IN complete
|
||||
dcd_event_xfer_complete(0, epnum | TUSB_DIR_IN_MASK, xfer->actual_len, XFER_RESULT_SUCCESS, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CBI OUT: Host -> Endpoint
|
||||
for(uint8_t epnum=0; epnum<8; epnum++)
|
||||
{
|
||||
if ( tu_bit_test(data_status, 16+epnum ) || ( epnum == 0 && is_control_out) )
|
||||
{
|
||||
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT);
|
||||
|
||||
if (xfer->actual_len < xfer->total_len)
|
||||
{
|
||||
xact_out_dma(epnum);
|
||||
}else
|
||||
{
|
||||
// Data overflow !!! Nah, nrf52840 will auto ACK OUT packet after DMA is done
|
||||
// Mark this endpoint with data received
|
||||
xfer->data_received = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,255 +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 "tusb_option.h"
|
||||
|
||||
#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_NRF5X
|
||||
|
||||
#include "nrf.h"
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_clock.h"
|
||||
#include "nrf_usbd.h"
|
||||
#include "nrfx_usbd_errata.h"
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#include "nrf_sdm.h"
|
||||
#include "nrf_soc.h"
|
||||
#endif
|
||||
|
||||
#include "nrfx_power.h"
|
||||
#include "device/dcd.h"
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* MACRO TYPEDEF CONSTANT ENUM
|
||||
*------------------------------------------------------------------*/
|
||||
void tusb_hal_nrf_power_event(uint32_t event);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* HFCLK helper
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
// check if SD is present and enabled
|
||||
static bool is_sd_enabled(void)
|
||||
{
|
||||
uint8_t sd_en = false;
|
||||
(void) sd_softdevice_is_enabled(&sd_en);
|
||||
return sd_en;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool hfclk_running(void)
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if ( is_sd_enabled() )
|
||||
{
|
||||
uint32_t is_running;
|
||||
(void) sd_clock_hfclk_is_running(&is_running);
|
||||
return (is_running ? true : false);
|
||||
}
|
||||
#endif
|
||||
|
||||
return nrf_clock_hf_is_running(NRF_CLOCK_HFCLK_HIGH_ACCURACY);
|
||||
}
|
||||
|
||||
static void hfclk_enable(void)
|
||||
{
|
||||
// already running, nothing to do
|
||||
if ( hfclk_running() ) return;
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if ( is_sd_enabled() )
|
||||
{
|
||||
(void)sd_clock_hfclk_request();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
nrf_clock_event_clear(NRF_CLOCK_EVENT_HFCLKSTARTED);
|
||||
nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTART);
|
||||
}
|
||||
|
||||
static void hfclk_disable(void)
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if ( is_sd_enabled() )
|
||||
{
|
||||
(void)sd_clock_hfclk_release();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTOP);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Controller Start up Sequence (USBD 51.4 specs)
|
||||
*------------------------------------------------------------------*/
|
||||
// tusb_hal_nrf_power_event must be called by SOC event handler
|
||||
void tusb_hal_nrf_power_event (uint32_t event)
|
||||
{
|
||||
switch ( event )
|
||||
{
|
||||
case NRFX_POWER_USB_EVT_DETECTED:
|
||||
if ( !NRF_USBD->ENABLE )
|
||||
{
|
||||
/* Prepare for READY event receiving */
|
||||
nrf_usbd_eventcause_clear(NRF_USBD_EVENTCAUSE_READY_MASK);
|
||||
|
||||
/* Enable the peripheral */
|
||||
// ERRATA 171, 187, 166
|
||||
|
||||
if ( nrfx_usbd_errata_187() )
|
||||
{
|
||||
// CRITICAL_REGION_ENTER();
|
||||
if ( *((volatile uint32_t *) (0x4006EC00)) == 0x00000000 )
|
||||
{
|
||||
*((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
|
||||
*((volatile uint32_t *) (0x4006ED14)) = 0x00000003;
|
||||
*((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
|
||||
}
|
||||
else
|
||||
{
|
||||
*((volatile uint32_t *) (0x4006ED14)) = 0x00000003;
|
||||
}
|
||||
// CRITICAL_REGION_EXIT();
|
||||
}
|
||||
|
||||
if ( nrfx_usbd_errata_171() )
|
||||
{
|
||||
// CRITICAL_REGION_ENTER();
|
||||
if ( *((volatile uint32_t *) (0x4006EC00)) == 0x00000000 )
|
||||
{
|
||||
*((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
|
||||
*((volatile uint32_t *) (0x4006EC14)) = 0x000000C0;
|
||||
*((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
|
||||
}
|
||||
else
|
||||
{
|
||||
*((volatile uint32_t *) (0x4006EC14)) = 0x000000C0;
|
||||
}
|
||||
// CRITICAL_REGION_EXIT();
|
||||
}
|
||||
|
||||
nrf_usbd_enable();
|
||||
|
||||
// Enable HFCLK
|
||||
hfclk_enable();
|
||||
}
|
||||
break;
|
||||
|
||||
case NRFX_POWER_USB_EVT_READY:
|
||||
/* Waiting for USBD peripheral enabled */
|
||||
while ( !(USBD_EVENTCAUSE_READY_Msk & NRF_USBD->EVENTCAUSE) ) { }
|
||||
|
||||
nrf_usbd_eventcause_clear(USBD_EVENTCAUSE_READY_Msk);
|
||||
nrf_usbd_event_clear(USBD_EVENTCAUSE_READY_Msk);
|
||||
|
||||
if ( nrfx_usbd_errata_171() )
|
||||
{
|
||||
// CRITICAL_REGION_ENTER();
|
||||
if ( *((volatile uint32_t *) (0x4006EC00)) == 0x00000000 )
|
||||
{
|
||||
*((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
|
||||
*((volatile uint32_t *) (0x4006EC14)) = 0x00000000;
|
||||
*((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
|
||||
}
|
||||
else
|
||||
{
|
||||
*((volatile uint32_t *) (0x4006EC14)) = 0x00000000;
|
||||
}
|
||||
|
||||
// CRITICAL_REGION_EXIT();
|
||||
}
|
||||
|
||||
if ( nrfx_usbd_errata_187() )
|
||||
{
|
||||
// CRITICAL_REGION_ENTER();
|
||||
if ( *((volatile uint32_t *) (0x4006EC00)) == 0x00000000 )
|
||||
{
|
||||
*((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
|
||||
*((volatile uint32_t *) (0x4006ED14)) = 0x00000000;
|
||||
*((volatile uint32_t *) (0x4006EC00)) = 0x00009375;
|
||||
}
|
||||
else
|
||||
{
|
||||
*((volatile uint32_t *) (0x4006ED14)) = 0x00000000;
|
||||
}
|
||||
// CRITICAL_REGION_EXIT();
|
||||
}
|
||||
|
||||
if ( nrfx_usbd_errata_166() )
|
||||
{
|
||||
*((volatile uint32_t *) (NRF_USBD_BASE + 0x800)) = 0x7E3;
|
||||
*((volatile uint32_t *) (NRF_USBD_BASE + 0x804)) = 0x40;
|
||||
|
||||
__ISB();
|
||||
__DSB();
|
||||
}
|
||||
|
||||
nrf_usbd_isosplit_set(USBD_ISOSPLIT_SPLIT_HalfIN);
|
||||
|
||||
// Enable interrupt
|
||||
NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_EPDATA_Msk |
|
||||
USBD_INTEN_EP0SETUP_Msk | USBD_INTEN_EP0DATADONE_Msk | USBD_INTEN_ENDEPIN0_Msk | USBD_INTEN_ENDEPOUT0_Msk;
|
||||
|
||||
// Enable interrupt, priorities should be set by application
|
||||
NVIC_ClearPendingIRQ(USBD_IRQn);
|
||||
NVIC_EnableIRQ(USBD_IRQn);
|
||||
|
||||
// Wait for HFCLK
|
||||
while ( !hfclk_running() ) { }
|
||||
|
||||
// Enable pull up
|
||||
nrf_usbd_pullup_enable();
|
||||
break;
|
||||
|
||||
case NRFX_POWER_USB_EVT_REMOVED:
|
||||
if ( NRF_USBD->ENABLE )
|
||||
{
|
||||
// Abort all transfers
|
||||
|
||||
// Disable pull up
|
||||
nrf_usbd_pullup_disable();
|
||||
|
||||
// Disable Interrupt
|
||||
NVIC_DisableIRQ(USBD_IRQn);
|
||||
|
||||
// disable all interrupt
|
||||
NRF_USBD->INTENCLR = NRF_USBD->INTEN;
|
||||
|
||||
nrf_usbd_disable();
|
||||
hfclk_disable();
|
||||
|
||||
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, true);
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,110 +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.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_H_
|
||||
#define _TUSB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "common/tusb_common.h"
|
||||
#include "osal/osal.h"
|
||||
#include "common/tusb_fifo.h"
|
||||
|
||||
//------------- HOST -------------//
|
||||
#if TUSB_OPT_HOST_ENABLED
|
||||
#include "host/usbh.h"
|
||||
|
||||
#if HOST_CLASS_HID
|
||||
#include "class/hid/hid_host.h"
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_MSC
|
||||
#include "class/msc/msc_host.h"
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_CDC
|
||||
#include "class/cdc/cdc_host.h"
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_VENDOR
|
||||
#include "class/vendor/vendor_host.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//------------- DEVICE -------------//
|
||||
#if TUSB_OPT_DEVICE_ENABLED
|
||||
#include "device/usbd.h"
|
||||
|
||||
#if CFG_TUD_HID
|
||||
#include "class/hid/hid_device.h"
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_CDC
|
||||
#include "class/cdc/cdc_device.h"
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MSC
|
||||
#include "class/msc/msc_device.h"
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MIDI
|
||||
#include "class/midi/midi_device.h"
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_VENDOR
|
||||
#include "class/vendor/vendor_device.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
/** \ingroup group_application_api
|
||||
* @{ */
|
||||
|
||||
// Initialize device/host stack
|
||||
bool tusb_init(void);
|
||||
|
||||
// Check if stack is initialized
|
||||
bool tusb_inited(void);
|
||||
|
||||
// TODO
|
||||
// bool tusb_teardown(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_H_ */
|
||||
@@ -1,203 +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.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_OPTION_H_
|
||||
#define _TUSB_OPTION_H_
|
||||
|
||||
#define TUSB_VERSION_MAJOR 0
|
||||
#define TUSB_VERSION_MINOR 5
|
||||
#define TUSB_VERSION_REVISION 0
|
||||
#define TUSB_VERSION_STRING TU_STRING(TUSB_VERSION_MAJOR) "." TU_STRING(TUSB_VERSION_MINOR) "." TU_STRING(TUSB_VERSION_REVISION)
|
||||
|
||||
/** \defgroup group_mcu Supported MCU
|
||||
* \ref CFG_TUSB_MCU must be defined to one of these
|
||||
* @{ */
|
||||
#define OPT_MCU_LPC11UXX 1 ///< NXP LPC11Uxx
|
||||
#define OPT_MCU_LPC13XX 3 ///< NXP LPC13xx
|
||||
#define OPT_MCU_LPC175X_6X 4 ///< NXP LPC175x, LPC176x
|
||||
#define OPT_MCU_LPC177X_8X 5 ///< NXP LPC177x, LPC178x
|
||||
#define OPT_MCU_LPC18XX 6 ///< NXP LPC18xx
|
||||
#define OPT_MCU_LPC40XX 7 ///< NXP LPC40xx
|
||||
#define OPT_MCU_LPC43XX 8 ///< NXP LPC43xx
|
||||
|
||||
#define OPT_MCU_NRF5X 100 ///< Nordic nRF5x series
|
||||
|
||||
#define OPT_MCU_SAMD21 200 ///< MicroChip SAMD21
|
||||
#define OPT_MCU_SAMD51 201 ///< MicroChip SAMD51
|
||||
|
||||
#define OPT_MCU_STM32F4 300 ///< ST STM32F4
|
||||
#define OPT_MCU_STM32F3 301 ///< ST STM32F3
|
||||
|
||||
/** @} */
|
||||
|
||||
/** \defgroup group_supported_os Supported RTOS
|
||||
* \ref CFG_TUSB_OS must be defined to one of these
|
||||
* @{ */
|
||||
#define OPT_OS_NONE 1 ///< No RTOS
|
||||
#define OPT_OS_FREERTOS 2 ///< FreeRTOS
|
||||
#define OPT_OS_MYNEWT 3 ///< Mynewt OS
|
||||
/** @} */
|
||||
|
||||
|
||||
// Allow to use command line to change the config name/location
|
||||
#ifndef CFG_TUSB_CONFIG_FILE
|
||||
#define CFG_TUSB_CONFIG_FILE "tusb_config.h"
|
||||
#endif
|
||||
|
||||
#include CFG_TUSB_CONFIG_FILE
|
||||
|
||||
/** \addtogroup group_configuration
|
||||
* @{ */
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// CONTROLLER
|
||||
// Only 1 roothub port can be configured to be device and/or host.
|
||||
// tinyusb does not support dual devices or dual host configuration
|
||||
//--------------------------------------------------------------------
|
||||
/** \defgroup group_mode Controller Mode Selection
|
||||
* \brief CFG_TUSB_CONTROLLER_N_MODE must be defined with these
|
||||
* @{ */
|
||||
#define OPT_MODE_NONE 0x00 ///< Disabled
|
||||
#define OPT_MODE_DEVICE 0x01 ///< Device Mode
|
||||
#define OPT_MODE_HOST 0x02 ///< Host Mode
|
||||
#define OPT_MODE_HIGH_SPEED 0x10 ///< High speed
|
||||
/** @} */
|
||||
|
||||
#ifndef CFG_TUSB_RHPORT0_MODE
|
||||
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUSB_RHPORT1_MODE
|
||||
#define CFG_TUSB_RHPORT1_MODE OPT_MODE_NONE
|
||||
#endif
|
||||
|
||||
#if ((CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST) && (CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST)) || \
|
||||
((CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE) && (CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE))
|
||||
#error "tinyusb does not support same modes on more than 1 roothub port"
|
||||
#endif
|
||||
|
||||
// Which roothub port is configured as host
|
||||
#define TUH_OPT_RHPORT ( (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST) ? 0 : ((CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST) ? 1 : -1) )
|
||||
#define TUSB_OPT_HOST_ENABLED ( TUH_OPT_RHPORT >= 0 )
|
||||
|
||||
// Which roothub port is configured as device
|
||||
#define TUD_OPT_RHPORT ( (CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE) ? 0 : ((CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE) ? 1 : -1) )
|
||||
|
||||
#if TUD_OPT_RHPORT == 0
|
||||
#define TUD_OPT_HIGH_SPEED ( CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED )
|
||||
#else
|
||||
#define TUD_OPT_HIGH_SPEED ( CFG_TUSB_RHPORT1_MODE & OPT_MODE_HIGH_SPEED )
|
||||
#endif
|
||||
|
||||
#define TUSB_OPT_DEVICE_ENABLED ( TUD_OPT_RHPORT >= 0 )
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// COMMON OPTIONS
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Debug enable to print out error message
|
||||
#ifndef CFG_TUSB_DEBUG
|
||||
#define CFG_TUSB_DEBUG 0
|
||||
#endif
|
||||
|
||||
// place data in accessible RAM for usb controller
|
||||
#ifndef CFG_TUSB_MEM_SECTION
|
||||
#define CFG_TUSB_MEM_SECTION
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUSB_MEM_ALIGN
|
||||
#define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUSB_OS
|
||||
#define CFG_TUSB_OS OPT_OS_NONE
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// DEVICE OPTIONS
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
#ifndef CFG_TUD_ENDOINT0_SIZE
|
||||
#define CFG_TUD_ENDOINT0_SIZE 64
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_CDC
|
||||
#define CFG_TUD_CDC 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_MSC
|
||||
#define CFG_TUD_MSC 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_HID
|
||||
#define CFG_TUD_HID 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_MIDI
|
||||
#define CFG_TUD_MIDI 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_VENDOR
|
||||
#define CFG_TUD_VENDOR 0
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// HOST OPTIONS
|
||||
//--------------------------------------------------------------------
|
||||
#if TUSB_OPT_HOST_ENABLED
|
||||
#ifndef CFG_TUSB_HOST_DEVICE_MAX
|
||||
#define CFG_TUSB_HOST_DEVICE_MAX 1
|
||||
#warning CFG_TUSB_HOST_DEVICE_MAX is not defined, default value is 1
|
||||
#endif
|
||||
|
||||
//------------- HUB CLASS -------------//
|
||||
#if CFG_TUH_HUB && (CFG_TUSB_HOST_DEVICE_MAX == 1)
|
||||
#error there is no benefit enable hub with max device is 1. Please disable hub or increase CFG_TUSB_HOST_DEVICE_MAX
|
||||
#endif
|
||||
|
||||
//------------- HID CLASS -------------//
|
||||
#define HOST_CLASS_HID ( CFG_TUH_HID_KEYBOARD + CFG_TUH_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC )
|
||||
|
||||
#ifndef CFG_TUSB_HOST_ENUM_BUFFER_SIZE
|
||||
#define CFG_TUSB_HOST_ENUM_BUFFER_SIZE 256
|
||||
#endif
|
||||
|
||||
//------------- CLASS -------------//
|
||||
#endif // TUSB_OPT_HOST_ENABLED
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Configuration Validation
|
||||
//------------------------------------------------------------------
|
||||
#if CFG_TUD_ENDOINT0_SIZE > 64
|
||||
#error Control Endpoint Max Packet Size cannot be larger than 64
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_OPTION_H_ */
|
||||
|
||||
/** @} */
|
||||
+31
-2
@@ -85,8 +85,33 @@ void suspendLoop(void);
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a < _b ? _a : _b; })
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
@@ -114,11 +139,15 @@ void suspendLoop(void);
|
||||
#endif
|
||||
|
||||
#define digitalPinToBitMask(P) ( 1UL << ( g_ADigitalPinMap[P] < 32 ? g_ADigitalPinMap[P] : (g_ADigitalPinMap[P]-32) ) )
|
||||
|
||||
#define digitalPinToPinName(P) g_ADigitalPinMap[P]
|
||||
|
||||
//#define analogInPinToBit(P) ( )
|
||||
#define portOutputRegister(port) ( &(port->OUT) )
|
||||
#define portInputRegister(port) ( (volatile uint32_t*) &(port->IN) )
|
||||
#define portModeRegister(port) ( &(port->DIR) )
|
||||
#define digitalPinHasPWM(P) ( g_ADigitalPinMap[P] > 1 )
|
||||
|
||||
/*
|
||||
* digitalPinToTimer(..) is AVR-specific and is not defined for nRF52
|
||||
* architecture. If you need to check if a pin supports PWM you must
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h> // for size_t
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "WString.h"
|
||||
#include "Printable.h"
|
||||
@@ -55,6 +56,10 @@ class Print
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overriden by subclasses with buffering
|
||||
virtual int availableForWrite() { return 0; }
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
|
||||
+1
Submodule cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore added at 09968245ad.
+20
-3
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018, hathach for Adafruit
|
||||
* Copyright (c) 2019, hathach for Adafruit
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -34,7 +34,7 @@
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#define USBD_STACK_SZ (150)
|
||||
#define USBD_STACK_SZ (200)
|
||||
|
||||
// tinyusb function that handles power event (detected, ready, removed)
|
||||
// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.
|
||||
@@ -54,6 +54,10 @@ static void usb_device_task(void* param)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Core Init & Touch1200
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Init usb hardware when starting up. Softdevice is not enabled yet
|
||||
static void usb_hardware_init(void)
|
||||
{
|
||||
@@ -99,7 +103,20 @@ void Adafruit_TinyUSB_Core_touch1200(void)
|
||||
enterSerialDfu();
|
||||
}
|
||||
|
||||
uint8_t load_serial_number(uint16_t* serial_str)
|
||||
//--------------------------------------------------------------------+
|
||||
// Adafruit_USBD_Device platform dependent
|
||||
//--------------------------------------------------------------------+
|
||||
void Adafruit_USBD_Device::detach(void)
|
||||
{
|
||||
NRF_USBD->USBPULLUP = 0;
|
||||
}
|
||||
|
||||
void Adafruit_USBD_Device::attach(void)
|
||||
{
|
||||
NRF_USBD->USBPULLUP = 1;
|
||||
}
|
||||
|
||||
uint8_t Adafruit_USBD_Device::getSerialDescriptor(uint16_t* serial_str)
|
||||
{
|
||||
// Serial is 64-bit DeviceID -> 16 chars len
|
||||
char tmp_serial[17];
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
#define CFG_TUSB_OS OPT_OS_FREERTOS
|
||||
#define CFG_TUSB_MEM_SECTION
|
||||
#define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
|
||||
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// DEVICE CONFIGURATION
|
||||
@@ -72,7 +72,6 @@
|
||||
#define CFG_TUD_MIDI_TX_BUFSIZE 64
|
||||
|
||||
// Vendor FIFO size of TX and RX
|
||||
// If not configured vendor endpoints will not be buffered
|
||||
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
|
||||
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
|
||||
|
||||
@@ -144,6 +144,10 @@ void detachInterrupt(uint32_t pin)
|
||||
|
||||
void GPIOTE_IRQHandler()
|
||||
{
|
||||
#if CFG_DEBUG >= 3
|
||||
SEGGER_SYSVIEW_RecordEnterISR();
|
||||
#endif
|
||||
|
||||
uint32_t event = offsetof(NRF_GPIOTE_Type, EVENTS_IN[0]);
|
||||
|
||||
for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) {
|
||||
@@ -166,4 +170,8 @@ void GPIOTE_IRQHandler()
|
||||
|
||||
event = (uint32_t)((uint32_t)event + 4);
|
||||
}
|
||||
|
||||
#if CFG_DEBUG >= 3
|
||||
SEGGER_SYSVIEW_RecordExitISR();
|
||||
#endif
|
||||
}
|
||||
@@ -114,12 +114,6 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// DEBUG HELPER
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_DEBUG == 2
|
||||
#define malloc_named( name, size ) ({ PRINTF("[malloc] %s : %d\r\n", name, size); malloc(size); })
|
||||
#else
|
||||
#define malloc_named( name, size ) malloc ( size )
|
||||
#endif
|
||||
|
||||
const char* dbg_err_str(int32_t err_id); // TODO move to other place
|
||||
|
||||
#if CFG_DEBUG
|
||||
@@ -177,7 +171,8 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place
|
||||
|
||||
#define ADALOG_BUFFER(_tag, _buf, _n) \
|
||||
do {\
|
||||
if ( _tag ) PRINTF("%-6s: len = %d\n", _tag, _n);\
|
||||
const char * _xtag = _tag;\
|
||||
if ( _xtag ) PRINTF("%-6s: len = %d\n", _xtag, _n);\
|
||||
dbgDumpMemory(_buf, 1, _n, true);\
|
||||
}while(0)
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY ( 2 ) // Normal
|
||||
#define configTIMER_QUEUE_LENGTH 32
|
||||
#define configTIMER_TASK_STACK_DEPTH ( 100 )
|
||||
#define configTIMER_TASK_STACK_DEPTH ( 256 )
|
||||
|
||||
/* Tickless Idle configuration. */
|
||||
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2
|
||||
|
||||
@@ -5,7 +5,7 @@ GROUP(-lgcc -lc -lnosys)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x6D000-0x26000
|
||||
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x6D000 - 0x26000
|
||||
|
||||
/* SRAM required by S132 depend on
|
||||
* - Attribute Table Size
|
||||
@@ -14,8 +14,7 @@ MEMORY
|
||||
* - Concurrent connection peripheral + central + secure links
|
||||
* - Event Len, HVN queue, Write CMD queue
|
||||
*/
|
||||
/* RAM (rwx) : ORIGIN = 0x20003200, LENGTH = 0x20010000 - 0x20003200 */
|
||||
RAM (rwx) : ORIGIN = 0x20003400, LENGTH = 0x20010000 - 0x20003400
|
||||
RAM (rwx) : ORIGIN = 0x20003600, LENGTH = 0x20010000 - 0x20003600
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
|
||||
@@ -8,13 +8,13 @@ MEMORY
|
||||
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0xED000 - 0x26000
|
||||
|
||||
/* SRAM required by S132 depend on
|
||||
* - Attribute Table Size
|
||||
* - Attribute Table Size (Number of Services and Characteristics)
|
||||
* - Vendor UUID count
|
||||
* - Max ATT MTU
|
||||
* - Concurrent connection peripheral + central + secure links
|
||||
* - Event Len, HVN queue, Write CMD queue
|
||||
*/
|
||||
RAM (rwx) : ORIGIN = 0x20003400, LENGTH = 0x20040000 - 0x20003400
|
||||
RAM (rwx) : ORIGIN = 0x20006000, LENGTH = 0x20040000 - 0x20006000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
|
||||
+4
-3
@@ -37,7 +37,8 @@ static TaskHandle_t _loopHandle;
|
||||
void initVariant() __attribute__((weak));
|
||||
void initVariant() { }
|
||||
|
||||
#define LOOP_STACK_SZ (512*3)
|
||||
#define LOOP_STACK_SZ (256*4)
|
||||
#define CALLBACK_STACK_SZ (256*3)
|
||||
|
||||
static void loop_task(void* arg)
|
||||
{
|
||||
@@ -56,7 +57,7 @@ static void loop_task(void* arg)
|
||||
while (1)
|
||||
{
|
||||
loop();
|
||||
yield(); // yield run usb background task
|
||||
yield(); // yield to run other task
|
||||
|
||||
// Serial events
|
||||
if (serialEvent && serialEventRun) serialEventRun();
|
||||
@@ -81,7 +82,7 @@ int main( void )
|
||||
xTaskCreate( loop_task, "loop", LOOP_STACK_SZ, NULL, TASK_PRIO_LOW, &_loopHandle);
|
||||
|
||||
// Initialize callback task
|
||||
ada_callback_init();
|
||||
ada_callback_init(CALLBACK_STACK_SZ);
|
||||
|
||||
// Start FreeRTOS scheduler.
|
||||
vTaskStartScheduler();
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
#include <stdlib.h>
|
||||
#include "rtos.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <malloc.h>
|
||||
|
||||
void *operator new(size_t size) {
|
||||
return rtos_malloc(size);
|
||||
}
|
||||
@@ -42,3 +46,46 @@ void operator delete(void * ptr, unsigned int) {
|
||||
void operator delete[](void * ptr, unsigned int) {
|
||||
rtos_free(ptr);
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
// defined in linker script
|
||||
extern unsigned char __HeapBase[];
|
||||
extern unsigned char __HeapLimit[];
|
||||
|
||||
static unsigned char *sbrk_heap_top = __HeapBase;
|
||||
|
||||
__attribute__((used))
|
||||
caddr_t _sbrk( int incr )
|
||||
{
|
||||
unsigned char *prev_heap;
|
||||
|
||||
if ( sbrk_heap_top + incr > __HeapLimit )
|
||||
{
|
||||
/* Out of dynamic memory heap space */
|
||||
errno = ENOMEM;
|
||||
return (caddr_t) -1;
|
||||
}
|
||||
|
||||
prev_heap = sbrk_heap_top;
|
||||
|
||||
sbrk_heap_top += incr;
|
||||
|
||||
return (caddr_t) prev_heap;
|
||||
}
|
||||
|
||||
void __malloc_lock(struct _reent *ptr)
|
||||
{
|
||||
(void) ptr;
|
||||
vTaskSuspendAll();
|
||||
}
|
||||
|
||||
void __malloc_unlock(struct _reent *ptr)
|
||||
{
|
||||
(void) ptr;
|
||||
xTaskResumeAll();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,50 @@
|
||||
# Changelog
|
||||
All notable changes to this project are documented in this file.
|
||||
|
||||
## [1.7.2] - 2019-07-25
|
||||
### Added
|
||||
- Added functions in the DPPI, GPIOTE, PPI, RTC, and TIMER HALs for getting tasks and events specified by index.
|
||||
- Added the possibility of suspending transfers in the TWI driver. This allows combining several transfers into one continuous TWI transaction.
|
||||
- Added termination of transfers at deinitialization of the UARTE driver.
|
||||
- Added buffer alignment checks in the QSPI driver.
|
||||
- Introduced the NRFX_OFFSETOF macro that duplicates the functionality of the built-in offsetof() mechanism, but can be used without issues also with non-constant expressions.
|
||||
- Added an alternative way of ending the DMA transfer loop in the USBD driver.
|
||||
- Added the CTSTARTED and CTSTOPPED events to the CLOCK HAL.
|
||||
|
||||
### Changed
|
||||
- Removed an assertion that prevented setting the data payload size of isochronous endpoints to zero, to fulfill requirements of the USB 2.0 specification, paragraph 5.6.3.
|
||||
- Declared the tx_buffer_length field in the UART driver's control block as volatile to prevent issues in case of compilation with high optimization level.
|
||||
|
||||
### Fixed
|
||||
- Fixed an incorrect conversion of frequency values in the RADIO HAL.
|
||||
- Fixed an incorrectly enabled interrupt in the QSPI driver.
|
||||
- Corrected the LFCLK source selection values in the template configuration file for nRF9160.
|
||||
- Fixed support for external LFCLK sources for nRF52811.
|
||||
|
||||
## [1.7.1] - 2019-04-08
|
||||
### Added
|
||||
- Added functions in the NVMC driver for getting the flash page size, the count of pages and the total flash size.
|
||||
|
||||
### Fixed
|
||||
- Fixed handling of short unaligned write requests (1 or 2 bytes in length) in the nrfx_nvmc_bytes_write() function.
|
||||
|
||||
## [1.7.0] - 2019-03-29
|
||||
### Added
|
||||
- Added drivers for NVMC and TEMP.
|
||||
- Added HALs: AAR and FICR.
|
||||
- Added support for the custom instruction long frame mode in the QSPI driver.
|
||||
|
||||
### Changed
|
||||
- Reworked HAL for NVMC. Now it can be used for all SoCs supported by nrfx.
|
||||
- Reworked HAL for TEMP.
|
||||
- Improved documentation. Now it is more precise and can be generated without warnings with newer versions of doxygen.
|
||||
- Improved the UARTE driver to consume less current after the TX operation. Now at the end of the transmission the transmitter is turned off by the STOPTX task.
|
||||
- Improved C++ support in drivers. Now fields in structures are filled up in the correct order.
|
||||
- Changed to size_t the type used for holding the amount of data in the TWIS driver.
|
||||
|
||||
### Fixed
|
||||
- Fixed a race condition in the USBD driver. It could occur when an IN transfer was interrupted by an OUT transaction, which in turn was interrupted by a process with a higher priority.
|
||||
|
||||
## [1.6.2] - 2019-02-12
|
||||
### Added
|
||||
- Added the possibility to use the macro NRFX_COREDEP_DELAY_US_LOOP_CYCLES to specify the number of cycles consumed by one iteration of the internal loop in the function nrfx_coredep_delay_us().
|
||||
|
||||
@@ -45,14 +45,17 @@ extern "C" {
|
||||
* @brief Bitmask managing module.
|
||||
*/
|
||||
|
||||
/** @brief Macro for getting index of byte in byte stream where @c abs_bit is put. */
|
||||
#define BITMASK_BYTE_GET(abs_bit) ((abs_bit)/8)
|
||||
|
||||
/** @brief Macro for getting relative index of bit in byte. */
|
||||
#define BITMASK_RELBIT_GET(abs_bit) ((abs_bit) & 0x00000007)
|
||||
|
||||
/**
|
||||
* Function for checking if bit in the multi-byte bit mask is set.
|
||||
* @brief Function for checking if bit in the multi-byte bit mask is set.
|
||||
*
|
||||
* @param bit Bit index.
|
||||
* @param p_mask A pointer to mask with bit fields.
|
||||
* @param[in] bit Bit index.
|
||||
* @param[in] p_mask Pointer to mask with bit fields.
|
||||
*
|
||||
* @return 0 if bit is not set, positive value otherwise.
|
||||
*/
|
||||
@@ -65,10 +68,10 @@ __STATIC_INLINE uint32_t nrf_bitmask_bit_is_set(uint32_t bit, void const * p_mas
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for setting a bit in the multi-byte bit mask.
|
||||
* @brief Function for setting a bit in the multi-byte bit mask.
|
||||
*
|
||||
* @param bit Bit index.
|
||||
* @param p_mask A pointer to mask with bit fields.
|
||||
* @param[in] bit Bit index.
|
||||
* @param[in] p_mask Pointer to mask with bit fields.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_bit_set(uint32_t bit, void * p_mask)
|
||||
{
|
||||
@@ -79,10 +82,10 @@ __STATIC_INLINE void nrf_bitmask_bit_set(uint32_t bit, void * p_mask)
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for clearing a bit in the multi-byte bit mask.
|
||||
* @brief Function for clearing a bit in the multi-byte bit mask.
|
||||
*
|
||||
* @param bit Bit index.
|
||||
* @param p_mask A pointer to mask with bit fields.
|
||||
* @param[in] bit Bit index.
|
||||
* @param[in] p_mask Pointer to mask with bit fields.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_bit_clear(uint32_t bit, void * p_mask)
|
||||
{
|
||||
@@ -93,12 +96,12 @@ __STATIC_INLINE void nrf_bitmask_bit_clear(uint32_t bit, void * p_mask)
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for performing bitwise OR operation on two multi-byte bit masks.
|
||||
* @brief Function for performing bitwise OR operation on two multi-byte bit masks.
|
||||
*
|
||||
* @param p_mask1 A pointer to the first bit mask.
|
||||
* @param p_mask2 A pointer to the second bit mask.
|
||||
* @param p_out_mask A pointer to the output bit mask.
|
||||
* @param length Length of output mask in bytes.
|
||||
* @param[in] p_mask1 Pointer to the first bit mask.
|
||||
* @param[in] p_mask2 Pointer to the second bit mask.
|
||||
* @param[in] p_out_mask Pointer to the output bit mask.
|
||||
* @param[in] length Length of output mask in bytes.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_masks_or(void const * p_mask1,
|
||||
void const * p_mask2,
|
||||
@@ -116,12 +119,12 @@ __STATIC_INLINE void nrf_bitmask_masks_or(void const * p_mask1,
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for performing bitwise AND operation on two multi-byte bit masks.
|
||||
* @brief Function for performing bitwise AND operation on two multi-byte bit masks.
|
||||
*
|
||||
* @param p_mask1 A pointer to the first bit mask.
|
||||
* @param p_mask2 A pointer to the second bit mask.
|
||||
* @param p_out_mask A pointer to the output bit mask.
|
||||
* @param length Length of output mask in bytes.
|
||||
* @param[in] p_mask1 Pointer to the first bit mask.
|
||||
* @param[in] p_mask2 Pointer to the second bit mask.
|
||||
* @param[in] p_out_mask Pointer to the output bit mask.
|
||||
* @param[in] length Length of output mask in bytes.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_masks_and(void const * p_mask1,
|
||||
void const * p_mask2,
|
||||
|
||||
@@ -46,35 +46,27 @@ extern "C" {
|
||||
* @brief Analog-to-Digital Converter (ADC) peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Driver event types.
|
||||
*/
|
||||
/** @brief Driver event types. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_ADC_EVT_DONE, ///< Event generated when the buffer is filled with samples.
|
||||
NRFX_ADC_EVT_SAMPLE, ///< Event generated when the requested channel is sampled.
|
||||
} nrfx_adc_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver DONE event.
|
||||
*/
|
||||
/** @brief ADC driver DONE event structure. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_adc_value_t * p_buffer; ///< Pointer to the buffer with converted samples.
|
||||
uint16_t size; ///< Number of samples in the buffer.
|
||||
} nrfx_adc_done_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver SAMPLE event.
|
||||
*/
|
||||
/** @brief SAMPLE event structure. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_adc_value_t sample; ///< Converted sample.
|
||||
} nrfx_adc_sample_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver event.
|
||||
*/
|
||||
/** @brief ADC driver event. */
|
||||
typedef struct
|
||||
{
|
||||
nrfx_adc_evt_type_t type; ///< Event type.
|
||||
@@ -82,10 +74,10 @@ typedef struct
|
||||
{
|
||||
nrfx_adc_done_evt_t done; ///< Data for DONE event.
|
||||
nrfx_adc_sample_evt_t sample; ///< Data for SAMPLE event.
|
||||
} data;
|
||||
} data; ///< Union to store event data.
|
||||
} nrfx_adc_evt_t;
|
||||
|
||||
/**@brief Macro for initializing the ADC channel with the default configuration. */
|
||||
/** @brief Macro for initializing the ADC channel with the default configuration. */
|
||||
#define NRFX_ADC_DEFAULT_CHANNEL(analog_input) \
|
||||
{ \
|
||||
NULL, \
|
||||
@@ -98,7 +90,7 @@ typedef struct
|
||||
} \
|
||||
}
|
||||
|
||||
// Forward declaration of the nrfx_adc_channel_t type.
|
||||
/** @brief Forward declaration of the nrfx_adc_channel_t type. */
|
||||
typedef struct nrfx_adc_channel_s nrfx_adc_channel_t;
|
||||
|
||||
/**
|
||||
@@ -113,9 +105,7 @@ struct nrfx_adc_channel_s
|
||||
nrf_adc_config_t config; ///< ADC configuration for the current channel.
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief ADC configuration.
|
||||
*/
|
||||
/** @brief ADC configuration. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t interrupt_priority; ///< Priority of ADC interrupt.
|
||||
@@ -142,11 +132,11 @@ typedef void (*nrfx_adc_event_handler_t)(nrfx_adc_evt_t const * p_event);
|
||||
* If a valid event handler is provided, the driver is initialized in non-blocking mode.
|
||||
* If event_handler is NULL, the driver works in blocking mode.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is already initialized.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver is already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_adc_init(nrfx_adc_config_t const * p_config,
|
||||
nrfx_adc_event_handler_t event_handler);
|
||||
@@ -169,6 +159,8 @@ void nrfx_adc_uninit(void);
|
||||
*
|
||||
* @note The channel instance variable @p p_channel is used by the driver as an item
|
||||
* in a list. Therefore, it cannot be an automatic variable that is located on the stack.
|
||||
*
|
||||
* @param[in] p_channel Pointer to the channel instance.
|
||||
*/
|
||||
void nrfx_adc_channel_enable(nrfx_adc_channel_t * const p_channel);
|
||||
|
||||
@@ -177,6 +169,8 @@ void nrfx_adc_channel_enable(nrfx_adc_channel_t * const p_channel);
|
||||
*
|
||||
* This function can be called only when there is no conversion in progress
|
||||
* (the ADC is not busy).
|
||||
*
|
||||
* @param p_channel Pointer to the channel instance.
|
||||
*/
|
||||
void nrfx_adc_channel_disable(nrfx_adc_channel_t * const p_channel);
|
||||
|
||||
@@ -206,11 +200,11 @@ void nrfx_adc_sample(void);
|
||||
* fail if ADC is busy. The channel does not need to be enabled to perform a single conversion.
|
||||
*
|
||||
* @param[in] p_channel Channel.
|
||||
* @param[out] p_value Pointer to the location where the result should be placed. Unless NULL is
|
||||
* @param[out] p_value Pointer to the location where the result is to be placed. Unless NULL is
|
||||
* provided, the function is blocking.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the ADC driver is busy.
|
||||
* @retval NRFX_SUCCESS Conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY The ADC driver is busy.
|
||||
*/
|
||||
nrfx_err_t nrfx_adc_sample_convert(nrfx_adc_channel_t const * const p_channel,
|
||||
nrf_adc_value_t * p_value);
|
||||
@@ -241,16 +235,16 @@ nrfx_err_t nrfx_adc_sample_convert(nrfx_adc_channel_t const * const p_channel,
|
||||
* @param[in] buffer Result buffer.
|
||||
* @param[in] size Buffer size in samples.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is busy.
|
||||
* @retval NRFX_SUCCESS Conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY The driver is busy.
|
||||
*/
|
||||
nrfx_err_t nrfx_adc_buffer_convert(nrf_adc_value_t * buffer, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the ADC state.
|
||||
*
|
||||
* @retval true If the ADC is busy.
|
||||
* @retval false If the ADC is ready.
|
||||
* @retval true The ADC is busy.
|
||||
* @retval false The ADC is ready.
|
||||
*/
|
||||
bool nrfx_adc_is_busy(void);
|
||||
|
||||
@@ -273,12 +267,12 @@ __STATIC_INLINE uint32_t nrfx_adc_start_task_get(void)
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_adc_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -47,9 +47,7 @@ extern "C" {
|
||||
* @brief CLOCK peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Clock events.
|
||||
*/
|
||||
/** @brief Clock events. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_CLOCK_EVT_HFCLK_STARTED, ///< HFCLK has been started.
|
||||
@@ -61,7 +59,7 @@ typedef enum
|
||||
/**
|
||||
* @brief Clock event handler.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
* @param[in] event Event.
|
||||
*/
|
||||
typedef void (*nrfx_clock_event_handler_t)(nrfx_clock_evt_type_t event);
|
||||
|
||||
@@ -73,71 +71,57 @@ typedef void (*nrfx_clock_event_handler_t)(nrfx_clock_evt_type_t event);
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_ALREADY_INITIALIZED If the driver was already initialized.
|
||||
* @retval NRFX_SUCCESS The procedure is successful.
|
||||
* @retval NRFX_ERROR_ALREADY_INITIALIZED The driver is already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_clock_init(nrfx_clock_event_handler_t event_handler);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling interrupts in the clock module.
|
||||
*/
|
||||
/** @brief Function for enabling interrupts in the clock module. */
|
||||
void nrfx_clock_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling interrupts in the clock module.
|
||||
*/
|
||||
/** @brief Function for disabling interrupts in the clock module. */
|
||||
void nrfx_clock_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the clock module.
|
||||
*/
|
||||
/** @brief Function for uninitializing the clock module. */
|
||||
void nrfx_clock_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the LFCLK.
|
||||
*/
|
||||
/** @brief Function for starting the LFCLK. */
|
||||
void nrfx_clock_lfclk_start(void);
|
||||
|
||||
/**
|
||||
* @brief Function for stoping the LFCLK.
|
||||
*/
|
||||
/** @brief Function for stopping the LFCLK. */
|
||||
void nrfx_clock_lfclk_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the LFCLK state.
|
||||
*
|
||||
* @retval true If the LFCLK is running.
|
||||
* @retval false If the LFCLK is not running.
|
||||
* @retval true The LFCLK is running.
|
||||
* @retval false The LFCLK is not running.
|
||||
*/
|
||||
__STATIC_INLINE bool nrfx_clock_lfclk_is_running(void);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the high-accuracy source HFCLK.
|
||||
*/
|
||||
/** @brief Function for starting the high-accuracy source HFCLK. */
|
||||
void nrfx_clock_hfclk_start(void);
|
||||
|
||||
/**
|
||||
* @brief Function for stoping external high-accuracy source HFCLK.
|
||||
*/
|
||||
/** @brief Function for stopping the external high-accuracy source HFCLK. */
|
||||
void nrfx_clock_hfclk_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the HFCLK state.
|
||||
*
|
||||
* @retval true If the HFCLK is running (XTAL source).
|
||||
* @retval false If the HFCLK is not running.
|
||||
* @retval true The HFCLK is running (XTAL source).
|
||||
* @retval false The HFCLK is not running.
|
||||
*/
|
||||
__STATIC_INLINE bool nrfx_clock_hfclk_is_running(void);
|
||||
|
||||
/**
|
||||
* @brief Function for starting calibration of internal LFCLK.
|
||||
* @brief Function for starting the calibration of internal LFCLK.
|
||||
*
|
||||
* This function starts the calibration process. The process cannot be aborted. LFCLK and HFCLK
|
||||
* must be running before this function is called.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the low-frequency of high-frequency clock is off.
|
||||
* @retval NRFX_ERROR_BUSY If calibration is in progress.
|
||||
* @retval NRFX_SUCCESS The procedure is successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The low-frequency of high-frequency clock is off.
|
||||
* @retval NRFX_ERROR_BUSY Clock is in the calibration phase.
|
||||
*/
|
||||
nrfx_err_t nrfx_clock_calibration_start(void);
|
||||
|
||||
@@ -146,35 +130,34 @@ nrfx_err_t nrfx_clock_calibration_start(void);
|
||||
*
|
||||
* This function indicates that the system is in calibration phase.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If calibration is in progress.
|
||||
* @retval NRFX_SUCCESS The procedure is successful.
|
||||
* @retval NRFX_ERROR_BUSY Clock is in the calibration phase.
|
||||
*/
|
||||
nrfx_err_t nrfx_clock_is_calibrating(void);
|
||||
|
||||
/**
|
||||
* @brief Function for starting calibration timer.
|
||||
* @param interval Time after which the CTTO event and interrupt will be generated (in 0.25 s units).
|
||||
*
|
||||
* @param[in] interval Time after which the CTTO event and interrupt will be generated (in 0.25 s units).
|
||||
*/
|
||||
void nrfx_clock_calibration_timer_start(uint8_t interval);
|
||||
|
||||
/**
|
||||
* @brief Function for stoping calibration timer.
|
||||
*/
|
||||
/** @brief Function for stopping the calibration timer. */
|
||||
void nrfx_clock_calibration_timer_stop(void);
|
||||
|
||||
/**@brief Function for returning a requested task address for the clock driver module.
|
||||
*
|
||||
* @param[in] task One of the peripheral tasks.
|
||||
* @param[in] task One of the peripheral tasks.
|
||||
*
|
||||
* @return Task address.
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_clock_ppi_task_addr(nrf_clock_task_t task);
|
||||
|
||||
/**@brief Function for returning a requested event address for the clock driver module.
|
||||
*
|
||||
* @param[in] event One of the peripheral events.
|
||||
* @param[in] event One of the peripheral events.
|
||||
*
|
||||
* @return Event address.
|
||||
* @return Event address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_clock_ppi_event_addr(nrf_clock_event_t event);
|
||||
|
||||
@@ -201,12 +184,12 @@ __STATIC_INLINE bool nrfx_clock_lfclk_is_running(void)
|
||||
}
|
||||
#endif //SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_clock_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -47,19 +47,20 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Macro to convert the threshold voltage to an integer value
|
||||
* @brief Macro for converting the threshold voltage to an integer value
|
||||
* (needed by the COMP_TH register).
|
||||
*
|
||||
* @param[in] vol Voltage to be changed to COMP_TH register value. This value
|
||||
* must not be smaller than reference voltage divided by 64.
|
||||
* @param[in] ref Reference voltage.
|
||||
* @param[in] vol Voltage to be changed to COMP_TH register value. This value
|
||||
* must not be smaller than reference voltage divided by 64.
|
||||
* @param[in] ref Reference voltage.
|
||||
*/
|
||||
#define NRFX_VOLTAGE_THRESHOLD_TO_INT(vol, ref) \
|
||||
(uint8_t)(((vol) > ((ref) / 64)) ? (NRFX_ROUNDED_DIV((vol) * 64,(ref)) - 1) : 0)
|
||||
|
||||
/**
|
||||
* @brief COMP event handler function type.
|
||||
* @param[in] event COMP event.
|
||||
*
|
||||
* @param[in] event COMP event.
|
||||
*/
|
||||
typedef void (* nrfx_comp_event_handler_t)(nrf_comp_event_t event);
|
||||
|
||||
@@ -88,7 +89,7 @@ typedef struct
|
||||
nrf_comp_main_mode_t main_mode; /**< Main operation mode. */
|
||||
nrf_comp_th_t threshold; /**< Structure holding THDOWN and THUP values needed by the COMP_TH register. */
|
||||
nrf_comp_sp_mode_t speed_mode; /**< Speed and power mode. */
|
||||
nrf_comp_hyst_t hyst; /**< Comparator hysteresis.*/
|
||||
nrf_comp_hyst_t hyst; /**< Comparator hysteresis. */
|
||||
#if defined (COMP_ISOURCE_ISOURCE_Msk) || defined (__NRFX_DOXYGEN__)
|
||||
nrf_isource_t isource; /**< Current source selected on analog input. */
|
||||
#endif
|
||||
@@ -108,6 +109,7 @@ typedef struct
|
||||
#define NRFX_COMP_DEFAULT_CONFIG(_input) \
|
||||
{ \
|
||||
.reference = (nrf_comp_ref_t)NRFX_COMP_CONFIG_REF, \
|
||||
.ext_ref = NRF_COMP_EXT_REF_0, \
|
||||
.main_mode = (nrf_comp_main_mode_t)NRFX_COMP_CONFIG_MAIN_MODE, \
|
||||
.threshold = NRFX_COMP_CONFIG_TH, \
|
||||
.speed_mode = (nrf_comp_sp_mode_t)NRFX_COMP_CONFIG_SPEED_MODE, \
|
||||
@@ -120,6 +122,7 @@ typedef struct
|
||||
#define NRFX_COMP_DEFAULT_CONFIG(_input) \
|
||||
{ \
|
||||
.reference = (nrf_comp_ref_t)NRFX_COMP_CONFIG_REF, \
|
||||
.ext_ref = NRF_COMP_EXT_REF_0, \
|
||||
.main_mode = (nrf_comp_main_mode_t)NRFX_COMP_CONFIG_MAIN_MODE, \
|
||||
.threshold = NRFX_COMP_CONFIG_TH, \
|
||||
.speed_mode = (nrf_comp_sp_mode_t)NRFX_COMP_CONFIG_SPEED_MODE, \
|
||||
@@ -135,35 +138,34 @@ typedef struct
|
||||
* This function initializes the COMP driver, but does not enable the peripheral or any interrupts.
|
||||
* To start the driver, call the function @ref nrfx_comp_start() after initialization.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver has already been initialized.
|
||||
* @retval NRFX_ERROR_BUSY If the LPCOMP peripheral is already in use.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver has already been initialized.
|
||||
* @retval NRFX_ERROR_BUSY The LPCOMP peripheral is already in use.
|
||||
* This is possible only if @ref nrfx_prs module
|
||||
* is enabled.
|
||||
*/
|
||||
nrfx_err_t nrfx_comp_init(nrfx_comp_config_t const * p_config,
|
||||
nrfx_comp_event_handler_t event_handler);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the COMP driver.
|
||||
* @brief Function for uninitializing the COMP driver.
|
||||
*
|
||||
* This function uninitializes the COMP driver. The COMP peripheral and
|
||||
* its interrupts are disabled, and local variables are cleaned. After this call, you must
|
||||
* initialize the driver again by calling nrfx_comp_init() if you want to use it.
|
||||
* This function uninitializes the COMP driver. The COMP peripheral and
|
||||
* its interrupts are disabled, and local variables are cleaned. After this call, you must
|
||||
* initialize the driver again by calling nrfx_comp_init() if you want to use it.
|
||||
*
|
||||
* @sa nrfx_comp_stop()
|
||||
* @sa nrfx_comp_stop
|
||||
*/
|
||||
void nrfx_comp_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the analog input.
|
||||
*
|
||||
* @param[in] psel COMP analog pin selection.
|
||||
* @param[in] psel COMP analog pin selection.
|
||||
*/
|
||||
void nrfx_comp_pin_select(nrf_comp_input_t psel);
|
||||
|
||||
@@ -173,38 +175,37 @@ void nrfx_comp_pin_select(nrf_comp_input_t psel);
|
||||
* Before calling this function, the driver must be initialized. This function
|
||||
* enables the COMP peripheral and its interrupts.
|
||||
*
|
||||
* @param[in] comp_evt_en_mask Mask of events to be enabled. This parameter should be built as
|
||||
* 'or' of elements from @ref nrfx_comp_evt_en_mask_t.
|
||||
* @param[in] comp_shorts_mask Mask of shorts to be enabled. This parameter should be built as
|
||||
* 'or' of elements from @ref nrfx_comp_short_mask_t.
|
||||
*
|
||||
* @sa nrfx_comp_init()
|
||||
* @param[in] comp_evt_en_mask Mask of events to be enabled. This parameter is to be built as
|
||||
* an OR of elements from @ref nrfx_comp_evt_en_mask_t.
|
||||
* @param[in] comp_shorts_mask Mask of shortcuts to be enabled. This parameter is to be built as
|
||||
* an OR of elements from @ref nrfx_comp_short_mask_t.
|
||||
*
|
||||
* @sa nrfx_comp_init
|
||||
*/
|
||||
void nrfx_comp_start(uint32_t comp_evt_en_mask, uint32_t comp_shorts_mask);
|
||||
|
||||
/**@brief Function for stopping the COMP peripheral.
|
||||
/**
|
||||
* @brief Function for stopping the COMP peripheral.
|
||||
*
|
||||
* Before calling this function, the driver must be enabled. This function disables the COMP
|
||||
* peripheral and its interrupts.
|
||||
*
|
||||
* @sa nrfx_comp_uninit()
|
||||
*
|
||||
* @sa nrfx_comp_uninit
|
||||
*/
|
||||
void nrfx_comp_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Function for copying the current state of the comparator result to the RESULT register.
|
||||
*
|
||||
* @retval 0 If the input voltage is below the threshold (VIN+ < VIN-).
|
||||
* @retval 1 If the input voltage is above the threshold (VIN+ > VIN-).
|
||||
* @retval 0 The input voltage is below the threshold (VIN+ < VIN-).
|
||||
* @retval 1 The input voltage is above the threshold (VIN+ > VIN-).
|
||||
*/
|
||||
uint32_t nrfx_comp_sample(void);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a COMP task.
|
||||
*
|
||||
* @param[in] task COMP task.
|
||||
* @param[in] task COMP task.
|
||||
*
|
||||
* @return Address of the given COMP task.
|
||||
*/
|
||||
@@ -225,12 +226,12 @@ __STATIC_INLINE uint32_t nrfx_comp_event_address_get(nrf_comp_event_t event)
|
||||
return (uint32_t)nrf_comp_event_address_get(event);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_comp_irq_handler(void);
|
||||
|
||||
|
||||
/** @} **/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -55,8 +55,8 @@ void nrfx_dppi_free(void);
|
||||
*
|
||||
* @param[out] p_channel Pointer to the DPPI channel number that has been allocated.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM If there is no available channel to be used.
|
||||
* @retval NRFX_SUCCESS The channel was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM There is no available channel to be used.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_channel_alloc(uint8_t * p_channel);
|
||||
|
||||
@@ -66,8 +66,8 @@ nrfx_err_t nrfx_dppi_channel_alloc(uint8_t * p_channel);
|
||||
*
|
||||
* @param[in] channel DPPI channel to be freed.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully freed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the specified channel is not allocated.
|
||||
* @retval NRFX_SUCCESS The channel was successfully freed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The specified channel is not allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_channel_free(uint8_t channel);
|
||||
|
||||
@@ -76,8 +76,8 @@ nrfx_err_t nrfx_dppi_channel_free(uint8_t channel);
|
||||
*
|
||||
* @param[in] channel DPPI channel to be enabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully enabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the specified channel is not allocated.
|
||||
* @retval NRFX_SUCCESS The channel was successfully enabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The specified channel is not allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_channel_enable(uint8_t channel);
|
||||
|
||||
@@ -86,8 +86,8 @@ nrfx_err_t nrfx_dppi_channel_enable(uint8_t channel);
|
||||
*
|
||||
* @param[in] channel DPPI channel to be disabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully disabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the specified channel is not allocated.
|
||||
* @retval NRFX_SUCCESS The channel was successfully disabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The specified channel is not allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_channel_disable(uint8_t channel);
|
||||
|
||||
@@ -97,8 +97,8 @@ nrfx_err_t nrfx_dppi_channel_disable(uint8_t channel);
|
||||
*
|
||||
* @param[out] p_group Pointer to the DPPI channel group that has been allocated.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel group was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM If there is no available channel group to be used.
|
||||
* @retval NRFX_SUCCESS The channel group was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM There is no available channel group to be used.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_group_alloc(nrf_dppi_channel_group_t * p_group);
|
||||
|
||||
@@ -108,8 +108,8 @@ nrfx_err_t nrfx_dppi_group_alloc(nrf_dppi_channel_group_t * p_group);
|
||||
*
|
||||
* @param[in] group DPPI channel group to be freed.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel group was successfully freed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the specified group is not allocated.
|
||||
* @retval NRFX_SUCCESS The channel group was successfully freed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_group_free(nrf_dppi_channel_group_t group);
|
||||
|
||||
@@ -119,8 +119,8 @@ nrfx_err_t nrfx_dppi_group_free(nrf_dppi_channel_group_t group);
|
||||
* @param[in] channel DPPI channel to be added.
|
||||
* @param[in] group Channel group in which to include the channel.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully included.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the specified group or channel is not allocated.
|
||||
* @retval NRFX_SUCCESS The channel was successfully included.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The specified group or channel is not allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_channel_include_in_group(uint8_t channel,
|
||||
nrf_dppi_channel_group_t group);
|
||||
@@ -131,8 +131,8 @@ nrfx_err_t nrfx_dppi_channel_include_in_group(uint8_t channel,
|
||||
* @param[in] channel DPPI channel to be removed.
|
||||
* @param[in] group Channel group from which to remove the channel.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully removed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the specified group or channel is not allocated.
|
||||
* @retval NRFX_SUCCESS The channel was successfully removed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The specified group or channel is not allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_channel_remove_from_group(uint8_t channel,
|
||||
nrf_dppi_channel_group_t group);
|
||||
@@ -142,8 +142,8 @@ nrfx_err_t nrfx_dppi_channel_remove_from_group(uint8_t channel,
|
||||
*
|
||||
* @param[in] group Channel group to be cleared.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the group was successfully cleared.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the specified group is not allocated.
|
||||
* @retval NRFX_SUCCESS The group was successfully cleared.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_group_clear(nrf_dppi_channel_group_t group);
|
||||
|
||||
@@ -152,8 +152,8 @@ nrfx_err_t nrfx_dppi_group_clear(nrf_dppi_channel_group_t group);
|
||||
*
|
||||
* @param[in] group Channel group to be enabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the group was successfully enabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the specified group is not allocated.
|
||||
* @retval NRFX_SUCCESS The group was successfully enabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_group_enable(nrf_dppi_channel_group_t group);
|
||||
|
||||
@@ -162,8 +162,8 @@ nrfx_err_t nrfx_dppi_group_enable(nrf_dppi_channel_group_t group);
|
||||
*
|
||||
* @param[in] group Channel group to be disabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the group was successfully disabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the specified group is not allocated.
|
||||
* @retval NRFX_SUCCESS The group was successfully disabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_dppi_group_disable(nrf_dppi_channel_group_t group);
|
||||
|
||||
|
||||
@@ -44,87 +44,102 @@ extern "C" {
|
||||
* @defgroup nrfx_gpiote GPIOTE driver
|
||||
* @{
|
||||
* @ingroup nrf_gpiote
|
||||
* @brief GPIOTE peripheral driver.
|
||||
* @brief GPIO Task Event (GPIOTE) peripheral driver.
|
||||
*/
|
||||
|
||||
/**@brief Input pin configuration. */
|
||||
/** @brief Input pin configuration. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_gpiote_polarity_t sense; /**< Transition that triggers interrupt. */
|
||||
nrf_gpiote_polarity_t sense; /**< Transition that triggers the interrupt. */
|
||||
nrf_gpio_pin_pull_t pull; /**< Pulling mode. */
|
||||
bool is_watcher : 1; /**< True when the input pin is tracking an output pin. */
|
||||
bool hi_accuracy : 1; /**< True when high accuracy (IN_EVENT) is used. */
|
||||
bool skip_gpio_setup : 1; /**< Do not change GPIO configuration */
|
||||
} nrfx_gpiote_in_config_t;
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect low-to-high transition.
|
||||
* @details Set hi_accu to true to use IN_EVENT. */
|
||||
/**
|
||||
* @brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect low-to-high transition.
|
||||
* @details Set hi_accu to true to use IN_EVENT.
|
||||
*/
|
||||
#define NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_LOTOHI, \
|
||||
}
|
||||
{ \
|
||||
.sense = NRF_GPIOTE_POLARITY_LOTOHI, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.skip_gpio_setup = false, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect high-to-low transition.
|
||||
* @details Set hi_accu to true to use IN_EVENT. */
|
||||
/**
|
||||
* @brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect high-to-low transition.
|
||||
* @details Set hi_accu to true to use IN_EVENT.
|
||||
*/
|
||||
#define NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_HITOLO, \
|
||||
}
|
||||
{ \
|
||||
.sense = NRF_GPIOTE_POLARITY_HITOLO, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.skip_gpio_setup = false, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect any change on the pin.
|
||||
* @details Set hi_accu to true to use IN_EVENT.*/
|
||||
/**
|
||||
* @brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect any change on the pin.
|
||||
* @details Set hi_accu to true to use IN_EVENT.
|
||||
*/
|
||||
#define NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_TOGGLE, \
|
||||
}
|
||||
{ \
|
||||
.sense = NRF_GPIOTE_POLARITY_TOGGLE, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.skip_gpio_setup = false, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect low-to-high transition.
|
||||
/**
|
||||
* @brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect low-to-high transition.
|
||||
* @details Set hi_accu to true to use IN_EVENT.
|
||||
* @note This macro prepares configuration that skips GPIO setup. */
|
||||
* @note This macro prepares configuration that skips the GPIO setup.
|
||||
*/
|
||||
#define NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_LOTOHI(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_LOTOHI, \
|
||||
.skip_gpio_setup = true, \
|
||||
}
|
||||
{ \
|
||||
.sense = NRF_GPIOTE_POLARITY_LOTOHI, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.skip_gpio_setup = true, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect high-to-low transition.
|
||||
/**
|
||||
* @brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect high-to-low transition.
|
||||
* @details Set hi_accu to true to use IN_EVENT.
|
||||
* @note This macro prepares configuration that skips GPIO setup. */
|
||||
* @note This macro prepares configuration that skips the GPIO setup.
|
||||
*/
|
||||
#define NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_HITOLO(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_HITOLO, \
|
||||
.skip_gpio_setup = true, \
|
||||
}
|
||||
{ \
|
||||
.sense = NRF_GPIOTE_POLARITY_HITOLO, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.skip_gpio_setup = true, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect any change on the pin.
|
||||
/**
|
||||
* @brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect any change on the pin.
|
||||
* @details Set hi_accu to true to use IN_EVENT.
|
||||
* @note This macro prepares configuration that skips GPIO setup. */
|
||||
* @note This macro prepares configuration that skips the GPIO setup.
|
||||
*/
|
||||
#define NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_TOGGLE(hi_accu) \
|
||||
{ \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.sense = NRF_GPIOTE_POLARITY_TOGGLE, \
|
||||
.skip_gpio_setup = true, \
|
||||
}
|
||||
{ \
|
||||
.sense = NRF_GPIOTE_POLARITY_TOGGLE, \
|
||||
.pull = NRF_GPIO_PIN_NOPULL, \
|
||||
.is_watcher = false, \
|
||||
.hi_accuracy = hi_accu, \
|
||||
.skip_gpio_setup = true, \
|
||||
}
|
||||
|
||||
|
||||
/**@brief Output pin configuration. */
|
||||
/** @brief Output pin configuration. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_gpiote_polarity_t action; /**< Configuration of the pin task. */
|
||||
@@ -132,15 +147,18 @@ typedef struct
|
||||
bool task_pin; /**< True if the pin is controlled by a GPIOTE task. */
|
||||
} nrfx_gpiote_out_config_t;
|
||||
|
||||
/**@brief Macro for configuring a pin to use as output. GPIOTE is not used for the pin. */
|
||||
/** @brief Macro for configuring a pin to use as output. GPIOTE is not used for the pin. */
|
||||
#define NRFX_GPIOTE_CONFIG_OUT_SIMPLE(init_high) \
|
||||
{ \
|
||||
.action = NRF_GPIOTE_POLARITY_LOTOHI, \
|
||||
.init_state = init_high ? NRF_GPIOTE_INITIAL_VALUE_HIGH : NRF_GPIOTE_INITIAL_VALUE_LOW, \
|
||||
.task_pin = false, \
|
||||
.task_pin = false, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use the GPIO OUT TASK to change the state from high to low.
|
||||
* @details The task will clear the pin. Therefore, the pin is set initially. */
|
||||
/**
|
||||
* @brief Macro for configuring a pin to use the GPIO OUT TASK to change the state from high to low.
|
||||
* @details The task will clear the pin. Therefore, the pin is set initially.
|
||||
*/
|
||||
#define NRFX_GPIOTE_CONFIG_OUT_TASK_LOW \
|
||||
{ \
|
||||
.init_state = NRF_GPIOTE_INITIAL_VALUE_HIGH, \
|
||||
@@ -148,22 +166,26 @@ typedef struct
|
||||
.action = NRF_GPIOTE_POLARITY_HITOLO, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use the GPIO OUT TASK to change the state from low to high.
|
||||
* @details The task will set the pin. Therefore, the pin is cleared initially. */
|
||||
/**
|
||||
* @brief Macro for configuring a pin to use the GPIO OUT TASK to change the state from low to high.
|
||||
* @details The task will set the pin. Therefore, the pin is cleared initially.
|
||||
*/
|
||||
#define NRFX_GPIOTE_CONFIG_OUT_TASK_HIGH \
|
||||
{ \
|
||||
.action = NRF_GPIOTE_POLARITY_LOTOHI, \
|
||||
.init_state = NRF_GPIOTE_INITIAL_VALUE_LOW, \
|
||||
.task_pin = true, \
|
||||
.action = NRF_GPIOTE_POLARITY_LOTOHI, \
|
||||
}
|
||||
|
||||
/**@brief Macro for configuring a pin to use the GPIO OUT TASK to toggle the pin state.
|
||||
* @details The initial pin state must be provided. */
|
||||
/**
|
||||
* @brief Macro for configuring a pin to use the GPIO OUT TASK to toggle the pin state.
|
||||
* @details The initial pin state must be provided.
|
||||
*/
|
||||
#define NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE(init_high) \
|
||||
{ \
|
||||
.action = NRF_GPIOTE_POLARITY_TOGGLE, \
|
||||
.init_state = init_high ? NRF_GPIOTE_INITIAL_VALUE_HIGH : NRF_GPIOTE_INITIAL_VALUE_LOW, \
|
||||
.task_pin = true, \
|
||||
.action = NRF_GPIOTE_POLARITY_TOGGLE, \
|
||||
}
|
||||
|
||||
/** @brief Pin. */
|
||||
@@ -172,8 +194,8 @@ typedef uint32_t nrfx_gpiote_pin_t;
|
||||
/**
|
||||
* @brief Pin event handler prototype.
|
||||
*
|
||||
* @param pin Pin that triggered this event.
|
||||
* @param action Action that lead to triggering this event.
|
||||
* @param[in] pin Pin that triggered this event.
|
||||
* @param[in] action Action that led to triggering this event.
|
||||
*/
|
||||
typedef void (*nrfx_gpiote_evt_handler_t)(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action);
|
||||
|
||||
@@ -183,25 +205,23 @@ typedef void (*nrfx_gpiote_evt_handler_t)(nrfx_gpiote_pin_t pin, nrf_gpiote_pola
|
||||
* @details Only static configuration is supported to prevent the shared
|
||||
* resource being customized by the initiator.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver was already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_gpiote_init(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking if the GPIOTE module is initialized.
|
||||
*
|
||||
* @details The GPIOTE module is a shared module. Therefore, you should check if
|
||||
* @details The GPIOTE module is a shared module. Therefore, check if
|
||||
* the module is already initialized and skip initialization if it is.
|
||||
*
|
||||
* @retval true If the module is already initialized.
|
||||
* @retval false If the module is not initialized.
|
||||
* @retval true The module is already initialized.
|
||||
* @retval false The module is not initialized.
|
||||
*/
|
||||
bool nrfx_gpiote_is_init(void);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the GPIOTE module.
|
||||
*/
|
||||
/** @brief Function for uninitializing the GPIOTE module. */
|
||||
void nrfx_gpiote_uninit(void);
|
||||
|
||||
/**
|
||||
@@ -214,9 +234,9 @@ void nrfx_gpiote_uninit(void);
|
||||
* @param[in] pin Pin.
|
||||
* @param[in] p_config Initial configuration.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is not initialized or the pin is already used.
|
||||
* @retval NRFX_ERROR_NO_MEM If no GPIOTE channel is available.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver is not initialized or the pin is already used.
|
||||
* @retval NRFX_ERROR_NO_MEM No GPIOTE channel is available.
|
||||
*/
|
||||
nrfx_err_t nrfx_gpiote_out_init(nrfx_gpiote_pin_t pin,
|
||||
nrfx_gpiote_out_config_t const * p_config);
|
||||
@@ -305,7 +325,7 @@ uint32_t nrfx_gpiote_clr_task_addr_get(nrfx_gpiote_pin_t pin);
|
||||
* If high-accuracy mode is used, the driver attempts to allocate one
|
||||
* of the available GPIOTE channels. If no channel is
|
||||
* available, an error is returned.
|
||||
* In low accuracy mode SENSE feature is used. In this case only one active pin
|
||||
* In low accuracy mode SENSE feature is used. In this case, only one active pin
|
||||
* can be detected at a time. It can be worked around by setting all of the used
|
||||
* low accuracy pins to toggle mode.
|
||||
* For more information about SENSE functionality, refer to Product Specification.
|
||||
@@ -314,9 +334,9 @@ uint32_t nrfx_gpiote_clr_task_addr_get(nrfx_gpiote_pin_t pin);
|
||||
* @param[in] p_config Initial configuration.
|
||||
* @param[in] evt_handler User function to be called when the configured transition occurs.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is not initialized or the pin is already used.
|
||||
* @retval NRFX_ERROR_NO_MEM If no GPIOTE channel is available.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver is not initialized or the pin is already used.
|
||||
* @retval NRFX_ERROR_NO_MEM No GPIOTE channel is available.
|
||||
*/
|
||||
nrfx_err_t nrfx_gpiote_in_init(nrfx_gpiote_pin_t pin,
|
||||
nrfx_gpiote_in_config_t const * p_config,
|
||||
@@ -335,8 +355,7 @@ void nrfx_gpiote_in_uninit(nrfx_gpiote_pin_t pin);
|
||||
*
|
||||
* @details If the input pin is configured as high-accuracy pin, the function
|
||||
* enables an IN_EVENT. Otherwise, the function enables the GPIO sense mechanism.
|
||||
* Note that a PORT event is shared between multiple pins, therefore the
|
||||
* interrupt is always enabled.
|
||||
* The PORT event is shared between multiple pins, therefore the interrupt is always enabled.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
* @param[in] int_enable True to enable the interrupt. Always valid for a high-accuracy pin.
|
||||
@@ -355,8 +374,8 @@ void nrfx_gpiote_in_event_disable(nrfx_gpiote_pin_t pin);
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*
|
||||
* @retval true If the input pin is set.
|
||||
* @retval false If the input pin is not set.
|
||||
* @retval true The input pin is set.
|
||||
* @retval false The input pin is not set.
|
||||
*/
|
||||
bool nrfx_gpiote_in_is_set(nrfx_gpiote_pin_t pin);
|
||||
|
||||
@@ -365,6 +384,8 @@ bool nrfx_gpiote_in_is_set(nrfx_gpiote_pin_t pin);
|
||||
* @details If the pin is configured to use low-accuracy mode, the address of the PORT event is returned.
|
||||
*
|
||||
* @param[in] pin Pin.
|
||||
*
|
||||
* @return Address of the specified input pin event.
|
||||
*/
|
||||
uint32_t nrfx_gpiote_in_event_addr_get(nrfx_gpiote_pin_t pin);
|
||||
|
||||
@@ -401,12 +422,12 @@ void nrfx_gpiote_set_task_trigger(nrfx_gpiote_pin_t pin);
|
||||
void nrfx_gpiote_clr_task_trigger(nrfx_gpiote_pin_t pin);
|
||||
#endif // defined(GPIOTE_FEATURE_CLR_PRESENT) || defined(__NRFX_DOXYGEN__)
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_gpiote_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -82,13 +82,11 @@ typedef struct
|
||||
/** @brief I2S driver buffers structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t * p_rx_buffer;
|
||||
uint32_t const * p_tx_buffer;
|
||||
uint32_t * p_rx_buffer; ///< Pointer to the buffer for received data.
|
||||
uint32_t const * p_tx_buffer; ///< Pointer to the buffer with data to be sent.
|
||||
} nrfx_i2s_buffers_t;
|
||||
|
||||
/**
|
||||
* @brief I2S driver default configuration.
|
||||
*/
|
||||
/** @brief I2S driver default configuration. */
|
||||
#define NRFX_I2S_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.sck_pin = NRFX_I2S_CONFIG_SCK_PIN, \
|
||||
@@ -108,28 +106,28 @@ typedef struct
|
||||
|
||||
|
||||
#define NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED (1UL << 0)
|
||||
/**< The application should provide buffers that are to be used in the next
|
||||
* part of the transfer. A call to @ref nrfx_i2s_next_buffers_set should
|
||||
/**< The application must provide buffers that are to be used in the next
|
||||
* part of the transfer. A call to @ref nrfx_i2s_next_buffers_set must
|
||||
* be done before the currently used buffers are completely processed
|
||||
* (i.e. the time remaining for supplying the next buffers depends on
|
||||
* (that is, the time remaining for supplying the next buffers depends on
|
||||
* the used size of the buffers). */
|
||||
|
||||
/**
|
||||
* @brief I2S driver data handler type.
|
||||
*
|
||||
* A data handling function of this type must be specified during initialization
|
||||
* A data handling function of this type must be specified during the initialization
|
||||
* of the driver. The driver will call this function when it finishes using
|
||||
* buffers passed to it by the application, and when it needs to be provided
|
||||
* with buffers for the next part of the transfer.
|
||||
*
|
||||
* @note The @c p_released pointer passed to this function is temporary and
|
||||
* will be invalid after the function returns, hence it cannot be stored
|
||||
* and used later. If needed, the pointed content (i.e. buffers pointers)
|
||||
* should be copied instead.
|
||||
* and used later. If needed, the pointed content (that is, buffers pointers)
|
||||
* must be copied instead.
|
||||
*
|
||||
* @param[in] p_released Pointer to a structure with pointers to buffers
|
||||
* passed previously to the driver that will no longer
|
||||
* be access by it (they can be now safely released or
|
||||
* be accessed by it (they can be now safely released or
|
||||
* used for another purpose, in particular for a next
|
||||
* part of the transfer).
|
||||
* This pointer will be NULL if the application did not
|
||||
@@ -158,13 +156,13 @@ typedef void (* nrfx_i2s_data_handler_t)(nrfx_i2s_buffers_t const * p_released,
|
||||
/**
|
||||
* @brief Function for initializing the I2S driver.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] handler Data handler provided by the user. Must not be NULL.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] handler Data handler provided by the user. Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the requested combination of configuration
|
||||
* options is not allowed by the I2S peripheral.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver was already initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The requested combination of configuration
|
||||
* options is not allowed by the I2S peripheral.
|
||||
*/
|
||||
nrfx_err_t nrfx_i2s_init(nrfx_i2s_config_t const * p_config,
|
||||
nrfx_i2s_data_handler_t handler);
|
||||
@@ -179,7 +177,7 @@ void nrfx_i2s_uninit(void);
|
||||
* only, TX (transmission) only, or in both directions simultaneously.
|
||||
* The mode is selected by specifying a proper buffer for a given direction
|
||||
* in the call to this function or by passing NULL instead if this direction
|
||||
* should be disabled.
|
||||
* is to be disabled.
|
||||
*
|
||||
* The length of the buffer (which is a common value for RX and TX if both
|
||||
* directions are enabled) is specified in 32-bit words. One 32-bit memory
|
||||
@@ -192,20 +190,20 @@ void nrfx_i2s_uninit(void);
|
||||
* to be placed in the Data RAM region. If this condition is not met,
|
||||
* this function will fail with the error code NRFX_ERROR_INVALID_ADDR.
|
||||
*
|
||||
* @param[in] p_initial_buffers Pointer to a structure specifying the buffers
|
||||
* to be used in the initial part of the transfer
|
||||
* (buffers for all consecutive parts are provided
|
||||
* through the data handler).
|
||||
* @param[in] buffer_size Size of the buffers (in 32-bit words).
|
||||
* Must not be 0.
|
||||
* @param[in] flags Transfer options (0 for default settings).
|
||||
* Currently, no additional flags are available.
|
||||
* @param[in] p_initial_buffers Pointer to a structure specifying the buffers
|
||||
* to be used in the initial part of the transfer
|
||||
* (buffers for all consecutive parts are provided
|
||||
* through the data handler).
|
||||
* @param[in] buffer_size Size of the buffers (in 32-bit words).
|
||||
* Must not be 0.
|
||||
* @param[in] flags Transfer options (0 for default settings).
|
||||
* Currently, no additional flags are available.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If a transfer was already started or
|
||||
* the driver has not been initialized.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffers are not placed
|
||||
* in the Data RAM region.
|
||||
* @retval NRFX_SUCCESS The operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE Transfer was already started or
|
||||
* the driver has not been initialized.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR The provided buffers are not placed
|
||||
* in the Data RAM region.
|
||||
*/
|
||||
nrfx_err_t nrfx_i2s_start(nrfx_i2s_buffers_t const * p_initial_buffers,
|
||||
uint16_t buffer_size,
|
||||
@@ -215,7 +213,7 @@ nrfx_err_t nrfx_i2s_start(nrfx_i2s_buffers_t const * p_initial_buffers,
|
||||
* @brief Function for supplying the buffers to be used in the next part of
|
||||
* the transfer.
|
||||
*
|
||||
* The application should call this function when the data handler receives
|
||||
* The application must call this function when the data handler receives
|
||||
* @ref NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED in the @c status parameter.
|
||||
* The call can be done immediately from the data handler function or later,
|
||||
* but it has to be done before the I2S peripheral finishes processing the
|
||||
@@ -223,9 +221,9 @@ nrfx_err_t nrfx_i2s_start(nrfx_i2s_buffers_t const * p_initial_buffers,
|
||||
*
|
||||
* @sa nrfx_i2s_data_handler_t
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the buffers were already supplied or
|
||||
* the peripheral is currently being stopped.
|
||||
* @retval NRFX_SUCCESS If the operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the buffers were already supplied or
|
||||
* the peripheral is currently being stopped.
|
||||
*/
|
||||
nrfx_err_t nrfx_i2s_next_buffers_set(nrfx_i2s_buffers_t const * p_buffers);
|
||||
|
||||
@@ -243,3 +241,4 @@ void nrfx_i2s_irq_handler(void);
|
||||
#endif
|
||||
|
||||
#endif // NRFX_I2S_H__
|
||||
|
||||
@@ -48,7 +48,7 @@ extern "C" {
|
||||
|
||||
/**
|
||||
* @brief LPCOMP event handler function type.
|
||||
* @param[in] event LPCOMP event.
|
||||
* @param[in] event LPCOMP event.
|
||||
*/
|
||||
typedef void (* nrfx_lpcomp_event_handler_t)(nrf_lpcomp_event_t event);
|
||||
|
||||
@@ -60,24 +60,24 @@ typedef struct
|
||||
uint8_t interrupt_priority; /**< LPCOMP interrupt priority. */
|
||||
} nrfx_lpcomp_config_t;
|
||||
|
||||
/** @brief LPCOMP driver default configuration including the LPCOMP HAL configuration. */
|
||||
/** @brief LPCOMP driver default configuration, including the LPCOMP HAL configuration. */
|
||||
#ifdef NRF52_SERIES
|
||||
#define NRFX_LPCOMP_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.hal = { (nrf_lpcomp_ref_t)NRFX_LPCOMP_CONFIG_REFERENCE , \
|
||||
(nrf_lpcomp_detect_t)NRFX_LPCOMP_CONFIG_DETECTION, \
|
||||
(nrf_lpcomp_hysteresis_t)NRFX_LPCOMP_CONFIG_HYST }, \
|
||||
.input = (nrf_lpcomp_input_t)NRFX_LPCOMP_CONFIG_INPUT, \
|
||||
.interrupt_priority = NRFX_LPCOMP_CONFIG_IRQ_PRIORITY \
|
||||
}
|
||||
#define NRFX_LPCOMP_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.hal = { (nrf_lpcomp_ref_t)NRFX_LPCOMP_CONFIG_REFERENCE , \
|
||||
(nrf_lpcomp_detect_t)NRFX_LPCOMP_CONFIG_DETECTION, \
|
||||
(nrf_lpcomp_hysteresis_t)NRFX_LPCOMP_CONFIG_HYST }, \
|
||||
.input = (nrf_lpcomp_input_t)NRFX_LPCOMP_CONFIG_INPUT, \
|
||||
.interrupt_priority = NRFX_LPCOMP_CONFIG_IRQ_PRIORITY \
|
||||
}
|
||||
#else
|
||||
#define NRFX_LPCOMP_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.hal = { (nrf_lpcomp_ref_t)NRFX_LPCOMP_CONFIG_REFERENCE , \
|
||||
(nrf_lpcomp_detect_t)NRFX_LPCOMP_CONFIG_DETECTION }, \
|
||||
.input = (nrf_lpcomp_input_t)NRFX_LPCOMP_CONFIG_INPUT, \
|
||||
.interrupt_priority = NRFX_LPCOMP_CONFIG_IRQ_PRIORITY \
|
||||
}
|
||||
#define NRFX_LPCOMP_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.hal = { (nrf_lpcomp_ref_t)NRFX_LPCOMP_CONFIG_REFERENCE , \
|
||||
(nrf_lpcomp_detect_t)NRFX_LPCOMP_CONFIG_DETECTION }, \
|
||||
.input = (nrf_lpcomp_input_t)NRFX_LPCOMP_CONFIG_INPUT, \
|
||||
.interrupt_priority = NRFX_LPCOMP_CONFIG_IRQ_PRIORITY \
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -86,13 +86,13 @@ typedef struct
|
||||
* This function initializes the LPCOMP driver, but does not enable the peripheral or any interrupts.
|
||||
* To start the driver, call the function nrfx_lpcomp_enable() after initialization.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver has already been initialized.
|
||||
* @retval NRFX_ERROR_BUSY If the COMP peripheral is already in use.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver has already been initialized.
|
||||
* @retval NRFX_ERROR_BUSY The COMP peripheral is already in use.
|
||||
* This is possible only if @ref nrfx_prs module
|
||||
* is enabled.
|
||||
*/
|
||||
@@ -100,39 +100,42 @@ nrfx_err_t nrfx_lpcomp_init(nrfx_lpcomp_config_t const * p_config,
|
||||
nrfx_lpcomp_event_handler_t event_handler);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the LCOMP driver.
|
||||
* @brief Function for uninitializing the LCOMP driver.
|
||||
*
|
||||
* This function uninitializes the LPCOMP driver. The LPCOMP peripheral and
|
||||
* its interrupts are disabled, and local variables are cleaned. After this call, you must
|
||||
* initialize the driver again by calling nrfx_lpcomp_init() if you want to use it.
|
||||
* This function uninitializes the LPCOMP driver. The LPCOMP peripheral and
|
||||
* its interrupts are disabled, and local variables are cleaned. After this call, you must
|
||||
* initialize the driver again by calling nrfx_lpcomp_init() if you want to use it.
|
||||
*
|
||||
* @sa nrfx_lpcomp_disable()
|
||||
* @sa nrfx_lpcomp_init()
|
||||
* @sa nrfx_lpcomp_disable
|
||||
* @sa nrfx_lpcomp_init
|
||||
*/
|
||||
void nrfx_lpcomp_uninit(void);
|
||||
|
||||
/**@brief Function for enabling the LPCOMP peripheral and interrupts.
|
||||
/**
|
||||
* @brief Function for enabling the LPCOMP peripheral and interrupts.
|
||||
*
|
||||
* Before calling this function, the driver must be initialized. This function
|
||||
* enables the LPCOMP peripheral and its interrupts.
|
||||
*
|
||||
* @sa nrfx_lpcomp_disable()
|
||||
* @sa nrfx_lpcomp_disable
|
||||
*/
|
||||
void nrfx_lpcomp_enable(void);
|
||||
|
||||
/**@brief Function for disabling the LPCOMP peripheral.
|
||||
/**
|
||||
* @brief Function for disabling the LPCOMP peripheral.
|
||||
*
|
||||
* Before calling this function, the driver must be initialized. This function disables the LPCOMP
|
||||
* peripheral and its interrupts.
|
||||
*
|
||||
* @sa nrfx_lpcomp_enable()
|
||||
* @sa nrfx_lpcomp_enable
|
||||
*/
|
||||
void nrfx_lpcomp_disable(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_lpcomp_irq_handler(void);
|
||||
|
||||
/** @} **/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -52,9 +52,7 @@ extern "C" {
|
||||
|
||||
#define NRFX_NFCT_NFCID1_DEFAULT_LEN NRFX_NFCT_NFCID1_DOUBLE_SIZE ///< Default length of NFC ID. */
|
||||
|
||||
/**
|
||||
* @brief NFCT hardware states.
|
||||
*/
|
||||
/** @brief NFCT hardware states. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_NFCT_STATE_DISABLED = NRF_NFCT_TASK_DISABLE, ///< NFC Tag is disabled (no sensing of an external NFC field).
|
||||
@@ -74,7 +72,7 @@ typedef enum
|
||||
NRFX_NFCT_ACTIVE_STATE_DEFAULT, ///< NFC Tag is either sleeping or idle, depending on the previous state before being selected by a poller.
|
||||
} nrfx_nfct_active_state_t;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief NFCT driver event types, passed to the upper-layer callback function
|
||||
* provided during the initialization.
|
||||
*/
|
||||
@@ -90,18 +88,14 @@ typedef enum
|
||||
NRFX_NFCT_EVT_ERROR = NRF_NFCT_INT_ERROR_MASK, ///< Error occurred in an NFC communication.
|
||||
} nrfx_nfct_evt_id_t;
|
||||
|
||||
/**
|
||||
* @brief NFCT timing-related error types.
|
||||
*/
|
||||
/** @brief NFCT timing-related error types. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_NFCT_ERROR_FRAMEDELAYTIMEOUT, ///< No response frame was transmitted to the poller in the transmit window.
|
||||
NRFX_NFCT_ERROR_NUM, ///< Total number of possible errors.
|
||||
} nrfx_nfct_error_t;
|
||||
|
||||
/**
|
||||
* @brief NFCT driver parameter types.
|
||||
*/
|
||||
/** @brief NFCT driver parameter types. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_NFCT_PARAM_ID_FDT, ///< NFC-A Frame Delay Time parameter.
|
||||
@@ -109,18 +103,14 @@ typedef enum
|
||||
NRFX_NFCT_PARAM_ID_NFCID1, ///< NFC-A NFCID1 setting (NFC tag identifier).
|
||||
} nrfx_nfct_param_id_t;
|
||||
|
||||
/**
|
||||
* @brief NFCID1 descriptor.
|
||||
*/
|
||||
/** @brief NFCID1 descriptor. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t const * p_id; ///< NFCID1 data.
|
||||
uint8_t id_size; ///< NFCID1 size.
|
||||
} nrfx_nfct_nfcid1_t;
|
||||
|
||||
/**
|
||||
* @brief NFCT driver parameter descriptor.
|
||||
*/
|
||||
/** @brief NFCT driver parameter descriptor. */
|
||||
typedef struct
|
||||
{
|
||||
nrfx_nfct_param_id_t id; ///< Type of parameter.
|
||||
@@ -129,46 +119,36 @@ typedef struct
|
||||
uint32_t fdt; ///< NFC-A Frame Delay Time. Filled when nrfx_nfct_param_t::id is @ref NRFX_NFCT_PARAM_ID_FDT.
|
||||
uint8_t sel_res_protocol; ///< NFC-A value of the 'Protocol' field in the SEL_RES frame. Filled when nrfx_nfct_param_t::id is @ref NRFX_NFCT_PARAM_ID_SEL_RES.
|
||||
nrfx_nfct_nfcid1_t nfcid1; ///< NFC-A NFCID1 value (tag identifier). Filled when nrfx_nfct_param_t::id is @ref NRFX_NFCT_PARAM_ID_NFCID1.
|
||||
} data;
|
||||
} data; ///< Union to store parameter data.
|
||||
} nrfx_nfct_param_t;
|
||||
|
||||
/**
|
||||
* @brief NFCT driver RX/TX buffer descriptor.
|
||||
*/
|
||||
/** @brief NFCT driver RX/TX buffer descriptor. */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t data_size; ///< RX/TX buffer size.
|
||||
uint8_t const * p_data; ///< RX/TX buffer.
|
||||
} nrfx_nfct_data_desc_t;
|
||||
|
||||
/**
|
||||
* @brief Structure used to describe the @ref NRFX_NFCT_EVT_RX_FRAMEEND event type.
|
||||
*/
|
||||
/** @brief Structure used to describe the @ref NRFX_NFCT_EVT_RX_FRAMEEND event type. */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t rx_status; ///< RX error status.
|
||||
nrfx_nfct_data_desc_t rx_data; ///< RX buffer.
|
||||
} nrfx_nfct_evt_rx_frameend_t;
|
||||
|
||||
/**
|
||||
* @brief Structure used to describe the @ref NRFX_NFCT_EVT_TX_FRAMESTART event type.
|
||||
*/
|
||||
/** @brief Structure used to describe the @ref NRFX_NFCT_EVT_TX_FRAMESTART event type. */
|
||||
typedef struct
|
||||
{
|
||||
nrfx_nfct_data_desc_t tx_data; ///< TX buffer.
|
||||
} nrfx_nfct_evt_tx_framestart_t;
|
||||
|
||||
/**
|
||||
* @brief Structure used to describe the @ref NRFX_NFCT_EVT_ERROR event type.
|
||||
*/
|
||||
/** @brief Structure used to describe the @ref NRFX_NFCT_EVT_ERROR event type. */
|
||||
typedef struct
|
||||
{
|
||||
nrfx_nfct_error_t reason; ///< Reason for error.
|
||||
} nrfx_nfct_evt_error_t;
|
||||
|
||||
/**
|
||||
* @brief NFCT driver event.
|
||||
*/
|
||||
/** @brief NFCT driver event. */
|
||||
typedef struct
|
||||
{
|
||||
nrfx_nfct_evt_id_t evt_id; ///< Type of event.
|
||||
@@ -177,32 +157,30 @@ typedef struct
|
||||
nrfx_nfct_evt_rx_frameend_t rx_frameend; ///< End of the RX frame data. Filled when nrfx_nfct_evt_t::evt_id is @ref NRFX_NFCT_EVT_RX_FRAMEEND.
|
||||
nrfx_nfct_evt_tx_framestart_t tx_framestart; ///< Start of the TX frame data. Filled when nrfx_nfct_evt_t::evt_id is @ref NRFX_NFCT_EVT_TX_FRAMESTART.
|
||||
nrfx_nfct_evt_error_t error; ///< Error data. Filled when nrfx_nfct_evt_t::evt_id is @ref NRFX_NFCT_EVT_ERROR.
|
||||
} params;
|
||||
} params; ///< Union to store event data.
|
||||
} nrfx_nfct_evt_t;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Callback descriptor to pass events from the NFCT driver to the upper layer.
|
||||
*
|
||||
* @param[in] p_event Pointer to the event descriptor.
|
||||
*/
|
||||
typedef void (*nrfx_nfct_handler_t)(nrfx_nfct_evt_t const * p_event);
|
||||
|
||||
/**
|
||||
* @brief NFCT driver configuration structure.
|
||||
*/
|
||||
/** @brief NFCT driver configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t rxtx_int_mask; ///< Mask for enabling RX/TX events. Indicate which events must be forwarded to the upper layer by using @ref nrfx_nfct_evt_id_t. By default, no events are enabled. */
|
||||
nrfx_nfct_handler_t cb; ///< Callback.
|
||||
} nrfx_nfct_config_t;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Function for initializing the NFCT driver.
|
||||
*
|
||||
* @param[in] p_config Pointer to the NFCT driver configuration structure.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the NFCT driver was initialized successfully.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the NFCT driver is already initialized.
|
||||
* @retval NRFX_SUCCESS The NFCT driver was initialized successfully.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The NFCT driver is already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_nfct_init(nrfx_nfct_config_t const * p_config);
|
||||
|
||||
@@ -231,26 +209,26 @@ void nrfx_nfct_disable(void);
|
||||
/**
|
||||
* @brief Function for checking whether the external NFC field is present in the range of the tag.
|
||||
*
|
||||
* @retval true If the NFC field is present.
|
||||
* @retval false If no NFC field is present.
|
||||
* @retval true The NFC field is present.
|
||||
* @retval false No NFC field is present.
|
||||
*/
|
||||
bool nrfx_nfct_field_check(void);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Function for preparing the NFCT driver for receiving an NFC frame.
|
||||
*
|
||||
* @param[in] p_rx_data Pointer to the RX buffer.
|
||||
*/
|
||||
void nrfx_nfct_rx(nrfx_nfct_data_desc_t const * p_rx_data);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Function for transmitting an NFC frame.
|
||||
*
|
||||
* @param[in] p_tx_data Pointer to the TX buffer.
|
||||
* @param[in] delay_mode Delay mode of the NFCT frame timer.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_LENGTH If the TX buffer size is invalid.
|
||||
* @retval NRFX_SUCCESS The operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_LENGTH The TX buffer size is invalid.
|
||||
*/
|
||||
nrfx_err_t nrfx_nfct_tx(nrfx_nfct_data_desc_t const * p_tx_data,
|
||||
nrf_nfct_frame_delay_mode_t delay_mode);
|
||||
@@ -265,7 +243,7 @@ nrfx_err_t nrfx_nfct_tx(nrfx_nfct_data_desc_t const * p_tx_data,
|
||||
*/
|
||||
void nrfx_nfct_state_force(nrfx_nfct_state_t state);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Function for moving the NFCT to a new initial substate within @ref NRFX_NFCT_STATE_ACTIVATED.
|
||||
*
|
||||
* @param[in] sub_state The required substate.
|
||||
@@ -279,12 +257,12 @@ void nrfx_nfct_init_substate_force(nrfx_nfct_active_state_t sub_state);
|
||||
*
|
||||
* @param[in] p_param Pointer to parameter descriptor.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the parameter data is invalid.
|
||||
* @retval NRFX_SUCCESS The operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The parameter data is invalid.
|
||||
*/
|
||||
nrfx_err_t nrfx_nfct_parameter_set(nrfx_nfct_param_t const * p_param);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Function for getting default bytes for NFCID1.
|
||||
*
|
||||
* @param[in,out] p_nfcid1_buff In: empty buffer for data;
|
||||
@@ -292,8 +270,8 @@ nrfx_err_t nrfx_nfct_parameter_set(nrfx_nfct_param_t const * p_param);
|
||||
* can be used to fill the Type 2 Tag Internal Bytes.
|
||||
* @param[in] nfcid1_buff_len Length of the NFCID1 buffer.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_LENGTH If length of the NFCID buffer is different than
|
||||
* @retval NRFX_SUCCESS The operation was successful.
|
||||
* @retval NRFX_ERROR_INVALID_LENGTH Length of the NFCID buffer is different than
|
||||
* @ref NRFX_NFCT_NFCID1_SINGLE_SIZE,
|
||||
* @ref NRFX_NFCT_NFCID1_DOUBLE_SIZE, or
|
||||
* @ref NRFX_NFCT_NFCID1_TRIPLE_SIZE.
|
||||
@@ -301,7 +279,7 @@ nrfx_err_t nrfx_nfct_parameter_set(nrfx_nfct_param_t const * p_param);
|
||||
nrfx_err_t nrfx_nfct_nfcid1_default_bytes_get(uint8_t * const p_nfcid1_buff,
|
||||
uint32_t nfcid1_buff_len);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Function for enabling the automatic collision resolution.
|
||||
*
|
||||
* @details As defined by the NFC Forum Digital Protocol Technical Specification (and ISO 14443-3),
|
||||
@@ -310,19 +288,19 @@ nrfx_err_t nrfx_nfct_nfcid1_default_bytes_get(uint8_t * const p_nfcid1_buff,
|
||||
*/
|
||||
void nrfx_nfct_autocolres_enable(void);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Function for disabling the automatic collision resolution.
|
||||
*
|
||||
* @details See also details in @ref nrfx_nfct_autocolres_enable.
|
||||
*/
|
||||
void nrfx_nfct_autocolres_disable(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_nfct_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -338,7 +316,7 @@ void nrfx_nfct_irq_handler(void);
|
||||
* - 79. NFCT: A false EVENTS_FIELDDETECTED event occurs after the field is lost.
|
||||
* - 116. NFCT does not release HFCLK when switching from ACTIVATED to SENSE mode.
|
||||
* To implement the first workaround, an instance of NRF_TIMER is used. After the NFC field is detected,
|
||||
* the timing module periodically polls its state to determine when the field is turned off.
|
||||
* the timing module periodically polls its state to determine when the field is turned off.
|
||||
* To implement the second workaround, power reset is used to release the clock acquired by NFCT
|
||||
* after the field is turned off. Note that the NFCT register configuration is restored to defaults.
|
||||
*
|
||||
@@ -358,7 +336,7 @@ void nrfx_nfct_irq_handler(void);
|
||||
* The application of the implemented workarounds for the nRF52840 chip is determined at runtime and depends
|
||||
* on the chip variant.
|
||||
*
|
||||
* The current code contains a patch for the anomaly 25 (NFCT: Reset value of
|
||||
* The current code contains a patch for the anomaly 25 (NFCT: Reset value of
|
||||
* SENSRES register is incorrect), so that the module now works on Windows Phone.
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -46,32 +46,25 @@ extern "C" {
|
||||
* @brief Pulse Density Modulation (PDM) peripheral driver.
|
||||
*/
|
||||
|
||||
|
||||
/** @brief Maximum supported PDM buffer size. */
|
||||
#define NRFX_PDM_MAX_BUFFER_SIZE 32767
|
||||
|
||||
|
||||
/**
|
||||
* @brief PDM error type.
|
||||
*/
|
||||
/** @brief PDM error type. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_PDM_NO_ERROR = 0,
|
||||
NRFX_PDM_ERROR_OVERFLOW = 1
|
||||
NRFX_PDM_NO_ERROR = 0, ///< No error.
|
||||
NRFX_PDM_ERROR_OVERFLOW = 1 ///< Overflow error.
|
||||
} nrfx_pdm_error_t;
|
||||
|
||||
/**
|
||||
* @brief PDM event structure.
|
||||
*/
|
||||
/** @brief PDM event structure. */
|
||||
typedef struct
|
||||
{
|
||||
bool buffer_requested; ///< Buffer request flag.
|
||||
int16_t * buffer_released; ///< Pointer to the released buffer. Can be NULL.
|
||||
nrfx_pdm_error_t error; ///< Error type.
|
||||
bool buffer_requested; ///< Buffer request flag.
|
||||
int16_t * buffer_released; ///< Pointer to the released buffer. Can be NULL.
|
||||
nrfx_pdm_error_t error; ///< Error type.
|
||||
} nrfx_pdm_evt_t;
|
||||
|
||||
/**
|
||||
* @brief PDM interface driver configuration structure.
|
||||
*/
|
||||
/** @brief PDM interface driver configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_pdm_mode_t mode; ///< Interface operation mode.
|
||||
@@ -86,7 +79,7 @@ typedef struct
|
||||
|
||||
/**
|
||||
* @brief Macro for setting @ref nrfx_pdm_config_t to default settings
|
||||
* in single ended mode.
|
||||
* in the single-ended mode.
|
||||
*
|
||||
* @param _pin_clk CLK output pin.
|
||||
* @param _pin_din DIN input pin.
|
||||
@@ -104,7 +97,7 @@ typedef struct
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handler for PDM interface ready events.
|
||||
* @brief Handler for the PDM interface ready events.
|
||||
*
|
||||
* This event handler is called on a buffer request, an error or when a buffer
|
||||
* is full and ready to be processed.
|
||||
@@ -117,12 +110,12 @@ typedef void (*nrfx_pdm_event_handler_t)(nrfx_pdm_evt_t const * const p_evt);
|
||||
/**
|
||||
* @brief Function for initializing the PDM interface.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user. Cannot be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is already initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If invalid configuration was specified.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver is already initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM Invalid configuration was specified.
|
||||
*/
|
||||
nrfx_err_t nrfx_pdm_init(nrfx_pdm_config_t const * p_config,
|
||||
nrfx_pdm_event_handler_t event_handler);
|
||||
@@ -137,9 +130,9 @@ void nrfx_pdm_uninit(void);
|
||||
/**
|
||||
* @brief Function for getting the address of a PDM interface task.
|
||||
*
|
||||
* @param[in] task Task.
|
||||
* @param[in] task Task.
|
||||
*
|
||||
* @return Task address.
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_pdm_task_address_get(nrf_pdm_task_t task)
|
||||
{
|
||||
@@ -149,8 +142,8 @@ __STATIC_INLINE uint32_t nrfx_pdm_task_address_get(nrf_pdm_task_t task)
|
||||
/**
|
||||
* @brief Function for getting the state of the PDM interface.
|
||||
*
|
||||
* @retval true If the PDM interface is enabled.
|
||||
* @retval false If the PDM interface is disabled.
|
||||
* @retval true The PDM interface is enabled.
|
||||
* @retval false The PDM interface is disabled.
|
||||
*/
|
||||
__STATIC_INLINE bool nrfx_pdm_enable_check(void)
|
||||
{
|
||||
@@ -158,46 +151,46 @@ __STATIC_INLINE bool nrfx_pdm_enable_check(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for starting PDM sampling.
|
||||
* @brief Function for starting the PDM sampling.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If sampling was started successfully or was already in progress.
|
||||
* @retval NRFX_ERROR_BUSY If a previous start/stop operation is in progress.
|
||||
* @retval NRFX_SUCCESS Sampling was started successfully or was already in progress.
|
||||
* @retval NRFX_ERROR_BUSY Previous start/stop operation is in progress.
|
||||
*/
|
||||
nrfx_err_t nrfx_pdm_start(void);
|
||||
|
||||
/**
|
||||
* @brief Function for stopping PDM sampling.
|
||||
* @brief Function for stopping the PDM sampling.
|
||||
*
|
||||
* When this function is called, the PDM interface is stopped after finishing
|
||||
* the current frame.
|
||||
* The event handler function might be called once more after calling this function.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If sampling was stopped successfully or was already stopped before.
|
||||
* @retval NRFX_ERROR_BUSY If a previous start/stop operation is in progress.
|
||||
* @retval NRFX_SUCCESS Sampling was stopped successfully or was already stopped before.
|
||||
* @retval NRFX_ERROR_BUSY Previous start/stop operation is in progress.
|
||||
*/
|
||||
nrfx_err_t nrfx_pdm_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Function for supplying the sample buffer.
|
||||
* @brief Function for supplying the sample buffer.
|
||||
*
|
||||
* Call this function after every buffer request event.
|
||||
*
|
||||
* @param[in] buffer Pointer to the receive buffer. Cannot be NULL.
|
||||
* @param[in] buffer_length Length of the receive buffer in 16-bit words.
|
||||
* @param[in] buffer Pointer to the receive buffer. Cannot be NULL.
|
||||
* @param[in] buffer_length Length of the receive buffer in 16-bit words.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the buffer was applied successfully.
|
||||
* @retval NRFX_ERROR_BUSY If the buffer was already supplied or the peripheral is currently being stopped.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was not initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If invalid parameters were provided.
|
||||
* @retval NRFX_SUCCESS The buffer was applied successfully.
|
||||
* @retval NRFX_ERROR_BUSY The buffer was already supplied or the peripheral is currently being stopped.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver was not initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM Invalid parameters were provided.
|
||||
*/
|
||||
nrfx_err_t nrfx_pdm_buffer_set(int16_t * buffer, uint16_t buffer_length);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_pdm_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -92,26 +92,26 @@ typedef enum
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRFX_POWER_USB_STATE_DISCONNECTED, /**< No power on USB lines detected */
|
||||
NRFX_POWER_USB_STATE_CONNECTED, /**< The USB power is detected, but USB power regulator is not ready */
|
||||
NRFX_POWER_USB_STATE_READY /**< From the power point of view USB is ready for working */
|
||||
NRFX_POWER_USB_STATE_DISCONNECTED, /**< No power on USB lines detected. */
|
||||
NRFX_POWER_USB_STATE_CONNECTED, /**< The USB power is detected, but USB power regulator is not ready. */
|
||||
NRFX_POWER_USB_STATE_READY /**< From the power viewpoint, USB is ready for working. */
|
||||
}nrfx_power_usb_state_t;
|
||||
#endif /* NRF_POWER_HAS_USBREG */
|
||||
|
||||
/**
|
||||
* @name Callback types
|
||||
*
|
||||
* Defined types of callback functions
|
||||
* Defined types of callback functions.
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Event handler for power failure warning
|
||||
* @brief Event handler for power failure warning.
|
||||
*/
|
||||
typedef void (*nrfx_power_pofwarn_event_handler_t)(void);
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Event handler for entering/exiting sleep
|
||||
* @brief Event handler for the sleep events.
|
||||
*
|
||||
* @param event Event type
|
||||
*/
|
||||
@@ -120,7 +120,7 @@ typedef void (*nrfx_power_sleep_event_handler_t)(nrfx_power_sleep_evt_t event);
|
||||
|
||||
#if NRF_POWER_HAS_USBREG || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Event handler for USB related power events
|
||||
* @brief Event handler for the USB-related power events.
|
||||
*
|
||||
* @param event Event type
|
||||
*/
|
||||
@@ -136,22 +136,22 @@ typedef void (*nrfx_power_usb_event_handler_t)(nrfx_power_usb_evt_t event);
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
* @brief Enable main DCDC regulator
|
||||
* @brief Enable main DCDC regulator.
|
||||
*
|
||||
* This bit only informs the driver that elements for DCDC regulator
|
||||
* are installed and regulator can be used.
|
||||
* The regulator would be enabled or disabled automatically
|
||||
* are installed and the regulator can be used.
|
||||
* The regulator will be enabled or disabled automatically
|
||||
* by the hardware, basing on current power requirement.
|
||||
*/
|
||||
bool dcdcen:1;
|
||||
|
||||
#if NRF_POWER_HAS_VDDH || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Enable HV DCDC regulator
|
||||
* @brief Enable HV DCDC regulator.
|
||||
*
|
||||
* This bit only informs the driver that elements for DCDC regulator
|
||||
* are installed and regulator can be used.
|
||||
* The regulator would be enabled or disabled automatically
|
||||
* are installed and the regulator can be used.
|
||||
* The regulator will be enabled or disabled automatically
|
||||
* by the hardware, basing on current power requirement.
|
||||
*/
|
||||
bool dcdcenhv: 1;
|
||||
@@ -159,44 +159,44 @@ typedef struct
|
||||
}nrfx_power_config_t;
|
||||
|
||||
/**
|
||||
* @brief The configuration for power failure comparator
|
||||
* @brief The configuration for power failure comparator.
|
||||
*
|
||||
* Configuration used to enable and configure power failure comparator
|
||||
* Configuration used to enable and configure the power failure comparator.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_power_pofwarn_event_handler_t handler; //!< Event handler
|
||||
nrfx_power_pofwarn_event_handler_t handler; //!< Event handler.
|
||||
#if NRF_POWER_HAS_POFCON || defined(__NRFX_DOXYGEN__)
|
||||
nrf_power_pof_thr_t thr; //!< Threshold for power failure detection
|
||||
#endif
|
||||
#if NRF_POWER_HAS_VDDH || defined(__NRFX_DOXYGEN__)
|
||||
nrf_power_pof_thrvddh_t thrvddh; //!< Threshold for power failure detection on VDDH pin
|
||||
nrf_power_pof_thrvddh_t thrvddh; //!< Threshold for power failure detection on the VDDH pin.
|
||||
#endif
|
||||
}nrfx_power_pofwarn_config_t;
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief The configuration of sleep event processing
|
||||
* @brief The configuration of sleep event processing.
|
||||
*
|
||||
* Configuration used to enable and configure sleep event handling
|
||||
* Configuration used to enable and configure sleep event handling.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_power_sleep_event_handler_t handler; //!< Event handler
|
||||
bool en_enter:1; //!< Enable event on sleep entering
|
||||
bool en_exit :1; //!< Enable event on sleep exiting
|
||||
nrfx_power_sleep_event_handler_t handler; //!< Event handler.
|
||||
bool en_enter:1; //!< Enable event on sleep entering.
|
||||
bool en_exit :1; //!< Enable event on sleep exiting.
|
||||
}nrfx_power_sleepevt_config_t;
|
||||
#endif
|
||||
|
||||
#if NRF_POWER_HAS_USBREG || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief The configuration of USB related power events
|
||||
* @brief The configuration of the USB-related power events.
|
||||
*
|
||||
* Configuration used to enable and configure USB power event handling
|
||||
* Configuration used to enable and configure USB power event handling.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrfx_power_usb_event_handler_t handler; //!< Event processing
|
||||
nrfx_power_usb_event_handler_t handler; //!< Event processing.
|
||||
}nrfx_power_usbevt_config_t;
|
||||
#endif /* NRF_POWER_HAS_USBREG */
|
||||
|
||||
@@ -215,11 +215,11 @@ nrfx_power_usb_event_handler_t nrfx_power_usb_handler_get(void);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize power module driver
|
||||
* @brief Function for initializing the power module driver.
|
||||
*
|
||||
* Enabled power module driver would process all the interrupts from power system.
|
||||
* Enabled power module driver processes all the interrupts from the power system.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
*
|
||||
* @retval NRFX_SUCCESS Successfully initialized.
|
||||
* @retval NRFX_ERROR_ALREADY_INITIALIZED Module was already initialized.
|
||||
@@ -227,7 +227,7 @@ nrfx_power_usb_event_handler_t nrfx_power_usb_handler_get(void);
|
||||
nrfx_err_t nrfx_power_init(nrfx_power_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Unintialize power module driver
|
||||
* @brief Function for unintializing the power module driver.
|
||||
*
|
||||
* Disables all the interrupt handling in the module.
|
||||
*
|
||||
@@ -237,36 +237,36 @@ void nrfx_power_uninit(void);
|
||||
|
||||
#if NRF_POWER_HAS_POFCON || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Initialize power failure comparator
|
||||
* @brief Function for initializing the power failure comparator.
|
||||
*
|
||||
* Configures the power failure comparator. This function does not setup and enable it.
|
||||
* Those steps can be done with functions @ref nrfx_power_pof_enable and @ref nrfx_power_pof_disable
|
||||
* or with Softdevice API (when Softdevice is using).
|
||||
* Configures the power failure comparator. This function does not set it up and enable it.
|
||||
* These steps can be done with functions @ref nrfx_power_pof_enable and @ref nrfx_power_pof_disable
|
||||
* or with the SoftDevice API (when in use).
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
* If event handler is set to NULL, interrupt would be disabled.
|
||||
* If event handler is set to NULL, the interrupt will be disabled.
|
||||
*/
|
||||
void nrfx_power_pof_init(nrfx_power_pofwarn_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Enable power failure comparator
|
||||
* Sets and enables interrupt of the power failure comparator. This functions cannot be using
|
||||
* when Softdevice is enabled. If event handler set in init function is set to NULL, interrupt
|
||||
* would be disabled.
|
||||
* @brief Function for enabling the power failure comparator.
|
||||
* Sets and enables the interrupt of the power failure comparator. This function cannot be in use
|
||||
* when SoftDevice is enabled. If the event handler set in the init function is set to NULL, the interrupt
|
||||
* will be disabled.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*/
|
||||
void nrfx_power_pof_enable(nrfx_power_pofwarn_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Disable the power failure comparator
|
||||
* @brief Function for disabling the power failure comparator.
|
||||
*
|
||||
* Disables the power failure comparator interrupt.
|
||||
*/
|
||||
void nrfx_power_pof_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Clear the power failure comparator settings
|
||||
* @brief Function for clearing the power failure comparator settings.
|
||||
*
|
||||
* Clears the settings of the power failure comparator.
|
||||
*/
|
||||
@@ -275,9 +275,9 @@ void nrfx_power_pof_uninit(void);
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Initialize sleep entering and exiting events processing
|
||||
* @brief Function for initializing the processing of the sleep events.
|
||||
*
|
||||
* Configures and setups the sleep event processing.
|
||||
* Configures and sets up the sleep event processing.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*
|
||||
@@ -287,19 +287,17 @@ void nrfx_power_pof_uninit(void);
|
||||
void nrfx_power_sleepevt_init(nrfx_power_sleepevt_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Enable sleep entering and exiting events processing
|
||||
* @brief Function for enabling the processing of the sleep events.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*/
|
||||
void nrfx_power_sleepevt_enable(nrfx_power_sleepevt_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Disable sleep entering and exiting events processing
|
||||
*/
|
||||
/** @brief Function for disabling the processing of the sleep events. */
|
||||
void nrfx_power_sleepevt_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Uninitialize sleep entering and exiting events processing
|
||||
* @brief Function for uninitializing the processing of the sleep events.
|
||||
*
|
||||
* @sa nrfx_power_sleepevt_init
|
||||
*/
|
||||
@@ -308,9 +306,9 @@ void nrfx_power_sleepevt_uninit(void);
|
||||
|
||||
#if NRF_POWER_HAS_USBREG || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Initialize USB power event processing
|
||||
* @brief Function for initializing the processing of USB power event.
|
||||
*
|
||||
* Configures and setups the USB power event processing.
|
||||
* Configures and sets up the USB power event processing.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*
|
||||
@@ -318,27 +316,23 @@ void nrfx_power_sleepevt_uninit(void);
|
||||
*/
|
||||
void nrfx_power_usbevt_init(nrfx_power_usbevt_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Enable USB power event processing
|
||||
*/
|
||||
/** @brief Function for enabling the processing of USB power event. */
|
||||
void nrfx_power_usbevt_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Disable USB power event processing
|
||||
*/
|
||||
/** @brief Function for disabling the processing of USB power event. */
|
||||
void nrfx_power_usbevt_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Uninitalize USB power event processing
|
||||
* @brief Function for uninitalizing the processing of USB power event.
|
||||
*
|
||||
* @sa nrfx_power_usbevt_init
|
||||
*/
|
||||
void nrfx_power_usbevt_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Get the status of USB power
|
||||
* @brief Function for getting the status of USB power.
|
||||
*
|
||||
* @return Current USB power status
|
||||
* @return Current USB power status.
|
||||
*/
|
||||
__STATIC_INLINE nrfx_power_usb_state_t nrfx_power_usbstatus_get(void);
|
||||
|
||||
@@ -364,12 +358,12 @@ __STATIC_INLINE nrfx_power_usb_state_t nrfx_power_usbstatus_get(void)
|
||||
|
||||
#endif /* SUPPRESS_INLINE_IMPLEMENTATION */
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_power_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -47,13 +47,15 @@ __STATIC_INLINE void nrfx_power_clock_irq_init(void)
|
||||
uint8_t priority;
|
||||
#if NRFX_CHECK(NRFX_POWER_ENABLED) && NRFX_CHECK(NRFX_CLOCK_ENABLED)
|
||||
#if NRFX_POWER_CONFIG_IRQ_PRIORITY != NRFX_CLOCK_CONFIG_IRQ_PRIORITY
|
||||
#error "IRQ priority for POWER and CLOCK have to be the same. Check <nrfx_config.h>."
|
||||
#error "IRQ priorities for POWER and CLOCK must be the same. Check <nrfx_config.h>."
|
||||
#endif
|
||||
priority = NRFX_POWER_CONFIG_IRQ_PRIORITY;
|
||||
#elif NRFX_CHECK(NRFX_POWER_ENABLED)
|
||||
priority = NRFX_POWER_CONFIG_IRQ_PRIORITY;
|
||||
#elif NRFX_CHECK(NRFX_CLOCK_ENABLED)
|
||||
priority = NRFX_CLOCK_CONFIG_IRQ_PRIORITY;
|
||||
#else
|
||||
#error "This code is not supposed to be compiled when neither POWER nor CLOCK is enabled."
|
||||
#endif
|
||||
|
||||
if (!NRFX_IRQ_IS_ENABLED(nrfx_get_irq_number(NRF_CLOCK)))
|
||||
|
||||
@@ -46,23 +46,28 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef NRFX_PPI_CHANNELS_USED
|
||||
#if !defined (NRFX_PPI_CHANNELS_USED) || defined(__NRFX_DOXYGEN__)
|
||||
/** @brief Bitfield representing PPI channels used by external modules. */
|
||||
#define NRFX_PPI_CHANNELS_USED 0
|
||||
#endif
|
||||
|
||||
#ifndef NRFX_PPI_GROUPS_USED
|
||||
#if !defined(NRFX_PPI_GROUPS_USED) || defined(__NRFX_DOXYGEN__)
|
||||
/** @brief Bitfield representing PPI groups used by external modules. */
|
||||
#define NRFX_PPI_GROUPS_USED 0
|
||||
#endif
|
||||
|
||||
#if PPI_CH_NUM > 16
|
||||
#define NRFX_PPI_ALL_APP_CHANNELS_MASK ((uint32_t)0xFFFFFFFFuL & ~(NRFX_PPI_CHANNELS_USED)) /**< All PPI channels available to the application. */
|
||||
#define NRFX_PPI_PROG_APP_CHANNELS_MASK ((uint32_t)0x000FFFFFuL & ~(NRFX_PPI_CHANNELS_USED)) /**< Programmable PPI channels available to the application. */
|
||||
#if (PPI_CH_NUM > 16) || defined(__NRFX_DOXYGEN__)
|
||||
/** @brief Bitfield representing all PPI channels available to the application. */
|
||||
#define NRFX_PPI_ALL_APP_CHANNELS_MASK ((uint32_t)0xFFFFFFFFuL & ~(NRFX_PPI_CHANNELS_USED))
|
||||
/** @brief Bitfield representing programmable PPI channels available to the application. */
|
||||
#define NRFX_PPI_PROG_APP_CHANNELS_MASK ((uint32_t)0x000FFFFFuL & ~(NRFX_PPI_CHANNELS_USED))
|
||||
#else
|
||||
#define NRFX_PPI_ALL_APP_CHANNELS_MASK ((uint32_t)0xFFF0FFFFuL & ~(NRFX_PPI_CHANNELS_USED)) /**< All PPI channels available to the application. */
|
||||
#define NRFX_PPI_PROG_APP_CHANNELS_MASK ((uint32_t)0x0000FFFFuL & ~(NRFX_PPI_CHANNELS_USED)) /**< Programmable PPI channels available to the application. */
|
||||
#define NRFX_PPI_ALL_APP_CHANNELS_MASK ((uint32_t)0xFFF0FFFFuL & ~(NRFX_PPI_CHANNELS_USED))
|
||||
#define NRFX_PPI_PROG_APP_CHANNELS_MASK ((uint32_t)0x0000FFFFuL & ~(NRFX_PPI_CHANNELS_USED))
|
||||
#endif
|
||||
|
||||
#define NRFX_PPI_ALL_APP_GROUPS_MASK (((1uL << PPI_GROUP_NUM) - 1) & ~(NRFX_PPI_GROUPS_USED)) /**< All PPI groups available to the application. */
|
||||
/** @brief Bitfield representing all PPI groups available to the application. */
|
||||
#define NRFX_PPI_ALL_APP_GROUPS_MASK (((1uL << PPI_GROUP_NUM) - 1) & ~(NRFX_PPI_GROUPS_USED))
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the PPI module.
|
||||
@@ -77,8 +82,8 @@ void nrfx_ppi_free_all(void);
|
||||
*
|
||||
* @param[out] p_channel Pointer to the PPI channel that has been allocated.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM If there is no available channel to be used.
|
||||
* @retval NRFX_SUCCESS The channel was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM There is no available channel to be used.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_alloc(nrf_ppi_channel_t * p_channel);
|
||||
|
||||
@@ -88,8 +93,8 @@ nrfx_err_t nrfx_ppi_channel_alloc(nrf_ppi_channel_t * p_channel);
|
||||
*
|
||||
* @param[in] channel PPI channel to be freed.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully freed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel is not user-configurable.
|
||||
* @retval NRFX_SUCCESS The channel was successfully freed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The channel is not user-configurable.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_free(nrf_ppi_channel_t channel);
|
||||
|
||||
@@ -100,21 +105,21 @@ nrfx_err_t nrfx_ppi_channel_free(nrf_ppi_channel_t channel);
|
||||
* @param[in] eep Event endpoint address.
|
||||
* @param[in] tep Task endpoint address.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully assigned.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the channel is not allocated for the user.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel is not user-configurable.
|
||||
* @retval NRFX_SUCCESS The channel was successfully assigned.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The channel is not allocated for the user.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The channel is not user-configurable.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_assign(nrf_ppi_channel_t channel, uint32_t eep, uint32_t tep);
|
||||
|
||||
/**
|
||||
* @brief Function for assigning or clearing fork endpoint to the PPI channel.
|
||||
* @brief Function for assigning fork endpoint to the PPI channel or clearing it.
|
||||
*
|
||||
* @param[in] channel PPI channel to be assigned endpoints.
|
||||
* @param[in] fork_tep Fork task endpoint address or 0 to clear.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully assigned.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the channel is not allocated for the user.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If function is not supported.
|
||||
* @retval NRFX_SUCCESS The channel was successfully assigned.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The channel is not allocated for the user.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED Function is not supported.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_fork_assign(nrf_ppi_channel_t channel, uint32_t fork_tep);
|
||||
|
||||
@@ -123,9 +128,9 @@ nrfx_err_t nrfx_ppi_channel_fork_assign(nrf_ppi_channel_t channel, uint32_t fork
|
||||
*
|
||||
* @param[in] channel PPI channel to be enabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully enabled.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the user-configurable channel is not allocated.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel cannot be enabled by the user.
|
||||
* @retval NRFX_SUCCESS The channel was successfully enabled.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The user-configurable channel is not allocated.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The channel cannot be enabled by the user.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_enable(nrf_ppi_channel_t channel);
|
||||
|
||||
@@ -134,9 +139,9 @@ nrfx_err_t nrfx_ppi_channel_enable(nrf_ppi_channel_t channel);
|
||||
*
|
||||
* @param[in] channel PPI channel to be disabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully disabled.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the user-configurable channel is not allocated.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel cannot be disabled by the user.
|
||||
* @retval NRFX_SUCCESS The channel was successfully disabled.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The user-configurable channel is not allocated.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The channel cannot be disabled by the user.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channel_disable(nrf_ppi_channel_t channel);
|
||||
|
||||
@@ -146,8 +151,8 @@ nrfx_err_t nrfx_ppi_channel_disable(nrf_ppi_channel_t channel);
|
||||
*
|
||||
* @param[out] p_group Pointer to the PPI channel group that has been allocated.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel group was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM If there is no available channel group to be used.
|
||||
* @retval NRFX_SUCCESS The channel group was successfully allocated.
|
||||
* @retval NRFX_ERROR_NO_MEM There is no available channel group to be used.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_group_alloc(nrf_ppi_channel_group_t * p_group);
|
||||
|
||||
@@ -157,8 +162,8 @@ nrfx_err_t nrfx_ppi_group_alloc(nrf_ppi_channel_group_t * p_group);
|
||||
*
|
||||
* @param[in] group PPI channel group to be freed.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel group was successfully freed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the channel group is not user-configurable.
|
||||
* @retval NRFX_SUCCESS The channel group was successfully freed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The channel group is not user-configurable.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_group_free(nrf_ppi_channel_group_t group);
|
||||
|
||||
@@ -167,7 +172,7 @@ nrfx_err_t nrfx_ppi_group_free(nrf_ppi_channel_group_t group);
|
||||
*
|
||||
* @param[in] channel Channel number to transform to a mask.
|
||||
*
|
||||
* @retval Channel mask.
|
||||
* @return Channel mask.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_ppi_channel_to_mask(nrf_ppi_channel_t channel)
|
||||
{
|
||||
@@ -180,10 +185,10 @@ __STATIC_INLINE uint32_t nrfx_ppi_channel_to_mask(nrf_ppi_channel_t channel)
|
||||
* @param[in] channel_mask PPI channels to be added.
|
||||
* @param[in] group Channel group in which to include the channels.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channels was successfully included.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group or channels are not an
|
||||
* @retval NRFX_SUCCESS The channels was successfully included.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM Group is not an application group or channels are not an
|
||||
* application channels.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE Group is not an allocated group.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channels_include_in_group(uint32_t channel_mask,
|
||||
nrf_ppi_channel_group_t group);
|
||||
@@ -194,10 +199,10 @@ nrfx_err_t nrfx_ppi_channels_include_in_group(uint32_t channel_ma
|
||||
* @param[in] channel PPI channel to be added.
|
||||
* @param[in] group Channel group in which to include the channel.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully included.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group or channel is not an
|
||||
* @retval NRFX_SUCCESS The channel was successfully included.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM Group is not an application group or channel is not an
|
||||
* application channel.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE Group is not an allocated group.
|
||||
*/
|
||||
__STATIC_INLINE nrfx_err_t nrfx_ppi_channel_include_in_group(nrf_ppi_channel_t channel,
|
||||
nrf_ppi_channel_group_t group)
|
||||
@@ -211,24 +216,24 @@ __STATIC_INLINE nrfx_err_t nrfx_ppi_channel_include_in_group(nrf_ppi_channel_t
|
||||
* @param[in] channel_mask PPI channels to be removed.
|
||||
* @param[in] group Channel group from which to remove the channels.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully removed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group or channels are not an
|
||||
* @retval NRFX_SUCCESS The channel was successfully removed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM Group is not an application group or channels are not an
|
||||
* application channels.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE Group is not an allocated group.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_channels_remove_from_group(uint32_t channel_mask,
|
||||
nrf_ppi_channel_group_t group);
|
||||
|
||||
/**
|
||||
* @brief Function for removing a PPI channel from a channel group.
|
||||
* @brief Function for removing a single PPI channel from a channel group.
|
||||
*
|
||||
* @param[in] channel PPI channel to be removed.
|
||||
* @param[in] group Channel group from which to remove the channel.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the channel was successfully removed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group or channel is not an
|
||||
* @retval NRFX_SUCCESS The channel was successfully removed.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM Group is not an application group or channel is not an
|
||||
* application channel.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE Group is not an allocated group.
|
||||
*/
|
||||
__STATIC_INLINE nrfx_err_t nrfx_ppi_channel_remove_from_group(nrf_ppi_channel_t channel,
|
||||
nrf_ppi_channel_group_t group)
|
||||
@@ -241,9 +246,9 @@ __STATIC_INLINE nrfx_err_t nrfx_ppi_channel_remove_from_group(nrf_ppi_channel_t
|
||||
*
|
||||
* @param[in] group Channel group to be cleared.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the group was successfully cleared.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
* @retval NRFX_SUCCESS The group was successfully cleared.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM Group is not an application group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE Group is not an allocated group.
|
||||
*/
|
||||
__STATIC_INLINE nrfx_err_t nrfx_ppi_group_clear(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
@@ -255,9 +260,9 @@ __STATIC_INLINE nrfx_err_t nrfx_ppi_group_clear(nrf_ppi_channel_group_t group)
|
||||
*
|
||||
* @param[in] group Channel group to be enabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the group was successfully enabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
* @retval NRFX_SUCCESS The group was successfully enabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM Group is not an application group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE Group is not an allocated group.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_group_enable(nrf_ppi_channel_group_t group);
|
||||
|
||||
@@ -266,9 +271,9 @@ nrfx_err_t nrfx_ppi_group_enable(nrf_ppi_channel_group_t group);
|
||||
*
|
||||
* @param[in] group Channel group to be disabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the group was successfully disabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If group is not an application group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If group is not an allocated group.
|
||||
* @retval NRFX_SUCCESS The group was successfully disabled.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM Group is not an application group.
|
||||
* @retval NRFX_ERROR_INVALID_STATE Group is not an allocated group.
|
||||
*/
|
||||
nrfx_err_t nrfx_ppi_group_disable(nrf_ppi_channel_group_t group);
|
||||
|
||||
@@ -277,7 +282,7 @@ nrfx_err_t nrfx_ppi_group_disable(nrf_ppi_channel_group_t group);
|
||||
*
|
||||
* @param[in] task Task.
|
||||
*
|
||||
* @retval Task address.
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_ppi_task_addr_get(nrf_ppi_task_t task)
|
||||
{
|
||||
@@ -285,11 +290,11 @@ __STATIC_INLINE uint32_t nrfx_ppi_task_addr_get(nrf_ppi_task_t task)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a PPI group enable task.
|
||||
* @brief Function for getting the address of the enable task of a PPI group.
|
||||
*
|
||||
* @param[in] group PPI channel group
|
||||
*
|
||||
* @retval Task address.
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_ppi_task_addr_group_enable_get(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
@@ -297,11 +302,11 @@ __STATIC_INLINE uint32_t nrfx_ppi_task_addr_group_enable_get(nrf_ppi_channel_gro
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for getting the address of a PPI group enable task.
|
||||
* @brief Function for getting the address of the enable task of a PPI group.
|
||||
*
|
||||
* @param[in] group PPI channel group
|
||||
*
|
||||
* @retval Task address.
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_ppi_task_addr_group_disable_get(nrf_ppi_channel_group_t group)
|
||||
{
|
||||
|
||||
@@ -46,24 +46,21 @@ extern "C" {
|
||||
* @brief Pulse Width Modulation (PWM) peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief PWM driver instance data structure.
|
||||
*/
|
||||
/** @brief PWM driver instance data structure. */
|
||||
typedef struct
|
||||
{
|
||||
NRF_PWM_Type * p_registers; ///< Pointer to the structure with PWM peripheral instance registers.
|
||||
uint8_t drv_inst_idx; ///< Driver instance index.
|
||||
uint8_t drv_inst_idx; ///< Index of the driver instance. For internal use only.
|
||||
} nrfx_pwm_t;
|
||||
|
||||
/**
|
||||
* @brief Macro for creating a PWM driver instance.
|
||||
*/
|
||||
/** @brief Macro for creating a PWM driver instance. */
|
||||
#define NRFX_PWM_INSTANCE(id) \
|
||||
{ \
|
||||
.p_registers = NRFX_CONCAT_2(NRF_PWM, id), \
|
||||
.drv_inst_idx = NRFX_CONCAT_3(NRFX_PWM, id, _INST_IDX), \
|
||||
}
|
||||
|
||||
#ifndef __NRFX_DOXYGEN__
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_PWM0_ENABLED)
|
||||
NRFX_PWM0_INST_IDX,
|
||||
@@ -79,6 +76,7 @@ enum {
|
||||
#endif
|
||||
NRFX_PWM_ENABLED_COUNT
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief This value can be provided instead of a pin number for any channel
|
||||
@@ -87,15 +85,10 @@ enum {
|
||||
*/
|
||||
#define NRFX_PWM_PIN_NOT_USED 0xFF
|
||||
|
||||
/**
|
||||
* @brief This value can be added to a pin number to inverse its polarity
|
||||
* (set idle state = 1).
|
||||
*/
|
||||
/** @brief This value can be added to a pin number to invert its polarity (set idle state = 1). */
|
||||
#define NRFX_PWM_PIN_INVERTED 0x80
|
||||
|
||||
/**
|
||||
* @brief PWM driver configuration structure.
|
||||
*/
|
||||
/** @brief PWM driver configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t output_pins[NRF_PWM_CHANNEL_COUNT]; ///< Pin numbers for individual output channels (optional).
|
||||
@@ -109,9 +102,7 @@ typedef struct
|
||||
nrf_pwm_dec_step_t step_mode; ///< Mode of advancing the active sequence.
|
||||
} nrfx_pwm_config_t;
|
||||
|
||||
/**
|
||||
* @brief PWM driver default configuration.
|
||||
*/
|
||||
/** @brief PWM driver default configuration. */
|
||||
#define NRFX_PWM_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.output_pins = { NRFX_PWM_DEFAULT_CONFIG_OUT0_PIN, \
|
||||
@@ -126,14 +117,11 @@ typedef struct
|
||||
.step_mode = (nrf_pwm_dec_step_t)NRFX_PWM_DEFAULT_CONFIG_STEP_MODE, \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief PWM flags providing additional playback options.
|
||||
*/
|
||||
/** @brief PWM flags that provide additional playback options. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_PWM_FLAG_STOP = 0x01, /**< When the requested playback is finished,
|
||||
the peripheral should be stopped.
|
||||
the peripheral will be stopped.
|
||||
@note The STOP task is triggered when
|
||||
the last value of the final sequence is
|
||||
loaded from RAM, and the peripheral stops
|
||||
@@ -143,7 +131,7 @@ typedef enum
|
||||
less than the requested number of repeats
|
||||
of the last value. */
|
||||
NRFX_PWM_FLAG_LOOP = 0x02, /**< When the requested playback is finished,
|
||||
it should be started from the beginning.
|
||||
it will be started from the beginning.
|
||||
This flag is ignored if used together
|
||||
with @ref NRFX_PWM_FLAG_STOP.
|
||||
@note The playback restart is done via a
|
||||
@@ -157,28 +145,25 @@ typedef enum
|
||||
the playback restart will occur right
|
||||
after switching to the final value (this
|
||||
final value will be played only once). */
|
||||
NRFX_PWM_FLAG_SIGNAL_END_SEQ0 = 0x04, /**< The event handler should be
|
||||
NRFX_PWM_FLAG_SIGNAL_END_SEQ0 = 0x04, /**< The event handler is to be
|
||||
called when the last value
|
||||
from sequence 0 is loaded. */
|
||||
NRFX_PWM_FLAG_SIGNAL_END_SEQ1 = 0x08, /**< The event handler should be
|
||||
NRFX_PWM_FLAG_SIGNAL_END_SEQ1 = 0x08, /**< The event handler is to be
|
||||
called when the last value
|
||||
from sequence 1 is loaded. */
|
||||
NRFX_PWM_FLAG_NO_EVT_FINISHED = 0x10, /**< The playback finished event
|
||||
(enabled by default) should be
|
||||
(enabled by default) is to be
|
||||
suppressed. */
|
||||
NRFX_PWM_FLAG_START_VIA_TASK = 0x80, /**< The playback should not be
|
||||
NRFX_PWM_FLAG_START_VIA_TASK = 0x80, /**< The playback must not be
|
||||
started directly by the called
|
||||
function. Instead, the function
|
||||
should only prepare it and
|
||||
must only prepare it and
|
||||
return the address of the task
|
||||
to be triggered to start the
|
||||
playback. */
|
||||
} nrfx_pwm_flag_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief PWM driver event type.
|
||||
*/
|
||||
/** @brief PWM driver event type. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_PWM_EVT_FINISHED, ///< Sequence playback finished.
|
||||
@@ -189,24 +174,20 @@ typedef enum
|
||||
NRFX_PWM_EVT_STOPPED, ///< The PWM peripheral has been stopped.
|
||||
} nrfx_pwm_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief PWM driver event handler type.
|
||||
*/
|
||||
/** @brief PWM driver event handler type. */
|
||||
typedef void (* nrfx_pwm_handler_t)(nrfx_pwm_evt_type_t event_type);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the PWM driver.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] handler Event handler provided by the user. If NULL is passed
|
||||
* instead, event notifications are not done and PWM
|
||||
* interrupts are disabled.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver was already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_pwm_init(nrfx_pwm_t const * const p_instance,
|
||||
nrfx_pwm_config_t const * p_config,
|
||||
@@ -227,20 +208,20 @@ void nrfx_pwm_uninit(nrfx_pwm_t const * const p_instance);
|
||||
* To take advantage of the looping mechanism in the PWM peripheral, both
|
||||
* sequences must be used (single sequence can be played back only once by
|
||||
* the peripheral). Therefore, the provided sequence is internally set and
|
||||
* played back as both sequence 0 and sequence 1. Consequently, if end of
|
||||
* sequence notifications are required, events for both sequences should be
|
||||
* used (that means that both the @ref NRFX_PWM_FLAG_SIGNAL_END_SEQ0 flag
|
||||
* and the @ref NRFX_PWM_FLAG_SIGNAL_END_SEQ1 flag should be specified and
|
||||
* played back as both sequence 0 and sequence 1. Consequently, if the end of
|
||||
* sequence notifications are required, events for both sequences must be
|
||||
* used (that is, both the @ref NRFX_PWM_FLAG_SIGNAL_END_SEQ0 flag
|
||||
* and the @ref NRFX_PWM_FLAG_SIGNAL_END_SEQ1 flag must be specified, and
|
||||
* the @ref NRFX_PWM_EVT_END_SEQ0 event and the @ref NRFX_PWM_EVT_END_SEQ1
|
||||
* event should be handled in the same way).
|
||||
* event must be handled in the same way).
|
||||
*
|
||||
* Use the @ref NRFX_PWM_FLAG_START_VIA_TASK flag if you want the playback
|
||||
* to be only prepared by this function, and you want to start it later by
|
||||
* triggering a task (using PPI for instance). The function will then return
|
||||
* triggering a task (for example, by using PPI). The function will then return
|
||||
* the address of the task to be triggered.
|
||||
*
|
||||
* @note The array containing the duty cycle values for the specified sequence
|
||||
* must be in RAM and cannot be allocated on stack.
|
||||
* must be in RAM and cannot be allocated on the stack.
|
||||
* For detailed information, see @ref nrf_pwm_sequence_t.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
@@ -267,7 +248,7 @@ uint32_t nrfx_pwm_simple_playback(nrfx_pwm_t const * const p_instance,
|
||||
* the address of the task to be triggered.
|
||||
*
|
||||
* @note The array containing the duty cycle values for the specified sequence
|
||||
* must be in RAM and cannot be allocated on stack.
|
||||
* must be in RAM and cannot be allocated on the stack.
|
||||
* For detailed information, see @ref nrf_pwm_sequence_t.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
@@ -305,7 +286,7 @@ __STATIC_INLINE void nrfx_pwm_step(nrfx_pwm_t const * const p_instance);
|
||||
* might appear on the output less times than requested.
|
||||
*
|
||||
* @note This function can be instructed to wait until the playback is stopped
|
||||
* (by setting @p wait_until_stopped to true). Note that, depending on
|
||||
* (by setting @p wait_until_stopped to true). Depending on
|
||||
* the length of the PMW period, this might take a significant amount of
|
||||
* time. Alternatively, the @ref nrfx_pwm_is_stopped function can be
|
||||
* used to poll the status, or the @ref NRFX_PWM_EVT_STOPPED event can
|
||||
@@ -316,19 +297,18 @@ __STATIC_INLINE void nrfx_pwm_step(nrfx_pwm_t const * const p_instance);
|
||||
* @param[in] wait_until_stopped If true, the function will not return until
|
||||
* the playback is stopped.
|
||||
*
|
||||
* @retval true If the PWM peripheral is stopped.
|
||||
* @retval false If the PWM peripheral is not stopped.
|
||||
* @retval true The PWM peripheral is stopped.
|
||||
* @retval false The PWM peripheral is not stopped.
|
||||
*/
|
||||
bool nrfx_pwm_stop(nrfx_pwm_t const * const p_instance,
|
||||
bool wait_until_stopped);
|
||||
bool nrfx_pwm_stop(nrfx_pwm_t const * const p_instance, bool wait_until_stopped);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the status of the PWM peripheral.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @retval true If the PWM peripheral is stopped.
|
||||
* @retval false If the PWM peripheral is not stopped.
|
||||
* @retval true The PWM peripheral is stopped.
|
||||
* @retval false The PWM peripheral is not stopped.
|
||||
*/
|
||||
bool nrfx_pwm_is_stopped(nrfx_pwm_t const * const p_instance);
|
||||
|
||||
@@ -339,10 +319,9 @@ bool nrfx_pwm_is_stopped(nrfx_pwm_t const * const p_instance);
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
* @param[in] p_sequence Pointer to the new sequence definition.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_update(
|
||||
nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
nrf_pwm_sequence_t const * p_sequence);
|
||||
__STATIC_INLINE void nrfx_pwm_sequence_update(nrfx_pwm_t const * const p_instance,
|
||||
uint8_t seq_id,
|
||||
nrf_pwm_sequence_t const * p_sequence);
|
||||
|
||||
/**
|
||||
* @brief Function for updating the pointer to the duty cycle values
|
||||
@@ -370,7 +349,7 @@ __STATIC_INLINE void nrfx_pwm_sequence_length_update(nrfx_pwm_t const * const p_
|
||||
|
||||
/**
|
||||
* @brief Function for updating the number of repeats for duty cycle values
|
||||
* in specified sequence during playback.
|
||||
* in the specified sequence during playback.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] seq_id Identifier of the sequence (0 or 1).
|
||||
@@ -404,18 +383,18 @@ __STATIC_INLINE void nrfx_pwm_sequence_end_delay_update(nrfx_pwm_t const * const
|
||||
__STATIC_INLINE uint32_t nrfx_pwm_task_address_get(nrfx_pwm_t const * const p_instance,
|
||||
nrf_pwm_task_t task);
|
||||
|
||||
/**@brief Function for returning the address of a specified PWM event that can
|
||||
/**
|
||||
* @brief Function for returning the address of a specified PWM event that can
|
||||
* be used in PPI module.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] event Requested event.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] event Requested event.
|
||||
*
|
||||
* @return Event address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_pwm_event_address_get(nrfx_pwm_t const * const p_instance,
|
||||
nrf_pwm_event_t event);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrfx_pwm_step(nrfx_pwm_t const * const p_instance)
|
||||
@@ -472,6 +451,8 @@ __STATIC_INLINE uint32_t nrfx_pwm_event_address_get(nrfx_pwm_t const * const p_i
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_pwm_0_irq_handler(void);
|
||||
void nrfx_pwm_1_irq_handler(void);
|
||||
@@ -479,8 +460,6 @@ void nrfx_pwm_2_irq_handler(void);
|
||||
void nrfx_pwm_3_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -46,7 +46,7 @@ extern "C" {
|
||||
* @brief Quadrature Decoder (QDEC) peripheral driver.
|
||||
*/
|
||||
|
||||
/**@brief QDEC configuration structure.*/
|
||||
/** @brief QDEC configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_qdec_reportper_t reportper; /**< Report period in samples. */
|
||||
@@ -62,91 +62,102 @@ typedef struct
|
||||
} nrfx_qdec_config_t;
|
||||
|
||||
/**@brief QDEC default configuration. */
|
||||
#define NRFX_QDEC_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.reportper = (nrf_qdec_reportper_t)NRFX_QDEC_CONFIG_REPORTPER, \
|
||||
.sampleper = (nrf_qdec_sampleper_t)NRFX_QDEC_CONFIG_SAMPLEPER, \
|
||||
.psela = NRFX_QDEC_CONFIG_PIO_A, \
|
||||
.pselb = NRFX_QDEC_CONFIG_PIO_B, \
|
||||
.pselled = NRFX_QDEC_CONFIG_PIO_LED, \
|
||||
.ledpre = NRFX_QDEC_CONFIG_LEDPRE, \
|
||||
.ledpol = (nrf_qdec_ledpol_t)NRFX_QDEC_CONFIG_LEDPOL, \
|
||||
.interrupt_priority = NRFX_QDEC_CONFIG_IRQ_PRIORITY, \
|
||||
.dbfen = NRFX_QDEC_CONFIG_DBFEN, \
|
||||
.sample_inten = NRFX_QDEC_CONFIG_SAMPLE_INTEN \
|
||||
}
|
||||
#define NRFX_QDEC_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.reportper = (nrf_qdec_reportper_t)NRFX_QDEC_CONFIG_REPORTPER, \
|
||||
.sampleper = (nrf_qdec_sampleper_t)NRFX_QDEC_CONFIG_SAMPLEPER, \
|
||||
.psela = NRFX_QDEC_CONFIG_PIO_A, \
|
||||
.pselb = NRFX_QDEC_CONFIG_PIO_B, \
|
||||
.pselled = NRFX_QDEC_CONFIG_PIO_LED, \
|
||||
.ledpre = NRFX_QDEC_CONFIG_LEDPRE, \
|
||||
.ledpol = (nrf_qdec_ledpol_t)NRFX_QDEC_CONFIG_LEDPOL, \
|
||||
.dbfen = NRFX_QDEC_CONFIG_DBFEN, \
|
||||
.sample_inten = NRFX_QDEC_CONFIG_SAMPLE_INTEN, \
|
||||
.interrupt_priority = NRFX_QDEC_CONFIG_IRQ_PRIORITY, \
|
||||
}
|
||||
|
||||
/**@brief QDEC sample event data.*/
|
||||
/** @brief QDEC sample event data. */
|
||||
typedef struct
|
||||
{
|
||||
int8_t value; /**< Sample value. */
|
||||
} nrfx_qdec_sample_data_evt_t;
|
||||
|
||||
/**@brief QDEC report event data.*/
|
||||
/** @brief QDEC report event data. */
|
||||
typedef struct
|
||||
{
|
||||
int16_t acc; /**< Accumulated transitions. */
|
||||
uint16_t accdbl; /**< Accumulated double transitions. */
|
||||
uint16_t accdbl; /**< Accumulated double transitions. */
|
||||
} nrfx_qdec_report_data_evt_t;
|
||||
|
||||
/**@brief QDEC event handler structure. */
|
||||
/** @brief QDEC event handler structure. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_qdec_event_t type;
|
||||
nrf_qdec_event_t type; /**< Event type. */
|
||||
union
|
||||
{
|
||||
nrfx_qdec_sample_data_evt_t sample; /**< Sample event data. */
|
||||
nrfx_qdec_report_data_evt_t report; /**< Report event data. */
|
||||
} data;
|
||||
} data; /**< Union to store event data. */
|
||||
} nrfx_qdec_event_t;
|
||||
|
||||
/**@brief QDEC event handler.
|
||||
* @param[in] event QDEC event structure.
|
||||
/**
|
||||
* @brief QDEC event handler.
|
||||
*
|
||||
* @param[in] event QDEC event structure.
|
||||
*/
|
||||
typedef void (*nrfx_qdec_event_handler_t)(nrfx_qdec_event_t event);
|
||||
|
||||
/**@brief Function for initializing QDEC.
|
||||
/**
|
||||
* @brief Function for initializing QDEC.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If QDEC was already initialized.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The QDEC was already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_qdec_init(nrfx_qdec_config_t const * p_config,
|
||||
nrfx_qdec_event_handler_t event_handler);
|
||||
|
||||
/**@brief Function for uninitializing QDEC.
|
||||
* @note Function asserts if module is uninitialized.
|
||||
/**
|
||||
* @brief Function for uninitializing QDEC.
|
||||
*
|
||||
* @note Function asserts if module is uninitialized.
|
||||
*/
|
||||
void nrfx_qdec_uninit(void);
|
||||
|
||||
/**@brief Function for enabling QDEC.
|
||||
* @note Function asserts if module is uninitialized or enabled.
|
||||
/**
|
||||
* @brief Function for enabling QDEC.
|
||||
*
|
||||
* @note Function asserts if module is uninitialized or enabled.
|
||||
*/
|
||||
void nrfx_qdec_enable(void);
|
||||
|
||||
/**@brief Function for disabling QDEC.
|
||||
* @note Function asserts if module is uninitialized or disabled.
|
||||
/**
|
||||
* @brief Function for disabling QDEC.
|
||||
*
|
||||
* @note Function asserts if module is uninitialized or disabled.
|
||||
*/
|
||||
void nrfx_qdec_disable(void);
|
||||
|
||||
/**@brief Function for reading accumulated transitions QDEC.
|
||||
* @note Function asserts if module is not enabled.
|
||||
* @note Accumulators are cleared after reading.
|
||||
/**
|
||||
* @brief Function for reading accumulated transitions from the QDEC peripheral.
|
||||
*
|
||||
* @param[out] p_acc Pointer to store accumulated transitions.
|
||||
* @param[out] p_accdbl Pointer to store accumulated double transitions.
|
||||
* @note Function asserts if module is not enabled.
|
||||
* @note Accumulators are cleared after reading.
|
||||
*
|
||||
* @param[out] p_acc Pointer to store the accumulated transitions.
|
||||
* @param[out] p_accdbl Pointer to store the accumulated double transitions.
|
||||
*/
|
||||
void nrfx_qdec_accumulators_read(int16_t * p_acc, int16_t * p_accdbl);
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific QDEC task.
|
||||
* @brief Function for returning the address of the specified QDEC task.
|
||||
*
|
||||
* @param task QDEC task.
|
||||
* @param task QDEC task.
|
||||
*
|
||||
* @return Task address.
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_qdec_task_address_get(nrf_qdec_task_t task)
|
||||
{
|
||||
@@ -154,21 +165,22 @@ __STATIC_INLINE uint32_t nrfx_qdec_task_address_get(nrf_qdec_task_t task)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for returning the address of a specific QDEC event.
|
||||
* @brief Function for returning the address of the specified QDEC event.
|
||||
*
|
||||
* @param event QDEC event.
|
||||
* @param event QDEC event.
|
||||
*
|
||||
* @return Event address.
|
||||
* @return Event address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_qdec_event_address_get(nrf_qdec_event_t event)
|
||||
{
|
||||
return (uint32_t)nrf_qdec_event_address_get(event);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_qdec_irq_handler(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -46,21 +46,17 @@ extern "C" {
|
||||
* @brief Quad Serial Peripheral Interface (QSPI) peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief QSPI driver instance configuration structure.
|
||||
*/
|
||||
/** @brief QSPI driver instance configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t xip_offset; /**< Address offset into the external memory for Execute in Place operation. */
|
||||
nrf_qspi_pins_t pins; /**< Pins configuration structure. */
|
||||
nrf_qspi_pins_t pins; /**< Pin configuration structure. */
|
||||
nrf_qspi_prot_conf_t prot_if; /**< Protocol layer interface configuration structure. */
|
||||
nrf_qspi_phy_conf_t phy_if; /**< Physical layer interface configuration structure. */
|
||||
uint8_t irq_priority; /**< Interrupt priority. */
|
||||
} nrfx_qspi_config_t;
|
||||
|
||||
/**
|
||||
* @brief QSPI instance default configuration.
|
||||
*/
|
||||
/** @brief QSPI instance default configuration. */
|
||||
#define NRFX_QSPI_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.xip_offset = NRFX_QSPI_CONFIG_XIP_OFFSET, \
|
||||
@@ -72,7 +68,6 @@ typedef struct
|
||||
.io2_pin = NRFX_QSPI_PIN_IO2, \
|
||||
.io3_pin = NRFX_QSPI_PIN_IO3, \
|
||||
}, \
|
||||
.irq_priority = (uint8_t)NRFX_QSPI_CONFIG_IRQ_PRIORITY, \
|
||||
.prot_if = { \
|
||||
.readoc = (nrf_qspi_readoc_t)NRFX_QSPI_CONFIG_READOC, \
|
||||
.writeoc = (nrf_qspi_writeoc_t)NRFX_QSPI_CONFIG_WRITEOC, \
|
||||
@@ -80,16 +75,15 @@ typedef struct
|
||||
.dpmconfig = false, \
|
||||
}, \
|
||||
.phy_if = { \
|
||||
.sck_freq = (nrf_qspi_frequency_t)NRFX_QSPI_CONFIG_FREQUENCY, \
|
||||
.sck_delay = (uint8_t)NRFX_QSPI_CONFIG_SCK_DELAY, \
|
||||
.dpmen = false, \
|
||||
.spi_mode = (nrf_qspi_spi_mode_t)NRFX_QSPI_CONFIG_MODE, \
|
||||
.dpmen = false \
|
||||
.sck_freq = (nrf_qspi_frequency_t)NRFX_QSPI_CONFIG_FREQUENCY, \
|
||||
}, \
|
||||
.irq_priority = (uint8_t)NRFX_QSPI_CONFIG_IRQ_PRIORITY, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QSPI custom instruction helper with default configuration.
|
||||
*/
|
||||
/** @brief QSPI custom instruction helper with the default configuration. */
|
||||
#define NRFX_QSPI_DEFAULT_CINSTR(opc, len) \
|
||||
{ \
|
||||
.opcode = (opc), \
|
||||
@@ -109,16 +103,14 @@ typedef enum
|
||||
NRFX_QSPI_EVENT_DONE, /**< Transfer done. */
|
||||
} nrfx_qspi_evt_t;
|
||||
|
||||
/**
|
||||
* @brief QSPI driver event handler type.
|
||||
*/
|
||||
/** @brief QSPI driver event handler type. */
|
||||
typedef void (*nrfx_qspi_handler_t)(nrfx_qspi_evt_t event, void * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the QSPI driver instance.
|
||||
*
|
||||
* This function configures the peripheral and its interrupts and activates it. During the
|
||||
* activation process, the internal clocks are started and the QSPI peripheral tries to read
|
||||
* This function configures the peripheral and its interrupts, and activates it. During the
|
||||
* activation process, the internal clocks are started and the QSPI peripheral tries to read
|
||||
* the status byte to read the busy bit. Reading the status byte is done in a simple poll and wait
|
||||
* mechanism.
|
||||
* If the busy bit is 1, this indicates issues with the external memory device. As a result,
|
||||
@@ -129,32 +121,30 @@ typedef void (*nrfx_qspi_handler_t)(nrfx_qspi_evt_t event, void * p_context);
|
||||
* - Make sure that the memory device does not perform other operations like erasing or writing.
|
||||
* - Check if there is a short circuit.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] handler Event handler provided by the user. If NULL, transfers
|
||||
* will be performed in blocking mode.
|
||||
* @param[in] p_context Pointer to context. Use in interrupt handler.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] handler Event handler provided by the user. If NULL, transfers
|
||||
* will be performed in blocking mode.
|
||||
* @param[in] p_context Pointer to context. Use in the interrupt handler.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT If the peripheral cannot connect with external memory.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM If the pin configuration was incorrect.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT The peripheral cannot connect with external memory.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver was already initialized.
|
||||
* @retval NRFX_ERROR_INVALID_PARAM The pin configuration was incorrect.
|
||||
*/
|
||||
nrfx_err_t nrfx_qspi_init(nrfx_qspi_config_t const * p_config,
|
||||
nrfx_qspi_handler_t handler,
|
||||
void * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the QSPI driver instance.
|
||||
*/
|
||||
/** @brief Function for uninitializing the QSPI driver instance. */
|
||||
void nrfx_qspi_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Function for reading data from QSPI memory.
|
||||
* @brief Function for reading data from the QSPI memory.
|
||||
*
|
||||
* Write, read, and erase operations check memory device busy state before starting the operation.
|
||||
* If the memory is busy, the resulting action depends on the mode in which the read operation is used:
|
||||
* - blocking mode (without handler) - a delay occurs until the last operation still runs and
|
||||
* until operation data is still being read.
|
||||
* - blocking mode (without handler) - a delay occurs until the last operation runs and
|
||||
* until the operation data is being read.
|
||||
* - interrupt mode (with handler) - event emission occurs after the last operation
|
||||
* and reading of data are finished.
|
||||
*
|
||||
@@ -162,10 +152,11 @@ void nrfx_qspi_uninit(void);
|
||||
* @param[in] rx_buffer_length Size of the data to read.
|
||||
* @param[in] src_address Address in memory to read from.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful (blocking mode) or operation
|
||||
* @retval NRFX_SUCCESS The operation was successful (blocking mode) or operation
|
||||
* was commissioned (handler mode).
|
||||
* @retval NRFX_ERROR_BUSY If the driver currently handles another operation.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffer is not placed in the Data RAM region.
|
||||
* @retval NRFX_ERROR_BUSY The driver currently handles another operation.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR The provided buffer is not placed in the Data RAM region
|
||||
* or its address is not aligned to a 32-bit word.
|
||||
*/
|
||||
nrfx_err_t nrfx_qspi_read(void * p_rx_buffer,
|
||||
size_t rx_buffer_length,
|
||||
@@ -176,8 +167,8 @@ nrfx_err_t nrfx_qspi_read(void * p_rx_buffer,
|
||||
*
|
||||
* Write, read, and erase operations check memory device busy state before starting the operation.
|
||||
* If the memory is busy, the resulting action depends on the mode in which the write operation is used:
|
||||
* - blocking mode (without handler) - a delay occurs until the last operation still runs and
|
||||
* until operation data is still being sent.
|
||||
* - blocking mode (without handler) - a delay occurs until the last operation runs or
|
||||
* until the operation data is being sent.
|
||||
* - interrupt mode (with handler) - event emission occurs after the last operation
|
||||
* and sending of operation data are finished.
|
||||
* To manually control operation execution in the memory device, use @ref nrfx_qspi_mem_busy_check
|
||||
@@ -189,10 +180,11 @@ nrfx_err_t nrfx_qspi_read(void * p_rx_buffer,
|
||||
* @param[in] tx_buffer_length Size of the data to write.
|
||||
* @param[in] dst_address Address in memory to write to.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful (blocking mode) or operation
|
||||
* @retval NRFX_SUCCESS The operation was successful (blocking mode) or operation
|
||||
* was commissioned (handler mode).
|
||||
* @retval NRFX_ERROR_BUSY If the driver currently handles other operation.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffer is not placed in the Data RAM region.
|
||||
* @retval NRFX_ERROR_BUSY The driver currently handles other operation.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR The provided buffer is not placed in the Data RAM region
|
||||
* or its address is not aligned to a 32-bit word.
|
||||
*/
|
||||
nrfx_err_t nrfx_qspi_write(void const * p_tx_buffer,
|
||||
size_t tx_buffer_length,
|
||||
@@ -203,8 +195,8 @@ nrfx_err_t nrfx_qspi_write(void const * p_tx_buffer,
|
||||
*
|
||||
* Write, read, and erase operations check memory device busy state before starting the operation.
|
||||
* If the memory is busy, the resulting action depends on the mode in which the erase operation is used:
|
||||
* - blocking mode (without handler) - a delay occurs until the last operation still runs and
|
||||
* until operation data is still being sent.
|
||||
* - blocking mode (without handler) - a delay occurs until the last operation runs or
|
||||
* until the operation data is being sent.
|
||||
* - interrupt mode (with handler) - event emission occurs after the last operation
|
||||
* and sending of operation data are finished.
|
||||
* To manually control operation execution in the memory device, use @ref nrfx_qspi_mem_busy_check
|
||||
@@ -216,9 +208,10 @@ nrfx_err_t nrfx_qspi_write(void const * p_tx_buffer,
|
||||
* @param[in] start_address Memory address to start erasing. If chip erase is performed, address
|
||||
* field is ommited.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful (blocking mode) or operation
|
||||
* was commissioned (handler mode).
|
||||
* @retval NRFX_ERROR_BUSY If the driver currently handles another operation.
|
||||
* @retval NRFX_SUCCESS The operation was successful (blocking mode) or operation
|
||||
* was commissioned (handler mode).
|
||||
* @retval NRFX_ERROR_INVALID_ADDR The provided start address is not aligned to a 32-bit word.
|
||||
* @retval NRFX_ERROR_BUSY The driver currently handles another operation.
|
||||
*/
|
||||
nrfx_err_t nrfx_qspi_erase(nrf_qspi_erase_len_t length,
|
||||
uint32_t start_address);
|
||||
@@ -226,9 +219,9 @@ nrfx_err_t nrfx_qspi_erase(nrf_qspi_erase_len_t length,
|
||||
/**
|
||||
* @brief Function for starting an erase operation of the whole chip.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful (blocking mode) or operation
|
||||
* @retval NRFX_SUCCESS The operation was successful (blocking mode) or operation
|
||||
* was commissioned (handler mode).
|
||||
* @retval NRFX_ERROR_BUSY If the driver currently handles another operation.
|
||||
* @retval NRFX_ERROR_BUSY The driver currently handles another operation.
|
||||
*/
|
||||
nrfx_err_t nrfx_qspi_chip_erase(void);
|
||||
|
||||
@@ -236,8 +229,8 @@ nrfx_err_t nrfx_qspi_chip_erase(void);
|
||||
* @brief Function for getting the current driver status and status byte of memory device with
|
||||
* testing WIP (write in progress) bit.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the driver and memory are ready to handle a new operation.
|
||||
* @retval NRFX_ERROR_BUSY If the driver or memory currently handle another operation.
|
||||
* @retval NRFX_SUCCESS The driver and memory are ready to handle a new operation.
|
||||
* @retval NRFX_ERROR_BUSY The driver or memory currently handle another operation.
|
||||
*/
|
||||
nrfx_err_t nrfx_qspi_mem_busy_check(void);
|
||||
|
||||
@@ -252,13 +245,14 @@ nrfx_err_t nrfx_qspi_mem_busy_check(void);
|
||||
* @param[in] p_tx_buffer Pointer to the array with data to send. Can be NULL if only opcode is transmitted.
|
||||
* @param[out] p_rx_buffer Pointer to the array for data to receive. Can be NULL if there is nothing to receive.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT If the external memory is busy or there are connection issues.
|
||||
* @retval NRFX_ERROR_BUSY If the driver currently handles other operation.
|
||||
* @retval NRFX_SUCCESS The operation was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT The external memory is busy or there are connection issues.
|
||||
* @retval NRFX_ERROR_BUSY The driver currently handles other operation.
|
||||
*/
|
||||
nrfx_err_t nrfx_qspi_cinstr_xfer(nrf_qspi_cinstr_conf_t const * p_config,
|
||||
void const * p_tx_buffer,
|
||||
void * p_rx_buffer);
|
||||
|
||||
/**
|
||||
* @brief Function for sending operation code and data to the memory device with simpler configuration.
|
||||
*
|
||||
@@ -269,17 +263,56 @@ nrfx_err_t nrfx_qspi_cinstr_xfer(nrf_qspi_cinstr_conf_t const * p_config,
|
||||
* @param[in] length Length of the data to send and opcode. See @ref nrf_qspi_cinstr_len_t.
|
||||
* @param[in] p_tx_buffer Pointer to input data array.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the operation was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver currently handles another operation.
|
||||
* @retval NRFX_SUCCESS The operation was successful.
|
||||
* @retval NRFX_ERROR_BUSY The driver currently handles another operation.
|
||||
*/
|
||||
nrfx_err_t nrfx_qspi_cinstr_quick_send(uint8_t opcode,
|
||||
nrf_qspi_cinstr_len_t length,
|
||||
void const * p_tx_buffer);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the custom instruction long frame mode.
|
||||
*
|
||||
* The long frame mode is a mechanism that allows for arbitrary byte length custom instructions.
|
||||
* Use this function to initiate a custom transaction by sending custom instruction opcode.
|
||||
* To send and receive data, use @ref nrfx_qspi_lfm_xfer.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with custom instruction opcode and transfer
|
||||
* configuration. Transfer length must be set to @ref NRF_QSPI_CINSTR_LEN_1B.
|
||||
*
|
||||
* @retval NRFX_SUCCESS Operation was successful.
|
||||
* @retval NRFX_ERROR_BUSY Driver currently handles other operation.
|
||||
* @retval NRFX_ERROR_TIMEOUT External memory is busy or there are connection issues.
|
||||
*/
|
||||
nrfx_err_t nrfx_qspi_lfm_start(nrf_qspi_cinstr_conf_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Function for sending and receiving data in the custom instruction long frame mode.
|
||||
*
|
||||
* Both specified buffers must be at least @p transfer_length bytes in size.
|
||||
*
|
||||
* @param[in] p_tx_buffer Pointer to the array with data to send.
|
||||
* Can be NULL if there is nothing to send.
|
||||
* @param[out] p_rx_buffer Pointer to the array for receiving data.
|
||||
* Can be NULL if there is nothing to receive.
|
||||
* @param[in] transfer_length Number of bytes to send and receive.
|
||||
* @param[in] finalize True if custom instruction long frame mode is to be finalized
|
||||
* after this transfer.
|
||||
*
|
||||
* @retval NRFX_SUCCESS Operation was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT External memory is busy or there are connection issues.
|
||||
* Long frame mode becomes deactivated.
|
||||
*/
|
||||
nrfx_err_t nrfx_qspi_lfm_xfer(void const * p_tx_buffer,
|
||||
void * p_rx_buffer,
|
||||
size_t transfer_length,
|
||||
bool finalize);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_qspi_irq_handler(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -45,13 +45,11 @@ extern "C" {
|
||||
* @brief Random Number Generator (RNG) peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Struct for RNG configuration.
|
||||
*/
|
||||
/** @brief Struct for RNG configuration. */
|
||||
typedef struct
|
||||
{
|
||||
bool error_correction : 1; /**< Error correction flag. */
|
||||
uint8_t interrupt_priority; /**< interrupt priority */
|
||||
uint8_t interrupt_priority; /**< Interrupt priority. */
|
||||
} nrfx_rng_config_t;
|
||||
|
||||
/**
|
||||
@@ -63,53 +61,49 @@ typedef struct
|
||||
* { ...
|
||||
* @endcode
|
||||
*/
|
||||
#define NRFX_RNG_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.error_correction = NRFX_RNG_CONFIG_ERROR_CORRECTION, \
|
||||
.interrupt_priority = NRFX_RNG_CONFIG_IRQ_PRIORITY, \
|
||||
}
|
||||
#define NRFX_RNG_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.error_correction = NRFX_RNG_CONFIG_ERROR_CORRECTION, \
|
||||
.interrupt_priority = NRFX_RNG_CONFIG_IRQ_PRIORITY, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RNG driver event handler type.
|
||||
*/
|
||||
/** @brief RNG driver event handler type. */
|
||||
typedef void (* nrfx_rng_evt_handler_t)(uint8_t rng_data);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the nrfx_rng module.
|
||||
*
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] handler Event handler provided by the user. Must not be NULL.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] handler Event handler provided by the user. Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS Driver was successfully initialized.
|
||||
* @retval NRFX_ERROR_ALREADY_INITIALIZED Driver was already initialized.
|
||||
* @retval NRFX_SUCCESS Driver was successfully initialized.
|
||||
* @retval NRFX_ERROR_ALREADY_INITIALIZED Driver was already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_rng_init(nrfx_rng_config_t const * p_config, nrfx_rng_evt_handler_t handler);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the random value generation.
|
||||
* @brief Function for starting the generation of random values.
|
||||
*
|
||||
* Function enables interrupts in perihperal and start them.
|
||||
* New data should be handled by handler passed to the @ref nrfx_rng_init() function.
|
||||
*/
|
||||
void nrfx_rng_start(void);
|
||||
|
||||
/**
|
||||
* @brief Function for stoping the random value generation.
|
||||
* @brief Function for stopping the generation of random values.
|
||||
*
|
||||
* Function disables interrupts in perihperal and stop generation of new random values.
|
||||
* Function disables interrupts in peripheral and stops the generation of new random values.
|
||||
*/
|
||||
void nrfx_rng_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the nrfx_rng module.
|
||||
*/
|
||||
/** @brief Function for uninitializing the nrfx_rng module. */
|
||||
void nrfx_rng_uninit(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_rng_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -46,10 +46,10 @@ extern "C" {
|
||||
* @brief Real Timer Counter (RTC) peripheral driver.
|
||||
*/
|
||||
|
||||
/**@brief Macro to convert microseconds into ticks. */
|
||||
/** @brief Macro for converting microseconds into ticks. */
|
||||
#define NRFX_RTC_US_TO_TICKS(us,freq) (((us) * (freq)) / 1000000U)
|
||||
|
||||
/**@brief RTC driver interrupt types. */
|
||||
/** @brief RTC driver interrupt types. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_RTC_INT_COMPARE0 = 0, /**< Interrupt from COMPARE0 event. */
|
||||
@@ -60,16 +60,16 @@ typedef enum
|
||||
NRFX_RTC_INT_OVERFLOW = 5 /**< Interrupt from OVERFLOW event. */
|
||||
} nrfx_rtc_int_type_t;
|
||||
|
||||
/**@brief RTC driver instance structure. */
|
||||
/** @brief RTC driver instance structure. */
|
||||
typedef struct
|
||||
{
|
||||
NRF_RTC_Type * p_reg; /**< Pointer to instance register set. */
|
||||
IRQn_Type irq; /**< Instance IRQ ID. */
|
||||
uint8_t instance_id; /**< Instance index. */
|
||||
uint8_t instance_id; /**< Index of the driver instance. For internal use only. */
|
||||
uint8_t cc_channel_count; /**< Number of capture/compare channels. */
|
||||
} nrfx_rtc_t;
|
||||
|
||||
/**@brief Macro for creating RTC driver instance.*/
|
||||
/** @brief Macro for creating an RTC driver instance. */
|
||||
#define NRFX_RTC_INSTANCE(id) \
|
||||
{ \
|
||||
.p_reg = NRFX_CONCAT_2(NRF_RTC, id), \
|
||||
@@ -78,6 +78,7 @@ typedef struct
|
||||
.cc_channel_count = NRF_RTC_CC_CHANNEL_COUNT(id), \
|
||||
}
|
||||
|
||||
#ifndef __NRFX_DOXYGEN__
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_RTC0_ENABLED)
|
||||
NRFX_RTC0_INST_IDX,
|
||||
@@ -90,215 +91,223 @@ enum {
|
||||
#endif
|
||||
NRFX_RTC_ENABLED_COUNT
|
||||
};
|
||||
#endif
|
||||
|
||||
/**@brief RTC driver instance configuration structure. */
|
||||
/** @brief RTC driver instance configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint16_t prescaler; /**< Prescaler. */
|
||||
uint8_t interrupt_priority; /**< Interrupt priority. */
|
||||
uint8_t tick_latency; /**< Maximum length of interrupt handler in ticks (max 7.7 ms). */
|
||||
uint8_t tick_latency; /**< Maximum length of the interrupt handler in ticks (maximum 7.7 ms). */
|
||||
bool reliable; /**< Reliable mode flag. */
|
||||
} nrfx_rtc_config_t;
|
||||
|
||||
/**@brief RTC instance default configuration. */
|
||||
/** @brief RTC instance default configuration. */
|
||||
#define NRFX_RTC_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.prescaler = RTC_FREQ_TO_PRESCALER(NRFX_RTC_DEFAULT_CONFIG_FREQUENCY), \
|
||||
.interrupt_priority = NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY, \
|
||||
.reliable = NRFX_RTC_DEFAULT_CONFIG_RELIABLE, \
|
||||
.tick_latency = NRFX_RTC_US_TO_TICKS(NRFX_RTC_MAXIMUM_LATENCY_US, \
|
||||
NRFX_RTC_DEFAULT_CONFIG_FREQUENCY), \
|
||||
.reliable = NRFX_RTC_DEFAULT_CONFIG_RELIABLE, \
|
||||
}
|
||||
|
||||
/**@brief RTC driver instance handler type. */
|
||||
/** @brief RTC driver instance handler type. */
|
||||
typedef void (*nrfx_rtc_handler_t)(nrfx_rtc_int_type_t int_type);
|
||||
|
||||
/**@brief Function for initializing the RTC driver instance.
|
||||
/**
|
||||
* @brief Function for initializing the RTC driver instance.
|
||||
*
|
||||
* After initialization, the instance is in power off state.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
* @param[in] handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If successfully initialized.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the instance is already initialized.
|
||||
* @retval NRFX_SUCCESS Successfully initialized.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The instance is already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_rtc_init(nrfx_rtc_t const * const p_instance,
|
||||
nrfx_rtc_config_t const * p_config,
|
||||
nrfx_rtc_handler_t handler);
|
||||
|
||||
/**@brief Function for uninitializing the RTC driver instance.
|
||||
/**
|
||||
* @brief Function for uninitializing the RTC driver instance.
|
||||
*
|
||||
* After uninitialization, the instance is in idle state. The hardware should return to the state
|
||||
* before initialization. The function asserts if the instance is in idle state.
|
||||
* before initialization.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_rtc_uninit(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for enabling the RTC driver instance.
|
||||
/**
|
||||
* @brief Function for enabling the RTC driver instance.
|
||||
*
|
||||
* @note Function asserts if instance is enabled.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_rtc_enable(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for disabling the RTC driver instance.
|
||||
/**
|
||||
* @brief Function for disabling the RTC driver instance.
|
||||
*
|
||||
* @note Function asserts if instance is disabled.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_rtc_disable(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for setting a compare channel.
|
||||
/**
|
||||
* @brief Function for setting a compare channel.
|
||||
*
|
||||
* The function asserts if the instance is not initialized or if the channel parameter is
|
||||
* wrong. The function powers on the instance if the instance was in power off state.
|
||||
* The function powers on the instance if the instance was in power off state.
|
||||
*
|
||||
* The driver is not entering a critical section when configuring RTC, which means that it can be
|
||||
* preempted for a certain amount of time. When the driver was preempted and the value to be set
|
||||
* is short in time, there is a risk that the driver sets a compare value that is
|
||||
* behind. If RTCn_CONFIG_RELIABLE is 1 for the given instance, the Reliable mode handles that case.
|
||||
* However, to detect if the requested value is behind, this mode makes the following assumptions:
|
||||
* - The maximum preemption time in ticks (8 - bit value) is known and is less than 7.7 ms
|
||||
* (for prescaler = 0, RTC frequency 32 kHz).
|
||||
* - The requested absolute compare value is not bigger than (0x00FFFFFF) - tick_latency. It is
|
||||
* the user's responsibility to ensure that.
|
||||
* preempted for a certain amount of time. When the driver was preempted and the value to be set
|
||||
* is short in time, there is a risk that the driver sets a compare value that is
|
||||
* behind. In this case, if the reliable mode is enabled for the specified instance,
|
||||
* the risk is handled.
|
||||
* However, to detect if the requested value is behind, this mode makes the following assumptions:
|
||||
* - The maximum preemption time in ticks (8-bit value) is known and is less than 7.7 ms
|
||||
* (for prescaler = 0, RTC frequency 32 kHz).
|
||||
* - The requested absolute compare value is not bigger than (0x00FFFFFF)-tick_latency. It is
|
||||
* the user's responsibility to ensure this.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] channel One of the instance's channels.
|
||||
* @param[in] val Absolute value to be set in the compare register.
|
||||
* @param[in] enable_irq True to enable the interrupt. False to disable the interrupt.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] channel One of the channels of the instance.
|
||||
* @param[in] val Absolute value to be set in the compare register.
|
||||
* @param[in] enable_irq True to enable the interrupt. False to disable the interrupt.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT If the compare was not set because the request value is behind the current counter
|
||||
* value. This error can only be reported if RTCn_CONFIG_RELIABLE = 1.
|
||||
* @retval NRFX_SUCCESS The procedure is successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT The compare is not set because the request value is behind the
|
||||
* current counter value. This error can only be reported
|
||||
* if the reliable mode is enabled.
|
||||
*/
|
||||
nrfx_err_t nrfx_rtc_cc_set(nrfx_rtc_t const * const p_instance,
|
||||
uint32_t channel,
|
||||
uint32_t val,
|
||||
bool enable_irq);
|
||||
|
||||
/**@brief Function for disabling a channel.
|
||||
/**
|
||||
* @brief Function for disabling a channel.
|
||||
*
|
||||
* This function disables channel events and channel interrupts. The function asserts if the instance is not
|
||||
* initialized or if the channel parameter is wrong.
|
||||
* This function disables channel events and channel interrupts.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] channel One of the instance's channels.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] channel One of the channels of the instance.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT If an interrupt was pending on the requested channel.
|
||||
* @retval NRFX_SUCCESS The procedure is successful.
|
||||
* @retval NRFX_ERROR_TIMEOUT Interrupt is pending on the requested channel.
|
||||
*/
|
||||
nrfx_err_t nrfx_rtc_cc_disable(nrfx_rtc_t const * const p_instance, uint32_t channel);
|
||||
|
||||
/**@brief Function for enabling tick.
|
||||
/**
|
||||
* @brief Function for enabling the TICK event.
|
||||
*
|
||||
* This function enables the tick event and optionally the interrupt. The function asserts if the instance is not
|
||||
* powered on.
|
||||
* This function enables the tick event and optionally the interrupt.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] enable_irq True to enable the interrupt. False to disable the interrupt.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] enable_irq True to enable the interrupt. False to disable the interrupt.
|
||||
*/
|
||||
void nrfx_rtc_tick_enable(nrfx_rtc_t const * const p_instance, bool enable_irq);
|
||||
|
||||
/**@brief Function for disabling tick.
|
||||
/**
|
||||
* @brief Function for disabling the TICK event.
|
||||
*
|
||||
* This function disables the tick event and interrupt.
|
||||
* This function disables the TICK event and interrupt.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_rtc_tick_disable(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for enabling overflow.
|
||||
/**
|
||||
* @brief Function for enabling overflow.
|
||||
*
|
||||
* This function enables the overflow event and optionally the interrupt. The function asserts if the instance is
|
||||
* not powered on.
|
||||
* This function enables the overflow event and optionally the interrupt.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] enable_irq True to enable the interrupt. False to disable the interrupt.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] enable_irq True to enable the interrupt. False to disable the interrupt.
|
||||
*/
|
||||
void nrfx_rtc_overflow_enable(nrfx_rtc_t const * const p_instance, bool enable_irq);
|
||||
|
||||
/**@brief Function for disabling overflow.
|
||||
/**
|
||||
* @brief Function for disabling overflow.
|
||||
*
|
||||
* This function disables the overflow event and interrupt.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_rtc_overflow_disable(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for getting the maximum relative ticks value that can be set in the compare channel.
|
||||
/**
|
||||
* @brief Function for getting the maximum relative tick value that can be set in the compare channel.
|
||||
*
|
||||
* When a stack (for example SoftDevice) is used and it occupies high priority interrupts,
|
||||
* the application code can be interrupted at any moment for a certain period of time.
|
||||
* If Reliable mode is enabled, the provided maximum latency is taken into account
|
||||
* If the reliable mode is enabled, the provided maximum latency is taken into account
|
||||
* and the return value is smaller than the RTC counter resolution.
|
||||
* If Reliable mode is disabled, the return value equals the counter resolution.
|
||||
* If the reliable mode is disabled, the return value equals the counter resolution.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @retval ticks Maximum ticks value.
|
||||
* @return Maximum ticks value.
|
||||
*/
|
||||
uint32_t nrfx_rtc_max_ticks_get(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for disabling all instance interrupts.
|
||||
/**
|
||||
* @brief Function for disabling all instance interrupts.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_mask Pointer to the location where the mask is filled.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_mask Pointer to the location where the mask is filled.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_rtc_int_disable(nrfx_rtc_t const * const p_instance,
|
||||
uint32_t * p_mask);
|
||||
|
||||
/**@brief Function for enabling instance interrupts.
|
||||
/**
|
||||
* @brief Function for enabling instance interrupts.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] mask Mask of interrupts to enable.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] mask Mask of interrupts to enable.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_rtc_int_enable(nrfx_rtc_t const * const p_instance, uint32_t mask);
|
||||
|
||||
/**@brief Function for retrieving the current counter value.
|
||||
/**
|
||||
* @brief Function for retrieving the current counter value.
|
||||
*
|
||||
* This function asserts if the instance is not powered on or if p_val is NULL.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @retval value Counter value.
|
||||
* @return Counter value.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_rtc_counter_get(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for clearing the counter value.
|
||||
/**
|
||||
* @brief Function for clearing the counter value.
|
||||
*
|
||||
* This function asserts if the instance is not powered on.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
__STATIC_INLINE void nrfx_rtc_counter_clear(nrfx_rtc_t const * const p_instance);
|
||||
|
||||
/**@brief Function for returning a requested task address for the RTC driver instance.
|
||||
/**
|
||||
* @brief Function for returning a requested task address for the RTC driver instance.
|
||||
*
|
||||
* This function asserts if the output pointer is NULL. The task address can be used by the PPI module.
|
||||
* The task address can be used by the PPI module.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the instance.
|
||||
* @param[in] task One of the peripheral tasks.
|
||||
* @param[in] p_instance Pointer to the instance.
|
||||
* @param[in] task One of the peripheral tasks.
|
||||
*
|
||||
* @retval Address of task register.
|
||||
* @return Address of task register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_rtc_task_address_get(nrfx_rtc_t const * const p_instance,
|
||||
nrf_rtc_task_t task);
|
||||
|
||||
/**@brief Function for returning a requested event address for the RTC driver instance.
|
||||
/**
|
||||
* @brief Function for returning a requested event address for the RTC driver instance.
|
||||
*
|
||||
* This function asserts if the output pointer is NULL. The event address can be used by the PPI module.
|
||||
* The event address can be used by the PPI module.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] event One of the peripheral events.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] event One of the peripheral events.
|
||||
*
|
||||
* @retval Address of event register.
|
||||
* @return Address of event register.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrfx_rtc_event_address_get(nrfx_rtc_t const * const p_instance,
|
||||
nrf_rtc_event_t event);
|
||||
@@ -345,14 +354,14 @@ __STATIC_INLINE uint32_t nrfx_rtc_event_address_get(nrfx_rtc_t const * const p_i
|
||||
}
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_rtc_0_irq_handler(void);
|
||||
void nrfx_rtc_1_irq_handler(void);
|
||||
void nrfx_rtc_2_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -46,18 +46,12 @@ extern "C" {
|
||||
* @brief Successive Approximation Analog-to-Digital Converter (SAADC) peripheral driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Value that should be set as high limit to disable limit detection.
|
||||
*/
|
||||
/** @brief Value to be set as high limit to disable limit detection. */
|
||||
#define NRFX_SAADC_LIMITH_DISABLED (2047)
|
||||
/**
|
||||
* @brief Value that should be set as low limit to disable limit detection.
|
||||
*/
|
||||
/** @brief Value to be set as low limit to disable limit detection. */
|
||||
#define NRFX_SAADC_LIMITL_DISABLED (-2048)
|
||||
|
||||
/**
|
||||
* @brief Macro for setting @ref nrfx_saadc_config_t to default settings.
|
||||
*/
|
||||
/** @brief Macro for setting @ref nrfx_saadc_config_t to default settings. */
|
||||
#define NRFX_SAADC_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.resolution = (nrf_saadc_resolution_t)NRFX_SAADC_CONFIG_RESOLUTION, \
|
||||
@@ -68,7 +62,7 @@ extern "C" {
|
||||
|
||||
/**
|
||||
* @brief Macro for setting @ref nrf_saadc_channel_config_t to default settings
|
||||
* in single ended mode.
|
||||
* in single-ended mode.
|
||||
*
|
||||
* @param PIN_P Analog input.
|
||||
*/
|
||||
@@ -100,13 +94,12 @@ extern "C" {
|
||||
.reference = NRF_SAADC_REFERENCE_INTERNAL, \
|
||||
.acq_time = NRF_SAADC_ACQTIME_10US, \
|
||||
.mode = NRF_SAADC_MODE_DIFFERENTIAL, \
|
||||
.burst = NRF_SAADC_BURST_DISABLED, \
|
||||
.pin_p = (nrf_saadc_input_t)(PIN_P), \
|
||||
.pin_n = (nrf_saadc_input_t)(PIN_N) \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver configuration structure.
|
||||
*/
|
||||
/** @brief SAADC driver configuration structure. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_saadc_resolution_t resolution; ///< Resolution configuration.
|
||||
@@ -115,9 +108,7 @@ typedef struct
|
||||
bool low_power_mode; ///< Indicates if low power mode is active.
|
||||
} nrfx_saadc_config_t;
|
||||
|
||||
/**
|
||||
* @brief Driver event types.
|
||||
*/
|
||||
/** @brief SAADC driver event types. */
|
||||
typedef enum
|
||||
{
|
||||
NRFX_SAADC_EVT_DONE, ///< Event generated when the buffer is filled with samples.
|
||||
@@ -125,27 +116,21 @@ typedef enum
|
||||
NRFX_SAADC_EVT_CALIBRATEDONE ///< Event generated when the calibration is complete.
|
||||
} nrfx_saadc_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver done event data.
|
||||
*/
|
||||
/** @brief SAADC driver done event data. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_saadc_value_t * p_buffer; ///< Pointer to buffer with converted samples.
|
||||
uint16_t size; ///< Number of samples in the buffer.
|
||||
} nrfx_saadc_done_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver limit event data.
|
||||
*/
|
||||
/** @brief SAADC driver limit event data. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t channel; ///< Channel on which the limit was detected.
|
||||
nrf_saadc_limit_t limit_type; ///< Type of limit detected.
|
||||
} nrfx_saadc_limit_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Analog-to-digital converter driver event structure.
|
||||
*/
|
||||
/** @brief SAADC driver event structure. */
|
||||
typedef struct
|
||||
{
|
||||
nrfx_saadc_evt_type_t type; ///< Event type.
|
||||
@@ -153,15 +138,14 @@ typedef struct
|
||||
{
|
||||
nrfx_saadc_done_evt_t done; ///< Data for @ref NRFX_SAADC_EVT_DONE event.
|
||||
nrfx_saadc_limit_evt_t limit; ///< Data for @ref NRFX_SAADC_EVT_LIMIT event.
|
||||
} data;
|
||||
} data; ///< Union to store event data.
|
||||
} nrfx_saadc_evt_t;
|
||||
|
||||
/**
|
||||
* @brief ADC event handler.
|
||||
* @brief SAADC driver event handler.
|
||||
*
|
||||
* @param[in] p_event Pointer to an ADC event. The event structure is allocated on
|
||||
* the stack, so it is valid only within the context of
|
||||
* the event handler.
|
||||
* @param[in] p_event Pointer to an SAADC driver event. The event structure is allocated on
|
||||
* the stack, so it is valid only within the context of the event handler.
|
||||
*/
|
||||
typedef void (* nrfx_saadc_event_handler_t)(nrfx_saadc_evt_t const * p_event);
|
||||
|
||||
@@ -172,8 +156,8 @@ typedef void (* nrfx_saadc_event_handler_t)(nrfx_saadc_evt_t const * p_event);
|
||||
* @param[in] event_handler Event handler provided by the user.
|
||||
* Must not be NULL.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver is already initialized.
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver is already initialized.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_init(nrfx_saadc_config_t const * p_config,
|
||||
nrfx_saadc_event_handler_t event_handler);
|
||||
@@ -189,7 +173,7 @@ void nrfx_saadc_uninit(void);
|
||||
/**
|
||||
* @brief Function for getting the address of a SAMPLE SAADC task.
|
||||
*
|
||||
* @return Task address.
|
||||
* @return Task address.
|
||||
*/
|
||||
uint32_t nrfx_saadc_sample_task_get(void);
|
||||
|
||||
@@ -198,43 +182,47 @@ uint32_t nrfx_saadc_sample_task_get(void);
|
||||
*
|
||||
* This function configures and enables the channel.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the ADC was not initialized.
|
||||
* @retval NRFX_ERROR_NO_MEM If the specified channel was already allocated.
|
||||
* @param[in] channel Channel index.
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
*
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The SAADC was not initialized.
|
||||
* @retval NRFX_ERROR_NO_MEM The specified channel was already allocated.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_channel_init(uint8_t channel,
|
||||
nrf_saadc_channel_config_t const * const p_config);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing an SAADC channel.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If uninitialization was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the ADC is busy.
|
||||
* @param[in] channel Channel index.
|
||||
*
|
||||
* @retval NRFX_SUCCESS Uninitialization was successful.
|
||||
* @retval NRFX_ERROR_BUSY The SAADC is busy.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_channel_uninit(uint8_t channel);
|
||||
|
||||
/**
|
||||
* @brief Function for starting SAADC sampling.
|
||||
* @brief Function for starting the SAADC sampling.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If ADC sampling was triggered.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If ADC is in idle state.
|
||||
* @retval NRFX_SUCCESS The SAADC sampling was triggered.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The SAADC is in idle state.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_sample(void);
|
||||
|
||||
/**
|
||||
* @brief Blocking function for executing a single ADC conversion.
|
||||
* @brief Blocking function for executing a single SAADC conversion.
|
||||
*
|
||||
* This function selects the desired input, starts a single conversion,
|
||||
* waits for it to finish, and returns the result.
|
||||
*
|
||||
* The function will fail if ADC is busy.
|
||||
* The function fails if the SAADC is busy.
|
||||
*
|
||||
* @param[in] channel Channel.
|
||||
* @param[out] p_value Pointer to the location where the result should be placed.
|
||||
* @param[out] p_value Pointer to the location where the result is to be placed.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the ADC driver is busy.
|
||||
* @retval NRFX_SUCCESS The conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY The SAADC driver is busy.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_sample_convert(uint8_t channel, nrf_saadc_value_t * p_value);
|
||||
|
||||
@@ -242,45 +230,47 @@ nrfx_err_t nrfx_saadc_sample_convert(uint8_t channel, nrf_saadc_value_t * p_valu
|
||||
* @brief Function for issuing conversion of data to the buffer.
|
||||
*
|
||||
* This function is non-blocking. The application is notified about filling the buffer by the event
|
||||
* handler. Conversion will be done on all enabled channels. If the ADC is in idle state, the
|
||||
* function will set up Easy DMA for the conversion. The ADC will be ready for sampling and wait for
|
||||
* the SAMPLE task. It can be triggered manually by the @ref nrfx_saadc_sample function or by PPI
|
||||
* using the @ref NRF_SAADC_TASK_SAMPLE task. If one buffer is already set and the conversion is
|
||||
* ongoing, calling this function will result in queuing the given buffer. The driver will start
|
||||
* filling the issued buffer when the first one is completed. If the function is called again before
|
||||
* the first buffer is filled or calibration is in progress, it will return with error.
|
||||
* handler. Conversion will be done on all enabled channels. If the SAADC is in idle state, the
|
||||
* function will set up EasyDMA for the conversion. The SAADC will be ready for sampling and wait
|
||||
* for the SAMPLE task. It can be triggered manually by the @ref nrfx_saadc_sample function
|
||||
* or by PPI using the @ref NRF_SAADC_TASK_SAMPLE task. If one buffer is already set and the
|
||||
* conversion is ongoing, calling this function will result in queuing the given buffer.
|
||||
* The driver will start filling the issued buffer when the first one is completed.
|
||||
* If the function is called again before the first buffer is filled or calibration
|
||||
* is in progress, it will return with error.
|
||||
*
|
||||
* @param[in] buffer Result buffer.
|
||||
* @param[in] size Buffer size in words.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver already has two buffers set or calibration is in progress.
|
||||
* @retval NRFX_SUCCESS The conversion was successful.
|
||||
* @retval NRFX_ERROR_BUSY The driver already has two buffers set or the calibration is in progress.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_buffer_convert(nrf_saadc_value_t * buffer, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Function for triggering the ADC offset calibration.
|
||||
* @brief Function for triggering the SAADC offset calibration.
|
||||
*
|
||||
* This function is non-blocking. The application is notified about completion by the event handler.
|
||||
* Calibration will also trigger DONE and RESULTDONE events.
|
||||
*
|
||||
* The function will fail if ADC is busy or calibration is already in progress.
|
||||
* The function will fail if the SAADC is busy or calibration is already in progress.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If calibration was started successfully.
|
||||
* @retval NRFX_ERROR_BUSY If the ADC driver is busy.
|
||||
* @retval NRFX_SUCCESS The calibration was started successfully.
|
||||
* @retval NRFX_ERROR_BUSY The SAADC driver is busy.
|
||||
*/
|
||||
nrfx_err_t nrfx_saadc_calibrate_offset(void);
|
||||
|
||||
/**
|
||||
* @brief Function for retrieving the SAADC state.
|
||||
*
|
||||
* @retval true If the ADC is busy.
|
||||
* @retval false If the ADC is ready.
|
||||
* @retval true The SAADC is busy.
|
||||
* @retval false The SAADC is ready.
|
||||
*/
|
||||
bool nrfx_saadc_is_busy(void);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting ongoing and buffered conversions.
|
||||
* @brief Function for aborting the ongoing and buffered conversions.
|
||||
*
|
||||
* @note @ref NRFX_SAADC_EVT_DONE event will be generated if there is a conversion in progress.
|
||||
* Event will contain number of words in the sample buffer.
|
||||
*/
|
||||
@@ -303,12 +293,12 @@ void nrfx_saadc_abort(void);
|
||||
*/
|
||||
void nrfx_saadc_limits_set(uint8_t channel, int16_t limit_low, int16_t limit_high);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_saadc_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -43,16 +43,14 @@ extern "C" {
|
||||
* @defgroup nrfx_spi SPI driver
|
||||
* @{
|
||||
* @ingroup nrf_spi
|
||||
* @brief SPI peripheral driver.
|
||||
* @brief Serial Peripheral Interface master (SPI) driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SPI master driver instance data structure.
|
||||
*/
|
||||
/** @brief Data structure of the Serial Peripheral Interface master (SPI) driver instance. */
|
||||
typedef struct
|
||||
{
|
||||
NRF_SPI_Type * p_reg; ///< Pointer to a structure with SPI registers.
|
||||
uint8_t drv_inst_idx; ///< Driver instance index.
|
||||
uint8_t drv_inst_idx; ///< Index of the driver instance. For internal use only.
|
||||
} nrfx_spi_t;
|
||||
|
||||
enum {
|
||||
@@ -68,9 +66,7 @@ enum {
|
||||
NRFX_SPI_ENABLED_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Macro for creating an SPI master driver instance.
|
||||
*/
|
||||
/** @brief Macro for creating an instance of the SPI master driver. */
|
||||
#define NRFX_SPI_INSTANCE(id) \
|
||||
{ \
|
||||
.p_reg = NRFX_CONCAT_2(NRF_SPI, id), \
|
||||
@@ -84,9 +80,7 @@ enum {
|
||||
*/
|
||||
#define NRFX_SPI_PIN_NOT_USED 0xFF
|
||||
|
||||
/**
|
||||
* @brief SPI master driver instance configuration structure.
|
||||
*/
|
||||
/** @brief Configuration structure of the SPI master driver instance. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t sck_pin; ///< SCK pin number.
|
||||
@@ -100,10 +94,10 @@ typedef struct
|
||||
/**< Set to @ref NRFX_SPI_PIN_NOT_USED
|
||||
* if this signal is not needed. The driver
|
||||
* supports only active low for this signal.
|
||||
* If the signal should be active high,
|
||||
* If the signal must be active high,
|
||||
* it must be controlled externally. */
|
||||
uint8_t irq_priority; ///< Interrupt priority.
|
||||
uint8_t orc; ///< Over-run character.
|
||||
uint8_t orc; ///< Overrun character.
|
||||
/**< This character is used when all bytes from the TX buffer are sent,
|
||||
but the transfer continues due to RX. */
|
||||
nrf_spi_frequency_t frequency; ///< SPI frequency.
|
||||
@@ -111,9 +105,7 @@ typedef struct
|
||||
nrf_spi_bit_order_t bit_order; ///< SPI bit order.
|
||||
} nrfx_spi_config_t;
|
||||
|
||||
/**
|
||||
* @brief SPI master instance default configuration.
|
||||
*/
|
||||
/** @brief SPI master instance default configuration. */
|
||||
#define NRFX_SPI_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.sck_pin = NRFX_SPI_PIN_NOT_USED, \
|
||||
@@ -127,45 +119,37 @@ typedef struct
|
||||
.bit_order = NRF_SPI_BIT_ORDER_MSB_FIRST, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Single transfer descriptor structure.
|
||||
*/
|
||||
/** @brief Single transfer descriptor structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t const * p_tx_buffer; ///< Pointer to TX buffer.
|
||||
size_t tx_length; ///< TX buffer length.
|
||||
uint8_t * p_rx_buffer; ///< Pointer to RX buffer.
|
||||
size_t rx_length; ///< RX buffer length.
|
||||
} nrfx_spi_xfer_desc_t;
|
||||
}nrfx_spi_xfer_desc_t;
|
||||
|
||||
/**
|
||||
* @brief Macro for setting up single transfer descriptor.
|
||||
*
|
||||
* This macro is for internal use only.
|
||||
*/
|
||||
#define NRFX_SPI_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len) \
|
||||
{ \
|
||||
.p_tx_buffer = (uint8_t const *)(p_tx), \
|
||||
.tx_length = (tx_len), \
|
||||
.p_rx_buffer = (p_rx), \
|
||||
.rx_length = (rx_len), \
|
||||
}
|
||||
#define NRFX_SPI_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len) \
|
||||
{ \
|
||||
.p_tx_buffer = (uint8_t const *)(p_tx), \
|
||||
.tx_length = (tx_len), \
|
||||
.p_rx_buffer = (p_rx), \
|
||||
.rx_length = (rx_len), \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Macro for setting duplex TX RX transfer.
|
||||
*/
|
||||
/** @brief Macro for setting the duplex TX RX transfer. */
|
||||
#define NRFX_SPI_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length) \
|
||||
NRFX_SPI_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length)
|
||||
|
||||
/**
|
||||
* @brief Macro for setting TX transfer.
|
||||
*/
|
||||
/** @brief Macro for setting the TX transfer. */
|
||||
#define NRFX_SPI_XFER_TX(p_buf, length) \
|
||||
NRFX_SPI_SINGLE_XFER(p_buf, length, NULL, 0)
|
||||
|
||||
/**
|
||||
* @brief Macro for setting RX transfer.
|
||||
*/
|
||||
/** @brief Macro for setting the RX transfer. */
|
||||
#define NRFX_SPI_XFER_RX(p_buf, length) \
|
||||
NRFX_SPI_SINGLE_XFER(NULL, 0, p_buf, length)
|
||||
|
||||
@@ -178,15 +162,14 @@ typedef enum
|
||||
NRFX_SPI_EVENT_DONE, ///< Transfer done.
|
||||
} nrfx_spi_evt_type_t;
|
||||
|
||||
/** @brief SPI master event description with transmission details. */
|
||||
typedef struct
|
||||
{
|
||||
nrfx_spi_evt_type_t type; ///< Event type.
|
||||
nrfx_spi_xfer_desc_t xfer_desc; ///< Transfer details.
|
||||
} nrfx_spi_evt_t;
|
||||
|
||||
/**
|
||||
* @brief SPI master driver event handler type.
|
||||
*/
|
||||
/** @brief SPI master driver event handler type. */
|
||||
typedef void (* nrfx_spi_evt_handler_t)(nrfx_spi_evt_t const * p_event,
|
||||
void * p_context);
|
||||
|
||||
@@ -196,15 +179,14 @@ typedef void (* nrfx_spi_evt_handler_t)(nrfx_spi_evt_t const * p_event,
|
||||
* This function configures and enables the specified peripheral.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
*
|
||||
* @param handler Event handler provided by the user. If NULL, transfers
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] handler Event handler provided by the user. If NULL, transfers
|
||||
* will be performed in blocking mode.
|
||||
* @param p_context Context passed to event handler.
|
||||
* @param[in] p_context Context passed to the event handler.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
* @retval NRFX_ERROR_BUSY If some other peripheral with the same
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver was already initialized.
|
||||
* @retval NRFX_ERROR_BUSY Some other peripheral with the same
|
||||
* instance ID is already in use. This is
|
||||
* possible only if @ref nrfx_prs module
|
||||
* is enabled.
|
||||
@@ -219,7 +201,7 @@ nrfx_err_t nrfx_spi_init(nrfx_spi_t const * const p_instance,
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_spi_uninit(nrfx_spi_t const * const p_instance);
|
||||
void nrfx_spi_uninit(nrfx_spi_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the SPI data transfer.
|
||||
@@ -234,29 +216,29 @@ void nrfx_spi_uninit(nrfx_spi_t const * const p_instance);
|
||||
* @param flags Transfer options (0 for default settings).
|
||||
* Currently, no additional flags are available.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If the provided parameters are not supported.
|
||||
* @retval NRFX_SUCCESS The procedure is successful.
|
||||
* @retval NRFX_ERROR_BUSY The driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED The provided parameters are not supported.
|
||||
*/
|
||||
nrfx_err_t nrfx_spi_xfer(nrfx_spi_t const * const p_instance,
|
||||
nrfx_spi_xfer_desc_t const * p_xfer_desc,
|
||||
uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting ongoing transfer.
|
||||
* @brief Function for aborting the ongoing transfer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_spi_abort(nrfx_spi_t const * p_instance);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_spi_0_irq_handler(void);
|
||||
void nrfx_spi_1_irq_handler(void);
|
||||
void nrfx_spi_2_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -43,18 +43,17 @@ extern "C" {
|
||||
* @defgroup nrfx_spim SPIM driver
|
||||
* @{
|
||||
* @ingroup nrf_spim
|
||||
* @brief SPIM peripheral driver.
|
||||
* @brief Serial Peripheral Interface Master with EasyDMA (SPIM) driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SPIM master driver instance data structure.
|
||||
*/
|
||||
/** @brief Data structure of the Serial Peripheral Interface Master with EasyDMA (SPIM) driver instance. */
|
||||
typedef struct
|
||||
{
|
||||
NRF_SPIM_Type * p_reg; ///< Pointer to a structure with SPIM registers.
|
||||
uint8_t drv_inst_idx; ///< Driver instance index.
|
||||
uint8_t drv_inst_idx; ///< Index of the driver instance. For internal use only.
|
||||
} nrfx_spim_t;
|
||||
|
||||
#ifndef __NRFX_DOXYGEN__
|
||||
enum {
|
||||
#if NRFX_CHECK(NRFX_SPIM0_ENABLED)
|
||||
NRFX_SPIM0_INST_IDX,
|
||||
@@ -70,10 +69,9 @@ enum {
|
||||
#endif
|
||||
NRFX_SPIM_ENABLED_COUNT
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Macro for creating an SPIM master driver instance.
|
||||
*/
|
||||
/** @brief Macro for creating an instance of the SPIM driver. */
|
||||
#define NRFX_SPIM_INSTANCE(id) \
|
||||
{ \
|
||||
.p_reg = NRFX_CONCAT_2(NRF_SPIM, id), \
|
||||
@@ -87,9 +85,7 @@ enum {
|
||||
*/
|
||||
#define NRFX_SPIM_PIN_NOT_USED 0xFF
|
||||
|
||||
/**
|
||||
* @brief SPIM master driver instance configuration structure.
|
||||
*/
|
||||
/** @brief Configuration structure of the SPIM driver instance. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t sck_pin; ///< SCK pin number.
|
||||
@@ -104,44 +100,42 @@ typedef struct
|
||||
* if this signal is not needed. */
|
||||
bool ss_active_high; ///< Polarity of the Slave Select pin during transmission.
|
||||
uint8_t irq_priority; ///< Interrupt priority.
|
||||
uint8_t orc; ///< Over-run character.
|
||||
uint8_t orc; ///< Overrun character.
|
||||
/**< This character is used when all bytes from the TX buffer are sent,
|
||||
but the transfer continues due to RX. */
|
||||
nrf_spim_frequency_t frequency; ///< SPI frequency.
|
||||
nrf_spim_mode_t mode; ///< SPI mode.
|
||||
nrf_spim_bit_order_t bit_order; ///< SPI bit order.
|
||||
nrf_spim_frequency_t frequency; ///< SPIM frequency.
|
||||
nrf_spim_mode_t mode; ///< SPIM mode.
|
||||
nrf_spim_bit_order_t bit_order; ///< SPIM bit order.
|
||||
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED) || defined(__NRFX_DOXYGEN__)
|
||||
uint8_t dcx_pin; ///< D/CX pin number (optional).
|
||||
uint8_t rx_delay; ///< Sample delay for input serial data on MISO.
|
||||
/**< The value specifies the delay, in number of 64 MHz clock cycles
|
||||
* (15.625 ns), from the the sampling edge of SCK (leading edge for
|
||||
* CONFIG.CPHA = 0, trailing edge for CONFIG.CPHA = 1) until
|
||||
* the input serial data is sampled.*/
|
||||
* the input serial data is sampled. */
|
||||
bool use_hw_ss; ///< Indication to use software or hardware controlled Slave Select pin.
|
||||
uint8_t ss_duration; ///< Slave Select duration before and after transmission.
|
||||
/**< Minimum duration between the edge of CSN and the edge of SCK and minimum
|
||||
* duration of CSN must stay inactive between transactions.
|
||||
* The value is specified in number of 64 MHz clock cycles (15.625 ns).
|
||||
* Supported only for hardware controlled Slave Select.*/
|
||||
* Supported only for hardware-controlled Slave Select. */
|
||||
#endif
|
||||
} nrfx_spim_config_t;
|
||||
|
||||
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief SPIM master instance extended default configuration.
|
||||
* @brief Extended default configuration of the SPIM instance.
|
||||
*/
|
||||
#define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG \
|
||||
.dcx_pin = NRFX_SPIM_PIN_NOT_USED, \
|
||||
.rx_delay = 0x02, \
|
||||
.ss_duration = 0x02, \
|
||||
.use_hw_ss = false,
|
||||
.use_hw_ss = false, \
|
||||
.ss_duration = 0x02,
|
||||
#else
|
||||
#define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief SPIM master instance default configuration.
|
||||
*/
|
||||
/** @brief The default configuration of the SPIM master instance. */
|
||||
#define NRFX_SPIM_DEFAULT_CONFIG \
|
||||
{ \
|
||||
.sck_pin = NRFX_SPIM_PIN_NOT_USED, \
|
||||
@@ -157,15 +151,18 @@ typedef struct
|
||||
NRFX_SPIM_DEFAULT_EXTENDED_CONFIG \
|
||||
}
|
||||
|
||||
#define NRFX_SPIM_FLAG_TX_POSTINC (1UL << 0) /**< TX buffer address incremented after transfer. */
|
||||
#define NRFX_SPIM_FLAG_RX_POSTINC (1UL << 1) /**< RX buffer address incremented after transfer. */
|
||||
#define NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) /**< Interrupt after each transfer is suppressed, and the event handler is not called. */
|
||||
#define NRFX_SPIM_FLAG_HOLD_XFER (1UL << 3) /**< Set up the transfer but do not start it. */
|
||||
#define NRFX_SPIM_FLAG_REPEATED_XFER (1UL << 4) /**< Flag indicating that the transfer will be executed multiple times. */
|
||||
/** @brief Flag indicating that TX buffer address will be incremented after transfer. */
|
||||
#define NRFX_SPIM_FLAG_TX_POSTINC (1UL << 0)
|
||||
/** @brief Flag indicating that RX buffer address will be incremented after transfer. */
|
||||
#define NRFX_SPIM_FLAG_RX_POSTINC (1UL << 1)
|
||||
/** @brief Flag indicating that the interrupt after each transfer will be suppressed, and the event handler will not be called. */
|
||||
#define NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER (1UL << 2)
|
||||
/** @brief Flag indicating that the transfer will be set up, but not started. */
|
||||
#define NRFX_SPIM_FLAG_HOLD_XFER (1UL << 3)
|
||||
/** @brief Flag indicating that the transfer will be executed multiple times. */
|
||||
#define NRFX_SPIM_FLAG_REPEATED_XFER (1UL << 4)
|
||||
|
||||
/**
|
||||
* @brief Single transfer descriptor structure.
|
||||
*/
|
||||
/** @brief Single transfer descriptor structure. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t const * p_tx_buffer; ///< Pointer to TX buffer.
|
||||
@@ -179,29 +176,23 @@ typedef struct
|
||||
*
|
||||
* This macro is for internal use only.
|
||||
*/
|
||||
#define NRFX_SPIM_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len) \
|
||||
{ \
|
||||
.p_tx_buffer = (uint8_t const *)(p_tx), \
|
||||
.tx_length = (tx_len), \
|
||||
.p_rx_buffer = (p_rx), \
|
||||
.rx_length = (rx_len), \
|
||||
#define NRFX_SPIM_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len) \
|
||||
{ \
|
||||
.p_tx_buffer = (uint8_t const *)(p_tx), \
|
||||
.tx_length = (tx_len), \
|
||||
.p_rx_buffer = (p_rx), \
|
||||
.rx_length = (rx_len), \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Macro for setting duplex TX RX transfer.
|
||||
*/
|
||||
#define NRFX_SPIM_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length) \
|
||||
/** @brief Macro for setting the duplex TX RX transfer. */
|
||||
#define NRFX_SPIM_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length) \
|
||||
NRFX_SPIM_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length)
|
||||
|
||||
/**
|
||||
* @brief Macro for setting TX transfer.
|
||||
*/
|
||||
/** @brief Macro for setting the TX transfer. */
|
||||
#define NRFX_SPIM_XFER_TX(p_buf, length) \
|
||||
NRFX_SPIM_SINGLE_XFER(p_buf, length, NULL, 0)
|
||||
|
||||
/**
|
||||
* @brief Macro for setting RX transfer.
|
||||
*/
|
||||
/** @brief Macro for setting the RX transfer. */
|
||||
#define NRFX_SPIM_XFER_RX(p_buf, length) \
|
||||
NRFX_SPIM_SINGLE_XFER(NULL, 0, p_buf, length)
|
||||
|
||||
@@ -214,37 +205,35 @@ typedef enum
|
||||
NRFX_SPIM_EVENT_DONE, ///< Transfer done.
|
||||
} nrfx_spim_evt_type_t;
|
||||
|
||||
/** @brief SPIM event description with transmission details. */
|
||||
typedef struct
|
||||
{
|
||||
nrfx_spim_evt_type_t type; ///< Event type.
|
||||
nrfx_spim_xfer_desc_t xfer_desc; ///< Transfer details.
|
||||
} nrfx_spim_evt_t;
|
||||
|
||||
/**
|
||||
* @brief SPIM master driver event handler type.
|
||||
*/
|
||||
/** @brief SPIM driver event handler type. */
|
||||
typedef void (* nrfx_spim_evt_handler_t)(nrfx_spim_evt_t const * p_event,
|
||||
void * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the SPI master driver instance.
|
||||
* @brief Function for initializing the SPIM driver instance.
|
||||
*
|
||||
* This function configures and enables the specified peripheral.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_config Pointer to the structure with initial configuration.
|
||||
*
|
||||
* @param handler Event handler provided by the user. If NULL, transfers
|
||||
* @param[in] p_config Pointer to the structure with the initial configuration.
|
||||
* @param[in] handler Event handler provided by the user. If NULL, transfers
|
||||
* will be performed in blocking mode.
|
||||
* @param p_context Context passed to event handler.
|
||||
* @param[in] p_context Context passed to event handler.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE If the driver was already initialized.
|
||||
* @retval NRFX_ERROR_BUSY If some other peripheral with the same
|
||||
* @retval NRFX_SUCCESS Initialization was successful.
|
||||
* @retval NRFX_ERROR_INVALID_STATE The driver was already initialized.
|
||||
* @retval NRFX_ERROR_BUSY Some other peripheral with the same
|
||||
* instance ID is already in use. This is
|
||||
* possible only if @ref nrfx_prs module
|
||||
* is enabled.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If requested configuration is not supported
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED Requested configuration is not supported
|
||||
* by the SPIM instance.
|
||||
*/
|
||||
nrfx_err_t nrfx_spim_init(nrfx_spim_t const * const p_instance,
|
||||
@@ -253,30 +242,30 @@ nrfx_err_t nrfx_spim_init(nrfx_spim_t const * const p_instance,
|
||||
void * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the SPI master driver instance.
|
||||
* @brief Function for uninitializing the SPIM driver instance.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_spim_uninit(nrfx_spim_t const * const p_instance);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the SPI data transfer.
|
||||
* @brief Function for starting the SPIM data transfer.
|
||||
*
|
||||
* Additional options are provided using the @c flags parameter:
|
||||
*
|
||||
* - @ref NRFX_SPIM_FLAG_TX_POSTINC and @ref NRFX_SPIM_FLAG_RX_POSTINC<span></span>:
|
||||
* Post-incrementation of buffer addresses. Supported only by SPIM.
|
||||
* - @ref NRFX_SPIM_FLAG_HOLD_XFER<span></span>: Driver is not starting the transfer. Use this
|
||||
* flag if the transfer is triggered externally by PPI. Supported only by SPIM. Use
|
||||
* - @ref NRFX_SPIM_FLAG_TX_POSTINC and @ref NRFX_SPIM_FLAG_RX_POSTINC -
|
||||
* Post-incrementation of buffer addresses.
|
||||
* - @ref NRFX_SPIM_FLAG_HOLD_XFER - Driver is not starting the transfer. Use this
|
||||
* flag if the transfer is triggered externally by PPI. Use
|
||||
* @ref nrfx_spim_start_task_get to get the address of the start task.
|
||||
* - @ref NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER<span></span>: No user event handler after transfer
|
||||
* completion. This also means no interrupt at the end of the transfer. Supported only by SPIM.
|
||||
* - @ref NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER - No user event handler after transfer
|
||||
* completion. This also means no interrupt at the end of the transfer.
|
||||
* If @ref NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER is used, the driver does not set the instance into
|
||||
* busy state, so you must ensure that the next transfers are set up when SPIM is not active.
|
||||
* @ref nrfx_spim_end_event_get function can be used to detect end of transfer. Option can be used
|
||||
* together with @ref NRFX_SPIM_FLAG_REPEATED_XFER to prepare a sequence of SPI transfers
|
||||
* without interruptions.
|
||||
* - @ref NRFX_SPIM_FLAG_REPEATED_XFER<span></span>: Prepare for repeated transfers. You can set
|
||||
* - @ref NRFX_SPIM_FLAG_REPEATED_XFER - Prepare for repeated transfers. You can set
|
||||
* up a number of transfers that will be triggered externally (for example by PPI). An example is
|
||||
* a TXRX transfer with the options @ref NRFX_SPIM_FLAG_RX_POSTINC,
|
||||
* @ref NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER, and @ref NRFX_SPIM_FLAG_REPEATED_XFER. After the
|
||||
@@ -285,7 +274,7 @@ void nrfx_spim_uninit(nrfx_spim_t const * const p_instance);
|
||||
* @ref nrfx_spim_end_event_get can be used to get the address of the END event, which can be
|
||||
* used to count the number of transfers. If @ref NRFX_SPIM_FLAG_REPEATED_XFER is used,
|
||||
* the driver does not set the instance into busy state, so you must ensure that the next
|
||||
* transfers are set up when SPIM is not active. Supported only by SPIM.
|
||||
* transfers are set up when SPIM is not active.
|
||||
*
|
||||
* @note Peripherals using EasyDMA (including SPIM) require the transfer buffers
|
||||
* to be placed in the Data RAM region. If this condition is not met,
|
||||
@@ -295,10 +284,10 @@ void nrfx_spim_uninit(nrfx_spim_t const * const p_instance);
|
||||
* @param p_xfer_desc Pointer to the transfer descriptor.
|
||||
* @param flags Transfer options (0 for default settings).
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If the provided parameters are not supported.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data
|
||||
* @retval NRFX_SUCCESS The procedure is successful.
|
||||
* @retval NRFX_ERROR_BUSY The driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED The provided parameters are not supported.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR The provided buffers are not placed in the Data
|
||||
* RAM region.
|
||||
*/
|
||||
nrfx_err_t nrfx_spim_xfer(nrfx_spim_t const * const p_instance,
|
||||
@@ -307,7 +296,7 @@ nrfx_err_t nrfx_spim_xfer(nrfx_spim_t const * const p_instance,
|
||||
|
||||
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED) || defined(__NRFX_DOXYGEN__)
|
||||
/**
|
||||
* @brief Function for starting the SPI data transfer with DCX control.
|
||||
* @brief Function for starting the SPIM data transfer with DCX control.
|
||||
*
|
||||
* See @ref nrfx_spim_xfer for description of additional options of transfer
|
||||
* provided by the @c flags parameter.
|
||||
@@ -328,11 +317,11 @@ nrfx_err_t nrfx_spim_xfer(nrfx_spim_t const * const p_instance,
|
||||
* @c cmd_length parameter causes all transmitted bytes
|
||||
* to be marked as command bytes.
|
||||
*
|
||||
* @retval NRFX_SUCCESS If the procedure was successful.
|
||||
* @retval NRFX_ERROR_BUSY If the driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED If the provided parameters are not supported.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data
|
||||
* RAM region.
|
||||
* @retval NRFX_SUCCESS The procedure is successful.
|
||||
* @retval NRFX_ERROR_BUSY The driver is not ready for a new transfer.
|
||||
* @retval NRFX_ERROR_NOT_SUPPORTED The provided parameters are not supported.
|
||||
* @retval NRFX_ERROR_INVALID_ADDR The provided buffers are not placed in the Data
|
||||
* RAM region.
|
||||
*/
|
||||
nrfx_err_t nrfx_spim_xfer_dcx(nrfx_spim_t const * const p_instance,
|
||||
nrfx_spim_xfer_desc_t const * p_xfer_desc,
|
||||
@@ -343,12 +332,12 @@ nrfx_err_t nrfx_spim_xfer_dcx(nrfx_spim_t const * const p_instance,
|
||||
/**
|
||||
* @brief Function for returning the address of a SPIM start task.
|
||||
*
|
||||
* This function should be used if @ref nrfx_spim_xfer was called with the flag @ref NRFX_SPIM_FLAG_HOLD_XFER.
|
||||
* This function is to be used if @ref nrfx_spim_xfer was called with the flag @ref NRFX_SPIM_FLAG_HOLD_XFER.
|
||||
* In that case, the transfer is not started by the driver, but it must be started externally by PPI.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*
|
||||
* @return Start task address.
|
||||
* @return Start task address.
|
||||
*/
|
||||
uint32_t nrfx_spim_start_task_get(nrfx_spim_t const * p_instance);
|
||||
|
||||
@@ -367,10 +356,12 @@ uint32_t nrfx_spim_end_event_get(nrfx_spim_t const * p_instance);
|
||||
/**
|
||||
* @brief Function for aborting ongoing transfer.
|
||||
*
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
* @param[in] p_instance Pointer to the driver instance structure.
|
||||
*/
|
||||
void nrfx_spim_abort(nrfx_spim_t const * p_instance);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
void nrfx_spim_0_irq_handler(void);
|
||||
void nrfx_spim_1_irq_handler(void);
|
||||
@@ -378,8 +369,6 @@ void nrfx_spim_2_irq_handler(void);
|
||||
void nrfx_spim_3_irq_handler(void);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Loaded 100 of 293 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user