Compare commits
232 Commits
v1.4.1
...
v1.5.0-rc2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
537ccfd945 | ||
|
|
6973ec73d9 | ||
|
|
1feaed024e | ||
|
|
88cbed9807 | ||
|
|
1d95077161 | ||
|
|
06a0c4393b | ||
|
|
6b7d755d3a | ||
|
|
078e7d1be0 | ||
|
|
ac4e4c569d | ||
|
|
b6650bdbc6 | ||
|
|
bff8a632a9 | ||
|
|
a8bf2687bd | ||
|
|
0251e3a145 | ||
|
|
f7c354b4eb | ||
|
|
ff42a6f2ea | ||
|
|
ca71e7411e | ||
|
|
16858c105a | ||
|
|
8c5026e9cb | ||
|
|
8a81d81435 | ||
|
|
c75e62c1e9 | ||
|
|
5a6023118e | ||
|
|
51ad3717c5 | ||
|
|
0ee859d339 | ||
|
|
e6d81344c3 | ||
|
|
af6df63acb | ||
|
|
b4fb10ee98 | ||
|
|
e3c50cde10 | ||
|
|
e65b8c0614 | ||
|
|
f9189b4278 | ||
|
|
51ea604ded | ||
|
|
fe24f8d4ba | ||
|
|
5fed8b7d05 | ||
|
|
45ccc810d2 | ||
|
|
7e5713ab89 | ||
|
|
05e5730cc2 | ||
|
|
d6f912c48d | ||
|
|
7465a59eaa | ||
|
|
e301e1f0a9 | ||
|
|
401dded10a | ||
|
|
03fc8b668a | ||
|
|
edc0c95db2 | ||
|
|
10e7fb60b4 | ||
|
|
619fb4fa5b | ||
|
|
eadcf7530b | ||
|
|
43692c0ba2 | ||
|
|
383d9b3141 | ||
|
|
01a25c7d93 | ||
|
|
5e45d15292 | ||
|
|
b19f70575a | ||
|
|
4f831f58ef | ||
|
|
684041f285 | ||
|
|
dbfcdb55af | ||
|
|
dd4c4fe180 | ||
|
|
3a028f7acf | ||
|
|
8c100cdccd | ||
|
|
6064c0beef | ||
|
|
dc5e8dc5ed | ||
|
|
4d3770b5d0 | ||
|
|
336aa91d24 | ||
|
|
7a0e8cae1a | ||
|
|
a92b5488b0 | ||
|
|
5253d5aa6b | ||
|
|
8393ed986a | ||
|
|
19f7548b60 | ||
|
|
ba2f91f24c | ||
|
|
2d8c4ca56a | ||
|
|
0ba374253b | ||
|
|
7affefe7f9 | ||
|
|
910f1f64ad | ||
|
|
96cbbfc1be | ||
|
|
9d06a940f0 | ||
|
|
c659bdc604 | ||
|
|
40f164e81e | ||
|
|
e0289d79f9 | ||
|
|
6516a470c8 | ||
|
|
bf2ba7324a | ||
|
|
cf22bcf252 | ||
|
|
d122f2d8f7 | ||
|
|
d012974a0e | ||
|
|
609305a28f | ||
|
|
d4dfb03afc | ||
|
|
a41000a000 | ||
|
|
e29d87bb20 | ||
|
|
93a8457700 | ||
|
|
3f736a3622 | ||
|
|
ccbe0232dc | ||
|
|
9aa7a76353 | ||
|
|
8bc602dc74 | ||
|
|
51ef13d217 | ||
|
|
7d93f7d0f0 | ||
|
|
5990e5c607 | ||
|
|
577ebd0999 | ||
|
|
c27458d71a | ||
|
|
644ac2b37f | ||
|
|
d3de69ae38 | ||
|
|
33dd56b7ce | ||
|
|
8aad86f66b | ||
|
|
0c3a64516d | ||
|
|
95d968bd57 | ||
|
|
4edd86c872 | ||
|
|
166795bd72 | ||
|
|
a838edb3e6 | ||
|
|
894b80d9ed | ||
|
|
4c8d448ca2 | ||
|
|
4897d6d622 | ||
|
|
e0fedaa956 | ||
|
|
d10b88c1a1 | ||
|
|
dd8ec4bbcf | ||
|
|
e6fb6af4a9 | ||
|
|
947f8530ef | ||
|
|
73c8062518 | ||
|
|
3f190b127d | ||
|
|
215db93943 | ||
|
|
c916f63bc3 | ||
|
|
8392ba6810 | ||
|
|
e5989ee41a | ||
|
|
364eb60396 | ||
|
|
dae76cb7bd | ||
|
|
339a99a728 | ||
|
|
6f25f797ed | ||
|
|
9a26c50900 | ||
|
|
91684e0677 | ||
|
|
4a9c90ddc0 | ||
|
|
83695e77cf | ||
|
|
5666fcb540 | ||
|
|
e9257baa5d | ||
|
|
f48fa44368 | ||
|
|
d9c0d27174 | ||
|
|
44dc3c00f6 | ||
|
|
4d5aa30778 | ||
|
|
e581097309 | ||
|
|
6378fb88d0 | ||
|
|
db0f5475b4 | ||
|
|
27c307abed | ||
|
|
374e6d6e4d | ||
|
|
c09ceb2537 | ||
|
|
56afada2cc | ||
|
|
8ac0b65b30 | ||
|
|
68434ccf7d | ||
|
|
17a591f719 | ||
|
|
23d2327a52 | ||
|
|
de7a73bc2f | ||
|
|
147dc4ab5d | ||
|
|
20c298b6ba | ||
|
|
0c5d2ad729 | ||
|
|
e90b29c2e7 | ||
|
|
ac6db49d00 | ||
|
|
43e6b5b1b1 | ||
|
|
40122200d1 | ||
|
|
e85d898503 | ||
|
|
e592a548e9 | ||
|
|
afc9213cd1 | ||
|
|
0826c164da | ||
|
|
609c85db68 | ||
|
|
d3aafb2174 | ||
|
|
95baa7845c | ||
|
|
c827c2e50b | ||
|
|
49d9775a1b | ||
|
|
5573472397 | ||
|
|
fd033f25c5 | ||
|
|
3e9f2b7777 | ||
|
|
efbfc9d70f | ||
|
|
f447de38dc | ||
|
|
8f44b8bad8 | ||
|
|
c399be3ea2 | ||
|
|
1aa2d038aa | ||
|
|
6769eac6e0 | ||
|
|
646e84bedc | ||
|
|
322595b910 | ||
|
|
ea27f5b238 | ||
|
|
d4940ebd22 | ||
|
|
e1398982f3 | ||
|
|
76b7a0172b | ||
|
|
6c3b828e77 | ||
|
|
0a295ee5eb | ||
|
|
5b74cecc4a | ||
|
|
99e2e6bfd4 | ||
|
|
64394bf246 | ||
|
|
1a1b475523 | ||
|
|
a1ac569236 | ||
|
|
570d2b5ff8 | ||
|
|
cc9c226aba | ||
|
|
1be34f4d36 | ||
|
|
515b83e0f8 | ||
|
|
be6537637c | ||
|
|
e6801fcbb8 | ||
|
|
75e6dc6300 | ||
|
|
effee4d4c2 | ||
|
|
05b46c8bad | ||
|
|
ddc19a9d65 | ||
|
|
886f1ec6b4 | ||
|
|
7980cb056c | ||
|
|
f86443a70b | ||
|
|
bfc1139d80 | ||
|
|
8d2afc1540 | ||
|
|
87b8a4ad7f | ||
|
|
9ff35e9020 | ||
|
|
a03a9cd481 | ||
|
|
88d57eb99b | ||
|
|
5850e27743 | ||
|
|
015aa77487 | ||
|
|
4416dfa5cf | ||
|
|
d874bed6aa | ||
|
|
7f75da270f | ||
|
|
1a39169f6e | ||
|
|
82a0d243f8 | ||
|
|
ac3be8cb3a | ||
|
|
a72ecd2202 | ||
|
|
c6bdacee6d | ||
|
|
ea03856337 | ||
|
|
1c1217f8fa | ||
|
|
093a1836f0 | ||
|
|
70ef616676 | ||
|
|
6517919bd2 | ||
|
|
2b72d8c6d8 | ||
|
|
261502f3b2 | ||
|
|
e3ff8ffe6a | ||
|
|
24fc172ad8 | ||
|
|
58d552d03d | ||
|
|
d0edc30c11 | ||
|
|
6ea1e2f94f | ||
|
|
037c2a8323 | ||
|
|
608ee773de | ||
|
|
c51a6f35a6 | ||
|
|
a13bee0663 | ||
|
|
fd1baa62df | ||
|
|
6e6fdda62a | ||
|
|
f02ff21cfb | ||
|
|
d6aae26371 | ||
|
|
77136aa743 | ||
|
|
4784017f56 | ||
|
|
149fb046bc |
311
.cmake-format.json
Normal file
311
.cmake-format.json
Normal file
@@ -0,0 +1,311 @@
|
||||
{
|
||||
"_help_parse": "Options affecting listfile parsing",
|
||||
"parse": {
|
||||
"_help_additional_commands": [
|
||||
"Specify structure for custom cmake functions"
|
||||
],
|
||||
"additional_commands": {
|
||||
"foo": {
|
||||
"flags": [
|
||||
"BAR",
|
||||
"BAZ"
|
||||
],
|
||||
"kwargs": {
|
||||
"HEADERS": "*",
|
||||
"SOURCES": "*",
|
||||
"DEPENDS": "*"
|
||||
}
|
||||
}
|
||||
},
|
||||
"_help_override_spec": [
|
||||
"Override configurations per-command where available"
|
||||
],
|
||||
"override_spec": {},
|
||||
"_help_vartags": [
|
||||
"Specify variable tags."
|
||||
],
|
||||
"vartags": [],
|
||||
"_help_proptags": [
|
||||
"Specify property tags."
|
||||
],
|
||||
"proptags": []
|
||||
},
|
||||
"_help_format": "Options affecting formatting.",
|
||||
"format": {
|
||||
"_help_disable": [
|
||||
"Disable formatting entirely, making cmake-format a no-op"
|
||||
],
|
||||
"disable": false,
|
||||
"_help_line_width": [
|
||||
"How wide to allow formatted cmake files"
|
||||
],
|
||||
"line_width": 120,
|
||||
"_help_tab_size": [
|
||||
"How many spaces to tab for indent"
|
||||
],
|
||||
"tab_size": 4,
|
||||
"_help_use_tabchars": [
|
||||
"If true, lines are indented using tab characters (utf-8",
|
||||
"0x09) instead of <tab_size> space characters (utf-8 0x20).",
|
||||
"In cases where the layout would require a fractional tab",
|
||||
"character, the behavior of the fractional indentation is",
|
||||
"governed by <fractional_tab_policy>"
|
||||
],
|
||||
"use_tabchars": false,
|
||||
"_help_fractional_tab_policy": [
|
||||
"If <use_tabchars> is True, then the value of this variable",
|
||||
"indicates how fractional indentions are handled during",
|
||||
"whitespace replacement. If set to 'use-space', fractional",
|
||||
"indentation is left as spaces (utf-8 0x20). If set to",
|
||||
"`round-up` fractional indentation is replaced with a single",
|
||||
"tab character (utf-8 0x09) effectively shifting the column",
|
||||
"to the next tabstop"
|
||||
],
|
||||
"fractional_tab_policy": "use-space",
|
||||
"_help_max_subgroups_hwrap": [
|
||||
"If an argument group contains more than this many sub-groups",
|
||||
"(parg or kwarg groups) then force it to a vertical layout."
|
||||
],
|
||||
"max_subgroups_hwrap": 2,
|
||||
"_help_max_pargs_hwrap": [
|
||||
"If a positional argument group contains more than this many",
|
||||
"arguments, then force it to a vertical layout."
|
||||
],
|
||||
"max_pargs_hwrap": 6,
|
||||
"_help_max_rows_cmdline": [
|
||||
"If a cmdline positional group consumes more than this many",
|
||||
"lines without nesting, then invalidate the layout (and nest)"
|
||||
],
|
||||
"max_rows_cmdline": 2,
|
||||
"_help_separate_ctrl_name_with_space": [
|
||||
"If true, separate flow control names from their parentheses",
|
||||
"with a space"
|
||||
],
|
||||
"separate_ctrl_name_with_space": false,
|
||||
"_help_separate_fn_name_with_space": [
|
||||
"If true, separate function names from parentheses with a",
|
||||
"space"
|
||||
],
|
||||
"separate_fn_name_with_space": false,
|
||||
"_help_dangle_parens": [
|
||||
"If a statement is wrapped to more than one line, than dangle",
|
||||
"the closing parenthesis on its own line."
|
||||
],
|
||||
"dangle_parens": true,
|
||||
"_help_dangle_align": [
|
||||
"If the trailing parenthesis must be 'dangled' on its on",
|
||||
"line, then align it to this reference: `prefix`: the start",
|
||||
"of the statement, `prefix-indent`: the start of the",
|
||||
"statement, plus one indentation level, `child`: align to",
|
||||
"the column of the arguments"
|
||||
],
|
||||
"dangle_align": "prefix",
|
||||
"_help_min_prefix_chars": [
|
||||
"If the statement spelling length (including space and",
|
||||
"parenthesis) is smaller than this amount, then force reject",
|
||||
"nested layouts."
|
||||
],
|
||||
"min_prefix_chars": 4,
|
||||
"_help_max_prefix_chars": [
|
||||
"If the statement spelling length (including space and",
|
||||
"parenthesis) is larger than the tab width by more than this",
|
||||
"amount, then force reject un-nested layouts."
|
||||
],
|
||||
"max_prefix_chars": 10,
|
||||
"_help_max_lines_hwrap": [
|
||||
"If a candidate layout is wrapped horizontally but it exceeds",
|
||||
"this many lines, then reject the layout."
|
||||
],
|
||||
"max_lines_hwrap": 2,
|
||||
"_help_line_ending": [
|
||||
"What style line endings to use in the output."
|
||||
],
|
||||
"line_ending": "unix",
|
||||
"_help_command_case": [
|
||||
"Format command names consistently as 'lower' or 'upper' case"
|
||||
],
|
||||
"command_case": "canonical",
|
||||
"_help_keyword_case": [
|
||||
"Format keywords consistently as 'lower' or 'upper' case"
|
||||
],
|
||||
"keyword_case": "unchanged",
|
||||
"_help_always_wrap": [
|
||||
"A list of command names which should always be wrapped"
|
||||
],
|
||||
"always_wrap": [],
|
||||
"_help_enable_sort": [
|
||||
"If true, the argument lists which are known to be sortable",
|
||||
"will be sorted lexicographicall"
|
||||
],
|
||||
"enable_sort": true,
|
||||
"_help_autosort": [
|
||||
"If true, the parsers may infer whether or not an argument",
|
||||
"list is sortable (without annotation)."
|
||||
],
|
||||
"autosort": false,
|
||||
"_help_require_valid_layout": [
|
||||
"By default, if cmake-format cannot successfully fit",
|
||||
"everything into the desired linewidth it will apply the",
|
||||
"last, most agressive attempt that it made. If this flag is",
|
||||
"True, however, cmake-format will print error, exit with non-",
|
||||
"zero status code, and write-out nothing"
|
||||
],
|
||||
"require_valid_layout": false,
|
||||
"_help_layout_passes": [
|
||||
"A dictionary mapping layout nodes to a list of wrap",
|
||||
"decisions. See the documentation for more information."
|
||||
],
|
||||
"layout_passes": {}
|
||||
},
|
||||
"_help_markup": "Options affecting comment reflow and formatting.",
|
||||
"markup": {
|
||||
"_help_bullet_char": [
|
||||
"What character to use for bulleted lists"
|
||||
],
|
||||
"bullet_char": "*",
|
||||
"_help_enum_char": [
|
||||
"What character to use as punctuation after numerals in an",
|
||||
"enumerated list"
|
||||
],
|
||||
"enum_char": ".",
|
||||
"_help_first_comment_is_literal": [
|
||||
"If comment markup is enabled, don't reflow the first comment",
|
||||
"block in each listfile. Use this to preserve formatting of",
|
||||
"your copyright/license statements."
|
||||
],
|
||||
"first_comment_is_literal": true,
|
||||
"_help_literal_comment_pattern": [
|
||||
"If comment markup is enabled, don't reflow any comment block",
|
||||
"which matches this (regex) pattern. Default is `None`",
|
||||
"(disabled)."
|
||||
],
|
||||
"literal_comment_pattern": null,
|
||||
"_help_fence_pattern": [
|
||||
"Regular expression to match preformat fences in comments",
|
||||
"default= ``r'^\\s*([`~]{3}[`~]*)(.*)$'``"
|
||||
],
|
||||
"fence_pattern": "^\\s*([`~]{3}[`~]*)(.*)$",
|
||||
"_help_ruler_pattern": [
|
||||
"Regular expression to match rulers in comments default=",
|
||||
"``r'^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'``"
|
||||
],
|
||||
"ruler_pattern": "^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$",
|
||||
"_help_explicit_trailing_pattern": [
|
||||
"If a comment line matches starts with this pattern then it",
|
||||
"is explicitly a trailing comment for the preceeding",
|
||||
"argument. Default is '#<'"
|
||||
],
|
||||
"explicit_trailing_pattern": "#<",
|
||||
"_help_hashruler_min_length": [
|
||||
"If a comment line starts with at least this many consecutive",
|
||||
"hash characters, then don't lstrip() them off. This allows",
|
||||
"for lazy hash rulers where the first hash char is not",
|
||||
"separated by space"
|
||||
],
|
||||
"hashruler_min_length": 10,
|
||||
"_help_canonicalize_hashrulers": [
|
||||
"If true, then insert a space between the first hash char and",
|
||||
"remaining hash chars in a hash ruler, and normalize its",
|
||||
"length to fill the column"
|
||||
],
|
||||
"canonicalize_hashrulers": true,
|
||||
"_help_enable_markup": [
|
||||
"enable comment markup parsing and reflow"
|
||||
],
|
||||
"enable_markup": true
|
||||
},
|
||||
"_help_lint": "Options affecting the linter",
|
||||
"lint": {
|
||||
"_help_disabled_codes": [
|
||||
"a list of lint codes to disable"
|
||||
],
|
||||
"disabled_codes": [],
|
||||
"_help_function_pattern": [
|
||||
"regular expression pattern describing valid function names"
|
||||
],
|
||||
"function_pattern": "[0-9a-z_]+",
|
||||
"_help_macro_pattern": [
|
||||
"regular expression pattern describing valid macro names"
|
||||
],
|
||||
"macro_pattern": "[0-9A-Z_]+",
|
||||
"_help_global_var_pattern": [
|
||||
"regular expression pattern describing valid names for",
|
||||
"variables with global (cache) scope"
|
||||
],
|
||||
"global_var_pattern": "[A-Z][0-9A-Z_]+",
|
||||
"_help_internal_var_pattern": [
|
||||
"regular expression pattern describing valid names for",
|
||||
"variables with global scope (but internal semantic)"
|
||||
],
|
||||
"internal_var_pattern": "_[A-Z][0-9A-Z_]+",
|
||||
"_help_local_var_pattern": [
|
||||
"regular expression pattern describing valid names for",
|
||||
"variables with local scope"
|
||||
],
|
||||
"local_var_pattern": "[a-z][a-z0-9_]+",
|
||||
"_help_private_var_pattern": [
|
||||
"regular expression pattern describing valid names for",
|
||||
"privatedirectory variables"
|
||||
],
|
||||
"private_var_pattern": "_[0-9a-z_]+",
|
||||
"_help_public_var_pattern": [
|
||||
"regular expression pattern describing valid names for public",
|
||||
"directory variables"
|
||||
],
|
||||
"public_var_pattern": "[A-Z][0-9A-Z_]+",
|
||||
"_help_argument_var_pattern": [
|
||||
"regular expression pattern describing valid names for",
|
||||
"function/macro arguments and loop variables."
|
||||
],
|
||||
"argument_var_pattern": "[a-z][a-z0-9_]+",
|
||||
"_help_keyword_pattern": [
|
||||
"regular expression pattern describing valid names for",
|
||||
"keywords used in functions or macros"
|
||||
],
|
||||
"keyword_pattern": "[A-Z][0-9A-Z_]+",
|
||||
"_help_max_conditionals_custom_parser": [
|
||||
"In the heuristic for C0201, how many conditionals to match",
|
||||
"within a loop in before considering the loop a parser."
|
||||
],
|
||||
"max_conditionals_custom_parser": 2,
|
||||
"_help_min_statement_spacing": [
|
||||
"Require at least this many newlines between statements"
|
||||
],
|
||||
"min_statement_spacing": 1,
|
||||
"_help_max_statement_spacing": [
|
||||
"Require no more than this many newlines between statements"
|
||||
],
|
||||
"max_statement_spacing": 2,
|
||||
"max_returns": 6,
|
||||
"max_branches": 12,
|
||||
"max_arguments": 5,
|
||||
"max_localvars": 15,
|
||||
"max_statements": 50
|
||||
},
|
||||
"_help_encode": "Options affecting file encoding",
|
||||
"encode": {
|
||||
"_help_emit_byteorder_mark": [
|
||||
"If true, emit the unicode byte-order mark (BOM) at the start",
|
||||
"of the file"
|
||||
],
|
||||
"emit_byteorder_mark": false,
|
||||
"_help_input_encoding": [
|
||||
"Specify the encoding of the input file. Defaults to utf-8"
|
||||
],
|
||||
"input_encoding": "utf-8",
|
||||
"_help_output_encoding": [
|
||||
"Specify the encoding of the output file. Defaults to utf-8.",
|
||||
"Note that cmake only claims to support utf-8 so be careful",
|
||||
"when using anything else"
|
||||
],
|
||||
"output_encoding": "utf-8"
|
||||
},
|
||||
"_help_misc": "Miscellaneous configurations options.",
|
||||
"misc": {
|
||||
"_help_per_command": [
|
||||
"A dictionary containing any per-command configuration",
|
||||
"overrides. Currently only `command_case` is supported."
|
||||
],
|
||||
"per_command": {}
|
||||
}
|
||||
}
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,6 +1,3 @@
|
||||
[submodule "third_party/zephyr_bluetooth-2.7.5/zephyr_bluetooth"]
|
||||
path = third_party/zephyr_bluetooth-2.7.5/zephyr_bluetooth
|
||||
url = https://github.com/sakumisu/zephyr_bluetooth.git
|
||||
[submodule "third_party/nimble-1.6.0/nimble"]
|
||||
path = third_party/nimble-1.6.0/nimble
|
||||
url = https://github.com/sakumisu/mynewt-nimble.git
|
||||
|
||||
305
CMakeLists.txt
305
CMakeLists.txt
@@ -1,151 +1,204 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
if(CONFIG_CHERRYUSB OR ESP_PLATFORM)
|
||||
|
||||
if(BL_SDK_BASE)
|
||||
set(CONFIG_CHERRYUSB_DEVICE 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_CDC_ACM 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_HID 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_MSC 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_AUDIO 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_VIDEO 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_DCD "bl")
|
||||
message(STATUS "enable cherryusb in bouffalo_sdk")
|
||||
|
||||
set(CONFIG_CHERRYUSB_HOST 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_ACM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_ECM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_NCM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_HID 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_MSC 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_VIDEO 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_AUDIO 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_RNDIS 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_BLUETOOTH 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_ASIX 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_RTL8152 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CH34X 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CP210X 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_FTDI 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_PL2303 1)
|
||||
set(CONFIG_CHERRYUSB_OSAL "freertos")
|
||||
set(CONFIG_CHERRYUSB_HOST_HCD "ehci_bouffalo")
|
||||
set(CONFIG_CHERRYUSB_DEVICE_CDC_ACM 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_HID 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_MSC 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_AUDIO 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_VIDEO 1)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_ACM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_ECM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_NCM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_HID 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_MSC 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_VIDEO 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_AUDIO 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_RNDIS 1)
|
||||
# set(CONFIG_CHERRYUSB_HOST_BLUETOOTH 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_ASIX 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_RTL8152 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CH34X 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CP210X 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_FTDI 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_PL2303 1)
|
||||
|
||||
sdk_generate_library(cherryusb)
|
||||
sdk_add_include_directories(${cherryusb_incs})
|
||||
sdk_library_add_sources(${cherryusb_srcs})
|
||||
set(CONFIG_CHERRYUSB_DEVICE_BL 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_EHCI_BL 1)
|
||||
set(CONFIG_CHERRYUSB_OSAL "freertos")
|
||||
|
||||
sdk_library_add_sources(platform/none/usbh_lwip.c)
|
||||
|
||||
elseif(HPM_SDK_BASE)
|
||||
set(CONFIG_CHERRYUSB_HOST 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_ACM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_ECM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_NCM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_HID 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_MSC 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_VIDEO 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_AUDIO 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_RNDIS 1)
|
||||
# set(CONFIG_CHERRYUSB_HOST_BLUETOOTH 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_ASIX 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_RTL8152 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CH34X 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CP210X 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_FTDI 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_PL2303 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_BL616 1)
|
||||
set(CONFIG_CHERRYUSB_OSAL "freertos")
|
||||
set(CONFIG_CHERRYUSB_HOST_HCD "ehci_hpm")
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
|
||||
|
||||
sdk_inc(${cherryusb_incs})
|
||||
sdk_src(${cherryusb_srcs})
|
||||
|
||||
sdk_src(platform/none/usbh_lwip.c)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
|
||||
list(REMOVE_DUPLICATES cherryusb_srcs)
|
||||
list(REMOVE_DUPLICATES cherryusb_incs)
|
||||
|
||||
sdk_generate_library(cherryusb)
|
||||
sdk_add_include_directories(${cherryusb_incs})
|
||||
sdk_library_add_sources(${cherryusb_srcs})
|
||||
elseif(ESP_PLATFORM)
|
||||
message(STATUS "enable cherryusb in esp-idf")
|
||||
|
||||
set(CONFIG_CHERRYUSB_DEVICE_DCD "dwc2_esp")
|
||||
set(CONFIG_CHERRYUSB_HOST_HCD "dwc2_esp")
|
||||
set(CONFIG_CHERRYUSB_OSAL "idf")
|
||||
set(CONFIG_CHERRYUSB_DEVICE_DWC2_ESP 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_DWC2_ESP 1)
|
||||
set(CONFIG_CHERRYUSB_OSAL "idf")
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
|
||||
list(REMOVE_DUPLICATES cherryusb_srcs)
|
||||
list(REMOVE_DUPLICATES cherryusb_incs)
|
||||
|
||||
set(ldfragments "osal/idf/linker.lf")
|
||||
set(ldfragments "osal/idf/linker.lf")
|
||||
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_ECM OR CONFIG_CHERRYUSB_HOST_CDC_RNDIS OR CONFIG_CHERRYUSB_HOST_CDC_NCM
|
||||
OR CONFIG_CHERRYUSB_HOST_ASIX OR CONFIG_CHERRYUSB_HOST_RTL8152 OR CONFIG_CHERRYUSB_HOST_BL616)
|
||||
list(APPEND cherryusb_srcs platform/none/usbh_lwip.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_ECM
|
||||
OR CONFIG_CHERRYUSB_HOST_CDC_RNDIS
|
||||
OR CONFIG_CHERRYUSB_HOST_CDC_NCM
|
||||
OR CONFIG_CHERRYUSB_HOST_ASIX
|
||||
OR CONFIG_CHERRYUSB_HOST_RTL8152
|
||||
OR CONFIG_CHERRYUSB_HOST_BL616
|
||||
)
|
||||
idf_component_get_property(lwip lwip COMPONENT_LIB)
|
||||
target_compile_definitions(${lwip} PRIVATE "-DPBUF_POOL_BUFSIZE=1600")
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS ${cherryusb_srcs}
|
||||
INCLUDE_DIRS ${cherryusb_incs}
|
||||
PRIV_REQUIRES usb
|
||||
LDFRAGMENTS ${ldfragments}
|
||||
)
|
||||
idf_component_get_property(freertos_include freertos ORIG_INCLUDE_PATH)
|
||||
|
||||
if(CONFIG_CHERRYUSB_HOST)
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "osal/idf/usbh_class_info.ld")
|
||||
idf_component_register(
|
||||
SRCS
|
||||
${cherryusb_srcs}
|
||||
INCLUDE_DIRS
|
||||
${cherryusb_incs}
|
||||
${freertos_include}
|
||||
PRIV_REQUIRES
|
||||
usb esp_mm
|
||||
LDFRAGMENTS
|
||||
${ldfragments}
|
||||
)
|
||||
|
||||
# 强制链接器不删除符号
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_ACM)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u cdc_acm_class_info")
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u cdc_data_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_HID)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u hid_custom_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_MSC)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u msc_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_ECM)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u cdc_ecm_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_RNDIS)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u rndis_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_NCM)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u cdc_ncm_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_VIDEO)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u video_ctrl_class_info")
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u video_streaming_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_AUDIO)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u audio_ctrl_intf_class_info")
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u audio_streaming_intf_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_BLUETOOTH)
|
||||
if(CONFIG_USBHOST_BLUETOOTH_HCI_H4)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u bluetooth_h4_nrf_class_info")
|
||||
else()
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u bluetooth_class_info")
|
||||
if(CONFIG_CHERRYUSB_HOST)
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "osal/idf/usbh_class_info.ld")
|
||||
|
||||
# 强制链接器不删除符号
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_ACM)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u cdc_acm_class_info")
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u cdc_data_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_HID)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u hid_custom_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_MSC)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u msc_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_ECM)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u cdc_ecm_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_RNDIS)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u rndis_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_NCM)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u cdc_ncm_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_VIDEO)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u video_ctrl_class_info")
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u video_streaming_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_AUDIO)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u audio_ctrl_intf_class_info")
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u audio_streaming_intf_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_BLUETOOTH)
|
||||
if(CONFIG_USBHOST_BLUETOOTH_HCI_H4)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u bluetooth_h4_nrf_class_info")
|
||||
else()
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u bluetooth_class_info")
|
||||
endif()
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_ASIX)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u asix_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_RTL8152)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u rtl8152_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_FTDI)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ftdi_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CH34X)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ch34x_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CP210X)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u cp210x_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_PL2303)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u pl2303_class_info")
|
||||
endif()
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_ASIX)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u asix_class_info")
|
||||
|
||||
if(CONFIG_CHERRYUSB)
|
||||
set_source_files_properties("class/audio/usbd_audio.c" PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_RTL8152)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u rtl8152_class_info")
|
||||
elseif(ZEPHYR_BASE)
|
||||
message(STATUS "enable cherryusb in zephyr")
|
||||
|
||||
set(CONFIG_CHERRYUSB_OSAL "zephyr")
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
|
||||
list(REMOVE_DUPLICATES cherryusb_srcs)
|
||||
list(REMOVE_DUPLICATES cherryusb_incs)
|
||||
|
||||
if (CONFIG_SHELL)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/platform/zephyr/usb_cmd.c)
|
||||
endif ()
|
||||
if (CONFIG_FILE_SYSTEM AND CONFIG_CHERRYUSB_HOST)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/platform/zephyr/usbh_msc_disk.c)
|
||||
endif ()
|
||||
|
||||
zephyr_library()
|
||||
if(cherryusb_incs)
|
||||
zephyr_include_directories(${cherryusb_incs})
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_FTDI)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ftdi_class_info")
|
||||
if(cherryusb_srcs)
|
||||
zephyr_library_sources(${cherryusb_srcs})
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CH34X)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ch34x_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CP210X)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u cp210x_class_info")
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_PL2303)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u pl2303_class_info")
|
||||
|
||||
if (CONFIG_CHERRYUSB_HOST)
|
||||
zephyr_linker_sources(SECTIONS zephyr/usbh_class_info.ld)
|
||||
endif()
|
||||
elseif(HPM_SDK_BASE)
|
||||
message(STATUS "enable cherryusb in hpm_sdk")
|
||||
|
||||
set(CONFIG_CHERRYUSB_DEVICE_CDC_ACM 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_HID 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_MSC 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_AUDIO 1)
|
||||
set(CONFIG_CHERRYUSB_DEVICE_VIDEO 1)
|
||||
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_ACM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_ECM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_NCM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_HID 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_MSC 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_VIDEO 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_AUDIO 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CDC_RNDIS 1)
|
||||
# set(CONFIG_CHERRYUSB_HOST_BLUETOOTH 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_ASIX 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_RTL8152 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CH34X 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_CP210X 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_FTDI 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_PL2303 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_BL616 1)
|
||||
|
||||
set(CONFIG_CHERRYUSB_DEVICE_HPM 1)
|
||||
set(CONFIG_CHERRYUSB_HOST_EHCI_HPM 1)
|
||||
set(CONFIG_CHERRYUSB_OSAL "freertos")
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cherryusb.cmake)
|
||||
list(REMOVE_DUPLICATES cherryusb_srcs)
|
||||
list(REMOVE_DUPLICATES cherryusb_incs)
|
||||
|
||||
sdk_inc(${cherryusb_incs})
|
||||
sdk_src(${cherryusb_srcs})
|
||||
endif()
|
||||
|
||||
if(CONFIG_CHERRYUSB)
|
||||
set_source_files_properties("class/audio/usbd_audio.c"
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
-Wno-maybe-uninitialized)
|
||||
endif()
|
||||
endif()
|
||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
40
Kconfig
40
Kconfig
@@ -26,18 +26,24 @@ if CHERRYUSB
|
||||
default CHERRYUSB_DEVICE_CUSTOM
|
||||
config CHERRYUSB_DEVICE_CUSTOM
|
||||
bool "CUSTOM (Implement it yourself)"
|
||||
config CHERRYUSB_DEVICE_FSDEV
|
||||
bool "fsdev"
|
||||
config CHERRYUSB_DEVICE_FSDEV_ST
|
||||
bool "fsdev_st"
|
||||
config CHERRYUSB_DEVICE_FSDEV_CUSTOM
|
||||
bool "fsdev_custom"
|
||||
config CHERRYUSB_DEVICE_DWC2_ST
|
||||
bool "dwc2_st"
|
||||
config CHERRYUSB_DEVICE_DWC2_ESP
|
||||
bool "dwc2_esp"
|
||||
config CHERRYUSB_DEVICE_DWC2_KENDRYTE
|
||||
bool "dwc2_kendryte"
|
||||
config CHERRYUSB_DEVICE_DWC2_AT
|
||||
bool "dwc2_at"
|
||||
config CHERRYUSB_DEVICE_DWC2_GD
|
||||
bool "dwc2_gd"
|
||||
config CHERRYUSB_DEVICE_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config CHERRYUSB_DEVICE_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config CHERRYUSB_DEVICE_DWC2_GD
|
||||
bool "dwc2_gd"
|
||||
config CHERRYUSB_DEVICE_DWC2_CUSTOM
|
||||
bool "dwc2_custom"
|
||||
config CHERRYUSB_DEVICE_MUSB_ES
|
||||
@@ -48,22 +54,24 @@ if CHERRYUSB
|
||||
bool "musb_bk"
|
||||
config CHERRYUSB_DEVICE_MUSB_CUSTOM
|
||||
bool "musb_custom"
|
||||
config CHERRYUSB_DEVICE_CHIPIDEA_MCX
|
||||
bool "chipidea_mcx"
|
||||
config CHERRYUSB_DEVICE_CHIPIDEA_CUSTOM
|
||||
bool "chipidea_custom"
|
||||
config CHERRYUSB_DEVICE_KINETIS_MCX
|
||||
bool "kinetis_mcx"
|
||||
config CHERRYUSB_DEVICE_KINETIS_MM32
|
||||
bool "kinetis_mm32"
|
||||
config CHERRYUSB_DEVICE_KINETIS_CUSTOM
|
||||
bool "kinetis_custom"
|
||||
config CHERRYUSB_DEVICE_CHIPIDEA_MCX
|
||||
bool "chipidea_mcx"
|
||||
config CHERRYUSB_DEVICE_CHIPIDEA_CUSTOM
|
||||
bool "chipidea_custom"
|
||||
config CHERRYUSB_DEVICE_BL
|
||||
bool "bouffalo"
|
||||
config CHERRYUSB_DEVICE_HPM
|
||||
bool "hpm"
|
||||
config CHERRYUSB_DEVICE_AIC
|
||||
bool "aic"
|
||||
config CHERRYUSB_DEVICE_RP2040
|
||||
bool "rp2040"
|
||||
config CHERRYUSB_DEVICE_CH32
|
||||
bool "ch32"
|
||||
config CHERRYUSB_DEVICE_PUSB2
|
||||
@@ -110,6 +118,11 @@ if CHERRYUSB
|
||||
prompt "Enable usb cdc ncm device"
|
||||
default n
|
||||
|
||||
config CHERRYUSB_DEVICE_MTP
|
||||
bool
|
||||
prompt "Enable usb mtp device, it is commercial charge"
|
||||
default n
|
||||
|
||||
config CHERRYUSB_DEVICE_DFU
|
||||
bool
|
||||
prompt "Enable usb dfu device"
|
||||
@@ -189,8 +202,12 @@ if CHERRYUSB
|
||||
bool "dwc2_st"
|
||||
config CHERRYUSB_HOST_DWC2_ESP
|
||||
bool "dwc2_esp"
|
||||
config CHERRYUSB_HOST_DWC2_KENDRYTE
|
||||
bool "dwc2_kendryte"
|
||||
config CHERRYUSB_HOST_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config CHERRYUSB_HOST_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config CHERRYUSB_HOST_DWC2_CUSTOM
|
||||
bool "dwc2_custom"
|
||||
config CHERRYUSB_HOST_MUSB_ES
|
||||
@@ -213,6 +230,8 @@ if CHERRYUSB
|
||||
bool "kinetis_mm32"
|
||||
config CHERRYUSB_HOST_KINETIS_CUSTOM
|
||||
bool "kinetis_custom"
|
||||
config CHERRYUSB_HOST_RP2040
|
||||
bool "rp2040"
|
||||
endchoice
|
||||
|
||||
config CHERRYUSB_HOST_CDC_ACM
|
||||
@@ -295,6 +314,11 @@ if CHERRYUSB
|
||||
prompt "Enable usb pl2303 driver"
|
||||
default n
|
||||
|
||||
config CHERRYUSB_HOST_AOA
|
||||
bool
|
||||
prompt "Enable usb aoa driver"
|
||||
default n
|
||||
|
||||
config USBHOST_PLATFORM_CDC_ECM
|
||||
bool
|
||||
|
||||
|
||||
364
Kconfig.rtt
Normal file
364
Kconfig.rtt
Normal file
@@ -0,0 +1,364 @@
|
||||
# Kconfig file for package CherryUSB
|
||||
menuconfig RT_USING_CHERRYUSB
|
||||
bool "Using USB with CherryUSB"
|
||||
default n
|
||||
|
||||
if RT_USING_CHERRYUSB
|
||||
|
||||
menuconfig RT_CHERRYUSB_DEVICE
|
||||
bool "Enable usb device mode"
|
||||
default n
|
||||
|
||||
if RT_CHERRYUSB_DEVICE
|
||||
choice
|
||||
prompt "Select usb device speed"
|
||||
default RT_CHERRYUSB_DEVICE_SPEED_FS
|
||||
config RT_CHERRYUSB_DEVICE_SPEED_FS
|
||||
bool "FS"
|
||||
config RT_CHERRYUSB_DEVICE_SPEED_HS
|
||||
bool "HS"
|
||||
config RT_CHERRYUSB_DEVICE_SPEED_AUTO
|
||||
bool "AUTO"
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "Select usb device ip, and some ip need config in usb_config.h, please check"
|
||||
default RT_CHERRYUSB_DEVICE_CUSTOM
|
||||
config RT_CHERRYUSB_DEVICE_CUSTOM
|
||||
bool "CUSTOM (Implement it yourself)"
|
||||
config RT_CHERRYUSB_DEVICE_FSDEV_ST
|
||||
bool "fsdev_st"
|
||||
config RT_CHERRYUSB_DEVICE_FSDEV_CUSTOM
|
||||
bool "fsdev_custom"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_ST
|
||||
bool "dwc2_st"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_ESP
|
||||
bool "dwc2_esp"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_KENDRYTE
|
||||
bool "dwc2_kendryte"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_AT
|
||||
bool "dwc2_at"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_GD
|
||||
bool "dwc2_gd"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_CUSTOM
|
||||
bool "dwc2_custom"
|
||||
config RT_CHERRYUSB_DEVICE_MUSB_ES
|
||||
bool "musb_es"
|
||||
config RT_CHERRYUSB_DEVICE_MUSB_SUNXI
|
||||
bool "musb_sunxi"
|
||||
config RT_CHERRYUSB_DEVICE_MUSB_BK
|
||||
bool "musb_bk"
|
||||
config RT_CHERRYUSB_DEVICE_MUSB_CUSTOM
|
||||
bool "musb_custom"
|
||||
config RT_CHERRYUSB_DEVICE_CHIPIDEA_MCX
|
||||
bool "chipidea_mcx"
|
||||
config RT_CHERRYUSB_DEVICE_CHIPIDEA_CUSTOM
|
||||
bool "chipidea_custom"
|
||||
config RT_CHERRYUSB_DEVICE_KINETIS_MCX
|
||||
bool "kinetis_mcx"
|
||||
config RT_CHERRYUSB_DEVICE_KINETIS_MM32
|
||||
bool "kinetis_mm32"
|
||||
config RT_CHERRYUSB_DEVICE_KINETIS_CUSTOM
|
||||
bool "kinetis_custom"
|
||||
config RT_CHERRYUSB_DEVICE_BL
|
||||
bool "bouffalo"
|
||||
config RT_CHERRYUSB_DEVICE_HPM
|
||||
bool "hpm"
|
||||
config RT_CHERRYUSB_DEVICE_AIC
|
||||
bool "aic"
|
||||
config RT_CHERRYUSB_DEVICE_RP2040
|
||||
bool "rp2040"
|
||||
config RT_CHERRYUSB_DEVICE_CH32
|
||||
bool "ch32"
|
||||
config RT_CHERRYUSB_DEVICE_PUSB2
|
||||
bool "pusb2"
|
||||
config RT_CHERRYUSB_DEVICE_NRF5X
|
||||
bool "nrf5x"
|
||||
endchoice
|
||||
|
||||
config RT_CHERRYUSB_DEVICE_CDC_ACM
|
||||
bool
|
||||
prompt "Enable usb cdc acm device"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_DEVICE_HID
|
||||
bool
|
||||
prompt "Enable usb hid device"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_DEVICE_MSC
|
||||
bool
|
||||
prompt "Enable usb msc device"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_DEVICE_AUDIO
|
||||
bool
|
||||
prompt "Enable usb audio device"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_DEVICE_VIDEO
|
||||
bool
|
||||
prompt "Enable usb video device"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_DEVICE_CDC_RNDIS
|
||||
bool
|
||||
prompt "Enable usb cdc rndis device"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_DEVICE_CDC_ECM
|
||||
bool
|
||||
prompt "Enable usb cdc ecm device"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_DEVICE_CDC_NCM
|
||||
bool
|
||||
prompt "Enable usb cdc ncm device"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_DEVICE_MTP
|
||||
bool
|
||||
prompt "Enable usb mtp device, it is commercial charge"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_DEVICE_DFU
|
||||
bool
|
||||
prompt "Enable usb dfu device"
|
||||
default n
|
||||
|
||||
choice
|
||||
prompt "Select usb device template"
|
||||
default RT_CHERRYUSB_DEVICE_TEMPLATE_NONE
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_NONE
|
||||
bool "none (Implement it yourself)"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM
|
||||
bool "cdc_acm"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_MSC
|
||||
bool "msc_ram"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_MSC_BLKDEV
|
||||
bool "msc_blkdev"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_HID_KEYBOARD
|
||||
bool "hid_keyboard"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_HID_MOUSE
|
||||
bool "hid_mouse"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_HID_CUSTOM
|
||||
bool "hid_custom"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_VIDEO
|
||||
bool "video"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_AUDIO_V1_MIC_SPEAKER
|
||||
bool "audio_v1_mic_speaker_multichan"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_AUDIO_V2_MIC_SPEAKER
|
||||
bool "audio_v2_mic_speaker_multichan"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_RNDIS
|
||||
bool "cdc_rndis"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ECM
|
||||
bool "cdc_ecm"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_NCM
|
||||
bool "cdc_ncm"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM_MSC
|
||||
bool "cdc_acm_msc"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM_MSC_HID
|
||||
bool "cdc_acm_msc_hid"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1
|
||||
bool "winusbv1"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC
|
||||
bool "winusbv2_cdc"
|
||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_HID
|
||||
bool "winusbv2_hid"
|
||||
endchoice
|
||||
|
||||
config CONFIG_USBDEV_MSC_BLOCK_DEV_NAME
|
||||
string "usb device msc block device name"
|
||||
depends on RT_CHERRYUSB_DEVICE_TEMPLATE_MSC_BLKDEV
|
||||
default "sd0"
|
||||
|
||||
endif
|
||||
|
||||
menuconfig RT_CHERRYUSB_HOST
|
||||
bool "Enable usb host mode"
|
||||
default n
|
||||
|
||||
if RT_CHERRYUSB_HOST
|
||||
choice
|
||||
prompt "Select usb host ip, and some ip need config in usb_config.h, please check"
|
||||
default RT_CHERRYUSB_HOST_CUSTOM
|
||||
config RT_CHERRYUSB_HOST_CUSTOM
|
||||
bool "CUSTOM (Implement it yourself)"
|
||||
config RT_CHERRYUSB_HOST_EHCI_BL
|
||||
bool "ehci_bouffalo"
|
||||
config RT_CHERRYUSB_HOST_EHCI_HPM
|
||||
bool "ehci_hpm"
|
||||
config RT_CHERRYUSB_HOST_EHCI_AIC
|
||||
bool "ehci_aic"
|
||||
config RT_CHERRYUSB_HOST_EHCI_MCX
|
||||
bool "ehci_mcx"
|
||||
config RT_CHERRYUSB_HOST_EHCI_NUC980
|
||||
bool "ehci_nuc980"
|
||||
config RT_CHERRYUSB_HOST_EHCI_MA35D0
|
||||
bool "ehci_ma35d0"
|
||||
config RT_CHERRYUSB_HOST_EHCI_CUSTOM
|
||||
bool "ehci_custom"
|
||||
config RT_CHERRYUSB_HOST_DWC2_ST
|
||||
bool "dwc2_st"
|
||||
config RT_CHERRYUSB_HOST_DWC2_ESP
|
||||
bool "dwc2_esp"
|
||||
config RT_CHERRYUSB_HOST_DWC2_KENDRYTE
|
||||
bool "dwc2_kendryte"
|
||||
config RT_CHERRYUSB_HOST_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config RT_CHERRYUSB_HOST_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config RT_CHERRYUSB_HOST_DWC2_CUSTOM
|
||||
bool "dwc2_custom"
|
||||
config RT_CHERRYUSB_HOST_MUSB_ES
|
||||
bool "musb_es"
|
||||
config RT_CHERRYUSB_HOST_MUSB_SUNXI
|
||||
bool "musb_sunxi"
|
||||
config RT_CHERRYUSB_HOST_MUSB_BK
|
||||
bool "musb_bk"
|
||||
config RT_CHERRYUSB_HOST_MUSB_CUSTOM
|
||||
bool "musb_custom"
|
||||
config RT_CHERRYUSB_HOST_PUSB2
|
||||
bool "pusb2"
|
||||
config RT_CHERRYUSB_HOST_XHCI
|
||||
bool "xhci"
|
||||
config RT_CHERRYUSB_HOST_RP2040
|
||||
bool "rp2040"
|
||||
endchoice
|
||||
|
||||
config RT_CHERRYUSB_HOST_CDC_ACM
|
||||
bool
|
||||
prompt "Enable usb cdc acm driver"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_HID
|
||||
bool
|
||||
prompt "Enable usb hid driver"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_MSC
|
||||
bool
|
||||
prompt "Enable usb msc driver"
|
||||
default n
|
||||
select RT_USING_DFS
|
||||
select RT_USING_DFS_ELMFAT
|
||||
|
||||
config RT_CHERRYUSB_HOST_CDC_ECM
|
||||
bool
|
||||
prompt "Enable usb cdc ecm driver"
|
||||
select RT_USING_LWIP
|
||||
select CONFIG_USBHOST_PLATFORM_CDC_ECM
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_CDC_RNDIS
|
||||
bool
|
||||
prompt "Enable usb rndis driver"
|
||||
select RT_USING_LWIP
|
||||
select CONFIG_USBHOST_PLATFORM_CDC_RNDIS
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_CDC_NCM
|
||||
bool
|
||||
prompt "Enable usb cdc ncm driver"
|
||||
select RT_USING_LWIP
|
||||
select CONFIG_USBHOST_PLATFORM_CDC_NCM
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_VIDEO
|
||||
bool
|
||||
prompt "Enable usb video driver, it is commercial charge"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_AUDIO
|
||||
bool
|
||||
prompt "Enable usb audio driver, it is commercial charge"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_BLUETOOTH
|
||||
bool
|
||||
prompt "Enable usb bluetooth driver"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_ASIX
|
||||
bool
|
||||
prompt "Enable usb asix driver"
|
||||
select RT_USING_LWIP
|
||||
select CONFIG_USBHOST_PLATFORM_ASIX
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_RTL8152
|
||||
bool
|
||||
prompt "Enable usb rtl8152 driver"
|
||||
select RT_USING_LWIP
|
||||
select CONFIG_USBHOST_PLATFORM_RTL8152
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_FTDI
|
||||
bool
|
||||
prompt "Enable usb ftdi driver"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_CH34X
|
||||
bool
|
||||
prompt "Enable usb ch34x driver"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_CP210X
|
||||
bool
|
||||
prompt "Enable usb cp210x driver"
|
||||
default n
|
||||
|
||||
config RT_CHERRYUSB_HOST_PL2303
|
||||
bool
|
||||
prompt "Enable usb pl2303 driver"
|
||||
default n
|
||||
|
||||
config CONFIG_USBHOST_PLATFORM_CDC_ECM
|
||||
bool
|
||||
|
||||
config CONFIG_USBHOST_PLATFORM_CDC_RNDIS
|
||||
bool
|
||||
|
||||
config CONFIG_USBHOST_PLATFORM_CDC_NCM
|
||||
bool
|
||||
|
||||
config CONFIG_USBHOST_PLATFORM_ASIX
|
||||
bool
|
||||
|
||||
config CONFIG_USBHOST_PLATFORM_RTL8152
|
||||
bool
|
||||
|
||||
config RT_LWIP_PBUF_POOL_BUFSIZE
|
||||
int "The size of each pbuf in the pbuf pool"
|
||||
range 1500 2000
|
||||
default 1600
|
||||
|
||||
config CONFIG_USB_DFS_MOUNT_POINT
|
||||
string "usb host dfs mount point"
|
||||
depends on RT_CHERRYUSB_HOST_MSC
|
||||
default "/"
|
||||
|
||||
config RT_CHERRYUSB_HOST_TEMPLATE
|
||||
bool
|
||||
prompt "Use usb host template"
|
||||
default n
|
||||
|
||||
if RT_CHERRYUSB_HOST_TEMPLATE
|
||||
config TEST_USBH_CDC_ACM
|
||||
int
|
||||
prompt "demo for test cdc acm"
|
||||
default 0
|
||||
depends on CHERRYUSB_HOST_CDC_ACM
|
||||
config TEST_USBH_HID
|
||||
int
|
||||
prompt "demo for test hid"
|
||||
default 0
|
||||
depends on CHERRYUSB_HOST_HID
|
||||
endif
|
||||
endif
|
||||
|
||||
endif
|
||||
404
Kconfig.rttpkg
Normal file
404
Kconfig.rttpkg
Normal file
@@ -0,0 +1,404 @@
|
||||
# Kconfig file for package CherryUSB
|
||||
menuconfig PKG_USING_CHERRYUSB
|
||||
depends on RT_VER_NUM < 0x50200
|
||||
bool "CherryUSB: tiny and portable USB host/device stack for embedded system with USB IP"
|
||||
default n
|
||||
|
||||
if PKG_USING_CHERRYUSB
|
||||
|
||||
menuconfig PKG_CHERRYUSB_DEVICE
|
||||
bool "Enable usb device mode"
|
||||
default n
|
||||
|
||||
if PKG_CHERRYUSB_DEVICE
|
||||
choice
|
||||
prompt "Select usb device speed"
|
||||
default PKG_CHERRYUSB_DEVICE_SPEED_FS
|
||||
config PKG_CHERRYUSB_DEVICE_SPEED_FS
|
||||
bool "FS"
|
||||
config PKG_CHERRYUSB_DEVICE_SPEED_HS
|
||||
bool "HS"
|
||||
config PKG_CHERRYUSB_DEVICE_SPEED_AUTO
|
||||
bool "AUTO"
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "Select usb device ip, and some ip need config in usb_config.h, please check"
|
||||
default PKG_CHERRYUSB_DEVICE_CUSTOM
|
||||
config PKG_CHERRYUSB_DEVICE_CUSTOM
|
||||
bool "CUSTOM (Implement it yourself)"
|
||||
config PKG_CHERRYUSB_DEVICE_FSDEV_ST
|
||||
bool "fsdev_st"
|
||||
config PKG_CHERRYUSB_DEVICE_FSDEV_CUSTOM
|
||||
bool "fsdev_custom"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_ST
|
||||
bool "dwc2_st"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_ESP
|
||||
bool "dwc2_esp"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_KENDRYTE
|
||||
bool "dwc2_kendryte"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_AT
|
||||
bool "dwc2_at"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_GD
|
||||
bool "dwc2_gd"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_CUSTOM
|
||||
bool "dwc2_custom"
|
||||
config PKG_CHERRYUSB_DEVICE_MUSB_ES
|
||||
bool "musb_es"
|
||||
config PKG_CHERRYUSB_DEVICE_MUSB_SUNXI
|
||||
bool "musb_sunxi"
|
||||
config PKG_CHERRYUSB_DEVICE_MUSB_BK
|
||||
bool "musb_bk"
|
||||
config PKG_CHERRYUSB_DEVICE_MUSB_CUSTOM
|
||||
bool "musb_custom"
|
||||
config PKG_CHERRYUSB_DEVICE_CHIPIDEA_MCX
|
||||
bool "chipidea_mcx"
|
||||
config PKG_CHERRYUSB_DEVICE_CHIPIDEA_CUSTOM
|
||||
bool "chipidea_custom"
|
||||
config PKG_CHERRYUSB_DEVICE_KINETIS_MCX
|
||||
bool "kinetis_mcx"
|
||||
config PKG_CHERRYUSB_DEVICE_KINETIS_MM32
|
||||
bool "kinetis_mm32"
|
||||
config PKG_CHERRYUSB_DEVICE_KINETIS_CUSTOM
|
||||
bool "kinetis_custom"
|
||||
config PKG_CHERRYUSB_DEVICE_BL
|
||||
bool "bouffalo"
|
||||
config PKG_CHERRYUSB_DEVICE_HPM
|
||||
bool "hpm"
|
||||
config PKG_CHERRYUSB_DEVICE_AIC
|
||||
bool "aic"
|
||||
config PKG_CHERRYUSB_DEVICE_RP2040
|
||||
bool "rp2040"
|
||||
config PKG_CHERRYUSB_DEVICE_CH32
|
||||
bool "ch32"
|
||||
config PKG_CHERRYUSB_DEVICE_PUSB2
|
||||
bool "pusb2"
|
||||
endchoice
|
||||
|
||||
config PKG_CHERRYUSB_DEVICE_CDC_ACM
|
||||
bool
|
||||
prompt "Enable usb cdc acm device"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_DEVICE_HID
|
||||
bool
|
||||
prompt "Enable usb hid device"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_DEVICE_MSC
|
||||
bool
|
||||
prompt "Enable usb msc device"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_DEVICE_AUDIO
|
||||
bool
|
||||
prompt "Enable usb audio device"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_DEVICE_VIDEO
|
||||
bool
|
||||
prompt "Enable usb video device"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_DEVICE_CDC_RNDIS
|
||||
bool
|
||||
prompt "Enable usb cdc rndis device"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_DEVICE_CDC_ECM
|
||||
bool
|
||||
prompt "Enable usb cdc ecm device"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_DEVICE_CDC_NCM
|
||||
bool
|
||||
prompt "Enable usb cdc ncm device"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_DEVICE_MTP
|
||||
bool
|
||||
prompt "Enable usb mtp device, it is commercial charge"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_DEVICE_DFU
|
||||
bool
|
||||
prompt "Enable usb dfu device"
|
||||
default n
|
||||
|
||||
choice
|
||||
prompt "Select usb device template"
|
||||
default PKG_CHERRYUSB_DEVICE_TEMPLATE_NONE
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_NONE
|
||||
bool "none (Implement it yourself)"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM
|
||||
bool "cdc_acm"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_MSC
|
||||
bool "msc_ram"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_MSC_BLKDEV
|
||||
bool "msc_blkdev"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_HID_KEYBOARD
|
||||
bool "hid_keyboard"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_HID_MOUSE
|
||||
bool "hid_mouse"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_HID_CUSTOM
|
||||
bool "hid_custom"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_VIDEO
|
||||
bool "video"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_AUDIO_V1_MIC_SPEAKER
|
||||
bool "audio_v1_mic_speaker_multichan"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_AUDIO_V2_MIC_SPEAKER
|
||||
bool "audio_v2_mic_speaker_multichan"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_CDC_RNDIS
|
||||
bool "cdc_rndis"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_CDC_ECM
|
||||
bool "cdc_ecm"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_CDC_NCM
|
||||
bool "cdc_ncm"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM_MSC
|
||||
bool "cdc_acm_msc"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM_MSC_HID
|
||||
bool "cdc_acm_msc_hid"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1
|
||||
bool "winusbv1"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC
|
||||
bool "winusbv2_cdc"
|
||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_HID
|
||||
bool "winusbv2_hid"
|
||||
endchoice
|
||||
|
||||
config CONFIG_USBDEV_MSC_BLOCK_DEV_NAME
|
||||
string "usb device msc block device name"
|
||||
depends on PKG_CHERRYUSB_DEVICE_TEMPLATE_MSC_BLKDEV
|
||||
default "sd0"
|
||||
|
||||
endif
|
||||
|
||||
menuconfig PKG_CHERRYUSB_HOST
|
||||
bool "Enable usb host mode"
|
||||
default n
|
||||
|
||||
if PKG_CHERRYUSB_HOST
|
||||
choice
|
||||
prompt "Select usb host ip, and some ip need config in usb_config.h, please check"
|
||||
default PKG_CHERRYUSB_HOST_CUSTOM
|
||||
config PKG_CHERRYUSB_HOST_CUSTOM
|
||||
bool "CUSTOM (Implement it yourself)"
|
||||
config PKG_CHERRYUSB_HOST_EHCI_BL
|
||||
bool "ehci_bouffalo"
|
||||
config PKG_CHERRYUSB_HOST_EHCI_HPM
|
||||
bool "ehci_hpm"
|
||||
config PKG_CHERRYUSB_HOST_EHCI_AIC
|
||||
bool "ehci_aic"
|
||||
config PKG_CHERRYUSB_HOST_EHCI_MCX
|
||||
bool "ehci_mcx"
|
||||
config PKG_CHERRYUSB_HOST_EHCI_NUC980
|
||||
bool "ehci_nuc980"
|
||||
config PKG_CHERRYUSB_HOST_EHCI_MA35D0
|
||||
bool "ehci_ma35d0"
|
||||
config PKG_CHERRYUSB_HOST_EHCI_CUSTOM
|
||||
bool "ehci_custom"
|
||||
config PKG_CHERRYUSB_HOST_DWC2_ST
|
||||
bool "dwc2_st"
|
||||
config PKG_CHERRYUSB_HOST_DWC2_ESP
|
||||
bool "dwc2_esp"
|
||||
config PKG_CHERRYUSB_HOST_DWC2_KENDRYTE
|
||||
bool "dwc2_kendryte"
|
||||
config PKG_CHERRYUSB_HOST_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config PKG_CHERRYUSB_HOST_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config PKG_CHERRYUSB_HOST_DWC2_CUSTOM
|
||||
bool "dwc2_custom"
|
||||
config PKG_CHERRYUSB_HOST_MUSB_ES
|
||||
bool "musb_es"
|
||||
config PKG_CHERRYUSB_HOST_MUSB_SUNXI
|
||||
bool "musb_sunxi"
|
||||
config PKG_CHERRYUSB_HOST_MUSB_BK
|
||||
bool "musb_bk"
|
||||
config PKG_CHERRYUSB_HOST_MUSB_CUSTOM
|
||||
bool "musb_custom"
|
||||
config PKG_CHERRYUSB_HOST_PUSB2
|
||||
bool "pusb2"
|
||||
config PKG_CHERRYUSB_HOST_XHCI
|
||||
bool "xhci"
|
||||
config PKG_CHERRYUSB_HOST_RP2040
|
||||
bool "rp2040"
|
||||
endchoice
|
||||
|
||||
config PKG_CHERRYUSB_HOST_CDC_ACM
|
||||
bool
|
||||
prompt "Enable usb cdc acm driver"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_HID
|
||||
bool
|
||||
prompt "Enable usb hid driver"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_MSC
|
||||
bool
|
||||
prompt "Enable usb msc driver"
|
||||
default n
|
||||
select RT_USING_DFS
|
||||
select RT_USING_DFS_ELMFAT
|
||||
|
||||
config PKG_CHERRYUSB_HOST_CDC_ECM
|
||||
bool
|
||||
prompt "Enable usb cdc ecm driver"
|
||||
select RT_USING_LWIP
|
||||
select CONFIG_USBHOST_PLATFORM_CDC_ECM
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_CDC_RNDIS
|
||||
bool
|
||||
prompt "Enable usb rndis driver"
|
||||
select RT_USING_LWIP
|
||||
select CONFIG_USBHOST_PLATFORM_CDC_RNDIS
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_CDC_NCM
|
||||
bool
|
||||
prompt "Enable usb cdc ncm driver"
|
||||
select RT_USING_LWIP
|
||||
select CONFIG_USBHOST_PLATFORM_CDC_NCM
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_VIDEO
|
||||
bool
|
||||
prompt "Enable usb video driver, it is commercial charge"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_AUDIO
|
||||
bool
|
||||
prompt "Enable usb audio driver, it is commercial charge"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_BLUETOOTH
|
||||
bool
|
||||
prompt "Enable usb bluetooth driver"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_ASIX
|
||||
bool
|
||||
prompt "Enable usb asix driver"
|
||||
select RT_USING_LWIP
|
||||
select CONFIG_USBHOST_PLATFORM_ASIX
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_RTL8152
|
||||
bool
|
||||
prompt "Enable usb rtl8152 driver"
|
||||
select RT_USING_LWIP
|
||||
select CONFIG_USBHOST_PLATFORM_RTL8152
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_FTDI
|
||||
bool
|
||||
prompt "Enable usb ftdi driver"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_CH34X
|
||||
bool
|
||||
prompt "Enable usb ch34x driver"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_CP210X
|
||||
bool
|
||||
prompt "Enable usb cp210x driver"
|
||||
default n
|
||||
|
||||
config PKG_CHERRYUSB_HOST_PL2303
|
||||
bool
|
||||
prompt "Enable usb pl2303 driver"
|
||||
default n
|
||||
|
||||
config CONFIG_USBHOST_PLATFORM_CDC_ECM
|
||||
bool
|
||||
|
||||
config CONFIG_USBHOST_PLATFORM_CDC_RNDIS
|
||||
bool
|
||||
|
||||
config CONFIG_USBHOST_PLATFORM_CDC_NCM
|
||||
bool
|
||||
|
||||
config CONFIG_USBHOST_PLATFORM_ASIX
|
||||
bool
|
||||
|
||||
config CONFIG_USBHOST_PLATFORM_RTL8152
|
||||
bool
|
||||
|
||||
config RT_LWIP_PBUF_POOL_BUFSIZE
|
||||
int "The size of each pbuf in the pbuf pool"
|
||||
range 1500 2000
|
||||
default 1600
|
||||
|
||||
config CONFIG_USB_DFS_MOUNT_POINT
|
||||
string "usb host dfs mount point"
|
||||
depends on RT_CHERRYUSB_HOST_MSC
|
||||
default "/"
|
||||
|
||||
config PKG_CHERRYUSB_HOST_TEMPLATE
|
||||
bool
|
||||
prompt "Use usb host template"
|
||||
default n
|
||||
|
||||
if PKG_CHERRYUSB_HOST_TEMPLATE
|
||||
config TEST_USBH_CDC_ACM
|
||||
int
|
||||
prompt "demo for test cdc acm"
|
||||
default 0
|
||||
depends on PKG_CHERRYUSB_HOST_CDC_ACM
|
||||
config TEST_USBH_HID
|
||||
int
|
||||
prompt "demo for test hid"
|
||||
default 0
|
||||
depends on PKG_CHERRYUSB_HOST_HID
|
||||
endif
|
||||
endif
|
||||
|
||||
config PKG_CHERRYUSB_PATH
|
||||
string
|
||||
default "/packages/system/CherryUSB"
|
||||
|
||||
choice
|
||||
prompt "Version"
|
||||
default PKG_USING_CHERRYUSB_V010500
|
||||
help
|
||||
Select the package version
|
||||
|
||||
config PKG_USING_CHERRYUSB_LATEST_VERSION
|
||||
bool "latest"
|
||||
config PKG_USING_CHERRYUSB_V010500
|
||||
bool "v1.5.0"
|
||||
config PKG_USING_CHERRYUSB_V010403
|
||||
bool "v1.4.3"
|
||||
config PKG_USING_CHERRYUSB_V010402
|
||||
bool "v1.4.2"
|
||||
config PKG_USING_CHERRYUSB_V010400
|
||||
bool "v1.4.0"
|
||||
config PKG_USING_CHERRYUSB_V010301
|
||||
bool "v1.3.1"
|
||||
config PKG_USING_CHERRYUSB_V010300
|
||||
bool "v1.3.0"
|
||||
config PKG_USING_CHERRYUSB_V010200
|
||||
bool "v1.2.0"
|
||||
config PKG_USING_CHERRYUSB_V001002
|
||||
bool "v0.10.2"
|
||||
endchoice
|
||||
|
||||
config PKG_CHERRYUSB_VER
|
||||
string
|
||||
default "latest" if PKG_USING_CHERRYUSB_LATEST_VERSION
|
||||
default "v1.5.0" if PKG_USING_CHERRYUSB_V010500
|
||||
default "v1.4.3" if PKG_USING_CHERRYUSB_V010403
|
||||
default "v1.4.2" if PKG_USING_CHERRYUSB_V010402
|
||||
default "v1.4.0" if PKG_USING_CHERRYUSB_V010400
|
||||
default "v1.3.1" if PKG_USING_CHERRYUSB_V010301
|
||||
default "v1.3.0" if PKG_USING_CHERRYUSB_V010300
|
||||
default "v1.2.0" if PKG_USING_CHERRYUSB_V010200
|
||||
default "v0.10.2" if PKG_USING_CHERRYUSB_V001002
|
||||
endif
|
||||
105
README.md
105
README.md
@@ -1,12 +1,18 @@
|
||||
# CherryUSB
|
||||
**English | [简体中文](README_zh.md)**
|
||||
|
||||
[中文版](./README_zh.md)
|
||||
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">CherryUSB</h1>
|
||||
<p align="center">
|
||||
<a href="https://github.com/cherry-embedded/CherryUSB/releases"><img src="https://img.shields.io/github/release/cherry-embedded/CherryUSB.svg"></a>
|
||||
<a href="https://github.com/cherry-embedded/CherryUSB/blob/master/LICENSE"><img src="https://img.shields.io/github/license/cherry-embedded/CherryUSB.svg?style=flat-square"></a>
|
||||
<a href="https://github.com/cherry-embedded/CherryUSB/actions/workflows/deploy-docs.yml"><img src="https://github.com/cherry-embedded/CherryUSB/actions/workflows/deploy-docs.yml/badge.svg"> </a>
|
||||
<a href="https://discord.com/invite/wFfvrSAey8"><img src="https://img.shields.io/badge/Discord-blue?logo=discord&style=flat-square"> </a>
|
||||
</p>
|
||||
|
||||
CherryUSB is a tiny, beautiful and portable USB host and device stack for embedded system with USB IP.
|
||||
CherryUSB is a tiny and beautiful, high performance and portable USB host and device stack for embedded system with USB IP.
|
||||
|
||||

|
||||
|
||||
## Why choose
|
||||
## Why choose CherryUSB
|
||||
|
||||
### Easy to study USB
|
||||
|
||||
@@ -52,78 +58,84 @@ Taking into account USB performance issues and trying to achieve the theoretical
|
||||
|
||||
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:
|
||||
CherryUSB Device Stack has the following functions:
|
||||
|
||||
- Support USB2.0 full and high speed, USB3.0 super speed
|
||||
- Support USB2.0 full and high speed(USB3.0 super speed TODO)
|
||||
- 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 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、WEBUSB、BOS
|
||||
- Support Media Transfer Protocol (MTP)
|
||||
- Support WINUSB1.0, WINUSB2.0, WEBUSB, BOS
|
||||
- Support Vendor class
|
||||
- Support UF2
|
||||
- Support Android Debug Bridge (Only support shell)
|
||||
- Support multi device with the same USB IP
|
||||
|
||||
CherryUSB Device Stack resource usage (GCC 10.2 with -O2):
|
||||
CherryUSB Device Stack resource usage (GCC 10.2 with -O2, disable log):
|
||||
|
||||
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||
|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:|
|
||||
|usbd_core.c | ~4400 | 512(default) + 320 | 0 | 0 |
|
||||
|usbd_cdc_acm.c | ~400 | 0 | 0 | 0 |
|
||||
|usbd_msc.c | ~3800 | 128 + 512(default) | 16 | 0 |
|
||||
|usbd_hid.c | ~360 | 0 | 0 | 0 |
|
||||
|usbd_audio.c | ~1500 | 0 | 0 | 0 |
|
||||
|usbd_video.c | ~2600 | 0 | 84 | 0 |
|
||||
|usbd_rndis.c | ~2100 | 2 * 1580(default)+156+8 | 76 | 0 |
|
||||
|usbd_core.c | ~4500 | (512(default) + 320) * bus | 0 | 0 |
|
||||
|usbd_cdc_acm.c | ~900 | 0 | 0 | 0 |
|
||||
|usbd_msc.c | ~5000 | (128 + 512(default)) * bus | 16 * bus | 0 |
|
||||
|usbd_hid.c | ~300 | 0 | 0 | 0 |
|
||||
|usbd_audio.c | ~4000 | 0 | 0 | 0 |
|
||||
|usbd_video.c | ~7000 | 0 | 132 * bus | 0 |
|
||||
|usbd_rndis.c | ~2500 | 2 * 1580(default)+156+8 | 80 | 0 |
|
||||
|usbd_cdc_ecm.c | ~900 | 2 * 1514(default)+16 | 42 | 0 |
|
||||
|usbd_mtp.c | ~9000 | 2048(default)+128 | sizeof(struct mtp_object) * n| 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.
|
||||
The CherryUSB Host Stack has a standard enumeration implementation for devices mounted on root hubs 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:
|
||||
CherryUSB Host Stack has the following functions:
|
||||
|
||||
- Support low speed, full speed, high speed and super speed devices
|
||||
- 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)
|
||||
- Multi-level HUB support, expandable up to 7 levels(Testing hub with 10 ports works well,only support dwc2/ehci/xhci/rp2040)
|
||||
- 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 Video CLASS (UVC1.0, UVC1.5)
|
||||
- Support USB Audio CLASS (UAC1.0)
|
||||
- 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 (serial, net, wifi)
|
||||
- Support USB modeswitch
|
||||
- Support Android Open Accessory
|
||||
- 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):
|
||||
CherryUSB Host Stack resource usage (GCC 10.2 with -O2, disable log):
|
||||
|
||||
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||
|:-------------:|:--------------:|:-------------------------------:|:---------------------------:|:------------:|
|
||||
|usbh_core.c | ~9000 | 512 + 8 * (1+x) *n | 28 | raw_config_desc |
|
||||
|usbh_hub.c | ~6000 | 32 + 4 * (1+x) | 12 + sizeof(struct usbh_hub) * (1+x) | 0 |
|
||||
|usbh_cdc_acm.c | ~900 | 7 | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|
||||
|usbh_msc.c | ~2700 | 64 | 4 + sizeof(struct usbh_msc) * x | 0 |
|
||||
|usbh_hid.c | ~1400 | 256 | 4 + sizeof(struct usbh_hid) * x | 0 |
|
||||
|usbh_video.c | ~3800 | 128 | 4 + sizeof(struct usbh_video) * x | 0 |
|
||||
|usbh_audio.c | ~4100 | 128 | 4 + sizeof(struct usbh_audio) * x | 0 |
|
||||
|usbh_rndis.c | ~4200 | 512 + 2 * 2048(default)| sizeof(struct usbh_rndis) * 1 | 0 |
|
||||
|usbh_cdc_ecm.c | ~2200 | 2 * 1514 + 16 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|
||||
|usbh_cdc_ncm.c | ~3300 | 2 * 2048(default) + 16 + 32 | sizeof(struct usbh_cdc_ncm) * 1 | 0 |
|
||||
|usbh_bluetooth.c | ~1000 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
|
||||
|usbh_core.c | ~4500 | (512(default) + 8 * (1+x) *n) * bus | sizeof(struct usbh_hub) * bus | raw_config_desc |
|
||||
|usbh_hub.c | ~3500 | (32 + 4 * (1+x)) * bus | 12 + sizeof(struct usbh_hub) * x | 0 |
|
||||
|usbh_cdc_acm.c | ~600 | 7 * x | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|
||||
|usbh_msc.c | ~2000 | 128 * x | 4 + sizeof(struct usbh_msc) * x | 0 |
|
||||
|usbh_hid.c | ~800 | 64 * x | 4 + sizeof(struct usbh_hid) * x | 0 |
|
||||
|usbh_video.c | ~5000 | 128 * x | 4 + sizeof(struct usbh_video) * x | 0 |
|
||||
|usbh_audio.c | ~4000 | 128 * x | 4 + sizeof(struct usbh_audio) * x | 0 |
|
||||
|usbh_rndis.c | ~3000 | 512 + 2 * 2048(default)| sizeof(struct usbh_rndis) * 1 | 0 |
|
||||
|usbh_cdc_ecm.c | ~1500 | 2 * 1514 + 16 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|
||||
|usbh_cdc_ncm.c | ~2000 | 2 * 2048(default) + 16 + 32 | sizeof(struct usbh_cdc_ncm) * 1| 0 |
|
||||
|usbh_bluetooth.c | ~1000 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
|
||||
|usbh_asix.c | ~7000 | 2 * 2048(default) + 16 + 32 | sizeof(struct usbh_asix) * 1 | 0 |
|
||||
|usbh_rtl8152.c | ~9000 | 16K+ 2K(default) + 2 + 32 | sizeof(struct usbh_rtl8152) * 1 | 0 |
|
||||
|
||||
Among them, `sizeof(struct usbh_hub)` and `sizeof(struct usbh_hubport)` are affected by the following macros:
|
||||
Among them, `sizeof(struct usbh_hub)` and `sizeof(struct usbh_hubport)` are affected by the following macros:
|
||||
|
||||
```
|
||||
#define CONFIG_USBHOST_MAX_EXTHUBS 1
|
||||
@@ -133,7 +145,7 @@ Among them, `sizeof(struct usbh_hub)` and `sizeof(struct usbh_hubport)` are affe
|
||||
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
|
||||
```
|
||||
|
||||
x is affected by the following macros:
|
||||
x is affected by the following macros:
|
||||
|
||||
```
|
||||
#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
|
||||
@@ -149,7 +161,7 @@ Only standard and commercial USB IP are listed.
|
||||
|
||||
| IP | device | host | Support status |
|
||||
|:----------------:|:----------:|:--------:|:--------------:|
|
||||
| OHCI(intel) | none | OHCI | × |
|
||||
| OHCI(intel) | none | OHCI | √ |
|
||||
| EHCI(intel) | none | EHCI | √ |
|
||||
| XHCI(intel) | none | XHCI | √ |
|
||||
| UHCI(intel) | none | UHCI | × |
|
||||
@@ -163,34 +175,36 @@ Only standard and commercial USB IP are listed.
|
||||
|
||||
## Documentation Tutorial
|
||||
|
||||
Quickly start, USB basic concepts, API manual, Class basic concepts and examples, see [CherryUSB Documentation Tutorial](https://cherryusb.readthedocs.io/)
|
||||
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).
|
||||
CherryUSB Cheese (based V1.4.3): https://www.bilibili.com/cheese/play/ss707687201 .
|
||||
|
||||
## Graphical Config Tool
|
||||
## Descriptor Generator 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.
|
||||
TODO
|
||||
|
||||
## 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 |
|
||||
|ST | STM32F1x/STM32F4/STM32H7 | fsdev/dwc2 |[stm32_repo](https://github.com/CherryUSB/cherryusb_stm32)|<= latest | Long-term |
|
||||
|HPMicro | HPM6000/HPM5000 | 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)|>=1.4.0 | Long-term |
|
||||
|Artinchip | d12x/d13x/d21x | aic/ehci/ohci |[luban-lite](https://gitee.com/artinchip/luban-lite)|<= latest | Long-term |
|
||||
|Espressif | esp32s2/esp32s3/esp32p4 | dwc2 |[esp32_repo](https://github.com/CherryUSB/cherryusb_esp32)|<= latest | Long-term |
|
||||
|NXP | mcx | kinetis/chipidea/ehci |[nxp_mcx_repo](https://github.com/CherryUSB/cherryusb_mcx)|<= latest | Long-term |
|
||||
|Kendryte | k230 | dwc2 |[k230_repo](https://github.com/CherryUSB/k230_sdk)|v1.2.0 | Long-term |
|
||||
|Actionstech | ATS30xx | dwc2 |[action_zephyr_repo](https://github.com/CherryUSB/lv_port_actions_technology/tree/master/action_technology_sdk)|>=1.4.0 | Long-term |
|
||||
|Nationstech | n32h4x | dwc2 |[nation_repo](https://github.com/CherryUSB/cherryusb_nation)|>=1.5.0 | Long-term |
|
||||
|Raspberry pi | rp2040/rp2350 | rp2040 |[pico-examples](https://github.com/CherryUSB/pico-examples)|<= latest | Long-term |
|
||||
|AllwinnerTech | F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s](https://github.com/CherryUSB/cherryusb_rtt_f1c100s)|<= latest | the same with musb |
|
||||
|Bekencorp | bk7256/bk7258 | musb |[bk_idk](https://github.com/CherryUSB/bk_idk)| v0.7.0 | the same with musb |
|
||||
|Sophgo | cv18xx | dwc2 |[cvi_alios_open](https://github.com/CherryUSB/cvi_alios_open)| v0.7.0 | TBD |
|
||||
|WCH | CH32V307/ch58x | ch32_usbfs/ch32_usbhs/ch58x |[wch_repo](https://github.com/CherryUSB/cherryusb_wch)|<= v0.10.2 | TBD |
|
||||
|Raspberry pi | rp2040 | rp2040 |[pico-examples](https://github.com/CherryUSB/pico-examples)|<= v0.10.2 | No more updated |
|
||||
|
||||
## Package Support
|
||||
|
||||
@@ -210,6 +224,7 @@ CherryUSB discord: https://discord.com/invite/wFfvrSAey8.
|
||||
|
||||
## Company Support
|
||||
|
||||
Thanks to the following companies for their support (in no particular order).
|
||||
Thanks to the following companies for their support (in no particular order):
|
||||
|
||||
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" />
|
||||
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" /> <img src="docs/assets/canaan.jpg" width="100" height="80" />
|
||||
<img src="docs/assets/actions.jpg" width="100" height="80" /> <img src="docs/assets/nationstech.jpg" width="100" height="80" />
|
||||
|
||||
95
README_zh.md
95
README_zh.md
@@ -1,12 +1,18 @@
|
||||
# CherryUSB
|
||||
**[English](README.md) | 简体中文**
|
||||
|
||||
[English](./README.md)
|
||||
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">CherryUSB</h1>
|
||||
<p align="center">
|
||||
<a href="https://github.com/cherry-embedded/CherryUSB/releases"><img src="https://img.shields.io/github/release/cherry-embedded/CherryUSB.svg"></a>
|
||||
<a href="https://github.com/cherry-embedded/CherryUSB/blob/master/LICENSE"><img src="https://img.shields.io/github/license/cherry-embedded/CherryUSB.svg?style=flat-square"></a>
|
||||
<a href="https://github.com/cherry-embedded/CherryUSB/actions/workflows/deploy-docs.yml"><img src="https://github.com/cherry-embedded/CherryUSB/actions/workflows/deploy-docs.yml/badge.svg"> </a>
|
||||
<a href="https://discord.com/invite/wFfvrSAey8"><img src="https://img.shields.io/badge/Discord-blue?logo=discord&style=flat-square"> </a>
|
||||
</p>
|
||||
|
||||
CherryUSB 是一个小而美的、可移植性高的、用于嵌入式系统(带 USB IP)的 USB 主从协议栈。
|
||||
CherryUSB 是一个小而美的、可移植性高的、用于嵌入式系统(带 USB IP)的高性能 USB 主从协议栈。
|
||||
|
||||

|
||||
|
||||
## 为什么选择
|
||||
## 为什么选择 CherryUSB
|
||||
|
||||
### 易于学习 USB
|
||||
|
||||
@@ -54,7 +60,7 @@ CherryUSB Device 协议栈对标准设备请求、CLASS 请求、VENDOR 请求
|
||||
|
||||
CherryUSB Device 协议栈当前实现以下功能:
|
||||
|
||||
- 支持 USB2.0 全速和高速设备,USB3.0 超速设备
|
||||
- 支持 USB2.0 全速和高速设备(USB3.0 超高速 TODO)
|
||||
- 支持端点中断注册功能,porting 给用户自己处理中断里的数据
|
||||
- 支持复合设备
|
||||
- 支持 Communication Device Class (CDC_ACM, CDC_ECM)
|
||||
@@ -65,6 +71,7 @@ CherryUSB Device 协议栈当前实现以下功能:
|
||||
- 支持 Device Firmware Upgrade CLASS (DFU)
|
||||
- 支持 USB MIDI CLASS (MIDI)
|
||||
- 支持 Remote NDIS (RNDIS)
|
||||
- 支持 Media Transfer Protocol (MTP)
|
||||
- 支持 WINUSB1.0、WINUSB2.0、WEBUSB、BOS
|
||||
- 支持 Vendor 类 class
|
||||
- 支持 UF2
|
||||
@@ -75,25 +82,27 @@ CherryUSB Device 协议栈资源占用说明(GCC 10.2 with -O2):
|
||||
|
||||
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||
|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:|
|
||||
|usbd_core.c | ~4400 | 512(default) + 320 | 0 | 0 |
|
||||
|usbd_cdc_acm.c | ~400 | 0 | 0 | 0 |
|
||||
|usbd_msc.c | ~3800 | 128 + 512(default) | 16 | 0 |
|
||||
|usbd_hid.c | ~360 | 0 | 0 | 0 |
|
||||
|usbd_audio.c | ~1500 | 0 | 0 | 0 |
|
||||
|usbd_video.c | ~2600 | 0 | 84 | 0 |
|
||||
|usbd_rndis.c | ~2100 | 2 * 1580(default)+156+8 | 76 | 0 |
|
||||
|usbd_core.c | ~4500 | (512(default) + 320) * bus | 0 | 0 |
|
||||
|usbd_cdc_acm.c | ~900 | 0 | 0 | 0 |
|
||||
|usbd_msc.c | ~5000 | (128 + 512(default)) * bus | 16 * bus | 0 |
|
||||
|usbd_hid.c | ~300 | 0 | 0 | 0 |
|
||||
|usbd_audio.c | ~4000 | 0 | 0 | 0 |
|
||||
|usbd_video.c | ~7000 | 0 | 132 * bus | 0 |
|
||||
|usbd_rndis.c | ~2500 | 2 * 1580(default)+156+8 | 80 | 0 |
|
||||
|usbd_cdc_ecm.c | ~900 | 2 * 1514(default)+16 | 42 | 0 |
|
||||
|usbd_mtp.c | ~9000 | 2048(default)+128 | sizeof(struct mtp_object) * n| 0 |
|
||||
|
||||
## Host 协议栈简介
|
||||
|
||||
CherryUSB Host 协议栈对挂载在 roothub、外部 hub 上的设备规范了一套标准的枚举实现,对不同的 Class 类也规范了一套标准接口,用来指示在枚举后和断开连接后该 Class 驱动需要做的事情。同时,规范了一套标准的 hcd porting 接口,用于适配不同的 USB IP,达到面向 IP 编程。最后,协议栈使用 OS 管理,并提供了 osal 用来适配不同的 os。
|
||||
CherryUSB Host 协议栈对挂载在 root hub、外部 hub 上的设备规范了一套标准的枚举实现,对不同的 Class 类也规范了一套标准接口,用来指示在枚举后和断开连接后该 Class 驱动需要做的事情。同时,规范了一套标准的 hcd porting 接口,用于适配不同的 USB IP,达到面向 IP 编程。最后,协议栈使用 OS 管理,并提供了 osal 用来适配不同的 os。
|
||||
|
||||
CherryUSB Host 协议栈当前实现以下功能:
|
||||
|
||||
- 支持 low speed, full speed, high speed 和 super speed 设备
|
||||
- 支持 low speed,full speed,high speed 和 super speed 设备
|
||||
- 自动加载支持的Class 驱动
|
||||
- 支持阻塞式传输和异步传输
|
||||
- 支持复合设备
|
||||
- 支持多级 HUB,最高可拓展到 7 级(目前测试 1拖 10 没有问题,当前仅支持 dwc2 和 ehci)
|
||||
- 支持多级 HUB,最高可拓展到 7 级(目前测试 1拖 10 没有问题,仅支持 dwc2/ehci/xhci/rp2040)
|
||||
- 支持 Communication Device Class (CDC_ACM, CDC_ECM)
|
||||
- 支持 Human Interface Device (HID)
|
||||
- 支持 Mass Storage Class (MSC)
|
||||
@@ -103,25 +112,28 @@ CherryUSB Host 协议栈当前实现以下功能:
|
||||
- 支持 USB Bluetooth (支持 nimble and zephyr bluetooth 协议栈,支持 **CLASS: 0xE0** 或者厂家自定义类,类似于 cdc acm 功能)
|
||||
- 支持 Vendor 类 class (serial, net, wifi)
|
||||
- 支持 USB modeswitch
|
||||
- 支持 Android Open Accessory
|
||||
- 支持相同 USB IP 的多主机
|
||||
|
||||
同时,CherryUSB Host 协议栈还提供了 lsusb 的功能,借助 shell 插件可以查看所有挂载设备的信息,包括外部 hub 上的设备的信息。
|
||||
|
||||
CherryUSB Host 协议栈资源占用说明(GCC 10.2 with -O2):
|
||||
CherryUSB Host 协议栈资源占用说明(GCC 10.2 with -O2,关闭 log):
|
||||
|
||||
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|
||||
|:-------------:|:--------------:|:-------------------------------:|:---------------------------:|:------------:|
|
||||
|usbh_core.c | ~9000 | 512 + 8 * (1+x) *n | 28 | raw_config_desc |
|
||||
|usbh_hub.c | ~6000 | 32 + 4 * (1+x) | 12 + sizeof(struct usbh_hub) * (1+x) | 0 |
|
||||
|usbh_cdc_acm.c | ~900 | 7 | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|
||||
|usbh_msc.c | ~2700 | 64 | 4 + sizeof(struct usbh_msc) * x | 0 |
|
||||
|usbh_hid.c | ~1400 | 256 | 4 + sizeof(struct usbh_hid) * x | 0 |
|
||||
|usbh_video.c | ~3800 | 128 | 4 + sizeof(struct usbh_video) * x | 0 |
|
||||
|usbh_audio.c | ~4100 | 128 | 4 + sizeof(struct usbh_audio) * x | 0 |
|
||||
|usbh_rndis.c | ~4200 | 512 + 2 * 2048(default)| sizeof(struct usbh_rndis) * 1 | 0 |
|
||||
|usbh_cdc_ecm.c | ~2200 | 2 * 1514 + 16 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|
||||
|usbh_cdc_ncm.c | ~3300 | 2 * 2048(default) + 16 + 32 | sizeof(struct usbh_cdc_ncm) * 1 | 0 |
|
||||
|usbh_bluetooth.c | ~1000 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
|
||||
|usbh_core.c | ~4500 | (512(default) + 8 * (1+x) *n) * bus | sizeof(struct usbh_hub) * bus | raw_config_desc |
|
||||
|usbh_hub.c | ~3500 | (32 + 4 * (1+x)) * bus | 12 + sizeof(struct usbh_hub) * x | 0 |
|
||||
|usbh_cdc_acm.c | ~600 | 7 * x | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|
||||
|usbh_msc.c | ~2000 | 128 * x | 4 + sizeof(struct usbh_msc) * x | 0 |
|
||||
|usbh_hid.c | ~800 | 64 * x | 4 + sizeof(struct usbh_hid) * x | 0 |
|
||||
|usbh_video.c | ~5000 | 128 * x | 4 + sizeof(struct usbh_video) * x | 0 |
|
||||
|usbh_audio.c | ~4000 | 128 * x | 4 + sizeof(struct usbh_audio) * x | 0 |
|
||||
|usbh_rndis.c | ~3000 | 512 + 2 * 2048(default)| sizeof(struct usbh_rndis) * 1 | 0 |
|
||||
|usbh_cdc_ecm.c | ~1500 | 2 * 1514 + 16 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|
||||
|usbh_cdc_ncm.c | ~2000 | 2 * 2048(default) + 16 + 32 | sizeof(struct usbh_cdc_ncm) * 1| 0 |
|
||||
|usbh_bluetooth.c | ~1000 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
|
||||
|usbh_asix.c | ~7000 | 2 * 2048(default) + 16 + 32 | sizeof(struct usbh_asix) * 1 | 0 |
|
||||
|usbh_rtl8152.c | ~9000 | 16K+ 2K(default) + 2 + 32 | sizeof(struct usbh_rtl8152) * 1 | 0 |
|
||||
|
||||
其中,`sizeof(struct usbh_hub)` 和 `sizeof(struct usbh_hubport)` 受以下宏影响:
|
||||
|
||||
@@ -149,7 +161,7 @@ x 受以下宏影响:
|
||||
|
||||
| IP | device | host | Support status |
|
||||
|:----------------:|:----------:|:--------:|:--------------:|
|
||||
| OHCI(intel) | none | OHCI | × |
|
||||
| OHCI(intel) | none | OHCI | √ |
|
||||
| EHCI(intel) | none | EHCI | √ |
|
||||
| XHCI(intel) | none | XHCI | √ |
|
||||
| UHCI(intel) | none | UHCI | × |
|
||||
@@ -163,39 +175,40 @@ x 受以下宏影响:
|
||||
|
||||
## 文档教程
|
||||
|
||||
CherryUSB 快速入门、USB 基本概念,API 手册,Class 基本概念和例程,参考 [CherryUSB Documentation Tutorial](https://cherryusb.readthedocs.io/)
|
||||
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.
|
||||
CherryUSB 课程(基于 V1.4.3):https://www.bilibili.com/cheese/play/ss707687201 。
|
||||
|
||||
## 图形化界面配置工具
|
||||
## 描述符生成工具
|
||||
|
||||
[chryusb_configurator](https://github.com/Egahp/chryusb_configurator) 采用 **electron + vite2 + ts** 框架编写,当前用于自动化生成描述符数组,后续会增加其他功能。
|
||||
TODO
|
||||
|
||||
## 示例仓库
|
||||
|
||||
| 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 |
|
||||
|ST | STM32F1x/STM32F4/STM32H7 | fsdev/dwc2 |[stm32_repo](https://github.com/CherryUSB/cherryusb_stm32)|<= latest | Long-term |
|
||||
|HPMicro | HPM6000/HPM5000 | 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)|>=1.4.0 | Long-term |
|
||||
|Artinchip | d12x/d13x/d21x | aic/ehci/ohci |[luban-lite](https://gitee.com/artinchip/luban-lite)|<= latest | Long-term |
|
||||
|Espressif | esp32s2/esp32s3/esp32p4 | dwc2 |[esp32_repo](https://github.com/CherryUSB/cherryusb_esp32)|<= latest | Long-term |
|
||||
|NXP | mcx | kinetis/chipidea/ehci |[nxp_mcx_repo](https://github.com/CherryUSB/cherryusb_mcx)|<= latest | Long-term |
|
||||
|Kendryte | k230 | dwc2 |[k230_repo](https://github.com/CherryUSB/k230_sdk)|v1.2.0 | Long-term |
|
||||
|Actionstech | ATS30xx | dwc2 |[action_zephyr_repo](https://github.com/CherryUSB/lv_port_actions_technology/tree/master/action_technology_sdk)|>=1.4.0 | Long-term |
|
||||
|Nationstech | n32h4x | dwc2 |[nation_repo](https://github.com/CherryUSB/cherryusb_nation)|>=1.5.0 | Long-term |
|
||||
|Raspberry pi | rp2040/rp2350 | rp2040 |[pico-examples](https://github.com/CherryUSB/pico-examples)|<= latest | Long-term |
|
||||
|AllwinnerTech | F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s](https://github.com/CherryUSB/cherryusb_rtt_f1c100s)|<= latest | the same with musb |
|
||||
|Bekencorp | bk7256/bk7258 | musb |[bk_idk](https://github.com/CherryUSB/bk_idk)| v0.7.0 | the same with musb |
|
||||
|Sophgo | cv18xx | dwc2 |[cvi_alios_open](https://github.com/CherryUSB/cvi_alios_open)| v0.7.0 | TBD |
|
||||
|WCH | CH32V307/ch58x | ch32_usbfs/ch32_usbhs/ch58x |[wch_repo](https://github.com/CherryUSB/cherryusb_wch)|<= v0.10.2 | TBD |
|
||||
|Raspberry pi | rp2040 | rp2040 |[pico-examples](https://github.com/CherryUSB/pico-examples)|<= v0.10.2 | No more updated |
|
||||
|
||||
## 软件包支持
|
||||
|
||||
CherryUSB 软件包可以通过以下方式获取:
|
||||
CherryUSB 软件包可以通过以下方式获取:
|
||||
|
||||
- [RT-Thread](https://packages.rt-thread.org/detail.html?package=CherryUSB)
|
||||
- [YOC](https://www.xrvm.cn/document?temp=usb-host-protocol-stack-device-driver-adaptation-instructions&slug=yocbook)
|
||||
@@ -207,11 +220,13 @@ CherryUSB 软件包可以通过以下方式获取:
|
||||
|
||||
## 联系
|
||||
|
||||
CherryUSB QQ 群:642693751
|
||||
CherryUSB QQ群:642693751
|
||||
|
||||
CherryUSB 微信群:与我联系后邀请加入
|
||||
|
||||
## 支持企业
|
||||
|
||||
感谢以下企业支持(顺序不分先后)。
|
||||
感谢以下企业支持(顺序不分先后):
|
||||
|
||||
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" />
|
||||
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" /> <img src="docs/assets/canaan.jpg" width="100" height="80" />
|
||||
<img src="docs/assets/actions.jpg" width="100" height="80" /> <img src="docs/assets/nationstech.jpg" width="100" height="80" />
|
||||
|
||||
63
SConscript
63
SConscript
@@ -1,18 +1,23 @@
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
path = [cwd + '/common']
|
||||
path = [cwd]
|
||||
path += [cwd + '/common']
|
||||
path += [cwd + '/core']
|
||||
path += [cwd + '/class/hub']
|
||||
path += [cwd + '/class/cdc']
|
||||
path += [cwd + '/class/msc']
|
||||
path += [cwd + '/class/hid']
|
||||
path += [cwd + '/class/audio']
|
||||
path += [cwd + '/class/video']
|
||||
path += [cwd + '/class/wireless']
|
||||
path += [cwd + '/class/midi']
|
||||
path += [cwd + '/class/adb']
|
||||
path += [cwd + '/class/dfu']
|
||||
path += [cwd + '/class/midi']
|
||||
path += [cwd + '/class/vendor/net']
|
||||
path += [cwd + '/class/vendor/serial']
|
||||
path += [cwd + '/class/vendor/wifi']
|
||||
src = []
|
||||
|
||||
LIBS = []
|
||||
@@ -25,10 +30,13 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
|
||||
src += Glob('core/usbd_core.c')
|
||||
src += Glob('osal/usb_osal_rtthread.c')
|
||||
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_HS']):
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_SPEED_HS']):
|
||||
CPPDEFINES+=['CONFIG_USB_HS']
|
||||
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_FSDEV']):
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_FSDEV_ST']):
|
||||
src += Glob('port/fsdev/usb_dc_fsdev.c')
|
||||
src += Glob('port/fsdev/usb_glue_st.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_FSDEV_CUSTOM']):
|
||||
src += Glob('port/fsdev/usb_dc_fsdev.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_ST']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
@@ -36,15 +44,21 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_ESP']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_esp.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_KENDRYTE']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_kendryte.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_AT']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_at.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_GD']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_gd.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_HC']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_hc.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_NATION']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_nation.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_GD']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_gd.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_CUSTOM']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_MUSB_ES']):
|
||||
@@ -58,18 +72,23 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
|
||||
src += Glob('port/musb/usb_glue_bk.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_MUSB_CUSTOM']):
|
||||
src += Glob('port/musb/usb_dc_musb.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_CHIPIDEA_MCX']):
|
||||
path += [cwd + '/port/chipidea']
|
||||
src += Glob('port/chipidea/usb_dc_chipidea.c')
|
||||
src += Glob('port/nxp/usb_glue_mcx.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_CHIPIDEA_CUSTOM']):
|
||||
path += [cwd + '/port/chipidea']
|
||||
src += Glob('port/chipidea/usb_dc_chipidea.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_KINETIS_MCX']):
|
||||
src += Glob('port/kinetis/usb_dc_kinetis.c')
|
||||
src += Glob('port/kinetis/usb_glue_mcx.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_KINETIS_CUSTOM']):
|
||||
src += Glob('port/kinetis/usb_dc_kinetis.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_CHIPIDEA_MCX']):
|
||||
src += Glob('port/chipidea/usb_dc_chipidea.c')
|
||||
src += Glob('port/chipidea/usb_glue_mcx.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_BL']):
|
||||
src += Glob('port/bouffalolab/usb_dc_bl.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_HPM']):
|
||||
src += Glob('port/hpm/usb_dc_hpm.c')
|
||||
src += Glob('port/hpmicro/usb_dc_hpm.c')
|
||||
src += Glob('port/hpmicro/usb_glue_hpm.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_AIC']):
|
||||
src += Glob('port/aic/usb_dc_aic.c')
|
||||
src += Glob('port/aic/usb_dc_aic_ll.c')
|
||||
@@ -79,7 +98,7 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
|
||||
else:
|
||||
src += Glob('port/ch32/usb_dc_usbfs.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_PUSB2']):
|
||||
path += [cwd + '/port/xhci/rt-thread']
|
||||
path += [cwd + '/port/pusb2/rt-thread']
|
||||
src += Glob('port/pusb2/rt-thread/usb_dc_glue_phytium.c')
|
||||
if GetDepend(['ARCH_ARMV8']):
|
||||
LIBPATH = [cwd + '/port/pusb2']
|
||||
@@ -87,6 +106,8 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
|
||||
if GetDepend(['ARCH_ARM_CORTEX_A']):
|
||||
LIBPATH = [cwd + '/port/pusb2']
|
||||
LIBS = ['libpusb2_dc_a32_softfp_neon.a']
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_NRF5X']):
|
||||
src += Glob('port/nrf5x/usb_dc_nrf5x.c')
|
||||
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_CDC_ACM']):
|
||||
src += Glob('class/cdc/usbd_cdc_acm.c')
|
||||
@@ -104,13 +125,15 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
|
||||
src += Glob('class/cdc/usbd_cdc_ecm.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_CDC_NCM']):
|
||||
src += Glob('class/cdc/usbd_cdc_ncm.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_USING_DFU']):
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DFU']):
|
||||
src += Glob('class/dfu/usbd_dfu.c')
|
||||
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM']):
|
||||
src += Glob('demo/cdc_acm_template.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_MSC']):
|
||||
src += Glob('demo/msc_ram_template.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_MSC_BLKDEV']):
|
||||
src += Glob('platform/rtthread/usbd_msc_blkdev.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_HID_MOUSE']):
|
||||
src += Glob('demo/hid_mouse_template.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_HID_KEYBOARD']):
|
||||
@@ -142,7 +165,6 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
|
||||
|
||||
# USB HOST
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST']):
|
||||
path += [cwd + '/class/hub']
|
||||
src += Glob('core/usbh_core.c')
|
||||
src += Glob('class/hub/usbh_hub.c')
|
||||
src += Glob('osal/usb_osal_rtthread.c')
|
||||
@@ -152,7 +174,8 @@ if GetDepend(['PKG_CHERRYUSB_HOST']):
|
||||
src += Glob('port/ehci/usb_glue_bouffalo.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_EHCI_HPM']):
|
||||
src += Glob('port/ehci/usb_hc_ehci.c')
|
||||
src += Glob('port/ehci/usb_glue_hpm.c')
|
||||
src += Glob('port/hpmicro/usb_hc_hpm.c')
|
||||
src += Glob('port/hpmicro/usb_glue_hpm.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_EHCI_AIC']):
|
||||
path += [cwd + '/port/ehci']
|
||||
path += [cwd + '/port/ohci']
|
||||
@@ -162,7 +185,7 @@ if GetDepend(['PKG_CHERRYUSB_HOST']):
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_EHCI_MCX']):
|
||||
path += [cwd + '/port/chipidea']
|
||||
src += Glob('port/ehci/usb_hc_ehci.c')
|
||||
src += Glob('port/ehci/usb_glue_mcx.c')
|
||||
src += Glob('port/nxp/usb_glue_mcx.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_EHCI_NUC980']):
|
||||
src += Glob('port/ehci/usb_hc_ehci.c')
|
||||
src += Glob('port/ehci/usb_glue_nuc980.c')
|
||||
@@ -177,6 +200,15 @@ if GetDepend(['PKG_CHERRYUSB_HOST']):
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_DWC2_ESP']):
|
||||
src += Glob('port/dwc2/usb_hc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_esp.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_DWC2_KENDRYTE']):
|
||||
src += Glob('port/dwc2/usb_hc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_kendryte.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_DWC2_HC']):
|
||||
src += Glob('port/dwc2/usb_hc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_hc.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_DWC2_NATION']):
|
||||
src += Glob('port/dwc2/usb_hc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_nation.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_DWC2_CUSTOM']):
|
||||
src += Glob('port/dwc2/usb_hc_dwc2.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_MUSB_STANDARD']):
|
||||
@@ -250,6 +282,7 @@ if GetDepend(['PKG_CHERRYUSB_HOST']):
|
||||
src += Glob('class/vendor/serial/usbh_pl2303.c')
|
||||
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_TEMPLATE']):
|
||||
CPPDEFINES+=['TEST_USBH_MSC=0']
|
||||
src += Glob('demo/usb_host.c')
|
||||
|
||||
if GetDepend('RT_USING_DFS') and GetDepend(['PKG_CHERRYUSB_HOST_MSC']):
|
||||
|
||||
4
VERSION
4
VERSION
@@ -1,5 +1,5 @@
|
||||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 4
|
||||
PATCHLEVEL = 1
|
||||
VERSION_MINOR = 5
|
||||
PATCHLEVEL = 0
|
||||
VERSION_TWEAK = 0
|
||||
EXTRAVERSION = 0
|
||||
|
||||
342
cherryusb.cmake
342
cherryusb.cmake
@@ -4,11 +4,15 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# cmake-format: off
|
||||
|
||||
# set(CONFIG_CHERRYUSB_DEVICE 1)
|
||||
# set(CONFIG_CHERRYUSB_DEVICE_CDC 1)
|
||||
# set(CONFIG_CHERRYUSB_DEVICE_HID 1)
|
||||
# set(CONFIG_CHERRYUSB_DEVICE_MSC 1)
|
||||
# set(CONFIG_CHERRYUSB_DEVICE_DCD "dwc2_st")
|
||||
# set(CONFIG_CHERRYUSB_DEVICE_AUDIO 1)
|
||||
# set(CONFIG_CHERRYUSB_DEVICE_VIDEO 1)
|
||||
# set(CONFIG_CHERRYUSB_DEVICE_DWC2_ST 1)
|
||||
|
||||
# set(CONFIG_CHERRYUSB_HOST 1)
|
||||
# set(CONFIG_CHERRYUSB_HOST_CDC_ACM 1)
|
||||
@@ -22,276 +26,336 @@
|
||||
# set(CONFIG_CHERRYUSB_HOST_BLUETOOTH 1)
|
||||
# set(CONFIG_CHERRYUSB_HOST_ASIX 1)
|
||||
# set(CONFIG_CHERRYUSB_HOST_RTL8152 1)
|
||||
# set(CONFIG_CHERRYUSB_OSAL "freertos")
|
||||
# set(CONFIG_CHERRYUSB_HOST_HCD "ehci_xxx")
|
||||
# set(CONFIG_CHERRYUSB_HOST_DWC2_ST 1)
|
||||
|
||||
list(APPEND cherryusb_incs
|
||||
${CMAKE_CURRENT_LIST_DIR}/common
|
||||
${CMAKE_CURRENT_LIST_DIR}/core
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/hub
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/cdc
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/hid
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/msc
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/audio
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/video
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/wireless
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/midi
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/adb
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/vendor/net
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/vendor/wifi
|
||||
# set(CONFIG_CHERRYUSB_OSAL "freertos")
|
||||
# cmake-format: on
|
||||
|
||||
list(
|
||||
APPEND
|
||||
cherryusb_incs
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/common
|
||||
${CMAKE_CURRENT_LIST_DIR}/core
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/hub
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/cdc
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/hid
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/msc
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/audio
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/video
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/wireless
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/midi
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/adb
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/dfu
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/vendor/net
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/vendor/wifi
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/aoa
|
||||
)
|
||||
|
||||
if(CONFIG_CHERRYUSB_DEVICE)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/core/usbd_core.c)
|
||||
if(CONFIG_CHERRYUSB_DEVICE_CDC_ACM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbd_cdc_acm.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbd_cdc_acm.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_DEVICE_HID)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/hid/usbd_hid.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/hid/usbd_hid.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_DEVICE_MSC)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/msc/usbd_msc.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/msc/usbd_msc.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_DEVICE_AUDIO)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/audio/usbd_audio.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/audio/usbd_audio.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_DEVICE_VIDEO)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/video/usbd_video.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/video/usbd_video.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_DEVICE_CDC_ECM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbd_cdc_ecm.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbd_cdc_ecm.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_DEVICE_CDC_NCM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbd_cdc_ncm.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbd_cdc_ncm.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_DEVICE_CDC_RNDIS)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/wireless/usbd_rndis.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/wireless/usbd_rndis.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_DEVICE_DFU)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/dfu/usbd_dfu.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/dfu/usbd_dfu.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_DEVICE_ADB)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/adb/usbd_adb.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/adb/usbd_adb.c)
|
||||
endif()
|
||||
|
||||
if(DEFINED CONFIG_CHERRYUSB_DEVICE_DCD)
|
||||
if("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "fsdev")
|
||||
if(CONFIG_CHERRYUSB_DEVICE_FSDEV_ST)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/fsdev/usb_dc_fsdev.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "dwc2_st")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/fsdev/usb_glue_st.c)
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_FSDEV_CUSTOM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/fsdev/usb_dc_fsdev.c)
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_DWC2_ST)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_dc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_st.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "dwc2_esp")
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_DWC2_ESP)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_dc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_esp.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "dwc2_at")
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_DWC2_KENDRYTE)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_dc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_kendryte.c)
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_DWC2_AT)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_dc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_at.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "dwc2_gd")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_dc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_gd.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "dwc2_hc")
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_DWC2_HC)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_dc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_hc.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "musb_es")
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_DWC2_GD)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_dc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_gd.c)
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_DWC2_CUSTOM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_dc_dwc2.c)
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_MUSB_ES)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_dc_musb.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_glue_es.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "musb_sunxi")
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_MUSB_SUNXI)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_dc_musb.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_glue_sunxi.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "musb_bk")
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_MUSB_BK)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_dc_musb.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_glue_bk.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "chipidea_mcx")
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_MUSB_CUSTOM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_dc_musb.c)
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_CHIPIDEA_MCX)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/chipidea/usb_dc_chipidea.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/chipidea/usb_glue_mcx.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "kinetis_mcx")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/nxp/usb_glue_mcx.c)
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_KINETIS_MCX)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_dc_kinetis.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_glue_mcx.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "hpm")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpm/usb_dc_hpm.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "bl")
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/chipidea)
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_CHIPIDEA_CUSTOM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/chipidea/usb_dc_chipidea.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/chipidea)
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_HPM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro/usb_dc_hpm.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro/usb_glue_hpm.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro)
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_BL)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/bouffalolab/usb_dc_bl.c)
|
||||
elseif("${CONFIG_CHERRYUSB_DEVICE_DCD}" STREQUAL "aic")
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_AIC)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/aic/usb_dc_aic.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/aic/usb_dc_aic_ll.c)
|
||||
endif()
|
||||
elseif(CONFIG_CHERRYUSB_DEVICE_RP2040)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/rp2040/usb_dc_rp2040.c)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if(CONFIG_CHERRYUSB_HOST)
|
||||
list(APPEND cherryusb_srcs
|
||||
${CMAKE_CURRENT_LIST_DIR}/core/usbh_core.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/hub/usbh_hub.c
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/core/usbh_core.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/class/hub/usbh_hub.c
|
||||
)
|
||||
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_ACM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbh_cdc_acm.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbh_cdc_acm.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_ECM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbh_cdc_ecm.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbh_cdc_ecm.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_RNDIS)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/wireless/usbh_rndis.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/wireless/usbh_rndis.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_NCM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbh_cdc_ncm.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/cdc/usbh_cdc_ncm.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_HID)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/hid/usbh_hid.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/hid/usbh_hid.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_MSC)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/msc/usbh_msc.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/msc/usbh_msc.c)
|
||||
|
||||
if(CONFIG_CHERRYUSB_HOST_MSC_FATFS)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source/port/fatfs_usbh.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source/diskio.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source/ff.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source/ffsystem.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source/ffunicode.c)
|
||||
if(CONFIG_CHERRYUSB_HOST_MSC_FATFS)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source/port/fatfs_usbh.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source/diskio.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source/ff.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source/ffsystem.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source/ffunicode.c)
|
||||
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source)
|
||||
endif()
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/fatfs-0.14/source)
|
||||
endif()
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_VIDEO)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/video/usbh_video.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/video/usbh_video.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_AUDIO)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/audio/usbh_audio.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/audio/usbh_audio.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_BLUETOOTH)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/wireless/usbh_bluetooth.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/wireless/usbh_bluetooth.c)
|
||||
|
||||
set(BLUETOOTH_PATH ${CMAKE_CURRENT_LIST_DIR}/third_party/zephyr_bluetooth-2.7.5)
|
||||
set(BLUETOOTH_PATH ${CMAKE_CURRENT_LIST_DIR}/third_party/zephyr_bluetooth-2.7.5)
|
||||
|
||||
list(APPEND cherryusb_srcs
|
||||
${BLUETOOTH_PATH}/ble_hci_usbh.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/beacon/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/central/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/central_hr/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/central_ht/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/central_multilink/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/central_multilink/src/central_multilink.c
|
||||
# ${BLUETOOTH_PATH}/zephyr_bluetooth/examples/handsfree/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/ibeacon/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral/src/cts.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_csc/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_dis/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_esp/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_hids/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_hids/src/hog.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_hr/src/main.c
|
||||
# ${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_ht/src/main.c
|
||||
# ${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_ht/src/hts.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_identity/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_identity/src/peripheral_identity.c
|
||||
# ${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_ots/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_sc_only/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/scan_adv/src/main.c
|
||||
)
|
||||
list(
|
||||
APPEND
|
||||
cherryusb_srcs
|
||||
${BLUETOOTH_PATH}/ble_hci_usbh.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/beacon/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/central/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/central_hr/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/central_ht/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/central_multilink/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/central_multilink/src/central_multilink.c
|
||||
# ${BLUETOOTH_PATH}/zephyr_bluetooth/examples/handsfree/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/ibeacon/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral/src/cts.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_csc/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_dis/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_esp/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_hids/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_hids/src/hog.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_hr/src/main.c
|
||||
# ${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_ht/src/main.c
|
||||
# ${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_ht/src/hts.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_identity/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_identity/src/peripheral_identity.c
|
||||
# ${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_ots/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/peripheral_sc_only/src/main.c
|
||||
${BLUETOOTH_PATH}/zephyr_bluetooth/examples/scan_adv/src/main.c
|
||||
)
|
||||
|
||||
include(${BLUETOOTH_PATH}/zephyr_bluetooth/zephyr_bluetooth.cmake)
|
||||
list(APPEND cherryusb_srcs ${zephyr_bluetooth_srcs})
|
||||
list(APPEND cherryusb_incs ${zephyr_bluetooth_incs})
|
||||
include(${BLUETOOTH_PATH}/zephyr_bluetooth/zephyr_bluetooth.cmake)
|
||||
list(APPEND cherryusb_srcs ${zephyr_bluetooth_srcs})
|
||||
list(APPEND cherryusb_incs ${zephyr_bluetooth_incs})
|
||||
endif()
|
||||
|
||||
if(CONFIG_CHERRYUSB_HOST_ASIX)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/net/usbh_asix.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/net/usbh_asix.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_RTL8152)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/net/usbh_rtl8152.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/net/usbh_rtl8152.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CH34X)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial/usbh_ch34x.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial/usbh_ch34x.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_CP210X)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial/usbh_cp210x.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial/usbh_cp210x.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_FTDI)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial/usbh_ftdi.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial/usbh_ftdi.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_PL2303)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial/usbh_pl2303.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/serial/usbh_pl2303.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_BL616)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/wifi/usbh_bl616.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/vendor/wifi/usbh_bl616.c)
|
||||
endif()
|
||||
if(CONFIG_CHERRYUSB_HOST_AOA)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/class/aoa/usbh_aoa.c)
|
||||
endif()
|
||||
|
||||
if(DEFINED CONFIG_CHERRYUSB_HOST_HCD)
|
||||
if("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "ehci_bouffalo")
|
||||
if(CONFIG_CHERRYUSB_HOST_CDC_ECM
|
||||
OR CONFIG_CHERRYUSB_HOST_CDC_RNDIS
|
||||
OR CONFIG_CHERRYUSB_HOST_CDC_NCM
|
||||
OR CONFIG_CHERRYUSB_HOST_ASIX
|
||||
OR CONFIG_CHERRYUSB_HOST_RTL8152
|
||||
OR CONFIG_CHERRYUSB_HOST_BL616
|
||||
)
|
||||
list(APPEND cherryusb_srcs platform/lwip/usbh_lwip.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_CHERRYUSB_HOST_EHCI_BL)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci.c)
|
||||
#list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
|
||||
# list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_glue_bouffalo.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/ehci)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "ehci_hpm")
|
||||
elseif(CONFIG_CHERRYUSB_HOST_EHCI_HPM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci.c)
|
||||
#list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_glue_hpm.c)
|
||||
# list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro/usb_hc_hpm.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro/usb_glue_hpm.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/hpmicro)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/ehci)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "ehci_aic")
|
||||
elseif(CONFIG_CHERRYUSB_HOST_EHCI_AIC)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci.c)
|
||||
#list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ohci/usb_hc_ohci.c)
|
||||
# list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_glue_aic.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/ehci)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "ehci_mcx")
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/ohci)
|
||||
elseif(CONFIG_CHERRYUSB_HOST_EHCI_MCX)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci.c)
|
||||
#list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_glue_mcx.c)
|
||||
# list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/nxp/usb_glue_mcx.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/ehci)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/chipidea)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "ehci_nuvoton")
|
||||
elseif(CONFIG_CHERRYUSB_HOST_EHCI_CUSTOM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci.c)
|
||||
#list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_glue_nuvoton.c)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "dwc2_st")
|
||||
# list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/ehci/usb_hc_ehci_iso.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/port/ehci)
|
||||
elseif(CONFIG_CHERRYUSB_HOST_DWC2_ST)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_hc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_st.c)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "dwc2_esp")
|
||||
elseif(CONFIG_CHERRYUSB_HOST_DWC2_ESP)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_hc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_esp.c)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "dwc2_hc")
|
||||
elseif(CONFIG_CHERRYUSB_HOST_DWC2_KENDRYTE)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_hc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_kendryte.c)
|
||||
elseif(CONFIG_CHERRYUSB_HOST_DWC2_HC)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_hc_dwc2.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_glue_hc.c)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "musb_es")
|
||||
elseif(CONFIG_CHERRYUSB_HOST_DWC2_CUSTOM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/dwc2/usb_hc_dwc2.c)
|
||||
elseif(CONFIG_CHERRYUSB_HOST_MUSB_ES)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_hc_musb.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_glue_es.c)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "musb_sunxi")
|
||||
elseif(CONFIG_CHERRYUSB_HOST_MUSB_SUNXI)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_hc_musb.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_glue_sunxi.c)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "musb_bk")
|
||||
elseif(CONFIG_CHERRYUSB_HOST_MUSB_BK)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_hc_musb.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_glue_bk.c)
|
||||
elseif("${CONFIG_CHERRYUSB_HOST_HCD}" STREQUAL "kinetis_mcx")
|
||||
elseif(CONFIG_CHERRYUSB_HOST_MUSB_CUSTOM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_hc_musb.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/musb/usb_glue_bk.c)
|
||||
elseif(CONFIG_CHERRYUSB_HOST_KINETIS_MCX)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_hc_kinetis.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_glue_mcx.c)
|
||||
endif()
|
||||
elseif(CONFIG_CHERRYUSB_HOST_KINETIS_CUSTOM)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_hc_kinetis.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/kinetis/usb_glue_mcx.c)
|
||||
elseif(CONFIG_CHERRYUSB_HOST_RP2040)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/port/rp2040/usb_hc_rp2040.c)
|
||||
endif()
|
||||
|
||||
if(CHERRYUSB_HOST_TEMPLATE)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/demo/usb_host.c)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(DEFINED CONFIG_CHERRYUSB_OSAL)
|
||||
if("${CONFIG_CHERRYUSB_OSAL}" STREQUAL "freertos")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/usb_osal_freertos.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/usb_osal_freertos.c)
|
||||
elseif("${CONFIG_CHERRYUSB_OSAL}" STREQUAL "rtthread")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/usb_osal_rtthread.c)
|
||||
elseif("${CONFIG_CHERRYUSB_OSAL}" STREQUAL "yoc")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/usb_osal_yoc.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/usb_osal_rtthread.c)
|
||||
elseif("${CONFIG_CHERRYUSB_OSAL}" STREQUAL "idf")
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/osal/idf)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/idf/usb_osal_idf.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/osal/idf)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/idf/usb_osal_idf.c)
|
||||
elseif("${CONFIG_CHERRYUSB_OSAL}" STREQUAL "threadx")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/usb_osal_threadx.c)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/usb_osal_threadx.c)
|
||||
elseif("${CONFIG_CHERRYUSB_OSAL}" STREQUAL "zephyr")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/osal/usb_osal_zephyr.c)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CONFIG_CHERRYRB)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherryrb/chry_ringbuffer.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherryrb)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherryrb/chry_ringbuffer.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherryrb)
|
||||
endif()
|
||||
|
||||
if(CONFIG_CHERRYMP)
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/chry_mempool.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp)
|
||||
endif()
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/chry_mempool.c)
|
||||
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp)
|
||||
if("${CONFIG_CHERRYUSB_OSAL}" STREQUAL "freertos")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/chry_mempool_osal_freertos.c)
|
||||
elseif("${CONFIG_CHERRYUSB_OSAL}" STREQUAL "rtthread")
|
||||
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/chry_mempool_osal_rtthread.c)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -8,7 +8,13 @@
|
||||
|
||||
/* ================ USB common Configuration ================ */
|
||||
|
||||
#ifdef __RTTHREAD__
|
||||
#include <rtthread.h>
|
||||
|
||||
#define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
|
||||
#else
|
||||
#define CONFIG_USB_PRINTF(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USB_DBG_LEVEL
|
||||
#define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
|
||||
@@ -17,14 +23,23 @@
|
||||
/* Enable print with color */
|
||||
#define CONFIG_USB_PRINTF_COLOR_ENABLE
|
||||
|
||||
/* data align size when use dma */
|
||||
#ifndef CONFIG_USB_ALIGN_SIZE
|
||||
// #define CONFIG_USB_DCACHE_ENABLE
|
||||
|
||||
/* data align size when use dma or use dcache */
|
||||
#ifdef CONFIG_USB_DCACHE_ENABLE
|
||||
#define CONFIG_USB_ALIGN_SIZE 32 // 32 or 64
|
||||
#else
|
||||
#define CONFIG_USB_ALIGN_SIZE 4
|
||||
#endif
|
||||
|
||||
/* attribute data into no cache ram */
|
||||
#define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable")))
|
||||
|
||||
/* use usb_memcpy default for high performance but cost more flash memory.
|
||||
* And, arm libc has a bug that memcpy() may cause data misalignment when the size is not a multiple of 4.
|
||||
*/
|
||||
// #define CONFIG_USB_MEMCPY_DISABLE
|
||||
|
||||
/* ================= USB Device Stack Configuration ================ */
|
||||
|
||||
/* Ep0 in and out transfer buffer */
|
||||
@@ -46,6 +61,20 @@
|
||||
/* Enable test mode */
|
||||
// #define CONFIG_USBDEV_TEST_MODE
|
||||
|
||||
/* enable advance desc register api */
|
||||
#define CONFIG_USBDEV_ADVANCE_DESC
|
||||
|
||||
/* move ep0 setup handler from isr to thread */
|
||||
// #define CONFIG_USBDEV_EP0_THREAD
|
||||
|
||||
#ifndef CONFIG_USBDEV_EP0_PRIO
|
||||
#define CONFIG_USBDEV_EP0_PRIO 4
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USBDEV_EP0_STACKSIZE
|
||||
#define CONFIG_USBDEV_EP0_STACKSIZE 2048
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USBDEV_MSC_MAX_LUN
|
||||
#define CONFIG_USBDEV_MSC_MAX_LUN 1
|
||||
#endif
|
||||
@@ -80,6 +109,28 @@
|
||||
#define CONFIG_USBDEV_MSC_STACKSIZE 2048
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USBDEV_MTP_MAX_BUFSIZE
|
||||
#define CONFIG_USBDEV_MTP_MAX_BUFSIZE 2048
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USBDEV_MTP_MAX_OBJECTS
|
||||
#define CONFIG_USBDEV_MTP_MAX_OBJECTS 256
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USBDEV_MTP_MAX_PATHNAME
|
||||
#define CONFIG_USBDEV_MTP_MAX_PATHNAME 256
|
||||
#endif
|
||||
|
||||
#define CONFIG_USBDEV_MTP_THREAD
|
||||
|
||||
#ifndef CONFIG_USBDEV_MTP_PRIO
|
||||
#define CONFIG_USBDEV_MTP_PRIO 4
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USBDEV_MTP_STACKSIZE
|
||||
#define CONFIG_USBDEV_MTP_STACKSIZE 4096
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
|
||||
#define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
|
||||
#endif
|
||||
@@ -98,6 +149,7 @@
|
||||
#endif
|
||||
|
||||
#define CONFIG_USBDEV_RNDIS_USING_LWIP
|
||||
#define CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
|
||||
/* ================ USB HOST Stack Configuration ================== */
|
||||
|
||||
@@ -208,6 +260,11 @@
|
||||
#define CONFIG_USBDEV_EP_NUM 8
|
||||
#endif
|
||||
|
||||
// #define CONFIG_USBDEV_SOF_ENABLE
|
||||
|
||||
/* When your chip hardware supports high-speed and wants to initialize it in high-speed mode, the relevant IP will configure the internal or external high-speed PHY according to CONFIG_USB_HS. */
|
||||
// #define CONFIG_USB_HS
|
||||
|
||||
/* ---------------- FSDEV Configuration ---------------- */
|
||||
//#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
|
||||
|
||||
@@ -246,15 +303,19 @@
|
||||
#define CONFIG_USB_EHCI_HCCR_OFFSET (0x0)
|
||||
#define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
|
||||
#define CONFIG_USB_EHCI_QH_NUM CONFIG_USBHOST_PIPE_NUM
|
||||
#define CONFIG_USB_EHCI_QTD_NUM 3
|
||||
#define CONFIG_USB_EHCI_ITD_NUM 20
|
||||
#define CONFIG_USB_EHCI_QTD_NUM (CONFIG_USB_EHCI_QH_NUM * 3)
|
||||
#define CONFIG_USB_EHCI_ITD_NUM 4
|
||||
// #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
|
||||
// #define CONFIG_USB_EHCI_CONFIGFLAG
|
||||
// #define CONFIG_USB_EHCI_ISO
|
||||
// #define CONFIG_USB_EHCI_WITH_OHCI
|
||||
// #define CONFIG_USB_EHCI_DESC_DCACHE_ENABLE
|
||||
|
||||
/* ---------------- OHCI Configuration ---------------- */
|
||||
#define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
|
||||
#define CONFIG_USB_OHCI_ED_NUM CONFIG_USBHOST_PIPE_NUM
|
||||
#define CONFIG_USB_OHCI_TD_NUM 3
|
||||
// #define CONFIG_USB_OHCI_DESC_DCACHE_ENABLE
|
||||
|
||||
/* ---------------- XHCI Configuration ---------------- */
|
||||
#define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
|
||||
@@ -273,4 +334,12 @@
|
||||
/* ---------------- MUSB Configuration ---------------- */
|
||||
// #define CONFIG_USB_MUSB_SUNXI
|
||||
|
||||
#ifndef usb_phyaddr2ramaddr
|
||||
#define usb_phyaddr2ramaddr(addr) (addr)
|
||||
#endif
|
||||
|
||||
#ifndef usb_ramaddr2phyaddr
|
||||
#define usb_ramaddr2phyaddr(addr) (addr)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -39,8 +39,8 @@ struct adb_msg {
|
||||
};
|
||||
|
||||
struct adb_packet {
|
||||
struct adb_msg msg;
|
||||
uint8_t payload[MAX_PAYLOAD];
|
||||
USB_MEM_ALIGNX struct adb_msg msg;
|
||||
USB_MEM_ALIGNX uint8_t payload[USB_ALIGN_UP(MAX_PAYLOAD, CONFIG_USB_ALIGN_SIZE)];
|
||||
};
|
||||
|
||||
struct usbd_adb {
|
||||
@@ -115,7 +115,7 @@ void usbd_adb_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
|
||||
if (adb_client.common_state == ADB_STATE_READ_MSG) {
|
||||
if (nbytes != sizeof(struct adb_msg)) {
|
||||
USB_LOG_ERR("invalid adb msg size:%d\r\n", nbytes);
|
||||
USB_LOG_ERR("invalid adb msg size:%d\r\n", (unsigned int)nbytes);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
48
class/aoa/usb_aoa.h
Normal file
48
class/aoa/usb_aoa.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USB_AOA_H
|
||||
#define USB_AOA_H
|
||||
|
||||
//AOA 1.0
|
||||
#define AOA_ACCESSORY_VENDOR_ID 0x18D1
|
||||
#define AOA_ACCESSORY_PRODUCT_ID 0x2D00
|
||||
#define AOA_ACCESSORY_ADB_PRODUCT_ID 0x2D01
|
||||
|
||||
//AOA 2.0
|
||||
#define AOA_AUDIO_PRODUCT_ID 0x2D02
|
||||
#define AOA_AUDIO_ADB_PRODUCT_ID 0x2D03
|
||||
#define AOA_ACCESSORY_AUDIO_PRODUCT_ID 0x2D04
|
||||
#define AOA_ACCESSORY_AUDIO_ADB_PRODUCT_ID 0x2D05
|
||||
|
||||
//AOA 1.0
|
||||
#define AOA_ACCESSORY_GET_PROTOCOL 51
|
||||
#define AOA_ACCESSORY_SEND_STRING 52
|
||||
#define AOA_ACCESSORY_START 53
|
||||
|
||||
//AOA 2.0
|
||||
#define AOA_ACCESSORY_REGISTER_HID 54
|
||||
#define AOA_ACCESSORY_UNREGISTER_HID 55
|
||||
#define AOA_ACCESSORY_SET_HID_REPORT_DESC 56
|
||||
#define AOA_ACCESSORY_SEND_HID_EVENT 57
|
||||
#define AOA_ACCESSORY_SET_AUDIO_MODE 58
|
||||
|
||||
#define AOA_ACCESSORY_STRING_MANUFACTURER 0
|
||||
#define AOA_ACCESSORY_STRING_MODEL 1
|
||||
#define AOA_ACCESSORY_STRING_DESCRIPTION 2
|
||||
#define AOA_ACCESSORY_STRING_VERSION 3
|
||||
#define AOA_ACCESSORY_STRING_URI 4
|
||||
#define AOA_ACCESSORY_STRING_SERIAL 5
|
||||
|
||||
struct aoa_string_info {
|
||||
char acc_manufacturer[64];
|
||||
char acc_model[64];
|
||||
char acc_description[64];
|
||||
char acc_version[64];
|
||||
char acc_uri[64];
|
||||
char acc_serial[64];
|
||||
};
|
||||
|
||||
#endif /* USB_AOA_H */
|
||||
289
class/aoa/usbh_aoa.c
Normal file
289
class/aoa/usbh_aoa.c
Normal file
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_aoa.h"
|
||||
|
||||
#undef USB_DBG_TAG
|
||||
#define USB_DBG_TAG "usbh_aoa"
|
||||
#include "usb_log.h"
|
||||
|
||||
#define DEV_FORMAT "/dev/aoa"
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_aoa_buffer[USB_ALIGN_UP(128, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static struct usbh_aoa g_aoa_class;
|
||||
|
||||
int usbh_aoa_switch(struct usbh_hubport *hport, struct aoa_string_info *info)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
|
||||
setup = hport->setup;
|
||||
|
||||
if (setup == NULL) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Try switch into aoa mode\r\n");
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_GET_PROTOCOL;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = 2;
|
||||
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
USB_LOG_INFO("AOA version: v%d.%d\r\n", g_aoa_buffer[0], g_aoa_buffer[1]);
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_MANUFACTURER;
|
||||
setup->wLength = strlen(info->acc_manufacturer) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_manufacturer, strlen(info->acc_manufacturer));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_MODEL;
|
||||
setup->wLength = strlen(info->acc_model) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_model, strlen(info->acc_model));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_DESCRIPTION;
|
||||
setup->wLength = strlen(info->acc_description) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_description, strlen(info->acc_description));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_VERSION;
|
||||
setup->wLength = strlen(info->acc_version) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_version, strlen(info->acc_version));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_URI;
|
||||
setup->wLength = strlen(info->acc_uri) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_uri, strlen(info->acc_uri));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_STRING;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = AOA_ACCESSORY_STRING_SERIAL;
|
||||
setup->wLength = strlen(info->acc_serial) + 1;
|
||||
|
||||
memcpy(g_aoa_buffer, info->acc_serial, strlen(info->acc_serial));
|
||||
ret = usbh_control_transfer(hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_START;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(hport, setup, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Switch into aoa mode success, wait usb device restart...\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_aoa_register_hid(struct usbh_aoa *aoa_class, uint16_t id, uint8_t *report, uint32_t report_len)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
uint8_t len;
|
||||
uint32_t offset;
|
||||
|
||||
if (!aoa_class || !aoa_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
setup = aoa_class->hport->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_REGISTER_HID;
|
||||
setup->wValue = id;
|
||||
setup->wIndex = report_len;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(aoa_class->hport, setup, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
while (report_len > 0) {
|
||||
len = report_len > 64 ? 64 : report_len;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SET_HID_REPORT_DESC;
|
||||
setup->wValue = id;
|
||||
setup->wIndex = offset;
|
||||
setup->wLength = len;
|
||||
|
||||
memcpy(g_aoa_buffer, report + offset, len);
|
||||
ret = usbh_control_transfer(aoa_class->hport, setup, g_aoa_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
offset += len;
|
||||
report_len -= len;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usbh_aoa_send_hid_event(struct usbh_aoa *aoa_class, uint16_t id, uint8_t *event, uint32_t event_len)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
uint8_t len;
|
||||
uint32_t offset;
|
||||
|
||||
if (!aoa_class || !aoa_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
setup = aoa_class->hport->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = AOA_ACCESSORY_SEND_HID_EVENT;
|
||||
setup->wValue = id;
|
||||
setup->wIndex = 0;
|
||||
setup->wLength = event_len;
|
||||
|
||||
memcpy(g_aoa_buffer, event, event_len);
|
||||
return usbh_control_transfer(aoa_class->hport, setup, event);
|
||||
}
|
||||
|
||||
static int usbh_aoa_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_aoa *aoa_class = &g_aoa_class;
|
||||
|
||||
memset(aoa_class, 0, sizeof(struct usbh_aoa));
|
||||
|
||||
aoa_class->hport = hport;
|
||||
aoa_class->intf = intf;
|
||||
|
||||
hport->config.intf[intf].priv = aoa_class;
|
||||
|
||||
for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
|
||||
ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
|
||||
|
||||
if (ep_desc->bEndpointAddress & 0x80) {
|
||||
USBH_EP_INIT(aoa_class->bulkin, ep_desc);
|
||||
} else {
|
||||
USBH_EP_INIT(aoa_class->bulkout, ep_desc);
|
||||
}
|
||||
}
|
||||
|
||||
strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN);
|
||||
|
||||
USB_LOG_INFO("Register AOA Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
|
||||
usbh_aoa_run(aoa_class);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbh_aoa_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_aoa *aoa_class = (struct usbh_aoa *)hport->config.intf[intf].priv;
|
||||
|
||||
if (aoa_class) {
|
||||
if (aoa_class->bulkin) {
|
||||
usbh_kill_urb(&aoa_class->bulkin_urb);
|
||||
}
|
||||
|
||||
if (aoa_class->bulkout) {
|
||||
usbh_kill_urb(&aoa_class->bulkout_urb);
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
USB_LOG_INFO("Unregister AOA Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_aoa_stop(aoa_class);
|
||||
}
|
||||
|
||||
memset(aoa_class, 0, sizeof(struct usbh_aoa));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
__WEAK void usbh_aoa_run(struct usbh_aoa *aoa_class)
|
||||
{
|
||||
(void)aoa_class;
|
||||
}
|
||||
|
||||
__WEAK void usbh_aoa_stop(struct usbh_aoa *aoa_class)
|
||||
{
|
||||
(void)aoa_class;
|
||||
}
|
||||
|
||||
static const uint16_t aoa_id_table[][2] = {
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_ACCESSORY_PRODUCT_ID },
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_ACCESSORY_ADB_PRODUCT_ID },
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_AUDIO_PRODUCT_ID },
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_AUDIO_ADB_PRODUCT_ID },
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_ACCESSORY_AUDIO_PRODUCT_ID },
|
||||
{ AOA_ACCESSORY_VENDOR_ID, AOA_ACCESSORY_AUDIO_ADB_PRODUCT_ID },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
const struct usbh_class_driver aoa_class_driver = {
|
||||
.driver_name = "aoa",
|
||||
.connect = usbh_aoa_connect,
|
||||
.disconnect = usbh_aoa_disconnect
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info aoa_intf_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0xff,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = aoa_id_table,
|
||||
.class_driver = &aoa_class_driver
|
||||
};
|
||||
40
class/aoa/usbh_aoa.h
Normal file
40
class/aoa/usbh_aoa.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USBH_AOA_H
|
||||
#define USBH_AOA_H
|
||||
|
||||
#include "usb_aoa.h"
|
||||
|
||||
struct usbh_aoa {
|
||||
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;
|
||||
|
||||
uint8_t intf;
|
||||
uint8_t minor;
|
||||
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int usbh_aoa_switch(struct usbh_hubport *hport, struct aoa_string_info *info);
|
||||
int usbh_aoa_register_hid(struct usbh_aoa *aoa_class, uint16_t id, uint8_t *report, uint32_t report_len);
|
||||
int usbh_aoa_send_hid_event(struct usbh_aoa *aoa_class, uint16_t id, uint8_t *event, uint32_t event_len);
|
||||
|
||||
void usbh_aoa_run(struct usbh_aoa *aoa_class);
|
||||
void usbh_aoa_stop(struct usbh_aoa *aoa_class);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBH_AOA_H */
|
||||
@@ -648,6 +648,18 @@ struct audio_cs_if_ac_feature_unit_descriptor {
|
||||
|
||||
#define AUDIO_SIZEOF_AC_FEATURE_UNIT_DESC(ch, n) (7 + (ch + 1) * n)
|
||||
|
||||
struct audio_cs_if_ac_selector_unit_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubtype;
|
||||
uint8_t bUnitID;
|
||||
uint8_t bNrInPins;
|
||||
uint8_t baSourceID[1];
|
||||
uint8_t iSelector;
|
||||
} __PACKED;
|
||||
|
||||
#define AUDIO_SIZEOF_AC_SELECTOR_UNIT_DESC(n) (6 + n)
|
||||
|
||||
struct audio_cs_if_as_general_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
@@ -810,7 +822,66 @@ struct audio_cs_ep_ep_general_descriptor {
|
||||
0x00, /* wLockDelay */ \
|
||||
0x00
|
||||
|
||||
#define AUDIO_AS_FEEDBACK_DESCRIPTOR_INIT(bInterfaceNumber, bTerminalLink, bNrChannels, bSubFrameSize, bBitResolution, bEndpointAddress, wMaxPacketSize, bInterval, bFeedbackEndpointAddress, ...) \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
bInterfaceNumber, /* bInterfaceNumber */ \
|
||||
0x00, /* bAlternateSetting */ \
|
||||
0x00, /* bNumEndpoints */ \
|
||||
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ \
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ \
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ \
|
||||
0x00, /* iInterface */ \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
bInterfaceNumber, /* bInterfaceNumber */ \
|
||||
0x01, /* bAlternateSetting */ \
|
||||
0x02, /* bNumEndpoints */ \
|
||||
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ \
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ \
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ \
|
||||
0x00, /* iInterface */ \
|
||||
0x07, /* bLength */ \
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
|
||||
AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */ \
|
||||
bTerminalLink, /* bTerminalLink : Unit ID of the Output Terminal*/ \
|
||||
0x01, /* bDelay */ \
|
||||
WBVAL(AUDIO_FORMAT_PCM), /* wFormatTag : AUDIO_FORMAT_PCM */ \
|
||||
0x08 + PP_NARG(__VA_ARGS__), /* bLength */ \
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
|
||||
AUDIO_STREAMING_FORMAT_TYPE, /* bDescriptorSubtype */ \
|
||||
AUDIO_FORMAT_TYPE_I, /* bFormatType */ \
|
||||
bNrChannels, /* bNrChannels */ \
|
||||
bSubFrameSize, /* bSubFrameSize : Bytes per audio subframe */ \
|
||||
bBitResolution, /* bBitResolution : bits per sample */ \
|
||||
(PP_NARG(__VA_ARGS__)/3), /* bSamFreqType : only one frequency supported */ \
|
||||
__VA_ARGS__, /* tSamFreq : Audio sampling frequency coded on 3 bytes */ \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
|
||||
bEndpointAddress, /* bEndpointAddress : IN endpoint 1 */ \
|
||||
0x05, /* bmAttributes */ \
|
||||
WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \
|
||||
bInterval, /* bInterval : one packet per frame */ \
|
||||
0x00, /* bRefresh */ \
|
||||
bFeedbackEndpointAddress, /* bSynchAddress */ \
|
||||
0x07, /* bLength */ \
|
||||
AUDIO_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ \
|
||||
AUDIO_ENDPOINT_GENERAL, /* bDescriptor */ \
|
||||
AUDIO_EP_CONTROL_SAMPLING_FEQ, /* bmAttributes AUDIO_SAMPLING_FREQ_CONTROL */ \
|
||||
0x00, /* bLockDelayUnits */ \
|
||||
0x00, /* wLockDelay */ \
|
||||
0x00, \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
|
||||
bFeedbackEndpointAddress, /* bFeedbackEndpointAddress Revise Dir to bEndpointAddress */ \
|
||||
0x11, /* bmAttributes: TransferType=Isochronous SyncType=None EndpointType=Feedback */ \
|
||||
WBVAL(4), /* XXXX wMaxPacketSize in Bytes */ \
|
||||
bInterval, /* bInterval */ \
|
||||
0x03, /* bRefresh, 8ms */ \
|
||||
0x00 /* bSynchAddress */
|
||||
|
||||
#define AUDIO_AS_DESCRIPTOR_INIT_LEN(n) (0x09 + 0x09 + 0x07 + 0x08 + 3 * n + 0x09 + 0x07)
|
||||
#define AUDIO_AS_FEEDBACK_DESCRIPTOR_INIT_LEN(n) (0x09 + 0x09 + 0x07 + 0x08 + 3 * n + 0x09 + 0x07 + 0x09)
|
||||
|
||||
#define AUDIO_AS_ALTSETTING_DESCRIPTOR_INIT(bInterfaceNumber, bAlternateSetting, bTerminalLink, bNrChannels, bSubFrameSize, bBitResolution, bEndpointAddress, bmAttributes, wMaxPacketSize, bInterval, ...) \
|
||||
0x09, /* bLength */ \
|
||||
@@ -1269,4 +1340,19 @@ struct audio_v2_control_range3_param_block {
|
||||
#define AUDIO_SAMPLE_FREQ_4B(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), \
|
||||
(uint8_t)((frq >> 16)), (uint8_t)((frq >> 24))
|
||||
|
||||
/* format 10.14 */
|
||||
#define AUDIO_FREQ_TO_FEEDBACK_FS(freq) ((freq << 10) / 1000)
|
||||
#define AUDIO_FEEDBACK_TO_BUF_FS(buf, feedback) \
|
||||
buf[0] = ((feedback << 4) & 0xFFU); \
|
||||
buf[1] = (((feedback << 4) >> 8U) & 0xFFU); \
|
||||
buf[2] = (((feedback << 4) >> 16U) & 0xFFU)
|
||||
|
||||
/* format 16.16 */
|
||||
#define AUDIO_FREQ_TO_FEEDBACK_HS(freq) ((freq << 13) / 1000)
|
||||
#define AUDIO_FEEDBACK_TO_BUF_HS(buf, feedback) \
|
||||
buf[0] = (((feedback & 0x00001FFFu) << 3) & 0xFFu); \
|
||||
buf[1] = ((((feedback & 0x00001FFFu) << 3) >> 8) & 0xFFu); \
|
||||
buf[2] = (((feedback & 0x01FFE000u) >> 13) & 0xFFu); \
|
||||
buf[3] = (((feedback & 0x01FFE000u) >> 21) & 0xFFu)
|
||||
|
||||
#endif /* USB_AUDIO_H */
|
||||
|
||||
@@ -136,27 +136,26 @@ static int audio_class_interface_request_handler(uint8_t busid, struct usb_setup
|
||||
memcpy(&volume, *data, *len);
|
||||
if (volume < 0x8000) {
|
||||
volume_db = volume / 256;
|
||||
} else if (volume > 0x8000) {
|
||||
volume_db = (0xffff - volume + 1) / -256;
|
||||
} else {
|
||||
volume_db = (volume - 0x10000) / 256;
|
||||
}
|
||||
volume_db += 128; /* 0 ~ 255 */
|
||||
USB_LOG_DBG("Set ep:0x%02x ch:%d volume:0x%04x\r\n", ep, ch, volume);
|
||||
USB_LOG_DBG("Set ep:0x%02x ch:%d vol_hex:0x%04x, vol_db:%d dB\r\n", ep, ch, volume, volume_db);
|
||||
usbd_audio_set_volume(busid, ep, ch, volume_db);
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_CUR:
|
||||
volume_db = usbd_audio_get_volume(busid, ep, ch);
|
||||
volume_db -= 128;
|
||||
if (volume_db >= 0) {
|
||||
volume = volume_db * 256;
|
||||
} else {
|
||||
volume = volume_db * 256 + 0xffff + 1;
|
||||
volume = volume_db * 256 + 0x10000;
|
||||
}
|
||||
USB_LOG_DBG("Get ep:0x%02x ch:%d vol_hex:0x%04x, vol_db:%d dB\r\n", ep, ch, volume, volume_db);
|
||||
memcpy(*data, &volume, 2);
|
||||
*len = 2;
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_MIN:
|
||||
(*data)[0] = 0x00; /* -2560/256 dB */
|
||||
(*data)[1] = 0xdb;
|
||||
(*data)[0] = 0x00; /* -100 dB */
|
||||
(*data)[1] = 0x9c;
|
||||
*len = 2;
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_MAX:
|
||||
@@ -165,7 +164,7 @@ static int audio_class_interface_request_handler(uint8_t busid, struct usb_setup
|
||||
*len = 2;
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_RES:
|
||||
(*data)[0] = 0x00; /* -256/256 dB */
|
||||
(*data)[0] = 0x00; /* 1 dB */
|
||||
(*data)[1] = 0x01;
|
||||
*len = 2;
|
||||
break;
|
||||
@@ -178,22 +177,31 @@ static int audio_class_interface_request_handler(uint8_t busid, struct usb_setup
|
||||
case AUDIO_REQUEST_CUR:
|
||||
if (setup->bmRequestType & USB_REQUEST_DIR_MASK) {
|
||||
volume_db = usbd_audio_get_volume(busid, ep, ch);
|
||||
volume = volume_db;
|
||||
if (volume_db >= 0) {
|
||||
volume = volume_db * 256;
|
||||
} else {
|
||||
volume = volume_db * 256 + 0x10000;
|
||||
}
|
||||
USB_LOG_DBG("Get ep:0x%02x ch:%d vol_hex:0x%04x, vol_db:%d dB\r\n", ep, ch, volume, volume_db);
|
||||
memcpy(*data, &volume, 2);
|
||||
*len = 2;
|
||||
} else {
|
||||
memcpy(&volume, *data, *len);
|
||||
volume_db = volume;
|
||||
USB_LOG_DBG("Set ep:0x%02x ch:%d volume:0x%02x\r\n", ep, ch, volume);
|
||||
if (volume < 0x8000) {
|
||||
volume_db = volume / 256;
|
||||
} else {
|
||||
volume_db = (volume - 0x10000) / 256;
|
||||
}
|
||||
USB_LOG_DBG("Set ep:0x%02x ch:%d vol_hex:0x%04x, vol_db:%d dB\r\n", ep, ch, volume, volume_db);
|
||||
usbd_audio_set_volume(busid, ep, ch, volume_db);
|
||||
}
|
||||
break;
|
||||
case AUDIO_REQUEST_RANGE:
|
||||
if (setup->bmRequestType & USB_REQUEST_DIR_MASK) {
|
||||
*((uint16_t *)(*data + 0)) = 1;
|
||||
*((uint16_t *)(*data + 2)) = 0;
|
||||
*((uint16_t *)(*data + 4)) = 100;
|
||||
*((uint16_t *)(*data + 6)) = 1;
|
||||
*((uint16_t *)(*data + 2)) = 0x9c00; /* MIN -100 dB */
|
||||
*((uint16_t *)(*data + 4)) = 0x0000; /* MAX 0 dB */
|
||||
*((uint16_t *)(*data + 6)) = 0x100; /* RES 1 dB */
|
||||
*len = 8;
|
||||
} else {
|
||||
}
|
||||
@@ -312,12 +320,12 @@ struct usbd_interface *usbd_audio_init_intf(uint8_t busid,
|
||||
return intf;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_set_volume(uint8_t busid, uint8_t ep, uint8_t ch, int volume)
|
||||
__WEAK void usbd_audio_set_volume(uint8_t busid, uint8_t ep, uint8_t ch, int volume_db)
|
||||
{
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
(void)ch;
|
||||
(void)volume;
|
||||
(void)volume_db;
|
||||
}
|
||||
|
||||
__WEAK int usbd_audio_get_volume(uint8_t busid, uint8_t ep, uint8_t ch)
|
||||
@@ -367,3 +375,15 @@ __WEAK void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_
|
||||
(void)ep;
|
||||
(void)sampling_freq_table;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_open(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ struct usbd_interface *usbd_audio_init_intf(uint8_t busid, struct usbd_interface
|
||||
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);
|
||||
void usbd_audio_set_volume(uint8_t busid, uint8_t ep, uint8_t ch, int volume_db);
|
||||
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);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#define INTF_DESC_bInterfaceNumber 2 /** Interface number offset */
|
||||
#define INTF_DESC_bAlternateSetting 3 /** Alternate setting offset */
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_audio_buf[128];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_audio_buf[USB_ALIGN_UP(128, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static struct usbh_audio g_audio_class[CONFIG_USBHOST_MAX_AUDIO_CLASS];
|
||||
static uint32_t g_devinuse = 0;
|
||||
@@ -184,18 +184,21 @@ int usbh_audio_close(struct usbh_audio *audio_class, const char *name)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint8_t ch, uint8_t volume)
|
||||
int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint8_t ch, int volume_db)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
uint8_t feature_id = 0xff;
|
||||
uint8_t intf;
|
||||
uint16_t volume_hex;
|
||||
int volume_min_db;
|
||||
int volume_max_db;
|
||||
|
||||
if (!audio_class || !audio_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
if (volume > 100) {
|
||||
if ((volume_db > 127) || (volume_db < -127)) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
@@ -204,20 +207,102 @@ int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
if (strcmp(name, audio_class->as_msg_table[i].stream_name) == 0) {
|
||||
feature_id = audio_class->as_msg_table[i].feature_terminal_id;
|
||||
intf = audio_class->as_msg_table[i].stream_intf;
|
||||
}
|
||||
}
|
||||
|
||||
if (feature_id == 0xff) {
|
||||
return -USB_ERR_NODEV;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_GET_CUR;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_VOLUME << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 2;
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(&audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_cur, g_audio_buf, 2);
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_GET_MIN;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_VOLUME << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 2;
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(&audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_min, g_audio_buf, 2);
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_GET_MAX;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_VOLUME << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 2;
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(&audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_max, g_audio_buf, 2);
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_GET_RES;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_VOLUME << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 2;
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(&audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_res, g_audio_buf, 2);
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_SET_CUR;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_VOLUME << 8) | ch;
|
||||
setup->wIndex = (feature_id << 8) | audio_class->ctrl_intf;
|
||||
setup->wLength = 2;
|
||||
|
||||
volume_hex = -0xDB00 / 100 * volume + 0xdb00;
|
||||
if (audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_min < 0x8000) {
|
||||
volume_min_db = audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_min / 256;
|
||||
} else {
|
||||
volume_min_db = (audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_min - 0x10000) / 256;
|
||||
}
|
||||
|
||||
if (audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_max < 0x8000) {
|
||||
volume_max_db = audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_max / 256;
|
||||
} else {
|
||||
volume_max_db = (audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_max - 0x10000) / 256;
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Get ch:%u dB range: %ddB ~ %ddB\r\n", ch, volume_min_db, volume_max_db);
|
||||
|
||||
if (volume_db >= 0) {
|
||||
volume_hex = volume_db * 256;
|
||||
if (volume_hex > audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_max) {
|
||||
return -USB_ERR_RANGE;
|
||||
}
|
||||
} else {
|
||||
volume_hex = volume_db * 256 + 0x10000;
|
||||
if (volume_hex < audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_min) {
|
||||
return -USB_ERR_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(g_audio_buf, &volume_hex, 2);
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, NULL);
|
||||
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].volume_cur = volume_hex;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -226,6 +311,7 @@ int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
uint8_t feature_id = 0xff;
|
||||
uint8_t intf = 0xff;
|
||||
|
||||
if (!audio_class || !audio_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
@@ -235,9 +321,14 @@ int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
if (strcmp(name, audio_class->as_msg_table[i].stream_name) == 0) {
|
||||
feature_id = audio_class->as_msg_table[i].feature_terminal_id;
|
||||
intf = audio_class->as_msg_table[i].stream_intf;
|
||||
}
|
||||
}
|
||||
|
||||
if (feature_id == 0xff) {
|
||||
return -USB_ERR_NODEV;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = AUDIO_REQUEST_SET_CUR;
|
||||
setup->wValue = (AUDIO_FU_CONTROL_MUTE << 8) | ch;
|
||||
@@ -246,7 +337,10 @@ int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_
|
||||
|
||||
memcpy(g_audio_buf, &mute, 1);
|
||||
ret = usbh_control_transfer(audio_class->hport, setup, g_audio_buf);
|
||||
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
audio_class->as_msg_table[intf - audio_class->ctrl_intf - 1].mute = mute;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -286,13 +380,14 @@ void usbh_audio_list_module(struct usbh_audio *audio_class)
|
||||
static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
int ret;
|
||||
uint8_t cur_iface = 0xff;
|
||||
uint8_t cur_iface_count = 0xff;
|
||||
uint8_t cur_alt_setting = 0xff;
|
||||
uint8_t cur_iface = 0;
|
||||
uint8_t cur_iface_count = 0;
|
||||
uint8_t cur_alt_setting = 0;
|
||||
uint8_t input_offset = 0;
|
||||
uint8_t output_offset = 0;
|
||||
uint8_t feature_unit_offset = 0;
|
||||
uint8_t *p;
|
||||
struct usbh_audio_ac_msg ac_msg_table[CONFIG_USBHOST_AUDIO_MAX_STREAMS];
|
||||
|
||||
struct usbh_audio *audio_class = usbh_audio_class_alloc();
|
||||
if (audio_class == NULL) {
|
||||
@@ -327,26 +422,24 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
case AUDIO_CONTROL_INPUT_TERMINAL: {
|
||||
struct audio_cs_if_ac_input_terminal_descriptor *desc = (struct audio_cs_if_ac_input_terminal_descriptor *)p;
|
||||
|
||||
memcpy(&audio_class->ac_msg_table[input_offset].ac_input, desc, sizeof(struct audio_cs_if_ac_input_terminal_descriptor));
|
||||
memcpy(&ac_msg_table[input_offset].ac_input, desc, sizeof(struct audio_cs_if_ac_input_terminal_descriptor));
|
||||
input_offset++;
|
||||
} break;
|
||||
case AUDIO_CONTROL_OUTPUT_TERMINAL: {
|
||||
struct audio_cs_if_ac_output_terminal_descriptor *desc = (struct audio_cs_if_ac_output_terminal_descriptor *)p;
|
||||
|
||||
memcpy(&audio_class->ac_msg_table[output_offset].ac_output, desc, sizeof(struct audio_cs_if_ac_output_terminal_descriptor));
|
||||
memcpy(&ac_msg_table[output_offset].ac_output, desc, sizeof(struct audio_cs_if_ac_output_terminal_descriptor));
|
||||
output_offset++;
|
||||
} break;
|
||||
case AUDIO_CONTROL_FEATURE_UNIT: {
|
||||
struct audio_cs_if_ac_feature_unit_descriptor *desc = (struct audio_cs_if_ac_feature_unit_descriptor *)p;
|
||||
|
||||
memcpy(&audio_class->ac_msg_table[feature_unit_offset].ac_feature_unit, desc, desc->bLength);
|
||||
memcpy(&ac_msg_table[feature_unit_offset].ac_feature_unit, desc, desc->bLength);
|
||||
feature_unit_offset++;
|
||||
} break;
|
||||
case AUDIO_CONTROL_PROCESSING_UNIT:
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
USB_LOG_ERR("Do not support %02x subtype\r\n", p[DESC_bDescriptorSubType]);
|
||||
return -USB_ERR_NOTSUPP;
|
||||
}
|
||||
} else if ((cur_iface > audio_class->ctrl_intf) && (cur_iface < (audio_class->ctrl_intf + cur_iface_count))) {
|
||||
switch (p[DESC_bDescriptorSubType]) {
|
||||
@@ -383,7 +476,12 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if ((input_offset != output_offset) && (input_offset != feature_unit_offset)) {
|
||||
USB_LOG_ERR("Audio descriptor is invalid\r\n");
|
||||
USB_LOG_ERR("Audio control descriptor is invalid\r\n");
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
if (cur_iface_count == 0xff) {
|
||||
USB_LOG_ERR("Audio descriptor must have iad descriptor\r\n");
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
@@ -392,21 +490,21 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
/* Search 0x0101 in input or output desc */
|
||||
for (uint8_t streamidx = 0; streamidx < audio_class->stream_intf_num; streamidx++) {
|
||||
if (audio_class->as_msg_table[i].as_general.bTerminalLink == audio_class->ac_msg_table[streamidx].ac_input.bTerminalID) {
|
||||
if (audio_class->as_msg_table[i].as_general.bTerminalLink == ac_msg_table[streamidx].ac_input.bTerminalID) {
|
||||
/* INPUT --> FEATURE UNIT --> OUTPUT */
|
||||
audio_class->as_msg_table[i].input_terminal_id = audio_class->ac_msg_table[streamidx].ac_input.bTerminalID;
|
||||
audio_class->as_msg_table[i].input_terminal_id = ac_msg_table[streamidx].ac_input.bTerminalID;
|
||||
|
||||
/* Search input terminal id in feature desc */
|
||||
for (uint8_t featureidx = 0; featureidx < audio_class->stream_intf_num; featureidx++) {
|
||||
if (audio_class->ac_msg_table[streamidx].ac_input.bTerminalID == audio_class->ac_msg_table[featureidx].ac_feature_unit.bSourceID) {
|
||||
audio_class->as_msg_table[i].feature_terminal_id = audio_class->ac_msg_table[featureidx].ac_feature_unit.bUnitID;
|
||||
if (ac_msg_table[streamidx].ac_input.bTerminalID == ac_msg_table[featureidx].ac_feature_unit.bSourceID) {
|
||||
audio_class->as_msg_table[i].feature_terminal_id = ac_msg_table[featureidx].ac_feature_unit.bUnitID;
|
||||
|
||||
/* Search feature unit id in output desc */
|
||||
for (uint8_t outputid = 0; outputid < audio_class->stream_intf_num; outputid++) {
|
||||
if (audio_class->ac_msg_table[featureidx].ac_feature_unit.bUnitID == audio_class->ac_msg_table[outputid].ac_output.bSourceID) {
|
||||
audio_class->as_msg_table[i].output_terminal_id = audio_class->ac_msg_table[outputid].ac_output.bTerminalID;
|
||||
if (ac_msg_table[featureidx].ac_feature_unit.bUnitID == ac_msg_table[outputid].ac_output.bSourceID) {
|
||||
audio_class->as_msg_table[i].output_terminal_id = ac_msg_table[outputid].ac_output.bTerminalID;
|
||||
|
||||
switch (audio_class->ac_msg_table[outputid].ac_output.wTerminalType) {
|
||||
switch (ac_msg_table[outputid].ac_output.wTerminalType) {
|
||||
case AUDIO_OUTTERM_SPEAKER:
|
||||
audio_class->as_msg_table[i].stream_name = "speaker";
|
||||
break;
|
||||
@@ -426,21 +524,21 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (audio_class->as_msg_table[i].as_general.bTerminalLink == audio_class->ac_msg_table[streamidx].ac_output.bTerminalID) {
|
||||
} else if (audio_class->as_msg_table[i].as_general.bTerminalLink == ac_msg_table[streamidx].ac_output.bTerminalID) {
|
||||
/* OUTPUT --> FEATURE UNIT --> INPUT */
|
||||
audio_class->as_msg_table[i].output_terminal_id = audio_class->ac_msg_table[streamidx].ac_output.bTerminalID;
|
||||
audio_class->as_msg_table[i].output_terminal_id = ac_msg_table[streamidx].ac_output.bTerminalID;
|
||||
|
||||
/* Search output terminal id in feature desc */
|
||||
for (uint8_t featureidx = 0; featureidx < audio_class->stream_intf_num; featureidx++) {
|
||||
if (audio_class->ac_msg_table[streamidx].ac_output.bSourceID == audio_class->ac_msg_table[featureidx].ac_feature_unit.bUnitID) {
|
||||
audio_class->as_msg_table[i].feature_terminal_id = audio_class->ac_msg_table[featureidx].ac_feature_unit.bUnitID;
|
||||
if (ac_msg_table[streamidx].ac_output.bSourceID == ac_msg_table[featureidx].ac_feature_unit.bUnitID) {
|
||||
audio_class->as_msg_table[i].feature_terminal_id = ac_msg_table[featureidx].ac_feature_unit.bUnitID;
|
||||
|
||||
/* Search feature unit id in input desc */
|
||||
for (uint8_t inputid = 0; inputid < audio_class->stream_intf_num; inputid++) {
|
||||
if (audio_class->ac_msg_table[featureidx].ac_feature_unit.bSourceID == audio_class->ac_msg_table[inputid].ac_input.bTerminalID) {
|
||||
audio_class->as_msg_table[i].input_terminal_id = audio_class->ac_msg_table[inputid].ac_input.bTerminalID;
|
||||
if (ac_msg_table[featureidx].ac_feature_unit.bSourceID == ac_msg_table[inputid].ac_input.bTerminalID) {
|
||||
audio_class->as_msg_table[i].input_terminal_id = ac_msg_table[inputid].ac_input.bTerminalID;
|
||||
|
||||
switch (audio_class->ac_msg_table[inputid].ac_input.wTerminalType) {
|
||||
switch (ac_msg_table[inputid].ac_input.wTerminalType) {
|
||||
case AUDIO_INTERM_MIC:
|
||||
audio_class->as_msg_table[i].stream_name = "mic";
|
||||
break;
|
||||
@@ -458,6 +556,13 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
if (audio_class->as_msg_table[i].stream_name == NULL) {
|
||||
USB_LOG_ERR("Audio stream search fail\r\n");
|
||||
return -USB_ERR_NODEV;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < audio_class->stream_intf_num; i++) {
|
||||
ret = usbh_audio_close(audio_class, audio_class->as_msg_table[i].stream_name);
|
||||
if (ret < 0) {
|
||||
@@ -489,6 +594,7 @@ static int usbh_audio_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister Audio Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_audio_stop(audio_class);
|
||||
}
|
||||
@@ -537,18 +643,18 @@ const struct usbh_class_driver audio_streaming_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info audio_ctrl_intf_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS,
|
||||
.class = USB_DEVICE_CLASS_AUDIO,
|
||||
.subclass = AUDIO_SUBCLASS_AUDIOCONTROL,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_AUDIO,
|
||||
.bInterfaceSubClass = AUDIO_SUBCLASS_AUDIOCONTROL,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &audio_ctrl_class_driver
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info audio_streaming_intf_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS,
|
||||
.class = USB_DEVICE_CLASS_AUDIO,
|
||||
.subclass = AUDIO_SUBCLASS_AUDIOSTREAMING,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_AUDIO,
|
||||
.bInterfaceSubClass = AUDIO_SUBCLASS_AUDIOSTREAMING,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &audio_streaming_class_driver
|
||||
};
|
||||
|
||||
@@ -26,6 +26,11 @@ struct usbh_audio_as_msg {
|
||||
uint8_t output_terminal_id;
|
||||
uint8_t ep_attr;
|
||||
uint8_t num_of_altsetting;
|
||||
uint16_t volume_min;
|
||||
uint16_t volume_max;
|
||||
uint16_t volume_res;
|
||||
uint16_t volume_cur;
|
||||
bool mute;
|
||||
struct audio_cs_if_as_general_descriptor as_general;
|
||||
struct audio_cs_if_as_format_type_descriptor as_format[CONFIG_USBHOST_MAX_INTF_ALTSETTINGS];
|
||||
};
|
||||
@@ -43,7 +48,6 @@ struct usbh_audio {
|
||||
uint16_t bcdADC;
|
||||
uint8_t bInCollection;
|
||||
uint8_t stream_intf_num;
|
||||
struct usbh_audio_ac_msg ac_msg_table[CONFIG_USBHOST_AUDIO_MAX_STREAMS];
|
||||
struct usbh_audio_as_msg as_msg_table[CONFIG_USBHOST_AUDIO_MAX_STREAMS];
|
||||
|
||||
void *user_data;
|
||||
@@ -55,7 +59,7 @@ extern "C" {
|
||||
|
||||
int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t samp_freq, uint8_t bitresolution);
|
||||
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_volume(struct usbh_audio *audio_class, const char *name, uint8_t ch, int volume_db);
|
||||
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);
|
||||
|
||||
@@ -524,7 +524,7 @@ struct cdc_ncm_ndp16 {
|
||||
int_ep, /* bEndpointAddress */ \
|
||||
0x03, /* bmAttributes */ \
|
||||
0x08, 0x00, /* wMaxPacketSize */ \
|
||||
0x10, /* bInterval */ \
|
||||
0x05, /* bInterval */ \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
(uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \
|
||||
@@ -596,7 +596,7 @@ eth_statistics, wMaxSegmentSize, wNumberMCFilters, bNumberPowerFilters, str_idx)
|
||||
int_ep, /* bEndpointAddress */ \
|
||||
0x03, /* bmAttributes */ \
|
||||
0x10, 0x00, /* wMaxPacketSize */ \
|
||||
0x10, /* bInterval */ \
|
||||
0x05, /* bInterval */ \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
(uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \
|
||||
|
||||
@@ -42,7 +42,7 @@ static int cdc_acm_class_interface_request_handler(uint8_t busid, struct usb_set
|
||||
memcpy(&line_coding, *data, setup->wLength);
|
||||
USB_LOG_DBG("Set intf:%d linecoding <%d %d %s %s>\r\n",
|
||||
intf_num,
|
||||
line_coding.dwDTERate,
|
||||
(unsigned int)line_coding.dwDTERate,
|
||||
line_coding.bDataBits,
|
||||
parity_name[line_coding.bParityType],
|
||||
stop_name[line_coding.bCharFormat]);
|
||||
@@ -67,7 +67,7 @@ static int cdc_acm_class_interface_request_handler(uint8_t busid, struct usb_set
|
||||
*len = 7;
|
||||
USB_LOG_DBG("Get intf:%d linecoding %d %d %d %d\r\n",
|
||||
intf_num,
|
||||
line_coding.dwDTERate,
|
||||
(unsigned int)line_coding.dwDTERate,
|
||||
line_coding.bCharFormat,
|
||||
line_coding.bParityType,
|
||||
line_coding.bDataBits);
|
||||
|
||||
@@ -7,17 +7,21 @@
|
||||
#include "usbd_cdc_ecm.h"
|
||||
|
||||
#define CDC_ECM_OUT_EP_IDX 0
|
||||
#define CDC_ECM_IN_EP_IDX 1
|
||||
#define CDC_ECM_INT_EP_IDX 2
|
||||
#define CDC_ECM_IN_EP_IDX 1
|
||||
#define CDC_ECM_INT_EP_IDX 2
|
||||
|
||||
/* Ethernet Maximum Segment size, typically 1514 bytes */
|
||||
#define CONFIG_CDC_ECM_ETH_MAX_SEGSZE 1536U
|
||||
|
||||
/* Describe EndPoints configuration */
|
||||
static struct usbd_endpoint cdc_ecm_ep_data[3];
|
||||
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_rx_buffer[CONFIG_CDC_ECM_ETH_MAX_SEGSZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_tx_buffer[CONFIG_CDC_ECM_ETH_MAX_SEGSZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_notify_buf[16];
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_rx_buffer[USB_ALIGN_UP(CONFIG_CDC_ECM_ETH_MAX_SEGSZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_tx_buffer[USB_ALIGN_UP(CONFIG_CDC_ECM_ETH_MAX_SEGSZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
#endif
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_notify_buf[USB_ALIGN_UP(16, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
volatile uint8_t *g_cdc_ecm_rx_data_buffer = NULL;
|
||||
volatile uint32_t g_cdc_ecm_rx_data_length = 0;
|
||||
volatile uint32_t g_cdc_ecm_tx_data_length = 0;
|
||||
|
||||
@@ -68,8 +72,10 @@ void usbd_cdc_ecm_send_notify(uint8_t notifycode, uint8_t value, uint32_t *speed
|
||||
break;
|
||||
}
|
||||
|
||||
if (bytes2send) {
|
||||
usbd_ep_start_write(0, cdc_ecm_ep_data[CDC_ECM_INT_EP_IDX].ep_addr, g_cdc_ecm_notify_buf, bytes2send);
|
||||
if (usb_device_is_configured(0)) {
|
||||
if (bytes2send) {
|
||||
usbd_ep_start_write(0, cdc_ecm_ep_data[CDC_ECM_INT_EP_IDX].ep_addr, g_cdc_ecm_notify_buf, bytes2send);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,11 +99,11 @@ static int cdc_ecm_class_interface_request_handler(uint8_t busid, struct usb_set
|
||||
* bit3 Broadcast
|
||||
* bit4 Multicast
|
||||
*/
|
||||
if (g_current_net_status == 0) {
|
||||
g_current_net_status = 1;
|
||||
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_NETWORK_CONNECTION, CDC_ECM_NET_CONNECTED, NULL);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
g_connect_speed_table[0] = 100000000; /* 100 Mbps */
|
||||
g_connect_speed_table[1] = 100000000; /* 100 Mbps */
|
||||
usbd_cdc_ecm_set_connect(true, g_connect_speed_table);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
USB_LOG_WRN("Unhandled CDC ECM Class bRequest 0x%02x\r\n", setup->bRequest);
|
||||
@@ -117,10 +123,11 @@ void cdc_ecm_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
g_current_net_status = 0;
|
||||
g_cdc_ecm_rx_data_length = 0;
|
||||
g_cdc_ecm_tx_data_length = 0;
|
||||
g_cdc_ecm_rx_data_buffer = NULL;
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
usbd_ep_start_read(0, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr, &g_cdc_ecm_rx_buffer[g_cdc_ecm_rx_data_length], usbd_get_ep_mps(busid, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr));
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
usbd_cdc_ecm_start_read(g_cdc_ecm_rx_buffer, CONFIG_CDC_ECM_ETH_MAX_SEGSZE);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -132,14 +139,8 @@ void cdc_ecm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
(void)busid;
|
||||
|
||||
g_cdc_ecm_rx_data_length += nbytes;
|
||||
|
||||
if (nbytes < usbd_get_ep_mps(0, ep)) {
|
||||
g_cdc_ecm_rx_data_buffer = g_cdc_ecm_rx_buffer;
|
||||
usbd_cdc_ecm_data_recv_done(g_cdc_ecm_rx_buffer, g_cdc_ecm_rx_data_length);
|
||||
} else {
|
||||
usbd_ep_start_read(0, ep, &g_cdc_ecm_rx_buffer[g_cdc_ecm_rx_data_length], usbd_get_ep_mps(0, ep));
|
||||
}
|
||||
g_cdc_ecm_rx_data_length = nbytes;
|
||||
usbd_cdc_ecm_data_recv_done(g_cdc_ecm_rx_data_length);
|
||||
}
|
||||
|
||||
void cdc_ecm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
@@ -150,6 +151,7 @@ void cdc_ecm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(0, ep, NULL, 0);
|
||||
} else {
|
||||
usbd_cdc_ecm_data_send_done(g_cdc_ecm_tx_data_length);
|
||||
g_cdc_ecm_tx_data_length = 0;
|
||||
}
|
||||
}
|
||||
@@ -160,14 +162,20 @@ void cdc_ecm_int_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
(void)ep;
|
||||
(void)nbytes;
|
||||
|
||||
if (g_current_net_status == 1) {
|
||||
g_current_net_status = 2;
|
||||
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_NETWORK_CONNECTION, CDC_ECM_NET_CONNECTED, g_connect_speed_table);
|
||||
if (g_current_net_status == 2) {
|
||||
g_current_net_status = 3;
|
||||
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_CONNECTION_SPEED_CHANGE, 0, g_connect_speed_table);
|
||||
} else {
|
||||
g_current_net_status = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int usbd_cdc_ecm_start_write(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
if (!usb_device_is_configured(0)) {
|
||||
return -USB_ERR_NOTCONN;
|
||||
}
|
||||
|
||||
if (g_cdc_ecm_tx_data_length > 0) {
|
||||
return -USB_ERR_BUSY;
|
||||
}
|
||||
@@ -175,14 +183,17 @@ int usbd_cdc_ecm_start_write(uint8_t *buf, uint32_t len)
|
||||
g_cdc_ecm_tx_data_length = len;
|
||||
|
||||
USB_LOG_DBG("txlen:%d\r\n", g_cdc_ecm_tx_data_length);
|
||||
return usbd_ep_start_write(0, cdc_ecm_ep_data[CDC_ECM_IN_EP_IDX].ep_addr, buf, g_cdc_ecm_tx_data_length);
|
||||
return usbd_ep_start_write(0, cdc_ecm_ep_data[CDC_ECM_IN_EP_IDX].ep_addr, buf, len);
|
||||
}
|
||||
|
||||
void usbd_cdc_ecm_start_read_next(void)
|
||||
int usbd_cdc_ecm_start_read(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
if (!usb_device_is_configured(0)) {
|
||||
return -USB_ERR_NOTCONN;
|
||||
}
|
||||
|
||||
g_cdc_ecm_rx_data_length = 0;
|
||||
g_cdc_ecm_rx_data_buffer = NULL;
|
||||
usbd_ep_start_read(0, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr, g_cdc_ecm_rx_buffer, usbd_get_ep_mps(0, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr));
|
||||
return usbd_ep_start_read(0, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr, buf, len);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
@@ -190,19 +201,19 @@ struct pbuf *usbd_cdc_ecm_eth_rx(void)
|
||||
{
|
||||
struct pbuf *p;
|
||||
|
||||
if (g_cdc_ecm_rx_data_buffer == NULL) {
|
||||
if (g_cdc_ecm_rx_data_length == 0) {
|
||||
return NULL;
|
||||
}
|
||||
p = pbuf_alloc(PBUF_RAW, g_cdc_ecm_rx_data_length, PBUF_POOL);
|
||||
if (p == NULL) {
|
||||
usbd_cdc_ecm_start_read_next();
|
||||
usbd_cdc_ecm_start_read(g_cdc_ecm_rx_buffer, CONFIG_CDC_ECM_ETH_MAX_SEGSZE);
|
||||
return NULL;
|
||||
}
|
||||
usb_memcpy(p->payload, (uint8_t *)g_cdc_ecm_rx_buffer, g_cdc_ecm_rx_data_length);
|
||||
p->len = g_cdc_ecm_rx_data_length;
|
||||
|
||||
USB_LOG_DBG("rxlen:%d\r\n", g_cdc_ecm_rx_data_length);
|
||||
usbd_cdc_ecm_start_read_next();
|
||||
usbd_cdc_ecm_start_read(g_cdc_ecm_rx_buffer, CONFIG_CDC_ECM_ETH_MAX_SEGSZE);
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -211,6 +222,10 @@ int usbd_cdc_ecm_eth_tx(struct pbuf *p)
|
||||
struct pbuf *q;
|
||||
uint8_t *buffer;
|
||||
|
||||
if (!usb_device_is_configured(0)) {
|
||||
return -USB_ERR_NOTCONN;
|
||||
}
|
||||
|
||||
if (g_cdc_ecm_tx_data_length > 0) {
|
||||
return -USB_ERR_BUSY;
|
||||
}
|
||||
@@ -250,13 +265,30 @@ struct usbd_interface *usbd_cdc_ecm_init_intf(struct usbd_interface *intf, const
|
||||
return intf;
|
||||
}
|
||||
|
||||
void usbd_cdc_ecm_set_connect_speed(uint32_t speed[2])
|
||||
int usbd_cdc_ecm_set_connect(bool connect, uint32_t speed[2])
|
||||
{
|
||||
memcpy(g_connect_speed_table, speed, 8);
|
||||
if (!usb_device_is_configured(0)) {
|
||||
return -USB_ERR_NOTCONN;
|
||||
}
|
||||
|
||||
if (connect) {
|
||||
g_current_net_status = 2;
|
||||
memcpy(g_connect_speed_table, speed, 8);
|
||||
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_NETWORK_CONNECTION, CDC_ECM_NET_CONNECTED, NULL);
|
||||
} else {
|
||||
g_current_net_status = 1;
|
||||
usbd_cdc_ecm_send_notify(CDC_ECM_NOTIFY_CODE_NETWORK_CONNECTION, CDC_ECM_NET_DISCONNECTED, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_ecm_data_recv_done(uint8_t *buf, uint32_t len)
|
||||
__WEAK void usbd_cdc_ecm_data_recv_done(uint32_t len)
|
||||
{
|
||||
(void)len;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_ecm_data_send_done(uint32_t len)
|
||||
{
|
||||
(void)buf;
|
||||
(void)len;
|
||||
}
|
||||
|
||||
@@ -12,21 +12,15 @@
|
||||
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]);
|
||||
int usbd_cdc_ecm_set_connect(bool connect, 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);
|
||||
void usbd_cdc_ecm_data_recv_done(uint32_t len);
|
||||
void usbd_cdc_ecm_data_send_done(uint32_t len);
|
||||
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);
|
||||
int usbd_cdc_ecm_start_read(uint8_t *buf, uint32_t len);
|
||||
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
#include "lwip/netif.h"
|
||||
|
||||
@@ -193,6 +193,7 @@ static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
#endif
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister CDC ACM Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_cdc_acm_stop(cdc_acm_class);
|
||||
}
|
||||
@@ -267,18 +268,18 @@ const struct usbh_class_driver cdc_data_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info cdc_acm_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS,
|
||||
.class = USB_DEVICE_CLASS_CDC,
|
||||
.subclass = CDC_ABSTRACT_CONTROL_MODEL,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_CDC,
|
||||
.bInterfaceSubClass = CDC_ABSTRACT_CONTROL_MODEL,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &cdc_acm_class_driver
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info cdc_data_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = USB_DEVICE_CLASS_CDC_DATA,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_CDC_DATA,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &cdc_data_class_driver
|
||||
};
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
#define CONFIG_USBHOST_CDC_ECM_PKT_FILTER 0x000C
|
||||
#define CONFIG_USBHOST_CDC_ECM_ETH_MAX_SIZE 1514U
|
||||
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_rx_buffer[CONFIG_USBHOST_CDC_ECM_ETH_MAX_SIZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_tx_buffer[CONFIG_USBHOST_CDC_ECM_ETH_MAX_SIZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_inttx_buffer[16];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_rx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_CDC_ECM_ETH_MAX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_tx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_CDC_ECM_ETH_MAX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ecm_inttx_buffer[USB_ALIGN_UP(16, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static struct usbh_cdc_ecm g_cdc_ecm_class;
|
||||
|
||||
@@ -221,6 +221,7 @@ static int usbh_cdc_ecm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister CDC ECM Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_cdc_ecm_stop(cdc_ecm_class);
|
||||
}
|
||||
@@ -231,12 +232,12 @@ static int usbh_cdc_ecm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void usbh_cdc_ecm_rx_thread(void *argument)
|
||||
void usbh_cdc_ecm_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
uint32_t g_cdc_ecm_rx_length;
|
||||
int ret;
|
||||
|
||||
(void)argument;
|
||||
(void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
|
||||
USB_LOG_INFO("Create cdc ecm rx thread\r\n");
|
||||
// clang-format off
|
||||
find_class:
|
||||
@@ -323,9 +324,9 @@ const struct usbh_class_driver cdc_ecm_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info cdc_ecm_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_CDC,
|
||||
.subclass = CDC_ETHERNET_NETWORKING_CONTROL_MODEL,
|
||||
.protocol = CDC_COMMON_PROTOCOL_NONE,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_CDC,
|
||||
.bInterfaceSubClass = CDC_ETHERNET_NETWORKING_CONTROL_MODEL,
|
||||
.bInterfaceProtocol = CDC_COMMON_PROTOCOL_NONE,
|
||||
.id_table = NULL,
|
||||
.class_driver = &cdc_ecm_class_driver
|
||||
};
|
||||
@@ -41,7 +41,7 @@ void usbh_cdc_ecm_stop(struct usbh_cdc_ecm *cdc_ecm_class);
|
||||
uint8_t *usbh_cdc_ecm_get_eth_txbuf(void);
|
||||
int usbh_cdc_ecm_eth_output(uint32_t buflen);
|
||||
void usbh_cdc_ecm_eth_input(uint8_t *buf, uint32_t buflen);
|
||||
void usbh_cdc_ecm_rx_thread(void *argument);
|
||||
void usbh_cdc_ecm_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_rx_buffer[CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_tx_buffer[CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_inttx_buffer[16];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_inttx_buffer[USB_ALIGN_UP(16, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_buf[32];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cdc_ncm_buf[USB_ALIGN_UP(32, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static struct usbh_cdc_ncm g_cdc_ncm_class;
|
||||
|
||||
@@ -52,7 +52,7 @@ static int usbh_cdc_ncm_get_ntb_parameters(struct usbh_cdc_ncm *cdc_ncm_class, s
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy((uint8_t *)param, g_cdc_ncm_buf, ret - 8);
|
||||
memcpy((uint8_t *)param, g_cdc_ncm_buf, MIN(ret - 8, sizeof(struct cdc_ncm_ntb_parameters)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -62,12 +62,12 @@ static void print_ntb_parameters(struct cdc_ncm_ntb_parameters *param)
|
||||
USB_LOG_RAW("wLength: 0x%02x \r\n", param->wLength);
|
||||
USB_LOG_RAW("bmNtbFormatsSupported: %s \r\n", param->bmNtbFormatsSupported ? "NTB16" : "NTB32");
|
||||
|
||||
USB_LOG_RAW("dwNtbInMaxSize: 0x%04x \r\n", param->dwNtbInMaxSize);
|
||||
USB_LOG_RAW("dwNtbInMaxSize: 0x%08x \r\n", (unsigned int)param->dwNtbInMaxSize);
|
||||
USB_LOG_RAW("wNdbInDivisor: 0x%02x \r\n", param->wNdbInDivisor);
|
||||
USB_LOG_RAW("wNdbInPayloadRemainder: 0x%02x \r\n", param->wNdbInPayloadRemainder);
|
||||
USB_LOG_RAW("wNdbInAlignment: 0x%02x \r\n", param->wNdbInAlignment);
|
||||
|
||||
USB_LOG_RAW("dwNtbOutMaxSize: 0x%04x \r\n", param->dwNtbOutMaxSize);
|
||||
USB_LOG_RAW("dwNtbOutMaxSize: 0x%08x \r\n", (unsigned int)param->dwNtbOutMaxSize);
|
||||
USB_LOG_RAW("wNdbOutDivisor: 0x%02x \r\n", param->wNdbOutDivisor);
|
||||
USB_LOG_RAW("wNdbOutPayloadRemainder: 0x%02x \r\n", param->wNdbOutPayloadRemainder);
|
||||
USB_LOG_RAW("wNdbOutAlignment: 0x%02x \r\n", param->wNdbOutAlignment);
|
||||
@@ -239,6 +239,7 @@ static int usbh_cdc_ncm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister CDC NCM Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_cdc_ncm_stop(cdc_ncm_class);
|
||||
}
|
||||
@@ -249,7 +250,7 @@ static int usbh_cdc_ncm_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void usbh_cdc_ncm_rx_thread(void *argument)
|
||||
void usbh_cdc_ncm_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
uint32_t g_cdc_ncm_rx_length;
|
||||
int ret;
|
||||
@@ -259,7 +260,7 @@ void usbh_cdc_ncm_rx_thread(void *argument)
|
||||
uint32_t transfer_size = (16 * 1024);
|
||||
#endif
|
||||
|
||||
(void)argument;
|
||||
(void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
|
||||
USB_LOG_INFO("Create cdc ncm rx thread\r\n");
|
||||
// clang-format off
|
||||
find_class:
|
||||
@@ -403,9 +404,9 @@ const struct usbh_class_driver cdc_ncm_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info cdc_ncm_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_CDC,
|
||||
.subclass = CDC_NETWORK_CONTROL_MODEL,
|
||||
.protocol = CDC_COMMON_PROTOCOL_NONE,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_CDC,
|
||||
.bInterfaceSubClass = CDC_NETWORK_CONTROL_MODEL,
|
||||
.bInterfaceProtocol = CDC_COMMON_PROTOCOL_NONE,
|
||||
.id_table = NULL,
|
||||
.class_driver = &cdc_ncm_class_driver
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ void usbh_cdc_ncm_stop(struct usbh_cdc_ncm *cdc_ncm_class);
|
||||
uint8_t *usbh_cdc_ncm_get_eth_txbuf(void);
|
||||
int usbh_cdc_ncm_eth_output(uint32_t buflen);
|
||||
void usbh_cdc_ncm_eth_input(uint8_t *buf, uint32_t buflen);
|
||||
void usbh_cdc_ncm_rx_thread(void *argument);
|
||||
void usbh_cdc_ncm_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -169,14 +169,14 @@
|
||||
#define HID_LOCAL_ITEM_DELIMITER_PREFIX 0xa8 /* Delimiter */
|
||||
|
||||
/* Modifier Keys (HID 8.3) */
|
||||
#define HID_MODIFER_LCTRL (1 << 0) /* Left Ctrl */
|
||||
#define HID_MODIFER_LSHIFT (1 << 1) /* Left Shift */
|
||||
#define HID_MODIFER_LALT (1 << 2) /* Left Alt */
|
||||
#define HID_MODIFER_LGUI (1 << 3) /* Left GUI */
|
||||
#define HID_MODIFER_RCTRL (1 << 4) /* Right Ctrl */
|
||||
#define HID_MODIFER_RSHIFT (1 << 5) /* Right Shift */
|
||||
#define HID_MODIFER_RALT (1 << 6) /* Right Alt */
|
||||
#define HID_MODIFER_RGUI (1 << 7) /* Right GUI */
|
||||
#define HID_MODIFIER_LCTRL (1 << 0) /* Left Ctrl */
|
||||
#define HID_MODIFIER_LSHIFT (1 << 1) /* Left Shift */
|
||||
#define HID_MODIFIER_LALT (1 << 2) /* Left Alt */
|
||||
#define HID_MODIFIER_LGUI (1 << 3) /* Left GUI */
|
||||
#define HID_MODIFIER_RCTRL (1 << 4) /* Right Ctrl */
|
||||
#define HID_MODIFIER_RSHIFT (1 << 5) /* Right Shift */
|
||||
#define HID_MODIFIER_RALT (1 << 6) /* Right Alt */
|
||||
#define HID_MODIFIER_RGUI (1 << 7) /* Right GUI */
|
||||
|
||||
/* Keyboard output report (1 byte) (HID B.1) */
|
||||
#define HID_KBD_OUTPUT_REPORT_NUMLOCK (1 << 0)
|
||||
@@ -191,11 +191,11 @@
|
||||
#define HID_MOUSE_INPUT_REPORT_BUTTON3 (1 << 2)
|
||||
#define HID_MOUSE_INPUT_REPORT_BUTTON_MASK (7)
|
||||
|
||||
#define HID_MOUSE_INPUT_BUTTON_LEFT (1 << 0)
|
||||
#define HID_MOUSE_INPUT_BUTTON_RIGHT (1 << 1)
|
||||
#define HID_MOUSE_INPUT_BUTTON_MIDDLE (1 << 2)
|
||||
#define HID_MOUSE_INPUT_BUTTON_BACKWARD (1 << 3)
|
||||
#define HID_MOUSE_INPUT_BUTTON_FORWARD (1 << 4)
|
||||
#define HID_MOUSE_INPUT_BUTTON_LEFT (1 << 0)
|
||||
#define HID_MOUSE_INPUT_BUTTON_RIGHT (1 << 1)
|
||||
#define HID_MOUSE_INPUT_BUTTON_MIDDLE (1 << 2)
|
||||
#define HID_MOUSE_INPUT_BUTTON_BACKWARD (1 << 3)
|
||||
#define HID_MOUSE_INPUT_BUTTON_FORWARD (1 << 4)
|
||||
|
||||
/* Joystick input report (4 bytes) (HID D.1) */
|
||||
#define HID_JS_INPUT_REPORT_HATSWITCH_SHIFT (0)
|
||||
@@ -241,14 +241,14 @@
|
||||
#define HID_DESKTOP_USAGE_UNDEFINED 0x00 /* Undefined */
|
||||
#define HID_DESKTOP_USAGE_POINTER 0x01 /* Pointer */
|
||||
#define HID_DESKTOP_USAGE_MOUSE 0x02 /* Mouse */
|
||||
/* 0x03 Reserved */
|
||||
/* 0x03 Reserved */
|
||||
#define HID_DESKTOP_USAGE_JOYSTICK 0x04 /* Joystick */
|
||||
#define HID_DESKTOP_USAGE_GAMEPAD 0x05 /* Game Pad */
|
||||
#define HID_DESKTOP_USAGE_KEYBOARD 0x06 /* Keyboard */
|
||||
#define HID_DESKTOP_USAGE_KEYPAD 0x07 /* Keypad */
|
||||
#define HID_DESKTOP_USAGE_MULTIAXIS 0x08 /* Multi-axis Controller */
|
||||
#define HID_DESKTOP_USAGE_TABLET 0x09 /* Tablet PC System Controls */
|
||||
/* 0x0a-2f Reserved */
|
||||
/* 0x0a-2f Reserved */
|
||||
#define HID_DESKTOP_USAGE_X 0x30 /* X */
|
||||
#define HID_DESKTOP_USAGE_Y 0x31 /* Y */
|
||||
#define HID_DESKTOP_USAGE_Z 0x32 /* Z */
|
||||
@@ -264,7 +264,7 @@
|
||||
#define HID_DESKTOP_USAGE_MOTION 0x3c /* Motion Wakeup */
|
||||
#define HID_DESKTOP_USAGE_START 0x3d /* Start */
|
||||
#define HID_DESKTOP_USAGE_SELECT 0x3e /* Select */
|
||||
/* 0x3f Reserved */
|
||||
/* 0x3f Reserved */
|
||||
#define HID_DESKTOP_USAGE_VX 0x40 /* Vx */
|
||||
#define HID_DESKTOP_USAGE_VY 0x41 /* Vy */
|
||||
#define HID_DESKTOP_USAGE_VZ 0x42 /* Vz */
|
||||
@@ -274,7 +274,7 @@
|
||||
#define HID_DESKTOP_USAGE_VNO 0x46 /* Vno */
|
||||
#define HID_DESKTOP_USAGE_FEATURE 0x47 /* Feature Notification */
|
||||
#define HID_DESKTOP_USAGE_RESOLUTION 0x48 /* Resolution Multiplier */
|
||||
/* 0x49-7f Reserved */
|
||||
/* 0x49-7f Reserved */
|
||||
#define HID_DESKTOP_USAGE_CONTROL 0x80 /* System Control */
|
||||
#define HID_DESKTOP_USAGE_POWERDOWN 0x81 /* System Power Down */
|
||||
#define HID_DESKTOP_USAGE_SLEEP 0x82 /* System Sleep */
|
||||
@@ -295,7 +295,7 @@
|
||||
#define HID_DESKTOP_USAGE_DPAD_DOWN 0x91 /* D-pad Down */
|
||||
#define HID_DESKTOP_USAGE_DPAD_RIGHT 0x92 /* D-pad Right */
|
||||
#define HID_DESKTOP_USAGE_DPAD_LEFT 0x93 /* D-pad Left */
|
||||
/* 0x94-9f Reserved */
|
||||
/* 0x94-9f Reserved */
|
||||
#define HID_DESKTOP_USAGE_DOCK 0xa0 /* System Dock */
|
||||
#define HID_DESKTOP_USAGE_UNDOCK 0xa1 /* System Undock */
|
||||
#define HID_DESKTOP_USAGE_SETUP 0xa2 /* System Setup */
|
||||
@@ -305,7 +305,7 @@
|
||||
#define HID_DESKTOP_USAGE_APP_DEBUG_BREAK 0xa6 /* Application Debugger Break */
|
||||
#define HID_DESKTOP_USAGE_MUTE 0xa7 /* System Speaker Mute */
|
||||
#define HID_DESKTOP_USAGE_HIBERNATE 0xa8 /* System Hibernate */
|
||||
/* 0xa9-af Reserved */
|
||||
/* 0xa9-af Reserved */
|
||||
#define HID_DESKTOP_USAGE_DISPLAY_INVERT 0xb0 /* System Display Invert */
|
||||
#define HID_DESKTOP_USAGE_DISPALY_INTERNAL 0xb1 /* System Display Internal */
|
||||
#define HID_DESKTOP_USAGE_DISPLAY_EXTERNAL 0xb2 /* System Display External */
|
||||
@@ -314,7 +314,7 @@
|
||||
#define HID_DESKTOP_USAGE_DISPLAY_TOGGLE 0xb5 /* System Display Toggle Int/Ext */
|
||||
#define HID_DESKTOP_USAGE_DISPLAY_SWAP 0xb6 /* System Display Swap */
|
||||
#define HID_DESKTOP_USAGE_ 0xb7 /* System Display LCD Autoscale */
|
||||
/* 0xb8-ffff Reserved */
|
||||
/* 0xb8-ffff Reserved */
|
||||
|
||||
/* Keyboard usage IDs (HuT 10) */
|
||||
#define HID_KBD_USAGE_NONE 0x00 /* Reserved (no event indicated) */
|
||||
@@ -529,16 +529,16 @@
|
||||
|
||||
/* HID Report Definitions */
|
||||
struct usb_hid_class_subdescriptor {
|
||||
uint8_t bDescriptorType;/* Class descriptor type (See 7.1) */
|
||||
uint16_t wDescriptorLength;/* Size of the report descriptor */
|
||||
uint8_t bDescriptorType; /* Class descriptor type (See 7.1) */
|
||||
uint16_t wDescriptorLength; /* Size of the report descriptor */
|
||||
} __PACKED;
|
||||
|
||||
struct usb_hid_descriptor {
|
||||
uint8_t bLength; /* Size of the HID descriptor */
|
||||
uint8_t bDescriptorType;/* HID descriptor type */
|
||||
uint16_t bcdHID;/* HID class specification release */
|
||||
uint8_t bCountryCode;/* Country code */
|
||||
uint8_t bNumDescriptors;/* Number of descriptors (>=1) */
|
||||
uint8_t bLength; /* Size of the HID descriptor */
|
||||
uint8_t bDescriptorType; /* HID descriptor type */
|
||||
uint16_t bcdHID; /* HID class specification release */
|
||||
uint8_t bCountryCode; /* Country code */
|
||||
uint8_t bNumDescriptors; /* Number of descriptors (>=1) */
|
||||
|
||||
/*
|
||||
* Specification says at least one Class Descriptor needs to
|
||||
@@ -550,11 +550,10 @@ struct usb_hid_descriptor {
|
||||
/* Standard Reports *********************************************************/
|
||||
|
||||
/* Keyboard input report (8 bytes) (HID B.1) */
|
||||
struct usb_hid_kbd_report
|
||||
{
|
||||
uint8_t modifier; /* Modifier keys. See HID_MODIFER_* definitions */
|
||||
uint8_t reserved;
|
||||
uint8_t key[6]; /* Keycode 1-6 */
|
||||
struct usb_hid_kbd_report {
|
||||
uint8_t modifier; /* Modifier keys. See HID_MODIFER_* definitions */
|
||||
uint8_t reserved;
|
||||
uint8_t key[6]; /* Keycode 1-6 */
|
||||
};
|
||||
|
||||
/* Keyboard output report (1 byte) (HID B.1),
|
||||
@@ -562,22 +561,109 @@ struct usb_hid_kbd_report
|
||||
*/
|
||||
|
||||
/* Mouse input report (HID B.2) */
|
||||
struct usb_hid_mouse_report
|
||||
{
|
||||
uint8_t buttons; /* See HID_MOUSE_INPUT_BUTTON_* definitions */
|
||||
int8_t xdisp; /* X displacement */
|
||||
int8_t ydisp; /* y displacement */
|
||||
struct usb_hid_mouse_report {
|
||||
uint8_t buttons; /* See HID_MOUSE_INPUT_BUTTON_* definitions */
|
||||
int8_t xdisp; /* X displacement */
|
||||
int8_t ydisp; /* y displacement */
|
||||
/* Device specific additional bytes may follow */
|
||||
uint8_t wdisp; /* Wheel displacement */
|
||||
uint8_t wdisp; /* Wheel displacement */
|
||||
};
|
||||
|
||||
/* Joystick input report (1 bytes) (HID D.1) */
|
||||
struct usb_hid_js_report
|
||||
{
|
||||
int8_t xpos; /* X position */
|
||||
int8_t ypos; /* X position */
|
||||
uint8_t buttons; /* See USBHID_JSIN_* definitions */
|
||||
uint8_t throttle; /* Throttle */
|
||||
struct usb_hid_js_report {
|
||||
int8_t xpos; /* X position */
|
||||
int8_t ypos; /* X position */
|
||||
uint8_t buttons; /* See USBHID_JSIN_* definitions */
|
||||
uint8_t throttle; /* Throttle */
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
#define HID_MOUSE_DESCRIPTOR_LEN (9 + 9 + 7)
|
||||
|
||||
#define HID_MOUSE_DESCRIPTOR_INIT(bInterfaceNumber, bInterfaceSubClass, wItemLength, int_ep, wMaxPacketSize, bInterval) \
|
||||
0x09, /* bLength: Interface Descriptor size */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */ \
|
||||
bInterfaceNumber, /* bInterfaceNumber: Number of Interface */ \
|
||||
0x00, /* bAlternateSetting: Alternate setting */ \
|
||||
0x01, /* bNumEndpoints */ \
|
||||
0x03, /* bInterfaceClass: HID */ \
|
||||
bInterfaceSubClass, /* bInterfaceSubClass : 1=BOOT, 0=no boot */ \
|
||||
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */ \
|
||||
0x00, /* iInterface: Index of string descriptor */ \
|
||||
0x09, /* bLength: HID Descriptor size */ \
|
||||
HID_DESCRIPTOR_TYPE_HID, /* bDescriptorType: HID */ \
|
||||
0x11, /* bcdHID: HID Class Spec release number */ \
|
||||
0x01, \
|
||||
0x00, /* bCountryCode: Hardware target country */ \
|
||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */ \
|
||||
0x22, /* bDescriptorType */ \
|
||||
WBVAL(wItemLength), /* wItemLength: Total length of Report descriptor */ \
|
||||
0x07, /* bLength: Endpoint Descriptor size */ \
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */ \
|
||||
int_ep, /* bEndpointAddress: Endpoint Address (IN) */ \
|
||||
0x03, /* bmAttributes: Interrupt endpoint */ \
|
||||
WBVAL(wMaxPacketSize), /* wMaxPacketSize: x Byte max */ \
|
||||
bInterval /* bInterval: Polling Interval */
|
||||
|
||||
#define HID_KEYBOARD_DESCRIPTOR_LEN (9 + 9 + 7)
|
||||
|
||||
#define HID_KEYBOARD_DESCRIPTOR_INIT(bInterfaceNumber, bInterfaceSubClass, wItemLength, int_ep, wMaxPacketSize, bInterval) \
|
||||
0x09, /* bLength: Interface Descriptor size */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */ \
|
||||
bInterfaceNumber, /* bInterfaceNumber: Number of Interface */ \
|
||||
0x00, /* bAlternateSetting: Alternate setting */ \
|
||||
0x01, /* bNumEndpoints */ \
|
||||
0x03, /* bInterfaceClass: HID */ \
|
||||
bInterfaceSubClass, /* bInterfaceSubClass : 1=BOOT, 0=no boot */ \
|
||||
0x01, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */ \
|
||||
0x00, /* iInterface: Index of string descriptor */ \
|
||||
0x09, /* bLength: HID Descriptor size */ \
|
||||
HID_DESCRIPTOR_TYPE_HID, /* bDescriptorType: HID */ \
|
||||
0x11, /* bcdHID: HID Class Spec release number */ \
|
||||
0x01, \
|
||||
0x00, /* bCountryCode: Hardware target country */ \
|
||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */ \
|
||||
0x22, /* bDescriptorType */ \
|
||||
WBVAL(wItemLength), /* wItemLength: Total length of Report descriptor */ \
|
||||
0x07, /* bLength: Endpoint Descriptor size */ \
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */ \
|
||||
int_ep, /* bEndpointAddress: Endpoint Address (IN) */ \
|
||||
0x03, /* bmAttributes: Interrupt endpoint */ \
|
||||
WBVAL(wMaxPacketSize), /* wMaxPacketSize: x Byte max */ \
|
||||
bInterval /* bInterval: Polling Interval */
|
||||
|
||||
#define HID_CUSTOM_INOUT_DESCRIPTOR_LEN (9 + 9 + 7 + 7)
|
||||
|
||||
#define HID_CUSTOM_INOUT_DESCRIPTOR_INIT(bInterfaceNumber, bInterfaceSubClass, wItemLength, in_ep, out_ep,wMaxPacketSize, bInterval) \
|
||||
0x09, /* bLength: Interface Descriptor size */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */ \
|
||||
bInterfaceNumber, /* bInterfaceNumber: Number of Interface */ \
|
||||
0x00, /* bAlternateSetting: Alternate setting */ \
|
||||
0x02, /* bNumEndpoints */ \
|
||||
0x03, /* bInterfaceClass: HID */ \
|
||||
bInterfaceSubClass, /* bInterfaceSubClass : 1=BOOT, 0=no boot */ \
|
||||
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */ \
|
||||
0x00, /* iInterface: Index of string descriptor */ \
|
||||
0x09, /* bLength: HID Descriptor size */ \
|
||||
HID_DESCRIPTOR_TYPE_HID, /* bDescriptorType: HID */ \
|
||||
0x11, /* bcdHID: HID Class Spec release number */ \
|
||||
0x01, \
|
||||
0x00, /* bCountryCode: Hardware target country */ \
|
||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */ \
|
||||
0x22, /* bDescriptorType */ \
|
||||
WBVAL(wItemLength), /* wItemLength: Total length of Report descriptor */ \
|
||||
0x07, /* bLength: Endpoint Descriptor size */ \
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */ \
|
||||
in_ep, /* bEndpointAddress: Endpoint Address (IN) */ \
|
||||
0x03, /* bmAttributes: Interrupt endpoint */ \
|
||||
WBVAL(wMaxPacketSize), /* wMaxPacketSize: x Byte max */ \
|
||||
bInterval, /* bInterval: Polling Interval */ \
|
||||
0x07, /* bLength: Endpoint Descriptor size */ \
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */ \
|
||||
out_ep, /* bEndpointAddress: Endpoint Address (IN) */ \
|
||||
0x03, /* bmAttributes: Interrupt endpoint */ \
|
||||
WBVAL(wMaxPacketSize), /* wMaxPacketSize: x Byte max */ \
|
||||
bInterval /* bInterval: Polling Interval */
|
||||
// clang-format on
|
||||
|
||||
#endif /* USB_HID_H */
|
||||
|
||||
@@ -15,10 +15,6 @@ extern "C" {
|
||||
/* 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);
|
||||
|
||||
@@ -106,7 +106,7 @@ int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer)
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(buffer, g_hid_buf[hid_class->minor], ret - 8);
|
||||
memcpy(buffer, g_hid_buf[hid_class->minor], MIN(ret - 8, 1));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -128,6 +128,30 @@ int usbh_hid_set_protocol(struct usbh_hid *hid_class, uint8_t protocol)
|
||||
return usbh_control_transfer(hid_class->hport, setup, NULL);
|
||||
}
|
||||
|
||||
int usbh_hid_get_protocol(struct usbh_hid *hid_class, uint8_t *protocol)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
int ret;
|
||||
|
||||
if (!hid_class || !hid_class->hport) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
setup = hid_class->hport->setup;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = HID_REQUEST_GET_PROTOCOL;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = hid_class->intf;
|
||||
setup->wLength = 1;
|
||||
|
||||
ret = usbh_control_transfer(hid_class->hport, setup, g_hid_buf[hid_class->minor]);
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(protocol, g_hid_buf[hid_class->minor], MIN(ret - 8, 1));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usbh_hid_set_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t report_id, uint8_t *buffer, uint32_t buflen)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
@@ -166,7 +190,7 @@ int usbh_hid_get_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(buffer, g_hid_buf[hid_class->minor], ret - 8);
|
||||
memcpy(buffer, g_hid_buf[hid_class->minor], MIN(ret - 8, buflen));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -275,6 +299,7 @@ int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister HID Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_hid_stop(hid_class);
|
||||
}
|
||||
@@ -303,9 +328,9 @@ const struct usbh_class_driver hid_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info hid_custom_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = USB_DEVICE_CLASS_HID,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_HID,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = NULL,
|
||||
.class_driver = &hid_class_driver
|
||||
};
|
||||
|
||||
@@ -31,6 +31,8 @@ extern "C" {
|
||||
int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer, uint32_t buflen);
|
||||
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_protocol(struct usbh_hid *hid_class, uint8_t protocol);
|
||||
int usbh_hid_get_protocol(struct usbh_hid *hid_class, uint8_t *protocol);
|
||||
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);
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ static int _usbh_hub_clear_feature(struct usbh_hub *hub, uint8_t port, uint8_t f
|
||||
return usbh_control_transfer(hub->parent, setup, NULL);
|
||||
}
|
||||
|
||||
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
||||
static int _usbh_hub_set_depth(struct usbh_hub *hub, uint16_t depth)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
@@ -167,7 +168,6 @@ static int _usbh_hub_set_depth(struct usbh_hub *hub, uint16_t depth)
|
||||
return usbh_control_transfer(hub->parent, setup, NULL);
|
||||
}
|
||||
|
||||
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
||||
static int parse_hub_descriptor(struct usb_hub_descriptor *desc, uint16_t length)
|
||||
{
|
||||
(void)length;
|
||||
@@ -270,6 +270,7 @@ int usbh_hub_clear_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature)
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
||||
static int usbh_hub_set_depth(struct usbh_hub *hub, uint16_t depth)
|
||||
{
|
||||
struct usb_setup_packet roothub_setup;
|
||||
@@ -288,7 +289,6 @@ static int usbh_hub_set_depth(struct usbh_hub *hub, uint16_t depth)
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
||||
static void hub_int_complete_callback(void *arg, int nbytes)
|
||||
{
|
||||
struct usbh_hub *hub = (struct usbh_hub *)arg;
|
||||
@@ -648,12 +648,12 @@ static void usbh_hub_events(struct usbh_hub *hub)
|
||||
}
|
||||
}
|
||||
|
||||
static void usbh_hub_thread(void *argument)
|
||||
static void usbh_hub_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
struct usbh_hub *hub;
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_bus *bus = (struct usbh_bus *)argument;
|
||||
struct usbh_bus *bus = (struct usbh_bus *)CONFIG_USB_OSAL_THREAD_GET_ARGV;
|
||||
|
||||
usb_hc_init(bus);
|
||||
while (1) {
|
||||
@@ -706,8 +706,6 @@ int usbh_hub_deinitialize(struct usbh_bus *bus)
|
||||
struct usbh_hub *hub;
|
||||
size_t flags;
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
|
||||
hub = &bus->hcd.roothub;
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
hport = &hub->child[port];
|
||||
@@ -715,6 +713,8 @@ int usbh_hub_deinitialize(struct usbh_bus *bus)
|
||||
usbh_hubport_release(hport);
|
||||
}
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
|
||||
usb_hc_deinit(bus);
|
||||
|
||||
usb_osal_leave_critical_section(flags);
|
||||
@@ -734,9 +734,9 @@ const struct usbh_class_driver hub_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info hub_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = USB_DEVICE_CLASS_HUB,
|
||||
.subclass = 0,
|
||||
.protocol = 0,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_HUB,
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.id_table = NULL,
|
||||
.class_driver = &hub_class_driver
|
||||
};
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include "usb_scsi.h"
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
#include "usb_osal.h"
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
#include "chry_ringbuffer.h"
|
||||
#endif
|
||||
|
||||
#define MSD_OUT_EP_IDX 0
|
||||
@@ -35,7 +33,7 @@ USB_NOCACHE_RAM_SECTION struct usbd_msc_priv {
|
||||
USB_MEM_ALIGNX struct CBW cbw;
|
||||
USB_MEM_ALIGNX struct CSW csw;
|
||||
|
||||
bool readonly;
|
||||
USB_MEM_ALIGNX bool readonly;
|
||||
bool popup;
|
||||
uint8_t sKey; /* Sense key */
|
||||
uint8_t ASC; /* Additional Sense Code */
|
||||
@@ -53,14 +51,13 @@ USB_NOCACHE_RAM_SECTION struct usbd_msc_priv {
|
||||
usb_osal_thread_t usbd_msc_thread;
|
||||
uint32_t nbytes;
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
chry_ringbuffer_t msc_rb;
|
||||
uint8_t msc_rb_pool[2];
|
||||
uint32_t event;
|
||||
uint32_t nbytes;
|
||||
#endif
|
||||
} g_usbd_msc[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
#ifdef CONFIG_USBDEV_MSC_THREAD
|
||||
static void usbdev_msc_thread(void *argument);
|
||||
static void usbdev_msc_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
#endif
|
||||
|
||||
static void usdb_msc_set_max_lun(uint8_t busid)
|
||||
@@ -114,7 +111,7 @@ void msc_storage_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
USB_LOG_ERR("No memory to alloc for g_usbd_msc[busid].usbd_msc_thread\r\n");
|
||||
}
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
chry_ringbuffer_init(&g_usbd_msc[busid].msc_rb, g_usbd_msc[busid].msc_rb_pool, sizeof(g_usbd_msc[busid].msc_rb_pool));
|
||||
g_usbd_msc[busid].event = 0;
|
||||
#endif
|
||||
break;
|
||||
case USBD_EVENT_DEINIT:
|
||||
@@ -539,7 +536,7 @@ static bool SCSI_read10(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
|
||||
return true;
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
|
||||
g_usbd_msc[busid].event = MSC_DATA_IN;
|
||||
return true;
|
||||
#else
|
||||
return SCSI_processRead(busid);
|
||||
@@ -577,7 +574,7 @@ static bool SCSI_read12(uint8_t busid, uint8_t **data, uint32_t *len)
|
||||
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
|
||||
return true;
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
|
||||
g_usbd_msc[busid].event = MSC_DATA_IN;
|
||||
return true;
|
||||
#else
|
||||
return SCSI_processRead(busid);
|
||||
@@ -852,7 +849,7 @@ void mass_storage_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_OUT);
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
g_usbd_msc[busid].nbytes = nbytes;
|
||||
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_OUT);
|
||||
g_usbd_msc[busid].event = MSC_DATA_OUT;
|
||||
#else
|
||||
if (SCSI_processWrite(busid, nbytes) == false) {
|
||||
usbd_msc_send_csw(busid, CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
|
||||
@@ -881,7 +878,7 @@ void mass_storage_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
|
||||
#elif defined(CONFIG_USBDEV_MSC_POLLING)
|
||||
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
|
||||
g_usbd_msc[busid].event = MSC_DATA_IN;
|
||||
#else
|
||||
if (SCSI_processRead(busid) == false) {
|
||||
usbd_msc_send_csw(busid, CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
|
||||
@@ -911,11 +908,11 @@ void mass_storage_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
}
|
||||
|
||||
#if defined(CONFIG_USBDEV_MSC_THREAD)
|
||||
static void usbdev_msc_thread(void *argument)
|
||||
static void usbdev_msc_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
uintptr_t event;
|
||||
int ret;
|
||||
uint8_t busid = (uint8_t)(uint32_t)argument;
|
||||
uint8_t busid = (uint8_t)CONFIG_USB_OSAL_THREAD_GET_ARGV;
|
||||
|
||||
while (1) {
|
||||
ret = usb_osal_mq_recv(g_usbd_msc[busid].usbd_msc_mq, (uintptr_t *)&event, USB_OSAL_WAITING_FOREVER);
|
||||
@@ -940,7 +937,10 @@ void usbd_msc_polling(uint8_t busid)
|
||||
{
|
||||
uint8_t event;
|
||||
|
||||
if (chry_ringbuffer_read_byte(&g_usbd_msc[busid].msc_rb, &event)) {
|
||||
event = g_usbd_msc[busid].event;
|
||||
|
||||
if (event != 0) {
|
||||
g_usbd_msc[busid].event = 0;
|
||||
USB_LOG_DBG("event:%d\r\n", event);
|
||||
if (event == MSC_DATA_OUT) {
|
||||
if (SCSI_processWrite(busid, g_usbd_msc[busid].nbytes) == false) {
|
||||
@@ -979,7 +979,8 @@ struct usbd_interface *usbd_msc_init_intf(uint8_t busid, struct usbd_interface *
|
||||
|
||||
if (CONFIG_USBDEV_MSC_MAX_BUFSIZE % g_usbd_msc[busid].scsi_blk_size[i]) {
|
||||
USB_LOG_ERR("CONFIG_USBDEV_MSC_MAX_BUFSIZE must be a multiple of block size\r\n");
|
||||
while(1){}
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -995,3 +996,34 @@ bool usbd_msc_get_popup(uint8_t busid)
|
||||
{
|
||||
return g_usbd_msc[busid].popup;
|
||||
}
|
||||
|
||||
__WEAK void usbd_msc_get_cap(uint8_t busid, uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
{
|
||||
(void)busid;
|
||||
(void)lun;
|
||||
|
||||
*block_num = 0;
|
||||
*block_size = 0;
|
||||
}
|
||||
|
||||
__WEAK int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
(void)busid;
|
||||
(void)lun;
|
||||
(void)sector;
|
||||
(void)buffer;
|
||||
(void)length;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
(void)busid;
|
||||
(void)lun;
|
||||
(void)sector;
|
||||
(void)buffer;
|
||||
(void)length;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -13,8 +13,11 @@
|
||||
|
||||
#define DEV_FORMAT "/dev/sd%c"
|
||||
|
||||
#define MSC_INQUIRY_TIMEOUT 500
|
||||
#ifndef CONFIG_USBHOST_MSC_READY_CHECK_TIMES
|
||||
#define CONFIG_USBHOST_MSC_READY_CHECK_TIMES 10
|
||||
#endif
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_msc_cbw_csw[CONFIG_USBHOST_MAX_MSC_CLASS][USB_ALIGN_UP(64, CONFIG_USB_ALIGN_SIZE)];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_msc_buf[CONFIG_USBHOST_MAX_MSC_CLASS][USB_ALIGN_UP(64, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static struct usbh_msc g_msc_class[CONFIG_USBHOST_MAX_MSC_CLASS];
|
||||
@@ -131,7 +134,7 @@ static int usbh_bulk_cbw_csw_xfer(struct usbh_msc *msc_class, struct CBW *cbw, s
|
||||
/* Send the CBW */
|
||||
nbytes = usbh_msc_bulk_out_transfer(msc_class, (uint8_t *)cbw, USB_SIZEOF_MSC_CBW, timeout);
|
||||
if (nbytes < 0) {
|
||||
USB_LOG_ERR("cbw transfer error\r\n");
|
||||
USB_LOG_ERR("cbw transfer error: %d\r\n", nbytes);
|
||||
goto __err_exit;
|
||||
}
|
||||
|
||||
@@ -150,7 +153,7 @@ static int usbh_bulk_cbw_csw_xfer(struct usbh_msc *msc_class, struct CBW *cbw, s
|
||||
}
|
||||
|
||||
if (nbytes < 0) {
|
||||
USB_LOG_ERR("msc data transfer error\r\n");
|
||||
USB_LOG_ERR("msc data transfer error: %d\r\n", nbytes);
|
||||
goto __err_exit;
|
||||
}
|
||||
}
|
||||
@@ -159,7 +162,7 @@ static int usbh_bulk_cbw_csw_xfer(struct usbh_msc *msc_class, struct CBW *cbw, s
|
||||
memset(csw, 0, USB_SIZEOF_MSC_CSW);
|
||||
nbytes = usbh_msc_bulk_in_transfer(msc_class, (uint8_t *)csw, USB_SIZEOF_MSC_CSW, timeout);
|
||||
if (nbytes < 0) {
|
||||
USB_LOG_ERR("csw transfer error\r\n");
|
||||
USB_LOG_ERR("csw transfer error: %d\r\n", nbytes);
|
||||
goto __err_exit;
|
||||
}
|
||||
|
||||
@@ -184,14 +187,14 @@ static inline int usbh_msc_scsi_testunitready(struct usbh_msc *msc_class)
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
cbw = (struct CBW *)g_msc_cbw_csw[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
cbw->bCBLength = SCSICMD_TESTUNITREADY_SIZEOF;
|
||||
cbw->CB[0] = SCSI_CMD_TESTUNITREADY;
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], NULL, MSC_INQUIRY_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_cbw_csw[msc_class->sdchar - 'a'], NULL, CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
}
|
||||
|
||||
static inline int usbh_msc_scsi_requestsense(struct usbh_msc *msc_class)
|
||||
@@ -199,7 +202,7 @@ static inline int usbh_msc_scsi_requestsense(struct usbh_msc *msc_class)
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
cbw = (struct CBW *)g_msc_cbw_csw[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
@@ -209,7 +212,7 @@ static inline int usbh_msc_scsi_requestsense(struct usbh_msc *msc_class)
|
||||
cbw->CB[0] = SCSI_CMD_REQUESTSENSE;
|
||||
cbw->CB[4] = SCSIRESP_FIXEDSENSEDATA_SIZEOF;
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], g_msc_buf[msc_class->sdchar - 'a'], MSC_INQUIRY_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_cbw_csw[msc_class->sdchar - 'a'], g_msc_buf[msc_class->sdchar - 'a'], CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
}
|
||||
|
||||
static inline int usbh_msc_scsi_inquiry(struct usbh_msc *msc_class)
|
||||
@@ -217,7 +220,7 @@ static inline int usbh_msc_scsi_inquiry(struct usbh_msc *msc_class)
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
cbw = (struct CBW *)g_msc_cbw_csw[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
@@ -227,7 +230,7 @@ static inline int usbh_msc_scsi_inquiry(struct usbh_msc *msc_class)
|
||||
cbw->CB[0] = SCSI_CMD_INQUIRY;
|
||||
cbw->CB[4] = SCSIRESP_INQUIRY_SIZEOF;
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], g_msc_buf[msc_class->sdchar - 'a'], MSC_INQUIRY_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_cbw_csw[msc_class->sdchar - 'a'], g_msc_buf[msc_class->sdchar - 'a'], CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
}
|
||||
|
||||
static inline int usbh_msc_scsi_readcapacity10(struct usbh_msc *msc_class)
|
||||
@@ -235,7 +238,7 @@ static inline int usbh_msc_scsi_readcapacity10(struct usbh_msc *msc_class)
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
cbw = (struct CBW *)g_msc_cbw_csw[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
@@ -244,7 +247,7 @@ static inline int usbh_msc_scsi_readcapacity10(struct usbh_msc *msc_class)
|
||||
cbw->bCBLength = SCSICMD_READCAPACITY10_SIZEOF;
|
||||
cbw->CB[0] = SCSI_CMD_READCAPACITY10;
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], g_msc_buf[msc_class->sdchar - 'a'], MSC_INQUIRY_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_cbw_csw[msc_class->sdchar - 'a'], g_msc_buf[msc_class->sdchar - 'a'], CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
}
|
||||
|
||||
static inline void usbh_msc_modeswitch(struct usbh_msc *msc_class, const uint8_t *message)
|
||||
@@ -252,18 +255,18 @@ static inline void usbh_msc_modeswitch(struct usbh_msc *msc_class, const uint8_t
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
cbw = (struct CBW *)g_msc_cbw_csw[msc_class->sdchar - 'a'];
|
||||
|
||||
memcpy(g_msc_buf[msc_class->sdchar - 'a'], message, 31);
|
||||
memcpy(g_msc_cbw_csw[msc_class->sdchar - 'a'], message, 31);
|
||||
|
||||
usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], NULL, MSC_INQUIRY_TIMEOUT);
|
||||
usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_cbw_csw[msc_class->sdchar - 'a'], NULL, CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
}
|
||||
|
||||
static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
int ret;
|
||||
struct usbh_msc_modeswitch_config *config;
|
||||
int ret;
|
||||
|
||||
struct usbh_msc *msc_class = usbh_msc_class_alloc();
|
||||
if (msc_class == NULL) {
|
||||
@@ -315,34 +318,6 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
}
|
||||
|
||||
ret = usbh_msc_scsi_testunitready(msc_class);
|
||||
if (ret < 0) {
|
||||
ret = usbh_msc_scsi_requestsense(msc_class);
|
||||
if (ret < 0) {
|
||||
USB_LOG_ERR("Fail to scsi_testunitready\r\n");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ret = usbh_msc_scsi_inquiry(msc_class);
|
||||
if (ret < 0) {
|
||||
USB_LOG_ERR("Fail to scsi_inquiry\r\n");
|
||||
return ret;
|
||||
}
|
||||
ret = usbh_msc_scsi_readcapacity10(msc_class);
|
||||
if (ret < 0) {
|
||||
USB_LOG_ERR("Fail to scsi_readcapacity10\r\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (msc_class->blocksize > 0) {
|
||||
USB_LOG_INFO("Capacity info:\r\n");
|
||||
USB_LOG_INFO("Block num:%d,block size:%d\r\n", (unsigned int)msc_class->blocknum, (unsigned int)msc_class->blocksize);
|
||||
} else {
|
||||
USB_LOG_ERR("Invalid block size\r\n");
|
||||
return -USB_ERR_RANGE;
|
||||
}
|
||||
|
||||
snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, msc_class->sdchar);
|
||||
|
||||
USB_LOG_INFO("Register MSC Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
@@ -367,6 +342,7 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister MSC Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_msc_stop(msc_class);
|
||||
}
|
||||
@@ -377,12 +353,52 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usbh_msc_scsi_init(struct usbh_msc *msc_class)
|
||||
{
|
||||
int ret;
|
||||
uint16_t cnt;
|
||||
|
||||
cnt = 0;
|
||||
while (usbh_msc_scsi_testunitready(msc_class) < 0) {
|
||||
USB_LOG_WRN("Device not ready, try again...\r\n");
|
||||
ret = usbh_msc_scsi_requestsense(msc_class);
|
||||
if (ret < 0) {
|
||||
USB_LOG_ERR("Fail to scsi_testunitready\r\n");
|
||||
}
|
||||
cnt++;
|
||||
if (cnt > CONFIG_USBHOST_MSC_READY_CHECK_TIMES) {
|
||||
return -USB_ERR_NODEV;
|
||||
}
|
||||
}
|
||||
ret = usbh_msc_scsi_inquiry(msc_class);
|
||||
if (ret < 0) {
|
||||
USB_LOG_ERR("Fail to scsi_inquiry\r\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = usbh_msc_scsi_readcapacity10(msc_class);
|
||||
if (ret < 0) {
|
||||
USB_LOG_ERR("Fail to scsi_readcapacity10\r\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (msc_class->blocksize > 0) {
|
||||
USB_LOG_INFO("Capacity info:\r\n");
|
||||
USB_LOG_INFO("Block num:%d,block size:%d\r\n", (unsigned int)msc_class->blocknum, (unsigned int)msc_class->blocksize);
|
||||
} else {
|
||||
USB_LOG_ERR("Invalid block size\r\n");
|
||||
return -USB_ERR_RANGE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_msc_scsi_write10(struct usbh_msc *msc_class, uint32_t start_sector, const uint8_t *buffer, uint32_t nsectors)
|
||||
{
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
cbw = (struct CBW *)g_msc_cbw_csw[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
@@ -393,7 +409,7 @@ int usbh_msc_scsi_write10(struct usbh_msc *msc_class, uint32_t start_sector, con
|
||||
SET_BE32(&cbw->CB[2], start_sector);
|
||||
SET_BE16(&cbw->CB[7], nsectors);
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], (uint8_t *)buffer, CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_cbw_csw[msc_class->sdchar - 'a'], (uint8_t *)buffer, CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
}
|
||||
|
||||
int usbh_msc_scsi_read10(struct usbh_msc *msc_class, uint32_t start_sector, const uint8_t *buffer, uint32_t nsectors)
|
||||
@@ -401,7 +417,7 @@ int usbh_msc_scsi_read10(struct usbh_msc *msc_class, uint32_t start_sector, cons
|
||||
struct CBW *cbw;
|
||||
|
||||
/* Construct the CBW */
|
||||
cbw = (struct CBW *)g_msc_buf[msc_class->sdchar - 'a'];
|
||||
cbw = (struct CBW *)g_msc_cbw_csw[msc_class->sdchar - 'a'];
|
||||
memset(cbw, 0, USB_SIZEOF_MSC_CBW);
|
||||
cbw->dSignature = MSC_CBW_Signature;
|
||||
|
||||
@@ -413,7 +429,7 @@ int usbh_msc_scsi_read10(struct usbh_msc *msc_class, uint32_t start_sector, cons
|
||||
SET_BE32(&cbw->CB[2], start_sector);
|
||||
SET_BE16(&cbw->CB[7], nsectors);
|
||||
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_buf[msc_class->sdchar - 'a'], (uint8_t *)buffer, CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
return usbh_bulk_cbw_csw_xfer(msc_class, cbw, (struct CSW *)g_msc_cbw_csw[msc_class->sdchar - 'a'], (uint8_t *)buffer, CONFIG_USBHOST_MSC_TIMEOUT);
|
||||
}
|
||||
|
||||
void usbh_msc_modeswitch_enable(struct usbh_msc_modeswitch_config *config)
|
||||
@@ -443,9 +459,9 @@ const struct usbh_class_driver msc_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info msc_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_MASS_STORAGE,
|
||||
.subclass = MSC_SUBCLASS_SCSI,
|
||||
.protocol = MSC_PROTOCOL_BULK_ONLY,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_MASS_STORAGE,
|
||||
.bInterfaceSubClass = MSC_SUBCLASS_SCSI,
|
||||
.bInterfaceProtocol = MSC_PROTOCOL_BULK_ONLY,
|
||||
.id_table = NULL,
|
||||
.class_driver = &msc_class_driver
|
||||
};
|
||||
|
||||
@@ -32,6 +32,7 @@ struct usbh_msc_modeswitch_config {
|
||||
};
|
||||
|
||||
void usbh_msc_modeswitch_enable(struct usbh_msc_modeswitch_config *config);
|
||||
int usbh_msc_scsi_init(struct usbh_msc *msc_class);
|
||||
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);
|
||||
|
||||
|
||||
683
class/mtp/usb_mtp.h
Normal file
683
class/mtp/usb_mtp.h
Normal file
@@ -0,0 +1,683 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USB_MTP_H
|
||||
#define USB_MTP_H
|
||||
|
||||
// clang-format off
|
||||
#define MTP_STANDARD_VERSION 100
|
||||
|
||||
// Container Types
|
||||
#define MTP_CONTAINER_TYPE_UNDEFINED 0
|
||||
#define MTP_CONTAINER_TYPE_COMMAND 1
|
||||
#define MTP_CONTAINER_TYPE_DATA 2
|
||||
#define MTP_CONTAINER_TYPE_RESPONSE 3
|
||||
#define MTP_CONTAINER_TYPE_EVENT 4
|
||||
|
||||
// Container Offsets
|
||||
#define MTP_CONTAINER_LENGTH_OFFSET 0
|
||||
#define MTP_CONTAINER_TYPE_OFFSET 4
|
||||
#define MTP_CONTAINER_CODE_OFFSET 6
|
||||
#define MTP_CONTAINER_TRANSACTION_ID_OFFSET 8
|
||||
#define MTP_CONTAINER_PARAMETER_OFFSET 12
|
||||
#define MTP_CONTAINER_HEADER_SIZE 12
|
||||
|
||||
// Maximum buffer size for a MTP packet.
|
||||
#define MTP_BUFFER_SIZE 16384
|
||||
|
||||
// MTP Data Types
|
||||
#define MTP_TYPE_UNDEFINED 0x0000 // Undefined
|
||||
#define MTP_TYPE_INT8 0x0001 // Signed 8-bit integer
|
||||
#define MTP_TYPE_UINT8 0x0002 // Unsigned 8-bit integer
|
||||
#define MTP_TYPE_INT16 0x0003 // Signed 16-bit integer
|
||||
#define MTP_TYPE_UINT16 0x0004 // Unsigned 16-bit integer
|
||||
#define MTP_TYPE_INT32 0x0005 // Signed 32-bit integer
|
||||
#define MTP_TYPE_UINT32 0x0006 // Unsigned 32-bit integer
|
||||
#define MTP_TYPE_INT64 0x0007 // Signed 64-bit integer
|
||||
#define MTP_TYPE_UINT64 0x0008 // Unsigned 64-bit integer
|
||||
#define MTP_TYPE_INT128 0x0009 // Signed 128-bit integer
|
||||
#define MTP_TYPE_UINT128 0x000A // Unsigned 128-bit integer
|
||||
#define MTP_TYPE_AINT8 0x4001 // Array of signed 8-bit integers
|
||||
#define MTP_TYPE_AUINT8 0x4002 // Array of unsigned 8-bit integers
|
||||
#define MTP_TYPE_AINT16 0x4003 // Array of signed 16-bit integers
|
||||
#define MTP_TYPE_AUINT16 0x4004 // Array of unsigned 16-bit integers
|
||||
#define MTP_TYPE_AINT32 0x4005 // Array of signed 32-bit integers
|
||||
#define MTP_TYPE_AUINT32 0x4006 // Array of unsigned 32-bit integers
|
||||
#define MTP_TYPE_AINT64 0x4007 // Array of signed 64-bit integers
|
||||
#define MTP_TYPE_AUINT64 0x4008 // Array of unsigned 64-bit integers
|
||||
#define MTP_TYPE_AINT128 0x4009 // Array of signed 128-bit integers
|
||||
#define MTP_TYPE_AUINT128 0x400A // Array of unsigned 128-bit integers
|
||||
#define MTP_TYPE_STR 0xFFFF // Variable-length Unicode string
|
||||
|
||||
// MTP Format Codes
|
||||
#define MTP_FORMAT_UNDEFINED 0x3000 // Undefined object
|
||||
#define MTP_FORMAT_ASSOCIATION 0x3001 // Association (for example, a folder)
|
||||
#define MTP_FORMAT_SCRIPT 0x3002 // Device model-specific script
|
||||
#define MTP_FORMAT_EXECUTABLE 0x3003 // Device model-specific binary executable
|
||||
#define MTP_FORMAT_TEXT 0x3004 // Text file
|
||||
#define MTP_FORMAT_HTML 0x3005 // Hypertext Markup Language file (text)
|
||||
#define MTP_FORMAT_DPOF 0x3006 // Digital Print Order Format file (text)
|
||||
#define MTP_FORMAT_AIFF 0x3007 // Audio clip
|
||||
#define MTP_FORMAT_WAV 0x3008 // Audio clip
|
||||
#define MTP_FORMAT_MP3 0x3009 // Audio clip
|
||||
#define MTP_FORMAT_AVI 0x300A // Video clip
|
||||
#define MTP_FORMAT_MPEG 0x300B // Video clip
|
||||
#define MTP_FORMAT_ASF 0x300C // Microsoft Advanced Streaming Format (video)
|
||||
#define MTP_FORMAT_DEFINED 0x3800 // Unknown image object
|
||||
#define MTP_FORMAT_EXIF_JPEG 0x3801 // Exchangeable File Format, JEIDA standard
|
||||
#define MTP_FORMAT_TIFF_EP 0x3802 // Tag Image File Format for Electronic Photography
|
||||
#define MTP_FORMAT_FLASHPIX 0x3803 // Structured Storage Image Format
|
||||
#define MTP_FORMAT_BMP 0x3804 // Microsoft Windows Bitmap file
|
||||
#define MTP_FORMAT_CIFF 0x3805 // Canon Camera Image File Format
|
||||
#define MTP_FORMAT_GIF 0x3807 // Graphics Interchange Format
|
||||
#define MTP_FORMAT_JFIF 0x3808 // JPEG File Interchange Format
|
||||
#define MTP_FORMAT_CD 0x3809 // PhotoCD Image Pac
|
||||
#define MTP_FORMAT_PICT 0x380A // Quickdraw Image Format
|
||||
#define MTP_FORMAT_PNG 0x380B // Portable Network Graphics
|
||||
#define MTP_FORMAT_TIFF 0x380D // Tag Image File Format
|
||||
#define MTP_FORMAT_TIFF_IT 0x380E // Tag Image File Format for Information Technology (graphic arts)
|
||||
#define MTP_FORMAT_JP2 0x380F // JPEG2000 Baseline File Format
|
||||
#define MTP_FORMAT_JPX 0x3810 // JPEG2000 Extended File Format
|
||||
#define MTP_FORMAT_DNG 0x3811 // Digital Negative
|
||||
#define MTP_FORMAT_HEIF 0x3812 // HEIF images
|
||||
#define MTP_FORMAT_UNDEFINED_FIRMWARE 0xB802
|
||||
#define MTP_FORMAT_WINDOWS_IMAGE_FORMAT 0xB881
|
||||
#define MTP_FORMAT_UNDEFINED_AUDIO 0xB900
|
||||
#define MTP_FORMAT_WMA 0xB901
|
||||
#define MTP_FORMAT_OGG 0xB902
|
||||
#define MTP_FORMAT_AAC 0xB903
|
||||
#define MTP_FORMAT_AUDIBLE 0xB904
|
||||
#define MTP_FORMAT_FLAC 0xB906
|
||||
#define MTP_FORMAT_UNDEFINED_VIDEO 0xB980
|
||||
#define MTP_FORMAT_WMV 0xB981
|
||||
#define MTP_FORMAT_MP4_CONTAINER 0xB982 // ISO 14496-1
|
||||
#define MTP_FORMAT_MP2 0xB983
|
||||
#define MTP_FORMAT_3GP_CONTAINER 0xB984 // 3GPP file format. Details: http://www.3gpp.org/ftp/Specs/html-info/26244.htm (page title - \u201cTransparent end-to-end packet switched streaming service, 3GPP file format\u201d).
|
||||
#define MTP_FORMAT_UNDEFINED_COLLECTION 0xBA00
|
||||
#define MTP_FORMAT_ABSTRACT_MULTIMEDIA_ALBUM 0xBA01
|
||||
#define MTP_FORMAT_ABSTRACT_IMAGE_ALBUM 0xBA02
|
||||
#define MTP_FORMAT_ABSTRACT_AUDIO_ALBUM 0xBA03
|
||||
#define MTP_FORMAT_ABSTRACT_VIDEO_ALBUM 0xBA04
|
||||
#define MTP_FORMAT_ABSTRACT_AV_PLAYLIST 0xBA05
|
||||
#define MTP_FORMAT_ABSTRACT_CONTACT_GROUP 0xBA06
|
||||
#define MTP_FORMAT_ABSTRACT_MESSAGE_FOLDER 0xBA07
|
||||
#define MTP_FORMAT_ABSTRACT_CHAPTERED_PRODUCTION 0xBA08
|
||||
#define MTP_FORMAT_ABSTRACT_AUDIO_PLAYLIST 0xBA09
|
||||
#define MTP_FORMAT_ABSTRACT_VIDEO_PLAYLIST 0xBA0A
|
||||
#define MTP_FORMAT_ABSTRACT_MEDIACAST 0xBA0B // For use with mediacasts; references multimedia enclosures of RSS feeds or episodic content
|
||||
#define MTP_FORMAT_WPL_PLAYLIST 0xBA10
|
||||
#define MTP_FORMAT_M3U_PLAYLIST 0xBA11
|
||||
#define MTP_FORMAT_MPL_PLAYLIST 0xBA12
|
||||
#define MTP_FORMAT_ASX_PLAYLIST 0xBA13
|
||||
#define MTP_FORMAT_PLS_PLAYLIST 0xBA14
|
||||
#define MTP_FORMAT_UNDEFINED_DOCUMENT 0xBA80
|
||||
#define MTP_FORMAT_ABSTRACT_DOCUMENT 0xBA81
|
||||
#define MTP_FORMAT_XML_DOCUMENT 0xBA82
|
||||
#define MTP_FORMAT_MS_WORD_DOCUMENT 0xBA83
|
||||
#define MTP_FORMAT_MHT_COMPILED_HTML_DOCUMENT 0xBA84
|
||||
#define MTP_FORMAT_MS_EXCEL_SPREADSHEET 0xBA85
|
||||
#define MTP_FORMAT_MS_POWERPOINT_PRESENTATION 0xBA86
|
||||
#define MTP_FORMAT_UNDEFINED_MESSAGE 0xBB00
|
||||
#define MTP_FORMAT_ABSTRACT_MESSSAGE 0xBB01
|
||||
#define MTP_FORMAT_UNDEFINED_CONTACT 0xBB80
|
||||
#define MTP_FORMAT_ABSTRACT_CONTACT 0xBB81
|
||||
#define MTP_FORMAT_VCARD_2 0xBB82
|
||||
|
||||
// MTP Object Property Codes
|
||||
#define MTP_PROPERTY_STORAGE_ID 0xDC01
|
||||
#define MTP_PROPERTY_OBJECT_FORMAT 0xDC02
|
||||
#define MTP_PROPERTY_PROTECTION_STATUS 0xDC03
|
||||
#define MTP_PROPERTY_OBJECT_SIZE 0xDC04
|
||||
#define MTP_PROPERTY_ASSOCIATION_TYPE 0xDC05
|
||||
#define MTP_PROPERTY_ASSOCIATION_DESC 0xDC06
|
||||
#define MTP_PROPERTY_OBJECT_FILE_NAME 0xDC07
|
||||
#define MTP_PROPERTY_DATE_CREATED 0xDC08
|
||||
#define MTP_PROPERTY_DATE_MODIFIED 0xDC09
|
||||
#define MTP_PROPERTY_KEYWORDS 0xDC0A
|
||||
#define MTP_PROPERTY_PARENT_OBJECT 0xDC0B
|
||||
#define MTP_PROPERTY_ALLOWED_FOLDER_CONTENTS 0xDC0C
|
||||
#define MTP_PROPERTY_HIDDEN 0xDC0D
|
||||
#define MTP_PROPERTY_SYSTEM_OBJECT 0xDC0E
|
||||
#define MTP_PROPERTY_PERSISTENT_UID 0xDC41
|
||||
#define MTP_PROPERTY_SYNC_ID 0xDC42
|
||||
#define MTP_PROPERTY_PROPERTY_BAG 0xDC43
|
||||
#define MTP_PROPERTY_NAME 0xDC44
|
||||
#define MTP_PROPERTY_CREATED_BY 0xDC45
|
||||
#define MTP_PROPERTY_ARTIST 0xDC46
|
||||
#define MTP_PROPERTY_DATE_AUTHORED 0xDC47
|
||||
#define MTP_PROPERTY_DESCRIPTION 0xDC48
|
||||
#define MTP_PROPERTY_URL_REFERENCE 0xDC49
|
||||
#define MTP_PROPERTY_LANGUAGE_LOCALE 0xDC4A
|
||||
#define MTP_PROPERTY_COPYRIGHT_INFORMATION 0xDC4B
|
||||
#define MTP_PROPERTY_SOURCE 0xDC4C
|
||||
#define MTP_PROPERTY_ORIGIN_LOCATION 0xDC4D
|
||||
#define MTP_PROPERTY_DATE_ADDED 0xDC4E
|
||||
#define MTP_PROPERTY_NON_CONSUMABLE 0xDC4F
|
||||
#define MTP_PROPERTY_CORRUPT_UNPLAYABLE 0xDC50
|
||||
#define MTP_PROPERTY_PRODUCER_SERIAL_NUMBER 0xDC51
|
||||
#define MTP_PROPERTY_REPRESENTATIVE_SAMPLE_FORMAT 0xDC81
|
||||
#define MTP_PROPERTY_REPRESENTATIVE_SAMPLE_SIZE 0xDC82
|
||||
#define MTP_PROPERTY_REPRESENTATIVE_SAMPLE_HEIGHT 0xDC83
|
||||
#define MTP_PROPERTY_REPRESENTATIVE_SAMPLE_WIDTH 0xDC84
|
||||
#define MTP_PROPERTY_REPRESENTATIVE_SAMPLE_DURATION 0xDC85
|
||||
#define MTP_PROPERTY_REPRESENTATIVE_SAMPLE_DATA 0xDC86
|
||||
#define MTP_PROPERTY_WIDTH 0xDC87
|
||||
#define MTP_PROPERTY_HEIGHT 0xDC88
|
||||
#define MTP_PROPERTY_DURATION 0xDC89
|
||||
#define MTP_PROPERTY_RATING 0xDC8A
|
||||
#define MTP_PROPERTY_TRACK 0xDC8B
|
||||
#define MTP_PROPERTY_GENRE 0xDC8C
|
||||
#define MTP_PROPERTY_CREDITS 0xDC8D
|
||||
#define MTP_PROPERTY_LYRICS 0xDC8E
|
||||
#define MTP_PROPERTY_SUBSCRIPTION_CONTENT_ID 0xDC8F
|
||||
#define MTP_PROPERTY_PRODUCED_BY 0xDC90
|
||||
#define MTP_PROPERTY_USE_COUNT 0xDC91
|
||||
#define MTP_PROPERTY_SKIP_COUNT 0xDC92
|
||||
#define MTP_PROPERTY_LAST_ACCESSED 0xDC93
|
||||
#define MTP_PROPERTY_PARENTAL_RATING 0xDC94
|
||||
#define MTP_PROPERTY_META_GENRE 0xDC95
|
||||
#define MTP_PROPERTY_COMPOSER 0xDC96
|
||||
#define MTP_PROPERTY_EFFECTIVE_RATING 0xDC97
|
||||
#define MTP_PROPERTY_SUBTITLE 0xDC98
|
||||
#define MTP_PROPERTY_ORIGINAL_RELEASE_DATE 0xDC99
|
||||
#define MTP_PROPERTY_ALBUM_NAME 0xDC9A
|
||||
#define MTP_PROPERTY_ALBUM_ARTIST 0xDC9B
|
||||
#define MTP_PROPERTY_MOOD 0xDC9C
|
||||
#define MTP_PROPERTY_DRM_STATUS 0xDC9D
|
||||
#define MTP_PROPERTY_SUB_DESCRIPTION 0xDC9E
|
||||
#define MTP_PROPERTY_IS_CROPPED 0xDCD1
|
||||
#define MTP_PROPERTY_IS_COLOUR_CORRECTED 0xDCD2
|
||||
#define MTP_PROPERTY_IMAGE_BIT_DEPTH 0xDCD3
|
||||
#define MTP_PROPERTY_F_NUMBER 0xDCD4
|
||||
#define MTP_PROPERTY_EXPOSURE_TIME 0xDCD5
|
||||
#define MTP_PROPERTY_EXPOSURE_INDEX 0xDCD6
|
||||
#define MTP_PROPERTY_TOTAL_BITRATE 0xDE91
|
||||
#define MTP_PROPERTY_BITRATE_TYPE 0xDE92
|
||||
#define MTP_PROPERTY_SAMPLE_RATE 0xDE93
|
||||
#define MTP_PROPERTY_NUMBER_OF_CHANNELS 0xDE94
|
||||
#define MTP_PROPERTY_AUDIO_BIT_DEPTH 0xDE95
|
||||
#define MTP_PROPERTY_SCAN_TYPE 0xDE97
|
||||
#define MTP_PROPERTY_AUDIO_WAVE_CODEC 0xDE99
|
||||
#define MTP_PROPERTY_AUDIO_BITRATE 0xDE9A
|
||||
#define MTP_PROPERTY_VIDEO_FOURCC_CODEC 0xDE9B
|
||||
#define MTP_PROPERTY_VIDEO_BITRATE 0xDE9C
|
||||
#define MTP_PROPERTY_FRAMES_PER_THOUSAND_SECONDS 0xDE9D
|
||||
#define MTP_PROPERTY_KEYFRAME_DISTANCE 0xDE9E
|
||||
#define MTP_PROPERTY_BUFFER_SIZE 0xDE9F
|
||||
#define MTP_PROPERTY_ENCODING_QUALITY 0xDEA0
|
||||
#define MTP_PROPERTY_ENCODING_PROFILE 0xDEA1
|
||||
#define MTP_PROPERTY_DISPLAY_NAME 0xDCE0
|
||||
#define MTP_PROPERTY_BODY_TEXT 0xDCE1
|
||||
#define MTP_PROPERTY_SUBJECT 0xDCE2
|
||||
#define MTP_PROPERTY_PRIORITY 0xDCE3
|
||||
#define MTP_PROPERTY_GIVEN_NAME 0xDD00
|
||||
#define MTP_PROPERTY_MIDDLE_NAMES 0xDD01
|
||||
#define MTP_PROPERTY_FAMILY_NAME 0xDD02
|
||||
#define MTP_PROPERTY_PREFIX 0xDD03
|
||||
#define MTP_PROPERTY_SUFFIX 0xDD04
|
||||
#define MTP_PROPERTY_PHONETIC_GIVEN_NAME 0xDD05
|
||||
#define MTP_PROPERTY_PHONETIC_FAMILY_NAME 0xDD06
|
||||
#define MTP_PROPERTY_EMAIL_PRIMARY 0xDD07
|
||||
#define MTP_PROPERTY_EMAIL_PERSONAL_1 0xDD08
|
||||
#define MTP_PROPERTY_EMAIL_PERSONAL_2 0xDD09
|
||||
#define MTP_PROPERTY_EMAIL_BUSINESS_1 0xDD0A
|
||||
#define MTP_PROPERTY_EMAIL_BUSINESS_2 0xDD0B
|
||||
#define MTP_PROPERTY_EMAIL_OTHERS 0xDD0C
|
||||
#define MTP_PROPERTY_PHONE_NUMBER_PRIMARY 0xDD0D
|
||||
#define MTP_PROPERTY_PHONE_NUMBER_PERSONAL 0xDD0E
|
||||
#define MTP_PROPERTY_PHONE_NUMBER_PERSONAL_2 0xDD0F
|
||||
#define MTP_PROPERTY_PHONE_NUMBER_BUSINESS 0xDD10
|
||||
#define MTP_PROPERTY_PHONE_NUMBER_BUSINESS_2 0xDD11
|
||||
#define MTP_PROPERTY_PHONE_NUMBER_MOBILE 0xDD12
|
||||
#define MTP_PROPERTY_PHONE_NUMBER_MOBILE_2 0xDD13
|
||||
#define MTP_PROPERTY_FAX_NUMBER_PRIMARY 0xDD14
|
||||
#define MTP_PROPERTY_FAX_NUMBER_PERSONAL 0xDD15
|
||||
#define MTP_PROPERTY_FAX_NUMBER_BUSINESS 0xDD16
|
||||
#define MTP_PROPERTY_PAGER_NUMBER 0xDD17
|
||||
#define MTP_PROPERTY_PHONE_NUMBER_OTHERS 0xDD18
|
||||
#define MTP_PROPERTY_PRIMARY_WEB_ADDRESS 0xDD19
|
||||
#define MTP_PROPERTY_PERSONAL_WEB_ADDRESS 0xDD1A
|
||||
#define MTP_PROPERTY_BUSINESS_WEB_ADDRESS 0xDD1B
|
||||
#define MTP_PROPERTY_INSTANT_MESSANGER_ADDRESS 0xDD1C
|
||||
#define MTP_PROPERTY_INSTANT_MESSANGER_ADDRESS_2 0xDD1D
|
||||
#define MTP_PROPERTY_INSTANT_MESSANGER_ADDRESS_3 0xDD1E
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_PERSONAL_FULL 0xDD1F
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_PERSONAL_LINE_1 0xDD20
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_PERSONAL_LINE_2 0xDD21
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_PERSONAL_CITY 0xDD22
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_PERSONAL_REGION 0xDD23
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_PERSONAL_POSTAL_CODE 0xDD24
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_PERSONAL_COUNTRY 0xDD25
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_BUSINESS_FULL 0xDD26
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_BUSINESS_LINE_1 0xDD27
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_BUSINESS_LINE_2 0xDD28
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_BUSINESS_CITY 0xDD29
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_BUSINESS_REGION 0xDD2A
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_BUSINESS_POSTAL_CODE 0xDD2B
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_BUSINESS_COUNTRY 0xDD2C
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_OTHER_FULL 0xDD2D
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_OTHER_LINE_1 0xDD2E
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_OTHER_LINE_2 0xDD2F
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_OTHER_CITY 0xDD30
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_OTHER_REGION 0xDD31
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_OTHER_POSTAL_CODE 0xDD32
|
||||
#define MTP_PROPERTY_POSTAL_ADDRESS_OTHER_COUNTRY 0xDD33
|
||||
#define MTP_PROPERTY_ORGANIZATION_NAME 0xDD34
|
||||
#define MTP_PROPERTY_PHONETIC_ORGANIZATION_NAME 0xDD35
|
||||
#define MTP_PROPERTY_ROLE 0xDD36
|
||||
#define MTP_PROPERTY_BIRTHDATE 0xDD37
|
||||
#define MTP_PROPERTY_MESSAGE_TO 0xDD40
|
||||
#define MTP_PROPERTY_MESSAGE_CC 0xDD41
|
||||
#define MTP_PROPERTY_MESSAGE_BCC 0xDD42
|
||||
#define MTP_PROPERTY_MESSAGE_READ 0xDD43
|
||||
#define MTP_PROPERTY_MESSAGE_RECEIVED_TIME 0xDD44
|
||||
#define MTP_PROPERTY_MESSAGE_SENDER 0xDD45
|
||||
#define MTP_PROPERTY_ACTIVITY_BEGIN_TIME 0xDD50
|
||||
#define MTP_PROPERTY_ACTIVITY_END_TIME 0xDD51
|
||||
#define MTP_PROPERTY_ACTIVITY_LOCATION 0xDD52
|
||||
#define MTP_PROPERTY_ACTIVITY_REQUIRED_ATTENDEES 0xDD54
|
||||
#define MTP_PROPERTY_ACTIVITY_OPTIONAL_ATTENDEES 0xDD55
|
||||
#define MTP_PROPERTY_ACTIVITY_RESOURCES 0xDD56
|
||||
#define MTP_PROPERTY_ACTIVITY_ACCEPTED 0xDD57
|
||||
#define MTP_PROPERTY_ACTIVITY_TENTATIVE 0xDD58
|
||||
#define MTP_PROPERTY_ACTIVITY_DECLINED 0xDD59
|
||||
#define MTP_PROPERTY_ACTIVITY_REMAINDER_TIME 0xDD5A
|
||||
#define MTP_PROPERTY_ACTIVITY_OWNER 0xDD5B
|
||||
#define MTP_PROPERTY_ACTIVITY_STATUS 0xDD5C
|
||||
#define MTP_PROPERTY_OWNER 0xDD5D
|
||||
#define MTP_PROPERTY_EDITOR 0xDD5E
|
||||
#define MTP_PROPERTY_WEBMASTER 0xDD5F
|
||||
#define MTP_PROPERTY_URL_SOURCE 0xDD60
|
||||
#define MTP_PROPERTY_URL_DESTINATION 0xDD61
|
||||
#define MTP_PROPERTY_TIME_BOOKMARK 0xDD62
|
||||
#define MTP_PROPERTY_OBJECT_BOOKMARK 0xDD63
|
||||
#define MTP_PROPERTY_BYTE_BOOKMARK 0xDD64
|
||||
#define MTP_PROPERTY_LAST_BUILD_DATE 0xDD70
|
||||
#define MTP_PROPERTY_TIME_TO_LIVE 0xDD71
|
||||
#define MTP_PROPERTY_MEDIA_GUID 0xDD72
|
||||
|
||||
// MTP Device Property Codes
|
||||
#define MTP_DEVICE_PROPERTY_UNDEFINED 0x5000
|
||||
#define MTP_DEVICE_PROPERTY_BATTERY_LEVEL 0x5001
|
||||
#define MTP_DEVICE_PROPERTY_FUNCTIONAL_MODE 0x5002
|
||||
#define MTP_DEVICE_PROPERTY_IMAGE_SIZE 0x5003
|
||||
#define MTP_DEVICE_PROPERTY_COMPRESSION_SETTING 0x5004
|
||||
#define MTP_DEVICE_PROPERTY_WHITE_BALANCE 0x5005
|
||||
#define MTP_DEVICE_PROPERTY_RGB_GAIN 0x5006
|
||||
#define MTP_DEVICE_PROPERTY_F_NUMBER 0x5007
|
||||
#define MTP_DEVICE_PROPERTY_FOCAL_LENGTH 0x5008
|
||||
#define MTP_DEVICE_PROPERTY_FOCUS_DISTANCE 0x5009
|
||||
#define MTP_DEVICE_PROPERTY_FOCUS_MODE 0x500A
|
||||
#define MTP_DEVICE_PROPERTY_EXPOSURE_METERING_MODE 0x500B
|
||||
#define MTP_DEVICE_PROPERTY_FLASH_MODE 0x500C
|
||||
#define MTP_DEVICE_PROPERTY_EXPOSURE_TIME 0x500D
|
||||
#define MTP_DEVICE_PROPERTY_EXPOSURE_PROGRAM_MODE 0x500E
|
||||
#define MTP_DEVICE_PROPERTY_EXPOSURE_INDEX 0x500F
|
||||
#define MTP_DEVICE_PROPERTY_EXPOSURE_BIAS_COMPENSATION 0x5010
|
||||
#define MTP_DEVICE_PROPERTY_DATETIME 0x5011
|
||||
#define MTP_DEVICE_PROPERTY_CAPTURE_DELAY 0x5012
|
||||
#define MTP_DEVICE_PROPERTY_STILL_CAPTURE_MODE 0x5013
|
||||
#define MTP_DEVICE_PROPERTY_CONTRAST 0x5014
|
||||
#define MTP_DEVICE_PROPERTY_SHARPNESS 0x5015
|
||||
#define MTP_DEVICE_PROPERTY_DIGITAL_ZOOM 0x5016
|
||||
#define MTP_DEVICE_PROPERTY_EFFECT_MODE 0x5017
|
||||
#define MTP_DEVICE_PROPERTY_BURST_NUMBER 0x5018
|
||||
#define MTP_DEVICE_PROPERTY_BURST_INTERVAL 0x5019
|
||||
#define MTP_DEVICE_PROPERTY_TIMELAPSE_NUMBER 0x501A
|
||||
#define MTP_DEVICE_PROPERTY_TIMELAPSE_INTERVAL 0x501B
|
||||
#define MTP_DEVICE_PROPERTY_FOCUS_METERING_MODE 0x501C
|
||||
#define MTP_DEVICE_PROPERTY_UPLOAD_URL 0x501D
|
||||
#define MTP_DEVICE_PROPERTY_ARTIST 0x501E
|
||||
#define MTP_DEVICE_PROPERTY_COPYRIGHT_INFO 0x501F
|
||||
#define MTP_DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER 0xD401
|
||||
#define MTP_DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME 0xD402
|
||||
#define MTP_DEVICE_PROPERTY_VOLUME 0xD403
|
||||
#define MTP_DEVICE_PROPERTY_SUPPORTED_FORMATS_ORDERED 0xD404
|
||||
#define MTP_DEVICE_PROPERTY_DEVICE_ICON 0xD405
|
||||
#define MTP_DEVICE_PROPERTY_PLAYBACK_RATE 0xD410
|
||||
#define MTP_DEVICE_PROPERTY_PLAYBACK_OBJECT 0xD411
|
||||
#define MTP_DEVICE_PROPERTY_PLAYBACK_CONTAINER_INDEX 0xD412
|
||||
#define MTP_DEVICE_PROPERTY_SESSION_INITIATOR_VERSION_INFO 0xD406
|
||||
#define MTP_DEVICE_PROPERTY_PERCEIVED_DEVICE_TYPE 0xD407
|
||||
|
||||
// MTP Operation Codes
|
||||
#define MTP_OPERATION_GET_DEVICE_INFO 0x1001
|
||||
#define MTP_OPERATION_OPEN_SESSION 0x1002
|
||||
#define MTP_OPERATION_CLOSE_SESSION 0x1003
|
||||
#define MTP_OPERATION_GET_STORAGE_IDS 0x1004
|
||||
#define MTP_OPERATION_GET_STORAGE_INFO 0x1005
|
||||
#define MTP_OPERATION_GET_NUM_OBJECTS 0x1006
|
||||
#define MTP_OPERATION_GET_OBJECT_HANDLES 0x1007
|
||||
#define MTP_OPERATION_GET_OBJECT_INFO 0x1008
|
||||
#define MTP_OPERATION_GET_OBJECT 0x1009
|
||||
#define MTP_OPERATION_GET_THUMB 0x100A
|
||||
#define MTP_OPERATION_DELETE_OBJECT 0x100B
|
||||
#define MTP_OPERATION_SEND_OBJECT_INFO 0x100C
|
||||
#define MTP_OPERATION_SEND_OBJECT 0x100D
|
||||
#define MTP_OPERATION_INITIATE_CAPTURE 0x100E
|
||||
#define MTP_OPERATION_FORMAT_STORE 0x100F
|
||||
#define MTP_OPERATION_RESET_DEVICE 0x1010
|
||||
#define MTP_OPERATION_SELF_TEST 0x1011
|
||||
#define MTP_OPERATION_SET_OBJECT_PROTECTION 0x1012
|
||||
#define MTP_OPERATION_POWER_DOWN 0x1013
|
||||
#define MTP_OPERATION_GET_DEVICE_PROP_DESC 0x1014
|
||||
#define MTP_OPERATION_GET_DEVICE_PROP_VALUE 0x1015
|
||||
#define MTP_OPERATION_SET_DEVICE_PROP_VALUE 0x1016
|
||||
#define MTP_OPERATION_RESET_DEVICE_PROP_VALUE 0x1017
|
||||
#define MTP_OPERATION_TERMINATE_OPEN_CAPTURE 0x1018
|
||||
#define MTP_OPERATION_MOVE_OBJECT 0x1019
|
||||
#define MTP_OPERATION_COPY_OBJECT 0x101A
|
||||
#define MTP_OPERATION_GET_PARTIAL_OBJECT 0x101B
|
||||
#define MTP_OPERATION_INITIATE_OPEN_CAPTURE 0x101C
|
||||
#define MTP_OPERATION_GET_OBJECT_PROPS_SUPPORTED 0x9801
|
||||
#define MTP_OPERATION_GET_OBJECT_PROP_DESC 0x9802
|
||||
#define MTP_OPERATION_GET_OBJECT_PROP_VALUE 0x9803
|
||||
#define MTP_OPERATION_SET_OBJECT_PROP_VALUE 0x9804
|
||||
#define MTP_OPERATION_GET_OBJECT_PROP_LIST 0x9805
|
||||
#define MTP_OPERATION_SET_OBJECT_PROP_LIST 0x9806
|
||||
#define MTP_OPERATION_GET_INTERDEPENDENT_PROP_DESC 0x9807
|
||||
#define MTP_OPERATION_SEND_OBJECT_PROP_LIST 0x9808
|
||||
#define MTP_OPERATION_GET_OBJECT_REFERENCES 0x9810
|
||||
#define MTP_OPERATION_SET_OBJECT_REFERENCES 0x9811
|
||||
#define MTP_OPERATION_SKIP 0x9820
|
||||
|
||||
// Android extensions for direct file IO
|
||||
|
||||
// Same as GetPartialObject, but with 64 bit offset
|
||||
#define MTP_OPERATION_GET_PARTIAL_OBJECT_64 0x95C1
|
||||
// Same as GetPartialObject64, but copying host to device
|
||||
#define MTP_OPERATION_SEND_PARTIAL_OBJECT 0x95C2
|
||||
// Truncates file to 64 bit length
|
||||
#define MTP_OPERATION_TRUNCATE_OBJECT 0x95C3
|
||||
// Must be called before using SendPartialObject and TruncateObject
|
||||
#define MTP_OPERATION_BEGIN_EDIT_OBJECT 0x95C4
|
||||
// Called to commit changes made by SendPartialObject and TruncateObject
|
||||
#define MTP_OPERATION_END_EDIT_OBJECT 0x95C5
|
||||
|
||||
// MTP Response Codes
|
||||
#define MTP_RESPONSE_UNDEFINED 0x2000
|
||||
#define MTP_RESPONSE_OK 0x2001
|
||||
#define MTP_RESPONSE_GENERAL_ERROR 0x2002
|
||||
#define MTP_RESPONSE_SESSION_NOT_OPEN 0x2003
|
||||
#define MTP_RESPONSE_INVALID_TRANSACTION_ID 0x2004
|
||||
#define MTP_RESPONSE_OPERATION_NOT_SUPPORTED 0x2005
|
||||
#define MTP_RESPONSE_PARAMETER_NOT_SUPPORTED 0x2006
|
||||
#define MTP_RESPONSE_INCOMPLETE_TRANSFER 0x2007
|
||||
#define MTP_RESPONSE_INVALID_STORAGE_ID 0x2008
|
||||
#define MTP_RESPONSE_INVALID_OBJECT_HANDLE 0x2009
|
||||
#define MTP_RESPONSE_DEVICE_PROP_NOT_SUPPORTED 0x200A
|
||||
#define MTP_RESPONSE_INVALID_OBJECT_FORMAT_CODE 0x200B
|
||||
#define MTP_RESPONSE_STORAGE_FULL 0x200C
|
||||
#define MTP_RESPONSE_OBJECT_WRITE_PROTECTED 0x200D
|
||||
#define MTP_RESPONSE_STORE_READ_ONLY 0x200E
|
||||
#define MTP_RESPONSE_ACCESS_DENIED 0x200F
|
||||
#define MTP_RESPONSE_NO_THUMBNAIL_PRESENT 0x2010
|
||||
#define MTP_RESPONSE_SELF_TEST_FAILED 0x2011
|
||||
#define MTP_RESPONSE_PARTIAL_DELETION 0x2012
|
||||
#define MTP_RESPONSE_STORE_NOT_AVAILABLE 0x2013
|
||||
#define MTP_RESPONSE_SPECIFICATION_BY_FORMAT_UNSUPPORTED 0x2014
|
||||
#define MTP_RESPONSE_NO_VALID_OBJECT_INFO 0x2015
|
||||
#define MTP_RESPONSE_INVALID_CODE_FORMAT 0x2016
|
||||
#define MTP_RESPONSE_UNKNOWN_VENDOR_CODE 0x2017
|
||||
#define MTP_RESPONSE_CAPTURE_ALREADY_TERMINATED 0x2018
|
||||
#define MTP_RESPONSE_DEVICE_BUSY 0x2019
|
||||
#define MTP_RESPONSE_INVALID_PARENT_OBJECT 0x201A
|
||||
#define MTP_RESPONSE_INVALID_DEVICE_PROP_FORMAT 0x201B
|
||||
#define MTP_RESPONSE_INVALID_DEVICE_PROP_VALUE 0x201C
|
||||
#define MTP_RESPONSE_INVALID_PARAMETER 0x201D
|
||||
#define MTP_RESPONSE_SESSION_ALREADY_OPEN 0x201E
|
||||
#define MTP_RESPONSE_TRANSACTION_CANCELLED 0x201F
|
||||
#define MTP_RESPONSE_SPECIFICATION_OF_DESTINATION_UNSUPPORTED 0x2020
|
||||
#define MTP_RESPONSE_INVALID_OBJECT_PROP_CODE 0xA801
|
||||
#define MTP_RESPONSE_INVALID_OBJECT_PROP_FORMAT 0xA802
|
||||
#define MTP_RESPONSE_INVALID_OBJECT_PROP_VALUE 0xA803
|
||||
#define MTP_RESPONSE_INVALID_OBJECT_REFERENCE 0xA804
|
||||
#define MTP_RESPONSE_GROUP_NOT_SUPPORTED 0xA805
|
||||
#define MTP_RESPONSE_INVALID_DATASET 0xA806
|
||||
#define MTP_RESPONSE_SPECIFICATION_BY_GROUP_UNSUPPORTED 0xA807
|
||||
#define MTP_RESPONSE_SPECIFICATION_BY_DEPTH_UNSUPPORTED 0xA808
|
||||
#define MTP_RESPONSE_OBJECT_TOO_LARGE 0xA809
|
||||
#define MTP_RESPONSE_OBJECT_PROP_NOT_SUPPORTED 0xA80A
|
||||
#define MTP_RESPONSE_NO_RESPONSE 0xFFFF
|
||||
|
||||
// MTP Event Codes
|
||||
#define MTP_EVENT_UNDEFINED 0x4000
|
||||
#define MTP_EVENT_CANCEL_TRANSACTION 0x4001
|
||||
#define MTP_EVENT_OBJECT_ADDED 0x4002
|
||||
#define MTP_EVENT_OBJECT_REMOVED 0x4003
|
||||
#define MTP_EVENT_STORE_ADDED 0x4004
|
||||
#define MTP_EVENT_STORE_REMOVED 0x4005
|
||||
#define MTP_EVENT_DEVICE_PROP_CHANGED 0x4006
|
||||
#define MTP_EVENT_OBJECT_INFO_CHANGED 0x4007
|
||||
#define MTP_EVENT_DEVICE_INFO_CHANGED 0x4008
|
||||
#define MTP_EVENT_REQUEST_OBJECT_TRANSFER 0x4009
|
||||
#define MTP_EVENT_STORE_FULL 0x400A
|
||||
#define MTP_EVENT_DEVICE_RESET 0x400B
|
||||
#define MTP_EVENT_STORAGE_INFO_CHANGED 0x400C
|
||||
#define MTP_EVENT_CAPTURE_COMPLETE 0x400D
|
||||
#define MTP_EVENT_UNREPORTED_STATUS 0x400E
|
||||
#define MTP_EVENT_OBJECT_PROP_CHANGED 0xC801
|
||||
#define MTP_EVENT_OBJECT_PROP_DESC_CHANGED 0xC802
|
||||
#define MTP_EVENT_OBJECT_REFERENCES_CHANGED 0xC803
|
||||
|
||||
// Storage Type
|
||||
#define MTP_STORAGE_FIXED_ROM 0x0001
|
||||
#define MTP_STORAGE_REMOVABLE_ROM 0x0002
|
||||
#define MTP_STORAGE_FIXED_RAM 0x0003
|
||||
#define MTP_STORAGE_REMOVABLE_RAM 0x0004
|
||||
|
||||
// Storage File System
|
||||
#define MTP_STORAGE_FILESYSTEM_FLAT 0x0001
|
||||
#define MTP_STORAGE_FILESYSTEM_HIERARCHICAL 0x0002
|
||||
#define MTP_STORAGE_FILESYSTEM_DCF 0x0003
|
||||
|
||||
// Storage Access Capability
|
||||
#define MTP_STORAGE_READ_WRITE 0x0000
|
||||
#define MTP_STORAGE_READ_ONLY_WITHOUT_DELETE 0x0001
|
||||
#define MTP_STORAGE_READ_ONLY_WITH_DELETE 0x0002
|
||||
|
||||
// Association Type
|
||||
#define MTP_ASSOCIATION_TYPE_UNDEFINED 0x0000
|
||||
#define MTP_ASSOCIATION_TYPE_GENERIC_FOLDER 0x0001
|
||||
|
||||
// MTP class reqeusts
|
||||
#define MTP_REQUEST_CANCEL 0x64
|
||||
#define MTP_REQUEST_GET_EXT_EVENT_DATA 0x65
|
||||
#define MTP_REQUEST_RESET 0x66
|
||||
#define MTP_REQUEST_GET_DEVICE_STATUS 0x67
|
||||
// clang-format on
|
||||
|
||||
#define USB_MTP_CLASS 0x06
|
||||
|
||||
#define USB_MTP_SUB_CLASS 0x01U
|
||||
#define USB_MTP_PROTOCOL 0x01U
|
||||
|
||||
struct mtp_header {
|
||||
uint32_t conlen;
|
||||
uint16_t contype;
|
||||
uint16_t code;
|
||||
uint32_t trans_id;
|
||||
uint32_t param[];
|
||||
};
|
||||
|
||||
struct mtp_string {
|
||||
uint8_t len;
|
||||
uint16_t string[255];
|
||||
};
|
||||
|
||||
struct mtp_device_info {
|
||||
uint16_t StandardVersion;
|
||||
uint32_t VendorExtensionID;
|
||||
uint16_t VendorExtensionVersion;
|
||||
uint8_t VendorExtensionDesc_len;
|
||||
uint16_t VendorExtensionDesc[255];
|
||||
uint16_t FunctionalMode;
|
||||
uint32_t OperationsSupported_len;
|
||||
uint16_t OperationsSupported[255];
|
||||
uint32_t EventsSupported_len;
|
||||
uint16_t EventsSupported[255];
|
||||
uint32_t DevicePropertiesSupported_len;
|
||||
uint16_t DevicePropertiesSupported[255];
|
||||
uint32_t CaptureFormats_len;
|
||||
uint16_t CaptureFormats[255];
|
||||
uint32_t ImageFormats_len;
|
||||
uint16_t ImageFormats[255];
|
||||
uint8_t Manufacturer_len;
|
||||
uint16_t Manufacturer[255];
|
||||
uint8_t Model_len;
|
||||
uint16_t Model[255];
|
||||
uint8_t DeviceVersion_len;
|
||||
uint16_t DeviceVersion[255];
|
||||
uint8_t SerialNumber_len;
|
||||
uint16_t SerialNumber[255];
|
||||
} __PACKED;
|
||||
|
||||
struct mtp_object_props_support {
|
||||
uint32_t ObjectPropCode_len;
|
||||
uint16_t ObjectPropCode[255];
|
||||
} __PACKED;
|
||||
|
||||
struct mtp_device_prop_desc {
|
||||
uint16_t DevicePropertyCode;
|
||||
uint16_t DataType;
|
||||
uint8_t GetSet;
|
||||
uint16_t DefaultValue[1];
|
||||
uint16_t CurrentValue[1];
|
||||
uint8_t FormFlag;
|
||||
} __PACKED;
|
||||
|
||||
struct mtp_storage_id {
|
||||
uint32_t StorageIDS_len;
|
||||
uint32_t StorageIDS[255];
|
||||
} __PACKED;
|
||||
|
||||
struct mtp_storage_info {
|
||||
uint16_t StorageType;
|
||||
uint16_t FilesystemType;
|
||||
uint16_t AccessCapability;
|
||||
uint64_t MaxCapability;
|
||||
uint64_t FreeSpaceInBytes;
|
||||
uint32_t FreeSpaceInObjects;
|
||||
uint8_t StorageDescription_len;
|
||||
uint8_t StorageDescription[255];
|
||||
uint8_t VolumeIdentifier_len;
|
||||
uint8_t VolumeIdentifier[255];
|
||||
} __PACKED;
|
||||
|
||||
struct mtp_object_handles {
|
||||
uint32_t ObjectHandle_len;
|
||||
uint32_t ObjectHandle[255];
|
||||
} __PACKED;
|
||||
|
||||
struct mtp_object_prop_desc {
|
||||
uint16_t ObjectPropertyCode;
|
||||
uint16_t DataType;
|
||||
uint8_t GetSet;
|
||||
uint8_t DefValue[16];
|
||||
uint32_t GroupCode;
|
||||
uint8_t FormFlag;
|
||||
} __PACKED;
|
||||
|
||||
struct mtp_object_prop_element {
|
||||
uint32_t ObjectHandle;
|
||||
uint16_t PropertyCode;
|
||||
uint16_t Datatype;
|
||||
uint8_t value[8];
|
||||
} __PACKED;
|
||||
|
||||
struct mtp_object_prop_list {
|
||||
uint32_t element_len;
|
||||
struct mtp_object_prop_element element[1];
|
||||
} __PACKED;
|
||||
|
||||
struct mtp_object_info {
|
||||
uint32_t StorageId;
|
||||
uint16_t ObjectFormat;
|
||||
uint16_t ProtectionStatus;
|
||||
uint32_t ObjectCompressedSize;
|
||||
uint16_t ThumbFormat;
|
||||
uint32_t ThumbCompressedSize;
|
||||
uint32_t ThumbPixWidth;
|
||||
uint32_t ThumbPixHeight;
|
||||
uint32_t ImagePixWidth;
|
||||
uint32_t ImagePixHeight;
|
||||
uint32_t ImageBitDepth;
|
||||
uint32_t ParentObject;
|
||||
uint16_t AssociationType;
|
||||
uint32_t AssociationDesc;
|
||||
uint32_t SequenceNumber;
|
||||
uint8_t Filename_len;
|
||||
uint16_t Filename[CONFIG_USBDEV_MTP_MAX_PATHNAME];
|
||||
uint8_t CaptureDate[6];
|
||||
uint8_t ModificationDate[6];
|
||||
} __PACKED;
|
||||
|
||||
struct mtp_object {
|
||||
uint32_t storage_id;
|
||||
uint32_t handle;
|
||||
uint32_t parent_handle;
|
||||
uint16_t format;
|
||||
bool is_dir;
|
||||
bool is_readonly;
|
||||
bool is_hidden;
|
||||
uint32_t file_size;
|
||||
uint32_t file_full_name_length;
|
||||
char file_full_name[CONFIG_USBDEV_MTP_MAX_PATHNAME];
|
||||
bool in_use;
|
||||
};
|
||||
|
||||
/*Length of template descriptor: 23 bytes*/
|
||||
#define MTP_DESCRIPTOR_LEN (9 + 7 + 7 + 7)
|
||||
|
||||
// clang-format off
|
||||
#define MTP_DESCRIPTOR_INIT(bFirstInterface, out_ep, in_ep, int_ep, wMaxPacketSize, str_idx) \
|
||||
/* Interface */ \
|
||||
0x09, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
bFirstInterface, /* bInterfaceNumber */ \
|
||||
0x00, /* bAlternateSetting */ \
|
||||
0x03, /* bNumEndpoints */ \
|
||||
USB_DEVICE_CLASS_IMAGE, /* bInterfaceClass */ \
|
||||
USB_MTP_SUB_CLASS, /* bInterfaceSubClass */ \
|
||||
USB_MTP_PROTOCOL, /* 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 */ \
|
||||
0x07, /* bLength */ \
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
|
||||
int_ep, /* bEndpointAddress */ \
|
||||
0x03, /* bmAttributes */ \
|
||||
0x1c, /* wMaxPacketSize */ \
|
||||
0x00, /* bInterval */ \
|
||||
0x06 /* bLength */
|
||||
// clang-format on
|
||||
|
||||
#endif
|
||||
62
class/mtp/usbd_mtp.h
Normal file
62
class/mtp/usbd_mtp.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2025, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USBD_MTP_H
|
||||
#define USBD_MTP_H
|
||||
|
||||
#include "usb_mtp.h"
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/* gcc toolchain does not implement dirent.h, so we define our own MTP_DIR and mtp_dirent */
|
||||
|
||||
typedef void MTP_DIR;
|
||||
|
||||
struct mtp_statfs {
|
||||
size_t f_bsize; /* block size */
|
||||
size_t f_blocks; /* total data blocks in file system */
|
||||
size_t f_bfree; /* free blocks in file system */
|
||||
};
|
||||
|
||||
struct mtp_dirent {
|
||||
uint8_t d_type; /* The type of the file */
|
||||
uint8_t d_namlen; /* The length of the not including the terminating null file name */
|
||||
uint16_t d_reclen; /* length of this record */
|
||||
char d_name[CONFIG_USBDEV_MTP_MAX_PATHNAME]; /* The null-terminated file name */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct usbd_interface *usbd_mtp_init_intf(struct usbd_interface *intf,
|
||||
const uint8_t out_ep,
|
||||
const uint8_t in_ep,
|
||||
const uint8_t int_ep);
|
||||
|
||||
const char *usbd_mtp_fs_root_path(void);
|
||||
const char *usbd_mtp_fs_description(void);
|
||||
|
||||
int usbd_mtp_mkdir(const char *path);
|
||||
int usbd_mtp_rmdir(const char *path);
|
||||
MTP_DIR *usbd_mtp_opendir(const char *name);
|
||||
int usbd_mtp_closedir(MTP_DIR *d);
|
||||
struct mtp_dirent *usbd_mtp_readdir(MTP_DIR *d);
|
||||
|
||||
int usbd_mtp_statfs(const char *path, struct mtp_statfs *buf);
|
||||
int usbd_mtp_stat(const char *file, struct stat *buf);
|
||||
|
||||
int usbd_mtp_open(const char *path, uint8_t mode);
|
||||
int usbd_mtp_close(int fd);
|
||||
int usbd_mtp_read(int fd, void *buf, size_t len);
|
||||
int usbd_mtp_write(int fd, const void *buf, size_t len);
|
||||
|
||||
int usbd_mtp_unlink(const char *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBD_MTP_H */
|
||||
312
class/mtp/usbd_mtp_support.h
Normal file
312
class/mtp/usbd_mtp_support.h
Normal file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Copyright (c) 2025, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USBD_MTP_SUPPORT_H
|
||||
#define USBD_MTP_SUPPORT_H
|
||||
|
||||
#define MTP_VERSION 100
|
||||
|
||||
typedef struct _profile_property {
|
||||
uint16_t prop_code;
|
||||
uint16_t data_type;
|
||||
uint8_t getset;
|
||||
uint64_t default_value;
|
||||
uint32_t group_code;
|
||||
uint8_t form_flag;
|
||||
uint16_t format_code;
|
||||
} profile_property;
|
||||
|
||||
typedef struct _format_property {
|
||||
uint16_t format_code;
|
||||
uint16_t *properties;
|
||||
} formats_property;
|
||||
|
||||
const char mtp_extension_string[] = "microsoft.com: 1.0; android.com: 1.0;";
|
||||
|
||||
const uint16_t supported_op[] = {
|
||||
MTP_OPERATION_GET_DEVICE_INFO, //0x1001
|
||||
MTP_OPERATION_OPEN_SESSION, //0x1002
|
||||
MTP_OPERATION_CLOSE_SESSION, //0x1003
|
||||
MTP_OPERATION_GET_STORAGE_IDS, //0x1004
|
||||
MTP_OPERATION_GET_STORAGE_INFO, //0x1005
|
||||
//MTP_OPERATION_GET_NUM_OBJECTS ,//0x1006
|
||||
MTP_OPERATION_GET_OBJECT_HANDLES, //0x1007
|
||||
MTP_OPERATION_GET_OBJECT_INFO, //0x1008
|
||||
MTP_OPERATION_GET_OBJECT, //0x1009
|
||||
//MTP_OPERATION_GET_THUMB ,//0x100A
|
||||
MTP_OPERATION_DELETE_OBJECT, //0x100B
|
||||
MTP_OPERATION_SEND_OBJECT_INFO, //0x100C
|
||||
MTP_OPERATION_SEND_OBJECT, //0x100D
|
||||
MTP_OPERATION_GET_DEVICE_PROP_DESC, //0x1014
|
||||
// MTP_OPERATION_GET_DEVICE_PROP_VALUE ,//0x1015
|
||||
// MTP_OPERATION_SET_DEVICE_PROP_VALUE ,//0x1016
|
||||
//MTP_OPERATION_RESET_DEVICE_PROP_VALUE ,//0x1017
|
||||
// MTP_OPERATION_GET_PARTIAL_OBJECT ,//0x101B
|
||||
MTP_OPERATION_GET_OBJECT_PROPS_SUPPORTED, //0x9801
|
||||
// MTP_OPERATION_GET_OBJECT_PROP_DESC, //0x9802
|
||||
// MTP_OPERATION_GET_OBJECT_PROP_VALUE ,//0x9803
|
||||
// MTP_OPERATION_SET_OBJECT_PROP_VALUE ,//0x9804
|
||||
// MTP_OPERATION_GET_OBJECT_PROP_LIST ,//0x9805
|
||||
//MTP_OPERATION_GET_OBJECT_REFERENCES ,//0x9810
|
||||
//MTP_OPERATION_SET_OBJECT_REFERENCES ,//0x9811
|
||||
// MTP_OPERATION_GET_PARTIAL_OBJECT_64 ,//0x95C1
|
||||
// MTP_OPERATION_SEND_PARTIAL_OBJECT ,//0x95C2
|
||||
// MTP_OPERATION_TRUNCATE_OBJECT ,//0x95C3
|
||||
// MTP_OPERATION_BEGIN_EDIT_OBJECT ,//0x95C4
|
||||
// MTP_OPERATION_END_EDIT_OBJECT //0x95C5
|
||||
};
|
||||
|
||||
int supported_op_size = sizeof(supported_op);
|
||||
|
||||
const uint16_t supported_event[] = {
|
||||
MTP_EVENT_OBJECT_ADDED, // 0x4002
|
||||
MTP_EVENT_OBJECT_REMOVED, // 0x4003
|
||||
MTP_EVENT_STORE_ADDED, // 0x4004
|
||||
MTP_EVENT_STORE_REMOVED, // 0x4005
|
||||
MTP_EVENT_STORAGE_INFO_CHANGED, // 0x400C
|
||||
MTP_EVENT_OBJECT_INFO_CHANGED, // 0x4007
|
||||
MTP_EVENT_DEVICE_PROP_CHANGED, // 0x4006
|
||||
MTP_EVENT_OBJECT_PROP_CHANGED // 0xC801
|
||||
};
|
||||
|
||||
int supported_event_size = sizeof(supported_event);
|
||||
|
||||
const formats_property support_format_properties[] = {
|
||||
// format code prop code
|
||||
{ MTP_FORMAT_UNDEFINED, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF } },
|
||||
{ MTP_FORMAT_ASSOCIATION, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF } }
|
||||
#if 0
|
||||
{ MTP_FORMAT_TEXT , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_HTML , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_MP4_CONTAINER, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_ARTIST, MTP_PROPERTY_ALBUM_NAME,
|
||||
MTP_PROPERTY_DURATION, MTP_PROPERTY_DESCRIPTION, MTP_PROPERTY_WIDTH, MTP_PROPERTY_HEIGHT, MTP_PROPERTY_DATE_AUTHORED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_3GP_CONTAINER, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_ARTIST, MTP_PROPERTY_ALBUM_NAME,
|
||||
MTP_PROPERTY_DURATION, MTP_PROPERTY_DESCRIPTION, MTP_PROPERTY_WIDTH, MTP_PROPERTY_HEIGHT, MTP_PROPERTY_DATE_AUTHORED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_WAV , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,MTP_PROPERTY_ARTIST,MTP_PROPERTY_ALBUM_NAME,
|
||||
MTP_PROPERTY_ALBUM_ARTIST, MTP_PROPERTY_TRACK, MTP_PROPERTY_ORIGINAL_RELEASE_DATE, MTP_PROPERTY_GENRE, MTP_PROPERTY_COMPOSER,
|
||||
MTP_PROPERTY_AUDIO_WAVE_CODEC, MTP_PROPERTY_BITRATE_TYPE, MTP_PROPERTY_AUDIO_BITRATE, MTP_PROPERTY_NUMBER_OF_CHANNELS,MTP_PROPERTY_SAMPLE_RATE,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_MP3 , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,MTP_PROPERTY_ARTIST,MTP_PROPERTY_ALBUM_NAME,
|
||||
MTP_PROPERTY_ALBUM_ARTIST, MTP_PROPERTY_TRACK, MTP_PROPERTY_ORIGINAL_RELEASE_DATE, MTP_PROPERTY_GENRE, MTP_PROPERTY_COMPOSER,
|
||||
MTP_PROPERTY_AUDIO_WAVE_CODEC, MTP_PROPERTY_BITRATE_TYPE, MTP_PROPERTY_AUDIO_BITRATE, MTP_PROPERTY_NUMBER_OF_CHANNELS,MTP_PROPERTY_SAMPLE_RATE,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_MPEG , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_ARTIST, MTP_PROPERTY_ALBUM_NAME,
|
||||
MTP_PROPERTY_DURATION, MTP_PROPERTY_DESCRIPTION, MTP_PROPERTY_WIDTH, MTP_PROPERTY_HEIGHT, MTP_PROPERTY_DATE_AUTHORED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_EXIF_JPEG , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_DESCRIPTION, MTP_PROPERTY_WIDTH,
|
||||
MTP_PROPERTY_HEIGHT, MTP_PROPERTY_DATE_AUTHORED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_BMP , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_DESCRIPTION, MTP_PROPERTY_WIDTH,
|
||||
MTP_PROPERTY_HEIGHT, MTP_PROPERTY_DATE_AUTHORED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_GIF , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_DESCRIPTION, MTP_PROPERTY_WIDTH,
|
||||
MTP_PROPERTY_HEIGHT, MTP_PROPERTY_DATE_AUTHORED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_JFIF , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_DESCRIPTION, MTP_PROPERTY_WIDTH,
|
||||
MTP_PROPERTY_HEIGHT, MTP_PROPERTY_DATE_AUTHORED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_WMA , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_ARTIST, MTP_PROPERTY_ALBUM_NAME,
|
||||
MTP_PROPERTY_ALBUM_ARTIST, MTP_PROPERTY_TRACK, MTP_PROPERTY_ORIGINAL_RELEASE_DATE, MTP_PROPERTY_DURATION, MTP_PROPERTY_DESCRIPTION,
|
||||
MTP_PROPERTY_GENRE, MTP_PROPERTY_COMPOSER, MTP_PROPERTY_AUDIO_WAVE_CODEC, MTP_PROPERTY_BITRATE_TYPE, MTP_PROPERTY_AUDIO_BITRATE,
|
||||
MTP_PROPERTY_NUMBER_OF_CHANNELS, MTP_PROPERTY_SAMPLE_RATE,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_OGG , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_ARTIST, MTP_PROPERTY_ALBUM_NAME,
|
||||
MTP_PROPERTY_ALBUM_ARTIST, MTP_PROPERTY_TRACK, MTP_PROPERTY_ORIGINAL_RELEASE_DATE, MTP_PROPERTY_DURATION, MTP_PROPERTY_DESCRIPTION,
|
||||
MTP_PROPERTY_GENRE, MTP_PROPERTY_COMPOSER, MTP_PROPERTY_AUDIO_WAVE_CODEC, MTP_PROPERTY_BITRATE_TYPE, MTP_PROPERTY_AUDIO_BITRATE,
|
||||
MTP_PROPERTY_NUMBER_OF_CHANNELS, MTP_PROPERTY_SAMPLE_RATE,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_AAC , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_ARTIST, MTP_PROPERTY_ALBUM_NAME,
|
||||
MTP_PROPERTY_ALBUM_ARTIST, MTP_PROPERTY_TRACK, MTP_PROPERTY_ORIGINAL_RELEASE_DATE, MTP_PROPERTY_DURATION, MTP_PROPERTY_DESCRIPTION,
|
||||
MTP_PROPERTY_GENRE, MTP_PROPERTY_COMPOSER, MTP_PROPERTY_AUDIO_WAVE_CODEC, MTP_PROPERTY_BITRATE_TYPE, MTP_PROPERTY_AUDIO_BITRATE,
|
||||
MTP_PROPERTY_NUMBER_OF_CHANNELS, MTP_PROPERTY_SAMPLE_RATE,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_ABSTRACT_AV_PLAYLIST, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_WPL_PLAYLIST, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_M3U_PLAYLIST, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_PLS_PLAYLIST, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_XML_DOCUMENT, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_FLAC , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_AVI , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_ARTIST, MTP_PROPERTY_ALBUM_NAME,
|
||||
MTP_PROPERTY_DURATION, MTP_PROPERTY_DESCRIPTION, MTP_PROPERTY_WIDTH, MTP_PROPERTY_HEIGHT, MTP_PROPERTY_DATE_AUTHORED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_ASF , (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED, MTP_PROPERTY_ARTIST, MTP_PROPERTY_ALBUM_NAME,
|
||||
MTP_PROPERTY_DURATION, MTP_PROPERTY_DESCRIPTION, MTP_PROPERTY_WIDTH, MTP_PROPERTY_HEIGHT, MTP_PROPERTY_DATE_AUTHORED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_MS_WORD_DOCUMENT, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_MS_EXCEL_SPREADSHEET, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
},
|
||||
{ MTP_FORMAT_MS_POWERPOINT_PRESENTATION, (uint16_t[]){ MTP_PROPERTY_STORAGE_ID, MTP_PROPERTY_OBJECT_FORMAT, MTP_PROPERTY_PROTECTION_STATUS, MTP_PROPERTY_OBJECT_SIZE,
|
||||
MTP_PROPERTY_OBJECT_FILE_NAME, MTP_PROPERTY_DATE_MODIFIED, MTP_PROPERTY_PARENT_OBJECT, MTP_PROPERTY_PERSISTENT_UID,
|
||||
MTP_PROPERTY_NAME, MTP_PROPERTY_DISPLAY_NAME, MTP_PROPERTY_DATE_CREATED,
|
||||
0xFFFF}
|
||||
}
|
||||
#endif
|
||||
,
|
||||
|
||||
{ 0xFFFF, (uint16_t[]){ 0xFFFF } }
|
||||
|
||||
};
|
||||
|
||||
const profile_property support_object_properties[] = {
|
||||
// prop_code data_type getset default_value group_code form_flag format_code
|
||||
{ MTP_PROPERTY_STORAGE_ID, MTP_TYPE_UINT32, 0x00, 0x00000000, 0x000000001, 0x00, 0xFFFF },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_UNDEFINED, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_ASSOCIATION, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_TEXT, 0x000000000, 0x00, MTP_FORMAT_TEXT },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_HTML, 0x000000000, 0x00, MTP_FORMAT_HTML },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_WAV, 0x000000000, 0x00, MTP_FORMAT_WAV },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_MP3, 0x000000000, 0x00, MTP_FORMAT_MP3 },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_MPEG, 0x000000000, 0x00, MTP_FORMAT_MPEG },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_EXIF_JPEG, 0x000000000, 0x00, MTP_FORMAT_EXIF_JPEG },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_BMP, 0x000000000, 0x00, MTP_FORMAT_BMP },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_AIFF, 0x000000000, 0x00, MTP_FORMAT_AIFF },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_MPEG, 0x000000000, 0x00, MTP_FORMAT_MPEG },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_WMA, 0x000000000, 0x00, MTP_FORMAT_WMA },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_OGG, 0x000000000, 0x00, MTP_FORMAT_OGG },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_AAC, 0x000000000, 0x00, MTP_FORMAT_AAC },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_MP4_CONTAINER, 0x000000000, 0x00, MTP_FORMAT_MP4_CONTAINER },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_3GP_CONTAINER, 0x000000000, 0x00, MTP_FORMAT_3GP_CONTAINER },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_ABSTRACT_AV_PLAYLIST, 0x000000000, 0x00, MTP_FORMAT_ABSTRACT_AV_PLAYLIST },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_WPL_PLAYLIST, 0x000000000, 0x00, MTP_FORMAT_WPL_PLAYLIST },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_M3U_PLAYLIST, 0x000000000, 0x00, MTP_FORMAT_M3U_PLAYLIST },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_PLS_PLAYLIST, 0x000000000, 0x00, MTP_FORMAT_PLS_PLAYLIST },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_XML_DOCUMENT, 0x000000000, 0x00, MTP_FORMAT_XML_DOCUMENT },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_FLAC, 0x000000000, 0x00, MTP_FORMAT_FLAC },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_AVI, 0x000000000, 0x00, MTP_FORMAT_AVI },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_ASF, 0x000000000, 0x00, MTP_FORMAT_ASF },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_MS_WORD_DOCUMENT, 0x000000000, 0x00, MTP_FORMAT_MS_WORD_DOCUMENT },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_MS_EXCEL_SPREADSHEET, 0x000000000, 0x00, MTP_FORMAT_MS_EXCEL_SPREADSHEET },
|
||||
{ MTP_PROPERTY_OBJECT_FORMAT, MTP_TYPE_UINT16, 0x00, MTP_FORMAT_MS_POWERPOINT_PRESENTATION, 0x000000000, 0x00, MTP_FORMAT_MS_POWERPOINT_PRESENTATION },
|
||||
|
||||
{ MTP_PROPERTY_OBJECT_SIZE, MTP_TYPE_UINT64, 0x00, 0x0000000000000000, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
{ MTP_PROPERTY_STORAGE_ID, MTP_TYPE_UINT32, 0x00, 0x00000000, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
{ MTP_PROPERTY_PROTECTION_STATUS, MTP_TYPE_UINT16, 0x00, 0x0000, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
{ MTP_PROPERTY_DISPLAY_NAME, MTP_TYPE_STR, 0x00, 0x0000, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
{ MTP_PROPERTY_OBJECT_FILE_NAME, MTP_TYPE_STR, 0x01, 0x0000, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
{ MTP_PROPERTY_DATE_CREATED, MTP_TYPE_STR, 0x00, 0x00, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
{ MTP_PROPERTY_DATE_MODIFIED, MTP_TYPE_STR, 0x00, 0x00, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
{ MTP_PROPERTY_PARENT_OBJECT, MTP_TYPE_UINT32, 0x00, 0x00000000, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
{ MTP_PROPERTY_PERSISTENT_UID, MTP_TYPE_UINT128, 0x00, 0x00, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
{ MTP_PROPERTY_NAME, MTP_TYPE_STR, 0x00, 0x00, 0x000000000, 0x00, MTP_FORMAT_ASSOCIATION },
|
||||
|
||||
{ MTP_PROPERTY_OBJECT_SIZE, MTP_TYPE_UINT64, 0x00, 0x0000000000000000, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
{ MTP_PROPERTY_STORAGE_ID, MTP_TYPE_UINT32, 0x00, 0x00000000, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
{ MTP_PROPERTY_PROTECTION_STATUS, MTP_TYPE_UINT16, 0x00, 0x0000, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
{ MTP_PROPERTY_DISPLAY_NAME, MTP_TYPE_STR, 0x00, 0x0000, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
{ MTP_PROPERTY_OBJECT_FILE_NAME, MTP_TYPE_STR, 0x01, 0x0000, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
{ MTP_PROPERTY_DATE_CREATED, MTP_TYPE_STR, 0x00, 0x00, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
{ MTP_PROPERTY_DATE_MODIFIED, MTP_TYPE_STR, 0x00, 0x00, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
{ MTP_PROPERTY_PARENT_OBJECT, MTP_TYPE_UINT32, 0x00, 0x00000000, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
{ MTP_PROPERTY_PERSISTENT_UID, MTP_TYPE_UINT128, 0x00, 0x00, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
{ MTP_PROPERTY_NAME, MTP_TYPE_STR, 0x00, 0x00, 0x000000000, 0x00, MTP_FORMAT_UNDEFINED },
|
||||
|
||||
//{MTP_PROPERTY_ASSOCIATION_TYPE, MTP_TYPE_UINT16, 0x00, 0x0001 , 0x000000000 , 0x00 , 0xFFFF },
|
||||
{ MTP_PROPERTY_ASSOCIATION_DESC, MTP_TYPE_UINT32, 0x00, 0x00000000, 0x000000000, 0x00, 0xFFFF },
|
||||
{ MTP_PROPERTY_PROTECTION_STATUS, MTP_TYPE_UINT16, 0x00, 0x0000, 0x000000000, 0x00, 0xFFFF },
|
||||
{ MTP_PROPERTY_HIDDEN, MTP_TYPE_UINT16, 0x00, 0x0000, 0x000000000, 0x00, 0xFFFF },
|
||||
|
||||
{ 0xFFFF, MTP_TYPE_UINT32, 0x00, 0x00000000, 0x000000000, 0x00 }
|
||||
};
|
||||
|
||||
const profile_property support_device_properties[] = {
|
||||
// prop_code data_type getset default_value group_code form_flag
|
||||
//{MTP_DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER, MTP_TYPE_UINT32, 0x00, 0x00000000 , 0x000000000 , 0x00 },
|
||||
//{MTP_DEVICE_PROPERTY_IMAGE_SIZE, MTP_TYPE_UINT32, 0x00, 0x00000000 , 0x000000000 , 0x00 },
|
||||
{ MTP_DEVICE_PROPERTY_BATTERY_LEVEL, MTP_TYPE_UINT16, 0x00, 0x00000000, 0x000000000, 0x00 },
|
||||
{ MTP_DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME, MTP_TYPE_STR, 0x00, 0x00000000, 0x000000000, 0x00 },
|
||||
|
||||
{ 0xFFFF, MTP_TYPE_UINT32, 0x00, 0x00000000, 0x000000000, 0x00 }
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -89,9 +89,9 @@ static const struct usbh_class_driver xxx_class_driver = {
|
||||
|
||||
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,
|
||||
.bInterfaceClass = 0,
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.id_table = NULL,
|
||||
.class_driver = &xxx_class_driver
|
||||
};
|
||||
|
||||
22
class/vendor/net/usbh_asix.c
vendored
22
class/vendor/net/usbh_asix.c
vendored
@@ -15,10 +15,11 @@
|
||||
|
||||
static struct usbh_asix g_asix_class;
|
||||
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_rx_buffer[CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_tx_buffer[CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_inttx_buffer[16];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_buf[32];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_rx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_tx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_inttx_buffer[USB_ALIGN_UP(16, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_buf[USB_ALIGN_UP(32, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
#define ETH_ALEN 6
|
||||
|
||||
@@ -73,7 +74,7 @@ static int usbh_asix_read_cmd(struct usbh_asix *asix_class,
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(data, g_asix_buf, ret - 8);
|
||||
memcpy(data, g_asix_buf, MIN(ret - 8, size));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -637,6 +638,7 @@ static int usbh_asix_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister ASIX Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_asix_stop(asix_class);
|
||||
}
|
||||
@@ -670,7 +672,7 @@ int usbh_asix_get_connect_status(struct usbh_asix *asix_class)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usbh_asix_rx_thread(void *argument)
|
||||
void usbh_asix_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
uint32_t g_asix_rx_length;
|
||||
int ret;
|
||||
@@ -683,7 +685,7 @@ void usbh_asix_rx_thread(void *argument)
|
||||
uint32_t transfer_size = (16 * 1024);
|
||||
#endif
|
||||
|
||||
(void)argument;
|
||||
(void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
|
||||
USB_LOG_INFO("Create asix rx thread\r\n");
|
||||
// clang-format off
|
||||
find_class:
|
||||
@@ -817,9 +819,9 @@ static const struct usbh_class_driver asix_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info asix_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = asix_id_table,
|
||||
.class_driver = &asix_class_driver
|
||||
};
|
||||
2
class/vendor/net/usbh_asix.h
vendored
2
class/vendor/net/usbh_asix.h
vendored
@@ -168,7 +168,7 @@ void usbh_asix_stop(struct usbh_asix *asix_class);
|
||||
uint8_t *usbh_asix_get_eth_txbuf(void);
|
||||
int usbh_asix_eth_output(uint32_t buflen);
|
||||
void usbh_asix_eth_input(uint8_t *buf, uint32_t buflen);
|
||||
void usbh_asix_rx_thread(void *argument);
|
||||
void usbh_asix_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
24
class/vendor/net/usbh_rtl8152.c
vendored
24
class/vendor/net/usbh_rtl8152.c
vendored
@@ -12,10 +12,11 @@
|
||||
|
||||
#define DEV_FORMAT "/dev/rtl8152"
|
||||
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_rx_buffer[CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_tx_buffer[CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_inttx_buffer[2];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_buf[32];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_rx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_tx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_inttx_buffer[USB_ALIGN_UP(2, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_buf[USB_ALIGN_UP(32, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static struct usbh_rtl8152 g_rtl8152_class;
|
||||
|
||||
@@ -964,7 +965,7 @@ static int usbh_rtl8152_read_regs(struct usbh_rtl8152 *rtl8152_class,
|
||||
if (ret < 8) {
|
||||
return ret;
|
||||
}
|
||||
memcpy(data, g_rtl8152_buf, ret - 8);
|
||||
memcpy(data, g_rtl8152_buf, MIN(ret - 8, size));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -2044,7 +2045,7 @@ static int usbh_rtl8152_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
rtl8152_class->rtl_ops.up(rtl8152_class);
|
||||
|
||||
if (rtl8152_class->rx_buf_sz > CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE) {
|
||||
USB_LOG_ERR("rx_buf_sz is overflow, default is %d\r\n", CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE);
|
||||
USB_LOG_ERR("rx_buf_sz is overflow, default is %d\r\n", (unsigned int)CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE);
|
||||
return -USB_ERR_NOMEM;
|
||||
}
|
||||
|
||||
@@ -2120,6 +2121,7 @@ static int usbh_rtl8152_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister rtl8152 Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_rtl8152_stop(rtl8152_class);
|
||||
}
|
||||
@@ -2130,7 +2132,7 @@ static int usbh_rtl8152_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void usbh_rtl8152_rx_thread(void *argument)
|
||||
void usbh_rtl8152_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
uint32_t g_rtl8152_rx_length;
|
||||
int ret;
|
||||
@@ -2142,7 +2144,7 @@ void usbh_rtl8152_rx_thread(void *argument)
|
||||
uint32_t transfer_size = (16 * 1024);
|
||||
#endif
|
||||
|
||||
(void)argument;
|
||||
(void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
|
||||
USB_LOG_INFO("Create rtl8152 rx thread\r\n");
|
||||
// clang-format off
|
||||
find_class:
|
||||
@@ -2272,9 +2274,9 @@ static const struct usbh_class_driver rtl8152_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info rtl8152_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = rtl_id_table,
|
||||
.class_driver = &rtl8152_class_driver
|
||||
};
|
||||
|
||||
2
class/vendor/net/usbh_rtl8152.h
vendored
2
class/vendor/net/usbh_rtl8152.h
vendored
@@ -59,7 +59,7 @@ void usbh_rtl8152_stop(struct usbh_rtl8152 *rtl8152_class);
|
||||
uint8_t *usbh_rtl8152_get_eth_txbuf(void);
|
||||
int usbh_rtl8152_eth_output(uint32_t buflen);
|
||||
void usbh_rtl8152_eth_input(uint8_t *buf, uint32_t buflen);
|
||||
void usbh_rtl8152_rx_thread(void *argument);
|
||||
void usbh_rtl8152_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
9
class/vendor/serial/usbh_ch34x.c
vendored
9
class/vendor/serial/usbh_ch34x.c
vendored
@@ -8,7 +8,7 @@
|
||||
|
||||
#define DEV_FORMAT "/dev/ttyUSB%d"
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_ch34x_buf[64];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_ch34x_buf[USB_ALIGN_UP(64, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
#define CONFIG_USBHOST_MAX_CP210X_CLASS 1
|
||||
|
||||
@@ -311,6 +311,7 @@ static int usbh_ch34x_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister CH34X Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_ch34x_stop(ch34x_class);
|
||||
}
|
||||
@@ -370,9 +371,9 @@ const struct usbh_class_driver ch34x_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info ch34x_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = ch34x_id_table,
|
||||
.class_driver = &ch34x_class_driver
|
||||
};
|
||||
9
class/vendor/serial/usbh_cp210x.c
vendored
9
class/vendor/serial/usbh_cp210x.c
vendored
@@ -8,7 +8,7 @@
|
||||
|
||||
#define DEV_FORMAT "/dev/ttyUSB%d"
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cp210x_buf[64];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_cp210x_buf[USB_ALIGN_UP(64, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
#define CONFIG_USBHOST_MAX_CP210X_CLASS 1
|
||||
|
||||
@@ -260,6 +260,7 @@ static int usbh_cp210x_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister CP210X Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_cp210x_stop(cp210x_class);
|
||||
}
|
||||
@@ -319,9 +320,9 @@ const struct usbh_class_driver cp210x_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info cp210x_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = cp210x_id_table,
|
||||
.class_driver = &cp210x_class_driver
|
||||
};
|
||||
179
class/vendor/serial/usbh_ftdi.c
vendored
179
class/vendor/serial/usbh_ftdi.c
vendored
@@ -8,13 +8,32 @@
|
||||
|
||||
#define DEV_FORMAT "/dev/ttyUSB%d"
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_ftdi_buf[64];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_ftdi_buf[USB_ALIGN_UP(64, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
#define CONFIG_USBHOST_MAX_FTDI_CLASS 1
|
||||
|
||||
static struct usbh_ftdi g_ftdi_class[CONFIG_USBHOST_MAX_FTDI_CLASS];
|
||||
static uint32_t g_devinuse = 0;
|
||||
|
||||
static const char *ftdi_chip_name[] = {
|
||||
[SIO] = "SIO", /* the serial part of FT8U100AX */
|
||||
[FT232A] = "FT232A",
|
||||
[FT232B] = "FT232B",
|
||||
[FT2232C] = "FT2232C/D",
|
||||
[FT232R] = "FT232R",
|
||||
[FT232H] = "FT232H",
|
||||
[FT2232H] = "FT2232H",
|
||||
[FT4232H] = "FT4232H",
|
||||
[FT4232HA] = "FT4232HA",
|
||||
[FT232HP] = "FT232HP",
|
||||
[FT233HP] = "FT233HP",
|
||||
[FT2232HP] = "FT2232HP",
|
||||
[FT2233HP] = "FT2233HP",
|
||||
[FT4232HP] = "FT4232HP",
|
||||
[FT4233HP] = "FT4233HP",
|
||||
[FTX] = "FT-X",
|
||||
};
|
||||
|
||||
static struct usbh_ftdi *usbh_ftdi_class_alloc(void)
|
||||
{
|
||||
uint8_t devno;
|
||||
@@ -40,33 +59,72 @@ static void usbh_ftdi_class_free(struct usbh_ftdi *ftdi_class)
|
||||
memset(ftdi_class, 0, sizeof(struct usbh_ftdi));
|
||||
}
|
||||
|
||||
static void usbh_ftdi_caculate_baudrate(uint32_t *itdf_divisor, uint32_t actual_baudrate)
|
||||
{
|
||||
#define FTDI_USB_CLK 48000000
|
||||
int baudrate;
|
||||
uint8_t frac[] = { 0, 8, 4, 2, 6, 10, 12, 14 };
|
||||
/*
|
||||
* Divide positive or negative dividend by positive or negative divisor
|
||||
* and round to closest integer. Result is undefined for negative
|
||||
* divisors if the dividend variable type is unsigned and for negative
|
||||
* dividends if the divisor variable type is unsigned.
|
||||
*/
|
||||
#define DIV_ROUND_CLOSEST(x, divisor) ( \
|
||||
{ \
|
||||
typeof(x) __x = x; \
|
||||
typeof(divisor) __d = divisor; \
|
||||
(((typeof(x))-1) > 0 || \
|
||||
((typeof(divisor))-1) > 0 || \
|
||||
(((__x) > 0) == ((__d) > 0))) ? \
|
||||
(((__x) + ((__d) / 2)) / (__d)) : \
|
||||
(((__x) - ((__d) / 2)) / (__d)); \
|
||||
})
|
||||
|
||||
if (actual_baudrate == 2000000) {
|
||||
*itdf_divisor = 0x01;
|
||||
} else if (actual_baudrate == 3000000) {
|
||||
*itdf_divisor = 0x00;
|
||||
} else {
|
||||
baudrate = actual_baudrate;
|
||||
if (baudrate > 100000 && baudrate < 12000000) {
|
||||
baudrate = (baudrate / 100000) + 100000;
|
||||
}
|
||||
int divisor = FTDI_USB_CLK / baudrate;
|
||||
int frac_bits = 0;
|
||||
for (uint8_t i = 0; i < sizeof(frac) / sizeof(frac[0]); i++) {
|
||||
if ((divisor & 0xF) == frac[i]) {
|
||||
frac_bits = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
divisor >>= 4;
|
||||
divisor &= 0x3FFF;
|
||||
*itdf_divisor = (divisor << 14) | (frac_bits << 8);
|
||||
}
|
||||
static uint32_t ftdi_232bm_baud_base_to_divisor(uint32_t baud, int base)
|
||||
{
|
||||
static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
|
||||
uint32_t divisor;
|
||||
/* divisor shifted 3 bits to the left */
|
||||
int divisor3 = DIV_ROUND_CLOSEST(base, 2 * baud);
|
||||
divisor = divisor3 >> 3;
|
||||
divisor |= (uint32_t)divfrac[divisor3 & 0x7] << 14;
|
||||
/* Deal with special cases for highest baud rates. */
|
||||
if (divisor == 1) /* 1.0 */
|
||||
divisor = 0;
|
||||
else if (divisor == 0x4001) /* 1.5 */
|
||||
divisor = 1;
|
||||
return divisor;
|
||||
}
|
||||
|
||||
static uint32_t ftdi_232bm_baud_to_divisor(uint32_t baud)
|
||||
{
|
||||
return ftdi_232bm_baud_base_to_divisor(baud, 48000000);
|
||||
}
|
||||
|
||||
static uint32_t ftdi_2232h_baud_base_to_divisor(uint32_t baud, int base)
|
||||
{
|
||||
static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
|
||||
uint32_t divisor;
|
||||
int divisor3;
|
||||
|
||||
/* hi-speed baud rate is 10-bit sampling instead of 16-bit */
|
||||
divisor3 = DIV_ROUND_CLOSEST(8 * base, 10 * baud);
|
||||
|
||||
divisor = divisor3 >> 3;
|
||||
divisor |= (uint32_t)divfrac[divisor3 & 0x7] << 14;
|
||||
/* Deal with special cases for highest baud rates. */
|
||||
if (divisor == 1) /* 1.0 */
|
||||
divisor = 0;
|
||||
else if (divisor == 0x4001) /* 1.5 */
|
||||
divisor = 1;
|
||||
/*
|
||||
* Set this bit to turn off a divide by 2.5 on baud rate generator
|
||||
* This enables baud rates up to 12Mbaud but cannot reach below 1200
|
||||
* baud with this bit set
|
||||
*/
|
||||
divisor |= 0x00020000;
|
||||
return divisor;
|
||||
}
|
||||
|
||||
static uint32_t ftdi_2232h_baud_to_divisor(uint32_t baud)
|
||||
{
|
||||
return ftdi_2232h_baud_base_to_divisor(baud, 120000000);
|
||||
}
|
||||
|
||||
int usbh_ftdi_reset(struct usbh_ftdi *ftdi_class)
|
||||
@@ -108,7 +166,7 @@ static int usbh_ftdi_set_modem(struct usbh_ftdi *ftdi_class, uint16_t value)
|
||||
static int usbh_ftdi_set_baudrate(struct usbh_ftdi *ftdi_class, uint32_t baudrate)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
uint32_t itdf_divisor;
|
||||
uint32_t div_value;
|
||||
uint16_t value;
|
||||
uint8_t baudrate_high;
|
||||
|
||||
@@ -117,9 +175,26 @@ static int usbh_ftdi_set_baudrate(struct usbh_ftdi *ftdi_class, uint32_t baudrat
|
||||
}
|
||||
setup = ftdi_class->hport->setup;
|
||||
|
||||
usbh_ftdi_caculate_baudrate(&itdf_divisor, baudrate);
|
||||
value = itdf_divisor & 0xFFFF;
|
||||
baudrate_high = (itdf_divisor >> 16) & 0xff;
|
||||
switch (ftdi_class->chip_type) {
|
||||
case FT232B:
|
||||
case FT2232C:
|
||||
case FT232R:
|
||||
if (baudrate > 3000000) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
div_value = ftdi_232bm_baud_to_divisor(baudrate);
|
||||
break;
|
||||
default:
|
||||
if ((baudrate <= 12000000) && (baudrate >= 1200)) {
|
||||
div_value = ftdi_2232h_baud_to_divisor(baudrate);
|
||||
} else {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
value = div_value & 0xFFFF;
|
||||
baudrate_high = (div_value >> 16) & 0xff;
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
||||
setup->bRequest = SIO_SET_BAUDRATE_REQUEST;
|
||||
@@ -220,7 +295,11 @@ static int usbh_ftdi_read_modem_status(struct usbh_ftdi *ftdi_class)
|
||||
int usbh_ftdi_set_line_coding(struct usbh_ftdi *ftdi_class, struct cdc_line_coding *line_coding)
|
||||
{
|
||||
memcpy((uint8_t *)&ftdi_class->line_coding, line_coding, sizeof(struct cdc_line_coding));
|
||||
usbh_ftdi_set_baudrate(ftdi_class, line_coding->dwDTERate);
|
||||
|
||||
int ret = usbh_ftdi_set_baudrate(ftdi_class, line_coding->dwDTERate);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
return usbh_ftdi_set_data_format(ftdi_class, line_coding->bDataBits, line_coding->bParityType, line_coding->bCharFormat, 0);
|
||||
}
|
||||
|
||||
@@ -253,6 +332,7 @@ static int usbh_ftdi_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
int ret = 0;
|
||||
uint16_t version;
|
||||
|
||||
struct usbh_ftdi *ftdi_class = usbh_ftdi_class_alloc();
|
||||
if (ftdi_class == NULL) {
|
||||
@@ -265,6 +345,34 @@ static int usbh_ftdi_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
|
||||
hport->config.intf[intf].priv = ftdi_class;
|
||||
|
||||
version = hport->device_desc.bcdDevice;
|
||||
|
||||
switch (version) {
|
||||
case 0x400:
|
||||
ftdi_class->chip_type = FT232B;
|
||||
case 0x500:
|
||||
ftdi_class->chip_type = FT2232C;
|
||||
break;
|
||||
case 0x600:
|
||||
ftdi_class->chip_type = FT232R;
|
||||
break;
|
||||
case 0x700:
|
||||
ftdi_class->chip_type = FT2232H;
|
||||
break;
|
||||
case 0x800:
|
||||
ftdi_class->chip_type = FT4232H;
|
||||
break;
|
||||
case 0x900:
|
||||
ftdi_class->chip_type = FT232H;
|
||||
break;
|
||||
|
||||
default:
|
||||
USB_LOG_ERR("Unknown FTDI chip version:%04x\r\n", version);
|
||||
return -USB_ERR_NOTSUPP;
|
||||
}
|
||||
|
||||
USB_LOG_INFO("FTDI chip name:%s\r\n", ftdi_chip_name[ftdi_class->chip_type]);
|
||||
|
||||
usbh_ftdi_reset(ftdi_class);
|
||||
usbh_ftdi_set_flow_ctrl(ftdi_class, SIO_DISABLE_FLOW_CTRL);
|
||||
usbh_ftdi_set_latency_timer(ftdi_class, 0x10);
|
||||
@@ -332,6 +440,7 @@ static int usbh_ftdi_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister FTDI Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_ftdi_stop(ftdi_class);
|
||||
}
|
||||
@@ -392,9 +501,9 @@ const struct usbh_class_driver ftdi_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info ftdi_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = ftdi_id_table,
|
||||
.class_driver = &ftdi_class_driver
|
||||
};
|
||||
20
class/vendor/serial/usbh_ftdi.h
vendored
20
class/vendor/serial/usbh_ftdi.h
vendored
@@ -39,6 +39,25 @@
|
||||
|
||||
#define SIO_RTS_CTS_HS (0x1 << 8)
|
||||
|
||||
enum ftdi_chip_type {
|
||||
SIO,
|
||||
FT232A,
|
||||
FT232B,
|
||||
FT2232C,
|
||||
FT232R,
|
||||
FT232H,
|
||||
FT2232H,
|
||||
FT4232H,
|
||||
FT4232HA,
|
||||
FT232HP,
|
||||
FT233HP,
|
||||
FT2232HP,
|
||||
FT2233HP,
|
||||
FT4232HP,
|
||||
FT4233HP,
|
||||
FTX,
|
||||
};
|
||||
|
||||
struct usbh_ftdi {
|
||||
struct usbh_hubport *hport;
|
||||
struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
|
||||
@@ -51,6 +70,7 @@ struct usbh_ftdi {
|
||||
uint8_t intf;
|
||||
uint8_t minor;
|
||||
uint8_t modem_status[2];
|
||||
enum ftdi_chip_type chip_type;
|
||||
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
9
class/vendor/serial/usbh_pl2303.c
vendored
9
class/vendor/serial/usbh_pl2303.c
vendored
@@ -13,7 +13,7 @@
|
||||
|
||||
#define DEV_FORMAT "/dev/ttyUSB%d"
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_pl2303_buf[64];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_pl2303_buf[USB_ALIGN_UP(64, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
#define CONFIG_USBHOST_MAX_PL2303_CLASS 1
|
||||
|
||||
@@ -375,6 +375,7 @@ static int usbh_pl2303_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister PL2303 Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_pl2303_stop(pl2303_class);
|
||||
}
|
||||
@@ -440,9 +441,9 @@ const struct usbh_class_driver pl2303_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info pl2303_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = pl2303_id_table,
|
||||
.class_driver = &pl2303_class_driver
|
||||
};
|
||||
11
class/vendor/wifi/usbh_bl616.c
vendored
11
class/vendor/wifi/usbh_bl616.c
vendored
@@ -337,6 +337,7 @@ static int usbh_bl616_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister BL616 WIFI Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_bl616_stop(bl616_class);
|
||||
}
|
||||
@@ -347,7 +348,7 @@ static int usbh_bl616_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void usbh_bl616_rx_thread(void *argument)
|
||||
void usbh_bl616_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
int ret;
|
||||
usb_data_t *usb_hdr;
|
||||
@@ -356,7 +357,7 @@ void usbh_bl616_rx_thread(void *argument)
|
||||
rnm_scan_ind_msg_t *scanmsg;
|
||||
uint8_t *data;
|
||||
|
||||
(void)argument;
|
||||
(void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
|
||||
USB_LOG_INFO("Create bl616 wifi rx thread\r\n");
|
||||
|
||||
while (1) {
|
||||
@@ -504,9 +505,9 @@ static const struct usbh_class_driver bl616_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info bl616_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = bl616_id_table,
|
||||
.class_driver = &bl616_class_driver
|
||||
};
|
||||
|
||||
2
class/vendor/wifi/usbh_bl616.h
vendored
2
class/vendor/wifi/usbh_bl616.h
vendored
@@ -205,7 +205,7 @@ void usbh_bl616_sta_update_ip(uint8_t ip4_addr[4], uint8_t ip4_mask[4], uint8_t
|
||||
uint8_t *usbh_bl616_get_eth_txbuf(void);
|
||||
int usbh_bl616_eth_output(uint32_t buflen);
|
||||
void usbh_bl616_eth_input(uint8_t *buf, uint32_t buflen);
|
||||
void usbh_bl616_rx_thread(void *argument);
|
||||
void usbh_bl616_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
|
||||
void usbh_bl616_run(struct usbh_bl616 *bl616_class);
|
||||
void usbh_bl616_stop(struct usbh_bl616 *bl616_class);
|
||||
|
||||
7
class/vendor/xbox/usbh_xbox.c
vendored
7
class/vendor/xbox/usbh_xbox.c
vendored
@@ -86,6 +86,7 @@ int usbh_xbox_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister XBOX Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_xbox_stop(xbox_class);
|
||||
}
|
||||
@@ -220,9 +221,9 @@ static const uint16_t xbox_id_table[][2] = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info xbox_custom_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_VEND_SPECIFIC,
|
||||
.subclass = 0x5d,
|
||||
.protocol = 0x01,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_VEND_SPECIFIC,
|
||||
.bInterfaceSubClass = 0x5d,
|
||||
.bInterfaceProtocol = 0x01,
|
||||
.id_table = xbox_id_table,
|
||||
.class_driver = &xbox_class_driver
|
||||
};
|
||||
|
||||
@@ -1237,7 +1237,7 @@ struct video_autoexposure_mode {
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType : INTERFACE */ \
|
||||
bInterfaceNumber, /* bInterfaceNumber: Index of this interface */ \
|
||||
bAlternateSetting, /* bAlternateSetting: Index of this alternate setting */ \
|
||||
bNumEndpoints, /* bNumEndpoints : 0 endpoints – no bandwidth used*/ \
|
||||
bNumEndpoints, /* bNumEndpoints : 0 endpoints, no bandwidth used*/ \
|
||||
0x0e, /* bInterfaceClass : CC_VIDEO */ \
|
||||
0x02, /* bInterfaceSubClass : SC_VIDEOSTREAMING */ \
|
||||
0x00, /* bInterfaceProtocol : PC_PROTOCOL_UNDEFINED */ \
|
||||
@@ -1315,8 +1315,8 @@ struct video_autoexposure_mode {
|
||||
bNumFrameDescriptors, /* bNumFrameDescriptors : One frame descriptor for this format follows. */ \
|
||||
0x00, /* bmFlags : Uses fixed size samples.. */ \
|
||||
0x01, /* bDefaultFrameIndex : Default frame index is 1. */ \
|
||||
0x00, /* bAspectRatioX : Non-interlaced stream – not required. */ \
|
||||
0x00, /* bAspectRatioY : Non-interlaced stream – not required. */ \
|
||||
0x00, /* bAspectRatioX : Non-interlaced stream, not required. */ \
|
||||
0x00, /* bAspectRatioY : Non-interlaced stream, not required. */ \
|
||||
0x00, /* bmInterlaceFlags : Non-interlaced stream */ \
|
||||
0x00 /* bCopyProtect : No restrictions imposed on the duplication of this video stream. */
|
||||
|
||||
@@ -1346,8 +1346,8 @@ struct video_autoexposure_mode {
|
||||
VIDEO_GUID_H264, \
|
||||
0x00, /* bmFlags : Uses fixed size samples.. */ \
|
||||
0x01, /* bDefaultFrameIndex : Default frame index is 1. */ \
|
||||
0x00, /* bAspectRatioX : Non-interlaced stream – not required. */ \
|
||||
0x00, /* bAspectRatioY : Non-interlaced stream – not required. */ \
|
||||
0x00, /* bAspectRatioX : Non-interlaced stream, not required. */ \
|
||||
0x00, /* bAspectRatioY : Non-interlaced stream, not required. */ \
|
||||
0x00, /* bmInterlaceFlags : Non-interlaced stream */ \
|
||||
0x00, /* bCopyProtect : No restrictions imposed on the duplication of this video stream. */ \
|
||||
0x00 /* Variable size: False */
|
||||
|
||||
@@ -18,10 +18,14 @@ struct usbd_video_priv {
|
||||
uint8_t power_mode;
|
||||
uint8_t error_code;
|
||||
struct video_entity_info info[3];
|
||||
uint8_t *ep_buffer;
|
||||
uint8_t *ep_buf;
|
||||
bool stream_finish;
|
||||
uint8_t *stream_buf;
|
||||
uint32_t stream_len;
|
||||
uint32_t stream_offset;
|
||||
uint8_t stream_frameid;
|
||||
uint32_t stream_headerlen;
|
||||
bool do_copy;
|
||||
} g_usbd_video[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
static int usbd_video_control_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
@@ -741,6 +745,9 @@ static void usbd_video_probe_and_commit_controls_init(uint8_t busid, uint32_t dw
|
||||
g_usbd_video[busid].commit.bPreferedVersion = 0;
|
||||
g_usbd_video[busid].commit.bMinVersion = 0;
|
||||
g_usbd_video[busid].commit.bMaxVersion = 0;
|
||||
|
||||
g_usbd_video[busid].stream_frameid = 0;
|
||||
g_usbd_video[busid].stream_headerlen = 12;
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_video_init_intf(uint8_t busid,
|
||||
@@ -770,76 +777,99 @@ struct usbd_interface *usbd_video_init_intf(uint8_t busid,
|
||||
|
||||
bool usbd_video_stream_split_transfer(uint8_t busid, uint8_t ep)
|
||||
{
|
||||
struct video_payload_header *header = (struct video_payload_header *)g_usbd_video[busid].ep_buffer;
|
||||
uint32_t remain;
|
||||
uint32_t len;
|
||||
struct video_payload_header *header;
|
||||
static uint32_t offset = 0;
|
||||
static uint32_t len = 0;
|
||||
|
||||
remain = g_usbd_video[busid].stream_len - g_usbd_video[busid].stream_offset;
|
||||
|
||||
if (remain == 0) {
|
||||
if (g_usbd_video[busid].stream_finish) {
|
||||
g_usbd_video[busid].stream_finish = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
header->bHeaderLength = 2;
|
||||
header->headerInfoUnion.headerInfoBits.endOfHeader = 1;
|
||||
offset = g_usbd_video[busid].stream_offset;
|
||||
|
||||
len = MIN(remain, g_usbd_video[busid].probe.dwMaxPayloadTransferSize - header->bHeaderLength);
|
||||
memcpy(&g_usbd_video[busid].ep_buffer[header->bHeaderLength],
|
||||
&g_usbd_video[busid].stream_buf[g_usbd_video[busid].stream_offset],
|
||||
len);
|
||||
len = MIN(g_usbd_video[busid].stream_len,
|
||||
g_usbd_video[busid].probe.dwMaxPayloadTransferSize -
|
||||
g_usbd_video[busid].stream_headerlen);
|
||||
|
||||
g_usbd_video[busid].stream_offset += len;
|
||||
|
||||
if (g_usbd_video[busid].stream_offset == g_usbd_video[busid].stream_len) {
|
||||
header->headerInfoUnion.headerInfoBits.endOfFrame = 1;
|
||||
if (g_usbd_video[busid].do_copy) {
|
||||
header = (struct video_payload_header *)&g_usbd_video[busid].ep_buf[0];
|
||||
usb_memcpy(&g_usbd_video[busid].ep_buf[g_usbd_video[busid].stream_headerlen], &g_usbd_video[busid].stream_buf[offset], len);
|
||||
} else {
|
||||
header = (struct video_payload_header *)&g_usbd_video[busid].stream_buf[offset - g_usbd_video[busid].stream_headerlen];
|
||||
}
|
||||
|
||||
memset(header, 0, g_usbd_video[busid].stream_headerlen);
|
||||
header->bHeaderLength = g_usbd_video[busid].stream_headerlen;
|
||||
header->headerInfoUnion.bmheaderInfo = 0;
|
||||
header->headerInfoUnion.headerInfoBits.endOfHeader = 1;
|
||||
header->headerInfoUnion.headerInfoBits.endOfFrame = 0;
|
||||
header->headerInfoUnion.headerInfoBits.frameIdentifier = g_usbd_video[busid].stream_frameid;
|
||||
|
||||
g_usbd_video[busid].stream_offset += len;
|
||||
g_usbd_video[busid].stream_len -= len;
|
||||
|
||||
if (g_usbd_video[busid].stream_len == 0) {
|
||||
header->headerInfoUnion.headerInfoBits.endOfFrame = 1;
|
||||
g_usbd_video[busid].stream_frameid ^= 1;
|
||||
g_usbd_video[busid].stream_finish = true;
|
||||
}
|
||||
|
||||
if (g_usbd_video[busid].do_copy) {
|
||||
usbd_ep_start_write(busid, ep,
|
||||
g_usbd_video[busid].ep_buf,
|
||||
g_usbd_video[busid].stream_headerlen + len);
|
||||
} else {
|
||||
usbd_ep_start_write(busid, ep,
|
||||
&g_usbd_video[busid].stream_buf[offset - g_usbd_video[busid].stream_headerlen],
|
||||
g_usbd_video[busid].stream_headerlen + len);
|
||||
}
|
||||
|
||||
usbd_ep_start_write(busid, ep, g_usbd_video[busid].ep_buffer, len + header->bHeaderLength);
|
||||
return false;
|
||||
}
|
||||
|
||||
int usbd_video_stream_start_write(uint8_t busid, uint8_t ep, uint8_t *ep_buffer, uint8_t *buf, uint32_t len)
|
||||
int usbd_video_stream_start_write(uint8_t busid, uint8_t ep, uint8_t *ep_buf, uint8_t *stream_buf, uint32_t stream_len, bool do_copy)
|
||||
{
|
||||
if (usb_device_is_configured(busid) == 0) {
|
||||
struct video_payload_header *header;
|
||||
|
||||
if ((usb_device_is_configured(busid) == 0) || (stream_len == 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_usbd_video[busid].ep_buffer = ep_buffer;
|
||||
g_usbd_video[busid].stream_buf = buf;
|
||||
g_usbd_video[busid].stream_len = len;
|
||||
g_usbd_video[busid].ep_buf = ep_buf;
|
||||
g_usbd_video[busid].stream_buf = stream_buf;
|
||||
g_usbd_video[busid].stream_len = stream_len;
|
||||
g_usbd_video[busid].stream_offset = 0;
|
||||
g_usbd_video[busid].stream_finish = false;
|
||||
g_usbd_video[busid].do_copy = do_copy;
|
||||
|
||||
struct video_payload_header *header = (struct video_payload_header *)g_usbd_video[busid].ep_buffer;
|
||||
uint32_t len = MIN(g_usbd_video[busid].stream_len,
|
||||
g_usbd_video[busid].probe.dwMaxPayloadTransferSize -
|
||||
g_usbd_video[busid].stream_headerlen);
|
||||
|
||||
header->headerInfoUnion.headerInfoBits.frameIdentifier ^= 1;
|
||||
header = (struct video_payload_header *)&ep_buf[0];
|
||||
header->bHeaderLength = g_usbd_video[busid].stream_headerlen;
|
||||
header->headerInfoUnion.bmheaderInfo = 0;
|
||||
header->headerInfoUnion.headerInfoBits.endOfHeader = 1;
|
||||
header->headerInfoUnion.headerInfoBits.endOfFrame = 0;
|
||||
header->headerInfoUnion.headerInfoBits.frameIdentifier = g_usbd_video[busid].stream_frameid;
|
||||
|
||||
usbd_video_stream_split_transfer(busid, ep);
|
||||
usb_memcpy(&ep_buf[g_usbd_video[busid].stream_headerlen], stream_buf, len);
|
||||
g_usbd_video[busid].stream_offset += len;
|
||||
g_usbd_video[busid].stream_len -= len;
|
||||
|
||||
usbd_ep_start_write(busid, ep, ep_buf, g_usbd_video[busid].stream_headerlen + len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t usbd_video_payload_fill(uint8_t busid, uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len)
|
||||
__WEAK void usbd_video_open(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
uint32_t packets;
|
||||
uint32_t last_packet_size;
|
||||
uint32_t picture_pos = 0;
|
||||
static uint8_t uvc_header[2] = { 0x02, 0x80 };
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
}
|
||||
|
||||
packets = (input_len + (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2)) / (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2);
|
||||
last_packet_size = input_len - ((packets - 1) * (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2));
|
||||
|
||||
for (size_t i = 0; i < packets; i++) {
|
||||
output[g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i] = uvc_header[0];
|
||||
output[g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i + 1] = uvc_header[1];
|
||||
if (i == (packets - 1)) {
|
||||
memcpy(&output[2 + g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i], &input[picture_pos], last_packet_size);
|
||||
output[g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i + 1] |= (1 << 1);
|
||||
} else {
|
||||
memcpy(&output[2 + g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i], &input[picture_pos], g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2);
|
||||
picture_pos += g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2;
|
||||
}
|
||||
}
|
||||
uvc_header[1] ^= 1;
|
||||
*out_len = (input_len + 2 * packets);
|
||||
return packets;
|
||||
__WEAK void usbd_video_close(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
(void)busid;
|
||||
(void)intf;
|
||||
}
|
||||
@@ -22,9 +22,7 @@ void usbd_video_open(uint8_t busid, uint8_t intf);
|
||||
void usbd_video_close(uint8_t busid, uint8_t intf);
|
||||
|
||||
bool usbd_video_stream_split_transfer(uint8_t busid, uint8_t ep);
|
||||
int usbd_video_stream_start_write(uint8_t busid, uint8_t ep, uint8_t *ep_buffer, uint8_t *buf, uint32_t len);
|
||||
|
||||
uint32_t usbd_video_payload_fill(uint8_t busid, uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len);
|
||||
int usbd_video_stream_start_write(uint8_t busid, uint8_t ep, uint8_t *ep_buf, uint8_t *stream_buf, uint32_t stream_len, bool do_copy);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#define INTF_DESC_bInterfaceNumber 2 /** Interface number offset */
|
||||
#define INTF_DESC_bAlternateSetting 3 /** Alternate setting offset */
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_video_buf[128];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_video_buf[USB_ALIGN_UP(128, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static const char *format_type[] = { "uncompressed", "mjpeg" };
|
||||
|
||||
@@ -483,6 +483,7 @@ static int usbh_video_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister Video Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_video_stop(video_class);
|
||||
}
|
||||
@@ -531,18 +532,18 @@ const struct usbh_class_driver video_streaming_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info video_ctrl_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_VIDEO,
|
||||
.subclass = VIDEO_SC_VIDEOCONTROL,
|
||||
.protocol = VIDEO_PC_PROTOCOL_UNDEFINED,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_VIDEO,
|
||||
.bInterfaceSubClass = VIDEO_SC_VIDEOCONTROL,
|
||||
.bInterfaceProtocol = VIDEO_PC_PROTOCOL_UNDEFINED,
|
||||
.id_table = NULL,
|
||||
.class_driver = &video_ctrl_class_driver
|
||||
};
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info video_streaming_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_VIDEO,
|
||||
.subclass = VIDEO_SC_VIDEOSTREAMING,
|
||||
.protocol = VIDEO_PC_PROTOCOL_UNDEFINED,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_VIDEO,
|
||||
.bInterfaceSubClass = VIDEO_SC_VIDEOSTREAMING,
|
||||
.bInterfaceProtocol = VIDEO_PC_PROTOCOL_UNDEFINED,
|
||||
.id_table = NULL,
|
||||
.class_driver = &video_streaming_class_driver
|
||||
};
|
||||
|
||||
@@ -24,6 +24,7 @@ struct usbd_rndis_priv {
|
||||
uint32_t net_filter;
|
||||
usb_eth_stat_t eth_state;
|
||||
rndis_state_t init_state;
|
||||
bool set_rsp_get;
|
||||
uint8_t mac[6];
|
||||
} g_usbd_rndis;
|
||||
|
||||
@@ -37,14 +38,17 @@ struct usbd_rndis_priv {
|
||||
#define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
|
||||
#endif
|
||||
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_rx_buffer[CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_tx_buffer[CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE];
|
||||
#ifdef CONFIG_USBDEV_RNDIS_USING_LWIP
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_rx_buffer[USB_ALIGN_UP(CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_tx_buffer[USB_ALIGN_UP(CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
#endif
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t rndis_encapsulated_resp_buffer[CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t NOTIFY_RESPONSE_AVAILABLE[8];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t rndis_encapsulated_resp_buffer[USB_ALIGN_UP(CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t NOTIFY_RESPONSE_AVAILABLE[USB_ALIGN_UP(8, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
volatile uint8_t *g_rndis_rx_data_buffer;
|
||||
volatile uint32_t g_rndis_rx_data_length;
|
||||
volatile uint32_t g_rndis_rx_total_length;
|
||||
volatile uint32_t g_rndis_tx_data_length;
|
||||
|
||||
/* RNDIS options list */
|
||||
@@ -106,9 +110,13 @@ static int rndis_class_interface_request_handler(uint8_t busid, struct usb_setup
|
||||
|
||||
switch (setup->bRequest) {
|
||||
case CDC_REQUEST_SEND_ENCAPSULATED_COMMAND:
|
||||
g_usbd_rndis.set_rsp_get = true;
|
||||
|
||||
rndis_encapsulated_cmd_handler(*data, setup->wLength);
|
||||
break;
|
||||
case CDC_REQUEST_GET_ENCAPSULATED_RESPONSE:
|
||||
g_usbd_rndis.set_rsp_get = false;
|
||||
|
||||
*data = rndis_encapsulated_resp_buffer;
|
||||
*len = ((rndis_generic_msg_t *)rndis_encapsulated_resp_buffer)->MessageLength;
|
||||
break;
|
||||
@@ -268,7 +276,7 @@ static int rndis_query_cmd_handler(uint8_t *data, uint32_t len)
|
||||
infomation_len = 4;
|
||||
break;
|
||||
case OID_GEN_MEDIA_CONNECT_STATUS:
|
||||
RNDIS_INQUIRY_PUT_LE32(g_usbd_rndis.link_status);
|
||||
RNDIS_INQUIRY_PUT_LE32(NDIS_MEDIA_STATE_CONNECTED);
|
||||
infomation_len = 4;
|
||||
break;
|
||||
case OID_GEN_RNDIS_CONFIG_PARAMETER:
|
||||
@@ -447,12 +455,14 @@ static void rndis_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
g_usbd_rndis.link_status = NDIS_MEDIA_STATE_DISCONNECTED;
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
g_rndis_rx_data_length = 0;
|
||||
g_rndis_tx_data_length = 0;
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
#ifdef CONFIG_USBDEV_RNDIS_USING_LWIP
|
||||
g_usbd_rndis.link_status = NDIS_MEDIA_STATE_CONNECTED;
|
||||
usbd_ep_start_read(0, rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr, g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
usbd_rndis_start_read(g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -467,10 +477,9 @@ void rndis_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
|
||||
hdr = (rndis_data_packet_t *)g_rndis_rx_buffer;
|
||||
g_rndis_rx_data_buffer = g_rndis_rx_buffer;
|
||||
hdr = (rndis_data_packet_t *)g_rndis_rx_data_buffer;
|
||||
if ((hdr->MessageType != REMOTE_NDIS_PACKET_MSG) || (nbytes < hdr->MessageLength)) {
|
||||
usbd_ep_start_read(0, rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr, g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
usbd_rndis_start_read((uint8_t *)g_rndis_rx_data_buffer, g_rndis_rx_total_length);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -478,7 +487,7 @@ void rndis_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
g_rndis_rx_data_buffer += hdr->DataOffset + sizeof(rndis_generic_msg_t);
|
||||
g_rndis_rx_data_length = hdr->DataLength;
|
||||
|
||||
usbd_rndis_data_recv_done();
|
||||
usbd_rndis_data_recv_done(g_rndis_rx_data_length);
|
||||
}
|
||||
|
||||
void rndis_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
@@ -489,6 +498,7 @@ void rndis_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(0, ep, NULL, 0);
|
||||
} else {
|
||||
usbd_rndis_data_send_done(g_rndis_tx_data_length);
|
||||
g_rndis_tx_data_length = 0;
|
||||
}
|
||||
}
|
||||
@@ -502,6 +512,34 @@ void rndis_int_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
//USB_LOG_DBG("len:%d\r\n", nbytes);
|
||||
}
|
||||
|
||||
int usbd_rndis_start_write(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
if (!usb_device_is_configured(0)) {
|
||||
return -USB_ERR_NOTCONN;
|
||||
}
|
||||
|
||||
if (g_rndis_tx_data_length > 0) {
|
||||
return -USB_ERR_BUSY;
|
||||
}
|
||||
|
||||
g_rndis_tx_data_length = len;
|
||||
|
||||
USB_LOG_DBG("txlen:%d\r\n", g_rndis_tx_data_length);
|
||||
return usbd_ep_start_write(0, rndis_ep_data[RNDIS_IN_EP_IDX].ep_addr, buf, len);
|
||||
}
|
||||
|
||||
int usbd_rndis_start_read(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
if (!usb_device_is_configured(0)) {
|
||||
return -USB_ERR_NOTCONN;
|
||||
}
|
||||
|
||||
g_rndis_rx_data_buffer = buf;
|
||||
g_rndis_rx_total_length = len;
|
||||
g_rndis_rx_data_length = 0;
|
||||
return usbd_ep_start_read(0, rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr, buf, len);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_RNDIS_USING_LWIP
|
||||
#include <lwip/pbuf.h>
|
||||
|
||||
@@ -514,15 +552,14 @@ struct pbuf *usbd_rndis_eth_rx(void)
|
||||
}
|
||||
p = pbuf_alloc(PBUF_RAW, g_rndis_rx_data_length, PBUF_POOL);
|
||||
if (p == NULL) {
|
||||
usbd_rndis_start_read(g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
return NULL;
|
||||
}
|
||||
usb_memcpy(p->payload, (uint8_t *)g_rndis_rx_data_buffer, g_rndis_rx_data_length);
|
||||
p->len = g_rndis_rx_data_length;
|
||||
|
||||
USB_LOG_DBG("rxlen:%d\r\n", g_rndis_rx_data_length);
|
||||
g_rndis_rx_data_length = 0;
|
||||
usbd_ep_start_read(0, rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr, g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
|
||||
usbd_rndis_start_read(g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -532,7 +569,7 @@ int usbd_rndis_eth_tx(struct pbuf *p)
|
||||
uint8_t *buffer;
|
||||
rndis_data_packet_t *hdr;
|
||||
|
||||
if (g_usbd_rndis.link_status == NDIS_MEDIA_STATE_DISCONNECTED) {
|
||||
if (!usb_device_is_configured(0)) {
|
||||
return -USB_ERR_NOTCONN;
|
||||
}
|
||||
|
||||
@@ -558,10 +595,7 @@ int usbd_rndis_eth_tx(struct pbuf *p)
|
||||
hdr->DataOffset = sizeof(rndis_data_packet_t) - sizeof(rndis_generic_msg_t);
|
||||
hdr->DataLength = p->tot_len;
|
||||
|
||||
g_rndis_tx_data_length = sizeof(rndis_data_packet_t) + p->tot_len;
|
||||
|
||||
USB_LOG_DBG("txlen:%d\r\n", g_rndis_tx_data_length);
|
||||
return usbd_ep_start_write(0, rndis_ep_data[RNDIS_IN_EP_IDX].ep_addr, g_rndis_tx_buffer, g_rndis_tx_data_length);
|
||||
return usbd_rndis_start_write(g_rndis_tx_buffer, sizeof(rndis_data_packet_t) + p->tot_len);
|
||||
}
|
||||
#endif
|
||||
struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf,
|
||||
@@ -592,3 +626,42 @@ struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf,
|
||||
|
||||
return intf;
|
||||
}
|
||||
|
||||
int usbd_rndis_set_connect(bool connect)
|
||||
{
|
||||
if (!usb_device_is_configured(0)) {
|
||||
return -USB_ERR_NOTCONN;
|
||||
}
|
||||
|
||||
if(g_usbd_rndis.set_rsp_get)
|
||||
return -USB_ERR_BUSY;
|
||||
|
||||
rndis_indicate_status_t *resp;
|
||||
|
||||
resp = ((rndis_indicate_status_t *)rndis_encapsulated_resp_buffer);
|
||||
resp->MessageType = REMOTE_NDIS_INDICATE_STATUS_MSG;
|
||||
resp->MessageLength = sizeof(rndis_indicate_status_t);
|
||||
if(connect) {
|
||||
resp->Status = RNDIS_STATUS_MEDIA_CONNECT;
|
||||
g_usbd_rndis.link_status = NDIS_MEDIA_STATE_CONNECTED;
|
||||
} else {
|
||||
resp->Status = RNDIS_STATUS_MEDIA_DISCONNECT;
|
||||
g_usbd_rndis.link_status = NDIS_MEDIA_STATE_DISCONNECTED;
|
||||
}
|
||||
resp->StatusBufferLength = 0;
|
||||
resp->StatusBufferOffset = 0;
|
||||
|
||||
rndis_notify_rsp();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_rndis_data_recv_done(uint32_t len)
|
||||
{
|
||||
(void)len;
|
||||
}
|
||||
|
||||
__WEAK void usbd_rndis_data_send_done(uint32_t len)
|
||||
{
|
||||
(void)len;
|
||||
}
|
||||
@@ -18,7 +18,12 @@ struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf,
|
||||
const uint8_t in_ep,
|
||||
const uint8_t int_ep, uint8_t mac[6]);
|
||||
|
||||
void usbd_rndis_data_recv_done(void);
|
||||
int usbd_rndis_set_connect(bool connect);
|
||||
|
||||
void usbd_rndis_data_recv_done(uint32_t len);
|
||||
void usbd_rndis_data_send_done(uint32_t len);
|
||||
int usbd_rndis_start_write(uint8_t *buf, uint32_t len);
|
||||
int usbd_rndis_start_read(uint8_t *buf, uint32_t len);
|
||||
|
||||
#ifdef CONFIG_USBDEV_RNDIS_USING_LWIP
|
||||
struct pbuf *usbd_rndis_eth_rx(void);
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
static struct usbh_bluetooth g_bluetooth_class;
|
||||
|
||||
#ifdef CONFIG_USBHOST_BLUETOOTH_HCI_H4
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_tx_buf[1 + CONFIG_USBHOST_BLUETOOTH_TX_SIZE];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_rx_buf[1 + CONFIG_USBHOST_BLUETOOTH_RX_SIZE];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_tx_buf[USB_ALIGN_UP(CONFIG_USBHOST_BLUETOOTH_TX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_rx_buf[USB_ALIGN_UP(CONFIG_USBHOST_BLUETOOTH_RX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
#else
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_cmd_buf[1 + 256];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_evt_buf[1 + 256];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_tx_buf[1 + CONFIG_USBHOST_BLUETOOTH_TX_SIZE];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_rx_buf[1 + CONFIG_USBHOST_BLUETOOTH_RX_SIZE];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_cmd_buf[USB_ALIGN_UP(256, CONFIG_USB_ALIGN_SIZE)];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_evt_buf[USB_ALIGN_UP(256, CONFIG_USB_ALIGN_SIZE)];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_tx_buf[USB_ALIGN_UP(CONFIG_USBHOST_BLUETOOTH_TX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_bluetooth_rx_buf[USB_ALIGN_UP(CONFIG_USBHOST_BLUETOOTH_RX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
#endif
|
||||
|
||||
static int usbh_bluetooth_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
@@ -134,6 +134,7 @@ static int usbh_bluetooth_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
// }
|
||||
#endif
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister Bluetooth Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_bluetooth_stop(bluetooth_class);
|
||||
}
|
||||
@@ -189,7 +190,7 @@ int usbh_bluetooth_hci_write(uint8_t hci_type, uint8_t *buffer, uint32_t buflen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void usbh_bluetooth_hci_rx_thread(void *argument)
|
||||
void usbh_bluetooth_hci_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
int ret;
|
||||
uint32_t ep_mps;
|
||||
@@ -271,7 +272,7 @@ int usbh_bluetooth_hci_write(uint8_t hci_type, uint8_t *buffer, uint32_t buflen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void usbh_bluetooth_hci_evt_rx_thread(void *argument)
|
||||
void usbh_bluetooth_hci_evt_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
int ret;
|
||||
uint32_t ep_mps;
|
||||
@@ -320,7 +321,7 @@ delete :
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
void usbh_bluetooth_hci_acl_rx_thread(void *argument)
|
||||
void usbh_bluetooth_hci_acl_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
int ret;
|
||||
uint32_t ep_mps;
|
||||
@@ -393,18 +394,18 @@ static const uint16_t bluetooth_id_table[][2] = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info bluetooth_h4_nrf_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS,
|
||||
.class = 0xff,
|
||||
.subclass = 0x00,
|
||||
.protocol = 0x00,
|
||||
.bInterfaceClass = 0xff,
|
||||
.bInterfaceSubClass = 0x00,
|
||||
.bInterfaceProtocol = 0x00,
|
||||
.id_table = bluetooth_id_table,
|
||||
.class_driver = &bluetooth_class_driver
|
||||
};
|
||||
#else
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info bluetooth_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_WIRELESS,
|
||||
.subclass = 0x01,
|
||||
.protocol = 0x01,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_WIRELESS,
|
||||
.bInterfaceSubClass = 0x01,
|
||||
.bInterfaceProtocol = 0x01,
|
||||
.id_table = NULL,
|
||||
.class_driver = &bluetooth_class_driver
|
||||
};
|
||||
|
||||
@@ -40,10 +40,10 @@ extern "C" {
|
||||
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);
|
||||
void usbh_bluetooth_hci_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
#else
|
||||
void usbh_bluetooth_hci_evt_rx_thread(void *argument);
|
||||
void usbh_bluetooth_hci_acl_rx_thread(void *argument);
|
||||
void usbh_bluetooth_hci_evt_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
void usbh_bluetooth_hci_acl_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
#endif
|
||||
|
||||
void usbh_bluetooth_run(struct usbh_bluetooth *bluetooth_class);
|
||||
|
||||
@@ -18,9 +18,9 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_buf[512];
|
||||
#define CONFIG_USBHOST_RNDIS_ETH_MAX_FRAME_SIZE 1514
|
||||
#define CONFIG_USBHOST_RNDIS_ETH_MSG_SIZE (CONFIG_USBHOST_RNDIS_ETH_MAX_FRAME_SIZE + 44)
|
||||
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_rx_buffer[CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_tx_buffer[CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE];
|
||||
// static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_inttx_buffer[16];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_rx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_tx_buffer[USB_ALIGN_UP(CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE, CONFIG_USB_ALIGN_SIZE)];
|
||||
// static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_inttx_buffer[USB_ALIGN_UP(16, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
static struct usbh_rndis g_rndis_class;
|
||||
|
||||
@@ -90,8 +90,8 @@ static int usbh_rndis_init_msg_transfer(struct usbh_rndis *rndis_class)
|
||||
|
||||
rndis_class->max_transfer_pkts = resp->MaxPacketsPerTransfer;
|
||||
rndis_class->max_transfer_size = resp->MaxTransferSize;
|
||||
USB_LOG_INFO("MaxPacketsPerTransfer:%d\r\n", resp->MaxPacketsPerTransfer);
|
||||
USB_LOG_INFO("MaxTransferSize:%d\r\n", resp->MaxTransferSize);
|
||||
USB_LOG_INFO("MaxPacketsPerTransfer:%u\r\n", (unsigned int)resp->MaxPacketsPerTransfer);
|
||||
USB_LOG_INFO("MaxTransferSize:%u\r\n", (unsigned int)resp->MaxTransferSize);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -278,8 +278,8 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
int ret;
|
||||
uint32_t *oid_support_list;
|
||||
unsigned int oid = 0;
|
||||
unsigned int oid_num = 0;
|
||||
uint32_t oid = 0;
|
||||
uint32_t oid_num = 0;
|
||||
uint32_t data_len;
|
||||
uint8_t tmp_buffer[512];
|
||||
uint8_t data[32];
|
||||
@@ -319,7 +319,7 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return ret;
|
||||
}
|
||||
oid_num = (data_len / 4);
|
||||
USB_LOG_INFO("rndis query OID_GEN_SUPPORTED_LIST success,oid num :%d\r\n", oid_num);
|
||||
USB_LOG_INFO("rndis query OID_GEN_SUPPORTED_LIST success,oid num :%u\r\n", (unsigned int)oid_num);
|
||||
|
||||
oid_support_list = (uint32_t *)tmp_buffer;
|
||||
|
||||
@@ -380,10 +380,10 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
USB_LOG_WRN("Ignore rndis query iod:%08x\r\n", oid);
|
||||
USB_LOG_WRN("Ignore rndis query iod:%08x\r\n", (unsigned int)oid);
|
||||
continue;
|
||||
}
|
||||
USB_LOG_INFO("rndis query iod:%08x success\r\n", oid);
|
||||
USB_LOG_INFO("rndis query iod:%08x success\r\n", (unsigned int)oid);
|
||||
}
|
||||
|
||||
uint32_t packet_filter = 0x0f;
|
||||
@@ -414,7 +414,7 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
usbh_rndis_run(rndis_class);
|
||||
return ret;
|
||||
query_errorout:
|
||||
USB_LOG_ERR("rndis query iod:%08x error\r\n", oid);
|
||||
USB_LOG_ERR("rndis query iod:%08x error\r\n", (unsigned int)oid);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -438,6 +438,7 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
// }
|
||||
|
||||
if (hport->config.intf[intf].devname[0] != '\0') {
|
||||
usb_osal_thread_schedule_other();
|
||||
USB_LOG_INFO("Unregister RNDIS Class:%s\r\n", hport->config.intf[intf].devname);
|
||||
usbh_rndis_stop(rndis_class);
|
||||
}
|
||||
@@ -448,7 +449,7 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void usbh_rndis_rx_thread(void *argument)
|
||||
void usbh_rndis_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
uint32_t g_rndis_rx_length;
|
||||
int ret;
|
||||
@@ -461,7 +462,7 @@ void usbh_rndis_rx_thread(void *argument)
|
||||
uint32_t transfer_size = (16 * 1024);
|
||||
#endif
|
||||
|
||||
(void)argument;
|
||||
(void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
|
||||
|
||||
USB_LOG_INFO("Create rndis rx thread\r\n");
|
||||
// clang-format off
|
||||
@@ -501,7 +502,7 @@ find_class:
|
||||
uint32_t total_len = g_rndis_rx_length;
|
||||
|
||||
while (g_rndis_rx_length > 0) {
|
||||
USB_LOG_DBG("rxlen:%d\r\n", g_rndis_rx_length);
|
||||
USB_LOG_DBG("rxlen:%u\r\n", (unsigned int)g_rndis_rx_length);
|
||||
|
||||
pmsg = (rndis_data_packet_t *)(g_rndis_rx_buffer + pmg_offset);
|
||||
|
||||
@@ -523,7 +524,7 @@ find_class:
|
||||
g_rndis_rx_length = 0;
|
||||
}
|
||||
} else {
|
||||
USB_LOG_ERR("offset:%d,remain:%d,total:%d\r\n", pmg_offset, g_rndis_rx_length, total_len);
|
||||
USB_LOG_ERR("offset:%u,remain:%u,total:%u\r\n", (unsigned int)pmg_offset, (unsigned int)g_rndis_rx_length, (unsigned int)total_len);
|
||||
g_rndis_rx_length = 0;
|
||||
USB_LOG_ERR("Error rndis packet message\r\n");
|
||||
}
|
||||
@@ -600,9 +601,9 @@ static const struct usbh_class_driver rndis_class_driver = {
|
||||
|
||||
CLASS_INFO_DEFINE const struct usbh_class_info rndis_class_info = {
|
||||
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
|
||||
.class = USB_DEVICE_CLASS_WIRELESS,
|
||||
.subclass = 0x01,
|
||||
.protocol = 0x03,
|
||||
.bInterfaceClass = USB_DEVICE_CLASS_WIRELESS,
|
||||
.bInterfaceSubClass = 0x01,
|
||||
.bInterfaceProtocol = 0x03,
|
||||
.id_table = NULL,
|
||||
.class_driver = &rndis_class_driver
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ void usbh_rndis_stop(struct usbh_rndis *rndis_class);
|
||||
uint8_t *usbh_rndis_get_eth_txbuf(void);
|
||||
int usbh_rndis_eth_output(uint32_t buflen);
|
||||
void usbh_rndis_eth_input(uint8_t *buf, uint32_t buflen);
|
||||
void usbh_rndis_rx_thread(void *argument);
|
||||
void usbh_rndis_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -136,7 +136,12 @@ int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, ui
|
||||
*/
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len);
|
||||
|
||||
/* usb dcd irq callback */
|
||||
/* usb dcd irq callback, called by user */
|
||||
|
||||
/**
|
||||
* @brief Usb sof irq callback.
|
||||
*/
|
||||
void usbd_event_sof_handler(uint8_t busid);
|
||||
|
||||
/**
|
||||
* @brief Usb connect irq callback.
|
||||
@@ -194,6 +199,9 @@ void usbd_event_ep_out_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbyt
|
||||
void usbd_execute_test_mode(uint8_t busid, uint8_t test_mode);
|
||||
#endif
|
||||
|
||||
/* called by user */
|
||||
void USBD_IRQHandler(uint8_t busid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
22
common/usb_dcache.h
Normal file
22
common/usb_dcache.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2024, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USB_DCACHE_H
|
||||
#define USB_DCACHE_H
|
||||
|
||||
#ifdef CONFIG_USB_DCACHE_ENABLE
|
||||
#if CONFIG_USB_ALIGN_SIZE % 32
|
||||
#error "CONFIG_USB_ALIGN_SIZE must be multiple of 32"
|
||||
#endif
|
||||
void usb_dcache_clean(uintptr_t addr, size_t size);
|
||||
void usb_dcache_invalidate(uintptr_t addr, size_t size);
|
||||
void usb_dcache_flush(uintptr_t addr, size_t size);
|
||||
#else
|
||||
#define usb_dcache_clean(addr, size)
|
||||
#define usb_dcache_invalidate(addr, size)
|
||||
#define usb_dcache_flush(addr, size)
|
||||
#endif
|
||||
|
||||
#endif /* USB_DCACHE_H */
|
||||
@@ -108,6 +108,9 @@ int usbh_submit_urb(struct usbh_urb *urb);
|
||||
*/
|
||||
int usbh_kill_urb(struct usbh_urb *urb);
|
||||
|
||||
/* called by user */
|
||||
void USBH_IRQHandler(uint8_t busid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -75,21 +75,40 @@
|
||||
|
||||
#define USB_LOG_RAW(...) CONFIG_USB_PRINTF(__VA_ARGS__)
|
||||
|
||||
void usb_assert(const char *filename, int linenum);
|
||||
#define USB_ASSERT(f) \
|
||||
do { \
|
||||
if (!(f)) \
|
||||
usb_assert(__FILE__, __LINE__); \
|
||||
} while (0)
|
||||
#ifndef CONFIG_USB_ASSERT_DISABLE
|
||||
#define USB_ASSERT(f) \
|
||||
do { \
|
||||
if (!(f)) { \
|
||||
USB_LOG_ERR("ASSERT FAIL [%s] @ %s:%d\r\n", #f, __FILE__, __LINE__); \
|
||||
while (1) { \
|
||||
} \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define USB_ASSERT_MSG(f, fmt, ...) \
|
||||
do { \
|
||||
if (!(f)) { \
|
||||
USB_LOG_ERR("ASSERT FAIL [%s] @ %s:%d\r\n", #f, __FILE__, __LINE__); \
|
||||
USB_LOG_ERR(fmt "\r\n", ##__VA_ARGS__); \
|
||||
while (1) { \
|
||||
} \
|
||||
} \
|
||||
} while (false)
|
||||
#else
|
||||
#define USB_ASSERT(f) {}
|
||||
#define USB_ASSERT_MSG(f, fmt, ...) {}
|
||||
#endif
|
||||
|
||||
#define ___is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
|
||||
static inline void usb_hexdump(const void *ptr, uint32_t buflen)
|
||||
{
|
||||
unsigned char *buf = (unsigned char *)ptr;
|
||||
uint32_t i, j;
|
||||
unsigned int i, j;
|
||||
|
||||
(void)buf;
|
||||
|
||||
for (i = 0; i < buflen; i += 16) {
|
||||
CONFIG_USB_PRINTF("%08X:", i);
|
||||
CONFIG_USB_PRINTF("%08x:", i);
|
||||
|
||||
for (j = 0; j < 16; j++)
|
||||
if (i + j < buflen) {
|
||||
|
||||
@@ -88,4 +88,9 @@ static inline void *usb_memcpy(void *s1, const void *s2, size_t n)
|
||||
}
|
||||
return s1;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_USB_MEMCPY_DISABLE
|
||||
#define memcpy usb_memcpy
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,19 +10,30 @@
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __INCLUDE_NUTTX_CONFIG_H
|
||||
#define CONFIG_USB_OSAL_THREAD_SET_ARGV int argc, char **argv
|
||||
#define CONFIG_USB_OSAL_THREAD_GET_ARGV ((uintptr_t)strtoul(argv[1], NULL, 16))
|
||||
#elif defined(__ZEPHYR__)
|
||||
#define CONFIG_USB_OSAL_THREAD_SET_ARGV void *p1, void *p2, void *p3
|
||||
#define CONFIG_USB_OSAL_THREAD_GET_ARGV ((uintptr_t)p1)
|
||||
#else
|
||||
#define CONFIG_USB_OSAL_THREAD_SET_ARGV void *argument
|
||||
#define CONFIG_USB_OSAL_THREAD_GET_ARGV ((uintptr_t)argument)
|
||||
#endif
|
||||
|
||||
#define USB_OSAL_WAITING_FOREVER (0xFFFFFFFFU)
|
||||
|
||||
typedef void *usb_osal_thread_t;
|
||||
typedef void *usb_osal_sem_t;
|
||||
typedef void *usb_osal_mutex_t;
|
||||
typedef void *usb_osal_mq_t;
|
||||
typedef void (*usb_thread_entry_t)(void *argument);
|
||||
typedef void (*usb_thread_entry_t)(CONFIG_USB_OSAL_THREAD_SET_ARGV);
|
||||
typedef void (*usb_timer_handler_t)(void *argument);
|
||||
struct usb_osal_timer {
|
||||
usb_timer_handler_t handler;
|
||||
void *argument;
|
||||
bool is_period;
|
||||
uint32_t ticks;
|
||||
uint32_t timeout_ms;
|
||||
void *timer;
|
||||
};
|
||||
|
||||
@@ -31,6 +42,7 @@ struct usb_osal_timer {
|
||||
*/
|
||||
usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size, uint32_t prio, usb_thread_entry_t entry, void *args);
|
||||
void usb_osal_thread_delete(usb_osal_thread_t thread);
|
||||
void usb_osal_thread_schedule_other(void);
|
||||
|
||||
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count);
|
||||
void usb_osal_sem_delete(usb_osal_sem_t sem);
|
||||
|
||||
41
common/usb_otg.h
Normal file
41
common/usb_otg.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2025, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USB_OTG_H
|
||||
#define USB_OTG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief usb otg controller hardware or gpio id simulator init.
|
||||
*
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usb_otg_init(uint8_t busid);
|
||||
/**
|
||||
* @brief usb otg controller hardware or gpio id simulator deinit.
|
||||
*
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usb_otg_deinit(uint8_t busid);
|
||||
/**
|
||||
* @brief get current role mode.
|
||||
*
|
||||
* @return return USBOTG_MODE_HOST or USBOTG_MODE_DEVICE.
|
||||
*/
|
||||
uint8_t usbotg_get_current_mode(uint8_t busid);
|
||||
|
||||
/* called by user */
|
||||
void USBOTG_IRQHandler(uint8_t busid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USB_OTG_H */
|
||||
@@ -206,5 +206,14 @@
|
||||
#define USB_MEM_ALIGNX __attribute__((aligned(CONFIG_USB_ALIGN_SIZE)))
|
||||
|
||||
#define USB_ALIGN_UP(size, align) (((size) + (align)-1) & ~((align)-1))
|
||||
#define USB_ALIGN_DOWN(size, align) ((size) & ~((align)-1))
|
||||
|
||||
#ifndef usb_phyaddr2ramaddr
|
||||
#define usb_phyaddr2ramaddr(addr) (addr)
|
||||
#endif
|
||||
|
||||
#ifndef usb_ramaddr2phyaddr
|
||||
#define usb_ramaddr2phyaddr(addr) (addr)
|
||||
#endif
|
||||
|
||||
#endif /* USB_UTIL_H */
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#undef CHERRYUSB_VERSION_STR
|
||||
#endif
|
||||
|
||||
#define CHERRYUSB_VERSION 0x010401
|
||||
#define CHERRYUSB_VERSION_STR "v1.4.1"
|
||||
#define CHERRYUSB_VERSION 0x010500
|
||||
#define CHERRYUSB_VERSION_STR "v1.5.0"
|
||||
|
||||
#endif
|
||||
199
core/usbd_core.c
199
core/usbd_core.c
@@ -4,6 +4,17 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#ifdef CONFIG_USBDEV_EP0_THREAD
|
||||
#include "usb_osal.h"
|
||||
|
||||
#define USB_EP0_STATE_SETUP 0
|
||||
#define USB_EP0_STATE_IN 1
|
||||
#define USB_EP0_STATE_OUT 2
|
||||
#endif
|
||||
|
||||
#undef USB_DBG_TAG
|
||||
#define USB_DBG_TAG "usbd_core"
|
||||
#include "usb_log.h"
|
||||
|
||||
/* general descriptor field offsets */
|
||||
#define DESC_bLength 0 /** Length offset */
|
||||
@@ -30,7 +41,7 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_priv {
|
||||
/** Setup packet */
|
||||
USB_MEM_ALIGNX struct usb_setup_packet setup;
|
||||
/** Pointer to data buffer */
|
||||
uint8_t *ep0_data_buf;
|
||||
USB_MEM_ALIGNX uint8_t *ep0_data_buf;
|
||||
/** Remaining bytes in buffer */
|
||||
uint32_t ep0_data_buf_residue;
|
||||
/** Total length of control transfer */
|
||||
@@ -48,11 +59,12 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_priv {
|
||||
struct usb_webusb_descriptor *webusb_url_desc;
|
||||
#endif
|
||||
/* Buffer used for storing standard, class and vendor request data */
|
||||
USB_MEM_ALIGNX uint8_t req_data[CONFIG_USBDEV_REQUEST_BUFFER_LEN];
|
||||
USB_MEM_ALIGNX uint8_t req_data[USB_ALIGN_UP(CONFIG_USBDEV_REQUEST_BUFFER_LEN, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
/** Currently selected configuration */
|
||||
uint8_t configuration;
|
||||
uint8_t device_address;
|
||||
uint8_t ep0_next_state;
|
||||
bool self_powered;
|
||||
bool remote_wakeup_support;
|
||||
bool remote_wakeup_enabled;
|
||||
@@ -62,8 +74,13 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_priv {
|
||||
#endif
|
||||
#ifdef CONFIG_USBDEV_TEST_MODE
|
||||
bool test_req;
|
||||
#endif
|
||||
#ifdef CONFIG_USBDEV_EP0_THREAD
|
||||
usb_osal_mq_t usbd_ep0_mq;
|
||||
usb_osal_thread_t usbd_ep0_thread;
|
||||
#endif
|
||||
struct usbd_interface *intf[16];
|
||||
uint8_t intf_altsetting[16];
|
||||
uint8_t intf_offset;
|
||||
|
||||
struct usbd_tx_rx_msg tx_msg[CONFIG_USBDEV_EP_NUM];
|
||||
@@ -98,6 +115,7 @@ static bool is_device_configured(uint8_t busid)
|
||||
* This function sets endpoint configuration according to one specified in USB
|
||||
* endpoint descriptor and then enables it for data transfers.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] ep Endpoint descriptor byte array
|
||||
*
|
||||
* @return true if successfully configured and enabled
|
||||
@@ -125,6 +143,7 @@ static bool usbd_set_endpoint(uint8_t busid, const struct usb_endpoint_descripto
|
||||
* This function cancels transfers that are associated with endpoint and
|
||||
* disabled endpoint itself.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] ep Endpoint descriptor byte array
|
||||
*
|
||||
* @return true if successfully deconfigured and disabled
|
||||
@@ -144,6 +163,7 @@ static bool usbd_reset_endpoint(uint8_t busid, const struct usb_endpoint_descrip
|
||||
* This function parses the list of installed USB descriptors and attempts
|
||||
* to find the specified USB descriptor.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] type_index Type and index of the descriptor
|
||||
* @param [out] data Descriptor data
|
||||
* @param [out] len Descriptor length
|
||||
@@ -166,6 +186,11 @@ static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **da
|
||||
switch (type) {
|
||||
case USB_DESCRIPTOR_TYPE_DEVICE:
|
||||
g_usbd_core[busid].speed = usbd_get_port_speed(busid); /* before we get device descriptor, we have known steady port speed */
|
||||
|
||||
if (g_usbd_core[busid].descriptors->device_descriptor_callback == NULL) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
desc = g_usbd_core[busid].descriptors->device_descriptor_callback(g_usbd_core[busid].speed);
|
||||
if (desc == NULL) {
|
||||
found = false;
|
||||
@@ -174,6 +199,10 @@ static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **da
|
||||
desc_len = desc[0];
|
||||
break;
|
||||
case USB_DESCRIPTOR_TYPE_CONFIGURATION:
|
||||
if (g_usbd_core[busid].descriptors->config_descriptor_callback == NULL) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
desc = g_usbd_core[busid].descriptors->config_descriptor_callback(g_usbd_core[busid].speed);
|
||||
if (desc == NULL) {
|
||||
found = false;
|
||||
@@ -194,6 +223,10 @@ static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **da
|
||||
desc = (uint8_t *)g_usbd_core[busid].descriptors->msosv1_descriptor->string;
|
||||
desc_len = g_usbd_core[busid].descriptors->msosv1_descriptor->string[0];
|
||||
} else {
|
||||
if (g_usbd_core[busid].descriptors->string_descriptor_callback == NULL) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
string = g_usbd_core[busid].descriptors->string_descriptor_callback(g_usbd_core[busid].speed, index);
|
||||
if (string == NULL) {
|
||||
found = false;
|
||||
@@ -233,6 +266,10 @@ static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **da
|
||||
#ifndef CONFIG_USB_HS
|
||||
return false;
|
||||
#else
|
||||
if (g_usbd_core[busid].descriptors->device_quality_descriptor_callback == NULL) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
desc = g_usbd_core[busid].descriptors->device_quality_descriptor_callback(g_usbd_core[busid].speed);
|
||||
if (desc == NULL) {
|
||||
found = false;
|
||||
@@ -242,6 +279,10 @@ static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **da
|
||||
break;
|
||||
#endif
|
||||
case USB_DESCRIPTOR_TYPE_OTHER_SPEED:
|
||||
if (g_usbd_core[busid].descriptors->other_speed_descriptor_callback == NULL) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
desc = g_usbd_core[busid].descriptors->other_speed_descriptor_callback(g_usbd_core[busid].speed);
|
||||
if (desc == NULL) {
|
||||
found = false;
|
||||
@@ -370,6 +411,7 @@ static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **da
|
||||
* index and alternate setting by parsing the installed USB descriptor list.
|
||||
* A configuration index of 0 unconfigures the device.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] config_index Configuration index
|
||||
* @param [in] alt_setting Alternate setting number
|
||||
*
|
||||
@@ -426,8 +468,8 @@ static bool usbd_set_configuration(uint8_t busid, uint8_t config_index, uint8_t
|
||||
}
|
||||
|
||||
/* skip to next descriptor */
|
||||
p += p[DESC_bLength];
|
||||
current_desc_len += p[DESC_bLength];
|
||||
p += p[DESC_bLength];
|
||||
if (current_desc_len >= desc_len && desc_len) {
|
||||
break;
|
||||
}
|
||||
@@ -439,6 +481,7 @@ static bool usbd_set_configuration(uint8_t busid, uint8_t config_index, uint8_t
|
||||
/**
|
||||
* @brief set USB interface
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] iface Interface index
|
||||
* @param [in] alt_setting Alternate setting number
|
||||
*
|
||||
@@ -491,10 +534,8 @@ static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting
|
||||
|
||||
if (alt_setting == 0) {
|
||||
ret = usbd_reset_endpoint(busid, ep_desc);
|
||||
goto find_end;
|
||||
} else if (cur_alt_setting == alt_setting) {
|
||||
ret = usbd_set_endpoint(busid, ep_desc);
|
||||
goto find_end;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
@@ -506,14 +547,13 @@ static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting
|
||||
}
|
||||
|
||||
/* skip to next descriptor */
|
||||
p += p[DESC_bLength];
|
||||
current_desc_len += p[DESC_bLength];
|
||||
p += p[DESC_bLength];
|
||||
if (current_desc_len >= desc_len && desc_len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
find_end:
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_SET_INTERFACE, (void *)if_desc);
|
||||
|
||||
return ret;
|
||||
@@ -522,6 +562,7 @@ find_end:
|
||||
/**
|
||||
* @brief handle a standard device request
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -617,6 +658,7 @@ static bool usbd_std_device_req_handler(uint8_t busid, struct usb_setup_packet *
|
||||
/**
|
||||
* @brief handle a standard interface request
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -678,8 +720,8 @@ static bool usbd_std_interface_req_handler(uint8_t busid, struct usb_setup_packe
|
||||
}
|
||||
|
||||
/* skip to next descriptor */
|
||||
p += p[DESC_bLength];
|
||||
current_desc_len += p[DESC_bLength];
|
||||
p += p[DESC_bLength];
|
||||
if (current_desc_len >= desc_len && desc_len) {
|
||||
break;
|
||||
}
|
||||
@@ -703,11 +745,12 @@ static bool usbd_std_interface_req_handler(uint8_t busid, struct usb_setup_packe
|
||||
ret = false;
|
||||
break;
|
||||
case USB_REQUEST_GET_INTERFACE:
|
||||
(*data)[0] = 0;
|
||||
(*data)[0] = g_usbd_core[busid].intf_altsetting[intf_num];
|
||||
*len = 1;
|
||||
break;
|
||||
|
||||
case USB_REQUEST_SET_INTERFACE:
|
||||
g_usbd_core[busid].intf_altsetting[intf_num] = LO_BYTE(setup->wValue);
|
||||
usbd_set_interface(busid, setup->wIndex, setup->wValue);
|
||||
*len = 0;
|
||||
break;
|
||||
@@ -723,6 +766,7 @@ static bool usbd_std_interface_req_handler(uint8_t busid, struct usb_setup_packe
|
||||
/**
|
||||
* @brief handle a standard endpoint request
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -787,6 +831,7 @@ static bool usbd_std_endpoint_req_handler(uint8_t busid, struct usb_setup_packet
|
||||
/**
|
||||
* @brief handle standard requests (list in chapter 9)
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -830,8 +875,7 @@ static int usbd_standard_request_handler(uint8_t busid, struct usb_setup_packet
|
||||
/**
|
||||
* @brief handler for class requests
|
||||
*
|
||||
* If a custom request handler was installed, this handler is called first.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -863,8 +907,7 @@ static int usbd_class_request_handler(uint8_t busid, struct usb_setup_packet *se
|
||||
/**
|
||||
* @brief handler for vendor requests
|
||||
*
|
||||
* If a custom request handler was installed, this handler is called first.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -1006,6 +1049,7 @@ static int usbd_vendor_request_handler(uint8_t busid, struct usb_setup_packet *s
|
||||
/**
|
||||
* @brief handle setup request( standard/class/vendor/other)
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -1067,6 +1111,11 @@ static void usbd_class_event_notify_handler(uint8_t busid, uint8_t event, void *
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_event_sof_handler(uint8_t busid)
|
||||
{
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_SOF);
|
||||
}
|
||||
|
||||
void usbd_event_connect_handler(uint8_t busid)
|
||||
{
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_CONNECTED);
|
||||
@@ -1074,6 +1123,7 @@ void usbd_event_connect_handler(uint8_t busid)
|
||||
|
||||
void usbd_event_disconnect_handler(uint8_t busid)
|
||||
{
|
||||
g_usbd_core[busid].configuration = 0;
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_DISCONNECTED);
|
||||
}
|
||||
|
||||
@@ -1096,6 +1146,7 @@ void usbd_event_reset_handler(uint8_t busid)
|
||||
usbd_set_address(busid, 0);
|
||||
g_usbd_core[busid].device_address = 0;
|
||||
g_usbd_core[busid].configuration = 0;
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_SETUP;
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
g_usbd_core[busid].speed = USB_SPEED_UNKNOWN;
|
||||
#endif
|
||||
@@ -1116,12 +1167,10 @@ void usbd_event_reset_handler(uint8_t busid)
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_RESET);
|
||||
}
|
||||
|
||||
void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup)
|
||||
static void __usbd_event_ep0_setup_complete_handler(uint8_t busid, struct usb_setup_packet *setup)
|
||||
{
|
||||
struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
|
||||
uint8_t *buf;
|
||||
|
||||
memcpy(setup, psetup, 8);
|
||||
#ifdef CONFIG_USBDEV_SETUP_LOG_PRINT
|
||||
usbd_print_setup(setup);
|
||||
#endif
|
||||
@@ -1142,12 +1191,14 @@ void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup)
|
||||
/* handle class request when all the data is received */
|
||||
if (setup->wLength && ((setup->bmRequestType & USB_REQUEST_DIR_MASK) == USB_REQUEST_DIR_OUT)) {
|
||||
USB_LOG_DBG("Start reading %d bytes from ep0\r\n", setup->wLength);
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_OUT_DATA;
|
||||
usbd_ep_start_read(busid, USB_CONTROL_OUT_EP0, g_usbd_core[busid].ep0_data_buf, setup->wLength);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Ask installed handler to process request */
|
||||
if (!usbd_setup_request_handler(busid, setup, &buf, &g_usbd_core[busid].ep0_data_buf_len)) {
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_SETUP;
|
||||
usbd_ep_set_stall(busid, USB_CONTROL_IN_EP0);
|
||||
return;
|
||||
}
|
||||
@@ -1156,6 +1207,7 @@ void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup)
|
||||
g_usbd_core[busid].ep0_data_buf_residue = MIN(g_usbd_core[busid].ep0_data_buf_len, setup->wLength);
|
||||
if (g_usbd_core[busid].ep0_data_buf_residue > CONFIG_USBDEV_REQUEST_BUFFER_LEN) {
|
||||
USB_LOG_ERR("Request buffer too small\r\n");
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_SETUP;
|
||||
usbd_ep_set_stall(busid, USB_CONTROL_IN_EP0);
|
||||
return;
|
||||
}
|
||||
@@ -1167,12 +1219,18 @@ void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup)
|
||||
#ifdef CONFIG_USBDEV_EP0_INDATA_NO_COPY
|
||||
g_usbd_core[busid].ep0_data_buf = buf;
|
||||
#else
|
||||
memcpy(g_usbd_core[busid].ep0_data_buf, buf, g_usbd_core[busid].ep0_data_buf_residue);
|
||||
usb_memcpy(g_usbd_core[busid].ep0_data_buf, buf, g_usbd_core[busid].ep0_data_buf_residue);
|
||||
#endif
|
||||
} else {
|
||||
/* use memcpy(*data, xxx, len); has copied into ep0 buffer, we do nothing */
|
||||
}
|
||||
|
||||
if (g_usbd_core[busid].ep0_data_buf_residue > 0) {
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_IN_DATA;
|
||||
} else {
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_IN_STATUS;
|
||||
}
|
||||
|
||||
/* Send data or status to host */
|
||||
usbd_ep_start_write(busid, USB_CONTROL_IN_EP0, g_usbd_core[busid].ep0_data_buf, g_usbd_core[busid].ep0_data_buf_residue);
|
||||
/*
|
||||
@@ -1186,7 +1244,20 @@ void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_event_ep0_in_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup)
|
||||
{
|
||||
struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
|
||||
|
||||
memcpy(setup, psetup, 8);
|
||||
|
||||
#ifdef CONFIG_USBDEV_EP0_THREAD
|
||||
usb_osal_mq_send(g_usbd_core[busid].usbd_ep0_mq, USB_EP0_STATE_SETUP);
|
||||
#else
|
||||
__usbd_event_ep0_setup_complete_handler(busid, setup);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void usbd_event_ep0_in_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
|
||||
|
||||
@@ -1195,7 +1266,7 @@ void usbd_event_ep0_in_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbyt
|
||||
g_usbd_core[busid].ep0_data_buf += nbytes;
|
||||
g_usbd_core[busid].ep0_data_buf_residue -= nbytes;
|
||||
|
||||
USB_LOG_DBG("EP0 send %d bytes, %d remained\r\n", nbytes, g_usbd_core[busid].ep0_data_buf_residue);
|
||||
USB_LOG_DBG("EP0 send %d bytes, %d remained\r\n", (unsigned int)nbytes, (unsigned int)g_usbd_core[busid].ep0_data_buf_residue);
|
||||
|
||||
if (g_usbd_core[busid].ep0_data_buf_residue != 0) {
|
||||
/* Start sending the remain data */
|
||||
@@ -1214,7 +1285,13 @@ void usbd_event_ep0_in_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbyt
|
||||
*/
|
||||
if (setup->wLength && ((setup->bmRequestType & USB_REQUEST_DIR_MASK) == USB_REQUEST_DIR_IN)) {
|
||||
/* if all data has sent completely, start reading out status */
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_OUT_STATUS;
|
||||
usbd_ep_start_read(busid, USB_CONTROL_OUT_EP0, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_usbd_core[busid].ep0_next_state == USBD_EP0_STATE_IN_STATUS) {
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_SETUP;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_TEST_MODE
|
||||
@@ -1227,33 +1304,41 @@ void usbd_event_ep0_in_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbyt
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_event_ep0_out_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
static void usbd_event_ep0_out_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
|
||||
|
||||
(void)ep;
|
||||
(void)setup;
|
||||
|
||||
if (nbytes > 0) {
|
||||
g_usbd_core[busid].ep0_data_buf += nbytes;
|
||||
g_usbd_core[busid].ep0_data_buf_residue -= nbytes;
|
||||
|
||||
USB_LOG_DBG("EP0 recv %d bytes, %d remained\r\n", nbytes, g_usbd_core[busid].ep0_data_buf_residue);
|
||||
USB_LOG_DBG("EP0 recv %d bytes, %d remained\r\n", (unsigned int)nbytes, (unsigned int)g_usbd_core[busid].ep0_data_buf_residue);
|
||||
|
||||
if (g_usbd_core[busid].ep0_data_buf_residue == 0) {
|
||||
#ifdef CONFIG_USBDEV_EP0_THREAD
|
||||
usb_osal_mq_send(g_usbd_core[busid].usbd_ep0_mq, USB_EP0_STATE_OUT);
|
||||
#else
|
||||
/* Received all, send data to handler */
|
||||
g_usbd_core[busid].ep0_data_buf = g_usbd_core[busid].req_data;
|
||||
if (!usbd_setup_request_handler(busid, setup, &g_usbd_core[busid].ep0_data_buf, &g_usbd_core[busid].ep0_data_buf_len)) {
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_SETUP;
|
||||
usbd_ep_set_stall(busid, USB_CONTROL_IN_EP0);
|
||||
return;
|
||||
}
|
||||
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_IN_STATUS;
|
||||
/*Send status to host*/
|
||||
usbd_ep_start_write(busid, USB_CONTROL_IN_EP0, NULL, 0);
|
||||
#endif
|
||||
} else {
|
||||
/* Start reading the remain data */
|
||||
usbd_ep_start_read(busid, USB_CONTROL_OUT_EP0, g_usbd_core[busid].ep0_data_buf, g_usbd_core[busid].ep0_data_buf_residue);
|
||||
}
|
||||
} else {
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_SETUP;
|
||||
/* Read out status completely, do nothing */
|
||||
USB_LOG_DBG("EP0 recv out status\r\n");
|
||||
}
|
||||
@@ -1387,6 +1472,54 @@ int usbd_send_remote_wakeup(uint8_t busid)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t usbd_get_ep0_next_state(uint8_t busid)
|
||||
{
|
||||
return g_usbd_core[busid].ep0_next_state;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_EP0_THREAD
|
||||
static void usbdev_ep0_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
|
||||
{
|
||||
uintptr_t event;
|
||||
int ret;
|
||||
uint8_t busid = (uint8_t)CONFIG_USB_OSAL_THREAD_GET_ARGV;
|
||||
struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
|
||||
|
||||
while (1) {
|
||||
ret = usb_osal_mq_recv(g_usbd_core[busid].usbd_ep0_mq, (uintptr_t *)&event, USB_OSAL_WAITING_FOREVER);
|
||||
if (ret < 0) {
|
||||
continue;
|
||||
}
|
||||
USB_LOG_DBG("event:%d\r\n", (unsigned int)event);
|
||||
|
||||
switch (event) {
|
||||
case USB_EP0_STATE_SETUP:
|
||||
__usbd_event_ep0_setup_complete_handler(busid, setup);
|
||||
break;
|
||||
case USB_EP0_STATE_IN:
|
||||
// do nothing
|
||||
break;
|
||||
case USB_EP0_STATE_OUT:
|
||||
/* Received all, send data to handler */
|
||||
g_usbd_core[busid].ep0_data_buf = g_usbd_core[busid].req_data;
|
||||
if (!usbd_setup_request_handler(busid, setup, &g_usbd_core[busid].ep0_data_buf, &g_usbd_core[busid].ep0_data_buf_len)) {
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_SETUP;
|
||||
usbd_ep_set_stall(busid, USB_CONTROL_IN_EP0);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_IN_STATUS;
|
||||
/*Send status to host*/
|
||||
usbd_ep_start_write(busid, USB_CONTROL_IN_EP0, NULL, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int usbd_initialize(uint8_t busid, uintptr_t reg_base, void (*event_handler)(uint8_t busid, uint8_t event))
|
||||
{
|
||||
int ret;
|
||||
@@ -1401,6 +1534,21 @@ int usbd_initialize(uint8_t busid, uintptr_t reg_base, void (*event_handler)(uin
|
||||
bus = &g_usbdev_bus[busid];
|
||||
bus->reg_base = reg_base;
|
||||
|
||||
#ifdef CONFIG_USBDEV_EP0_THREAD
|
||||
g_usbd_core[busid].usbd_ep0_mq = usb_osal_mq_create(1);
|
||||
if (g_usbd_core[busid].usbd_ep0_mq == NULL) {
|
||||
USB_LOG_ERR("No memory to alloc for g_usbd_core[busid].usbd_ep0_mq\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
g_usbd_core[busid].usbd_ep0_thread = usb_osal_thread_create("usbd_ep0", CONFIG_USBDEV_EP0_STACKSIZE, CONFIG_USBDEV_EP0_PRIO, usbdev_ep0_thread, (void *)(uint32_t)busid);
|
||||
if (g_usbd_core[busid].usbd_ep0_thread == NULL) {
|
||||
USB_LOG_ERR("No memory to alloc for g_usbd_core[busid].usbd_ep0_thread\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
g_usbd_core[busid].event_handler = event_handler;
|
||||
ret = usb_dc_init(busid);
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_INIT, NULL);
|
||||
@@ -1420,5 +1568,14 @@ int usbd_deinitialize(uint8_t busid)
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_DEINIT, NULL);
|
||||
usb_dc_deinit(busid);
|
||||
g_usbd_core[busid].intf_offset = 0;
|
||||
#ifdef CONFIG_USBDEV_EP0_THREAD
|
||||
if (g_usbd_core[busid].usbd_ep0_mq) {
|
||||
usb_osal_mq_delete(g_usbd_core[busid].usbd_ep0_mq);
|
||||
}
|
||||
if (g_usbd_core[busid].usbd_ep0_thread) {
|
||||
usb_osal_thread_delete(g_usbd_core[busid].usbd_ep0_thread);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ extern "C" {
|
||||
#include "usb_list.h"
|
||||
#include "usb_log.h"
|
||||
#include "usb_dc.h"
|
||||
#include "usb_osal.h"
|
||||
#include "usb_memcpy.h"
|
||||
#include "usb_dcache.h"
|
||||
#include "usb_version.h"
|
||||
|
||||
enum usbd_event_type {
|
||||
@@ -45,6 +47,12 @@ enum usbd_event_type {
|
||||
USBD_EVENT_UNKNOWN
|
||||
};
|
||||
|
||||
#define USBD_EP0_STATE_SETUP 0
|
||||
#define USBD_EP0_STATE_IN_DATA 1
|
||||
#define USBD_EP0_STATE_OUT_DATA 2
|
||||
#define USBD_EP0_STATE_IN_STATUS 3
|
||||
#define USBD_EP0_STATE_OUT_STATUS 4
|
||||
|
||||
typedef int (*usbd_request_handler)(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len);
|
||||
typedef void (*usbd_endpoint_callback)(uint8_t busid, uint8_t ep, uint32_t nbytes);
|
||||
typedef void (*usbd_notify_handler)(uint8_t busid, uint8_t event, void *arg);
|
||||
@@ -105,6 +113,7 @@ uint8_t usbd_get_ep_mult(uint8_t busid, uint8_t ep);
|
||||
bool usb_device_is_configured(uint8_t busid);
|
||||
bool usb_device_is_suspend(uint8_t busid);
|
||||
int usbd_send_remote_wakeup(uint8_t busid);
|
||||
uint8_t usbd_get_ep0_next_state(uint8_t busid);
|
||||
|
||||
int usbd_initialize(uint8_t busid, uintptr_t reg_base, void (*event_handler)(uint8_t busid, uint8_t event));
|
||||
int usbd_deinitialize(uint8_t busid);
|
||||
|
||||
115
core/usbh_core.c
115
core/usbh_core.c
@@ -14,8 +14,12 @@ struct usbh_class_info *usbh_class_info_table_end = NULL;
|
||||
|
||||
usb_slist_t g_bus_head = USB_SLIST_OBJECT_INIT(g_bus_head);
|
||||
|
||||
struct setup_align_buffer {
|
||||
uint8_t buffer[USB_ALIGN_UP(8, CONFIG_USB_ALIGN_SIZE)];
|
||||
};
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t ep0_request_buffer[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(CONFIG_USBHOST_REQUEST_BUFFER_LEN, CONFIG_USB_ALIGN_SIZE)];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX struct usb_setup_packet g_setup_buffer[CONFIG_USBHOST_MAX_BUS][CONFIG_USBHOST_MAX_EXTHUBS + 1][CONFIG_USBHOST_MAX_EHPORTS];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX struct setup_align_buffer g_setup_buffer[CONFIG_USBHOST_MAX_BUS][CONFIG_USBHOST_MAX_EXTHUBS + 1][CONFIG_USBHOST_MAX_EHPORTS];
|
||||
|
||||
struct usbh_bus g_usbhost_bus[CONFIG_USBHOST_MAX_BUS];
|
||||
|
||||
@@ -93,19 +97,22 @@ static const struct usbh_class_driver *usbh_find_class_driver(uint8_t class, uin
|
||||
struct usbh_class_info *index = NULL;
|
||||
|
||||
for (index = usbh_class_info_table_begin; index < usbh_class_info_table_end; index++) {
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_CLASS) && !(index->class == class)) {
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_CLASS) && !(index->bInterfaceClass == class)) {
|
||||
continue;
|
||||
}
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_SUBCLASS) && !(index->subclass == subclass)) {
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_SUBCLASS) && !(index->bInterfaceSubClass == subclass)) {
|
||||
continue;
|
||||
}
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_PROTOCOL) && !(index->protocol == protocol)) {
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_PROTOCOL) && !(index->bInterfaceProtocol == protocol)) {
|
||||
continue;
|
||||
}
|
||||
if (index->match_flags & USB_CLASS_MATCH_VID_PID && index->id_table) {
|
||||
/* scan id table */
|
||||
uint32_t i;
|
||||
for (i = 0; index->id_table[i][0] && index->id_table[i][0] != vid && index->id_table[i][1] != pid; i++) {
|
||||
for (i = 0; index->id_table[i][0]; i++) {
|
||||
if (index->id_table[i][0] == vid && index->id_table[i][1] == pid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* do not match, continue next */
|
||||
if (!index->id_table[i][0]) {
|
||||
@@ -220,21 +227,13 @@ static int parse_config_descriptor(struct usbh_hubport *hport, struct usb_config
|
||||
cur_alt_setting = intf_desc->bAlternateSetting;
|
||||
cur_ep_num = intf_desc->bNumEndpoints;
|
||||
cur_ep = 0;
|
||||
if (cur_iface > (CONFIG_USBHOST_MAX_INTERFACES - 1)) {
|
||||
USB_LOG_ERR("Interface num overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
if (cur_alt_setting > (CONFIG_USBHOST_MAX_INTF_ALTSETTINGS - 1)) {
|
||||
USB_LOG_ERR("Interface altsetting num overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
if (cur_ep_num > CONFIG_USBHOST_MAX_ENDPOINTS) {
|
||||
USB_LOG_ERR("Endpoint num overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
USB_ASSERT_MSG(cur_iface < CONFIG_USBHOST_MAX_INTERFACES,
|
||||
"Interface num %d overflow", cur_iface);
|
||||
USB_ASSERT_MSG(cur_alt_setting < CONFIG_USBHOST_MAX_INTF_ALTSETTINGS,
|
||||
"Interface altsetting num %d overflow", cur_alt_setting);
|
||||
USB_ASSERT_MSG(cur_ep_num <= CONFIG_USBHOST_MAX_ENDPOINTS,
|
||||
"Endpoint num %d overflow", cur_ep_num);
|
||||
#if 0
|
||||
USB_LOG_DBG("Interface Descriptor:\r\n");
|
||||
USB_LOG_DBG("bLength: 0x%02x \r\n", intf_desc->bLength);
|
||||
@@ -321,6 +320,19 @@ static void usbh_print_hubport_info(struct usbh_hubport *hport)
|
||||
}
|
||||
}
|
||||
|
||||
static void usbh_print_setup(struct usb_setup_packet *setup)
|
||||
{
|
||||
(void)setup;
|
||||
|
||||
USB_LOG_DBG("Setup: "
|
||||
"bmRequestType 0x%02x, bRequest 0x%02x, wValue 0x%04x, wIndex 0x%04x, wLength 0x%04x\r\n",
|
||||
setup->bmRequestType,
|
||||
setup->bRequest,
|
||||
setup->wValue,
|
||||
setup->wIndex,
|
||||
setup->wLength);
|
||||
}
|
||||
|
||||
static int usbh_get_default_mps(int speed)
|
||||
{
|
||||
switch (speed) {
|
||||
@@ -349,7 +361,7 @@ int usbh_enumerate(struct usbh_hubport *hport)
|
||||
uint8_t config_index;
|
||||
int ret;
|
||||
|
||||
hport->setup = &g_setup_buffer[hport->bus->busid][hport->parent->index - 1][hport->port - 1];
|
||||
hport->setup = (struct usb_setup_packet *)&g_setup_buffer[hport->bus->busid][hport->parent->index - 1][hport->port - 1];
|
||||
setup = hport->setup;
|
||||
ep = &hport->ep0;
|
||||
|
||||
@@ -464,7 +476,7 @@ int usbh_enumerate(struct usbh_hubport *hport)
|
||||
|
||||
if (wTotalLength > CONFIG_USBHOST_REQUEST_BUFFER_LEN) {
|
||||
ret = -USB_ERR_NOMEM;
|
||||
USB_LOG_ERR("wTotalLength %d is overflow, default is %d\r\n", wTotalLength, CONFIG_USBHOST_REQUEST_BUFFER_LEN);
|
||||
USB_LOG_ERR("wTotalLength %d is overflow, default is %d\r\n", wTotalLength, (unsigned int)CONFIG_USBHOST_REQUEST_BUFFER_LEN);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
@@ -671,10 +683,16 @@ int usbh_control_transfer(struct usbh_hubport *hport, struct usb_setup_packet *s
|
||||
struct usbh_urb *urb;
|
||||
int ret;
|
||||
|
||||
if (!hport || !setup) {
|
||||
return -USB_ERR_INVAL;
|
||||
}
|
||||
|
||||
urb = &hport->ep0_urb;
|
||||
|
||||
usb_osal_mutex_take(hport->mutex);
|
||||
|
||||
usbh_print_setup(setup);
|
||||
|
||||
usbh_control_urb_fill(urb, hport, setup, buffer, setup->wLength, CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT, NULL, NULL);
|
||||
ret = usbh_submit_urb(urb);
|
||||
if (ret == 0) {
|
||||
@@ -831,6 +849,42 @@ static void usbh_list_all_interface_desc(struct usbh_bus *bus, struct usbh_hub *
|
||||
}
|
||||
}
|
||||
|
||||
static struct usbh_hubport *usbh_list_all_hubport(struct usbh_hub *hub, uint8_t hub_index, uint8_t hub_port)
|
||||
{
|
||||
struct usbh_hubport *hport;
|
||||
struct usbh_hub *hub_next;
|
||||
|
||||
if (hub->index == hub_index) {
|
||||
hport = &hub->child[hub_port - 1];
|
||||
if (hport->connected) {
|
||||
return hport;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
hport = &hub->child[port];
|
||||
if (hport->connected) {
|
||||
for (uint8_t itf = 0; itf < hport->config.config_desc.bNumInterfaces; itf++) {
|
||||
if (hport->config.intf[itf].class_driver && hport->config.intf[itf].class_driver->driver_name) {
|
||||
if (strcmp(hport->config.intf[itf].class_driver->driver_name, "hub") == 0) {
|
||||
hub_next = hport->config.intf[itf].priv;
|
||||
|
||||
if (hub_next && hub_next->connected) {
|
||||
hport = usbh_list_all_hubport(hub_next, hub_index, hub_port);
|
||||
if (hport) {
|
||||
return hport;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *usbh_find_class_instance(const char *devname)
|
||||
{
|
||||
usb_slist_t *bus_list;
|
||||
@@ -855,6 +909,23 @@ void *usbh_find_class_instance(const char *devname)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct usbh_hubport *usbh_find_hubport(uint8_t busid, uint8_t hub_index, uint8_t hub_port)
|
||||
{
|
||||
struct usbh_hub *hub;
|
||||
struct usbh_bus *bus;
|
||||
struct usbh_hubport *hport;
|
||||
size_t flags;
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
|
||||
bus = &g_usbhost_bus[busid];
|
||||
hub = &bus->hcd.roothub;
|
||||
|
||||
hport = usbh_list_all_hubport(hub, hub_index, hub_port);
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return hport;
|
||||
}
|
||||
|
||||
int lsusb(int argc, char **argv)
|
||||
{
|
||||
usb_slist_t *bus_list;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "usb_osal.h"
|
||||
#include "usbh_hub.h"
|
||||
#include "usb_memcpy.h"
|
||||
#include "usb_dcache.h"
|
||||
#include "usb_version.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -61,9 +62,9 @@ extern "C" {
|
||||
|
||||
struct usbh_class_info {
|
||||
uint8_t match_flags; /* Used for product specific matches; range is inclusive */
|
||||
uint8_t class; /* Base device class code */
|
||||
uint8_t subclass; /* Sub-class, depends on base class. Eg. */
|
||||
uint8_t protocol; /* Protocol, depends on base class. Eg. */
|
||||
uint8_t bInterfaceClass; /* Base device class code */
|
||||
uint8_t bInterfaceSubClass; /* Sub-class, depends on base class. Eg. */
|
||||
uint8_t bInterfaceProtocol; /* Protocol, depends on base class. Eg. */
|
||||
const uint16_t (*id_table)[2]; /* List of Vendor/Product ID pairs */
|
||||
const struct usbh_class_driver *class_driver;
|
||||
};
|
||||
@@ -275,6 +276,7 @@ int usbh_set_interface(struct usbh_hubport *hport, uint8_t intf, uint8_t altsett
|
||||
int usbh_initialize(uint8_t busid, uintptr_t reg_base);
|
||||
int usbh_deinitialize(uint8_t busid);
|
||||
void *usbh_find_class_instance(const char *devname);
|
||||
struct usbh_hubport *usbh_find_hubport(uint8_t busid, uint8_t hub_index, uint8_t hub_port);
|
||||
|
||||
int lsusb(int argc, char **argv);
|
||||
|
||||
|
||||
137
core/usbotg_core.c
Normal file
137
core/usbotg_core.c
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2025, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbotg_core.h"
|
||||
|
||||
struct usbotg_core_priv {
|
||||
uint8_t busid;
|
||||
uint32_t reg_base;
|
||||
usb_osal_sem_t change_sem;
|
||||
usb_osal_thread_t change_thread;
|
||||
bool usbh_initialized;
|
||||
bool usbd_initialized;
|
||||
int (*usbh_initialize)(uint8_t busid, uint32_t reg_base);
|
||||
int (*usbd_initialize)(uint8_t busid, uint32_t reg_base);
|
||||
} g_usbotg_core[CONFIG_USBHOST_MAX_BUS];
|
||||
|
||||
static void usbotg_host_initialize(uint8_t busid)
|
||||
{
|
||||
if (g_usbotg_core[busid].usbd_initialized) {
|
||||
g_usbotg_core[busid].usbd_initialized = false;
|
||||
usbd_deinitialize(busid);
|
||||
}
|
||||
if (g_usbotg_core[busid].usbh_initialize && !g_usbotg_core[busid].usbh_initialized) {
|
||||
g_usbotg_core[busid].usbh_initialized = true;
|
||||
g_usbotg_core[busid].usbh_initialize(g_usbotg_core[busid].busid, g_usbotg_core[busid].reg_base);
|
||||
}
|
||||
}
|
||||
|
||||
static void usbotg_device_initialize(uint8_t busid)
|
||||
{
|
||||
if (g_usbotg_core[busid].usbh_initialized) {
|
||||
g_usbotg_core[busid].usbh_initialized = false;
|
||||
usbh_deinitialize(busid);
|
||||
}
|
||||
if (g_usbotg_core[busid].usbd_initialize && !g_usbotg_core[busid].usbd_initialize) {
|
||||
g_usbotg_core[busid].usbd_initialized = true;
|
||||
g_usbotg_core[busid].usbd_initialize(g_usbotg_core[busid].busid, g_usbotg_core[busid].reg_base);
|
||||
}
|
||||
}
|
||||
|
||||
static void usbotg_rolechange_thread(void *argument)
|
||||
{
|
||||
uint8_t busid = (uint8_t)(uintptr_t)argument;
|
||||
|
||||
usb_otg_init(busid);
|
||||
|
||||
while (1) {
|
||||
if (usb_osal_sem_take(g_usbotg_core[busid].change_sem, USB_OSAL_WAITING_FOREVER) == 0) {
|
||||
if (usbotg_get_current_mode(busid) == USBOTG_MODE_HOST) {
|
||||
usbotg_host_initialize(busid);
|
||||
} else if (usbotg_get_current_mode(busid) == USBOTG_MODE_DEVICE) {
|
||||
usbotg_device_initialize(busid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int usbotg_initialize(uint8_t otg_mode, uint8_t busid, uint32_t reg_base,
|
||||
int (*usbh_initialize)(uint8_t busid, uint32_t reg_base),
|
||||
int (*usbd_initialize)(uint8_t busid, uint32_t reg_base))
|
||||
{
|
||||
char thread_name[32] = { 0 };
|
||||
|
||||
if (busid >= CONFIG_USBHOST_MAX_BUS) {
|
||||
USB_LOG_ERR("bus overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
g_usbotg_core[busid].busid = busid;
|
||||
g_usbotg_core[busid].reg_base = reg_base;
|
||||
g_usbotg_core[busid].usbh_initialize = usbh_initialize;
|
||||
g_usbotg_core[busid].usbd_initialize = usbd_initialize;
|
||||
|
||||
if (otg_mode == USBOTG_MODE_OTG) {
|
||||
g_usbotg_core[busid].change_sem = usb_osal_sem_create(0);
|
||||
if (g_usbotg_core[busid].change_sem == NULL) {
|
||||
USB_LOG_ERR("Failed to create change_sem\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
snprintf(thread_name, 32, "usbotg%u", busid);
|
||||
g_usbotg_core[busid].change_thread = usb_osal_thread_create(thread_name, CONFIG_USBHOST_PSC_STACKSIZE, CONFIG_USBHOST_PSC_PRIO, usbotg_rolechange_thread, (void *)(uintptr_t)busid);
|
||||
if (g_usbotg_core[busid].change_thread == NULL) {
|
||||
USB_LOG_ERR("Failed to create usbotg thread\r\n");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (otg_mode == USBOTG_MODE_HOST) {
|
||||
usbotg_host_initialize(busid);
|
||||
} else if (otg_mode == USBOTG_MODE_DEVICE) {
|
||||
usbotg_device_initialize(busid);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbotg_deinitialize(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
if (g_usbotg_core[busid].usbd_initialized) {
|
||||
g_usbotg_core[busid].usbd_initialized = false;
|
||||
usbd_deinitialize(busid);
|
||||
}
|
||||
|
||||
if (g_usbotg_core[busid].usbh_initialized) {
|
||||
g_usbotg_core[busid].usbh_initialized = false;
|
||||
usbh_deinitialize(busid);
|
||||
}
|
||||
|
||||
if (g_usbotg_core[busid].change_sem) {
|
||||
usb_otg_deinit(busid);
|
||||
usb_osal_sem_delete(g_usbotg_core[busid].change_sem);
|
||||
}
|
||||
|
||||
if (g_usbotg_core[busid].change_thread) {
|
||||
usb_osal_thread_delete(g_usbotg_core[busid].change_thread);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usbotg_trigger_role_change(uint8_t busid)
|
||||
{
|
||||
usb_osal_sem_give(g_usbotg_core[busid].change_sem);
|
||||
}
|
||||
|
||||
void USBOTG_IRQHandler(uint8_t busid)
|
||||
{
|
||||
if (usbotg_get_current_mode(busid) == USBOTG_MODE_HOST) {
|
||||
USBH_IRQHandler(busid);
|
||||
} else if (usbotg_get_current_mode(busid) == USBOTG_MODE_DEVICE) {
|
||||
USBD_IRQHandler(busid);
|
||||
}
|
||||
}
|
||||
34
core/usbotg_core.h
Normal file
34
core/usbotg_core.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2025, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USBOTG_CORE_H
|
||||
#define USBOTG_CORE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define USBOTG_MODE_UNKNOWN 0
|
||||
#define USBOTG_MODE_OTG 1
|
||||
#define USBOTG_MODE_HOST 2
|
||||
#define USBOTG_MODE_DEVICE 3
|
||||
|
||||
#include "usbd_core.h"
|
||||
#include "usbh_core.h"
|
||||
#include "usb_otg.h"
|
||||
|
||||
int usbotg_initialize(uint8_t otg_mode, uint8_t busid, uint32_t reg_base,
|
||||
int (*usbh_initialize)(uint8_t busid, uint32_t reg_base),
|
||||
int (*usbd_initialize)(uint8_t busid, uint32_t reg_base));
|
||||
int usbotg_deinitialize(uint8_t busid, uint32_t reg_base);
|
||||
|
||||
/* called by user */
|
||||
void usbotg_trigger_role_change(uint8_t busid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBOTG_CORE_H */
|
||||
@@ -108,6 +108,70 @@ struct usb_msosv1_descriptor msosv1_desc = {
|
||||
.comp_id_property = WINUSB_IFx_WCIDProperties,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0100, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
ADB_DESCRIPTOR_INIT(ADB_INTF_NUM, WINUSB_IN_EP, WINUSB_OUT_EP, WINUSB_MAX_MPS)
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryADB", /* Product */
|
||||
"CherryADB2024", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor msc_bootuf2_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback,
|
||||
.msosv1_descriptor = &msosv1_desc
|
||||
};
|
||||
#else
|
||||
/*!< global descriptor */
|
||||
static const uint8_t adb_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0100, 0x01),
|
||||
@@ -171,15 +235,16 @@ static const uint8_t adb_descriptor[] = {
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x02,
|
||||
0x02,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
@@ -222,7 +287,14 @@ void cherryadb_init(uint8_t busid, uint32_t reg_base)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &adb_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, adb_descriptor);
|
||||
#endif
|
||||
#ifndef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_msosv1_desc_register(busid, &msosv1_desc);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_adb_init_intf(busid, &intf0, WINUSB_IN_EP, WINUSB_OUT_EP));
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
@@ -68,6 +68,73 @@
|
||||
AUDIO_SIZEOF_AC_FEATURE_UNIT_DESC(IN_CHANNEL_NUM, 1) + \
|
||||
AUDIO_SIZEOF_AC_OUTPUT_TERMINAL_DESC)
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xef, 0x02, 0x01, USBD_VID, USBD_PID, 0x0001, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_AUDIO_CONFIG_DESC_SIZ, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
AUDIO_AC_DESCRIPTOR_INIT(0x00, 0x02, AUDIO_AC_SIZ, 0x00, 0x01),
|
||||
AUDIO_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(0x01, AUDIO_INTERM_MIC, IN_CHANNEL_NUM, INPUT_CH_ENABLE),
|
||||
AUDIO_AC_FEATURE_UNIT_DESCRIPTOR_INIT(AUDIO_IN_FU_ID, 0x01, 0x01, INPUT_CTRL),
|
||||
AUDIO_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(0x03, AUDIO_TERMINAL_STREAMING, AUDIO_IN_FU_ID),
|
||||
AUDIO_AS_DESCRIPTOR_INIT(0x01, 0x03, IN_CHANNEL_NUM, 2, 16, AUDIO_IN_EP, 0x05, AUDIO_IN_PACKET, EP_INTERVAL, AUDIO_SAMPLE_FREQ_3B(AUDIO_FREQ))
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB UAC DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor audio_v1_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
const uint8_t audio_v1_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xef, 0x02, 0x01, USBD_VID, USBD_PID, 0x0001, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_AUDIO_CONFIG_DESC_SIZ, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -125,12 +192,12 @@ const uint8_t audio_v1_descriptor[] = {
|
||||
'2', 0x00, /* wcChar0 */
|
||||
'0', 0x00, /* wcChar1 */
|
||||
'2', 0x00, /* wcChar2 */
|
||||
'1', 0x00, /* wcChar3 */
|
||||
'0', 0x00, /* wcChar4 */
|
||||
'3', 0x00, /* wcChar5 */
|
||||
'1', 0x00, /* wcChar6 */
|
||||
'0', 0x00, /* wcChar7 */
|
||||
'0', 0x00, /* wcChar8 */
|
||||
'2', 0x00, /* wcChar3 */
|
||||
'1', 0x00, /* wcChar4 */
|
||||
'2', 0x00, /* wcChar5 */
|
||||
'3', 0x00, /* wcChar6 */
|
||||
'4', 0x00, /* wcChar7 */
|
||||
'5', 0x00, /* wcChar8 */
|
||||
'0' + IN_CHANNEL_NUM, 0x00, /* wcChar9 */
|
||||
#ifdef CONFIG_USB_HS
|
||||
///////////////////////////////////////
|
||||
@@ -149,9 +216,11 @@ const uint8_t audio_v1_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
volatile bool tx_flag = 0;
|
||||
volatile bool ep_tx_busy_flag = false;
|
||||
volatile uint32_t s_mic_sample_rate;
|
||||
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
@@ -192,9 +261,29 @@ void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
tx_flag = 0;
|
||||
}
|
||||
|
||||
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
|
||||
{
|
||||
if (ep == AUDIO_IN_EP) {
|
||||
s_mic_sample_rate = sampling_freq;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep)
|
||||
{
|
||||
(void)busid;
|
||||
|
||||
uint32_t freq = 0;
|
||||
|
||||
if (ep == AUDIO_IN_EP) {
|
||||
freq = s_mic_sample_rate;
|
||||
}
|
||||
|
||||
return freq;
|
||||
}
|
||||
|
||||
void usbd_audio_iso_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
|
||||
@@ -214,7 +303,11 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
|
||||
void audio_v1_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &audio_v1_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, audio_v1_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf0, 0x0100, audio_entity_table, 1));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf1, 0x0100, audio_entity_table, 1));
|
||||
usbd_add_endpoint(busid, &audio_in_ep);
|
||||
|
||||
@@ -6,19 +6,24 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_audio.h"
|
||||
|
||||
#define USING_FEEDBACK 0
|
||||
|
||||
#define USBD_VID 0xffff
|
||||
#define USBD_PID 0xffff
|
||||
#define USBD_MAX_POWER 100
|
||||
#define USBD_LANGID_STRING 1033
|
||||
|
||||
#ifdef CONFIG_USB_HS
|
||||
#define EP_INTERVAL 0x04
|
||||
#define EP_INTERVAL 0x04
|
||||
#define FEEDBACK_ENDP_PACKET_SIZE 0x04
|
||||
#else
|
||||
#define EP_INTERVAL 0x01
|
||||
#define EP_INTERVAL 0x01
|
||||
#define FEEDBACK_ENDP_PACKET_SIZE 0x03
|
||||
#endif
|
||||
|
||||
#define AUDIO_IN_EP 0x81
|
||||
#define AUDIO_OUT_EP 0x02
|
||||
#define AUDIO_OUT_FEEDBACK_EP 0x83
|
||||
|
||||
#define AUDIO_IN_FU_ID 0x02
|
||||
#define AUDIO_OUT_FU_ID 0x05
|
||||
@@ -38,6 +43,7 @@
|
||||
/* 16bit(2 Bytes) 双声道(Mono:2) */
|
||||
#define AUDIO_IN_PACKET ((uint32_t)((AUDIO_MIC_FREQ * AUDIO_MIC_FRAME_SIZE_BYTE * 2) / 1000))
|
||||
|
||||
#if USING_FEEDBACK == 0
|
||||
#define USB_AUDIO_CONFIG_DESC_SIZ (unsigned long)(9 + \
|
||||
AUDIO_AC_DESCRIPTOR_INIT_LEN(2) + \
|
||||
AUDIO_SIZEOF_AC_INPUT_TERMINAL_DESC + \
|
||||
@@ -48,6 +54,18 @@
|
||||
AUDIO_SIZEOF_AC_OUTPUT_TERMINAL_DESC + \
|
||||
AUDIO_AS_DESCRIPTOR_INIT_LEN(1) + \
|
||||
AUDIO_AS_DESCRIPTOR_INIT_LEN(1))
|
||||
#else
|
||||
#define USB_AUDIO_CONFIG_DESC_SIZ (unsigned long)(9 + \
|
||||
AUDIO_AC_DESCRIPTOR_INIT_LEN(2) + \
|
||||
AUDIO_SIZEOF_AC_INPUT_TERMINAL_DESC + \
|
||||
AUDIO_SIZEOF_AC_FEATURE_UNIT_DESC(2, 1) + \
|
||||
AUDIO_SIZEOF_AC_OUTPUT_TERMINAL_DESC + \
|
||||
AUDIO_SIZEOF_AC_INPUT_TERMINAL_DESC + \
|
||||
AUDIO_SIZEOF_AC_FEATURE_UNIT_DESC(2, 1) + \
|
||||
AUDIO_SIZEOF_AC_OUTPUT_TERMINAL_DESC + \
|
||||
AUDIO_AS_DESCRIPTOR_INIT_LEN(1) + \
|
||||
AUDIO_AS_FEEDBACK_DESCRIPTOR_INIT_LEN(1))
|
||||
#endif
|
||||
|
||||
#define AUDIO_AC_SIZ (AUDIO_SIZEOF_AC_HEADER_DESC(2) + \
|
||||
AUDIO_SIZEOF_AC_INPUT_TERMINAL_DESC + \
|
||||
@@ -57,6 +75,84 @@
|
||||
AUDIO_SIZEOF_AC_FEATURE_UNIT_DESC(2, 1) + \
|
||||
AUDIO_SIZEOF_AC_OUTPUT_TERMINAL_DESC)
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xef, 0x02, 0x01, USBD_VID, USBD_PID, 0x0001, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_AUDIO_CONFIG_DESC_SIZ, 0x03, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
AUDIO_AC_DESCRIPTOR_INIT(0x00, 0x03, AUDIO_AC_SIZ, 0x00, 0x01, 0x02),
|
||||
AUDIO_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(0x01, AUDIO_INTERM_MIC, 0x02, 0x0003),
|
||||
AUDIO_AC_FEATURE_UNIT_DESCRIPTOR_INIT(0x02, 0x01, 0x01, 0x03, 0x00, 0x00),
|
||||
AUDIO_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(0x03, AUDIO_TERMINAL_STREAMING, 0x02),
|
||||
AUDIO_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(0x04, AUDIO_TERMINAL_STREAMING, 0x02, 0x0003),
|
||||
AUDIO_AC_FEATURE_UNIT_DESCRIPTOR_INIT(0x05, 0x04, 0x01, 0x03, 0x00, 0x00),
|
||||
AUDIO_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(0x06, AUDIO_OUTTERM_SPEAKER, 0x05),
|
||||
#if USING_FEEDBACK == 0
|
||||
AUDIO_AS_DESCRIPTOR_INIT(0x01, 0x04, 0x02, AUDIO_SPEAKER_FRAME_SIZE_BYTE, AUDIO_SPEAKER_RESOLUTION_BIT, AUDIO_OUT_EP, 0x09, AUDIO_OUT_PACKET,
|
||||
EP_INTERVAL, AUDIO_SAMPLE_FREQ_3B(AUDIO_SPEAKER_FREQ)),
|
||||
#else
|
||||
AUDIO_AS_FEEDBACK_DESCRIPTOR_INIT(0x01, 0x04, 0x02, AUDIO_SPEAKER_FRAME_SIZE_BYTE, AUDIO_SPEAKER_RESOLUTION_BIT, AUDIO_OUT_EP, AUDIO_OUT_PACKET,
|
||||
EP_INTERVAL, AUDIO_OUT_FEEDBACK_EP, AUDIO_SAMPLE_FREQ_3B(AUDIO_SPEAKER_FREQ)),
|
||||
#endif
|
||||
AUDIO_AS_DESCRIPTOR_INIT(0x02, 0x03, 0x02, AUDIO_MIC_FRAME_SIZE_BYTE, AUDIO_MIC_RESOLUTION_BIT, AUDIO_IN_EP, 0x05, AUDIO_IN_PACKET,
|
||||
EP_INTERVAL, AUDIO_SAMPLE_FREQ_3B(AUDIO_MIC_FREQ))
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB UAC DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor audio_v1_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
const uint8_t audio_v1_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xef, 0x02, 0x01, USBD_VID, USBD_PID, 0x0001, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_AUDIO_CONFIG_DESC_SIZ, 0x03, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -67,8 +163,13 @@ const uint8_t audio_v1_descriptor[] = {
|
||||
AUDIO_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(0x04, AUDIO_TERMINAL_STREAMING, 0x02, 0x0003),
|
||||
AUDIO_AC_FEATURE_UNIT_DESCRIPTOR_INIT(0x05, 0x04, 0x01, 0x03, 0x00, 0x00),
|
||||
AUDIO_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(0x06, AUDIO_OUTTERM_SPEAKER, 0x05),
|
||||
#if USING_FEEDBACK == 0
|
||||
AUDIO_AS_DESCRIPTOR_INIT(0x01, 0x04, 0x02, AUDIO_SPEAKER_FRAME_SIZE_BYTE, AUDIO_SPEAKER_RESOLUTION_BIT, AUDIO_OUT_EP, 0x09, AUDIO_OUT_PACKET,
|
||||
EP_INTERVAL, AUDIO_SAMPLE_FREQ_3B(AUDIO_SPEAKER_FREQ)),
|
||||
#else
|
||||
AUDIO_AS_FEEDBACK_DESCRIPTOR_INIT(0x01, 0x04, 0x02, AUDIO_SPEAKER_FRAME_SIZE_BYTE, AUDIO_SPEAKER_RESOLUTION_BIT, AUDIO_OUT_EP, AUDIO_OUT_PACKET,
|
||||
EP_INTERVAL, AUDIO_OUT_FEEDBACK_EP, AUDIO_SAMPLE_FREQ_3B(AUDIO_SPEAKER_FREQ)),
|
||||
#endif
|
||||
AUDIO_AS_DESCRIPTOR_INIT(0x02, 0x03, 0x02, AUDIO_MIC_FRAME_SIZE_BYTE, AUDIO_MIC_RESOLUTION_BIT, AUDIO_IN_EP, 0x05, AUDIO_IN_PACKET,
|
||||
EP_INTERVAL, AUDIO_SAMPLE_FREQ_3B(AUDIO_MIC_FREQ)),
|
||||
///////////////////////////////////////
|
||||
@@ -120,13 +221,17 @@ const uint8_t audio_v1_descriptor[] = {
|
||||
'2', 0x00, /* wcChar0 */
|
||||
'0', 0x00, /* wcChar1 */
|
||||
'2', 0x00, /* wcChar2 */
|
||||
'1', 0x00, /* wcChar3 */
|
||||
'0', 0x00, /* wcChar4 */
|
||||
'3', 0x00, /* wcChar5 */
|
||||
'1', 0x00, /* wcChar6 */
|
||||
'0', 0x00, /* wcChar7 */
|
||||
'0', 0x00, /* wcChar8 */
|
||||
'2', 0x00, /* wcChar3 */
|
||||
'1', 0x00, /* wcChar4 */
|
||||
'2', 0x00, /* wcChar5 */
|
||||
'3', 0x00, /* wcChar6 */
|
||||
'4', 0x00, /* wcChar7 */
|
||||
'5', 0x00, /* wcChar8 */
|
||||
#if USING_FEEDBACK == 0
|
||||
'1', 0x00, /* wcChar9 */
|
||||
#else
|
||||
'2', 0x00, /* wcChar9 */
|
||||
#endif
|
||||
#ifdef CONFIG_USB_HS
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
@@ -144,13 +249,17 @@ const uint8_t audio_v1_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[AUDIO_OUT_PACKET];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[AUDIO_IN_PACKET];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t s_speaker_feedback_buffer[4];
|
||||
|
||||
volatile bool tx_flag = 0;
|
||||
volatile bool rx_flag = 0;
|
||||
volatile bool ep_tx_busy_flag = false;
|
||||
volatile uint32_t s_mic_sample_rate;
|
||||
volatile uint32_t s_speaker_sample_rate;
|
||||
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
@@ -183,6 +292,11 @@ void usbd_audio_open(uint8_t busid, uint8_t intf)
|
||||
rx_flag = 1;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
#if USING_FEEDBACK == 1
|
||||
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate);
|
||||
AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value); /* uac1 can only use 10.14 */
|
||||
usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);
|
||||
#endif
|
||||
printf("OPEN1\r\n");
|
||||
} else {
|
||||
tx_flag = 1;
|
||||
@@ -203,18 +317,52 @@ void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
|
||||
{
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
s_speaker_sample_rate = sampling_freq;
|
||||
} else if (ep == AUDIO_IN_EP) {
|
||||
s_mic_sample_rate = sampling_freq;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep)
|
||||
{
|
||||
(void)busid;
|
||||
|
||||
uint32_t freq = 0;
|
||||
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
freq = s_speaker_sample_rate;
|
||||
} else if (ep == AUDIO_IN_EP) {
|
||||
freq = s_mic_sample_rate;
|
||||
}
|
||||
|
||||
return freq;
|
||||
}
|
||||
|
||||
void usbd_audio_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
void usbd_audio_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
|
||||
#if USING_FEEDBACK == 1
|
||||
void usbd_audio_iso_out_feedback_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual feedback len:%d\r\n", (unsigned int)nbytes);
|
||||
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate);
|
||||
AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value);
|
||||
usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct usbd_endpoint audio_in_ep = {
|
||||
.ep_cb = usbd_audio_in_callback,
|
||||
.ep_addr = AUDIO_IN_EP
|
||||
@@ -225,6 +373,13 @@ static struct usbd_endpoint audio_out_ep = {
|
||||
.ep_addr = AUDIO_OUT_EP
|
||||
};
|
||||
|
||||
#if USING_FEEDBACK == 1
|
||||
static struct usbd_endpoint audio_out_feedback_ep = {
|
||||
.ep_cb = usbd_audio_iso_out_feedback_callback,
|
||||
.ep_addr = AUDIO_OUT_FEEDBACK_EP
|
||||
};
|
||||
#endif
|
||||
|
||||
struct usbd_interface intf0;
|
||||
struct usbd_interface intf1;
|
||||
struct usbd_interface intf2;
|
||||
@@ -240,13 +395,19 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
|
||||
void audio_v1_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &audio_v1_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, audio_v1_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf0, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf1, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf2, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_endpoint(busid, &audio_in_ep);
|
||||
usbd_add_endpoint(busid, &audio_out_ep);
|
||||
|
||||
#if USING_FEEDBACK == 1
|
||||
usbd_add_endpoint(busid, &audio_out_feedback_ep);
|
||||
#endif
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
#define AUDIO_IN_CLOCK_ID 0x01
|
||||
#define AUDIO_IN_FU_ID 0x03
|
||||
|
||||
#define AUDIO_FREQ 48000
|
||||
#define HALF_WORD_BYTES 2 //2 half word (one channel)
|
||||
#define SAMPLE_BITS 16 //16 bit per channel
|
||||
#define AUDIO_IN_MAX_FREQ 16000
|
||||
#define HALF_WORD_BYTES 2 //2 half word (one channel)
|
||||
#define SAMPLE_BITS 16 //16 bit per channel
|
||||
|
||||
#define BMCONTROL (AUDIO_V2_FU_CONTROL_MUTE | AUDIO_V2_FU_CONTROL_VOLUME)
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
#define INPUT_CH_ENABLE 0x000000ff
|
||||
#endif
|
||||
|
||||
#define AUDIO_IN_PACKET ((uint32_t)((AUDIO_FREQ * HALF_WORD_BYTES * IN_CHANNEL_NUM) / 1000))
|
||||
#define AUDIO_IN_PACKET ((uint32_t)((AUDIO_IN_MAX_FREQ * HALF_WORD_BYTES * IN_CHANNEL_NUM) / 1000))
|
||||
|
||||
#define USB_AUDIO_CONFIG_DESC_SIZ (9 + \
|
||||
AUDIO_V2_AC_DESCRIPTOR_INIT_LEN + \
|
||||
@@ -72,6 +72,74 @@
|
||||
AUDIO_V2_SIZEOF_AC_FEATURE_UNIT_DESC(IN_CHANNEL_NUM) + \
|
||||
AUDIO_V2_SIZEOF_AC_OUTPUT_TERMINAL_DESC)
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_AUDIO_CONFIG_DESC_SIZ, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
AUDIO_V2_AC_DESCRIPTOR_INIT(0x00, 0x02, AUDIO_AC_SIZ, AUDIO_CATEGORY_MICROPHONE, 0x00, 0x00),
|
||||
AUDIO_V2_AC_CLOCK_SOURCE_DESCRIPTOR_INIT(0x01, 0x03, 0x03),
|
||||
AUDIO_V2_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(0x02, AUDIO_INTERM_MIC, 0x01, IN_CHANNEL_NUM, INPUT_CH_ENABLE, 0x0000),
|
||||
AUDIO_V2_AC_FEATURE_UNIT_DESCRIPTOR_INIT(0x03, 0x02, INPUT_CTRL),
|
||||
AUDIO_V2_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(0x04, AUDIO_TERMINAL_STREAMING, 0x03, 0x01, 0x0000),
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT(0x01, 0x04, IN_CHANNEL_NUM, INPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_IN_EP, 0x05, (AUDIO_IN_PACKET + 4), EP_INTERVAL)
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB UAC DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor audio_v2_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
const uint8_t audio_v2_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_AUDIO_CONFIG_DESC_SIZ, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -154,6 +222,7 @@ const uint8_t audio_v2_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
static const uint8_t mic_default_sampling_freq_table[] = {
|
||||
AUDIO_SAMPLE_FREQ_NUM(1),
|
||||
@@ -162,7 +231,11 @@ static const uint8_t mic_default_sampling_freq_table[] = {
|
||||
AUDIO_SAMPLE_FREQ_4B(0x00)
|
||||
};
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[AUDIO_IN_PACKET];
|
||||
|
||||
volatile bool tx_flag = 0;
|
||||
volatile bool ep_tx_busy_flag = false;
|
||||
volatile uint32_t s_mic_sample_rate;
|
||||
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
@@ -201,6 +274,26 @@ void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
tx_flag = 0;
|
||||
}
|
||||
|
||||
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
|
||||
{
|
||||
if (ep == AUDIO_IN_EP) {
|
||||
s_mic_sample_rate = sampling_freq;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep)
|
||||
{
|
||||
(void)busid;
|
||||
|
||||
uint32_t freq = 0;
|
||||
|
||||
if (ep == AUDIO_IN_EP) {
|
||||
freq = s_mic_sample_rate;
|
||||
}
|
||||
|
||||
return freq;
|
||||
}
|
||||
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table)
|
||||
{
|
||||
if (ep == AUDIO_IN_EP) {
|
||||
@@ -210,6 +303,7 @@ void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sam
|
||||
|
||||
void usbd_audio_iso_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
|
||||
static struct usbd_endpoint audio_in_ep = {
|
||||
@@ -231,7 +325,11 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
|
||||
void audio_v2_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &audio_v2_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, audio_v2_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf0, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf1, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_endpoint(busid, &audio_in_ep);
|
||||
@@ -242,5 +340,13 @@ void audio_v2_init(uint8_t busid, uintptr_t reg_base)
|
||||
void audio_v2_test(uint8_t busid)
|
||||
{
|
||||
if (tx_flag) {
|
||||
memset(write_buffer, 'a', AUDIO_IN_PACKET);
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(busid, AUDIO_IN_EP, write_buffer, AUDIO_IN_PACKET);
|
||||
while (ep_tx_busy_flag) {
|
||||
if (tx_flag == false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,26 +6,33 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_audio.h"
|
||||
|
||||
#define USING_FEEDBACK 0
|
||||
|
||||
#define USBD_VID 0xffff
|
||||
#define USBD_PID 0xffff
|
||||
#define USBD_MAX_POWER 100
|
||||
#define USBD_LANGID_STRING 1033
|
||||
|
||||
#ifdef CONFIG_USB_HS
|
||||
#define EP_INTERVAL 0x04
|
||||
#define EP_INTERVAL 0x04
|
||||
#define FEEDBACK_ENDP_PACKET_SIZE 0x04
|
||||
#else
|
||||
#define EP_INTERVAL 0x01
|
||||
#define EP_INTERVAL 0x01
|
||||
#define FEEDBACK_ENDP_PACKET_SIZE 0x03
|
||||
#endif
|
||||
|
||||
#define AUDIO_OUT_EP 0x02
|
||||
#define AUDIO_IN_EP 0x81
|
||||
#define AUDIO_OUT_EP 0x02
|
||||
#define AUDIO_IN_EP 0x81
|
||||
#define AUDIO_OUT_FEEDBACK_EP 0x83
|
||||
|
||||
#define AUDIO_OUT_CLOCK_ID 0x01
|
||||
#define AUDIO_OUT_FU_ID 0x03
|
||||
#define AUDIO_IN_CLOCK_ID 0x05
|
||||
#define AUDIO_IN_FU_ID 0x07
|
||||
|
||||
#define AUDIO_FREQ 48000
|
||||
#define AUDIO_OUT_MAX_FREQ 96000
|
||||
#define AUDIO_IN_MAX_FREQ 16000
|
||||
|
||||
#define HALF_WORD_BYTES 2 //2 half word (one channel)
|
||||
#define SAMPLE_BITS 16 //16 bit per channel
|
||||
|
||||
@@ -88,9 +95,10 @@
|
||||
#endif
|
||||
|
||||
/* AudioFreq * DataSize (2 bytes) * NumChannels */
|
||||
#define AUDIO_OUT_PACKET ((uint32_t)((AUDIO_FREQ * HALF_WORD_BYTES * OUT_CHANNEL_NUM) / 1000))
|
||||
#define AUDIO_IN_PACKET ((uint32_t)((AUDIO_FREQ * HALF_WORD_BYTES * IN_CHANNEL_NUM) / 1000))
|
||||
#define AUDIO_OUT_PACKET ((uint32_t)((AUDIO_OUT_MAX_FREQ * HALF_WORD_BYTES * OUT_CHANNEL_NUM) / 1000))
|
||||
#define AUDIO_IN_PACKET ((uint32_t)((AUDIO_IN_MAX_FREQ * HALF_WORD_BYTES * IN_CHANNEL_NUM) / 1000))
|
||||
|
||||
#if USING_FEEDBACK == 0
|
||||
#define USB_AUDIO_CONFIG_DESC_SIZ (9 + \
|
||||
AUDIO_V2_AC_DESCRIPTOR_INIT_LEN + \
|
||||
AUDIO_V2_SIZEOF_AC_CLOCK_SOURCE_DESC + \
|
||||
@@ -103,6 +111,20 @@
|
||||
AUDIO_V2_SIZEOF_AC_OUTPUT_TERMINAL_DESC + \
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT_LEN + \
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT_LEN)
|
||||
#else
|
||||
#define USB_AUDIO_CONFIG_DESC_SIZ (9 + \
|
||||
AUDIO_V2_AC_DESCRIPTOR_INIT_LEN + \
|
||||
AUDIO_V2_SIZEOF_AC_CLOCK_SOURCE_DESC + \
|
||||
AUDIO_V2_SIZEOF_AC_INPUT_TERMINAL_DESC + \
|
||||
AUDIO_V2_SIZEOF_AC_FEATURE_UNIT_DESC(OUT_CHANNEL_NUM) + \
|
||||
AUDIO_V2_SIZEOF_AC_OUTPUT_TERMINAL_DESC + \
|
||||
AUDIO_V2_SIZEOF_AC_CLOCK_SOURCE_DESC + \
|
||||
AUDIO_V2_SIZEOF_AC_INPUT_TERMINAL_DESC + \
|
||||
AUDIO_V2_SIZEOF_AC_FEATURE_UNIT_DESC(IN_CHANNEL_NUM) + \
|
||||
AUDIO_V2_SIZEOF_AC_OUTPUT_TERMINAL_DESC + \
|
||||
AUDIO_V2_AS_FEEDBACK_DESCRIPTOR_INIT_LEN + \
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT_LEN)
|
||||
#endif
|
||||
|
||||
#define AUDIO_AC_SIZ (AUDIO_V2_SIZEOF_AC_HEADER_DESC + \
|
||||
AUDIO_V2_SIZEOF_AC_CLOCK_SOURCE_DESC + \
|
||||
@@ -114,6 +136,83 @@
|
||||
AUDIO_V2_SIZEOF_AC_FEATURE_UNIT_DESC(IN_CHANNEL_NUM) + \
|
||||
AUDIO_V2_SIZEOF_AC_OUTPUT_TERMINAL_DESC)
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_AUDIO_CONFIG_DESC_SIZ, 0x03, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
AUDIO_V2_AC_DESCRIPTOR_INIT(0x00, 0x03, AUDIO_AC_SIZ, AUDIO_CATEGORY_UNDEF, 0x00, 0x00),
|
||||
AUDIO_V2_AC_CLOCK_SOURCE_DESCRIPTOR_INIT(0x01, 0x03, 0x03),
|
||||
AUDIO_V2_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(0x02, AUDIO_TERMINAL_STREAMING, 0x01, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, 0x0000),
|
||||
AUDIO_V2_AC_FEATURE_UNIT_DESCRIPTOR_INIT(0x03, 0x02, OUTPUT_CTRL),
|
||||
AUDIO_V2_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(0x04, AUDIO_OUTTERM_SPEAKER, 0x03, 0x01, 0x0000),
|
||||
AUDIO_V2_AC_CLOCK_SOURCE_DESCRIPTOR_INIT(0x05, 0x03, 0x03),
|
||||
AUDIO_V2_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(0x06, AUDIO_INTERM_MIC, 0x05, IN_CHANNEL_NUM, INPUT_CH_ENABLE, 0x0000),
|
||||
AUDIO_V2_AC_FEATURE_UNIT_DESCRIPTOR_INIT(0x07, 0x06, INPUT_CTRL),
|
||||
AUDIO_V2_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(0x08, AUDIO_TERMINAL_STREAMING, 0x07, 0x05, 0x0000),
|
||||
#if USING_FEEDBACK == 0
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT(0x01, 0x02, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_OUT_EP, 0x09, AUDIO_OUT_PACKET, EP_INTERVAL),
|
||||
#else
|
||||
AUDIO_V2_AS_FEEDBACK_DESCRIPTOR_INIT(0x01, 0x02, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_OUT_EP, 0x09, AUDIO_OUT_PACKET, EP_INTERVAL, AUDIO_OUT_FEEDBACK_EP),
|
||||
#endif
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT(0x02, 0x08, IN_CHANNEL_NUM, INPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_IN_EP, 0x05, (AUDIO_IN_PACKET + 4), EP_INTERVAL)
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB UAC DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor audio_v2_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
uint8_t audio_v2_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_AUDIO_CONFIG_DESC_SIZ, 0x03, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -126,7 +225,11 @@ uint8_t audio_v2_descriptor[] = {
|
||||
AUDIO_V2_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(0x06, AUDIO_INTERM_MIC, 0x05, IN_CHANNEL_NUM, INPUT_CH_ENABLE, 0x0000),
|
||||
AUDIO_V2_AC_FEATURE_UNIT_DESCRIPTOR_INIT(0x07, 0x06, INPUT_CTRL),
|
||||
AUDIO_V2_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(0x08, AUDIO_TERMINAL_STREAMING, 0x07, 0x05, 0x0000),
|
||||
#if USING_FEEDBACK == 0
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT(0x01, 0x02, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_OUT_EP, 0x09, AUDIO_OUT_PACKET, EP_INTERVAL),
|
||||
#else
|
||||
AUDIO_V2_AS_FEEDBACK_DESCRIPTOR_INIT(0x01, 0x02, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_OUT_EP, 0x09, AUDIO_OUT_PACKET, EP_INTERVAL, AUDIO_OUT_FEEDBACK_EP),
|
||||
#endif
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT(0x02, 0x08, IN_CHANNEL_NUM, INPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_IN_EP, 0x05, (AUDIO_IN_PACKET + 4), EP_INTERVAL),
|
||||
///////////////////////////////////////
|
||||
/// string0 descriptor
|
||||
@@ -183,7 +286,11 @@ uint8_t audio_v2_descriptor[] = {
|
||||
'1', 0x00, /* wcChar6 */
|
||||
'0', 0x00, /* wcChar7 */
|
||||
'0', 0x00, /* wcChar8 */
|
||||
'5', 0x00, /* wcChar9 */
|
||||
#if USING_FEEDBACK == 0
|
||||
'3', 0x00, /* wcChar9 */
|
||||
#else
|
||||
'4', 0x00, /* wcChar9 */
|
||||
#endif
|
||||
#ifdef CONFIG_USB_HS
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
@@ -201,6 +308,7 @@ uint8_t audio_v2_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
static const uint8_t speaker_default_sampling_freq_table[] = {
|
||||
AUDIO_SAMPLE_FREQ_NUM(5),
|
||||
@@ -233,6 +341,9 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[AUDIO_IN_PACKET];
|
||||
|
||||
volatile bool tx_flag = 0;
|
||||
volatile bool rx_flag = 0;
|
||||
volatile bool ep_tx_busy_flag = false;
|
||||
volatile uint32_t s_mic_sample_rate;
|
||||
volatile uint32_t s_speaker_sample_rate;
|
||||
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
@@ -265,6 +376,16 @@ void usbd_audio_open(uint8_t busid, uint8_t intf)
|
||||
rx_flag = 1;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
#if USING_FEEDBACK == 1
|
||||
#ifdef CONFIG_USB_HS
|
||||
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(AUDIO_FREQ);
|
||||
AUDIO_FEEDBACK_TO_BUF_HS(s_speaker_feedback_buffer, feedback_value);
|
||||
#else
|
||||
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(AUDIO_FREQ);
|
||||
AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value);
|
||||
#endif
|
||||
usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);
|
||||
#endif
|
||||
USB_LOG_RAW("OPEN1\r\n");
|
||||
} else {
|
||||
tx_flag = 1;
|
||||
@@ -283,6 +404,30 @@ void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
|
||||
{
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
s_speaker_sample_rate = sampling_freq;
|
||||
} else if (ep == AUDIO_IN_EP) {
|
||||
s_mic_sample_rate = sampling_freq;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep)
|
||||
{
|
||||
(void)busid;
|
||||
|
||||
uint32_t freq = 0;
|
||||
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
freq = s_speaker_sample_rate;
|
||||
} else if (ep == AUDIO_IN_EP) {
|
||||
freq = s_mic_sample_rate;
|
||||
}
|
||||
|
||||
return freq;
|
||||
}
|
||||
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table)
|
||||
{
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
@@ -293,30 +438,33 @@ void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sam
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
|
||||
{
|
||||
uint16_t packet_size = 0;
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
packet_size = ((sampling_freq * 2 * OUT_CHANNEL_NUM) / 1000);
|
||||
audio_v2_descriptor[18 + USB_AUDIO_CONFIG_DESC_SIZ - AUDIO_V2_AS_DESCRIPTOR_INIT_LEN - 11] = packet_size;
|
||||
audio_v2_descriptor[18 + USB_AUDIO_CONFIG_DESC_SIZ - AUDIO_V2_AS_DESCRIPTOR_INIT_LEN - 10] = packet_size >> 8;
|
||||
} else if (ep == AUDIO_IN_EP) {
|
||||
packet_size = ((sampling_freq * 2 * IN_CHANNEL_NUM) / 1000);
|
||||
audio_v2_descriptor[18 + USB_AUDIO_CONFIG_DESC_SIZ - 11] = packet_size;
|
||||
audio_v2_descriptor[18 + USB_AUDIO_CONFIG_DESC_SIZ - 10] = packet_size >> 8;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_iso_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
void usbd_audio_iso_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
|
||||
#if USING_FEEDBACK == 1
|
||||
void usbd_audio_iso_out_feedback_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual feedback len:%d\r\n", nbytes);
|
||||
#ifdef CONFIG_USB_HS
|
||||
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(s_speaker_sample_rate);
|
||||
AUDIO_FEEDBACK_TO_BUF_HS(s_speaker_feedback_buffer, feedback_value);
|
||||
#else
|
||||
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate);
|
||||
AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value);
|
||||
#endif
|
||||
usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct usbd_endpoint audio_out_ep = {
|
||||
.ep_cb = usbd_audio_iso_out_callback,
|
||||
.ep_addr = AUDIO_OUT_EP
|
||||
@@ -327,6 +475,13 @@ static struct usbd_endpoint audio_in_ep = {
|
||||
.ep_addr = AUDIO_IN_EP
|
||||
};
|
||||
|
||||
#if USING_FEEDBACK == 1
|
||||
static struct usbd_endpoint audio_out_feedback_ep = {
|
||||
.ep_cb = usbd_audio_iso_out_feedback_callback,
|
||||
.ep_addr = AUDIO_OUT_FEEDBACK_EP
|
||||
};
|
||||
#endif
|
||||
|
||||
struct usbd_interface intf0;
|
||||
struct usbd_interface intf1;
|
||||
struct usbd_interface intf2;
|
||||
@@ -348,12 +503,19 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
|
||||
void audio_v2_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &audio_v2_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, audio_v2_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf0, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf1, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf2, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_endpoint(busid, &audio_in_ep);
|
||||
usbd_add_endpoint(busid, &audio_out_ep);
|
||||
#if USING_FEEDBACK == 1
|
||||
usbd_add_endpoint(busid, &audio_out_feedback_ep);
|
||||
#endif
|
||||
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
@@ -361,6 +523,14 @@ void audio_v2_init(uint8_t busid, uintptr_t reg_base)
|
||||
void audio_v2_test(uint8_t busid)
|
||||
{
|
||||
if (tx_flag) {
|
||||
memset(write_buffer, 'a', AUDIO_IN_PACKET);
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(busid, AUDIO_IN_EP, write_buffer, AUDIO_IN_PACKET);
|
||||
while (ep_tx_busy_flag) {
|
||||
if (tx_flag == false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rx_flag) {
|
||||
}
|
||||
|
||||
@@ -6,25 +6,30 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_audio.h"
|
||||
|
||||
#define USING_FEEDBACK 0
|
||||
|
||||
#define USBD_VID 0xffff
|
||||
#define USBD_PID 0xffff
|
||||
#define USBD_MAX_POWER 100
|
||||
#define USBD_LANGID_STRING 1033
|
||||
|
||||
#ifdef CONFIG_USB_HS
|
||||
#define EP_INTERVAL 0x04
|
||||
#define EP_INTERVAL 0x04
|
||||
#define FEEDBACK_ENDP_PACKET_SIZE 0x04
|
||||
#else
|
||||
#define EP_INTERVAL 0x01
|
||||
#define EP_INTERVAL 0x01
|
||||
#define FEEDBACK_ENDP_PACKET_SIZE 0x03
|
||||
#endif
|
||||
|
||||
#define AUDIO_OUT_EP 0x01
|
||||
#define AUDIO_OUT_EP 0x01
|
||||
#define AUDIO_OUT_FEEDBACK_EP 0x82
|
||||
|
||||
#define AUDIO_OUT_CLOCK_ID 0x01
|
||||
#define AUDIO_OUT_FU_ID 0x03
|
||||
|
||||
#define AUDIO_FREQ 48000
|
||||
#define HALF_WORD_BYTES 2 //2 half word (one channel)
|
||||
#define SAMPLE_BITS 16 //16 bit per channel
|
||||
#define AUDIO_OUT_MAX_FREQ 96000
|
||||
#define HALF_WORD_BYTES 2 //2 half word (one channel)
|
||||
#define SAMPLE_BITS 16 //16 bit per channel
|
||||
|
||||
#define BMCONTROL (AUDIO_V2_FU_CONTROL_MUTE | AUDIO_V2_FU_CONTROL_VOLUME)
|
||||
|
||||
@@ -56,8 +61,9 @@
|
||||
#define OUTPUT_CH_ENABLE 0x000000ff
|
||||
#endif
|
||||
|
||||
#define AUDIO_OUT_PACKET ((uint32_t)((AUDIO_FREQ * HALF_WORD_BYTES * OUT_CHANNEL_NUM) / 1000))
|
||||
#define AUDIO_OUT_PACKET ((uint32_t)((AUDIO_OUT_MAX_FREQ * HALF_WORD_BYTES * OUT_CHANNEL_NUM) / 1000))
|
||||
|
||||
#if USING_FEEDBACK == 0
|
||||
#define USB_AUDIO_CONFIG_DESC_SIZ (9 + \
|
||||
AUDIO_V2_AC_DESCRIPTOR_INIT_LEN + \
|
||||
AUDIO_V2_SIZEOF_AC_CLOCK_SOURCE_DESC + \
|
||||
@@ -65,6 +71,15 @@
|
||||
AUDIO_V2_SIZEOF_AC_FEATURE_UNIT_DESC(OUT_CHANNEL_NUM) + \
|
||||
AUDIO_V2_SIZEOF_AC_OUTPUT_TERMINAL_DESC + \
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT_LEN)
|
||||
#else
|
||||
#define USB_AUDIO_CONFIG_DESC_SIZ (9 + \
|
||||
AUDIO_V2_AC_DESCRIPTOR_INIT_LEN + \
|
||||
AUDIO_V2_SIZEOF_AC_CLOCK_SOURCE_DESC + \
|
||||
AUDIO_V2_SIZEOF_AC_INPUT_TERMINAL_DESC + \
|
||||
AUDIO_V2_SIZEOF_AC_FEATURE_UNIT_DESC(OUT_CHANNEL_NUM) + \
|
||||
AUDIO_V2_SIZEOF_AC_OUTPUT_TERMINAL_DESC + \
|
||||
AUDIO_V2_AS_FEEDBACK_DESCRIPTOR_INIT_LEN)
|
||||
#endif
|
||||
|
||||
#define AUDIO_AC_SIZ (AUDIO_V2_SIZEOF_AC_HEADER_DESC + \
|
||||
AUDIO_V2_SIZEOF_AC_CLOCK_SOURCE_DESC + \
|
||||
@@ -72,6 +87,78 @@
|
||||
AUDIO_V2_SIZEOF_AC_FEATURE_UNIT_DESC(OUT_CHANNEL_NUM) + \
|
||||
AUDIO_V2_SIZEOF_AC_OUTPUT_TERMINAL_DESC)
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_AUDIO_CONFIG_DESC_SIZ, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
AUDIO_V2_AC_DESCRIPTOR_INIT(0x00, 0x02, AUDIO_AC_SIZ, AUDIO_CATEGORY_SPEAKER, 0x00, 0x00),
|
||||
AUDIO_V2_AC_CLOCK_SOURCE_DESCRIPTOR_INIT(AUDIO_OUT_CLOCK_ID, 0x03, 0x03),
|
||||
AUDIO_V2_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(0x02, AUDIO_TERMINAL_STREAMING, 0x01, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, 0x0000),
|
||||
AUDIO_V2_AC_FEATURE_UNIT_DESCRIPTOR_INIT(AUDIO_OUT_FU_ID, 0x02, OUTPUT_CTRL),
|
||||
AUDIO_V2_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(0x04, AUDIO_OUTTERM_SPEAKER, 0x03, 0x01, 0x0000),
|
||||
#if USING_FEEDBACK == 0
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT(0x01, 0x02, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_OUT_EP, 0x09, AUDIO_OUT_PACKET, EP_INTERVAL),
|
||||
#else
|
||||
AUDIO_V2_AS_FEEDBACK_DESCRIPTOR_INIT(0x01, 0x02, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_OUT_EP, AUDIO_OUT_PACKET, EP_INTERVAL, AUDIO_OUT_FEEDBACK_EP),
|
||||
#endif
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB UAC DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor audio_v2_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
const uint8_t audio_v2_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_AUDIO_CONFIG_DESC_SIZ, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -80,7 +167,11 @@ const uint8_t audio_v2_descriptor[] = {
|
||||
AUDIO_V2_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(0x02, AUDIO_TERMINAL_STREAMING, 0x01, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, 0x0000),
|
||||
AUDIO_V2_AC_FEATURE_UNIT_DESCRIPTOR_INIT(AUDIO_OUT_FU_ID, 0x02, OUTPUT_CTRL),
|
||||
AUDIO_V2_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(0x04, AUDIO_OUTTERM_SPEAKER, 0x03, 0x01, 0x0000),
|
||||
#if USING_FEEDBACK == 0
|
||||
AUDIO_V2_AS_DESCRIPTOR_INIT(0x01, 0x02, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_OUT_EP, 0x09, AUDIO_OUT_PACKET, EP_INTERVAL),
|
||||
#else
|
||||
AUDIO_V2_AS_FEEDBACK_DESCRIPTOR_INIT(0x01, 0x02, OUT_CHANNEL_NUM, OUTPUT_CH_ENABLE, HALF_WORD_BYTES, SAMPLE_BITS, AUDIO_OUT_EP, AUDIO_OUT_PACKET, EP_INTERVAL, AUDIO_OUT_FEEDBACK_EP),
|
||||
#endif
|
||||
///////////////////////////////////////
|
||||
/// string0 descriptor
|
||||
///////////////////////////////////////
|
||||
@@ -136,7 +227,11 @@ const uint8_t audio_v2_descriptor[] = {
|
||||
'1', 0x00, /* wcChar6 */
|
||||
'0', 0x00, /* wcChar7 */
|
||||
'0', 0x00, /* wcChar8 */
|
||||
#if USING_FEEDBACK == 0
|
||||
'3', 0x00, /* wcChar9 */
|
||||
#else
|
||||
'4', 0x00, /* wcChar9 */
|
||||
#endif
|
||||
#ifdef CONFIG_USB_HS
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
@@ -154,6 +249,7 @@ const uint8_t audio_v2_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
static const uint8_t default_sampling_freq_table[] = {
|
||||
AUDIO_SAMPLE_FREQ_NUM(5),
|
||||
@@ -175,8 +271,10 @@ static const uint8_t default_sampling_freq_table[] = {
|
||||
};
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[AUDIO_OUT_PACKET];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t s_speaker_feedback_buffer[4];
|
||||
|
||||
volatile bool rx_flag = 0;
|
||||
volatile uint32_t s_speaker_sample_rate;
|
||||
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
@@ -208,6 +306,16 @@ void usbd_audio_open(uint8_t busid, uint8_t intf)
|
||||
rx_flag = 1;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
#if USING_FEEDBACK == 1
|
||||
#ifdef CONFIG_USB_HS
|
||||
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(s_speaker_sample_rate);
|
||||
AUDIO_FEEDBACK_TO_BUF_HS(s_speaker_feedback_buffer, feedback_value);
|
||||
#else
|
||||
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate);
|
||||
AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value);
|
||||
#endif
|
||||
usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);
|
||||
#endif
|
||||
USB_LOG_RAW("OPEN\r\n");
|
||||
}
|
||||
|
||||
@@ -217,6 +325,26 @@ void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
rx_flag = 0;
|
||||
}
|
||||
|
||||
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
|
||||
{
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
s_speaker_sample_rate = sampling_freq;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep)
|
||||
{
|
||||
(void)busid;
|
||||
|
||||
uint32_t freq = 0;
|
||||
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
freq = s_speaker_sample_rate;
|
||||
}
|
||||
|
||||
return freq;
|
||||
}
|
||||
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table)
|
||||
{
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
@@ -226,15 +354,37 @@ void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sam
|
||||
|
||||
void usbd_audio_iso_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
#if USING_FEEDBACK == 1
|
||||
void usbd_audio_iso_out_feedback_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual feedback len:%d\r\n", (unsigned int)nbytes);
|
||||
#ifdef CONFIG_USB_HS
|
||||
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(s_speaker_sample_rate);
|
||||
AUDIO_FEEDBACK_TO_BUF_HS(s_speaker_feedback_buffer, feedback_value);
|
||||
#else
|
||||
uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate);
|
||||
AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value);
|
||||
#endif
|
||||
usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct usbd_endpoint audio_out_ep = {
|
||||
.ep_cb = usbd_audio_iso_out_callback,
|
||||
.ep_addr = AUDIO_OUT_EP
|
||||
};
|
||||
|
||||
#if USING_FEEDBACK == 1
|
||||
static struct usbd_endpoint audio_out_feedback_ep = {
|
||||
.ep_cb = usbd_audio_iso_out_feedback_callback,
|
||||
.ep_addr = AUDIO_OUT_FEEDBACK_EP
|
||||
};
|
||||
#endif
|
||||
|
||||
struct usbd_interface intf0;
|
||||
struct usbd_interface intf1;
|
||||
|
||||
@@ -249,11 +399,17 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
|
||||
void audio_v2_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &audio_v2_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, audio_v2_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf0, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf1, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_endpoint(busid, &audio_out_ep);
|
||||
|
||||
#if USING_FEEDBACK == 1
|
||||
usbd_add_endpoint(busid, &audio_out_feedback_ep);
|
||||
#endif
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,69 @@
|
||||
#define MSC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0200, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
MSC_DESCRIPTOR_INIT(0x00, MSC_OUT_EP, MSC_IN_EP, MSC_MAX_MPS, 0x02)
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB UF2 DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor msc_bootuf2_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
const uint8_t msc_bootuf2_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0200, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -100,6 +163,7 @@ const uint8_t msc_bootuf2_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
@@ -132,7 +196,7 @@ void usbd_msc_get_cap(uint8_t busid, uint8_t lun, uint32_t *block_num, uint32_t
|
||||
*block_num = bootuf2_get_sector_count();
|
||||
*block_size = bootuf2_get_sector_size();
|
||||
|
||||
USB_LOG_INFO("sector count:%d, sector size:%d\n", *block_num, *block_size);
|
||||
USB_LOG_INFO("sector count:%d, sector size:%d\n", (unsigned int)*block_num, (unsigned int)*block_size);
|
||||
}
|
||||
int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
@@ -151,7 +215,11 @@ static struct usbd_interface intf0;
|
||||
void msc_bootuf2_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
boot2uf2_flash_init();
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &msc_bootuf2_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, msc_bootuf2_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_msc_init_intf(busid, &intf0, MSC_OUT_EP, MSC_IN_EP));
|
||||
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
@@ -163,6 +231,6 @@ void boot2uf2_flash_init(void)
|
||||
|
||||
int bootuf2_flash_write(uint32_t address, const uint8_t *data, size_t size)
|
||||
{
|
||||
USB_LOG_INFO("address:%08x, size:%d\n", address, size);
|
||||
USB_LOG_INFO("address:%08x, size:%d\n", (unsigned int)address, (unsigned int)size);
|
||||
return 0;
|
||||
}
|
||||
@@ -8,6 +8,10 @@
|
||||
#include "usbd_cdc_acm.h"
|
||||
#include "usbd_hid.h"
|
||||
|
||||
#if CONFIG_USBDEV_EP_NUM < 7
|
||||
#error endpoint number is too small for this demo, please try other chips
|
||||
#endif
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
@@ -43,6 +47,101 @@
|
||||
#define MSC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0200, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x04, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
CDC_ACM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, 0x02),
|
||||
MSC_DESCRIPTOR_INIT(0x02, MSC_OUT_EP, MSC_IN_EP, MSC_MAX_MPS, 0x02),
|
||||
/************** Descriptor of Joystick Mouse interface ****************/
|
||||
/* 09 */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
0x03, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints */
|
||||
0x03, /* bInterfaceClass: HID */
|
||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||
0, /* iInterface: Index of string descriptor */
|
||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
||||
/* 18 */
|
||||
0x09, /* bLength: HID Descriptor size */
|
||||
HID_DESCRIPTOR_TYPE_HID, /* bDescriptorType: HID */
|
||||
0x11, /* bcdHID: HID Class Spec release number */
|
||||
0x01,
|
||||
0x00, /* bCountryCode: Hardware target country */
|
||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||
0x22, /* bDescriptorType */
|
||||
HID_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||
0x00,
|
||||
/******************** Descriptor of Mouse endpoint ********************/
|
||||
/* 27 */
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
||||
0x00,
|
||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB CDC MSC HID DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor cdc_acm_hid_msc_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
const uint8_t cdc_acm_hid_msc_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0200, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x04, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -152,6 +251,7 @@ const uint8_t cdc_acm_hid_msc_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
/*!< hid mouse report descriptor */
|
||||
static const uint8_t hid_mouse_report_desc[HID_MOUSE_REPORT_DESC_SIZE] = {
|
||||
@@ -268,14 +368,14 @@ static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
|
||||
void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
||||
|
||||
if ((nbytes % usbd_get_ep_mps(busid, ep)) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
@@ -303,8 +403,11 @@ struct usbd_interface intf3;
|
||||
|
||||
void cdc_acm_hid_msc_descriptor_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &cdc_acm_hid_msc_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, cdc_acm_hid_msc_descriptor);
|
||||
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf0));
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf1));
|
||||
usbd_add_endpoint(busid, &cdc_out_ep);
|
||||
@@ -332,14 +435,15 @@ void cdc_acm_hid_msc_descriptor_init(uint8_t busid, uintptr_t reg_base)
|
||||
*/
|
||||
void hid_mouse_test(uint8_t busid)
|
||||
{
|
||||
if(usb_device_is_configured(busid) == false) {
|
||||
return;
|
||||
}
|
||||
/*!< move mouse pointer */
|
||||
mouse_cfg.x += 10;
|
||||
mouse_cfg.y = 0;
|
||||
int ret = usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
hid_state = HID_STATE_BUSY;
|
||||
usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
while (hid_state == HID_STATE_BUSY) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include "usbd_cdc_acm.h"
|
||||
#include "usbd_msc.h"
|
||||
|
||||
#if CONFIG_USBDEV_EP_NUM < 6
|
||||
#error endpoint number is too small for this demo, please try other chips
|
||||
#endif
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
@@ -54,9 +58,9 @@ static const uint8_t device_quality_descriptor[] = {
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x02,
|
||||
0x02,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
@@ -169,9 +173,9 @@ static const uint8_t cdc_msc_descriptor[] = {
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x02,
|
||||
0x02,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
@@ -215,14 +219,14 @@ static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
|
||||
void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
||||
|
||||
if ((nbytes % usbd_get_ep_mps(busid, ep)) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_cdc_acm.h"
|
||||
|
||||
#if CONFIG_USBDEV_EP_NUM < 8
|
||||
#error endpoint number is too small for this demo, please try other chips
|
||||
#endif
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x01
|
||||
@@ -37,8 +41,74 @@
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x08, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
CDC_ACM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, 0x02),
|
||||
CDC_ACM_DESCRIPTOR_INIT(0x02, CDC_INT_EP2, CDC_OUT_EP2, CDC_IN_EP2, CDC_MAX_MPS, 0x02),
|
||||
CDC_ACM_DESCRIPTOR_INIT(0x04, CDC_INT_EP3, CDC_OUT_EP3, CDC_IN_EP3, CDC_MAX_MPS, 0x02),
|
||||
CDC_ACM_DESCRIPTOR_INIT(0x06, CDC_INT_EP4, CDC_OUT_EP4, CDC_IN_EP4, CDC_MAX_MPS, 0x02)
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB CDC MULTI DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor cdc_multi_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
/*!< global descriptor */
|
||||
static const uint8_t cdc_descriptor[] = {
|
||||
static const uint8_t cdc_multi_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x08, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
CDC_ACM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, 0x02),
|
||||
@@ -109,15 +179,16 @@ static const uint8_t cdc_descriptor[] = {
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x02,
|
||||
0x02,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[4][2048];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[4][2048];
|
||||
@@ -157,14 +228,14 @@ static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
|
||||
void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
||||
|
||||
if ((nbytes % CDC_MAX_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
@@ -225,8 +296,11 @@ struct usbd_interface intf7;
|
||||
|
||||
void cdc_acm_multi_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
usbd_desc_register(busid, cdc_descriptor);
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &cdc_multi_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, cdc_multi_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf0));
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf1));
|
||||
usbd_add_endpoint(busid, &cdc_out_ep1);
|
||||
|
||||
@@ -25,6 +25,69 @@
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
CDC_ACM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, 0x02)
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB CDC DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor cdc_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
/*!< global descriptor */
|
||||
static const uint8_t cdc_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
|
||||
@@ -94,15 +157,16 @@ static const uint8_t cdc_descriptor[] = {
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x02,
|
||||
0x02,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[2048]; /* 2048 is only for test speed , please use CDC_MAX_MPS for common*/
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[2048];
|
||||
@@ -139,7 +203,7 @@ static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
|
||||
void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||
// for (int i = 0; i < 100; i++) {
|
||||
// printf("%02x ", read_buffer[i]);
|
||||
// }
|
||||
@@ -150,7 +214,7 @@ void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
||||
|
||||
if ((nbytes % usbd_get_ep_mps(busid, ep)) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
@@ -181,7 +245,11 @@ void cdc_acm_init(uint8_t busid, uintptr_t reg_base)
|
||||
memcpy(&write_buffer[0], data, 10);
|
||||
memset(&write_buffer[10], 'a', 2038);
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &cdc_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, cdc_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf0));
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf1));
|
||||
usbd_add_endpoint(busid, &cdc_out_ep);
|
||||
|
||||
@@ -6,10 +6,14 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_cdc_ecm.h"
|
||||
|
||||
#ifndef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
#error "Please enable CONFIG_USBDEV_CDC_ECM_USING_LWIP for this demo"
|
||||
#endif
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
#define CDC_INT_EP 0x83
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
#define CDC_INT_EP 0x83
|
||||
|
||||
#define USBD_VID 0xFFFF
|
||||
#define USBD_PID 0xFFFF
|
||||
@@ -17,7 +21,7 @@
|
||||
#define USBD_LANGID_STRING 1033
|
||||
|
||||
/*!< config descriptor size */
|
||||
#define USB_CONFIG_SIZE (9 + CDC_ECM_DESCRIPTOR_LEN)
|
||||
#define USB_CONFIG_SIZE (9 + CDC_ECM_DESCRIPTOR_LEN)
|
||||
|
||||
#ifdef CONFIG_USB_HS
|
||||
#define CDC_MAX_MPS 512
|
||||
@@ -28,8 +32,74 @@
|
||||
#define CDC_ECM_ETH_STATISTICS_BITMAP 0x00000000
|
||||
|
||||
/* str idx = 4 is for mac address: aa:bb:cc:dd:ee:ff*/
|
||||
#define CDC_ECM_MAC_STRING_INDEX 4
|
||||
#define CDC_ECM_MAC_STRING_INDEX 4
|
||||
|
||||
/* Ethernet Maximum Segment size, typically 1514 bytes */
|
||||
#define CONFIG_CDC_ECM_ETH_MAX_SEGSZE 1514U
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
CDC_ECM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, CDC_ECM_ETH_STATISTICS_BITMAP, CONFIG_CDC_ECM_ETH_MAX_SEGSZE, 0, 0, CDC_ECM_MAC_STRING_INDEX)
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB CDC ECM DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor cdc_ecm_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
/*!< global descriptor */
|
||||
static const uint8_t cdc_ecm_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
|
||||
@@ -120,23 +190,115 @@ static const uint8_t cdc_ecm_descriptor[] = {
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x02,
|
||||
0x02,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
const uint8_t mac[6] = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
|
||||
|
||||
volatile bool cdc_ecm_tx_done = false;
|
||||
|
||||
void usbd_cdc_ecm_data_send_done(uint32_t len)
|
||||
{
|
||||
cdc_ecm_tx_done = true; // suggest you to use semaphore in os
|
||||
}
|
||||
|
||||
#ifdef RT_USING_LWIP
|
||||
|
||||
#ifndef RT_LWIP_DHCP
|
||||
#error cdc_ecm must enable RT_LWIP_DHCP
|
||||
#endif
|
||||
|
||||
#ifndef LWIP_USING_DHCPD
|
||||
#error cdc_ecm must enable LWIP_USING_DHCPD
|
||||
#endif
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <netif/ethernetif.h>
|
||||
#include <dhcp_server.h>
|
||||
|
||||
struct eth_device cdc_ecm_dev;
|
||||
|
||||
static rt_err_t rt_usbd_cdc_ecm_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
switch (cmd) {
|
||||
case NIOCTL_GADDR:
|
||||
|
||||
/* get mac address */
|
||||
if (args) {
|
||||
uint8_t *mac_dev = (uint8_t *)args;
|
||||
rt_memcpy(mac_dev, mac, 6);
|
||||
mac_dev[5] = ~mac_dev[5]; /* device mac can't same as host. */
|
||||
} else
|
||||
return -RT_ERROR;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
struct pbuf *rt_usbd_cdc_ecm_eth_rx(rt_device_t dev)
|
||||
{
|
||||
return usbd_cdc_ecm_eth_rx();
|
||||
}
|
||||
|
||||
rt_err_t rt_usbd_cdc_ecm_eth_tx(rt_device_t dev, struct pbuf *p)
|
||||
{
|
||||
int ret;
|
||||
|
||||
cdc_ecm_tx_done = false;
|
||||
ret = usbd_cdc_ecm_eth_tx(p);
|
||||
if (ret == 0) {
|
||||
while (!cdc_ecm_tx_done) {
|
||||
}
|
||||
return RT_EOK;
|
||||
} else
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
void cdc_ecm_lwip_init(void)
|
||||
{
|
||||
cdc_ecm_dev.parent.control = rt_usbd_cdc_ecm_control;
|
||||
cdc_ecm_dev.eth_rx = rt_usbd_cdc_ecm_eth_rx;
|
||||
cdc_ecm_dev.eth_tx = rt_usbd_cdc_ecm_eth_tx;
|
||||
|
||||
eth_device_init(&cdc_ecm_dev, "u0");
|
||||
|
||||
eth_device_linkchange(&cdc_ecm_dev, RT_TRUE);
|
||||
dhcpd_start("u0");
|
||||
}
|
||||
|
||||
void usbd_cdc_ecm_data_recv_done(uint32_t len)
|
||||
{
|
||||
eth_device_ready(&cdc_ecm_dev);
|
||||
}
|
||||
|
||||
#else
|
||||
#include "netif/etharp.h"
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/pbuf.h"
|
||||
|
||||
#include "dhserver.h"
|
||||
#include "dnserver.h"
|
||||
|
||||
/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
|
||||
#define IP_ADDR0 (uint8_t)192
|
||||
#define IP_ADDR1 (uint8_t)168
|
||||
#define IP_ADDR2 (uint8_t)123
|
||||
#define IP_ADDR3 (uint8_t)100
|
||||
#define IP_ADDR0 (uint8_t)192
|
||||
#define IP_ADDR1 (uint8_t)168
|
||||
#define IP_ADDR2 (uint8_t)7
|
||||
#define IP_ADDR3 (uint8_t)1
|
||||
|
||||
/*NETMASK*/
|
||||
#define NETMASK_ADDR0 (uint8_t)255
|
||||
@@ -145,34 +307,59 @@ const uint8_t mac[6] = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
|
||||
#define NETMASK_ADDR3 (uint8_t)0
|
||||
|
||||
/*Gateway Address*/
|
||||
#define GW_ADDR0 (uint8_t)192
|
||||
#define GW_ADDR1 (uint8_t)168
|
||||
#define GW_ADDR2 (uint8_t)123
|
||||
#define GW_ADDR3 (uint8_t)1
|
||||
|
||||
#include "netif/etharp.h"
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#define GW_ADDR0 (uint8_t)0
|
||||
#define GW_ADDR1 (uint8_t)0
|
||||
#define GW_ADDR2 (uint8_t)0
|
||||
#define GW_ADDR3 (uint8_t)0
|
||||
|
||||
const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
|
||||
const ip_addr_t netmask = IPADDR4_INIT_BYTES(NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
const ip_addr_t gateway = IPADDR4_INIT_BYTES(GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
|
||||
#define NUM_DHCP_ENTRY 3
|
||||
|
||||
static dhcp_entry_t entries[NUM_DHCP_ENTRY] = {
|
||||
/* mac ip address subnet mask lease time */
|
||||
{ { 0 }, { 192, 168, 7, 2 }, { 255, 255, 255, 0 }, 24 * 60 * 60 },
|
||||
{ { 0 }, { 192, 168, 7, 3 }, { 255, 255, 255, 0 }, 24 * 60 * 60 },
|
||||
{ { 0 }, { 192, 168, 7, 4 }, { 255, 255, 255, 0 }, 24 * 60 * 60 }
|
||||
};
|
||||
|
||||
static dhcp_config_t dhcp_config = {
|
||||
{ 192, 168, 7, 1 }, /* server address */
|
||||
67, /* port */
|
||||
{ 192, 168, 7, 1 }, /* dns server */
|
||||
"cherry", /* dns suffix */
|
||||
NUM_DHCP_ENTRY, /* num entry */
|
||||
entries /* entries */
|
||||
};
|
||||
|
||||
static bool dns_query_proc(const char *name, ip_addr_t *addr)
|
||||
{
|
||||
if (strcmp(name, "cdc_ecm.cherry") == 0 || strcmp(name, "www.cdc_ecm.cherry") == 0) {
|
||||
addr->addr = ipaddr.addr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct netif cdc_ecm_netif; //network interface
|
||||
|
||||
/* Network interface name */
|
||||
#define IFNAME0 'E'
|
||||
#define IFNAME1 'X'
|
||||
#define IFNAME0 'E'
|
||||
#define IFNAME1 'X'
|
||||
|
||||
static err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
|
||||
err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
static int ret;
|
||||
int ret;
|
||||
|
||||
cdc_ecm_tx_done = false;
|
||||
ret = usbd_cdc_ecm_eth_tx(p);
|
||||
if (ret == 0)
|
||||
if (ret == 0) {
|
||||
while (!cdc_ecm_tx_done) {
|
||||
}
|
||||
return ERR_OK;
|
||||
else
|
||||
} else
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
@@ -192,8 +379,8 @@ err_t cdc_ecm_if_init(struct netif *netif)
|
||||
|
||||
err_t cdc_ecm_if_input(struct netif *netif)
|
||||
{
|
||||
static err_t err;
|
||||
static struct pbuf *p;
|
||||
err_t err;
|
||||
struct pbuf *p;
|
||||
|
||||
p = usbd_cdc_ecm_eth_rx();
|
||||
if (p != NULL) {
|
||||
@@ -222,12 +409,14 @@ void cdc_ecm_lwip_init(void)
|
||||
while (!netif_is_up(netif)) {
|
||||
}
|
||||
|
||||
// while (dhserv_init(&dhcp_config)) {}
|
||||
while (dhserv_init(&dhcp_config)) {
|
||||
}
|
||||
|
||||
// while (dnserv_init(&ipaddr, PORT_DNS, dns_query_proc)) {}
|
||||
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_cdc_ecm_data_recv_done(uint8_t *buf, uint32_t len)
|
||||
void usbd_cdc_ecm_data_recv_done(uint32_t len)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -235,6 +424,7 @@ void cdc_ecm_input_poll(void)
|
||||
{
|
||||
cdc_ecm_if_input(&cdc_ecm_netif);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
@@ -273,7 +463,11 @@ void cdc_ecm_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
cdc_ecm_lwip_init();
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &cdc_ecm_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, cdc_ecm_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_cdc_ecm_init_intf(&intf0, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP));
|
||||
usbd_add_interface(busid, usbd_cdc_ecm_init_intf(&intf1, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP));
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_rndis.h"
|
||||
|
||||
#ifndef CONFIG_USBDEV_RNDIS_USING_LWIP
|
||||
#error "Please enable CONFIG_USBDEV_RNDIS_USING_LWIP for this demo"
|
||||
#endif
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
@@ -25,8 +29,71 @@
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
CDC_RNDIS_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, 0x02)
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB RNDIS DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor cdc_rndis_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
/*!< global descriptor */
|
||||
static const uint8_t cdc_descriptor[] = {
|
||||
static const uint8_t cdc_rndis_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
CDC_RNDIS_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, 0x02),
|
||||
@@ -96,43 +163,40 @@ static const uint8_t cdc_descriptor[] = {
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x02,
|
||||
0x02,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
const uint8_t mac[6] = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
|
||||
/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
|
||||
#define IP_ADDR0 (uint8_t)192
|
||||
#define IP_ADDR1 (uint8_t)168
|
||||
#define IP_ADDR2 (uint8_t)123
|
||||
#define IP_ADDR3 (uint8_t)100
|
||||
|
||||
/*NETMASK*/
|
||||
#define NETMASK_ADDR0 (uint8_t)255
|
||||
#define NETMASK_ADDR1 (uint8_t)255
|
||||
#define NETMASK_ADDR2 (uint8_t)255
|
||||
#define NETMASK_ADDR3 (uint8_t)0
|
||||
volatile bool rndis_tx_done = false;
|
||||
|
||||
/*Gateway Address*/
|
||||
#define GW_ADDR0 (uint8_t)192
|
||||
#define GW_ADDR1 (uint8_t)168
|
||||
#define GW_ADDR2 (uint8_t)123
|
||||
#define GW_ADDR3 (uint8_t)1
|
||||
void usbd_rndis_data_send_done(uint32_t len)
|
||||
{
|
||||
rndis_tx_done = true; // suggest you to use semaphore in os
|
||||
}
|
||||
|
||||
#ifdef RT_USING_LWIP
|
||||
|
||||
#ifndef RT_LWIP_DHCP
|
||||
#error rndis must enable RT_LWIP_DHCP
|
||||
#endif
|
||||
|
||||
#ifndef LWIP_USING_DHCPD
|
||||
#error rndis must enable LWIP_USING_DHCPD
|
||||
#endif
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <netif/ethernetif.h>
|
||||
|
||||
const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
|
||||
const ip_addr_t netmask = IPADDR4_INIT_BYTES(NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
const ip_addr_t gateway = IPADDR4_INIT_BYTES(GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
#include <dhcp_server.h>
|
||||
|
||||
struct eth_device rndis_dev;
|
||||
|
||||
@@ -142,13 +206,11 @@ static rt_err_t rt_usbd_rndis_control(rt_device_t dev, int cmd, void *args)
|
||||
case NIOCTL_GADDR:
|
||||
|
||||
/* get mac address */
|
||||
if (args)
|
||||
{
|
||||
if (args) {
|
||||
uint8_t *mac_dev = (uint8_t *)args;
|
||||
rt_memcpy(mac_dev, mac, 6);
|
||||
mac_dev[5] = ~mac_dev[5]; /* device mac can't same as host. */
|
||||
}
|
||||
else
|
||||
} else
|
||||
return -RT_ERROR;
|
||||
|
||||
break;
|
||||
@@ -167,15 +229,19 @@ struct pbuf *rt_usbd_rndis_eth_rx(rt_device_t dev)
|
||||
|
||||
rt_err_t rt_usbd_rndis_eth_tx(rt_device_t dev, struct pbuf *p)
|
||||
{
|
||||
return usbd_rndis_eth_tx(p);
|
||||
int ret;
|
||||
|
||||
rndis_tx_done = false;
|
||||
ret = usbd_rndis_eth_tx(p);
|
||||
if (ret == 0) {
|
||||
while (!rndis_tx_done) {
|
||||
}
|
||||
return RT_EOK;
|
||||
} else
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
void usbd_rndis_data_recv_done(void)
|
||||
{
|
||||
eth_device_ready(&rndis_dev);
|
||||
}
|
||||
|
||||
void rt_usbd_rndis_init(void)
|
||||
void rndis_lwip_init(void)
|
||||
{
|
||||
rndis_dev.parent.control = rt_usbd_rndis_control;
|
||||
rndis_dev.eth_rx = rt_usbd_rndis_eth_rx;
|
||||
@@ -183,32 +249,90 @@ void rt_usbd_rndis_init(void)
|
||||
|
||||
eth_device_init(&rndis_dev, "u0");
|
||||
|
||||
eth_device_linkchange(&rndis_dev, RT_FALSE);
|
||||
eth_device_linkchange(&rndis_dev, RT_TRUE);
|
||||
dhcpd_start("u0");
|
||||
}
|
||||
|
||||
void usbd_rndis_data_recv_done(uint32_t len)
|
||||
{
|
||||
eth_device_ready(&rndis_dev);
|
||||
}
|
||||
|
||||
#else
|
||||
#include "netif/etharp.h"
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/pbuf.h"
|
||||
|
||||
#include "dhserver.h"
|
||||
#include "dnserver.h"
|
||||
|
||||
/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
|
||||
#define IP_ADDR0 (uint8_t)192
|
||||
#define IP_ADDR1 (uint8_t)168
|
||||
#define IP_ADDR2 (uint8_t)7
|
||||
#define IP_ADDR3 (uint8_t)1
|
||||
|
||||
/*NETMASK*/
|
||||
#define NETMASK_ADDR0 (uint8_t)255
|
||||
#define NETMASK_ADDR1 (uint8_t)255
|
||||
#define NETMASK_ADDR2 (uint8_t)255
|
||||
#define NETMASK_ADDR3 (uint8_t)0
|
||||
|
||||
/*Gateway Address*/
|
||||
#define GW_ADDR0 (uint8_t)0
|
||||
#define GW_ADDR1 (uint8_t)0
|
||||
#define GW_ADDR2 (uint8_t)0
|
||||
#define GW_ADDR3 (uint8_t)0
|
||||
|
||||
const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
|
||||
const ip_addr_t netmask = IPADDR4_INIT_BYTES(NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
const ip_addr_t gateway = IPADDR4_INIT_BYTES(GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
|
||||
#define NUM_DHCP_ENTRY 3
|
||||
|
||||
static dhcp_entry_t entries[NUM_DHCP_ENTRY] = {
|
||||
/* mac ip address subnet mask lease time */
|
||||
{ { 0 }, { 192, 168, 7, 2 }, { 255, 255, 255, 0 }, 24 * 60 * 60 },
|
||||
{ { 0 }, { 192, 168, 7, 3 }, { 255, 255, 255, 0 }, 24 * 60 * 60 },
|
||||
{ { 0 }, { 192, 168, 7, 4 }, { 255, 255, 255, 0 }, 24 * 60 * 60 }
|
||||
};
|
||||
|
||||
static dhcp_config_t dhcp_config = {
|
||||
{ 192, 168, 7, 1 }, /* server address */
|
||||
67, /* port */
|
||||
{ 192, 168, 7, 1 }, /* dns server */
|
||||
"cherry", /* dns suffix */
|
||||
NUM_DHCP_ENTRY, /* num entry */
|
||||
entries /* entries */
|
||||
};
|
||||
|
||||
static bool dns_query_proc(const char *name, ip_addr_t *addr)
|
||||
{
|
||||
if (strcmp(name, "rndis.cherry") == 0 || strcmp(name, "www.rndis.cherry") == 0) {
|
||||
addr->addr = ipaddr.addr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct netif rndis_netif; //network interface
|
||||
|
||||
/* Network interface name */
|
||||
#define IFNAME0 'E'
|
||||
#define IFNAME1 'X'
|
||||
#define IFNAME0 'E'
|
||||
#define IFNAME1 'X'
|
||||
|
||||
err_t linkoutput_fn(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
static int ret;
|
||||
int ret;
|
||||
|
||||
rndis_tx_done = false;
|
||||
ret = usbd_rndis_eth_tx(p);
|
||||
if (ret == 0)
|
||||
if (ret == 0) {
|
||||
while (!rndis_tx_done) {
|
||||
}
|
||||
return ERR_OK;
|
||||
else
|
||||
} else
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
@@ -228,8 +352,8 @@ err_t rndisif_init(struct netif *netif)
|
||||
|
||||
err_t rndisif_input(struct netif *netif)
|
||||
{
|
||||
static err_t err;
|
||||
static struct pbuf *p;
|
||||
err_t err;
|
||||
struct pbuf *p;
|
||||
|
||||
p = usbd_rndis_eth_rx();
|
||||
if (p != NULL) {
|
||||
@@ -258,12 +382,14 @@ void rndis_lwip_init(void)
|
||||
while (!netif_is_up(netif)) {
|
||||
}
|
||||
|
||||
// while (dhserv_init(&dhcp_config)) {}
|
||||
while (dhserv_init(&dhcp_config)) {
|
||||
}
|
||||
|
||||
// while (dnserv_init(&ipaddr, PORT_DNS, dns_query_proc)) {}
|
||||
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc)) {
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_rndis_data_recv_done(void)
|
||||
void usbd_rndis_data_recv_done(uint32_t len)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -287,9 +413,6 @@ static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
case USBD_EVENT_SUSPEND:
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
#ifdef RT_USING_LWIP
|
||||
eth_device_linkchange(&rndis_dev, RT_TRUE);
|
||||
#endif
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@@ -306,13 +429,14 @@ struct usbd_interface intf1;
|
||||
|
||||
void cdc_rndis_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef RT_USING_LWIP
|
||||
rt_usbd_rndis_init();
|
||||
#else
|
||||
rndis_lwip_init();
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &cdc_rndis_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, cdc_rndis_descriptor);
|
||||
#endif
|
||||
usbd_desc_register(busid, cdc_descriptor);
|
||||
usbd_add_interface(busid, usbd_rndis_init_intf(&intf0, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, mac));
|
||||
usbd_add_interface(busid, usbd_rndis_init_intf(&intf1, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, mac));
|
||||
usbd_add_interface(busid, usbd_rndis_init_intf(&intf0, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, (uint8_t *)mac));
|
||||
usbd_add_interface(busid, usbd_rndis_init_intf(&intf1, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, (uint8_t *)mac));
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,69 @@
|
||||
|
||||
#define USB_CONFIG_SIZE (9 + 9 + 9)
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0200, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
DFU_DESCRIPTOR_INIT()
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB DFU DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor dfu_flash_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
const uint8_t dfu_flash_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0200, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -141,6 +204,7 @@ const uint8_t dfu_flash_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
@@ -171,7 +235,11 @@ struct usbd_interface intf0;
|
||||
|
||||
void dfu_flash_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &dfu_flash_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, dfu_flash_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_dfu_init_intf(&intf0));
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,103 @@
|
||||
/*!< custom hid report descriptor size */
|
||||
#define HID_CUSTOM_REPORT_DESC_SIZE 38
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
/************** Descriptor of Custom interface *****************/
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints */
|
||||
0x03, /* bInterfaceClass: HID */
|
||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||
0, /* iInterface: Index of string descriptor */
|
||||
/******************** Descriptor of Custom HID ********************/
|
||||
0x09, /* bLength: HID Descriptor size */
|
||||
HID_DESCRIPTOR_TYPE_HID, /* bDescriptorType: HID */
|
||||
0x11, /* bcdHID: HID Class Spec release number */
|
||||
0x01,
|
||||
0x00, /* bCountryCode: Hardware target country */
|
||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||
0x22, /* bDescriptorType */
|
||||
HID_CUSTOM_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||
0x00,
|
||||
/******************** Descriptor of Custom in endpoint ********************/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
HIDRAW_IN_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
WBVAL(HIDRAW_IN_EP_SIZE), /* wMaxPacketSize: 4 Byte max */
|
||||
HIDRAW_IN_INTERVAL, /* bInterval: Polling Interval */
|
||||
/******************** Descriptor of Custom out endpoint ********************/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
HIDRAW_OUT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
WBVAL(HIDRAW_OUT_EP_SIZE), /* wMaxPacketSize: 4 Byte max */
|
||||
HIDRAW_OUT_EP_INTERVAL, /* bInterval: Polling Interval */
|
||||
/* 73 */
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB HID DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor hid_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
/*!< global descriptor */
|
||||
static const uint8_t hid_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
||||
@@ -151,6 +248,7 @@ static const uint8_t hid_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
/*!< custom hid report descriptor */
|
||||
static const uint8_t hid_custom_report_desc[HID_CUSTOM_REPORT_DESC_SIZE] = {
|
||||
@@ -241,13 +339,13 @@ static void usbd_hid_custom_in_callback(uint8_t busid, uint8_t ep, uint32_t nbyt
|
||||
{
|
||||
(void)busid;
|
||||
(void)ep;
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
||||
custom_state = HID_STATE_IDLE;
|
||||
}
|
||||
|
||||
static void usbd_hid_custom_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||
usbd_ep_start_read(busid, ep, read_buffer, HIDRAW_IN_EP_SIZE);
|
||||
read_buffer[0] = 0x02; /* IN: report id */
|
||||
usbd_ep_start_write(busid, HIDRAW_IN_EP, read_buffer, nbytes);
|
||||
@@ -274,7 +372,11 @@ struct usbd_interface intf0;
|
||||
|
||||
void hid_custom_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &hid_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, hid_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_hid_init_intf(busid, &intf0, hid_custom_report_desc, HID_CUSTOM_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(busid, &custom_in_ep);
|
||||
usbd_add_endpoint(busid, &custom_out_ep);
|
||||
|
||||
@@ -18,6 +18,101 @@
|
||||
#define USB_HID_CONFIG_DESC_SIZ 34
|
||||
#define HID_KEYBOARD_REPORT_DESC_SIZE 63
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
|
||||
/************** Descriptor of Joystick Mouse interface ****************/
|
||||
/* 09 */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints */
|
||||
0x03, /* bInterfaceClass: HID */
|
||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||
0x01, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||
0, /* iInterface: Index of string descriptor */
|
||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
||||
/* 18 */
|
||||
0x09, /* bLength: HID Descriptor size */
|
||||
HID_DESCRIPTOR_TYPE_HID, /* bDescriptorType: HID */
|
||||
0x11, /* bcdHID: HID Class Spec release number */
|
||||
0x01,
|
||||
0x00, /* bCountryCode: Hardware target country */
|
||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||
0x22, /* bDescriptorType */
|
||||
HID_KEYBOARD_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||
0x00,
|
||||
/******************** Descriptor of Mouse endpoint ********************/
|
||||
/* 27 */
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
||||
0x00,
|
||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
||||
/* 34 */
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB HID DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor hid_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
static const uint8_t hid_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -127,6 +222,7 @@ static const uint8_t hid_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
/* USB HID device Configuration Descriptor */
|
||||
static uint8_t hid_desc[9] __ALIGN_END = {
|
||||
@@ -223,7 +319,11 @@ struct usbd_interface intf0;
|
||||
|
||||
void hid_keyboard_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &hid_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, hid_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_hid_init_intf(busid, &intf0, hid_keyboard_report_desc, HID_KEYBOARD_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(busid, &hid_in_ep);
|
||||
|
||||
@@ -236,12 +336,13 @@ void hid_keyboard_test(uint8_t busid)
|
||||
{
|
||||
const uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
memcpy(write_buffer, sendbuffer, 8);
|
||||
int ret = usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
|
||||
if (ret < 0) {
|
||||
if(usb_device_is_configured(busid) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(write_buffer, sendbuffer, 8);
|
||||
hid_state = HID_STATE_BUSY;
|
||||
usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
|
||||
while (hid_state == HID_STATE_BUSY) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,101 @@
|
||||
/*!< report descriptor size */
|
||||
#define HID_MOUSE_REPORT_DESC_SIZE 74
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
|
||||
/************** Descriptor of Joystick Mouse interface ****************/
|
||||
/* 09 */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints */
|
||||
0x03, /* bInterfaceClass: HID */
|
||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||
0, /* iInterface: Index of string descriptor */
|
||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
||||
/* 18 */
|
||||
0x09, /* bLength: HID Descriptor size */
|
||||
HID_DESCRIPTOR_TYPE_HID, /* bDescriptorType: HID */
|
||||
0x11, /* bcdHID: HID Class Spec release number */
|
||||
0x01,
|
||||
0x00, /* bCountryCode: Hardware target country */
|
||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||
0x22, /* bDescriptorType */
|
||||
HID_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||
0x00,
|
||||
/******************** Descriptor of Mouse endpoint ********************/
|
||||
/* 27 */
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
||||
0x00,
|
||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
||||
/* 34 */
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB HID DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor hid_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
/*!< global descriptor */
|
||||
const uint8_t hid_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
||||
@@ -131,6 +226,7 @@ const uint8_t hid_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
/*!< hid mouse report descriptor */
|
||||
static const uint8_t hid_mouse_report_desc[HID_MOUSE_REPORT_DESC_SIZE] = {
|
||||
@@ -241,7 +337,11 @@ struct usbd_interface intf0;
|
||||
|
||||
void hid_mouse_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &hid_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, hid_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_hid_init_intf(busid, &intf0, hid_mouse_report_desc, HID_MOUSE_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(busid, &hid_in_ep);
|
||||
|
||||
@@ -304,14 +404,15 @@ void draw_circle(uint8_t *buf)
|
||||
/* https://cps-check.com/cn/polling-rate-check */
|
||||
void hid_mouse_test(uint8_t busid)
|
||||
{
|
||||
if(usb_device_is_configured(busid) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
int counter = 0;
|
||||
while (counter < 1000) {
|
||||
draw_circle((uint8_t *)&mouse_cfg);
|
||||
int ret = usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
hid_state = HID_STATE_BUSY;
|
||||
usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
while (hid_state == HID_STATE_BUSY) {
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,101 @@
|
||||
/*!< report descriptor size */
|
||||
#define HID_MOUSE_REPORT_DESC_SIZE 74
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_REMOTE_WAKEUP | USB_CONFIG_SELF_POWERED, USBD_MAX_POWER),
|
||||
|
||||
/************** Descriptor of Joystick Mouse interface ****************/
|
||||
/* 09 */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints */
|
||||
0x03, /* bInterfaceClass: HID */
|
||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||
0, /* iInterface: Index of string descriptor */
|
||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
||||
/* 18 */
|
||||
0x09, /* bLength: HID Descriptor size */
|
||||
HID_DESCRIPTOR_TYPE_HID, /* bDescriptorType: HID */
|
||||
0x11, /* bcdHID: HID Class Spec release number */
|
||||
0x01,
|
||||
0x00, /* bCountryCode: Hardware target country */
|
||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||
0x22, /* bDescriptorType */
|
||||
HID_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||
0x00,
|
||||
/******************** Descriptor of Mouse endpoint ********************/
|
||||
/* 27 */
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
||||
0x00,
|
||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
||||
/* 34 */
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB HID DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor hid_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
/*!< global descriptor */
|
||||
const uint8_t hid_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
||||
@@ -131,6 +226,7 @@ const uint8_t hid_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
/*!< hid mouse report descriptor */
|
||||
static const uint8_t hid_mouse_report_desc[HID_MOUSE_REPORT_DESC_SIZE] = {
|
||||
@@ -241,7 +337,11 @@ static struct usbd_interface intf0;
|
||||
|
||||
void hid_mouse_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &hid_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, hid_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_hid_init_intf(busid, &intf0, hid_mouse_report_desc, HID_MOUSE_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(busid, &hid_in_ep);
|
||||
|
||||
@@ -307,6 +407,10 @@ void hid_mouse_test(uint8_t busid)
|
||||
static uint32_t count = 1000;
|
||||
int ret;
|
||||
|
||||
if(usb_device_is_configured(busid) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if (gpio_read_pin(GPIO_PIN) == 1) {
|
||||
// ret = usbd_send_remote_wakeup(busid);
|
||||
// if (ret < 0) {
|
||||
@@ -317,11 +421,8 @@ void hid_mouse_test(uint8_t busid)
|
||||
|
||||
while (count) {
|
||||
draw_circle((uint8_t *)&mouse_cfg);
|
||||
int ret = usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
hid_state = HID_STATE_BUSY;
|
||||
usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
while (hid_state == HID_STATE_BUSY) {
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,118 @@
|
||||
#define MIDI_EP_MPS 64
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0100, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
// Standard AC Interface Descriptor
|
||||
0x09,
|
||||
0x04,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
// Class-specific AC Interface Descriptor
|
||||
0x09,
|
||||
0x24,
|
||||
0x01,
|
||||
0x00,
|
||||
0x01,
|
||||
0x09,
|
||||
0x00,
|
||||
0x01,
|
||||
0x01,
|
||||
// MIDIStreaming Interface Descriptors
|
||||
0x09,
|
||||
0x04,
|
||||
0x01,
|
||||
0x00,
|
||||
0x02,
|
||||
0x01,
|
||||
0x03,
|
||||
0x00,
|
||||
0x00,
|
||||
// Class-Specific MS Interface Header Descriptor
|
||||
0x07,
|
||||
0x24,
|
||||
0x01,
|
||||
0x00,
|
||||
0x01,
|
||||
WBVAL(65),
|
||||
|
||||
// MIDI_IN_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EMBEDDED, 0x01),
|
||||
// MIDI_IN_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EXTERNAL, 0x02),
|
||||
// MIDI_OUT_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EMBEDDED, 0x03, 0x02),
|
||||
// MIDI_OUT_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EXTERNAL, 0x04, 0x01),
|
||||
MIDI_JACK_DESCRIPTOR_INIT(0x01),
|
||||
// OUT endpoint descriptor
|
||||
0x09, 0x05, MIDI_OUT_EP, 0x02, WBVAL(MIDI_EP_MPS), 0x00, 0x00, 0x00,
|
||||
0x05, 0x25, 0x01, 0x01, 0x01,
|
||||
|
||||
// IN endpoint descriptor
|
||||
0x09, 0x05, MIDI_IN_EP, 0x02, WBVAL(MIDI_EP_MPS), 0x00, 0x00, 0x00,
|
||||
0x05, 0x25, 0x01, 0x01, 0x03
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB MIDI DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor midi_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
const uint8_t midi_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0100, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -141,15 +253,16 @@ const uint8_t midi_descriptor[] = {
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x02,
|
||||
0x02,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[MIDI_EP_MPS];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[MIDI_EP_MPS];
|
||||
@@ -204,7 +317,11 @@ struct usbd_endpoint midi_in_ep = {
|
||||
|
||||
void midi_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &midi_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, midi_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, &intf0);
|
||||
usbd_add_interface(busid, &intf1);
|
||||
usbd_add_endpoint(busid, &midi_out_ep);
|
||||
|
||||
@@ -22,6 +22,69 @@
|
||||
#define MSC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static const uint8_t device_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0200, 0x01)
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
MSC_DESCRIPTOR_INIT(0x00, MSC_OUT_EP, MSC_IN_EP, MSC_MAX_MPS, 0x02)
|
||||
};
|
||||
|
||||
static const uint8_t device_quality_descriptor[] = {
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
|
||||
static const char *string_descriptors[] = {
|
||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||
"CherryUSB", /* Manufacturer */
|
||||
"CherryUSB MSC DEMO", /* Product */
|
||||
"2022123456", /* Serial Number */
|
||||
};
|
||||
|
||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return config_descriptor;
|
||||
}
|
||||
|
||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||
{
|
||||
return device_quality_descriptor;
|
||||
}
|
||||
|
||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||
{
|
||||
if (index > 3) {
|
||||
return NULL;
|
||||
}
|
||||
return string_descriptors[index];
|
||||
}
|
||||
|
||||
const struct usb_descriptor msc_ram_descriptor = {
|
||||
.device_descriptor_callback = device_descriptor_callback,
|
||||
.config_descriptor_callback = config_descriptor_callback,
|
||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||
.string_descriptor_callback = string_descriptor_callback
|
||||
};
|
||||
#else
|
||||
const uint8_t msc_ram_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0200, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
@@ -99,6 +162,7 @@ const uint8_t msc_ram_descriptor[] = {
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
#endif
|
||||
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
@@ -125,6 +189,7 @@ static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(RT_CHERRYUSB_DEVICE_TEMPLATE_MSC_BLKDEV) && !defined(PKG_CHERRYUSB_DEVICE_TEMPLATE_MSC_BLKDEV)
|
||||
#define BLOCK_SIZE 512
|
||||
#define BLOCK_COUNT 10
|
||||
|
||||
@@ -153,12 +218,60 @@ int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *
|
||||
memcpy(mass_block[sector].BlockSpace, buffer, length);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifndef CONFIG_USBDEV_MSC_THREAD
|
||||
#error "Please enable CONFIG_USBDEV_MSC_THREAD, move msc read & write from isr to thread"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USBDEV_MSC_BLOCK_DEV_NAME
|
||||
#define CONFIG_USBDEV_MSC_BLOCK_DEV_NAME "sd0"
|
||||
#endif
|
||||
|
||||
static rt_device_t blk_dev = RT_NULL;
|
||||
struct rt_device_blk_geometry geometry = { 0 };
|
||||
|
||||
void usbd_msc_get_cap(uint8_t busid, uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
{
|
||||
rt_device_control(blk_dev, RT_DEVICE_CTRL_BLK_GETGEOME, &geometry);
|
||||
|
||||
*block_num = geometry.sector_count;
|
||||
*block_size = geometry.bytes_per_sector;
|
||||
}
|
||||
|
||||
int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
rt_device_read(blk_dev, sector, buffer, length / geometry.bytes_per_sector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
rt_device_write(blk_dev, sector, buffer, length / geometry.bytes_per_sector);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct usbd_interface intf0;
|
||||
|
||||
void msc_ram_init(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
#if defined(RT_CHERRYUSB_DEVICE_TEMPLATE_MSC_BLKDEV) || defined(PKG_CHERRYUSB_DEVICE_TEMPLATE_MSC_BLKDEV)
|
||||
rt_err_t res;
|
||||
|
||||
blk_dev = rt_device_find(CONFIG_USBDEV_MSC_BLOCK_DEV_NAME);
|
||||
RT_ASSERT(blk_dev);
|
||||
|
||||
res = rt_device_open(blk_dev, RT_DEVICE_OFLAG_RDWR);
|
||||
RT_ASSERT(res == RT_EOK);
|
||||
#endif
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(busid, &msc_ram_descriptor);
|
||||
#else
|
||||
usbd_desc_register(busid, msc_ram_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(busid, usbd_msc_init_intf(busid, &intf0, MSC_OUT_EP, MSC_IN_EP));
|
||||
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user