mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-28 16:14:20 +08:00
refactor(drivers/usb):replace rtt usb stack with cherryusb (#8799)
This commit is contained in:
+145
-26
File diff suppressed because it is too large
Load Diff
@@ -15,12 +15,7 @@ config PKGS_DIR
|
|||||||
option env="PKGS_ROOT"
|
option env="PKGS_ROOT"
|
||||||
default "packages"
|
default "packages"
|
||||||
|
|
||||||
config LIBRARIES_DIR
|
|
||||||
string
|
|
||||||
option env="LIBRARIES_DIR"
|
|
||||||
default "../libraries"
|
|
||||||
|
|
||||||
source "$RTT_DIR/Kconfig"
|
source "$RTT_DIR/Kconfig"
|
||||||
source "$PKGS_DIR/Kconfig"
|
source "$PKGS_DIR/Kconfig"
|
||||||
source "board/Kconfig"
|
source "board/Kconfig"
|
||||||
source "$LIBRARIES_DIR/Kconfig"
|
source "../libraries/Kconfig"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ config BSP_USING_BL61X
|
|||||||
select ARCH_RISCV32
|
select ARCH_RISCV32
|
||||||
select ARCH_RISCV_FPU_S
|
select ARCH_RISCV_FPU_S
|
||||||
select BSP_USING_ROMAPI
|
select BSP_USING_ROMAPI
|
||||||
|
select RT_USING_CACHE
|
||||||
default y
|
default y
|
||||||
|
|
||||||
config BSP_USING_ROMAPI
|
config BSP_USING_ROMAPI
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2024/04/23 sakumisu first version
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
/* low level init here, this has implemented in cherryusb */
|
||||||
|
|
||||||
|
/* low level deinit here, this has implemented in cherryusb */
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+261
-32
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2024/04/23 sakumisu first version
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
/* low level init here, this has implemented in cherryusb */
|
||||||
|
|
||||||
|
/* low level deinit here, this has implemented in cherryusb */
|
||||||
@@ -111,6 +111,12 @@ SECTIONS
|
|||||||
KEEP (*(.fini))
|
KEEP (*(.fini))
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
|
|
||||||
|
/* section information for usbh class */
|
||||||
|
. = ALIGN(8);
|
||||||
|
__usbh_class_info_start__ = .;
|
||||||
|
KEEP(*(.usbh_class_info))
|
||||||
|
__usbh_class_info_end__ = .;
|
||||||
|
|
||||||
/*********************************************
|
/*********************************************
|
||||||
*
|
*
|
||||||
* RT-Thread related sections - Start
|
* RT-Thread related sections - Start
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -68,7 +68,7 @@ if GetDepend(['BSP_USING_FEMC']):
|
|||||||
if GetDepend(['BSP_USING_PWM']):
|
if GetDepend(['BSP_USING_PWM']):
|
||||||
src += ['drivers/src/hpm_pwm_drv.c']
|
src += ['drivers/src/hpm_pwm_drv.c']
|
||||||
|
|
||||||
if GetDepend(['BSP_USING_USB']):
|
if GetDepend(['BSP_USING_USB']) or GetDepend(['RT_USING_CHERRYUSB']):
|
||||||
src += ['drivers/src/hpm_usb_drv.c']
|
src += ['drivers/src/hpm_usb_drv.c']
|
||||||
|
|
||||||
if GetDepend(['BSP_USING_I2S']):
|
if GetDepend(['BSP_USING_I2S']):
|
||||||
|
|||||||
@@ -44,4 +44,7 @@ if RT_USING_SMART
|
|||||||
source "$RTT_DIR/components/lwp/Kconfig"
|
source "$RTT_DIR/components/lwp/Kconfig"
|
||||||
source "$RTT_DIR/components/mm/Kconfig"
|
source "$RTT_DIR/components/mm/Kconfig"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
source "$RTT_DIR/components/legacy/Kconfig"
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|||||||
+1
-200
File diff suppressed because it is too large
Load Diff
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
# files format check exclude path, please follow the instructions below to modify;
|
||||||
|
# If you need to exclude an entire folder, add the folder path in dir_path;
|
||||||
|
# If you need to exclude a file, add the path to the file in file_path.
|
||||||
|
|
||||||
|
dir_path:
|
||||||
|
- cherryusb
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
# for module compiling
|
# RT-Thread building script for bridge
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from building import *
|
from building import *
|
||||||
|
|
||||||
cwd = GetCurrentDir()
|
cwd = GetCurrentDir()
|
||||||
objs = []
|
objs = []
|
||||||
list = os.listdir(cwd)
|
list = os.listdir(cwd)
|
||||||
|
|
||||||
for d in list:
|
for d in list:
|
||||||
path = os.path.join(cwd, d)
|
path = os.path.join(cwd, d)
|
||||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||||
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
objs = objs + SConscript(os.path.join(d, 'SConscript'))
|
||||||
|
|
||||||
Return('objs')
|
Return('objs')
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
# clang-format configuration file. Intended for clang-format >= 11.0
|
||||||
|
#
|
||||||
|
# For more information, see:
|
||||||
|
#
|
||||||
|
# https://clang.llvm.org/docs/ClangFormat.html
|
||||||
|
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||||
|
#
|
||||||
|
---
|
||||||
|
# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto
|
||||||
|
Language: Cpp
|
||||||
|
# BasedOnStyle: LLVM
|
||||||
|
# 访问说明符(public、private等)的偏移
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
# 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行)
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
# 连续赋值时,对齐所有等号
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
# 对齐位域
|
||||||
|
AlignConsecutiveBitFields: true
|
||||||
|
# 连续声明时,对齐所有声明的变量名
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
# 连续宏时,进行对齐
|
||||||
|
AlignConsecutiveMacros: true
|
||||||
|
# 左对齐逃脱换行(使用反斜杠换行)的反斜杠
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
# 水平对齐二元和三元表达式的操作数
|
||||||
|
AlignOperands: true
|
||||||
|
# 对齐连续的尾随的注释
|
||||||
|
AlignTrailingComments: true
|
||||||
|
# 允许函数声明的所有参数在放在下一行
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
# 允许短的块放在同一行
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
# 允许短的case标签放在同一行
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All
|
||||||
|
AllowShortFunctionsOnASingleLine: None
|
||||||
|
# 允许短的if语句保持在同一行
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
# 允许短的循环保持在同一行
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
# 总是在定义返回类型后换行(deprecated)
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数),
|
||||||
|
# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义)
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
# 总是在多行string字面量前换行
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
# 总是在template声明后换行
|
||||||
|
AlwaysBreakTemplateDeclarations: false
|
||||||
|
# false表示函数实参要么都在同一行,要么都各自一行
|
||||||
|
BinPackArguments: true
|
||||||
|
# false表示所有形参要么都在同一行,要么都各自一行
|
||||||
|
BinPackParameters: true
|
||||||
|
# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效
|
||||||
|
BraceWrapping:
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false # Unknown to clang-format-5.0
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true # Unknown to clang-format-4.0
|
||||||
|
SplitEmptyRecord: true # Unknown to clang-format-4.0
|
||||||
|
SplitEmptyNamespace: true # Unknown to clang-format-4.0
|
||||||
|
# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
|
||||||
|
# 在三元运算符前换行
|
||||||
|
BreakBeforeTernaryOperators: false
|
||||||
|
# 在构造函数的初始化列表的逗号前换行
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: false
|
||||||
|
# 每行字符的限制,0表示没有限制
|
||||||
|
ColumnLimit: 0
|
||||||
|
# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false # Unknown to clang-format-4.0
|
||||||
|
# 构造函数的初始化列表要么都在同一行,要么都各自一行
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
# 构造函数的初始化列表的缩进宽度
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
# 延续的行的缩进宽度
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
# 去除C++11的列表初始化的大括号{后和}前的空格
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
# 继承最常用的指针和引用的对齐方式
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
# 关闭格式化
|
||||||
|
DisableFormat: false
|
||||||
|
ForEachMacros:
|
||||||
|
- 'SHELL_EXPORT_CMD'
|
||||||
|
|
||||||
|
# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental)
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
# 缩进case标签
|
||||||
|
IndentCaseLabels: true
|
||||||
|
# 缩进宽度
|
||||||
|
IndentWidth: 4
|
||||||
|
# 函数返回类型换行时,缩进函数声明或函数定义的函数名
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
# 保留在块开始处的空行
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
# 开始一个块的宏的正则表达式
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
# 结束一个块的宏的正则表达式
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
# 连续空行的最大数量
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All
|
||||||
|
NamespaceIndentation: None
|
||||||
|
# 使用ObjC块时缩进宽度
|
||||||
|
ObjCBlockIndentWidth: 4
|
||||||
|
# 在ObjC的@property后添加一个空格
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
# 在ObjC的protocol列表前添加一个空格
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
# 在call(后对函数调用换行的penalty
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 30
|
||||||
|
# 在一个注释中引入换行的penalty
|
||||||
|
PenaltyBreakComment: 10
|
||||||
|
# 第一次在<<前换行的penalty
|
||||||
|
PenaltyBreakFirstLessLess: 0
|
||||||
|
# 在一个字符串字面量中引入换行的penalty
|
||||||
|
PenaltyBreakString: 10
|
||||||
|
# 对于每个在行字符数限制之外的字符的penalty
|
||||||
|
PenaltyExcessCharacter: 100
|
||||||
|
# 将函数的返回类型放到它自己的行的penalty
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
# 指针和引用的对齐: Left, Right, Middle
|
||||||
|
PointerAlignment: Right
|
||||||
|
# 允许重新排版注释
|
||||||
|
ReflowComments: false
|
||||||
|
# 允许排序#include
|
||||||
|
SortIncludes: false
|
||||||
|
# 在C风格类型转换后添加空格
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
# 在赋值运算符之前添加空格
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
# 开圆括号之前添加一个空格: Never, ControlStatements, Always
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
# 在空的圆括号中添加空格
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
# 在尾随的评论前添加的空格数(只适用于//)
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
# 在尖括号的<后和>前添加空格
|
||||||
|
SpacesInAngles: false
|
||||||
|
# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
# 在C风格类型转换的括号中添加空格
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
# 在圆括号的(后和)前添加空格
|
||||||
|
SpacesInParentheses: false
|
||||||
|
# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
# 标准: Cpp03, Cpp11, Auto
|
||||||
|
Standard: Cpp03
|
||||||
|
# tab宽度
|
||||||
|
TabWidth: 4
|
||||||
|
# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always
|
||||||
|
UseTab: Never
|
||||||
|
...
|
||||||
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
*.c linguist-language=C
|
||||||
|
*.C linguist-language=C
|
||||||
|
*.h linguist-language=C
|
||||||
|
*.H linguist-language=C
|
||||||
|
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
*.S text
|
||||||
|
*.asm text
|
||||||
|
*.c text
|
||||||
|
*.cc text
|
||||||
|
*.cpp text
|
||||||
|
*.cxx text
|
||||||
|
*.h text
|
||||||
|
*.htm text
|
||||||
|
*.html text
|
||||||
|
*.in text
|
||||||
|
*.ld text
|
||||||
|
*.m4 text
|
||||||
|
*.mak text
|
||||||
|
*.mk text
|
||||||
|
*.py text
|
||||||
|
*.rb text
|
||||||
|
*.s text
|
||||||
|
*.sct text
|
||||||
|
*.sh text
|
||||||
|
*.txt text
|
||||||
|
*.xml text
|
||||||
|
SConscript text
|
||||||
|
Makefile text
|
||||||
|
AUTHORS text
|
||||||
|
COPYING text
|
||||||
|
|
||||||
|
*.LZO -text
|
||||||
|
*.Opt -text
|
||||||
|
*.Uv2 -text
|
||||||
|
*.ewp -text
|
||||||
|
*.eww -text
|
||||||
|
*.vcproj -text
|
||||||
|
*.bat -text
|
||||||
|
*.dos -text
|
||||||
|
*.icf -text
|
||||||
|
*.inf -text
|
||||||
|
*.ini -text
|
||||||
|
*.sct -text
|
||||||
|
*.xsd -text
|
||||||
|
Jamfile -text
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
.vscode
|
||||||
|
**/Drivers/**
|
||||||
|
**/MDK-ARM/DebugConfig/**
|
||||||
|
**/MDK-ARM/RTE/**
|
||||||
|
**/obj/**
|
||||||
|
**/RET/**
|
||||||
|
**/Listings/**
|
||||||
|
**/Objects/**
|
||||||
|
*.map
|
||||||
|
*.o
|
||||||
|
*.d
|
||||||
|
*.htm
|
||||||
|
*.dep
|
||||||
|
*.lnp
|
||||||
|
*.iex
|
||||||
|
*.lst
|
||||||
|
*.axf
|
||||||
|
*.crf
|
||||||
|
*.hex
|
||||||
|
*.Bak
|
||||||
|
*.uvguix.*
|
||||||
|
*.scvd
|
||||||
|
*.usb.tmp
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# Read the Docs configuration file for Sphinx projects
|
||||||
|
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||||
|
|
||||||
|
# Required
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
# Set the OS, Python version and other tools you might need
|
||||||
|
build:
|
||||||
|
os: ubuntu-22.04
|
||||||
|
tools:
|
||||||
|
python: "3.11"
|
||||||
|
# You can also specify other tool versions:
|
||||||
|
# nodejs: "20"
|
||||||
|
# rust: "1.70"
|
||||||
|
# golang: "1.20"
|
||||||
|
|
||||||
|
# Build documentation in the "docs/" directory with Sphinx
|
||||||
|
sphinx:
|
||||||
|
configuration: docs/source/conf.py
|
||||||
|
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
|
||||||
|
# builder: "dirhtml"
|
||||||
|
# Fail on all warnings to avoid broken references
|
||||||
|
# fail_on_warning: true
|
||||||
|
|
||||||
|
# Optionally build your docs in additional formats such as PDF and ePub
|
||||||
|
# formats:
|
||||||
|
# - pdf
|
||||||
|
# - epub
|
||||||
|
|
||||||
|
# Optional but recommended, declare the Python requirements required
|
||||||
|
# to build your documentation
|
||||||
|
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
|
||||||
|
python:
|
||||||
|
install:
|
||||||
|
- requirements: docs/requirements.txt
|
||||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 38 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,196 @@
|
|||||||
|
# CherryUSB
|
||||||
|
|
||||||
|
[中文版](./README_zh.md)
|
||||||
|
|
||||||
|
CherryUSB is a tiny, beautiful and portable USB host and device stack for embedded system with USB IP.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Why choose
|
||||||
|
|
||||||
|
### Easy to study USB
|
||||||
|
|
||||||
|
In order to make it easier for users to learn USB basics, enumeration, driver loading and IP drivers, the code has been written with the following advantages:
|
||||||
|
|
||||||
|
- Lean code, simple logic, no complex C syntax
|
||||||
|
- Tree-based programming with cascading code
|
||||||
|
- Class-drivers and porting-drivers are templating and simplification
|
||||||
|
- Clear API classification (slave: initialisation, registration api, command callback api, data sending and receiving api; host: initialisation, lookup api, data sending and receiving api)
|
||||||
|
|
||||||
|
### Easy to use USB
|
||||||
|
|
||||||
|
In order to facilitate the use of the USB interface and to take into account the fact that users have learned about uart and dma, the following advantages have been designed for the data sending and receiving class of interface:
|
||||||
|
|
||||||
|
- Equivalent to using uart tx dma/uart rx dma
|
||||||
|
- There is no limit to the length of send and receive, the user does not need to care about the USB packetization process (the porting driver does the packetization process)
|
||||||
|
|
||||||
|
### Easy to bring out USB performance
|
||||||
|
|
||||||
|
Taking into account USB performance issues and trying to achieve the theoretical bandwidth of the USB hardware, the design of the data transceiver class interface has the following advantages:
|
||||||
|
|
||||||
|
- Porting drivers directly to registers, no abstraction layer encapsulation
|
||||||
|
- Memory zero copy
|
||||||
|
- If IP has DMA then uses DMA mode (DMA with hardware packetization)
|
||||||
|
- Unlimited length make it easier to interface with hardware DMA and take advantage of DMA
|
||||||
|
- Subcontracting function is handled in interrupt
|
||||||
|
|
||||||
|
## Directoy Structure
|
||||||
|
|
||||||
|
| Directory | Description |
|
||||||
|
|:-------------:|:---------------------------:|
|
||||||
|
|class | usb class driver |
|
||||||
|
|common | usb spec macros and utils |
|
||||||
|
|core | usb core implementation |
|
||||||
|
|demo | usb device and host demo |
|
||||||
|
|osal | os wrapper |
|
||||||
|
|platform | class support for other os |
|
||||||
|
|docs | doc for guiding |
|
||||||
|
|port | usb dcd and hcd porting |
|
||||||
|
|tools | tool url |
|
||||||
|
|
||||||
|
## Device Stack Overview
|
||||||
|
|
||||||
|
CherryUSB Device Stack provides a unified framework of functions for standard device requests, CLASS requests, VENDOR requests and custom special requests. The object-oriented and chained approach allows the user to quickly get started with composite devices without having to worry about the underlying logic. At the same time, a standard dcd porting interface has been standardised for adapting different USB IPs to achieve ip-oriented programming.
|
||||||
|
|
||||||
|
CherryUSB Device Stack has the following functions:
|
||||||
|
|
||||||
|
- Support USB2.0 full and high speed, USB3.0 super speed
|
||||||
|
- Support endpoint irq callback register by users, let users do whatever they wants in endpoint irq callback.
|
||||||
|
- Support Composite Device
|
||||||
|
- Support Communication Device Class (CDC_ACM, CDC_ECM)
|
||||||
|
- Support Human Interface Device (HID)
|
||||||
|
- Support Mass Storage Class (MSC)
|
||||||
|
- Support USB VIDEO CLASS (UVC1.0、UVC1.5)
|
||||||
|
- Support USB AUDIO CLASS (UAC1.0、UAC2.0)
|
||||||
|
- Support Device Firmware Upgrade CLASS (DFU)
|
||||||
|
- Support USB MIDI CLASS (MIDI)
|
||||||
|
- Support Remote NDIS (RNDIS)
|
||||||
|
- Support WINUSB1.0、WINUSB2.0(with BOS)
|
||||||
|
- Support Vendor class
|
||||||
|
- Support multi device with the same USB IP
|
||||||
|
|
||||||
|
CherryUSB Device Stack resource usage (GCC 10.2 with -O2):
|
||||||
|
|
||||||
|
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||||
|
|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:|
|
||||||
|
|usbd_core.c | 3516 | 256(default) + 320 | 0 | 0 |
|
||||||
|
|usbd_cdc.c | 392 | 0 | 0 | 0 |
|
||||||
|
|usbd_msc.c | 2839 | 128 + 512(default) | 16 | 0 |
|
||||||
|
|usbd_hid.c | 364 | 0 | 0 | 0 |
|
||||||
|
|usbd_audio.c | 1455 | 0 | 0 | 0 |
|
||||||
|
|usbd_video.c | 2494 | 0 | 84 | 0 |
|
||||||
|
|usbd_rndis.c | 2109 | 3340 | 76 | 0 |
|
||||||
|
|
||||||
|
## Host Stack Overview
|
||||||
|
|
||||||
|
The CherryUSB Host Stack has a standard enumeration implementation for devices mounted on roothubs and external hubs, and a standard interface for different Classes to indicate what the Class driver needs to do after enumeration and after disconnection. A standard hcd porting interface has also been standardised for adapting different USB IPs for IP-oriented programming. Finally, the host stack is managed using os, and provides osal to make a adaptation for different os.
|
||||||
|
|
||||||
|
CherryUSB Host Stack has the following functions:
|
||||||
|
|
||||||
|
- Automatic loading of supported Class drivers
|
||||||
|
- Support blocking transfers and asynchronous transfers
|
||||||
|
- Support Composite Device
|
||||||
|
- Multi-level HUB support, expandable up to 7 levels(Testing hub with 10 ports works well,only support dwc2 and ehci now)
|
||||||
|
- Support Communication Device Class (CDC_ACM, CDC_ECM)
|
||||||
|
- Support Human Interface Device (HID)
|
||||||
|
- Support Mass Storage Class (MSC)
|
||||||
|
- Support USB Video CLASS (commercial charge)
|
||||||
|
- Support USB Audio CLASS (commercial charge)
|
||||||
|
- Support Remote NDIS (RNDIS)
|
||||||
|
- Support USB Bluetooth class (support nimble and zephyr bluetooth stack, support **CLASS:0xE0** or vendor class like cdc acm)
|
||||||
|
- Support Vendor class
|
||||||
|
- Support USB modeswitch
|
||||||
|
- Support multi host with the same USB IP
|
||||||
|
|
||||||
|
The CherryUSB Host stack also provides the lsusb function, which allows you to view information about all mounted devices, including those on external hubs, with the help of a shell plugin.
|
||||||
|
|
||||||
|
CherryUSB Host Stack resource usage (GCC 10.2 with -O2):
|
||||||
|
|
||||||
|
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||||
|
|:-------------:|:--------------:|:-------------------------------:|:---------------------------:|:------------:|
|
||||||
|
|usbh_core.c | ~7700 | 512 + 8 * (1+x) *n | 28 | 0 |
|
||||||
|
|usbh_hub.c | ~5600 | 32 + 4* (1+x) | 12 + sizeof(struct usbh_hub) * (1+x) | 0 |
|
||||||
|
|usbh_cdc_acm.c | ~1200 | 7 | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|
||||||
|
|usbh_msc.c | ~2500 | 32 | 4 + sizeof(struct usbh_msc) * x | 0 |
|
||||||
|
|usbh_hid.c | ~1000 | 128 | 4 + sizeof(struct usbh_hid) * x | 0 |
|
||||||
|
|usbh_video.c | ~3700 | 128 | 4 + sizeof(struct usbh_video) * x | 0 |
|
||||||
|
|usbh_audio.c | ~3100 | 128 | 4 + sizeof(struct usbh_audio) * x | 0 |
|
||||||
|
|usbh_rndis.c | ~3900 | 4096 + 2 * 2048 | sizeof(struct usbh_rndis) * 1 | 0 |
|
||||||
|
|usbh_cdc_ecm.c | ~2500 | 2 * 1514 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|
||||||
|
|usbh_bluetooth.c | ~2300 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
|
||||||
|
|
||||||
|
Among them, `sizeof(struct usbh_hub)` and `sizeof(struct usbh_hubport)` are affected by the following macros:
|
||||||
|
|
||||||
|
```
|
||||||
|
#define CONFIG_USBHOST_MAX_EXTHUBS 1
|
||||||
|
#define CONFIG_USBHOST_MAX_EHPORTS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_INTERFACES 8
|
||||||
|
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
|
||||||
|
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
|
||||||
|
```
|
||||||
|
|
||||||
|
x is affected by the following macros:
|
||||||
|
|
||||||
|
```
|
||||||
|
#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_HID_CLASS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_MSC_CLASS 2
|
||||||
|
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
|
||||||
|
#define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
|
||||||
|
```
|
||||||
|
|
||||||
|
## USB IP Support
|
||||||
|
|
||||||
|
Only standard and commercial USB IP are listed.
|
||||||
|
|
||||||
|
| IP | device | host | Support status |
|
||||||
|
|:----------------:|:----------:|:--------:|:--------------:|
|
||||||
|
| OHCI(intel) | none | OHCI | × |
|
||||||
|
| EHCI(intel) | none | EHCI | √ |
|
||||||
|
| XHCI(intel) | none | XHCI | √ |
|
||||||
|
| UHCI(intel) | none | UHCI | × |
|
||||||
|
| DWC2(synopsys) | DWC2 | DWC2 | √ |
|
||||||
|
| MUSB(mentor) | MUSB | MUSB | √ |
|
||||||
|
| FOTG210(faraday)| FOTG210 | EHCI | √ |
|
||||||
|
| CDNS2(cadence) | CDNS2 | CDNS2 | √ |
|
||||||
|
| CDNS3(cadence) | CDNS3 | XHCI | × |
|
||||||
|
| DWC3(synopsys) | DWC3 | XHCI | × |
|
||||||
|
|
||||||
|
## Documentation Tutorial
|
||||||
|
|
||||||
|
Quickly start, USB basic concepts, API manual, Class basic concepts and examples, see [CherryUSB Documentation Tutorial](https://cherryusb.readthedocs.io/)
|
||||||
|
|
||||||
|
## Video Tutorial
|
||||||
|
|
||||||
|
USB basic concepts and how the CherryUSB Device stack is implemented, see [CherryUSB Device Stack Tutorial](https://www.bilibili.com/video/BV1Ef4y1t73d).
|
||||||
|
|
||||||
|
## Graphical Config Tool
|
||||||
|
|
||||||
|
[chryusb_configurator](https://github.com/Egahp/chryusb_configurator) is written in **electron + vite2 + ts** framework,currently used to automate the generation of descriptor arrays, with additional functionality to be added later.
|
||||||
|
|
||||||
|
## Demo Repo
|
||||||
|
|
||||||
|
| Manufacturer | CHIP or Series | USB IP| Repo Url | Support version | Support status |
|
||||||
|
|:--------------------:|:------------------:|:-----:|:--------:|:------------------:|:-------------:|
|
||||||
|
|Bouffalolab | BL702/BL616/BL808 | bouffalolab/ehci|[bouffalo_sdk](https://github.com/CherryUSB/bouffalo_sdk)|<= latest | Long-term |
|
||||||
|
|ST | STM32F1x | fsdev |[stm32_repo](https://github.com/CherryUSB/cherryusb_stm32)|<= latest | Long-term |
|
||||||
|
|ST | STM32F4/STM32H7 | dwc2 |[stm32_repo](https://github.com/CherryUSB/cherryusb_stm32)|<= latest | Long-term |
|
||||||
|
|HPMicro | HPM6750 | hpm/ehci |[hpm_sdk](https://github.com/CherryUSB/hpm_sdk)|<= latest | Long-term |
|
||||||
|
|Essemi | ES32F36xx | musb |[es32f369_repo](https://github.com/CherryUSB/cherryusb_es32)|<= latest | Long-term |
|
||||||
|
|Phytium | e2000 | pusb2/xhci |[phytium_repo](https://gitee.com/phytium_embedded/phytium-free-rtos-sdk)|v0.10.2 | Long-term |
|
||||||
|
|artinchip | d12x/d13x/d21x | aic/ehci/ohci |[luban-lite](https://gitee.com/artinchip/luban-lite)|<= latest | Long-term |
|
||||||
|
|Espressif | esp32s2/esp32s3 | dwc2 |[esp32_repo](https://github.com/CherryUSB/cherryusb_esp32)|<= latest | the same with ST |
|
||||||
|
|AllwinnerTech | F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s](https://github.com/CherryUSB/cherryusb_rtt_f1c100s)|<= latest | the same with Essemi |
|
||||||
|
|WCH | CH32V307/ch58x | ch32_usbfs/ch32_usbhs/ch58x |[wch_repo](https://github.com/CherryUSB/cherryusb_wch)|<= v0.10.2 | TBD |
|
||||||
|
|Nordicsemi | Nrf52840 | nrf5x |[nrf5x_repo](https://github.com/CherryUSB/cherryusb_nrf5x)|<= v0.10.2 | No more updated |
|
||||||
|
|Raspberry pi | rp2040 | rp2040 |[pico-examples](https://github.com/CherryUSB/pico-examples)|<= v0.10.2 | No more updated |
|
||||||
|
|
||||||
|
## Contact
|
||||||
|
|
||||||
|
CherryUSB discord: https://discord.com/invite/wFfvrSAey8.
|
||||||
|
|
||||||
|
## Company Support
|
||||||
|
|
||||||
|
Thanks to the following companies for their support (in no particular order).
|
||||||
|
|
||||||
|
<img src="docs/assets/bouffalolab.jpg" width="100" height="100"/> <img src="docs/assets/hpmicro.jpg" width="100" height="100" /> <img src="docs/assets/eastsoft.jpg" width="100" height="100" /> <img src="docs/assets/rtthread.jpg" width="100" height="100" /> <img src="docs/assets/sophgo.jpg" width="100" height="100" /> <img src="docs/assets/phytium.jpg" width="100" height="100" /> <img src="docs/assets/thead.jpg" width="100" height="100" /> <img src="docs/assets/nuvoton.jpg" width="100" height="100" /> <img src="docs/assets/artinchip.jpg" width="100" height="100" />
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
# CherryUSB
|
||||||
|
|
||||||
|
[English](./README.md)
|
||||||
|
|
||||||
|
CherryUSB 是一个小而美的、可移植性高的、用于嵌入式系统(带 USB IP)的 USB 主从协议栈。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 为什么选择
|
||||||
|
|
||||||
|
### 易于学习 USB
|
||||||
|
|
||||||
|
为了方便用户学习 USB 基本知识、枚举、驱动加载、IP 驱动,因此,编写的代码具备以下优点:
|
||||||
|
|
||||||
|
- 代码精简,逻辑简单,无复杂 C 语言语法
|
||||||
|
- 树状化编程,代码层层递进
|
||||||
|
- Class 驱动和 porting 驱动模板化、精简化
|
||||||
|
- API 分类清晰(从机:初始化、注册类、命令回调类、数据收发类;主机:初始化、查找类、数据收发类)
|
||||||
|
|
||||||
|
### 易于使用 USB
|
||||||
|
|
||||||
|
为了方便用户使用 USB 接口,考虑到用户学习过 uart 和 dma,因此,设计的数据收发类接口具备以下优点:
|
||||||
|
|
||||||
|
- 等价于使用 uart tx dma/uart rx dma
|
||||||
|
- 收发长度没有限制,用户不需要关心 USB 分包过程(porting 驱动做分包过程)
|
||||||
|
|
||||||
|
### 易于发挥 USB 性能
|
||||||
|
|
||||||
|
考虑到 USB 性能问题,尽量达到 USB 硬件理论带宽,因此,设计的数据收发类接口具备以下优点:
|
||||||
|
|
||||||
|
- Porting 驱动直接对接寄存器,无抽象层封装
|
||||||
|
- Memory zero copy
|
||||||
|
- IP 如果带 DMA 则使用 DMA 模式(DMA 带硬件分包功能)
|
||||||
|
- 长度无限制,方便对接硬件 DMA 并且发挥 DMA 的优势
|
||||||
|
- 分包功能在中断中处理
|
||||||
|
|
||||||
|
## 目录结构
|
||||||
|
|
||||||
|
| 目录名 | 描述 |
|
||||||
|
|:-------------:|:-------------------------------:|
|
||||||
|
|class | usb class 类主从驱动 |
|
||||||
|
|common | usb spec 定义、常用宏、标准接口定义 |
|
||||||
|
|core | usb 主从协议栈核心实现 |
|
||||||
|
|demo | 主从 class demo |
|
||||||
|
|docs | 文档 |
|
||||||
|
|osal | os 封装层 |
|
||||||
|
|platform | 其他 os 全家桶适配 |
|
||||||
|
|port | usb 主从需要实现的 porting 接口 |
|
||||||
|
|tools | 工具链接 |
|
||||||
|
|
||||||
|
## Device 协议栈简介
|
||||||
|
|
||||||
|
CherryUSB Device 协议栈对标准设备请求、CLASS 请求、VENDOR 请求以及 custom 特殊请求规范了一套统一的函数框架,采用面向对象和链表的方式,能够使得用户快速上手复合设备,不用管底层的逻辑。同时,规范了一套标准的 dcd porting 接口,用于适配不同的 USB IP,达到面向 ip 编程。
|
||||||
|
|
||||||
|
CherryUSB Device 协议栈当前实现以下功能:
|
||||||
|
|
||||||
|
- 支持 USB2.0 全速和高速设备,USB3.0 超速设备
|
||||||
|
- 支持端点中断注册功能,porting 给用户自己处理中断里的数据
|
||||||
|
- 支持复合设备
|
||||||
|
- 支持 Communication Device Class (CDC_ACM, CDC_ECM)
|
||||||
|
- 支持 Human Interface Device (HID)
|
||||||
|
- 支持 Mass Storage Class (MSC)
|
||||||
|
- 支持 USB VIDEO CLASS (UVC1.0、UVC1.5)
|
||||||
|
- 支持 USB AUDIO CLASS (UAC1.0、UAC2.0)
|
||||||
|
- 支持 Device Firmware Upgrade CLASS (DFU)
|
||||||
|
- 支持 USB MIDI CLASS (MIDI)
|
||||||
|
- 支持 Remote NDIS (RNDIS)
|
||||||
|
- 支持 WINUSB1.0、WINUSB2.0(带 BOS )
|
||||||
|
- 支持 Vendor 类 class
|
||||||
|
- 支持相同 USB IP 的多从机
|
||||||
|
|
||||||
|
CherryUSB Device 协议栈资源占用说明(GCC 10.2 with -O2):
|
||||||
|
|
||||||
|
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||||
|
|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:|
|
||||||
|
|usbd_core.c | 3516 | 256(default) + 320 | 0 | 0 |
|
||||||
|
|usbd_cdc.c | 392 | 0 | 0 | 0 |
|
||||||
|
|usbd_msc.c | 2839 | 128 + 512(default) | 16 | 0 |
|
||||||
|
|usbd_hid.c | 364 | 0 | 0 | 0 |
|
||||||
|
|usbd_audio.c | 1455 | 0 | 0 | 0 |
|
||||||
|
|usbd_video.c | 2494 | 0 | 84 | 0 |
|
||||||
|
|usbd_rndis.c | 2109 | 3340 | 76 | 0 |
|
||||||
|
|
||||||
|
## Host 协议栈简介
|
||||||
|
|
||||||
|
CherryUSB Host 协议栈对挂载在 roothub、外部 hub 上的设备规范了一套标准的枚举实现,对不同的 Class 类也规范了一套标准接口,用来指示在枚举后和断开连接后该 Class 驱动需要做的事情。同时,规范了一套标准的 hcd porting 接口,用于适配不同的 USB IP,达到面向 IP 编程。最后,协议栈使用 OS 管理,并提供了 osal 用来适配不同的 os。
|
||||||
|
|
||||||
|
CherryUSB Host 协议栈当前实现以下功能:
|
||||||
|
|
||||||
|
- 自动加载支持的Class 驱动
|
||||||
|
- 支持阻塞式传输和异步传输
|
||||||
|
- 支持复合设备
|
||||||
|
- 支持多级 HUB,最高可拓展到 7 级(目前测试 1拖 10 没有问题,当前仅支持 dwc2 和 ehci)
|
||||||
|
- 支持 Communication Device Class (CDC_ACM, CDC_ECM)
|
||||||
|
- 支持 Human Interface Device (HID)
|
||||||
|
- 支持 Mass Storage Class (MSC)
|
||||||
|
- Support USB Video CLASS(商业收费)
|
||||||
|
- Support USB Audio CLASS(商业收费)
|
||||||
|
- 支持 Remote NDIS (RNDIS)
|
||||||
|
- 支持 USB Bluetooth (支持 nimble and zephyr bluetooth 协议栈,支持 **CLASS: 0xE0** 或者厂家自定义类,类似于 cdc acm 功能)
|
||||||
|
- 支持 Vendor 类 class
|
||||||
|
- 支持 USB modeswitch
|
||||||
|
- 支持相同 USB IP 的多主机
|
||||||
|
|
||||||
|
同时,CherryUSB Host 协议栈还提供了 lsusb 的功能,借助 shell 插件可以查看所有挂载设备的信息,包括外部 hub 上的设备的信息。
|
||||||
|
|
||||||
|
CherryUSB Host 协议栈资源占用说明(GCC 10.2 with -O2):
|
||||||
|
|
||||||
|
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||||
|
|:-------------:|:--------------:|:-------------------------------:|:---------------------------:|:------------:|
|
||||||
|
|usbh_core.c | ~7700 | 512 + 8 * (1+x) *n | 28 | 0 |
|
||||||
|
|usbh_hub.c | ~5600 | 32 + 4* (1+x) | 12 + sizeof(struct usbh_hub) * (1+x) | 0 |
|
||||||
|
|usbh_cdc_acm.c | ~1200 | 7 | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|
||||||
|
|usbh_msc.c | ~2500 | 32 | 4 + sizeof(struct usbh_msc) * x | 0 |
|
||||||
|
|usbh_hid.c | ~1000 | 128 | 4 + sizeof(struct usbh_hid) * x | 0 |
|
||||||
|
|usbh_video.c | ~3700 | 128 | 4 + sizeof(struct usbh_video) * x | 0 |
|
||||||
|
|usbh_audio.c | ~3100 | 128 | 4 + sizeof(struct usbh_audio) * x | 0 |
|
||||||
|
|usbh_rndis.c | ~3900 | 4096 + 2 * 2048 | sizeof(struct usbh_rndis) * 1 | 0 |
|
||||||
|
|usbh_cdc_ecm.c | ~2500 | 2 * 1514 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|
||||||
|
|usbh_bluetooth.c | ~2300 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
|
||||||
|
|
||||||
|
其中,`sizeof(struct usbh_hub)` 和 `sizeof(struct usbh_hubport)` 受以下宏影响:
|
||||||
|
|
||||||
|
```
|
||||||
|
#define CONFIG_USBHOST_MAX_EXTHUBS 1
|
||||||
|
#define CONFIG_USBHOST_MAX_EHPORTS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_INTERFACES 8
|
||||||
|
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
|
||||||
|
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
|
||||||
|
```
|
||||||
|
|
||||||
|
x 受以下宏影响:
|
||||||
|
|
||||||
|
```
|
||||||
|
#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_HID_CLASS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_MSC_CLASS 2
|
||||||
|
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
|
||||||
|
#define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
|
||||||
|
```
|
||||||
|
|
||||||
|
## USB IP 支持情况
|
||||||
|
|
||||||
|
仅列举标准 USB IP 和商业性 USB IP
|
||||||
|
|
||||||
|
| IP | device | host | Support status |
|
||||||
|
|:----------------:|:----------:|:--------:|:--------------:|
|
||||||
|
| OHCI(intel) | none | OHCI | × |
|
||||||
|
| EHCI(intel) | none | EHCI | √ |
|
||||||
|
| XHCI(intel) | none | XHCI | √ |
|
||||||
|
| UHCI(intel) | none | UHCI | × |
|
||||||
|
| DWC2(synopsys) | DWC2 | DWC2 | √ |
|
||||||
|
| MUSB(mentor) | MUSB | MUSB | √ |
|
||||||
|
| FOTG210(faraday)| FOTG210 | EHCI | √ |
|
||||||
|
| CDNS2(cadence) | CDNS2 | CDNS2 | √ |
|
||||||
|
| CDNS3(cadence) | CDNS3 | XHCI | × |
|
||||||
|
| DWC3(synopsys) | DWC3 | XHCI | × |
|
||||||
|
|
||||||
|
## 文档教程
|
||||||
|
|
||||||
|
CherryUSB 快速入门、USB 基本概念,API 手册,Class 基本概念和例程,参考 [CherryUSB Documentation Tutorial](https://cherryusb.readthedocs.io/)
|
||||||
|
|
||||||
|
## 视频教程
|
||||||
|
|
||||||
|
- USB 基本知识点与 CherryUSB Device 协议栈是如何编写的(使用v0.4.1 版本),参考 https://www.bilibili.com/video/BV1Ef4y1t73d.
|
||||||
|
- CherryUSB 腾讯会议(使用v1.1.0 版本),参考 https://www.bilibili.com/video/BV16x421y7mM.
|
||||||
|
|
||||||
|
## 图形化界面配置工具
|
||||||
|
|
||||||
|
[chryusb_configurator](https://github.com/Egahp/chryusb_configurator) 采用 **electron + vite2 + ts** 框架编写,当前用于自动化生成描述符数组,后续会增加其他功能。
|
||||||
|
|
||||||
|
## 示例仓库
|
||||||
|
|
||||||
|
| Manufacturer | CHIP or Series | USB IP| Repo Url | Support version | Support status |
|
||||||
|
|:--------------------:|:------------------:|:-----:|:--------:|:------------------:|:-------------:|
|
||||||
|
|Bouffalolab | BL702/BL616/BL808 | bouffalolab/ehci|[bouffalo_sdk](https://github.com/CherryUSB/bouffalo_sdk)|<= latest | Long-term |
|
||||||
|
|ST | STM32F1x | fsdev |[stm32_repo](https://github.com/CherryUSB/cherryusb_stm32)|<= latest | Long-term |
|
||||||
|
|ST | STM32F4/STM32H7 | dwc2 |[stm32_repo](https://github.com/CherryUSB/cherryusb_stm32)|<= latest | Long-term |
|
||||||
|
|HPMicro | HPM6750 | hpm/ehci |[hpm_sdk](https://github.com/CherryUSB/hpm_sdk)|<= latest | Long-term |
|
||||||
|
|Essemi | ES32F36xx | musb |[es32f369_repo](https://github.com/CherryUSB/cherryusb_es32)|<= latest | Long-term |
|
||||||
|
|Phytium | e2000 | pusb2/xhci |[phytium_repo](https://gitee.com/phytium_embedded/phytium-free-rtos-sdk)|v0.10.2 | Long-term |
|
||||||
|
|artinchip | d12x/d13x/d21x | aic/ehci/ohci |[luban-lite](https://gitee.com/artinchip/luban-lite)|<= latest | Long-term |
|
||||||
|
|Espressif | esp32s2/esp32s3 | dwc2 |[esp32_repo](https://github.com/CherryUSB/cherryusb_esp32)|<= latest | the same with ST |
|
||||||
|
|AllwinnerTech | F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s](https://github.com/CherryUSB/cherryusb_rtt_f1c100s)|<= latest | the same with Essemi |
|
||||||
|
|WCH | CH32V307/ch58x | ch32_usbfs/ch32_usbhs/ch58x |[wch_repo](https://github.com/CherryUSB/cherryusb_wch)|<= v0.10.2 | TBD |
|
||||||
|
|Nordicsemi | Nrf52840 | nrf5x |[nrf5x_repo](https://github.com/CherryUSB/cherryusb_nrf5x)|<= v0.10.2 | No more updated |
|
||||||
|
|Raspberry pi | rp2040 | rp2040 |[pico-examples](https://github.com/CherryUSB/pico-examples)|<= v0.10.2 | No more updated |
|
||||||
|
|
||||||
|
## Contact
|
||||||
|
|
||||||
|
CherryUSB QQ 群:642693751
|
||||||
|
CherryUSB 微信群:与我联系后邀请加入
|
||||||
|
|
||||||
|
## 支持企业
|
||||||
|
|
||||||
|
感谢以下企业支持(顺序不分先后)。
|
||||||
|
|
||||||
|
<img src="docs/assets/bouffalolab.jpg" width="100" height="100"/> <img src="docs/assets/hpmicro.jpg" width="100" height="100" /> <img src="docs/assets/eastsoft.jpg" width="100" height="100" /> <img src="docs/assets/rtthread.jpg" width="100" height="100" /> <img src="docs/assets/sophgo.jpg" width="100" height="100" /> <img src="docs/assets/phytium.jpg" width="100" height="100" /> <img src="docs/assets/thead.jpg" width="100" height="100" /> <img src="docs/assets/nuvoton.jpg" width="100" height="100" /> <img src="docs/assets/artinchip.jpg" width="100" height="100" />
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
|||||||
|
VERSION_MAJOR = 1
|
||||||
|
VERSION_MINOR = 3
|
||||||
|
PATCHLEVEL = 0
|
||||||
|
VERSION_TWEAK = 0
|
||||||
|
EXTRAVERSION = 0
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBD_AUDIO_H
|
||||||
|
#define USBD_AUDIO_H
|
||||||
|
|
||||||
|
#include "usb_audio.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct audio_entity_info {
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bEntityId;
|
||||||
|
uint8_t ep;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Init audio interface driver */
|
||||||
|
struct usbd_interface *usbd_audio_init_intf(uint8_t busid, struct usbd_interface *intf,
|
||||||
|
uint16_t uac_version,
|
||||||
|
struct audio_entity_info *table,
|
||||||
|
uint8_t num);
|
||||||
|
|
||||||
|
void usbd_audio_open(uint8_t busid, uint8_t intf);
|
||||||
|
void usbd_audio_close(uint8_t busid, uint8_t intf);
|
||||||
|
|
||||||
|
void usbd_audio_set_volume(uint8_t busid, uint8_t ep, uint8_t ch, int volume);
|
||||||
|
int usbd_audio_get_volume(uint8_t busid, uint8_t ep, uint8_t ch);
|
||||||
|
void usbd_audio_set_mute(uint8_t busid, uint8_t ep, uint8_t ch, bool mute);
|
||||||
|
bool usbd_audio_get_mute(uint8_t busid, uint8_t ep, uint8_t ch);
|
||||||
|
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq);
|
||||||
|
uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep);
|
||||||
|
|
||||||
|
void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBD_AUDIO_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_AUDIO_H
|
||||||
|
#define USBH_AUDIO_H
|
||||||
|
|
||||||
|
#include "usb_audio.h"
|
||||||
|
|
||||||
|
struct usbh_audio_format_type {
|
||||||
|
uint8_t channels;
|
||||||
|
uint8_t format_type;
|
||||||
|
uint8_t bitresolution;
|
||||||
|
uint8_t sampfreq_num;
|
||||||
|
uint32_t sampfreq[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bSourceID in feature_unit = input_terminal_id
|
||||||
|
* bSourceID in output_terminal = feature_unit_id
|
||||||
|
* terminal_link_id = input_terminal_id or output_terminal_id (if input_terminal_type or output_terminal_type is 0x0101)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct usbh_audio_module {
|
||||||
|
const char *name;
|
||||||
|
uint8_t data_intf;
|
||||||
|
uint8_t input_terminal_id;
|
||||||
|
uint16_t input_terminal_type;
|
||||||
|
uint16_t input_channel_config;
|
||||||
|
uint8_t output_terminal_id;
|
||||||
|
uint16_t output_terminal_type;
|
||||||
|
uint8_t feature_unit_id;
|
||||||
|
uint8_t feature_unit_controlsize;
|
||||||
|
uint8_t feature_unit_controls[8];
|
||||||
|
uint8_t terminal_link_id;
|
||||||
|
struct usbh_audio_format_type altsetting[CONFIG_USBHOST_MAX_INTF_ALTSETTINGS];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usbh_audio {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *isoin; /* ISO IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *isoout; /* ISO OUT endpoint */
|
||||||
|
|
||||||
|
uint8_t ctrl_intf; /* interface number */
|
||||||
|
uint8_t minor;
|
||||||
|
uint16_t isoin_mps;
|
||||||
|
uint16_t isoout_mps;
|
||||||
|
bool is_opened;
|
||||||
|
uint16_t bcdADC;
|
||||||
|
uint8_t bInCollection;
|
||||||
|
uint8_t num_of_intf_altsettings;
|
||||||
|
struct usbh_audio_module module[2];
|
||||||
|
uint8_t module_num;
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t samp_freq);
|
||||||
|
int usbh_audio_close(struct usbh_audio *audio_class, const char *name);
|
||||||
|
int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint8_t ch, uint8_t volume);
|
||||||
|
int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_t ch, bool mute);
|
||||||
|
|
||||||
|
void usbh_audio_run(struct usbh_audio *audio_class);
|
||||||
|
void usbh_audio_stop(struct usbh_audio *audio_class);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_AUDIO_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_cdc.h"
|
||||||
|
|
||||||
|
const char *stop_name[] = { "1", "1.5", "2" };
|
||||||
|
const char *parity_name[] = { "N", "O", "E", "M", "S" };
|
||||||
|
|
||||||
|
static int cdc_acm_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||||
|
{
|
||||||
|
USB_LOG_DBG("CDC Class request: "
|
||||||
|
"bRequest 0x%02x\r\n",
|
||||||
|
setup->bRequest);
|
||||||
|
|
||||||
|
struct cdc_line_coding line_coding;
|
||||||
|
bool dtr, rts;
|
||||||
|
uint8_t intf_num = LO_BYTE(setup->wIndex);
|
||||||
|
|
||||||
|
switch (setup->bRequest) {
|
||||||
|
case CDC_REQUEST_SET_LINE_CODING:
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
/* Line Coding Structure */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Offset | Field | Size | Value | Description */
|
||||||
|
/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/
|
||||||
|
/* 4 | bCharFormat | 1 | Number | Stop bits */
|
||||||
|
/* 0 - 1 Stop bit */
|
||||||
|
/* 1 - 1.5 Stop bits */
|
||||||
|
/* 2 - 2 Stop bits */
|
||||||
|
/* 5 | bParityType | 1 | Number | Parity */
|
||||||
|
/* 0 - None */
|
||||||
|
/* 1 - Odd */
|
||||||
|
/* 2 - Even */
|
||||||
|
/* 3 - Mark */
|
||||||
|
/* 4 - Space */
|
||||||
|
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
|
||||||
|
/*******************************************************************************/
|
||||||
|
memcpy(&line_coding, *data, setup->wLength);
|
||||||
|
USB_LOG_DBG("Set intf:%d linecoding <%d %d %s %s>\r\n",
|
||||||
|
intf_num,
|
||||||
|
line_coding.dwDTERate,
|
||||||
|
line_coding.bDataBits,
|
||||||
|
parity_name[line_coding.bParityType],
|
||||||
|
stop_name[line_coding.bCharFormat]);
|
||||||
|
|
||||||
|
usbd_cdc_acm_set_line_coding(busid, intf_num, &line_coding);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_REQUEST_SET_CONTROL_LINE_STATE:
|
||||||
|
dtr = (setup->wValue & 0x0001);
|
||||||
|
rts = (setup->wValue & 0x0002);
|
||||||
|
USB_LOG_DBG("Set intf:%d DTR 0x%x,RTS 0x%x\r\n",
|
||||||
|
intf_num,
|
||||||
|
dtr,
|
||||||
|
rts);
|
||||||
|
usbd_cdc_acm_set_dtr(busid, intf_num, dtr);
|
||||||
|
usbd_cdc_acm_set_rts(busid, intf_num, rts);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_REQUEST_GET_LINE_CODING:
|
||||||
|
usbd_cdc_acm_get_line_coding(busid, intf_num, &line_coding);
|
||||||
|
memcpy(*data, &line_coding, 7);
|
||||||
|
*len = 7;
|
||||||
|
USB_LOG_DBG("Get intf:%d linecoding %d %d %d %d\r\n",
|
||||||
|
intf_num,
|
||||||
|
line_coding.dwDTERate,
|
||||||
|
line_coding.bCharFormat,
|
||||||
|
line_coding.bParityType,
|
||||||
|
line_coding.bDataBits);
|
||||||
|
break;
|
||||||
|
case CDC_REQUEST_SEND_BREAK:
|
||||||
|
usbd_cdc_acm_send_break(busid, intf_num);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
USB_LOG_WRN("Unhandled CDC Class bRequest 0x%02x\r\n", setup->bRequest);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct usbd_interface *usbd_cdc_acm_init_intf(uint8_t busid, struct usbd_interface *intf)
|
||||||
|
{
|
||||||
|
intf->class_interface_handler = cdc_acm_class_interface_request_handler;
|
||||||
|
intf->class_endpoint_handler = NULL;
|
||||||
|
intf->vendor_handler = NULL;
|
||||||
|
intf->notify_handler = NULL;
|
||||||
|
|
||||||
|
return intf;
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbd_cdc_acm_set_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbd_cdc_acm_get_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding)
|
||||||
|
{
|
||||||
|
line_coding->dwDTERate = 2000000;
|
||||||
|
line_coding->bDataBits = 8;
|
||||||
|
line_coding->bParityType = 0;
|
||||||
|
line_coding->bCharFormat = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbd_cdc_acm_set_rts(uint8_t busid, uint8_t intf, bool rts)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbd_cdc_acm_send_break(uint8_t busid, uint8_t intf)
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBD_CDC_H
|
||||||
|
#define USBD_CDC_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Init cdc acm interface driver */
|
||||||
|
struct usbd_interface *usbd_cdc_acm_init_intf(uint8_t busid, struct usbd_interface *intf);
|
||||||
|
|
||||||
|
/* Setup request command callback api */
|
||||||
|
void usbd_cdc_acm_set_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding);
|
||||||
|
void usbd_cdc_acm_get_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding);
|
||||||
|
void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr);
|
||||||
|
void usbd_cdc_acm_set_rts(uint8_t busid, uint8_t intf, bool rts);
|
||||||
|
void usbd_cdc_acm_send_break(uint8_t busid, uint8_t intf);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBD_CDC_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBD_CDC_ECM_H
|
||||||
|
#define USBD_CDC_ECM_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Ethernet Maximum Segment size, typically 1514 bytes */
|
||||||
|
#define CONFIG_CDC_ECM_ETH_MAX_SEGSZE 1514U
|
||||||
|
|
||||||
|
/* Init cdc ecm interface driver */
|
||||||
|
struct usbd_interface *usbd_cdc_ecm_init_intf(struct usbd_interface *intf, const uint8_t int_ep, const uint8_t out_ep, const uint8_t in_ep);
|
||||||
|
|
||||||
|
/* Setup request command callback api */
|
||||||
|
void usbd_cdc_ecm_set_connect_speed(uint32_t speed[2]);
|
||||||
|
|
||||||
|
/* Api for eth only without any net stack */
|
||||||
|
uint8_t *usbd_cdc_ecm_get_tx_buffer(void);
|
||||||
|
void usbd_cdc_ecm_send_done(void);
|
||||||
|
int usbd_cdc_ecm_start_write(uint8_t *buf, uint32_t len);
|
||||||
|
void usbd_cdc_ecm_data_recv_done(uint8_t *buf, uint32_t len);
|
||||||
|
void usbd_cdc_ecm_start_read_next(void);
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||||
|
#include "lwip/netif.h"
|
||||||
|
#include "lwip/pbuf.h"
|
||||||
|
struct pbuf *usbd_cdc_ecm_eth_rx(void);
|
||||||
|
int usbd_cdc_ecm_eth_tx(struct pbuf *p);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBD_CDC_ECM_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_CDC_ACM_H
|
||||||
|
#define USBH_CDC_ACM_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
struct usbh_cdc_acm {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
#ifdef CONFIG_USBHOST_CDC_ACM_NOTIFY
|
||||||
|
struct usb_endpoint_descriptor *intin; /* INTR IN endpoint (optional) */
|
||||||
|
#endif
|
||||||
|
struct usbh_urb bulkout_urb;
|
||||||
|
struct usbh_urb bulkin_urb;
|
||||||
|
#ifdef CONFIG_USBHOST_CDC_ACM_NOTIFY
|
||||||
|
struct usbh_urb intin_urb;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct cdc_line_coding linecoding;
|
||||||
|
|
||||||
|
uint8_t intf;
|
||||||
|
uint8_t minor;
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding);
|
||||||
|
int usbh_cdc_acm_get_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding);
|
||||||
|
int usbh_cdc_acm_set_line_state(struct usbh_cdc_acm *cdc_acm_class, bool dtr, bool rts);
|
||||||
|
|
||||||
|
int usbh_cdc_acm_bulk_in_transfer(struct usbh_cdc_acm *cdc_acm_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
|
||||||
|
int usbh_cdc_acm_bulk_out_transfer(struct usbh_cdc_acm *cdc_acm_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
|
||||||
|
|
||||||
|
void usbh_cdc_acm_run(struct usbh_cdc_acm *cdc_acm_class);
|
||||||
|
void usbh_cdc_acm_stop(struct usbh_cdc_acm *cdc_acm_class);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_CDC_ACM_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_CDC_ECM_H
|
||||||
|
#define USBH_CDC_ECM_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
struct usbh_cdc_ecm {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
struct usb_endpoint_descriptor *intin; /* Interrupt IN endpoint */
|
||||||
|
struct usbh_urb bulkout_urb; /* Bulk out endpoint */
|
||||||
|
struct usbh_urb bulkin_urb; /* Bulk IN endpoint */
|
||||||
|
struct usbh_urb intin_urb; /* Interrupt IN endpoint */
|
||||||
|
|
||||||
|
uint8_t ctrl_intf; /* Control interface number */
|
||||||
|
uint8_t data_intf; /* Data interface number */
|
||||||
|
uint8_t minor;
|
||||||
|
|
||||||
|
uint8_t mac[6];
|
||||||
|
bool connect_status;
|
||||||
|
uint16_t max_segment_size;
|
||||||
|
uint32_t speed[2];
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_cdc_ecm_get_connect_status(struct usbh_cdc_ecm *cdc_ecm_class);
|
||||||
|
|
||||||
|
void usbh_cdc_ecm_run(struct usbh_cdc_ecm *cdc_ecm_class);
|
||||||
|
void usbh_cdc_ecm_stop(struct usbh_cdc_ecm *cdc_ecm_class);
|
||||||
|
|
||||||
|
int usbh_cdc_ecm_eth_output(uint8_t *buf, uint32_t buflen);
|
||||||
|
void usbh_cdc_ecm_eth_input(uint8_t *buf, uint32_t buflen);
|
||||||
|
void usbh_cdc_ecm_rx_thread(void *argument);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_CDC_ECM_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_CDC_NCM_H
|
||||||
|
#define USBH_CDC_NCM_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
struct usbh_cdc_ncm {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
struct usb_endpoint_descriptor *intin; /* Interrupt IN endpoint */
|
||||||
|
struct usbh_urb bulkout_urb; /* Bulk out endpoint */
|
||||||
|
struct usbh_urb bulkin_urb; /* Bulk IN endpoint */
|
||||||
|
struct usbh_urb intin_urb; /* Interrupt IN endpoint */
|
||||||
|
|
||||||
|
uint8_t ctrl_intf; /* Control interface number */
|
||||||
|
uint8_t data_intf; /* Data interface number */
|
||||||
|
uint8_t minor;
|
||||||
|
|
||||||
|
struct cdc_ncm_ntb_parameters ntb_param;
|
||||||
|
uint16_t bulkin_sequence;
|
||||||
|
uint16_t bulkout_sequence;
|
||||||
|
|
||||||
|
uint8_t mac[6];
|
||||||
|
bool connect_status;
|
||||||
|
uint16_t max_segment_size;
|
||||||
|
uint32_t speed[2];
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_cdc_ncm_get_connect_status(struct usbh_cdc_ncm *cdc_ncm_class);
|
||||||
|
|
||||||
|
void usbh_cdc_ncm_run(struct usbh_cdc_ncm *cdc_ncm_class);
|
||||||
|
void usbh_cdc_ncm_stop(struct usbh_cdc_ncm *cdc_ncm_class);
|
||||||
|
|
||||||
|
int usbh_cdc_ncm_eth_output(uint8_t *buf, uint32_t buflen);
|
||||||
|
void usbh_cdc_ncm_eth_input(uint8_t *buf, uint32_t buflen);
|
||||||
|
void usbh_cdc_ncm_rx_thread(void *argument);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_CDC_NCM_H */
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USB_DFU_H
|
||||||
|
#define USB_DFU_H
|
||||||
|
|
||||||
|
/**\addtogroup USB_MODULE_DFU USB DFU class
|
||||||
|
* \brief This module contains USB Device Firmware Upgrade class definitions.
|
||||||
|
* \details This module based on
|
||||||
|
* + [USB Device Firmware Upgrade Specification, Revision 1.1]
|
||||||
|
* (https://www.usb.org/sites/default/files/DFU_1.1.pdf)
|
||||||
|
* @{ */
|
||||||
|
|
||||||
|
/** DFU Specification release */
|
||||||
|
#define DFU_VERSION 0x0110
|
||||||
|
|
||||||
|
/** DFU Class Subclass */
|
||||||
|
#define DFU_SUBCLASS_DFU 0x01
|
||||||
|
|
||||||
|
/** DFU Class runtime Protocol */
|
||||||
|
#define DFU_PROTOCOL_RUNTIME 0x01
|
||||||
|
|
||||||
|
/** DFU Class DFU mode Protocol */
|
||||||
|
#define DFU_PROTOCOL_MODE 0x02
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DFU Class Specific Requests
|
||||||
|
*/
|
||||||
|
#define DFU_REQUEST_DETACH 0x00
|
||||||
|
#define DFU_REQUEST_DNLOAD 0x01
|
||||||
|
#define DFU_REQUEST_UPLOAD 0x02
|
||||||
|
#define DFU_REQUEST_GETSTATUS 0x03
|
||||||
|
#define DFU_REQUEST_CLRSTATUS 0x04
|
||||||
|
#define DFU_REQUEST_GETSTATE 0x05
|
||||||
|
#define DFU_REQUEST_ABORT 0x06
|
||||||
|
|
||||||
|
/** DFU FUNCTIONAL descriptor type */
|
||||||
|
#define DFU_FUNC_DESC 0x21
|
||||||
|
|
||||||
|
/** DFU attributes DFU Functional Descriptor */
|
||||||
|
#define DFU_ATTR_WILL_DETACH 0x08
|
||||||
|
#define DFU_ATTR_MANIFESTATION_TOLERANT 0x04
|
||||||
|
#define DFU_ATTR_CAN_UPLOAD 0x02
|
||||||
|
#define DFU_ATTR_CAN_DNLOAD 0x01
|
||||||
|
|
||||||
|
/** bStatus values for the DFU_GETSTATUS response */
|
||||||
|
#define DFU_STATUS_OK 0x00U
|
||||||
|
#define DFU_STATUS_ERR_TARGET 0x01U
|
||||||
|
#define DFU_STATUS_ERR_FILE 0x02U
|
||||||
|
#define DFU_STATUS_ERR_WRITE 0x03U
|
||||||
|
#define DFU_STATUS_ERR_ERASE 0x04U
|
||||||
|
#define DFU_STATUS_ERR_CHECK_ERASED 0x05U
|
||||||
|
#define DFU_STATUS_ERR_PROG 0x06U
|
||||||
|
#define DFU_STATUS_ERR_VERIFY 0x07U
|
||||||
|
#define DFU_STATUS_ERR_ADDRESS 0x08U
|
||||||
|
#define DFU_STATUS_ERR_NOTDONE 0x09U
|
||||||
|
#define DFU_STATUS_ERR_FIRMWARE 0x0AU
|
||||||
|
#define DFU_STATUS_ERR_VENDOR 0x0BU
|
||||||
|
#define DFU_STATUS_ERR_USB 0x0CU
|
||||||
|
#define DFU_STATUS_ERR_POR 0x0DU
|
||||||
|
#define DFU_STATUS_ERR_UNKNOWN 0x0EU
|
||||||
|
#define DFU_STATUS_ERR_STALLEDPKT 0x0FU
|
||||||
|
|
||||||
|
/** bState values for the DFU_GETSTATUS response */
|
||||||
|
#define DFU_STATE_APP_IDLE 0U
|
||||||
|
#define DFU_STATE_APP_DETACH 1U
|
||||||
|
#define DFU_STATE_DFU_IDLE 2U
|
||||||
|
#define DFU_STATE_DFU_DNLOAD_SYNC 3U
|
||||||
|
#define DFU_STATE_DFU_DNLOAD_BUSY 4U
|
||||||
|
#define DFU_STATE_DFU_DNLOAD_IDLE 5U
|
||||||
|
#define DFU_STATE_DFU_MANIFEST_SYNC 6U
|
||||||
|
#define DFU_STATE_DFU_MANIFEST 7U
|
||||||
|
#define DFU_STATE_DFU_MANIFEST_WAIT_RESET 8U
|
||||||
|
#define DFU_STATE_DFU_UPLOAD_IDLE 9U
|
||||||
|
#define DFU_STATE_DFU_ERROR 10U
|
||||||
|
|
||||||
|
/** DFU Manifestation State */
|
||||||
|
#define DFU_MANIFEST_COMPLETE 0U
|
||||||
|
#define DFU_MANIFEST_IN_PROGRESS 1U
|
||||||
|
|
||||||
|
/** Special Commands with Download Request */
|
||||||
|
#define DFU_CMD_GETCOMMANDS 0U
|
||||||
|
#define DFU_CMD_SETADDRESSPOINTER 0x21U
|
||||||
|
#define DFU_CMD_ERASE 0x41U
|
||||||
|
#define DFU_MEDIA_ERASE 0x00U
|
||||||
|
#define DFU_MEDIA_PROGRAM 0x01U
|
||||||
|
|
||||||
|
/** Other defines */
|
||||||
|
/* Bit Detach capable = bit 3 in bmAttributes field */
|
||||||
|
#define DFU_DETACH_MASK (1U << 3)
|
||||||
|
#define DFU_MANIFEST_MASK (1U << 2)
|
||||||
|
|
||||||
|
/** Run-Time Functional Descriptor */
|
||||||
|
struct dfu_runtime_descriptor {
|
||||||
|
uint8_t bLength; /**<\brief Descriptor length in bytes.*/
|
||||||
|
uint8_t bDescriptorType; /**<\brief DFU functional descriptor type.*/
|
||||||
|
uint8_t bmAttributes; /**<\brief USB DFU capabilities \ref USB_DFU_CAPAB*/
|
||||||
|
uint16_t wDetachTimeout; /**<\brief USB DFU detach timeout in ms.*/
|
||||||
|
uint16_t wTransferSize; /**<\brief USB DFU maximum transfer block size in bytes.*/
|
||||||
|
uint16_t bcdDFUVersion; /**<\brief USB DFU version \ref VERSION_BCD utility macro.*/
|
||||||
|
} __PACKED;
|
||||||
|
|
||||||
|
/**\brief Payload packet to response in DFU_GETSTATUS request */
|
||||||
|
struct dfu_info {
|
||||||
|
uint8_t bStatus; /**<\brief An indication of the status resulting from the
|
||||||
|
* execution of the most recent request.*/
|
||||||
|
uint8_t bPollTimeout; /**<\brief Minimum time (LSB) in ms, that the host should wait
|
||||||
|
* before sending a subsequent DFU_GETSTATUS request.*/
|
||||||
|
uint16_t wPollTimeout; /**<\brief Minimum time (MSB) in ms, that the host should wait
|
||||||
|
* before sending a subsequent DFU_GETSTATUS request.*/
|
||||||
|
uint8_t bState; /**<\brief An indication of the state that the device is going
|
||||||
|
* to enter immediately following transmission of this response.*/
|
||||||
|
uint8_t iString; /**<\brief Index of the status string descriptor.*/
|
||||||
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
#define DFU_DESCRIPTOR_INIT() \
|
||||||
|
0x09, /* bLength */ \
|
||||||
|
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||||
|
0x00, /* bInterfaceNumber */ \
|
||||||
|
0x00, /* bAlternateSetting */ \
|
||||||
|
0x00, /* bNumEndpoints Default Control Pipe only */ \
|
||||||
|
USB_DEVICE_CLASS_APP_SPECIFIC, /* bInterfaceClass */ \
|
||||||
|
0x01, /* bInterfaceSubClass Device Firmware Upgrade */ \
|
||||||
|
0x02, /* bInterfaceProtocol DFU mode */ \
|
||||||
|
0x04, /* iInterface */ /*!< Device Firmware Update Functional Descriptor */ \
|
||||||
|
0x09, /* bLength */ \
|
||||||
|
0x21, /* DFU Functional Descriptor */ \
|
||||||
|
0x0B, /* bmAttributes */ \
|
||||||
|
WBVAL(0x00ff), /* wDetachTimeOut */ \
|
||||||
|
WBVAL(USBD_DFU_XFER_SIZE), /* wTransferSize */ \
|
||||||
|
WBVAL(0x011a) /* bcdDFUVersion */
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
#endif /* USB_DFU_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBD_DFU_H
|
||||||
|
#define USBD_DFU_H
|
||||||
|
|
||||||
|
#include "usb_dfu.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Init dfu interface driver */
|
||||||
|
struct usbd_interface *usbd_dfu_init_intf(struct usbd_interface *intf);
|
||||||
|
|
||||||
|
/* Interface functions that need to be implemented by the user */
|
||||||
|
uint8_t *dfu_read_flash(uint8_t *src, uint8_t *dest, uint32_t len);
|
||||||
|
uint16_t dfu_write_flash(uint8_t *src, uint8_t *dest, uint32_t len);
|
||||||
|
uint16_t dfu_erase_flash(uint32_t add);
|
||||||
|
void dfu_leave(void);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBD_DFU_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_hid.h"
|
||||||
|
|
||||||
|
static int hid_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||||
|
{
|
||||||
|
USB_LOG_DBG("HID Class request: "
|
||||||
|
"bRequest 0x%02x\r\n",
|
||||||
|
setup->bRequest);
|
||||||
|
|
||||||
|
uint8_t intf_num = LO_BYTE(setup->wIndex);
|
||||||
|
|
||||||
|
switch (setup->bRequest) {
|
||||||
|
case HID_REQUEST_GET_REPORT:
|
||||||
|
/* report id ,report type */
|
||||||
|
usbd_hid_get_report(busid, intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), data, len);
|
||||||
|
break;
|
||||||
|
case HID_REQUEST_GET_IDLE:
|
||||||
|
(*data)[0] = usbd_hid_get_idle(busid, intf_num, LO_BYTE(setup->wValue));
|
||||||
|
*len = 1;
|
||||||
|
break;
|
||||||
|
case HID_REQUEST_GET_PROTOCOL:
|
||||||
|
(*data)[0] = usbd_hid_get_protocol(busid, intf_num);
|
||||||
|
*len = 1;
|
||||||
|
break;
|
||||||
|
case HID_REQUEST_SET_REPORT:
|
||||||
|
/* report id ,report type, report, report len */
|
||||||
|
usbd_hid_set_report(busid, intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), *data, *len);
|
||||||
|
break;
|
||||||
|
case HID_REQUEST_SET_IDLE:
|
||||||
|
/* report id, duration */
|
||||||
|
usbd_hid_set_idle(busid, intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue));
|
||||||
|
break;
|
||||||
|
case HID_REQUEST_SET_PROTOCOL:
|
||||||
|
/* protocol */
|
||||||
|
usbd_hid_set_protocol(busid, intf_num, LO_BYTE(setup->wValue));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
USB_LOG_WRN("Unhandled HID Class bRequest 0x%02x\r\n", setup->bRequest);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct usbd_interface *usbd_hid_init_intf(uint8_t busid, struct usbd_interface *intf, const uint8_t *desc, uint32_t desc_len)
|
||||||
|
{
|
||||||
|
intf->class_interface_handler = hid_class_interface_request_handler;
|
||||||
|
intf->class_endpoint_handler = NULL;
|
||||||
|
intf->vendor_handler = NULL;
|
||||||
|
intf->notify_handler = NULL;
|
||||||
|
|
||||||
|
intf->hid_report_descriptor = desc;
|
||||||
|
intf->hid_report_descriptor_len = desc_len;
|
||||||
|
return intf;
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbd_hid_get_report(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **data, uint32_t *len)
|
||||||
|
{
|
||||||
|
(*data[0]) = 0;
|
||||||
|
*len = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK uint8_t usbd_hid_get_idle(uint8_t busid, uint8_t intf, uint8_t report_id)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK uint8_t usbd_hid_get_protocol(uint8_t busid, uint8_t intf)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbd_hid_set_report(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint32_t report_len)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbd_hid_set_idle(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t duration)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbd_hid_set_protocol(uint8_t busid, uint8_t intf, uint8_t protocol)
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBD_HID_H
|
||||||
|
#define USBD_HID_H
|
||||||
|
|
||||||
|
#include "usb_hid.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Init hid interface driver */
|
||||||
|
struct usbd_interface *usbd_hid_init_intf(uint8_t busid, struct usbd_interface *intf, const uint8_t *desc, uint32_t desc_len);
|
||||||
|
|
||||||
|
/* Register desc api */
|
||||||
|
void usbd_hid_descriptor_register(uint8_t busid, uint8_t intf_num, const uint8_t *desc);
|
||||||
|
void usbd_hid_report_descriptor_register(uint8_t busid, uint8_t intf_num, const uint8_t *desc, uint32_t desc_len);
|
||||||
|
|
||||||
|
/* Setup request command callback api */
|
||||||
|
void usbd_hid_get_report(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **data, uint32_t *len);
|
||||||
|
uint8_t usbd_hid_get_idle(uint8_t busid, uint8_t intf, uint8_t report_id);
|
||||||
|
uint8_t usbd_hid_get_protocol(uint8_t busid, uint8_t intf);
|
||||||
|
void usbd_hid_set_report(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint32_t report_len);
|
||||||
|
void usbd_hid_set_idle(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t duration);
|
||||||
|
void usbd_hid_set_protocol(uint8_t busid, uint8_t intf, uint8_t protocol);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBD_HID_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_HID_H
|
||||||
|
#define USBH_HID_H
|
||||||
|
|
||||||
|
#include "usb_hid.h"
|
||||||
|
|
||||||
|
struct usbh_hid {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *intin; /* INTR IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *intout; /* INTR OUT endpoint */
|
||||||
|
struct usbh_urb intin_urb; /* INTR IN urb */
|
||||||
|
struct usbh_urb intout_urb; /* INTR OUT urb */
|
||||||
|
|
||||||
|
uint8_t report_desc[256];
|
||||||
|
uint8_t intf; /* interface number */
|
||||||
|
uint8_t minor;
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t duration);
|
||||||
|
int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer);
|
||||||
|
int usbh_hid_set_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t report_id, uint8_t *buffer, uint32_t buflen);
|
||||||
|
int usbh_hid_get_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t report_id, uint8_t *buffer, uint32_t buflen);
|
||||||
|
|
||||||
|
void usbh_hid_run(struct usbh_hid *hid_class);
|
||||||
|
void usbh_hid_stop(struct usbh_hid *hid_class);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_HID_H */
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USB_HUB_H
|
||||||
|
#define USB_HUB_H
|
||||||
|
|
||||||
|
/* HUB Class Descriptor Types */
|
||||||
|
#define HUB_DESCRIPTOR_TYPE_HUB 0x29
|
||||||
|
#define HUB_DESCRIPTOR_TYPE_HUB3 0x2A
|
||||||
|
|
||||||
|
/* Hub class requests */
|
||||||
|
#define HUB_REQUEST_GET_STATUS USB_REQUEST_GET_STATUS
|
||||||
|
#define HUB_REQUEST_CLEAR_FEATURE USB_REQUEST_CLEAR_FEATURE
|
||||||
|
#define HUB_REQUEST_SET_FEATURE USB_REQUEST_SET_FEATURE
|
||||||
|
#define HUB_REQUEST_GET_DESCRIPTOR USB_REQUEST_GET_DESCRIPTOR
|
||||||
|
#define HUB_REQUEST_SET_DESCRIPTOR USB_REQUEST_SET_DESCRIPTOR
|
||||||
|
#define HUB_REQUEST_CLEAR_TT_BUFFER (0x08)
|
||||||
|
#define HUB_REQUEST_RESET_TT (0x09)
|
||||||
|
#define HUB_REQUEST_GET_TT_STATE (0x0a)
|
||||||
|
#define HUB_REQUEST_STOP_TT (0x0b)
|
||||||
|
#define HUB_REQUEST_SET_HUB_DEPTH (0x0C)
|
||||||
|
|
||||||
|
/* Hub class features */
|
||||||
|
#define HUB_FEATURE_HUB_C_LOCALPOWER (0x0)
|
||||||
|
#define HUB_FEATURE_HUB_C_OVERCURRENT (0x1)
|
||||||
|
|
||||||
|
/* Port features */
|
||||||
|
#define HUB_PORT_FEATURE_CONNECTION (0x00)
|
||||||
|
#define HUB_PORT_FEATURE_ENABLE (0x01)
|
||||||
|
#define HUB_PORT_FEATURE_SUSPEND (0x02)
|
||||||
|
#define HUB_PORT_FEATURE_OVERCURRENT (0x03)
|
||||||
|
#define HUB_PORT_FEATURE_RESET (0x04)
|
||||||
|
#define HUB_PORT_FEATURE_L1 (0x05)
|
||||||
|
#define HUB_PORT_FEATURE_POWER (0x08)
|
||||||
|
#define HUB_PORT_FEATURE_LOWSPEED (0x09)
|
||||||
|
#define HUB_PORT_FEATURE_HIGHSPEED (0x0a)
|
||||||
|
#define HUB_PORT_FEATURE_C_CONNECTION (0x10)
|
||||||
|
#define HUB_PORT_FEATURE_C_ENABLE (0x11)
|
||||||
|
#define HUB_PORT_FEATURE_C_SUSPEND (0x12)
|
||||||
|
#define HUB_PORT_FEATURE_C_OVER_CURREN (0x13)
|
||||||
|
#define HUB_PORT_FEATURE_C_RESET (0x14)
|
||||||
|
#define HUB_PORT_FEATURE_TEST (0x15)
|
||||||
|
#define HUB_PORT_FEATURE_INDICATOR (0x16)
|
||||||
|
#define HUB_PORT_FEATURE_C_PORTL1 (0x17)
|
||||||
|
|
||||||
|
/* Hub status */
|
||||||
|
#define HUB_STATUS_LOCALPOWER (1 << 0)
|
||||||
|
#define HUB_STATUS_OVERCURRENT (1 << 1)
|
||||||
|
|
||||||
|
/* Hub status change */
|
||||||
|
#define HUB_STATUS_C_LOCALPOWER (1 << 0)
|
||||||
|
#define HUB_STATUS_C_OVERCURRENT (1 << 1)
|
||||||
|
|
||||||
|
/* Hub port status */
|
||||||
|
#define HUB_PORT_STATUS_CONNECTION (1 << 0)
|
||||||
|
#define HUB_PORT_STATUS_ENABLE (1 << 1)
|
||||||
|
#define HUB_PORT_STATUS_SUSPEND (1 << 2)
|
||||||
|
#define HUB_PORT_STATUS_OVERCURRENT (1 << 3)
|
||||||
|
#define HUB_PORT_STATUS_RESET (1 << 4)
|
||||||
|
#define HUB_PORT_STATUS_L1 (1 << 5)
|
||||||
|
#define HUB_PORT_STATUS_POWER (1 << 8)
|
||||||
|
#define HUB_PORT_STATUS_LOW_SPEED (1 << 9)
|
||||||
|
#define HUB_PORT_STATUS_HIGH_SPEED (1 << 10)
|
||||||
|
#define HUB_PORT_STATUS_TEST (1 << 11)
|
||||||
|
#define HUB_PORT_STATUS_INDICATOR (1 << 12)
|
||||||
|
|
||||||
|
/* Hub port status change */
|
||||||
|
#define HUB_PORT_STATUS_C_CONNECTION (1 << 0)
|
||||||
|
#define HUB_PORT_STATUS_C_ENABLE (1 << 1)
|
||||||
|
#define HUB_PORT_STATUS_C_SUSPEND (1 << 2)
|
||||||
|
#define HUB_PORT_STATUS_C_OVERCURRENT (1 << 3)
|
||||||
|
#define HUB_PORT_STATUS_C_RESET (1 << 4)
|
||||||
|
#define HUB_PORT_STATUS_C_L1 (1 << 5)
|
||||||
|
|
||||||
|
/* Hub characteristics */
|
||||||
|
#define HUB_CHAR_LPSM_SHIFT (0) /* Bits 0-1: Logical Power Switching Mode */
|
||||||
|
#define HUB_CHAR_LPSM_MASK (3 << HUB_CHAR_LPSM_SHIFT)
|
||||||
|
#define HUB_CHAR_LPSM_GANGED (0 << HUB_CHAR_LPSM_SHIFT)
|
||||||
|
#define HUB_CHAR_LPSM_INDIVIDUAL (1 << HUB_CHAR_LPSM_SHIFT)
|
||||||
|
#define HUB_CHAR_COMPOUND (1 << 2) /* Bit 2: Compound device */
|
||||||
|
#define HUB_CHAR_OCPM_SHIFT (3) /* Bits 3-4: Over-current Protection Mode */
|
||||||
|
#define HUB_CHAR_OCPM_MASK (3 << HUB_CHAR_OCPM_SHIFT)
|
||||||
|
#define HUB_CHAR_OCPM_GLOBAL (0 << HUB_CHAR_OCPM_SHIFT)
|
||||||
|
#define HUB_CHAR_OCPM_INDIVIDUAL (1 << HUB_CHAR_OCPM_SHIFT)
|
||||||
|
#define HUB_CHAR_TTTT_SHIFT (5) /* Bits 5-6: TT Think Time */
|
||||||
|
#define HUB_CHAR_TTTT_MASK (3 << HUB_CHAR_TTTT_SHIFT)
|
||||||
|
#define HUB_CHAR_TTTT_8_BITS (0 << HUB_CHAR_TTTT_SHIFT)
|
||||||
|
#define HUB_CHAR_TTTT_16_BITS (1 << HUB_CHAR_TTTT_SHIFT)
|
||||||
|
#define HUB_CHAR_TTTT_24_BITS (2 << HUB_CHAR_TTTT_SHIFT)
|
||||||
|
#define HUB_CHAR_TTTT_32_BITS (3 << HUB_CHAR_TTTT_SHIFT)
|
||||||
|
#define HUB_CHAR_PORTIND (1 << 7) /* Bit 7: Port Indicators Supported */
|
||||||
|
|
||||||
|
/* Hub descriptor */
|
||||||
|
struct usb_hub_descriptor {
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bNbrPorts;
|
||||||
|
uint16_t wHubCharacteristics;
|
||||||
|
uint8_t bPwrOn2PwrGood;
|
||||||
|
uint8_t bHubContrCurrent;
|
||||||
|
uint8_t DeviceRemovable;
|
||||||
|
uint8_t PortPwrCtrlMask;
|
||||||
|
} __PACKED;
|
||||||
|
|
||||||
|
#define USB_SIZEOF_HUB_DESC 9
|
||||||
|
|
||||||
|
/* Hub status */
|
||||||
|
struct hub_status {
|
||||||
|
uint16_t wPortStatus;
|
||||||
|
uint16_t wPortChange;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Hub port status */
|
||||||
|
struct hub_port_status {
|
||||||
|
uint16_t wPortStatus;
|
||||||
|
uint16_t wPortChange;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* USB_HUB_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_HUB_H
|
||||||
|
#define USBH_HUB_H
|
||||||
|
|
||||||
|
#include "usb_hub.h"
|
||||||
|
|
||||||
|
struct usbh_hub;
|
||||||
|
|
||||||
|
#define USBH_HUB_MAX_PORTS 4
|
||||||
|
/* Maximum size of an interrupt IN transfer */
|
||||||
|
#define USBH_HUB_INTIN_BUFSIZE ((USBH_HUB_MAX_PORTS + 8) >> 3)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_hub_set_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature);
|
||||||
|
int usbh_hub_clear_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature);
|
||||||
|
|
||||||
|
void usbh_hub_thread_wakeup(struct usbh_hub *hub);
|
||||||
|
|
||||||
|
int usbh_hub_initialize(struct usbh_bus *bus);
|
||||||
|
int usbh_hub_deinitialize(struct usbh_bus *bus);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_HUB_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USB_MSC_H
|
||||||
|
#define USB_MSC_H
|
||||||
|
|
||||||
|
/* MSC Subclass Codes */
|
||||||
|
#define MSC_SUBCLASS_RBC 0x01 /* Reduced block commands (e.g., flash devices) */
|
||||||
|
#define MSC_SUBCLASS_SFF8020I_MMC2 0x02 /* SFF-8020i/MMC-2 (ATAPI) (e.g., C/DVD) */
|
||||||
|
#define MSC_SUBCLASS_QIC157 0x03 /* QIC-157 (e.g., tape device) */
|
||||||
|
#define MSC_SUBCLASS_UFI 0x04 /* e.g. floppy device */
|
||||||
|
#define MSC_SUBCLASS_SFF8070I 0x05 /* SFF-8070i (e.g. floppy disk) */
|
||||||
|
#define MSC_SUBCLASS_SCSI 0x06 /* SCSI transparent */
|
||||||
|
|
||||||
|
/* MSC Protocol Codes */
|
||||||
|
#define MSC_PROTOCOL_CBI_INT 0x00 /* CBI transport with command completion interrupt */
|
||||||
|
#define MSC_PROTOCOL_CBI_NOINT 0x01 /* CBI transport without command completion interrupt */
|
||||||
|
#define MSC_PROTOCOL_BULK_ONLY 0x50 /* Bulk only transport */
|
||||||
|
|
||||||
|
/* MSC Request Codes */
|
||||||
|
#define MSC_REQUEST_RESET 0xFF
|
||||||
|
#define MSC_REQUEST_GET_MAX_LUN 0xFE
|
||||||
|
|
||||||
|
/** MSC Command Block Wrapper (CBW) Signature */
|
||||||
|
#define MSC_CBW_Signature 0x43425355
|
||||||
|
/** Bulk-only Command Status Wrapper (CSW) Signature */
|
||||||
|
#define MSC_CSW_Signature 0x53425355
|
||||||
|
|
||||||
|
/** MSC Command Block Status Values */
|
||||||
|
#define CSW_STATUS_CMD_PASSED 0x00
|
||||||
|
#define CSW_STATUS_CMD_FAILED 0x01
|
||||||
|
#define CSW_STATUS_PHASE_ERROR 0x02
|
||||||
|
|
||||||
|
#define MSC_MAX_CDB_LEN (16) /* Max length of SCSI Command Data Block */
|
||||||
|
|
||||||
|
/** MSC Bulk-Only Command Block Wrapper (CBW) */
|
||||||
|
struct CBW {
|
||||||
|
uint32_t dSignature; /* 'USBC' = 0x43425355 */
|
||||||
|
uint32_t dTag; /* Depends on command id */
|
||||||
|
uint32_t dDataLength; /* Number of bytes that host expects to transfer */
|
||||||
|
uint8_t bmFlags; /* Bit 7: Direction=IN (other obsolete or reserved) */
|
||||||
|
uint8_t bLUN; /* LUN (normally 0) */
|
||||||
|
uint8_t bCBLength; /* len of cdb[] */
|
||||||
|
uint8_t CB[MSC_MAX_CDB_LEN]; /* Command Data Block */
|
||||||
|
} __PACKED;
|
||||||
|
|
||||||
|
#define USB_SIZEOF_MSC_CBW 31
|
||||||
|
|
||||||
|
/** MSC Bulk-Only Command Status Wrapper (CSW) */
|
||||||
|
struct CSW {
|
||||||
|
uint32_t dSignature; /* 'USBS' = 0x53425355 */
|
||||||
|
uint32_t dTag; /* Same tag as original command */
|
||||||
|
uint32_t dDataResidue; /* Amount not transferred */
|
||||||
|
uint8_t bStatus; /* Status of transfer */
|
||||||
|
} __PACKED;
|
||||||
|
|
||||||
|
#define USB_SIZEOF_MSC_CSW 13
|
||||||
|
|
||||||
|
/*Length of template descriptor: 23 bytes*/
|
||||||
|
#define MSC_DESCRIPTOR_LEN (9 + 7 + 7)
|
||||||
|
// clang-format off
|
||||||
|
#define MSC_DESCRIPTOR_INIT(bFirstInterface, out_ep, in_ep, wMaxPacketSize, str_idx) \
|
||||||
|
/* Interface */ \
|
||||||
|
0x09, /* bLength */ \
|
||||||
|
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||||
|
bFirstInterface, /* bInterfaceNumber */ \
|
||||||
|
0x00, /* bAlternateSetting */ \
|
||||||
|
0x02, /* bNumEndpoints */ \
|
||||||
|
USB_DEVICE_CLASS_MASS_STORAGE, /* bInterfaceClass */ \
|
||||||
|
MSC_SUBCLASS_SCSI, /* bInterfaceSubClass */ \
|
||||||
|
MSC_PROTOCOL_BULK_ONLY, /* bInterfaceProtocol */ \
|
||||||
|
str_idx, /* iInterface */ \
|
||||||
|
0x07, /* bLength */ \
|
||||||
|
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
|
||||||
|
out_ep, /* bEndpointAddress */ \
|
||||||
|
0x02, /* bmAttributes */ \
|
||||||
|
WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \
|
||||||
|
0x00, /* bInterval */ \
|
||||||
|
0x07, /* bLength */ \
|
||||||
|
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
|
||||||
|
in_ep, /* bEndpointAddress */ \
|
||||||
|
0x02, /* bmAttributes */ \
|
||||||
|
WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \
|
||||||
|
0x00 /* bInterval */
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
#endif /* USB_MSC_H */
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
* Copyright (c) 2024, zhihong chen
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBD_MSC_H
|
||||||
|
#define USBD_MSC_H
|
||||||
|
|
||||||
|
#include "usb_msc.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Init msc interface driver */
|
||||||
|
struct usbd_interface *usbd_msc_init_intf(uint8_t busid, struct usbd_interface *intf,
|
||||||
|
const uint8_t out_ep,
|
||||||
|
const uint8_t in_ep);
|
||||||
|
|
||||||
|
void usbd_msc_get_cap(uint8_t busid, uint8_t lun, uint32_t *block_num, uint32_t *block_size);
|
||||||
|
int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length);
|
||||||
|
int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length);
|
||||||
|
|
||||||
|
void usbd_msc_set_readonly(uint8_t busid, bool readonly);
|
||||||
|
bool usbd_msc_set_popup(uint8_t busid);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBD_MSC_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_MSC_H
|
||||||
|
#define USBH_MSC_H
|
||||||
|
|
||||||
|
#include "usb_msc.h"
|
||||||
|
#include "usb_scsi.h"
|
||||||
|
|
||||||
|
struct usbh_msc {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
struct usbh_urb bulkin_urb; /* Bulk IN urb */
|
||||||
|
struct usbh_urb bulkout_urb; /* Bulk OUT urb */
|
||||||
|
|
||||||
|
uint8_t intf; /* Data interface number */
|
||||||
|
uint8_t sdchar;
|
||||||
|
uint32_t blocknum; /* Number of blocks on the USB mass storage device */
|
||||||
|
uint16_t blocksize; /* Block size of USB mass storage device */
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usbh_msc_modeswitch_config {
|
||||||
|
const char *name;
|
||||||
|
uint16_t vid; /* Vendor ID (for vendor/product specific devices) */
|
||||||
|
uint16_t pid; /* Product ID (for vendor/product specific devices) */
|
||||||
|
const uint8_t *message_content;
|
||||||
|
};
|
||||||
|
|
||||||
|
void usbh_msc_modeswitch_enable(struct usbh_msc_modeswitch_config *config);
|
||||||
|
int usbh_msc_scsi_write10(struct usbh_msc *msc_class, uint32_t start_sector, const uint8_t *buffer, uint32_t nsectors);
|
||||||
|
int usbh_msc_scsi_read10(struct usbh_msc *msc_class, uint32_t start_sector, const uint8_t *buffer, uint32_t nsectors);
|
||||||
|
|
||||||
|
void usbh_msc_run(struct usbh_msc *msc_class);
|
||||||
|
void usbh_msc_stop(struct usbh_msc *msc_class);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_MSC_H */
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#ifndef _USB_XXX_H
|
||||||
|
#define _USB_XXX_H
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_xxx.h"
|
||||||
|
|
||||||
|
static int xxx_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||||
|
{
|
||||||
|
USB_LOG_WRN("XXX Class request: "
|
||||||
|
"bRequest 0x%02x\r\n",
|
||||||
|
setup->bRequest);
|
||||||
|
|
||||||
|
switch (setup->bRequest) {
|
||||||
|
default:
|
||||||
|
USB_LOG_WRN("Unhandled XXX Class bRequest 0x%02x\r\n", setup->bRequest);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void xxx_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||||
|
{
|
||||||
|
switch (event) {
|
||||||
|
case USBD_EVENT_RESET:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct usbd_interface *usbd_xxx_init_intf(uint8_t busid, struct usbd_interface *intf)
|
||||||
|
{
|
||||||
|
intf->class_interface_handler = xxx_class_interface_request_handler;
|
||||||
|
intf->class_endpoint_handler = NULL;
|
||||||
|
intf->vendor_handler = NULL;
|
||||||
|
intf->notify_handler = xxx_notify_handler;
|
||||||
|
|
||||||
|
return intf;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef _USBD_XXX_H_
|
||||||
|
#define _USBD_XXX_H_
|
||||||
|
|
||||||
|
#include "usb_xxx.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct usbd_interface *usbd_xxx_init_intf(uint8_t busid, struct usbd_interface *intf);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _USBD_XXX_H_ */
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
#include "usbh_core.h"
|
||||||
|
#include "usbh_xxx.h"
|
||||||
|
|
||||||
|
#define DEV_FORMAT "/dev/xxx"
|
||||||
|
|
||||||
|
#define CONFIG_USBHOST_MAX_CUSTOM_CLASS 1
|
||||||
|
static struct usbh_xxx g_xxx_class[CONFIG_USBHOST_MAX_CUSTOM_CLASS];
|
||||||
|
static uint32_t g_devinuse = 0;
|
||||||
|
|
||||||
|
static struct usbh_xxx *usbh_xxx_class_alloc(void)
|
||||||
|
{
|
||||||
|
int devno;
|
||||||
|
|
||||||
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_CUSTOM_CLASS; devno++) {
|
||||||
|
if ((g_devinuse & (1 << devno)) == 0) {
|
||||||
|
g_devinuse |= (1 << devno);
|
||||||
|
memset(&g_xxx_class[devno], 0, sizeof(struct usbh_xxx));
|
||||||
|
g_xxx_class[devno].minor = devno;
|
||||||
|
return &g_xxx_class[devno];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void usbh_xxx_class_free(struct usbh_xxx *xxx_class)
|
||||||
|
{
|
||||||
|
int devno = xxx_class->minor;
|
||||||
|
|
||||||
|
if (devno >= 0 && devno < 32) {
|
||||||
|
g_devinuse &= ~(1 << devno);
|
||||||
|
}
|
||||||
|
memset(xxx_class, 0, sizeof(struct usbh_xxx));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int usbh_xxx_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||||
|
{
|
||||||
|
struct usb_endpoint_descriptor *ep_desc;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
struct usbh_xxx *xxx_class = usbh_xxx_class_alloc();
|
||||||
|
if (xxx_class == NULL) {
|
||||||
|
USB_LOG_ERR("Fail to alloc xxx_class\r\n");
|
||||||
|
return -USB_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int usbh_xxx_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
struct usbh_xxx *xxx_class = (struct usbh_xxx *)hport->config.intf[intf].priv;
|
||||||
|
|
||||||
|
if (xxx_class) {
|
||||||
|
if (xxx_class->xxxin) {
|
||||||
|
usbh_kill_urb(&xxx_class->xxxin_urb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xxx_class->xxxout) {
|
||||||
|
usbh_kill_urb(&xxx_class->xxxout_urb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||||
|
USB_LOG_INFO("Unregister xxx Class:%s\r\n", hport->config.intf[intf].devname);
|
||||||
|
usbh_xxx_stop(xxx_class);
|
||||||
|
}
|
||||||
|
|
||||||
|
usbh_xxx_class_free(xxx_class);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbh_xxx_run(struct usbh_xxx *xxx_class)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
__WEAK void usbh_xxx_stop(struct usbh_xxx *xxx_class)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct usbh_class_driver xxx_class_driver = {
|
||||||
|
.driver_name = "xxx",
|
||||||
|
.connect = usbh_xxx_connect,
|
||||||
|
.disconnect = usbh_xxx_disconnect
|
||||||
|
};
|
||||||
|
|
||||||
|
CLASS_INFO_DEFINE const struct usbh_class_info xxx_class_info = {
|
||||||
|
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||||
|
.class = 0,
|
||||||
|
.subclass = 0,
|
||||||
|
.protocol = 0,
|
||||||
|
.id_table = NULL,
|
||||||
|
.class_driver = &xxx_class_driver
|
||||||
|
};
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#ifndef _USBH_XXX_H
|
||||||
|
#define _USBH_XXX_H
|
||||||
|
|
||||||
|
#include "usb_xxx.h"
|
||||||
|
|
||||||
|
struct usbh_xxx {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *xxxin;
|
||||||
|
struct usb_endpoint_descriptor *xxxout;
|
||||||
|
struct usbh_urb xxxin_urb;
|
||||||
|
struct usbh_urb xxxout_urb;
|
||||||
|
|
||||||
|
uint8_t intf; /* interface number */
|
||||||
|
uint8_t minor;
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
void usbh_xxx_run(struct usbh_xxx *xxx_class);
|
||||||
|
void usbh_xxx_stop(struct usbh_xxx *xxx_class);
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_ASIX_H
|
||||||
|
#define USBH_ASIX_H
|
||||||
|
|
||||||
|
/* ASIX AX8817X based USB 2.0 Ethernet Devices */
|
||||||
|
|
||||||
|
#define AX_CMD_SET_SW_MII 0x06
|
||||||
|
#define AX_CMD_READ_MII_REG 0x07
|
||||||
|
#define AX_CMD_WRITE_MII_REG 0x08
|
||||||
|
#define AX_CMD_STATMNGSTS_REG 0x09
|
||||||
|
#define AX_CMD_SET_HW_MII 0x0a
|
||||||
|
#define AX_CMD_READ_EEPROM 0x0b
|
||||||
|
#define AX_CMD_WRITE_EEPROM 0x0c
|
||||||
|
#define AX_CMD_WRITE_ENABLE 0x0d
|
||||||
|
#define AX_CMD_WRITE_DISABLE 0x0e
|
||||||
|
#define AX_CMD_READ_RX_CTL 0x0f
|
||||||
|
#define AX_CMD_WRITE_RX_CTL 0x10
|
||||||
|
#define AX_CMD_READ_IPG012 0x11
|
||||||
|
#define AX_CMD_WRITE_IPG0 0x12
|
||||||
|
#define AX_CMD_WRITE_IPG1 0x13
|
||||||
|
#define AX_CMD_READ_NODE_ID 0x13
|
||||||
|
#define AX_CMD_WRITE_NODE_ID 0x14
|
||||||
|
#define AX_CMD_WRITE_IPG2 0x14
|
||||||
|
#define AX_CMD_WRITE_MULTI_FILTER 0x16
|
||||||
|
#define AX88172_CMD_READ_NODE_ID 0x17
|
||||||
|
#define AX_CMD_READ_PHY_ID 0x19
|
||||||
|
#define AX_CMD_READ_MEDIUM_STATUS 0x1a
|
||||||
|
#define AX_CMD_WRITE_MEDIUM_MODE 0x1b
|
||||||
|
#define AX_CMD_READ_MONITOR_MODE 0x1c
|
||||||
|
#define AX_CMD_WRITE_MONITOR_MODE 0x1d
|
||||||
|
#define AX_CMD_READ_GPIOS 0x1e
|
||||||
|
#define AX_CMD_WRITE_GPIOS 0x1f
|
||||||
|
#define AX_CMD_SW_RESET 0x20
|
||||||
|
#define AX_CMD_SW_PHY_STATUS 0x21
|
||||||
|
#define AX_CMD_SW_PHY_SELECT 0x22
|
||||||
|
#define AX_QCTCTRL 0x2A
|
||||||
|
|
||||||
|
#define AX_CHIPCODE_MASK 0x70
|
||||||
|
#define AX_AX88772_CHIPCODE 0x00
|
||||||
|
#define AX_AX88772A_CHIPCODE 0x10
|
||||||
|
#define AX_AX88772B_CHIPCODE 0x20
|
||||||
|
#define AX_HOST_EN 0x01
|
||||||
|
|
||||||
|
#define AX_PHYSEL_PSEL 0x01
|
||||||
|
#define AX_PHYSEL_SSMII 0
|
||||||
|
#define AX_PHYSEL_SSEN 0x10
|
||||||
|
|
||||||
|
#define AX_PHY_SELECT_MASK (BIT(3) | BIT(2))
|
||||||
|
#define AX_PHY_SELECT_INTERNAL 0
|
||||||
|
#define AX_PHY_SELECT_EXTERNAL BIT(2)
|
||||||
|
|
||||||
|
#define AX_MONITOR_MODE 0x01
|
||||||
|
#define AX_MONITOR_LINK 0x02
|
||||||
|
#define AX_MONITOR_MAGIC 0x04
|
||||||
|
#define AX_MONITOR_HSFS 0x10
|
||||||
|
|
||||||
|
/* AX88172 Medium Status Register values */
|
||||||
|
#define AX88172_MEDIUM_FD 0x02
|
||||||
|
#define AX88172_MEDIUM_TX 0x04
|
||||||
|
#define AX88172_MEDIUM_FC 0x10
|
||||||
|
#define AX88172_MEDIUM_DEFAULT \
|
||||||
|
(AX88172_MEDIUM_FD | AX88172_MEDIUM_TX | AX88172_MEDIUM_FC)
|
||||||
|
|
||||||
|
#define AX_MCAST_FILTER_SIZE 8
|
||||||
|
#define AX_MAX_MCAST 64
|
||||||
|
|
||||||
|
#define AX_SWRESET_CLEAR 0x00
|
||||||
|
#define AX_SWRESET_RR 0x01
|
||||||
|
#define AX_SWRESET_RT 0x02
|
||||||
|
#define AX_SWRESET_PRTE 0x04
|
||||||
|
#define AX_SWRESET_PRL 0x08
|
||||||
|
#define AX_SWRESET_BZ 0x10
|
||||||
|
#define AX_SWRESET_IPRL 0x20
|
||||||
|
#define AX_SWRESET_IPPD 0x40
|
||||||
|
|
||||||
|
#define AX88772_IPG0_DEFAULT 0x15
|
||||||
|
#define AX88772_IPG1_DEFAULT 0x0c
|
||||||
|
#define AX88772_IPG2_DEFAULT 0x12
|
||||||
|
|
||||||
|
/* AX88772 & AX88178 Medium Mode Register */
|
||||||
|
#define AX_MEDIUM_PF 0x0080
|
||||||
|
#define AX_MEDIUM_JFE 0x0040
|
||||||
|
#define AX_MEDIUM_TFC 0x0020
|
||||||
|
#define AX_MEDIUM_RFC 0x0010
|
||||||
|
#define AX_MEDIUM_ENCK 0x0008
|
||||||
|
#define AX_MEDIUM_AC 0x0004
|
||||||
|
#define AX_MEDIUM_FD 0x0002
|
||||||
|
#define AX_MEDIUM_GM 0x0001
|
||||||
|
#define AX_MEDIUM_SM 0x1000
|
||||||
|
#define AX_MEDIUM_SBP 0x0800
|
||||||
|
#define AX_MEDIUM_PS 0x0200
|
||||||
|
#define AX_MEDIUM_RE 0x0100
|
||||||
|
|
||||||
|
#define AX88178_MEDIUM_DEFAULT \
|
||||||
|
(AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
|
||||||
|
AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
|
||||||
|
AX_MEDIUM_RE)
|
||||||
|
|
||||||
|
#define AX88772_MEDIUM_DEFAULT \
|
||||||
|
(AX_MEDIUM_FD | AX_MEDIUM_PS | \
|
||||||
|
AX_MEDIUM_AC | AX_MEDIUM_RE)
|
||||||
|
|
||||||
|
/* AX88772 & AX88178 RX_CTL values */
|
||||||
|
#define AX_RX_CTL_SO 0x0080
|
||||||
|
#define AX_RX_CTL_AP 0x0020
|
||||||
|
#define AX_RX_CTL_AM 0x0010
|
||||||
|
#define AX_RX_CTL_AB 0x0008
|
||||||
|
#define AX_RX_CTL_SEP 0x0004
|
||||||
|
#define AX_RX_CTL_AMALL 0x0002
|
||||||
|
#define AX_RX_CTL_PRO 0x0001
|
||||||
|
#define AX_RX_CTL_MFB_2048 0x0000
|
||||||
|
#define AX_RX_CTL_MFB_4096 0x0100
|
||||||
|
#define AX_RX_CTL_MFB_8192 0x0200
|
||||||
|
#define AX_RX_CTL_MFB_16384 0x0300
|
||||||
|
|
||||||
|
#define AX_DEFAULT_RX_CTL (AX_RX_CTL_SO | AX_RX_CTL_AB)
|
||||||
|
|
||||||
|
/* GPIO 0 .. 2 toggles */
|
||||||
|
#define AX_GPIO_GPO0EN 0x01 /* GPIO0 Output enable */
|
||||||
|
#define AX_GPIO_GPO_0 0x02 /* GPIO0 Output value */
|
||||||
|
#define AX_GPIO_GPO1EN 0x04 /* GPIO1 Output enable */
|
||||||
|
#define AX_GPIO_GPO_1 0x08 /* GPIO1 Output value */
|
||||||
|
#define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
|
||||||
|
#define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
|
||||||
|
#define AX_GPIO_RESERVED 0x40 /* Reserved */
|
||||||
|
#define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
|
||||||
|
|
||||||
|
#define AX_EEPROM_MAGIC 0xdeadbeef
|
||||||
|
#define AX_EEPROM_LEN 0x200
|
||||||
|
|
||||||
|
#define AX_EMBD_PHY_ADDR 0x10
|
||||||
|
|
||||||
|
struct usbh_asix {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
struct usb_endpoint_descriptor *intin; /* INTR IN endpoint */
|
||||||
|
struct usbh_urb bulkout_urb;
|
||||||
|
struct usbh_urb bulkin_urb;
|
||||||
|
struct usbh_urb intin_urb;
|
||||||
|
|
||||||
|
uint8_t intf;
|
||||||
|
char *name;
|
||||||
|
uint8_t phy_addr;
|
||||||
|
uint8_t embd_phy;
|
||||||
|
uint8_t chipcode;
|
||||||
|
uint16_t mac_capabilities;
|
||||||
|
|
||||||
|
bool connect_status;
|
||||||
|
uint8_t mac[6];
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_asix_get_connect_status(struct usbh_asix *asix_class);
|
||||||
|
|
||||||
|
void usbh_asix_run(struct usbh_asix *asix_class);
|
||||||
|
void usbh_asix_stop(struct usbh_asix *asix_class);
|
||||||
|
|
||||||
|
int usbh_asix_eth_output(uint8_t *buf, uint32_t buflen);
|
||||||
|
void usbh_asix_eth_input(uint8_t *buf, uint32_t buflen);
|
||||||
|
void usbh_asix_rx_thread(void *argument);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_ASIX_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_RTL8152_H
|
||||||
|
#define USBH_RTL8152_H
|
||||||
|
|
||||||
|
struct usbh_rtl8152 {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
struct usb_endpoint_descriptor *intin; /* INTR IN endpoint */
|
||||||
|
struct usbh_urb bulkout_urb;
|
||||||
|
struct usbh_urb bulkin_urb;
|
||||||
|
struct usbh_urb intin_urb;
|
||||||
|
|
||||||
|
uint8_t intf;
|
||||||
|
|
||||||
|
uint8_t mac[6];
|
||||||
|
bool connect_status;
|
||||||
|
uint32_t speed[2];
|
||||||
|
|
||||||
|
uint8_t version;
|
||||||
|
uint8_t eee_adv;
|
||||||
|
uint8_t eee_en;
|
||||||
|
uint8_t supports_gmii;
|
||||||
|
uint16_t min_mtu;
|
||||||
|
uint16_t max_mtu;
|
||||||
|
uint16_t ocp_base;
|
||||||
|
uint32_t saved_wolopts;
|
||||||
|
uint32_t rx_buf_sz;
|
||||||
|
|
||||||
|
struct rtl_ops {
|
||||||
|
void (*init)(struct usbh_rtl8152 *tp);
|
||||||
|
int (*enable)(struct usbh_rtl8152 *tp);
|
||||||
|
void (*disable)(struct usbh_rtl8152 *tp);
|
||||||
|
void (*up)(struct usbh_rtl8152 *tp);
|
||||||
|
void (*down)(struct usbh_rtl8152 *tp);
|
||||||
|
void (*unload)(struct usbh_rtl8152 *tp);
|
||||||
|
bool (*in_nway)(struct usbh_rtl8152 *tp);
|
||||||
|
void (*hw_phy_cfg)(struct usbh_rtl8152 *tp);
|
||||||
|
void (*autosuspend_en)(struct usbh_rtl8152 *tp, bool enable);
|
||||||
|
void (*change_mtu)(struct usbh_rtl8152 *tp);
|
||||||
|
} rtl_ops;
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_rtl8152_get_connect_status(struct usbh_rtl8152 *rtl8152_class);
|
||||||
|
|
||||||
|
void usbh_rtl8152_run(struct usbh_rtl8152 *rtl8152_class);
|
||||||
|
void usbh_rtl8152_stop(struct usbh_rtl8152 *rtl8152_class);
|
||||||
|
|
||||||
|
int usbh_rtl8152_eth_output(uint8_t *buf, uint32_t buflen);
|
||||||
|
void usbh_rtl8152_eth_input(uint8_t *buf, uint32_t buflen);
|
||||||
|
void usbh_rtl8152_rx_thread(void *argument);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_RTL8152_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_CH34X_H
|
||||||
|
#define USBH_CH34X_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
/* Requests */
|
||||||
|
#define CH34X_READ_VERSION 0x5F
|
||||||
|
#define CH34X_WRITE_REG 0x9A
|
||||||
|
#define CH34X_READ_REG 0x95
|
||||||
|
#define CH34X_SERIAL_INIT 0xA1
|
||||||
|
#define CH34X_MODEM_CTRL 0xA4
|
||||||
|
|
||||||
|
// modem control bits
|
||||||
|
#define CH34X_BIT_RTS (1 << 6)
|
||||||
|
#define CH34X_BIT_DTR (1 << 5)
|
||||||
|
|
||||||
|
#define CH341_CTO_O 0x10
|
||||||
|
#define CH341_CTO_D 0x20
|
||||||
|
#define CH341_CTO_R 0x40
|
||||||
|
#define CH341_CTI_C 0x01
|
||||||
|
#define CH341_CTI_DS 0x02
|
||||||
|
#define CH341_CTRL_RI 0x04
|
||||||
|
#define CH341_CTI_DC 0x08
|
||||||
|
#define CH341_CTI_ST 0x0f
|
||||||
|
|
||||||
|
#define CH341_L_ER 0x80
|
||||||
|
#define CH341_L_ET 0x40
|
||||||
|
#define CH341_L_PS 0x38
|
||||||
|
#define CH341_L_PM 0x28
|
||||||
|
#define CH341_L_PE 0x18
|
||||||
|
#define CH341_L_PO 0x08
|
||||||
|
#define CH341_L_SB 0x04
|
||||||
|
#define CH341_L_D8 0x03
|
||||||
|
#define CH341_L_D7 0x02
|
||||||
|
#define CH341_L_D6 0x01
|
||||||
|
#define CH341_L_D5 0x00
|
||||||
|
|
||||||
|
struct usbh_ch34x {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
struct usbh_urb bulkout_urb;
|
||||||
|
struct usbh_urb bulkin_urb;
|
||||||
|
|
||||||
|
struct cdc_line_coding line_coding;
|
||||||
|
|
||||||
|
uint8_t intf;
|
||||||
|
uint8_t minor;
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_ch34x_set_line_coding(struct usbh_ch34x *ch34x_class, struct cdc_line_coding *line_coding);
|
||||||
|
int usbh_ch34x_get_line_coding(struct usbh_ch34x *ch34x_class, struct cdc_line_coding *line_coding);
|
||||||
|
int usbh_ch34x_set_line_state(struct usbh_ch34x *ch34x_class, bool dtr, bool rts);
|
||||||
|
|
||||||
|
int usbh_ch34x_bulk_in_transfer(struct usbh_ch34x *ch34x_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
|
||||||
|
int usbh_ch34x_bulk_out_transfer(struct usbh_ch34x *ch34x_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
|
||||||
|
|
||||||
|
void usbh_ch34x_run(struct usbh_ch34x *ch34x_class);
|
||||||
|
void usbh_ch34x_stop(struct usbh_ch34x *ch34x_class);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_CH34X_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_CP210X_H
|
||||||
|
#define USBH_CP210X_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
/* Requests */
|
||||||
|
#define CP210X_IFC_ENABLE 0x00
|
||||||
|
#define CP210X_SET_BAUDDIV 0x01
|
||||||
|
#define CP210X_GET_BAUDDIV 0x02
|
||||||
|
#define CP210X_SET_LINE_CTL 0x03 // Set parity, data bits, stop bits
|
||||||
|
#define CP210X_GET_LINE_CTL 0x04
|
||||||
|
#define CP210X_SET_BREAK 0x05
|
||||||
|
#define CP210X_IMM_CHAR 0x06
|
||||||
|
#define CP210X_SET_MHS 0x07 // Set DTR, RTS
|
||||||
|
#define CP210X_GET_MDMSTS 0x08
|
||||||
|
#define CP210X_SET_XON 0x09
|
||||||
|
#define CP210X_SET_XOFF 0x0A
|
||||||
|
#define CP210X_SET_EVENTMASK 0x0B
|
||||||
|
#define CP210X_GET_EVENTMASK 0x0C
|
||||||
|
#define CP210X_SET_CHAR 0x0D
|
||||||
|
#define CP210X_GET_CHARS 0x0E
|
||||||
|
#define CP210X_GET_PROPS 0x0F
|
||||||
|
#define CP210X_GET_COMM_STATUS 0x10
|
||||||
|
#define CP210X_RESET 0x11
|
||||||
|
#define CP210X_PURGE 0x12
|
||||||
|
#define CP210X_SET_FLOW 0x13
|
||||||
|
#define CP210X_GET_FLOW 0x14
|
||||||
|
#define CP210X_EMBED_EVENTS 0x15
|
||||||
|
#define CP210X_GET_EVENTSTATE 0x16
|
||||||
|
#define CP210X_SET_CHARS 0x19
|
||||||
|
#define CP210X_GET_BAUDRATE 0x1D
|
||||||
|
#define CP210X_SET_BAUDRATE 0x1E // Set baudrate
|
||||||
|
#define CP210X_VENDOR_SPECIFIC 0xFF
|
||||||
|
|
||||||
|
struct usbh_cp210x {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
struct usbh_urb bulkout_urb;
|
||||||
|
struct usbh_urb bulkin_urb;
|
||||||
|
|
||||||
|
struct cdc_line_coding line_coding;
|
||||||
|
|
||||||
|
uint8_t intf;
|
||||||
|
uint8_t minor;
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_cp210x_set_line_coding(struct usbh_cp210x *ftdi_class, struct cdc_line_coding *line_coding);
|
||||||
|
int usbh_cp210x_get_line_coding(struct usbh_cp210x *ftdi_class, struct cdc_line_coding *line_coding);
|
||||||
|
int usbh_cp210x_set_line_state(struct usbh_cp210x *ftdi_class, bool dtr, bool rts);
|
||||||
|
|
||||||
|
int usbh_cp210x_bulk_in_transfer(struct usbh_cp210x *cp210x_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
|
||||||
|
int usbh_cp210x_bulk_out_transfer(struct usbh_cp210x *cp210x_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
|
||||||
|
|
||||||
|
void usbh_cp210x_run(struct usbh_cp210x *cp210x_class);
|
||||||
|
void usbh_cp210x_stop(struct usbh_cp210x *cp210x_class);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_CP210X_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_FTDI_H
|
||||||
|
#define USBH_FTDI_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
/* Requests */
|
||||||
|
#define SIO_RESET_REQUEST 0x00 /* Reset the port */
|
||||||
|
#define SIO_SET_MODEM_CTRL_REQUEST 0x01 /* Set the modem control register */
|
||||||
|
#define SIO_SET_FLOW_CTRL_REQUEST 0x02 /* Set flow control register */
|
||||||
|
#define SIO_SET_BAUDRATE_REQUEST 0x03 /* Set baud rate */
|
||||||
|
#define SIO_SET_DATA_REQUEST 0x04 /* Set the data characteristics of the port */
|
||||||
|
#define SIO_POLL_MODEM_STATUS_REQUEST 0x05
|
||||||
|
#define SIO_SET_EVENT_CHAR_REQUEST 0x06
|
||||||
|
#define SIO_SET_ERROR_CHAR_REQUEST 0x07
|
||||||
|
#define SIO_SET_LATENCY_TIMER_REQUEST 0x09
|
||||||
|
#define SIO_GET_LATENCY_TIMER_REQUEST 0x0A
|
||||||
|
#define SIO_SET_BITMODE_REQUEST 0x0B
|
||||||
|
#define SIO_READ_PINS_REQUEST 0x0C
|
||||||
|
#define SIO_READ_EEPROM_REQUEST 0x90
|
||||||
|
#define SIO_WRITE_EEPROM_REQUEST 0x91
|
||||||
|
#define SIO_ERASE_EEPROM_REQUEST 0x92
|
||||||
|
|
||||||
|
#define SIO_DISABLE_FLOW_CTRL 0x0
|
||||||
|
#define SIO_RTS_CTS_HS (0x1 << 8)
|
||||||
|
#define SIO_DTR_DSR_HS (0x2 << 8)
|
||||||
|
#define SIO_XON_XOFF_HS (0x4 << 8)
|
||||||
|
|
||||||
|
#define SIO_SET_DTR_MASK 0x1
|
||||||
|
#define SIO_SET_DTR_HIGH (1 | (SIO_SET_DTR_MASK << 8))
|
||||||
|
#define SIO_SET_DTR_LOW (0 | (SIO_SET_DTR_MASK << 8))
|
||||||
|
#define SIO_SET_RTS_MASK 0x2
|
||||||
|
#define SIO_SET_RTS_HIGH (2 | (SIO_SET_RTS_MASK << 8))
|
||||||
|
#define SIO_SET_RTS_LOW (0 | (SIO_SET_RTS_MASK << 8))
|
||||||
|
|
||||||
|
#define SIO_RTS_CTS_HS (0x1 << 8)
|
||||||
|
|
||||||
|
struct usbh_ftdi {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
struct usbh_urb bulkout_urb;
|
||||||
|
struct usbh_urb bulkin_urb;
|
||||||
|
|
||||||
|
struct cdc_line_coding line_coding;
|
||||||
|
|
||||||
|
uint8_t intf;
|
||||||
|
uint8_t minor;
|
||||||
|
uint8_t modem_status[2];
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_ftdi_set_line_coding(struct usbh_ftdi *ftdi_class, struct cdc_line_coding *line_coding);
|
||||||
|
int usbh_ftdi_get_line_coding(struct usbh_ftdi *ftdi_class, struct cdc_line_coding *line_coding);
|
||||||
|
int usbh_ftdi_set_line_state(struct usbh_ftdi *ftdi_class, bool dtr, bool rts);
|
||||||
|
|
||||||
|
int usbh_ftdi_bulk_in_transfer(struct usbh_ftdi *ftdi_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
|
||||||
|
int usbh_ftdi_bulk_out_transfer(struct usbh_ftdi *ftdi_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
|
||||||
|
|
||||||
|
void usbh_ftdi_run(struct usbh_ftdi *ftdi_class);
|
||||||
|
void usbh_ftdi_stop(struct usbh_ftdi *ftdi_class);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_FTDI_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_PL2303_H
|
||||||
|
#define USBH_PL2303_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
#define PL2303_SET_REQUEST 0x01
|
||||||
|
#define PL2303_SET_REQUEST_PL2303HXN 0x80
|
||||||
|
#define PL2303_SET_CRTSCTS 0x41
|
||||||
|
#define PL2303_SET_CRTSCTS_PL2303X 0x61
|
||||||
|
#define PL2303_SET_CRTSCTS_PL2303HXN 0xFA
|
||||||
|
#define PL2303_CLEAR_CRTSCTS_PL2303HXN 0xFF
|
||||||
|
#define PL2303_CRTSCTS_REG_PL2303HXN 0x0A
|
||||||
|
#define PL2303_STATUS_REG_PL2303HX 0x8080
|
||||||
|
|
||||||
|
/* Different PL2303 IC types */
|
||||||
|
#define USBH_PL2303_TYPE_UNKNOWN 0
|
||||||
|
#define USBH_PL2303_TYPE_PL2303 1
|
||||||
|
#define USBH_PL2303_TYPE_PL2303HX 2
|
||||||
|
#define USBH_PL2303_TYPE_PL2303HXD 3
|
||||||
|
#define USBH_PL2303_TYPE_PL2303HXN 4
|
||||||
|
|
||||||
|
struct usbh_pl2303 {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
|
||||||
|
struct usbh_urb bulkout_urb;
|
||||||
|
struct usbh_urb bulkin_urb;
|
||||||
|
|
||||||
|
struct cdc_line_coding linecoding;
|
||||||
|
|
||||||
|
uint8_t intf;
|
||||||
|
uint8_t minor;
|
||||||
|
uint8_t chiptype;
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_pl2303_set_line_coding(struct usbh_pl2303 *pl2303_class, struct cdc_line_coding *line_coding);
|
||||||
|
int usbh_pl2303_get_line_coding(struct usbh_pl2303 *pl2303_class, struct cdc_line_coding *line_coding);
|
||||||
|
int usbh_pl2303_set_line_state(struct usbh_pl2303 *pl2303_class, bool dtr, bool rts);
|
||||||
|
|
||||||
|
int usbh_pl2303_bulk_in_transfer(struct usbh_pl2303 *pl2303_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
|
||||||
|
int usbh_pl2303_bulk_out_transfer(struct usbh_pl2303 *pl2303_class, uint8_t *buffer, uint32_t buflen, uint32_t timeout);
|
||||||
|
|
||||||
|
void usbh_pl2303_run(struct usbh_pl2303 *pl2303_class);
|
||||||
|
void usbh_pl2303_stop(struct usbh_pl2303 *pl2303_class);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_PL2303_H */
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBD_VIDEO_H
|
||||||
|
#define USBD_VIDEO_H
|
||||||
|
|
||||||
|
#include "usb_video.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Init video interface driver */
|
||||||
|
struct usbd_interface *usbd_video_init_intf(uint8_t busid, struct usbd_interface *intf,
|
||||||
|
uint32_t dwFrameInterval,
|
||||||
|
uint32_t dwMaxVideoFrameSize,
|
||||||
|
uint32_t dwMaxPayloadTransferSize);
|
||||||
|
|
||||||
|
void usbd_video_open(uint8_t busid, uint8_t intf);
|
||||||
|
void usbd_video_close(uint8_t busid, uint8_t intf);
|
||||||
|
uint32_t usbd_video_mjpeg_payload_fill(uint8_t busid, uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBD_VIDEO_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_VIDEO_H
|
||||||
|
#define USBH_VIDEO_H
|
||||||
|
|
||||||
|
#include "usb_video.h"
|
||||||
|
|
||||||
|
#define USBH_VIDEO_FORMAT_UNCOMPRESSED 0
|
||||||
|
#define USBH_VIDEO_FORMAT_MJPEG 1
|
||||||
|
|
||||||
|
struct usbh_video_resolution {
|
||||||
|
uint16_t wWidth;
|
||||||
|
uint16_t wHeight;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usbh_video_format {
|
||||||
|
struct usbh_video_resolution frame[12];
|
||||||
|
uint8_t format_type;
|
||||||
|
uint8_t num_of_frames;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usbh_videoframe {
|
||||||
|
uint8_t *frame_buf;
|
||||||
|
uint32_t frame_bufsize;
|
||||||
|
uint32_t frame_format;
|
||||||
|
uint32_t frame_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usbh_videostreaming {
|
||||||
|
struct usbh_videoframe *frame;
|
||||||
|
uint32_t frame_format;
|
||||||
|
uint32_t bufoffset;
|
||||||
|
uint16_t width;
|
||||||
|
uint16_t height;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usbh_video {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *isoin; /* ISO IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *isoout; /* ISO OUT endpoint */
|
||||||
|
|
||||||
|
uint8_t ctrl_intf; /* interface number */
|
||||||
|
uint8_t data_intf; /* interface number */
|
||||||
|
uint8_t minor;
|
||||||
|
struct video_probe_and_commit_controls probe;
|
||||||
|
struct video_probe_and_commit_controls commit;
|
||||||
|
uint16_t isoin_mps;
|
||||||
|
uint16_t isoout_mps;
|
||||||
|
bool is_opened;
|
||||||
|
uint8_t current_format;
|
||||||
|
uint16_t bcdVDC;
|
||||||
|
uint8_t num_of_intf_altsettings;
|
||||||
|
uint8_t num_of_formats;
|
||||||
|
struct usbh_video_format format[3];
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_video_get(struct usbh_video *video_class, uint8_t request, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len);
|
||||||
|
int usbh_video_set(struct usbh_video *video_class, uint8_t request, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len);
|
||||||
|
|
||||||
|
int usbh_video_open(struct usbh_video *video_class,
|
||||||
|
uint8_t format_type,
|
||||||
|
uint16_t wWidth,
|
||||||
|
uint16_t wHeight,
|
||||||
|
uint8_t altsetting);
|
||||||
|
int usbh_video_close(struct usbh_video *video_class);
|
||||||
|
|
||||||
|
void usbh_video_list_info(struct usbh_video *video_class);
|
||||||
|
|
||||||
|
void usbh_video_run(struct usbh_video *video_class);
|
||||||
|
void usbh_video_stop(struct usbh_video *video_class);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_VIDEO_H */
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBD_RNDIS_H
|
||||||
|
#define USBD_RNDIS_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Init rndis interface driver */
|
||||||
|
struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf,
|
||||||
|
const uint8_t out_ep,
|
||||||
|
const uint8_t in_ep,
|
||||||
|
const uint8_t int_ep, uint8_t mac[6]);
|
||||||
|
|
||||||
|
void usbd_rndis_data_recv_done(void);
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBDEV_RNDIS_USING_LWIP
|
||||||
|
struct pbuf *usbd_rndis_eth_rx(void);
|
||||||
|
int usbd_rndis_eth_tx(struct pbuf *p);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBD_RNDIS_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_BLUETOOTH_H
|
||||||
|
#define USBH_BLUETOOTH_H
|
||||||
|
|
||||||
|
#define USB_BLUETOOTH_HCI_NONE 0x00
|
||||||
|
#define USB_BLUETOOTH_HCI_CMD 0x01
|
||||||
|
#define USB_BLUETOOTH_HCI_ACL 0x02
|
||||||
|
#define USB_BLUETOOTH_HCI_SCO 0x03
|
||||||
|
#define USB_BLUETOOTH_HCI_EVT 0x04
|
||||||
|
#define USB_BLUETOOTH_HCI_ISO 0x05
|
||||||
|
|
||||||
|
struct usbh_bluetooth {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
uint8_t intf;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
struct usbh_urb bulkin_urb; /* Bulk IN urb */
|
||||||
|
struct usbh_urb bulkout_urb; /* Bulk OUT urb */
|
||||||
|
#ifndef CONFIG_USBHOST_BLUETOOTH_HCI_H4
|
||||||
|
struct usb_endpoint_descriptor *intin; /* INTR endpoint */
|
||||||
|
struct usb_endpoint_descriptor *isoin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *isoout; /* Bulk OUT endpoint */
|
||||||
|
struct usbh_urb intin_urb; /* INTR IN urb */
|
||||||
|
struct usbh_urb *isoin_urb; /* Bulk IN urb */
|
||||||
|
struct usbh_urb *isoout_urb; /* Bulk OUT urb */
|
||||||
|
uint8_t num_of_intf_altsettings;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_bluetooth_hci_write(uint8_t hci_type, uint8_t *buffer, uint32_t buflen);
|
||||||
|
void usbh_bluetooth_hci_read_callback(uint8_t *data, uint32_t len);
|
||||||
|
#ifdef CONFIG_USBHOST_BLUETOOTH_HCI_H4
|
||||||
|
void usbh_bluetooth_hci_rx_thread(void *argument);
|
||||||
|
#else
|
||||||
|
void usbh_bluetooth_hci_evt_rx_thread(void *argument);
|
||||||
|
void usbh_bluetooth_hci_acl_rx_thread(void *argument);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void usbh_bluetooth_run(struct usbh_bluetooth *bluetooth_class);
|
||||||
|
void usbh_bluetooth_stop(struct usbh_bluetooth *bluetooth_class);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_BLUETOOTH_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USBH_RNDIS_H
|
||||||
|
#define USBH_RNDIS_H
|
||||||
|
|
||||||
|
#include "usb_cdc.h"
|
||||||
|
|
||||||
|
struct usbh_rndis {
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||||
|
struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
|
||||||
|
struct usb_endpoint_descriptor *intin; /* INTR endpoint */
|
||||||
|
struct usbh_urb bulkin_urb; /* Bulk IN urb */
|
||||||
|
struct usbh_urb bulkout_urb; /* Bulk OUT urb */
|
||||||
|
struct usbh_urb intin_urb; /* INTR IN urb */
|
||||||
|
|
||||||
|
uint8_t ctrl_intf; /* Control interface number */
|
||||||
|
uint8_t data_intf; /* Data interface number */
|
||||||
|
uint8_t minor;
|
||||||
|
|
||||||
|
uint32_t request_id;
|
||||||
|
|
||||||
|
uint32_t link_speed;
|
||||||
|
bool connect_status;
|
||||||
|
uint8_t mac[6];
|
||||||
|
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int usbh_rndis_get_connect_status(struct usbh_rndis *rndis_class);
|
||||||
|
int usbh_rndis_keepalive(struct usbh_rndis *rndis_class);
|
||||||
|
|
||||||
|
void usbh_rndis_run(struct usbh_rndis *rndis_class);
|
||||||
|
void usbh_rndis_stop(struct usbh_rndis *rndis_class);
|
||||||
|
|
||||||
|
int usbh_rndis_eth_output(uint8_t *buf, uint32_t buflen);
|
||||||
|
void usbh_rndis_eth_input(uint8_t *buf, uint32_t buflen);
|
||||||
|
void usbh_rndis_rx_thread(void *argument);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBH_RNDIS_H */
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USB_DC_H
|
||||||
|
#define USB_DC_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief init device controller registers.
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usb_dc_init(uint8_t busid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief deinit device controller registers.
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usb_dc_deinit(uint8_t busid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set USB device address
|
||||||
|
*
|
||||||
|
* @param[in] addr Device address
|
||||||
|
*
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usbd_set_address(uint8_t busid, const uint8_t addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get USB device speed
|
||||||
|
*
|
||||||
|
* @param[in] busid bus index
|
||||||
|
*
|
||||||
|
* @return port speed, USB_SPEED_LOW or USB_SPEED_FULL or USB_SPEED_HIGH
|
||||||
|
*/
|
||||||
|
uint8_t usbd_get_port_speed(uint8_t busid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief configure and enable endpoint.
|
||||||
|
*
|
||||||
|
* @param [in] ep_cfg Endpoint config.
|
||||||
|
*
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Disable the selected endpoint
|
||||||
|
*
|
||||||
|
* @param[in] ep Endpoint address
|
||||||
|
*
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usbd_ep_close(uint8_t busid, const uint8_t ep);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set stall condition for the selected endpoint
|
||||||
|
*
|
||||||
|
* @param[in] ep Endpoint address
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clear stall condition for the selected endpoint
|
||||||
|
*
|
||||||
|
* @param[in] ep Endpoint address corresponding to the one
|
||||||
|
* listed in the device configuration table
|
||||||
|
*
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if the selected endpoint is stalled
|
||||||
|
*
|
||||||
|
* @param[in] ep Endpoint address
|
||||||
|
*
|
||||||
|
* @param[out] stalled Endpoint stall status
|
||||||
|
*
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Setup in ep transfer setting and start transfer.
|
||||||
|
*
|
||||||
|
* This function is asynchronous.
|
||||||
|
* This function is similar to uart with tx dma.
|
||||||
|
*
|
||||||
|
* This function is called to write data to the specified endpoint. The
|
||||||
|
* supplied usbd_endpoint_callback function will be called when data is transmitted
|
||||||
|
* out.
|
||||||
|
*
|
||||||
|
* @param[in] ep Endpoint address corresponding to the one
|
||||||
|
* listed in the device configuration table
|
||||||
|
* @param[in] data Pointer to data to write
|
||||||
|
* @param[in] data_len Length of the data requested to write. This may
|
||||||
|
* be zero for a zero length status packet.
|
||||||
|
* @return 0 on success, negative errno code on fail.
|
||||||
|
*/
|
||||||
|
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Setup out ep transfer setting and start transfer.
|
||||||
|
*
|
||||||
|
* This function is asynchronous.
|
||||||
|
* This function is similar to uart with rx dma.
|
||||||
|
*
|
||||||
|
* This function is called to read data to the specified endpoint. The
|
||||||
|
* supplied usbd_endpoint_callback function will be called when data is received
|
||||||
|
* in.
|
||||||
|
*
|
||||||
|
* @param[in] ep Endpoint address corresponding to the one
|
||||||
|
* listed in the device configuration table
|
||||||
|
* @param[in] data Pointer to data to read
|
||||||
|
* @param[in] data_len Max length of the data requested to read.
|
||||||
|
*
|
||||||
|
* @return 0 on success, negative errno code on fail.
|
||||||
|
*/
|
||||||
|
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len);
|
||||||
|
|
||||||
|
/* usb dcd irq callback */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Usb connect irq callback.
|
||||||
|
*/
|
||||||
|
void usbd_event_connect_handler(uint8_t busid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Usb disconnect irq callback.
|
||||||
|
*/
|
||||||
|
void usbd_event_disconnect_handler(uint8_t busid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Usb resume irq callback.
|
||||||
|
*/
|
||||||
|
void usbd_event_resume_handler(uint8_t busid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Usb suspend irq callback.
|
||||||
|
*/
|
||||||
|
void usbd_event_suspend_handler(uint8_t busid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Usb reset irq callback.
|
||||||
|
*/
|
||||||
|
void usbd_event_reset_handler(uint8_t busid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Usb setup packet recv irq callback.
|
||||||
|
* @param[in] psetup setup packet.
|
||||||
|
*/
|
||||||
|
void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief In ep transfer complete irq callback.
|
||||||
|
* @param[in] ep Endpoint address corresponding to the one
|
||||||
|
* listed in the device configuration table
|
||||||
|
* @param[in] nbytes How many nbytes have transferred.
|
||||||
|
*/
|
||||||
|
void usbd_event_ep_in_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Out ep transfer complete irq callback.
|
||||||
|
* @param[in] ep Endpoint address corresponding to the one
|
||||||
|
* listed in the device configuration table
|
||||||
|
* @param[in] nbytes How many nbytes have transferred.
|
||||||
|
*/
|
||||||
|
void usbd_event_ep_out_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes);
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBDEV_TEST_MODE
|
||||||
|
/**
|
||||||
|
* @brief Usb execute test mode
|
||||||
|
* @param[in] busid device busid
|
||||||
|
* @param[in] test_mode usb test mode
|
||||||
|
*/
|
||||||
|
void usbd_execute_test_mode(uint8_t busid, uint8_t test_mode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USB_DC_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USB_ERRNO_H
|
||||||
|
#define USB_ERRNO_H
|
||||||
|
|
||||||
|
#define USB_ERR_NOMEM 1
|
||||||
|
#define USB_ERR_INVAL 2
|
||||||
|
#define USB_ERR_NODEV 3
|
||||||
|
#define USB_ERR_NOTCONN 4
|
||||||
|
#define USB_ERR_NOTSUPP 5
|
||||||
|
#define USB_ERR_BUSY 6
|
||||||
|
#define USB_ERR_RANGE 7
|
||||||
|
#define USB_ERR_STALL 8
|
||||||
|
#define USB_ERR_BABBLE 9
|
||||||
|
#define USB_ERR_NAK 10
|
||||||
|
#define USB_ERR_DT 11
|
||||||
|
#define USB_ERR_IO 12
|
||||||
|
#define USB_ERR_SHUTDOWN 13
|
||||||
|
#define USB_ERR_TIMEOUT 14
|
||||||
|
|
||||||
|
#endif /* USB_ERRNO_H */
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef USB_HC_H
|
||||||
|
#define USB_HC_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef void (*usbh_complete_callback_t)(void *arg, int nbytes);
|
||||||
|
|
||||||
|
struct usbh_bus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USB Iso Configuration.
|
||||||
|
*
|
||||||
|
* Structure containing the USB Iso configuration.
|
||||||
|
*/
|
||||||
|
struct usbh_iso_frame_packet {
|
||||||
|
uint8_t *transfer_buffer;
|
||||||
|
uint32_t transfer_buffer_length;
|
||||||
|
uint32_t actual_length;
|
||||||
|
int errorcode;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USB Urb Configuration.
|
||||||
|
*
|
||||||
|
* Structure containing the USB Urb configuration.
|
||||||
|
*/
|
||||||
|
struct usbh_urb {
|
||||||
|
void *hcpriv;
|
||||||
|
struct usbh_hubport *hport;
|
||||||
|
struct usb_endpoint_descriptor *ep;
|
||||||
|
uint8_t data_toggle;
|
||||||
|
uint8_t interval;
|
||||||
|
struct usb_setup_packet *setup;
|
||||||
|
uint8_t *transfer_buffer;
|
||||||
|
uint32_t transfer_buffer_length;
|
||||||
|
int transfer_flags;
|
||||||
|
uint32_t actual_length;
|
||||||
|
uint32_t timeout;
|
||||||
|
int errorcode;
|
||||||
|
uint32_t num_of_iso_packets;
|
||||||
|
uint32_t start_frame;
|
||||||
|
usbh_complete_callback_t complete;
|
||||||
|
void *arg;
|
||||||
|
#if defined(__ICCARM__) || defined(__ICCRISCV__) || defined(__ICCRX__)
|
||||||
|
struct usbh_iso_frame_packet *iso_packet;
|
||||||
|
#else
|
||||||
|
struct usbh_iso_frame_packet iso_packet[0];
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief usb host controller hardware init.
|
||||||
|
*
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usb_hc_init(struct usbh_bus *bus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief usb host controller hardware deinit.
|
||||||
|
*
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usb_hc_deinit(struct usbh_bus *bus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get frame number.
|
||||||
|
*
|
||||||
|
* @return frame number.
|
||||||
|
*/
|
||||||
|
uint16_t usbh_get_frame_number(struct usbh_bus *bus);
|
||||||
|
/**
|
||||||
|
* @brief control roothub.
|
||||||
|
*
|
||||||
|
* @param setup setup request buffer.
|
||||||
|
* @param buf buf for reading response or write data.
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usbh_roothub_control(struct usbh_bus *bus, struct usb_setup_packet *setup, uint8_t *buf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Submit a usb transfer request to an endpoint.
|
||||||
|
*
|
||||||
|
* If timeout is not zero, this function will be in poll transfer mode,
|
||||||
|
* otherwise will be in async transfer mode.
|
||||||
|
*
|
||||||
|
* @param urb Usb request block.
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usbh_submit_urb(struct usbh_urb *urb);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Cancel a transfer request.
|
||||||
|
*
|
||||||
|
* This function will call When calls usbh_submit_urb and return -USB_ERR_TIMEOUT or -USB_ERR_SHUTDOWN.
|
||||||
|
*
|
||||||
|
* @param urb Usb request block.
|
||||||
|
* @return On success will return 0, and others indicate fail.
|
||||||
|
*/
|
||||||
|
int usbh_kill_urb(struct usbh_urb *urb);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USB_HC_H */
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user