forked from PAWPAW-Mirror/lib_xua
Compare commits
395 Commits
v3.3.0
...
xu316yidu_
| Author | SHA1 | Date | |
|---|---|---|---|
| 50ba897b9e | |||
| f5556c618a | |||
| 09678f5971 | |||
|
|
c4da4c5653 | ||
|
|
3a78f44872 | ||
|
|
425eb89e07 | ||
|
|
aef5311a4b | ||
|
|
24a62d5cfd | ||
|
|
5caee234e5 | ||
|
|
e92665174d | ||
|
|
aa769dabb4 | ||
|
|
5daee760af | ||
|
|
a96a137533 | ||
|
|
a982c24303 | ||
|
|
974ede7aab | ||
|
|
c7d0449a1f | ||
|
|
f401831766 | ||
|
|
6b055755d8 | ||
|
|
cf80a9aeaf | ||
|
|
6adf19ad93 | ||
|
|
d32ff7b3f6 | ||
|
|
a9f4f51f03 | ||
|
|
0595d8c8f7 | ||
|
|
4b2cd1c5ca | ||
|
|
ec3b8a2832 | ||
|
|
99a0535198 | ||
|
|
c9f3c53228 | ||
|
|
cb690527c9 | ||
|
|
1308f3a1cb | ||
|
|
a11195b54a | ||
|
|
89541bb88f | ||
|
|
b635b0a64b | ||
|
|
70a45d219c | ||
|
|
e4517f3776 | ||
|
|
ac0e1ebe7b | ||
|
|
7ea3ead62d | ||
|
|
a942c8af3d | ||
|
|
708f65b3e9 | ||
|
|
d861d358c4 | ||
|
|
09269c61fa | ||
|
|
f7df5fca20 | ||
|
|
4a74c81a96 | ||
|
|
ad91d19f94 | ||
|
|
f97f4dbf9b | ||
|
|
823eed0725 | ||
|
|
a9762e048a | ||
|
|
67b90f6c8c | ||
|
|
62b74a0419 | ||
|
|
a73bb8217b | ||
|
|
e1352e93d8 | ||
|
|
7a52b7dd83 | ||
|
|
8c4043fd4c | ||
|
|
6023af906e | ||
|
|
3d5b9608dc | ||
|
|
82bcb360a4 | ||
|
|
653bd73143 | ||
|
|
1ec2c28ded | ||
|
|
a81bd2ba48 | ||
|
|
415bd8605d | ||
|
|
a19d968a8b | ||
|
|
6c49d5fe36 | ||
|
|
d8cc579518 | ||
|
|
3f00a9ae10 | ||
|
|
509cd4fc2e | ||
|
|
ebf4d0e387 | ||
|
|
28a530685f | ||
|
|
d429068bcf | ||
|
|
d57559764f | ||
|
|
45ad7bc425 | ||
|
|
8627ef9744 | ||
|
|
98cfaffd4b | ||
|
|
19a18c2db5 | ||
|
|
867da0d9c9 | ||
|
|
787ffee132 | ||
|
|
7acd4ffe99 | ||
|
|
9ddfff1d60 | ||
|
|
92fd8aa11b | ||
|
|
6562a35b73 | ||
|
|
c2da737961 | ||
|
|
c5b44caeff | ||
|
|
4e4a026261 | ||
|
|
d163ccc7ef | ||
|
|
32ddf24e39 | ||
|
|
a3670d6b85 | ||
|
|
9201d7a570 | ||
|
|
655612c673 | ||
|
|
873f5bedd8 | ||
|
|
e83bbf51cf | ||
|
|
8a90660f7c | ||
|
|
ba0f07d355 | ||
|
|
cd497a0c78 | ||
|
|
bee1d878af | ||
|
|
365e9bf014 | ||
|
|
d02561da19 | ||
|
|
d55ade4ecf | ||
|
|
1848209a63 | ||
|
|
7fbf400ded | ||
|
|
ca3a7eb1f9 | ||
|
|
bbd0f2693d | ||
|
|
76ab4060d5 | ||
|
|
8a991dd638 | ||
|
|
9a8dfea641 | ||
|
|
25cd5ffafc | ||
|
|
5f4aa1f7a2 | ||
|
|
e5fb428880 | ||
|
|
aecffab0c6 | ||
|
|
82f7649079 | ||
|
|
7853807790 | ||
|
|
fb6cdbb57b | ||
|
|
5822ec7037 | ||
|
|
7967275001 | ||
|
|
c960d82233 | ||
|
|
b15eb3a329 | ||
|
|
36b32a36db | ||
|
|
540fb4baa5 | ||
|
|
398d966145 | ||
|
|
a6969a8610 | ||
|
|
53bd0e4c29 | ||
|
|
098c39b659 | ||
|
|
977408d3bf | ||
|
|
4e4ae01a35 | ||
|
|
17206d4b8f | ||
|
|
2fbeb47191 | ||
|
|
255ca79718 | ||
|
|
4589319151 | ||
|
|
e789da24d3 | ||
|
|
7ffeaf3dde | ||
|
|
9ba6425d83 | ||
|
|
8f63590956 | ||
|
|
6235c168a1 | ||
|
|
f3a0dbc79f | ||
|
|
68a1a793cc | ||
|
|
0fc8aec495 | ||
|
|
4e893d4565 | ||
|
|
c11e62e27f | ||
|
|
57d5ea7613 | ||
|
|
03a646f95d | ||
|
|
05c8c44619 | ||
|
|
0d913cdce3 | ||
|
|
165417962f | ||
|
|
cffb7a272d | ||
|
|
41566b3970 | ||
|
|
7847a5ee42 | ||
|
|
8ec5f8c7fc | ||
|
|
4d3fe82113 | ||
|
|
5980d0edea | ||
|
|
e72a386fa2 | ||
|
|
0d1f81276d | ||
|
|
7febbfdcd0 | ||
|
|
44049ecfca | ||
|
|
d49c6b4656 | ||
|
|
3be17bf8cc | ||
|
|
e8317eae36 | ||
|
|
5669a5b021 | ||
|
|
fc708fe4e9 | ||
|
|
f32955a419 | ||
|
|
a9ed38252c | ||
|
|
27a7d185d1 | ||
|
|
7126b91848 | ||
|
|
cb84d69231 | ||
|
|
8b58fe5aaa | ||
|
|
fe6afc93de | ||
|
|
eb4b19ce16 | ||
|
|
3d9d174dcc | ||
|
|
f0709d35fc | ||
|
|
4edf86b3a6 | ||
|
|
de0279d769 | ||
|
|
a12111ba55 | ||
|
|
1b6a785b03 | ||
|
|
2d1585b8b1 | ||
|
|
eb6ed9f56e | ||
|
|
af9a6b18b2 | ||
|
|
ca16467158 | ||
|
|
aac2b4b7fb | ||
|
|
c0a844c303 | ||
|
|
103aa8840b | ||
|
|
a4e6fd0194 | ||
|
|
57debd0558 | ||
|
|
de6210d1dd | ||
|
|
ce987622d9 | ||
|
|
e04ecf5fc9 | ||
|
|
d81b510102 | ||
|
|
8ef63fcdf5 | ||
|
|
529aea28dc | ||
|
|
edbadca0cd | ||
|
|
13d9229f52 | ||
|
|
a0610fc1e0 | ||
|
|
334f36e5e1 | ||
|
|
c412c81fe3 | ||
|
|
9abfa167ca | ||
|
|
c6a970d7c0 | ||
|
|
3291a05493 | ||
|
|
91d23fb1d6 | ||
|
|
2fcc9ca2ac | ||
|
|
6d8d66f823 | ||
|
|
23f1a8d48e | ||
|
|
e6899afbb9 | ||
|
|
87a105d8f6 | ||
|
|
3003ce7241 | ||
|
|
ccaaf40ab3 | ||
|
|
dc81964f22 | ||
|
|
a3419fdba7 | ||
|
|
4962cebc9c | ||
|
|
56d728f349 | ||
|
|
7f8f07b4b6 | ||
|
|
8e161707a5 | ||
|
|
b242c54574 | ||
|
|
702e8d14b9 | ||
|
|
ace59f63a4 | ||
|
|
780a407519 | ||
|
|
61f17f3fe9 | ||
|
|
d644775e4c | ||
|
|
2133598347 | ||
|
|
7b843b1d56 | ||
|
|
f035e1dc13 | ||
|
|
c5496ea994 | ||
|
|
b0db22a50b | ||
|
|
1f74f8c601 | ||
|
|
9f8a4e737f | ||
|
|
c57079cd4a | ||
|
|
5a78b5079f | ||
|
|
5b5ee132e0 | ||
|
|
15c3007d1c | ||
|
|
ab7a94a821 | ||
|
|
29156d5b19 | ||
|
|
5e5b2b7bd5 | ||
|
|
eebbb88fee | ||
|
|
db63b93ac1 | ||
|
|
32c783795b | ||
|
|
5b37c4d224 | ||
|
|
8fbe410e0e | ||
|
|
52b72285e0 | ||
|
|
2cfaff9221 | ||
|
|
0f4cb1ccb5 | ||
|
|
bd702db2c6 | ||
|
|
764fe0bfe9 | ||
|
|
f1d902306f | ||
|
|
74894341d1 | ||
|
|
a89df80da8 | ||
|
|
07ffd9221a | ||
|
|
7bbaff49af | ||
|
|
f970623edf | ||
|
|
b4c1587478 | ||
|
|
be682f2b72 | ||
|
|
86f531b6ea | ||
|
|
66e6894f95 | ||
|
|
a8a0feaf52 | ||
|
|
fc3e3636ec | ||
|
|
a796e1ee36 | ||
|
|
b49bd69abe | ||
|
|
ae550d5fc9 | ||
|
|
a485ffe41a | ||
|
|
f25a9eeade | ||
|
|
dff72573f8 | ||
|
|
f7331a1ed3 | ||
|
|
aaaf1e9652 | ||
|
|
d6b23cf960 | ||
|
|
fa8329edaa | ||
|
|
83d86e885f | ||
|
|
15036f2bcc | ||
|
|
fa5723947f | ||
|
|
b1b28f1005 | ||
|
|
6d41cfcbea | ||
|
|
5404127dbf | ||
|
|
e5a270347a | ||
|
|
f509a12e7d | ||
|
|
4528bed740 | ||
|
|
e812ca3e8b | ||
|
|
2accc0429f | ||
|
|
36d5201365 | ||
|
|
cea580ba48 | ||
|
|
6815f12a90 | ||
|
|
799ad7ba86 | ||
|
|
3d7e66bdc0 | ||
|
|
a6387d5fef | ||
|
|
5ca0738b02 | ||
|
|
b0e732110d | ||
|
|
1702078e7c | ||
|
|
136ec2506c | ||
|
|
45e5ef7702 | ||
|
|
1ef5129fde | ||
|
|
b1fe49aff3 | ||
|
|
d3ad29e8a6 | ||
|
|
17944ad908 | ||
|
|
131dd252c0 | ||
|
|
23d043630f | ||
|
|
761a33f5e4 | ||
|
|
12ec1d7536 | ||
|
|
2dba6dce36 | ||
|
|
9cf931898e | ||
|
|
9b104af8cf | ||
|
|
c469dd6cde | ||
|
|
b238196f74 | ||
|
|
e9586b59d3 | ||
|
|
6d168b3209 | ||
|
|
d301fef6d7 | ||
|
|
1f4e9a99b8 | ||
|
|
981ea78be7 | ||
|
|
6cee90d876 | ||
|
|
79d14f8b59 | ||
|
|
05dcb8f3ab | ||
|
|
4e7ddb4036 | ||
|
|
e8fcc80415 | ||
|
|
71a657dc9a | ||
|
|
ccfca90451 | ||
|
|
cb379f5bfb | ||
|
|
e2c36a9a95 | ||
|
|
7e3ae59acc | ||
|
|
f1f453921b | ||
|
|
7703fc1a7d | ||
|
|
53a65344fc | ||
|
|
3b2814f8cb | ||
|
|
55a62cf589 | ||
|
|
4a84c3e1ec | ||
|
|
b17f585004 | ||
|
|
57593bfea3 | ||
|
|
8dc77090bf | ||
|
|
9c20fab216 | ||
|
|
cf1940245f | ||
|
|
837b648bbc | ||
|
|
c1159143ea | ||
|
|
2964861b70 | ||
|
|
208491fe51 | ||
|
|
3fe4593b52 | ||
|
|
49a116c705 | ||
|
|
eee5b474a0 | ||
|
|
4655a07542 | ||
|
|
c578bb92d5 | ||
|
|
d5a614df55 | ||
|
|
495140ab8d | ||
|
|
f53c1bab09 | ||
|
|
0c6d947e67 | ||
|
|
ee271e3769 | ||
|
|
950beb55cb | ||
|
|
ca3276792a | ||
|
|
e26b934233 | ||
|
|
51629dba24 | ||
|
|
c5e944d73d | ||
|
|
22a3d5e043 | ||
|
|
58f691078d | ||
|
|
f80d7647e0 | ||
|
|
fe697929bc | ||
|
|
b265ccd8bf | ||
|
|
6c2e7e3042 | ||
|
|
15ca5ec281 | ||
|
|
71aa64425d | ||
|
|
9080990234 | ||
|
|
6d8cf9913f | ||
|
|
60040de58f | ||
|
|
27a59ab3bc | ||
|
|
317e27e421 | ||
|
|
035c20e01c | ||
|
|
ef97d667de | ||
|
|
0e07dc29bc | ||
|
|
43f77c177d | ||
|
|
6754f812c9 | ||
|
|
fc732b8512 | ||
|
|
39ed235476 | ||
|
|
0d7224bd6d | ||
|
|
fd4dfd40a9 | ||
|
|
3d50c96595 | ||
|
|
379e8eb54c | ||
|
|
63763cf4f5 | ||
|
|
b18c34fb0f | ||
|
|
64d65afeaf | ||
|
|
7a47d70229 | ||
|
|
ce8e5a6dbb | ||
|
|
bbed806aab | ||
|
|
9af31b8c70 | ||
|
|
73955c1a4c | ||
|
|
cffd35d146 | ||
|
|
ab535e0fb3 | ||
|
|
17b039dce8 | ||
|
|
7a0d0e1f97 | ||
|
|
2f31260612 | ||
|
|
9922190450 | ||
|
|
0ce91bec90 | ||
|
|
2404eaf35f | ||
|
|
8966ad1bb9 | ||
|
|
513761ef5b | ||
|
|
da7c45500d | ||
|
|
395c88cb22 | ||
|
|
94e58edfaf | ||
|
|
9f00f9159a | ||
|
|
785a857ca8 | ||
|
|
3130088c91 | ||
|
|
c51ee0c460 | ||
|
|
17ed636a74 | ||
|
|
0db1b08948 | ||
|
|
9c460f753f | ||
|
|
6a9537fb69 | ||
|
|
abfa3a2011 | ||
|
|
a1946f340a | ||
|
|
28be17282f | ||
|
|
a1082b1dfd |
60
.gitignore
vendored
60
.gitignore
vendored
@@ -1,29 +1,25 @@
|
||||
*.log
|
||||
*.dSYM
|
||||
*/.build_*/*
|
||||
*/bin/*
|
||||
*.o
|
||||
# XMOS bin files
|
||||
*.xe
|
||||
*.vcd
|
||||
*.swo
|
||||
*.bin
|
||||
*/bin/*
|
||||
|
||||
# XMOS temp files
|
||||
.build*
|
||||
*.a
|
||||
_build*
|
||||
*.i
|
||||
*.s
|
||||
*.xi
|
||||
*.i
|
||||
*.bin
|
||||
*~
|
||||
*.a
|
||||
*.swp
|
||||
*.*~
|
||||
*.pyc
|
||||
.build*
|
||||
*.o
|
||||
*/.build_*/*
|
||||
|
||||
# Temp files
|
||||
.DS_Store
|
||||
test_results.csv
|
||||
_build*
|
||||
**/.venv/**
|
||||
**/.vscode/**
|
||||
**.egg-info
|
||||
*.pdf
|
||||
*tests/logs/*
|
||||
*.*~
|
||||
*.swp
|
||||
*.swn
|
||||
*~
|
||||
*.swo
|
||||
|
||||
# waf build files
|
||||
.lock-waf_*
|
||||
@@ -36,3 +32,23 @@ xscope.xmt
|
||||
# Traces
|
||||
*.gtkw
|
||||
*.vcd
|
||||
|
||||
# Host binaries
|
||||
host_usb_mixer_control/xmos_mixer
|
||||
|
||||
# Documentation build
|
||||
*.pdf
|
||||
|
||||
# Misc
|
||||
*.log
|
||||
*.dSYM
|
||||
*.vcd
|
||||
*.pyc
|
||||
**/.venv/**
|
||||
**/.vscode/**
|
||||
**.egg-info
|
||||
*tests/logs/*
|
||||
midi_tx_cmds.txt
|
||||
midi_rx_cmds.txt
|
||||
trace.txt
|
||||
tests/xua_unit_tests/src.runners
|
||||
|
||||
125
CHANGELOG.rst
125
CHANGELOG.rst
@@ -1,6 +1,129 @@
|
||||
lib_xua Change Log
|
||||
lib_xua change log
|
||||
==================
|
||||
|
||||
4.1.0
|
||||
-----
|
||||
|
||||
* ADDED: MIDI unit and sub-system tests
|
||||
* CHANGED: Only the minimum number of ADAT input formats are enabled based
|
||||
on the supported sample rates
|
||||
* CHANGED: Enabling ADAT tx enables different channel count interface alts,
|
||||
based on sample rate
|
||||
* CHANGED: Input audio buffer size and the exit condition underflow modified
|
||||
to to fix buffer underflow in some configurations
|
||||
* CHANGED: CT_END token based handshake in MIDI channels transactions,
|
||||
reducing opportuninity for deadlock
|
||||
* FIXED: Device fails to enumerate when ADAT and S/PDIF transmit are
|
||||
enabled
|
||||
* FIXED: Update software PLL at the correct rate for ADAT S/MUX
|
||||
* FIXED: Incorrect internal input EP count for input only devices
|
||||
* FIXED: Samples transferred to ADAT tx too frequently in TDM mode
|
||||
* FIXED: S/MUX not initialised to a value based on DEFAULT_FREQ in
|
||||
clockgen
|
||||
* FIXED: Trap when moving to DSD mode on XS3A based devices
|
||||
|
||||
* Changes to dependencies:
|
||||
|
||||
- lib_adat: 1.0.1 -> 1.2.0
|
||||
|
||||
- lib_locks: 2.1.0 -> 2.2.0
|
||||
|
||||
- lib_logging: 3.1.1 -> 3.2.0
|
||||
|
||||
- lib_sw_pll: 2.1.0 -> 2.2.0
|
||||
|
||||
- lib_xassert: 4.1.0 -> 4.2.0
|
||||
|
||||
4.0.0
|
||||
-----
|
||||
|
||||
* ADDED: Support for XCommon CMake build system
|
||||
* FIXED: Output volume control not enabled by default when MIXER disabled
|
||||
* FIXED: Full 32bit result of volume processing not calculated when
|
||||
required
|
||||
* FIXED: Input stream sending an erroneous zero-length packet when exiting
|
||||
underflow state
|
||||
* FIXED Build failures when XUA_USB_EN = 0
|
||||
* FIXED: Clock configuration issues when ADAT and S/PDIF receive are
|
||||
enabled (#352)
|
||||
* FIXED: Repeated old S/PDIF and ADAT samples when entering underflow
|
||||
state
|
||||
* CHANGED: QUAD_SPI_FLASH replaced by XUA_QUAD_SPI_FLASH (default: 1)
|
||||
* CHANGED: UserBufferManagementInit() now takes a sample rate parameter
|
||||
* CHANGED: xcore.ai targets use sigma-delta software PLL for clock recovery
|
||||
of digital Rx streams and synchronous USB audio by default
|
||||
* CHANGED: Windows host mixer control application now requires driver GUID
|
||||
option
|
||||
|
||||
* Changes to dependencies:
|
||||
|
||||
- lib_dsp: 6.2.1 -> 6.3.0
|
||||
|
||||
- lib_mic_array: 4.5.0 -> 4.6.0
|
||||
|
||||
- lib_spdif: 5.0.1 -> 6.1.0
|
||||
|
||||
- lib_sw_pll: Added dependency 2.1.0
|
||||
|
||||
- lib_xud: 2.2.3 -> 2.3.1
|
||||
|
||||
3.5.1
|
||||
-----
|
||||
|
||||
* FIXED: Respect I2S_CHANS_PER_FRAME when calculating bit-clock rates
|
||||
|
||||
* Changes to dependencies:
|
||||
|
||||
- lib_spdif: 5.0.0 -> 5.0.1
|
||||
|
||||
3.5.0
|
||||
-----
|
||||
|
||||
* ADDED: Configurable word-length for I2S/TDM via XUA_I2S_N_BITS
|
||||
* ADDED: Support for statically defined custom HID descriptor
|
||||
* CHANGED: Rearranged main() such that adding custom code that uses lib_xud
|
||||
is possible
|
||||
* CHANGED: bNumConfigurations changed from 2 to 1, removing a work-around to
|
||||
stop old Windows versions loading the composite driver
|
||||
* FIXED: Memory corruption due to erroneous initialisation of mixer
|
||||
weights when not in use (#152)
|
||||
* FIXED: UserHostActive() not being called as expected (#326)
|
||||
* FIXED: Exception when entering DSD mode (#327)
|
||||
|
||||
* Changes to dependencies:
|
||||
|
||||
- lib_spdif: 4.2.1 -> 5.0.0
|
||||
|
||||
- lib_xud: 2.2.2 -> 2.2.3
|
||||
|
||||
3.4.0
|
||||
-----
|
||||
|
||||
* ADDED: Unit tests for mixer functionality
|
||||
* ADDED: Host mixer control applications (for Win/macOS)
|
||||
* CHANGED: Small tidies to mixer implementation
|
||||
* CHANGED: Improved mixer control channel communication protocol to avoid
|
||||
deadlock situations
|
||||
* CHANGED: By default, output volume processing occurs in mixer task, if
|
||||
present. Previously occurred in decouple task
|
||||
* CHANGED: Some optimisations in sample transfer from decouple task
|
||||
* FIXED: Exception on startup when USB input disabled
|
||||
* FIXED: Full 32bit volume processing only applied when required
|
||||
* FIXED: Setting OUT_VOLUME_AFTER_MIX to zero now has the expected effect
|
||||
|
||||
* Changes to dependencies:
|
||||
|
||||
- lib_xud: 2.2.1 -> 2.2.2
|
||||
|
||||
3.3.1
|
||||
-----
|
||||
|
||||
* CHANGED: Documentation updates
|
||||
|
||||
* Changes to dependencies:
|
||||
|
||||
- lib_spdif: 4.1.0 -> 4.2.1
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
|
||||
42
Jenkinsfile
vendored
42
Jenkinsfile
vendored
@@ -1,4 +1,4 @@
|
||||
@Library('xmos_jenkins_shared_library@v0.18.0') _
|
||||
@Library('xmos_jenkins_shared_library@v0.27.0') _
|
||||
|
||||
getApproval()
|
||||
|
||||
@@ -7,6 +7,7 @@ pipeline {
|
||||
environment {
|
||||
REPO = 'lib_xua'
|
||||
VIEW = getViewName(REPO)
|
||||
TOOLS_VERSION = "15.2.1" // For unit tests
|
||||
}
|
||||
options {
|
||||
skipDefaultCheckout()
|
||||
@@ -24,7 +25,7 @@ pipeline {
|
||||
}
|
||||
stage('Library checks') {
|
||||
steps {
|
||||
xcoreLibraryChecks("${REPO}")
|
||||
xcoreLibraryChecks("${REPO}", false)
|
||||
}
|
||||
}
|
||||
stage('Testing') {
|
||||
@@ -35,7 +36,8 @@ pipeline {
|
||||
dir("${REPO}/tests"){
|
||||
viewEnv(){
|
||||
withVenv{
|
||||
runPytest('--numprocesses=4')
|
||||
sh "xmake -C test_midi -j" // Xdist does not like building so do here
|
||||
runPytest('--numprocesses=auto -vvv')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,14 +45,14 @@ pipeline {
|
||||
}
|
||||
stage('Unity tests') {
|
||||
steps {
|
||||
dir("${REPO}") {
|
||||
dir('tests') {
|
||||
dir('xua_unit_tests') {
|
||||
withVenv {
|
||||
runWaf('.', "configure clean build --target=xcore200")
|
||||
viewEnv() {
|
||||
runPython("TARGET=XCORE200 pytest -s")
|
||||
}
|
||||
dir("${REPO}/tests/xua_unit_tests") {
|
||||
withTools("${env.TOOLS_VERSION}") {
|
||||
withVenv {
|
||||
withEnv(["XMOS_CMAKE_PATH=${WORKSPACE}/xcommon_cmake"]) {
|
||||
sh "cmake -G 'Unix Makefiles' -B build"
|
||||
sh 'xmake -C build -j'
|
||||
runPython("pytest -s --junitxml=pytest_unity.xml")
|
||||
junit "pytest_unity.xml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,6 +108,12 @@ pipeline {
|
||||
dir("${REPO}/${REPO}/host/xmosdfu") {
|
||||
sh 'make -f Makefile.OSX64'
|
||||
}
|
||||
dir("${REPO}/host_usb_mixer_control") {
|
||||
sh 'make -f Makefile.OSX'
|
||||
sh 'mkdir OSX/x86'
|
||||
sh 'mv xmos_mixer OSX/x86/xmos_mixer'
|
||||
archiveArtifacts artifacts: "OSX/x86/xmos_mixer", fingerprint: true
|
||||
}
|
||||
}
|
||||
post {
|
||||
cleanup {
|
||||
@@ -139,7 +147,17 @@ pipeline {
|
||||
dir("${REPO}") {
|
||||
checkout scm
|
||||
dir("${REPO}/host/xmosdfu") {
|
||||
runVS('nmake /f Makefile.Win32')
|
||||
withVS("vcvars32.bat") {
|
||||
bat "nmake /f Makefile.Win32"
|
||||
}
|
||||
}
|
||||
dir("host_usb_mixer_control") {
|
||||
withVS() {
|
||||
bat 'msbuild host_usb_mixer_control.vcxproj /property:Configuration=Release /property:Platform=x64'
|
||||
}
|
||||
bat 'mkdir Win\\x64'
|
||||
bat 'mv bin/Release/x64/host_usb_mixer_control.exe Win/x64/xmos_mixer.exe'
|
||||
archiveArtifacts artifacts: "Win/x64/xmos_mixer.exe", fingerprint: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
58
README.rst
58
README.rst
@@ -1,20 +1,20 @@
|
||||
lib_xua
|
||||
=======
|
||||
|
||||
:Latest release: 3.3.0
|
||||
#######
|
||||
|
||||
:Version: 4.0.0
|
||||
:Vendor: XMOS
|
||||
|
||||
:Scope: General Use
|
||||
|
||||
Summary
|
||||
-------
|
||||
*******
|
||||
|
||||
lib_xua contains shared components for use in the XMOS USB Audio (XUA) Reference Designs.
|
||||
|
||||
These components enable the development of USB Audio devices on the XMOS xCORE architecture.
|
||||
|
||||
Features
|
||||
~~~~~~~~
|
||||
========
|
||||
|
||||
Key features of the various components in this repository are as follows
|
||||
|
||||
@@ -40,9 +40,9 @@ Key features of the various components in this repository are as follows
|
||||
|
||||
- Synchronisation to external digital streams i.e. S/PDIF or ADAT (when in asynchronous mode)
|
||||
|
||||
- I2S slave & master modes
|
||||
- I2S (slave/master modes with configurable word-length)
|
||||
|
||||
- TDM slave & master modes
|
||||
- TDM (slave/master modes with configurable word-length)
|
||||
|
||||
- MIDI input/output (Compliant to USB Class Specification for MIDI devices)
|
||||
|
||||
@@ -52,11 +52,13 @@ Key features of the various components in this repository are as follows
|
||||
|
||||
- Simple playback controls via USB Human Interface Device (HID) Class
|
||||
|
||||
- Support for adding custom HID interfaces
|
||||
|
||||
Note, not all features may be supported at all sample frequencies, simultaneously or on all devices.
|
||||
Some features may also require specific host driver support.
|
||||
|
||||
Host System Requirements
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
========================
|
||||
|
||||
USB Audio devices built using `lib_xua` have the following host system requirements.
|
||||
|
||||
@@ -69,27 +71,33 @@ USB Audio devices built using `lib_xua` have the following host system requireme
|
||||
Older versions of Windows are not guaranteed to operate as expected. Devices are also expected to operate with various Linux distributions including mobile variants.
|
||||
|
||||
Related Application Notes
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
=========================
|
||||
|
||||
The following application notes use this library:
|
||||
|
||||
* AN000246 - Simple USB Audio Device using lib_xua
|
||||
* AN000247 - Using lib_xua with lib_spdif (transmit)
|
||||
* AN000248 - Using lib_xua with lib_mic_array
|
||||
* AN000246 - Simple USB Audio Device using lib_xua
|
||||
* AN000247 - Using lib_xua with lib_spdif (transmit)
|
||||
* AN000248 - Using lib_xua with lib_mic_array
|
||||
|
||||
Required software (dependencies)
|
||||
Required Software (dependencies)
|
||||
================================
|
||||
|
||||
* lib_locks (git@github.com:xmos/lib_locks.git)
|
||||
* lib_logging (git@github.com:xmos/lib_logging.git)
|
||||
* lib_mic_array (git@github.com:xmos/lib_mic_array.git)
|
||||
* lib_xassert (git@github.com:xmos/lib_xassert.git)
|
||||
* lib_dsp (git@github.com:xmos/lib_dsp)
|
||||
* lib_i2c (git@github.com:xmos/lib_i2c.git)
|
||||
* lib_i2s (git@github.com:xmos/lib_i2s.git)
|
||||
* lib_gpio (git@github.com:xmos/lib_gpio.git)
|
||||
* lib_mic_array_board_support (git@github.com:xmos/lib_mic_array_board_support.git)
|
||||
* lib_spdif (git@github.com:xmos/lib_spdif.git)
|
||||
* lib_xud (git@github.com:xmos/lib_xud.git)
|
||||
* lib_adat (git@github.com:xmos/lib_adat)
|
||||
* lib_adat (www.github.com/xmos/lib_adat)
|
||||
* lib_locks (www.github.com/xmos/lib_locks)
|
||||
* lib_logging (www.github.com/xmos/lib_logging)
|
||||
* lib_mic_array (www.github.com/xmos/lib_mic_array)
|
||||
* lib_xassert (www.github.com/xmos/lib_xassert)
|
||||
* lib_dsp (www.github.com/xmos/lib_dsp)
|
||||
* lib_spdif (www.github.com/xmos/lib_spdif)
|
||||
* lib_sw_pll (www.github.com/xmos/lib_sw_pll)
|
||||
* lib_xud (www.github.com/xmos/lib_xud)
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
You can find the documentation for this software in the /doc directory of the package.
|
||||
|
||||
Support
|
||||
=======
|
||||
|
||||
This package is supported by XMOS Ltd. Issues can be raised against the software at: http://www.xmos.com/support
|
||||
|
||||
@@ -21,4 +21,3 @@ USED_MODULES = lib_xua lib_xud lib_i2c
|
||||
|
||||
XMOS_MAKE_PATH ?= ../..
|
||||
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Required hardware
|
||||
.................
|
||||
|
||||
The example code provided with the application has been implemented
|
||||
and tested on the xCORE-200 Multi-channel Audio Board
|
||||
and tested on the xCORE.ai Multi-channel Audio Board
|
||||
|
||||
Prerequisites
|
||||
.............
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// Copyright 2017-2022 XMOS LIMITED.
|
||||
// Copyright 2017-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include <xs1.h>
|
||||
#include <platform.h>
|
||||
#include "xua.h"
|
||||
#include "../../shared/apppll.h"
|
||||
extern "C"{
|
||||
#include "sw_pll.h"
|
||||
}
|
||||
|
||||
on tile[0]: out port p_ctrl = XS1_PORT_8D;
|
||||
|
||||
@@ -38,19 +40,26 @@ void AudioHwInit()
|
||||
delay_milliseconds(100);
|
||||
|
||||
/* Use xCORE Secondary PLL to generate *fixed* master clock */
|
||||
AppPllEnable_SampleRate(DEFAULT_FREQ);
|
||||
if(DEFAULT_FREQ % 22050 == 0)
|
||||
{
|
||||
sw_pll_fixed_clock(MCLK_441);
|
||||
}
|
||||
else
|
||||
{
|
||||
sw_pll_fixed_clock(MCLK_48);
|
||||
}
|
||||
|
||||
delay_milliseconds(100);
|
||||
|
||||
/* DAC setup: For basic I2S input we don't need any register setup. DACs will clock auto detect etc.
|
||||
* It holds DAC in reset until it gets clocks anyway.
|
||||
* Note, this example doesn't use the ADC's
|
||||
* Note, this example doesn't use the ADCs
|
||||
*/
|
||||
}
|
||||
|
||||
/* Configures the external audio hardware for the required sample frequency */
|
||||
void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode, unsigned sampRes_DAC, unsigned sampRes_ADC)
|
||||
{
|
||||
AppPllEnable_SampleRate(samFreq);
|
||||
sw_pll_fixed_clock(mClk);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,4 +20,3 @@ USED_MODULES = lib_xua lib_xud lib_spdif
|
||||
|
||||
XMOS_MAKE_PATH ?= ../..
|
||||
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
// Copyright 2017-2022 XMOS LIMITED.
|
||||
// Copyright 2017-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include <xs1.h>
|
||||
#include <platform.h>
|
||||
#include "xua.h"
|
||||
#include "../../shared/apppll.h"
|
||||
#include "xassert.h"
|
||||
extern "C"{
|
||||
#include "sw_pll.h"
|
||||
}
|
||||
|
||||
on tile[0]: out port p_ctrl = XS1_PORT_8D;
|
||||
|
||||
@@ -38,19 +41,26 @@ void AudioHwInit()
|
||||
delay_milliseconds(100);
|
||||
|
||||
/* Use xCORE Secondary PLL to generate *fixed* master clock */
|
||||
AppPllEnable_SampleRate(DEFAULT_FREQ);
|
||||
if(DEFAULT_FREQ % 22050 == 0)
|
||||
{
|
||||
sw_pll_fixed_clock(MCLK_441);
|
||||
}
|
||||
else
|
||||
{
|
||||
sw_pll_fixed_clock(MCLK_48);
|
||||
}
|
||||
|
||||
delay_milliseconds(100);
|
||||
|
||||
/* DAC setup: For basic I2S input we don't need any register setup. DACs will clock auto detect etc.
|
||||
* It holds DAC in reset until it gets clocks anyway.
|
||||
* Note, this example doesn't use the ADC's
|
||||
* Note, this example doesn't use the ADCs
|
||||
*/
|
||||
}
|
||||
|
||||
/* Configures the external audio hardware for the required sample frequency */
|
||||
void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode, unsigned sampRes_DAC, unsigned sampRes_ADC)
|
||||
{
|
||||
AppPllEnable_SampleRate(samFreq);
|
||||
sw_pll_fixed_clock(mClk);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,3 @@ USED_MODULES = lib_xua lib_xud lib_mic_array
|
||||
|
||||
XMOS_MAKE_PATH ?= ../..
|
||||
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
|
||||
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
// Copyright 2022 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include <stdint.h>
|
||||
#include "xassert.h"
|
||||
|
||||
// App PLL setup
|
||||
#define APP_PLL_CTL_BYPASS (0) // 0 = no bypass, 1 = bypass.
|
||||
#define APP_PLL_CTL_INPUT_SEL (0) // 0 = XTAL, 1 = sysPLL
|
||||
#define APP_PLL_CTL_ENABLE (1) // 0 = disabled, 1 = enabled.
|
||||
|
||||
// 24MHz in, 24.576MHz out, integer mode
|
||||
// Found exact solution: IN 24000000.0, OUT 24576000.0, VCO 2457600000.0, RD 5, FD 512, OD 10, FOD 10
|
||||
#define APP_PLL_CTL_OD_48 (4) // Output divider = (OD+1)
|
||||
#define APP_PLL_CTL_F_48 (511) // FB divider = (F+1)/2
|
||||
#define APP_PLL_CTL_R_48 (4) // Ref divider = (R+1)
|
||||
|
||||
#define APP_PLL_CTL_48 ((APP_PLL_CTL_BYPASS << 29) | (APP_PLL_CTL_INPUT_SEL << 28) | (APP_PLL_CTL_ENABLE << 27) |\
|
||||
(APP_PLL_CTL_OD_48 << 23) | (APP_PLL_CTL_F_48 << 8) | APP_PLL_CTL_R_48)
|
||||
|
||||
// Fractional divide is M/N
|
||||
#define APP_PLL_FRAC_EN_48 (0) // 0 = disabled
|
||||
#define APP_PLL_FRAC_NPLUS1_CYCLES_48 (0) // M value is this reg value + 1.
|
||||
#define APP_PLL_FRAC_TOTAL_CYCLES_48 (0) // N value is this reg value + 1.
|
||||
#define APP_PLL_FRAC_48 ((APP_PLL_FRAC_EN_48 << 31) | (APP_PLL_FRAC_NPLUS1_CYCLES_48 << 8) | APP_PLL_FRAC_TOTAL_CYCLES_48)
|
||||
|
||||
// 24MHz in, 22.5792MHz out (44.1kHz * 512), frac mode
|
||||
// Found exact solution: IN 24000000.0, OUT 22579200.0, VCO 2257920000.0, RD 5, FD 470.400 (m = 2, n = 5), OD 5, FOD 10
|
||||
#define APP_PLL_CTL_OD_441 (4) // Output divider = (OD+1)
|
||||
#define APP_PLL_CTL_F_441 (469) // FB divider = (F+1)/2
|
||||
#define APP_PLL_CTL_R_441 (4) // Ref divider = (R+1)
|
||||
|
||||
#define APP_PLL_CTL_441 ((APP_PLL_CTL_BYPASS << 29) | (APP_PLL_CTL_INPUT_SEL << 28) | (APP_PLL_CTL_ENABLE << 27) |\
|
||||
(APP_PLL_CTL_OD_441 << 23) | (APP_PLL_CTL_F_441 << 8) | APP_PLL_CTL_R_441)
|
||||
|
||||
#define APP_PLL_FRAC_EN_44 (1) // 1 = enabled
|
||||
#define APP_PLL_FRAC_NPLUS1_CYCLES_44 (1) // M value is this reg value + 1.
|
||||
#define APP_PLL_FRAC_TOTAL_CYCLES_44 (4) // N value is this reg value + 1.define APP_PLL_CTL_R_441 (4) // Ref divider = (R+1)
|
||||
#define APP_PLL_FRAC_44 ((APP_PLL_FRAC_EN_44 << 31) | (APP_PLL_FRAC_NPLUS1_CYCLES_44 << 8) | APP_PLL_FRAC_TOTAL_CYCLES_44)
|
||||
|
||||
#define APP_PLL_DIV_INPUT_SEL (1) // 0 = sysPLL, 1 = app_PLL
|
||||
#define APP_PLL_DIV_DISABLE (0) // 1 = disabled (pin connected to X1D11), 0 = enabled divider output to pin.
|
||||
#define APP_PLL_DIV_VALUE (4) // Divide by N+1 - remember there's a /2 also afterwards for 50/50 duty cycle.
|
||||
#define APP_PLL_DIV ((APP_PLL_DIV_INPUT_SEL << 31) | (APP_PLL_DIV_DISABLE << 16) | APP_PLL_DIV_VALUE)
|
||||
|
||||
/* TODO support more than two freqs..*/
|
||||
void AppPllEnable(int32_t clkFreq_hz)
|
||||
{
|
||||
switch(clkFreq_hz)
|
||||
{
|
||||
case 44100*512:
|
||||
|
||||
// Disable the PLL
|
||||
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, (APP_PLL_CTL_441 & 0xF7FFFFFF));
|
||||
// Enable the PLL to invoke a reset on the appPLL.
|
||||
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_441);
|
||||
// Must write the CTL register twice so that the F and R divider values are captured using a running clock.
|
||||
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_441);
|
||||
// Now disable and re-enable the PLL so we get the full 5us reset time with the correct F and R values.
|
||||
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, (APP_PLL_CTL_441 & 0xF7FFFFFF));
|
||||
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_441);
|
||||
|
||||
// Set the fractional divider if used
|
||||
write_node_config_reg(tile[0], XS1_SSWITCH_SS_APP_PLL_FRAC_N_DIVIDER_NUM, APP_PLL_FRAC_44);
|
||||
|
||||
break;
|
||||
|
||||
case 48000*512:
|
||||
|
||||
// Disable the PLL
|
||||
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, (APP_PLL_CTL_48 & 0xF7FFFFFF));
|
||||
// Enable the PLL to invoke a reset on the appPLL.
|
||||
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_48);
|
||||
// Must write the CTL register twice so that the F and R divider values are captured using a running clock.
|
||||
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_48);
|
||||
// Now disable and re-enable the PLL so we get the full 5us reset time with the correct F and R values.
|
||||
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, (APP_PLL_CTL_48 & 0xF7FFFFFF));
|
||||
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_48);
|
||||
|
||||
// Set the fractional divider if used
|
||||
write_node_config_reg(tile[0], XS1_SSWITCH_SS_APP_PLL_FRAC_N_DIVIDER_NUM, APP_PLL_FRAC_48);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
|
||||
// Wait for PLL output frequency to stabilise due to fractional divider enable
|
||||
delay_microseconds(100);
|
||||
|
||||
// Turn on the clock output
|
||||
write_node_config_reg(tile[0], XS1_SSWITCH_SS_APP_CLK_DIVIDER_NUM, APP_PLL_DIV);
|
||||
}
|
||||
|
||||
void AppPllEnable_SampleRate(int32_t sampleRate_hz)
|
||||
{
|
||||
assert(sampleRate_hz >= 22050);
|
||||
|
||||
if(sampleRate_hz % 22050 == 0)
|
||||
{
|
||||
AppPllEnable(44100*512);
|
||||
}
|
||||
else
|
||||
{
|
||||
AppPllEnable(48000*512);
|
||||
}
|
||||
}
|
||||
|
||||
10
host_usb_mixer_control/.makefile
Normal file
10
host_usb_mixer_control/.makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
all:
|
||||
@echo =======================================================
|
||||
@echo Build complete [module only - cannot be run on its own]
|
||||
@echo =======================================================
|
||||
|
||||
clean:
|
||||
@echo =======================================================
|
||||
@echo Build clean [module only - cannot be run on its own]
|
||||
@echo =======================================================
|
||||
|
||||
77
host_usb_mixer_control/.project
Normal file
77
host_usb_mixer_control/.project
Normal file
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>host_usb_mixer_control</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>?name?</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.append_environment</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
|
||||
<value>all</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildArguments</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildCommand</key>
|
||||
<value>xmake</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
|
||||
<value>clean</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.contents</key>
|
||||
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
|
||||
<value>all</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.stopOnError</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
2
host_usb_mixer_control/Makefile.OSX
Normal file
2
host_usb_mixer_control/Makefile.OSX
Normal file
@@ -0,0 +1,2 @@
|
||||
all:
|
||||
g++ -g -o xmos_mixer usb_mixer.cpp mixer_app.cpp -I. -IOSX OSX/libusb-1.0.0.dylib -arch x86_64
|
||||
5
host_usb_mixer_control/Makefile.Win
Normal file
5
host_usb_mixer_control/Makefile.Win
Normal file
@@ -0,0 +1,5 @@
|
||||
!if [set SDKPath=C:\Program^ Files\XMOS\tusbaudiosdk]
|
||||
!endif
|
||||
|
||||
all:
|
||||
msbuild host_usb_mixer_control.vcxproj /property:Configuration=Release /property:Platform=x64
|
||||
BIN
host_usb_mixer_control/OSX/libusb-1.0.0.dylib
Normal file
BIN
host_usb_mixer_control/OSX/libusb-1.0.0.dylib
Normal file
Binary file not shown.
1233
host_usb_mixer_control/OSX/libusb.h
Normal file
1233
host_usb_mixer_control/OSX/libusb.h
Normal file
File diff suppressed because it is too large
Load Diff
117
host_usb_mixer_control/README
Normal file
117
host_usb_mixer_control/README
Normal file
@@ -0,0 +1,117 @@
|
||||
The XMOS USB Audio Reference Design, by default, contains an 18x8 mixer unit
|
||||
(note that at sample rates above 96Khz only the first two outputs are
|
||||
enabled).
|
||||
|
||||
----WINDOWS REQUIREMENTS----
|
||||
Building the mixer on Windows requires the tusbaudio SDK from Thesycon. The
|
||||
default location for the SDK is C:\Program Files\XMOS\tusbaudiosdk\
|
||||
If it can be found on a different path then this can be changed in
|
||||
Makefile.Win.
|
||||
|
||||
The mixer app on windows makes use of a USB dynamic library, also from Thesycon.
|
||||
If required please contact thesycon.de for support.
|
||||
----------------------------
|
||||
|
||||
This unit takes input takes 18 inputs: USB OUT channels 1..10 and
|
||||
DEVICE IN channels 1..6,9..10 and produces 8 outputs: Mixer Output
|
||||
1..8
|
||||
|
||||
Before the mixer there is an unit that allows the selection of the 18 mixer inputs
|
||||
from all the possible device inputs (DAW and physical audio). This is
|
||||
an extension unit with id 50 in the descriptors
|
||||
|
||||
After the mixer unit there is are channel map units for each output terminal:
|
||||
Each of these outputs can select a source from one of 28 channels sources: USB OUT
|
||||
channels 1..10, DEVICE IN channels 1..10 and Mixer Output 1..8
|
||||
|
||||
The channel map units are extension unit with init ids 51 and 52. This unit
|
||||
lets you implement arbitrary routings including loopbacks.
|
||||
|
||||
The mixer is controlled on macOS via the command line utility
|
||||
xmos_mixer. Running this application requires having the
|
||||
libusb-1.0.0.dylib in the dynamic library load path. Sourcing the
|
||||
setup.sh script will do this. Source code for the application is
|
||||
provided as a guide on how to communicate with the device.
|
||||
|
||||
Here are the commands for the mixer application (note that the USB
|
||||
audio reference design has only one unit so the mixer_id argument
|
||||
should always be 0):
|
||||
|
||||
--help
|
||||
|
||||
--display-info
|
||||
|
||||
Show information about the device.
|
||||
|
||||
--display-mixer-nodes mixer_id
|
||||
|
||||
Display all the weights of all the mixer nodes (and their id) of a particular mixer.
|
||||
|
||||
--display-min mixer_id
|
||||
|
||||
Display the minimum allowable weights of a particular mixer.
|
||||
|
||||
--display-max mixer_id
|
||||
|
||||
Display the maximum allowable weights of a particular mixer.
|
||||
|
||||
--display-res mixer_id
|
||||
|
||||
Display the resolution of a particular mixer.
|
||||
|
||||
--set-value mixer_id mixer_unit value
|
||||
|
||||
Set the weight value in the mixer. The second argument should
|
||||
correspond to the values shown by the --display-unit command. Values
|
||||
can range from -127db to +128db with the special value -inf for mute.
|
||||
|
||||
--get-value mixer_id mixer_unit
|
||||
|
||||
Get the weight value in the mixer. The second argument should
|
||||
correspond to the values shown by the --display-unit command. Values
|
||||
can range from -127db to +128db with the special value -inf for mute.
|
||||
|
||||
--set-mixer-source mixer_id, dst_channel_id, src_channel_id
|
||||
|
||||
Allows the selection of the mixer inputs. Sets mixer input (dst) to src
|
||||
|
||||
--display-current-mixer-sources mixer_id
|
||||
|
||||
Displays the current inputs to a particular mixer
|
||||
|
||||
--display-available-mixer-sources mixer_id
|
||||
|
||||
Displays all the input channels available that can be fed into the inputs of a particular mixer
|
||||
|
||||
--set-aud-channel-map dst src
|
||||
|
||||
Sets a channel map value for the device audio output
|
||||
|
||||
--display-aud-channel-map
|
||||
|
||||
Show audio output channel map i.e. for each audio output of the device what the source is.
|
||||
|
||||
--display-aud-channel-map-sources
|
||||
|
||||
Show the available audio output channel map sources.
|
||||
|
||||
--set-daw-channel-map dst src
|
||||
|
||||
Sets a channel map value for the DAW output to the host
|
||||
|
||||
--display-daw-channel-map
|
||||
|
||||
Show audio output channel map i.e. for each DAW output to host, what the source is.
|
||||
|
||||
--display-daw-channel-map-sources
|
||||
|
||||
Show the DAW output channel map sources.
|
||||
|
||||
--get-mixer-levels-input
|
||||
|
||||
--get-mixer-levels-output
|
||||
|
||||
--vendor-audio-request-get bRequest, ControlSelector, ChannelNumber, UnitId
|
||||
|
||||
--vendor-audio-request-set bRequest, ControlSelector, ChannelNumber, UnitId, Data[0], Data[1],...
|
||||
|
||||
48
host_usb_mixer_control/Win/global.h
Normal file
48
host_usb_mixer_control/Win/global.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright 2022-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* Module: global.h
|
||||
* Description:
|
||||
* APP global includes, constants, declarations, etc.
|
||||
*
|
||||
* Author(s):
|
||||
* Udo Eberhardt
|
||||
*
|
||||
* Companies:
|
||||
* Thesycon GmbH, Germany http://www.thesycon.de
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#ifndef __global_h__
|
||||
#define __global_h__
|
||||
|
||||
// define the Windows versions supported by the application
|
||||
#define _WIN32_WINNT 0x0500 //Windows 2000 or later
|
||||
//#define _WIN32_WINNT 0x0501 //Windows XP or later
|
||||
//#define _WIN32_WINNT 0x0600 //Windows Vista or later
|
||||
//#define _WIN32_WINNT 0x0A00 //Windows 10 or later
|
||||
|
||||
// exclude rarely-used stuff from Windows headers
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
|
||||
|
||||
// version defs
|
||||
//#include "version.h"
|
||||
|
||||
// libwn.h pulls in windows.h
|
||||
#include "libwn.h"
|
||||
// TUSBAUDIO driver API
|
||||
#include "tusbaudioapi.h"
|
||||
#include "TUsbAudioApiDll.h"
|
||||
|
||||
|
||||
#endif // __global_h__
|
||||
|
||||
/*************************** EOF **************************************/
|
||||
177
host_usb_mixer_control/host_usb_mixer_control.vcxproj
Normal file
177
host_usb_mixer_control/host_usb_mixer_control.vcxproj
Normal file
@@ -0,0 +1,177 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{84eacf4f-e405-4909-b440-a04a84a3f8c8}</ProjectGuid>
|
||||
<RootNamespace>
|
||||
</RootNamespace>
|
||||
<SDKPath Condition="'$(SDKPath)' == ''">C:\Program Files\XMOS\tusbaudiosdk</SDKPath>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
<Import Project="$(SDKPath)\source\tusbaudioapi_inc\tusbaudioapi_inc_vs2019.vcxitems" Label="Shared" />
|
||||
<Import Project="$(SDKPath)\source\libwn_min\_libwn_min_vs2019.vcxitems" Label="Shared" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>.\bin\$(Configuration)\$(PlatformName)\</OutDir>
|
||||
<IntDir>$(Configuration)\$(PlatformName)_$(PlatformToolset)</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>.\bin\$(Configuration)\$(PlatformName)\</OutDir>
|
||||
<IntDir>$(Configuration)\$(PlatformName)_$(PlatformToolset)</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<SDLCheck>
|
||||
</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_AMD64;_CONSOLE;_UNICODE;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>.;.\Win;$(SDKPath)\source\shared;$(SDKPath)\source\inc;$(SDKPath)\source\libwn_min;$(SDKPath)\source\libwtl;$(SDKPath)\source\tusbaudioapi_inc</AdditionalIncludeDirectories>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<ExceptionHandling>Async</ExceptionHandling>
|
||||
<PrecompiledHeaderFile />
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<UACExecutionLevel />
|
||||
<UACUIAccess />
|
||||
<GenerateMapFile>true</GenerateMapFile>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>false</IntrinsicFunctions>
|
||||
<SDLCheck>
|
||||
</SDLCheck>
|
||||
<PreprocessorDefinitions>_AMD64;_CONSOLE;_UNICODE;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>.;.\Win;$(SDKPath)\source\shared;$(SDKPath)\source\inc;$(SDKPath)\source\libwn_min;$(SDKPath)\source\libwtl;$(SDKPath)\source\tusbaudioapi_inc</AdditionalIncludeDirectories>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<ExceptionHandling>Async</ExceptionHandling>
|
||||
<PrecompiledHeaderFile />
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<UACExecutionLevel />
|
||||
<UACUIAccess />
|
||||
<GenerateMapFile>true</GenerateMapFile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="usb_mixer.h" />
|
||||
<ClInclude Include="Win\global.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="mixer_app.cpp" />
|
||||
<ClCompile Include="usb_mixer.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="usb_mixer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Win\global.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="mixer_app.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Win\usb_mixer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
762
host_usb_mixer_control/mixer_app.cpp
Normal file
762
host_usb_mixer_control/mixer_app.cpp
Normal file
@@ -0,0 +1,762 @@
|
||||
// Copyright 2022-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "usb_mixer.h"
|
||||
|
||||
#define MIXER_UNIT_DISPLAY_VALUE 2
|
||||
#define MIXER_UNIT_DISPLAY_MIN 3
|
||||
#define MIXER_UNIT_DISPLAY_MAX 4
|
||||
#define MIXER_UNIT_DISPLAY_RES 5
|
||||
|
||||
// TODO
|
||||
// res, min, max
|
||||
|
||||
#ifdef _WIN32
|
||||
int mixer_init(TCHAR guid[GUID_STR_LEN])
|
||||
#else
|
||||
int mixer_init(void)
|
||||
#endif
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int ret = usb_mixer_connect(guid);
|
||||
#else
|
||||
int ret = usb_mixer_connect();
|
||||
#endif
|
||||
|
||||
/* Open the connection to the USB mixer */
|
||||
if (ret == USB_MIXER_FAILURE)
|
||||
{
|
||||
return USB_MIXER_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
return USB_MIXER_SUCCESS;
|
||||
}
|
||||
|
||||
int mixer_deinit(void) {
|
||||
// Close the connection to the USB mixer
|
||||
if (usb_mixer_disconnect() == USB_MIXER_FAILURE) {
|
||||
return USB_MIXER_FAILURE;
|
||||
}
|
||||
|
||||
return USB_MIXER_SUCCESS;
|
||||
}
|
||||
|
||||
int mixer_display(unsigned int mixer_index, unsigned int type) {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
int num_inputs = usb_mixer_get_num_inputs(mixer_index);
|
||||
int num_outputs = usb_mixer_get_num_outputs(mixer_index);
|
||||
|
||||
|
||||
printf("\n");
|
||||
switch (type) {
|
||||
case MIXER_UNIT_DISPLAY_VALUE:
|
||||
//mixer_update_all_values(mixer_index);
|
||||
printf(" Mixer Values (%d)\n", mixer_index);
|
||||
printf(" ----------------\n\n");
|
||||
break;
|
||||
case MIXER_UNIT_DISPLAY_MIN:
|
||||
printf(" Mixer Ranges Min (%d)\n", mixer_index);
|
||||
printf(" --------------------\n\n");
|
||||
break;
|
||||
case MIXER_UNIT_DISPLAY_MAX:
|
||||
printf(" Mixer Ranges Max (%d)\n", mixer_index);
|
||||
printf(" --------------------\n\n");
|
||||
break;
|
||||
case MIXER_UNIT_DISPLAY_RES:
|
||||
printf(" Mixer Ranges Res (%d)\n", mixer_index);
|
||||
printf(" --------------------\n\n");
|
||||
break;
|
||||
default:
|
||||
return USB_MIXER_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
||||
printf(" \t\t\t");
|
||||
printf("Mixer Outputs\n");
|
||||
printf("\t\t ");
|
||||
for (i = 0; i < num_outputs; i++) {
|
||||
printf(" %d", i+1);
|
||||
}
|
||||
printf("\n");
|
||||
for (i = 0; i < num_inputs; i++) {
|
||||
printf(" %-20s", usb_mixer_get_input_name(mixer_index,i));
|
||||
for (j = 0; j < num_outputs; j++) {
|
||||
switch (type) {
|
||||
case MIXER_UNIT_DISPLAY_VALUE:
|
||||
{
|
||||
double mixNodeVal = usb_mixer_get_value(mixer_index, (i*num_outputs)+j);
|
||||
int nodeid = (i*num_outputs)+j;
|
||||
|
||||
if (mixNodeVal <= -127.996)// todo shoud be < min
|
||||
{
|
||||
printf("\t%3d:[ %s ]", nodeid,"-inf");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\t%3d:[%08.03f]", nodeid, mixNodeVal);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MIXER_UNIT_DISPLAY_MIN:
|
||||
{
|
||||
int nodeid = (i*num_outputs)+j;
|
||||
printf("\t%3d:[%08.03f]", nodeid, usb_mixer_get_min(mixer_index, (i*num_outputs)+j)) ;
|
||||
}
|
||||
break;
|
||||
case MIXER_UNIT_DISPLAY_MAX:
|
||||
{
|
||||
int nodeid = (i*num_outputs)+j;
|
||||
printf("\t%3d:[%08.03f]", nodeid, usb_mixer_get_max(mixer_index, (i*num_outputs)+j)) ;
|
||||
}
|
||||
break;
|
||||
case MIXER_UNIT_DISPLAY_RES:
|
||||
{
|
||||
int nodeid = (i*num_outputs)+j;
|
||||
printf("\t%3d:[%08.03f]", nodeid, usb_mixer_get_res(mixer_index, (i*num_outputs)+j)) ;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return USB_MIXER_FAILURE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return USB_MIXER_SUCCESS;
|
||||
}
|
||||
|
||||
/* Displays basic mixer information */
|
||||
int mixer_display_info(void)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
int num_mixers = usb_mixer_get_num_mixers();
|
||||
|
||||
printf("\n");
|
||||
printf(" Mixer Info\n");
|
||||
printf(" ----------\n\n");
|
||||
printf(" Mixers : %d\n\n", num_mixers);
|
||||
|
||||
for (i = 0; i < num_mixers; i++)
|
||||
{
|
||||
int num_inputs = usb_mixer_get_num_inputs(i);
|
||||
int num_outputs = usb_mixer_get_num_outputs(i);
|
||||
|
||||
|
||||
printf(" Mixer %d\n", i);
|
||||
printf(" -------\n");
|
||||
|
||||
printf(" Inputs : %d\n"
|
||||
" Outputs : %d\n\n", num_inputs, num_outputs);
|
||||
|
||||
printf(" Mixer Output Labels:\n");
|
||||
for(int j = 0; j < num_outputs; j++)
|
||||
{
|
||||
printf(" %d: %s\n", j,usb_mixer_get_output_name(i,j));
|
||||
}
|
||||
|
||||
//printf("\n Selectable Inputs (%d): \n", usb_mixsel_get_input_count(i));
|
||||
//for(int j = 0; j < usb_mixsel_get_input_count(i); j++)
|
||||
//{
|
||||
// printf(" %d: %s\n", j, usb_mixsel_get_input_string(i,j));
|
||||
//}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return USB_MIXER_SUCCESS;
|
||||
}
|
||||
|
||||
void display_available_mixer_sources(int mixIndex)
|
||||
{
|
||||
printf("\n");
|
||||
printf(" Available Mixer Sources (%d)\n", mixIndex);
|
||||
printf(" -------------------------\n\n");
|
||||
|
||||
for(int j = 0; j < usb_mixsel_get_input_count(mixIndex); j++)
|
||||
{
|
||||
printf(" %d: %s\n", j, usb_mixsel_get_input_string(mixIndex,j));
|
||||
}
|
||||
}
|
||||
|
||||
/* Gets the current mixer inputs from the device an displays them */
|
||||
void display_mixer_sources(int mixerIndex)
|
||||
{
|
||||
printf("\n");
|
||||
printf(" Current Mixer Sources (%d)\n", mixerIndex);
|
||||
printf(" -------------------------\n\n");
|
||||
|
||||
/* Note, mixSel output cound and mixer input chan count should be the same! */
|
||||
printf(" Number of mixer sources: %d\n", usb_mixsel_get_output_count(mixerIndex));
|
||||
|
||||
/* Get the current channel number for every mixer input */
|
||||
for(int i = 0; i < usb_mixsel_get_output_count(mixerIndex); i++)
|
||||
{
|
||||
int inputChan = (int)usb_mixsel_get_state(mixerIndex, i);
|
||||
char *str = usb_mixer_get_input_name(mixerIndex,inputChan);
|
||||
printf(" Mixer input %d: Source chan id: %d (%s)\n", i, inputChan, str);
|
||||
}
|
||||
}
|
||||
|
||||
/* set mixer source */
|
||||
void set_mixer_source(unsigned mixerIndex, unsigned dst, unsigned src)
|
||||
{
|
||||
usb_mixsel_set_state(mixerIndex, dst, src);
|
||||
|
||||
/* String lookup */
|
||||
char *str = usb_mixer_get_input_name(mixerIndex, dst);
|
||||
int state = usb_mixsel_get_state(mixerIndex, dst);
|
||||
|
||||
printf("\n Set mixer(%d) input %d to device input %d (%s)\n", mixerIndex, dst, state, str);
|
||||
}
|
||||
|
||||
void display_aud_channel_map()
|
||||
{
|
||||
printf("\n");
|
||||
printf(" Audio Output Channel Map\n");
|
||||
printf(" ------------------------\n\n");
|
||||
|
||||
for (int i=0;i<usb_get_aud_channel_map_num_outputs();i++)
|
||||
{
|
||||
int x = usb_get_aud_channel_map(i);
|
||||
printf("%d (DEVICE OUT - %s) source is ",i, usb_get_aud_channel_map_name(i));
|
||||
|
||||
switch (usb_get_aud_channel_map_type(x))
|
||||
{
|
||||
case USB_CHAN_OUT:
|
||||
printf(" %d (DAW OUT - %s)\n",x,usb_get_aud_channel_map_name(x));
|
||||
break;
|
||||
case USB_CHAN_IN:
|
||||
printf("%d (DEVICE IN - %s)\n",x,usb_get_aud_channel_map_name(x));
|
||||
break;
|
||||
case USB_CHAN_MIXER:
|
||||
printf("%d (%s)\n",x,usb_get_aud_channel_map_name(x));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void display_daw_channel_map()
|
||||
{
|
||||
printf("\n");
|
||||
printf(" DAW Output To Host Channel Map\n");
|
||||
printf(" ------------------------\n\n");
|
||||
|
||||
for (int i=0;i<usb_get_usb_channel_map_num_outputs();i++)
|
||||
{
|
||||
int x = usb_get_usb_channel_map(i);
|
||||
printf("%d (DAW IN - %s) source is ",i, usb_get_usb_channel_map_name(i + usb_get_aud_channel_map_num_outputs()));
|
||||
|
||||
switch (usb_get_usb_channel_map_type(x))
|
||||
{
|
||||
case USB_CHAN_OUT:
|
||||
printf(" %d (DAW OUT - %s)\n",x,usb_get_usb_channel_map_name(x));
|
||||
break;
|
||||
case USB_CHAN_IN:
|
||||
printf("%d (DEVICE IN - %s)\n",x,usb_get_usb_channel_map_name(x));
|
||||
break;
|
||||
case USB_CHAN_MIXER:
|
||||
printf("%d (%s)\n",x,usb_get_usb_channel_map_name(x));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void display_aud_channel_map_sources(void)
|
||||
{
|
||||
printf("\n");
|
||||
printf(" Audio Output Channel Map Source List\n");
|
||||
printf(" ------------------------------------\n\n");
|
||||
for (int i=0;i<usb_get_aud_channel_map_num_inputs();i++) {
|
||||
switch (usb_get_aud_channel_map_type(i))
|
||||
{
|
||||
case USB_CHAN_OUT:
|
||||
printf("%d (DAW OUT - %s)\n",i,usb_get_aud_channel_map_name(i));
|
||||
break;
|
||||
case USB_CHAN_IN:
|
||||
printf("%d (DEVICE IN - %s)\n",i,usb_get_aud_channel_map_name(i));
|
||||
break;
|
||||
case USB_CHAN_MIXER:
|
||||
printf("%d (%s)\n",i,usb_get_aud_channel_map_name(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void display_daw_channel_map_sources(void)
|
||||
{
|
||||
printf("\n");
|
||||
printf(" DAW Output to Host Channel Map Source List\n");
|
||||
printf(" ------------------------------------------\n\n");
|
||||
for (int i=0;i<usb_get_usb_channel_map_num_inputs();i++) {
|
||||
switch (usb_get_usb_channel_map_type(i))
|
||||
{
|
||||
case USB_CHAN_OUT:
|
||||
printf("%d (DAW OUT - %s)\n",i,usb_get_usb_channel_map_name(i));
|
||||
break;
|
||||
case USB_CHAN_IN:
|
||||
printf("%d (DEVICE IN - %s)\n",i,usb_get_usb_channel_map_name(i));
|
||||
break;
|
||||
case USB_CHAN_MIXER:
|
||||
printf("%d (%s)\n",i,usb_get_usb_channel_map_name(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int usb_audio_request_get(unsigned bRequest, unsigned cs, unsigned cn, unsigned unitId, unsigned char *data)
|
||||
{
|
||||
char reqStr[] = "Custom";
|
||||
|
||||
if(bRequest == CUR)
|
||||
{
|
||||
strcpy(reqStr, "CUR");
|
||||
}
|
||||
else if(bRequest == RANGE)
|
||||
{
|
||||
strcpy(reqStr, "RANGE");
|
||||
}
|
||||
else if(bRequest == MEM)
|
||||
{
|
||||
strcpy(reqStr, "MEM");
|
||||
}
|
||||
|
||||
printf("Performing class GET request to Audio Interface:\n\
|
||||
bRequest: 0x%02x (%s)\n\
|
||||
wValue: 0x%04x (Control Sel: %d, Channel Number: %d)\n\
|
||||
wIndex: 0x%04x (Interface: 0, Entity: %d)\n\
|
||||
\n", bRequest, reqStr, (cs<<8)|cn, cs, cn, unitId<<8, unitId);
|
||||
|
||||
return usb_audio_class_get(bRequest, cs, cn, unitId, 64, data);
|
||||
}
|
||||
|
||||
int usb_audio_request_set(unsigned bRequest, unsigned cs, unsigned cn, unsigned unitId,
|
||||
unsigned char *data, int datalength)
|
||||
{
|
||||
char reqStr[] = "Custom";
|
||||
|
||||
if(bRequest == CUR)
|
||||
{
|
||||
strcpy(reqStr, "CUR");
|
||||
}
|
||||
else if(bRequest == RANGE)
|
||||
{
|
||||
strcpy(reqStr, "RANGE");
|
||||
}
|
||||
{
|
||||
strcpy(reqStr, "MEM");
|
||||
}
|
||||
|
||||
printf("Performing class SET request to Audio Interface:\n\
|
||||
bRequest: 0x%02x (%s)\n\
|
||||
wValue: 0x%04x (Control Sel: %d, Channel Number: %d)\n\
|
||||
wIndex: 0x%04x (Interface: 0, Entity: %d)\n\
|
||||
\n", bRequest, reqStr, (cs<<8)|cn, cs, cn, unitId<<8, unitId);
|
||||
|
||||
return usb_audio_class_set(bRequest, cs, cn, unitId, datalength, data);
|
||||
}
|
||||
|
||||
|
||||
int usb_audio_memreq_get(unsigned unitId, unsigned offset, unsigned char *data)
|
||||
{
|
||||
/* Mem requests dont have CS/CN, just an offset.. */
|
||||
return usb_audio_request_get(MEM, (offset>>8), offset&0xff, unitId, data);
|
||||
}
|
||||
|
||||
void print_levels(const char* levelTitle, unsigned char* levels, int levelBytes)
|
||||
{
|
||||
unsigned levelCount = levelBytes/2;
|
||||
unsigned short* levelData = (unsigned short*) levels;
|
||||
|
||||
printf("\n %s Level Data\n"
|
||||
" ----------------------\n\n"
|
||||
"%d bytes (%d channels) returned:\n"
|
||||
, levelTitle, levelBytes, levelCount);
|
||||
|
||||
for(int i = 0; i<levelCount; i++)
|
||||
{
|
||||
printf("%s %d: 0x%04x\n", levelTitle, i,levelData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mixer_display_usage(void) {
|
||||
fprintf(stderr, "Usage: xmos_mixer "
|
||||
#ifdef _WIN32
|
||||
"-g<GUID> "
|
||||
#endif
|
||||
"<options>\n");
|
||||
fprintf(stderr,
|
||||
#ifdef _WIN32
|
||||
" -g<GUID> Driver GUID string, eg. -g{E5A2658B-817D-4A02-A1DE-B628A93DDF5D}\n"
|
||||
#endif
|
||||
" --display-info\n"
|
||||
" --display-mixer-nodes mixer_id\n"
|
||||
" --display-min mixer_id\n"
|
||||
" --display-max mixer_id\n"
|
||||
" --display-res mixer_id\n"
|
||||
" --set-value mixer_id, mixer_node, value\n"
|
||||
" --get-value mixer_id, mixer_node\n"
|
||||
"\n"
|
||||
" --set-mixer-source mixer_id dst channel_id, src_channel_id\n"
|
||||
" --display-current-mixer-sources mixer_id\n"
|
||||
" --display-available-mixer-sources mixer_id\n"
|
||||
"\n"
|
||||
" --set-aud-channel-map dst_channel_id, src_channel_id\n"
|
||||
" --display-aud-channel-map \n"
|
||||
" --display-aud-channel-map-sources\n"
|
||||
" --set-daw-channel-map dst_channel_id, src_channel_id\n"
|
||||
" --display-daw-channel-map \n"
|
||||
" --display-daw-channel-map-sources\n"
|
||||
"\n"
|
||||
" --get-mixer-levels-input mixer_id\n"
|
||||
" --get-mixer-levels-output mixer_id\n"
|
||||
" --vendor-audio-request-get bRequest, ControlSelector, ChannelNumber, UnitId\n"
|
||||
" --vendor-audio-request-set bRequest, ControlSelector, ChannelNumber, UnitId, Data[0], Data[1],...\n"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void usage_error()
|
||||
{
|
||||
fprintf(stderr, "ERROR :: incorrect number of arguments passed. See --help\n");
|
||||
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
|
||||
unsigned int mixer_index = 0;
|
||||
unsigned int result = 0;
|
||||
|
||||
int min_argc;
|
||||
// arg_idx is the position in the arguments to start parsing to skip the "-g" GUID option on Windows
|
||||
int arg_idx;
|
||||
#ifdef _WIN32
|
||||
// Driver GUID string is required on Windows
|
||||
min_argc = 3;
|
||||
arg_idx = 2;
|
||||
#else
|
||||
min_argc = 2;
|
||||
arg_idx = 1;
|
||||
#endif
|
||||
|
||||
if (argc < min_argc) {
|
||||
fprintf(stderr, "ERROR :: No options passed to mixer application\n");
|
||||
mixer_display_usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
TCHAR driver_guid[GUID_STR_LEN];
|
||||
|
||||
if (strncmp(argv[1], "-g", 2) == 0) {
|
||||
swprintf(driver_guid, GUID_STR_LEN, L"%hs", argv[1]+2);
|
||||
} else {
|
||||
fprintf(stderr, "ERROR :: First option must be driver GUID\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (strcmp(argv[1], "--help") == 0) {
|
||||
mixer_display_usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int ret = mixer_init(driver_guid);
|
||||
#else
|
||||
int ret = mixer_init();
|
||||
#endif
|
||||
|
||||
if (ret != USB_MIXER_SUCCESS) {
|
||||
fprintf(stderr, "ERROR :: Cannot connect\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcmp(argv[arg_idx], "--display-info") == 0)
|
||||
{
|
||||
mixer_display_info();
|
||||
}
|
||||
else if (strcmp(argv[arg_idx], "--display-mixer-nodes") == 0)
|
||||
{
|
||||
if (argv[arg_idx+1])
|
||||
{
|
||||
mixer_index = atoi(argv[arg_idx+1]);
|
||||
} else {
|
||||
fprintf(stderr, "ERROR :: No mixer index supplied\n");
|
||||
return -1;
|
||||
}
|
||||
mixer_display(mixer_index, MIXER_UNIT_DISPLAY_VALUE);
|
||||
} else if (strcmp(argv[arg_idx], "--display-mixer-nodes") == 0) {
|
||||
if (argv[2]) {
|
||||
mixer_index = atoi(argv[arg_idx+1]);
|
||||
} else {
|
||||
fprintf(stderr, "ERROR :: No mixer index supplied\n");
|
||||
return -1;
|
||||
}
|
||||
mixer_display(mixer_index, MIXER_UNIT_DISPLAY_VALUE);
|
||||
} else if (strcmp(argv[arg_idx], "--display-min") == 0) {
|
||||
if (argv[arg_idx+1]) {
|
||||
mixer_index = atoi(argv[arg_idx+1]);
|
||||
} else {
|
||||
fprintf(stderr, "ERROR :: No mixer index supplied\n");
|
||||
return -1;
|
||||
}
|
||||
mixer_display(mixer_index, MIXER_UNIT_DISPLAY_MIN);
|
||||
} else if (strcmp(argv[arg_idx], "--display-max") == 0) {
|
||||
if (argv[arg_idx+1]) {
|
||||
mixer_index = atoi(argv[arg_idx+1]);
|
||||
} else {
|
||||
fprintf(stderr, "ERROR :: No mixer index supplied\n");
|
||||
return -1;
|
||||
}
|
||||
mixer_display(mixer_index, MIXER_UNIT_DISPLAY_MAX);
|
||||
} else if (strcmp(argv[arg_idx], "--display-res") == 0) {
|
||||
if (argv[arg_idx+1]) {
|
||||
mixer_index = atoi(argv[arg_idx+1]);
|
||||
} else {
|
||||
fprintf(stderr, "ERROR :: No mixer index supplied\n");
|
||||
return -1;
|
||||
}
|
||||
mixer_display(mixer_index, MIXER_UNIT_DISPLAY_RES);
|
||||
}
|
||||
else if (strcmp(argv[arg_idx], "--set-value") == 0) {
|
||||
unsigned int mixer_unit = 0;
|
||||
double value = 0;
|
||||
if (argc - arg_idx < 4) {
|
||||
fprintf(stderr, "ERROR :: incorrect number of arguments passed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mixer_index = atoi(argv[arg_idx+1]);
|
||||
mixer_unit = atoi(argv[arg_idx+2]);
|
||||
if (strcmp(argv[arg_idx+3],"-inf")==0)
|
||||
value = -128;
|
||||
else
|
||||
value = atof(argv[arg_idx+3]);
|
||||
|
||||
usb_mixer_set_value(mixer_index, mixer_unit, value);
|
||||
} else if (strcmp(argv[arg_idx], "--get-value") == 0) {
|
||||
unsigned int mixer_unit = 0;
|
||||
double result = 0;
|
||||
if (argc - arg_idx < 3) {
|
||||
fprintf(stderr, "ERROR :: incorrect number of arguments passed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mixer_index = atoi(argv[arg_idx+1]);
|
||||
mixer_unit = atoi(argv[arg_idx+2]);
|
||||
|
||||
result = usb_mixer_get_value(mixer_index, mixer_unit);
|
||||
if (result <= -127.996)
|
||||
printf("%s\n", "-inf");
|
||||
else
|
||||
printf("%g\n",result);
|
||||
}
|
||||
else if (strcmp(argv[arg_idx], "--display-current-mixer-sources") == 0)
|
||||
{
|
||||
if(argc - arg_idx < 2)
|
||||
{
|
||||
usage_error();
|
||||
return -1;
|
||||
}
|
||||
display_mixer_sources(atoi(argv[arg_idx+1]));
|
||||
}
|
||||
else if (strcmp(argv[arg_idx], "--display-available-mixer-sources") == 0)
|
||||
{
|
||||
if(argc - arg_idx < 2)
|
||||
{
|
||||
usage_error();
|
||||
return -1;
|
||||
}
|
||||
display_available_mixer_sources(atoi(argv[arg_idx+1]));
|
||||
}
|
||||
else if(strcmp(argv[arg_idx], "--set-mixer-source") == 0)
|
||||
{
|
||||
if(argc - arg_idx < 4)
|
||||
{
|
||||
usage_error();
|
||||
return -1;
|
||||
}
|
||||
set_mixer_source(atoi(argv[arg_idx+1]), atoi(argv[arg_idx+2]), atoi(argv[arg_idx+3]));
|
||||
}
|
||||
else if (strcmp(argv[arg_idx], "--display-aud-channel-map") == 0)
|
||||
{
|
||||
/* Display the channel mapping to the devices audio outputs */
|
||||
display_aud_channel_map();
|
||||
}
|
||||
else if (strcmp(argv[arg_idx], "--display-aud-channel-map-sources") == 0)
|
||||
{
|
||||
display_aud_channel_map_sources();
|
||||
}
|
||||
else if (strcmp(argv[arg_idx], "--display-daw-channel-map") == 0)
|
||||
{
|
||||
/* Display the channel mapping to the devices DAW output to host */
|
||||
display_daw_channel_map();
|
||||
}
|
||||
else if (strcmp(argv[arg_idx], "--display-daw-channel-map-sources") == 0)
|
||||
{
|
||||
display_daw_channel_map_sources();
|
||||
}
|
||||
else if (strcmp(argv[arg_idx], "--set-aud-channel-map") == 0)
|
||||
{
|
||||
unsigned int dst = 0;
|
||||
unsigned int src = 0;
|
||||
if (argc - arg_idx != 3)
|
||||
{
|
||||
usage_error();
|
||||
return -1;
|
||||
}
|
||||
dst = atoi(argv[arg_idx+1]);
|
||||
src = atoi(argv[arg_idx+2]);
|
||||
|
||||
usb_set_aud_channel_map(dst, src);
|
||||
}
|
||||
else if (strcmp(argv[arg_idx], "--set-daw-channel-map") == 0)
|
||||
{
|
||||
unsigned int dst = 0;
|
||||
unsigned int src = 0;
|
||||
if (argc - arg_idx != 3)
|
||||
{
|
||||
usage_error();
|
||||
return -1;
|
||||
}
|
||||
dst = atoi(argv[arg_idx+1]);
|
||||
src = atoi(argv[arg_idx+2]);
|
||||
|
||||
usb_set_usb_channel_map(dst, src);
|
||||
}
|
||||
else if(strcmp(argv[arg_idx], "--get-mixer-levels-input") == 0 ||
|
||||
strcmp(argv[arg_idx],"--get-mixer-levels-output") == 0)
|
||||
{
|
||||
unsigned int dst = 0;
|
||||
unsigned char levels[64];
|
||||
int datalength = 0;
|
||||
int offset = 0;
|
||||
|
||||
if (argc - arg_idx < 2) {
|
||||
fprintf(stderr, "ERROR :: incorrect number of arguments passed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(strcmp(argv[arg_idx],"--get-mixer-levels-output") == 0)
|
||||
offset = 1;
|
||||
|
||||
for(int i = 0; i < 64; i++)
|
||||
levels[i] = 0;
|
||||
|
||||
dst = atoi(argv[arg_idx+1]);
|
||||
|
||||
/* Mem request to mixer with offset of 0 gives input levels */
|
||||
datalength = usb_mixer_mem_get(dst, offset, levels);
|
||||
|
||||
if(datalength < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR in control request: %d\n", datalength);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(offset)
|
||||
print_levels("Mixer Output", levels, datalength);
|
||||
else
|
||||
print_levels("Mixer Input", levels, datalength);
|
||||
|
||||
}
|
||||
else if(strcmp(argv[arg_idx], "--vendor-audio-request-get") == 0)
|
||||
{
|
||||
unsigned int bRequest = 0;
|
||||
unsigned int cs = 0;
|
||||
unsigned int cn = 0;
|
||||
unsigned int unitId = 0;
|
||||
int datalength = 0;
|
||||
unsigned char data[64];
|
||||
|
||||
if(argc - arg_idx < 5)
|
||||
{
|
||||
fprintf(stderr, "ERROR :: incorrect number of arguments passed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 64; i++)
|
||||
data[i] = 0;
|
||||
|
||||
bRequest = atoi(argv[arg_idx+1]);
|
||||
cs = atoi(argv[arg_idx+2]);
|
||||
cn = atoi(argv[arg_idx+3]);
|
||||
unitId = atoi(argv[arg_idx+4]);
|
||||
|
||||
/* Do request */
|
||||
datalength = usb_audio_request_get(bRequest, cs, cn, unitId, data);
|
||||
|
||||
/* Print result */
|
||||
if(datalength < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR in control request: %d\n", datalength);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Response (%d bytes):\n", datalength);
|
||||
for(int i = 0; i < datalength; i++)
|
||||
printf("0x%02x\n" ,data[i]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[arg_idx], "--vendor-audio-request-set") == 0)
|
||||
{
|
||||
|
||||
unsigned int bRequest = 0;
|
||||
unsigned int cs = 0;
|
||||
unsigned int cn = 0;
|
||||
unsigned int unitId = 0;
|
||||
unsigned char data[64];
|
||||
|
||||
for(int i=0; i<64; i++)
|
||||
{
|
||||
data[i] = 0;
|
||||
}
|
||||
|
||||
if(argc - arg_idx < 6)
|
||||
{
|
||||
fprintf(stderr, "ERROR :: incorrect number of arguments passed - no data passed\n");
|
||||
return -1;
|
||||
}
|
||||
bRequest = atoi(argv[arg_idx+1]);
|
||||
cs = atoi(argv[arg_idx+2]);
|
||||
cn = atoi(argv[arg_idx+3]);
|
||||
unitId = atoi(argv[arg_idx+4]);
|
||||
|
||||
/* Get data */
|
||||
for(int i=0; i < argc-arg_idx-5; i++)
|
||||
{
|
||||
data[i] = atoi(argv[i+arg_idx+5]);
|
||||
}
|
||||
|
||||
result = usb_audio_request_set(bRequest, cs, cn, unitId, data, argc-arg_idx-5);
|
||||
|
||||
if(result < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR :: Error detected in Set request: %d\n", result);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "ERROR :: Invalid option passed to mixer application\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mixer_deinit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
1
host_usb_mixer_control/setup.sh
Normal file
1
host_usb_mixer_control/setup.sh
Normal file
@@ -0,0 +1 @@
|
||||
export DYLD_LIBRARY_PATH=$PWD/OSX:$DYLD_LIBRARY_PATH
|
||||
1046
host_usb_mixer_control/usb_mixer.cpp
Normal file
1046
host_usb_mixer_control/usb_mixer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
115
host_usb_mixer_control/usb_mixer.h
Normal file
115
host_usb_mixer_control/usb_mixer.h
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright 2022-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#define USB_MIXER_SUCCESS 0
|
||||
#define USB_MIXER_FAILURE -1
|
||||
|
||||
#define USB_MIXERS 1
|
||||
#define USB_MIXER_INPUTS 18
|
||||
#define USB_MIXER_OUTPUTS 8
|
||||
#define USB_MAX_CHANNEL_MAP_SIZE 40
|
||||
#define USB_MIXER_MAX_NAME_LEN 64
|
||||
|
||||
enum usb_chan_type {
|
||||
USB_CHAN_OUT=0,
|
||||
USB_CHAN_IN=1,
|
||||
USB_CHAN_MIXER=2
|
||||
};
|
||||
|
||||
/* A.14 Audio Class-Specific Request Codes */
|
||||
#define REQUEST_CODE_UNDEFINED 0x00
|
||||
#define CUR (1)
|
||||
#define RANGE (2)
|
||||
#define MEM (3)
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <tchar.h>
|
||||
// GUID strings are 36 characters, plus a pair of braces and NUL-termination
|
||||
#define GUID_STR_LEN (36+2+1)
|
||||
int usb_mixer_connect(TCHAR guid[GUID_STR_LEN]);
|
||||
#else
|
||||
int usb_mixer_connect();
|
||||
#endif
|
||||
int usb_mixer_disconnect();
|
||||
|
||||
/* MIXER UNIT(s) INTERFACE */
|
||||
|
||||
/* Returns total number of mixers in device */
|
||||
int usb_mixer_get_num_mixers();
|
||||
|
||||
/* Returns number of inputs and outputs for a selected mixer */
|
||||
int usb_mixer_get_layout(unsigned int mixer, unsigned int *inputs, unsigned int *outputs);
|
||||
|
||||
/* Returns the name for a selected mixer input */
|
||||
char *usb_mixer_get_input_name(unsigned int mixer, unsigned int input);
|
||||
|
||||
/* Returns the name for a selected mixer output */
|
||||
char *usb_mixer_get_output_name(unsigned int mixer, unsigned int output);
|
||||
|
||||
/* Returns the current value of a selected mixer unit */
|
||||
double usb_mixer_get_value(unsigned int mixer, unsigned int mixer_unit);
|
||||
|
||||
/* Sets the current value for a selected mixer unit */
|
||||
int usb_mixer_set_value(unsigned int mixer, unsigned int mixer_unit, double val);
|
||||
|
||||
/* Returns the range values for a selected mixer unit */
|
||||
int usb_mixer_get_range(unsigned int mixer, unsigned int mixer_unit, double *min, double *max, double *res);
|
||||
|
||||
/* Returns the number of bytes read from a mem request, data is stored in data */
|
||||
int usb_mixer_mem_get(unsigned int mixer, unsigned offset, unsigned char *data);
|
||||
|
||||
|
||||
/* INPUT / OUTPUT / MIXER MAPPING UNIT INTERFACE */
|
||||
|
||||
/* Get the number of selectable inputs */
|
||||
int usb_mixsel_get_input_count(unsigned int mixer);
|
||||
|
||||
/* Get the string of a input */
|
||||
char *usb_mixsel_get_input_string(unsigned int mixer, unsigned int channel);
|
||||
|
||||
int usb_mixsel_get_output_count(unsigned int mixer);
|
||||
|
||||
int usb_mixer_get_num_outputs(unsigned int mixer);
|
||||
|
||||
int usb_mixer_get_num_inputs(unsigned int mixer);
|
||||
|
||||
unsigned char usb_mixsel_get_state(unsigned int mixer, unsigned int channel);
|
||||
|
||||
void usb_mixsel_set_state(unsigned int mixer, unsigned int dst, unsigned int src);
|
||||
|
||||
int usb_set_usb_channel_map(int channel, int val);
|
||||
|
||||
|
||||
/* Get the current map for a specified input / output / mixer channel */
|
||||
int usb_get_usb_channel_map(int channel);
|
||||
int usb_get_aud_channel_map(int channel);
|
||||
|
||||
/* Maps an input / output / mixer channel to another input / output / mixer channel */
|
||||
int usb_set_aud_channel_map(int channel, int val);
|
||||
int usb_set_usb_channel_map(int channel, int val);
|
||||
|
||||
/* Gets the name of a specified channel */
|
||||
char *usb_get_aud_channel_map_name(int channel);
|
||||
char *usb_get_usb_channel_map_name(int channel);
|
||||
|
||||
/* Get the type of a channel map */
|
||||
enum usb_chan_type usb_get_aud_channel_map_type(int channel);
|
||||
enum usb_chan_type usb_get_usb_channel_map_type(int channel);
|
||||
|
||||
int usb_get_aud_channel_map_num_outputs();
|
||||
int usb_get_usb_channel_map_num_outputs();
|
||||
|
||||
int usb_get_aud_channel_map_num_inputs();
|
||||
int usb_get_usb_channel_map_num_inputs();
|
||||
|
||||
/* CUSTOM/GENERIC AUDIO CLASS REQUESTS */
|
||||
|
||||
int usb_audio_class_get(unsigned char bRequest, unsigned char cs, unsigned char cn, unsigned short unitID, unsigned short wLength, unsigned char *data);
|
||||
|
||||
int usb_audio_class_set(unsigned char bRequest, unsigned char cs, unsigned char cn, unsigned short unitID, unsigned short wLength, unsigned char *data);
|
||||
|
||||
double usb_mixer_get_res(unsigned int mixer, unsigned int nodeId);
|
||||
|
||||
double usb_mixer_get_min(unsigned int mixer, unsigned int nodeId) ;
|
||||
|
||||
double usb_mixer_get_max(unsigned int mixer, unsigned int nodeId) ;
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2022 XMOS LIMITED.
|
||||
// Copyright 2017-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#ifndef _XUA_H_
|
||||
#define _XUA_H_
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
#include "xua_conf_full.h"
|
||||
|
||||
#if __XC__ || __STDC__
|
||||
#ifndef __ASSEMBLER__
|
||||
#include "xua_audiohub.h"
|
||||
#include "xua_endpoint0.h"
|
||||
#include "xua_buffer.h"
|
||||
#include "xua_mixer.h"
|
||||
#endif
|
||||
|
||||
#if __XC__
|
||||
#ifdef __XC__
|
||||
#include "xua_clocking.h"
|
||||
#include "xua_midi.h"
|
||||
#if XUA_NUM_PDM_MICS > 0
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#ifndef __XUA_AUDIOHUB_H__
|
||||
#define __XUA_AUDIOHUB_H__
|
||||
#ifndef _XUA_AUDIOHUB_H_
|
||||
#define _XUA_AUDIOHUB_H_
|
||||
|
||||
#if __XC__
|
||||
#ifdef __XC__
|
||||
|
||||
#include "xccompat.h"
|
||||
#include "xs1.h"
|
||||
@@ -12,32 +12,42 @@
|
||||
#include "dfu_interface.h"
|
||||
#endif
|
||||
|
||||
#include "xua_clocking.h"
|
||||
|
||||
/** The audio driver thread.
|
||||
*
|
||||
* This function drives I2S ports and handles samples to/from other digital
|
||||
* I/O threads.
|
||||
*
|
||||
* \param c_aud Audio sample channel connected to the mixer() thread or the
|
||||
* decouple() thread
|
||||
* \param c_aud Audio sample channel connected to the mixer() thread or the
|
||||
* decouple() thread
|
||||
*
|
||||
* \param clk_audio_mclk Nullable clockblock to be clocked from master clock
|
||||
* \param clk_audio_mclk Nullable clockblock to be clocked from master clock
|
||||
*
|
||||
* \param clk_audio_bclk Nullable clockblock to be clocked from i2s bit clock
|
||||
* \param clk_audio_bclk Nullable clockblock to be clocked from i2s bit clock
|
||||
*
|
||||
* \param p_mclk_in Master clock inport port (must be 1-bit)
|
||||
* \param p_mclk_in Master clock inport port (must be 1-bit)
|
||||
*
|
||||
* \param p_lrclk Nullable port for I2S sample clock
|
||||
* \param p_lrclk Nullable port for I2S sample clock
|
||||
*
|
||||
* \param p_bclk Nullable port for I2S bit
|
||||
* \param p_bclk Nullable port for I2S bit clock
|
||||
*
|
||||
* \param p_i2s_dac Nullable array of ports for I2S data output lines
|
||||
* \param p_i2s_dac Nullable array of ports for I2S data output lines
|
||||
*
|
||||
* \param p_i2s_adc Nullable array of ports for I2S data input lines
|
||||
* \param p_i2s_adc Nullable array of ports for I2S data input lines
|
||||
*
|
||||
* \param c_spdif_tx Channel connected to S/PDIF transmiter core from lib_spdif
|
||||
* \param i_SoftPll Interface to software PLL task
|
||||
*
|
||||
* \param c_dig Channel connected to the clockGen() thread for
|
||||
* receiving/transmitting samples
|
||||
* \param c_spdif_tx Channel connected to S/PDIF transmitter core from lib_spdif
|
||||
*
|
||||
* \param c_dig Channel connected to the clockGen() thread for
|
||||
* receiving/transmitting samples
|
||||
*
|
||||
* \param c_audio_rate_change Channel notifying ep_buffer of an mclk frequency change and sync for stable clock
|
||||
*
|
||||
* \param dfuInterface Interface supporting DFU methods
|
||||
*
|
||||
* \param c_pdm_in Channel for receiving decimated PDM samples
|
||||
*/
|
||||
void XUA_AudioHub(chanend ?c_aud,
|
||||
clock ?clk_audio_mclk,
|
||||
@@ -53,10 +63,13 @@ void XUA_AudioHub(chanend ?c_aud,
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN || defined(__DOXYGEN__))
|
||||
, chanend c_dig
|
||||
#endif
|
||||
#if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0) && (XUA_DFU_EN == 1)
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC || XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN || defined(__DOXYGEN__))
|
||||
, chanend c_audio_rate_change
|
||||
#endif
|
||||
#if (((XUD_TILE != 0) && (AUDIO_IO_TILE == 0) && (XUA_DFU_EN == 1)) || defined(__DOXYGEN__))
|
||||
, server interface i_dfu ?dfuInterface
|
||||
#endif
|
||||
#if (XUA_NUM_PDM_MICS > 0)
|
||||
#if (XUA_NUM_PDM_MICS > 0 || defined(__DOXYGEN__))
|
||||
, chanend c_pdm_in
|
||||
#endif
|
||||
);
|
||||
@@ -76,8 +89,29 @@ void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode,
|
||||
|
||||
#endif // __XC__
|
||||
|
||||
void UserBufferManagementInit();
|
||||
|
||||
/**
|
||||
* @brief User buffer management code
|
||||
*
|
||||
* This function is called at the sample rate of the USB Audio stack (e.g,. 48 kHz) and between the two parameter arrays
|
||||
* contain a full multi-channel audio-frame. The first array carries all the data that has been received from the USB host
|
||||
* and is to be presented to the audio interfaces. The second array carries all the data received from the interfaces and
|
||||
* is to be presented to the USB host. The user can chose to intercept and overwrite the samples stored in these arrays.
|
||||
*
|
||||
* \param sampsFromUsbToAudio Samples received from USB host and to be presented to audio interfaces
|
||||
*
|
||||
* \param sampsFromAudioToUsb Samples received from the audio interfaces and to be presented to the USB host
|
||||
*/
|
||||
void UserBufferManagement(unsigned sampsFromUsbToAudio[], unsigned sampsFromAudioToUsb[]);
|
||||
|
||||
#endif // __XUA_AUDIOHUB_H__
|
||||
/**
|
||||
* @brief User buffer managment init code
|
||||
*
|
||||
* This function is called once, before the first call to UserBufferManagement(), and can be used to initialise any
|
||||
* related user state
|
||||
*
|
||||
* \param sampFreq The initial sample frequency
|
||||
*
|
||||
*/
|
||||
void UserBufferManagementInit(unsigned sampFreq);
|
||||
|
||||
#endif // _XUA_AUDIOHUB_H_
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#ifndef __XUA_BUFFER_H__
|
||||
#define __XUA_BUFFER_H__
|
||||
#ifndef _XUA_BUFFER_H_
|
||||
#define _XUA_BUFFER_H_
|
||||
|
||||
#if __XC__
|
||||
|
||||
@@ -13,19 +13,21 @@
|
||||
* Most of the chanend parameters to the function should be connected to
|
||||
* XUD_Manager(). The uses two cores.
|
||||
*
|
||||
* \param c_aud_out Audio OUT endpoint channel connected to the XUD
|
||||
* \param c_aud_in Audio IN endpoint channel connected to the XUD
|
||||
* \param c_aud_fb Audio feedback endpoint channel connected to the XUD
|
||||
* \param c_midi_from_host MIDI OUT endpoint channel connected to the XUD
|
||||
* \param c_midi_to_host MIDI IN endpoint channel connected to the XUD
|
||||
* \param c_midi Channel connected to MIDI core
|
||||
* \param c_int Audio clocking interrupt endpoint channel connected to the XUD
|
||||
* \param c_clk_int Optional chanend connected to the clockGen() thread if present
|
||||
* \param c_sof Start of frame channel connected to the XUD
|
||||
* \param c_aud_ctl Audio control channel connected to Endpoint0()
|
||||
* \param p_off_mclk A port that is clocked of the MCLK input (not the MCLK input itself)
|
||||
* \param c_aud Channel connected to XUA_AudioHub() core
|
||||
* \param i_pll_ref Interface to task that toggles reference pin to CS2100
|
||||
* \param c_aud_out Audio OUT endpoint channel connected to the XUD
|
||||
* \param c_aud_in Audio IN endpoint channel connected to the XUD
|
||||
* \param c_aud_fb Audio feedback endpoint channel connected to the XUD
|
||||
* \param c_midi_from_host MIDI OUT endpoint channel connected to the XUD
|
||||
* \param c_midi_to_host MIDI IN endpoint channel connected to the XUD
|
||||
* \param c_midi Channel connected to MIDI core
|
||||
* \param c_int Audio clocking interrupt endpoint channel connected to the XUD
|
||||
* \param c_clk_int Optional chanend connected to the clockGen() thread if present
|
||||
* \param c_sof Start of frame channel connected to the XUD
|
||||
* \param c_aud_ctl Audio control channel connected to Endpoint0()
|
||||
* \param p_off_mclk A port that is clocked of the MCLK input (not the MCLK input itself)
|
||||
* \param c_aud Channel connected to XUA_AudioHub() core
|
||||
* \param c_audio_rate_change Channel to notify and synchronise on audio rate change
|
||||
* \param i_pll_ref Interface to task that toggles reference pin to CS2100
|
||||
* \param c_swpll_update Channel connected to software PLL task. Expects master clock counts based on USB frames.
|
||||
*/
|
||||
void XUA_Buffer(
|
||||
chanend c_aud_out,
|
||||
@@ -38,7 +40,7 @@ void XUA_Buffer(
|
||||
#if defined(MIDI) || defined(__DOXYGEN__)
|
||||
chanend c_midi_from_host,
|
||||
chanend c_midi_to_host,
|
||||
chanend c_midi,
|
||||
chanend c_midi,
|
||||
#endif
|
||||
#if XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN || defined(__DOXYGEN__)
|
||||
chanend ?c_int,
|
||||
@@ -50,9 +52,19 @@ void XUA_Buffer(
|
||||
#if (HID_CONTROLS)
|
||||
, chanend c_hid
|
||||
#endif
|
||||
#if PAWPAW_INOUTHID
|
||||
, chanend c_hid
|
||||
, chanend c_hid_out
|
||||
#endif//#if PAWPAW_INOUTHID
|
||||
, chanend c_aud
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || defined(__DOXYGEN__)
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || defined(__DOYXGEN__)
|
||||
, chanend c_audio_rate_change
|
||||
#if (!XUA_USE_SW_PLL) || defined(__DOXYGEN__)
|
||||
, client interface pll_ref_if i_pll_ref
|
||||
#endif
|
||||
#if (XUA_USE_SW_PLL) || defined(__DOXYGEN__)
|
||||
, chanend c_swpll_update
|
||||
#endif
|
||||
#endif
|
||||
);
|
||||
|
||||
@@ -66,7 +78,7 @@ void XUA_Buffer_Ep(chanend c_aud_out,
|
||||
#ifdef MIDI
|
||||
chanend c_midi_from_host,
|
||||
chanend c_midi_to_host,
|
||||
chanend c_midi,
|
||||
chanend c_midi,
|
||||
#endif
|
||||
#if (XUA_SPDIF_RX_EN) || (XUA_ADAT_RX_EN)
|
||||
chanend ?c_int,
|
||||
@@ -78,13 +90,24 @@ void XUA_Buffer_Ep(chanend c_aud_out,
|
||||
#if (HID_CONTROLS)
|
||||
, chanend c_hid
|
||||
#endif
|
||||
#if PAWPAW_INOUTHID
|
||||
, chanend c_hid
|
||||
, chanend c_hid_out
|
||||
#endif //#if PAWPAW_INOUTHID
|
||||
#ifdef CHAN_BUFF_CTRL
|
||||
, chanend c_buff_ctrl
|
||||
#endif
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || defined(__DOXYGEN__)
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || defined(__DOYXGEN__)
|
||||
, chanend c_audio_rate_change
|
||||
#if (!XUA_USE_SW_PLL) || defined(__DOXYGEN__)
|
||||
, client interface pll_ref_if i_pll_ref
|
||||
#endif
|
||||
#if (XUA_USE_SW_PLL) || defined(__DOXYGEN__)
|
||||
, chanend c_swpll_update
|
||||
#endif
|
||||
#endif
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
/** Manage the data transfer between the USB audio buffer and the
|
||||
* Audio I/O driver.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#ifndef _CLOCKING_H_
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <xs1.h>
|
||||
|
||||
#include "sw_pll_wrapper.h"
|
||||
|
||||
interface pll_ref_if
|
||||
{
|
||||
void toggle();
|
||||
@@ -18,15 +20,31 @@ void PllRefPinTask(server interface pll_ref_if i_pll_ref, out port p_sync);
|
||||
|
||||
/** Clock generation and digital audio I/O handling.
|
||||
*
|
||||
* \param c_spdif_rx channel connected to S/PDIF receive thread
|
||||
* \param c_adat_rx channel connect to ADAT receive thread
|
||||
* \param i_pll_ref interface to taslk that outputs clock signal to drive external frequency synthesizer
|
||||
* \param c_audio channel connected to the audio() thread
|
||||
* \param c_clk_ctl channel connected to Endpoint0() for configuration of the
|
||||
* clock
|
||||
* \param c_clk_int channel connected to the decouple() thread for clock
|
||||
interrupts
|
||||
* \param c_spdif_rx channel connected to S/PDIF receive thread
|
||||
* \param c_adat_rx channel connect to ADAT receive thread
|
||||
* \param i_pll_ref interface to taslk that outputs clock signal to drive external frequency synthesizer
|
||||
* \param c_audio channel connected to the audio() thread
|
||||
* \param c_clk_ctl channel connected to Endpoint0() for configuration of the
|
||||
* clock
|
||||
* \param c_clk_int channel connected to the decouple() thread for clock
|
||||
* interrupts
|
||||
* \param c_audio_rate_change channel to notify of master clock change
|
||||
* \param p_for_mclk_count_aud port used for counting mclk and providing a timestamp
|
||||
* \param c_sw_pll channel used to communicate with software PLL task
|
||||
*
|
||||
*/
|
||||
void clockGen(streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interface pll_ref_if i_pll_ref, chanend c_audio, chanend c_clk_ctl, chanend c_clk_int);
|
||||
void clockGen( streaming chanend ?c_spdif_rx,
|
||||
chanend ?c_adat_rx,
|
||||
client interface pll_ref_if i_pll_ref,
|
||||
chanend c_audio,
|
||||
chanend c_clk_ctl,
|
||||
chanend c_clk_int,
|
||||
chanend c_audio_rate_change
|
||||
#if XUA_USE_SW_PLL
|
||||
, port p_for_mclk_count_aud
|
||||
, chanend c_sw_pll
|
||||
#endif
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
/*
|
||||
* @brief Defines relating to device configuration and customisation of lib_xua
|
||||
@@ -11,7 +11,9 @@
|
||||
#include "xua_conf.h"
|
||||
#endif
|
||||
|
||||
/* Default tile arrangement */
|
||||
/*
|
||||
* Tile arrangement defines
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Location (tile) of audio I/O. Default: 0
|
||||
@@ -55,12 +57,9 @@
|
||||
#define PLL_REF_TILE AUDIO_IO_TILE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Disable USB functionalty just leaving AudioHub
|
||||
/*
|
||||
* Channel based defines
|
||||
*/
|
||||
#ifndef XUA_USB_EN
|
||||
#define XUA_USB_EN (1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Number of input channels (device to host). Default: NONE (Must be defined by app)
|
||||
@@ -79,7 +78,18 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Number of DSD output channels. Default: 0 (disabled)
|
||||
* @brief Number of PDM microphones in the design.
|
||||
*
|
||||
* Default: 0
|
||||
*/
|
||||
#ifndef XUA_NUM_PDM_MICS
|
||||
#define XUA_NUM_PDM_MICS (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Number of DSD output channels.
|
||||
*
|
||||
* Default: 0 (disabled)
|
||||
*/
|
||||
#if defined(DSD_CHANS_DAC) && (DSD_CHANS_DAC != 0)
|
||||
#if defined(NATIVE_DSD) && (NATIVE_DSD == 0)
|
||||
@@ -91,9 +101,41 @@
|
||||
#define DSD_CHANS_DAC 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Number of I2S channesl to DAC/CODEC. Must be a multiple of 2.
|
||||
*
|
||||
* Default: NONE (Must be defined by app)
|
||||
*/
|
||||
#ifndef I2S_CHANS_DAC
|
||||
#error I2S_CHANS_DAC not defined
|
||||
#define I2S_CHANS_DAC 2 /* Define anyway for doxygen */
|
||||
#else
|
||||
#define I2S_WIRES_DAC (I2S_CHANS_DAC / I2S_CHANS_PER_FRAME)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Number of I2S channels from ADC/CODEC. Must be a multiple of 2.
|
||||
*
|
||||
* Default: NONE (Must be defined by app)
|
||||
*/
|
||||
#ifndef I2S_CHANS_ADC
|
||||
#error I2S_CHANS_ADC not defined
|
||||
#define I2S_CHANS_ADC 2 /* Define anyway for doxygen */
|
||||
#else
|
||||
#define I2S_WIRES_ADC (I2S_CHANS_ADC / I2S_CHANS_PER_FRAME)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Defines relating to the interface to external audio hardware i.e. DAC/ADC
|
||||
*/
|
||||
|
||||
#define XUA_PCM_FORMAT_I2S (0)
|
||||
#define XUA_PCM_FORMAT_TDM (1)
|
||||
|
||||
/**
|
||||
* @brief Format of PCM audio interface. Should be set to XUA_PCM_FORMAT_I2S or XUA_PCM_FORMAT_TDM
|
||||
*
|
||||
* Default: XUA_PCM_FORMAT_I2S
|
||||
*/
|
||||
#ifdef XUA_PCM_FORMAT
|
||||
#if (XUA_PCM_FORMAT != XUA_PCM_FORMAT_I2S) && (XUA_PCM_FORMAT != XUA_PCM_FORMAT_TDM)
|
||||
#error Bad value for XUA_PCM_FORMAT
|
||||
@@ -116,30 +158,17 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Number of IS2 channesl to DAC/CODEC. Must be a multiple of 2.
|
||||
* @brief Number of bits per channel for I2S/TDM. Supported values: 16/32-bit.
|
||||
*
|
||||
* Default: NONE (Must be defined by app)
|
||||
* Default: 32 bits
|
||||
*/
|
||||
#ifndef I2S_CHANS_DAC
|
||||
#error I2S_CHANS_DAC not defined
|
||||
#define I2S_CHANS_DAC 2 /* Define anyway for doxygen */
|
||||
#else
|
||||
#define I2S_WIRES_DAC (I2S_CHANS_DAC / I2S_CHANS_PER_FRAME)
|
||||
#ifndef XUA_I2S_N_BITS
|
||||
#define XUA_I2S_N_BITS (32)
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Number of I2S channels from ADC/CODEC. Must be a multiple of 2.
|
||||
*
|
||||
* Default: NONE (Must be defined by app)
|
||||
*/
|
||||
#ifndef I2S_CHANS_ADC
|
||||
#error I2S_CHANS_ADC not defined
|
||||
#define I2S_CHANS_ADC 2 /* Define anyway for doxygen */
|
||||
#else
|
||||
#define I2S_WIRES_ADC (I2S_CHANS_ADC / I2S_CHANS_PER_FRAME)
|
||||
#if (XUA_I2S_N_BITS != 16) && (XUA_I2S_N_BITS != 32)
|
||||
#error Unsupported value for XUA_I2S_N_BITS (only values 16/32 supported)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -193,22 +222,32 @@
|
||||
#define I2S_DOWNSAMPLE_CHANS_IN I2S_CHANS_ADC
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Clocking related defines
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Max supported sample frequency for device (Hz). Default: 192000
|
||||
* @brief Max supported sample frequency for device (Hz).
|
||||
*
|
||||
* Default: 192000Hz
|
||||
*/
|
||||
#ifndef MAX_FREQ
|
||||
#define MAX_FREQ (192000)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Min supported sample frequency for device (Hz). Default 44100
|
||||
* @brief Min supported sample frequency for device (Hz).
|
||||
*
|
||||
* Default: 44100Hz
|
||||
*/
|
||||
#ifndef MIN_FREQ
|
||||
#define MIN_FREQ (44100)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Master clock defines for 44100 rates (in Hz). Default: NONE (Must be defined by app)
|
||||
* @brief Master clock defines for 44100 rates (in Hz).
|
||||
*
|
||||
* Default: NONE (Must be defined by app)
|
||||
*/
|
||||
#ifndef MCLK_441
|
||||
#error MCLK_441 not defined
|
||||
@@ -216,7 +255,9 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Master clock defines for 48000 rates (in Hz). Default: NONE (Must be defined by app)
|
||||
* @brief Master clock defines for 48000 rates (in Hz).
|
||||
*
|
||||
* Default: NONE (Must be defined by app)
|
||||
*/
|
||||
#ifndef MCLK_48
|
||||
#error MCLK_48 not defined
|
||||
@@ -224,26 +265,61 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Default device sample frequency. A safe default should be used. Default: MIN_FREQ
|
||||
* @brief Enable/disable the use of the secondary/application PLL for generating and recovering master-clocks.
|
||||
* Only available on xcore.ai devices.
|
||||
*
|
||||
* Default: Enabled (for xcore.ai devices)
|
||||
*/
|
||||
#ifndef XUA_USE_SW_PLL
|
||||
#if defined(__XS3A__)
|
||||
#define XUA_USE_SW_PLL (1)
|
||||
#else
|
||||
#define XUA_USE_SW_PLL (0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Default device sample frequency. A safe default should be used.
|
||||
*
|
||||
* Default: MIN_FREQ
|
||||
*/
|
||||
#ifndef DEFAULT_FREQ
|
||||
#define DEFAULT_FREQ (MIN_FREQ)
|
||||
#endif
|
||||
|
||||
/* Audio Class Defines */
|
||||
#define DEFAULT_MCLK (((DEFAULT_FREQ % 7350) == 0) ? MCLK_441 : MCLK_48)
|
||||
|
||||
/**
|
||||
* @brief USB Audio Class Version. Default: 2 (Audio Class version 2.0)
|
||||
* @brief Defines whether XMOS device runs as master (i.e. drives LR and Bit clocks)
|
||||
*
|
||||
* 0: XMOS is I2S master. 1: CODEC is I2s master.
|
||||
*
|
||||
* Default: 0 (XMOS is master)
|
||||
*/
|
||||
#ifndef CODEC_MASTER
|
||||
#define CODEC_MASTER (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Audio Class defines
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USB Audio Class Version
|
||||
*
|
||||
* Default: 2 (Audio Class version 2.0)
|
||||
*/
|
||||
#ifndef AUDIO_CLASS
|
||||
#define AUDIO_CLASS 2
|
||||
#define AUDIO_CLASS (2)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Whether or not to fall back to Audio Class 1.0 in USB Full-speed. Default: 0 (Disabled)
|
||||
* @brief Enable/disable fall back to Audio Class 1.0 in USB Full-speed.
|
||||
*
|
||||
* Default: Disabled
|
||||
*/
|
||||
#ifndef AUDIO_CLASS_FALLBACK
|
||||
#define AUDIO_CLASS_FALLBACK 0 /* Default to not falling back to UAC 1 */
|
||||
#define AUDIO_CLASS_FALLBACK (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -272,14 +348,17 @@
|
||||
#error AUDIO_CLASS set to 1 and FULL_SPEED_AUDIO_2 enabled!
|
||||
#endif
|
||||
|
||||
|
||||
/* Feature defines */
|
||||
/*
|
||||
* Feature defines
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Number of PDM microphones in the design. Default: None
|
||||
* @brief Disable USB functionalty just leaving AudioHub
|
||||
*
|
||||
* Default: Enabled
|
||||
*/
|
||||
#ifndef XUA_NUM_PDM_MICS
|
||||
#define XUA_NUM_PDM_MICS (0)
|
||||
#ifndef XUA_USB_EN
|
||||
#define XUA_USB_EN (1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -333,6 +412,28 @@
|
||||
#define SPDIF_TX_INDEX (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables SPDIF Rx. Default: 0 (Disabled)
|
||||
*/
|
||||
#ifndef XUA_SPDIF_RX_EN
|
||||
#define XUA_SPDIF_RX_EN (0)
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief S/PDIF Rx first channel index, defines which channels S/PDIF will be input on.
|
||||
* Note, indexed from 0.
|
||||
*
|
||||
* Default: NONE (Must be defined by app when SPDIF_RX enabled)
|
||||
*/
|
||||
#if (XUA_SPDIF_RX_EN) || defined (__DOXYGEN__)
|
||||
#ifndef SPDIF_RX_INDEX
|
||||
#error SPDIF_RX_INDEX not defined and XUA_SPDIF_RX_EN defined
|
||||
#define SPDIF_RX_INDEX 0 /* Default define for doxygen */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enables ADAT Tx. Default: 0 (Disabled)
|
||||
*/
|
||||
@@ -340,20 +441,35 @@
|
||||
#define XUA_ADAT_TX_EN (0)
|
||||
#endif
|
||||
|
||||
/* Calculate max ADAT channels based on sample rate range. Used for Tx and Rx */
|
||||
#if (MIN_FREQ < 88200)
|
||||
#define ADAT_MAX_CHANS (8)
|
||||
#elif (MIN_FREQ < 176400)
|
||||
#define ADAT_MAX_CHANS (4)
|
||||
#else
|
||||
#define ADAT_MAX_CHANS (2)
|
||||
#endif
|
||||
|
||||
/* Set the maximum number of channels for ADAT */
|
||||
#if XUA_ADAT_TX_EN
|
||||
#define ADAT_TX_MAX_CHANS ADAT_MAX_CHANS
|
||||
#else
|
||||
#define ADAT_TX_MAX_CHANS (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Defines which output channels (8) should be output on ADAT. Note, Output channels indexed from 0.
|
||||
*
|
||||
* Default: 0 (i.e. channels [0:7])
|
||||
* */
|
||||
#ifndef ADAT_TX_INDEX
|
||||
#define ADAT_TX_INDEX (0)
|
||||
#endif
|
||||
#if (XUA_ADAT_TX_EN) || defined(__DOXYGEN__)
|
||||
#ifndef ADAT_TX_INDEX
|
||||
#define ADAT_TX_INDEX (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables SPDIF Rx. Default: 0 (Disabled)
|
||||
*/
|
||||
#ifndef XUA_SPDIF_RX_EN
|
||||
#define XUA_SPDIF_RX_EN (0)
|
||||
#if (ADAT_TX_INDEX + ADAT_TX_MAX_CHANS > NUM_USB_CHAN_OUT)
|
||||
#error Not enough channels for ADAT Tx
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -363,17 +479,11 @@
|
||||
#define XUA_ADAT_RX_EN (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief S/PDIF Rx first channel index, defines which channels S/PDIF will be input on.
|
||||
* Note, indexed from 0.
|
||||
*
|
||||
* Default: NONE (Must be defined by app when SPDIF_RX enabled)
|
||||
*/
|
||||
#if (XUA_SPDIF_RX_EN) || defined (__DOXYGEN__)
|
||||
#ifndef SPDIF_RX_INDEX
|
||||
#error SPDIF_RX_INDEX not defined and XUA_SPDIF_RX_EN defined
|
||||
#define SPDIF_RX_INDEX 0 /* Default define for doxygen */
|
||||
#endif
|
||||
/* Set the maximum number of channels for ADAT */
|
||||
#if XUA_ADAT_RX_EN
|
||||
#define ADAT_RX_MAX_CHANS ADAT_MAX_CHANS
|
||||
#else
|
||||
#define ADAT_RX_MAX_CHANS (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -383,30 +493,80 @@
|
||||
* Default: NONE (Must be defined by app when XUA_ADAT_RX_EN is true)
|
||||
*/
|
||||
#if (XUA_ADAT_RX_EN) || defined(__DOXYGEN__)
|
||||
#ifndef ADAT_RX_INDEX
|
||||
#error ADAT_RX_INDEX not defined and XUA_ADAT_RX_EN is true
|
||||
#define ADAT_RX_INDEX (0) /* Default define for doxygen */
|
||||
#ifndef ADAT_RX_INDEX
|
||||
#error ADAT_RX_INDEX not defined and XUA_ADAT_RX_EN is true
|
||||
#define ADAT_RX_INDEX (0) /* Default define for doxygen */
|
||||
#endif
|
||||
|
||||
#if (ADAT_RX_INDEX + ADAT_RX_MAX_CHANS > NUM_USB_CHAN_IN)
|
||||
#error Not enough channels for ADAT Rx
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (ADAT_RX_INDEX + 8 > NUM_USB_CHAN_IN)
|
||||
#error Not enough channels for ADAT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (XUA_ADAT_RX_EN)
|
||||
|
||||
/* Setup input stream formats for ADAT */
|
||||
#if(MAX_FREQ > 96000)
|
||||
#define INPUT_FORMAT_COUNT 3
|
||||
#elif(MAX_FREQ > 48000)
|
||||
#define INPUT_FORMAT_COUNT 2
|
||||
#else
|
||||
#define INPUT_FORMAT_COUNT 1
|
||||
#if (XUA_ADAT_RX_EN)
|
||||
#if (MAX_FREQ > 96000)
|
||||
#if (MIN_FREQ > 96000)
|
||||
#define INPUT_FORMAT_COUNT 1
|
||||
#define HS_STREAM_FORMAT_INPUT_1_CHAN_COUNT NUM_USB_CHAN_IN
|
||||
#elif (MIN_FREQ > 48000)
|
||||
#define INPUT_FORMAT_COUNT 2
|
||||
#define HS_STREAM_FORMAT_INPUT_1_CHAN_COUNT NUM_USB_CHAN_IN
|
||||
#define HS_STREAM_FORMAT_INPUT_2_CHAN_COUNT (NUM_USB_CHAN_IN - 2)
|
||||
#else
|
||||
#define INPUT_FORMAT_COUNT 3
|
||||
#define HS_STREAM_FORMAT_INPUT_1_CHAN_COUNT NUM_USB_CHAN_IN
|
||||
#define HS_STREAM_FORMAT_INPUT_2_CHAN_COUNT (NUM_USB_CHAN_IN - 4)
|
||||
#define HS_STREAM_FORMAT_INPUT_3_CHAN_COUNT (NUM_USB_CHAN_IN - 6)
|
||||
#endif
|
||||
#elif (MAX_FREQ > 48000)
|
||||
#if (MIN_FREQ > 48000)
|
||||
#define INPUT_FORMAT_COUNT 1
|
||||
#define HS_STREAM_FORMAT_INPUT_1_CHAN_COUNT NUM_USB_CHAN_IN
|
||||
#else
|
||||
#define INPUT_FORMAT_COUNT 2
|
||||
#define HS_STREAM_FORMAT_INPUT_1_CHAN_COUNT NUM_USB_CHAN_IN
|
||||
#define HS_STREAM_FORMAT_INPUT_2_CHAN_COUNT (NUM_USB_CHAN_IN - 4)
|
||||
#endif
|
||||
#else
|
||||
#define INPUT_FORMAT_COUNT 1
|
||||
#define HS_STREAM_FORMAT_INPUT_1_CHAN_COUNT NUM_USB_CHAN_IN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define HS_STREAM_FORMAT_INPUT_1_CHAN_COUNT NUM_USB_CHAN_IN
|
||||
#define HS_STREAM_FORMAT_INPUT_2_CHAN_COUNT (NUM_USB_CHAN_IN - 4)
|
||||
#define HS_STREAM_FORMAT_INPUT_3_CHAN_COUNT (NUM_USB_CHAN_IN - 6)
|
||||
/* Setup output stream formats for ADAT */
|
||||
#if (XUA_ADAT_TX_EN)
|
||||
#if (MAX_FREQ > 96000)
|
||||
#if (MIN_FREQ > 96000)
|
||||
#define OUTPUT_FORMAT_COUNT 1
|
||||
#define HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT NUM_USB_CHAN_OUT
|
||||
#elif (MIN_FREQ > 48000)
|
||||
#define OUTPUT_FORMAT_COUNT 2
|
||||
#define HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT NUM_USB_CHAN_OUT
|
||||
#define HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT (NUM_USB_CHAN_OUT - 2)
|
||||
#else
|
||||
#define OUTPUT_FORMAT_COUNT 3
|
||||
#define HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT NUM_USB_CHAN_OUT
|
||||
#define HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT (NUM_USB_CHAN_OUT - 4)
|
||||
#define HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT (NUM_USB_CHAN_OUT - 6)
|
||||
#endif
|
||||
#elif (MAX_FREQ > 48000)
|
||||
#if (MIN_FREQ > 48000)
|
||||
#define OUTPUT_FORMAT_COUNT 1
|
||||
#define HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT NUM_USB_CHAN_OUT
|
||||
#else
|
||||
#define OUTPUT_FORMAT_COUNT 2
|
||||
#define HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT NUM_USB_CHAN_OUT
|
||||
#define HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT (NUM_USB_CHAN_OUT - 4)
|
||||
#endif
|
||||
#else
|
||||
#define OUTPUT_FORMAT_COUNT 1
|
||||
#define HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT NUM_USB_CHAN_OUT
|
||||
#endif
|
||||
#define STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS 24
|
||||
#define STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS 24
|
||||
#define STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS 24
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -432,14 +592,36 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Defines whether XMOS device runs as master (i.e. drives LR and Bit clocks)
|
||||
* HID may be required in two forms: the built-in XUA-HID reports, or a
|
||||
* user-provided static HID. Some sections of code are always needed, they
|
||||
* are enclosed in XUA_OR_STATIC_HID_ENABLED; code specific to XUA-HID
|
||||
* reports are enclosed in XUA_HID_ENABLED.
|
||||
*
|
||||
* 0: XMOS is I2S master. 1: CODEC is I2s master.
|
||||
* HID_CONTROLS implies that the XUA_HID is used, and hence defines both.
|
||||
* In order to roll your own, do not enable HID_CONTROLS, but instead
|
||||
* create a file static_hid_report.h that contains the static descriptor.
|
||||
*
|
||||
* Default: 0 (XMOS is master)
|
||||
* You must also supply your own function to deal with the HID endpoint(s)
|
||||
* in this case.
|
||||
*/
|
||||
#ifndef CODEC_MASTER
|
||||
#define CODEC_MASTER (0)
|
||||
#if (HID_CONTROLS) || defined (__DOXYGEN__)
|
||||
#define XUA_HID_ENABLED (1)
|
||||
#define XUA_OR_STATIC_HID_ENABLED (1)
|
||||
#endif
|
||||
|
||||
#if defined(__static_hid_report_h_exists__)
|
||||
#define XUA_OR_STATIC_HID_ENABLED (1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable a HID OUT endpoint. Only use this if you supply your own HID control.
|
||||
*
|
||||
* 1 for enabled, 0 for disabled.
|
||||
*
|
||||
* Default 0 (Disabled)
|
||||
*/
|
||||
#ifndef HID_OUT_REQUIRED
|
||||
#define HID_OUT_REQUIRED (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -566,7 +748,7 @@
|
||||
#define OUTPUT_FORMAT_COUNT 2
|
||||
#else
|
||||
/* Default format count is 3 (16bit, 24bit, DSD) */
|
||||
#define OUTPUT_FORMAT_COUNT 3
|
||||
#define OUTPUT_FORMAT_COUNT 2
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -600,7 +782,7 @@
|
||||
#if (NATIVE_DSD_FORMAT_NUM == 1)
|
||||
#define STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS 32 /* DSD requires 32bits */
|
||||
#else
|
||||
#define STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS 24
|
||||
#define STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS 32
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -614,7 +796,7 @@
|
||||
#if (NATIVE_DSD_FORMAT_NUM == 2)
|
||||
#define STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS 32 /* DSD requires 32bits */
|
||||
#else
|
||||
#define STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS 16
|
||||
#define STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS 24
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -798,7 +980,7 @@
|
||||
* Default: 1
|
||||
*/
|
||||
#ifndef INPUT_FORMAT_COUNT
|
||||
#define INPUT_FORMAT_COUNT 1
|
||||
#define INPUT_FORMAT_COUNT 2
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -811,7 +993,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef STREAM_FORMAT_INPUT_2_RESOLUTION_BITS
|
||||
#define STREAM_FORMAT_INPUT_2_RESOLUTION_BITS 24
|
||||
#define STREAM_FORMAT_INPUT_2_RESOLUTION_BITS 32
|
||||
#endif
|
||||
|
||||
#ifndef STREAM_FORMAT_INPUT_3_RESOLUTION_BITS
|
||||
@@ -861,7 +1043,18 @@
|
||||
#define HS_STREAM_FORMAT_INPUT_3_CHAN_COUNT NUM_USB_CHAN_IN
|
||||
#endif
|
||||
|
||||
/* Channel count defines for output streams */
|
||||
#ifndef HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT
|
||||
#define HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT NUM_USB_CHAN_OUT
|
||||
#endif
|
||||
|
||||
#ifndef HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT
|
||||
#define HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT NUM_USB_CHAN_OUT
|
||||
#endif
|
||||
|
||||
#ifndef HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT
|
||||
#define HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT NUM_USB_CHAN_OUT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Sample sub-slot size (bytes) of input stream Alternate 1 when running in high-speed
|
||||
@@ -943,7 +1136,7 @@
|
||||
* Default: 1 (Enabled)
|
||||
*/
|
||||
#ifndef OUTPUT_VOLUME_CONTROL
|
||||
#define OUTPUT_VOLUME_CONTROL (1)
|
||||
#define OUTPUT_VOLUME_CONTROL (1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -952,7 +1145,7 @@
|
||||
* Default: 1 (Enabled)
|
||||
*/
|
||||
#ifndef INPUT_VOLUME_CONTROL
|
||||
#define INPUT_VOLUME_CONTROL (1)
|
||||
#define INPUT_VOLUME_CONTROL (1)
|
||||
#endif
|
||||
|
||||
/* Power */
|
||||
@@ -997,19 +1190,14 @@
|
||||
#define MIXER (0)
|
||||
#endif
|
||||
|
||||
/* Tidy up old ifndef usage */
|
||||
#if defined(MIXER) && (MIXER == 0)
|
||||
#undef MIXER
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Number of seperate mixes to perform
|
||||
*
|
||||
* Default: 8 if MIXER enabled, else 0
|
||||
*/
|
||||
#ifdef MIXER
|
||||
#if (MIXER)
|
||||
#ifndef MAX_MIX_COUNT
|
||||
#define MAX_MIX_COUNT (8)
|
||||
#define MAX_MIX_COUNT (8)
|
||||
#endif
|
||||
#else
|
||||
#ifndef MAX_MIX_COUNT
|
||||
@@ -1087,44 +1275,28 @@
|
||||
#define VOLUME_RES_MIXER (0x100)
|
||||
#endif
|
||||
|
||||
/* Handle out volume control in the mixer */
|
||||
#if defined(OUT_VOLUME_IN_MIXER) && (OUT_VOLUME_IN_MIXER==0)
|
||||
#undef OUT_VOLUME_IN_MIXER
|
||||
/* Handle out volume control in the mixer - enabled by default */
|
||||
#ifndef OUT_VOLUME_IN_MIXER
|
||||
#if MIXER
|
||||
#define OUT_VOLUME_IN_MIXER (1)
|
||||
#else
|
||||
#if defined(MIXER)
|
||||
// Disabled by default
|
||||
//#define OUT_VOLUME_IN_MIXER
|
||||
#define OUT_VOLUME_IN_MIXER (0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Apply out volume controls after the mix */
|
||||
#if defined(OUT_VOLUME_AFTER_MIX) && (OUT_VOLUME_AFTER_MIX==0)
|
||||
#undef OUT_VOLUME_AFTER_MIX
|
||||
#else
|
||||
#if defined(MIXER) && defined(OUT_VOLUME_IN_MIXER)
|
||||
// Enabled by default
|
||||
#define OUT_VOLUME_AFTER_MIX
|
||||
#endif
|
||||
/* Apply out volume controls after the mix. Only relevant when OUT_VOLUME_IN_MIXER enabled. Enabled by default */
|
||||
#ifndef OUT_VOLUME_AFTER_MIX
|
||||
#define OUT_VOLUME_AFTER_MIX (1)
|
||||
#endif
|
||||
|
||||
/* Handle in volume control in the mixer */
|
||||
#if defined(IN_VOLUME_IN_MIXER) && (IN_VOLUME_IN_MIXER==0)
|
||||
#undef IN_VOLUME_IN_MIXER
|
||||
#else
|
||||
#if defined(MIXER)
|
||||
/* Disabled by default */
|
||||
//#define IN_VOLUME_IN_MIXER
|
||||
#endif
|
||||
/* Handle in volume control in the mixer - disabled by default */
|
||||
#ifndef IN_VOLUME_IN_MIXER
|
||||
#define IN_VOLUME_IN_MIXER (0)
|
||||
#endif
|
||||
|
||||
/* Apply in volume controls after the mix */
|
||||
#if defined(IN_VOLUME_AFTER_MIX) && (IN_VOLUME_AFTER_MIX==0)
|
||||
#undef IN_VOLUME_AFTER_MIX
|
||||
#else
|
||||
#if defined(MIXER) && defined(IN_VOLUME_IN_MIXER)
|
||||
// Enabled by default
|
||||
#define IN_VOLUME_AFTER_MIX
|
||||
#endif
|
||||
/* Apply in volume controls after the mix. Only relevant when IN_VOLUMNE_IN MIXER enabled. Enabled by default */
|
||||
#ifndef IN_VOLUME_AFTER_MIX
|
||||
#define IN_VOLUME_AFTER_MIX (1)
|
||||
#endif
|
||||
|
||||
/* Always enable explicit feedback EP, even when input stream is present */
|
||||
@@ -1146,7 +1318,7 @@
|
||||
#endif
|
||||
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
#if (XUA_SPDIF_RX_EN|| ADAT_RX)
|
||||
#if (XUA_SPDIF_RX_EN|| XUA_ADAT_RX_EN)
|
||||
#error "Digital input streams not supported in Sync mode"
|
||||
#endif
|
||||
#endif
|
||||
@@ -1164,14 +1336,16 @@ enum USBEndpointNumber_In
|
||||
#if (NUM_USB_CHAN_IN == 0) || defined (UAC_FORCE_FEEDBACK_EP)
|
||||
ENDPOINT_NUMBER_IN_FEEDBACK,
|
||||
#endif
|
||||
#if (NUM_USB_CHAN_IN != 0)
|
||||
ENDPOINT_NUMBER_IN_AUDIO,
|
||||
#endif
|
||||
#if (XUA_SPDIF_RX_EN) || (XUA_ADAT_RX_EN)
|
||||
ENDPOINT_NUMBER_IN_INTERRUPT, /* Audio interrupt/status EP */
|
||||
#endif
|
||||
#ifdef MIDI
|
||||
ENDPOINT_NUMBER_IN_MIDI,
|
||||
#endif
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
ENDPOINT_NUMBER_IN_HID,
|
||||
#endif
|
||||
#ifdef IAP
|
||||
@@ -1198,6 +1372,9 @@ enum USBEndpointNumber_Out
|
||||
#ifdef IAP_EA_NATIVE_TRANS
|
||||
ENDPOINT_NUMBER_OUT_IAP_EA_NATIVE_TRANS,
|
||||
#endif
|
||||
#endif
|
||||
#if XUA_OR_STATIC_HID_ENABLED && HID_OUT_REQUIRED
|
||||
ENDPOINT_NUMBER_OUT_HID,
|
||||
#endif
|
||||
XUA_ENDPOINT_COUNT_OUT /* End marker */
|
||||
};
|
||||
@@ -1219,7 +1396,8 @@ enum USBEndpointNumber_Out
|
||||
#define AUDIO_START_FROM_DFU (0x87654321)
|
||||
#define AUDIO_REBOOT_FROM_DFU (0xa5a5a5a5)
|
||||
|
||||
#define MAX_VOL (0x20000000)
|
||||
/* Result of db_to_mult(MAX_VOLUME, 8, 29) */
|
||||
#define MAX_VOLUME_MULT (0x20000000)
|
||||
|
||||
#if defined(LEVEL_METER_LEDS) && !defined(LEVEL_UPDATE_RATE)
|
||||
#define LEVEL_UPDATE_RATE (400000)
|
||||
@@ -1319,9 +1497,9 @@ enum USBEndpointNumber_Out
|
||||
/* Some defines that allow us to remove unused code */
|
||||
|
||||
/* Useful for dropping lower part of macs in volume processing... */
|
||||
#if (FS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS > 24) || (FS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS > 24) || \
|
||||
(FS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS > 24) || (HS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS > 24) || \
|
||||
(HS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS > 24) || (HS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS > 24)
|
||||
#if (FS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS > 24) || (HS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS > 24) || \
|
||||
(((FS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS > 24) || (HS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS > 24)) && (OUTPUT_FORMAT_COUNT > 1)) || \
|
||||
(((FS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS > 24) || (HS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS > 24)) && (OUTPUT_FORMAT_COUNT > 2))
|
||||
#define STREAM_FORMAT_OUTPUT_RESOLUTION_32BIT_USED 1
|
||||
#else
|
||||
#define STREAM_FORMAT_OUTPUT_RESOLUTION_32BIT_USED 0
|
||||
@@ -1353,29 +1531,29 @@ enum USBEndpointNumber_Out
|
||||
#endif
|
||||
|
||||
/* Useful for dropping lower part of macs in volume processing... */
|
||||
#if (FS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS > 24) || (FS_STREAM_FORMAT_INPUT_2_RESOLUTION_BITS > 24)
|
||||
#define STREAM_FORMAT_INPUT_RESOLUTION_32BIT_USED 1
|
||||
#else
|
||||
#define STREAM_FORMAT_INPUT_RESOLUTION_32BIT_USED 0
|
||||
#endif
|
||||
#if (FS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS > 24) || (HS_STREAM_FORMAT_INPUT_1_RESOLUTION_BITS > 24)
|
||||
#define STREAM_FORMAT_INPUT_RESOLUTION_32BIT_USED 1
|
||||
#else
|
||||
#define STREAM_FORMAT_INPUT_RESOLUTION_32BIT_USED 0
|
||||
#endif
|
||||
|
||||
#if((FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 4) || (HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 4))
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_4_USED 1
|
||||
#else
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_4_USED 0
|
||||
#endif
|
||||
#if((FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 4) || (HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 4))
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_4_USED 1
|
||||
#else
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_4_USED 0
|
||||
#endif
|
||||
|
||||
#if((FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 3) || (HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 3))
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_3_USED 1
|
||||
#else
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_3_USED 0
|
||||
#endif
|
||||
#if((FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 3) || (HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 3))
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_3_USED 1
|
||||
#else
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_3_USED 0
|
||||
#endif
|
||||
|
||||
#if((FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 2) || (HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 2))
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_2_USED 1
|
||||
#else
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_2_USED 0
|
||||
#endif
|
||||
#if((FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 2) || (HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES == 2))
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_2_USED 1
|
||||
#else
|
||||
#define STREAM_FORMAT_INPUT_SUBSLOT_2_USED 0
|
||||
#endif
|
||||
|
||||
#if MAX_FREQ < MIN_FREQ
|
||||
#error MAX_FREQ should be >= MIN_FREQ!!
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2022 XMOS LIMITED.
|
||||
// Copyright 2017-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#ifndef __XUA_CONF_FULL_H__
|
||||
#define __XUA_CONF_FULL_H__
|
||||
#ifndef _XUA_CONF_FULL_H_
|
||||
#define _XUA_CONF_FULL_H_
|
||||
|
||||
#ifdef __xua_conf_h_exists__
|
||||
#include "xua_conf.h"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#ifndef _XUA_MIDI_H_
|
||||
#define _XUA_MIDI_H_
|
||||
@@ -57,24 +57,25 @@ void midi_get_ack_or_data(chanend c, int &is_ack, unsigned int &datum);
|
||||
INLINE void midi_get_ack_or_data(chanend c, int &is_ack, unsigned int &datum) {
|
||||
if (testct(c)) {
|
||||
is_ack = 1;
|
||||
(void) inct(c); // read 1-bytes control token
|
||||
(void) inuchar(c);
|
||||
(void) inuchar(c);
|
||||
(void) inuchar(c);
|
||||
chkct(c, XS1_CT_END);
|
||||
}
|
||||
else {
|
||||
is_ack = 0;
|
||||
datum = inuint(c);
|
||||
chkct(c, XS1_CT_END);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
INLINE void midi_send_ack(chanend c) {
|
||||
outct(c, MIDI_ACK);
|
||||
outuchar(c, 0);
|
||||
outuchar(c, 0);
|
||||
outuchar(c, 0);
|
||||
outct(c, XS1_CT_END);
|
||||
}
|
||||
|
||||
INLINE void midi_send_data(chanend c, unsigned int datum) {
|
||||
outuint(c, datum);
|
||||
outct(c, XS1_CT_END);
|
||||
}
|
||||
|
||||
#define MIDI_RATE (31250)
|
||||
#define MIDI_BITTIME (XS1_TIMER_MHZ * 1000000 / MIDI_RATE)
|
||||
#define MIDI_BITTIME_2 (MIDI_BITTIME>>1)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#ifndef _XUA_MIXER_H_
|
||||
#define _XUA_MIXER_H_
|
||||
|
||||
#include "xua.h"
|
||||
|
||||
enum mix_ctl_cmd {
|
||||
SET_SAMPLES_TO_HOST_MAP,
|
||||
SET_SAMPLES_TO_DEVICE_MAP,
|
||||
@@ -31,4 +33,14 @@ enum mix_ctl_cmd {
|
||||
*/
|
||||
void mixer(chanend c_to_host, chanend c_to_audio, chanend c_mix_ctl);
|
||||
|
||||
#define XUA_MIXER_OFFSET_OUT (0)
|
||||
#define XUA_MIXER_OFFSET_IN (NUM_USB_CHAN_OUT)
|
||||
#define XUA_MIXER_OFFSET_MIX (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN)
|
||||
#define XUA_MIXER_OFFSET_OFF (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT)
|
||||
|
||||
/* Defines uses for DB to actual muliplier conversion */
|
||||
#define XUA_MIXER_MULT_FRAC_BITS (25)
|
||||
#define XUA_MIXER_DB_FRAC_BITS (8)
|
||||
#define XUA_MIXER_MAX_MULT (1<<XUA_MIXER_MULT_FRAC_BITS) /* i.e. multiply by 0 */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
.. _sec_api:
|
||||
|
||||
|
||||
API Reference
|
||||
-------------
|
||||
*************
|
||||
|
||||
.. toctree::
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.. _sec_api_component:
|
||||
|
||||
Component API
|
||||
-------------
|
||||
=============
|
||||
|
||||
The following functions can be called from the top level main of an
|
||||
application and implement the various components described in
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
.. _sec_api_defines:
|
||||
|
||||
Configuration Defines
|
||||
---------------------
|
||||
=====================
|
||||
|
||||
An application using the USB audio framework needs to have defines set for configuration.
|
||||
Defaults for these defines are found in ``xua_conf_default.h``.
|
||||
|
||||
These defines should be over-ridden in an optional header file ``xua_conf.h`` file or in the ``Makefile``
|
||||
for a relevant build configuration.
|
||||
for a relevant build configuration.
|
||||
|
||||
This section fully documents all of the settable defines and their default values (where appropriate).
|
||||
This section fully documents all of the settable defines and their default values (where appropriate).
|
||||
|
||||
Code Location (tile)
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
--------------------
|
||||
|
||||
.. doxygendefine:: AUDIO_IO_TILE
|
||||
.. doxygendefine:: XUD_TILE
|
||||
@@ -23,41 +23,51 @@ Code Location (tile)
|
||||
.. doxygendefine:: PLL_REF_TILE
|
||||
|
||||
Channel Counts
|
||||
~~~~~~~~~~~~~~
|
||||
--------------
|
||||
|
||||
.. doxygendefine:: NUM_USB_CHAN_OUT
|
||||
.. doxygendefine:: NUM_USB_CHAN_IN
|
||||
.. doxygendefine:: I2S_CHANS_DAC
|
||||
.. doxygendefine:: I2S_CHANS_ADC
|
||||
.. doxygendefine:: NUM_USB_CHAN_OUT
|
||||
.. doxygendefine:: NUM_USB_CHAN_IN
|
||||
.. doxygendefine:: I2S_CHANS_DAC
|
||||
.. doxygendefine:: I2S_CHANS_ADC
|
||||
|
||||
Frequencies and Clocks
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
Frequencies and Clocks
|
||||
----------------------
|
||||
|
||||
.. doxygendefine:: MAX_FREQ
|
||||
.. doxygendefine:: MIN_FREQ
|
||||
.. doxygendefine:: DEFAULT_FREQ
|
||||
.. doxygendefine:: MCLK_441
|
||||
.. doxygendefine:: MCLK_48
|
||||
.. doxygendefine:: XUA_USE_SW_PLL
|
||||
|
||||
Audio Class
|
||||
~~~~~~~~~~~
|
||||
-----------
|
||||
|
||||
.. doxygendefine:: AUDIO_CLASS
|
||||
.. doxygendefine:: AUDIO_CLASS_FALLBACK
|
||||
.. doxygendefine:: FULL_SPEED_AUDIO_2
|
||||
|
||||
|
||||
System Feature Configuration
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Feature Configuration
|
||||
---------------------
|
||||
|
||||
I2S/TDM
|
||||
^^^^^^^
|
||||
|
||||
.. doxygendefine:: I2S_CHANS_DAC
|
||||
.. doxygendefine:: I2S_CHANS_ADC
|
||||
.. doxygendefine:: CODEC_MASTER
|
||||
.. doxygendefine:: XUA_I2S_N_BITS
|
||||
.. doxygendefine:: XUA_PCM_FORMAT
|
||||
|
||||
MIDI
|
||||
....
|
||||
^^^^
|
||||
|
||||
.. doxygendefine:: MIDI
|
||||
.. doxygendefine:: MIDI_RX_PORT_WIDTH
|
||||
|
||||
S/PDIF
|
||||
......
|
||||
^^^^^^
|
||||
|
||||
.. doxygendefine:: XUA_SPDIF_TX_EN
|
||||
.. doxygendefine:: SPDIF_TX_INDEX
|
||||
@@ -65,37 +75,37 @@ S/PDIF
|
||||
.. doxygendefine:: SPDIF_RX_INDEX
|
||||
|
||||
ADAT
|
||||
....
|
||||
^^^^
|
||||
|
||||
.. doxygendefine:: XUA_ADAT_RX_EN
|
||||
.. doxygendefine:: ADAT_RX_INDEX
|
||||
|
||||
PDM Microphones
|
||||
...............
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
.. doxygendefine:: XUA_NUM_PDM_MICS
|
||||
|
||||
DFU
|
||||
...
|
||||
^^^
|
||||
|
||||
.. doxygendefine:: XUA_DFU_EN
|
||||
|
||||
.. .. doxygendefine:: DFU_FLASH_DEVICE
|
||||
|
||||
HID
|
||||
...
|
||||
^^^
|
||||
|
||||
.. doxygendefine:: HID_CONTROLS
|
||||
|
||||
|
||||
CODEC Interface
|
||||
...............
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
.. doxygendefine:: CODEC_MASTER
|
||||
|
||||
|
||||
USB Device Configuration
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
------------------------
|
||||
|
||||
.. doxygendefine:: VENDOR_STR
|
||||
.. doxygendefine:: VENDOR_ID
|
||||
@@ -108,10 +118,10 @@ USB Device Configuration
|
||||
|
||||
|
||||
Stream Formats
|
||||
~~~~~~~~~~~~~~
|
||||
--------------
|
||||
|
||||
Output/Playback
|
||||
...............
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
.. doxygendefine:: OUTPUT_FORMAT_COUNT
|
||||
|
||||
@@ -132,7 +142,8 @@ Output/Playback
|
||||
.. doxygendefine:: STREAM_FORMAT_OUTPUT_3_DATAFORMAT
|
||||
|
||||
Input/Recording
|
||||
...............
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
.. doxygendefine:: INPUT_FORMAT_COUNT
|
||||
|
||||
.. doxygendefine:: STREAM_FORMAT_INPUT_1_RESOLUTION_BITS
|
||||
@@ -144,7 +155,7 @@ Input/Recording
|
||||
.. doxygendefine:: STREAM_FORMAT_INPUT_1_DATAFORMAT
|
||||
|
||||
Volume Control
|
||||
~~~~~~~~~~~~~~
|
||||
--------------
|
||||
|
||||
.. doxygendefine:: OUTPUT_VOLUME_CONTROL
|
||||
.. doxygendefine:: INPUT_VOLUME_CONTROL
|
||||
@@ -152,8 +163,8 @@ Volume Control
|
||||
.. doxygendefine:: MAX_VOLUME
|
||||
.. doxygendefine:: VOLUME_RES
|
||||
|
||||
Mixing Parameters
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Mixing
|
||||
------
|
||||
|
||||
.. doxygendefine:: MIXER
|
||||
.. doxygendefine:: MAX_MIX_COUNT
|
||||
@@ -163,8 +174,7 @@ Mixing Parameters
|
||||
.. doxygendefine:: VOLUME_RES_MIXER
|
||||
|
||||
Power
|
||||
~~~~~
|
||||
-----
|
||||
|
||||
.. doxygendefine:: SELF_POWERED
|
||||
.. doxygendefine:: BMAX_POWER
|
||||
.. doxygendefine:: XUA_POWERMODE
|
||||
|
||||
|
||||
@@ -1,73 +1,49 @@
|
||||
Required User Function Definitions
|
||||
----------------------------------
|
||||
|newpage|
|
||||
|
||||
The following functions need to be defined by an application using the XMOS USB Audio framework.
|
||||
User Function Definitions
|
||||
=========================
|
||||
|
||||
The following functions can be defined by an application using `lib_xua`.
|
||||
|
||||
.. note:: Default, empty, implementations of these functions are provided in `lib_xua`. These are marked
|
||||
as weak symbols so the application can simply define its own version of them.
|
||||
|
||||
External Audio Hardware Configuration Functions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
-----------------------------------------------
|
||||
|
||||
.. c:function:: void AudioHwInit(chanend ?c_codec)
|
||||
The following functions can be optionally used by the design to configure external audio hardware.
|
||||
As a minimum, in most applications, it is expected that a implementation of `AudioHwConfig()` will need
|
||||
to be provided.
|
||||
|
||||
This function is called when the audio core starts after the
|
||||
device boots up and should initialize the external audio harware e.g. clocking, DAC, ADC etc
|
||||
.. doxygenfunction:: AudioHwInit
|
||||
.. doxygenfunction:: AudioHwConfig
|
||||
.. doxygenfunction:: AudioHwConfig_Mute
|
||||
.. doxygenfunction:: AudioHwConfig_UnMute
|
||||
|
||||
:param c_codec: An optional chanend that was original passed into
|
||||
:c:func:`audio` that can be used to communicate
|
||||
with other cores.
|
||||
|
||||
|
||||
.. c:function:: void AudioHwConfig(unsigned samFreq, unsigned mclk, chanend ?c_codec, unsigned dsdMode, unsigned sampRes_DAC, unsigned sampRes_ADC)
|
||||
|
||||
This function is called when the audio core starts or changes
|
||||
sample rate. It should configure the extenal audio hardware to run at the specified
|
||||
sample rate given the supplied master clock frequency.
|
||||
|
||||
:param samFreq: The sample frequency in Hz that the hardware should be configured to (in Hz).
|
||||
|
||||
:param mclk: The master clock frequency that is required in Hz.
|
||||
|
||||
:param c_codec: An optional chanend that was original passed into
|
||||
:c:func:`audio` that can be used to communicate
|
||||
with other cores.
|
||||
|
||||
:param dsdMode: Signifies if the audio hardware should be configured for DSD operation
|
||||
|
||||
:param sampRes_DAC: The sample resolution of the DAC stream
|
||||
|
||||
:param sampRes_ADC: The sample resolution of the ADC stream
|
||||
|
||||
|
||||
Audio Streaming Functions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Audio Stream Start/Stop Functions
|
||||
---------------------------------
|
||||
|
||||
The following functions can be optionally used by the design. They can be useful for mute lines etc.
|
||||
|
||||
.. c:function:: void AudioStreamStart(void)
|
||||
.. doxygenfunction:: UserAudioStreamStart
|
||||
.. doxygenfunction:: UserAudioStreamStop
|
||||
.. doxygenfunction:: UserAudioInputStreamStart
|
||||
.. doxygenfunction:: UserAudioInputStreamStop
|
||||
.. doxygenfunction:: UserAudioOutputStreamStart
|
||||
.. doxygenfunction:: UserAudioOutputStreamStop
|
||||
|
||||
This function is called when the audio stream from device to host
|
||||
starts.
|
||||
|
||||
.. c:function:: void AudioStreamStop(void)
|
||||
|
||||
This function is called when the audio stream from device to host stops.
|
||||
|
||||
Host Active
|
||||
~~~~~~~~~~~
|
||||
Host Active Functions
|
||||
---------------------
|
||||
|
||||
The following function can be used to signal that the device is connected to a valid host.
|
||||
|
||||
This is called on a change in state.
|
||||
|
||||
.. c:function:: void AudioStreamStart(int active)
|
||||
|
||||
:param active: Indicates if the host is active or not. 1 for active else 0.
|
||||
|
||||
.. doxygenfunction:: UserHostActive
|
||||
|
||||
HID Controls
|
||||
~~~~~~~~~~~~
|
||||
------------
|
||||
|
||||
The following function is called when the device wishes to read physical user input (buttons etc).
|
||||
The function should write relevant HID bits into this array. The bit ordering and functionality is defined by the HID report descriptor used.
|
||||
|
||||
.. c:function:: void UserReadHIDButtons(unsigned char hidData[])
|
||||
|
||||
:param hidData: The function should write relevant HID bits into this array. The bit ordering and functionality is defined by the HID report descriptor used.
|
||||
.. doxygenfunction:: UserHIDGetData
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
.. _usb_audio_sec_architecture:
|
||||
|
||||
Software Architecture
|
||||
---------------------
|
||||
*********************
|
||||
|
||||
This section describes the required software architecture of a USB Audio device implemented using `lib_xua`, its dependencies and other supporting libraries.
|
||||
|
||||
@@ -54,7 +54,9 @@ In addition :ref:`usb_audio_optional_components` shows optional components that
|
||||
* - Clockgen
|
||||
- Drives an external frequency generator (PLL) and manages
|
||||
changes between internal clocks and external clocks arising
|
||||
from digital input.
|
||||
from digital input. On xcore.ai Clockgen may also work in
|
||||
conjunction with lib_sw_pll to produce a local clock from
|
||||
the XCORE which is locked to the incoming digital stream.
|
||||
* - MIDI
|
||||
- Outputs and inputs MIDI over a serial UART interface.
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
Features & Options
|
||||
------------------
|
||||
Additional Features
|
||||
*******************
|
||||
|
||||
The previous section describes the use of core functionality contained within ``lib_xua``
|
||||
The previous chapter describes the use of core functionality contained within ``lib_xua``
|
||||
This seciton details enabling additional features with supported external dependencies, for example,
|
||||
``lib_xua`` can provide S/PDIF output though the used of ``lib_spdif``
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
S/PDIF Receive
|
||||
~~~~~~~~~~~~~~
|
||||
==============
|
||||
|
||||
``lib_xua`` supports the development of devices with S/PDIF receive functionality through the use of
|
||||
``lib_spdif``. The XMOS S/PDIF receiver runs in a single core and supports rates up to 192kHz.
|
||||
@@ -20,19 +20,20 @@ Finally, a channel for the output samples must be declared, note, this should be
|
||||
|
||||
The S/PDIF receiver should be called on the appropriate tile::
|
||||
|
||||
SpdifReceive(p_spdif_rx, c_spdif_rx, 1, clk_spd_rx);
|
||||
spdif_rx(c_spdif_rx,p_spdif_rx,clk_spd_rx,192000);
|
||||
|
||||
.. note::
|
||||
|
||||
It is recomended to use the value 1 for the ``initial_divider`` parameter
|
||||
It is recomended to use the value 192000 for the ``sample_freq_estimate`` parameter
|
||||
|
||||
With the steps above an S/PDIF stream can be captured by the xCORE. To be functionally useful the audio
|
||||
master clock must be able to synchronise to this external digital stream. Additionally, the host can be
|
||||
notified regarding changes in the validity of this stream, it's frequency etc. To synchronise to external
|
||||
streams the codebase assumes the use of an external Cirrus Logic CS2100 device.
|
||||
streams the codebase assumes the use of an external Cirrus Logic CS2100 device or lib_sw_pll on xcore.ai designs.
|
||||
|
||||
The ``ClockGen()`` task from ``lib_xua`` provides the reference signal to the CS2100 device and also handles
|
||||
recording of clock validity etc. See :ref:`usb_audio_sec_clock_recovery` for full details regarding ``ClockGen()``.
|
||||
The ``ClockGen()`` task from ``lib_xua`` provides the reference signal to the CS2100 device or timing information
|
||||
to lib_sw_pll and also handles recording of clock validity etc.
|
||||
See :ref:`usb_audio_sec_clock_recovery` for full details regarding ``ClockGen()``.
|
||||
|
||||
It also provides a small FIFO for S/PDIF samples before they are forwarded to the ``AudioHub`` core.
|
||||
As such it requires to be inserted in the communication path between the S/PDIF receiver and the
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
S/PDIF Transmit
|
||||
~~~~~~~~~~~~~~~
|
||||
===============
|
||||
|
||||
``lib_xua`` supports the development of devices with S/PDIF transmit functionality through the use of
|
||||
``lib_spdif``. The XMOS S/PDIF transmitter runs in a single core and supports rates up to 192kHz.
|
||||
|
||||
@@ -52,11 +52,11 @@ Three methods of generating an audio master clock are provided on the board:
|
||||
|
||||
* A Skyworks Si5351B PLL device. The Si5351 is an I2C configurable clock generator that is ideally suited for replacing crystals, crystal oscillators, VCXOs, phase-locked loops (PLLs), and fanout buffers.
|
||||
|
||||
* xCORE.ai devices are equipped with a secondary (or 'application') PLL which can be used to generate audio clocks
|
||||
* xCORE.ai devices are equipped with a secondary (or 'application') PLL which can be used to generate fixed audio clocks or recover external clocks using lib_sw_pll.
|
||||
|
||||
Selection between these methods is done via writing to bits 6 and 7 of PORT 8D on tile[0].
|
||||
|
||||
Either the locally generated clock (from the PL611) or the recovered low jitter clock (from the CS2100) may be selected to clock the audio stages; the xCORE-200, the ADC/DAC and Digital output stages. Selection is controlled via an additional I/O, bit 5 of PORT 8C, see :ref:`hw_316_ctrlport`.
|
||||
Either the locally generated clock (from the PL611) or the recovered low jitter clock (from the CS2100) may be selected to clock the audio stages; the xcore.ai, the ADC/DAC and Digital output stages. Selection is controlled via an additional I/O, bit 5 of PORT 8C, see :ref:`hw_316_ctrlport`.
|
||||
|
||||
.. _hw_316_ctrlport:
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|appendix|
|
||||
|
||||
Known Issues
|
||||
------------
|
||||
************
|
||||
|
||||
- Quad-SPI DFU will corrupt the factory image with tools version < 14.0.4 due to an issue with libquadflash
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
.. include:: ../../../README.rst
|
||||
|
||||
About This Document
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
===================
|
||||
|
||||
This document describes the structure of ``lib_xua``, its use and resources required. It also covers some implementation detail.
|
||||
|
||||
@@ -18,7 +17,7 @@ the XMOS tool chain and XC language.
|
||||
Options <opt>
|
||||
Advanced Usage <using_adv>
|
||||
Additional Features <feat>
|
||||
Software Detail <sw>
|
||||
Implementation Detail <sw>
|
||||
API <api>
|
||||
Known Issues <issues>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
.. _sec_options:
|
||||
|
||||
Options
|
||||
-------
|
||||
*******
|
||||
|
||||
This section describes key options of ``lib_xua``. These are typically controlled using build time defines.
|
||||
Where something must be defined, it is recommended this is done in `xua_conf.h` but could also be done in the application Makefile.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
USB Audio Class Version
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
=======================
|
||||
|
||||
The codebase supports USB Audio Class versions 1.0 and 2.0.
|
||||
|
||||
@@ -15,22 +15,22 @@ Additional improvements, amongst others, include:
|
||||
- Extensive support for interrupts to inform the host about dynamic changes that occur to different entities such as Clocks etc
|
||||
|
||||
Driver Support
|
||||
..............
|
||||
--------------
|
||||
|
||||
Audio Class 1.0
|
||||
+++++++++++++++
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
Audio Class 1.0 is fully supported in Apple OSX. Audio Class 1.0 is fully supported in all modern Microsoft Windows operating systems (i.e. Windows XP and later).
|
||||
|
||||
Audio Class 2.0
|
||||
+++++++++++++++
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
Audio Class 2.0 is fully supported in Apple OSX since version 10.6.4. Starting with Windows 10, release 1703, a USB Audio 2.0 driver is shipped with Windows.
|
||||
|
||||
Third party Windows drivers are also available, however, documentation of these is beyond the scope of this document, please contact XMOS for further details.
|
||||
|
||||
Audio Class 1.0 Mode and Fall-back
|
||||
..................................
|
||||
----------------------------------
|
||||
|
||||
The default for XMOS USB Audio applications is to run as a high-speed Audio Class 2.0
|
||||
device. However, some products may prefer to run in Audio Class 1.0 mode, this is normally to
|
||||
@@ -64,7 +64,7 @@ Due to bandwidth limitations of full-speed USB the following sample-frequency re
|
||||
|
||||
|
||||
Related Defines
|
||||
................
|
||||
---------------
|
||||
|
||||
:ref:`opt_audio_class_defines` descibes the defines that effect audio class selection.
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
.. _sec_opt_audio_formats:
|
||||
|
||||
Audio Stream Formats
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
====================
|
||||
|
||||
The design currently supports up to three different stream formats for playback, selectable at
|
||||
run time. This is implemented using standard Alternative Settings to the Audio Streaming interfaces.
|
||||
@@ -32,7 +32,7 @@ By default the design exposes two sets of Alternative Settings for the playback
|
||||
24-bit playback. When DSD is enabled an additional (32-bit) alternative is exposed.
|
||||
|
||||
Audio Subslot
|
||||
.............
|
||||
-------------
|
||||
|
||||
An audio subslot holds a single audio sample. See `USB Device Class Definition for Audio Data Formats
|
||||
<http://www.usb.org/developers/devclass_docs/Audio2.0_final.zip>`_ for full details.
|
||||
@@ -73,7 +73,7 @@ Values other than 4 may be used for the following reasons:
|
||||
|
||||
|
||||
Audio Sample Resolution
|
||||
.......................
|
||||
-----------------------
|
||||
|
||||
An audio sample is represented using a number of bits (`bBitResolution`) less than or equal to the number
|
||||
of total bits available in the audio subslot i.e. `bBitResolution` <= `bSubslotSize` * 8). The design
|
||||
@@ -99,7 +99,7 @@ supports values 16, 24 and 32.
|
||||
|
||||
|
||||
Audio Format
|
||||
............
|
||||
------------
|
||||
|
||||
The design supports two audio formats, PCM and, when "Native" DSD is enabled, Direct Stream Digital (DSD).
|
||||
A DSD capable DAC is required for the latter.
|
||||
@@ -122,7 +122,6 @@ The following options are supported:
|
||||
|
||||
* UAC_FORMAT_TYPEI_PCM
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
Currently DSD is only supported on the output/playback stream
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
Channel Counts and Sample Rates
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
===============================
|
||||
|
||||
The codebase is fully configurable in relation to channel counts and sample rates.
|
||||
Practical limitations of these are normally based on USB packet size restrictions and I/O
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
Direct Stream Digital (DSD)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
===========================
|
||||
|
||||
Direct Stream Digital (DSD) is used for digitally encoding audio signals on Super Audio CDs (SACD).
|
||||
It uses pulse-density modulation (PDM) encoding.
|
||||
@@ -48,7 +48,7 @@ If only DoP functionality is desired the Native implementation can be disabled w
|
||||
|
||||
|
||||
DSD over PCM (DoP)
|
||||
..................
|
||||
------------------
|
||||
|
||||
DoP support follows the method described in the `DoP Open Standard 1.1
|
||||
<http://dsd-guide.com/sites/default/files/white-papers/DoP_openStandard_1v1.pdf>`_.
|
||||
@@ -81,14 +81,14 @@ of rate.
|
||||
DoP requires bit-perfect transmission - therefore any audio/volume processing will break the stream.
|
||||
|
||||
"Native" vs DoP
|
||||
~~~~~~~~~~~~~~~
|
||||
---------------
|
||||
|
||||
Since the DoP specification requires header bytes this eats into the data bandwidth. The "Native" implementation
|
||||
has no such overhead and can therefore transfer the same DSD rate and half the effective PCM rate of DoP.
|
||||
Such a property may be desired when upporting DSD128 without exposing a 352.8kHz PCM rate, for example.
|
||||
|
||||
Ports
|
||||
.....
|
||||
-----
|
||||
|
||||
The codebase expects 1-bit ports to be defined in the application XN file for the DSD data and
|
||||
clock lines for example::
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
I2S/TDM
|
||||
~~~~~~~
|
||||
=======
|
||||
|
||||
I2S/TDM is typically fundamental to most products and is built into the ``XUA_AudioHub()`` core.
|
||||
|
||||
@@ -23,11 +23,14 @@ The defines in :ref:`opt_i2s_defines` effect the I2S implementation.
|
||||
- The desired number of input channels via I2S (0 for disabled)
|
||||
- N/A (Must be defined)
|
||||
* - ``XUA_PCM_FORMAT``
|
||||
- Enabled either TDM or I2S mode
|
||||
- Enables either TDM or I2S mode
|
||||
- ``XUA_PCM_FORMAT_I2S``
|
||||
* - ``CODEC_MASTER``
|
||||
- Sets is xCORE is I2S master or slave
|
||||
- Sets if xCORE is I2S master or slave
|
||||
- ``0`` (xCORE is master)
|
||||
* - ``XUA_I2S_N_BITS``
|
||||
- I2S/TDM word length (16, 32-bit supported)
|
||||
- ``32``
|
||||
|
||||
The I2S code expects that the ports required for I2S (master clock, LR-clock, bit-clock and data lines) are be defined in the application XN file in the relevant `Tile``.
|
||||
For example::
|
||||
@@ -42,8 +45,16 @@ For example::
|
||||
<Port Location="XS1_PORT_1G" Name="PORT_I2S_ADC1"/>
|
||||
</Tile>
|
||||
|
||||
All of the I2S related ports must be 1-bit ports.
|
||||
All of the I2S/TDM related ports must be 1-bit ports.
|
||||
|
||||
.. note::
|
||||
|
||||
TDM mode allows 8 channels (rather than 2) to be supplied on each dataline.
|
||||
TDM mode allows 8 channels (rather than 2) to be supplied on each data-line.
|
||||
|
||||
.. note::
|
||||
|
||||
Data output/input is in "I2S" format, rather than, say "left-justified" or "right-justified" formats.
|
||||
I2S format specifies a single bit-clock delay after the LR-clock transition before sample-data is driven/received.
|
||||
This also applies to TDM mode. TDM support in ADC/DAC hardware is quite varied, an "offset" value may need to be programmed into
|
||||
the external device for compatible operation.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
Code Location
|
||||
~~~~~~~~~~~~~
|
||||
=============
|
||||
|
||||
When designing a system there is a choice as to which hardware resources to use for each interface.
|
||||
In a multi-tile system the codebase needs to be informed as to which tiles to use for these hardware
|
||||
@@ -21,7 +21,7 @@ full listing of these ``TILE`` defines.
|
||||
- Description
|
||||
- Default
|
||||
* - ``AUDIO_IO_TILE``
|
||||
- Tile on which I2S, ADAT Rx, S/PDIF Rx & mixer resides
|
||||
- Tile on which I2S/TDM, ADAT Rx, S/PDIF Rx & mixer resides
|
||||
- ``0``
|
||||
* - ``XUD_TILE``
|
||||
- Tile on which USB resides, including buffering for all USB interfaces/endppoints
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|newpage|
|
||||
|
||||
MIDI
|
||||
~~~~
|
||||
====
|
||||
|
||||
The codebase supports MIDI input/output over USB as per `Universal Serial Bus Device Class Definition for MIDI Devices <https://www.usb.org/sites/default/files/midi10.pdf>`_.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
Mixer
|
||||
~~~~~
|
||||
=====
|
||||
|
||||
The codebase supports audio mixing functionality with highly flexible routing options.
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
|newpage|
|
||||
|
||||
Other Options
|
||||
~~~~~~~~~~~~~
|
||||
=============
|
||||
|
||||
There are a few other, lesser used, options available.
|
||||
|
||||
|
||||
.. _opt_other_defines:
|
||||
|
||||
.. list-table:: Other defines
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
PDM Microphones
|
||||
~~~~~~~~~~~~~~~
|
||||
===============
|
||||
|
||||
The codebase supports input from up to 8 PDM microphones.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
S/PDIF Receive
|
||||
~~~~~~~~~~~~~~
|
||||
==============
|
||||
|
||||
The codebase supports a single, stereo, S/PDIF receiver. This can be input via 75 Ω coaxial or optical fibre.
|
||||
In order to provide S/PDIF functionality ``lib_xua`` uses ``lib_spdif`` (https://www.github.com/xmos/lib_spdif).
|
||||
@@ -33,8 +33,8 @@ This must be a 1-bit port, for example::
|
||||
|
||||
<Port Location="XS1_PORT_1A" Name="PORT_SPDIF_IN"/>
|
||||
|
||||
When S/PDIF receive is enabled the codebase expects to drive a synchronisation signal to an external
|
||||
Cirrus Logic CS2100 device for master-clock generation.
|
||||
When S/PDIF receive is enabled the codebase expects to either drive a synchronisation signal to an external
|
||||
Cirrus Logic CS2100 device or use lib_swp_pll (xcore.ai only) for master-clock generation.
|
||||
|
||||
The programmer should ensure the define in :ref:`opt_spdif_rx_ref_defines` is set appropriately.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
S/PDIF Transmit
|
||||
~~~~~~~~~~~~~~~
|
||||
===============
|
||||
|
||||
The codebase supports a single, stereo, S/PDIF transmitter. This can be output over 75 Ω coaxial or optical fibre.
|
||||
In order to provide S/PDIF transmit functionality ``lib_xua`` uses ``lib_spdif`` (https://www.github.com/xmos/lib_spdif).
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
Strings and ID's
|
||||
~~~~~~~~~~~~~~~~
|
||||
================
|
||||
|
||||
The codebase includes various strings and ID's that should be customised to match the product requirements.
|
||||
These are listed in ::ref:`opt_strings_defines`.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|newpage|
|
||||
|
||||
Synchronisation
|
||||
~~~~~~~~~~~~~~~
|
||||
===============
|
||||
|
||||
The codebase supports "Synchronous" and "Asynchronous" modes for USB transfer as defined by the
|
||||
USB specification(s).
|
||||
@@ -39,8 +39,11 @@ Setting the synchronisation mode of the device is done using the define in :ref:
|
||||
- USB synchronisation mode
|
||||
- ``XUA_SYNCMODE_ASYNC``
|
||||
|
||||
When operating in synchronous mode an external Cirrus Logic CS2100 device is required for master clock
|
||||
generation. The codebase expects to drive a synchronisation signal to this external device
|
||||
When operating in synchronous mode a local master clock must be generated that is synchronised to the incoming
|
||||
SoF rate from USB. Either an external Cirrus Logic CS2100 device is required for this purpose
|
||||
or, on xcore.ai devices, the on-chip application PLL may be used via lib_sw_pll.
|
||||
In the case of using the CS2100, the codebase expects to drive a synchronisation signal to this external device
|
||||
as a reference.
|
||||
|
||||
The programmer should ensure the define in :ref:`opt_sync_ref_defines` is set appropriately.
|
||||
|
||||
@@ -56,8 +59,11 @@ The programmer should ensure the define in :ref:`opt_sync_ref_defines` is set ap
|
||||
* - ``PLL_REF_TILE``
|
||||
- Tile location of reference to CS2100 device
|
||||
- ``AUDIO_IO_TILE``
|
||||
* - ``XUA_USE_SW_PLL``
|
||||
- Whether or not to use sw_pll to recover the clock (xcore.ai only)
|
||||
- 1 for xcore.ai targets. May be overridden to 0 in ``xua_conf.h``
|
||||
|
||||
The codebase expects this reference signal port to be defined in the application XN file as ``PORT_PLL_REF``.
|
||||
The codebase expects the CS2100 reference signal port to be defined in the application XN file as ``PORT_PLL_REF``.
|
||||
This may be a port of any bit-width, however, connection to bit[0] is assumed::
|
||||
|
||||
<Port Location="XS1_PORT_1A" Name="PORT_PLL_REF"/>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
Overview
|
||||
--------
|
||||
|
||||
********
|
||||
|
||||
.. table::
|
||||
:class: vertical-borders
|
||||
@@ -26,7 +25,7 @@ Overview
|
||||
| +---------------------------------------------------------------------------------------------+
|
||||
| | `USB Midi Device Class 1.0 <http://www.usb.org/developers/devclass_docs/midi10.pdf>`_ |
|
||||
+---------------------------------+---------------------------------------------------------------------------------------------+
|
||||
| Audio | I2S/TDM |
|
||||
| Audio | I2S/TDM (16/32-bit) |
|
||||
| +---------------------------------------------------------------------------------------------+
|
||||
| | S/PDIF |
|
||||
| +---------------------------------------------------------------------------------------------+
|
||||
@@ -75,5 +74,3 @@ Overview
|
||||
| Reference code is maintained by XMOS Limited. |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
Implementation Detail
|
||||
---------------------
|
||||
*********************
|
||||
|
||||
This section examines the implementation of the various components that make up ``lib_xua``. It also examines the integration of dependencies and supporting libraries.
|
||||
This chapter examines the implementation of the various components that make up ``lib_xua``. It also examines the integration of dependencies and supporting libraries.
|
||||
|
||||
.. toctree::
|
||||
|
||||
@@ -10,8 +10,8 @@ This section examines the implementation of the various components that make up
|
||||
sw_ep0
|
||||
sw_xud
|
||||
sw_clocking
|
||||
sw_spdif
|
||||
sw_mixer
|
||||
sw_spdif
|
||||
sw_spdif_rx
|
||||
sw_adat_rx
|
||||
sw_midi
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
ADAT Receive
|
||||
------------
|
||||
============
|
||||
|
||||
The ADAT receive component receives up to eight channels of audio at a sample rate
|
||||
of 44.1kHz or 48kHz. The API for calling the receiver functions is
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
.. _usb_audio_sec_audio:
|
||||
|
||||
Audio Hub
|
||||
.........
|
||||
=========
|
||||
|
||||
The Audio Hub task performs many functions. It receives and transmits samples from/to the Decoupler
|
||||
or Mixer core over a channel.
|
||||
@@ -96,9 +96,8 @@ Two master clock frequencies to support 44.1kHz and 48kHz audio frequencies (e.g
|
||||
and 12.288/24.576MHz respectively). This master clock input is then provided to the external audio
|
||||
hardware and the xCORE device.
|
||||
|
||||
|
||||
Port Configuration (xCORE Master)
|
||||
+++++++++++++++++++++++++++++++++
|
||||
---------------------------------
|
||||
|
||||
The default software configuration is xCORE is I2S master. That is, the XMOS device provides the BCLK and LRCLK signals to the external audio hardware
|
||||
|
||||
@@ -143,7 +142,7 @@ before the data (as required by the I2S standard) and alternates between high an
|
||||
and right channels of audio.
|
||||
|
||||
Changing Audio Sample Frequency
|
||||
+++++++++++++++++++++++++++++++
|
||||
-------------------------------
|
||||
|
||||
.. _usb_audio_sec_chang-audio-sample:
|
||||
|
||||
@@ -159,5 +158,3 @@ functions.
|
||||
|
||||
Once this is complete, the I2S/TDM interface (i.e. the main loop in AudioHub) is restarted at the new frequency.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
.. _usb_audio_sec_clock_recovery:
|
||||
|
||||
External Clock Recovery (Clock Gen)
|
||||
-----------------------------------
|
||||
===================================
|
||||
|
||||
To provide an audio master clock an application may use selectable oscillators, clock
|
||||
generation IC or, in the case of xCORE.ai devices, integrated secondary PLL, to generate fixed
|
||||
@@ -14,33 +14,36 @@ It may also use an external PLL/Clock Multiplier to generate a master clock base
|
||||
the xCORE.
|
||||
|
||||
Using an external PLL/Clock Multiplier allows an Asynchronous mode design to lock to an external
|
||||
clock source from a digital stream (e.g. S/PDIF or ADAT input). The code-base supports the Cirrus
|
||||
Logic CS2100 device for this purpose. Other devices may be supported via code modification.
|
||||
clock source from a digital stream (e.g. S/PDIF or ADAT input). The codebase supports the Cirrus
|
||||
Logic CS2100 device or use of lib_sw_pll (xcore.ai only) for this purpose. Other devices may be
|
||||
supported via code modification.
|
||||
|
||||
.. note::
|
||||
|
||||
It is expected that in a future release the secondary PLL in xCORE.ai devices, coupled with
|
||||
associated software changes, will be capable of replacing the CS2100 part for most designs.
|
||||
The Clock Recovery core (Clock Gen) is responsible for either generating the reference frequency
|
||||
to the CS2100 device or driving lib_sw_pll from time measurements based on the local master clock
|
||||
and the time of received samples. Clock Gen (via CS2100 or lib_sw_pll) generates the master clock
|
||||
used over the whole design. This core also serves as a smaller buffer between ADAT and S/PDIF
|
||||
receiving cores and the Audio Hub core.
|
||||
|
||||
The Clock Recovery core (Clock Gen) is responsible for generating the reference frequency
|
||||
to the CS2100 device. This, in turn, generates the master clock used over the whole design.
|
||||
This core also serves as a smaller buffer between ADAT and S/PDIF receiving cores and the Audio Hub
|
||||
core.
|
||||
When using lib_sw_pll (xcore.ai only) an further core is instantiated which performs the sigma-delta
|
||||
modulation of the xCORE PLL to ensure the lowest jitter over the audio band. See lib_sw_pll
|
||||
documentation for further details.
|
||||
|
||||
When running in *Internal Clock* mode this core simply generates this clock using a local
|
||||
timer, based on the XMOS reference clock.
|
||||
|
||||
When running in an external clock mode (i.e. S/PDIF Clock" or "ADAT Clock" mode) samples are
|
||||
received from the S/PDIF and/or ADAT receive core. The external frequency is calculated through
|
||||
counting samples in a given period. The reference clock to the CS2100 is then generated based on
|
||||
the reception of these samples.
|
||||
received from the S/PDIF and/or ADAT receive core. The external frequency is calculated through
|
||||
counting samples in a given period. Either the reference clock to the CS2100 is then generated based on
|
||||
the reception of these samples or the timing information is provided to lib_sw_pll to generate
|
||||
the phase-locked clock on-chip (xcore.ai only).
|
||||
|
||||
If an external stream becomes invalid, the *Internal Clock* timer event will fire to ensure that
|
||||
valid master clock generation continues regardless of cable unplugs etc. Efforts are made to
|
||||
ensure the transition between these clocks are relatively seamless. Additionally efforts are also
|
||||
made to try and keep the jitter on the reference clock as low as possibly, regardless of activity
|
||||
made to try and keep the jitter on the reference clock as low as possible, regardless of activity
|
||||
level of the Clock Gen core. The is achieved though the use of port times to schedule pin toggling
|
||||
rather than directly outputting to the port.
|
||||
rather than directly outputting to the port in the case of using the CS2100. For lib_sw_pll cases the
|
||||
last setting is kept for the sigma-delta modulator ensuring clock continuity.
|
||||
|
||||
The Clock Gen core gets clock selection Get/Set commands from Endpoint 0 via the ``c_clk_ctl``
|
||||
channel. This core also records the validity of external clocks, which is also queried
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
.. _usb_audio_sec_usb:
|
||||
|
||||
Endpoint 0: Management and Control
|
||||
..................................
|
||||
==================================
|
||||
|
||||
All USB devices must support a mandatory control endpoint, Endpoint 0. This controls the management tasks of the USB device.
|
||||
|
||||
These tasks can be generally split into enumeration, audio configuration and firmware upgrade requests.
|
||||
|
||||
Enumeration
|
||||
~~~~~~~~~~~
|
||||
-----------
|
||||
|
||||
When the device is first attached to a host, enumeration occurs. This process involves the host interrogating the device as to its functionality. The device does this by presenting several interfaces to the host via a set of descriptors.
|
||||
|
||||
@@ -41,12 +41,13 @@ The function may also return ``XUD_RES_RST`` if a bus-reset has been issued onto
|
||||
Since the ``USB_StandardRequests()`` function STALLs an unknown request, the endpoint 0 code must first parse the ``USB_SetupPacket_t`` structure to handle device specific requests and then call ``USB_StandardRequests()`` as required.
|
||||
|
||||
Over-riding Standard Requests
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
-----------------------------
|
||||
|
||||
The USB Audio design "over-rides" some of the requests handled by ``USB_StandardRequests()``, for example it uses the SET_INTERFACE request to indicate if the host is streaming audio to the device. In this case the setup packet is parsed, the relevant action taken, the ``USB_StandardRequests()`` is still called to handle the response to the host.
|
||||
|
||||
Class Requests
|
||||
~~~~~~~~~~~~~~
|
||||
--------------
|
||||
|
||||
Before making the call to ``USB_StandardRequests()`` the setup packet is parsed for Class requests. These are handled in functions such as ``AudioClassRequests_1()``, ``AudioClassRequests_2``, ``DFUDeviceRequests()`` etc depending on the type of request.
|
||||
|
||||
Any device specific requests are handled - in this case Audio Class, MIDI class, DFU requests etc.
|
||||
@@ -54,7 +55,7 @@ Any device specific requests are handled - in this case Audio Class, MIDI class,
|
||||
Some of the common Audio Class requests and their associated behaviour will now be examined.
|
||||
|
||||
Audio Requests
|
||||
++++++++++++++
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
When the host issues an audio request (e.g. sample rate or volume change), it sends a command to Endpoint 0. Like all requests this is returned from ``USB_GetSetupPacket()``. After some parsing (namely as Class Request to an Audio Interface) the request is handled by either the ``AudioClassRequests_1()`` or ``AudioClassRequests_2()`` function (based on whether the device is running in Audio Class 1.0 or 2.0 mode).
|
||||
|
||||
@@ -63,7 +64,7 @@ Note, Audio Class 1.0 Sample rate changes are send to the relevant endpoint, rat
|
||||
The ``AudioClassRequests_X()`` functions further parses the request in order to ascertain the correct audio operation to execute.
|
||||
|
||||
Audio Request: Set Sample Rate
|
||||
++++++++++++++++++++++++++++++
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The ``AudioClassRequests_2()`` function parses the passed ``USB_SetupPacket_t`` structure for a ``CUR`` request of type ``SAM_FREQ_CONTROL`` to a Clock Unit in the devices topology (as described in the devices descriptors).
|
||||
|
||||
@@ -72,7 +73,7 @@ The new sample frequency is extracted and passed via channel to the rest of the
|
||||
.. _usb_audio_sec_audio-requ-volume:
|
||||
|
||||
Audio Request: Volume Control
|
||||
+++++++++++++++++++++++++++++
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
When the host requests a volume change, it
|
||||
sends an audio interface request to Endpoint 0. An array is
|
||||
@@ -102,10 +103,10 @@ to the mixer to change the volume. Mixer commands
|
||||
are described in :ref:`usb_audio_sec_mixer`.
|
||||
|
||||
Audio Endpoints (Endpoint Buffer and Decoupler)
|
||||
...............................................
|
||||
===============================================
|
||||
|
||||
Endpoint Buffer
|
||||
~~~~~~~~~~~~~~~
|
||||
---------------
|
||||
|
||||
All endpoints other that Endpoint 0 are handled in one core. This
|
||||
core is implemented in the file ``ep_buffer.xc``. This core communicates directly with the XUD library.
|
||||
@@ -114,7 +115,7 @@ The USB buffer core is also responsible for feedback calculation based on USB St
|
||||
(SOF) notification and reads from the port counter of a port connected to the master clock.
|
||||
|
||||
Decouple
|
||||
~~~~~~~~
|
||||
--------
|
||||
|
||||
The decoupler supplies the USB buffering core with buffers to
|
||||
transmit/receive audio data to/from the host. It marshals these buffers into
|
||||
@@ -125,7 +126,7 @@ matching the audio rate to the USB packet rate). The decoupler is
|
||||
implemented in the file ``decouple.xc``.
|
||||
|
||||
Audio Buffering Scheme
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
----------------------
|
||||
|
||||
This scheme is executed by co-operation between the buffering
|
||||
core, the decouple core and the XUD library.
|
||||
@@ -133,7 +134,6 @@ core, the decouple core and the XUD library.
|
||||
For data going from the device to the host the following scheme is
|
||||
used:
|
||||
|
||||
|
||||
#. The Decouple core receives samples from the Audio Hub core and
|
||||
puts them into a FIFO. This FIFO is split into packets when data is
|
||||
entered into it. Packets are stored in a format consisting of their
|
||||
@@ -152,11 +152,9 @@ used:
|
||||
Decouple core that the buffer has been sent and the Decouple core
|
||||
moves the read pointer of the FIFO.
|
||||
|
||||
|
||||
For data going from the host to the device the following scheme is
|
||||
used:
|
||||
|
||||
|
||||
#. The Decouple core passes a pointer to the Endpoint Buffer core
|
||||
pointing into a FIFO of data and signals to the XUD library that
|
||||
the Endpoint Buffer core is ready to receive.
|
||||
@@ -171,9 +169,8 @@ used:
|
||||
#. Upon request from the Audio Hub core, the Decouple core sends
|
||||
samples to the Audio Hub core by reading samples out of the FIFO.
|
||||
|
||||
|
||||
Decoupler/Audio Core interaction
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
--------------------------------
|
||||
|
||||
To meet timing requirements of the audio system (i.e Audio Hub/Mixer), the Decoupler
|
||||
core must respond to requests from the audio system to
|
||||
@@ -200,7 +197,6 @@ in channel count sized chunks (i.e. ``NUM_USB_CHAN_OUT`` and
|
||||
The complete communication scheme is shown in the table below (for non sample
|
||||
frequency change case):
|
||||
|
||||
|
||||
.. table:: Decouple/Audio System Channel Communication
|
||||
|
||||
+-----------------+-----------------+-----------------------------------------+
|
||||
@@ -242,7 +238,7 @@ frequency change case):
|
||||
(this is especially advantageous in the DSD over PCM (DoP) case)
|
||||
|
||||
Asynchronous Feedback
|
||||
+++++++++++++++++++++
|
||||
---------------------
|
||||
|
||||
When built to operate in Asynchronous mode the device uses a feedback endpoint to report the rate at which
|
||||
audio is output/input to/from external audio interfaces/devices. This feedback is in accordance with
|
||||
@@ -265,7 +261,7 @@ sent to the host. In practice this an explicit feedback endpoint is normally use
|
||||
in Microsoft Windows operating systems (see ``UAC_FORCE_FEEDBACK_EP``).
|
||||
|
||||
USB Rate Control
|
||||
++++++++++++++++
|
||||
----------------
|
||||
|
||||
.. _usb_audio_sec_usb-rate-control:
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Audio Controls via Human Interface Device (HID)
|
||||
------------------------------------------------
|
||||
===============================================
|
||||
|
||||
The design supports simple audio controls such as play/pause, volume up/down etc via the USB Human
|
||||
Interface Device Class Specification.
|
||||
|
||||
@@ -1,13 +1,28 @@
|
||||
|newpage|
|
||||
|
||||
MIDI
|
||||
----
|
||||
====
|
||||
|
||||
The MIDI core implements a 31250 baud UART for both input and output. On receiving 32-bit USB MIDI events
|
||||
from the Endpoint Buffer core, it parses these and translates them to 8-bit MIDI messages which are sent
|
||||
over UART. Similarly, incoming 8-bit MIDI messages are aggregated into 32-bit USB-MIDI events and
|
||||
passed on to the Endpoint Buffer core. The MIDI core is implemented in the file ``usb_midi.xc``.
|
||||
The MIDI core implements a 31250 baud UART (8-N-1) for both input and output. It uses a single dedicated thread which performs multiple functions:
|
||||
|
||||
- UART Tx peripheral.
|
||||
- UART Tx FIFO of 1024 bytes (may be configured by the user).
|
||||
- Decoding of USB MIDI message to bytes.
|
||||
- UART Rx peripheral.
|
||||
- Packing of received MIDI bytes into USB MIDI messages/events.
|
||||
|
||||
It is connected via a channel to the Endpoint Buffer core meaning that it can be placed on any XCORE tile in the system subject to resource availability. The channel uses an optimised low level protocol meaning that it always occupies a switch path.
|
||||
|
||||
The Endpoint Buffer core implements the two Bulk endpoints (one In and one Out) as well as interacting with small, shared-memory, FIFOs for each endpoint.
|
||||
|
||||
On receiving 32-bit USB MIDI events from the Endpoint Buffer core over the channel, the MIDI core parses these and translates them to 8-bit MIDI messages which are sent
|
||||
out over the UART. Up to 1024 bytes may be buffered by the MIDI task for outgoing messages in the default configuration. If the outgoing buffer is full then it will cause the USB endpoint to be NACKed which provides flow control in the case that the host application sends messages faster than the UART can transmit them. This is important because the USB bandwidth far exceeds the MIDI UART bandwidth by many orders of magnitude. The combination of buffering and flow control ensures outgoing messages are not dropped during normal operation.
|
||||
|
||||
Incoming 8-bit MIDI messages from the UART receiver are packed into 32-bit USB MIDI events and passed on to the Endpoint Buffer core. Since the rate of ingress
|
||||
to the MIDI port is tiny in comparison to the host USB bandwidth, no buffering is required in the MIDI core and the MIDI events are always forwarded on directly to USB immediately.
|
||||
|
||||
All MIDI message types are supported including `Sysex` (MIDI System Exclusive) strings allowing custom function such as bank updates and patches, backup and device firmware upgrade (DFU) where supported by the MIDI device.
|
||||
|
||||
The MIDI core is implemented in the file ``usb_midi.xc`` and the USB buffering is handled in the file ``ep_buffer.xc``.
|
||||
|
||||
The Endpoint Buffer core implements the two Bulk endpoints (one In and one Out) as well as interacting
|
||||
with small, shared-memory, FIFOs for each endpoint.
|
||||
|
||||
|
||||
@@ -87,6 +87,9 @@ intended as an example of how you might add mixer control to your own control ap
|
||||
intended to be exposed to end users.
|
||||
|
||||
For details, consult the README file in the host_usb_mixer_control directory.
|
||||
A list of arguments can also be seen with::
|
||||
|
||||
$ ./xmos_mixer --help
|
||||
|
||||
The main requirements of this control utility are to
|
||||
|
||||
@@ -102,78 +105,147 @@ The main requirements of this control utility are to
|
||||
functionality to their end users.
|
||||
|
||||
Whilst using the XMOS Host control example application, consider the example of setting the
|
||||
mixer to perform a loop-back from analogue inputs 1 and 2 to analogue outputs 1 and 2.
|
||||
mixer to perform a loop-back from analogue inputs 1 & 2 to analogue outputs 1 & 2.
|
||||
|
||||
Firstly consider the inputs to the mixer. The following will displays which channels are mapped
|
||||
to which mixer inputs::
|
||||
.. note::
|
||||
|
||||
./xmos_mixer --display-aud-channel-map 0
|
||||
The command outputs shown are examples; the actual output will depend on the mixer configuration.
|
||||
|
||||
The following command will displays which channels could possibly be mapped to mixer inputs. Notice
|
||||
that analogue inputs 1 and 2 are on mixer inputs 10 and 11::
|
||||
The following will show the index for each device output along with which channel is currently mapped to it.
|
||||
In this example the analogue outputs 1 & 2 are 0 & 1 respectively::
|
||||
|
||||
./xmos_mixer --display-aud-channel-map-sources 0
|
||||
$ ./xmos_mixer --display-aud-channel-map
|
||||
|
||||
Now examine the audio output mapping using the following command::
|
||||
Audio Output Channel Map
|
||||
------------------------
|
||||
|
||||
0 (DEVICE OUT - Analogue 1) source is 0 (DAW OUT - Analogue 1)
|
||||
1 (DEVICE OUT - Analogue 2) source is 1 (DAW OUT - Analogue 2)
|
||||
2 (DEVICE OUT - SPDIF 1) source is 2 (DAW OUT - SPDIF 1)
|
||||
3 (DEVICE OUT - SPDIF 2) source is 3 (DAW OUT - SPDIF 2)
|
||||
$ _
|
||||
|
||||
./xmos_mixer --display-aud-channel-map 0
|
||||
The DAW Output Map can be seen with::
|
||||
|
||||
This displays which channels are mapped to which outputs. By default all
|
||||
of these bypass the mixer. We can also see what all the possible
|
||||
mappings are with the following command::
|
||||
$ ./xmos_mixer --display-daw-channel-map
|
||||
|
||||
./xmos_mixer --display-aud-channel-map-sources 0
|
||||
DAW Output To Host Channel Map
|
||||
------------------------
|
||||
|
||||
0 (DEVICE IN - Analogue 1) source is 4 (DEVICE IN - Analogue 1)
|
||||
1 (DEVICE IN - Analogue 2) source is 5 (DEVICE IN - Analogue 2)
|
||||
$ _
|
||||
|
||||
We will now map the first two mixer outputs to physical outputs 1 and 2::
|
||||
.. note::
|
||||
|
||||
./xmos_mixer --set-aud-channel-map 0 26
|
||||
./xmos_mixer --set-aud-channel-map 1 27
|
||||
In both cases, by default, these bypass the mixer.
|
||||
|
||||
The following command will list the channels which can be mapped to the device outputs from the
|
||||
Audio Output Channel Map. Note that, in this example, analogue inputs 1 & 2 are source 4 & 5 and
|
||||
Mix 1 & 2 are source 6 & 7::
|
||||
|
||||
$ ./xmos_mixer --display-aud-channel-map-sources
|
||||
|
||||
Audio Output Channel Map Source List
|
||||
------------------------------------
|
||||
|
||||
0 (DAW OUT - Analogue 1)
|
||||
1 (DAW OUT - Analogue 2)
|
||||
2 (DAW OUT - SPDIF 1)
|
||||
3 (DAW OUT - SPDIF 2)
|
||||
4 (DEVICE IN - Analogue 1)
|
||||
5 (DEVICE IN - Analogue 2)
|
||||
6 (MIX - Mix 1)
|
||||
7 (MIX - Mix 2)
|
||||
$ _
|
||||
|
||||
Using the indices from the previous commands, we will now re-map the first two mixer channels (Mix 1 & Mix 2) to device outputs 1 & 2::
|
||||
|
||||
$ ./xmos_mixer --set-aud-channel-map 0 6
|
||||
$ ./xmos_mixer --set-aud-channel-map 1 7
|
||||
$ _
|
||||
|
||||
You can confirm the effect of this by re-checking the map::
|
||||
|
||||
./xmos_mixer --display-aud-channel-map 0
|
||||
$ ./xmos_mixer --display-aud-channel-map
|
||||
|
||||
This now derives analogue outputs 1 and 2 from the mixer, rather than directly from USB. However,
|
||||
since the mixer is still mapped to pass the USB channels through to the outputs there will be no
|
||||
Audio Output Channel Map
|
||||
------------------------
|
||||
|
||||
0 (DEVICE OUT - Analogue 1) source is 6 (MIX - Mix 1)
|
||||
1 (DEVICE OUT - Analogue 2) source is 7 (MIX - Mix 2)
|
||||
2 (DEVICE OUT - SPDIF 1) source is 2 (DAW OUT - SPDIF 1)
|
||||
3 (DEVICE OUT - SPDIF 2) source is 3 (DAW OUT - SPDIF 2)
|
||||
$ _
|
||||
|
||||
This now derives analogue outputs 1 & 2 from the mixer, rather than directly from USB. However,
|
||||
since the mixer is mapped, by default, to just pass the USB channels through to the outputs there will be no
|
||||
functional change.
|
||||
|
||||
The mixer nodes need to be individually set. They can be displayed
|
||||
|
||||
.. note::
|
||||
|
||||
The USB audio reference design has only one unit so the mixer_id argument should always be 0.
|
||||
|
||||
The mixer nodes need to be individually set. The nodes in mixer_id 0 can be displayed
|
||||
with the following command::
|
||||
|
||||
./xmos_mixer --display-mixer-nodes 0
|
||||
$ ./xmos_mixer --display-mixer-nodes 0
|
||||
|
||||
To get the audio from the analogue inputs to outputs 1 and 2, nodes 80
|
||||
and 89 need to be set::
|
||||
Mixer Values (0)
|
||||
----------------
|
||||
|
||||
./xmos_mixer --set-value 0 80 0
|
||||
./xmos_mixer --set-value 0 89 0
|
||||
Mixer outputs
|
||||
1 2
|
||||
DAW - Analogue 1 0:[0000.000] 1:[ -inf ]
|
||||
DAW - Analogue 2 2:[ -inf ] 3:[0000.000]
|
||||
DAW - SPDIF 1 4:[ -inf ] 5:[ -inf ]
|
||||
DAW - SPDIF 2 6:[ -inf ] 7:[ -inf ]
|
||||
AUD - Analogue 1 8:[ -inf ] 9:[ -inf ]
|
||||
AUD - Analogue 2 10:[ -inf ] 11:[ -inf ]
|
||||
$ _
|
||||
|
||||
With mixer outputs 1 & 2 mapped to device outputs analogue 1 & 2; to get the audio from the analogue inputs to device
|
||||
outputs mixer_id 0 node 8 and node 11 need to be set to 0db::
|
||||
|
||||
$ ./xmos_mixer --set-value 0 8 0
|
||||
$ ./xmos_mixer --set-value 0 11 0
|
||||
$ _
|
||||
|
||||
At the same time, the original mixer outputs can be muted::
|
||||
|
||||
./xmos_mixer --set-value 0 0 -inf
|
||||
./xmos_mixer --set-value 0 9 -inf
|
||||
$ ./xmos_mixer --set-value 0 0 -inf
|
||||
$ ./xmos_mixer --set-value 0 3 -inf
|
||||
$ _
|
||||
|
||||
Now audio inputs on analogue 1/2 should be heard on outputs 1/2.
|
||||
Now audio inputs on analogue 1 and 2 should be heard on outputs 1 and 2 respectively.
|
||||
|
||||
As mentioned above, the flexibility of the mixer is such that there will be multiple ways to create
|
||||
a particular mix. Another option to create the same routing would be to change the mixer sources
|
||||
such that mixer 1/2 outputs come from the analogue inputs.
|
||||
such that mixer outputs 1 and 2 come from the analogue inputs 1 and 2.
|
||||
|
||||
To demonstrate this, firstly undo the changes above (or simply reset the device)::
|
||||
|
||||
./xmos_mixer --set-value 0 80 -inf
|
||||
./xmos_mixer --set-value 0 89 -inf
|
||||
./xmos_mixer --set-value 0 0 0
|
||||
./xmos_mixer --set-value 0 9 0
|
||||
$ ./xmos_mixer --set-value 0 8 -inf
|
||||
$ ./xmos_mixer --set-value 0 11 -inf
|
||||
$ ./xmos_mixer --set-value 0 0 0
|
||||
$ ./xmos_mixer --set-value 0 3 0
|
||||
$ _
|
||||
|
||||
The mixer should now have the default values. The sources for mixer 1/2 can now be changed::
|
||||
The mixer should now have the default values. The sources for mixer 0 output 1 and 2 can now be changed
|
||||
using indices from the Audio Output Channel Map Source List::
|
||||
|
||||
./xmos_mixer --set-mixer-source 0 0 10
|
||||
./xmos_mixer --set-mixer-source 0 1 11
|
||||
$ ./xmos_mixer --set-mixer-source 0 0 4
|
||||
|
||||
Set mixer(0) input 0 to device input 4 (AUD - Analogue 1)
|
||||
$ ./xmos_mixer --set-mixer-source 0 1 5
|
||||
|
||||
Set mixer(0) input 1 to device input 5 (AUD - Analogue 2)
|
||||
$ _
|
||||
|
||||
If you re-run the following command then the first column now has "AUD - Analogue 1 and 2" rather
|
||||
than "DAW (Digital Audio Workstation i.e. the host) - Analogue 1 and 2" confirming the new mapping.
|
||||
Again, by playing audio into analogue inputs 1/2 this can be heard looped through to analogue outputs 1/2::
|
||||
|
||||
./xmos_mixer --display-mixer-nodes 0
|
||||
$ ./xmos_mixer --display-mixer-nodes 0
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
PDM Microphones
|
||||
---------------
|
||||
===============
|
||||
|
||||
The XMOS USB Audio Reference Design firmware is capable of integrating with PDM microphones.
|
||||
The PDM stream from the microphones is converted to PCM and output to the host via USB.
|
||||
@@ -46,9 +46,8 @@ After the decimation to the output sample-rate various other steps take place e.
|
||||
and compensation etc. Please refer to the documentation provided with ``lib_mic_array`` for further
|
||||
implementation detail and complete feature set.
|
||||
|
||||
|
||||
PDM Microphone Hardware Characteristics
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
---------------------------------------
|
||||
|
||||
The PDM microphones require a *clock input* and provide the PDM signal on a *data output*. All of
|
||||
the PDM microphones must share the same clock signal (buffered on the PCB as appropriate), and
|
||||
@@ -78,7 +77,7 @@ divide down 12.288 MHz master clock. Or, if clock accuracy is not important, the
|
||||
reference can be divided down to provide an approximate clock.
|
||||
|
||||
Usage & Integration
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
-------------------
|
||||
|
||||
A PDM microphone wrapper is called from ``main()`` and takes one channel argument connecting it to the rest of the system:
|
||||
|
||||
@@ -113,3 +112,4 @@ sends the frame of audio back over this channel.
|
||||
|
||||
Note, it is assumed that the system shares a global master-clock, therefore no additional buffering or rate-matching/conversion
|
||||
is required.
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
.. _usb_audio_sec_resource_usage:
|
||||
|
||||
Resource Usage
|
||||
--------------
|
||||
==============
|
||||
|
||||
The following table details the resource usage of each component of the reference design software.
|
||||
Note, memory usage is approximate and varies based on device used, compiler settings etc.
|
||||
@@ -50,3 +50,4 @@ Note, memory usage is approximate and varies based on device used, compiler sett
|
||||
|
||||
Unlike other interfaces, since the USB PHY is internal the USB ports are a fixed set of ports
|
||||
and cannot be modified. See ``lib_xud`` documentation for full details.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|newpage|
|
||||
|
||||
S/PDIF Transmit
|
||||
...............
|
||||
===============
|
||||
|
||||
``lib_xua`` supports the development of devices with S/PDIF transmit throught the use of ``lib_spdif``.
|
||||
The XMOS S/SPDIF transmitter component runs in a single core and supports sample-rates upto 192kHz.
|
||||
@@ -21,7 +21,7 @@ bits) and transmitted in biphase-mark encoding (BMC) with respect to an *externa
|
||||
Note that a minor change to the ``SpdifTransmitPortConfig`` function would enable *internal* master
|
||||
clock generation (e.g. when clock source is already locked to desired audio clock).
|
||||
|
||||
.. list-table:: S/PDIF Capabilities
|
||||
.. list-table:: S/PDIF Capabilities
|
||||
|
||||
* - **Sample frequencies**
|
||||
- 44.1, 48, 88.2, 96, 176.4, 192 kHz
|
||||
@@ -31,7 +31,7 @@ clock generation (e.g. when clock source is already locked to desired audio cloc
|
||||
- ``lib_spdif``
|
||||
|
||||
Clocking
|
||||
++++++++
|
||||
--------
|
||||
|
||||
.. only:: latex
|
||||
|
||||
@@ -54,7 +54,7 @@ This resamples the master clock to its clock domain (oscillator), which introduc
|
||||
A typical jitter-reduction scheme is an external D-type flip-flop clocked from the master clock (as shown in the preceding diagram).
|
||||
|
||||
Usage
|
||||
+++++
|
||||
-----
|
||||
|
||||
The interface to the S/PDIF transmitter core is via a normal channel with streaming built-ins
|
||||
(``outuint``, ``inuint``). Data format should be 24-bit left-aligned in a 32-bit word: ``0x12345600``
|
||||
@@ -84,9 +84,8 @@ The following protocol is used on the channel:
|
||||
|
||||
This communication is wrapped up in the API functions provided by ``lib_spdif``.
|
||||
|
||||
|
||||
Output stream structure
|
||||
+++++++++++++++++++++++
|
||||
Output Stream Structure
|
||||
-----------------------
|
||||
|
||||
The stream is composed of words with the following structure shown in
|
||||
:ref:`usb_audio_spdif_stream_structure`. The channel status bits are
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
S/PDIF Receive
|
||||
---------------
|
||||
==============
|
||||
|
||||
XMOS devices can support S/PDIF receive up to 192kHz - see ``lib_spdif`` for full specifications.
|
||||
|
||||
@@ -45,7 +45,7 @@ The tag has one of three values:
|
||||
See S/PDIF, IEC 60958-3:2006, specification for further details on format, user bits etc.
|
||||
|
||||
Usage and Integration
|
||||
+++++++++++++++++++++
|
||||
---------------------
|
||||
|
||||
Since S/PDIF is a digital steam the devices master clock must be synchronised to it. This is typically
|
||||
done with an external device. See `Clock Recovery` (:ref:`usb_audio_sec_clock_recovery`).
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|newpage|
|
||||
|
||||
XMOS USB Device (XUD) Library
|
||||
.............................
|
||||
=============================
|
||||
|
||||
All low level communication with the USB host is handled by the XMOS USB Device (XUD) library - `lib_xud`
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
|
||||
Basic Usage
|
||||
-----------
|
||||
***********
|
||||
|
||||
This sections describes the basic usage of `lib_xua` and provides a guide on how to program USB Audio Devices.
|
||||
|
||||
|
||||
Library Structure
|
||||
~~~~~~~~~~~~~~~~~
|
||||
=================
|
||||
|
||||
The code is split into several directories.
|
||||
|
||||
@@ -26,7 +26,7 @@ Note, the midi and dfu directories are potential candidates for separate libs in
|
||||
|
||||
|
||||
Using in a Project
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
==================
|
||||
|
||||
All `lib_xua` functions can be accessed via the ``xua.h`` header file::
|
||||
|
||||
@@ -39,7 +39,7 @@ It is also required to add ``lib_xua`` to the ``USED_MODULES`` field of your app
|
||||
.. _sec_basic_usage_codeless:
|
||||
|
||||
"Codeless" Programming Model
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
============================
|
||||
|
||||
Whilst it is possible to code a USB Audio device using the building blocks provided by `lib_xua`
|
||||
it is realised that this might not be desirable for many classes of customers or products.
|
||||
@@ -71,7 +71,7 @@ set ``EXCLUDE_USB_AUDIO_MAIN`` to 1 in the application makefile or ``xua_conf.h`
|
||||
::ref:`sec_advanced_usage`.
|
||||
|
||||
Configuring lib_xua
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
===================
|
||||
|
||||
Configuration of the various build time options of ``lib_xua`` is done via the optional header `xua_conf.h`.
|
||||
To allow the build scripts to locate this file it should reside somewhere in the application `src` directory.
|
||||
@@ -93,9 +93,8 @@ should continue to include `xua.h` as previously directed. A simple example is s
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
User Functions
|
||||
~~~~~~~~~~~~~~
|
||||
==============
|
||||
|
||||
To enable custom functionality, such as configuring external audio hardware, bespoke behaviour on
|
||||
stream start/stop etc, various functions can be overridden by the user. (see ::ref:`sec_api` for
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.. _sec_advanced_usage:
|
||||
|
||||
Advanced Usage
|
||||
--------------
|
||||
**************
|
||||
|
||||
Whilst it is possible to program USB Audio devices using ``lib_xua`` by only setting defines
|
||||
(see :ref:`sec_basic_usage_codeless`) some developers may want to code a USB Audio device from
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Running the Core Components
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
===========================
|
||||
|
||||
In their most basic form the core components can be run as follows::
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Core Hardware Resources
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
=======================
|
||||
|
||||
The user must declare and initialise relevant hardware resources (globally) and pass them to the
|
||||
relevant function of `lib_xua`.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|newpage|
|
||||
|
||||
I2S/TDM
|
||||
~~~~~~~
|
||||
=======
|
||||
|
||||
I2S/TDM is typically fundamental to most products and is built into the ``XUA_AudioHub()`` core.
|
||||
|
||||
In order to enable I2S on must declare an array of ports for the data-lines (one for each direction)::
|
||||
In order to enable I2S/TDM on must declare an array of ports for the data-lines (one for each direction)::
|
||||
|
||||
/* Port declarations. Note, the defines come from the XN file */
|
||||
buffered out port:32 p_i2s_dac[] = {PORT_I2S_DAC0}; /* I2S Data-line(s) */
|
||||
@@ -22,7 +22,7 @@ Ports for the sample and bit clocks are also required::
|
||||
|
||||
These ports must then be passed to the ``XUA_AudioHub()`` task appropriately.
|
||||
|
||||
I2S functionality also requires two clock-blocks, one for bit and sample clock e.g.::
|
||||
I2S/TDM functionality also requires two clock-blocks, one for bit-clock and another for the master clock e.g.::
|
||||
|
||||
/* Clock-block declarations */
|
||||
clock clk_audio_bclk = on tile[0]: XS1_CLKBLK_4; /* Bit clock */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|newpage|
|
||||
|
||||
Mixer
|
||||
~~~~~
|
||||
=====
|
||||
|
||||
Since the mixer has no I/O the instantiation is straight forward. Communication wises, the mixer cores are inserted
|
||||
between the `AudioHub` and Buffering core(s)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
XMOSNEWSTYLE = 2
|
||||
DOXYGEN_DIRS=../../api
|
||||
DOXYGEN_DIRS=../../api ../../src/core/user/audiostream ../../src/core/user/hostactive ../../src/core/user/hid ../../src/core/user/audiohw
|
||||
SOURCE_INCLUDE_DIRS=../../../lib_xua
|
||||
SPHINX_MASTER_DOC=lib_xua
|
||||
|
||||
|
||||
@@ -6,4 +6,4 @@
|
||||
|
||||
xmosdfu: xmosdfu.cpp
|
||||
mkdir -p bin
|
||||
g++ -D_GNU_SOURCE -Wall -g -o bin/xmosdfu -Ilibusb/Rasp -lusb-1.0 -x c xmosdfu.cpp -std=c99
|
||||
g++ -D_GNU_SOURCE -Wall -g -o bin/xmosdfu -Ilibusb/Rasp -x c xmosdfu.cpp -std=c99 -lusb-1.0
|
||||
|
||||
53
lib_xua/lib_build_info.cmake
Normal file
53
lib_xua/lib_build_info.cmake
Normal file
@@ -0,0 +1,53 @@
|
||||
set(LIB_NAME lib_xua)
|
||||
set(LIB_VERSION 4.1.0)
|
||||
set(LIB_INCLUDES api
|
||||
src/core
|
||||
src/core/audiohub
|
||||
src/core/buffer/ep
|
||||
src/core/endpoint0
|
||||
src/dfu
|
||||
src/core/buffer/decouple
|
||||
src/core/clocking
|
||||
src/core/mixer
|
||||
src/core/pdm_mics
|
||||
src/core/ports
|
||||
src/core/support
|
||||
src/core/user
|
||||
src/core/user/audiostream
|
||||
src/core/user/audiohw
|
||||
src/core/user/hid
|
||||
src/core/user/hostactive
|
||||
src/hid
|
||||
src/midi)
|
||||
set(LIB_OPTIONAL_HEADERS xua_conf.h static_hid_report.h)
|
||||
set(LIB_DEPENDENT_MODULES "lib_adat(1.2.0)"
|
||||
"lib_locks(2.2.0)"
|
||||
"lib_logging(3.2.0)"
|
||||
"lib_mic_array(4.6.0)"
|
||||
"lib_spdif(6.1.0)"
|
||||
"lib_sw_pll(2.2.0)"
|
||||
"lib_xassert(4.2.0)"
|
||||
"lib_xud(2.3.1)")
|
||||
|
||||
set(LIB_COMPILER_FLAGS -O3 -DREF_CLK_FREQ=100 -fasm-linenum -fcomment-asm)
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
list(APPEND LIB_COMPILER_FLAGS -DXASSERT_ENABLE_ASSERTIONS=1
|
||||
-DXASSERT_ENABLE_DEBUG=1
|
||||
-DXASSERT_ENBALE_LINE_NUMBERS=1)
|
||||
else()
|
||||
list(APPEND LIB_COMPILER_FLAGS -DXASSERT_ENABLE_ASSERTIONS=0
|
||||
-DXASSERT_ENABLE_DEBUG=0
|
||||
-DXASSERT_ENABLE_LINE_NUMBERS=0)
|
||||
endif()
|
||||
|
||||
set(LIB_COMPILER_FLAGS_xua_endpoint0.c ${LIB_COMPILER_FLAGS} -Os -mno-dual-issue)
|
||||
set(LIB_COMPILER_FLAGS_xua_ep0_uacreqs.xc ${LIB_COMPILER_FLAGS} -Os -mno-dual-issue)
|
||||
set(LIB_COMPILER_FLAGS_dbcalc.xc ${LIB_COMPILER_FLAGS} -Os -mno-dual-issue)
|
||||
set(LIB_COMPILER_FLAGS_audioports.c ${LIB_COMPILER_FLAGS} -Os -mno-dual-issue)
|
||||
set(LIB_COMPILER_FLAGS_audioports.xc ${LIB_COMPILER_FLAGS} -Os -mno-dual-issue)
|
||||
set(LIB_COMPILER_FLAGS_dfu.xc ${LIB_COMPILER_FLAGS} -Os -mno-dual-issue)
|
||||
set(LIB_COMPILER_FLAGS_flash_interface.c ${LIB_COMPILER_FLAGS} -Os -mno-dual-issue)
|
||||
set(LIB_COMPILER_FLAGS_flashlib_user.c ${LIB_COMPILER_FLAGS} -Os -mno-dual-issue)
|
||||
|
||||
XMOS_REGISTER_MODULE()
|
||||
@@ -1,20 +1,21 @@
|
||||
VERSION = 3.3.0
|
||||
VERSION = 4.1.0
|
||||
|
||||
DEBUG ?= 0
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
DEBUG_FLAGS = -g -DXASSERT_ENABLE_ASSERTIONS_DECOUPLE=1
|
||||
DEBUG_FLAGS = -g -DXASSERT_ENABLE_ASSERTIONS=1 -DXASSERT_ENABLE_DEBUG=1 -DXASSERT_ENABLE_LINE_NUMBERS=1
|
||||
else
|
||||
DEBUG_FLAGS = -DXASSERT_DISABLE_ASSERTIONS_DECOUPLE=1
|
||||
DEBUG_FLAGS = -DXASSERT_ENABLE_ASSERTIONS=0 -DXASSERT_ENABLE_DEBUG=0 -DXASSERT_ENABLE_LINE_NUMBERS=0
|
||||
endif
|
||||
|
||||
DEPENDENT_MODULES = lib_locks(>=2.1.0) \
|
||||
lib_logging(>=3.1.1) \
|
||||
lib_mic_array(>=4.5.0) \
|
||||
lib_spdif(>=4.1.0) \
|
||||
lib_xassert(>=4.1.0) \
|
||||
lib_xud(>=2.2.1) \
|
||||
lib_adat(>=1.0.0)
|
||||
DEPENDENT_MODULES = lib_adat(>=1.2.0) \
|
||||
lib_locks(>=2.2.0) \
|
||||
lib_logging(>=3.2.0) \
|
||||
lib_mic_array(>=4.6.0) \
|
||||
lib_spdif(>=6.1.0) \
|
||||
lib_sw_pll(>=2.2.0) \
|
||||
lib_xassert(>=4.2.0) \
|
||||
lib_xud(>=2.3.1)
|
||||
|
||||
MODULE_XCC_FLAGS = $(XCC_FLAGS) \
|
||||
-O3 \
|
||||
@@ -35,7 +36,7 @@ XCC_FLAGS_dfu.xc = $(MODULE_XCC_FLAGS) -Os -mno-dual-issue
|
||||
XCC_FLAGS_flash_interface.c = $(MODULE_XCC_FLAGS) -Os -mno-dual-issue
|
||||
XCC_FLAGS_flashlib_user.c = $(MODULE_XCC_FLAGS) -Os -mno-dual-issue
|
||||
|
||||
OPTIONAL_HEADERS += xua_conf.h
|
||||
OPTIONAL_HEADERS += xua_conf.h static_hid_report.h
|
||||
|
||||
EXPORT_INCLUDE_DIRS = api \
|
||||
src/core \
|
||||
@@ -53,6 +54,7 @@ INCLUDE_DIRS = $(EXPORT_INCLUDE_DIRS) \
|
||||
src/core/support \
|
||||
src/core/user \
|
||||
src/core/user/audiostream \
|
||||
src/core/user/audiohw \
|
||||
src/core/user/hid \
|
||||
src/core/user/hostactive \
|
||||
src/hid \
|
||||
@@ -69,6 +71,7 @@ SOURCE_DIRS = src/core \
|
||||
src/core/ports \
|
||||
src/core/support \
|
||||
src/core/user/audiostream \
|
||||
src/core/user/audiohw \
|
||||
src/core/user/hostactive \
|
||||
src/core/xuduser \
|
||||
src/dfu \
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Copyright 2018-2022 XMOS LIMITED.
|
||||
// Copyright 2018-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
unsigned adatCounter = 0;
|
||||
unsigned adatSamples[8];
|
||||
|
||||
#pragma unsafe arrays
|
||||
static inline void TransferAdatTxSamples(chanend c_adat_out, const unsigned samplesFromHost[], int smux, int handshake)
|
||||
{
|
||||
|
||||
/* Do some re-arranging for SMUX.. */
|
||||
unsafe
|
||||
{
|
||||
@@ -29,7 +27,6 @@ static inline void TransferAdatTxSamples(chanend c_adat_out, const unsigned samp
|
||||
|
||||
if(adatCounter == smux)
|
||||
{
|
||||
|
||||
#ifdef ADAT_TX_USE_SHARED_BUFF
|
||||
unsafe
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2018-2022 XMOS LIMITED.
|
||||
// Copyright 2018-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#if (DSD_CHANS_DAC != 0)
|
||||
@@ -52,7 +52,7 @@ static inline void DoDsdDop(int &everyOther, unsigned samplesOut[], unsigned &ds
|
||||
/* When DSD is enabled and streaming is standard PCM, this function checks for a series of DoP markers in the upper byte.
|
||||
If found it will exit deliver() with the command to restart in DoP mode.
|
||||
When in DoP mode, this function will check for a single absence of the DoP marker and exit deliver() with the command
|
||||
to restart in I2S mode. */
|
||||
to restart in I2S/PCM mode. */
|
||||
static inline int DoDsdDopCheck(unsigned &dsdMode, int &dsdCount, unsigned curSamFreq, unsigned samplesOut[], unsigned &dsdMarker)
|
||||
{
|
||||
/* Check for DSD - note we only move into DoP mode if valid DoP Freq */
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2018-2022 XMOS LIMITED.
|
||||
// Copyright 2018-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include "xua.h"
|
||||
|
||||
#include "dsd_support.h"
|
||||
|
||||
#if (DSD_CHANS_DAC != 0)
|
||||
@@ -12,7 +11,7 @@ extern buffered out port:32 p_dsd_clk;
|
||||
extern unsigned dsdMode;
|
||||
|
||||
#if !CODEC_MASTER
|
||||
void InitPorts_master(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC], buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC])
|
||||
void InitPorts_master(buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC], buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC])
|
||||
{
|
||||
#if (DSD_CHANS_DAC > 0)
|
||||
if(dsdMode == DSD_MODE_OFF)
|
||||
@@ -38,9 +37,13 @@ void InitPorts_master(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, bu
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma xta endpoint "divide_1"
|
||||
unsigned tmp;
|
||||
p_lrclk <: 0 @ tmp;
|
||||
|
||||
if(XUA_I2S_N_BITS == 32)
|
||||
p_lrclk <: 0 @ tmp;
|
||||
else
|
||||
tmp = partout_timestamped(p_lrclk, XUA_I2S_N_BITS, 0);
|
||||
|
||||
tmp += 100;
|
||||
|
||||
/* Since BCLK is free-running, setup outputs/inputs at a known point in the future */
|
||||
@@ -48,19 +51,30 @@ void InitPorts_master(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, bu
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < I2S_WIRES_DAC; i++)
|
||||
{
|
||||
p_i2s_dac[i] @ tmp <: 0;
|
||||
if(XUA_I2S_N_BITS == 32)
|
||||
p_i2s_dac[i] @ tmp <: 0;
|
||||
else
|
||||
partout_timed(p_i2s_dac[i], XUA_I2S_N_BITS, 0, tmp);
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned lrClkVal = 0x7FFFFFFF;
|
||||
if(XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
|
||||
p_lrclk @ tmp <: 0x80000000;
|
||||
{
|
||||
lrClkVal = 0x80000000;
|
||||
}
|
||||
|
||||
if(XUA_I2S_N_BITS == 32)
|
||||
p_lrclk @ tmp <: lrClkVal;
|
||||
else
|
||||
p_lrclk @ tmp <: 0x7FFFFFFF;
|
||||
partout_timed(p_lrclk, XUA_I2S_N_BITS, lrClkVal, tmp);
|
||||
|
||||
#if (I2S_CHANS_ADC != 0)
|
||||
for(int i = 0; i < I2S_WIRES_ADC; i++)
|
||||
{
|
||||
asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp-1));
|
||||
|
||||
if(XUA_I2S_N_BITS != 32)
|
||||
set_port_shift_count(p_i2s_adc[i], XUA_I2S_N_BITS);
|
||||
}
|
||||
#endif
|
||||
#endif /* (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) */
|
||||
@@ -76,7 +90,7 @@ void InitPorts_master(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, bu
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
void InitPorts_slave(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC], buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC])
|
||||
void InitPorts_slave(buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC], buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC])
|
||||
{
|
||||
#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0)
|
||||
unsigned tmp;
|
||||
@@ -93,7 +107,7 @@ void InitPorts_slave(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buf
|
||||
p_lrclk when pinseq(0) :> void @ tmp;
|
||||
#endif
|
||||
|
||||
tmp += (I2S_CHANS_PER_FRAME * 32) - 32 + 1 ;
|
||||
tmp += ((I2S_CHANS_PER_FRAME * XUA_I2S_N_BITS) - XUA_I2S_N_BITS + 1) ;
|
||||
/* E.g. 2 * 32 - 32 + 1 = 33 for stereo */
|
||||
/* E.g. 8 * 32 - 32 + 1 = 225 for 8 chan TDM */
|
||||
|
||||
@@ -101,7 +115,10 @@ void InitPorts_slave(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buf
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < I2S_WIRES_DAC; i++)
|
||||
{
|
||||
p_i2s_dac[i] @ tmp <: 0;
|
||||
if(XUA_I2S_N_BITS == 32)
|
||||
p_i2s_dac[i] @ tmp <: 0;
|
||||
else
|
||||
partout_timed(p_i2s_dac[i], XUA_I2S_N_BITS, 0, tmp);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -109,11 +126,15 @@ void InitPorts_slave(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buf
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < I2S_WIRES_ADC; i++)
|
||||
{
|
||||
asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp-1));
|
||||
asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp-1));
|
||||
if(XUA_I2S_N_BITS != 32)
|
||||
set_port_shift_count(p_i2s_adc[i], XUA_I2S_N_BITS);
|
||||
}
|
||||
#endif
|
||||
|
||||
asm("setpt res[%0], %1"::"r"(p_lrclk),"r"(tmp-1));
|
||||
if(XUA_I2S_N_BITS != 32)
|
||||
set_port_shift_count(p_lrclk, XUA_I2S_N_BITS);
|
||||
#endif /* (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0) */
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
/**
|
||||
* @file xua_audiohub.xc
|
||||
@@ -15,9 +15,12 @@
|
||||
#include <xclib.h>
|
||||
#include <xs1_su.h>
|
||||
#include <string.h>
|
||||
#include <xassert.h>
|
||||
|
||||
|
||||
#include "xua.h"
|
||||
|
||||
#include "audiohw.h"
|
||||
#include "audioports.h"
|
||||
#include "mic_array_conf.h"
|
||||
#if (XUA_SPDIF_TX_EN)
|
||||
@@ -43,25 +46,12 @@
|
||||
|
||||
#define MAX(x,y) ((x)>(y) ? (x) : (y))
|
||||
|
||||
static unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)];
|
||||
unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)];
|
||||
|
||||
/* Two buffers for ADC data to allow for DAC and ADC I2S ports being offset */
|
||||
#define IN_CHAN_COUNT (I2S_CHANS_ADC + XUA_NUM_PDM_MICS + (8*XUA_ADAT_RX_EN) + (2*XUA_SPDIF_RX_EN))
|
||||
|
||||
static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)];
|
||||
|
||||
#ifdef XTA_TIMING_AUDIO
|
||||
#pragma xta command "add exclusion received_command"
|
||||
#pragma xta command "analyse path i2s_output_l i2s_output_r"
|
||||
#pragma xta command "set required - 2000 ns"
|
||||
|
||||
#pragma xta command "add exclusion received_command"
|
||||
#pragma xta command "add exclusion received_underflow"
|
||||
#pragma xta command "add exclusion divide_1"
|
||||
#pragma xta command "add exclusion deliver_return"
|
||||
#pragma xta command "analyse path i2s_output_r i2s_output_l"
|
||||
#pragma xta command "set required - 2000 ns"
|
||||
#endif
|
||||
unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)];
|
||||
|
||||
#if (XUA_ADAT_TX_EN)
|
||||
extern buffered out port:32 p_adat_tx;
|
||||
@@ -76,7 +66,7 @@ void InitPorts_slave
|
||||
#else
|
||||
void InitPorts_master
|
||||
#endif
|
||||
(unsigned divide, buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC],
|
||||
(buffered _XUA_CLK_DIR port:32 p_lrclk, buffered _XUA_CLK_DIR port:32 p_bclk, buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC],
|
||||
buffered in port:32 (&?p_i2s_adc)[I2S_WIRES_ADC]);
|
||||
|
||||
|
||||
@@ -89,76 +79,24 @@ unsigned dsdMode = DSD_MODE_OFF;
|
||||
#if (XUA_ADAT_TX_EN)
|
||||
#include "audiohub_adat.h"
|
||||
#endif
|
||||
|
||||
#pragma unsafe arrays
|
||||
static inline unsigned DoSampleTransfer(chanend ?c_out, const int readBuffNo, const unsigned underflowWord)
|
||||
{
|
||||
if(XUA_USB_EN)
|
||||
{
|
||||
outuint(c_out, underflowWord);
|
||||
|
||||
/* Check for sample freq change (or other command) or new samples from mixer*/
|
||||
if(testct(c_out))
|
||||
{
|
||||
unsigned command = inct(c_out);
|
||||
#ifndef CODEC_MASTER
|
||||
if(dsdMode == DSD_MODE_OFF)
|
||||
{
|
||||
#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0)
|
||||
/* Set clocks low */
|
||||
p_lrclk <: 0;
|
||||
p_bclk <: 0;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if(DSD_CHANS_DAC != 0)
|
||||
/* DSD Clock might not be shared with lrclk or bclk... */
|
||||
p_dsd_clk <: 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if (DSD_CHANS_DAC > 0)
|
||||
if(dsdMode == DSD_MODE_DOP)
|
||||
dsdMode = DSD_MODE_OFF;
|
||||
#endif
|
||||
return command;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NUM_USB_CHAN_OUT > 0
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
|
||||
{
|
||||
int tmp = inuint(c_out);
|
||||
samplesOut[i] = tmp;
|
||||
}
|
||||
#else
|
||||
inuint(c_out);
|
||||
#endif
|
||||
UserBufferManagement(samplesOut, samplesIn[readBuffNo]);
|
||||
|
||||
#if NUM_USB_CHAN_IN > 0
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < NUM_USB_CHAN_IN; i++)
|
||||
{
|
||||
outuint(c_out, samplesIn[readBuffNo][i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
UserBufferManagement(samplesOut, samplesIn[readBuffNo]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include "xua_audiohub_st.h"
|
||||
|
||||
static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:32 p_lrclk)
|
||||
{
|
||||
#if CODEC_MASTER
|
||||
unsigned syncError = 0;
|
||||
unsigned lrval = 0;
|
||||
p_lrclk :> lrval;
|
||||
const unsigned lrval_mask = (0xffffffff << (32 - XUA_I2S_N_BITS));
|
||||
|
||||
if(XUA_I2S_N_BITS != 32)
|
||||
{
|
||||
asm volatile("in %0, res[%1]":"=r"(lrval):"r"(p_lrclk):"memory");
|
||||
set_port_shift_count(p_lrclk, XUA_I2S_N_BITS);
|
||||
}
|
||||
else
|
||||
{
|
||||
p_lrclk :> lrval;
|
||||
}
|
||||
|
||||
if(XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
|
||||
{
|
||||
@@ -176,30 +114,46 @@ static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:3
|
||||
}
|
||||
else
|
||||
{
|
||||
if(frameCount == 0)
|
||||
syncError += (lrval != 0x80000000);
|
||||
if(XUA_I2S_N_BITS == 32)
|
||||
{
|
||||
if(frameCount == 0)
|
||||
syncError = (lrval != 0x80000000);
|
||||
else
|
||||
syncError = (lrval != 0x7FFFFFFF);
|
||||
}
|
||||
else
|
||||
syncError += (lrval != 0x7FFFFFFF);
|
||||
{
|
||||
if(frameCount == 0)
|
||||
syncError = ((lrval & lrval_mask) != 0x80000000);
|
||||
else
|
||||
syncError = ((lrval | (~lrval_mask)) != 0x7FFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
return syncError;
|
||||
|
||||
#else
|
||||
unsigned clkVal;
|
||||
if(XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
|
||||
{
|
||||
if(frameCount == (I2S_CHANS_PER_FRAME-1))
|
||||
p_lrclk <: 0x80000000;
|
||||
clkVal = 0x80000000;
|
||||
else
|
||||
p_lrclk <: 0x00000000;
|
||||
clkVal = 0x00000000;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(frameCount == 0)
|
||||
p_lrclk <: 0x80000000;
|
||||
clkVal = 0x80000000;
|
||||
else
|
||||
p_lrclk <: 0x7fffffff;
|
||||
clkVal = 0x7fffffff;
|
||||
}
|
||||
|
||||
if(XUA_I2S_N_BITS == 32)
|
||||
p_lrclk <: clkVal;
|
||||
else
|
||||
partout(p_lrclk, XUA_I2S_N_BITS, clkVal >> (32 - XUA_I2S_N_BITS));
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
@@ -288,12 +242,12 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
}
|
||||
#endif // ((DEBUG_MIC_ARRAY == 1) && (XUA_NUM_PDM_MICS > 0))
|
||||
|
||||
UserBufferManagementInit();
|
||||
UserBufferManagementInit(curSamFreq);
|
||||
|
||||
unsigned command = DoSampleTransfer(c_out, readBuffNo, underflowWord);
|
||||
|
||||
// Reinitialise user state before entering the main loop
|
||||
UserBufferManagementInit();
|
||||
UserBufferManagementInit(curSamFreq);
|
||||
|
||||
#if (XUA_ADAT_TX_EN)
|
||||
unsafe{
|
||||
@@ -316,9 +270,9 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
if ((I2S_CHANS_DAC > 0 || I2S_CHANS_ADC > 0))
|
||||
{
|
||||
#if CODEC_MASTER
|
||||
InitPorts_slave(divide, p_lrclk, p_bclk, p_i2s_dac, p_i2s_adc);
|
||||
InitPorts_slave(p_lrclk, p_bclk, p_i2s_dac, p_i2s_adc);
|
||||
#else
|
||||
InitPorts_master(divide, p_lrclk, p_bclk, p_i2s_dac, p_i2s_adc);
|
||||
InitPorts_master(p_lrclk, p_bclk, p_i2s_dac, p_i2s_adc);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -352,9 +306,17 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
// p_i2s_adc[index++] :> sample;
|
||||
// Manual IN instruction since compiler generates an extra setc per IN (bug #15256)
|
||||
unsigned sample;
|
||||
asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++]));
|
||||
asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index]));
|
||||
|
||||
sample = bitrev(sample);
|
||||
int chanIndex = ((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i; // channels 0, 2, 4.. on each line.
|
||||
if(XUA_I2S_N_BITS != 32)
|
||||
{
|
||||
set_port_shift_count(p_i2s_adc[index], XUA_I2S_N_BITS);
|
||||
sample <<= (32 - XUA_I2S_N_BITS);
|
||||
}
|
||||
index++;
|
||||
|
||||
int chanIndex = ((frameCount-2) & (I2S_CHANS_PER_FRAME-1)) + i; // channels 0, 2, 4.. on each line.
|
||||
|
||||
#if (AUD_TO_USB_RATIO > 1)
|
||||
if ((AUD_TO_USB_RATIO - 1) == audioToUsbRatioCounter)
|
||||
@@ -406,16 +368,18 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
src_ff3v_fir_coefs[2-audioToUsbRatioCounter]);
|
||||
}
|
||||
#endif /* (AUD_TO_USB_RATIO > 1) */
|
||||
p_i2s_dac[index++] <: bitrev(samplesOut[frameCount +i]);
|
||||
if(XUA_I2S_N_BITS == 32)
|
||||
p_i2s_dac[index++] <: bitrev(samplesOut[frameCount +i]);
|
||||
else
|
||||
partout(p_i2s_dac[index++], XUA_I2S_N_BITS, bitrev(samplesOut[frameCount +i]));
|
||||
}
|
||||
#endif // (I2S_CHANS_DAC != 0)
|
||||
|
||||
#if (XUA_ADAT_TX_EN)
|
||||
TransferAdatTxSamples(c_adat_out, samplesOut, adatSmuxMode, 1);
|
||||
#endif
|
||||
|
||||
if(frameCount == 0)
|
||||
{
|
||||
#if (XUA_ADAT_TX_EN)
|
||||
TransferAdatTxSamples(c_adat_out, samplesOut, adatSmuxMode, 1);
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
/* Sync with clockgen */
|
||||
@@ -443,9 +407,8 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
outuint(c_dig_rx, 0);
|
||||
#endif
|
||||
#if (XUA_SPDIF_TX_EN) && (NUM_USB_CHAN_OUT > 0)
|
||||
outuint(c_spd_out, samplesOut[SPDIF_TX_INDEX]); /* Forward sample to S/PDIF Tx thread */
|
||||
unsigned sample = samplesOut[SPDIF_TX_INDEX + 1];
|
||||
outuint(c_spd_out, sample); /* Forward sample to S/PDIF Tx thread */
|
||||
outuint(c_spd_out, samplesOut[SPDIF_TX_INDEX]); /* Forward samples to S/PDIF Tx thread */
|
||||
outuint(c_spd_out, samplesOut[SPDIF_TX_INDEX + 1]);
|
||||
#endif
|
||||
|
||||
#if (XUA_NUM_PDM_MICS > 0)
|
||||
@@ -480,8 +443,15 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
{
|
||||
/* Manual IN instruction since compiler generates an extra setc per IN (bug #15256) */
|
||||
unsigned sample;
|
||||
asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++]));
|
||||
asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index]));
|
||||
sample = bitrev(sample);
|
||||
if(XUA_I2S_N_BITS != 32)
|
||||
{
|
||||
set_port_shift_count(p_i2s_adc[index], XUA_I2S_N_BITS);
|
||||
sample <<= (32 - XUA_I2S_N_BITS);
|
||||
}
|
||||
index++;
|
||||
|
||||
int chanIndex = ((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i; // channels 1, 3, 5.. on each line.
|
||||
#if (AUD_TO_USB_RATIO > 1 && !I2S_DOWNSAMPLE_MONO_IN)
|
||||
if ((AUD_TO_USB_RATIO - 1) == audioToUsbRatioCounter)
|
||||
@@ -513,7 +483,6 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
#endif
|
||||
|
||||
index = 0;
|
||||
#pragma xta endpoint "i2s_output_r"
|
||||
#if (I2S_CHANS_DAC != 0)
|
||||
/* Output "odd" channel to DAC (i.e. right) */
|
||||
#pragma loop unroll
|
||||
@@ -532,7 +501,10 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
src_ff3v_fir_coefs[2-audioToUsbRatioCounter]);
|
||||
}
|
||||
#endif /* (AUD_TO_USB_RATIO > 1) */
|
||||
p_i2s_dac[index++] <: bitrev(samplesOut[frameCount + i]);
|
||||
if(XUA_I2S_N_BITS == 32)
|
||||
p_i2s_dac[index++] <: bitrev(samplesOut[frameCount + i]);
|
||||
else
|
||||
partout(p_i2s_dac[index++], XUA_I2S_N_BITS, bitrev(samplesOut[frameCount + i]));
|
||||
}
|
||||
#endif // (I2S_CHANS_DAC != 0)
|
||||
|
||||
@@ -586,7 +558,6 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma xta endpoint "deliver_return"
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -670,6 +641,9 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
|
||||
#if (XUA_ADAT_RX_EN || XUA_SPDIF_RX_EN)
|
||||
, chanend c_dig_rx
|
||||
#endif
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC || XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
, chanend c_audio_rate_change
|
||||
#endif
|
||||
#if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0) && (XUA_DFU_EN == 1)
|
||||
, server interface i_dfu ?dfuInterface
|
||||
#endif
|
||||
@@ -693,9 +667,14 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
|
||||
|
||||
/* Clock master clock-block from master-clock port */
|
||||
/* Note, marked unsafe since other cores may be using this mclk port */
|
||||
|
||||
// 加了这里就可以播放705,但是有杂音(不加的花705没有声音)
|
||||
// set_thread_fast_mode_on();
|
||||
// set_port_inv(p_mclk_in); // invert sense of MCLK to improve timing for external latch
|
||||
|
||||
// set_thread_fast_mode_on();
|
||||
configure_clock_src(clk_audio_mclk, p_mclk_in);
|
||||
|
||||
start_clock(clk_audio_mclk);
|
||||
|
||||
#if (DSD_CHANS_DAC > 0)
|
||||
/* Make sure the DSD ports are on and buffered - just in case they are not shared with I2S */
|
||||
@@ -707,15 +686,12 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
|
||||
#endif
|
||||
|
||||
#if (XUA_ADAT_TX_EN)
|
||||
/* Share SPDIF clk blk */
|
||||
configure_clock_src(clk_mst_spd, p_mclk_in);
|
||||
configure_out_port_no_ready(p_adat_tx, clk_mst_spd, 0);
|
||||
set_clock_fall_delay(clk_mst_spd, 7);
|
||||
#if (XUA_SPDIF_TX_EN == 0)
|
||||
start_clock(clk_mst_spd);
|
||||
#endif
|
||||
configure_out_port_no_ready(p_adat_tx, clk_audio_mclk, 0);
|
||||
set_clock_fall_delay(clk_audio_mclk, 7);
|
||||
#endif
|
||||
|
||||
start_clock(clk_audio_mclk);
|
||||
|
||||
/* Perform required CODEC/ADC/DAC initialisation */
|
||||
AudioHwInit();
|
||||
|
||||
@@ -744,13 +720,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
|
||||
/* Calculate master clock to bit clock (or DSD clock) divide for current sample freq
|
||||
* e.g. 11.289600 / (176400 * 64) = 1 */
|
||||
{
|
||||
#if (XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM)
|
||||
/* I2S has 32 bits per sample. *8 as 8 channels */
|
||||
unsigned numBits = 256;
|
||||
#else
|
||||
/* I2S has 32 bits per sample. *2 as 2 channels */
|
||||
unsigned numBits = 64;
|
||||
#endif
|
||||
unsigned numBits = XUA_I2S_N_BITS * I2S_CHANS_PER_FRAME;
|
||||
|
||||
#if (DSD_CHANS_DAC > 0)
|
||||
if(dsdMode == DSD_MODE_DOP)
|
||||
@@ -764,17 +734,24 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
|
||||
numBits = 32;
|
||||
}
|
||||
#endif
|
||||
divide = mClk / ( curSamFreq * numBits);
|
||||
divide = mClk / (curSamFreq * numBits);
|
||||
|
||||
//Do some checks
|
||||
xassert((divide > 0) && "Error: divider is 0, BCLK rate unachievable");
|
||||
|
||||
unsigned remainder = mClk % ( curSamFreq * numBits);
|
||||
xassert((!remainder) && "Error: MCLK not divisible into BCLK by an integer number");
|
||||
|
||||
unsigned divider_is_odd = divide & 0x1;
|
||||
xassert((!divider_is_odd) && "Error: divider is odd, clockblock cannot produce desired BCLK");
|
||||
|
||||
/* TODO; we should catch and handle the case when divide is 0. Currently design will lock up */
|
||||
}
|
||||
|
||||
|
||||
#if (DSD_CHANS_DAC > 0)
|
||||
if(dsdMode)
|
||||
{
|
||||
/* Configure audio ports */
|
||||
ConfigAudioPortsWrapper(
|
||||
/* Configure audio ports */
|
||||
ConfigAudioPortsWrapper(
|
||||
#if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0)
|
||||
p_dsd_dac,
|
||||
DSD_CHANS_DAC,
|
||||
@@ -787,7 +764,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
|
||||
null,
|
||||
p_dsd_clk,
|
||||
#endif
|
||||
p_mclk_in, clk_audio_bclk, divide, curSamFreq, dsdMode);
|
||||
p_mclk_in, clk_audio_bclk, divide, curSamFreq);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@@ -810,9 +787,8 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
|
||||
p_bclk,
|
||||
#endif
|
||||
#endif
|
||||
p_mclk_in, clk_audio_bclk, divide, curSamFreq, dsdMode);
|
||||
}
|
||||
|
||||
p_mclk_in, clk_audio_bclk, divide, curSamFreq);
|
||||
}
|
||||
|
||||
{
|
||||
unsigned curFreq = curSamFreq;
|
||||
@@ -828,14 +804,30 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
|
||||
}
|
||||
#endif
|
||||
/* Configure Clocking/CODEC/DAC/ADC for SampleFreq/MClk */
|
||||
|
||||
/* User should mute audio hardware */
|
||||
AudioHwConfig_Mute();
|
||||
|
||||
/* User code should configure audio harware for SampleFreq/MClk etc */
|
||||
AudioHwConfig(curFreq, mClk, dsdMode, curSamRes_DAC, curSamRes_ADC);
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC || XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
/* Notify clockgen of new mCLk */
|
||||
c_audio_rate_change <: mClk;
|
||||
c_audio_rate_change <: curFreq;
|
||||
|
||||
/* Wait for ACK back from clockgen or ep_buffer to signal clocks all good */
|
||||
c_audio_rate_change :> int _;
|
||||
#endif
|
||||
|
||||
/* User should unmute audio hardware */
|
||||
AudioHwConfig_UnMute();
|
||||
}
|
||||
|
||||
if(!firstRun)
|
||||
{
|
||||
/* TODO wait for good mclk instead of delay */
|
||||
/* No delay for DFU modes */
|
||||
if (((curSamFreq / AUD_TO_USB_RATIO) != AUDIO_REBOOT_FROM_DFU) && ((curSamFreq / AUD_TO_USB_RATIO) != AUDIO_STOP_FOR_DFU) && command)
|
||||
if (((curSamFreq / AUD_TO_USB_RATIO) != AUDIO_STOP_FOR_DFU) && command)
|
||||
{
|
||||
#if 0
|
||||
/* User should ensure MCLK is stable in AudioHwConfig */
|
||||
@@ -945,13 +937,9 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
|
||||
#else
|
||||
dummy_deliver(c_aud, command);
|
||||
#endif
|
||||
/* Note, we do not expect to reach here */
|
||||
curSamFreq = inuint(c_aud);
|
||||
|
||||
if (curSamFreq == AUDIO_START_FROM_DFU)
|
||||
{
|
||||
outct(c_aud, XS1_CT_END);
|
||||
break;
|
||||
}
|
||||
outct(c_aud, XS1_CT_END);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
66
lib_xua/src/core/audiohub/xua_audiohub_st.h
Normal file
66
lib_xua/src/core/audiohub/xua_audiohub_st.h
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright 2011-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#pragma unsafe arrays
|
||||
static inline unsigned DoSampleTransfer(chanend ?c_out, const int readBuffNo, const unsigned underflowWord)
|
||||
{
|
||||
if(XUA_USB_EN)
|
||||
{
|
||||
outuint(c_out, underflowWord);
|
||||
|
||||
/* Check for sample freq change (or other command) or new samples from mixer*/
|
||||
if(testct(c_out))
|
||||
{
|
||||
unsigned command = inct(c_out);
|
||||
#ifndef CODEC_MASTER
|
||||
if(dsdMode == DSD_MODE_OFF)
|
||||
{
|
||||
#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0)
|
||||
/* Set clocks low */
|
||||
p_lrclk <: 0;
|
||||
p_bclk <: 0;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if(DSD_CHANS_DAC != 0)
|
||||
/* DSD Clock might not be shared with lrclk or bclk... */
|
||||
p_dsd_clk <: 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if (DSD_CHANS_DAC > 0)
|
||||
if(dsdMode == DSD_MODE_DOP)
|
||||
dsdMode = DSD_MODE_OFF;
|
||||
#endif
|
||||
return command;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NUM_USB_CHAN_OUT > 0
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
|
||||
{
|
||||
int tmp = inuint(c_out);
|
||||
samplesOut[i] = tmp;
|
||||
}
|
||||
#else
|
||||
inuint(c_out);
|
||||
#endif
|
||||
UserBufferManagement(samplesOut, samplesIn[readBuffNo]);
|
||||
|
||||
#if NUM_USB_CHAN_IN > 0
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < NUM_USB_CHAN_IN; i++)
|
||||
{
|
||||
outuint(c_out, samplesIn[readBuffNo][i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
UserBufferManagement(samplesOut, samplesIn[readBuffNo]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright 2016-2021 XMOS LIMITED.
|
||||
// Copyright 2016-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#include "xccompat.h"
|
||||
#include "xua_audiohub.h"
|
||||
|
||||
/* Default implementation for UserBufferManagementInit() */
|
||||
void __attribute__ ((weak)) UserBufferManagementInit()
|
||||
void __attribute__ ((weak)) UserBufferManagementInit(unsigned sampFreq)
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include "xua.h"
|
||||
|
||||
@@ -42,8 +42,13 @@
|
||||
#define MAX_DEVICE_AUD_PACKET_SIZE_OUT (MAX(MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS, MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS))
|
||||
|
||||
/*** BUFFER SIZES ***/
|
||||
|
||||
#define BUFFER_PACKET_COUNT 4 /* How many packets too allow for in buffer - minimum is 4 */
|
||||
/* How many packets too allow for in buffer - minimum is 5.
|
||||
2 for having in the aud_to_host buffer when it comes out of underflow, space available for 2 more for to accomodate cases when
|
||||
2 pkts from audio hub get written into the aud_to_host buffer within 1 SOF period, and space for 1 extra packet to ensure that
|
||||
when the 4th packet gets written to the buffer, there's space to accomodate the next packet, otherwise handle_audio_request() will
|
||||
drop packets after writing the 4th packet in the buffer
|
||||
*/
|
||||
#define BUFFER_PACKET_COUNT (5)
|
||||
|
||||
#define BUFF_SIZE_OUT_HS MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS * BUFFER_PACKET_COUNT
|
||||
#define BUFF_SIZE_OUT_FS MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS * BUFFER_PACKET_COUNT
|
||||
@@ -55,18 +60,25 @@
|
||||
#define BUFF_SIZE_IN MAX(BUFF_SIZE_IN_HS, BUFF_SIZE_IN_FS)
|
||||
|
||||
#define OUT_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS, MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS))
|
||||
#define IN_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_IN_HS, MAX_DEVICE_AUD_PACKET_SIZE_IN_FS)*2)
|
||||
#define IN_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_IN_HS, MAX_DEVICE_AUD_PACKET_SIZE_IN_FS)*2)
|
||||
|
||||
/* Volume and mute tables */
|
||||
#if !defined(OUT_VOLUME_IN_MIXER) && (OUTPUT_VOLUME_CONTROL == 1)
|
||||
#if (OUT_VOLUME_IN_MIXER == 0) && (OUTPUT_VOLUME_CONTROL == 1)
|
||||
unsigned int multOut[NUM_USB_CHAN_OUT + 1];
|
||||
static xc_ptr p_multOut;
|
||||
unsafe
|
||||
{
|
||||
unsigned int volatile * unsafe multOutPtr = multOut;
|
||||
}
|
||||
#endif
|
||||
#if !defined(IN_VOLUME_IN_MIXER) && (INPUT_VOLUME_CONTROL == 1)
|
||||
#if (IN_VOLUME_IN_MIXER == 0) && (INPUT_VOLUME_CONTROL == 1)
|
||||
unsigned int multIn[NUM_USB_CHAN_IN + 1];
|
||||
static xc_ptr p_multIn;
|
||||
unsafe
|
||||
{
|
||||
unsigned int volatile * unsafe multInPtr = multIn;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Default to something sensible but the following are setup at stream start (unless UAC1 only..) */
|
||||
#if (AUDIO_CLASS == 2)
|
||||
int g_numUsbChan_In = NUM_USB_CHAN_IN; /* Number of channels to/from the USB bus - initialised to HS for UAC2.0 */
|
||||
int g_numUsbChan_Out = NUM_USB_CHAN_OUT;
|
||||
@@ -143,7 +155,69 @@ unsigned unpackData = 0;
|
||||
unsigned packState = 0;
|
||||
unsigned packData = 0;
|
||||
|
||||
/* Default to something sensible but the following are setup at stream start (unless UAC1 only..) */
|
||||
static inline void _send_sample_4(chanend c_mix_out, int ch)
|
||||
{
|
||||
int sample;
|
||||
read_via_xc_ptr(sample, g_aud_from_host_rdptr);
|
||||
g_aud_from_host_rdptr+=4;
|
||||
|
||||
#if (OUTPUT_VOLUME_CONTROL == 1) && (!OUT_VOLUME_IN_MIXER)
|
||||
int mult;
|
||||
int h;
|
||||
unsigned l;
|
||||
unsafe
|
||||
{
|
||||
mult = multOutPtr[ch];
|
||||
}
|
||||
{h, l} = macs(mult, sample, 0, 0);
|
||||
h <<= 3;
|
||||
#if (STREAM_FORMAT_OUTPUT_RESOLUTION_32BIT_USED == 1)
|
||||
h |= (l >>29) & 0x7; // Note: This step is not required if we assume sample depth is 24bit (rather than 32bit)
|
||||
// Note: We need all 32bits for Native DSD
|
||||
#endif
|
||||
outuint(c_mix_out, h);
|
||||
#else
|
||||
outuint(c_mix_out, sample);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void SendSamples4(chanend c_mix_out)
|
||||
{
|
||||
/* Doing this allows us to unroll */
|
||||
if(g_numUsbChan_Out == HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT)
|
||||
{
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT; i++)
|
||||
{
|
||||
_send_sample_4(c_mix_out, i);
|
||||
}
|
||||
}
|
||||
else if(g_numUsbChan_Out == HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT)
|
||||
{
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT; i++)
|
||||
{
|
||||
_send_sample_4(c_mix_out, i);
|
||||
}
|
||||
}
|
||||
else if(g_numUsbChan_Out == HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT)
|
||||
{
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT; i++)
|
||||
{
|
||||
_send_sample_4(c_mix_out, i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma loop unroll
|
||||
for(int i = 0; i < NUM_USB_CHAN_OUT_FS; i++)
|
||||
{
|
||||
_send_sample_4(c_mix_out, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma select handler
|
||||
#pragma unsafe arrays
|
||||
@@ -206,8 +280,11 @@ __builtin_unreachable();
|
||||
g_aud_from_host_rdptr+=2;
|
||||
sample <<= 16;
|
||||
|
||||
#if (OUTPUT_VOLUME_CONTROL == 1) && !defined(OUT_VOLUME_IN_MIXER)
|
||||
asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
||||
#if (OUTPUT_VOLUME_CONTROL == 1) && (!OUT_VOLUME_IN_MIXER)
|
||||
unsafe
|
||||
{
|
||||
mult = multOutPtr[i];
|
||||
}
|
||||
{h, l} = macs(mult, sample, 0, 0);
|
||||
/* Note, in 2 byte subslot mode - ignore lower result of macs */
|
||||
h <<= 3;
|
||||
@@ -223,41 +300,17 @@ __builtin_unreachable();
|
||||
__builtin_unreachable();
|
||||
#endif
|
||||
/* Buffering not underflow condition send out some samples...*/
|
||||
for(int i = 0; i < g_numUsbChan_Out; i++)
|
||||
{
|
||||
#pragma xta endpoint "mixer_request"
|
||||
int sample;
|
||||
int mult;
|
||||
int h;
|
||||
unsigned l;
|
||||
|
||||
read_via_xc_ptr(sample, g_aud_from_host_rdptr);
|
||||
g_aud_from_host_rdptr+=4;
|
||||
|
||||
#if (OUTPUT_VOLUME_CONTROL == 1) && !defined(OUT_VOLUME_IN_MIXER)
|
||||
asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
||||
{h, l} = macs(mult, sample, 0, 0);
|
||||
h <<= 3;
|
||||
#if (STREAM_FORMAT_OUTPUT_RESOLUTION_32BIT_USED == 1)
|
||||
h |= (l >>29)& 0x7; // Note: This step is not required if we assume sample depth is 24bit (rather than 32bit)
|
||||
// Note: We need all 32bits for Native DSD
|
||||
#endif
|
||||
outuint(c_mix_out, h);
|
||||
#else
|
||||
outuint(c_mix_out, sample);
|
||||
#endif
|
||||
}
|
||||
|
||||
SendSamples4(c_mix_out);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
#if (STREAM_FORMAT_OUTPUT_SUBSLOT_3_USED == 0)
|
||||
__builtin_unreachable();
|
||||
#endif
|
||||
/* Buffering not underflow condition send out some samples...*/
|
||||
/* Note, in this case the unpacking of data is more of an overhead than the loop overhead
|
||||
* so we do not currently make attempts to unroll */
|
||||
for(int i = 0; i < g_numUsbChan_Out; i++)
|
||||
{
|
||||
#pragma xta endpoint "mixer_request"
|
||||
int sample;
|
||||
int mult;
|
||||
int h;
|
||||
@@ -289,19 +342,20 @@ __builtin_unreachable();
|
||||
}
|
||||
unpackState++;
|
||||
|
||||
#if (OUTPUT_VOLUME_CONTROL == 1) && !defined(OUT_VOLUME_IN_MIXER)
|
||||
asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
|
||||
#if (OUTPUT_VOLUME_CONTROL == 1) && (!OUT_VOLUME_IN_MIXER)
|
||||
unsafe
|
||||
{
|
||||
mult = multOutPtr[i];
|
||||
}
|
||||
{h, l} = macs(mult, sample, 0, 0);
|
||||
h <<= 3;
|
||||
outuint(c_mix_out, h);
|
||||
#else
|
||||
outuint(c_mix_out, sample);
|
||||
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
__builtin_unreachable();
|
||||
break;
|
||||
@@ -335,17 +389,20 @@ __builtin_unreachable();
|
||||
/* Receive sample */
|
||||
int sample = inuint(c_mix_out);
|
||||
#if (INPUT_VOLUME_CONTROL == 1)
|
||||
#if !defined(IN_VOLUME_IN_MIXER)
|
||||
#if (!IN_VOLUME_IN_MIXER)
|
||||
/* Apply volume */
|
||||
int mult;
|
||||
int h;
|
||||
unsigned l;
|
||||
asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i));
|
||||
unsafe
|
||||
{
|
||||
mult = multInPtr[i];
|
||||
}
|
||||
{h, l} = macs(mult, sample, 0, 0);
|
||||
sample = h << 3;
|
||||
|
||||
/* Note, in 2 byte sub slot - ignore lower bits of macs */
|
||||
#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX)
|
||||
#elif (IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX)
|
||||
sample = sample << 3;
|
||||
#endif
|
||||
#endif
|
||||
@@ -365,18 +422,21 @@ __builtin_unreachable();
|
||||
/* Receive sample */
|
||||
int sample = inuint(c_mix_out);
|
||||
#if(INPUT_VOLUME_CONTROL == 1)
|
||||
#if !defined(IN_VOLUME_IN_MIXER)
|
||||
#if (!IN_VOLUME_IN_MIXER)
|
||||
/* Apply volume */
|
||||
int mult;
|
||||
int h;
|
||||
unsigned l;
|
||||
asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i));
|
||||
unsafe
|
||||
{
|
||||
mult = multInPtr[i];
|
||||
}
|
||||
{h, l} = macs(mult, sample, 0, 0);
|
||||
sample = h << 3;
|
||||
#if (STREAM_FORMAT_INPUT_RESOLUTION_32BIT_USED == 1)
|
||||
sample |= (l >> 29) & 0x7; // Note, this step is not required if we assume sample depth is 24 (rather than 32)
|
||||
#endif
|
||||
#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX)
|
||||
#elif (IN_VOLUME_IN_MIXER) && (IN_VOLUME_AFTER_MIX)
|
||||
sample = sample << 3;
|
||||
#endif
|
||||
#endif
|
||||
@@ -396,12 +456,15 @@ __builtin_unreachable();
|
||||
{
|
||||
/* Receive sample */
|
||||
int sample = inuint(c_mix_out);
|
||||
#if (INPUT_VOLUME_CONTROL) && !defined(IN_VOLUME_IN_MIXER)
|
||||
#if (INPUT_VOLUME_CONTROL) && (!IN_VOLUME_IN_MIXER)
|
||||
/* Apply volume */
|
||||
int mult;
|
||||
int h;
|
||||
unsigned l;
|
||||
asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multIn),"r"(i));
|
||||
unsafe
|
||||
{
|
||||
mult = multInPtr[i];
|
||||
}
|
||||
{h, l} = macs(mult, sample, 0, 0);
|
||||
sample = h << 3;
|
||||
#endif
|
||||
@@ -453,7 +516,7 @@ __builtin_unreachable();
|
||||
{
|
||||
/* Finished creating packet - commit it to the FIFO */
|
||||
/* Total samps to write could start at 0 (i.e. no MCLK) so need to check for < 0) */
|
||||
if (sampsToWrite <= 0)
|
||||
if(sampsToWrite <= 0)
|
||||
{
|
||||
int speed, wrPtr;
|
||||
packState = 0;
|
||||
@@ -588,7 +651,9 @@ __builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
#if (NUM_USB_CHAN_IN > 0)
|
||||
/* Mark Endpoint (IN) ready with an appropriately sized zero buffer */
|
||||
/* TODO We should properly size zeros packet rather than using "mid" */
|
||||
static inline void SetupZerosSendBuffer(XUD_ep aud_to_host_usb_ep, unsigned sampFreq, unsigned slotSize,
|
||||
xc_ptr aud_to_host_zeros)
|
||||
{
|
||||
@@ -597,8 +662,8 @@ static inline void SetupZerosSendBuffer(XUD_ep aud_to_host_usb_ep, unsigned samp
|
||||
|
||||
/* Set IN stream packet size to something sensible. We expect the buffer to
|
||||
* over flow and this to be reset */
|
||||
SET_SHARED_GLOBAL(sampsToWrite, 0);
|
||||
SET_SHARED_GLOBAL(totalSampsToWrite, 0);
|
||||
SET_SHARED_GLOBAL(sampsToWrite, mid);
|
||||
SET_SHARED_GLOBAL(totalSampsToWrite, mid);
|
||||
|
||||
mid *= g_numUsbChan_In * slotSize;
|
||||
|
||||
@@ -619,6 +684,7 @@ static inline void SetupZerosSendBuffer(XUD_ep aud_to_host_usb_ep, unsigned samp
|
||||
|
||||
XUD_SetReady_InPtr(aud_to_host_usb_ep, aud_to_host_zeros+4, mid);
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma unsafe arrays
|
||||
void XUA_Buffer_Decouple(chanend c_mix_out
|
||||
@@ -638,13 +704,6 @@ void XUA_Buffer_Decouple(chanend c_mix_out
|
||||
|
||||
int t = array_to_xc_ptr(outAudioBuff);
|
||||
|
||||
#if !defined(OUT_VOLUME_IN_MIXER) && (OUTPUT_VOLUME_CONTROL == 1)
|
||||
p_multOut = array_to_xc_ptr(multOut);
|
||||
#endif
|
||||
#if !defined(IN_VOLUME_IN_MIXER) && (INPUT_VOLUME_CONTROL == 1)
|
||||
p_multIn = array_to_xc_ptr(multIn);
|
||||
#endif
|
||||
|
||||
aud_from_host_fifo_start = t;
|
||||
aud_from_host_fifo_end = aud_from_host_fifo_start + BUFF_SIZE_OUT;
|
||||
g_aud_from_host_wrptr = aud_from_host_fifo_start;
|
||||
@@ -668,17 +727,17 @@ void XUA_Buffer_Decouple(chanend c_mix_out
|
||||
xc_ptr aud_to_host_zeros = t;
|
||||
|
||||
/* Init vol mult tables */
|
||||
#if !defined(OUT_VOLUME_IN_MIXER) && (OUTPUT_VOLUME_CONTROL == 1)
|
||||
#if (OUT_VOLUME_IN_MIXER == 0) && (OUTPUT_VOLUME_CONTROL == 1)
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT + 1; i++)
|
||||
{
|
||||
asm volatile("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(p_multOut),"r"(i));
|
||||
unsafe{
|
||||
multOutPtr[i] = MAX_VOLUME_MULT;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(IN_VOLUME_IN_MIXER) && (INPUT_VOLUME_CONTROL == 1)
|
||||
#if (IN_VOLUME_IN_MIXER == 0) && (INPUT_VOLUME_CONTROL == 1)
|
||||
for (int i = 0; i < NUM_USB_CHAN_IN + 1; i++)
|
||||
{
|
||||
asm volatile("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(p_multIn),"r"(i));
|
||||
unsafe{
|
||||
multInPtr[i] = MAX_VOLUME_MULT;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -760,9 +819,12 @@ void XUA_Buffer_Decouple(chanend c_mix_out
|
||||
/* Set buffer to send back to zeros buffer */
|
||||
aud_to_host_buffer = aud_to_host_zeros;
|
||||
|
||||
#if (NUM_USB_CHAN_IN > 0)
|
||||
/* Update size of zeros buffer (and sampsToWrite) */
|
||||
SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq, g_curSubSlot_In, aud_to_host_zeros);
|
||||
#endif
|
||||
|
||||
#if (NUM_USB_CHAN_OUT > 0)
|
||||
/* Reset OUT buffer state */
|
||||
outUnderflow = 1;
|
||||
SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start);
|
||||
@@ -772,9 +834,10 @@ void XUA_Buffer_Decouple(chanend c_mix_out
|
||||
if(outOverflow)
|
||||
{
|
||||
/* If we were previously in overflow we wont have marked as ready */
|
||||
XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_fifo_start+4);
|
||||
XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_fifo_start + 4);
|
||||
outOverflow = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Wait for handshake back and pass back up */
|
||||
@@ -815,8 +878,10 @@ void XUA_Buffer_Decouple(chanend c_mix_out
|
||||
/* Set buffer back to zeros buffer */
|
||||
aud_to_host_buffer = aud_to_host_zeros;
|
||||
|
||||
#if (NUM_USB_CHAN_IN > 0)
|
||||
/* Update size of zeros buffer (and sampsToWrite) */
|
||||
SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq, g_curSubSlot_In, aud_to_host_zeros);
|
||||
#endif
|
||||
|
||||
GET_SHARED_GLOBAL(usbSpeed, g_curUsbSpeed);
|
||||
if (usbSpeed == XUD_SPEED_HS)
|
||||
@@ -846,6 +911,7 @@ void XUA_Buffer_Decouple(chanend c_mix_out
|
||||
GET_SHARED_GLOBAL(dataFormat, g_formatChange_DataFormat);
|
||||
GET_SHARED_GLOBAL(sampRes, g_formatChange_SampRes);
|
||||
|
||||
#if (NUM_USB_CHAN_OUT > 0)
|
||||
/* Reset OUT buffer state */
|
||||
SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start);
|
||||
SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start);
|
||||
@@ -861,6 +927,7 @@ void XUA_Buffer_Decouple(chanend c_mix_out
|
||||
XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_fifo_start+4);
|
||||
outOverflow = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NATIVE_DSD
|
||||
if(dataFormat == UAC_FORMAT_TYPEI_RAW_DATA)
|
||||
@@ -981,7 +1048,7 @@ void XUA_Buffer_Decouple(chanend c_mix_out
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
|
||||
if (inUnderflow)
|
||||
if(inUnderflow)
|
||||
{
|
||||
int fillLevel;
|
||||
GET_SHARED_GLOBAL(fillLevel, g_aud_to_host_fill_level);
|
||||
@@ -989,7 +1056,21 @@ void XUA_Buffer_Decouple(chanend c_mix_out
|
||||
assert(fillLevel <= BUFF_SIZE_IN);
|
||||
|
||||
/* Check if we have come out of underflow */
|
||||
if (fillLevel >= IN_BUFFER_PREFILL)
|
||||
unsigned sampFreq;
|
||||
GET_SHARED_GLOBAL(sampFreq, g_freqChange_sampFreq);
|
||||
int min, mid, max;
|
||||
GetADCCounts(sampFreq, min, mid, max);
|
||||
const int min_pkt_size = ((min * g_curSubSlot_In * g_numUsbChan_In + 3) & ~0x3) + 4;
|
||||
|
||||
/*
|
||||
Come out of underflow if there are exactly 2 packets in the buffer.
|
||||
This ensures that handle_audio_request() does not drop packets when writing packets into the aud_to_host buffer
|
||||
when aud_to_host buffer is not in underflow.
|
||||
For example, coming out of underflow with 3 packets in the buffer would mean handle_audio_request()
|
||||
drops packets if 2 pkts are received from audio hub in 1 SOF period. Coming out of underflow with 4
|
||||
packets would mean handle_audio_request would drop packets after writing 1 packet to the aud_to_host buffer.
|
||||
*/
|
||||
if ((fillLevel >= (min_pkt_size*2)) && (fillLevel < (min_pkt_size*3)))
|
||||
{
|
||||
int aud_to_host_rdptr;
|
||||
GET_SHARED_GLOBAL(aud_to_host_rdptr, g_aud_to_host_rdptr);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include "xua.h"
|
||||
#if XUA_USB_EN
|
||||
@@ -10,13 +10,21 @@
|
||||
#include "xud.h"
|
||||
#include "testct_byref.h"
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_HID_ENABLED
|
||||
#include "xua_hid_report.h"
|
||||
#include "user_hid.h"
|
||||
#include "xua_hid.h"
|
||||
unsigned char g_hidData[HID_MAX_DATA_BYTES] = {0U};
|
||||
#endif
|
||||
|
||||
#if PAWPAW_INOUTHID
|
||||
#include "stdio.h"
|
||||
#include "pp_hid_exchange.h"
|
||||
unsigned char g_hidData_in[PAWPAW_CFG_HID_IN_BUFSIZE+8] = {0};
|
||||
unsigned char g_hidData_out[PAWPAW_CFG_HID_OUT_BUFSIZE+8] = {0};
|
||||
extern int set_hid_up_size;
|
||||
#endif//#if PAWPAW_INOUTHID
|
||||
|
||||
void GetADCCounts(unsigned samFreq, int &min, int &mid, int &max);
|
||||
#define BUFFER_SIZE_OUT (1028 >> 2)
|
||||
#define BUFFER_SIZE_IN (1028 >> 2)
|
||||
@@ -103,9 +111,18 @@ void XUA_Buffer(
|
||||
#if (HID_CONTROLS )
|
||||
, chanend c_hid
|
||||
#endif
|
||||
#if PAWPAW_INOUTHID
|
||||
, chanend c_hid
|
||||
, chanend c_hid_out
|
||||
#endif//#if PAWPAW_INOUTHID
|
||||
, chanend c_aud
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
, chanend c_audio_rate_change
|
||||
#if(XUA_USE_SW_PLL)
|
||||
, chanend c_sw_pll
|
||||
#else
|
||||
, client interface pll_ref_if i_pll_ref
|
||||
#endif
|
||||
#endif
|
||||
)
|
||||
{
|
||||
@@ -134,14 +151,24 @@ void XUA_Buffer(
|
||||
c_clk_int,
|
||||
#endif
|
||||
c_sof, c_aud_ctl, p_off_mclk
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_HID_ENABLED
|
||||
, c_hid
|
||||
#endif
|
||||
|
||||
#if PAWPAW_INOUTHID
|
||||
, c_hid
|
||||
, c_hid_out
|
||||
#endif //#if PAWPAW_INOUTHID
|
||||
#ifdef CHAN_BUFF_CTRL
|
||||
, c_buff_ctrl
|
||||
#endif
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
, i_pll_ref
|
||||
, c_audio_rate_change
|
||||
#if(XUA_USE_SW_PLL)
|
||||
, c_sw_pll
|
||||
#else
|
||||
, i_pll_ref
|
||||
#endif
|
||||
#endif
|
||||
);
|
||||
|
||||
@@ -187,11 +214,21 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
#if(HID_CONTROLS)
|
||||
, chanend c_hid
|
||||
#endif
|
||||
#if PAWPAW_INOUTHID
|
||||
, chanend c_hid
|
||||
, chanend c_hid_out
|
||||
#endif//#if PAWPAW_INOUTHID
|
||||
|
||||
#ifdef CHAN_BUFF_CTRL
|
||||
, chanend c_buff_ctrl
|
||||
#endif
|
||||
#if XUA_SYNCMODE == XUA_SYNCMODE_SYNC
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
, chanend c_audio_rate_change
|
||||
#if (XUA_USE_SW_PLL)
|
||||
, chanend c_sw_pll
|
||||
#else
|
||||
, client interface pll_ref_if i_pll_ref
|
||||
#endif
|
||||
#endif
|
||||
)
|
||||
{
|
||||
@@ -224,9 +261,15 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
XUD_ep ep_int = XUD_InitEp(c_ep_int);
|
||||
#endif
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_HID_ENABLED
|
||||
XUD_ep ep_hid = XUD_InitEp(c_hid);
|
||||
#endif
|
||||
|
||||
#if PAWPAW_INOUTHID
|
||||
XUD_ep ep_hid = XUD_InitEp(c_hid);
|
||||
XUD_ep ep_hid_out = XUD_InitEp(c_hid_out);//dwj+
|
||||
#endif//#if PAWPAW_INOUTHID
|
||||
|
||||
unsigned u_tmp;
|
||||
unsigned sampleFreq = DEFAULT_FREQ;
|
||||
unsigned masterClockFreq = DEFAULT_MCLK_FREQ;
|
||||
@@ -247,7 +290,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
#if (NUM_USB_CHAN_IN > 0)
|
||||
unsigned bufferIn = 1;
|
||||
#endif
|
||||
unsigned sofCount = 0;
|
||||
int sofCount = 0;
|
||||
|
||||
unsigned mod_from_last_time = 0;
|
||||
#ifdef FB_TOLERANCE_TEST
|
||||
@@ -294,7 +337,6 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
unsigned iap_ea_native_interface_alt_setting = 0;
|
||||
unsigned iap_ea_native_control_to_send = 0;
|
||||
unsigned iap_ea_native_incoming = 0;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -332,7 +374,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_HID_ENABLED
|
||||
|
||||
while (!hidIsReportDescriptorPrepared())
|
||||
;
|
||||
@@ -357,6 +399,24 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
#ifndef LOCAL_CLOCK_MARGIN
|
||||
#define LOCAL_CLOCK_MARGIN (1000)
|
||||
#endif
|
||||
|
||||
#if (XUA_USE_SW_PLL)
|
||||
/* Setup the phase frequency detector */
|
||||
const unsigned controller_rate_hz = 100;
|
||||
const unsigned pfd_ppm_max = 2000; /* PPM range before we assume unlocked */
|
||||
|
||||
sw_pll_pfd_state_t sw_pll_pfd;
|
||||
sw_pll_pfd_init(&sw_pll_pfd,
|
||||
1, /* How often the PFD is invoked per call */
|
||||
masterClockFreq / controller_rate_hz, /* pll ratio integer */
|
||||
0, /* Assume precise timing of sampling */
|
||||
pfd_ppm_max);
|
||||
outuint(c_sw_pll, masterClockFreq);
|
||||
outct(c_sw_pll, XS1_CT_END);
|
||||
inuint(c_sw_pll); /* receive ACK */
|
||||
inct(c_sw_pll);
|
||||
|
||||
#else /* XUA_USE_SW_PLL */
|
||||
timer t_sofCheck;
|
||||
unsigned timeLastEdge;
|
||||
unsigned timeNextEdge;
|
||||
@@ -365,6 +425,13 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
i_pll_ref.toggle();
|
||||
#endif
|
||||
|
||||
#endif /* (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) */
|
||||
|
||||
#if PAWPAW_INOUTHID
|
||||
XUD_SetReady_In(ep_hid, g_hidData_in, PAWPAW_CFG_HID_IN_BUFSIZE);// 上行
|
||||
XUD_SetReady_Out(ep_hid_out,g_hidData_out);// 下行
|
||||
#endif //#if PAWPAW_INOUTHID
|
||||
|
||||
while(1)
|
||||
{
|
||||
XUD_Result_t result;
|
||||
@@ -427,7 +494,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
/* Reset FB */
|
||||
/* Note, Endpoint 0 will hold off host for a sufficient period to allow our feedback
|
||||
* to stabilise (i.e. sofCount == 128 to fire) */
|
||||
sofCount = 1;
|
||||
sofCount = 0;
|
||||
clocks = 0;
|
||||
clockcounter = 0;
|
||||
mod_from_last_time = 0;
|
||||
@@ -450,7 +517,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
masterClockFreq = MCLK_441;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* (MAX_FREQ != MIN_FREQ) */
|
||||
/* Ideally we want to wait for handshake (and pass back up) here. But we cannot keep this
|
||||
* core locked, it must stay responsive to packets (MIDI etc) and SOFs. So, set a flag and check for
|
||||
* handshake elsewhere */
|
||||
@@ -502,13 +569,13 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
}
|
||||
#endif
|
||||
/* Pass on sample freq change to decouple() via global flag (saves a chanend) */
|
||||
/* Note: freqChange flags now used to communicate other commands also */
|
||||
/* Note: freqChange_flag now used to communicate other commands also */
|
||||
SET_SHARED_GLOBAL0(g_freqChange, cmd); /* Set command */
|
||||
SET_SHARED_GLOBAL(g_freqChange_flag, cmd); /* Set Flag */
|
||||
}
|
||||
break;
|
||||
}
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) && (!XUA_USE_SW_PLL)
|
||||
case t_sofCheck when timerafter(timeNextEdge) :> void:
|
||||
i_pll_ref.toggle();
|
||||
timeLastEdge = timeNextEdge;
|
||||
@@ -523,28 +590,61 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
/* SOF notification from XUD_Manager() */
|
||||
case inuint_byref(c_sof, u_tmp):
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
/* This really could (should) be done in decouple. However, for a quick demo this is okay
|
||||
* Decouple expects a 16:16 number in fixed point stored in the global g_speed */
|
||||
unsigned usbSpeed;
|
||||
int framesPerSec;
|
||||
GET_SHARED_GLOBAL(usbSpeed, g_curUsbSpeed);
|
||||
static int sofCount = 0;
|
||||
#if (XUA_USE_SW_PLL)
|
||||
/* Run PFD and sw_pll controller at 100Hz */
|
||||
const int sofFreqDivider = (usbSpeed == XUD_SPEED_HS) ? (8000 / controller_rate_hz) : (1000 / controller_rate_hz);
|
||||
#else /* (XUA_USE_SW_PLL) */
|
||||
/* 1000 toggles per second for CS2100 reference -> 500 Hz */
|
||||
const int toggleRateHz = 1000;
|
||||
const int sofFreqDivider = (usbSpeed == XUD_SPEED_HS) ? (8000 / toggleRateHz) : (1000 / toggleRateHz);
|
||||
#endif /* (XUA_USE_SW_PLL) */
|
||||
|
||||
framesPerSec = (usbSpeed == XUD_SPEED_HS) ? 8000 : 1000;
|
||||
|
||||
clocks = ((int64_t) sampleFreq << 16) / framesPerSec;
|
||||
|
||||
asm volatile("stw %0, dp[g_speed]"::"r"(clocks));
|
||||
|
||||
sofCount += 1000;
|
||||
if (sofCount == framesPerSec)
|
||||
sofCount++;
|
||||
if (sofCount == sofFreqDivider)
|
||||
{
|
||||
#if (XUA_USE_SW_PLL)
|
||||
/* Grab port timer count, run through PFD and send to sw_pll */
|
||||
unsigned short mclk_pt;
|
||||
asm volatile("getts %0, res[%1]" : "=r" (mclk_pt) : "r" (p_off_mclk));
|
||||
|
||||
uint8_t first_loop = 0;
|
||||
unsafe{
|
||||
sw_pll_calc_error_from_port_timers(&sw_pll_pfd, &first_loop, mclk_pt, 0);
|
||||
}
|
||||
|
||||
int error = 0;
|
||||
if(!first_loop)
|
||||
{
|
||||
error = sw_pll_pfd.mclk_diff;
|
||||
}
|
||||
sw_pll_pfd.mclk_pt_last = mclk_pt;
|
||||
|
||||
/* Send error to sw_pll */
|
||||
outuint(c_sw_pll, error);
|
||||
outct(c_sw_pll, XS1_CT_END);
|
||||
|
||||
#else /* (XUA_USE_SW_PLL) */
|
||||
/* Do toggle for CS2100 reference clock */
|
||||
/* Port is accessed via interface to allow flexibilty with location */
|
||||
i_pll_ref.toggle();
|
||||
t_sofCheck :> timeLastEdge;
|
||||
sofCount = 0;
|
||||
timeNextEdge = timeLastEdge + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
|
||||
#endif /* (XUA_USE_SW_PLL) */
|
||||
sofCount = 0;
|
||||
}
|
||||
|
||||
/* This really could (should) be done in decouple. However, for a quick demo this is okay
|
||||
* Decouple expects a 16:16 number in fixed point stored in the global g_speed */
|
||||
|
||||
const int framesPerSec = (usbSpeed == XUD_SPEED_HS) ? 8000 : 1000;
|
||||
|
||||
clocks = ((int64_t) sampleFreq << 16) / framesPerSec;
|
||||
asm volatile("stw %0, dp[g_speed]"::"r"(clocks));
|
||||
|
||||
|
||||
#elif (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC)
|
||||
|
||||
/* NOTE our feedback will be wrong for a couple of SOF's after a SF change due to
|
||||
@@ -646,7 +746,6 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
clockcounter = 0;
|
||||
}
|
||||
#else
|
||||
|
||||
/* Assuming 48kHz from a 24.576 master clock (0.0407uS period)
|
||||
* MCLK ticks per SOF = 125uS / 0.0407 = 3072 MCLK ticks per SOF.
|
||||
* expected Feedback is 48000/8000 = 6 samples. so 0x60000 in 16:16 format.
|
||||
@@ -691,7 +790,6 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
clocks < (expected_fb + FB_TOLERANCE))
|
||||
#endif
|
||||
{
|
||||
int usb_speed;
|
||||
asm volatile("stw %0, dp[g_speed]"::"r"(clocks)); // g_speed = clocks
|
||||
|
||||
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
|
||||
@@ -897,8 +995,8 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
/* HID Report Data */
|
||||
#if (XUA_HID_ENABLED)
|
||||
/* HID Report Data */
|
||||
case XUD_SetData_Select(c_hid, ep_hid, result):
|
||||
hid_ready_flag = 0U;
|
||||
unsigned reportTime;
|
||||
@@ -910,8 +1008,33 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
#if PAWPAW_INOUTHID
|
||||
case XUD_SetData_Select(c_hid, ep_hid, result):
|
||||
{
|
||||
/* 通过HID上报DATA给PC端 */
|
||||
hid_to_host_buf(g_hidData_in);
|
||||
|
||||
XUD_SetReady_In(ep_hid, g_hidData_in, set_hid_up_size);
|
||||
}
|
||||
break;
|
||||
|
||||
#if (HID_OUT_REQUIRED)
|
||||
case XUD_GetData_Select(c_hid_out, ep_hid_out,length, result):
|
||||
{
|
||||
XUD_SetReady_Out(ep_hid_out,g_hidData_out);
|
||||
|
||||
/* 从PC端,HID获取数据给到XMOS */
|
||||
hid_from_host_buf(g_hidData_out);
|
||||
|
||||
}
|
||||
break;
|
||||
#endif //#if (HID_OUT_REQUIRED)
|
||||
|
||||
#endif//#if PAWPAW_INOUTHID
|
||||
|
||||
#ifdef MIDI
|
||||
/* Received word from MIDI thread - Check for ACK or Data */
|
||||
/* Received word from MIDI thread - Check for ACK or Data */
|
||||
case midi_get_ack_or_data(c_midi, is_ack, datum):
|
||||
if (is_ack)
|
||||
{
|
||||
@@ -963,6 +1086,33 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
|
||||
break;
|
||||
#endif /* ifdef MIDI */
|
||||
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
case c_audio_rate_change :> u_tmp:
|
||||
unsigned selected_mclk_rate = u_tmp;
|
||||
c_audio_rate_change :> u_tmp; /* Sample rate is discarded as only care about mclk */
|
||||
#if (XUA_USE_SW_PLL)
|
||||
sw_pll_pfd_init(&sw_pll_pfd,
|
||||
1, /* How often the PFD is invoked per call */
|
||||
selected_mclk_rate / controller_rate_hz, /* pll muliplication ratio integer */
|
||||
0, /* Assume precise timing of sampling */
|
||||
pfd_ppm_max);
|
||||
restart_sigma_delta(c_sw_pll, selected_mclk_rate);
|
||||
/* Delay ACK until sw_pll says it is ready */
|
||||
#else
|
||||
c_audio_rate_change <: 0; /* ACK back to audio to release I2S immediately */
|
||||
#endif /* XUA_USE_SW_PLL */
|
||||
break;
|
||||
|
||||
#if (XUA_USE_SW_PLL)
|
||||
/* This is fired when sw_pll has completed initialising a new mclk_rate */
|
||||
case inuint_byref(c_sw_pll, u_tmp):
|
||||
inct(c_sw_pll);
|
||||
c_audio_rate_change <: 0; /* ACK back to audio to release */
|
||||
|
||||
break;
|
||||
#endif /* (XUA_USE_SW_PLL) */
|
||||
#endif /* (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) */
|
||||
|
||||
#ifdef IAP
|
||||
/* Received word from iap thread - Check for ACK or Data */
|
||||
case iap_get_ack_or_reset_or_data(c_iap, is_ack_iap, is_reset, datum_iap):
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#include <xs1.h>
|
||||
#include <assert.h>
|
||||
#include <print.h>
|
||||
@@ -13,24 +12,24 @@
|
||||
#include "spdif.h"
|
||||
#endif
|
||||
|
||||
#define LOCAL_CLOCK_INCREMENT 166667
|
||||
#define LOCAL_CLOCK_MARGIN 1666
|
||||
#define LOCAL_CLOCK_INCREMENT (166667)
|
||||
#define LOCAL_CLOCK_MARGIN (1666)
|
||||
|
||||
#define MAX_SAMPLES 64 /* Must be power of 2 */
|
||||
#define MAX_SAMPLES (64) /* Must be power of 2 */
|
||||
#define MAX_SPDIF_SAMPLES (2 * MAX_SAMPLES) /* Must be power of 2 */
|
||||
#define MAX_ADAT_SAMPLES (8 * MAX_SAMPLES) /* Must be power of 2 */
|
||||
|
||||
#define SPDIF_FRAME_ERRORS_THRESH 40
|
||||
#define SPDIF_FRAME_ERRORS_THRESH (40)
|
||||
|
||||
unsigned g_digData[10];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int receivedSamples;
|
||||
int samples;
|
||||
int savedSamples;
|
||||
int lastDiff;
|
||||
unsigned identicaldiffs;
|
||||
int receivedSamples; /* Uses by clockgen to count number of dig rx samples to ascertain clock specs */
|
||||
int samples; /* Raw sample count - rolling int and never reset */
|
||||
int savedSamples; /* Used by validSamples() to store state of last raw sample count */
|
||||
int lastDiff; /* Used by validSamples() to store state of last sample count diff */
|
||||
unsigned identicaldiffs; /* Used by validSamples() to store state of number of identical diffs */
|
||||
int samplesPerTick;
|
||||
} Counter;
|
||||
|
||||
@@ -39,6 +38,7 @@ static int clockValid[NUM_CLOCKS]; /* Store current val
|
||||
static int clockInt[NUM_CLOCKS]; /* Interupt flag for clocks */
|
||||
static int clockId[NUM_CLOCKS];
|
||||
|
||||
|
||||
[[distributable]]
|
||||
void PllRefPinTask(server interface pll_ref_if i_pll_ref, out port p_pll_ref)
|
||||
{
|
||||
@@ -88,27 +88,10 @@ static int abs(int x)
|
||||
return x;
|
||||
}
|
||||
|
||||
static int channelContainsControlToken(chanend x)
|
||||
{
|
||||
unsigned char tmpc;
|
||||
|
||||
select
|
||||
{
|
||||
case inct_byref(x, tmpc):
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void outInterrupt(chanend c_interruptControl, int value)
|
||||
{
|
||||
/* Non-blocking check for control token */
|
||||
//if (channelContainsControlToken(c_interruptControl))
|
||||
{
|
||||
outuint(c_interruptControl, value);
|
||||
outct(c_interruptControl, XS1_CT_END);
|
||||
}
|
||||
outuint(c_interruptControl, value);
|
||||
outct(c_interruptControl, XS1_CT_END);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -141,9 +124,6 @@ static inline void setClockValidity(chanend c_interruptControl, int clkIndex, in
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Returns 1 for valid clock found else 0 */
|
||||
static inline int validSamples(Counter &counter, int clockIndex)
|
||||
{
|
||||
@@ -210,7 +190,7 @@ static inline int validSamples(Counter &counter, int clockIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else /* No valid frequency found - reset state */
|
||||
{
|
||||
counter.identicaldiffs = 0;
|
||||
counter.lastDiff = diff;
|
||||
@@ -219,16 +199,11 @@ static inline int validSamples(Counter &counter, int clockIndex)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
//:badParity
|
||||
/* Returns 1 for bad parity, else 0 */
|
||||
static inline int badParity(unsigned x)
|
||||
#if XUA_USE_SW_PLL
|
||||
unsafe
|
||||
{
|
||||
unsigned X = (x>>4);
|
||||
crc32(X, 0, 1);
|
||||
return X & 1;
|
||||
unsigned * unsafe selected_mclk_rate_ptr = NULL;
|
||||
}
|
||||
//:
|
||||
#endif
|
||||
|
||||
#ifdef LEVEL_METER_LEDS
|
||||
@@ -241,20 +216,42 @@ extern int samples_to_host_inputs_buff[NUM_USB_CHAN_IN];
|
||||
int VendorAudCoreReqs(unsigned cmd, chanend c);
|
||||
|
||||
#pragma unsafe arrays
|
||||
//#if (AUDIO_IO_TILE == PLL_REF_TILE)
|
||||
#if 0
|
||||
void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, out port p, chanend c_dig_rx, chanend c_clk_ctl, chanend c_clk_int)
|
||||
#else
|
||||
void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interface pll_ref_if i_pll_ref, chanend c_dig_rx, chanend c_clk_ctl, chanend c_clk_int)
|
||||
void clockGen ( streaming chanend ?c_spdif_rx,
|
||||
chanend ?c_adat_rx,
|
||||
client interface pll_ref_if i_pll_ref,
|
||||
chanend c_dig_rx,
|
||||
chanend c_clk_ctl,
|
||||
chanend c_clk_int,
|
||||
chanend c_audio_rate_change
|
||||
#if XUA_USE_SW_PLL
|
||||
, port p_for_mclk_count_aud
|
||||
, chanend c_sw_pll
|
||||
#endif
|
||||
)
|
||||
{
|
||||
timer t_local;
|
||||
unsigned timeNextEdge, timeLastEdge, timeNextClockDetection;
|
||||
unsigned clkMode = CLOCK_INTERNAL; /* Current clocking mode in operation */
|
||||
unsigned tmp;
|
||||
|
||||
/* start in no-SMUX (8-channel) mode */
|
||||
int smux = 0;
|
||||
/* Start in no-SMUX (8-channel) mode */
|
||||
int smux;
|
||||
// Initialise smux based based on the DEFAULT_FREQ
|
||||
if(DEFAULT_FREQ < 88200)
|
||||
{
|
||||
/* No SMUX */
|
||||
smux = 0;
|
||||
}
|
||||
else if(DEFAULT_FREQ < 176400)
|
||||
{
|
||||
/* SMUX */
|
||||
smux = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* SMUX II */
|
||||
smux = 2;
|
||||
}
|
||||
|
||||
#ifdef LEVEL_METER_LEDS
|
||||
timer t_level;
|
||||
@@ -263,20 +260,31 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
timer t_external;
|
||||
unsigned selected_mclk_rate = MCLK_48; // Assume 24.576MHz initial clock
|
||||
unsigned selected_sample_rate = 0;
|
||||
#if XUA_USE_SW_PLL
|
||||
|
||||
unsigned mclks_per_sample = 0;
|
||||
unsigned short mclk_time_stamp = 0;
|
||||
|
||||
/* Get MCLK count */
|
||||
asm volatile(" getts %0, res[%1]" : "=r" (mclk_time_stamp) : "r" (p_for_mclk_count_aud));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
/* S/PDIF buffer state */
|
||||
int spdifSamples[MAX_SPDIF_SAMPLES]; /* S/PDIF sample buffer */
|
||||
int spdifWr = 0; /* Write index */
|
||||
int spdifRd = 0; /* Read index */ //(spdifWriteIndex ^ (MAX_SPDIF_SAMPLES >> 1)) & ~1; // Start in middle
|
||||
int spdifOverflow = 0; /* Overflow/undeflow flags */
|
||||
int spdifSamples[MAX_SPDIF_SAMPLES]; /* S/PDIF sample buffer */
|
||||
int spdifWr = 0; /* Write index */
|
||||
int spdifRd = 0; /* Read index */ //(spdifWriteIndex ^ (MAX_SPDIF_SAMPLES >> 1)) & ~1; // Start in middle
|
||||
int spdifOverflow = 0; /* Overflow/undeflow flags */
|
||||
int spdifUnderflow = 1;
|
||||
int spdifSamps = 0; /* Number of samples in buffer */
|
||||
Counter spdifCounters;
|
||||
int spdifReceivedTime;
|
||||
int spdifRxTime;
|
||||
unsigned tmp2;
|
||||
unsigned spdifLeft = 0;
|
||||
unsigned spdifRxData;
|
||||
#endif
|
||||
|
||||
#if (XUA_ADAT_RX_EN)
|
||||
@@ -301,21 +309,21 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
}
|
||||
|
||||
/* Init clock unit state */
|
||||
clockFreq[CLOCK_INTERNAL] = 0;
|
||||
clockId[CLOCK_INTERNAL] = ID_CLKSRC_INT;
|
||||
clockValid[CLOCK_INTERNAL] = 0;
|
||||
clockInt[CLOCK_INTERNAL] = 0;
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
clockFreq[CLOCK_SPDIF_INDEX] = 0;
|
||||
clockValid[CLOCK_SPDIF_INDEX] = 0;
|
||||
clockInt[CLOCK_SPDIF_INDEX] = 0;
|
||||
clockId[CLOCK_SPDIF_INDEX] = ID_CLKSRC_SPDIF;
|
||||
clockFreq[CLOCK_SPDIF] = 0;
|
||||
clockValid[CLOCK_SPDIF] = 0;
|
||||
clockInt[CLOCK_SPDIF] = 0;
|
||||
clockId[CLOCK_SPDIF] = ID_CLKSRC_SPDIF;
|
||||
#endif
|
||||
clockFreq[CLOCK_INTERNAL_INDEX] = 0;
|
||||
clockId[CLOCK_INTERNAL_INDEX] = ID_CLKSRC_INT;
|
||||
clockValid[CLOCK_INTERNAL_INDEX] = 0;
|
||||
clockInt[CLOCK_INTERNAL_INDEX] = 0;
|
||||
#if (XUA_ADAT_RX_EN)
|
||||
clockFreq[CLOCK_ADAT_INDEX] = 0;
|
||||
clockInt[CLOCK_ADAT_INDEX] = 0;
|
||||
clockValid[CLOCK_ADAT_INDEX] = 0;
|
||||
clockId[CLOCK_ADAT_INDEX] = ID_CLKSRC_ADAT;
|
||||
clockFreq[CLOCK_ADAT] = 0;
|
||||
clockInt[CLOCK_ADAT] = 0;
|
||||
clockValid[CLOCK_ADAT] = 0;
|
||||
clockId[CLOCK_ADAT] = ID_CLKSRC_ADAT;
|
||||
#endif
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
spdifCounters.receivedSamples = 0;
|
||||
@@ -335,7 +343,6 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
adatCounters.samplesPerTick = 0;
|
||||
#endif
|
||||
|
||||
|
||||
t_local :> timeNextEdge;
|
||||
timeLastEdge = timeNextEdge;
|
||||
timeNextClockDetection = timeNextEdge + (LOCAL_CLOCK_INCREMENT / 2);
|
||||
@@ -354,6 +361,12 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
/* Initial ref clock output and get timestamp */
|
||||
i_pll_ref.init();
|
||||
|
||||
#if ((XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN) && XUA_USE_SW_PLL)
|
||||
int reset_sw_pll_pfd = 1;
|
||||
int require_ack_to_audio = 0;
|
||||
restart_sigma_delta(c_sw_pll, MCLK_48); /* default to 48kHz - this will be reset shortly when host selects rate */
|
||||
#endif
|
||||
|
||||
while(1)
|
||||
{
|
||||
select
|
||||
@@ -395,8 +408,8 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
break;
|
||||
#endif
|
||||
|
||||
/* Updates to clock settings from endpoint 0 */
|
||||
case inuint_byref(c_clk_ctl, tmp):
|
||||
/* Updates to clock settings from endpoint 0 */
|
||||
case inuint_byref(c_clk_ctl, tmp):
|
||||
switch(tmp)
|
||||
{
|
||||
case GET_SEL:
|
||||
@@ -410,13 +423,9 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
|
||||
case SET_SEL:
|
||||
/* Update clock mode */
|
||||
tmp = inuint(c_clk_ctl);
|
||||
clkMode = inuint(c_clk_ctl);
|
||||
chkct(c_clk_ctl, XS1_CT_END);
|
||||
|
||||
if(tmp!=0)
|
||||
{
|
||||
clkMode = tmp;
|
||||
}
|
||||
#ifdef CLOCK_VALIDITY_CALL
|
||||
switch(clkMode)
|
||||
{
|
||||
@@ -425,12 +434,12 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
break;
|
||||
#if (XUA_ADAT_RX_EN)
|
||||
case CLOCK_ADAT:
|
||||
VendorClockValidity(clockValid[CLOCK_ADAT_INDEX]);
|
||||
VendorClockValidity(clockValid[CLOCK_ADAT]);
|
||||
break;
|
||||
#endif
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
case CLOCK_SPDIF:
|
||||
VendorClockValidity(clockValid[CLOCK_SPDIF_INDEX]);
|
||||
VendorClockValidity(clockValid[CLOCK_SPDIF]);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
@@ -470,14 +479,17 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
/* Generate local clock from timer */
|
||||
case t_local when timerafter(timeNextEdge) :> void:
|
||||
|
||||
#if XUA_USE_SW_PLL
|
||||
/* Do nothing - hold the most recent sw_pll setting */
|
||||
#else
|
||||
/* Setup next local clock edge */
|
||||
i_pll_ref.toggle_timed(0);
|
||||
|
||||
#endif
|
||||
/* Record time of edge */
|
||||
timeLastEdge = timeNextEdge;
|
||||
|
||||
@@ -504,58 +516,89 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
case t_external when timerafter(timeNextClockDetection) :> void:
|
||||
|
||||
timeNextClockDetection += (LOCAL_CLOCK_INCREMENT);
|
||||
{
|
||||
int valid;
|
||||
timeNextClockDetection += (LOCAL_CLOCK_INCREMENT);
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
tmp = spdifCounters.samplesPerTick;
|
||||
|
||||
/* Returns 1 if valid clock found */
|
||||
tmp = validSamples(spdifCounters, CLOCK_SPDIF_INDEX);
|
||||
setClockValidity(c_clk_int, CLOCK_SPDIF_INDEX, tmp, clkMode);
|
||||
/* Returns 1 if valid clock found */
|
||||
valid = validSamples(spdifCounters, CLOCK_SPDIF);
|
||||
setClockValidity(c_clk_int, CLOCK_SPDIF, valid, clkMode);
|
||||
#endif
|
||||
#if (XUA_ADAT_RX_EN)
|
||||
tmp = validSamples(adatCounters, CLOCK_ADAT_INDEX);
|
||||
setClockValidity(c_clk_int, CLOCK_ADAT_INDEX, tmp, clkMode);
|
||||
/* Returns 1 if valid clock found */
|
||||
valid = validSamples(adatCounters, CLOCK_ADAT);
|
||||
setClockValidity(c_clk_int, CLOCK_ADAT, valid, clkMode);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if ((XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN) && XUA_USE_SW_PLL)
|
||||
case inuint_byref(c_sw_pll, tmp):
|
||||
inct(c_sw_pll);
|
||||
/* Send ACK back to audiohub to allow I2S to start
|
||||
This happens only on SDM restart and only once */
|
||||
if(require_ack_to_audio)
|
||||
{
|
||||
c_audio_rate_change <: tmp;
|
||||
require_ack_to_audio = 0;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
/* Receive notification of audio streaming settings change and store */
|
||||
case c_audio_rate_change :> selected_mclk_rate:
|
||||
c_audio_rate_change :> selected_sample_rate;
|
||||
#if XUA_USE_SW_PLL
|
||||
mclks_per_sample = selected_mclk_rate / selected_sample_rate;
|
||||
restart_sigma_delta(c_sw_pll, selected_mclk_rate);
|
||||
reset_sw_pll_pfd = 1;
|
||||
/* We will shedule an ACK when sigma delta is up and running */
|
||||
require_ack_to_audio = 1;
|
||||
#else
|
||||
/* Send ACK immediately as we are good to go if not using SW_PLL */
|
||||
c_audio_rate_change <: 0;
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
/* Receive sample from S/PDIF RX thread (steaming chan) */
|
||||
case c_spdif_rx :> tmp:
|
||||
/* Receive sample from S/PDIF RX thread (streaming chan) */
|
||||
case c_spdif_rx :> spdifRxData:
|
||||
|
||||
#if XUA_USE_SW_PLL
|
||||
/* Record time of sample */
|
||||
t_local :> spdifReceivedTime;
|
||||
asm volatile(" getts %0, res[%1]" : "=r" (mclk_time_stamp) : "r" (p_for_mclk_count_aud));
|
||||
#endif
|
||||
t_local :> spdifRxTime;
|
||||
|
||||
/* Check parity and ignore if bad */
|
||||
if(badParity(tmp))
|
||||
if(spdif_rx_check_parity(spdifRxData))
|
||||
continue;
|
||||
|
||||
/* Get pre-amble */
|
||||
tmp2 = tmp & 0xF;
|
||||
switch(tmp2)
|
||||
/* Get preamble */
|
||||
unsigned preamble = spdifRxData & SPDIF_RX_PREAMBLE_MASK;
|
||||
|
||||
switch(preamble)
|
||||
{
|
||||
/* LEFT */
|
||||
case SPDIF_FRAME_X:
|
||||
case SPDIF_FRAME_Z:
|
||||
|
||||
spdifLeft = tmp << 4;
|
||||
spdifLeft = SPDIF_RX_EXTRACT_SAMPLE(spdifRxData);
|
||||
break;
|
||||
|
||||
/* RIGHT */
|
||||
case SPDIF_FRAME_Y:
|
||||
|
||||
/* Only store sample if not in overflow and stream is reasonably valid */
|
||||
if(!spdifOverflow && clockValid[CLOCK_SPDIF_INDEX])
|
||||
if(!spdifOverflow && clockValid[CLOCK_SPDIF])
|
||||
{
|
||||
/* Store left and right sample pair to buffer */
|
||||
spdifSamples[spdifWr] = spdifLeft;
|
||||
spdifSamples[spdifWr+1] = tmp << 4;
|
||||
spdifSamples[spdifWr+1] = SPDIF_RX_EXTRACT_SAMPLE(spdifRxData);
|
||||
|
||||
spdifWr = (spdifWr + 2) & (MAX_SPDIF_SAMPLES - 1);
|
||||
|
||||
@@ -583,7 +626,7 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
|
||||
spdifCounters.samples += 1;
|
||||
|
||||
if(clkMode == CLOCK_SPDIF && clockValid[CLOCK_SPDIF_INDEX])
|
||||
if(clkMode == CLOCK_SPDIF && clockValid[CLOCK_SPDIF])
|
||||
{
|
||||
spdifCounters.receivedSamples+=1;
|
||||
|
||||
@@ -591,17 +634,24 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
if((spdifCounters.receivedSamples >= spdifCounters.samplesPerTick))
|
||||
{
|
||||
/* Check edge is about right... S/PDIF may have changed freq... */
|
||||
if(timeafter(spdifReceivedTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN)))
|
||||
if(timeafter(spdifRxTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN)))
|
||||
{
|
||||
/* Record edge time */
|
||||
timeLastEdge = spdifReceivedTime;
|
||||
timeLastEdge = spdifRxTime;
|
||||
|
||||
/* Setup for next edge */
|
||||
timeNextEdge = spdifReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
|
||||
timeNextEdge = spdifRxTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
|
||||
|
||||
#if XUA_USE_SW_PLL
|
||||
do_sw_pll_phase_frequency_detector_dig_rx( mclk_time_stamp,
|
||||
mclks_per_sample,
|
||||
c_sw_pll,
|
||||
spdifCounters.receivedSamples,
|
||||
reset_sw_pll_pfd);
|
||||
#else
|
||||
/* Toggle edge */
|
||||
i_pll_ref.toggle_timed(1);
|
||||
|
||||
#endif
|
||||
/* Reset counters */
|
||||
spdifCounters.receivedSamples = 0;
|
||||
}
|
||||
@@ -612,7 +662,11 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
#if (XUA_ADAT_RX_EN)
|
||||
/* receive sample from ADAT rx thread (streaming channel with CT_END) */
|
||||
case inuint_byref(c_adat_rx, tmp):
|
||||
|
||||
#if XUA_USE_SW_PLL
|
||||
/* record time of sample */
|
||||
asm volatile(" getts %0, res[%1]" : "=r" (mclk_time_stamp) : "r" (p_for_mclk_count_aud));
|
||||
#endif
|
||||
t_local :> adatReceivedTime;
|
||||
|
||||
/* Sync is: 1 | (user_byte << 4) */
|
||||
@@ -632,7 +686,7 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
if (adatChannel == 8)
|
||||
{
|
||||
/* only store left samples if not in overflow and stream is reasonably valid */
|
||||
if (!adatOverflow && clockValid[CLOCK_ADAT_INDEX])
|
||||
if (!adatOverflow && clockValid[CLOCK_ADAT])
|
||||
{
|
||||
/* Unpick the SMUX.. */
|
||||
if(smux == 2)
|
||||
@@ -685,11 +739,18 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
}
|
||||
}
|
||||
}
|
||||
if(adatChannel == 4 || adatChannel == 8)
|
||||
|
||||
/* An edge needs to be recorded/toggled in the following cases:
|
||||
* smux = 0: adatChannel = 4, 8
|
||||
* smux = 1: adatChannel = 2, 4, 6, 8
|
||||
* smux = 2: adatChannel = 1, 2, 3, 4, 5, 6, 7, 8
|
||||
* This is simplified to a shift-and-mask in the if-condition below.
|
||||
*/
|
||||
if ((adatChannel != 0) && ((adatChannel << smux) & 3) == 0)
|
||||
{
|
||||
adatCounters.samples += 1;
|
||||
|
||||
if (clkMode == CLOCK_ADAT && clockValid[CLOCK_ADAT_INDEX])
|
||||
if (clkMode == CLOCK_ADAT && clockValid[CLOCK_ADAT])
|
||||
{
|
||||
adatCounters.receivedSamples += 1;
|
||||
|
||||
@@ -705,12 +766,19 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
/* Setup for next edge */
|
||||
timeNextEdge = adatReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
|
||||
|
||||
#if XUA_USE_SW_PLL
|
||||
do_sw_pll_phase_frequency_detector_dig_rx( mclk_time_stamp,
|
||||
mclks_per_sample,
|
||||
c_sw_pll,
|
||||
adatCounters.receivedSamples,
|
||||
reset_sw_pll_pfd);
|
||||
#else
|
||||
/* Toggle edge */
|
||||
i_pll_ref.toggle_timed(1);
|
||||
#endif
|
||||
|
||||
/* Reset counters */
|
||||
adatCounters.receivedSamples = 0;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -719,12 +787,11 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
adatChannel = 0;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#endif // XUA_ADAT_RX_EN
|
||||
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
/* Mixer requests data */
|
||||
case inuint_byref(c_dig_rx, tmp):
|
||||
/* AudioHub requests data */
|
||||
case inuint_byref(c_dig_rx, tmp):
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
if(spdifUnderflow)
|
||||
{
|
||||
@@ -739,7 +806,7 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
tmp2 = spdifSamples[spdifRd + 1];
|
||||
|
||||
spdifRd += 2;
|
||||
spdifRd &= (MAX_SPDIF_SAMPLES - 1);
|
||||
spdifRd &= (MAX_SPDIF_SAMPLES - 1);
|
||||
|
||||
g_digData[0] = tmp;
|
||||
g_digData[1] = tmp2;
|
||||
@@ -747,7 +814,7 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
spdifSamps -= 2;
|
||||
|
||||
/* spdifSamps could go to -1 */
|
||||
if(spdifSamps < 0)
|
||||
if(spdifSamps <= 0)
|
||||
{
|
||||
/* We're out of S/PDIF samples, mark underflow condition */
|
||||
spdifUnderflow = 1;
|
||||
@@ -761,7 +828,6 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
spdifOverflow = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#if (XUA_ADAT_RX_EN)
|
||||
if (adatUnderflow)
|
||||
@@ -829,7 +895,7 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
}
|
||||
|
||||
/* adatSamps could go to -1 */
|
||||
if (adatSamps < 0)
|
||||
if (adatSamps <= 0)
|
||||
{
|
||||
/* we're out of ADAT samples, mark underflow condition */
|
||||
adatUnderflow = 1;
|
||||
@@ -844,11 +910,9 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
||||
}
|
||||
#endif
|
||||
outuint(c_dig_rx, 1);
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} /* select */
|
||||
} /* while(1) */
|
||||
} /* clkgen task scope */
|
||||
|
||||
|
||||
57
lib_xua/src/core/clocking/sw_pll_wrapper.h
Normal file
57
lib_xua/src/core/clocking/sw_pll_wrapper.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#ifndef _SW_PLL_WRAPPPER_H_
|
||||
#define _SW_PLL_WRAPPPER_H_
|
||||
|
||||
#include "xua.h"
|
||||
|
||||
#if XUA_USE_SW_PLL
|
||||
extern "C"
|
||||
{
|
||||
#include "sw_pll.h"
|
||||
}
|
||||
|
||||
/* Special control value to disable SDM. Outside of normal range which is less than 16b.*/
|
||||
#define DISABLE_SDM 0x10000000
|
||||
|
||||
|
||||
/** Task that receives an error term, passes it through a PI controller and periodically
|
||||
* calclulates a sigma delta output value and sends it to the PLL fractional register.
|
||||
*
|
||||
* \param c_sw_pll Channel connected to the clocking thread to pass raw error terms.
|
||||
*/
|
||||
void sw_pll_task(chanend c_sw_pll);
|
||||
|
||||
/** Helper function that sends a special restart command. It causes the SDM task
|
||||
* to quit and restart using the new mclk.
|
||||
*
|
||||
* \param c_sw_pll Channel connected to the clocking thread to pass raw error terms.
|
||||
* \param mclk_Rate The mclk frequency in Hz.
|
||||
*/
|
||||
void restart_sigma_delta(chanend c_sw_pll, unsigned mclk_rate);
|
||||
|
||||
/** Performs a frequency comparsion between the incoming digital Rx stream and the local mclk.
|
||||
*
|
||||
* \param mclk_time_stamp The captured mclk count (using port timer) at the time of sample Rx.
|
||||
* \param mclks_per_sample The nominal number of mclks per audio sample.
|
||||
* \param c_sw_pll Channel connected to the sigma delta and controller thread.
|
||||
* \param receivedSamples The number of received samples since tha last call to this function.
|
||||
* \param reset_sw_pll_pfd Reference to a flag which will be used to signal reset of this function's state.
|
||||
*/
|
||||
void do_sw_pll_phase_frequency_detector_dig_rx( unsigned short mclk_time_stamp,
|
||||
unsigned mclks_per_sample,
|
||||
chanend c_sw_pll,
|
||||
int receivedSamples,
|
||||
int &reset_sw_pll_pfd);
|
||||
|
||||
/** Initilaises the software PLL both hardware and state. Sets the mclk frequency to a nominal point.
|
||||
*
|
||||
* \param sw_pll Reference to a software pll state struct to be initialised.
|
||||
* \param mClk The current nominal mClk frequency.
|
||||
*
|
||||
* returns The SDM update interval in ticks and the initial DCO setting for nominal frequency */
|
||||
{unsigned, unsigned} InitSWPLL(sw_pll_state_t &sw_pll, unsigned mClk);
|
||||
|
||||
#endif /* XUA_USE_SW_PLL */
|
||||
#endif /* _SW_PLL_WRAPPPER_H_ */
|
||||
202
lib_xua/src/core/clocking/sw_pll_wrapper.xc
Normal file
202
lib_xua/src/core/clocking/sw_pll_wrapper.xc
Normal file
@@ -0,0 +1,202 @@
|
||||
// Copyright 2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include <xs1.h>
|
||||
#include <assert.h>
|
||||
#include <print.h>
|
||||
|
||||
#include "sw_pll_wrapper.h"
|
||||
#include "xua.h"
|
||||
|
||||
#if XUA_USE_SW_PLL
|
||||
|
||||
|
||||
{unsigned, unsigned} init_sw_pll(sw_pll_state_t &sw_pll, unsigned mClk)
|
||||
{
|
||||
/* Autogenerated SDM App PLL setup by dco_model.py using 22.5792_1M profile */
|
||||
/* Input freq: 24000000
|
||||
F: 134
|
||||
R: 0
|
||||
f: 8
|
||||
p: 18
|
||||
OD: 5
|
||||
ACD: 5
|
||||
*/
|
||||
|
||||
#define APP_PLL_CTL_REG_22 0x0A808600
|
||||
#define APP_PLL_DIV_REG_22 0x80000005
|
||||
#define APP_PLL_FRAC_REG_22 0x80000812
|
||||
#define SW_PLL_SDM_CTRL_MID_22 498283
|
||||
#define SW_PLL_SDM_RATE_22 1000000
|
||||
|
||||
/* Autogenerated SDM App PLL setup by dco_model.py using 24.576_1M profile */
|
||||
/* Input freq: 24000000
|
||||
F: 146
|
||||
R: 0
|
||||
f: 4
|
||||
p: 10
|
||||
OD: 5
|
||||
ACD: 5
|
||||
*/
|
||||
|
||||
#define APP_PLL_CTL_REG_24 0x0A809200
|
||||
#define APP_PLL_DIV_REG_24 0x80000005
|
||||
#define APP_PLL_FRAC_REG_24 0x8000040A
|
||||
#define SW_PLL_SDM_CTRL_MID_24 478151
|
||||
#define SW_PLL_SDM_RATE_24 1000000
|
||||
|
||||
|
||||
const uint32_t app_pll_ctl_reg[2] = {APP_PLL_CTL_REG_22, APP_PLL_CTL_REG_24};
|
||||
const uint32_t app_pll_div_reg[2] = {APP_PLL_DIV_REG_22, APP_PLL_DIV_REG_24};
|
||||
const uint32_t app_pll_frac_reg[2] = {APP_PLL_FRAC_REG_22, APP_PLL_FRAC_REG_24};
|
||||
const uint32_t sw_pll_sdm_ctrl_mid[2] = {SW_PLL_SDM_CTRL_MID_22, SW_PLL_SDM_CTRL_MID_24};
|
||||
const uint32_t sw_pll_sdm_rate[2] = {SW_PLL_SDM_RATE_22, SW_PLL_SDM_RATE_24};
|
||||
|
||||
const int clkIndex = mClk == MCLK_48 ? 1 : 0;
|
||||
|
||||
sw_pll_sdm_init(&sw_pll,
|
||||
SW_PLL_15Q16(0.0),
|
||||
SW_PLL_15Q16(32.0),
|
||||
SW_PLL_15Q16(0.25),
|
||||
0, /* LOOP COUNT Don't care for this API */
|
||||
0, /* PLL_RATIO Don't care for this API */
|
||||
0, /* No jitter compensation needed */
|
||||
app_pll_ctl_reg[clkIndex],
|
||||
app_pll_div_reg[clkIndex],
|
||||
app_pll_frac_reg[clkIndex],
|
||||
sw_pll_sdm_ctrl_mid[clkIndex],
|
||||
3000 /* PPM_RANGE (FOR PFD) Don't care for this API*/ );
|
||||
|
||||
/* Reset SDM too */
|
||||
sw_pll_init_sigma_delta(&sw_pll.sdm_state);
|
||||
|
||||
return {XS1_TIMER_HZ / sw_pll_sdm_rate[clkIndex], sw_pll_sdm_ctrl_mid[clkIndex]};
|
||||
}
|
||||
|
||||
void do_sw_pll_phase_frequency_detector_dig_rx( unsigned short mclk_time_stamp,
|
||||
unsigned mclks_per_sample,
|
||||
chanend c_sw_pll,
|
||||
int receivedSamples,
|
||||
int &reset_sw_pll_pfd)
|
||||
{
|
||||
const unsigned control_loop_rate_divider = 6; /* 300Hz * 2 edges / 6 -> 100Hz loop rate */
|
||||
static unsigned control_loop_counter = 0;
|
||||
static unsigned total_received_samples = 0;
|
||||
|
||||
/* Keep a store of the last mclk time stamp so we can work out the increment */
|
||||
static unsigned short last_mclk_time_stamp = 0;
|
||||
|
||||
control_loop_counter++;
|
||||
|
||||
total_received_samples += receivedSamples;
|
||||
|
||||
if(control_loop_counter == control_loop_rate_divider)
|
||||
{
|
||||
/* Calculate what the zero-error mclk count increment should be for this many samples */
|
||||
const unsigned expected_mclk_inc = mclks_per_sample * total_received_samples / 2; /* divide by 2 because this fn is called per edge */
|
||||
|
||||
/* Calculate actualy time-stamped mclk count increment is */
|
||||
const unsigned short actual_mclk_inc = mclk_time_stamp - last_mclk_time_stamp;
|
||||
|
||||
/* The difference is the raw error in terms of mclk counts */
|
||||
short f_error = (int)actual_mclk_inc - (int)expected_mclk_inc;
|
||||
if(reset_sw_pll_pfd)
|
||||
{
|
||||
f_error = 0; /* Skip first measurement as it will likely be very out */
|
||||
reset_sw_pll_pfd = 0;
|
||||
}
|
||||
|
||||
/* send PFD output to the sigma delta thread */
|
||||
outuint(c_sw_pll, (int) f_error);
|
||||
outct(c_sw_pll, XS1_CT_END);
|
||||
|
||||
last_mclk_time_stamp = mclk_time_stamp;
|
||||
control_loop_counter = 0;
|
||||
total_received_samples = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void sw_pll_task(chanend c_sw_pll){
|
||||
/* Zero is an invalid number and the SDM will not write the frac reg until
|
||||
the first control value has been received. This avoids issues with
|
||||
channel lockup if two tasks (eg. init and SDM) try to write at the same time. */
|
||||
|
||||
while(1)
|
||||
{
|
||||
unsigned selected_mclk_rate = inuint(c_sw_pll);
|
||||
inct(c_sw_pll);
|
||||
|
||||
int f_error = 0;
|
||||
int dco_setting = 0; /* gets set at init_sw_pll */
|
||||
unsigned sdm_interval = 0; /* gets set at init_sw_pll */
|
||||
sw_pll_state_t sw_pll;
|
||||
|
||||
/* initialse the SDM and gather SDM initial settings */
|
||||
{sdm_interval, dco_setting} = init_sw_pll(sw_pll, selected_mclk_rate);
|
||||
|
||||
tileref_t this_tile = get_local_tile_id();
|
||||
|
||||
timer tmr;
|
||||
int32_t time_trigger;
|
||||
tmr :> time_trigger;
|
||||
time_trigger += sdm_interval; /* ensure first loop has correct delay */
|
||||
int running = 1;
|
||||
|
||||
outuint(c_sw_pll, 0); /* Signal back via clockgen to audio to start I2S */
|
||||
outct(c_sw_pll, XS1_CT_END);
|
||||
|
||||
unsigned rx_word = 0;
|
||||
while(running)
|
||||
{
|
||||
/* Poll for new SDM control value */
|
||||
select
|
||||
{
|
||||
case inuint_byref(c_sw_pll, rx_word):
|
||||
inct(c_sw_pll);
|
||||
if(rx_word == DISABLE_SDM)
|
||||
{
|
||||
f_error = 0;
|
||||
running = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
f_error = (int32_t)rx_word;
|
||||
unsafe
|
||||
{
|
||||
sw_pll_sdm_do_control_from_error(&sw_pll, -f_error);
|
||||
dco_setting = sw_pll.sdm_state.current_ctrl_val;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Do nothing & fall-through. Above case polls only once per loop */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Wait until the timer value has been reached
|
||||
This implements a timing barrier and keeps
|
||||
the loop rate constant. */
|
||||
select
|
||||
{
|
||||
case tmr when timerafter(time_trigger) :> int _:
|
||||
time_trigger += sdm_interval;
|
||||
break;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
sw_pll_do_sigma_delta(&sw_pll.sdm_state, this_tile, dco_setting);
|
||||
}
|
||||
} /* while running */
|
||||
} /* while(1) */
|
||||
}
|
||||
|
||||
|
||||
void restart_sigma_delta(chanend c_sw_pll, unsigned selected_mclk_rate)
|
||||
{
|
||||
outuint(c_sw_pll, DISABLE_SDM); /* Resets SDM */
|
||||
outct(c_sw_pll, XS1_CT_END);
|
||||
outuint(c_sw_pll, selected_mclk_rate);
|
||||
outct(c_sw_pll, XS1_CT_END);
|
||||
}
|
||||
|
||||
#endif /* XUA_USE_SW_PLL */
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2015-2021 XMOS LIMITED.
|
||||
// Copyright 2015-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#ifndef __DESCRIPTOR_DEFS_H__
|
||||
@@ -33,6 +33,7 @@
|
||||
#define ENDPOINT_ADDRESS_OUT_MIDI (ENDPOINT_NUMBER_OUT_MIDI)
|
||||
#define ENDPOINT_ADDRESS_OUT_IAP (ENDPOINT_NUMBER_OUT_IAP)
|
||||
#define ENDPOINT_ADDRESS_OUT_IAP_EA_NATIVE_TRANS (ENDPOINT_NUMBER_OUT_IAP_EA_NATIVE_TRANS)
|
||||
#define ENDPOINT_ADDRESS_OUT_HID (ENDPOINT_NUMBER_OUT_HID)
|
||||
|
||||
/* Interface numbers enum */
|
||||
enum USBInterfaceNumber
|
||||
@@ -60,7 +61,7 @@ enum USBInterfaceNumber
|
||||
INTERFACE_NUMBER_IAP_EA_NATIVE_TRANS,
|
||||
#endif
|
||||
#endif
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
INTERFACE_NUMBER_HID,
|
||||
#endif
|
||||
INTERFACE_COUNT /* End marker */
|
||||
@@ -70,4 +71,8 @@ enum USBInterfaceNumber
|
||||
#define ENDPOINT_INT_INTERVAL_IN_HID 0x08
|
||||
#endif
|
||||
|
||||
#ifndef ENDPOINT_INT_INTERVAL_OUT_HID
|
||||
#define ENDPOINT_INT_INTERVAL_OUT_HID 0x08
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
/**
|
||||
* @brief Implements endpoint zero for an USB Audio 1.0/2.0 device
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "xc_ptr.h"
|
||||
#include "xua_ep0_uacreqs.h"
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
#include "hid.h"
|
||||
#include "xua_hid.h"
|
||||
#include "xua_hid_report.h"
|
||||
@@ -106,13 +106,17 @@ unsigned int mutesOut[NUM_USB_CHAN_OUT + 1];
|
||||
int volsIn[NUM_USB_CHAN_IN + 1];
|
||||
unsigned int mutesIn[NUM_USB_CHAN_IN + 1];
|
||||
|
||||
#ifdef MIXER
|
||||
unsigned char mixer1Crossbar[18];
|
||||
short mixer1Weights[18*8];
|
||||
#if (MIXER)
|
||||
short mixer1Weights[MIX_INPUTS * MAX_MIX_COUNT];
|
||||
|
||||
unsigned char channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT];
|
||||
//unsigned char channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT];
|
||||
/* Mapping of channels to output audio interfaces */
|
||||
unsigned char channelMapAud[NUM_USB_CHAN_OUT];
|
||||
|
||||
/* Mapping of channels to USB host */
|
||||
unsigned char channelMapUsb[NUM_USB_CHAN_IN];
|
||||
|
||||
/* Mapping of channels to Mixer(s) */
|
||||
unsigned char mixSel[MAX_MIX_COUNT][MIX_INPUTS];
|
||||
#endif
|
||||
|
||||
@@ -241,7 +245,6 @@ const unsigned g_dataFormat_In[INPUT_FORMAT_COUNT] = {STREAM_FORMAT_INPUT_1
|
||||
};
|
||||
|
||||
/* Channel count */
|
||||
/* Note, currently only input changes.. */
|
||||
const unsigned g_chanCount_In_HS[INPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_INPUT_1_CHAN_COUNT,
|
||||
#if(INPUT_FORMAT_COUNT > 1)
|
||||
HS_STREAM_FORMAT_INPUT_2_CHAN_COUNT,
|
||||
@@ -251,6 +254,15 @@ const unsigned g_chanCount_In_HS[INPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_I
|
||||
#endif
|
||||
};
|
||||
|
||||
const unsigned g_chanCount_Out_HS[OUTPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT,
|
||||
#if(OUTPUT_FORMAT_COUNT > 1)
|
||||
HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT,
|
||||
#endif
|
||||
#if(OUTPUT_FORMAT_COUNT > 2)
|
||||
HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT
|
||||
#endif
|
||||
};
|
||||
|
||||
XUD_ep ep0_out;
|
||||
XUD_ep ep0_in;
|
||||
|
||||
@@ -262,6 +274,44 @@ void XUA_Endpoint0_setVendorId(unsigned short vid) {
|
||||
#endif // AUDIO_CLASS == 1}
|
||||
}
|
||||
|
||||
#if (MIXER)
|
||||
void InitLocalMixerState()
|
||||
{
|
||||
for (int i = 0; i < MIX_INPUTS * MAX_MIX_COUNT; i++)
|
||||
{
|
||||
mixer1Weights[i] = 0x8001; //-inf
|
||||
}
|
||||
|
||||
/* Configure default connections */
|
||||
for (int i = 0; i < MAX_MIX_COUNT; i++)
|
||||
{
|
||||
mixer1Weights[(i * MAX_MIX_COUNT) + i] = 0;
|
||||
}
|
||||
|
||||
#if NUM_USB_CHAN_OUT > 0
|
||||
/* Setup up audio output channel mapping */
|
||||
for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
|
||||
{
|
||||
channelMapAud[i] = i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NUM_USB_CHAN_IN > 0
|
||||
for(int i = 0; i < NUM_USB_CHAN_IN; i++)
|
||||
{
|
||||
channelMapUsb[i] = i + NUM_USB_CHAN_OUT;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Init mixer inputs */
|
||||
for(int j = 0; j < MAX_MIX_COUNT; j++)
|
||||
for(int i = 0; i < MIX_INPUTS; i++)
|
||||
{
|
||||
mixSel[j][i] = i;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void concatenateAndCopyStrings(char* string1, char* string2, char* string_buffer) {
|
||||
debug_printf("concatenateAndCopyStrings() for \"%s\" and \"%s\"\n", string1, string2);
|
||||
|
||||
@@ -400,6 +450,99 @@ void XUA_Endpoint0_setBcdDevice(unsigned short bcd) {
|
||||
#endif // AUDIO_CLASS == 1}
|
||||
}
|
||||
|
||||
#if defined(__static_hid_report_h_exists__)
|
||||
#define hidReportDescriptorLength (sizeof(hidReportDescriptorPtr))
|
||||
static unsigned char hidReportDescriptorPtr[] = {
|
||||
#include "static_hid_report.h"
|
||||
};
|
||||
#endif
|
||||
|
||||
#if PAWPAW_INOUTHID
|
||||
#define hidReportDescriptorLength (sizeof(hidReportDescriptorPtr))
|
||||
static unsigned char hidReportDescriptorPtr[] = {
|
||||
|
||||
0x05, 0x0c, // HID_USAGE_PAGE (Vendor Defined)
|
||||
0x09, 0x01, // USAGE (Undefined)
|
||||
0xa1, 0x01, // COLLECTION (Application)
|
||||
// Report ID if any
|
||||
// 0x85, 0x01, // REPORT_ID (1) 为这个报告集合指定Report ID为1
|
||||
0x09, 0x02, // USAGE (Undefined)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, PAWPAW_CFG_HID_IN_BUFSIZE, // REPORT_COUNT (report_size)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
// Output
|
||||
0x09, 0x03, // USAGE (Undefined)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, PAWPAW_CFG_HID_OUT_BUFSIZE, // REPORT_COUNT (report_size)
|
||||
0x91, 0x02, // OUTPUT (Data,Var,Abs)
|
||||
0xc0 // END_COLLECTION
|
||||
|
||||
// 0x05, 0x0c, // HID_USAGE_PAGE (Vendor Defined)
|
||||
// 0x09, 0x01, // USAGE (Undefined)
|
||||
// 0xa1, 0x01, // COLLECTION (Application)
|
||||
// 0x85, 0x01, // REPORT_ID (1) 为这个报告集合指定Report ID为1
|
||||
// 0x09, 0x02, // USAGE (Undefined)
|
||||
// 0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
// 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||
// 0x75, 0x08, // REPORT_SIZE (8)
|
||||
// 0x95, (PAWPAW_CFG_HID_IN_BUFSIZE-1), // REPORT_COUNT (report_size)
|
||||
// 0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
// // Output
|
||||
// 0x09, 0x03, // USAGE (Undefined)
|
||||
// 0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
// 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||
// 0x75, 0x08, // REPORT_SIZE (8)
|
||||
// 0x95, (PAWPAW_CFG_HID_OUT_BUFSIZE-1), // REPORT_COUNT (report_size)
|
||||
// 0x91, 0x02, // OUTPUT (Data,Var,Abs)
|
||||
// 0xc0, // END_COLLECTION
|
||||
|
||||
// 0x05, 0x0B, // Usage Page (Telephony)
|
||||
// 0x09, 0x05, // Usage (Keypad)
|
||||
// 0xA1, 0x01, // Collection (Application)
|
||||
// 0x85, 0x02, // Report ID (2)
|
||||
// 0x15, 0x00, // Logical Minimum (0)
|
||||
// 0x25, 0x01, // Logical Maximum (1)
|
||||
// 0x95, 0x01, // Report Count (1)
|
||||
// 0x75, 0x01, // Report Size (1 bit)
|
||||
// 0x09, 0x20, // Usage (Hook Switch)
|
||||
// 0x81, 0x02, // Input (Data, Var, Abs)
|
||||
// 0x09, 0x2F, // Usage (Phone Mute)
|
||||
// 0x81, 0x06, // Input (Data, Var, Rel)
|
||||
// 0x09, 0x21, // Usage (Flash)
|
||||
// 0x81, 0x02, // Input (Data, Var, Abs)
|
||||
// 0x09, 0x24, // Usage (Redial)
|
||||
// 0x81, 0x02, // Input (Data, Var, Abs)
|
||||
// 0x95, 0x01, // Report Count (1)
|
||||
// 0x75, 0x04, // Report Size (4 bits)
|
||||
// 0x81, 0x01, // Input (Const)
|
||||
// 0x05, 0x08, // Usage Page (LEDs)
|
||||
// 0x09, 0x17, // Usage (Off-Hook)
|
||||
// 0x15, 0x00, // Logical Minimum (0)
|
||||
// 0x25, 0x01, // Logical Maximum (1)
|
||||
// 0x95, 0x01, // Report Count (1)
|
||||
// 0x75, 0x01, // Report Size (1 bit)
|
||||
// 0x91, 0x02, // Output (Data, Var, Abs)
|
||||
// 0x09, 0x09, // Usage (Message Waiting)
|
||||
// 0x91, 0x02, // Output (Data, Var, Abs)
|
||||
// 0x09, 0x18, // Usage (Ring)
|
||||
// 0x91, 0x02, // Output (Data, Var, Abs)
|
||||
// 0x09, 0x20, // Usage (Hook Switch)
|
||||
// 0x91, 0x02, // Output (Data, Var, Abs)
|
||||
// 0x95, 0x01, // Report Count (1)
|
||||
// 0x75, 0x04, // Report Size (4 bits)
|
||||
// 0x91, 0x01, // Output (Const)
|
||||
// 0xC0, // End Collection
|
||||
|
||||
|
||||
};
|
||||
#endif //#if PAWPAW_INOUTHID
|
||||
|
||||
|
||||
|
||||
void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(chanend, c_audioControl),
|
||||
chanend c_mix_ctl, chanend c_clk_ctl, chanend c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_)
|
||||
{
|
||||
@@ -408,75 +551,11 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(c
|
||||
|
||||
XUA_Endpoint0_setStrTable();
|
||||
|
||||
#if 0
|
||||
/* Dont need to init globals.. */
|
||||
/* Init tables for volumes (+ 1 for master) */
|
||||
for(int i = 0; i < NUM_USB_CHAN_OUT + 1; i++)
|
||||
{
|
||||
volsOut[i] = 0;
|
||||
mutesOut[i] = 0;
|
||||
}
|
||||
|
||||
for(int i = 0; i < NUM_USB_CHAN_IN + 1; i++)
|
||||
{
|
||||
volsIn[i] = 0;
|
||||
mutesIn[i] = 0;
|
||||
}
|
||||
#endif
|
||||
VendorRequests_Init(VENDOR_REQUESTS_PARAMS);
|
||||
|
||||
#ifdef MIXER
|
||||
#if (MIXER)
|
||||
/* Set up mixer default state */
|
||||
for (int i = 0; i < 18*8; i++)
|
||||
{
|
||||
mixer1Weights[i] = 0x8001; //-inf
|
||||
}
|
||||
|
||||
/* Configure default connections */
|
||||
mixer1Weights[0] = 0;
|
||||
mixer1Weights[9] = 0;
|
||||
mixer1Weights[18] = 0;
|
||||
mixer1Weights[27] = 0;
|
||||
mixer1Weights[36] = 0;
|
||||
mixer1Weights[45] = 0;
|
||||
mixer1Weights[54] = 0;
|
||||
mixer1Weights[63] = 0;
|
||||
|
||||
#if NUM_USB_CHAN_OUT > 0
|
||||
/* Setup up audio output channel mapping */
|
||||
for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
|
||||
{
|
||||
channelMapAud[i] = i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NUM_USB_CHAN_IN > 0
|
||||
for(int i = 0; i < NUM_USB_CHAN_IN; i++)
|
||||
{
|
||||
channelMapUsb[i] = i + NUM_USB_CHAN_OUT;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set up channel mapping default */
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN; i++)
|
||||
{
|
||||
channelMap[i] = i;
|
||||
}
|
||||
|
||||
#if MAX_MIX_COUNT > 0
|
||||
/* Mixer outputs mapping defaults */
|
||||
for (int i = 0; i < MAX_MIX_COUNT; i++)
|
||||
{
|
||||
channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + i] = i;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Init mixer inputs */
|
||||
for(int j = 0; j < MAX_MIX_COUNT; j++)
|
||||
for(int i = 0; i < MIX_INPUTS; i++)
|
||||
{
|
||||
mixSel[j][i] = i;
|
||||
}
|
||||
InitLocalMixerState();
|
||||
#endif
|
||||
|
||||
#ifdef VENDOR_AUDIO_REQS
|
||||
@@ -529,18 +608,19 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(c
|
||||
cfgDesc_Audio1[USB_AS_OUT_INTERFACE_DESCRIPTOR_OFFSET_FREQ + 3*i + 2] = (get_usb_to_device_rate() & 0xff0000)>> 16;
|
||||
}
|
||||
|
||||
|
||||
cfgDesc_Audio1[USB_AS_OUT_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE] = ((get_usb_to_device_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_OUT_FS) & 0xff; //max packet size
|
||||
cfgDesc_Audio1[USB_AS_OUT_EP_DESCRIPTOR_OFFSET_MAXPACKETSIZE + 1] = (((get_usb_to_device_bit_res() >> 3) * MAX_PACKET_SIZE_MULT_OUT_FS) & 0xff00) >> 8; //max packet size
|
||||
#endif // NUM_USB_CHAN_OUT
|
||||
|
||||
#endif // XUA_USB_DESCRIPTOR_OVERWRITE_RATE_RES
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
#if XUA_HID_ENABLED
|
||||
hidReportInit();
|
||||
hidPrepareReportDescriptor();
|
||||
|
||||
size_t hidReportDescriptorLength = hidGetReportDescriptorLength();
|
||||
#endif
|
||||
unsigned char hidReportDescriptorLengthLo = hidReportDescriptorLength & 0xFF;
|
||||
unsigned char hidReportDescriptorLengthHi = (hidReportDescriptorLength & 0xFF00) >> 8;
|
||||
|
||||
@@ -551,6 +631,7 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(c
|
||||
|
||||
hidDescriptor[HID_DESCRIPTOR_LENGTH_FIELD_OFFSET ] = hidReportDescriptorLengthLo;
|
||||
hidDescriptor[HID_DESCRIPTOR_LENGTH_FIELD_OFFSET + 1] = hidReportDescriptorLengthHi;
|
||||
|
||||
#endif // 0 < HID_CONTROLS
|
||||
|
||||
}
|
||||
@@ -591,7 +672,7 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0
|
||||
|
||||
if(g_curUsbSpeed == XUD_SPEED_HS)
|
||||
{
|
||||
outuint(c_audioControl, NUM_USB_CHAN_OUT); /* Channel count */
|
||||
outuint(c_audioControl, g_chanCount_Out_HS[sp.wValue-1]); /* Channel count */
|
||||
outuint(c_audioControl, g_subSlot_Out_HS[sp.wValue-1]); /* Subslot */
|
||||
outuint(c_audioControl, g_sampRes_Out_HS[sp.wValue-1]); /* Resolution */
|
||||
}
|
||||
@@ -754,7 +835,7 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0
|
||||
|
||||
switch(sp.bRequest)
|
||||
{
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
case USB_GET_DESCRIPTOR:
|
||||
|
||||
/* Check what inteface request is for */
|
||||
@@ -769,15 +850,17 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0
|
||||
{
|
||||
/* Return HID Descriptor */
|
||||
result = XUD_DoGetRequest(ep0_out, ep0_in, hidDescriptor,
|
||||
sizeof(hidDescriptor), sp.wLength);
|
||||
hidDescriptor[0], sp.wLength);
|
||||
}
|
||||
break;
|
||||
case HID_REPORT:
|
||||
{
|
||||
/* Return HID report descriptor */
|
||||
#if XUA_HID_ENABLED
|
||||
unsigned char* hidReportDescriptorPtr;
|
||||
hidReportDescriptorPtr = hidGetReportDescriptor();
|
||||
size_t hidReportDescriptorLength = hidGetReportDescriptorLength();
|
||||
#endif
|
||||
result = XUD_DoGetRequest(ep0_out, ep0_in, hidReportDescriptorPtr,
|
||||
hidReportDescriptorLength, sp.wLength);
|
||||
}
|
||||
@@ -823,7 +906,14 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0
|
||||
{
|
||||
unsigned epNum = sp.wIndex & 0xff;
|
||||
|
||||
if ((epNum == ENDPOINT_ADDRESS_OUT_AUDIO) || (epNum == ENDPOINT_ADDRESS_IN_AUDIO))
|
||||
// Ensure we only check for AUDIO EPs if enabled
|
||||
#if (NUM_USB_CHAN_IN != 0 && NUM_USB_CHAN_OUT == 0)
|
||||
if (epNum == ENDPOINT_ADDRESS_IN_AUDIO)
|
||||
#elif (NUM_USB_CHAN_IN == 0 && NUM_USB_CHAN_OUT != 0)
|
||||
if (epNum == ENDPOINT_ADDRESS_OUT_AUDIO)
|
||||
#elif (NUM_USB_CHAN_IN != 0 && NUM_USB_CHAN_OUT != 0)
|
||||
if ((epNum == ENDPOINT_ADDRESS_IN_AUDIO) || (epNum == ENDPOINT_ADDRESS_OUT_AUDIO))
|
||||
#endif
|
||||
{
|
||||
#if (AUDIO_CLASS == 2) && (AUDIO_CLASS_FALLBACK)
|
||||
if(g_curUsbSpeed == XUD_SPEED_FS)
|
||||
@@ -881,12 +971,22 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_HID_ENABLED
|
||||
if (interfaceNum == INTERFACE_NUMBER_HID)
|
||||
{
|
||||
result = HidInterfaceClassRequests(ep0_out, ep0_in, &sp);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PAWPAW_INOUTHID
|
||||
if (interfaceNum == INTERFACE_NUMBER_HID)
|
||||
{
|
||||
debug_printf("INTERFACE_NUMBER_HID");
|
||||
extern XUD_Result_t HidInterfaceClassRequests_PAWPAW(XUD_ep c_ep0_out, XUD_ep c_ep0_in, USB_SetupPacket_t sp);
|
||||
HidInterfaceClassRequests_PAWPAW(ep0_out, ep0_in, sp);
|
||||
}
|
||||
#endif//#if PAWPAW_INOUTHID
|
||||
|
||||
/* Check for: - Audio CONTROL interface request - always 0, note we check for DFU first
|
||||
* - Audio STREAMING interface request (In or Out)
|
||||
* - Audio endpoint request (Audio 1.0 Sampling freq requests are sent to the endpoint)
|
||||
@@ -970,20 +1070,20 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0
|
||||
cfgDesc_Audio2.Audio_Out_Format.bSubslotSize = HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES;
|
||||
cfgDesc_Audio2.Audio_Out_Format.bBitResolution = HS_STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS;
|
||||
cfgDesc_Audio2.Audio_Out_Endpoint.wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE;
|
||||
cfgDesc_Audio2.Audio_Out_ClassStreamInterface.bNrChannels = NUM_USB_CHAN_OUT;
|
||||
cfgDesc_Audio2.Audio_Out_ClassStreamInterface.bNrChannels = HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT;
|
||||
#endif
|
||||
#if (OUTPUT_FORMAT_COUNT > 1)
|
||||
cfgDesc_Audio2.Audio_Out_Format_2.bSubslotSize = HS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES;
|
||||
cfgDesc_Audio2.Audio_Out_Format_2.bBitResolution = HS_STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS;
|
||||
cfgDesc_Audio2.Audio_Out_Endpoint_2.wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_2_MAXPACKETSIZE;
|
||||
cfgDesc_Audio2.Audio_Out_ClassStreamInterface_2.bNrChannels = NUM_USB_CHAN_OUT;
|
||||
cfgDesc_Audio2.Audio_Out_ClassStreamInterface_2.bNrChannels = HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT;
|
||||
#endif
|
||||
|
||||
#if (OUTPUT_FORMAT_COUNT > 2)
|
||||
cfgDesc_Audio2.Audio_Out_Format_3.bSubslotSize = HS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES;
|
||||
cfgDesc_Audio2.Audio_Out_Format_3.bBitResolution = HS_STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS;
|
||||
cfgDesc_Audio2.Audio_Out_Endpoint_3.wMaxPacketSize = HS_STREAM_FORMAT_OUTPUT_3_MAXPACKETSIZE;
|
||||
cfgDesc_Audio2.Audio_Out_ClassStreamInterface_3.bNrChannels = NUM_USB_CHAN_OUT;
|
||||
cfgDesc_Audio2.Audio_Out_ClassStreamInterface_3.bNrChannels = HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT;
|
||||
#endif
|
||||
#endif
|
||||
#if (NUM_USB_CHAN_IN > 0)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
/**
|
||||
* @file xua_ep0_descriptors.h
|
||||
@@ -308,28 +308,28 @@ typedef struct
|
||||
#error NUM_USB_CHAN > 32
|
||||
#endif
|
||||
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 0)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 0)
|
||||
STR_TABLE_ENTRY(mixOutStr_1);
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 1)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 1)
|
||||
STR_TABLE_ENTRY(mixOutStr_2);
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 2)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 2)
|
||||
STR_TABLE_ENTRY(mixOutStr_3);
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 3)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 3)
|
||||
STR_TABLE_ENTRY(mixOutStr_4);
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 4)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 4)
|
||||
STR_TABLE_ENTRY(mixOutStr_5);
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 5)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 5)
|
||||
STR_TABLE_ENTRY(mixOutStr_6);
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 6)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 6)
|
||||
STR_TABLE_ENTRY(mixOutStr_7);
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 7)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 7)
|
||||
STR_TABLE_ENTRY(mixOutStr_8);
|
||||
#endif
|
||||
#ifdef IAP
|
||||
@@ -391,31 +391,31 @@ StringDescTable_t g_strTable =
|
||||
#error NUM_USB_CHAN_IN > 32
|
||||
#endif
|
||||
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 0)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 0)
|
||||
.mixOutStr_1 = "Mix 1",
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 1)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 1)
|
||||
.mixOutStr_2 = "Mix 2",
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 2)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 2)
|
||||
.mixOutStr_3 = "Mix 3",
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 3)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 3)
|
||||
.mixOutStr_4 = "Mix 4",
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 4)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 4)
|
||||
.mixOutStr_5 = "Mix 5",
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 5)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 5)
|
||||
.mixOutStr_6 = "Mix 6",
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 6)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 6)
|
||||
.mixOutStr_7 = "Mix 7",
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 7)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 7)
|
||||
.mixOutStr_8 = "Mix 8",
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 8)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 8)
|
||||
#error
|
||||
#endif
|
||||
#ifdef IAP
|
||||
@@ -481,7 +481,7 @@ USB_Descriptor_Device_t devDesc_Audio2 =
|
||||
.iManufacturer = offsetof(StringDescTable_t, vendorStr)/sizeof(char *),
|
||||
.iProduct = offsetof(StringDescTable_t, productStr_Audio2)/sizeof(char *),
|
||||
.iSerialNumber = offsetof(StringDescTable_t, serialStr)/sizeof(char *),
|
||||
.bNumConfigurations = 0x02 /* Set to 2 such that windows does not load composite driver */
|
||||
.bNumConfigurations = 0x01
|
||||
};
|
||||
|
||||
/* Device Descriptor for Null Device */
|
||||
@@ -558,7 +558,7 @@ unsigned char devQualDesc_Null[] =
|
||||
};
|
||||
|
||||
|
||||
#if defined(MIXER) && !defined(AUDIO_PATH_XUS) && (MAX_MIX_COUNT > 0)
|
||||
#if (MIXER) && !defined(AUDIO_PATH_XUS) && (MAX_MIX_COUNT > 0)
|
||||
//#warning Extension units on the audio path are required for mixer. Enabling them now.
|
||||
#define AUDIO_PATH_XUS
|
||||
#endif
|
||||
@@ -575,7 +575,7 @@ unsigned char devQualDesc_Null[] =
|
||||
#define DFU_LENGTH (0)
|
||||
#endif
|
||||
|
||||
#ifdef MIXER
|
||||
#if (MIXER)
|
||||
#define MIX_BMCONTROLS_LEN_TMP ((MAX_MIX_COUNT * MIX_INPUTS) / 8)
|
||||
|
||||
#if ((MAX_MIX_COUNT * MIX_INPUTS)%8)==0
|
||||
@@ -666,7 +666,7 @@ typedef struct
|
||||
#if (NUM_USB_CHAN_OUT > 0)
|
||||
/* Output path */
|
||||
USB_Descriptor_Audio_InputTerminal_t Audio_Out_InputTerminal;
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 0)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 0)
|
||||
USB_Descriptor_Audio_ExtensionUnit_t Audio_Out_ExtensionUnit;
|
||||
#endif
|
||||
#if(OUTPUT_VOLUME_CONTROL == 1)
|
||||
@@ -677,7 +677,7 @@ typedef struct
|
||||
#if (NUM_USB_CHAN_IN > 0)
|
||||
/* Input path */
|
||||
USB_Descriptor_Audio_InputTerminal_t Audio_In_InputTerminal;
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 0)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 0)
|
||||
USB_Descriptor_Audio_ExtensionUnit_t Audio_In_ExtensionUnit;
|
||||
#endif
|
||||
#if(INPUT_VOLUME_CONTROL == 1)
|
||||
@@ -685,7 +685,7 @@ typedef struct
|
||||
#endif
|
||||
USB_Descriptor_Audio_OutputTerminal_t Audio_In_OutputTerminal;
|
||||
#endif
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 0)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 0)
|
||||
USB_Descriptor_Audio_ExtensionUnit2_t Audio_Mix_ExtensionUnit;
|
||||
// Currently no struct for mixer unit
|
||||
// USB_Descriptor_Audio_MixerUnit_t Audio_MixerUnit;
|
||||
@@ -772,6 +772,11 @@ typedef struct
|
||||
unsigned char configDesc_DFU[DFU_LENGTH];
|
||||
#endif
|
||||
|
||||
#ifdef USB_CONTROL_DESCS
|
||||
/* Inferface descriptor for control */
|
||||
unsigned char itfDesc_control[9];
|
||||
#endif
|
||||
|
||||
#ifdef IAP
|
||||
USB_Descriptor_Interface_t iAP_Interface;
|
||||
USB_Descriptor_Endpoint_t iAP_Out_Endpoint;
|
||||
@@ -787,10 +792,13 @@ typedef struct
|
||||
#endif
|
||||
#endif // IAP
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
USB_Descriptor_Interface_t HID_Interface;
|
||||
USB_HID_Descriptor_t HID_Descriptor;
|
||||
USB_Descriptor_Endpoint_t HID_In_Endpoint;
|
||||
#if HID_OUT_REQUIRED
|
||||
USB_Descriptor_Endpoint_t HID_Out_Endpoint;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}__attribute__((packed)) USB_Config_Descriptor_Audio2_t;
|
||||
@@ -1114,9 +1122,9 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
.wTerminalType = UAC_TT_OUTPUT_TERMTYPE_SPEAKER,
|
||||
0x00, /* 6 bAssocTerminal */
|
||||
#if (OUTPUT_VOLUME_CONTROL == 1)
|
||||
FU_USBOUT, /* 7 bSourceID Connect to analog input feature unit*/
|
||||
FU_USBOUT, /* 7 bSourceID Connect to analog output feature unit */
|
||||
#else
|
||||
ID_IT_USB, /* 7 bSourceID Connect to analog input feature unit*/
|
||||
ID_IT_USB, /* 7 bSourceID Connect to USB streaming input term */
|
||||
#endif
|
||||
ID_CLKSEL, /* 8 bCSourceUD */
|
||||
0x0000, /* 9 bmControls */
|
||||
@@ -1168,7 +1176,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
UAC_CS_DESCTYPE_INTERFACE, /* 1 bDescriptorType: CS_INTERFACE */
|
||||
UAC_CS_AC_INTERFACE_SUBTYPE_FEATURE_UNIT, /* 2 bDescriptorSubType: FEATURE_UNIT */
|
||||
FU_USBIN, /* 3 bUnitID */
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 0)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 0)
|
||||
ID_XU_IN, /* 4 bSourceID */
|
||||
#else
|
||||
ID_IT_AUD, /* 4 bSourceID */
|
||||
@@ -1300,7 +1308,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
},
|
||||
#endif /* (NUM_USB_CHAN_IN > 0) */
|
||||
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 0)
|
||||
#if (MIXER) && (MAX_MIX_COUNT > 0)
|
||||
/* Extension Unit Descriptor (4.7.2.12) */
|
||||
.Audio_Mix_ExtensionUnit =
|
||||
{
|
||||
@@ -1392,7 +1400,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
0x00, /* bmControls */
|
||||
0 /* Mixer unit string descriptor index */
|
||||
},
|
||||
#endif /* defined(MIXER) && (MAX_MIX_COUNT > 0) */
|
||||
#endif /* (MIXER) && (MAX_MIX_COUNT > 0) */
|
||||
|
||||
#if (XUA_SPDIF_RX_EN) || (XUA_ADAT_RX_EN)
|
||||
/* Standard AS Interrupt Endpoint Descriptor (4.8.2.1): */
|
||||
@@ -1446,15 +1454,15 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
/* Class Specific AS Interface Descriptor */
|
||||
.Audio_Out_ClassStreamInterface =
|
||||
{
|
||||
0x10, /* 0 bLength: 16 */
|
||||
UAC_CS_DESCTYPE_INTERFACE, /* 1 bDescriptorType: 0x24 */
|
||||
0x10, /* 0 bLength: 16 */
|
||||
UAC_CS_DESCTYPE_INTERFACE, /* 1 bDescriptorType: 0x24 */
|
||||
UAC_CS_AS_INTERFACE_SUBTYPE_AS_GENERAL, /* 2 bDescriptorSubType */
|
||||
ID_IT_USB, /* 3 bTerminalLink (Linked to USB input terminal) */
|
||||
0x00, /* 4 bmControls */
|
||||
UAC_FORMAT_TYPE_I, /* 5 bFormatType */
|
||||
STREAM_FORMAT_OUTPUT_1_DATAFORMAT,/* 6:10 bmFormats (note this is a bitmap) */
|
||||
NUM_USB_CHAN_OUT, /* 11 bNrChannels */
|
||||
0x00000000, /* 12:14: bmChannelConfig */
|
||||
ID_IT_USB, /* 3 bTerminalLink (Linked to USB input terminal) */
|
||||
0x00, /* 4 bmControls */
|
||||
UAC_FORMAT_TYPE_I, /* 5 bFormatType */
|
||||
STREAM_FORMAT_OUTPUT_1_DATAFORMAT, /* 6:10 bmFormats (note this is a bitmap) */
|
||||
HS_STREAM_FORMAT_OUTPUT_1_CHAN_COUNT, /* 11 bNrChannels */
|
||||
0x00000000, /* 12:14: bmChannelConfig */
|
||||
.iChannelNames = offsetof(StringDescTable_t, outputChanStr_1)/sizeof(char *),
|
||||
},
|
||||
|
||||
@@ -1537,15 +1545,15 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
/* Class Specific AS Interface Descriptor */
|
||||
.Audio_Out_ClassStreamInterface_2 =
|
||||
{
|
||||
0x10, /* 0 bLength: 16 */
|
||||
UAC_CS_DESCTYPE_INTERFACE, /* 1 bDescriptorType: 0x24 */
|
||||
0x10, /* 0 bLength: 16 */
|
||||
UAC_CS_DESCTYPE_INTERFACE, /* 1 bDescriptorType: 0x24 */
|
||||
UAC_CS_AS_INTERFACE_SUBTYPE_AS_GENERAL, /* 2 bDescriptorSubType */
|
||||
ID_IT_USB, /* 3 bTerminalLink (Linked to USB input terminal) */
|
||||
0x00, /* 4 bmControls */
|
||||
UAC_FORMAT_TYPE_I, /* 5 bFormatType */
|
||||
STREAM_FORMAT_OUTPUT_2_DATAFORMAT,/* 6:10 bmFormats (note this is a bitmap) */
|
||||
NUM_USB_CHAN_OUT, /* 11 bNrChannels */
|
||||
0x00000000, /* 12:14: bmChannelConfig */
|
||||
ID_IT_USB, /* 3 bTerminalLink (Linked to USB input terminal) */
|
||||
0x00, /* 4 bmControls */
|
||||
UAC_FORMAT_TYPE_I, /* 5 bFormatType */
|
||||
STREAM_FORMAT_OUTPUT_2_DATAFORMAT, /* 6:10 bmFormats (note this is a bitmap) */
|
||||
HS_STREAM_FORMAT_OUTPUT_2_CHAN_COUNT, /* 11 bNrChannels */
|
||||
0x00000000, /* 12:14: bmChannelConfig */
|
||||
.iChannelNames = (offsetof(StringDescTable_t, outputChanStr_1)/sizeof(char *)),
|
||||
},
|
||||
|
||||
@@ -1628,15 +1636,15 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
/* Class Specific AS Interface Descriptor */
|
||||
.Audio_Out_ClassStreamInterface_3 =
|
||||
{
|
||||
0x10, /* 0 bLength: 16 */
|
||||
UAC_CS_DESCTYPE_INTERFACE, /* 1 bDescriptorType: 0x24 */
|
||||
0x10, /* 0 bLength: 16 */
|
||||
UAC_CS_DESCTYPE_INTERFACE, /* 1 bDescriptorType: 0x24 */
|
||||
UAC_CS_AS_INTERFACE_SUBTYPE_AS_GENERAL, /* 2 bDescriptorSubType */
|
||||
ID_IT_USB, /* 3 bTerminalLink (Linked to USB input terminal) */
|
||||
0x00, /* 4 bmControls */
|
||||
UAC_FORMAT_TYPE_I, /* 5 bFormatType */
|
||||
STREAM_FORMAT_OUTPUT_3_DATAFORMAT,/* 6:10 bmFormats (note this is a bitmap) */
|
||||
NUM_USB_CHAN_OUT, /* 11 bNrChannels */
|
||||
0x00000000, /* 12:14: bmChannelConfig */
|
||||
ID_IT_USB, /* 3 bTerminalLink (Linked to USB input terminal) */
|
||||
0x00, /* 4 bmControls */
|
||||
UAC_FORMAT_TYPE_I, /* 5 bFormatType */
|
||||
STREAM_FORMAT_OUTPUT_3_DATAFORMAT, /* 6:10 bmFormats (note this is a bitmap) */
|
||||
HS_STREAM_FORMAT_OUTPUT_3_CHAN_COUNT, /* 11 bNrChannels */
|
||||
0x00000000, /* 12:14: bmChannelConfig */
|
||||
.iChannelNames = offsetof(StringDescTable_t, outputChanStr_1)/sizeof(char *),
|
||||
},
|
||||
|
||||
@@ -2101,6 +2109,21 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
#endif
|
||||
#endif /* (XUA_DFU_EN == 1) */
|
||||
|
||||
#ifdef USB_CONTROL_DESCS
|
||||
{
|
||||
/* Control interface descriptor */
|
||||
0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */
|
||||
0x04, /* 1 bDescriptorType : INTERFACE descriptor. (field size 1 bytes) */
|
||||
(INTERFACE_NUMBER_MISC_CONTROL), /* 2 bInterfaceNumber */
|
||||
0x00, /* 3 bAlternateSetting : Index of this setting. (field size 1 bytes) */
|
||||
0x00, /* 4 bNumEndpoints : 0 endpoints. (field size 1 bytes) */
|
||||
USB_CLASS_VENDOR_SPECIFIC, /* 5 bInterfaceClass : Vendor specific. (field size 1 bytes) */
|
||||
0xFF, /* 6 bInterfaceSubclass : (field size 1 bytes) */
|
||||
0xFF, /* 7 bInterfaceProtocol : Unused. (field size 1 bytes) */
|
||||
offsetof(StringDescTable_t, ctrlStr)/sizeof(char *), /* 8 iInterface */
|
||||
},
|
||||
#endif
|
||||
|
||||
#ifdef IAP
|
||||
/* Interface descriptor */
|
||||
.iAP_Interface =
|
||||
@@ -2208,14 +2231,14 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
#endif
|
||||
#endif /* IAP */
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
#include "xua_hid_descriptors.h"
|
||||
#endif
|
||||
|
||||
};
|
||||
#endif /* (AUDIO_CLASS == 2) */
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
#if (AUDIO_CLASS ==1 )
|
||||
unsigned char hidDescriptor[] =
|
||||
{
|
||||
@@ -2330,14 +2353,14 @@ const unsigned num_freqs_a1 = MAX(3, (0
|
||||
#define DFU_INTERFACES_A1 0
|
||||
#endif
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
/*
|
||||
* The value of HID_INTERFACE_BYTES must match the length of the descriptors defined in
|
||||
* - xua_hid_descriptor_contents.h
|
||||
* - xua_hid_endpoint_descriptor_contents.h and
|
||||
* - xua_hid_interface_descriptor_contents.h
|
||||
*/
|
||||
#define HID_INTERFACE_BYTES ( 9 + 9 + 7 )
|
||||
#define HID_INTERFACE_BYTES ( 9 + 9 + (7 * (1 + HID_OUT_REQUIRED))) // always IN
|
||||
#define HID_INTERFACES_A1 1
|
||||
#else
|
||||
#define HID_INTERFACE_BYTES 0
|
||||
@@ -2379,7 +2402,7 @@ const unsigned num_freqs_a1 = MAX(3, (0
|
||||
|
||||
#endif
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
#define USB_HID_DESCRIPTOR_OFFSET (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES + INTERFACE_DESCRIPTOR_BYTES)
|
||||
#endif
|
||||
|
||||
@@ -2893,7 +2916,7 @@ unsigned char cfgDesc_Audio1[] =
|
||||
offsetof(StringDescTable_t, ctrlStr)/sizeof(char *), /* 8 iInterface */
|
||||
#endif
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
#include "xua_hid_descriptors.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2011-2022 XMOS LIMITED.
|
||||
// Copyright 2011-2023 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
/**
|
||||
* @brief Implements relevant requests from the USB Audio 2.0 Specification
|
||||
@@ -14,26 +14,29 @@
|
||||
#include "usbaudio10.h"
|
||||
#include "dbcalc.h"
|
||||
#include "xua_commands.h"
|
||||
#include "xc_ptr.h"
|
||||
|
||||
#define CS_XU_MIXSEL (0x06)
|
||||
|
||||
/* From decouple.xc */
|
||||
#if (OUT_VOLUME_IN_MIXER == 0) && (OUTPUT_VOLUME_CONTROL == 1)
|
||||
extern unsigned int multOut[NUM_USB_CHAN_OUT + 1];
|
||||
#endif
|
||||
#if (IN_VOLUME_IN_MIXER == 0) && (INPUT_VOLUME_CONTROL == 1)
|
||||
extern unsigned int multIn[NUM_USB_CHAN_IN + 1];
|
||||
#endif
|
||||
|
||||
extern int interfaceAlt[];
|
||||
|
||||
/* Global volume and mute tables */
|
||||
/* Global volume and mute tables - from xua_endpoint0.c */
|
||||
extern int volsOut[];
|
||||
extern unsigned int mutesOut[];
|
||||
|
||||
extern int volsIn[];
|
||||
extern unsigned int mutesIn[];
|
||||
|
||||
/* Mixer settings */
|
||||
#ifdef MIXER
|
||||
extern unsigned char mixer1Crossbar[];
|
||||
extern short mixer1Weights[];
|
||||
#if (MIXER)
|
||||
/* Mixer weights */
|
||||
extern short mixer1Weights[MIX_INPUTS * MAX_MIX_COUNT];
|
||||
|
||||
/* Device channel mapping */
|
||||
extern unsigned char channelMapAud[NUM_USB_CHAN_OUT];
|
||||
@@ -102,20 +105,6 @@ void FeedbackStabilityDelay()
|
||||
t when timerafter(time + delay):> void;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Original feedback implementation */
|
||||
unsafe
|
||||
{
|
||||
unsigned * unsafe curSamFreqMultiplier = &g_curSamFreqMultiplier;
|
||||
|
||||
static void setG_curSamFreqMultiplier(unsigned x)
|
||||
{
|
||||
// asm(" stw %0, dp[g_curSamFreqMultiplier]" :: "r"(x));
|
||||
*curSamFreqMultiplier = x;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OUTPUT_VOLUME_CONTROL == 1) || (INPUT_VOLUME_CONTROL == 1)
|
||||
static unsigned longMul(unsigned a, unsigned b, int prec)
|
||||
{
|
||||
@@ -130,16 +119,9 @@ static unsigned longMul(unsigned a, unsigned b, int prec)
|
||||
}
|
||||
|
||||
/* Update master volume i.e. i.e update weights for all channels */
|
||||
static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
|
||||
static void updateMasterVol(int unitID, chanend ?c_mix_ctl)
|
||||
{
|
||||
int x;
|
||||
#ifndef OUT_VOLUME_IN_MIXER
|
||||
xc_ptr p_multOut = array_to_xc_ptr(multOut);
|
||||
#endif
|
||||
#ifndef IN_VOLUME_IN_MIXER
|
||||
xc_ptr p_multIn = array_to_xc_ptr(multIn);
|
||||
#endif
|
||||
switch( unitID)
|
||||
switch(unitID)
|
||||
{
|
||||
case FU_USBOUT:
|
||||
{
|
||||
@@ -151,18 +133,24 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
|
||||
/* 0x8000 is a special value representing -inf (i.e. mute) */
|
||||
unsigned vol = volsOut[i] == 0x8000 ? 0 : db_to_mult(volsOut[i], 8, 29);
|
||||
|
||||
x = longMul(master_vol, vol, 29) * !mutesOut[0] * !mutesOut[i];
|
||||
int x = longMul(master_vol, vol, 29) * !mutesOut[0] * !mutesOut[i];
|
||||
|
||||
#ifdef OUT_VOLUME_IN_MIXER
|
||||
#if (OUT_VOLUME_IN_MIXER)
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
inct(c_mix_ctl);
|
||||
outuint(c_mix_ctl, SET_MIX_OUT_VOL);
|
||||
outuint(c_mix_ctl, i-1);
|
||||
outuint(c_mix_ctl, x);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
#else
|
||||
asm("stw %0, %1[%2]"::"r"(x),"r"(p_multOut),"r"(i-1));
|
||||
unsafe
|
||||
{
|
||||
unsigned int * unsafe multOutPtr = multOut;
|
||||
multOutPtr[i-1] = x;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -177,18 +165,24 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
|
||||
/* 0x8000 is a special value representing -inf (i.e. mute) */
|
||||
unsigned vol = volsIn[i] == 0x8000 ? 0 : db_to_mult(volsIn[i], 8, 29);
|
||||
|
||||
x = longMul(master_vol, vol, 29) * !mutesIn[0] * !mutesIn[i];
|
||||
int x = longMul(master_vol, vol, 29) * !mutesIn[0] * !mutesIn[i];
|
||||
|
||||
#ifdef IN_VOLUME_IN_MIXER
|
||||
#if (IN_VOLUME_IN_MIXER)
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
inct(c_mix_ctl);
|
||||
outuint(c_mix_ctl, SET_MIX_IN_VOL);
|
||||
outuint(c_mix_ctl, i-1);
|
||||
outuint(c_mix_ctl, x);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
#else
|
||||
asm("stw %0, %1[%2]"::"r"(x),"r"(p_multIn),"r"(i-1));
|
||||
unsafe
|
||||
{
|
||||
unsigned int * unsafe multInPtr = multIn;
|
||||
multInPtr[i-1] = x;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -202,12 +196,6 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
|
||||
static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
|
||||
{
|
||||
int x;
|
||||
#ifndef OUT_VOLUME_IN_MIXER
|
||||
xc_ptr p_multOut = array_to_xc_ptr(multOut);
|
||||
#endif
|
||||
#ifndef IN_VOLUME_IN_MIXER
|
||||
xc_ptr p_multIn = array_to_xc_ptr(multIn);
|
||||
#endif
|
||||
/* Check for master volume update */
|
||||
if (channel == 0)
|
||||
{
|
||||
@@ -226,16 +214,22 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
|
||||
|
||||
x = longMul(master_vol, vol, 29) * !mutesOut[0] * !mutesOut[channel];
|
||||
|
||||
#ifdef OUT_VOLUME_IN_MIXER
|
||||
#if (OUT_VOLUME_IN_MIXER)
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
inct(c_mix_ctl);
|
||||
outuint(c_mix_ctl, SET_MIX_OUT_VOL);
|
||||
outuint(c_mix_ctl, channel-1);
|
||||
outuint(c_mix_ctl, x);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
#else
|
||||
asm("stw %0, %1[%2]"::"r"(x),"r"(p_multOut),"r"(channel-1));
|
||||
unsafe
|
||||
{
|
||||
unsigned int * unsafe multOutPtr = multOut;
|
||||
multOutPtr[channel-1] = x;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
@@ -244,20 +238,26 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
|
||||
/* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */
|
||||
/* 0x8000 is a special value representing -inf (i.e. mute) */
|
||||
unsigned master_vol = volsIn[0] == 0x8000 ? 0 : db_to_mult(volsIn[0], 8, 29);
|
||||
unsigned vol = volsIn[channel] == 0x8000 ? 0 : db_to_mult(volsIn[channel], 8, 29);
|
||||
unsigned vol = volsIn[channel] == 0x8000 ? 0 : db_to_mult(volsIn[channel], 8, 29);
|
||||
|
||||
x = longMul(master_vol, vol, 29) * !mutesIn[0] * !mutesIn[channel];
|
||||
|
||||
#ifdef IN_VOLUME_IN_MIXER
|
||||
#if (IN_VOLUME_IN_MIXER)
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
inct(c_mix_ctl);
|
||||
outuint(c_mix_ctl, SET_MIX_IN_VOL);
|
||||
outuint(c_mix_ctl, channel-1);
|
||||
outuint(c_mix_ctl, x);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
#else
|
||||
asm("stw %0, %1[%2]"::"r"(x),"r"(p_multIn),"r"(channel-1));
|
||||
unsafe
|
||||
{
|
||||
unsigned int * unsafe multInPtr = multIn;
|
||||
multInPtr[channel-1] = x;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
@@ -266,6 +266,38 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
|
||||
}
|
||||
#endif
|
||||
|
||||
void UpdateMixerOutputRouting(chanend c_mix_ctl, unsigned map, unsigned dst, unsigned src)
|
||||
{
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
inct(c_mix_ctl);
|
||||
outuint(c_mix_ctl, map);
|
||||
outuint(c_mix_ctl, dst);
|
||||
outuint(c_mix_ctl, src);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
|
||||
void UpdateMixMap(chanend c_mix_ctl, int mix, int input, int src)
|
||||
{
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
inct(c_mix_ctl);
|
||||
outuint(c_mix_ctl, SET_MIX_MAP);
|
||||
outuint(c_mix_ctl, mix); /* Mix bus */
|
||||
outuint(c_mix_ctl, input); /* Mixer input (cn) */
|
||||
outuint(c_mix_ctl, src); /* Source (mixSel[cn]) */
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
|
||||
void UpdateMixerWeight(chanend c_mix_ctl, int mix, int index, unsigned mult)
|
||||
{
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
inct(c_mix_ctl);
|
||||
outuint(c_mix_ctl, SET_MIX_MULT);
|
||||
outuint(c_mix_ctl, mix);
|
||||
outuint(c_mix_ctl, index);
|
||||
outuint(c_mix_ctl, mult);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
|
||||
/* Handles the audio class specific requests
|
||||
* returns: XUD_RES_OKAY if request dealt with successfully without error,
|
||||
* XUD_RES_RST for device reset
|
||||
@@ -282,7 +314,6 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
/* Inspect request, NOTE: these are class specific requests */
|
||||
switch( sp.bRequest )
|
||||
{
|
||||
|
||||
/* CUR Request*/
|
||||
case CUR:
|
||||
{
|
||||
@@ -318,7 +349,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
int newSampleRate = buffer[0];
|
||||
|
||||
/* Instruct audio thread to change sample freq (if change required) */
|
||||
//if(newSampleRate != g_curSamFreq)
|
||||
if(newSampleRate != g_curSamFreq)
|
||||
{
|
||||
int newMasterClock;
|
||||
|
||||
@@ -371,7 +402,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
}
|
||||
#endif /* MAX_FREQ != MIN_FREQ */
|
||||
/* Send 0 Length as status stage */
|
||||
int x = XUD_DoSetRequestStatus(ep0_in);
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
/* Direction: Device-to-host: Send Current Sample Freq */
|
||||
else
|
||||
@@ -425,34 +456,35 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
(buffer, unsigned char[])[0] = 1;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), 1, sp.wLength);
|
||||
break;
|
||||
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
case ID_CLKSRC_SPDIF:
|
||||
|
||||
/* Interogate clockgen thread for validity */
|
||||
if (!isnull(c_clk_ctl))
|
||||
{
|
||||
outuint(c_clk_ctl, GET_VALID);
|
||||
outuint(c_clk_ctl, CLOCK_SPDIF_INDEX);
|
||||
outuint(c_clk_ctl, CLOCK_SPDIF);
|
||||
outct(c_clk_ctl, XS1_CT_END);
|
||||
(buffer, unsigned char[])[0] = inuint(c_clk_ctl);
|
||||
chkct(c_clk_ctl, XS1_CT_END);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), 1, sp.wLength);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
#endif
|
||||
#if (XUA_ADAT_RX_EN)
|
||||
case ID_CLKSRC_ADAT:
|
||||
|
||||
if (!isnull(c_clk_ctl))
|
||||
{
|
||||
outuint(c_clk_ctl, GET_VALID);
|
||||
outuint(c_clk_ctl, CLOCK_ADAT_INDEX);
|
||||
outuint(c_clk_ctl, CLOCK_ADAT);
|
||||
outct(c_clk_ctl, XS1_CT_END);
|
||||
(buffer, unsigned char[])[0] = inuint(c_clk_ctl);
|
||||
chkct(c_clk_ctl, XS1_CT_END);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), 1, sp.wLength);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
//Unknown Unit ID in Clock Valid Control Request
|
||||
@@ -482,19 +514,23 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Check for correct datalength for clock sel */
|
||||
if(datalength == 1)
|
||||
{
|
||||
if (!isnull(c_clk_ctl))
|
||||
{
|
||||
outuint(c_clk_ctl, SET_SEL);
|
||||
outuint(c_clk_ctl, (buffer, unsigned char[])[0]);
|
||||
outct(c_clk_ctl, XS1_CT_END);
|
||||
}
|
||||
/* Send 0 Length as status stage */
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
int clockIndex = (int) (buffer, unsigned char[])[0];
|
||||
clockIndex -= 1; /* Index to/from host is 1-based */
|
||||
|
||||
if((clockIndex >= 0) && (clockIndex < CLOCK_COUNT))
|
||||
{
|
||||
if(!isnull(c_clk_ctl))
|
||||
{
|
||||
outuint(c_clk_ctl, SET_SEL);
|
||||
outuint(c_clk_ctl, clockIndex);
|
||||
outct(c_clk_ctl, XS1_CT_END);
|
||||
}
|
||||
/* Send 0 Length as status stage */
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -502,13 +538,15 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
(buffer, unsigned char[])[0] = 1;
|
||||
if (!isnull(c_clk_ctl))
|
||||
{
|
||||
int clockIndex;
|
||||
outuint(c_clk_ctl, GET_SEL);
|
||||
outct(c_clk_ctl, XS1_CT_END);
|
||||
(buffer, unsigned char[])[0] = inuint(c_clk_ctl);
|
||||
clockIndex = inuint(c_clk_ctl);
|
||||
clockIndex += 1; /* Index to/from host is 1-based */
|
||||
(buffer, unsigned char[])[0] = (unsigned char) clockIndex;
|
||||
chkct(c_clk_ctl, XS1_CT_END);
|
||||
}
|
||||
return XUD_DoGetRequest( ep0_out, ep0_in, (buffer, unsigned char[]), 1, sp.wLength );
|
||||
|
||||
return XUD_DoGetRequest( ep0_out, ep0_in, (buffer, unsigned char[]), 1, sp.wLength);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -537,7 +575,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT)
|
||||
{
|
||||
volsOut[ sp.wValue&0xff ] = (buffer, unsigned char[])[0] | (((int) (signed char) (buffer, unsigned char[])[1]) << 8);
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl );
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl);
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
}
|
||||
@@ -546,7 +584,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN)
|
||||
{
|
||||
volsIn[ sp.wValue&0xff ] = (buffer, unsigned char[])[0] | (((int) (signed char) (buffer, unsigned char[])[1]) << 8);
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl );
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl);
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
}
|
||||
@@ -632,85 +670,76 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
break; /* FU_USBIN */
|
||||
#endif
|
||||
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 0)
|
||||
#if ((MIXER) && (MAX_MIX_COUNT > 0))
|
||||
case ID_XU_OUT:
|
||||
{
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */
|
||||
{
|
||||
unsigned volume = 0;
|
||||
int c = sp.wValue & 0xff;
|
||||
int dst = sp.wValue & 0xff;
|
||||
|
||||
|
||||
if((result = XUD_GetBuffer(ep0_out, (buffer, unsigned char[]), datalength)) != XUD_RES_OKAY)
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
channelMapAud[c] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8;
|
||||
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
if (c < NUM_USB_CHAN_OUT)
|
||||
if((result = XUD_GetBuffer(ep0_out, (buffer, unsigned char[]), datalength)) != XUD_RES_OKAY)
|
||||
{
|
||||
outuint(c_mix_ctl, SET_SAMPLES_TO_DEVICE_MAP);
|
||||
outuint(c_mix_ctl, c);
|
||||
outuint(c_mix_ctl, channelMapAud[c]);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
/* Send 0 Length as status stage */
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (dst < NUM_USB_CHAN_OUT)
|
||||
{
|
||||
channelMapAud[dst] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8;
|
||||
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
UpdateMixerOutputRouting(c_mix_ctl, SET_SAMPLES_TO_DEVICE_MAP, dst, channelMapAud[dst]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Send 0 Length as status stage */
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
(buffer, unsigned char[])[0] = channelMapAud[dst];
|
||||
(buffer, unsigned char[])[1] = 0;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
(buffer, unsigned char[])[0] = channelMapAud[sp.wValue & 0xff];
|
||||
(buffer, unsigned char[])[1] = 0;
|
||||
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case ID_XU_IN:
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */
|
||||
{
|
||||
unsigned volume = 0;
|
||||
int c = sp.wValue & 0xff;
|
||||
int dst = sp.wValue & 0xff;
|
||||
|
||||
if((result = XUD_GetBuffer(ep0_out, (buffer, unsigned char[]), datalength)) != XUD_RES_OKAY)
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
channelMapUsb[c] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8;
|
||||
|
||||
if (c < NUM_USB_CHAN_IN)
|
||||
{
|
||||
if (!isnull(c_mix_ctl))
|
||||
if((result = XUD_GetBuffer(ep0_out, (buffer, unsigned char[]), datalength)) != XUD_RES_OKAY)
|
||||
{
|
||||
outuint(c_mix_ctl, SET_SAMPLES_TO_HOST_MAP);
|
||||
outuint(c_mix_ctl, c);
|
||||
outuint(c_mix_ctl, channelMapUsb[c]);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (dst < NUM_USB_CHAN_IN)
|
||||
{
|
||||
channelMapUsb[dst] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8;
|
||||
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
UpdateMixerOutputRouting(c_mix_ctl, SET_SAMPLES_TO_HOST_MAP, dst, channelMapUsb[dst]);
|
||||
}
|
||||
}
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Direction: Device-to-host */
|
||||
(buffer, unsigned char[])[0] = channelMapUsb[dst];
|
||||
(buffer, unsigned char[])[1] = 0;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Direction: Device-to-host */
|
||||
(buffer, unsigned char[])[0] = channelMapUsb[sp.wValue & 0xff];
|
||||
(buffer, unsigned char[])[1] = 0;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength);
|
||||
}
|
||||
break;
|
||||
|
||||
case ID_XU_MIXSEL:
|
||||
{
|
||||
int cs = sp.wValue >> 8; /* Control Selector */
|
||||
int cn = sp.wValue & 0xff; /* Channel number */
|
||||
int cn = sp.wValue & 0xff; /* Channel Number */
|
||||
|
||||
/* Check for Get or Set */
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
@@ -723,21 +752,19 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
|
||||
if(datalength > 0)
|
||||
{
|
||||
/* cn bounds check for safety..*/
|
||||
/* CN bounds check for safety..*/
|
||||
if(cn < MIX_INPUTS)
|
||||
{
|
||||
//if(cs == CS_XU_MIXSEL)
|
||||
/* cs now contains mix number */
|
||||
if(cs < (MAX_MIX_COUNT + 1))
|
||||
{
|
||||
int source = (buffer, unsigned char[])[0];
|
||||
|
||||
/* Check for "off" - update local state */
|
||||
if((buffer, unsigned char[])[0] == 0xFF)
|
||||
if(source == 0xFF)
|
||||
{
|
||||
mixSel[cs][cn] = (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT);
|
||||
}
|
||||
else
|
||||
{
|
||||
mixSel[cs][cn] = (buffer, unsigned char[])[0];
|
||||
source = (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT);
|
||||
}
|
||||
|
||||
if(cs == 0)
|
||||
@@ -745,21 +772,17 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
/* Update all mix maps */
|
||||
for (int i = 0; i < MAX_MIX_COUNT; i++)
|
||||
{
|
||||
outuint(c_mix_ctl, SET_MIX_MAP);
|
||||
outuint(c_mix_ctl, i); /* Mix bus */
|
||||
outuint(c_mix_ctl, cn); /* Mixer input */
|
||||
outuint(c_mix_ctl, (int) mixSel[cn]); /* Source */
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
/* i : Mix bus */
|
||||
/* cn: Mixer input */
|
||||
mixSel[i][cn] = source;
|
||||
UpdateMixMap(c_mix_ctl, i, cn, mixSel[i][cn]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update relevant mix map */
|
||||
outuint(c_mix_ctl, SET_MIX_MAP); /* Command */
|
||||
outuint(c_mix_ctl, (cs-1)); /* Mix bus */
|
||||
outuint(c_mix_ctl, cn); /* Mixer input */
|
||||
outuint(c_mix_ctl, (int) mixSel[cs][cn]); /* Source */
|
||||
outct(c_mix_ctl, XS1_CT_END); /* Wait for handshake back */
|
||||
mixSel[cs-1][cn] = source;
|
||||
UpdateMixMap(c_mix_ctl, cs-1, cn, mixSel[cs-1][cn]);
|
||||
}
|
||||
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
@@ -780,7 +803,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
if((cs > 0) && (cs < (MAX_MIX_COUNT+1)))
|
||||
{
|
||||
(buffer, unsigned char[])[0] = mixSel[cs-1][cn];
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), 1, 1 );
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -788,49 +811,53 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
}
|
||||
|
||||
case ID_MIXER_1:
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */
|
||||
{
|
||||
unsigned volume = 0;
|
||||
int cs = sp.wValue >> 8; /* Control Selector - currently unused */
|
||||
int cn = sp.wValue & 0xff; /* Channel number - used for mixer node index */
|
||||
|
||||
/* Expect OUT here with mute */
|
||||
if((result = XUD_GetBuffer(ep0_out, (buffer, unsigned char[]), datalength)) != XUD_RES_OKAY)
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */
|
||||
{
|
||||
return result;
|
||||
}
|
||||
unsigned weightMult = 0;
|
||||
|
||||
mixer1Weights[sp.wValue & 0xff] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8;
|
||||
/* Expect OUT here with weight */
|
||||
if((result = XUD_GetBuffer(ep0_out, (buffer, unsigned char[]), datalength)) != XUD_RES_OKAY)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (mixer1Weights[sp.wValue & 0xff] == 0x8000)
|
||||
{
|
||||
volume = 0;
|
||||
if(cn < sizeof(mixer1Weights)/sizeof(mixer1Weights[0]))
|
||||
{
|
||||
mixer1Weights[cn] = (buffer, unsigned char[])[0] | (buffer, unsigned char[])[1] << 8;
|
||||
|
||||
if (mixer1Weights[cn] != 0x8000)
|
||||
{
|
||||
weightMult = db_to_mult(mixer1Weights[cn], XUA_MIXER_DB_FRAC_BITS, XUA_MIXER_MULT_FRAC_BITS);
|
||||
}
|
||||
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
UpdateMixerWeight(c_mix_ctl, (cn) % 8, (cn) / 8, weightMult);
|
||||
}
|
||||
}
|
||||
|
||||
/* Send 0 Length as status stage */
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
volume = db_to_mult(mixer1Weights[sp.wValue & 0xff], 8, 25);
|
||||
}
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outuint(c_mix_ctl, SET_MIX_MULT);
|
||||
outuint(c_mix_ctl, (sp.wValue & 0xff) % 8);
|
||||
outuint(c_mix_ctl, (sp.wValue & 0xff) / 8);
|
||||
outuint(c_mix_ctl, volume);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
short weight = 0x8000;
|
||||
|
||||
/* Send 0 Length as status stage */
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
short weight = mixer1Weights[sp.wValue & 0xff];
|
||||
(buffer, unsigned char[])[0] = weight & 0xff;
|
||||
(buffer, unsigned char[])[1] = (weight >> 8) & 0xff;
|
||||
if(cn < sizeof(mixer1Weights)/sizeof(mixer1Weights[0]))
|
||||
{
|
||||
weight = mixer1Weights[cn];
|
||||
}
|
||||
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength);
|
||||
storeShort((buffer, unsigned char[]), 0, weight);
|
||||
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
#endif
|
||||
default:
|
||||
/* We dont have a unit with this ID! */
|
||||
@@ -896,17 +923,20 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
{
|
||||
storeFreq((buffer, unsigned char[]), i, currentFreq44);
|
||||
num_freqs++;
|
||||
currentFreq44*=2;
|
||||
}
|
||||
|
||||
if((currentFreq48 <= maxFreq))
|
||||
currentFreq44*=2;
|
||||
|
||||
if((currentFreq48 <= maxFreq) && (currentFreq48 >= MIN_FREQ))
|
||||
{
|
||||
/* Note i passed byref here */
|
||||
storeFreq((buffer, unsigned char[]), i, currentFreq48);
|
||||
num_freqs++;
|
||||
currentFreq48*=2;
|
||||
}
|
||||
else
|
||||
|
||||
currentFreq48*=2;
|
||||
|
||||
if((currentFreq48 > MAX_FREQ) && (currentFreq44 > MAX_FREQ))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -919,7 +949,6 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
num_freqs++;
|
||||
}
|
||||
#endif
|
||||
|
||||
storeShort((buffer, unsigned char[]), 0, num_freqs);
|
||||
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), i, sp.wLength);
|
||||
@@ -957,7 +986,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef MIXER
|
||||
#if (MIXER)
|
||||
/* Mixer Unit */
|
||||
case ID_MIXER_1:
|
||||
storeShort((buffer, unsigned char[]), 0, 1);
|
||||
@@ -967,7 +996,6 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, (buffer, unsigned char[]), sp.wLength, sp.wLength);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
/* Unknown Unit ID in Range Request selector for FU */
|
||||
break;
|
||||
@@ -977,7 +1005,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
break; /* case: RANGE */
|
||||
}
|
||||
|
||||
#if defined (MIXER) && (MAX_MIX_COUNT > 0)
|
||||
#if ((MIXER) && (MAX_MIX_COUNT > 0))
|
||||
case MEM: /* Memory Requests (5.2.7.1) */
|
||||
|
||||
unitID = sp.wIndex >> 8;
|
||||
@@ -1003,6 +1031,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
{
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
inct(c_mix_ctl);
|
||||
outuint(c_mix_ctl, GET_STREAM_LEVELS);
|
||||
outuint(c_mix_ctl, i);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
@@ -1018,6 +1048,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
{
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
inct(c_mix_ctl);
|
||||
outuint(c_mix_ctl, GET_INPUT_LEVELS);
|
||||
outuint(c_mix_ctl, (i - NUM_USB_CHAN_OUT));
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
@@ -1040,6 +1072,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
{
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
inct(c_mix_ctl);
|
||||
outuint(c_mix_ctl, GET_OUTPUT_LEVELS);
|
||||
outuint(c_mix_ctl, i);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
@@ -1107,13 +1141,10 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
|
||||
|
||||
if(newSampleRate != g_curSamFreq)
|
||||
{
|
||||
int curSamFreq44100Family;
|
||||
int curSamFreq48000Family;
|
||||
|
||||
/* Windows Audio Class driver has a nice habbit of sending invalid SF's (e.g. 48001Hz)
|
||||
* when under stress. Lets double check it here and ignore if not valid. */
|
||||
curSamFreq48000Family = MCLK_48 % newSampleRate == 0;
|
||||
curSamFreq44100Family = MCLK_441 % newSampleRate == 0;
|
||||
int curSamFreq48000Family = MCLK_48 % newSampleRate == 0;
|
||||
int curSamFreq44100Family = MCLK_441 % newSampleRate == 0;
|
||||
|
||||
if(curSamFreq48000Family || curSamFreq44100Family)
|
||||
{
|
||||
@@ -1128,7 +1159,7 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
|
||||
|
||||
/* Allow time for the change - feedback to stabilise */
|
||||
FeedbackStabilityDelay();
|
||||
}
|
||||
}
|
||||
}
|
||||
return XUD_SetBuffer(ep0_in, (buffer, unsigned char[]), 0);
|
||||
}
|
||||
@@ -1190,12 +1221,12 @@ XUD_Result_t AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket
|
||||
{
|
||||
case FU_USBOUT:
|
||||
volsOut[ sp.wValue & 0xff ] = buffer[0] | (((int) (signed char) buffer[1]) << 8);
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl );
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl);
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
|
||||
case FU_USBIN:
|
||||
volsIn[ sp.wValue & 0xff ] = buffer[0] | (((int) (signed char) buffer[1]) << 8);
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl );
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl);
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
}
|
||||
@@ -1209,12 +1240,12 @@ XUD_Result_t AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket
|
||||
{
|
||||
case FU_USBOUT:
|
||||
mutesOut[ sp.wValue & 0xff ] = buffer[0];
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl );
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl);
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
|
||||
case FU_USBIN:
|
||||
mutesIn[ sp.wValue & 0xff ] = buffer[0];
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl );
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl);
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2012-2022 XMOS LIMITED.
|
||||
// Copyright 2012-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#include "xua.h" /* Device specific defines */
|
||||
@@ -30,8 +30,8 @@
|
||||
#include "iap.h"
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
#include "SpdifReceive.h"
|
||||
#if (XUA_SPDIF_RX_EN || XUA_SPDIF_TX_EN)
|
||||
#include "spdif.h" /* From lib_spdif */
|
||||
#endif
|
||||
|
||||
#if (XUA_ADAT_RX_EN)
|
||||
@@ -42,10 +42,6 @@
|
||||
#include "xua_pdm_mic.h"
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_TX_EN)
|
||||
#include "spdif.h" /* From lib_spdif */
|
||||
#endif
|
||||
|
||||
#if (XUA_DFU_EN == 1)
|
||||
[[distributable]]
|
||||
void DFUHandler(server interface i_dfu i, chanend ?c_user_cmd);
|
||||
@@ -142,12 +138,17 @@ on stdcore[XUD_TILE] : buffered in port:32 p_adat_rx = PORT_ADAT_IN;
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_RX_EN)
|
||||
on tile[XUD_TILE] : buffered in port:4 p_spdif_rx = PORT_SPDIF_IN;
|
||||
on tile[XUD_TILE] : in port p_spdif_rx = PORT_SPDIF_IN;
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_RX_EN) || (XUA_ADAT_RX_EN) || (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
/* Reference to external clock multiplier */
|
||||
on tile[PLL_REF_TILE] : out port p_pll_ref = PORT_PLL_REF;
|
||||
#ifdef __XS3A__
|
||||
on tile[AUDIO_IO_TILE] : port p_for_mclk_count_audio = PORT_MCLK_COUNT_2;
|
||||
#else /* __XS3A__ */
|
||||
#define p_for_mclk_count_audio null
|
||||
#endif /* __XS3A__ */
|
||||
#endif
|
||||
|
||||
#ifdef MIDI
|
||||
@@ -213,6 +214,9 @@ XUD_EpType epTypeTableOut[ENDPOINT_COUNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_EN
|
||||
#ifdef MIDI
|
||||
XUD_EPTYPE_BUL, /* MIDI */
|
||||
#endif
|
||||
#if HID_OUT_REQUIRED
|
||||
XUD_EPTYPE_INT,
|
||||
#endif
|
||||
#ifdef IAP
|
||||
XUD_EPTYPE_BUL, /* iAP */
|
||||
#ifdef IAP_EA_NATIVE_TRANS
|
||||
@@ -228,12 +232,12 @@ XUD_EpType epTypeTableIn[ENDPOINT_COUNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENAB
|
||||
XUD_EPTYPE_ISO, /* Async feedback endpoint */
|
||||
#endif
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
XUD_EPTYPE_BUL,
|
||||
XUD_EPTYPE_INT,
|
||||
#endif
|
||||
#ifdef MIDI
|
||||
XUD_EPTYPE_BUL,
|
||||
#endif
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#if XUA_OR_STATIC_HID_ENABLED
|
||||
XUD_EPTYPE_INT,
|
||||
#endif
|
||||
#ifdef IAP
|
||||
@@ -267,115 +271,6 @@ void xscope_user_init()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if XUA_USB_EN
|
||||
/* Core USB Audio functions - must be called on the Tile connected to the USB Phy */
|
||||
void usb_audio_core(chanend c_mix_out
|
||||
#ifdef MIDI
|
||||
, chanend c_midi
|
||||
#endif
|
||||
#ifdef MIXER
|
||||
, chanend c_mix_ctl
|
||||
#endif
|
||||
, chanend ?c_clk_int
|
||||
, chanend ?c_clk_ctl
|
||||
, client interface i_dfu ?dfuInterface
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
, client interface pll_ref_if i_pll_ref
|
||||
#endif
|
||||
VENDOR_REQUESTS_PARAMS_DEC_
|
||||
)
|
||||
{
|
||||
chan c_sof;
|
||||
chan c_xud_out[ENDPOINT_COUNT_OUT]; /* Endpoint channels for XUD */
|
||||
chan c_xud_in[ENDPOINT_COUNT_IN];
|
||||
chan c_aud_ctl;
|
||||
|
||||
#ifndef MIXER
|
||||
#define c_mix_ctl null
|
||||
#endif
|
||||
|
||||
#ifdef IAP_EA_NATIVE_TRANS
|
||||
chan c_EANativeTransport_ctrl;
|
||||
#else
|
||||
#define c_EANativeTransport_ctrl null
|
||||
#endif
|
||||
|
||||
par
|
||||
{
|
||||
{
|
||||
#ifdef XUD_PRIORITY_HIGH
|
||||
set_core_high_priority_on();
|
||||
#endif
|
||||
|
||||
/* Run UAC2.0 at high-speed, UAC1.0 at full-speed */
|
||||
unsigned usbSpeed = (AUDIO_CLASS == 2) ? XUD_SPEED_HS : XUD_SPEED_FS;
|
||||
|
||||
unsigned xudPwrCfg = (XUA_POWERMODE == XUA_POWERMODE_SELF) ? XUD_PWR_SELF : XUD_PWR_BUS;
|
||||
|
||||
/* USB interface core */
|
||||
XUD_Main(c_xud_out, ENDPOINT_COUNT_OUT, c_xud_in, ENDPOINT_COUNT_IN,
|
||||
c_sof, epTypeTableOut, epTypeTableIn, usbSpeed, xudPwrCfg);
|
||||
}
|
||||
|
||||
{
|
||||
unsigned x;
|
||||
thread_speed();
|
||||
|
||||
/* Attach mclk count port to mclk clock-block (for feedback) */
|
||||
//set_port_clock(p_for_mclk_count, clk_audio_mclk);
|
||||
#if(AUDIO_IO_TILE != XUD_TILE)
|
||||
set_clock_src(clk_audio_mclk_usb, p_mclk_in_usb);
|
||||
set_port_clock(p_for_mclk_count, clk_audio_mclk_usb);
|
||||
start_clock(clk_audio_mclk_usb);
|
||||
#else
|
||||
/* Clock port from same clock-block as I2S */
|
||||
/* TODO remove asm() */
|
||||
asm("ldw %0, dp[clk_audio_mclk]":"=r"(x));
|
||||
asm("setclk res[%0], %1"::"r"(p_for_mclk_count), "r"(x));
|
||||
#endif
|
||||
/* Endpoint & audio buffering cores */
|
||||
XUA_Buffer(c_xud_out[ENDPOINT_NUMBER_OUT_AUDIO],/* Audio Out*/
|
||||
#if (NUM_USB_CHAN_IN > 0)
|
||||
|
||||
c_xud_in[ENDPOINT_NUMBER_IN_AUDIO], /* Audio In */
|
||||
#endif
|
||||
#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP)
|
||||
c_xud_in[ENDPOINT_NUMBER_IN_FEEDBACK], /* Audio FB */
|
||||
#endif
|
||||
#ifdef MIDI
|
||||
c_xud_out[ENDPOINT_NUMBER_OUT_MIDI], /* MIDI Out */ // 2
|
||||
c_xud_in[ENDPOINT_NUMBER_IN_MIDI], /* MIDI In */ // 4
|
||||
c_midi,
|
||||
#endif
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
/* Audio Interrupt - only used for interrupts on external clock change */
|
||||
c_xud_in[ENDPOINT_NUMBER_IN_INTERRUPT],
|
||||
c_clk_int,
|
||||
#endif
|
||||
c_sof, c_aud_ctl, p_for_mclk_count
|
||||
#if (HID_CONTROLS)
|
||||
, c_xud_in[ENDPOINT_NUMBER_IN_HID]
|
||||
#endif
|
||||
, c_mix_out
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
, i_pll_ref
|
||||
#endif
|
||||
);
|
||||
//:
|
||||
}
|
||||
|
||||
/* Endpoint 0 Core */
|
||||
{
|
||||
thread_speed();
|
||||
XUA_Endpoint0( c_xud_out[0], c_xud_in[0], c_aud_ctl, c_mix_ctl, c_clk_ctl, c_EANativeTransport_ctrl, dfuInterface VENDOR_REQUESTS_PARAMS_);
|
||||
}
|
||||
|
||||
//:
|
||||
}
|
||||
}
|
||||
#endif /* XUA_USB_EN */
|
||||
|
||||
|
||||
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
|
||||
void SpdifTxWrapper(chanend c_spdif_tx)
|
||||
{
|
||||
@@ -401,7 +296,7 @@ void usb_audio_io(chanend ?c_aud_in,
|
||||
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
|
||||
chanend c_spdif_tx,
|
||||
#endif
|
||||
#ifdef MIXER
|
||||
#if (MIXER)
|
||||
chanend c_mix_ctl,
|
||||
#endif
|
||||
streaming chanend ?c_spdif_rx,
|
||||
@@ -420,17 +315,29 @@ void usb_audio_io(chanend ?c_aud_in,
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
, client interface pll_ref_if i_pll_ref
|
||||
#endif
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
, chanend c_audio_rate_change
|
||||
#endif
|
||||
#if ((XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN) && XUA_USE_SW_PLL)
|
||||
, port p_for_mclk_count_aud
|
||||
, chanend c_sw_pll
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#ifdef MIXER
|
||||
#if (MIXER)
|
||||
chan c_mix_out;
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
chan c_dig_rx;
|
||||
#else
|
||||
#define c_dig_rx null
|
||||
#endif
|
||||
chan c_audio_rate_change; /* Notification of new mclk freq to clockgen and synch */
|
||||
#if XUA_USE_SW_PLL
|
||||
/* Connect p_for_mclk_count_aud to clk_audio_mclk so we can count mclks/timestamp in digital rx*/
|
||||
unsigned x = 0;
|
||||
asm("ldw %0, dp[clk_audio_mclk]":"=r"(x));
|
||||
asm("setclk res[%0], %1"::"r"(p_for_mclk_count_aud), "r"(x));
|
||||
#endif /* XUA_USE_SW_PLL */
|
||||
#endif /* (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN) */
|
||||
|
||||
#if (XUA_NUM_PDM_MICS > 0) && (PDM_TILE == AUDIO_IO_TILE)
|
||||
/* Configure clocks ports - sharing mclk port with I2S */
|
||||
@@ -446,7 +353,7 @@ void usb_audio_io(chanend ?c_aud_in,
|
||||
|
||||
par
|
||||
{
|
||||
#ifdef MIXER
|
||||
#if (MIXER && XUA_USB_EN)
|
||||
/* Mixer cores(s) */
|
||||
{
|
||||
thread_speed();
|
||||
@@ -463,8 +370,9 @@ void usb_audio_io(chanend ?c_aud_in,
|
||||
|
||||
/* Audio I/O core (pars additional S/PDIF TX Core) */
|
||||
{
|
||||
thread_speed();
|
||||
#ifdef MIXER
|
||||
// thread_speed();
|
||||
set_thread_fast_mode_on();
|
||||
#if (MIXER)
|
||||
#define AUDIO_CHANNEL c_mix_out
|
||||
#else
|
||||
#define AUDIO_CHANNEL c_aud_in
|
||||
@@ -476,6 +384,9 @@ void usb_audio_io(chanend ?c_aud_in,
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
, c_dig_rx
|
||||
#endif
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC || XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
, c_audio_rate_change
|
||||
#endif
|
||||
#if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0) && (XUA_DFU_EN == 1)
|
||||
, dfuInterface
|
||||
#endif
|
||||
@@ -495,12 +406,22 @@ void usb_audio_io(chanend ?c_aud_in,
|
||||
* However, due to the use of an interface the pll reference signal port can be on another tile
|
||||
*/
|
||||
thread_speed();
|
||||
clockGen(c_spdif_rx, c_adat_rx, i_pll_ref, c_dig_rx, c_clk_ctl, c_clk_int);
|
||||
clockGen( c_spdif_rx,
|
||||
c_adat_rx,
|
||||
i_pll_ref,
|
||||
c_dig_rx,
|
||||
c_clk_ctl,
|
||||
c_clk_int,
|
||||
c_audio_rate_change
|
||||
#if XUA_USE_SW_PLL
|
||||
, p_for_mclk_count_aud
|
||||
, c_sw_pll
|
||||
#endif
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
//:
|
||||
}
|
||||
} // par
|
||||
}
|
||||
|
||||
#ifndef USER_MAIN_DECLARATIONS
|
||||
@@ -531,7 +452,7 @@ int main()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MIXER
|
||||
#if (MIXER)
|
||||
chan c_mix_ctl;
|
||||
#endif
|
||||
|
||||
@@ -547,7 +468,7 @@ int main()
|
||||
#define c_adat_rx null
|
||||
#endif
|
||||
|
||||
#if (XUA_SPDIF_TX_EN) //&& (SPDIF_TX_TILE != AUDIO_IO_TILE)
|
||||
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
|
||||
chan c_spdif_tx;
|
||||
#endif
|
||||
|
||||
@@ -573,62 +494,146 @@ int main()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ((XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
#if (((XUA_SYNCMODE == XUA_SYNCMODE_SYNC && !XUA_USE_SW_PLL) || XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN) )
|
||||
interface pll_ref_if i_pll_ref;
|
||||
#endif
|
||||
|
||||
#if ((XUA_SYNCMODE == XUA_SYNCMODE_SYNC || XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN) && XUA_USE_SW_PLL)
|
||||
chan c_sw_pll;
|
||||
#endif
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
chan c_audio_rate_change; /* Notification of new mclk freq to ep_buffer */
|
||||
#endif
|
||||
chan c_sof;
|
||||
chan c_xud_out[ENDPOINT_COUNT_OUT]; /* Endpoint channels for XUD */
|
||||
chan c_xud_in[ENDPOINT_COUNT_IN];
|
||||
chan c_aud_ctl;
|
||||
|
||||
#if (!MIXER)
|
||||
#define c_mix_ctl null
|
||||
#endif
|
||||
|
||||
#ifdef IAP_EA_NATIVE_TRANS
|
||||
chan c_EANativeTransport_ctrl;
|
||||
#else
|
||||
#define c_EANativeTransport_ctrl null
|
||||
#endif
|
||||
|
||||
USER_MAIN_DECLARATIONS
|
||||
|
||||
par
|
||||
{
|
||||
USER_MAIN_CORES
|
||||
|
||||
#if ((XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
#if (((XUA_SYNCMODE == XUA_SYNCMODE_SYNC && !XUA_USE_SW_PLL) || XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN))
|
||||
on tile[PLL_REF_TILE]: PllRefPinTask(i_pll_ref, p_pll_ref);
|
||||
#endif
|
||||
on tile[XUD_TILE]:
|
||||
par
|
||||
{
|
||||
#if (XUD_TILE == 0)
|
||||
#if XUA_USB_EN
|
||||
#if ((XUD_TILE == 0) && (XUA_DFU_EN == 1))
|
||||
/* Check if USB is on the flash tile (tile 0) */
|
||||
#if (XUA_DFU_EN == 1)
|
||||
[[distribute]]
|
||||
DFUHandler(dfuInterface, null);
|
||||
#endif
|
||||
#endif
|
||||
#if XUA_USB_EN
|
||||
/* Core USB audio task, buffering, USB etc */
|
||||
usb_audio_core(c_mix_out
|
||||
#ifdef MIDI
|
||||
, c_midi
|
||||
#endif
|
||||
#ifdef IAP
|
||||
, c_iap
|
||||
#ifdef IAP_EA_NATIVE_TRANS
|
||||
, c_ea_data
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MIXER
|
||||
, c_mix_ctl
|
||||
#endif
|
||||
, c_clk_int, c_clk_ctl, dfuInterface
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
, i_pll_ref
|
||||
#endif
|
||||
VENDOR_REQUESTS_PARAMS_
|
||||
|
||||
);
|
||||
/* Core USB task, buffering, USB etc */
|
||||
{
|
||||
#ifdef XUD_PRIORITY_HIGH
|
||||
set_core_high_priority_on();
|
||||
#endif
|
||||
|
||||
/* Run UAC2.0 at high-speed, UAC1.0 at full-speed */
|
||||
unsigned usbSpeed = (AUDIO_CLASS == 2) ? XUD_SPEED_HS : XUD_SPEED_FS;
|
||||
|
||||
unsigned xudPwrCfg = (XUA_POWERMODE == XUA_POWERMODE_SELF) ? XUD_PWR_SELF : XUD_PWR_BUS;
|
||||
|
||||
/* USB interface core */
|
||||
XUD_Main(c_xud_out, ENDPOINT_COUNT_OUT, c_xud_in, ENDPOINT_COUNT_IN,
|
||||
c_sof, epTypeTableOut, epTypeTableIn, usbSpeed, xudPwrCfg);
|
||||
}
|
||||
|
||||
/* Core USB audio task, buffering, USB etc */
|
||||
{
|
||||
unsigned x;
|
||||
thread_speed();
|
||||
|
||||
/* Attach mclk count port to mclk clock-block (for feedback) */
|
||||
//set_port_clock(p_for_mclk_count, clk_audio_mclk);
|
||||
#if(AUDIO_IO_TILE != XUD_TILE)
|
||||
set_clock_src(clk_audio_mclk_usb, p_mclk_in_usb);
|
||||
set_port_clock(p_for_mclk_count, clk_audio_mclk_usb);
|
||||
start_clock(clk_audio_mclk_usb);
|
||||
#else
|
||||
/* Clock port from same clock-block as I2S */
|
||||
/* TODO remove asm() */
|
||||
asm("ldw %0, dp[clk_audio_mclk]":"=r"(x)); //跟这里无关
|
||||
asm("setclk res[%0], %1"::"r"(p_for_mclk_count), "r"(x));
|
||||
#endif
|
||||
/* Endpoint & audio buffering cores */
|
||||
XUA_Buffer(c_xud_out[ENDPOINT_NUMBER_OUT_AUDIO],/* Audio Out*/
|
||||
#if (NUM_USB_CHAN_IN > 0)
|
||||
|
||||
c_xud_in[ENDPOINT_NUMBER_IN_AUDIO], /* Audio In */
|
||||
#endif
|
||||
#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP)
|
||||
c_xud_in[ENDPOINT_NUMBER_IN_FEEDBACK], /* Audio FB */
|
||||
#endif
|
||||
#ifdef MIDI
|
||||
c_xud_out[ENDPOINT_NUMBER_OUT_MIDI], /* MIDI Out */ // 2
|
||||
c_xud_in[ENDPOINT_NUMBER_IN_MIDI], /* MIDI In */ // 4
|
||||
c_midi,
|
||||
#endif
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
/* Audio Interrupt - only used for interrupts on external clock change */
|
||||
c_xud_in[ENDPOINT_NUMBER_IN_INTERRUPT],
|
||||
c_clk_int,
|
||||
#endif
|
||||
c_sof, c_aud_ctl, p_for_mclk_count
|
||||
#if (XUA_HID_ENABLED)
|
||||
, c_xud_in[ENDPOINT_NUMBER_IN_HID]
|
||||
#endif
|
||||
#if PAWPAW_INOUTHID
|
||||
, c_xud_in[ENDPOINT_NUMBER_IN_HID]
|
||||
, c_xud_out[ENDPOINT_NUMBER_OUT_HID]
|
||||
#endif //#if PAWPAW_INOUTHID
|
||||
, c_mix_out
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
, c_audio_rate_change
|
||||
#if (!XUA_USE_SW_PLL)
|
||||
, i_pll_ref
|
||||
#else
|
||||
, c_sw_pll
|
||||
#endif
|
||||
#endif
|
||||
|
||||
);
|
||||
//:
|
||||
}
|
||||
XUD_UNSAFE_RESRC
|
||||
/* Endpoint 0 Core */
|
||||
{
|
||||
thread_speed();
|
||||
XUA_Endpoint0( c_xud_out[0], c_xud_in[0], c_aud_ctl, c_mix_ctl, c_clk_ctl, c_EANativeTransport_ctrl, dfuInterface VENDOR_REQUESTS_PARAMS_);
|
||||
}
|
||||
|
||||
#endif /* XUA_USB_EN */
|
||||
}
|
||||
|
||||
#if ((XUA_SYNCMODE == XUA_SYNCMODE_SYNC || XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN) && XUA_USE_SW_PLL)
|
||||
on tile[AUDIO_IO_TILE]: sw_pll_task(c_sw_pll);
|
||||
#endif
|
||||
|
||||
on tile[AUDIO_IO_TILE]:
|
||||
{
|
||||
AUDIO_UNSAFE_RESRC
|
||||
/* Audio I/O task, includes mixing etc */
|
||||
usb_audio_io(c_mix_out
|
||||
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
|
||||
, c_spdif_tx
|
||||
#endif
|
||||
#ifdef MIXER
|
||||
#if (MIXER)
|
||||
, c_mix_ctl
|
||||
#endif
|
||||
, c_spdif_rx, c_adat_rx, c_clk_ctl, c_clk_int
|
||||
@@ -636,13 +641,16 @@ int main()
|
||||
, dfuInterface
|
||||
#endif
|
||||
#if (XUA_NUM_PDM_MICS > 0)
|
||||
#if (PDM_TILE == AUDIO_IO_TILE)
|
||||
, c_ds_output
|
||||
#endif
|
||||
, c_pdm_pcm
|
||||
#endif
|
||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||
, i_pll_ref
|
||||
#endif
|
||||
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
|
||||
, c_audio_rate_change
|
||||
#endif
|
||||
#if ((XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN) && XUA_USE_SW_PLL)
|
||||
, p_for_mclk_count_audio
|
||||
, c_sw_pll
|
||||
#endif
|
||||
);
|
||||
}
|
||||
@@ -685,7 +693,7 @@ int main()
|
||||
on tile[XUD_TILE]:
|
||||
{
|
||||
thread_speed();
|
||||
SpdifReceive(p_spdif_rx, c_spdif_rx, 1, clk_spd_rx);
|
||||
spdif_rx(c_spdif_rx, p_spdif_rx, clk_spd_rx, 192000);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user